@metagl/sdk-render 1.0.12 → 1.0.14

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.
@@ -0,0 +1,3519 @@
1
+ /*
2
+ html2canvas 0.5.0-beta3 <http://html2canvas.hertzen.com>
3
+ Copyright (c) 2016 Niklas von Hertzen
4
+
5
+ Released under License
6
+ */
7
+
8
+ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.html2canvas=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
9
+ (function (global){
10
+ /*! http://mths.be/punycode v1.2.4 by @mathias */
11
+ ;(function(root) {
12
+
13
+ /** Detect free variables */
14
+ var freeExports = typeof exports == 'object' && exports;
15
+ var freeModule = typeof module == 'object' && module &&
16
+ module.exports == freeExports && module;
17
+ var freeGlobal = typeof global == 'object' && global;
18
+ if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
19
+ root = freeGlobal;
20
+ }
21
+
22
+ /**
23
+ * The `punycode` object.
24
+ * @name punycode
25
+ * @type Object
26
+ */
27
+ var punycode,
28
+
29
+ /** Highest positive signed 32-bit float value */
30
+ maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
31
+
32
+ /** Bootstring parameters */
33
+ base = 36,
34
+ tMin = 1,
35
+ tMax = 26,
36
+ skew = 38,
37
+ damp = 700,
38
+ initialBias = 72,
39
+ initialN = 128, // 0x80
40
+ delimiter = '-', // '\x2D'
41
+
42
+ /** Regular expressions */
43
+ regexPunycode = /^xn--/,
44
+ regexNonASCII = /[^ -~]/, // unprintable ASCII chars + non-ASCII chars
45
+ regexSeparators = /\x2E|\u3002|\uFF0E|\uFF61/g, // RFC 3490 separators
46
+
47
+ /** Error messages */
48
+ errors = {
49
+ 'overflow': 'Overflow: input needs wider integers to process',
50
+ 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
51
+ 'invalid-input': 'Invalid input'
52
+ },
53
+
54
+ /** Convenience shortcuts */
55
+ baseMinusTMin = base - tMin,
56
+ floor = Math.floor,
57
+ stringFromCharCode = String.fromCharCode,
58
+
59
+ /** Temporary variable */
60
+ key;
61
+
62
+ /*--------------------------------------------------------------------------*/
63
+
64
+ /**
65
+ * A generic error utility function.
66
+ * @private
67
+ * @param {String} type The error type.
68
+ * @returns {Error} Throws a `RangeError` with the applicable error message.
69
+ */
70
+ function error(type) {
71
+ throw RangeError(errors[type]);
72
+ }
73
+
74
+ /**
75
+ * A generic `Array#map` utility function.
76
+ * @private
77
+ * @param {Array} array The array to iterate over.
78
+ * @param {Function} callback The function that gets called for every array
79
+ * item.
80
+ * @returns {Array} A new array of values returned by the callback function.
81
+ */
82
+ function map(array, fn) {
83
+ var length = array.length;
84
+ while (length--) {
85
+ array[length] = fn(array[length]);
86
+ }
87
+ return array;
88
+ }
89
+
90
+ /**
91
+ * A simple `Array#map`-like wrapper to work with domain name strings.
92
+ * @private
93
+ * @param {String} domain The domain name.
94
+ * @param {Function} callback The function that gets called for every
95
+ * character.
96
+ * @returns {Array} A new string of characters returned by the callback
97
+ * function.
98
+ */
99
+ function mapDomain(string, fn) {
100
+ return map(string.split(regexSeparators), fn).join('.');
101
+ }
102
+
103
+ /**
104
+ * Creates an array containing the numeric code points of each Unicode
105
+ * character in the string. While JavaScript uses UCS-2 internally,
106
+ * this function will convert a pair of surrogate halves (each of which
107
+ * UCS-2 exposes as separate characters) into a single code point,
108
+ * matching UTF-16.
109
+ * @see `punycode.ucs2.encode`
110
+ * @see <http://mathiasbynens.be/notes/javascript-encoding>
111
+ * @memberOf punycode.ucs2
112
+ * @name decode
113
+ * @param {String} string The Unicode input string (UCS-2).
114
+ * @returns {Array} The new array of code points.
115
+ */
116
+ function ucs2decode(string) {
117
+ var output = [],
118
+ counter = 0,
119
+ length = string.length,
120
+ value,
121
+ extra;
122
+ while (counter < length) {
123
+ value = string.charCodeAt(counter++);
124
+ if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
125
+ // high surrogate, and there is a next character
126
+ extra = string.charCodeAt(counter++);
127
+ if ((extra & 0xFC00) == 0xDC00) { // low surrogate
128
+ output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
129
+ } else {
130
+ // unmatched surrogate; only append this code unit, in case the next
131
+ // code unit is the high surrogate of a surrogate pair
132
+ output.push(value);
133
+ counter--;
134
+ }
135
+ } else {
136
+ output.push(value);
137
+ }
138
+ }
139
+ return output;
140
+ }
141
+
142
+ /**
143
+ * Creates a string based on an array of numeric code points.
144
+ * @see `punycode.ucs2.decode`
145
+ * @memberOf punycode.ucs2
146
+ * @name encode
147
+ * @param {Array} codePoints The array of numeric code points.
148
+ * @returns {String} The new Unicode string (UCS-2).
149
+ */
150
+ function ucs2encode(array) {
151
+ return map(array, function(value) {
152
+ var output = '';
153
+ if (value > 0xFFFF) {
154
+ value -= 0x10000;
155
+ output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
156
+ value = 0xDC00 | value & 0x3FF;
157
+ }
158
+ output += stringFromCharCode(value);
159
+ return output;
160
+ }).join('');
161
+ }
162
+
163
+ /**
164
+ * Converts a basic code point into a digit/integer.
165
+ * @see `digitToBasic()`
166
+ * @private
167
+ * @param {Number} codePoint The basic numeric code point value.
168
+ * @returns {Number} The numeric value of a basic code point (for use in
169
+ * representing integers) in the range `0` to `base - 1`, or `base` if
170
+ * the code point does not represent a value.
171
+ */
172
+ function basicToDigit(codePoint) {
173
+ if (codePoint - 48 < 10) {
174
+ return codePoint - 22;
175
+ }
176
+ if (codePoint - 65 < 26) {
177
+ return codePoint - 65;
178
+ }
179
+ if (codePoint - 97 < 26) {
180
+ return codePoint - 97;
181
+ }
182
+ return base;
183
+ }
184
+
185
+ /**
186
+ * Converts a digit/integer into a basic code point.
187
+ * @see `basicToDigit()`
188
+ * @private
189
+ * @param {Number} digit The numeric value of a basic code point.
190
+ * @returns {Number} The basic code point whose value (when used for
191
+ * representing integers) is `digit`, which needs to be in the range
192
+ * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
193
+ * used; else, the lowercase form is used. The behavior is undefined
194
+ * if `flag` is non-zero and `digit` has no uppercase form.
195
+ */
196
+ function digitToBasic(digit, flag) {
197
+ // 0..25 map to ASCII a..z or A..Z
198
+ // 26..35 map to ASCII 0..9
199
+ return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
200
+ }
201
+
202
+ /**
203
+ * Bias adaptation function as per section 3.4 of RFC 3492.
204
+ * http://tools.ietf.org/html/rfc3492#section-3.4
205
+ * @private
206
+ */
207
+ function adapt(delta, numPoints, firstTime) {
208
+ var k = 0;
209
+ delta = firstTime ? floor(delta / damp) : delta >> 1;
210
+ delta += floor(delta / numPoints);
211
+ for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
212
+ delta = floor(delta / baseMinusTMin);
213
+ }
214
+ return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
215
+ }
216
+
217
+ /**
218
+ * Converts a Punycode string of ASCII-only symbols to a string of Unicode
219
+ * symbols.
220
+ * @memberOf punycode
221
+ * @param {String} input The Punycode string of ASCII-only symbols.
222
+ * @returns {String} The resulting string of Unicode symbols.
223
+ */
224
+ function decode(input) {
225
+ // Don't use UCS-2
226
+ var output = [],
227
+ inputLength = input.length,
228
+ out,
229
+ i = 0,
230
+ n = initialN,
231
+ bias = initialBias,
232
+ basic,
233
+ j,
234
+ index,
235
+ oldi,
236
+ w,
237
+ k,
238
+ digit,
239
+ t,
240
+ /** Cached calculation results */
241
+ baseMinusT;
242
+
243
+ // Handle the basic code points: let `basic` be the number of input code
244
+ // points before the last delimiter, or `0` if there is none, then copy
245
+ // the first basic code points to the output.
246
+
247
+ basic = input.lastIndexOf(delimiter);
248
+ if (basic < 0) {
249
+ basic = 0;
250
+ }
251
+
252
+ for (j = 0; j < basic; ++j) {
253
+ // if it's not a basic code point
254
+ if (input.charCodeAt(j) >= 0x80) {
255
+ error('not-basic');
256
+ }
257
+ output.push(input.charCodeAt(j));
258
+ }
259
+
260
+ // Main decoding loop: start just after the last delimiter if any basic code
261
+ // points were copied; start at the beginning otherwise.
262
+
263
+ for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
264
+
265
+ // `index` is the index of the next character to be consumed.
266
+ // Decode a generalized variable-length integer into `delta`,
267
+ // which gets added to `i`. The overflow checking is easier
268
+ // if we increase `i` as we go, then subtract off its starting
269
+ // value at the end to obtain `delta`.
270
+ for (oldi = i, w = 1, k = base; /* no condition */; k += base) {
271
+
272
+ if (index >= inputLength) {
273
+ error('invalid-input');
274
+ }
275
+
276
+ digit = basicToDigit(input.charCodeAt(index++));
277
+
278
+ if (digit >= base || digit > floor((maxInt - i) / w)) {
279
+ error('overflow');
280
+ }
281
+
282
+ i += digit * w;
283
+ t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
284
+
285
+ if (digit < t) {
286
+ break;
287
+ }
288
+
289
+ baseMinusT = base - t;
290
+ if (w > floor(maxInt / baseMinusT)) {
291
+ error('overflow');
292
+ }
293
+
294
+ w *= baseMinusT;
295
+
296
+ }
297
+
298
+ out = output.length + 1;
299
+ bias = adapt(i - oldi, out, oldi == 0);
300
+
301
+ // `i` was supposed to wrap around from `out` to `0`,
302
+ // incrementing `n` each time, so we'll fix that now:
303
+ if (floor(i / out) > maxInt - n) {
304
+ error('overflow');
305
+ }
306
+
307
+ n += floor(i / out);
308
+ i %= out;
309
+
310
+ // Insert `n` at position `i` of the output
311
+ output.splice(i++, 0, n);
312
+
313
+ }
314
+
315
+ return ucs2encode(output);
316
+ }
317
+
318
+ /**
319
+ * Converts a string of Unicode symbols to a Punycode string of ASCII-only
320
+ * symbols.
321
+ * @memberOf punycode
322
+ * @param {String} input The string of Unicode symbols.
323
+ * @returns {String} The resulting Punycode string of ASCII-only symbols.
324
+ */
325
+ function encode(input) {
326
+ var n,
327
+ delta,
328
+ handledCPCount,
329
+ basicLength,
330
+ bias,
331
+ j,
332
+ m,
333
+ q,
334
+ k,
335
+ t,
336
+ currentValue,
337
+ output = [],
338
+ /** `inputLength` will hold the number of code points in `input`. */
339
+ inputLength,
340
+ /** Cached calculation results */
341
+ handledCPCountPlusOne,
342
+ baseMinusT,
343
+ qMinusT;
344
+
345
+ // Convert the input in UCS-2 to Unicode
346
+ input = ucs2decode(input);
347
+
348
+ // Cache the length
349
+ inputLength = input.length;
350
+
351
+ // Initialize the state
352
+ n = initialN;
353
+ delta = 0;
354
+ bias = initialBias;
355
+
356
+ // Handle the basic code points
357
+ for (j = 0; j < inputLength; ++j) {
358
+ currentValue = input[j];
359
+ if (currentValue < 0x80) {
360
+ output.push(stringFromCharCode(currentValue));
361
+ }
362
+ }
363
+
364
+ handledCPCount = basicLength = output.length;
365
+
366
+ // `handledCPCount` is the number of code points that have been handled;
367
+ // `basicLength` is the number of basic code points.
368
+
369
+ // Finish the basic string - if it is not empty - with a delimiter
370
+ if (basicLength) {
371
+ output.push(delimiter);
372
+ }
373
+
374
+ // Main encoding loop:
375
+ while (handledCPCount < inputLength) {
376
+
377
+ // All non-basic code points < n have been handled already. Find the next
378
+ // larger one:
379
+ for (m = maxInt, j = 0; j < inputLength; ++j) {
380
+ currentValue = input[j];
381
+ if (currentValue >= n && currentValue < m) {
382
+ m = currentValue;
383
+ }
384
+ }
385
+
386
+ // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
387
+ // but guard against overflow
388
+ handledCPCountPlusOne = handledCPCount + 1;
389
+ if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
390
+ error('overflow');
391
+ }
392
+
393
+ delta += (m - n) * handledCPCountPlusOne;
394
+ n = m;
395
+
396
+ for (j = 0; j < inputLength; ++j) {
397
+ currentValue = input[j];
398
+
399
+ if (currentValue < n && ++delta > maxInt) {
400
+ error('overflow');
401
+ }
402
+
403
+ if (currentValue == n) {
404
+ // Represent delta as a generalized variable-length integer
405
+ for (q = delta, k = base; /* no condition */; k += base) {
406
+ t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
407
+ if (q < t) {
408
+ break;
409
+ }
410
+ qMinusT = q - t;
411
+ baseMinusT = base - t;
412
+ output.push(
413
+ stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
414
+ );
415
+ q = floor(qMinusT / baseMinusT);
416
+ }
417
+
418
+ output.push(stringFromCharCode(digitToBasic(q, 0)));
419
+ bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
420
+ delta = 0;
421
+ ++handledCPCount;
422
+ }
423
+ }
424
+
425
+ ++delta;
426
+ ++n;
427
+
428
+ }
429
+ return output.join('');
430
+ }
431
+
432
+ /**
433
+ * Converts a Punycode string representing a domain name to Unicode. Only the
434
+ * Punycoded parts of the domain name will be converted, i.e. it doesn't
435
+ * matter if you call it on a string that has already been converted to
436
+ * Unicode.
437
+ * @memberOf punycode
438
+ * @param {String} domain The Punycode domain name to convert to Unicode.
439
+ * @returns {String} The Unicode representation of the given Punycode
440
+ * string.
441
+ */
442
+ function toUnicode(domain) {
443
+ return mapDomain(domain, function(string) {
444
+ return regexPunycode.test(string)
445
+ ? decode(string.slice(4).toLowerCase())
446
+ : string;
447
+ });
448
+ }
449
+
450
+ /**
451
+ * Converts a Unicode string representing a domain name to Punycode. Only the
452
+ * non-ASCII parts of the domain name will be converted, i.e. it doesn't
453
+ * matter if you call it with a domain that's already in ASCII.
454
+ * @memberOf punycode
455
+ * @param {String} domain The domain name to convert, as a Unicode string.
456
+ * @returns {String} The Punycode representation of the given domain name.
457
+ */
458
+ function toASCII(domain) {
459
+ return mapDomain(domain, function(string) {
460
+ return regexNonASCII.test(string)
461
+ ? 'xn--' + encode(string)
462
+ : string;
463
+ });
464
+ }
465
+
466
+ /*--------------------------------------------------------------------------*/
467
+
468
+ /** Define the public API */
469
+ punycode = {
470
+ /**
471
+ * A string representing the current Punycode.js version number.
472
+ * @memberOf punycode
473
+ * @type String
474
+ */
475
+ 'version': '1.2.4',
476
+ /**
477
+ * An object of methods to convert from JavaScript's internal character
478
+ * representation (UCS-2) to Unicode code points, and back.
479
+ * @see <http://mathiasbynens.be/notes/javascript-encoding>
480
+ * @memberOf punycode
481
+ * @type Object
482
+ */
483
+ 'ucs2': {
484
+ 'decode': ucs2decode,
485
+ 'encode': ucs2encode
486
+ },
487
+ 'decode': decode,
488
+ 'encode': encode,
489
+ 'toASCII': toASCII,
490
+ 'toUnicode': toUnicode
491
+ };
492
+
493
+ /** Expose `punycode` */
494
+ // Some AMD build optimizers, like r.js, check for specific condition patterns
495
+ // like the following:
496
+ if (
497
+ typeof define == 'function' &&
498
+ typeof define.amd == 'object' &&
499
+ define.amd
500
+ ) {
501
+ define('punycode', function() {
502
+ return punycode;
503
+ });
504
+ } else if (freeExports && !freeExports.nodeType) {
505
+ if (freeModule) { // in Node.js or RingoJS v0.8.0+
506
+ freeModule.exports = punycode;
507
+ } else { // in Narwhal or RingoJS v0.7.0-
508
+ for (key in punycode) {
509
+ punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
510
+ }
511
+ }
512
+ } else { // in Rhino or a web browser
513
+ root.punycode = punycode;
514
+ }
515
+
516
+ }(this));
517
+
518
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
519
+ },{}],2:[function(_dereq_,module,exports){
520
+ var log = _dereq_('./log');
521
+
522
+ function restoreOwnerScroll(ownerDocument, x, y) {
523
+ if (ownerDocument.defaultView && (x !== ownerDocument.defaultView.pageXOffset || y !== ownerDocument.defaultView.pageYOffset)) {
524
+ ownerDocument.defaultView.scrollTo(x, y);
525
+ }
526
+ }
527
+
528
+ function cloneCanvasContents(canvas, clonedCanvas) {
529
+ try {
530
+ if (clonedCanvas) {
531
+ clonedCanvas.width = canvas.width;
532
+ clonedCanvas.height = canvas.height;
533
+ clonedCanvas.getContext("2d").putImageData(canvas.getContext("2d").getImageData(0, 0, canvas.width, canvas.height), 0, 0);
534
+ }
535
+ } catch(e) {
536
+ log("Unable to copy canvas content from", canvas, e);
537
+ }
538
+ }
539
+
540
+ function cloneNode(node, javascriptEnabled) {
541
+ var clone = node.nodeType === 3 ? document.createTextNode(node.nodeValue) : node.cloneNode(false);
542
+
543
+ var child = node.firstChild;
544
+ while(child) {
545
+ if (javascriptEnabled === true || child.nodeType !== 1 || child.nodeName !== 'SCRIPT') {
546
+ clone.appendChild(cloneNode(child, javascriptEnabled));
547
+ }
548
+ child = child.nextSibling;
549
+ }
550
+
551
+ if (node.nodeType === 1) {
552
+ clone._scrollTop = node.scrollTop;
553
+ clone._scrollLeft = node.scrollLeft;
554
+ if (node.nodeName === "CANVAS") {
555
+ cloneCanvasContents(node, clone);
556
+ } else if (node.nodeName === "TEXTAREA" || node.nodeName === "SELECT") {
557
+ clone.value = node.value;
558
+ }
559
+ }
560
+
561
+ return clone;
562
+ }
563
+
564
+ function initNode(node) {
565
+ if (node.nodeType === 1) {
566
+ node.scrollTop = node._scrollTop;
567
+ node.scrollLeft = node._scrollLeft;
568
+
569
+ var child = node.firstChild;
570
+ while(child) {
571
+ initNode(child);
572
+ child = child.nextSibling;
573
+ }
574
+ }
575
+ }
576
+
577
+ module.exports = function(ownerDocument, containerDocument, width, height, options, x ,y) {
578
+ var documentElement = cloneNode(ownerDocument.documentElement, options.javascriptEnabled);
579
+ var container = containerDocument.createElement("iframe");
580
+
581
+ container.className = "html2canvas-container";
582
+ container.style.visibility = "hidden";
583
+ container.style.position = "fixed";
584
+ container.style.left = "-10000px";
585
+ container.style.top = "0px";
586
+ container.style.border = "0";
587
+ container.width = width;
588
+ container.height = height;
589
+ container.scrolling = "no"; // ios won't scroll without it
590
+ containerDocument.body.appendChild(container);
591
+
592
+ return new Promise(function(resolve) {
593
+ var documentClone = container.contentWindow.document;
594
+
595
+ /* Chrome doesn't detect relative background-images assigned in inline <style> sheets when fetched through getComputedStyle
596
+ if window url is about:blank, we can assign the url to current by writing onto the document
597
+ */
598
+ container.contentWindow.onload = container.onload = function() {
599
+ var interval = setInterval(function() {
600
+ if (documentClone.body.childNodes.length > 0) {
601
+ initNode(documentClone.documentElement);
602
+ clearInterval(interval);
603
+ if (options.type === "view") {
604
+ container.contentWindow.scrollTo(x, y);
605
+ if ((/(iPad|iPhone|iPod)/g).test(navigator.userAgent) && (container.contentWindow.scrollY !== y || container.contentWindow.scrollX !== x)) {
606
+ documentClone.documentElement.style.top = (-y) + "px";
607
+ documentClone.documentElement.style.left = (-x) + "px";
608
+ documentClone.documentElement.style.position = 'absolute';
609
+ }
610
+ }
611
+ resolve(container);
612
+ }
613
+ }, 50);
614
+ };
615
+
616
+ documentClone.open();
617
+ documentClone.write("<!DOCTYPE html><html></html>");
618
+ // Chrome scrolls the parent document for some reason after the write to the cloned window???
619
+ restoreOwnerScroll(ownerDocument, x, y);
620
+ documentClone.replaceChild(documentClone.adoptNode(documentElement), documentClone.documentElement);
621
+ documentClone.close();
622
+ });
623
+ };
624
+
625
+ },{"./log":13}],3:[function(_dereq_,module,exports){
626
+ // http://dev.w3.org/csswg/css-color/
627
+
628
+ function Color(value) {
629
+ this.r = 0;
630
+ this.g = 0;
631
+ this.b = 0;
632
+ this.a = null;
633
+ var result = this.fromArray(value) ||
634
+ this.namedColor(value) ||
635
+ this.rgb(value) ||
636
+ this.rgba(value) ||
637
+ this.hex6(value) ||
638
+ this.hex3(value);
639
+ }
640
+
641
+ Color.prototype.darken = function(amount) {
642
+ var a = 1 - amount;
643
+ return new Color([
644
+ Math.round(this.r * a),
645
+ Math.round(this.g * a),
646
+ Math.round(this.b * a),
647
+ this.a
648
+ ]);
649
+ };
650
+
651
+ Color.prototype.isTransparent = function() {
652
+ return this.a === 0;
653
+ };
654
+
655
+ Color.prototype.isBlack = function() {
656
+ return this.r === 0 && this.g === 0 && this.b === 0;
657
+ };
658
+
659
+ Color.prototype.fromArray = function(array) {
660
+ if (Array.isArray(array)) {
661
+ this.r = Math.min(array[0], 255);
662
+ this.g = Math.min(array[1], 255);
663
+ this.b = Math.min(array[2], 255);
664
+ if (array.length > 3) {
665
+ this.a = array[3];
666
+ }
667
+ }
668
+
669
+ return (Array.isArray(array));
670
+ };
671
+
672
+ var _hex3 = /^#([a-f0-9]{3})$/i;
673
+
674
+ Color.prototype.hex3 = function(value) {
675
+ var match = null;
676
+ if ((match = value.match(_hex3)) !== null) {
677
+ this.r = parseInt(match[1][0] + match[1][0], 16);
678
+ this.g = parseInt(match[1][1] + match[1][1], 16);
679
+ this.b = parseInt(match[1][2] + match[1][2], 16);
680
+ }
681
+ return match !== null;
682
+ };
683
+
684
+ var _hex6 = /^#([a-f0-9]{6})$/i;
685
+
686
+ Color.prototype.hex6 = function(value) {
687
+ var match = null;
688
+ if ((match = value.match(_hex6)) !== null) {
689
+ this.r = parseInt(match[1].substring(0, 2), 16);
690
+ this.g = parseInt(match[1].substring(2, 4), 16);
691
+ this.b = parseInt(match[1].substring(4, 6), 16);
692
+ }
693
+ return match !== null;
694
+ };
695
+
696
+
697
+ var _rgb = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/;
698
+
699
+ Color.prototype.rgb = function(value) {
700
+ var match = null;
701
+ if ((match = value.match(_rgb)) !== null) {
702
+ this.r = Number(match[1]);
703
+ this.g = Number(match[2]);
704
+ this.b = Number(match[3]);
705
+ }
706
+ return match !== null;
707
+ };
708
+
709
+ var _rgba = /^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d?\.?\d+)\s*\)$/;
710
+
711
+ Color.prototype.rgba = function(value) {
712
+ var match = null;
713
+ if ((match = value.match(_rgba)) !== null) {
714
+ this.r = Number(match[1]);
715
+ this.g = Number(match[2]);
716
+ this.b = Number(match[3]);
717
+ this.a = Number(match[4]);
718
+ }
719
+ return match !== null;
720
+ };
721
+
722
+ Color.prototype.toString = function() {
723
+ return this.a !== null && this.a !== 1 ?
724
+ "rgba(" + [this.r, this.g, this.b, this.a].join(",") + ")" :
725
+ "rgb(" + [this.r, this.g, this.b].join(",") + ")";
726
+ };
727
+
728
+ Color.prototype.namedColor = function(value) {
729
+ value = value.toLowerCase();
730
+ var color = colors[value];
731
+ if (color) {
732
+ this.r = color[0];
733
+ this.g = color[1];
734
+ this.b = color[2];
735
+ } else if (value === "transparent") {
736
+ this.r = this.g = this.b = this.a = 0;
737
+ return true;
738
+ }
739
+
740
+ return !!color;
741
+ };
742
+
743
+ Color.prototype.isColor = true;
744
+
745
+ // JSON.stringify([].slice.call($$('.named-color-table tr'), 1).map(function(row) { return [row.childNodes[3].textContent, row.childNodes[5].textContent.trim().split(",").map(Number)] }).reduce(function(data, row) {data[row[0]] = row[1]; return data}, {}))
746
+ var colors = {
747
+ "aliceblue": [240, 248, 255],
748
+ "antiquewhite": [250, 235, 215],
749
+ "aqua": [0, 255, 255],
750
+ "aquamarine": [127, 255, 212],
751
+ "azure": [240, 255, 255],
752
+ "beige": [245, 245, 220],
753
+ "bisque": [255, 228, 196],
754
+ "black": [0, 0, 0],
755
+ "blanchedalmond": [255, 235, 205],
756
+ "blue": [0, 0, 255],
757
+ "blueviolet": [138, 43, 226],
758
+ "brown": [165, 42, 42],
759
+ "burlywood": [222, 184, 135],
760
+ "cadetblue": [95, 158, 160],
761
+ "chartreuse": [127, 255, 0],
762
+ "chocolate": [210, 105, 30],
763
+ "coral": [255, 127, 80],
764
+ "cornflowerblue": [100, 149, 237],
765
+ "cornsilk": [255, 248, 220],
766
+ "crimson": [220, 20, 60],
767
+ "cyan": [0, 255, 255],
768
+ "darkblue": [0, 0, 139],
769
+ "darkcyan": [0, 139, 139],
770
+ "darkgoldenrod": [184, 134, 11],
771
+ "darkgray": [169, 169, 169],
772
+ "darkgreen": [0, 100, 0],
773
+ "darkgrey": [169, 169, 169],
774
+ "darkkhaki": [189, 183, 107],
775
+ "darkmagenta": [139, 0, 139],
776
+ "darkolivegreen": [85, 107, 47],
777
+ "darkorange": [255, 140, 0],
778
+ "darkorchid": [153, 50, 204],
779
+ "darkred": [139, 0, 0],
780
+ "darksalmon": [233, 150, 122],
781
+ "darkseagreen": [143, 188, 143],
782
+ "darkslateblue": [72, 61, 139],
783
+ "darkslategray": [47, 79, 79],
784
+ "darkslategrey": [47, 79, 79],
785
+ "darkturquoise": [0, 206, 209],
786
+ "darkviolet": [148, 0, 211],
787
+ "deeppink": [255, 20, 147],
788
+ "deepskyblue": [0, 191, 255],
789
+ "dimgray": [105, 105, 105],
790
+ "dimgrey": [105, 105, 105],
791
+ "dodgerblue": [30, 144, 255],
792
+ "firebrick": [178, 34, 34],
793
+ "floralwhite": [255, 250, 240],
794
+ "forestgreen": [34, 139, 34],
795
+ "fuchsia": [255, 0, 255],
796
+ "gainsboro": [220, 220, 220],
797
+ "ghostwhite": [248, 248, 255],
798
+ "gold": [255, 215, 0],
799
+ "goldenrod": [218, 165, 32],
800
+ "gray": [128, 128, 128],
801
+ "green": [0, 128, 0],
802
+ "greenyellow": [173, 255, 47],
803
+ "grey": [128, 128, 128],
804
+ "honeydew": [240, 255, 240],
805
+ "hotpink": [255, 105, 180],
806
+ "indianred": [205, 92, 92],
807
+ "indigo": [75, 0, 130],
808
+ "ivory": [255, 255, 240],
809
+ "khaki": [240, 230, 140],
810
+ "lavender": [230, 230, 250],
811
+ "lavenderblush": [255, 240, 245],
812
+ "lawngreen": [124, 252, 0],
813
+ "lemonchiffon": [255, 250, 205],
814
+ "lightblue": [173, 216, 230],
815
+ "lightcoral": [240, 128, 128],
816
+ "lightcyan": [224, 255, 255],
817
+ "lightgoldenrodyellow": [250, 250, 210],
818
+ "lightgray": [211, 211, 211],
819
+ "lightgreen": [144, 238, 144],
820
+ "lightgrey": [211, 211, 211],
821
+ "lightpink": [255, 182, 193],
822
+ "lightsalmon": [255, 160, 122],
823
+ "lightseagreen": [32, 178, 170],
824
+ "lightskyblue": [135, 206, 250],
825
+ "lightslategray": [119, 136, 153],
826
+ "lightslategrey": [119, 136, 153],
827
+ "lightsteelblue": [176, 196, 222],
828
+ "lightyellow": [255, 255, 224],
829
+ "lime": [0, 255, 0],
830
+ "limegreen": [50, 205, 50],
831
+ "linen": [250, 240, 230],
832
+ "magenta": [255, 0, 255],
833
+ "maroon": [128, 0, 0],
834
+ "mediumaquamarine": [102, 205, 170],
835
+ "mediumblue": [0, 0, 205],
836
+ "mediumorchid": [186, 85, 211],
837
+ "mediumpurple": [147, 112, 219],
838
+ "mediumseagreen": [60, 179, 113],
839
+ "mediumslateblue": [123, 104, 238],
840
+ "mediumspringgreen": [0, 250, 154],
841
+ "mediumturquoise": [72, 209, 204],
842
+ "mediumvioletred": [199, 21, 133],
843
+ "midnightblue": [25, 25, 112],
844
+ "mintcream": [245, 255, 250],
845
+ "mistyrose": [255, 228, 225],
846
+ "moccasin": [255, 228, 181],
847
+ "navajowhite": [255, 222, 173],
848
+ "navy": [0, 0, 128],
849
+ "oldlace": [253, 245, 230],
850
+ "olive": [128, 128, 0],
851
+ "olivedrab": [107, 142, 35],
852
+ "orange": [255, 165, 0],
853
+ "orangered": [255, 69, 0],
854
+ "orchid": [218, 112, 214],
855
+ "palegoldenrod": [238, 232, 170],
856
+ "palegreen": [152, 251, 152],
857
+ "paleturquoise": [175, 238, 238],
858
+ "palevioletred": [219, 112, 147],
859
+ "papayawhip": [255, 239, 213],
860
+ "peachpuff": [255, 218, 185],
861
+ "peru": [205, 133, 63],
862
+ "pink": [255, 192, 203],
863
+ "plum": [221, 160, 221],
864
+ "powderblue": [176, 224, 230],
865
+ "purple": [128, 0, 128],
866
+ "rebeccapurple": [102, 51, 153],
867
+ "red": [255, 0, 0],
868
+ "rosybrown": [188, 143, 143],
869
+ "royalblue": [65, 105, 225],
870
+ "saddlebrown": [139, 69, 19],
871
+ "salmon": [250, 128, 114],
872
+ "sandybrown": [244, 164, 96],
873
+ "seagreen": [46, 139, 87],
874
+ "seashell": [255, 245, 238],
875
+ "sienna": [160, 82, 45],
876
+ "silver": [192, 192, 192],
877
+ "skyblue": [135, 206, 235],
878
+ "slateblue": [106, 90, 205],
879
+ "slategray": [112, 128, 144],
880
+ "slategrey": [112, 128, 144],
881
+ "snow": [255, 250, 250],
882
+ "springgreen": [0, 255, 127],
883
+ "steelblue": [70, 130, 180],
884
+ "tan": [210, 180, 140],
885
+ "teal": [0, 128, 128],
886
+ "thistle": [216, 191, 216],
887
+ "tomato": [255, 99, 71],
888
+ "turquoise": [64, 224, 208],
889
+ "violet": [238, 130, 238],
890
+ "wheat": [245, 222, 179],
891
+ "white": [255, 255, 255],
892
+ "whitesmoke": [245, 245, 245],
893
+ "yellow": [255, 255, 0],
894
+ "yellowgreen": [154, 205, 50]
895
+ };
896
+
897
+ module.exports = Color;
898
+
899
+ },{}],4:[function(_dereq_,module,exports){
900
+ var Support = _dereq_('./support');
901
+ var CanvasRenderer = _dereq_('./renderers/canvas');
902
+ var ImageLoader = _dereq_('./imageloader');
903
+ var NodeParser = _dereq_('./nodeparser');
904
+ var NodeContainer = _dereq_('./nodecontainer');
905
+ var log = _dereq_('./log');
906
+ var utils = _dereq_('./utils');
907
+ var createWindowClone = _dereq_('./clone');
908
+ var loadUrlDocument = _dereq_('./proxy').loadUrlDocument;
909
+ var getBounds = utils.getBounds;
910
+
911
+ var html2canvasNodeAttribute = "data-html2canvas-node";
912
+ var html2canvasCloneIndex = 0;
913
+
914
+ function html2canvas(nodeList, options) {
915
+ var index = html2canvasCloneIndex++;
916
+ options = options || {};
917
+ if (options.logging) {
918
+ log.options.logging = true;
919
+ log.options.start = Date.now();
920
+ }
921
+
922
+ options.async = typeof(options.async) === "undefined" ? true : options.async;
923
+ options.allowTaint = typeof(options.allowTaint) === "undefined" ? false : options.allowTaint;
924
+ options.removeContainer = typeof(options.removeContainer) === "undefined" ? true : options.removeContainer;
925
+ options.javascriptEnabled = typeof(options.javascriptEnabled) === "undefined" ? false : options.javascriptEnabled;
926
+ options.imageTimeout = typeof(options.imageTimeout) === "undefined" ? 10000 : options.imageTimeout;
927
+ options.renderer = typeof(options.renderer) === "function" ? options.renderer : CanvasRenderer;
928
+ options.strict = !!options.strict;
929
+
930
+ if (typeof(nodeList) === "string") {
931
+ if (typeof(options.proxy) !== "string") {
932
+ return Promise.reject("Proxy must be used when rendering url");
933
+ }
934
+ var width = options.width != null ? options.width : window.innerWidth;
935
+ var height = options.height != null ? options.height : window.innerHeight;
936
+ return loadUrlDocument(absoluteUrl(nodeList), options.proxy, document, width, height, options).then(function(container) {
937
+ return renderWindow(container.contentWindow.document.documentElement, container, options, width, height);
938
+ });
939
+ }
940
+
941
+ var node = ((nodeList === undefined) ? [document.documentElement] : ((nodeList.length) ? nodeList : [nodeList]))[0];
942
+ node.setAttribute(html2canvasNodeAttribute + index, index);
943
+ return renderDocument(node.ownerDocument, options, node.ownerDocument.defaultView.innerWidth, node.ownerDocument.defaultView.innerHeight, index).then(function(canvas) {
944
+ if (typeof(options.onrendered) === "function") {
945
+ log("options.onrendered is deprecated, html2canvas returns a Promise containing the canvas");
946
+ options.onrendered(canvas);
947
+ }
948
+ return canvas;
949
+ });
950
+ }
951
+
952
+ html2canvas.CanvasRenderer = CanvasRenderer;
953
+ html2canvas.NodeContainer = NodeContainer;
954
+ html2canvas.log = log;
955
+ html2canvas.utils = utils;
956
+
957
+ var html2canvasExport = (typeof(document) === "undefined" || typeof(Object.create) !== "function" || typeof(document.createElement("canvas").getContext) !== "function") ? function() {
958
+ return Promise.reject("No canvas support");
959
+ } : html2canvas;
960
+
961
+ module.exports = html2canvasExport;
962
+
963
+ if (typeof(define) === 'function' && define.amd) {
964
+ define('html2canvas', [], function() {
965
+ return html2canvasExport;
966
+ });
967
+ }
968
+
969
+ function renderDocument(document, options, windowWidth, windowHeight, html2canvasIndex) {
970
+ return createWindowClone(document, document, windowWidth, windowHeight, options, document.defaultView.pageXOffset, document.defaultView.pageYOffset).then(function(container) {
971
+ log("Document cloned");
972
+ var attributeName = html2canvasNodeAttribute + html2canvasIndex;
973
+ var selector = "[" + attributeName + "='" + html2canvasIndex + "']";
974
+ document.querySelector(selector).removeAttribute(attributeName);
975
+ var clonedWindow = container.contentWindow;
976
+ var node = clonedWindow.document.querySelector(selector);
977
+ var oncloneHandler = (typeof(options.onclone) === "function") ? Promise.resolve(options.onclone(clonedWindow.document)) : Promise.resolve(true);
978
+ return oncloneHandler.then(function() {
979
+ return renderWindow(node, container, options, windowWidth, windowHeight);
980
+ });
981
+ });
982
+ }
983
+
984
+ function renderWindow(node, container, options, windowWidth, windowHeight) {
985
+ var clonedWindow = container.contentWindow;
986
+ var support = new Support(clonedWindow.document);
987
+ var imageLoader = new ImageLoader(options, support);
988
+ var bounds = getBounds(node);
989
+ var width = options.type === "view" ? windowWidth : documentWidth(clonedWindow.document);
990
+ var height = options.type === "view" ? windowHeight : documentHeight(clonedWindow.document);
991
+ var renderer = new options.renderer(width, height, imageLoader, options, document);
992
+ var parser = new NodeParser(node, renderer, support, imageLoader, options);
993
+ return parser.ready.then(function() {
994
+ log("Finished rendering");
995
+ var canvas;
996
+
997
+ if (options.type === "view") {
998
+ canvas = crop(renderer.canvas, {width: renderer.canvas.width, height: renderer.canvas.height, top: 0, left: 0, x: 0, y: 0});
999
+ } else if (node === clonedWindow.document.body || node === clonedWindow.document.documentElement || options.canvas != null) {
1000
+ canvas = renderer.canvas;
1001
+ } else {
1002
+ canvas = crop(renderer.canvas, {width: options.width != null ? options.width : bounds.width, height: options.height != null ? options.height : bounds.height, top: bounds.top, left: bounds.left, x: 0, y: 0});
1003
+ }
1004
+
1005
+ cleanupContainer(container, options);
1006
+ return canvas;
1007
+ });
1008
+ }
1009
+
1010
+ function cleanupContainer(container, options) {
1011
+ if (options.removeContainer) {
1012
+ container.parentNode.removeChild(container);
1013
+ log("Cleaned up container");
1014
+ }
1015
+ }
1016
+
1017
+ function crop(canvas, bounds) {
1018
+ var croppedCanvas = document.createElement("canvas");
1019
+ var x1 = Math.min(canvas.width - 1, Math.max(0, bounds.left));
1020
+ var x2 = Math.min(canvas.width, Math.max(1, bounds.left + bounds.width));
1021
+ var y1 = Math.min(canvas.height - 1, Math.max(0, bounds.top));
1022
+ var y2 = Math.min(canvas.height, Math.max(1, bounds.top + bounds.height));
1023
+ croppedCanvas.width = bounds.width;
1024
+ croppedCanvas.height = bounds.height;
1025
+ var width = x2-x1;
1026
+ var height = y2-y1;
1027
+ log("Cropping canvas at:", "left:", bounds.left, "top:", bounds.top, "width:", width, "height:", height);
1028
+ log("Resulting crop with width", bounds.width, "and height", bounds.height, "with x", x1, "and y", y1);
1029
+ croppedCanvas.getContext("2d").drawImage(canvas, x1, y1, width, height, bounds.x, bounds.y, width, height);
1030
+ return croppedCanvas;
1031
+ }
1032
+
1033
+ function documentWidth (doc) {
1034
+ return Math.max(
1035
+ Math.max(doc.body.scrollWidth, doc.documentElement.scrollWidth),
1036
+ Math.max(doc.body.offsetWidth, doc.documentElement.offsetWidth),
1037
+ Math.max(doc.body.clientWidth, doc.documentElement.clientWidth)
1038
+ );
1039
+ }
1040
+
1041
+ function documentHeight (doc) {
1042
+ return Math.max(
1043
+ Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight),
1044
+ Math.max(doc.body.offsetHeight, doc.documentElement.offsetHeight),
1045
+ Math.max(doc.body.clientHeight, doc.documentElement.clientHeight)
1046
+ );
1047
+ }
1048
+
1049
+ function absoluteUrl(url) {
1050
+ var link = document.createElement("a");
1051
+ link.href = url;
1052
+ link.href = link.href;
1053
+ return link;
1054
+ }
1055
+
1056
+ },{"./clone":2,"./imageloader":11,"./log":13,"./nodecontainer":14,"./nodeparser":15,"./proxy":16,"./renderers/canvas":20,"./support":22,"./utils":26}],5:[function(_dereq_,module,exports){
1057
+ var log = _dereq_('./log');
1058
+ var smallImage = _dereq_('./utils').smallImage;
1059
+
1060
+ function DummyImageContainer(src) {
1061
+ this.src = src;
1062
+ log("DummyImageContainer for", src);
1063
+ if (!this.promise || !this.image) {
1064
+ log("Initiating DummyImageContainer");
1065
+ DummyImageContainer.prototype.image = new Image();
1066
+ var image = this.image;
1067
+ DummyImageContainer.prototype.promise = new Promise(function(resolve, reject) {
1068
+ image.onload = resolve;
1069
+ image.onerror = reject;
1070
+ image.src = smallImage();
1071
+ if (image.complete === true) {
1072
+ resolve(image);
1073
+ }
1074
+ });
1075
+ }
1076
+ }
1077
+
1078
+ module.exports = DummyImageContainer;
1079
+
1080
+ },{"./log":13,"./utils":26}],6:[function(_dereq_,module,exports){
1081
+ var smallImage = _dereq_('./utils').smallImage;
1082
+
1083
+ function Font(family, size) {
1084
+ var container = document.createElement('div'),
1085
+ img = document.createElement('img'),
1086
+ span = document.createElement('span'),
1087
+ sampleText = 'Hidden Text',
1088
+ baseline,
1089
+ middle;
1090
+
1091
+ container.style.visibility = "hidden";
1092
+ container.style.fontFamily = family;
1093
+ container.style.fontSize = size;
1094
+ container.style.margin = 0;
1095
+ container.style.padding = 0;
1096
+
1097
+ document.body.appendChild(container);
1098
+
1099
+ img.src = smallImage();
1100
+ img.width = 1;
1101
+ img.height = 1;
1102
+
1103
+ img.style.margin = 0;
1104
+ img.style.padding = 0;
1105
+ img.style.verticalAlign = "baseline";
1106
+
1107
+ span.style.fontFamily = family;
1108
+ span.style.fontSize = size;
1109
+ span.style.margin = 0;
1110
+ span.style.padding = 0;
1111
+
1112
+ span.appendChild(document.createTextNode(sampleText));
1113
+ container.appendChild(span);
1114
+ container.appendChild(img);
1115
+ baseline = (img.offsetTop - span.offsetTop) + 1;
1116
+
1117
+ container.removeChild(span);
1118
+ container.appendChild(document.createTextNode(sampleText));
1119
+
1120
+ container.style.lineHeight = "normal";
1121
+ img.style.verticalAlign = "super";
1122
+
1123
+ middle = (img.offsetTop-container.offsetTop) + 1;
1124
+
1125
+ document.body.removeChild(container);
1126
+
1127
+ this.baseline = baseline;
1128
+ this.lineWidth = 1;
1129
+ this.middle = middle;
1130
+ }
1131
+
1132
+ module.exports = Font;
1133
+
1134
+ },{"./utils":26}],7:[function(_dereq_,module,exports){
1135
+ var Font = _dereq_('./font');
1136
+
1137
+ function FontMetrics() {
1138
+ this.data = {};
1139
+ }
1140
+
1141
+ FontMetrics.prototype.getMetrics = function(family, size) {
1142
+ if (this.data[family + "-" + size] === undefined) {
1143
+ this.data[family + "-" + size] = new Font(family, size);
1144
+ }
1145
+ return this.data[family + "-" + size];
1146
+ };
1147
+
1148
+ module.exports = FontMetrics;
1149
+
1150
+ },{"./font":6}],8:[function(_dereq_,module,exports){
1151
+ var utils = _dereq_('./utils');
1152
+ var getBounds = utils.getBounds;
1153
+ var loadUrlDocument = _dereq_('./proxy').loadUrlDocument;
1154
+
1155
+ function FrameContainer(container, sameOrigin, options) {
1156
+ this.image = null;
1157
+ this.src = container;
1158
+ var self = this;
1159
+ var bounds = getBounds(container);
1160
+ this.promise = (!sameOrigin ? this.proxyLoad(options.proxy, bounds, options) : new Promise(function(resolve) {
1161
+ if (container.contentWindow.document.URL === "about:blank" || container.contentWindow.document.documentElement == null) {
1162
+ container.contentWindow.onload = container.onload = function() {
1163
+ resolve(container);
1164
+ };
1165
+ } else {
1166
+ resolve(container);
1167
+ }
1168
+ })).then(function(container) {
1169
+ var html2canvas = _dereq_('./core');
1170
+ return html2canvas(container.contentWindow.document.documentElement, {type: 'view', width: container.width, height: container.height, proxy: options.proxy, javascriptEnabled: options.javascriptEnabled, removeContainer: options.removeContainer, allowTaint: options.allowTaint, imageTimeout: options.imageTimeout / 2});
1171
+ }).then(function(canvas) {
1172
+ return self.image = canvas;
1173
+ });
1174
+ }
1175
+
1176
+ FrameContainer.prototype.proxyLoad = function(proxy, bounds, options) {
1177
+ var container = this.src;
1178
+ return loadUrlDocument(container.src, proxy, container.ownerDocument, bounds.width, bounds.height, options);
1179
+ };
1180
+
1181
+ module.exports = FrameContainer;
1182
+
1183
+ },{"./core":4,"./proxy":16,"./utils":26}],9:[function(_dereq_,module,exports){
1184
+ function GradientContainer(imageData) {
1185
+ this.src = imageData.value;
1186
+ this.colorStops = [];
1187
+ this.type = null;
1188
+ this.x0 = 0.5;
1189
+ this.y0 = 0.5;
1190
+ this.x1 = 0.5;
1191
+ this.y1 = 0.5;
1192
+ this.promise = Promise.resolve(true);
1193
+ }
1194
+
1195
+ GradientContainer.TYPES = {
1196
+ LINEAR: 1,
1197
+ RADIAL: 2
1198
+ };
1199
+
1200
+ // TODO: support hsl[a], negative %/length values
1201
+ // TODO: support <angle> (e.g. -?\d{1,3}(?:\.\d+)deg, etc. : https://developer.mozilla.org/docs/Web/CSS/angle )
1202
+ GradientContainer.REGEXP_COLORSTOP = /^\s*(rgba?\(\s*\d{1,3},\s*\d{1,3},\s*\d{1,3}(?:,\s*[0-9\.]+)?\s*\)|[a-z]{3,20}|#[a-f0-9]{3,6})(?:\s+(\d{1,3}(?:\.\d+)?)(%|px)?)?(?:\s|$)/i;
1203
+
1204
+ module.exports = GradientContainer;
1205
+
1206
+ },{}],10:[function(_dereq_,module,exports){
1207
+ function ImageContainer(src, cors) {
1208
+ this.src = src;
1209
+ this.image = new Image();
1210
+ var self = this;
1211
+ this.tainted = null;
1212
+ this.promise = new Promise(function(resolve, reject) {
1213
+ self.image.onload = resolve;
1214
+ self.image.onerror = reject;
1215
+ if (cors) {
1216
+ self.image.crossOrigin = "anonymous";
1217
+ }
1218
+ self.image.src = src;
1219
+ if (self.image.complete === true) {
1220
+ resolve(self.image);
1221
+ }
1222
+ });
1223
+ }
1224
+
1225
+ module.exports = ImageContainer;
1226
+
1227
+ },{}],11:[function(_dereq_,module,exports){
1228
+ var log = _dereq_('./log');
1229
+ var ImageContainer = _dereq_('./imagecontainer');
1230
+ var DummyImageContainer = _dereq_('./dummyimagecontainer');
1231
+ var ProxyImageContainer = _dereq_('./proxyimagecontainer');
1232
+ var FrameContainer = _dereq_('./framecontainer');
1233
+ var SVGContainer = _dereq_('./svgcontainer');
1234
+ var SVGNodeContainer = _dereq_('./svgnodecontainer');
1235
+ var LinearGradientContainer = _dereq_('./lineargradientcontainer');
1236
+ var WebkitGradientContainer = _dereq_('./webkitgradientcontainer');
1237
+ var bind = _dereq_('./utils').bind;
1238
+
1239
+ function ImageLoader(options, support) {
1240
+ this.link = null;
1241
+ this.options = options;
1242
+ this.support = support;
1243
+ this.origin = this.getOrigin(window.location.href);
1244
+ }
1245
+
1246
+ ImageLoader.prototype.findImages = function(nodes) {
1247
+ var images = [];
1248
+ nodes.reduce(function(imageNodes, container) {
1249
+ switch(container.node.nodeName) {
1250
+ case "IMG":
1251
+ return imageNodes.concat([{
1252
+ args: [container.node.src],
1253
+ method: "url"
1254
+ }]);
1255
+ case "svg":
1256
+ case "IFRAME":
1257
+ return imageNodes.concat([{
1258
+ args: [container.node],
1259
+ method: container.node.nodeName
1260
+ }]);
1261
+ }
1262
+ return imageNodes;
1263
+ }, []).forEach(this.addImage(images, this.loadImage), this);
1264
+ return images;
1265
+ };
1266
+
1267
+ ImageLoader.prototype.findBackgroundImage = function(images, container) {
1268
+ container.parseBackgroundImages().filter(this.hasImageBackground).forEach(this.addImage(images, this.loadImage), this);
1269
+ return images;
1270
+ };
1271
+
1272
+ ImageLoader.prototype.addImage = function(images, callback) {
1273
+ return function(newImage) {
1274
+ newImage.args.forEach(function(image) {
1275
+ if (!this.imageExists(images, image)) {
1276
+ images.splice(0, 0, callback.call(this, newImage));
1277
+ log('Added image #' + (images.length), typeof(image) === "string" ? image.substring(0, 100) : image);
1278
+ }
1279
+ }, this);
1280
+ };
1281
+ };
1282
+
1283
+ ImageLoader.prototype.hasImageBackground = function(imageData) {
1284
+ return imageData.method !== "none";
1285
+ };
1286
+
1287
+ ImageLoader.prototype.loadImage = function(imageData) {
1288
+ if (imageData.method === "url") {
1289
+ var src = imageData.args[0];
1290
+ if (this.isSVG(src) && !this.support.svg && !this.options.allowTaint) {
1291
+ return new SVGContainer(src);
1292
+ } else if (src.match(/data:image\/.*;base64,/i)) {
1293
+ return new ImageContainer(src.replace(/url\(['"]{0,}|['"]{0,}\)$/ig, ''), false);
1294
+ } else if (this.isSameOrigin(src) || this.options.allowTaint === true || this.isSVG(src)) {
1295
+ return new ImageContainer(src, false);
1296
+ } else if (this.support.cors && !this.options.allowTaint && this.options.useCORS) {
1297
+ return new ImageContainer(src, true);
1298
+ } else if (this.options.proxy) {
1299
+ return new ProxyImageContainer(src, this.options.proxy);
1300
+ } else {
1301
+ return new DummyImageContainer(src);
1302
+ }
1303
+ } else if (imageData.method === "linear-gradient") {
1304
+ return new LinearGradientContainer(imageData);
1305
+ } else if (imageData.method === "gradient") {
1306
+ return new WebkitGradientContainer(imageData);
1307
+ } else if (imageData.method === "svg") {
1308
+ return new SVGNodeContainer(imageData.args[0], this.support.svg);
1309
+ } else if (imageData.method === "IFRAME") {
1310
+ return new FrameContainer(imageData.args[0], this.isSameOrigin(imageData.args[0].src), this.options);
1311
+ } else {
1312
+ return new DummyImageContainer(imageData);
1313
+ }
1314
+ };
1315
+
1316
+ ImageLoader.prototype.isSVG = function(src) {
1317
+ return src.substring(src.length - 3).toLowerCase() === "svg" || SVGContainer.prototype.isInline(src);
1318
+ };
1319
+
1320
+ ImageLoader.prototype.imageExists = function(images, src) {
1321
+ return images.some(function(image) {
1322
+ return image.src === src;
1323
+ });
1324
+ };
1325
+
1326
+ ImageLoader.prototype.isSameOrigin = function(url) {
1327
+ return (this.getOrigin(url) === this.origin);
1328
+ };
1329
+
1330
+ ImageLoader.prototype.getOrigin = function(url) {
1331
+ var link = this.link || (this.link = document.createElement("a"));
1332
+ link.href = url;
1333
+ link.href = link.href; // IE9, LOL! - http://jsfiddle.net/niklasvh/2e48b/
1334
+ return link.protocol + link.hostname + link.port;
1335
+ };
1336
+
1337
+ ImageLoader.prototype.getPromise = function(container) {
1338
+ return this.timeout(container, this.options.imageTimeout)['catch'](function() {
1339
+ var dummy = new DummyImageContainer(container.src);
1340
+ return dummy.promise.then(function(image) {
1341
+ container.image = image;
1342
+ });
1343
+ });
1344
+ };
1345
+
1346
+ ImageLoader.prototype.get = function(src) {
1347
+ var found = null;
1348
+ return this.images.some(function(img) {
1349
+ return (found = img).src === src;
1350
+ }) ? found : null;
1351
+ };
1352
+
1353
+ ImageLoader.prototype.fetch = function(nodes) {
1354
+ this.images = nodes.reduce(bind(this.findBackgroundImage, this), this.findImages(nodes));
1355
+ this.images.forEach(function(image, index) {
1356
+ image.promise.then(function() {
1357
+ log("Succesfully loaded image #"+ (index+1), image);
1358
+ }, function(e) {
1359
+ log("Failed loading image #"+ (index+1), image, e);
1360
+ });
1361
+ });
1362
+ this.ready = Promise.all(this.images.map(this.getPromise, this));
1363
+ log("Finished searching images");
1364
+ return this;
1365
+ };
1366
+
1367
+ ImageLoader.prototype.timeout = function(container, timeout) {
1368
+ var timer;
1369
+ var promise = Promise.race([container.promise, new Promise(function(res, reject) {
1370
+ timer = setTimeout(function() {
1371
+ log("Timed out loading image", container);
1372
+ reject(container);
1373
+ }, timeout);
1374
+ })]).then(function(container) {
1375
+ clearTimeout(timer);
1376
+ return container;
1377
+ });
1378
+ promise['catch'](function() {
1379
+ clearTimeout(timer);
1380
+ });
1381
+ return promise;
1382
+ };
1383
+
1384
+ module.exports = ImageLoader;
1385
+
1386
+ },{"./dummyimagecontainer":5,"./framecontainer":8,"./imagecontainer":10,"./lineargradientcontainer":12,"./log":13,"./proxyimagecontainer":17,"./svgcontainer":23,"./svgnodecontainer":24,"./utils":26,"./webkitgradientcontainer":27}],12:[function(_dereq_,module,exports){
1387
+ var GradientContainer = _dereq_('./gradientcontainer');
1388
+ var Color = _dereq_('./color');
1389
+
1390
+ function LinearGradientContainer(imageData) {
1391
+ GradientContainer.apply(this, arguments);
1392
+ this.type = GradientContainer.TYPES.LINEAR;
1393
+
1394
+ var hasDirection = LinearGradientContainer.REGEXP_DIRECTION.test( imageData.args[0] ) ||
1395
+ !GradientContainer.REGEXP_COLORSTOP.test( imageData.args[0] );
1396
+
1397
+ if (hasDirection) {
1398
+ imageData.args[0].split(/\s+/).reverse().forEach(function(position, index) {
1399
+ switch(position) {
1400
+ case "left":
1401
+ this.x0 = 0;
1402
+ this.x1 = 1;
1403
+ break;
1404
+ case "top":
1405
+ this.y0 = 0;
1406
+ this.y1 = 1;
1407
+ break;
1408
+ case "right":
1409
+ this.x0 = 1;
1410
+ this.x1 = 0;
1411
+ break;
1412
+ case "bottom":
1413
+ this.y0 = 1;
1414
+ this.y1 = 0;
1415
+ break;
1416
+ case "to":
1417
+ var y0 = this.y0;
1418
+ var x0 = this.x0;
1419
+ this.y0 = this.y1;
1420
+ this.x0 = this.x1;
1421
+ this.x1 = x0;
1422
+ this.y1 = y0;
1423
+ break;
1424
+ case "center":
1425
+ break; // centered by default
1426
+ // Firefox internally converts position keywords to percentages:
1427
+ // http://www.w3.org/TR/2010/WD-CSS2-20101207/colors.html#propdef-background-position
1428
+ default: // percentage or absolute length
1429
+ // TODO: support absolute start point positions (e.g., use bounds to convert px to a ratio)
1430
+ var ratio = parseFloat(position, 10) * 1e-2;
1431
+ if (isNaN(ratio)) { // invalid or unhandled value
1432
+ break;
1433
+ }
1434
+ if (index === 0) {
1435
+ this.y0 = ratio;
1436
+ this.y1 = 1 - this.y0;
1437
+ } else {
1438
+ this.x0 = ratio;
1439
+ this.x1 = 1 - this.x0;
1440
+ }
1441
+ break;
1442
+ }
1443
+ }, this);
1444
+ } else {
1445
+ this.y0 = 0;
1446
+ this.y1 = 1;
1447
+ }
1448
+
1449
+ this.colorStops = imageData.args.slice(hasDirection ? 1 : 0).map(function(colorStop) {
1450
+ var colorStopMatch = colorStop.match(GradientContainer.REGEXP_COLORSTOP);
1451
+ var value = +colorStopMatch[2];
1452
+ var unit = value === 0 ? "%" : colorStopMatch[3]; // treat "0" as "0%"
1453
+ return {
1454
+ color: new Color(colorStopMatch[1]),
1455
+ // TODO: support absolute stop positions (e.g., compute gradient line length & convert px to ratio)
1456
+ stop: unit === "%" ? value / 100 : null
1457
+ };
1458
+ });
1459
+
1460
+ if (this.colorStops[0].stop === null) {
1461
+ this.colorStops[0].stop = 0;
1462
+ }
1463
+
1464
+ if (this.colorStops[this.colorStops.length - 1].stop === null) {
1465
+ this.colorStops[this.colorStops.length - 1].stop = 1;
1466
+ }
1467
+
1468
+ // calculates and fills-in explicit stop positions when omitted from rule
1469
+ this.colorStops.forEach(function(colorStop, index) {
1470
+ if (colorStop.stop === null) {
1471
+ this.colorStops.slice(index).some(function(find, count) {
1472
+ if (find.stop !== null) {
1473
+ colorStop.stop = ((find.stop - this.colorStops[index - 1].stop) / (count + 1)) + this.colorStops[index - 1].stop;
1474
+ return true;
1475
+ } else {
1476
+ return false;
1477
+ }
1478
+ }, this);
1479
+ }
1480
+ }, this);
1481
+ }
1482
+
1483
+ LinearGradientContainer.prototype = Object.create(GradientContainer.prototype);
1484
+
1485
+ // TODO: support <angle> (e.g. -?\d{1,3}(?:\.\d+)deg, etc. : https://developer.mozilla.org/docs/Web/CSS/angle )
1486
+ LinearGradientContainer.REGEXP_DIRECTION = /^\s*(?:to|left|right|top|bottom|center|\d{1,3}(?:\.\d+)?%?)(?:\s|$)/i;
1487
+
1488
+ module.exports = LinearGradientContainer;
1489
+
1490
+ },{"./color":3,"./gradientcontainer":9}],13:[function(_dereq_,module,exports){
1491
+ var logger = function() {
1492
+ if (logger.options.logging && window.console && window.console.log) {
1493
+ Function.prototype.bind.call(window.console.log, (window.console)).apply(window.console, [(Date.now() - logger.options.start) + "ms", "html2canvas:"].concat([].slice.call(arguments, 0)));
1494
+ }
1495
+ };
1496
+
1497
+ logger.options = {logging: false};
1498
+ module.exports = logger;
1499
+
1500
+ },{}],14:[function(_dereq_,module,exports){
1501
+ var Color = _dereq_('./color');
1502
+ var utils = _dereq_('./utils');
1503
+ var getBounds = utils.getBounds;
1504
+ var parseBackgrounds = utils.parseBackgrounds;
1505
+ var offsetBounds = utils.offsetBounds;
1506
+
1507
+ function NodeContainer(node, parent) {
1508
+ this.node = node;
1509
+ this.parent = parent;
1510
+ this.stack = null;
1511
+ this.bounds = null;
1512
+ this.borders = null;
1513
+ this.clip = [];
1514
+ this.backgroundClip = [];
1515
+ this.offsetBounds = null;
1516
+ this.visible = null;
1517
+ this.computedStyles = null;
1518
+ this.colors = {};
1519
+ this.styles = {};
1520
+ this.backgroundImages = null;
1521
+ this.transformData = null;
1522
+ this.transformMatrix = null;
1523
+ this.isPseudoElement = false;
1524
+ this.opacity = null;
1525
+ }
1526
+
1527
+ NodeContainer.prototype.cloneTo = function(stack) {
1528
+ stack.visible = this.visible;
1529
+ stack.borders = this.borders;
1530
+ stack.bounds = this.bounds;
1531
+ stack.clip = this.clip;
1532
+ stack.backgroundClip = this.backgroundClip;
1533
+ stack.computedStyles = this.computedStyles;
1534
+ stack.styles = this.styles;
1535
+ stack.backgroundImages = this.backgroundImages;
1536
+ stack.opacity = this.opacity;
1537
+ };
1538
+
1539
+ NodeContainer.prototype.getOpacity = function() {
1540
+ return this.opacity === null ? (this.opacity = this.cssFloat('opacity')) : this.opacity;
1541
+ };
1542
+
1543
+ NodeContainer.prototype.assignStack = function(stack) {
1544
+ this.stack = stack;
1545
+ stack.children.push(this);
1546
+ };
1547
+
1548
+ NodeContainer.prototype.isElementVisible = function() {
1549
+ return this.node.nodeType === Node.TEXT_NODE ? this.parent.visible : (
1550
+ this.css('display') !== "none" &&
1551
+ this.css('visibility') !== "hidden" &&
1552
+ !this.node.hasAttribute("data-html2canvas-ignore") &&
1553
+ (this.node.nodeName !== "INPUT" || this.node.getAttribute("type") !== "hidden")
1554
+ );
1555
+ };
1556
+
1557
+ NodeContainer.prototype.css = function(attribute) {
1558
+ if (!this.computedStyles) {
1559
+ this.computedStyles = this.isPseudoElement ? this.parent.computedStyle(this.before ? ":before" : ":after") : this.computedStyle(null);
1560
+ }
1561
+
1562
+ return this.styles[attribute] || (this.styles[attribute] = this.computedStyles[attribute]);
1563
+ };
1564
+
1565
+ NodeContainer.prototype.prefixedCss = function(attribute) {
1566
+ var prefixes = ["webkit", "moz", "ms", "o"];
1567
+ var value = this.css(attribute);
1568
+ if (value === undefined) {
1569
+ prefixes.some(function(prefix) {
1570
+ value = this.css(prefix + attribute.substr(0, 1).toUpperCase() + attribute.substr(1));
1571
+ return value !== undefined;
1572
+ }, this);
1573
+ }
1574
+ return value === undefined ? null : value;
1575
+ };
1576
+
1577
+ NodeContainer.prototype.computedStyle = function(type) {
1578
+ return this.node.ownerDocument.defaultView.getComputedStyle(this.node, type);
1579
+ };
1580
+
1581
+ NodeContainer.prototype.cssInt = function(attribute) {
1582
+ var value = parseInt(this.css(attribute), 10);
1583
+ return (isNaN(value)) ? 0 : value; // borders in old IE are throwing 'medium' for demo.html
1584
+ };
1585
+
1586
+ NodeContainer.prototype.color = function(attribute) {
1587
+ return this.colors[attribute] || (this.colors[attribute] = new Color(this.css(attribute)));
1588
+ };
1589
+
1590
+ NodeContainer.prototype.cssFloat = function(attribute) {
1591
+ var value = parseFloat(this.css(attribute));
1592
+ return (isNaN(value)) ? 0 : value;
1593
+ };
1594
+
1595
+ NodeContainer.prototype.fontWeight = function() {
1596
+ var weight = this.css("fontWeight");
1597
+ switch(parseInt(weight, 10)){
1598
+ case 401:
1599
+ weight = "bold";
1600
+ break;
1601
+ case 400:
1602
+ weight = "normal";
1603
+ break;
1604
+ }
1605
+ return weight;
1606
+ };
1607
+
1608
+ NodeContainer.prototype.parseClip = function() {
1609
+ var matches = this.css('clip').match(this.CLIP);
1610
+ if (matches) {
1611
+ return {
1612
+ top: parseInt(matches[1], 10),
1613
+ right: parseInt(matches[2], 10),
1614
+ bottom: parseInt(matches[3], 10),
1615
+ left: parseInt(matches[4], 10)
1616
+ };
1617
+ }
1618
+ return null;
1619
+ };
1620
+
1621
+ NodeContainer.prototype.parseBackgroundImages = function() {
1622
+ return this.backgroundImages || (this.backgroundImages = parseBackgrounds(this.css("backgroundImage")));
1623
+ };
1624
+
1625
+ NodeContainer.prototype.cssList = function(property, index) {
1626
+ var value = (this.css(property) || '').split(',');
1627
+ value = value[index || 0] || value[0] || 'auto';
1628
+ value = value.trim().split(' ');
1629
+ if (value.length === 1) {
1630
+ value = [value[0], isPercentage(value[0]) ? 'auto' : value[0]];
1631
+ }
1632
+ return value;
1633
+ };
1634
+
1635
+ NodeContainer.prototype.parseBackgroundSize = function(bounds, image, index) {
1636
+ var size = this.cssList("backgroundSize", index);
1637
+ var width, height;
1638
+
1639
+ if (isPercentage(size[0])) {
1640
+ width = bounds.width * parseFloat(size[0]) / 100;
1641
+ } else if (/contain|cover/.test(size[0])) {
1642
+ var targetRatio = bounds.width / bounds.height, currentRatio = image.width / image.height;
1643
+ return (targetRatio < currentRatio ^ size[0] === 'contain') ? {width: bounds.height * currentRatio, height: bounds.height} : {width: bounds.width, height: bounds.width / currentRatio};
1644
+ } else {
1645
+ width = parseInt(size[0], 10);
1646
+ }
1647
+
1648
+ if (size[0] === 'auto' && size[1] === 'auto') {
1649
+ height = image.height;
1650
+ } else if (size[1] === 'auto') {
1651
+ height = width / image.width * image.height;
1652
+ } else if (isPercentage(size[1])) {
1653
+ height = bounds.height * parseFloat(size[1]) / 100;
1654
+ } else {
1655
+ height = parseInt(size[1], 10);
1656
+ }
1657
+
1658
+ if (size[0] === 'auto') {
1659
+ width = height / image.height * image.width;
1660
+ }
1661
+
1662
+ return {width: width, height: height};
1663
+ };
1664
+
1665
+ NodeContainer.prototype.parseBackgroundPosition = function(bounds, image, index, backgroundSize) {
1666
+ var position = this.cssList('backgroundPosition', index);
1667
+ var left, top;
1668
+
1669
+ if (isPercentage(position[0])){
1670
+ left = (bounds.width - (backgroundSize || image).width) * (parseFloat(position[0]) / 100);
1671
+ } else {
1672
+ left = parseInt(position[0], 10);
1673
+ }
1674
+
1675
+ if (position[1] === 'auto') {
1676
+ top = left / image.width * image.height;
1677
+ } else if (isPercentage(position[1])){
1678
+ top = (bounds.height - (backgroundSize || image).height) * parseFloat(position[1]) / 100;
1679
+ } else {
1680
+ top = parseInt(position[1], 10);
1681
+ }
1682
+
1683
+ if (position[0] === 'auto') {
1684
+ left = top / image.height * image.width;
1685
+ }
1686
+
1687
+ return {left: left, top: top};
1688
+ };
1689
+
1690
+ NodeContainer.prototype.parseBackgroundRepeat = function(index) {
1691
+ return this.cssList("backgroundRepeat", index)[0];
1692
+ };
1693
+
1694
+ NodeContainer.prototype.parseTextShadows = function() {
1695
+ var textShadow = this.css("textShadow");
1696
+ var results = [];
1697
+
1698
+ if (textShadow && textShadow !== 'none') {
1699
+ var shadows = textShadow.match(this.TEXT_SHADOW_PROPERTY);
1700
+ for (var i = 0; shadows && (i < shadows.length); i++) {
1701
+ var s = shadows[i].match(this.TEXT_SHADOW_VALUES);
1702
+ results.push({
1703
+ color: new Color(s[0]),
1704
+ offsetX: s[1] ? parseFloat(s[1].replace('px', '')) : 0,
1705
+ offsetY: s[2] ? parseFloat(s[2].replace('px', '')) : 0,
1706
+ blur: s[3] ? s[3].replace('px', '') : 0
1707
+ });
1708
+ }
1709
+ }
1710
+ return results;
1711
+ };
1712
+
1713
+ NodeContainer.prototype.parseTransform = function() {
1714
+ if (!this.transformData) {
1715
+ if (this.hasTransform()) {
1716
+ var offset = this.parseBounds();
1717
+ var origin = this.prefixedCss("transformOrigin").split(" ").map(removePx).map(asFloat);
1718
+ origin[0] += offset.left;
1719
+ origin[1] += offset.top;
1720
+ this.transformData = {
1721
+ origin: origin,
1722
+ matrix: this.parseTransformMatrix()
1723
+ };
1724
+ } else {
1725
+ this.transformData = {
1726
+ origin: [0, 0],
1727
+ matrix: [1, 0, 0, 1, 0, 0]
1728
+ };
1729
+ }
1730
+ }
1731
+ return this.transformData;
1732
+ };
1733
+
1734
+ NodeContainer.prototype.parseTransformMatrix = function() {
1735
+ if (!this.transformMatrix) {
1736
+ var transform = this.prefixedCss("transform");
1737
+ var matrix = transform ? parseMatrix(transform.match(this.MATRIX_PROPERTY)) : null;
1738
+ this.transformMatrix = matrix ? matrix : [1, 0, 0, 1, 0, 0];
1739
+ }
1740
+ return this.transformMatrix;
1741
+ };
1742
+
1743
+ NodeContainer.prototype.parseBounds = function() {
1744
+ return this.bounds || (this.bounds = this.hasTransform() ? offsetBounds(this.node) : getBounds(this.node));
1745
+ };
1746
+
1747
+ NodeContainer.prototype.hasTransform = function() {
1748
+ return this.parseTransformMatrix().join(",") !== "1,0,0,1,0,0" || (this.parent && this.parent.hasTransform());
1749
+ };
1750
+
1751
+ NodeContainer.prototype.getValue = function() {
1752
+ var value = this.node.value || "";
1753
+ if (this.node.tagName === "SELECT") {
1754
+ value = selectionValue(this.node);
1755
+ } else if (this.node.type === "password") {
1756
+ value = Array(value.length + 1).join('\u2022'); // jshint ignore:line
1757
+ }
1758
+ return value.length === 0 ? (this.node.placeholder || "") : value;
1759
+ };
1760
+
1761
+ NodeContainer.prototype.MATRIX_PROPERTY = /(matrix|matrix3d)\((.+)\)/;
1762
+ NodeContainer.prototype.TEXT_SHADOW_PROPERTY = /((rgba|rgb)\([^\)]+\)(\s-?\d+px){0,})/g;
1763
+ NodeContainer.prototype.TEXT_SHADOW_VALUES = /(-?\d+px)|(#.+)|(rgb\(.+\))|(rgba\(.+\))/g;
1764
+ NodeContainer.prototype.CLIP = /^rect\((\d+)px,? (\d+)px,? (\d+)px,? (\d+)px\)$/;
1765
+
1766
+ function selectionValue(node) {
1767
+ var option = node.options[node.selectedIndex || 0];
1768
+ return option ? (option.text || "") : "";
1769
+ }
1770
+
1771
+ function parseMatrix(match) {
1772
+ if (match && match[1] === "matrix") {
1773
+ return match[2].split(",").map(function(s) {
1774
+ return parseFloat(s.trim());
1775
+ });
1776
+ } else if (match && match[1] === "matrix3d") {
1777
+ var matrix3d = match[2].split(",").map(function(s) {
1778
+ return parseFloat(s.trim());
1779
+ });
1780
+ return [matrix3d[0], matrix3d[1], matrix3d[4], matrix3d[5], matrix3d[12], matrix3d[13]];
1781
+ }
1782
+ }
1783
+
1784
+ function isPercentage(value) {
1785
+ return value.toString().indexOf("%") !== -1;
1786
+ }
1787
+
1788
+ function removePx(str) {
1789
+ return str.replace("px", "");
1790
+ }
1791
+
1792
+ function asFloat(str) {
1793
+ return parseFloat(str);
1794
+ }
1795
+
1796
+ module.exports = NodeContainer;
1797
+
1798
+ },{"./color":3,"./utils":26}],15:[function(_dereq_,module,exports){
1799
+ var log = _dereq_('./log');
1800
+ var punycode = _dereq_('punycode');
1801
+ var NodeContainer = _dereq_('./nodecontainer');
1802
+ var TextContainer = _dereq_('./textcontainer');
1803
+ var PseudoElementContainer = _dereq_('./pseudoelementcontainer');
1804
+ var FontMetrics = _dereq_('./fontmetrics');
1805
+ var Color = _dereq_('./color');
1806
+ var StackingContext = _dereq_('./stackingcontext');
1807
+ var utils = _dereq_('./utils');
1808
+ var bind = utils.bind;
1809
+ var getBounds = utils.getBounds;
1810
+ var parseBackgrounds = utils.parseBackgrounds;
1811
+ var offsetBounds = utils.offsetBounds;
1812
+
1813
+ function NodeParser(element, renderer, support, imageLoader, options) {
1814
+ log("Starting NodeParser");
1815
+ this.renderer = renderer;
1816
+ this.options = options;
1817
+ this.range = null;
1818
+ this.support = support;
1819
+ this.renderQueue = [];
1820
+ this.stack = new StackingContext(true, 1, element.ownerDocument, null);
1821
+ var parent = new NodeContainer(element, null);
1822
+ if (options.background) {
1823
+ renderer.rectangle(0, 0, renderer.width, renderer.height, new Color(options.background));
1824
+ }
1825
+ if (element === element.ownerDocument.documentElement) {
1826
+ // http://www.w3.org/TR/css3-background/#special-backgrounds
1827
+ var canvasBackground = new NodeContainer(parent.color('backgroundColor').isTransparent() ? element.ownerDocument.body : element.ownerDocument.documentElement, null);
1828
+ renderer.rectangle(0, 0, renderer.width, renderer.height, canvasBackground.color('backgroundColor'));
1829
+ }
1830
+ parent.visibile = parent.isElementVisible();
1831
+ this.createPseudoHideStyles(element.ownerDocument);
1832
+ this.disableAnimations(element.ownerDocument);
1833
+ this.nodes = flatten([parent].concat(this.getChildren(parent)).filter(function(container) {
1834
+ return container.visible = container.isElementVisible();
1835
+ }).map(this.getPseudoElements, this));
1836
+ this.fontMetrics = new FontMetrics();
1837
+ log("Fetched nodes, total:", this.nodes.length);
1838
+ log("Calculate overflow clips");
1839
+ this.calculateOverflowClips();
1840
+ log("Start fetching images");
1841
+ this.images = imageLoader.fetch(this.nodes.filter(isElement));
1842
+ this.ready = this.images.ready.then(bind(function() {
1843
+ log("Images loaded, starting parsing");
1844
+ log("Creating stacking contexts");
1845
+ this.createStackingContexts();
1846
+ log("Sorting stacking contexts");
1847
+ this.sortStackingContexts(this.stack);
1848
+ this.parse(this.stack);
1849
+ log("Render queue created with " + this.renderQueue.length + " items");
1850
+ return new Promise(bind(function(resolve) {
1851
+ if (!options.async) {
1852
+ this.renderQueue.forEach(this.paint, this);
1853
+ resolve();
1854
+ } else if (typeof(options.async) === "function") {
1855
+ options.async.call(this, this.renderQueue, resolve);
1856
+ } else if (this.renderQueue.length > 0){
1857
+ this.renderIndex = 0;
1858
+ this.asyncRenderer(this.renderQueue, resolve);
1859
+ } else {
1860
+ resolve();
1861
+ }
1862
+ }, this));
1863
+ }, this));
1864
+ }
1865
+
1866
+ NodeParser.prototype.calculateOverflowClips = function() {
1867
+ this.nodes.forEach(function(container) {
1868
+ if (isElement(container)) {
1869
+ if (isPseudoElement(container)) {
1870
+ container.appendToDOM();
1871
+ }
1872
+ container.borders = this.parseBorders(container);
1873
+ var clip = (container.css('overflow') === "hidden") ? [container.borders.clip] : [];
1874
+ var cssClip = container.parseClip();
1875
+ if (cssClip && ["absolute", "fixed"].indexOf(container.css('position')) !== -1) {
1876
+ clip.push([["rect",
1877
+ container.bounds.left + cssClip.left,
1878
+ container.bounds.top + cssClip.top,
1879
+ cssClip.right - cssClip.left,
1880
+ cssClip.bottom - cssClip.top
1881
+ ]]);
1882
+ }
1883
+ container.clip = hasParentClip(container) ? container.parent.clip.concat(clip) : clip;
1884
+ container.backgroundClip = (container.css('overflow') !== "hidden") ? container.clip.concat([container.borders.clip]) : container.clip;
1885
+ if (isPseudoElement(container)) {
1886
+ container.cleanDOM();
1887
+ }
1888
+ } else if (isTextNode(container)) {
1889
+ container.clip = hasParentClip(container) ? container.parent.clip : [];
1890
+ }
1891
+ if (!isPseudoElement(container)) {
1892
+ container.bounds = null;
1893
+ }
1894
+ }, this);
1895
+ };
1896
+
1897
+ function hasParentClip(container) {
1898
+ return container.parent && container.parent.clip.length;
1899
+ }
1900
+
1901
+ NodeParser.prototype.asyncRenderer = function(queue, resolve, asyncTimer) {
1902
+ asyncTimer = asyncTimer || Date.now();
1903
+ this.paint(queue[this.renderIndex++]);
1904
+ if (queue.length === this.renderIndex) {
1905
+ resolve();
1906
+ } else if (asyncTimer + 20 > Date.now()) {
1907
+ this.asyncRenderer(queue, resolve, asyncTimer);
1908
+ } else {
1909
+ setTimeout(bind(function() {
1910
+ this.asyncRenderer(queue, resolve);
1911
+ }, this), 0);
1912
+ }
1913
+ };
1914
+
1915
+ NodeParser.prototype.createPseudoHideStyles = function(document) {
1916
+ this.createStyles(document, '.' + PseudoElementContainer.prototype.PSEUDO_HIDE_ELEMENT_CLASS_BEFORE + ':before { content: "" !important; display: none !important; }' +
1917
+ '.' + PseudoElementContainer.prototype.PSEUDO_HIDE_ELEMENT_CLASS_AFTER + ':after { content: "" !important; display: none !important; }');
1918
+ };
1919
+
1920
+ NodeParser.prototype.disableAnimations = function(document) {
1921
+ this.createStyles(document, '* { -webkit-animation: none !important; -moz-animation: none !important; -o-animation: none !important; animation: none !important; ' +
1922
+ '-webkit-transition: none !important; -moz-transition: none !important; -o-transition: none !important; transition: none !important;}');
1923
+ };
1924
+
1925
+ NodeParser.prototype.createStyles = function(document, styles) {
1926
+ var hidePseudoElements = document.createElement('style');
1927
+ hidePseudoElements.innerHTML = styles;
1928
+ document.body.appendChild(hidePseudoElements);
1929
+ };
1930
+
1931
+ NodeParser.prototype.getPseudoElements = function(container) {
1932
+ var nodes = [[container]];
1933
+ if (container.node.nodeType === Node.ELEMENT_NODE) {
1934
+ var before = this.getPseudoElement(container, ":before");
1935
+ var after = this.getPseudoElement(container, ":after");
1936
+
1937
+ if (before) {
1938
+ nodes.push(before);
1939
+ }
1940
+
1941
+ if (after) {
1942
+ nodes.push(after);
1943
+ }
1944
+ }
1945
+ return flatten(nodes);
1946
+ };
1947
+
1948
+ function toCamelCase(str) {
1949
+ return str.replace(/(\-[a-z])/g, function(match){
1950
+ return match.toUpperCase().replace('-','');
1951
+ });
1952
+ }
1953
+
1954
+ NodeParser.prototype.getPseudoElement = function(container, type) {
1955
+ var style = container.computedStyle(type);
1956
+ if(!style || !style.content || style.content === "none" || style.content === "-moz-alt-content" || style.display === "none") {
1957
+ return null;
1958
+ }
1959
+
1960
+ var content = stripQuotes(style.content);
1961
+ var isImage = content.substr(0, 3) === 'url';
1962
+ var pseudoNode = document.createElement(isImage ? 'img' : 'html2canvaspseudoelement');
1963
+ var pseudoContainer = new PseudoElementContainer(pseudoNode, container, type);
1964
+
1965
+ for (var i = style.length-1; i >= 0; i--) {
1966
+ var property = toCamelCase(style.item(i));
1967
+ pseudoNode.style[property] = style[property];
1968
+ }
1969
+
1970
+ pseudoNode.className = PseudoElementContainer.prototype.PSEUDO_HIDE_ELEMENT_CLASS_BEFORE + " " + PseudoElementContainer.prototype.PSEUDO_HIDE_ELEMENT_CLASS_AFTER;
1971
+
1972
+ if (isImage) {
1973
+ pseudoNode.src = parseBackgrounds(content)[0].args[0];
1974
+ return [pseudoContainer];
1975
+ } else {
1976
+ var text = document.createTextNode(content);
1977
+ pseudoNode.appendChild(text);
1978
+ return [pseudoContainer, new TextContainer(text, pseudoContainer)];
1979
+ }
1980
+ };
1981
+
1982
+
1983
+ NodeParser.prototype.getChildren = function(parentContainer) {
1984
+ return flatten([].filter.call(parentContainer.node.childNodes, renderableNode).map(function(node) {
1985
+ var container = [node.nodeType === Node.TEXT_NODE ? new TextContainer(node, parentContainer) : new NodeContainer(node, parentContainer)].filter(nonIgnoredElement);
1986
+ return node.nodeType === Node.ELEMENT_NODE && container.length && node.tagName !== "TEXTAREA" ? (container[0].isElementVisible() ? container.concat(this.getChildren(container[0])) : []) : container;
1987
+ }, this));
1988
+ };
1989
+
1990
+ NodeParser.prototype.newStackingContext = function(container, hasOwnStacking) {
1991
+ var stack = new StackingContext(hasOwnStacking, container.getOpacity(), container.node, container.parent);
1992
+ container.cloneTo(stack);
1993
+ var parentStack = hasOwnStacking ? stack.getParentStack(this) : stack.parent.stack;
1994
+ parentStack.contexts.push(stack);
1995
+ container.stack = stack;
1996
+ };
1997
+
1998
+ NodeParser.prototype.createStackingContexts = function() {
1999
+ this.nodes.forEach(function(container) {
2000
+ if (isElement(container) && (this.isRootElement(container) || hasOpacity(container) || isPositionedForStacking(container) || this.isBodyWithTransparentRoot(container) || container.hasTransform())) {
2001
+ this.newStackingContext(container, true);
2002
+ } else if (isElement(container) && ((isPositioned(container) && zIndex0(container)) || isInlineBlock(container) || isFloating(container))) {
2003
+ this.newStackingContext(container, false);
2004
+ } else {
2005
+ container.assignStack(container.parent.stack);
2006
+ }
2007
+ }, this);
2008
+ };
2009
+
2010
+ NodeParser.prototype.isBodyWithTransparentRoot = function(container) {
2011
+ return container.node.nodeName === "BODY" && container.parent.color('backgroundColor').isTransparent();
2012
+ };
2013
+
2014
+ NodeParser.prototype.isRootElement = function(container) {
2015
+ return container.parent === null;
2016
+ };
2017
+
2018
+ NodeParser.prototype.sortStackingContexts = function(stack) {
2019
+ stack.contexts.sort(zIndexSort(stack.contexts.slice(0)));
2020
+ stack.contexts.forEach(this.sortStackingContexts, this);
2021
+ };
2022
+
2023
+ NodeParser.prototype.parseTextBounds = function(container) {
2024
+ return function(text, index, textList) {
2025
+ if (container.parent.css("textDecoration").substr(0, 4) !== "none" || text.trim().length !== 0) {
2026
+ if (this.support.rangeBounds && !container.parent.hasTransform()) {
2027
+ var offset = textList.slice(0, index).join("").length;
2028
+ return this.getRangeBounds(container.node, offset, text.length);
2029
+ } else if (container.node && typeof(container.node.data) === "string") {
2030
+ var replacementNode = container.node.splitText(text.length);
2031
+ var bounds = this.getWrapperBounds(container.node, container.parent.hasTransform());
2032
+ container.node = replacementNode;
2033
+ return bounds;
2034
+ }
2035
+ } else if(!this.support.rangeBounds || container.parent.hasTransform()){
2036
+ container.node = container.node.splitText(text.length);
2037
+ }
2038
+ return {};
2039
+ };
2040
+ };
2041
+
2042
+ NodeParser.prototype.getWrapperBounds = function(node, transform) {
2043
+ var wrapper = node.ownerDocument.createElement('html2canvaswrapper');
2044
+ var parent = node.parentNode,
2045
+ backupText = node.cloneNode(true);
2046
+
2047
+ wrapper.appendChild(node.cloneNode(true));
2048
+ parent.replaceChild(wrapper, node);
2049
+ var bounds = transform ? offsetBounds(wrapper) : getBounds(wrapper);
2050
+ parent.replaceChild(backupText, wrapper);
2051
+ return bounds;
2052
+ };
2053
+
2054
+ NodeParser.prototype.getRangeBounds = function(node, offset, length) {
2055
+ var range = this.range || (this.range = node.ownerDocument.createRange());
2056
+ range.setStart(node, offset);
2057
+ range.setEnd(node, offset + length);
2058
+ return range.getBoundingClientRect();
2059
+ };
2060
+
2061
+ function ClearTransform() {}
2062
+
2063
+ NodeParser.prototype.parse = function(stack) {
2064
+ // http://www.w3.org/TR/CSS21/visuren.html#z-index
2065
+ var negativeZindex = stack.contexts.filter(negativeZIndex); // 2. the child stacking contexts with negative stack levels (most negative first).
2066
+ var descendantElements = stack.children.filter(isElement);
2067
+ var descendantNonFloats = descendantElements.filter(not(isFloating));
2068
+ var nonInlineNonPositionedDescendants = descendantNonFloats.filter(not(isPositioned)).filter(not(inlineLevel)); // 3 the in-flow, non-inline-level, non-positioned descendants.
2069
+ var nonPositionedFloats = descendantElements.filter(not(isPositioned)).filter(isFloating); // 4. the non-positioned floats.
2070
+ var inFlow = descendantNonFloats.filter(not(isPositioned)).filter(inlineLevel); // 5. the in-flow, inline-level, non-positioned descendants, including inline tables and inline blocks.
2071
+ var stackLevel0 = stack.contexts.concat(descendantNonFloats.filter(isPositioned)).filter(zIndex0); // 6. the child stacking contexts with stack level 0 and the positioned descendants with stack level 0.
2072
+ var text = stack.children.filter(isTextNode).filter(hasText);
2073
+ var positiveZindex = stack.contexts.filter(positiveZIndex); // 7. the child stacking contexts with positive stack levels (least positive first).
2074
+ negativeZindex.concat(nonInlineNonPositionedDescendants).concat(nonPositionedFloats)
2075
+ .concat(inFlow).concat(stackLevel0).concat(text).concat(positiveZindex).forEach(function(container) {
2076
+ this.renderQueue.push(container);
2077
+ if (isStackingContext(container)) {
2078
+ this.parse(container);
2079
+ this.renderQueue.push(new ClearTransform());
2080
+ }
2081
+ }, this);
2082
+ };
2083
+
2084
+ NodeParser.prototype.paint = function(container) {
2085
+ try {
2086
+ if (container instanceof ClearTransform) {
2087
+ this.renderer.ctx.restore();
2088
+ } else if (isTextNode(container)) {
2089
+ if (isPseudoElement(container.parent)) {
2090
+ container.parent.appendToDOM();
2091
+ }
2092
+ this.paintText(container);
2093
+ if (isPseudoElement(container.parent)) {
2094
+ container.parent.cleanDOM();
2095
+ }
2096
+ } else {
2097
+ this.paintNode(container);
2098
+ }
2099
+ } catch(e) {
2100
+ log(e);
2101
+ if (this.options.strict) {
2102
+ throw e;
2103
+ }
2104
+ }
2105
+ };
2106
+
2107
+ NodeParser.prototype.paintNode = function(container) {
2108
+ if (isStackingContext(container)) {
2109
+ this.renderer.setOpacity(container.opacity);
2110
+ this.renderer.ctx.save();
2111
+ if (container.hasTransform()) {
2112
+ this.renderer.setTransform(container.parseTransform());
2113
+ }
2114
+ }
2115
+
2116
+ if (container.node.nodeName === "INPUT" && container.node.type === "checkbox") {
2117
+ this.paintCheckbox(container);
2118
+ } else if (container.node.nodeName === "INPUT" && container.node.type === "radio") {
2119
+ this.paintRadio(container);
2120
+ } else {
2121
+ this.paintElement(container);
2122
+ }
2123
+ };
2124
+
2125
+ NodeParser.prototype.paintElement = function(container) {
2126
+ var bounds = container.parseBounds();
2127
+ this.renderer.clip(container.backgroundClip, function() {
2128
+ this.renderer.renderBackground(container, bounds, container.borders.borders.map(getWidth));
2129
+ }, this);
2130
+
2131
+ this.renderer.clip(container.clip, function() {
2132
+ this.renderer.renderBorders(container.borders.borders);
2133
+ }, this);
2134
+
2135
+ this.renderer.clip(container.backgroundClip, function() {
2136
+ switch (container.node.nodeName) {
2137
+ case "svg":
2138
+ case "IFRAME":
2139
+ var imgContainer = this.images.get(container.node);
2140
+ if (imgContainer) {
2141
+ this.renderer.renderImage(container, bounds, container.borders, imgContainer);
2142
+ } else {
2143
+ log("Error loading <" + container.node.nodeName + ">", container.node);
2144
+ }
2145
+ break;
2146
+ case "IMG":
2147
+ var imageContainer = this.images.get(container.node.src);
2148
+ if (imageContainer) {
2149
+ this.renderer.renderImage(container, bounds, container.borders, imageContainer);
2150
+ } else {
2151
+ log("Error loading <img>", container.node.src);
2152
+ }
2153
+ break;
2154
+ case "CANVAS":
2155
+ this.renderer.renderImage(container, bounds, container.borders, {image: container.node});
2156
+ break;
2157
+ case "SELECT":
2158
+ case "INPUT":
2159
+ case "TEXTAREA":
2160
+ this.paintFormValue(container);
2161
+ break;
2162
+ }
2163
+ }, this);
2164
+ };
2165
+
2166
+ NodeParser.prototype.paintCheckbox = function(container) {
2167
+ var b = container.parseBounds();
2168
+
2169
+ var size = Math.min(b.width, b.height);
2170
+ var bounds = {width: size - 1, height: size - 1, top: b.top, left: b.left};
2171
+ var r = [3, 3];
2172
+ var radius = [r, r, r, r];
2173
+ var borders = [1,1,1,1].map(function(w) {
2174
+ return {color: new Color('#A5A5A5'), width: w};
2175
+ });
2176
+
2177
+ var borderPoints = calculateCurvePoints(bounds, radius, borders);
2178
+
2179
+ this.renderer.clip(container.backgroundClip, function() {
2180
+ this.renderer.rectangle(bounds.left + 1, bounds.top + 1, bounds.width - 2, bounds.height - 2, new Color("#DEDEDE"));
2181
+ this.renderer.renderBorders(calculateBorders(borders, bounds, borderPoints, radius));
2182
+ if (container.node.checked) {
2183
+ this.renderer.font(new Color('#424242'), 'normal', 'normal', 'bold', (size - 3) + "px", 'arial');
2184
+ this.renderer.text("\u2714", bounds.left + size / 6, bounds.top + size - 1);
2185
+ }
2186
+ }, this);
2187
+ };
2188
+
2189
+ NodeParser.prototype.paintRadio = function(container) {
2190
+ var bounds = container.parseBounds();
2191
+
2192
+ var size = Math.min(bounds.width, bounds.height) - 2;
2193
+
2194
+ this.renderer.clip(container.backgroundClip, function() {
2195
+ this.renderer.circleStroke(bounds.left + 1, bounds.top + 1, size, new Color('#DEDEDE'), 1, new Color('#A5A5A5'));
2196
+ if (container.node.checked) {
2197
+ this.renderer.circle(Math.ceil(bounds.left + size / 4) + 1, Math.ceil(bounds.top + size / 4) + 1, Math.floor(size / 2), new Color('#424242'));
2198
+ }
2199
+ }, this);
2200
+ };
2201
+
2202
+ NodeParser.prototype.paintFormValue = function(container) {
2203
+ var value = container.getValue();
2204
+ if (value.length > 0) {
2205
+ var document = container.node.ownerDocument;
2206
+ var wrapper = document.createElement('html2canvaswrapper');
2207
+ var properties = ['lineHeight', 'textAlign', 'fontFamily', 'fontWeight', 'fontSize', 'color',
2208
+ 'paddingLeft', 'paddingTop', 'paddingRight', 'paddingBottom',
2209
+ 'width', 'height', 'borderLeftStyle', 'borderTopStyle', 'borderLeftWidth', 'borderTopWidth',
2210
+ 'boxSizing', 'whiteSpace', 'wordWrap'];
2211
+
2212
+ properties.forEach(function(property) {
2213
+ try {
2214
+ wrapper.style[property] = container.css(property);
2215
+ } catch(e) {
2216
+ // Older IE has issues with "border"
2217
+ log("html2canvas: Parse: Exception caught in renderFormValue: " + e.message);
2218
+ }
2219
+ });
2220
+ var bounds = container.parseBounds();
2221
+ wrapper.style.position = "fixed";
2222
+ wrapper.style.left = bounds.left + "px";
2223
+ wrapper.style.top = bounds.top + "px";
2224
+ wrapper.textContent = value;
2225
+ document.body.appendChild(wrapper);
2226
+ this.paintText(new TextContainer(wrapper.firstChild, container));
2227
+ document.body.removeChild(wrapper);
2228
+ }
2229
+ };
2230
+
2231
+ NodeParser.prototype.paintText = function(container) {
2232
+ container.applyTextTransform();
2233
+ var characters = punycode.ucs2.decode(container.node.data);
2234
+ var textList = (!this.options.letterRendering || noLetterSpacing(container)) && !hasUnicode(container.node.data) ? getWords(characters) : characters.map(function(character) {
2235
+ return punycode.ucs2.encode([character]);
2236
+ });
2237
+
2238
+ var weight = container.parent.fontWeight();
2239
+ var size = container.parent.css('fontSize');
2240
+ var family = container.parent.css('fontFamily');
2241
+ var shadows = container.parent.parseTextShadows();
2242
+
2243
+ this.renderer.font(container.parent.color('color'), container.parent.css('fontStyle'), container.parent.css('fontVariant'), weight, size, family);
2244
+ if (shadows.length) {
2245
+ // TODO: support multiple text shadows
2246
+ this.renderer.fontShadow(shadows[0].color, shadows[0].offsetX, shadows[0].offsetY, shadows[0].blur);
2247
+ } else {
2248
+ this.renderer.clearShadow();
2249
+ }
2250
+
2251
+ this.renderer.clip(container.parent.clip, function() {
2252
+ textList.map(this.parseTextBounds(container), this).forEach(function(bounds, index) {
2253
+ if (bounds) {
2254
+ this.renderer.text(textList[index], bounds.left, bounds.bottom);
2255
+ this.renderTextDecoration(container.parent, bounds, this.fontMetrics.getMetrics(family, size));
2256
+ }
2257
+ }, this);
2258
+ }, this);
2259
+ };
2260
+
2261
+ NodeParser.prototype.renderTextDecoration = function(container, bounds, metrics) {
2262
+ switch(container.css("textDecoration").split(" ")[0]) {
2263
+ case "underline":
2264
+ // Draws a line at the baseline of the font
2265
+ // TODO As some browsers display the line as more than 1px if the font-size is big, need to take that into account both in position and size
2266
+ this.renderer.rectangle(bounds.left, Math.round(bounds.top + metrics.baseline + metrics.lineWidth), bounds.width, 1, container.color("color"));
2267
+ break;
2268
+ case "overline":
2269
+ this.renderer.rectangle(bounds.left, Math.round(bounds.top), bounds.width, 1, container.color("color"));
2270
+ break;
2271
+ case "line-through":
2272
+ // TODO try and find exact position for line-through
2273
+ this.renderer.rectangle(bounds.left, Math.ceil(bounds.top + metrics.middle + metrics.lineWidth), bounds.width, 1, container.color("color"));
2274
+ break;
2275
+ }
2276
+ };
2277
+
2278
+ var borderColorTransforms = {
2279
+ inset: [
2280
+ ["darken", 0.60],
2281
+ ["darken", 0.10],
2282
+ ["darken", 0.10],
2283
+ ["darken", 0.60]
2284
+ ]
2285
+ };
2286
+
2287
+ NodeParser.prototype.parseBorders = function(container) {
2288
+ var nodeBounds = container.parseBounds();
2289
+ var radius = getBorderRadiusData(container);
2290
+ var borders = ["Top", "Right", "Bottom", "Left"].map(function(side, index) {
2291
+ var style = container.css('border' + side + 'Style');
2292
+ var color = container.color('border' + side + 'Color');
2293
+ if (style === "inset" && color.isBlack()) {
2294
+ color = new Color([255, 255, 255, color.a]); // this is wrong, but
2295
+ }
2296
+ var colorTransform = borderColorTransforms[style] ? borderColorTransforms[style][index] : null;
2297
+ return {
2298
+ width: container.cssInt('border' + side + 'Width'),
2299
+ color: colorTransform ? color[colorTransform[0]](colorTransform[1]) : color,
2300
+ args: null
2301
+ };
2302
+ });
2303
+ var borderPoints = calculateCurvePoints(nodeBounds, radius, borders);
2304
+
2305
+ return {
2306
+ clip: this.parseBackgroundClip(container, borderPoints, borders, radius, nodeBounds),
2307
+ borders: calculateBorders(borders, nodeBounds, borderPoints, radius)
2308
+ };
2309
+ };
2310
+
2311
+ function calculateBorders(borders, nodeBounds, borderPoints, radius) {
2312
+ return borders.map(function(border, borderSide) {
2313
+ if (border.width > 0) {
2314
+ var bx = nodeBounds.left;
2315
+ var by = nodeBounds.top;
2316
+ var bw = nodeBounds.width;
2317
+ var bh = nodeBounds.height - (borders[2].width);
2318
+
2319
+ switch(borderSide) {
2320
+ case 0:
2321
+ // top border
2322
+ bh = borders[0].width;
2323
+ border.args = drawSide({
2324
+ c1: [bx, by],
2325
+ c2: [bx + bw, by],
2326
+ c3: [bx + bw - borders[1].width, by + bh],
2327
+ c4: [bx + borders[3].width, by + bh]
2328
+ }, radius[0], radius[1],
2329
+ borderPoints.topLeftOuter, borderPoints.topLeftInner, borderPoints.topRightOuter, borderPoints.topRightInner);
2330
+ break;
2331
+ case 1:
2332
+ // right border
2333
+ bx = nodeBounds.left + nodeBounds.width - (borders[1].width);
2334
+ bw = borders[1].width;
2335
+
2336
+ border.args = drawSide({
2337
+ c1: [bx + bw, by],
2338
+ c2: [bx + bw, by + bh + borders[2].width],
2339
+ c3: [bx, by + bh],
2340
+ c4: [bx, by + borders[0].width]
2341
+ }, radius[1], radius[2],
2342
+ borderPoints.topRightOuter, borderPoints.topRightInner, borderPoints.bottomRightOuter, borderPoints.bottomRightInner);
2343
+ break;
2344
+ case 2:
2345
+ // bottom border
2346
+ by = (by + nodeBounds.height) - (borders[2].width);
2347
+ bh = borders[2].width;
2348
+ border.args = drawSide({
2349
+ c1: [bx + bw, by + bh],
2350
+ c2: [bx, by + bh],
2351
+ c3: [bx + borders[3].width, by],
2352
+ c4: [bx + bw - borders[3].width, by]
2353
+ }, radius[2], radius[3],
2354
+ borderPoints.bottomRightOuter, borderPoints.bottomRightInner, borderPoints.bottomLeftOuter, borderPoints.bottomLeftInner);
2355
+ break;
2356
+ case 3:
2357
+ // left border
2358
+ bw = borders[3].width;
2359
+ border.args = drawSide({
2360
+ c1: [bx, by + bh + borders[2].width],
2361
+ c2: [bx, by],
2362
+ c3: [bx + bw, by + borders[0].width],
2363
+ c4: [bx + bw, by + bh]
2364
+ }, radius[3], radius[0],
2365
+ borderPoints.bottomLeftOuter, borderPoints.bottomLeftInner, borderPoints.topLeftOuter, borderPoints.topLeftInner);
2366
+ break;
2367
+ }
2368
+ }
2369
+ return border;
2370
+ });
2371
+ }
2372
+
2373
+ NodeParser.prototype.parseBackgroundClip = function(container, borderPoints, borders, radius, bounds) {
2374
+ var backgroundClip = container.css('backgroundClip'),
2375
+ borderArgs = [];
2376
+
2377
+ switch(backgroundClip) {
2378
+ case "content-box":
2379
+ case "padding-box":
2380
+ parseCorner(borderArgs, radius[0], radius[1], borderPoints.topLeftInner, borderPoints.topRightInner, bounds.left + borders[3].width, bounds.top + borders[0].width);
2381
+ parseCorner(borderArgs, radius[1], radius[2], borderPoints.topRightInner, borderPoints.bottomRightInner, bounds.left + bounds.width - borders[1].width, bounds.top + borders[0].width);
2382
+ parseCorner(borderArgs, radius[2], radius[3], borderPoints.bottomRightInner, borderPoints.bottomLeftInner, bounds.left + bounds.width - borders[1].width, bounds.top + bounds.height - borders[2].width);
2383
+ parseCorner(borderArgs, radius[3], radius[0], borderPoints.bottomLeftInner, borderPoints.topLeftInner, bounds.left + borders[3].width, bounds.top + bounds.height - borders[2].width);
2384
+ break;
2385
+
2386
+ default:
2387
+ parseCorner(borderArgs, radius[0], radius[1], borderPoints.topLeftOuter, borderPoints.topRightOuter, bounds.left, bounds.top);
2388
+ parseCorner(borderArgs, radius[1], radius[2], borderPoints.topRightOuter, borderPoints.bottomRightOuter, bounds.left + bounds.width, bounds.top);
2389
+ parseCorner(borderArgs, radius[2], radius[3], borderPoints.bottomRightOuter, borderPoints.bottomLeftOuter, bounds.left + bounds.width, bounds.top + bounds.height);
2390
+ parseCorner(borderArgs, radius[3], radius[0], borderPoints.bottomLeftOuter, borderPoints.topLeftOuter, bounds.left, bounds.top + bounds.height);
2391
+ break;
2392
+ }
2393
+
2394
+ return borderArgs;
2395
+ };
2396
+
2397
+ function getCurvePoints(x, y, r1, r2) {
2398
+ var kappa = 4 * ((Math.sqrt(2) - 1) / 3);
2399
+ var ox = (r1) * kappa, // control point offset horizontal
2400
+ oy = (r2) * kappa, // control point offset vertical
2401
+ xm = x + r1, // x-middle
2402
+ ym = y + r2; // y-middle
2403
+ return {
2404
+ topLeft: bezierCurve({x: x, y: ym}, {x: x, y: ym - oy}, {x: xm - ox, y: y}, {x: xm, y: y}),
2405
+ topRight: bezierCurve({x: x, y: y}, {x: x + ox,y: y}, {x: xm, y: ym - oy}, {x: xm, y: ym}),
2406
+ bottomRight: bezierCurve({x: xm, y: y}, {x: xm, y: y + oy}, {x: x + ox, y: ym}, {x: x, y: ym}),
2407
+ bottomLeft: bezierCurve({x: xm, y: ym}, {x: xm - ox, y: ym}, {x: x, y: y + oy}, {x: x, y:y})
2408
+ };
2409
+ }
2410
+
2411
+ function calculateCurvePoints(bounds, borderRadius, borders) {
2412
+ var x = bounds.left,
2413
+ y = bounds.top,
2414
+ width = bounds.width,
2415
+ height = bounds.height,
2416
+
2417
+ tlh = borderRadius[0][0] < width / 2 ? borderRadius[0][0] : width / 2,
2418
+ tlv = borderRadius[0][1] < height / 2 ? borderRadius[0][1] : height / 2,
2419
+ trh = borderRadius[1][0] < width / 2 ? borderRadius[1][0] : width / 2,
2420
+ trv = borderRadius[1][1] < height / 2 ? borderRadius[1][1] : height / 2,
2421
+ brh = borderRadius[2][0] < width / 2 ? borderRadius[2][0] : width / 2,
2422
+ brv = borderRadius[2][1] < height / 2 ? borderRadius[2][1] : height / 2,
2423
+ blh = borderRadius[3][0] < width / 2 ? borderRadius[3][0] : width / 2,
2424
+ blv = borderRadius[3][1] < height / 2 ? borderRadius[3][1] : height / 2;
2425
+
2426
+ var topWidth = width - trh,
2427
+ rightHeight = height - brv,
2428
+ bottomWidth = width - brh,
2429
+ leftHeight = height - blv;
2430
+
2431
+ return {
2432
+ topLeftOuter: getCurvePoints(x, y, tlh, tlv).topLeft.subdivide(0.5),
2433
+ topLeftInner: getCurvePoints(x + borders[3].width, y + borders[0].width, Math.max(0, tlh - borders[3].width), Math.max(0, tlv - borders[0].width)).topLeft.subdivide(0.5),
2434
+ topRightOuter: getCurvePoints(x + topWidth, y, trh, trv).topRight.subdivide(0.5),
2435
+ topRightInner: getCurvePoints(x + Math.min(topWidth, width + borders[3].width), y + borders[0].width, (topWidth > width + borders[3].width) ? 0 :trh - borders[3].width, trv - borders[0].width).topRight.subdivide(0.5),
2436
+ bottomRightOuter: getCurvePoints(x + bottomWidth, y + rightHeight, brh, brv).bottomRight.subdivide(0.5),
2437
+ bottomRightInner: getCurvePoints(x + Math.min(bottomWidth, width - borders[3].width), y + Math.min(rightHeight, height + borders[0].width), Math.max(0, brh - borders[1].width), brv - borders[2].width).bottomRight.subdivide(0.5),
2438
+ bottomLeftOuter: getCurvePoints(x, y + leftHeight, blh, blv).bottomLeft.subdivide(0.5),
2439
+ bottomLeftInner: getCurvePoints(x + borders[3].width, y + leftHeight, Math.max(0, blh - borders[3].width), blv - borders[2].width).bottomLeft.subdivide(0.5)
2440
+ };
2441
+ }
2442
+
2443
+ function bezierCurve(start, startControl, endControl, end) {
2444
+ var lerp = function (a, b, t) {
2445
+ return {
2446
+ x: a.x + (b.x - a.x) * t,
2447
+ y: a.y + (b.y - a.y) * t
2448
+ };
2449
+ };
2450
+
2451
+ return {
2452
+ start: start,
2453
+ startControl: startControl,
2454
+ endControl: endControl,
2455
+ end: end,
2456
+ subdivide: function(t) {
2457
+ var ab = lerp(start, startControl, t),
2458
+ bc = lerp(startControl, endControl, t),
2459
+ cd = lerp(endControl, end, t),
2460
+ abbc = lerp(ab, bc, t),
2461
+ bccd = lerp(bc, cd, t),
2462
+ dest = lerp(abbc, bccd, t);
2463
+ return [bezierCurve(start, ab, abbc, dest), bezierCurve(dest, bccd, cd, end)];
2464
+ },
2465
+ curveTo: function(borderArgs) {
2466
+ borderArgs.push(["bezierCurve", startControl.x, startControl.y, endControl.x, endControl.y, end.x, end.y]);
2467
+ },
2468
+ curveToReversed: function(borderArgs) {
2469
+ borderArgs.push(["bezierCurve", endControl.x, endControl.y, startControl.x, startControl.y, start.x, start.y]);
2470
+ }
2471
+ };
2472
+ }
2473
+
2474
+ function drawSide(borderData, radius1, radius2, outer1, inner1, outer2, inner2) {
2475
+ var borderArgs = [];
2476
+
2477
+ if (radius1[0] > 0 || radius1[1] > 0) {
2478
+ borderArgs.push(["line", outer1[1].start.x, outer1[1].start.y]);
2479
+ outer1[1].curveTo(borderArgs);
2480
+ } else {
2481
+ borderArgs.push([ "line", borderData.c1[0], borderData.c1[1]]);
2482
+ }
2483
+
2484
+ if (radius2[0] > 0 || radius2[1] > 0) {
2485
+ borderArgs.push(["line", outer2[0].start.x, outer2[0].start.y]);
2486
+ outer2[0].curveTo(borderArgs);
2487
+ borderArgs.push(["line", inner2[0].end.x, inner2[0].end.y]);
2488
+ inner2[0].curveToReversed(borderArgs);
2489
+ } else {
2490
+ borderArgs.push(["line", borderData.c2[0], borderData.c2[1]]);
2491
+ borderArgs.push(["line", borderData.c3[0], borderData.c3[1]]);
2492
+ }
2493
+
2494
+ if (radius1[0] > 0 || radius1[1] > 0) {
2495
+ borderArgs.push(["line", inner1[1].end.x, inner1[1].end.y]);
2496
+ inner1[1].curveToReversed(borderArgs);
2497
+ } else {
2498
+ borderArgs.push(["line", borderData.c4[0], borderData.c4[1]]);
2499
+ }
2500
+
2501
+ return borderArgs;
2502
+ }
2503
+
2504
+ function parseCorner(borderArgs, radius1, radius2, corner1, corner2, x, y) {
2505
+ if (radius1[0] > 0 || radius1[1] > 0) {
2506
+ borderArgs.push(["line", corner1[0].start.x, corner1[0].start.y]);
2507
+ corner1[0].curveTo(borderArgs);
2508
+ corner1[1].curveTo(borderArgs);
2509
+ } else {
2510
+ borderArgs.push(["line", x, y]);
2511
+ }
2512
+
2513
+ if (radius2[0] > 0 || radius2[1] > 0) {
2514
+ borderArgs.push(["line", corner2[0].start.x, corner2[0].start.y]);
2515
+ }
2516
+ }
2517
+
2518
+ function negativeZIndex(container) {
2519
+ return container.cssInt("zIndex") < 0;
2520
+ }
2521
+
2522
+ function positiveZIndex(container) {
2523
+ return container.cssInt("zIndex") > 0;
2524
+ }
2525
+
2526
+ function zIndex0(container) {
2527
+ return container.cssInt("zIndex") === 0;
2528
+ }
2529
+
2530
+ function inlineLevel(container) {
2531
+ return ["inline", "inline-block", "inline-table"].indexOf(container.css("display")) !== -1;
2532
+ }
2533
+
2534
+ function isStackingContext(container) {
2535
+ return (container instanceof StackingContext);
2536
+ }
2537
+
2538
+ function hasText(container) {
2539
+ return container.node.data.trim().length > 0;
2540
+ }
2541
+
2542
+ function noLetterSpacing(container) {
2543
+ return (/^(normal|none|0px)$/.test(container.parent.css("letterSpacing")));
2544
+ }
2545
+
2546
+ function getBorderRadiusData(container) {
2547
+ return ["TopLeft", "TopRight", "BottomRight", "BottomLeft"].map(function(side) {
2548
+ var value = container.css('border' + side + 'Radius');
2549
+ var arr = value.split(" ");
2550
+ if (arr.length <= 1) {
2551
+ arr[1] = arr[0];
2552
+ }
2553
+ return arr.map(asInt);
2554
+ });
2555
+ }
2556
+
2557
+ function renderableNode(node) {
2558
+ return (node.nodeType === Node.TEXT_NODE || node.nodeType === Node.ELEMENT_NODE);
2559
+ }
2560
+
2561
+ function isPositionedForStacking(container) {
2562
+ var position = container.css("position");
2563
+ var zIndex = (["absolute", "relative", "fixed"].indexOf(position) !== -1) ? container.css("zIndex") : "auto";
2564
+ return zIndex !== "auto";
2565
+ }
2566
+
2567
+ function isPositioned(container) {
2568
+ return container.css("position") !== "static";
2569
+ }
2570
+
2571
+ function isFloating(container) {
2572
+ return container.css("float") !== "none";
2573
+ }
2574
+
2575
+ function isInlineBlock(container) {
2576
+ return ["inline-block", "inline-table"].indexOf(container.css("display")) !== -1;
2577
+ }
2578
+
2579
+ function not(callback) {
2580
+ var context = this;
2581
+ return function() {
2582
+ return !callback.apply(context, arguments);
2583
+ };
2584
+ }
2585
+
2586
+ function isElement(container) {
2587
+ return container.node.nodeType === Node.ELEMENT_NODE;
2588
+ }
2589
+
2590
+ function isPseudoElement(container) {
2591
+ return container.isPseudoElement === true;
2592
+ }
2593
+
2594
+ function isTextNode(container) {
2595
+ return container.node.nodeType === Node.TEXT_NODE;
2596
+ }
2597
+
2598
+ function zIndexSort(contexts) {
2599
+ return function(a, b) {
2600
+ return (a.cssInt("zIndex") + (contexts.indexOf(a) / contexts.length)) - (b.cssInt("zIndex") + (contexts.indexOf(b) / contexts.length));
2601
+ };
2602
+ }
2603
+
2604
+ function hasOpacity(container) {
2605
+ return container.getOpacity() < 1;
2606
+ }
2607
+
2608
+ function asInt(value) {
2609
+ return parseInt(value, 10);
2610
+ }
2611
+
2612
+ function getWidth(border) {
2613
+ return border.width;
2614
+ }
2615
+
2616
+ function nonIgnoredElement(nodeContainer) {
2617
+ return (nodeContainer.node.nodeType !== Node.ELEMENT_NODE || ["SCRIPT", "HEAD", "TITLE", "OBJECT", "BR", "OPTION"].indexOf(nodeContainer.node.nodeName) === -1);
2618
+ }
2619
+
2620
+ function flatten(arrays) {
2621
+ return [].concat.apply([], arrays);
2622
+ }
2623
+
2624
+ function stripQuotes(content) {
2625
+ var first = content.substr(0, 1);
2626
+ return (first === content.substr(content.length - 1) && first.match(/'|"/)) ? content.substr(1, content.length - 2) : content;
2627
+ }
2628
+
2629
+ function getWords(characters) {
2630
+ var words = [], i = 0, onWordBoundary = false, word;
2631
+ while(characters.length) {
2632
+ if (isWordBoundary(characters[i]) === onWordBoundary) {
2633
+ word = characters.splice(0, i);
2634
+ if (word.length) {
2635
+ words.push(punycode.ucs2.encode(word));
2636
+ }
2637
+ onWordBoundary =! onWordBoundary;
2638
+ i = 0;
2639
+ } else {
2640
+ i++;
2641
+ }
2642
+
2643
+ if (i >= characters.length) {
2644
+ word = characters.splice(0, i);
2645
+ if (word.length) {
2646
+ words.push(punycode.ucs2.encode(word));
2647
+ }
2648
+ }
2649
+ }
2650
+ return words;
2651
+ }
2652
+
2653
+ function isWordBoundary(characterCode) {
2654
+ return [
2655
+ 32, // <space>
2656
+ 13, // \r
2657
+ 10, // \n
2658
+ 9, // \t
2659
+ 45 // -
2660
+ ].indexOf(characterCode) !== -1;
2661
+ }
2662
+
2663
+ function hasUnicode(string) {
2664
+ return (/[^\u0000-\u00ff]/).test(string);
2665
+ }
2666
+
2667
+ module.exports = NodeParser;
2668
+
2669
+ },{"./color":3,"./fontmetrics":7,"./log":13,"./nodecontainer":14,"./pseudoelementcontainer":18,"./stackingcontext":21,"./textcontainer":25,"./utils":26,"punycode":1}],16:[function(_dereq_,module,exports){
2670
+ var XHR = _dereq_('./xhr');
2671
+ var utils = _dereq_('./utils');
2672
+ var log = _dereq_('./log');
2673
+ var createWindowClone = _dereq_('./clone');
2674
+ var decode64 = utils.decode64;
2675
+
2676
+ function Proxy(src, proxyUrl, document) {
2677
+ var supportsCORS = ('withCredentials' in new XMLHttpRequest());
2678
+ if (!proxyUrl) {
2679
+ return Promise.reject("No proxy configured");
2680
+ }
2681
+ var callback = createCallback(supportsCORS);
2682
+ var url = createProxyUrl(proxyUrl, src, callback);
2683
+
2684
+ return supportsCORS ? XHR(url) : (jsonp(document, url, callback).then(function(response) {
2685
+ return decode64(response.content);
2686
+ }));
2687
+ }
2688
+ var proxyCount = 0;
2689
+
2690
+ function ProxyURL(src, proxyUrl, document) {
2691
+ var supportsCORSImage = ('crossOrigin' in new Image());
2692
+ var callback = createCallback(supportsCORSImage);
2693
+ var url = createProxyUrl(proxyUrl, src, callback);
2694
+ return (supportsCORSImage ? Promise.resolve(url) : jsonp(document, url, callback).then(function(response) {
2695
+ return "data:" + response.type + ";base64," + response.content;
2696
+ }));
2697
+ }
2698
+
2699
+ function jsonp(document, url, callback) {
2700
+ return new Promise(function(resolve, reject) {
2701
+ var s = document.createElement("script");
2702
+ var cleanup = function() {
2703
+ delete window.html2canvas.proxy[callback];
2704
+ document.body.removeChild(s);
2705
+ };
2706
+ window.html2canvas.proxy[callback] = function(response) {
2707
+ cleanup();
2708
+ resolve(response);
2709
+ };
2710
+ s.src = url;
2711
+ s.onerror = function(e) {
2712
+ cleanup();
2713
+ reject(e);
2714
+ };
2715
+ document.body.appendChild(s);
2716
+ });
2717
+ }
2718
+
2719
+ function createCallback(useCORS) {
2720
+ return !useCORS ? "html2canvas_" + Date.now() + "_" + (++proxyCount) + "_" + Math.round(Math.random() * 100000) : "";
2721
+ }
2722
+
2723
+ function createProxyUrl(proxyUrl, src, callback) {
2724
+ return proxyUrl + "?url=" + encodeURIComponent(src) + (callback.length ? "&callback=html2canvas.proxy." + callback : "");
2725
+ }
2726
+
2727
+ function documentFromHTML(src) {
2728
+ return function(html) {
2729
+ var parser = new DOMParser(), doc;
2730
+ try {
2731
+ doc = parser.parseFromString(html, "text/html");
2732
+ } catch(e) {
2733
+ log("DOMParser not supported, falling back to createHTMLDocument");
2734
+ doc = document.implementation.createHTMLDocument("");
2735
+ try {
2736
+ doc.open();
2737
+ doc.write(html);
2738
+ doc.close();
2739
+ } catch(ee) {
2740
+ log("createHTMLDocument write not supported, falling back to document.body.innerHTML");
2741
+ doc.body.innerHTML = html; // ie9 doesnt support writing to documentElement
2742
+ }
2743
+ }
2744
+
2745
+ var b = doc.querySelector("base");
2746
+ if (!b || !b.href.host) {
2747
+ var base = doc.createElement("base");
2748
+ base.href = src;
2749
+ doc.head.insertBefore(base, doc.head.firstChild);
2750
+ }
2751
+
2752
+ return doc;
2753
+ };
2754
+ }
2755
+
2756
+ function loadUrlDocument(src, proxy, document, width, height, options) {
2757
+ return new Proxy(src, proxy, window.document).then(documentFromHTML(src)).then(function(doc) {
2758
+ return createWindowClone(doc, document, width, height, options, 0, 0);
2759
+ });
2760
+ }
2761
+
2762
+ exports.Proxy = Proxy;
2763
+ exports.ProxyURL = ProxyURL;
2764
+ exports.loadUrlDocument = loadUrlDocument;
2765
+
2766
+ },{"./clone":2,"./log":13,"./utils":26,"./xhr":28}],17:[function(_dereq_,module,exports){
2767
+ var ProxyURL = _dereq_('./proxy').ProxyURL;
2768
+
2769
+ function ProxyImageContainer(src, proxy) {
2770
+ var link = document.createElement("a");
2771
+ link.href = src;
2772
+ src = link.href;
2773
+ this.src = src;
2774
+ this.image = new Image();
2775
+ var self = this;
2776
+ this.promise = new Promise(function(resolve, reject) {
2777
+ self.image.crossOrigin = "Anonymous";
2778
+ self.image.onload = resolve;
2779
+ self.image.onerror = reject;
2780
+
2781
+ new ProxyURL(src, proxy, document).then(function(url) {
2782
+ self.image.src = url;
2783
+ })['catch'](reject);
2784
+ });
2785
+ }
2786
+
2787
+ module.exports = ProxyImageContainer;
2788
+
2789
+ },{"./proxy":16}],18:[function(_dereq_,module,exports){
2790
+ var NodeContainer = _dereq_('./nodecontainer');
2791
+
2792
+ function PseudoElementContainer(node, parent, type) {
2793
+ NodeContainer.call(this, node, parent);
2794
+ this.isPseudoElement = true;
2795
+ this.before = type === ":before";
2796
+ }
2797
+
2798
+ PseudoElementContainer.prototype.cloneTo = function(stack) {
2799
+ PseudoElementContainer.prototype.cloneTo.call(this, stack);
2800
+ stack.isPseudoElement = true;
2801
+ stack.before = this.before;
2802
+ };
2803
+
2804
+ PseudoElementContainer.prototype = Object.create(NodeContainer.prototype);
2805
+
2806
+ PseudoElementContainer.prototype.appendToDOM = function() {
2807
+ if (this.before) {
2808
+ this.parent.node.insertBefore(this.node, this.parent.node.firstChild);
2809
+ } else {
2810
+ this.parent.node.appendChild(this.node);
2811
+ }
2812
+ this.parent.node.className += " " + this.getHideClass();
2813
+ };
2814
+
2815
+ PseudoElementContainer.prototype.cleanDOM = function() {
2816
+ this.node.parentNode.removeChild(this.node);
2817
+ this.parent.node.className = this.parent.node.className.replace(this.getHideClass(), "");
2818
+ };
2819
+
2820
+ PseudoElementContainer.prototype.getHideClass = function() {
2821
+ return this["PSEUDO_HIDE_ELEMENT_CLASS_" + (this.before ? "BEFORE" : "AFTER")];
2822
+ };
2823
+
2824
+ PseudoElementContainer.prototype.PSEUDO_HIDE_ELEMENT_CLASS_BEFORE = "___html2canvas___pseudoelement_before";
2825
+ PseudoElementContainer.prototype.PSEUDO_HIDE_ELEMENT_CLASS_AFTER = "___html2canvas___pseudoelement_after";
2826
+
2827
+ module.exports = PseudoElementContainer;
2828
+
2829
+ },{"./nodecontainer":14}],19:[function(_dereq_,module,exports){
2830
+ var log = _dereq_('./log');
2831
+
2832
+ function Renderer(width, height, images, options, document) {
2833
+ this.width = width;
2834
+ this.height = height;
2835
+ this.images = images;
2836
+ this.options = options;
2837
+ this.document = document;
2838
+ }
2839
+
2840
+ Renderer.prototype.renderImage = function(container, bounds, borderData, imageContainer) {
2841
+ var paddingLeft = container.cssInt('paddingLeft'),
2842
+ paddingTop = container.cssInt('paddingTop'),
2843
+ paddingRight = container.cssInt('paddingRight'),
2844
+ paddingBottom = container.cssInt('paddingBottom'),
2845
+ borders = borderData.borders;
2846
+
2847
+ var width = bounds.width - (borders[1].width + borders[3].width + paddingLeft + paddingRight);
2848
+ var height = bounds.height - (borders[0].width + borders[2].width + paddingTop + paddingBottom);
2849
+ this.drawImage(
2850
+ imageContainer,
2851
+ 0,
2852
+ 0,
2853
+ imageContainer.image.width || width,
2854
+ imageContainer.image.height || height,
2855
+ bounds.left + paddingLeft + borders[3].width,
2856
+ bounds.top + paddingTop + borders[0].width,
2857
+ width,
2858
+ height
2859
+ );
2860
+ };
2861
+
2862
+ Renderer.prototype.renderBackground = function(container, bounds, borderData) {
2863
+ if (bounds.height > 0 && bounds.width > 0) {
2864
+ this.renderBackgroundColor(container, bounds);
2865
+ this.renderBackgroundImage(container, bounds, borderData);
2866
+ }
2867
+ };
2868
+
2869
+ Renderer.prototype.renderBackgroundColor = function(container, bounds) {
2870
+ var color = container.color("backgroundColor");
2871
+ if (!color.isTransparent()) {
2872
+ this.rectangle(bounds.left, bounds.top, bounds.width, bounds.height, color);
2873
+ }
2874
+ };
2875
+
2876
+ Renderer.prototype.renderBorders = function(borders) {
2877
+ borders.forEach(this.renderBorder, this);
2878
+ };
2879
+
2880
+ Renderer.prototype.renderBorder = function(data) {
2881
+ if (!data.color.isTransparent() && data.args !== null) {
2882
+ this.drawShape(data.args, data.color);
2883
+ }
2884
+ };
2885
+
2886
+ Renderer.prototype.renderBackgroundImage = function(container, bounds, borderData) {
2887
+ var backgroundImages = container.parseBackgroundImages();
2888
+ backgroundImages.reverse().forEach(function(backgroundImage, index, arr) {
2889
+ switch(backgroundImage.method) {
2890
+ case "url":
2891
+ var image = this.images.get(backgroundImage.args[0]);
2892
+ if (image) {
2893
+ this.renderBackgroundRepeating(container, bounds, image, arr.length - (index+1), borderData);
2894
+ } else {
2895
+ log("Error loading background-image", backgroundImage.args[0]);
2896
+ }
2897
+ break;
2898
+ case "linear-gradient":
2899
+ case "gradient":
2900
+ var gradientImage = this.images.get(backgroundImage.value);
2901
+ if (gradientImage) {
2902
+ this.renderBackgroundGradient(gradientImage, bounds, borderData);
2903
+ } else {
2904
+ log("Error loading background-image", backgroundImage.args[0]);
2905
+ }
2906
+ break;
2907
+ case "none":
2908
+ break;
2909
+ default:
2910
+ log("Unknown background-image type", backgroundImage.args[0]);
2911
+ }
2912
+ }, this);
2913
+ };
2914
+
2915
+ Renderer.prototype.renderBackgroundRepeating = function(container, bounds, imageContainer, index, borderData) {
2916
+ var size = container.parseBackgroundSize(bounds, imageContainer.image, index);
2917
+ var position = container.parseBackgroundPosition(bounds, imageContainer.image, index, size);
2918
+ var repeat = container.parseBackgroundRepeat(index);
2919
+ switch (repeat) {
2920
+ case "repeat-x":
2921
+ case "repeat no-repeat":
2922
+ this.backgroundRepeatShape(imageContainer, position, size, bounds, bounds.left + borderData[3], bounds.top + position.top + borderData[0], 99999, size.height, borderData);
2923
+ break;
2924
+ case "repeat-y":
2925
+ case "no-repeat repeat":
2926
+ this.backgroundRepeatShape(imageContainer, position, size, bounds, bounds.left + position.left + borderData[3], bounds.top + borderData[0], size.width, 99999, borderData);
2927
+ break;
2928
+ case "no-repeat":
2929
+ this.backgroundRepeatShape(imageContainer, position, size, bounds, bounds.left + position.left + borderData[3], bounds.top + position.top + borderData[0], size.width, size.height, borderData);
2930
+ break;
2931
+ default:
2932
+ this.renderBackgroundRepeat(imageContainer, position, size, {top: bounds.top, left: bounds.left}, borderData[3], borderData[0]);
2933
+ break;
2934
+ }
2935
+ };
2936
+
2937
+ module.exports = Renderer;
2938
+
2939
+ },{"./log":13}],20:[function(_dereq_,module,exports){
2940
+ var Renderer = _dereq_('../renderer');
2941
+ var LinearGradientContainer = _dereq_('../lineargradientcontainer');
2942
+ var log = _dereq_('../log');
2943
+
2944
+ function CanvasRenderer(width, height) {
2945
+ Renderer.apply(this, arguments);
2946
+ this.canvas = this.options.canvas || this.document.createElement("canvas");
2947
+ if (!this.options.canvas) {
2948
+ this.canvas.width = width;
2949
+ this.canvas.height = height;
2950
+ }
2951
+ this.ctx = this.canvas.getContext("2d");
2952
+ this.taintCtx = this.document.createElement("canvas").getContext("2d");
2953
+ this.ctx.textBaseline = "bottom";
2954
+ this.variables = {};
2955
+ log("Initialized CanvasRenderer with size", width, "x", height);
2956
+ }
2957
+
2958
+ CanvasRenderer.prototype = Object.create(Renderer.prototype);
2959
+
2960
+ CanvasRenderer.prototype.setFillStyle = function(fillStyle) {
2961
+ this.ctx.fillStyle = typeof(fillStyle) === "object" && !!fillStyle.isColor ? fillStyle.toString() : fillStyle;
2962
+ return this.ctx;
2963
+ };
2964
+
2965
+ CanvasRenderer.prototype.rectangle = function(left, top, width, height, color) {
2966
+ this.setFillStyle(color).fillRect(left, top, width, height);
2967
+ };
2968
+
2969
+ CanvasRenderer.prototype.circle = function(left, top, size, color) {
2970
+ this.setFillStyle(color);
2971
+ this.ctx.beginPath();
2972
+ this.ctx.arc(left + size / 2, top + size / 2, size / 2, 0, Math.PI*2, true);
2973
+ this.ctx.closePath();
2974
+ this.ctx.fill();
2975
+ };
2976
+
2977
+ CanvasRenderer.prototype.circleStroke = function(left, top, size, color, stroke, strokeColor) {
2978
+ this.circle(left, top, size, color);
2979
+ this.ctx.strokeStyle = strokeColor.toString();
2980
+ this.ctx.stroke();
2981
+ };
2982
+
2983
+ CanvasRenderer.prototype.drawShape = function(shape, color) {
2984
+ this.shape(shape);
2985
+ this.setFillStyle(color).fill();
2986
+ };
2987
+
2988
+ CanvasRenderer.prototype.taints = function(imageContainer) {
2989
+ if (imageContainer.tainted === null) {
2990
+ this.taintCtx.drawImage(imageContainer.image, 0, 0);
2991
+ try {
2992
+ this.taintCtx.getImageData(0, 0, 1, 1);
2993
+ imageContainer.tainted = false;
2994
+ } catch(e) {
2995
+ this.taintCtx = document.createElement("canvas").getContext("2d");
2996
+ imageContainer.tainted = true;
2997
+ }
2998
+ }
2999
+
3000
+ return imageContainer.tainted;
3001
+ };
3002
+
3003
+ CanvasRenderer.prototype.drawImage = function(imageContainer, sx, sy, sw, sh, dx, dy, dw, dh) {
3004
+ if (!this.taints(imageContainer) || this.options.allowTaint) {
3005
+ this.ctx.drawImage(imageContainer.image, sx, sy, sw, sh, dx, dy, dw, dh);
3006
+ }
3007
+ };
3008
+
3009
+ CanvasRenderer.prototype.clip = function(shapes, callback, context) {
3010
+ this.ctx.save();
3011
+ shapes.filter(hasEntries).forEach(function(shape) {
3012
+ this.shape(shape).clip();
3013
+ }, this);
3014
+ callback.call(context);
3015
+ this.ctx.restore();
3016
+ };
3017
+
3018
+ CanvasRenderer.prototype.shape = function(shape) {
3019
+ this.ctx.beginPath();
3020
+ shape.forEach(function(point, index) {
3021
+ if (point[0] === "rect") {
3022
+ this.ctx.rect.apply(this.ctx, point.slice(1));
3023
+ } else {
3024
+ this.ctx[(index === 0) ? "moveTo" : point[0] + "To" ].apply(this.ctx, point.slice(1));
3025
+ }
3026
+ }, this);
3027
+ this.ctx.closePath();
3028
+ return this.ctx;
3029
+ };
3030
+
3031
+ CanvasRenderer.prototype.font = function(color, style, variant, weight, size, family) {
3032
+ this.setFillStyle(color).font = [style, variant, weight, size, family].join(" ").split(",")[0];
3033
+ };
3034
+
3035
+ CanvasRenderer.prototype.fontShadow = function(color, offsetX, offsetY, blur) {
3036
+ this.setVariable("shadowColor", color.toString())
3037
+ .setVariable("shadowOffsetY", offsetX)
3038
+ .setVariable("shadowOffsetX", offsetY)
3039
+ .setVariable("shadowBlur", blur);
3040
+ };
3041
+
3042
+ CanvasRenderer.prototype.clearShadow = function() {
3043
+ this.setVariable("shadowColor", "rgba(0,0,0,0)");
3044
+ };
3045
+
3046
+ CanvasRenderer.prototype.setOpacity = function(opacity) {
3047
+ this.ctx.globalAlpha = opacity;
3048
+ };
3049
+
3050
+ CanvasRenderer.prototype.setTransform = function(transform) {
3051
+ this.ctx.translate(transform.origin[0], transform.origin[1]);
3052
+ this.ctx.transform.apply(this.ctx, transform.matrix);
3053
+ this.ctx.translate(-transform.origin[0], -transform.origin[1]);
3054
+ };
3055
+
3056
+ CanvasRenderer.prototype.setVariable = function(property, value) {
3057
+ if (this.variables[property] !== value) {
3058
+ this.variables[property] = this.ctx[property] = value;
3059
+ }
3060
+
3061
+ return this;
3062
+ };
3063
+
3064
+ CanvasRenderer.prototype.text = function(text, left, bottom) {
3065
+ this.ctx.fillText(text, left, bottom);
3066
+ };
3067
+
3068
+ CanvasRenderer.prototype.backgroundRepeatShape = function(imageContainer, backgroundPosition, size, bounds, left, top, width, height, borderData) {
3069
+ var shape = [
3070
+ ["line", Math.round(left), Math.round(top)],
3071
+ ["line", Math.round(left + width), Math.round(top)],
3072
+ ["line", Math.round(left + width), Math.round(height + top)],
3073
+ ["line", Math.round(left), Math.round(height + top)]
3074
+ ];
3075
+ this.clip([shape], function() {
3076
+ this.renderBackgroundRepeat(imageContainer, backgroundPosition, size, bounds, borderData[3], borderData[0]);
3077
+ }, this);
3078
+ };
3079
+
3080
+ CanvasRenderer.prototype.renderBackgroundRepeat = function(imageContainer, backgroundPosition, size, bounds, borderLeft, borderTop) {
3081
+ var offsetX = Math.round(bounds.left + backgroundPosition.left + borderLeft), offsetY = Math.round(bounds.top + backgroundPosition.top + borderTop);
3082
+ this.setFillStyle(this.ctx.createPattern(this.resizeImage(imageContainer, size), "repeat"));
3083
+ this.ctx.translate(offsetX, offsetY);
3084
+ this.ctx.fill();
3085
+ this.ctx.translate(-offsetX, -offsetY);
3086
+ };
3087
+
3088
+ CanvasRenderer.prototype.renderBackgroundGradient = function(gradientImage, bounds) {
3089
+ if (gradientImage instanceof LinearGradientContainer) {
3090
+ var gradient = this.ctx.createLinearGradient(
3091
+ bounds.left + bounds.width * gradientImage.x0,
3092
+ bounds.top + bounds.height * gradientImage.y0,
3093
+ bounds.left + bounds.width * gradientImage.x1,
3094
+ bounds.top + bounds.height * gradientImage.y1);
3095
+ gradientImage.colorStops.forEach(function(colorStop) {
3096
+ gradient.addColorStop(colorStop.stop, colorStop.color.toString());
3097
+ });
3098
+ this.rectangle(bounds.left, bounds.top, bounds.width, bounds.height, gradient);
3099
+ }
3100
+ };
3101
+
3102
+ CanvasRenderer.prototype.resizeImage = function(imageContainer, size) {
3103
+ var image = imageContainer.image;
3104
+ if(image.width === size.width && image.height === size.height) {
3105
+ return image;
3106
+ }
3107
+
3108
+ var ctx, canvas = document.createElement('canvas');
3109
+ canvas.width = size.width;
3110
+ canvas.height = size.height;
3111
+ ctx = canvas.getContext("2d");
3112
+ ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, size.width, size.height );
3113
+ return canvas;
3114
+ };
3115
+
3116
+ function hasEntries(array) {
3117
+ return array.length > 0;
3118
+ }
3119
+
3120
+ module.exports = CanvasRenderer;
3121
+
3122
+ },{"../lineargradientcontainer":12,"../log":13,"../renderer":19}],21:[function(_dereq_,module,exports){
3123
+ var NodeContainer = _dereq_('./nodecontainer');
3124
+
3125
+ function StackingContext(hasOwnStacking, opacity, element, parent) {
3126
+ NodeContainer.call(this, element, parent);
3127
+ this.ownStacking = hasOwnStacking;
3128
+ this.contexts = [];
3129
+ this.children = [];
3130
+ this.opacity = (this.parent ? this.parent.stack.opacity : 1) * opacity;
3131
+ }
3132
+
3133
+ StackingContext.prototype = Object.create(NodeContainer.prototype);
3134
+
3135
+ StackingContext.prototype.getParentStack = function(context) {
3136
+ var parentStack = (this.parent) ? this.parent.stack : null;
3137
+ return parentStack ? (parentStack.ownStacking ? parentStack : parentStack.getParentStack(context)) : context.stack;
3138
+ };
3139
+
3140
+ module.exports = StackingContext;
3141
+
3142
+ },{"./nodecontainer":14}],22:[function(_dereq_,module,exports){
3143
+ function Support(document) {
3144
+ this.rangeBounds = this.testRangeBounds(document);
3145
+ this.cors = this.testCORS();
3146
+ this.svg = this.testSVG();
3147
+ }
3148
+
3149
+ Support.prototype.testRangeBounds = function(document) {
3150
+ var range, testElement, rangeBounds, rangeHeight, support = false;
3151
+
3152
+ if (document.createRange) {
3153
+ range = document.createRange();
3154
+ if (range.getBoundingClientRect) {
3155
+ testElement = document.createElement('boundtest');
3156
+ testElement.style.height = "123px";
3157
+ testElement.style.display = "block";
3158
+ document.body.appendChild(testElement);
3159
+
3160
+ range.selectNode(testElement);
3161
+ rangeBounds = range.getBoundingClientRect();
3162
+ rangeHeight = rangeBounds.height;
3163
+
3164
+ if (rangeHeight === 123) {
3165
+ support = true;
3166
+ }
3167
+ document.body.removeChild(testElement);
3168
+ }
3169
+ }
3170
+
3171
+ return support;
3172
+ };
3173
+
3174
+ Support.prototype.testCORS = function() {
3175
+ return typeof((new Image()).crossOrigin) !== "undefined";
3176
+ };
3177
+
3178
+ Support.prototype.testSVG = function() {
3179
+ var img = new Image();
3180
+ var canvas = document.createElement("canvas");
3181
+ var ctx = canvas.getContext("2d");
3182
+ img.src = "data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'></svg>";
3183
+
3184
+ try {
3185
+ ctx.drawImage(img, 0, 0);
3186
+ canvas.toDataURL();
3187
+ } catch(e) {
3188
+ return false;
3189
+ }
3190
+ return true;
3191
+ };
3192
+
3193
+ module.exports = Support;
3194
+
3195
+ },{}],23:[function(_dereq_,module,exports){
3196
+ var XHR = _dereq_('./xhr');
3197
+ var decode64 = _dereq_('./utils').decode64;
3198
+
3199
+ function SVGContainer(src) {
3200
+ this.src = src;
3201
+ this.image = null;
3202
+ var self = this;
3203
+
3204
+ this.promise = this.hasFabric().then(function() {
3205
+ return (self.isInline(src) ? Promise.resolve(self.inlineFormatting(src)) : XHR(src));
3206
+ }).then(function(svg) {
3207
+ return new Promise(function(resolve) {
3208
+ window.html2canvas.svg.fabric.loadSVGFromString(svg, self.createCanvas.call(self, resolve));
3209
+ });
3210
+ });
3211
+ }
3212
+
3213
+ SVGContainer.prototype.hasFabric = function() {
3214
+ return !window.html2canvas.svg || !window.html2canvas.svg.fabric ? Promise.reject(new Error("html2canvas.svg.js is not loaded, cannot render svg")) : Promise.resolve();
3215
+ };
3216
+
3217
+ SVGContainer.prototype.inlineFormatting = function(src) {
3218
+ return (/^data:image\/svg\+xml;base64,/.test(src)) ? this.decode64(this.removeContentType(src)) : this.removeContentType(src);
3219
+ };
3220
+
3221
+ SVGContainer.prototype.removeContentType = function(src) {
3222
+ return src.replace(/^data:image\/svg\+xml(;base64)?,/,'');
3223
+ };
3224
+
3225
+ SVGContainer.prototype.isInline = function(src) {
3226
+ return (/^data:image\/svg\+xml/i.test(src));
3227
+ };
3228
+
3229
+ SVGContainer.prototype.createCanvas = function(resolve) {
3230
+ var self = this;
3231
+ return function (objects, options) {
3232
+ var canvas = new window.html2canvas.svg.fabric.StaticCanvas('c');
3233
+ self.image = canvas.lowerCanvasEl;
3234
+ canvas
3235
+ .setWidth(options.width)
3236
+ .setHeight(options.height)
3237
+ .add(window.html2canvas.svg.fabric.util.groupSVGElements(objects, options))
3238
+ .renderAll();
3239
+ resolve(canvas.lowerCanvasEl);
3240
+ };
3241
+ };
3242
+
3243
+ SVGContainer.prototype.decode64 = function(str) {
3244
+ return (typeof(window.atob) === "function") ? window.atob(str) : decode64(str);
3245
+ };
3246
+
3247
+ module.exports = SVGContainer;
3248
+
3249
+ },{"./utils":26,"./xhr":28}],24:[function(_dereq_,module,exports){
3250
+ var SVGContainer = _dereq_('./svgcontainer');
3251
+
3252
+ function SVGNodeContainer(node, _native) {
3253
+ this.src = node;
3254
+ this.image = null;
3255
+ var self = this;
3256
+
3257
+ this.promise = _native ? new Promise(function(resolve, reject) {
3258
+ self.image = new Image();
3259
+ self.image.onload = resolve;
3260
+ self.image.onerror = reject;
3261
+ self.image.src = "data:image/svg+xml," + (new XMLSerializer()).serializeToString(node);
3262
+ if (self.image.complete === true) {
3263
+ resolve(self.image);
3264
+ }
3265
+ }) : this.hasFabric().then(function() {
3266
+ return new Promise(function(resolve) {
3267
+ window.html2canvas.svg.fabric.parseSVGDocument(node, self.createCanvas.call(self, resolve));
3268
+ });
3269
+ });
3270
+ }
3271
+
3272
+ SVGNodeContainer.prototype = Object.create(SVGContainer.prototype);
3273
+
3274
+ module.exports = SVGNodeContainer;
3275
+
3276
+ },{"./svgcontainer":23}],25:[function(_dereq_,module,exports){
3277
+ var NodeContainer = _dereq_('./nodecontainer');
3278
+
3279
+ function TextContainer(node, parent) {
3280
+ NodeContainer.call(this, node, parent);
3281
+ }
3282
+
3283
+ TextContainer.prototype = Object.create(NodeContainer.prototype);
3284
+
3285
+ TextContainer.prototype.applyTextTransform = function() {
3286
+ this.node.data = this.transform(this.parent.css("textTransform"));
3287
+ };
3288
+
3289
+ TextContainer.prototype.transform = function(transform) {
3290
+ var text = this.node.data;
3291
+ switch(transform){
3292
+ case "lowercase":
3293
+ return text.toLowerCase();
3294
+ case "capitalize":
3295
+ return text.replace(/(^|\s|:|-|\(|\))([a-z])/g, capitalize);
3296
+ case "uppercase":
3297
+ return text.toUpperCase();
3298
+ default:
3299
+ return text;
3300
+ }
3301
+ };
3302
+
3303
+ function capitalize(m, p1, p2) {
3304
+ if (m.length > 0) {
3305
+ return p1 + p2.toUpperCase();
3306
+ }
3307
+ }
3308
+
3309
+ module.exports = TextContainer;
3310
+
3311
+ },{"./nodecontainer":14}],26:[function(_dereq_,module,exports){
3312
+ exports.smallImage = function smallImage() {
3313
+ return "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
3314
+ };
3315
+
3316
+ exports.bind = function(callback, context) {
3317
+ return function() {
3318
+ return callback.apply(context, arguments);
3319
+ };
3320
+ };
3321
+
3322
+ /*
3323
+ * base64-arraybuffer
3324
+ * https://github.com/niklasvh/base64-arraybuffer
3325
+ *
3326
+ * Copyright (c) 2012 Niklas von Hertzen
3327
+ * Licensed under the MIT license.
3328
+ */
3329
+
3330
+ exports.decode64 = function(base64) {
3331
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
3332
+ var len = base64.length, i, encoded1, encoded2, encoded3, encoded4, byte1, byte2, byte3;
3333
+
3334
+ var output = "";
3335
+
3336
+ for (i = 0; i < len; i+=4) {
3337
+ encoded1 = chars.indexOf(base64[i]);
3338
+ encoded2 = chars.indexOf(base64[i+1]);
3339
+ encoded3 = chars.indexOf(base64[i+2]);
3340
+ encoded4 = chars.indexOf(base64[i+3]);
3341
+
3342
+ byte1 = (encoded1 << 2) | (encoded2 >> 4);
3343
+ byte2 = ((encoded2 & 15) << 4) | (encoded3 >> 2);
3344
+ byte3 = ((encoded3 & 3) << 6) | encoded4;
3345
+ if (encoded3 === 64) {
3346
+ output += String.fromCharCode(byte1);
3347
+ } else if (encoded4 === 64 || encoded4 === -1) {
3348
+ output += String.fromCharCode(byte1, byte2);
3349
+ } else{
3350
+ output += String.fromCharCode(byte1, byte2, byte3);
3351
+ }
3352
+ }
3353
+
3354
+ return output;
3355
+ };
3356
+
3357
+ exports.getBounds = function(node) {
3358
+ if (node.getBoundingClientRect) {
3359
+ var clientRect = node.getBoundingClientRect();
3360
+ var width = node.offsetWidth == null ? clientRect.width : node.offsetWidth;
3361
+ return {
3362
+ top: clientRect.top,
3363
+ bottom: clientRect.bottom || (clientRect.top + clientRect.height),
3364
+ right: clientRect.left + width,
3365
+ left: clientRect.left,
3366
+ width: width,
3367
+ height: node.offsetHeight == null ? clientRect.height : node.offsetHeight
3368
+ };
3369
+ }
3370
+ return {};
3371
+ };
3372
+
3373
+ exports.offsetBounds = function(node) {
3374
+ var parent = node.offsetParent ? exports.offsetBounds(node.offsetParent) : {top: 0, left: 0};
3375
+
3376
+ return {
3377
+ top: node.offsetTop + parent.top,
3378
+ bottom: node.offsetTop + node.offsetHeight + parent.top,
3379
+ right: node.offsetLeft + parent.left + node.offsetWidth,
3380
+ left: node.offsetLeft + parent.left,
3381
+ width: node.offsetWidth,
3382
+ height: node.offsetHeight
3383
+ };
3384
+ };
3385
+
3386
+ exports.parseBackgrounds = function(backgroundImage) {
3387
+ var whitespace = ' \r\n\t',
3388
+ method, definition, prefix, prefix_i, block, results = [],
3389
+ mode = 0, numParen = 0, quote, args;
3390
+ var appendResult = function() {
3391
+ if(method) {
3392
+ if (definition.substr(0, 1) === '"') {
3393
+ definition = definition.substr(1, definition.length - 2);
3394
+ }
3395
+ if (definition) {
3396
+ args.push(definition);
3397
+ }
3398
+ if (method.substr(0, 1) === '-' && (prefix_i = method.indexOf('-', 1 ) + 1) > 0) {
3399
+ prefix = method.substr(0, prefix_i);
3400
+ method = method.substr(prefix_i);
3401
+ }
3402
+ results.push({
3403
+ prefix: prefix,
3404
+ method: method.toLowerCase(),
3405
+ value: block,
3406
+ args: args,
3407
+ image: null
3408
+ });
3409
+ }
3410
+ args = [];
3411
+ method = prefix = definition = block = '';
3412
+ };
3413
+ args = [];
3414
+ method = prefix = definition = block = '';
3415
+ backgroundImage.split("").forEach(function(c) {
3416
+ if (mode === 0 && whitespace.indexOf(c) > -1) {
3417
+ return;
3418
+ }
3419
+ switch(c) {
3420
+ case '"':
3421
+ if(!quote) {
3422
+ quote = c;
3423
+ } else if(quote === c) {
3424
+ quote = null;
3425
+ }
3426
+ break;
3427
+ case '(':
3428
+ if(quote) {
3429
+ break;
3430
+ } else if(mode === 0) {
3431
+ mode = 1;
3432
+ block += c;
3433
+ return;
3434
+ } else {
3435
+ numParen++;
3436
+ }
3437
+ break;
3438
+ case ')':
3439
+ if (quote) {
3440
+ break;
3441
+ } else if(mode === 1) {
3442
+ if(numParen === 0) {
3443
+ mode = 0;
3444
+ block += c;
3445
+ appendResult();
3446
+ return;
3447
+ } else {
3448
+ numParen--;
3449
+ }
3450
+ }
3451
+ break;
3452
+
3453
+ case ',':
3454
+ if (quote) {
3455
+ break;
3456
+ } else if(mode === 0) {
3457
+ appendResult();
3458
+ return;
3459
+ } else if (mode === 1) {
3460
+ if (numParen === 0 && !method.match(/^url$/i)) {
3461
+ args.push(definition);
3462
+ definition = '';
3463
+ block += c;
3464
+ return;
3465
+ }
3466
+ }
3467
+ break;
3468
+ }
3469
+
3470
+ block += c;
3471
+ if (mode === 0) {
3472
+ method += c;
3473
+ } else {
3474
+ definition += c;
3475
+ }
3476
+ });
3477
+
3478
+ appendResult();
3479
+ return results;
3480
+ };
3481
+
3482
+ },{}],27:[function(_dereq_,module,exports){
3483
+ var GradientContainer = _dereq_('./gradientcontainer');
3484
+
3485
+ function WebkitGradientContainer(imageData) {
3486
+ GradientContainer.apply(this, arguments);
3487
+ this.type = imageData.args[0] === "linear" ? GradientContainer.TYPES.LINEAR : GradientContainer.TYPES.RADIAL;
3488
+ }
3489
+
3490
+ WebkitGradientContainer.prototype = Object.create(GradientContainer.prototype);
3491
+
3492
+ module.exports = WebkitGradientContainer;
3493
+
3494
+ },{"./gradientcontainer":9}],28:[function(_dereq_,module,exports){
3495
+ function XHR(url) {
3496
+ return new Promise(function(resolve, reject) {
3497
+ var xhr = new XMLHttpRequest();
3498
+ xhr.open('GET', url);
3499
+
3500
+ xhr.onload = function() {
3501
+ if (xhr.status === 200) {
3502
+ resolve(xhr.responseText);
3503
+ } else {
3504
+ reject(new Error(xhr.statusText));
3505
+ }
3506
+ };
3507
+
3508
+ xhr.onerror = function() {
3509
+ reject(new Error("Network Error"));
3510
+ };
3511
+
3512
+ xhr.send();
3513
+ });
3514
+ }
3515
+
3516
+ module.exports = XHR;
3517
+
3518
+ },{}]},{},[4])(4)
3519
+ });