@formulaxjs/tiptap 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +212 -207
  2. package/README.zh-CN.md +71 -66
  3. package/dist/base.css +47 -0
  4. package/dist/canvg-runtime-UR3JNX5Q.js +2759 -0
  5. package/dist/canvg-runtime-UR3JNX5Q.js.map +1 -0
  6. package/dist/chunk-OCSSWPUX.js +3407 -0
  7. package/dist/chunk-OCSSWPUX.js.map +1 -0
  8. package/dist/images/scrollbar/custom/bar-bg.png +0 -0
  9. package/dist/images/scrollbar/custom/bar.png +0 -0
  10. package/dist/images/scrollbar/custom/bg.png +0 -0
  11. package/dist/images/scrollbar/custom/bottom.png +0 -0
  12. package/dist/images/scrollbar/custom/btn.png +0 -0
  13. package/dist/images/scrollbar/custom/down.png +0 -0
  14. package/dist/images/scrollbar/custom/top.png +0 -0
  15. package/dist/images/scrollbar/custom/up.png +0 -0
  16. package/dist/images/scrollbar/edit/bar-bg.png +0 -0
  17. package/dist/images/scrollbar/edit/bar-left.png +0 -0
  18. package/dist/images/scrollbar/edit/bar-right.png +0 -0
  19. package/dist/images/scrollbar/edit/thumb-bg.png +0 -0
  20. package/dist/images/scrollbar/edit/thumb-left.png +0 -0
  21. package/dist/images/scrollbar/edit/thumb-right.png +0 -0
  22. package/dist/images/toolbar/btn.png +0 -0
  23. package/dist/index.cjs +24075 -65
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.global.js +2385 -2241
  26. package/dist/index.global.js.map +1 -1
  27. package/dist/index.js +3768 -21
  28. package/dist/index.js.map +1 -1
  29. package/dist/install-XGCSWTLU.js +5464 -0
  30. package/dist/install-XGCSWTLU.js.map +1 -0
  31. package/dist/install-XVTKACEN.js +1349 -0
  32. package/dist/install-XVTKACEN.js.map +1 -0
  33. package/dist/other.png +0 -0
  34. package/dist/scrollbar.css +78 -0
  35. package/dist/start-MBLTNR2Q.js +4926 -0
  36. package/dist/start-MBLTNR2Q.js.map +1 -0
  37. package/dist/ui.css +625 -0
  38. package/package.json +9 -4
  39. /package/dist/{KF_AMS_BB-5QF7FUSO.woff → KF_AMS_BB.woff} +0 -0
  40. /package/dist/{KF_AMS_CAL-NXRNLAZN.woff → KF_AMS_CAL.woff} +0 -0
  41. /package/dist/{KF_AMS_FRAK-CO33WWN4.woff → KF_AMS_FRAK.woff} +0 -0
  42. /package/dist/{KF_AMS_MAIN-25QJVAWY.woff → KF_AMS_MAIN.woff} +0 -0
  43. /package/dist/{KF_AMS_ROMAN-243BR7HH.woff → KF_AMS_ROMAN.woff} +0 -0
  44. /package/dist/{btn-5DANP6JY.png → btn.png} +0 -0
  45. /package/dist/{editor-JT5KLVXX.css → editor.css} +0 -0
  46. /package/dist/{other-OMWJFGL5.png → images/toolbar/other.png} +0 -0
@@ -0,0 +1,2759 @@
1
+ // ../kity-runtime/src/vendor/kity-formula/canvg-runtime.ts
2
+ function createCanvgRuntime() {
3
+ const target = globalThis;
4
+ function RGBColor(color_string) {
5
+ this.ok = false;
6
+ if (color_string.charAt(0) == "#") {
7
+ color_string = color_string.substr(1, 6);
8
+ }
9
+ color_string = color_string.replace(/ /g, "");
10
+ color_string = color_string.toLowerCase();
11
+ let simple_colors = {
12
+ aliceblue: "f0f8ff",
13
+ antiquewhite: "faebd7",
14
+ aqua: "00ffff",
15
+ aquamarine: "7fffd4",
16
+ azure: "f0ffff",
17
+ beige: "f5f5dc",
18
+ bisque: "ffe4c4",
19
+ black: "000000",
20
+ blanchedalmond: "ffebcd",
21
+ blue: "0000ff",
22
+ blueviolet: "8a2be2",
23
+ brown: "a52a2a",
24
+ burlywood: "deb887",
25
+ cadetblue: "5f9ea0",
26
+ chartreuse: "7fff00",
27
+ chocolate: "d2691e",
28
+ coral: "ff7f50",
29
+ cornflowerblue: "6495ed",
30
+ cornsilk: "fff8dc",
31
+ crimson: "dc143c",
32
+ cyan: "00ffff",
33
+ darkblue: "00008b",
34
+ darkcyan: "008b8b",
35
+ darkgoldenrod: "b8860b",
36
+ darkgray: "a9a9a9",
37
+ darkgreen: "006400",
38
+ darkkhaki: "bdb76b",
39
+ darkmagenta: "8b008b",
40
+ darkolivegreen: "556b2f",
41
+ darkorange: "ff8c00",
42
+ darkorchid: "9932cc",
43
+ darkred: "8b0000",
44
+ darksalmon: "e9967a",
45
+ darkseagreen: "8fbc8f",
46
+ darkslateblue: "483d8b",
47
+ darkslategray: "2f4f4f",
48
+ darkturquoise: "00ced1",
49
+ darkviolet: "9400d3",
50
+ deeppink: "ff1493",
51
+ deepskyblue: "00bfff",
52
+ dimgray: "696969",
53
+ dodgerblue: "1e90ff",
54
+ feldspar: "d19275",
55
+ firebrick: "b22222",
56
+ floralwhite: "fffaf0",
57
+ forestgreen: "228b22",
58
+ fuchsia: "ff00ff",
59
+ gainsboro: "dcdcdc",
60
+ ghostwhite: "f8f8ff",
61
+ gold: "ffd700",
62
+ goldenrod: "daa520",
63
+ gray: "808080",
64
+ green: "008000",
65
+ greenyellow: "adff2f",
66
+ honeydew: "f0fff0",
67
+ hotpink: "ff69b4",
68
+ indianred: "cd5c5c",
69
+ indigo: "4b0082",
70
+ ivory: "fffff0",
71
+ khaki: "f0e68c",
72
+ lavender: "e6e6fa",
73
+ lavenderblush: "fff0f5",
74
+ lawngreen: "7cfc00",
75
+ lemonchiffon: "fffacd",
76
+ lightblue: "add8e6",
77
+ lightcoral: "f08080",
78
+ lightcyan: "e0ffff",
79
+ lightgoldenrodyellow: "fafad2",
80
+ lightgrey: "d3d3d3",
81
+ lightgreen: "90ee90",
82
+ lightpink: "ffb6c1",
83
+ lightsalmon: "ffa07a",
84
+ lightseagreen: "20b2aa",
85
+ lightskyblue: "87cefa",
86
+ lightslateblue: "8470ff",
87
+ lightslategray: "778899",
88
+ lightsteelblue: "b0c4de",
89
+ lightyellow: "ffffe0",
90
+ lime: "00ff00",
91
+ limegreen: "32cd32",
92
+ linen: "faf0e6",
93
+ magenta: "ff00ff",
94
+ maroon: "800000",
95
+ mediumaquamarine: "66cdaa",
96
+ mediumblue: "0000cd",
97
+ mediumorchid: "ba55d3",
98
+ mediumpurple: "9370d8",
99
+ mediumseagreen: "3cb371",
100
+ mediumslateblue: "7b68ee",
101
+ mediumspringgreen: "00fa9a",
102
+ mediumturquoise: "48d1cc",
103
+ mediumvioletred: "c71585",
104
+ midnightblue: "191970",
105
+ mintcream: "f5fffa",
106
+ mistyrose: "ffe4e1",
107
+ moccasin: "ffe4b5",
108
+ navajowhite: "ffdead",
109
+ navy: "000080",
110
+ oldlace: "fdf5e6",
111
+ olive: "808000",
112
+ olivedrab: "6b8e23",
113
+ orange: "ffa500",
114
+ orangered: "ff4500",
115
+ orchid: "da70d6",
116
+ palegoldenrod: "eee8aa",
117
+ palegreen: "98fb98",
118
+ paleturquoise: "afeeee",
119
+ palevioletred: "d87093",
120
+ papayawhip: "ffefd5",
121
+ peachpuff: "ffdab9",
122
+ peru: "cd853f",
123
+ pink: "ffc0cb",
124
+ plum: "dda0dd",
125
+ powderblue: "b0e0e6",
126
+ purple: "800080",
127
+ red: "ff0000",
128
+ rosybrown: "bc8f8f",
129
+ royalblue: "4169e1",
130
+ saddlebrown: "8b4513",
131
+ salmon: "fa8072",
132
+ sandybrown: "f4a460",
133
+ seagreen: "2e8b57",
134
+ seashell: "fff5ee",
135
+ sienna: "a0522d",
136
+ silver: "c0c0c0",
137
+ skyblue: "87ceeb",
138
+ slateblue: "6a5acd",
139
+ slategray: "708090",
140
+ snow: "fffafa",
141
+ springgreen: "00ff7f",
142
+ steelblue: "4682b4",
143
+ tan: "d2b48c",
144
+ teal: "008080",
145
+ thistle: "d8bfd8",
146
+ tomato: "ff6347",
147
+ turquoise: "40e0d0",
148
+ violet: "ee82ee",
149
+ violetred: "d02090",
150
+ wheat: "f5deb3",
151
+ white: "ffffff",
152
+ whitesmoke: "f5f5f5",
153
+ yellow: "ffff00",
154
+ yellowgreen: "9acd32"
155
+ };
156
+ for (let key in simple_colors) {
157
+ if (color_string == key) {
158
+ color_string = simple_colors[key];
159
+ }
160
+ }
161
+ let color_defs = [{
162
+ re: /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,
163
+ example: ["rgb(123, 234, 45)", "rgb(255,234,245)"],
164
+ process: function(bits) {
165
+ return [parseInt(bits[1]), parseInt(bits[2]), parseInt(bits[3])];
166
+ }
167
+ }, {
168
+ re: /^(\w{2})(\w{2})(\w{2})$/,
169
+ example: ["#00ff00", "336699"],
170
+ process: function(bits) {
171
+ return [parseInt(bits[1], 16), parseInt(bits[2], 16), parseInt(bits[3], 16)];
172
+ }
173
+ }, {
174
+ re: /^(\w{1})(\w{1})(\w{1})$/,
175
+ example: ["#fb0", "f0f"],
176
+ process: function(bits) {
177
+ return [parseInt(bits[1] + bits[1], 16), parseInt(bits[2] + bits[2], 16), parseInt(bits[3] + bits[3], 16)];
178
+ }
179
+ }];
180
+ for (let i2 = 0; i2 < color_defs.length; i2++) {
181
+ let re = color_defs[i2].re;
182
+ let processor = color_defs[i2].process;
183
+ let bits = re.exec(color_string);
184
+ if (bits) {
185
+ channels = processor(bits);
186
+ this.r = channels[0];
187
+ this.g = channels[1];
188
+ this.b = channels[2];
189
+ this.ok = true;
190
+ }
191
+ }
192
+ this.r = this.r < 0 || isNaN(this.r) ? 0 : this.r > 255 ? 255 : this.r;
193
+ this.g = this.g < 0 || isNaN(this.g) ? 0 : this.g > 255 ? 255 : this.g;
194
+ this.b = this.b < 0 || isNaN(this.b) ? 0 : this.b > 255 ? 255 : this.b;
195
+ this.toRGB = function() {
196
+ return "rgb(" + this.r + ", " + this.g + ", " + this.b + ")";
197
+ };
198
+ this.toHex = function() {
199
+ let r = this.r.toString(16);
200
+ let g = this.g.toString(16);
201
+ let b = this.b.toString(16);
202
+ if (r.length == 1) r = "0" + r;
203
+ if (g.length == 1) g = "0" + g;
204
+ if (b.length == 1) b = "0" + b;
205
+ return "#" + r + g + b;
206
+ };
207
+ this.getHelpXML = function() {
208
+ let examples = new Array();
209
+ for (let i2 = 0; i2 < color_defs.length; i2++) {
210
+ let example = color_defs[i2].example;
211
+ for (let j = 0; j < example.length; j++) {
212
+ examples[examples.length] = example[j];
213
+ }
214
+ }
215
+ for (let sc in simple_colors) {
216
+ examples[examples.length] = sc;
217
+ }
218
+ let xml = document.createElement("ul");
219
+ xml.setAttribute("id", "rgbcolor-examples");
220
+ for (let i2 = 0; i2 < examples.length; i2++) {
221
+ try {
222
+ let list_item = document.createElement("li");
223
+ let list_color = new RGBColor(examples[i2]);
224
+ let example_div = document.createElement("div");
225
+ example_div.style.cssText = "margin: 3px; border: 1px solid black; background:" + list_color.toHex() + "; color:" + list_color.toHex();
226
+ example_div.appendChild(document.createTextNode("test"));
227
+ let list_item_value = document.createTextNode(" " + examples[i2] + " -> " + list_color.toRGB() + " -> " + list_color.toHex());
228
+ list_item.appendChild(example_div);
229
+ list_item.appendChild(list_item_value);
230
+ xml.appendChild(list_item);
231
+ } catch {
232
+ }
233
+ }
234
+ return xml;
235
+ };
236
+ }
237
+ let mul_table = [512, 512, 456, 512, 328, 456, 335, 512, 405, 328, 271, 456, 388, 335, 292, 512, 454, 405, 364, 328, 298, 271, 496, 456, 420, 388, 360, 335, 312, 292, 273, 512, 482, 454, 428, 405, 383, 364, 345, 328, 312, 298, 284, 271, 259, 496, 475, 456, 437, 420, 404, 388, 374, 360, 347, 335, 323, 312, 302, 292, 282, 273, 265, 512, 497, 482, 468, 454, 441, 428, 417, 405, 394, 383, 373, 364, 354, 345, 337, 328, 320, 312, 305, 298, 291, 284, 278, 271, 265, 259, 507, 496, 485, 475, 465, 456, 446, 437, 428, 420, 412, 404, 396, 388, 381, 374, 367, 360, 354, 347, 341, 335, 329, 323, 318, 312, 307, 302, 297, 292, 287, 282, 278, 273, 269, 265, 261, 512, 505, 497, 489, 482, 475, 468, 461, 454, 447, 441, 435, 428, 422, 417, 411, 405, 399, 394, 389, 383, 378, 373, 368, 364, 359, 354, 350, 345, 341, 337, 332, 328, 324, 320, 316, 312, 309, 305, 301, 298, 294, 291, 287, 284, 281, 278, 274, 271, 268, 265, 262, 259, 257, 507, 501, 496, 491, 485, 480, 475, 470, 465, 460, 456, 451, 446, 442, 437, 433, 428, 424, 420, 416, 412, 408, 404, 400, 396, 392, 388, 385, 381, 377, 374, 370, 367, 363, 360, 357, 354, 350, 347, 344, 341, 338, 335, 332, 329, 326, 323, 320, 318, 315, 312, 310, 307, 304, 302, 299, 297, 294, 292, 289, 287, 285, 282, 280, 278, 275, 273, 271, 269, 267, 265, 263, 261, 259];
238
+ let shg_table = [9, 11, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24];
239
+ function stackBlurCanvasRGBA(id, top_x, top_y, width2, height2, radius) {
240
+ if (isNaN(radius) || radius < 1) return;
241
+ radius |= 0;
242
+ let canvas = document.getElementById(id);
243
+ let context = canvas.getContext("2d");
244
+ let imageData;
245
+ try {
246
+ try {
247
+ imageData = context.getImageData(top_x, top_y, width2, height2);
248
+ } catch {
249
+ try {
250
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
251
+ imageData = context.getImageData(top_x, top_y, width2, height2);
252
+ } catch (e) {
253
+ alert("Cannot access local image");
254
+ throw new Error("unable to access local image data: " + e);
255
+ return;
256
+ }
257
+ }
258
+ } catch (e) {
259
+ alert("Cannot access image");
260
+ throw new Error("unable to access image data: " + e);
261
+ }
262
+ let pixels = imageData.data;
263
+ let x, y, i2, p, yp, yi, yw, r_sum, g_sum, b_sum, a_sum, r_out_sum, g_out_sum, b_out_sum, a_out_sum, r_in_sum, g_in_sum, b_in_sum, a_in_sum, pr, pg, pb, pa, rbs;
264
+ let div = radius + radius + 1;
265
+ let widthMinus1 = width2 - 1;
266
+ let heightMinus1 = height2 - 1;
267
+ let radiusPlus1 = radius + 1;
268
+ let sumFactor = radiusPlus1 * (radiusPlus1 + 1) / 2;
269
+ let stackStart = new BlurStack();
270
+ let stack = stackStart;
271
+ let stackEnd = stackStart;
272
+ for (i2 = 1; i2 < div; i2++) {
273
+ stack = stack.next = new BlurStack();
274
+ if (i2 == radiusPlus1) stackEnd = stack;
275
+ }
276
+ stack.next = stackStart;
277
+ let stackIn = null;
278
+ let stackOut = null;
279
+ yw = yi = 0;
280
+ let mul_sum = mul_table[radius];
281
+ let shg_sum = shg_table[radius];
282
+ for (y = 0; y < height2; y++) {
283
+ r_in_sum = g_in_sum = b_in_sum = a_in_sum = r_sum = g_sum = b_sum = a_sum = 0;
284
+ r_out_sum = radiusPlus1 * (pr = pixels[yi]);
285
+ g_out_sum = radiusPlus1 * (pg = pixels[yi + 1]);
286
+ b_out_sum = radiusPlus1 * (pb = pixels[yi + 2]);
287
+ a_out_sum = radiusPlus1 * (pa = pixels[yi + 3]);
288
+ r_sum += sumFactor * pr;
289
+ g_sum += sumFactor * pg;
290
+ b_sum += sumFactor * pb;
291
+ a_sum += sumFactor * pa;
292
+ stack = stackStart;
293
+ for (i2 = 0; i2 < radiusPlus1; i2++) {
294
+ stack.r = pr;
295
+ stack.g = pg;
296
+ stack.b = pb;
297
+ stack.a = pa;
298
+ stack = stack.next;
299
+ }
300
+ for (i2 = 1; i2 < radiusPlus1; i2++) {
301
+ p = yi + ((widthMinus1 < i2 ? widthMinus1 : i2) << 2);
302
+ r_sum += (stack.r = pr = pixels[p]) * (rbs = radiusPlus1 - i2);
303
+ g_sum += (stack.g = pg = pixels[p + 1]) * rbs;
304
+ b_sum += (stack.b = pb = pixels[p + 2]) * rbs;
305
+ a_sum += (stack.a = pa = pixels[p + 3]) * rbs;
306
+ r_in_sum += pr;
307
+ g_in_sum += pg;
308
+ b_in_sum += pb;
309
+ a_in_sum += pa;
310
+ stack = stack.next;
311
+ }
312
+ stackIn = stackStart;
313
+ stackOut = stackEnd;
314
+ for (x = 0; x < width2; x++) {
315
+ pixels[yi + 3] = pa = a_sum * mul_sum >> shg_sum;
316
+ if (pa != 0) {
317
+ pa = 255 / pa;
318
+ pixels[yi] = (r_sum * mul_sum >> shg_sum) * pa;
319
+ pixels[yi + 1] = (g_sum * mul_sum >> shg_sum) * pa;
320
+ pixels[yi + 2] = (b_sum * mul_sum >> shg_sum) * pa;
321
+ } else {
322
+ pixels[yi] = pixels[yi + 1] = pixels[yi + 2] = 0;
323
+ }
324
+ r_sum -= r_out_sum;
325
+ g_sum -= g_out_sum;
326
+ b_sum -= b_out_sum;
327
+ a_sum -= a_out_sum;
328
+ r_out_sum -= stackIn.r;
329
+ g_out_sum -= stackIn.g;
330
+ b_out_sum -= stackIn.b;
331
+ a_out_sum -= stackIn.a;
332
+ p = yw + ((p = x + radius + 1) < widthMinus1 ? p : widthMinus1) << 2;
333
+ r_in_sum += stackIn.r = pixels[p];
334
+ g_in_sum += stackIn.g = pixels[p + 1];
335
+ b_in_sum += stackIn.b = pixels[p + 2];
336
+ a_in_sum += stackIn.a = pixels[p + 3];
337
+ r_sum += r_in_sum;
338
+ g_sum += g_in_sum;
339
+ b_sum += b_in_sum;
340
+ a_sum += a_in_sum;
341
+ stackIn = stackIn.next;
342
+ r_out_sum += pr = stackOut.r;
343
+ g_out_sum += pg = stackOut.g;
344
+ b_out_sum += pb = stackOut.b;
345
+ a_out_sum += pa = stackOut.a;
346
+ r_in_sum -= pr;
347
+ g_in_sum -= pg;
348
+ b_in_sum -= pb;
349
+ a_in_sum -= pa;
350
+ stackOut = stackOut.next;
351
+ yi += 4;
352
+ }
353
+ yw += width2;
354
+ }
355
+ for (x = 0; x < width2; x++) {
356
+ g_in_sum = b_in_sum = a_in_sum = r_in_sum = g_sum = b_sum = a_sum = r_sum = 0;
357
+ yi = x << 2;
358
+ r_out_sum = radiusPlus1 * (pr = pixels[yi]);
359
+ g_out_sum = radiusPlus1 * (pg = pixels[yi + 1]);
360
+ b_out_sum = radiusPlus1 * (pb = pixels[yi + 2]);
361
+ a_out_sum = radiusPlus1 * (pa = pixels[yi + 3]);
362
+ r_sum += sumFactor * pr;
363
+ g_sum += sumFactor * pg;
364
+ b_sum += sumFactor * pb;
365
+ a_sum += sumFactor * pa;
366
+ stack = stackStart;
367
+ for (i2 = 0; i2 < radiusPlus1; i2++) {
368
+ stack.r = pr;
369
+ stack.g = pg;
370
+ stack.b = pb;
371
+ stack.a = pa;
372
+ stack = stack.next;
373
+ }
374
+ yp = width2;
375
+ for (i2 = 1; i2 <= radius; i2++) {
376
+ yi = yp + x << 2;
377
+ r_sum += (stack.r = pr = pixels[yi]) * (rbs = radiusPlus1 - i2);
378
+ g_sum += (stack.g = pg = pixels[yi + 1]) * rbs;
379
+ b_sum += (stack.b = pb = pixels[yi + 2]) * rbs;
380
+ a_sum += (stack.a = pa = pixels[yi + 3]) * rbs;
381
+ r_in_sum += pr;
382
+ g_in_sum += pg;
383
+ b_in_sum += pb;
384
+ a_in_sum += pa;
385
+ stack = stack.next;
386
+ if (i2 < heightMinus1) {
387
+ yp += width2;
388
+ }
389
+ }
390
+ yi = x;
391
+ stackIn = stackStart;
392
+ stackOut = stackEnd;
393
+ for (y = 0; y < height2; y++) {
394
+ p = yi << 2;
395
+ pixels[p + 3] = pa = a_sum * mul_sum >> shg_sum;
396
+ if (pa > 0) {
397
+ pa = 255 / pa;
398
+ pixels[p] = (r_sum * mul_sum >> shg_sum) * pa;
399
+ pixels[p + 1] = (g_sum * mul_sum >> shg_sum) * pa;
400
+ pixels[p + 2] = (b_sum * mul_sum >> shg_sum) * pa;
401
+ } else {
402
+ pixels[p] = pixels[p + 1] = pixels[p + 2] = 0;
403
+ }
404
+ r_sum -= r_out_sum;
405
+ g_sum -= g_out_sum;
406
+ b_sum -= b_out_sum;
407
+ a_sum -= a_out_sum;
408
+ r_out_sum -= stackIn.r;
409
+ g_out_sum -= stackIn.g;
410
+ b_out_sum -= stackIn.b;
411
+ a_out_sum -= stackIn.a;
412
+ p = x + ((p = y + radiusPlus1) < heightMinus1 ? p : heightMinus1) * width2 << 2;
413
+ r_sum += r_in_sum += stackIn.r = pixels[p];
414
+ g_sum += g_in_sum += stackIn.g = pixels[p + 1];
415
+ b_sum += b_in_sum += stackIn.b = pixels[p + 2];
416
+ a_sum += a_in_sum += stackIn.a = pixels[p + 3];
417
+ stackIn = stackIn.next;
418
+ r_out_sum += pr = stackOut.r;
419
+ g_out_sum += pg = stackOut.g;
420
+ b_out_sum += pb = stackOut.b;
421
+ a_out_sum += pa = stackOut.a;
422
+ r_in_sum -= pr;
423
+ g_in_sum -= pg;
424
+ b_in_sum -= pb;
425
+ a_in_sum -= pa;
426
+ stackOut = stackOut.next;
427
+ yi += width2;
428
+ }
429
+ }
430
+ context.putImageData(imageData, top_x, top_y);
431
+ }
432
+ function BlurStack() {
433
+ this.r = 0;
434
+ this.g = 0;
435
+ this.b = 0;
436
+ this.a = 0;
437
+ this.next = null;
438
+ }
439
+ (function(global) {
440
+ global.canvg = function(target2, s, opts) {
441
+ if (target2 == null && s == null && opts == null) {
442
+ let svgTags = document.getElementsByTagName("svg");
443
+ for (let i2 = 0; i2 < svgTags.length; i2++) {
444
+ let svgTag = svgTags[i2];
445
+ let c = document.createElement("canvas");
446
+ c.width = svgTag.clientWidth;
447
+ c.height = svgTag.clientHeight;
448
+ svgTag.parentNode.insertBefore(c, svgTag);
449
+ svgTag.parentNode.removeChild(svgTag);
450
+ let div = document.createElement("div");
451
+ div.appendChild(svgTag);
452
+ canvg(c, div.innerHTML);
453
+ }
454
+ return;
455
+ }
456
+ opts = opts || {};
457
+ if (typeof target2 == "string") {
458
+ target2 = document.getElementById(target2);
459
+ }
460
+ if (target2.svg != null) target2.svg.stop();
461
+ let svg = build();
462
+ if (!(target2.childNodes.length == 1 && target2.childNodes[0].nodeName == "OBJECT")) target2.svg = svg;
463
+ svg.opts = opts;
464
+ let ctx2 = target2.getContext("2d");
465
+ if (typeof s.documentElement != "undefined") {
466
+ svg.loadXmlDoc(ctx2, s);
467
+ } else if (s.substr(0, 1) == "<") {
468
+ svg.loadXml(ctx2, s);
469
+ } else {
470
+ svg.load(ctx2, s);
471
+ }
472
+ };
473
+ function build() {
474
+ let svg = {};
475
+ svg.FRAMERATE = 30;
476
+ svg.MAX_VIRTUAL_PIXELS = 3e4;
477
+ svg.init = function(ctx2) {
478
+ let uniqueId = 0;
479
+ svg.UniqueId = function() {
480
+ uniqueId++;
481
+ return "canvg" + uniqueId;
482
+ };
483
+ svg.Definitions = {};
484
+ svg.Styles = {};
485
+ svg.Animations = [];
486
+ svg.Images = [];
487
+ svg.ctx = ctx2;
488
+ svg.ViewPort = new function() {
489
+ this.viewPorts = [];
490
+ this.Clear = function() {
491
+ this.viewPorts = [];
492
+ };
493
+ this.SetCurrent = function(width2, height2) {
494
+ this.viewPorts.push({
495
+ width: width2,
496
+ height: height2
497
+ });
498
+ };
499
+ this.RemoveCurrent = function() {
500
+ this.viewPorts.pop();
501
+ };
502
+ this.Current = function() {
503
+ return this.viewPorts[this.viewPorts.length - 1];
504
+ };
505
+ this.width = function() {
506
+ return this.Current().width;
507
+ };
508
+ this.height = function() {
509
+ return this.Current().height;
510
+ };
511
+ this.ComputeSize = function(d) {
512
+ if (d != null && typeof d == "number") return d;
513
+ if (d == "x") return this.width();
514
+ if (d == "y") return this.height();
515
+ return Math.sqrt(Math.pow(this.width(), 2) + Math.pow(this.height(), 2)) / Math.sqrt(2);
516
+ };
517
+ }();
518
+ };
519
+ svg.init();
520
+ svg.ImagesLoaded = function() {
521
+ for (let i2 = 0; i2 < svg.Images.length; i2++) {
522
+ if (!svg.Images[i2].loaded) return false;
523
+ }
524
+ return true;
525
+ };
526
+ svg.trim = function(s) {
527
+ return s.replace(/^\s+|\s+$/g, "");
528
+ };
529
+ svg.compressSpaces = function(s) {
530
+ return s.replace(/[\s\r\t\n]+/gm, " ");
531
+ };
532
+ svg.ajax = function(url) {
533
+ let AJAX;
534
+ if (window.XMLHttpRequest) {
535
+ AJAX = new XMLHttpRequest();
536
+ } else {
537
+ AJAX = new ActiveXObject("Microsoft.XMLHTTP");
538
+ }
539
+ if (AJAX) {
540
+ AJAX.open("GET", url, false);
541
+ AJAX.send(null);
542
+ return AJAX.responseText;
543
+ }
544
+ return null;
545
+ };
546
+ svg.parseXml = function(xml) {
547
+ if (window.DOMParser) {
548
+ let parser = new DOMParser();
549
+ return parser.parseFromString(xml, "text/xml");
550
+ } else {
551
+ xml = xml.replace(/<!DOCTYPE svg[^>]*>/, "");
552
+ let xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
553
+ xmlDoc.async = "false";
554
+ xmlDoc.loadXML(xml);
555
+ return xmlDoc;
556
+ }
557
+ };
558
+ svg.Property = function(name, value) {
559
+ this.name = name;
560
+ this.value = value;
561
+ };
562
+ svg.Property.prototype.getValue = function() {
563
+ return this.value;
564
+ };
565
+ svg.Property.prototype.hasValue = function() {
566
+ return this.value != null && this.value !== "";
567
+ };
568
+ svg.Property.prototype.numValue = function() {
569
+ if (!this.hasValue()) return 0;
570
+ let n = parseFloat(this.value);
571
+ if ((this.value + "").match(/%$/)) {
572
+ n = n / 100;
573
+ }
574
+ return n;
575
+ };
576
+ svg.Property.prototype.valueOrDefault = function(def) {
577
+ if (this.hasValue()) return this.value;
578
+ return def;
579
+ };
580
+ svg.Property.prototype.numValueOrDefault = function(def) {
581
+ if (this.hasValue()) return this.numValue();
582
+ return def;
583
+ };
584
+ svg.Property.prototype.addOpacity = function(opacity) {
585
+ let newValue = this.value;
586
+ if (opacity != null && opacity != "" && typeof this.value == "string") {
587
+ let color = new RGBColor(this.value);
588
+ if (color.ok) {
589
+ newValue = "rgba(" + color.r + ", " + color.g + ", " + color.b + ", " + opacity + ")";
590
+ }
591
+ }
592
+ return new svg.Property(this.name, newValue);
593
+ };
594
+ svg.Property.prototype.getDefinition = function() {
595
+ let name = this.value.match(/#([^\)'"]+)/);
596
+ if (name) {
597
+ name = name[1];
598
+ }
599
+ if (!name) {
600
+ name = this.value;
601
+ }
602
+ return svg.Definitions[name];
603
+ };
604
+ svg.Property.prototype.isUrlDefinition = function() {
605
+ return this.value.indexOf("url(") == 0;
606
+ };
607
+ svg.Property.prototype.getFillStyleDefinition = function(e, opacityProp) {
608
+ let def = this.getDefinition();
609
+ if (def != null && def.createGradient) {
610
+ return def.createGradient(svg.ctx, e, opacityProp);
611
+ }
612
+ if (def != null && def.createPattern) {
613
+ if (def.getHrefAttribute().hasValue()) {
614
+ let pt = def.attribute("patternTransform");
615
+ def = def.getHrefAttribute().getDefinition();
616
+ if (pt.hasValue()) {
617
+ def.attribute("patternTransform", true).value = pt.value;
618
+ }
619
+ }
620
+ return def.createPattern(svg.ctx, e);
621
+ }
622
+ return null;
623
+ };
624
+ svg.Property.prototype.getDPI = function() {
625
+ return 96;
626
+ };
627
+ svg.Property.prototype.getEM = function(viewPort) {
628
+ let em = 12;
629
+ let fontSize = new svg.Property("fontSize", svg.Font.Parse(svg.ctx.font).fontSize);
630
+ if (fontSize.hasValue()) em = fontSize.toPixels(viewPort);
631
+ return em;
632
+ };
633
+ svg.Property.prototype.getUnits = function() {
634
+ let s = this.value + "";
635
+ return s.replace(/[0-9\.\-]/g, "");
636
+ };
637
+ svg.Property.prototype.toPixels = function(viewPort, processPercent) {
638
+ if (!this.hasValue()) return 0;
639
+ let s = this.value + "";
640
+ if (s.match(/em$/)) return this.numValue() * this.getEM(viewPort);
641
+ if (s.match(/ex$/)) return this.numValue() * this.getEM(viewPort) / 2;
642
+ if (s.match(/px$/)) return this.numValue();
643
+ if (s.match(/pt$/)) return this.numValue() * this.getDPI(viewPort) * (1 / 72);
644
+ if (s.match(/pc$/)) return this.numValue() * 15;
645
+ if (s.match(/cm$/)) return this.numValue() * this.getDPI(viewPort) / 2.54;
646
+ if (s.match(/mm$/)) return this.numValue() * this.getDPI(viewPort) / 25.4;
647
+ if (s.match(/in$/)) return this.numValue() * this.getDPI(viewPort);
648
+ if (s.match(/%$/)) return this.numValue() * svg.ViewPort.ComputeSize(viewPort);
649
+ let n = this.numValue();
650
+ if (processPercent && n < 1) return n * svg.ViewPort.ComputeSize(viewPort);
651
+ return n;
652
+ };
653
+ svg.Property.prototype.toMilliseconds = function() {
654
+ if (!this.hasValue()) return 0;
655
+ let s = this.value + "";
656
+ if (s.match(/s$/)) return this.numValue() * 1e3;
657
+ if (s.match(/ms$/)) return this.numValue();
658
+ return this.numValue();
659
+ };
660
+ svg.Property.prototype.toRadians = function() {
661
+ if (!this.hasValue()) return 0;
662
+ let s = this.value + "";
663
+ if (s.match(/deg$/)) return this.numValue() * (Math.PI / 180);
664
+ if (s.match(/grad$/)) return this.numValue() * (Math.PI / 200);
665
+ if (s.match(/rad$/)) return this.numValue();
666
+ return this.numValue() * (Math.PI / 180);
667
+ };
668
+ svg.Font = new function() {
669
+ this.Styles = "normal|italic|oblique|inherit";
670
+ this.Variants = "normal|small-caps|inherit";
671
+ this.Weights = "normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900|inherit";
672
+ this.CreateFont = function(fontStyle, fontVariant, fontWeight, fontSize, fontFamily, inherit) {
673
+ let f = inherit != null ? this.Parse(inherit) : this.CreateFont("", "", "", "", "", svg.ctx.font);
674
+ return {
675
+ fontFamily: fontFamily || f.fontFamily,
676
+ fontSize: fontSize || f.fontSize,
677
+ fontStyle: fontStyle || f.fontStyle,
678
+ fontWeight: fontWeight || f.fontWeight,
679
+ fontVariant: fontVariant || f.fontVariant,
680
+ toString: function() {
681
+ return [this.fontStyle, this.fontVariant, this.fontWeight, this.fontSize, this.fontFamily].join(" ");
682
+ }
683
+ };
684
+ };
685
+ let that = this;
686
+ this.Parse = function(s) {
687
+ let f = {};
688
+ let d = svg.trim(svg.compressSpaces(s || "")).split(" ");
689
+ let set = {
690
+ fontSize: false,
691
+ fontStyle: false,
692
+ fontWeight: false,
693
+ fontVariant: false
694
+ };
695
+ let ff = "";
696
+ for (let i2 = 0; i2 < d.length; i2++) {
697
+ if (!set.fontStyle && that.Styles.indexOf(d[i2]) != -1) {
698
+ if (d[i2] != "inherit") f.fontStyle = d[i2];
699
+ set.fontStyle = true;
700
+ } else if (!set.fontVariant && that.Variants.indexOf(d[i2]) != -1) {
701
+ if (d[i2] != "inherit") f.fontVariant = d[i2];
702
+ set.fontStyle = set.fontVariant = true;
703
+ } else if (!set.fontWeight && that.Weights.indexOf(d[i2]) != -1) {
704
+ if (d[i2] != "inherit") f.fontWeight = d[i2];
705
+ set.fontStyle = set.fontVariant = set.fontWeight = true;
706
+ } else if (!set.fontSize) {
707
+ if (d[i2] != "inherit") f.fontSize = d[i2].split("/")[0];
708
+ set.fontStyle = set.fontVariant = set.fontWeight = set.fontSize = true;
709
+ } else {
710
+ if (d[i2] != "inherit") ff += d[i2];
711
+ }
712
+ }
713
+ if (ff != "") f.fontFamily = ff;
714
+ return f;
715
+ };
716
+ }();
717
+ svg.ToNumberArray = function(s) {
718
+ let a = svg.trim(svg.compressSpaces((s || "").replace(/,/g, " "))).split(" ");
719
+ for (let i2 = 0; i2 < a.length; i2++) {
720
+ a[i2] = parseFloat(a[i2]);
721
+ }
722
+ return a;
723
+ };
724
+ svg.Point = function(x, y) {
725
+ this.x = x;
726
+ this.y = y;
727
+ };
728
+ svg.Point.prototype.angleTo = function(p) {
729
+ return Math.atan2(p.y - this.y, p.x - this.x);
730
+ };
731
+ svg.Point.prototype.applyTransform = function(v) {
732
+ let xp = this.x * v[0] + this.y * v[2] + v[4];
733
+ let yp = this.x * v[1] + this.y * v[3] + v[5];
734
+ this.x = xp;
735
+ this.y = yp;
736
+ };
737
+ svg.CreatePoint = function(s) {
738
+ let a = svg.ToNumberArray(s);
739
+ return new svg.Point(a[0], a[1]);
740
+ };
741
+ svg.CreatePath = function(s) {
742
+ let a = svg.ToNumberArray(s);
743
+ let path = [];
744
+ for (let i2 = 0; i2 < a.length; i2 += 2) {
745
+ path.push(new svg.Point(a[i2], a[i2 + 1]));
746
+ }
747
+ return path;
748
+ };
749
+ svg.BoundingBox = function(x1, y1, x2, y2) {
750
+ this.x1 = Number.NaN;
751
+ this.y1 = Number.NaN;
752
+ this.x2 = Number.NaN;
753
+ this.y2 = Number.NaN;
754
+ this.x = function() {
755
+ return this.x1;
756
+ };
757
+ this.y = function() {
758
+ return this.y1;
759
+ };
760
+ this.width = function() {
761
+ return this.x2 - this.x1;
762
+ };
763
+ this.height = function() {
764
+ return this.y2 - this.y1;
765
+ };
766
+ this.addPoint = function(x, y) {
767
+ if (x != null) {
768
+ if (isNaN(this.x1) || isNaN(this.x2)) {
769
+ this.x1 = x;
770
+ this.x2 = x;
771
+ }
772
+ if (x < this.x1) this.x1 = x;
773
+ if (x > this.x2) this.x2 = x;
774
+ }
775
+ if (y != null) {
776
+ if (isNaN(this.y1) || isNaN(this.y2)) {
777
+ this.y1 = y;
778
+ this.y2 = y;
779
+ }
780
+ if (y < this.y1) this.y1 = y;
781
+ if (y > this.y2) this.y2 = y;
782
+ }
783
+ };
784
+ this.addX = function(x) {
785
+ this.addPoint(x, null);
786
+ };
787
+ this.addY = function(y) {
788
+ this.addPoint(null, y);
789
+ };
790
+ this.addBoundingBox = function(bb) {
791
+ this.addPoint(bb.x1, bb.y1);
792
+ this.addPoint(bb.x2, bb.y2);
793
+ };
794
+ this.addQuadraticCurve = function(p0x, p0y, p1x, p1y, p2x, p2y) {
795
+ let cp1x = p0x + 2 / 3 * (p1x - p0x);
796
+ let cp1y = p0y + 2 / 3 * (p1y - p0y);
797
+ let cp2x = cp1x + 1 / 3 * (p2x - p0x);
798
+ let cp2y = cp1y + 1 / 3 * (p2y - p0y);
799
+ this.addBezierCurve(p0x, p0y, cp1x, cp2x, cp1y, cp2y, p2x, p2y);
800
+ };
801
+ this.addBezierCurve = function(p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y) {
802
+ let p0 = [p0x, p0y], p1 = [p1x, p1y], p2 = [p2x, p2y], p3 = [p3x, p3y];
803
+ this.addPoint(p0[0], p0[1]);
804
+ this.addPoint(p3[0], p3[1]);
805
+ for (i = 0; i <= 1; i++) {
806
+ let f = function(t) {
807
+ return Math.pow(1 - t, 3) * p0[i] + 3 * Math.pow(1 - t, 2) * t * p1[i] + 3 * (1 - t) * Math.pow(t, 2) * p2[i] + Math.pow(t, 3) * p3[i];
808
+ };
809
+ let b = 6 * p0[i] - 12 * p1[i] + 6 * p2[i];
810
+ let a = -3 * p0[i] + 9 * p1[i] - 9 * p2[i] + 3 * p3[i];
811
+ let c = 3 * p1[i] - 3 * p0[i];
812
+ if (a == 0) {
813
+ if (b == 0) continue;
814
+ let t = -c / b;
815
+ if (0 < t && t < 1) {
816
+ if (i == 0) this.addX(f(t));
817
+ if (i == 1) this.addY(f(t));
818
+ }
819
+ continue;
820
+ }
821
+ let b2ac = Math.pow(b, 2) - 4 * c * a;
822
+ if (b2ac < 0) continue;
823
+ let t1 = (-b + Math.sqrt(b2ac)) / (2 * a);
824
+ if (0 < t1 && t1 < 1) {
825
+ if (i == 0) this.addX(f(t1));
826
+ if (i == 1) this.addY(f(t1));
827
+ }
828
+ let t2 = (-b - Math.sqrt(b2ac)) / (2 * a);
829
+ if (0 < t2 && t2 < 1) {
830
+ if (i == 0) this.addX(f(t2));
831
+ if (i == 1) this.addY(f(t2));
832
+ }
833
+ }
834
+ };
835
+ this.isPointInBox = function(x, y) {
836
+ return this.x1 <= x && x <= this.x2 && this.y1 <= y && y <= this.y2;
837
+ };
838
+ this.addPoint(x1, y1);
839
+ this.addPoint(x2, y2);
840
+ };
841
+ svg.Transform = function(v) {
842
+ let that = this;
843
+ this.Type = {};
844
+ this.Type.translate = function(s) {
845
+ this.p = svg.CreatePoint(s);
846
+ this.apply = function(ctx2) {
847
+ ctx2.translate(this.p.x || 0, this.p.y || 0);
848
+ };
849
+ this.unapply = function(ctx2) {
850
+ ctx2.translate(-1 * this.p.x || 0, -1 * this.p.y || 0);
851
+ };
852
+ this.applyToPoint = function(p) {
853
+ p.applyTransform([1, 0, 0, 1, this.p.x || 0, this.p.y || 0]);
854
+ };
855
+ };
856
+ this.Type.rotate = function(s) {
857
+ let a = svg.ToNumberArray(s);
858
+ this.angle = new svg.Property("angle", a[0]);
859
+ this.cx = a[1] || 0;
860
+ this.cy = a[2] || 0;
861
+ this.apply = function(ctx2) {
862
+ ctx2.translate(this.cx, this.cy);
863
+ ctx2.rotate(this.angle.toRadians());
864
+ ctx2.translate(-this.cx, -this.cy);
865
+ };
866
+ this.unapply = function(ctx2) {
867
+ ctx2.translate(this.cx, this.cy);
868
+ ctx2.rotate(-1 * this.angle.toRadians());
869
+ ctx2.translate(-this.cx, -this.cy);
870
+ };
871
+ this.applyToPoint = function(p) {
872
+ let a2 = this.angle.toRadians();
873
+ p.applyTransform([1, 0, 0, 1, this.p.x || 0, this.p.y || 0]);
874
+ p.applyTransform([Math.cos(a2), Math.sin(a2), -Math.sin(a2), Math.cos(a2), 0, 0]);
875
+ p.applyTransform([1, 0, 0, 1, -this.p.x || 0, -this.p.y || 0]);
876
+ };
877
+ };
878
+ this.Type.scale = function(s) {
879
+ this.p = svg.CreatePoint(s);
880
+ this.apply = function(ctx2) {
881
+ ctx2.scale(this.p.x || 1, this.p.y || this.p.x || 1);
882
+ };
883
+ this.unapply = function(ctx2) {
884
+ ctx2.scale(1 / this.p.x || 1, 1 / this.p.y || this.p.x || 1);
885
+ };
886
+ this.applyToPoint = function(p) {
887
+ p.applyTransform([this.p.x || 0, 0, 0, this.p.y || 0, 0, 0]);
888
+ };
889
+ };
890
+ this.Type.matrix = function(s) {
891
+ this.m = svg.ToNumberArray(s);
892
+ this.apply = function(ctx2) {
893
+ ctx2.transform(this.m[0], this.m[1], this.m[2], this.m[3], this.m[4], this.m[5]);
894
+ };
895
+ this.applyToPoint = function(p) {
896
+ p.applyTransform(this.m);
897
+ };
898
+ };
899
+ this.Type.SkewBase = function(s) {
900
+ this.base = that.Type.matrix;
901
+ this.base(s);
902
+ this.angle = new svg.Property("angle", s);
903
+ };
904
+ this.Type.SkewBase.prototype = new this.Type.matrix();
905
+ this.Type.skewX = function(s) {
906
+ this.base = that.Type.SkewBase;
907
+ this.base(s);
908
+ this.m = [1, 0, Math.tan(this.angle.toRadians()), 1, 0, 0];
909
+ };
910
+ this.Type.skewX.prototype = new this.Type.SkewBase();
911
+ this.Type.skewY = function(s) {
912
+ this.base = that.Type.SkewBase;
913
+ this.base(s);
914
+ this.m = [1, Math.tan(this.angle.toRadians()), 0, 1, 0, 0];
915
+ };
916
+ this.Type.skewY.prototype = new this.Type.SkewBase();
917
+ this.transforms = [];
918
+ this.apply = function(ctx2) {
919
+ for (let i2 = 0; i2 < this.transforms.length; i2++) {
920
+ this.transforms[i2].apply(ctx2);
921
+ }
922
+ };
923
+ this.unapply = function(ctx2) {
924
+ for (let i2 = this.transforms.length - 1; i2 >= 0; i2--) {
925
+ this.transforms[i2].unapply(ctx2);
926
+ }
927
+ };
928
+ this.applyToPoint = function(p) {
929
+ for (let i2 = 0; i2 < this.transforms.length; i2++) {
930
+ this.transforms[i2].applyToPoint(p);
931
+ }
932
+ };
933
+ let data = svg.trim(svg.compressSpaces(v)).replace(/\)(\s?,\s?)/g, ") ").split(/\s(?=[a-z])/);
934
+ for (let i2 = 0; i2 < data.length; i2++) {
935
+ let type = svg.trim(data[i2].split("(")[0]);
936
+ let s = data[i2].split("(")[1].replace(")", "");
937
+ let transform = new this.Type[type](s);
938
+ transform.type = type;
939
+ this.transforms.push(transform);
940
+ }
941
+ };
942
+ svg.AspectRatio = function(ctx2, aspectRatio, width2, desiredWidth, height2, desiredHeight, minX, minY, refX, refY) {
943
+ aspectRatio = svg.compressSpaces(aspectRatio);
944
+ aspectRatio = aspectRatio.replace(/^defer\s/, "");
945
+ let align = aspectRatio.split(" ")[0] || "xMidYMid";
946
+ let meetOrSlice = aspectRatio.split(" ")[1] || "meet";
947
+ let scaleX = width2 / desiredWidth;
948
+ let scaleY = height2 / desiredHeight;
949
+ let scaleMin = Math.min(scaleX, scaleY);
950
+ let scaleMax = Math.max(scaleX, scaleY);
951
+ if (meetOrSlice == "meet") {
952
+ desiredWidth *= scaleMin;
953
+ desiredHeight *= scaleMin;
954
+ }
955
+ if (meetOrSlice == "slice") {
956
+ desiredWidth *= scaleMax;
957
+ desiredHeight *= scaleMax;
958
+ }
959
+ refX = new svg.Property("refX", refX);
960
+ refY = new svg.Property("refY", refY);
961
+ if (refX.hasValue() && refY.hasValue()) {
962
+ ctx2.translate(-scaleMin * refX.toPixels("x"), -scaleMin * refY.toPixels("y"));
963
+ } else {
964
+ if (align.match(/^xMid/) && (meetOrSlice == "meet" && scaleMin == scaleY || meetOrSlice == "slice" && scaleMax == scaleY)) ctx2.translate(width2 / 2 - desiredWidth / 2, 0);
965
+ if (align.match(/YMid$/) && (meetOrSlice == "meet" && scaleMin == scaleX || meetOrSlice == "slice" && scaleMax == scaleX)) ctx2.translate(0, height2 / 2 - desiredHeight / 2);
966
+ if (align.match(/^xMax/) && (meetOrSlice == "meet" && scaleMin == scaleY || meetOrSlice == "slice" && scaleMax == scaleY)) ctx2.translate(width2 - desiredWidth, 0);
967
+ if (align.match(/YMax$/) && (meetOrSlice == "meet" && scaleMin == scaleX || meetOrSlice == "slice" && scaleMax == scaleX)) ctx2.translate(0, height2 - desiredHeight);
968
+ }
969
+ if (align == "none") ctx2.scale(scaleX, scaleY);
970
+ else if (meetOrSlice == "meet") ctx2.scale(scaleMin, scaleMin);
971
+ else if (meetOrSlice == "slice") ctx2.scale(scaleMax, scaleMax);
972
+ ctx2.translate(minX == null ? 0 : -minX, minY == null ? 0 : -minY);
973
+ };
974
+ svg.Element = {};
975
+ svg.EmptyProperty = new svg.Property("EMPTY", "");
976
+ svg.Element.ElementBase = function(node) {
977
+ this.attributes = {};
978
+ this.styles = {};
979
+ this.children = [];
980
+ this.attribute = function(name, createIfNotExists) {
981
+ let a = this.attributes[name];
982
+ if (a != null) return a;
983
+ if (createIfNotExists == true) {
984
+ a = new svg.Property(name, "");
985
+ this.attributes[name] = a;
986
+ }
987
+ return a || svg.EmptyProperty;
988
+ };
989
+ this.getHrefAttribute = function() {
990
+ for (let a in this.attributes) {
991
+ if (a.match(/:href$/)) {
992
+ return this.attributes[a];
993
+ }
994
+ }
995
+ return svg.EmptyProperty;
996
+ };
997
+ this.style = function(name, createIfNotExists) {
998
+ let s = this.styles[name];
999
+ if (s != null) return s;
1000
+ let a = this.attribute(name);
1001
+ if (a != null && a.hasValue()) {
1002
+ this.styles[name] = a;
1003
+ return a;
1004
+ }
1005
+ let p = this.parent;
1006
+ if (p != null) {
1007
+ let ps = p.style(name);
1008
+ if (ps != null && ps.hasValue()) {
1009
+ return ps;
1010
+ }
1011
+ }
1012
+ if (createIfNotExists == true) {
1013
+ s = new svg.Property(name, "");
1014
+ this.styles[name] = s;
1015
+ }
1016
+ return s || svg.EmptyProperty;
1017
+ };
1018
+ this.render = function(ctx2) {
1019
+ if (this.style("display").value == "none") return;
1020
+ if (this.attribute("visibility").value == "hidden") return;
1021
+ ctx2.save();
1022
+ if (this.attribute("mask").hasValue()) {
1023
+ let mask = this.attribute("mask").getDefinition();
1024
+ if (mask != null) mask.apply(ctx2, this);
1025
+ } else if (this.style("filter").hasValue()) {
1026
+ let filter = this.style("filter").getDefinition();
1027
+ if (filter != null) filter.apply(ctx2, this);
1028
+ } else {
1029
+ this.setContext(ctx2);
1030
+ this.renderChildren(ctx2);
1031
+ this.clearContext(ctx2);
1032
+ }
1033
+ ctx2.restore();
1034
+ };
1035
+ this.setContext = function(_ctx) {
1036
+ };
1037
+ this.clearContext = function(_ctx) {
1038
+ };
1039
+ this.renderChildren = function(ctx2) {
1040
+ for (let i2 = 0; i2 < this.children.length; i2++) {
1041
+ this.children[i2].render(ctx2);
1042
+ }
1043
+ };
1044
+ this.addChild = function(childNode, create) {
1045
+ let child = childNode;
1046
+ if (create) child = svg.CreateElement(childNode);
1047
+ child.parent = this;
1048
+ this.children.push(child);
1049
+ };
1050
+ if (node != null && node.nodeType == 1) {
1051
+ for (let i2 = 0; i2 < node.childNodes.length; i2++) {
1052
+ let childNode = node.childNodes[i2];
1053
+ if (childNode.nodeType == 1) this.addChild(childNode, true);
1054
+ if (this.captureTextNodes && childNode.nodeType == 3) {
1055
+ let text = childNode.nodeValue || childNode.text || "";
1056
+ if (svg.trim(svg.compressSpaces(text)) != "") {
1057
+ this.addChild(new svg.Element.tspan(childNode), false);
1058
+ }
1059
+ }
1060
+ }
1061
+ for (let i2 = 0; i2 < node.attributes.length; i2++) {
1062
+ let attribute = node.attributes[i2];
1063
+ this.attributes[attribute.nodeName] = new svg.Property(attribute.nodeName, attribute.nodeValue);
1064
+ }
1065
+ let styles = svg.Styles[node.nodeName];
1066
+ if (styles != null) {
1067
+ for (let name in styles) {
1068
+ this.styles[name] = styles[name];
1069
+ }
1070
+ }
1071
+ if (this.attribute("class").hasValue()) {
1072
+ let classes = svg.compressSpaces(this.attribute("class").value).split(" ");
1073
+ for (let j = 0; j < classes.length; j++) {
1074
+ styles = svg.Styles["." + classes[j]];
1075
+ if (styles != null) {
1076
+ for (let name in styles) {
1077
+ this.styles[name] = styles[name];
1078
+ }
1079
+ }
1080
+ styles = svg.Styles[node.nodeName + "." + classes[j]];
1081
+ if (styles != null) {
1082
+ for (let name in styles) {
1083
+ this.styles[name] = styles[name];
1084
+ }
1085
+ }
1086
+ }
1087
+ }
1088
+ if (this.attribute("id").hasValue()) {
1089
+ let styles2 = svg.Styles["#" + this.attribute("id").value];
1090
+ if (styles2 != null) {
1091
+ for (let name in styles2) {
1092
+ this.styles[name] = styles2[name];
1093
+ }
1094
+ }
1095
+ }
1096
+ if (this.attribute("style").hasValue()) {
1097
+ let styles2 = this.attribute("style").value.split(";");
1098
+ for (let i2 = 0; i2 < styles2.length; i2++) {
1099
+ if (svg.trim(styles2[i2]) != "") {
1100
+ let style = styles2[i2].split(":");
1101
+ let name = svg.trim(style[0]);
1102
+ let value = svg.trim(style[1]);
1103
+ this.styles[name] = new svg.Property(name, value);
1104
+ }
1105
+ }
1106
+ }
1107
+ if (this.attribute("id").hasValue()) {
1108
+ if (svg.Definitions[this.attribute("id").value] == null) {
1109
+ svg.Definitions[this.attribute("id").value] = this;
1110
+ }
1111
+ }
1112
+ }
1113
+ };
1114
+ svg.Element.RenderedElementBase = function(node) {
1115
+ this.base = svg.Element.ElementBase;
1116
+ this.base(node);
1117
+ this.setContext = function(ctx2) {
1118
+ if (this.style("fill").isUrlDefinition()) {
1119
+ let fs = this.style("fill").getFillStyleDefinition(this, this.style("fill-opacity"));
1120
+ if (fs != null) ctx2.fillStyle = fs;
1121
+ } else if (this.style("fill").hasValue()) {
1122
+ let fillStyle = this.style("fill");
1123
+ if (fillStyle.value == "currentColor") fillStyle.value = this.style("color").value;
1124
+ ctx2.fillStyle = fillStyle.value == "none" ? "rgba(0,0,0,0)" : fillStyle.value;
1125
+ }
1126
+ if (this.style("fill-opacity").hasValue()) {
1127
+ let fillStyle = new svg.Property("fill", ctx2.fillStyle);
1128
+ fillStyle = fillStyle.addOpacity(this.style("fill-opacity").value);
1129
+ ctx2.fillStyle = fillStyle.value;
1130
+ }
1131
+ if (this.style("stroke").isUrlDefinition()) {
1132
+ let fs = this.style("stroke").getFillStyleDefinition(this, this.style("stroke-opacity"));
1133
+ if (fs != null) ctx2.strokeStyle = fs;
1134
+ } else if (this.style("stroke").hasValue()) {
1135
+ let strokeStyle = this.style("stroke");
1136
+ if (strokeStyle.value == "currentColor") strokeStyle.value = this.style("color").value;
1137
+ ctx2.strokeStyle = strokeStyle.value == "none" ? "rgba(0,0,0,0)" : strokeStyle.value;
1138
+ }
1139
+ if (this.style("stroke-opacity").hasValue()) {
1140
+ let strokeStyle = new svg.Property("stroke", ctx2.strokeStyle);
1141
+ strokeStyle = strokeStyle.addOpacity(this.style("stroke-opacity").value);
1142
+ ctx2.strokeStyle = strokeStyle.value;
1143
+ }
1144
+ if (this.style("stroke-width").hasValue()) {
1145
+ let newLineWidth = this.style("stroke-width").toPixels();
1146
+ ctx2.lineWidth = newLineWidth == 0 ? 1e-3 : newLineWidth;
1147
+ }
1148
+ if (this.style("stroke-linecap").hasValue()) ctx2.lineCap = this.style("stroke-linecap").value;
1149
+ if (this.style("stroke-linejoin").hasValue()) ctx2.lineJoin = this.style("stroke-linejoin").value;
1150
+ if (this.style("stroke-miterlimit").hasValue()) ctx2.miterLimit = this.style("stroke-miterlimit").value;
1151
+ if (this.style("stroke-dasharray").hasValue()) {
1152
+ let gaps = svg.ToNumberArray(this.style("stroke-dasharray").value);
1153
+ if (typeof ctx2.setLineDash != "undefined") {
1154
+ ctx2.setLineDash(gaps);
1155
+ } else if (typeof ctx2.webkitLineDash != "undefined") {
1156
+ ctx2.webkitLineDash = gaps;
1157
+ } else if (typeof ctx2.mozDash != "undefined") {
1158
+ ctx2.mozDash = gaps;
1159
+ }
1160
+ let offset = this.style("stroke-dashoffset").numValueOrDefault(1);
1161
+ if (typeof ctx2.lineDashOffset != "undefined") {
1162
+ ctx2.lineDashOffset = offset;
1163
+ } else if (typeof ctx2.webkitLineDashOffset != "undefined") {
1164
+ ctx2.webkitLineDashOffset = offset;
1165
+ } else if (typeof ctx2.mozDashOffset != "undefined") {
1166
+ ctx2.mozDashOffset = offset;
1167
+ }
1168
+ }
1169
+ if (typeof ctx2.font != "undefined") {
1170
+ ctx2.font = svg.Font.CreateFont(this.style("font-style").value, this.style("font-variant").value, this.style("font-weight").value, this.style("font-size").hasValue() ? this.style("font-size").toPixels() + "px" : "", this.style("font-family").value).toString();
1171
+ }
1172
+ if (this.attribute("transform").hasValue()) {
1173
+ let transform = new svg.Transform(this.attribute("transform").value);
1174
+ transform.apply(ctx2);
1175
+ }
1176
+ if (this.style("clip-path").hasValue()) {
1177
+ let clip = this.style("clip-path").getDefinition();
1178
+ if (clip != null) clip.apply(ctx2);
1179
+ }
1180
+ if (this.style("opacity").hasValue()) {
1181
+ ctx2.globalAlpha = this.style("opacity").numValue();
1182
+ }
1183
+ };
1184
+ };
1185
+ svg.Element.RenderedElementBase.prototype = new svg.Element.ElementBase();
1186
+ svg.Element.PathElementBase = function(node) {
1187
+ this.base = svg.Element.RenderedElementBase;
1188
+ this.base(node);
1189
+ this.path = function(ctx2) {
1190
+ if (ctx2 != null) ctx2.beginPath();
1191
+ return new svg.BoundingBox();
1192
+ };
1193
+ this.renderChildren = function(ctx2) {
1194
+ this.path(ctx2);
1195
+ svg.Mouse.checkPath(this, ctx2);
1196
+ if (ctx2.fillStyle != "") {
1197
+ if (this.attribute("fill-rule").hasValue()) {
1198
+ ctx2.fill(this.attribute("fill-rule").value);
1199
+ } else {
1200
+ ctx2.fill();
1201
+ }
1202
+ }
1203
+ if (ctx2.strokeStyle != "") ctx2.stroke();
1204
+ let markers = this.getMarkers();
1205
+ if (markers != null) {
1206
+ if (this.style("marker-start").isUrlDefinition()) {
1207
+ let marker = this.style("marker-start").getDefinition();
1208
+ marker.render(ctx2, markers[0][0], markers[0][1]);
1209
+ }
1210
+ if (this.style("marker-mid").isUrlDefinition()) {
1211
+ let marker = this.style("marker-mid").getDefinition();
1212
+ for (let i2 = 1; i2 < markers.length - 1; i2++) {
1213
+ marker.render(ctx2, markers[i2][0], markers[i2][1]);
1214
+ }
1215
+ }
1216
+ if (this.style("marker-end").isUrlDefinition()) {
1217
+ let marker = this.style("marker-end").getDefinition();
1218
+ marker.render(ctx2, markers[markers.length - 1][0], markers[markers.length - 1][1]);
1219
+ }
1220
+ }
1221
+ };
1222
+ this.getBoundingBox = function() {
1223
+ return this.path();
1224
+ };
1225
+ this.getMarkers = function() {
1226
+ return null;
1227
+ };
1228
+ };
1229
+ svg.Element.PathElementBase.prototype = new svg.Element.RenderedElementBase();
1230
+ svg.Element.svg = function(node) {
1231
+ this.base = svg.Element.RenderedElementBase;
1232
+ this.base(node);
1233
+ this.baseClearContext = this.clearContext;
1234
+ this.clearContext = function(ctx2) {
1235
+ this.baseClearContext(ctx2);
1236
+ svg.ViewPort.RemoveCurrent();
1237
+ };
1238
+ this.baseSetContext = this.setContext;
1239
+ this.setContext = function(ctx2) {
1240
+ ctx2.strokeStyle = "rgba(0,0,0,0)";
1241
+ ctx2.lineCap = "butt";
1242
+ ctx2.lineJoin = "miter";
1243
+ ctx2.miterLimit = 4;
1244
+ this.baseSetContext(ctx2);
1245
+ if (!this.attribute("x").hasValue()) this.attribute("x", true).value = 0;
1246
+ if (!this.attribute("y").hasValue()) this.attribute("y", true).value = 0;
1247
+ ctx2.translate(this.attribute("x").toPixels("x"), this.attribute("y").toPixels("y"));
1248
+ let width2 = svg.ViewPort.width();
1249
+ let height2 = svg.ViewPort.height();
1250
+ if (!this.attribute("width").hasValue()) this.attribute("width", true).value = "100%";
1251
+ if (!this.attribute("height").hasValue()) this.attribute("height", true).value = "100%";
1252
+ if (typeof this.root == "undefined") {
1253
+ width2 = this.attribute("width").toPixels("x");
1254
+ height2 = this.attribute("height").toPixels("y");
1255
+ let x = 0;
1256
+ let y = 0;
1257
+ if (this.attribute("refX").hasValue() && this.attribute("refY").hasValue()) {
1258
+ x = -this.attribute("refX").toPixels("x");
1259
+ y = -this.attribute("refY").toPixels("y");
1260
+ }
1261
+ ctx2.beginPath();
1262
+ ctx2.moveTo(x, y);
1263
+ ctx2.lineTo(width2, y);
1264
+ ctx2.lineTo(width2, height2);
1265
+ ctx2.lineTo(x, height2);
1266
+ ctx2.closePath();
1267
+ ctx2.clip();
1268
+ }
1269
+ svg.ViewPort.SetCurrent(width2, height2);
1270
+ if (this.attribute("viewBox").hasValue()) {
1271
+ let viewBox = svg.ToNumberArray(this.attribute("viewBox").value);
1272
+ let minX = viewBox[0];
1273
+ let minY = viewBox[1];
1274
+ width2 = viewBox[2];
1275
+ height2 = viewBox[3];
1276
+ svg.AspectRatio(ctx2, this.attribute("preserveAspectRatio").value, svg.ViewPort.width(), width2, svg.ViewPort.height(), height2, minX, minY, this.attribute("refX").value, this.attribute("refY").value);
1277
+ svg.ViewPort.RemoveCurrent();
1278
+ svg.ViewPort.SetCurrent(viewBox[2], viewBox[3]);
1279
+ }
1280
+ };
1281
+ };
1282
+ svg.Element.svg.prototype = new svg.Element.RenderedElementBase();
1283
+ svg.Element.rect = function(node) {
1284
+ this.base = svg.Element.PathElementBase;
1285
+ this.base(node);
1286
+ this.path = function(ctx2) {
1287
+ let x = this.attribute("x").toPixels("x");
1288
+ let y = this.attribute("y").toPixels("y");
1289
+ let width2 = this.attribute("width").toPixels("x");
1290
+ let height2 = this.attribute("height").toPixels("y");
1291
+ let rx = this.attribute("rx").toPixels("x");
1292
+ let ry = this.attribute("ry").toPixels("y");
1293
+ if (this.attribute("rx").hasValue() && !this.attribute("ry").hasValue()) ry = rx;
1294
+ if (this.attribute("ry").hasValue() && !this.attribute("rx").hasValue()) rx = ry;
1295
+ rx = Math.min(rx, width2 / 2);
1296
+ ry = Math.min(ry, height2 / 2);
1297
+ if (ctx2 != null) {
1298
+ ctx2.beginPath();
1299
+ ctx2.moveTo(x + rx, y);
1300
+ ctx2.lineTo(x + width2 - rx, y);
1301
+ ctx2.quadraticCurveTo(x + width2, y, x + width2, y + ry);
1302
+ ctx2.lineTo(x + width2, y + height2 - ry);
1303
+ ctx2.quadraticCurveTo(x + width2, y + height2, x + width2 - rx, y + height2);
1304
+ ctx2.lineTo(x + rx, y + height2);
1305
+ ctx2.quadraticCurveTo(x, y + height2, x, y + height2 - ry);
1306
+ ctx2.lineTo(x, y + ry);
1307
+ ctx2.quadraticCurveTo(x, y, x + rx, y);
1308
+ ctx2.closePath();
1309
+ }
1310
+ return new svg.BoundingBox(x, y, x + width2, y + height2);
1311
+ };
1312
+ };
1313
+ svg.Element.rect.prototype = new svg.Element.PathElementBase();
1314
+ svg.Element.circle = function(node) {
1315
+ this.base = svg.Element.PathElementBase;
1316
+ this.base(node);
1317
+ this.path = function(ctx2) {
1318
+ let cx = this.attribute("cx").toPixels("x");
1319
+ let cy = this.attribute("cy").toPixels("y");
1320
+ let r = this.attribute("r").toPixels();
1321
+ if (ctx2 != null) {
1322
+ ctx2.beginPath();
1323
+ ctx2.arc(cx, cy, r, 0, Math.PI * 2, true);
1324
+ ctx2.closePath();
1325
+ }
1326
+ return new svg.BoundingBox(cx - r, cy - r, cx + r, cy + r);
1327
+ };
1328
+ };
1329
+ svg.Element.circle.prototype = new svg.Element.PathElementBase();
1330
+ svg.Element.ellipse = function(node) {
1331
+ this.base = svg.Element.PathElementBase;
1332
+ this.base(node);
1333
+ this.path = function(ctx2) {
1334
+ let KAPPA = 4 * ((Math.sqrt(2) - 1) / 3);
1335
+ let rx = this.attribute("rx").toPixels("x");
1336
+ let ry = this.attribute("ry").toPixels("y");
1337
+ let cx = this.attribute("cx").toPixels("x");
1338
+ let cy = this.attribute("cy").toPixels("y");
1339
+ if (ctx2 != null) {
1340
+ ctx2.beginPath();
1341
+ ctx2.moveTo(cx, cy - ry);
1342
+ ctx2.bezierCurveTo(cx + KAPPA * rx, cy - ry, cx + rx, cy - KAPPA * ry, cx + rx, cy);
1343
+ ctx2.bezierCurveTo(cx + rx, cy + KAPPA * ry, cx + KAPPA * rx, cy + ry, cx, cy + ry);
1344
+ ctx2.bezierCurveTo(cx - KAPPA * rx, cy + ry, cx - rx, cy + KAPPA * ry, cx - rx, cy);
1345
+ ctx2.bezierCurveTo(cx - rx, cy - KAPPA * ry, cx - KAPPA * rx, cy - ry, cx, cy - ry);
1346
+ ctx2.closePath();
1347
+ }
1348
+ return new svg.BoundingBox(cx - rx, cy - ry, cx + rx, cy + ry);
1349
+ };
1350
+ };
1351
+ svg.Element.ellipse.prototype = new svg.Element.PathElementBase();
1352
+ svg.Element.line = function(node) {
1353
+ this.base = svg.Element.PathElementBase;
1354
+ this.base(node);
1355
+ this.getPoints = function() {
1356
+ return [new svg.Point(this.attribute("x1").toPixels("x"), this.attribute("y1").toPixels("y")), new svg.Point(this.attribute("x2").toPixels("x"), this.attribute("y2").toPixels("y"))];
1357
+ };
1358
+ this.path = function(ctx2) {
1359
+ let points = this.getPoints();
1360
+ if (ctx2 != null) {
1361
+ ctx2.beginPath();
1362
+ ctx2.moveTo(points[0].x, points[0].y);
1363
+ ctx2.lineTo(points[1].x, points[1].y);
1364
+ }
1365
+ return new svg.BoundingBox(points[0].x, points[0].y, points[1].x, points[1].y);
1366
+ };
1367
+ this.getMarkers = function() {
1368
+ let points = this.getPoints();
1369
+ let a = points[0].angleTo(points[1]);
1370
+ return [[points[0], a], [points[1], a]];
1371
+ };
1372
+ };
1373
+ svg.Element.line.prototype = new svg.Element.PathElementBase();
1374
+ svg.Element.polyline = function(node) {
1375
+ this.base = svg.Element.PathElementBase;
1376
+ this.base(node);
1377
+ this.points = svg.CreatePath(this.attribute("points").value);
1378
+ this.path = function(ctx2) {
1379
+ let bb = new svg.BoundingBox(this.points[0].x, this.points[0].y);
1380
+ if (ctx2 != null) {
1381
+ ctx2.beginPath();
1382
+ ctx2.moveTo(this.points[0].x, this.points[0].y);
1383
+ }
1384
+ for (let i2 = 1; i2 < this.points.length; i2++) {
1385
+ bb.addPoint(this.points[i2].x, this.points[i2].y);
1386
+ if (ctx2 != null) ctx2.lineTo(this.points[i2].x, this.points[i2].y);
1387
+ }
1388
+ return bb;
1389
+ };
1390
+ this.getMarkers = function() {
1391
+ let markers = [];
1392
+ for (let i2 = 0; i2 < this.points.length - 1; i2++) {
1393
+ markers.push([this.points[i2], this.points[i2].angleTo(this.points[i2 + 1])]);
1394
+ }
1395
+ markers.push([this.points[this.points.length - 1], markers[markers.length - 1][1]]);
1396
+ return markers;
1397
+ };
1398
+ };
1399
+ svg.Element.polyline.prototype = new svg.Element.PathElementBase();
1400
+ svg.Element.polygon = function(node) {
1401
+ this.base = svg.Element.polyline;
1402
+ this.base(node);
1403
+ this.basePath = this.path;
1404
+ this.path = function(ctx2) {
1405
+ let bb = this.basePath(ctx2);
1406
+ if (ctx2 != null) {
1407
+ ctx2.lineTo(this.points[0].x, this.points[0].y);
1408
+ ctx2.closePath();
1409
+ }
1410
+ return bb;
1411
+ };
1412
+ };
1413
+ svg.Element.polygon.prototype = new svg.Element.polyline();
1414
+ svg.Element.path = function(node) {
1415
+ this.base = svg.Element.PathElementBase;
1416
+ this.base(node);
1417
+ let d = this.attribute("d").value;
1418
+ d = d.replace(/,/gm, " ");
1419
+ d = d.replace(/([MmZzLlHhVvCcSsQqTtAa])([MmZzLlHhVvCcSsQqTtAa])/gm, "$1 $2");
1420
+ d = d.replace(/([MmZzLlHhVvCcSsQqTtAa])([MmZzLlHhVvCcSsQqTtAa])/gm, "$1 $2");
1421
+ d = d.replace(/([MmZzLlHhVvCcSsQqTtAa])([^\s])/gm, "$1 $2");
1422
+ d = d.replace(/([^\s])([MmZzLlHhVvCcSsQqTtAa])/gm, "$1 $2");
1423
+ d = d.replace(/([0-9])([+\-])/gm, "$1 $2");
1424
+ d = d.replace(/(\.[0-9]*)(\.)/gm, "$1 $2");
1425
+ d = d.replace(/([Aa](\s+[0-9]+){3})\s+([01])\s*([01])/gm, "$1 $3 $4 ");
1426
+ d = svg.compressSpaces(d);
1427
+ d = svg.trim(d);
1428
+ this.PathParser = new function(d2) {
1429
+ this.tokens = d2.split(" ");
1430
+ this.reset = function() {
1431
+ this.i = -1;
1432
+ this.command = "";
1433
+ this.previousCommand = "";
1434
+ this.start = new svg.Point(0, 0);
1435
+ this.control = new svg.Point(0, 0);
1436
+ this.current = new svg.Point(0, 0);
1437
+ this.points = [];
1438
+ this.angles = [];
1439
+ };
1440
+ this.isEnd = function() {
1441
+ return this.i >= this.tokens.length - 1;
1442
+ };
1443
+ this.isCommandOrEnd = function() {
1444
+ if (this.isEnd()) return true;
1445
+ return this.tokens[this.i + 1].match(/^[A-Za-z]$/) != null;
1446
+ };
1447
+ this.isRelativeCommand = function() {
1448
+ switch (this.command) {
1449
+ case "m":
1450
+ case "l":
1451
+ case "h":
1452
+ case "v":
1453
+ case "c":
1454
+ case "s":
1455
+ case "q":
1456
+ case "t":
1457
+ case "a":
1458
+ case "z":
1459
+ return true;
1460
+ break;
1461
+ }
1462
+ return false;
1463
+ };
1464
+ this.getToken = function() {
1465
+ this.i++;
1466
+ return this.tokens[this.i];
1467
+ };
1468
+ this.getScalar = function() {
1469
+ return parseFloat(this.getToken());
1470
+ };
1471
+ this.nextCommand = function() {
1472
+ this.previousCommand = this.command;
1473
+ this.command = this.getToken();
1474
+ };
1475
+ this.getPoint = function() {
1476
+ let p = new svg.Point(this.getScalar(), this.getScalar());
1477
+ return this.makeAbsolute(p);
1478
+ };
1479
+ this.getAsControlPoint = function() {
1480
+ let p = this.getPoint();
1481
+ this.control = p;
1482
+ return p;
1483
+ };
1484
+ this.getAsCurrentPoint = function() {
1485
+ let p = this.getPoint();
1486
+ this.current = p;
1487
+ return p;
1488
+ };
1489
+ this.getReflectedControlPoint = function() {
1490
+ if (this.previousCommand.toLowerCase() != "c" && this.previousCommand.toLowerCase() != "s" && this.previousCommand.toLowerCase() != "q" && this.previousCommand.toLowerCase() != "t") {
1491
+ return this.current;
1492
+ }
1493
+ let p = new svg.Point(2 * this.current.x - this.control.x, 2 * this.current.y - this.control.y);
1494
+ return p;
1495
+ };
1496
+ this.makeAbsolute = function(p) {
1497
+ if (this.isRelativeCommand()) {
1498
+ p.x += this.current.x;
1499
+ p.y += this.current.y;
1500
+ }
1501
+ return p;
1502
+ };
1503
+ this.addMarker = function(p, from, priorTo) {
1504
+ if (priorTo != null && this.angles.length > 0 && this.angles[this.angles.length - 1] == null) {
1505
+ this.angles[this.angles.length - 1] = this.points[this.points.length - 1].angleTo(priorTo);
1506
+ }
1507
+ this.addMarkerAngle(p, from == null ? null : from.angleTo(p));
1508
+ };
1509
+ this.addMarkerAngle = function(p, a) {
1510
+ this.points.push(p);
1511
+ this.angles.push(a);
1512
+ };
1513
+ this.getMarkerPoints = function() {
1514
+ return this.points;
1515
+ };
1516
+ this.getMarkerAngles = function() {
1517
+ for (let i2 = 0; i2 < this.angles.length; i2++) {
1518
+ if (this.angles[i2] == null) {
1519
+ for (let j = i2 + 1; j < this.angles.length; j++) {
1520
+ if (this.angles[j] != null) {
1521
+ this.angles[i2] = this.angles[j];
1522
+ break;
1523
+ }
1524
+ }
1525
+ }
1526
+ }
1527
+ return this.angles;
1528
+ };
1529
+ }(d);
1530
+ this.path = function(ctx2) {
1531
+ let pp = this.PathParser;
1532
+ pp.reset();
1533
+ let bb = new svg.BoundingBox();
1534
+ if (ctx2 != null) ctx2.beginPath();
1535
+ while (!pp.isEnd()) {
1536
+ pp.nextCommand();
1537
+ switch (pp.command) {
1538
+ case "M":
1539
+ case "m":
1540
+ let p = pp.getAsCurrentPoint();
1541
+ pp.addMarker(p);
1542
+ bb.addPoint(p.x, p.y);
1543
+ if (ctx2 != null) ctx2.moveTo(p.x, p.y);
1544
+ pp.start = pp.current;
1545
+ while (!pp.isCommandOrEnd()) {
1546
+ let p2 = pp.getAsCurrentPoint();
1547
+ pp.addMarker(p2, pp.start);
1548
+ bb.addPoint(p2.x, p2.y);
1549
+ if (ctx2 != null) ctx2.lineTo(p2.x, p2.y);
1550
+ }
1551
+ break;
1552
+ case "L":
1553
+ case "l":
1554
+ while (!pp.isCommandOrEnd()) {
1555
+ let c = pp.current;
1556
+ let p2 = pp.getAsCurrentPoint();
1557
+ pp.addMarker(p2, c);
1558
+ bb.addPoint(p2.x, p2.y);
1559
+ if (ctx2 != null) ctx2.lineTo(p2.x, p2.y);
1560
+ }
1561
+ break;
1562
+ case "H":
1563
+ case "h":
1564
+ while (!pp.isCommandOrEnd()) {
1565
+ let newP = new svg.Point((pp.isRelativeCommand() ? pp.current.x : 0) + pp.getScalar(), pp.current.y);
1566
+ pp.addMarker(newP, pp.current);
1567
+ pp.current = newP;
1568
+ bb.addPoint(pp.current.x, pp.current.y);
1569
+ if (ctx2 != null) ctx2.lineTo(pp.current.x, pp.current.y);
1570
+ }
1571
+ break;
1572
+ case "V":
1573
+ case "v":
1574
+ while (!pp.isCommandOrEnd()) {
1575
+ let newP = new svg.Point(pp.current.x, (pp.isRelativeCommand() ? pp.current.y : 0) + pp.getScalar());
1576
+ pp.addMarker(newP, pp.current);
1577
+ pp.current = newP;
1578
+ bb.addPoint(pp.current.x, pp.current.y);
1579
+ if (ctx2 != null) ctx2.lineTo(pp.current.x, pp.current.y);
1580
+ }
1581
+ break;
1582
+ case "C":
1583
+ case "c":
1584
+ while (!pp.isCommandOrEnd()) {
1585
+ let curr = pp.current;
1586
+ let p1 = pp.getPoint();
1587
+ let cntrl = pp.getAsControlPoint();
1588
+ let cp = pp.getAsCurrentPoint();
1589
+ pp.addMarker(cp, cntrl, p1);
1590
+ bb.addBezierCurve(curr.x, curr.y, p1.x, p1.y, cntrl.x, cntrl.y, cp.x, cp.y);
1591
+ if (ctx2 != null) ctx2.bezierCurveTo(p1.x, p1.y, cntrl.x, cntrl.y, cp.x, cp.y);
1592
+ }
1593
+ break;
1594
+ case "S":
1595
+ case "s":
1596
+ while (!pp.isCommandOrEnd()) {
1597
+ let curr = pp.current;
1598
+ let p1 = pp.getReflectedControlPoint();
1599
+ let cntrl = pp.getAsControlPoint();
1600
+ let cp = pp.getAsCurrentPoint();
1601
+ pp.addMarker(cp, cntrl, p1);
1602
+ bb.addBezierCurve(curr.x, curr.y, p1.x, p1.y, cntrl.x, cntrl.y, cp.x, cp.y);
1603
+ if (ctx2 != null) ctx2.bezierCurveTo(p1.x, p1.y, cntrl.x, cntrl.y, cp.x, cp.y);
1604
+ }
1605
+ break;
1606
+ case "Q":
1607
+ case "q":
1608
+ while (!pp.isCommandOrEnd()) {
1609
+ let curr = pp.current;
1610
+ let cntrl = pp.getAsControlPoint();
1611
+ let cp = pp.getAsCurrentPoint();
1612
+ pp.addMarker(cp, cntrl, cntrl);
1613
+ bb.addQuadraticCurve(curr.x, curr.y, cntrl.x, cntrl.y, cp.x, cp.y);
1614
+ if (ctx2 != null) ctx2.quadraticCurveTo(cntrl.x, cntrl.y, cp.x, cp.y);
1615
+ }
1616
+ break;
1617
+ case "T":
1618
+ case "t":
1619
+ while (!pp.isCommandOrEnd()) {
1620
+ let curr = pp.current;
1621
+ let cntrl = pp.getReflectedControlPoint();
1622
+ pp.control = cntrl;
1623
+ let cp = pp.getAsCurrentPoint();
1624
+ pp.addMarker(cp, cntrl, cntrl);
1625
+ bb.addQuadraticCurve(curr.x, curr.y, cntrl.x, cntrl.y, cp.x, cp.y);
1626
+ if (ctx2 != null) ctx2.quadraticCurveTo(cntrl.x, cntrl.y, cp.x, cp.y);
1627
+ }
1628
+ break;
1629
+ case "A":
1630
+ case "a":
1631
+ while (!pp.isCommandOrEnd()) {
1632
+ let curr = pp.current;
1633
+ let rx = pp.getScalar();
1634
+ let ry = pp.getScalar();
1635
+ let xAxisRotation = pp.getScalar() * (Math.PI / 180);
1636
+ let largeArcFlag = pp.getScalar();
1637
+ let sweepFlag = pp.getScalar();
1638
+ let cp = pp.getAsCurrentPoint();
1639
+ let currp = new svg.Point(Math.cos(xAxisRotation) * (curr.x - cp.x) / 2 + Math.sin(xAxisRotation) * (curr.y - cp.y) / 2, -Math.sin(xAxisRotation) * (curr.x - cp.x) / 2 + Math.cos(xAxisRotation) * (curr.y - cp.y) / 2);
1640
+ let l = Math.pow(currp.x, 2) / Math.pow(rx, 2) + Math.pow(currp.y, 2) / Math.pow(ry, 2);
1641
+ if (l > 1) {
1642
+ rx *= Math.sqrt(l);
1643
+ ry *= Math.sqrt(l);
1644
+ }
1645
+ let s = (largeArcFlag == sweepFlag ? -1 : 1) * Math.sqrt((Math.pow(rx, 2) * Math.pow(ry, 2) - Math.pow(rx, 2) * Math.pow(currp.y, 2) - Math.pow(ry, 2) * Math.pow(currp.x, 2)) / (Math.pow(rx, 2) * Math.pow(currp.y, 2) + Math.pow(ry, 2) * Math.pow(currp.x, 2)));
1646
+ if (isNaN(s)) s = 0;
1647
+ let cpp = new svg.Point(s * rx * currp.y / ry, s * -ry * currp.x / rx);
1648
+ let centp = new svg.Point((curr.x + cp.x) / 2 + Math.cos(xAxisRotation) * cpp.x - Math.sin(xAxisRotation) * cpp.y, (curr.y + cp.y) / 2 + Math.sin(xAxisRotation) * cpp.x + Math.cos(xAxisRotation) * cpp.y);
1649
+ let m = function(v2) {
1650
+ return Math.sqrt(Math.pow(v2[0], 2) + Math.pow(v2[1], 2));
1651
+ };
1652
+ let r = function(u2, v2) {
1653
+ return (u2[0] * v2[0] + u2[1] * v2[1]) / (m(u2) * m(v2));
1654
+ };
1655
+ let a = function(u2, v2) {
1656
+ return (u2[0] * v2[1] < u2[1] * v2[0] ? -1 : 1) * Math.acos(r(u2, v2));
1657
+ };
1658
+ let a1 = a([1, 0], [(currp.x - cpp.x) / rx, (currp.y - cpp.y) / ry]);
1659
+ let u = [(currp.x - cpp.x) / rx, (currp.y - cpp.y) / ry];
1660
+ let v = [(-currp.x - cpp.x) / rx, (-currp.y - cpp.y) / ry];
1661
+ let ad = a(u, v);
1662
+ if (r(u, v) <= -1) ad = Math.PI;
1663
+ if (r(u, v) >= 1) ad = 0;
1664
+ let dir = 1 - sweepFlag ? 1 : -1;
1665
+ let ah = a1 + dir * (ad / 2);
1666
+ let halfWay = new svg.Point(centp.x + rx * Math.cos(ah), centp.y + ry * Math.sin(ah));
1667
+ pp.addMarkerAngle(halfWay, ah - dir * Math.PI / 2);
1668
+ pp.addMarkerAngle(cp, ah - dir * Math.PI);
1669
+ bb.addPoint(cp.x, cp.y);
1670
+ if (ctx2 != null) {
1671
+ let r2 = rx > ry ? rx : ry;
1672
+ let sx = rx > ry ? 1 : rx / ry;
1673
+ let sy = rx > ry ? ry / rx : 1;
1674
+ ctx2.translate(centp.x, centp.y);
1675
+ ctx2.rotate(xAxisRotation);
1676
+ ctx2.scale(sx, sy);
1677
+ ctx2.arc(0, 0, r2, a1, a1 + ad, 1 - sweepFlag);
1678
+ ctx2.scale(1 / sx, 1 / sy);
1679
+ ctx2.rotate(-xAxisRotation);
1680
+ ctx2.translate(-centp.x, -centp.y);
1681
+ }
1682
+ }
1683
+ break;
1684
+ case "Z":
1685
+ case "z":
1686
+ if (ctx2 != null) ctx2.closePath();
1687
+ pp.current = pp.start;
1688
+ }
1689
+ }
1690
+ return bb;
1691
+ };
1692
+ this.getMarkers = function() {
1693
+ let points = this.PathParser.getMarkerPoints();
1694
+ let angles = this.PathParser.getMarkerAngles();
1695
+ let markers = [];
1696
+ for (let i2 = 0; i2 < points.length; i2++) {
1697
+ markers.push([points[i2], angles[i2]]);
1698
+ }
1699
+ return markers;
1700
+ };
1701
+ };
1702
+ svg.Element.path.prototype = new svg.Element.PathElementBase();
1703
+ svg.Element.pattern = function(node) {
1704
+ this.base = svg.Element.ElementBase;
1705
+ this.base(node);
1706
+ this.createPattern = function(_ctx, _element) {
1707
+ let width2 = this.attribute("width").toPixels("x", true);
1708
+ let height2 = this.attribute("height").toPixels("y", true);
1709
+ let tempSvg = new svg.Element.svg();
1710
+ tempSvg.attributes["viewBox"] = new svg.Property("viewBox", this.attribute("viewBox").value);
1711
+ tempSvg.attributes["width"] = new svg.Property("width", width2 + "px");
1712
+ tempSvg.attributes["height"] = new svg.Property("height", height2 + "px");
1713
+ tempSvg.attributes["transform"] = new svg.Property("transform", this.attribute("patternTransform").value);
1714
+ tempSvg.children = this.children;
1715
+ let c = document.createElement("canvas");
1716
+ c.width = width2;
1717
+ c.height = height2;
1718
+ let cctx = c.getContext("2d");
1719
+ if (this.attribute("x").hasValue() && this.attribute("y").hasValue()) {
1720
+ cctx.translate(this.attribute("x").toPixels("x", true), this.attribute("y").toPixels("y", true));
1721
+ }
1722
+ for (let x = -1; x <= 1; x++) {
1723
+ for (let y = -1; y <= 1; y++) {
1724
+ cctx.save();
1725
+ cctx.translate(x * c.width, y * c.height);
1726
+ tempSvg.render(cctx);
1727
+ cctx.restore();
1728
+ }
1729
+ }
1730
+ let pattern = ctx.createPattern(c, "repeat");
1731
+ return pattern;
1732
+ };
1733
+ };
1734
+ svg.Element.pattern.prototype = new svg.Element.ElementBase();
1735
+ svg.Element.marker = function(node) {
1736
+ this.base = svg.Element.ElementBase;
1737
+ this.base(node);
1738
+ this.baseRender = this.render;
1739
+ this.render = function(ctx2, point, angle) {
1740
+ ctx2.translate(point.x, point.y);
1741
+ if (this.attribute("orient").valueOrDefault("auto") == "auto") ctx2.rotate(angle);
1742
+ if (this.attribute("markerUnits").valueOrDefault("strokeWidth") == "strokeWidth") ctx2.scale(ctx2.lineWidth, ctx2.lineWidth);
1743
+ ctx2.save();
1744
+ let tempSvg = new svg.Element.svg();
1745
+ tempSvg.attributes["viewBox"] = new svg.Property("viewBox", this.attribute("viewBox").value);
1746
+ tempSvg.attributes["refX"] = new svg.Property("refX", this.attribute("refX").value);
1747
+ tempSvg.attributes["refY"] = new svg.Property("refY", this.attribute("refY").value);
1748
+ tempSvg.attributes["width"] = new svg.Property("width", this.attribute("markerWidth").value);
1749
+ tempSvg.attributes["height"] = new svg.Property("height", this.attribute("markerHeight").value);
1750
+ tempSvg.attributes["fill"] = new svg.Property("fill", this.attribute("fill").valueOrDefault("black"));
1751
+ tempSvg.attributes["stroke"] = new svg.Property("stroke", this.attribute("stroke").valueOrDefault("none"));
1752
+ tempSvg.children = this.children;
1753
+ tempSvg.render(ctx2);
1754
+ ctx2.restore();
1755
+ if (this.attribute("markerUnits").valueOrDefault("strokeWidth") == "strokeWidth") ctx2.scale(1 / ctx2.lineWidth, 1 / ctx2.lineWidth);
1756
+ if (this.attribute("orient").valueOrDefault("auto") == "auto") ctx2.rotate(-angle);
1757
+ ctx2.translate(-point.x, -point.y);
1758
+ };
1759
+ };
1760
+ svg.Element.marker.prototype = new svg.Element.ElementBase();
1761
+ svg.Element.defs = function(node) {
1762
+ this.base = svg.Element.ElementBase;
1763
+ this.base(node);
1764
+ this.render = function(_ctx) {
1765
+ };
1766
+ };
1767
+ svg.Element.defs.prototype = new svg.Element.ElementBase();
1768
+ svg.Element.GradientBase = function(node) {
1769
+ this.base = svg.Element.ElementBase;
1770
+ this.base(node);
1771
+ this.gradientUnits = this.attribute("gradientUnits").valueOrDefault("objectBoundingBox");
1772
+ this.stops = [];
1773
+ for (let i2 = 0; i2 < this.children.length; i2++) {
1774
+ let child = this.children[i2];
1775
+ if (child.type == "stop") this.stops.push(child);
1776
+ }
1777
+ this.getGradient = function() {
1778
+ };
1779
+ this.createGradient = function(ctx2, element, parentOpacityProp) {
1780
+ let stopsContainer = this;
1781
+ if (this.getHrefAttribute().hasValue()) {
1782
+ stopsContainer = this.getHrefAttribute().getDefinition();
1783
+ }
1784
+ let addParentOpacity = function(color) {
1785
+ if (parentOpacityProp.hasValue()) {
1786
+ let p = new svg.Property("color", color);
1787
+ return p.addOpacity(parentOpacityProp.value).value;
1788
+ }
1789
+ return color;
1790
+ };
1791
+ let g = this.getGradient(ctx2, element);
1792
+ if (g == null) return addParentOpacity(stopsContainer.stops[stopsContainer.stops.length - 1].color);
1793
+ for (let i2 = 0; i2 < stopsContainer.stops.length; i2++) {
1794
+ g.addColorStop(stopsContainer.stops[i2].offset, addParentOpacity(stopsContainer.stops[i2].color));
1795
+ }
1796
+ if (this.attribute("gradientTransform").hasValue()) {
1797
+ let rootView = svg.ViewPort.viewPorts[0];
1798
+ let rect = new svg.Element.rect();
1799
+ rect.attributes["x"] = new svg.Property("x", -svg.MAX_VIRTUAL_PIXELS / 3);
1800
+ rect.attributes["y"] = new svg.Property("y", -svg.MAX_VIRTUAL_PIXELS / 3);
1801
+ rect.attributes["width"] = new svg.Property("width", svg.MAX_VIRTUAL_PIXELS);
1802
+ rect.attributes["height"] = new svg.Property("height", svg.MAX_VIRTUAL_PIXELS);
1803
+ let group = new svg.Element.g();
1804
+ group.attributes["transform"] = new svg.Property("transform", this.attribute("gradientTransform").value);
1805
+ group.children = [rect];
1806
+ let tempSvg = new svg.Element.svg();
1807
+ tempSvg.attributes["x"] = new svg.Property("x", 0);
1808
+ tempSvg.attributes["y"] = new svg.Property("y", 0);
1809
+ tempSvg.attributes["width"] = new svg.Property("width", rootView.width);
1810
+ tempSvg.attributes["height"] = new svg.Property("height", rootView.height);
1811
+ tempSvg.children = [group];
1812
+ let c = document.createElement("canvas");
1813
+ c.width = rootView.width;
1814
+ c.height = rootView.height;
1815
+ let tempCtx = c.getContext("2d");
1816
+ tempCtx.fillStyle = g;
1817
+ tempSvg.render(tempCtx);
1818
+ return tempCtx.createPattern(c, "no-repeat");
1819
+ }
1820
+ return g;
1821
+ };
1822
+ };
1823
+ svg.Element.GradientBase.prototype = new svg.Element.ElementBase();
1824
+ svg.Element.linearGradient = function(node) {
1825
+ this.base = svg.Element.GradientBase;
1826
+ this.base(node);
1827
+ this.getGradient = function(ctx2, element) {
1828
+ let bb = element.getBoundingBox();
1829
+ if (!this.attribute("x1").hasValue() && !this.attribute("y1").hasValue() && !this.attribute("x2").hasValue() && !this.attribute("y2").hasValue()) {
1830
+ this.attribute("x1", true).value = 0;
1831
+ this.attribute("y1", true).value = 0;
1832
+ this.attribute("x2", true).value = 1;
1833
+ this.attribute("y2", true).value = 0;
1834
+ }
1835
+ let x1 = this.gradientUnits == "objectBoundingBox" ? bb.x() + bb.width() * this.attribute("x1").numValue() : this.attribute("x1").toPixels("x");
1836
+ let y1 = this.gradientUnits == "objectBoundingBox" ? bb.y() + bb.height() * this.attribute("y1").numValue() : this.attribute("y1").toPixels("y");
1837
+ let x2 = this.gradientUnits == "objectBoundingBox" ? bb.x() + bb.width() * this.attribute("x2").numValue() : this.attribute("x2").toPixels("x");
1838
+ let y2 = this.gradientUnits == "objectBoundingBox" ? bb.y() + bb.height() * this.attribute("y2").numValue() : this.attribute("y2").toPixels("y");
1839
+ if (x1 == x2 && y1 == y2) return null;
1840
+ return ctx2.createLinearGradient(x1, y1, x2, y2);
1841
+ };
1842
+ };
1843
+ svg.Element.linearGradient.prototype = new svg.Element.GradientBase();
1844
+ svg.Element.radialGradient = function(node) {
1845
+ this.base = svg.Element.GradientBase;
1846
+ this.base(node);
1847
+ this.getGradient = function(ctx2, element) {
1848
+ let bb = element.getBoundingBox();
1849
+ if (!this.attribute("cx").hasValue()) this.attribute("cx", true).value = "50%";
1850
+ if (!this.attribute("cy").hasValue()) this.attribute("cy", true).value = "50%";
1851
+ if (!this.attribute("r").hasValue()) this.attribute("r", true).value = "50%";
1852
+ let cx = this.gradientUnits == "objectBoundingBox" ? bb.x() + bb.width() * this.attribute("cx").numValue() : this.attribute("cx").toPixels("x");
1853
+ let cy = this.gradientUnits == "objectBoundingBox" ? bb.y() + bb.height() * this.attribute("cy").numValue() : this.attribute("cy").toPixels("y");
1854
+ let fx = cx;
1855
+ let fy = cy;
1856
+ if (this.attribute("fx").hasValue()) {
1857
+ fx = this.gradientUnits == "objectBoundingBox" ? bb.x() + bb.width() * this.attribute("fx").numValue() : this.attribute("fx").toPixels("x");
1858
+ }
1859
+ if (this.attribute("fy").hasValue()) {
1860
+ fy = this.gradientUnits == "objectBoundingBox" ? bb.y() + bb.height() * this.attribute("fy").numValue() : this.attribute("fy").toPixels("y");
1861
+ }
1862
+ let r = this.gradientUnits == "objectBoundingBox" ? (bb.width() + bb.height()) / 2 * this.attribute("r").numValue() : this.attribute("r").toPixels();
1863
+ return ctx2.createRadialGradient(fx, fy, 0, cx, cy, r);
1864
+ };
1865
+ };
1866
+ svg.Element.radialGradient.prototype = new svg.Element.GradientBase();
1867
+ svg.Element.stop = function(node) {
1868
+ this.base = svg.Element.ElementBase;
1869
+ this.base(node);
1870
+ this.offset = this.attribute("offset").numValue();
1871
+ if (this.offset < 0) this.offset = 0;
1872
+ if (this.offset > 1) this.offset = 1;
1873
+ let stopColor = this.style("stop-color");
1874
+ if (this.style("stop-opacity").hasValue()) stopColor = stopColor.addOpacity(this.style("stop-opacity").value);
1875
+ this.color = stopColor.value;
1876
+ };
1877
+ svg.Element.stop.prototype = new svg.Element.ElementBase();
1878
+ svg.Element.AnimateBase = function(node) {
1879
+ this.base = svg.Element.ElementBase;
1880
+ this.base(node);
1881
+ svg.Animations.push(this);
1882
+ this.duration = 0;
1883
+ this.begin = this.attribute("begin").toMilliseconds();
1884
+ this.maxDuration = this.begin + this.attribute("dur").toMilliseconds();
1885
+ this.getProperty = function() {
1886
+ let attributeType = this.attribute("attributeType").value;
1887
+ let attributeName = this.attribute("attributeName").value;
1888
+ if (attributeType == "CSS") {
1889
+ return this.parent.style(attributeName, true);
1890
+ }
1891
+ return this.parent.attribute(attributeName, true);
1892
+ };
1893
+ this.initialValue = null;
1894
+ this.initialUnits = "";
1895
+ this.removed = false;
1896
+ this.calcValue = function() {
1897
+ return "";
1898
+ };
1899
+ this.update = function(delta) {
1900
+ if (this.initialValue == null) {
1901
+ this.initialValue = this.getProperty().value;
1902
+ this.initialUnits = this.getProperty().getUnits();
1903
+ }
1904
+ if (this.duration > this.maxDuration) {
1905
+ if (this.attribute("repeatCount").value == "indefinite" || this.attribute("repeatDur").value == "indefinite") {
1906
+ this.duration = 0;
1907
+ } else if (this.attribute("fill").valueOrDefault("remove") == "remove" && !this.removed) {
1908
+ this.removed = true;
1909
+ this.getProperty().value = this.initialValue;
1910
+ return true;
1911
+ } else {
1912
+ return false;
1913
+ }
1914
+ }
1915
+ this.duration = this.duration + delta;
1916
+ let updated = false;
1917
+ if (this.begin < this.duration) {
1918
+ let newValue = this.calcValue();
1919
+ if (this.attribute("type").hasValue()) {
1920
+ let type = this.attribute("type").value;
1921
+ newValue = type + "(" + newValue + ")";
1922
+ }
1923
+ this.getProperty().value = newValue;
1924
+ updated = true;
1925
+ }
1926
+ return updated;
1927
+ };
1928
+ this.from = this.attribute("from");
1929
+ this.to = this.attribute("to");
1930
+ this.values = this.attribute("values");
1931
+ if (this.values.hasValue()) this.values.value = this.values.value.split(";");
1932
+ this.progress = function() {
1933
+ let ret = {
1934
+ progress: (this.duration - this.begin) / (this.maxDuration - this.begin)
1935
+ };
1936
+ if (this.values.hasValue()) {
1937
+ let p = ret.progress * (this.values.value.length - 1);
1938
+ let lb = Math.floor(p), ub = Math.ceil(p);
1939
+ ret.from = new svg.Property("from", parseFloat(this.values.value[lb]));
1940
+ ret.to = new svg.Property("to", parseFloat(this.values.value[ub]));
1941
+ ret.progress = (p - lb) / (ub - lb);
1942
+ } else {
1943
+ ret.from = this.from;
1944
+ ret.to = this.to;
1945
+ }
1946
+ return ret;
1947
+ };
1948
+ };
1949
+ svg.Element.AnimateBase.prototype = new svg.Element.ElementBase();
1950
+ svg.Element.animate = function(node) {
1951
+ this.base = svg.Element.AnimateBase;
1952
+ this.base(node);
1953
+ this.calcValue = function() {
1954
+ let p = this.progress();
1955
+ let newValue = p.from.numValue() + (p.to.numValue() - p.from.numValue()) * p.progress;
1956
+ return newValue + this.initialUnits;
1957
+ };
1958
+ };
1959
+ svg.Element.animate.prototype = new svg.Element.AnimateBase();
1960
+ svg.Element.animateColor = function(node) {
1961
+ this.base = svg.Element.AnimateBase;
1962
+ this.base(node);
1963
+ this.calcValue = function() {
1964
+ let p = this.progress();
1965
+ let from = new RGBColor(p.from.value);
1966
+ let to = new RGBColor(p.to.value);
1967
+ if (from.ok && to.ok) {
1968
+ let r = from.r + (to.r - from.r) * p.progress;
1969
+ let g = from.g + (to.g - from.g) * p.progress;
1970
+ let b = from.b + (to.b - from.b) * p.progress;
1971
+ return "rgb(" + parseInt(r, 10) + "," + parseInt(g, 10) + "," + parseInt(b, 10) + ")";
1972
+ }
1973
+ return this.attribute("from").value;
1974
+ };
1975
+ };
1976
+ svg.Element.animateColor.prototype = new svg.Element.AnimateBase();
1977
+ svg.Element.animateTransform = function(node) {
1978
+ this.base = svg.Element.AnimateBase;
1979
+ this.base(node);
1980
+ this.calcValue = function() {
1981
+ let p = this.progress();
1982
+ let from = svg.ToNumberArray(p.from.value);
1983
+ let to = svg.ToNumberArray(p.to.value);
1984
+ let newValue = "";
1985
+ for (let i2 = 0; i2 < from.length; i2++) {
1986
+ newValue += from[i2] + (to[i2] - from[i2]) * p.progress + " ";
1987
+ }
1988
+ return newValue;
1989
+ };
1990
+ };
1991
+ svg.Element.animateTransform.prototype = new svg.Element.animate();
1992
+ svg.Element.font = function(node) {
1993
+ this.base = svg.Element.ElementBase;
1994
+ this.base(node);
1995
+ this.horizAdvX = this.attribute("horiz-adv-x").numValue();
1996
+ this.isRTL = false;
1997
+ this.isArabic = false;
1998
+ this.fontFace = null;
1999
+ this.missingGlyph = null;
2000
+ this.glyphs = [];
2001
+ for (let i2 = 0; i2 < this.children.length; i2++) {
2002
+ let child = this.children[i2];
2003
+ if (child.type == "font-face") {
2004
+ this.fontFace = child;
2005
+ if (child.style("font-family").hasValue()) {
2006
+ svg.Definitions[child.style("font-family").value] = this;
2007
+ }
2008
+ } else if (child.type == "missing-glyph") this.missingGlyph = child;
2009
+ else if (child.type == "glyph") {
2010
+ if (child.arabicForm != "") {
2011
+ this.isRTL = true;
2012
+ this.isArabic = true;
2013
+ if (typeof this.glyphs[child.unicode] == "undefined") this.glyphs[child.unicode] = [];
2014
+ this.glyphs[child.unicode][child.arabicForm] = child;
2015
+ } else {
2016
+ this.glyphs[child.unicode] = child;
2017
+ }
2018
+ }
2019
+ }
2020
+ };
2021
+ svg.Element.font.prototype = new svg.Element.ElementBase();
2022
+ svg.Element.fontface = function(node) {
2023
+ this.base = svg.Element.ElementBase;
2024
+ this.base(node);
2025
+ this.ascent = this.attribute("ascent").value;
2026
+ this.descent = this.attribute("descent").value;
2027
+ this.unitsPerEm = this.attribute("units-per-em").numValue();
2028
+ };
2029
+ svg.Element.fontface.prototype = new svg.Element.ElementBase();
2030
+ svg.Element.missingglyph = function(node) {
2031
+ this.base = svg.Element.path;
2032
+ this.base(node);
2033
+ this.horizAdvX = 0;
2034
+ };
2035
+ svg.Element.missingglyph.prototype = new svg.Element.path();
2036
+ svg.Element.glyph = function(node) {
2037
+ this.base = svg.Element.path;
2038
+ this.base(node);
2039
+ this.horizAdvX = this.attribute("horiz-adv-x").numValue();
2040
+ this.unicode = this.attribute("unicode").value;
2041
+ this.arabicForm = this.attribute("arabic-form").value;
2042
+ };
2043
+ svg.Element.glyph.prototype = new svg.Element.path();
2044
+ svg.Element.text = function(node) {
2045
+ this.captureTextNodes = true;
2046
+ this.base = svg.Element.RenderedElementBase;
2047
+ this.base(node);
2048
+ this.baseSetContext = this.setContext;
2049
+ this.setContext = function(ctx2) {
2050
+ this.baseSetContext(ctx2);
2051
+ if (this.style("dominant-baseline").hasValue()) ctx2.textBaseline = this.style("dominant-baseline").value;
2052
+ if (this.style("alignment-baseline").hasValue()) ctx2.textBaseline = this.style("alignment-baseline").value;
2053
+ };
2054
+ this.getBoundingBox = function() {
2055
+ return new svg.BoundingBox(this.attribute("x").toPixels("x"), this.attribute("y").toPixels("y"), 0, 0);
2056
+ };
2057
+ this.renderChildren = function(ctx2) {
2058
+ this.x = this.attribute("x").toPixels("x");
2059
+ this.y = this.attribute("y").toPixels("y");
2060
+ this.x += this.getAnchorDelta(ctx2, this, 0);
2061
+ for (let i2 = 0; i2 < this.children.length; i2++) {
2062
+ this.renderChild(ctx2, this, i2);
2063
+ }
2064
+ };
2065
+ this.getAnchorDelta = function(ctx2, parent, startI) {
2066
+ let textAnchor = this.style("text-anchor").valueOrDefault("start");
2067
+ if (textAnchor != "start") {
2068
+ let width2 = 0;
2069
+ for (let i2 = startI; i2 < parent.children.length; i2++) {
2070
+ let child = parent.children[i2];
2071
+ if (i2 > startI && child.attribute("x").hasValue()) break;
2072
+ width2 += child.measureTextRecursive(ctx2);
2073
+ }
2074
+ return -1 * (textAnchor == "end" ? width2 : width2 / 2);
2075
+ }
2076
+ return 0;
2077
+ };
2078
+ this.renderChild = function(ctx2, parent, i2) {
2079
+ let child = parent.children[i2];
2080
+ if (child.attribute("x").hasValue()) {
2081
+ child.x = child.attribute("x").toPixels("x") + this.getAnchorDelta(ctx2, parent, i2);
2082
+ } else {
2083
+ if (this.attribute("dx").hasValue()) this.x += this.attribute("dx").toPixels("x");
2084
+ if (child.attribute("dx").hasValue()) this.x += child.attribute("dx").toPixels("x");
2085
+ child.x = this.x;
2086
+ }
2087
+ this.x = child.x + child.measureText(ctx2);
2088
+ if (child.attribute("y").hasValue()) {
2089
+ child.y = child.attribute("y").toPixels("y");
2090
+ } else {
2091
+ if (this.attribute("dy").hasValue()) this.y += this.attribute("dy").toPixels("y");
2092
+ if (child.attribute("dy").hasValue()) this.y += child.attribute("dy").toPixels("y");
2093
+ child.y = this.y;
2094
+ }
2095
+ this.y = child.y;
2096
+ child.render(ctx2);
2097
+ for (let i3 = 0; i3 < child.children.length; i3++) {
2098
+ this.renderChild(ctx2, child, i3);
2099
+ }
2100
+ };
2101
+ };
2102
+ svg.Element.text.prototype = new svg.Element.RenderedElementBase();
2103
+ svg.Element.TextElementBase = function(node) {
2104
+ this.base = svg.Element.RenderedElementBase;
2105
+ this.base(node);
2106
+ this.getGlyph = function(font, text, i2) {
2107
+ let c = text[i2];
2108
+ let glyph = null;
2109
+ if (font.isArabic) {
2110
+ let arabicForm = "isolated";
2111
+ if ((i2 == 0 || text[i2 - 1] == " ") && i2 < text.length - 2 && text[i2 + 1] != " ") arabicForm = "terminal";
2112
+ if (i2 > 0 && text[i2 - 1] != " " && i2 < text.length - 2 && text[i2 + 1] != " ") arabicForm = "medial";
2113
+ if (i2 > 0 && text[i2 - 1] != " " && (i2 == text.length - 1 || text[i2 + 1] == " ")) arabicForm = "initial";
2114
+ if (typeof font.glyphs[c] != "undefined") {
2115
+ glyph = font.glyphs[c][arabicForm];
2116
+ if (glyph == null && font.glyphs[c].type == "glyph") glyph = font.glyphs[c];
2117
+ }
2118
+ } else {
2119
+ glyph = font.glyphs[c];
2120
+ }
2121
+ if (glyph == null) glyph = font.missingGlyph;
2122
+ return glyph;
2123
+ };
2124
+ this.renderChildren = function(ctx2) {
2125
+ let customFont = this.parent.style("font-family").getDefinition();
2126
+ if (customFont != null) {
2127
+ let fontSize = this.parent.style("font-size").numValueOrDefault(svg.Font.Parse(svg.ctx.font).fontSize);
2128
+ let fontStyle = this.parent.style("font-style").valueOrDefault(svg.Font.Parse(svg.ctx.font).fontStyle);
2129
+ let text = this.getText();
2130
+ if (customFont.isRTL) text = text.split("").reverse().join("");
2131
+ let dx = svg.ToNumberArray(this.parent.attribute("dx").value);
2132
+ for (let i2 = 0; i2 < text.length; i2++) {
2133
+ let glyph = this.getGlyph(customFont, text, i2);
2134
+ let scale = fontSize / customFont.fontFace.unitsPerEm;
2135
+ ctx2.translate(this.x, this.y);
2136
+ ctx2.scale(scale, -scale);
2137
+ let lw = ctx2.lineWidth;
2138
+ ctx2.lineWidth = ctx2.lineWidth * customFont.fontFace.unitsPerEm / fontSize;
2139
+ if (fontStyle == "italic") ctx2.transform(1, 0, 0.4, 1, 0, 0);
2140
+ glyph.render(ctx2);
2141
+ if (fontStyle == "italic") ctx2.transform(1, 0, -0.4, 1, 0, 0);
2142
+ ctx2.lineWidth = lw;
2143
+ ctx2.scale(1 / scale, -1 / scale);
2144
+ ctx2.translate(-this.x, -this.y);
2145
+ this.x += fontSize * (glyph.horizAdvX || customFont.horizAdvX) / customFont.fontFace.unitsPerEm;
2146
+ if (typeof dx[i2] != "undefined" && !isNaN(dx[i2])) {
2147
+ this.x += dx[i2];
2148
+ }
2149
+ }
2150
+ return;
2151
+ }
2152
+ if (ctx2.fillStyle != "") ctx2.fillText(svg.compressSpaces(this.getText()), this.x, this.y);
2153
+ if (ctx2.strokeStyle != "") ctx2.strokeText(svg.compressSpaces(this.getText()), this.x, this.y);
2154
+ };
2155
+ this.getText = function() {
2156
+ };
2157
+ this.measureTextRecursive = function(ctx2) {
2158
+ let width2 = this.measureText(ctx2);
2159
+ for (let i2 = 0; i2 < this.children.length; i2++) {
2160
+ width2 += this.children[i2].measureTextRecursive(ctx2);
2161
+ }
2162
+ return width2;
2163
+ };
2164
+ this.measureText = function(ctx2) {
2165
+ let customFont = this.parent.style("font-family").getDefinition();
2166
+ if (customFont != null) {
2167
+ let fontSize = this.parent.style("font-size").numValueOrDefault(svg.Font.Parse(svg.ctx.font).fontSize);
2168
+ let measure = 0;
2169
+ let text = this.getText();
2170
+ if (customFont.isRTL) text = text.split("").reverse().join("");
2171
+ let dx = svg.ToNumberArray(this.parent.attribute("dx").value);
2172
+ for (let i2 = 0; i2 < text.length; i2++) {
2173
+ let glyph = this.getGlyph(customFont, text, i2);
2174
+ measure += (glyph.horizAdvX || customFont.horizAdvX) * fontSize / customFont.fontFace.unitsPerEm;
2175
+ if (typeof dx[i2] != "undefined" && !isNaN(dx[i2])) {
2176
+ measure += dx[i2];
2177
+ }
2178
+ }
2179
+ return measure;
2180
+ }
2181
+ let textToMeasure = svg.compressSpaces(this.getText());
2182
+ if (!ctx2.measureText) return textToMeasure.length * 10;
2183
+ ctx2.save();
2184
+ this.setContext(ctx2);
2185
+ let width2 = ctx2.measureText(textToMeasure).width;
2186
+ ctx2.restore();
2187
+ return width2;
2188
+ };
2189
+ };
2190
+ svg.Element.TextElementBase.prototype = new svg.Element.RenderedElementBase();
2191
+ svg.Element.tspan = function(node) {
2192
+ this.captureTextNodes = true;
2193
+ this.base = svg.Element.TextElementBase;
2194
+ this.base(node);
2195
+ this.text = node.nodeValue || node.text || "";
2196
+ this.getText = function() {
2197
+ return this.text;
2198
+ };
2199
+ };
2200
+ svg.Element.tspan.prototype = new svg.Element.TextElementBase();
2201
+ svg.Element.tref = function(node) {
2202
+ this.base = svg.Element.TextElementBase;
2203
+ this.base(node);
2204
+ this.getText = function() {
2205
+ let element = this.getHrefAttribute().getDefinition();
2206
+ if (element != null) return element.children[0].getText();
2207
+ };
2208
+ };
2209
+ svg.Element.tref.prototype = new svg.Element.TextElementBase();
2210
+ svg.Element.a = function(node) {
2211
+ this.base = svg.Element.TextElementBase;
2212
+ this.base(node);
2213
+ this.hasText = true;
2214
+ for (let i2 = 0; i2 < node.childNodes.length; i2++) {
2215
+ if (node.childNodes[i2].nodeType != 3) this.hasText = false;
2216
+ }
2217
+ this.text = this.hasText ? node.childNodes[0].nodeValue : "";
2218
+ this.getText = function() {
2219
+ return this.text;
2220
+ };
2221
+ this.baseRenderChildren = this.renderChildren;
2222
+ this.renderChildren = function(ctx2) {
2223
+ if (this.hasText) {
2224
+ this.baseRenderChildren(ctx2);
2225
+ let fontSize = new svg.Property("fontSize", svg.Font.Parse(svg.ctx.font).fontSize);
2226
+ svg.Mouse.checkBoundingBox(this, new svg.BoundingBox(this.x, this.y - fontSize.toPixels("y"), this.x + this.measureText(ctx2), this.y));
2227
+ } else {
2228
+ let g = new svg.Element.g();
2229
+ g.children = this.children;
2230
+ g.parent = this;
2231
+ g.render(ctx2);
2232
+ }
2233
+ };
2234
+ this.onclick = function() {
2235
+ window.open(this.getHrefAttribute().value);
2236
+ };
2237
+ this.onmousemove = function() {
2238
+ svg.ctx.canvas.style.cursor = "pointer";
2239
+ };
2240
+ };
2241
+ svg.Element.a.prototype = new svg.Element.TextElementBase();
2242
+ svg.Element.image = function(node) {
2243
+ this.base = svg.Element.RenderedElementBase;
2244
+ this.base(node);
2245
+ let href = this.getHrefAttribute().value;
2246
+ let isSvg = href.match(/\.svg$/);
2247
+ svg.Images.push(this);
2248
+ this.loaded = false;
2249
+ if (!isSvg) {
2250
+ this.img = document.createElement("img");
2251
+ let self = this;
2252
+ this.img.onload = function() {
2253
+ self.loaded = true;
2254
+ };
2255
+ this.img.onerror = function() {
2256
+ if (typeof console != "undefined") {
2257
+ console.log('ERROR: image "' + href + '" not found');
2258
+ self.loaded = true;
2259
+ }
2260
+ };
2261
+ this.img.src = href;
2262
+ } else {
2263
+ this.img = svg.ajax(href);
2264
+ this.loaded = true;
2265
+ }
2266
+ this.renderChildren = function(ctx2) {
2267
+ let x = this.attribute("x").toPixels("x");
2268
+ let y = this.attribute("y").toPixels("y");
2269
+ let width2 = this.attribute("width").toPixels("x");
2270
+ let height2 = this.attribute("height").toPixels("y");
2271
+ if (width2 == 0 || height2 == 0) return;
2272
+ ctx2.save();
2273
+ if (isSvg) {
2274
+ ctx2.drawSvg(this.img, x, y, width2, height2);
2275
+ } else {
2276
+ ctx2.translate(x, y);
2277
+ svg.AspectRatio(ctx2, this.attribute("preserveAspectRatio").value, width2, this.img.width, height2, this.img.height, 0, 0);
2278
+ ctx2.drawImage(this.img, 0, 0);
2279
+ }
2280
+ ctx2.restore();
2281
+ };
2282
+ this.getBoundingBox = function() {
2283
+ let x = this.attribute("x").toPixels("x");
2284
+ let y = this.attribute("y").toPixels("y");
2285
+ let width2 = this.attribute("width").toPixels("x");
2286
+ let height2 = this.attribute("height").toPixels("y");
2287
+ return new svg.BoundingBox(x, y, x + width2, y + height2);
2288
+ };
2289
+ };
2290
+ svg.Element.image.prototype = new svg.Element.RenderedElementBase();
2291
+ svg.Element.g = function(node) {
2292
+ this.base = svg.Element.RenderedElementBase;
2293
+ this.base(node);
2294
+ this.getBoundingBox = function() {
2295
+ let bb = new svg.BoundingBox();
2296
+ for (let i2 = 0; i2 < this.children.length; i2++) {
2297
+ bb.addBoundingBox(this.children[i2].getBoundingBox());
2298
+ }
2299
+ return bb;
2300
+ };
2301
+ };
2302
+ svg.Element.g.prototype = new svg.Element.RenderedElementBase();
2303
+ svg.Element.symbol = function(node) {
2304
+ this.base = svg.Element.RenderedElementBase;
2305
+ this.base(node);
2306
+ this.baseSetContext = this.setContext;
2307
+ this.setContext = function(ctx2) {
2308
+ this.baseSetContext(ctx2);
2309
+ if (this.attribute("viewBox").hasValue()) {
2310
+ let viewBox = svg.ToNumberArray(this.attribute("viewBox").value);
2311
+ let minX = viewBox[0];
2312
+ let minY = viewBox[1];
2313
+ width = viewBox[2];
2314
+ height = viewBox[3];
2315
+ svg.AspectRatio(ctx2, this.attribute("preserveAspectRatio").value, this.attribute("width").toPixels("x"), width, this.attribute("height").toPixels("y"), height, minX, minY);
2316
+ svg.ViewPort.SetCurrent(viewBox[2], viewBox[3]);
2317
+ }
2318
+ };
2319
+ };
2320
+ svg.Element.symbol.prototype = new svg.Element.RenderedElementBase();
2321
+ svg.Element.style = function(node) {
2322
+ this.base = svg.Element.ElementBase;
2323
+ this.base(node);
2324
+ let css = "";
2325
+ for (let i2 = 0; i2 < node.childNodes.length; i2++) {
2326
+ css += node.childNodes[i2].nodeValue;
2327
+ }
2328
+ css = css.replace(/(\/\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*+\/)|(^[\s]*\/\/.*)/gm, "");
2329
+ css = svg.compressSpaces(css);
2330
+ let cssDefs = css.split("}");
2331
+ for (let i2 = 0; i2 < cssDefs.length; i2++) {
2332
+ if (svg.trim(cssDefs[i2]) != "") {
2333
+ let cssDef = cssDefs[i2].split("{");
2334
+ let cssClasses = cssDef[0].split(",");
2335
+ let cssProps = cssDef[1].split(";");
2336
+ for (let j = 0; j < cssClasses.length; j++) {
2337
+ let cssClass = svg.trim(cssClasses[j]);
2338
+ if (cssClass != "") {
2339
+ let props = {};
2340
+ for (let k = 0; k < cssProps.length; k++) {
2341
+ let prop = cssProps[k].indexOf(":");
2342
+ let name = cssProps[k].substr(0, prop);
2343
+ let value = cssProps[k].substr(prop + 1, cssProps[k].length - prop);
2344
+ if (name != null && value != null) {
2345
+ props[svg.trim(name)] = new svg.Property(svg.trim(name), svg.trim(value));
2346
+ }
2347
+ }
2348
+ svg.Styles[cssClass] = props;
2349
+ if (cssClass == "@font-face") {
2350
+ let fontFamily = props["font-family"].value.replace(/"/g, "");
2351
+ let srcs = props["src"].value.split(",");
2352
+ for (let s = 0; s < srcs.length; s++) {
2353
+ if (srcs[s].indexOf('format("svg")') > 0) {
2354
+ let urlStart = srcs[s].indexOf("url");
2355
+ let urlEnd = srcs[s].indexOf(")", urlStart);
2356
+ let url = srcs[s].substr(urlStart + 5, urlEnd - urlStart - 6);
2357
+ let doc = svg.parseXml(svg.ajax(url));
2358
+ let fonts = doc.getElementsByTagName("font");
2359
+ for (let f = 0; f < fonts.length; f++) {
2360
+ let font = svg.CreateElement(fonts[f]);
2361
+ svg.Definitions[fontFamily] = font;
2362
+ }
2363
+ }
2364
+ }
2365
+ }
2366
+ }
2367
+ }
2368
+ }
2369
+ }
2370
+ };
2371
+ svg.Element.style.prototype = new svg.Element.ElementBase();
2372
+ svg.Element.use = function(node) {
2373
+ this.base = svg.Element.RenderedElementBase;
2374
+ this.base(node);
2375
+ this.baseSetContext = this.setContext;
2376
+ this.setContext = function(ctx2) {
2377
+ this.baseSetContext(ctx2);
2378
+ if (this.attribute("x").hasValue()) ctx2.translate(this.attribute("x").toPixels("x"), 0);
2379
+ if (this.attribute("y").hasValue()) ctx2.translate(0, this.attribute("y").toPixels("y"));
2380
+ };
2381
+ this.getDefinition = function() {
2382
+ let element = this.getHrefAttribute().getDefinition();
2383
+ if (this.attribute("width").hasValue()) element.attribute("width", true).value = this.attribute("width").value;
2384
+ if (this.attribute("height").hasValue()) element.attribute("height", true).value = this.attribute("height").value;
2385
+ return element;
2386
+ };
2387
+ this.path = function(ctx2) {
2388
+ let element = this.getDefinition();
2389
+ if (element != null) element.path(ctx2);
2390
+ };
2391
+ this.getBoundingBox = function() {
2392
+ let element = this.getDefinition();
2393
+ if (element != null) return element.getBoundingBox();
2394
+ };
2395
+ this.renderChildren = function(ctx2) {
2396
+ let element = this.getDefinition();
2397
+ if (element != null) {
2398
+ let oldParent = element.parent;
2399
+ element.parent = null;
2400
+ element.render(ctx2);
2401
+ element.parent = oldParent;
2402
+ }
2403
+ };
2404
+ };
2405
+ svg.Element.use.prototype = new svg.Element.RenderedElementBase();
2406
+ svg.Element.mask = function(node) {
2407
+ this.base = svg.Element.ElementBase;
2408
+ this.base(node);
2409
+ this.apply = function(ctx2, element) {
2410
+ let x = this.attribute("x").toPixels("x");
2411
+ let y = this.attribute("y").toPixels("y");
2412
+ let width2 = this.attribute("width").toPixels("x");
2413
+ let height2 = this.attribute("height").toPixels("y");
2414
+ if (width2 == 0 && height2 == 0) {
2415
+ let bb = new svg.BoundingBox();
2416
+ for (let i2 = 0; i2 < this.children.length; i2++) {
2417
+ bb.addBoundingBox(this.children[i2].getBoundingBox());
2418
+ }
2419
+ }
2420
+ let mask = element.attribute("mask").value;
2421
+ element.attribute("mask").value = "";
2422
+ let cMask = document.createElement("canvas");
2423
+ cMask.width = x + width2;
2424
+ cMask.height = y + height2;
2425
+ let maskCtx = cMask.getContext("2d");
2426
+ this.renderChildren(maskCtx);
2427
+ let c = document.createElement("canvas");
2428
+ c.width = x + width2;
2429
+ c.height = y + height2;
2430
+ let tempCtx = c.getContext("2d");
2431
+ element.render(tempCtx);
2432
+ tempCtx.globalCompositeOperation = "destination-in";
2433
+ tempCtx.fillStyle = maskCtx.createPattern(cMask, "no-repeat");
2434
+ tempCtx.fillRect(0, 0, x + width2, y + height2);
2435
+ ctx2.fillStyle = tempCtx.createPattern(c, "no-repeat");
2436
+ ctx2.fillRect(0, 0, x + width2, y + height2);
2437
+ element.attribute("mask").value = mask;
2438
+ };
2439
+ this.render = function() {
2440
+ };
2441
+ };
2442
+ svg.Element.mask.prototype = new svg.Element.ElementBase();
2443
+ svg.Element.clipPath = function(node) {
2444
+ this.base = svg.Element.ElementBase;
2445
+ this.base(node);
2446
+ this.apply = function(ctx2) {
2447
+ for (let i2 = 0; i2 < this.children.length; i2++) {
2448
+ let child = this.children[i2];
2449
+ if (typeof child.path != "undefined") {
2450
+ let transform = null;
2451
+ if (child.attribute("transform").hasValue()) {
2452
+ transform = new svg.Transform(child.attribute("transform").value);
2453
+ transform.apply(ctx2);
2454
+ }
2455
+ child.path(ctx2);
2456
+ ctx2.clip();
2457
+ if (transform) {
2458
+ transform.unapply(ctx2);
2459
+ }
2460
+ }
2461
+ }
2462
+ };
2463
+ this.render = function() {
2464
+ };
2465
+ };
2466
+ svg.Element.clipPath.prototype = new svg.Element.ElementBase();
2467
+ svg.Element.filter = function(node) {
2468
+ this.base = svg.Element.ElementBase;
2469
+ this.base(node);
2470
+ this.apply = function(ctx2, element) {
2471
+ let bb = element.getBoundingBox();
2472
+ let x = Math.floor(bb.x1);
2473
+ let y = Math.floor(bb.y1);
2474
+ let width2 = Math.floor(bb.width());
2475
+ let height2 = Math.floor(bb.height());
2476
+ let filter = element.style("filter").value;
2477
+ element.style("filter").value = "";
2478
+ let px = 0, py = 0;
2479
+ for (let i2 = 0; i2 < this.children.length; i2++) {
2480
+ let efd = this.children[i2].extraFilterDistance || 0;
2481
+ px = Math.max(px, efd);
2482
+ py = Math.max(py, efd);
2483
+ }
2484
+ let c = document.createElement("canvas");
2485
+ c.width = width2 + 2 * px;
2486
+ c.height = height2 + 2 * py;
2487
+ let tempCtx = c.getContext("2d");
2488
+ tempCtx.translate(-x + px, -y + py);
2489
+ element.render(tempCtx);
2490
+ for (let i2 = 0; i2 < this.children.length; i2++) {
2491
+ this.children[i2].apply(tempCtx, 0, 0, width2 + 2 * px, height2 + 2 * py);
2492
+ }
2493
+ ctx2.drawImage(c, 0, 0, width2 + 2 * px, height2 + 2 * py, x - px, y - py, width2 + 2 * px, height2 + 2 * py);
2494
+ element.style("filter", true).value = filter;
2495
+ };
2496
+ this.render = function() {
2497
+ };
2498
+ };
2499
+ svg.Element.filter.prototype = new svg.Element.ElementBase();
2500
+ svg.Element.feMorphology = function(node) {
2501
+ this.base = svg.Element.ElementBase;
2502
+ this.base(node);
2503
+ this.apply = function() {
2504
+ };
2505
+ };
2506
+ svg.Element.feMorphology.prototype = new svg.Element.ElementBase();
2507
+ svg.Element.feColorMatrix = function(node) {
2508
+ this.base = svg.Element.ElementBase;
2509
+ this.base(node);
2510
+ function imGet(img, x, y, width2, height2, rgba) {
2511
+ return img[y * width2 * 4 + x * 4 + rgba];
2512
+ }
2513
+ function imSet(img, x, y, width2, height2, rgba, val) {
2514
+ img[y * width2 * 4 + x * 4 + rgba] = val;
2515
+ }
2516
+ this.apply = function(ctx2, x, y, width2, height2) {
2517
+ let srcData = ctx2.getImageData(0, 0, width2, height2);
2518
+ for (let y2 = 0; y2 < height2; y2++) {
2519
+ for (let x2 = 0; x2 < width2; x2++) {
2520
+ let r = imGet(srcData.data, x2, y2, width2, height2, 0);
2521
+ let g = imGet(srcData.data, x2, y2, width2, height2, 1);
2522
+ let b = imGet(srcData.data, x2, y2, width2, height2, 2);
2523
+ let gray = (r + g + b) / 3;
2524
+ imSet(srcData.data, x2, y2, width2, height2, 0, gray);
2525
+ imSet(srcData.data, x2, y2, width2, height2, 1, gray);
2526
+ imSet(srcData.data, x2, y2, width2, height2, 2, gray);
2527
+ }
2528
+ }
2529
+ ctx2.clearRect(0, 0, width2, height2);
2530
+ ctx2.putImageData(srcData, 0, 0);
2531
+ };
2532
+ };
2533
+ svg.Element.feColorMatrix.prototype = new svg.Element.ElementBase();
2534
+ svg.Element.feGaussianBlur = function(node) {
2535
+ this.base = svg.Element.ElementBase;
2536
+ this.base(node);
2537
+ this.blurRadius = Math.floor(this.attribute("stdDeviation").numValue());
2538
+ this.extraFilterDistance = this.blurRadius;
2539
+ this.apply = function(ctx2, x, y, width2, height2) {
2540
+ if (typeof stackBlurCanvasRGBA == "undefined") {
2541
+ if (typeof console != "undefined") {
2542
+ console.log("ERROR: StackBlur.js must be included for blur to work");
2543
+ }
2544
+ return;
2545
+ }
2546
+ ctx2.canvas.id = svg.UniqueId();
2547
+ ctx2.canvas.style.display = "none";
2548
+ document.body.appendChild(ctx2.canvas);
2549
+ stackBlurCanvasRGBA(ctx2.canvas.id, x, y, width2, height2, this.blurRadius);
2550
+ document.body.removeChild(ctx2.canvas);
2551
+ };
2552
+ };
2553
+ svg.Element.feGaussianBlur.prototype = new svg.Element.ElementBase();
2554
+ svg.Element.title = function() {
2555
+ };
2556
+ svg.Element.title.prototype = new svg.Element.ElementBase();
2557
+ svg.Element.desc = function() {
2558
+ };
2559
+ svg.Element.desc.prototype = new svg.Element.ElementBase();
2560
+ svg.Element.MISSING = function(node) {
2561
+ if (typeof console != "undefined") {
2562
+ console.log("ERROR: Element '" + node.nodeName + "' not yet implemented.");
2563
+ }
2564
+ };
2565
+ svg.Element.MISSING.prototype = new svg.Element.ElementBase();
2566
+ svg.CreateElement = function(node) {
2567
+ let className = node.nodeName.replace(/^[^:]+:/, "");
2568
+ className = className.replace(/\-/g, "");
2569
+ let e = null;
2570
+ if (typeof svg.Element[className] != "undefined") {
2571
+ e = new svg.Element[className](node);
2572
+ } else {
2573
+ e = new svg.Element.MISSING(node);
2574
+ }
2575
+ e.type = node.nodeName;
2576
+ return e;
2577
+ };
2578
+ svg.load = function(ctx2, url) {
2579
+ svg.loadXml(ctx2, svg.ajax(url));
2580
+ };
2581
+ svg.loadXml = function(ctx2, xml) {
2582
+ svg.loadXmlDoc(ctx2, svg.parseXml(xml));
2583
+ };
2584
+ svg.loadXmlDoc = function(ctx2, dom) {
2585
+ svg.init(ctx2);
2586
+ let mapXY = function(p) {
2587
+ let e2 = ctx2.canvas;
2588
+ while (e2) {
2589
+ p.x -= e2.offsetLeft;
2590
+ p.y -= e2.offsetTop;
2591
+ e2 = e2.offsetParent;
2592
+ }
2593
+ if (window.scrollX) p.x += window.scrollX;
2594
+ if (window.scrollY) p.y += window.scrollY;
2595
+ return p;
2596
+ };
2597
+ if (svg.opts["ignoreMouse"] != true) {
2598
+ ctx2.canvas.onclick = function(e2) {
2599
+ let p = mapXY(new svg.Point(e2 != null ? e2.clientX : event.clientX, e2 != null ? e2.clientY : event.clientY));
2600
+ svg.Mouse.onclick(p.x, p.y);
2601
+ };
2602
+ ctx2.canvas.onmousemove = function(e2) {
2603
+ let p = mapXY(new svg.Point(e2 != null ? e2.clientX : event.clientX, e2 != null ? e2.clientY : event.clientY));
2604
+ svg.Mouse.onmousemove(p.x, p.y);
2605
+ };
2606
+ }
2607
+ let e = svg.CreateElement(dom.documentElement);
2608
+ e.root = true;
2609
+ let isFirstRender = true;
2610
+ let draw = function() {
2611
+ svg.ViewPort.Clear();
2612
+ if (ctx2.canvas.parentNode) svg.ViewPort.SetCurrent(ctx2.canvas.parentNode.clientWidth, ctx2.canvas.parentNode.clientHeight);
2613
+ if (svg.opts["ignoreDimensions"] != true) {
2614
+ if (e.style("width").hasValue()) {
2615
+ ctx2.canvas.width = e.style("width").toPixels("x");
2616
+ ctx2.canvas.style.width = ctx2.canvas.width + "px";
2617
+ }
2618
+ if (e.style("height").hasValue()) {
2619
+ ctx2.canvas.height = e.style("height").toPixels("y");
2620
+ ctx2.canvas.style.height = ctx2.canvas.height + "px";
2621
+ }
2622
+ }
2623
+ let cWidth = ctx2.canvas.clientWidth || ctx2.canvas.width;
2624
+ let cHeight = ctx2.canvas.clientHeight || ctx2.canvas.height;
2625
+ if (svg.opts["ignoreDimensions"] == true && e.style("width").hasValue() && e.style("height").hasValue()) {
2626
+ cWidth = e.style("width").toPixels("x");
2627
+ cHeight = e.style("height").toPixels("y");
2628
+ }
2629
+ svg.ViewPort.SetCurrent(cWidth, cHeight);
2630
+ if (svg.opts["offsetX"] != null) e.attribute("x", true).value = svg.opts["offsetX"];
2631
+ if (svg.opts["offsetY"] != null) e.attribute("y", true).value = svg.opts["offsetY"];
2632
+ if (svg.opts["scaleWidth"] != null && svg.opts["scaleHeight"] != null) {
2633
+ let xRatio = 1, yRatio = 1, viewBox = svg.ToNumberArray(e.attribute("viewBox").value);
2634
+ if (e.attribute("width").hasValue()) xRatio = e.attribute("width").toPixels("x") / svg.opts["scaleWidth"];
2635
+ else if (!isNaN(viewBox[2])) xRatio = viewBox[2] / svg.opts["scaleWidth"];
2636
+ if (e.attribute("height").hasValue()) yRatio = e.attribute("height").toPixels("y") / svg.opts["scaleHeight"];
2637
+ else if (!isNaN(viewBox[3])) yRatio = viewBox[3] / svg.opts["scaleHeight"];
2638
+ e.attribute("width", true).value = svg.opts["scaleWidth"];
2639
+ e.attribute("height", true).value = svg.opts["scaleHeight"];
2640
+ e.attribute("viewBox", true).value = "0 0 " + cWidth * xRatio + " " + cHeight * yRatio;
2641
+ e.attribute("preserveAspectRatio", true).value = "none";
2642
+ }
2643
+ if (svg.opts["ignoreClear"] != true) {
2644
+ ctx2.clearRect(0, 0, cWidth, cHeight);
2645
+ }
2646
+ e.render(ctx2);
2647
+ if (isFirstRender) {
2648
+ isFirstRender = false;
2649
+ if (typeof svg.opts["renderCallback"] == "function") svg.opts["renderCallback"](dom);
2650
+ }
2651
+ };
2652
+ let waitingForImages = true;
2653
+ if (svg.ImagesLoaded()) {
2654
+ waitingForImages = false;
2655
+ draw();
2656
+ }
2657
+ svg.intervalID = setInterval(function() {
2658
+ let needUpdate = false;
2659
+ if (waitingForImages && svg.ImagesLoaded()) {
2660
+ waitingForImages = false;
2661
+ needUpdate = true;
2662
+ }
2663
+ if (svg.opts["ignoreMouse"] != true) {
2664
+ needUpdate = needUpdate | svg.Mouse.hasEvents();
2665
+ }
2666
+ if (svg.opts["ignoreAnimation"] != true) {
2667
+ for (let i2 = 0; i2 < svg.Animations.length; i2++) {
2668
+ needUpdate = needUpdate | svg.Animations[i2].update(1e3 / svg.FRAMERATE);
2669
+ }
2670
+ }
2671
+ if (typeof svg.opts["forceRedraw"] == "function") {
2672
+ if (svg.opts["forceRedraw"]() == true) needUpdate = true;
2673
+ }
2674
+ if (needUpdate) {
2675
+ draw();
2676
+ svg.Mouse.runEvents();
2677
+ }
2678
+ }, 1e3 / svg.FRAMERATE);
2679
+ };
2680
+ svg.stop = function() {
2681
+ if (svg.intervalID) {
2682
+ clearInterval(svg.intervalID);
2683
+ }
2684
+ };
2685
+ svg.Mouse = new function() {
2686
+ this.events = [];
2687
+ this.hasEvents = function() {
2688
+ return this.events.length != 0;
2689
+ };
2690
+ this.onclick = function(x, y) {
2691
+ this.events.push({
2692
+ type: "onclick",
2693
+ x,
2694
+ y,
2695
+ run: function(e) {
2696
+ if (e.onclick) e.onclick();
2697
+ }
2698
+ });
2699
+ };
2700
+ this.onmousemove = function(x, y) {
2701
+ this.events.push({
2702
+ type: "onmousemove",
2703
+ x,
2704
+ y,
2705
+ run: function(e) {
2706
+ if (e.onmousemove) e.onmousemove();
2707
+ }
2708
+ });
2709
+ };
2710
+ this.eventElements = [];
2711
+ this.checkPath = function(element, ctx2) {
2712
+ for (let i2 = 0; i2 < this.events.length; i2++) {
2713
+ let e = this.events[i2];
2714
+ if (ctx2.isPointInPath && ctx2.isPointInPath(e.x, e.y)) this.eventElements[i2] = element;
2715
+ }
2716
+ };
2717
+ this.checkBoundingBox = function(element, bb) {
2718
+ for (let i2 = 0; i2 < this.events.length; i2++) {
2719
+ let e = this.events[i2];
2720
+ if (bb.isPointInBox(e.x, e.y)) this.eventElements[i2] = element;
2721
+ }
2722
+ };
2723
+ this.runEvents = function() {
2724
+ svg.ctx.canvas.style.cursor = "";
2725
+ for (let i2 = 0; i2 < this.events.length; i2++) {
2726
+ let e = this.events[i2];
2727
+ let element = this.eventElements[i2];
2728
+ while (element) {
2729
+ e.run(element);
2730
+ element = element.parent;
2731
+ }
2732
+ }
2733
+ this.events = [];
2734
+ this.eventElements = [];
2735
+ };
2736
+ }();
2737
+ return svg;
2738
+ }
2739
+ }).call(target, target);
2740
+ if (typeof CanvasRenderingContext2D != "undefined") {
2741
+ CanvasRenderingContext2D.prototype.drawSvg = function(s, dx, dy, dw, dh) {
2742
+ canvg(this.canvas, s, {
2743
+ ignoreMouse: true,
2744
+ ignoreAnimation: true,
2745
+ ignoreDimensions: true,
2746
+ ignoreClear: true,
2747
+ offsetX: dx,
2748
+ offsetY: dy,
2749
+ scaleWidth: dw,
2750
+ scaleHeight: dh
2751
+ });
2752
+ };
2753
+ }
2754
+ return canvg;
2755
+ }
2756
+ export {
2757
+ createCanvgRuntime
2758
+ };
2759
+ //# sourceMappingURL=canvg-runtime-UR3JNX5Q.js.map