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 & 0x3F
128F) + 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 >>>
vendor: 13,846 bytes, lines 155-472
155 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 width = options.width != null ? options.width : node.ownerDocument.defaultView.innerWidth; 944 height = options.height != null ? options.height : node.ownerDocument.defaultView.innerHeight; 945 return renderDocument(node.ownerDocument, options, width, height, index).then(function(canvas) { 946 if (typeof(options.onrendered) === "function") { 947 log("options.onrendered is deprecated, html2canvas returns a Promise containing the canvas"); 948 options.onrendered(canvas); 949 } 950 return canvas; 951 }); 952 } 953 954 html2canvas.CanvasRenderer = CanvasRenderer; 955 html2canvas.NodeContainer = NodeContainer; 956 html2canvas.log = log; 957 html2canvas.utils = utils; 958 959 var html2canvasExport = (typeof(document) === "undefined" || typeof(Object.create) !== "function" || typeof(document.createElement("canvas").getContext) !== "function") ? function() { 960 return Promise.reject("No canvas support"); 961 } : html2canvas; 962 963 module.exports = html2canvasExport; 964 965 if (typeof(define) === 'function' && define.amd) { 966 define('html2canvas', [], function() { 967 return html2canvasExport; 968 }); 969 } 970 971 function renderDocument(document, options, windowWidth, windowHeight, html2canvasIndex) { 972 return createWindowClone(document, document, windowWidth, windowHeight, options, document.defaultView.pageXOffset, document.defaultView.pageYOffset).then(function(container) { 973 log("Document cloned"); 974 975 var attributeName = html2canvasNodeAttribute + html2canvasIndex; 976 var selector = "[" + attributeName + "='" + html2canvasIndex + "']"; 977 document.querySelector(selector).removeAttribute(attributeName); 978 var clonedWindow = container.contentWindow; 979 var node = clonedWindow.document.querySelector(selector);
980 var oncloneHandler = (typeof(options.onclone) === "function") ? Promise.resolve(options.onclone(clonedWindow.document)) : Promise.resolve(true); 981 return oncloneHandler.then(function() { 982 return renderWindow(node, container, options, windowWidth, windowHeight); 983 }); 984 }); 985 } 986 987 function renderWindow(node, container, options, windowWidth, windowHeight) { 988 var clonedWindow = container.contentWindow; 989 var support = new Support(clonedWindow.document); 990 var imageLoader = new ImageLoader(options, support); 991 var bounds = getBounds(node); 992 var width = options.type === "view" ? windowWidth : documentWidth(clonedWindow.document); 993 var height = options.type === "view" ? windowHeight : documentHeight(clonedWindow.document); 994 // console.log() 995 var renderer = new options.renderer(width, height, imageLoader, options, node.ownerDocument); 996 var parser = new NodeParser(node, renderer, support, imageLoader, options); 997 return parser.ready.then(function() { 998 log("Finished rendering"); 999 var canvas; 1000 if (options.type === "view") { 1001 canvas = crop(renderer.canvas, {width: renderer.canvas.width, height: renderer.canvas.height, top: 0, left: 0, x: 0, y: 0}); 1002 } else if (node === clonedWindow.document.body || node === clonedWindow.document.documentElement) { 1003 canvas = renderer.canvas; 1004 }else if(options.scale && options.canvas !=null){ 1005 log("放大canvas",options.canvas); 1006 var scale = options.scale || 1; 1007 // console.log(bounds.top *scale) 1008 canvas = crop(renderer.canvas, {width: bounds.width * scale, height:bounds.height * scale, top: bounds.top *scale, left: bounds.left *scale, x: 0, y: 0}); 1009 // console.log(canvas.width) 1010 1011 } 1012 else { 1013 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}); 1014 } 1015 1016 cleanupContainer(container, options); 1017 return canvas; 1018 }); 1019 } 1020 1021 function cleanupContainer(container, options) { 1022 if (options.removeContainer) { 1023 container.parentNode.removeChild(container); 1024 log("Cleaned up container"); 1025 } 1026 } 1027 1028 function crop(canvas, bounds) { 1029 var croppedCanvas = document.createElement("canvas"); 1030 var x1 = Math.min(canvas.width - 1, Math.max(0, bounds.left)); 1031 var x2 = Math.min(canvas.width, Math.max(1, bounds.left + bounds.width)); 1032 var y1 = Math.min(canvas.height - 1, Math.max(0, bounds.top)); 1033 var y2 = Math.min(canvas.height, Math.max(1, bounds.top + bounds.height)); 1034 croppedCanvas.width = bounds.width; 1035 croppedCanvas.height = bounds.height; 1036 var width = x2-x1; 1037 var height = y2-y1; 1038 1039 log("Cropping canvas at:", "left:", bounds.left, "top:", bounds.top, "width:", width, "height:", height); 1040 log("Resulting crop with width", bounds.width, "and height", bounds.height, "with x", x1, "and y", y1); 1041 croppedCanvas.getContext("2d").drawImage(canvas, x1, y1, width, height, bounds.x, bounds.y, width, height); 1042 return croppedCanvas; 1043 } 1044 1045 function documentWidth (doc) { 1046 return Math.max( 1047 Math.max(doc.body.scrollWidth, doc.documentElement.scrollWidth), 1048 Math.max(doc.body.offsetWidth, doc.documentElement.offsetWidth), 1049 Math.max(doc.body.clientWidth, doc.documentElement.clientWidth) 1050 ); 1051 } 1052 1053 function documentHeight (doc) { 1054 return Math.max( 1055 Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight), 1056 Math.max(doc.body.offsetHeight, doc.documentElement.offsetHeight), 1057 Math.max(doc.body.clientHeight, doc.documentElement.clientHeight) 1058 ); 1059 } 1060 1061 function absoluteUrl(url) { 1062 var link = document.createElement("a"); 1063 link.href = url; 1064 link.href = link.href; 1065 return link; 1066 } 1067 1068 },{"./clone":2,"./imageloader":11,"./log":13,"./nodecontainer":14,"./nodeparser":15,"./proxy":16,"./renderers/canvas":20,"./support":22,"./utils":26}],5:[function(_dereq_,module,exports){ 1069 var log = _dereq_('./log'); 1070 var smallImage = _dereq_('./utils').smallImage; 1071 1072 function DummyImageContainer(src) { 1073 this.src = src; 1074 log("DummyImageContainer for", src); 1075 if (!this.promise || !this.image) { 1076 log("Initiating DummyImageContainer"); 1077 DummyImageContainer.prototype.image = new Image(); 1078 var image = this.image; 1079 DummyImageContainer.prototype.promise = new Promise(function(resolve, reject) { 1080 image.onload = resolve; 1081 image.onerror = reject; 1082 image.src = smallImage(); 1083 if (image.complete === true) { 1084 resolve(image); 1085 } 1086 }); 1087 } 1088 } 1089 1090 module.exports = DummyImageContainer; 1091 1092 }
1092,{"./log":13,"./utils":26}],6:[function(_dereq_,module,exports){ 1093 var smallImage = _dereq_('./utils').smallImage; 1094 1095 function Font(family, size) { 1096 var container = document.createElement('div'), 1097 img = document.createElement('img'), 1098 span = document.createElement('span'), 1099 sampleText = 'Hidden Text', 1100 baseline, 1101 middle; 1102 1103 container.style.visibility = "hidden"; 1104 container.style.fontFamily = family; 1105 container.style.fontSize = size; 1106 container.style.margin = 0; 1107 container.style.padding = 0; 1108 1109 document.body.appendChild(container); 1110 1111 img.src = smallImage(); 1112 img.width = 1; 1113 img.height = 1; 1114 1115 img.style.margin = 0; 1116 img.style.padding = 0; 1117 img.style.verticalAlign = "baseline"; 1118 1119 span.style.fontFamily = family; 1120 span.style.fontSize = size; 1121 span.style.margin = 0; 1122 span.style.padding = 0; 1123 1124 span.appendChild(document.createTextNode(sampleText)); 1125 container.appendChild(span); 1126 container.appendChild(img); 1127 baseline = (img.offsetTop - span.offsetTop) + 1; 1128 1129 container.removeChild(span); 1130 container.appendChild(document.createTextNode(sampleText)); 1131 1132 container.style.lineHeight = "normal"; 1133 img.style.verticalAlign = "super"; 1134 1135 middle = (img.offsetTop-container.offsetTop) + 1; 1136 1137 document.body.removeChild(container); 1138 1139 this.baseline = baseline; 1140 this.lineWidth = 1; 1141 this.middle = middle; 1142 } 1143 1144 module.exports = Font; 1145 1146 },{"./utils":26}],7:[function(_dereq_,module,exports){ 1147 var Font = _dereq_('./font'); 1148 1149 function FontMetrics() { 1150 this.data = {}; 1151 } 1152 1153 FontMetrics.prototype.getMetrics = function(family, size) { 1154 if (this.data[family + "-" + size] === undefined) { 1155 this.data[family + "-" + size] = new Font(family, size); 1156 } 1157 return this.data[family + "-" + size]; 1158 }; 1159 1160 module.exports = FontMetrics; 1161 1162 },{"./font":6}],8:[function(_dereq_,module,exports){ 1163 var utils = _dereq_('./utils'); 1164 var getBounds = utils.getBounds; 1165 var loadUrlDocument = _dereq_('./proxy').loadUrlDocument; 1166 1167 function FrameContainer(container, sameOrigin, options) { 1168 this.image = null; 1169 this.src = container; 1170 var self = this; 1171 var bounds = getBounds(container); 1172 this.promise = (!sameOrigin ? this.proxyLoad(options.proxy, bounds, options) : new Promise(function(resolve) { 1173 if (container.contentWindow.document.URL === "about:blank" || container.contentWindow.document.documentElement == null) { 1174 container.contentWindow.onload = container.onload = function() { 1175 resolve(container); 1176 }; 1177 } else { 1178 resolve(container); 1179 } 1180 })).then(function(container) { 1181 var html2canvas = _dereq_('./core'); 1182 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}); 1183 }).then(function(canvas) { 1184 return self.image = canvas; 1185 }); 1186 } 1187 1188 FrameContainer.prototype.proxyLoad = function(proxy, bounds, options) { 1189 var container = this.src; 1190 return loadUrlDocument(container.src, proxy, container.ownerDocument, bounds.width, bounds.height, options); 1191 }; 1192 1193 module.exports = FrameContainer; 1194 1195 },{"./core":4,"./proxy":16,"./utils":26}],9:[function(_dereq_,module,exports){ 1196 function GradientContainer(imageData) { 1197 this.src = imageData.value; 1198 this.colorStops = []; 1199 this.type = null; 1200 this.x0 = 0.5; 1201 this.y0 = 0.5; 1202 this.x1 = 0.5; 1203 this.y1 = 0.5; 1204 this.promise = Promise.resolve(true); 1205 } 1206 1207 GradientContainer.TYPES = { 1208 LINEAR: 1, 1209 RADIAL: 2 1210 }; 1211 1212// TODO: support hsl[a], negative %/length values 1213// TODO: support <angle> (e.g. -?\d{1,3}(?:\.\d+)deg, etc. : https://developer.mozilla.org/docs/Web/CSS/angle ) 1214 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; 1215 1216 module.exports = GradientContainer; 1217 1218 },{}],10:[function(_dereq_,module,exports){ 1219 function ImageContainer(src, cors) { 1220 this.src = src; 1221 this.image = new Image(); 1222 var self = this; 1223 this.tainted = null; 1224 this.promise = new Promise(function(resolve, reject) { 1225 self.image.onload = resolve; 1226 self.image.onerror = reject; 1227 if (cors) { 1228 self.image.crossOrigin = "anonymous"; 1229 } 1230 self.image.src = src; 1231 if (self.image.complete === true) { 1232 resolve(self.image); 1233 } 1234 }); 1235 } 1236 1237 module.exports = ImageContainer; 1238 1239 },{}],11:[function(_dereq_,module,exports){ 1240 var log = _dereq_('./log'); 1241 var ImageContainer = _dereq_('./imagecontainer'); 1242 var DummyImageContainer = _dereq_('./dummyimagecontainer'); 1243 var ProxyImageContainer = _dereq_('./proxyimagecontainer'); 1244 var FrameContainer = _dereq_('./framecontainer'); 1245 var SVGContainer = _dereq_('./svgcontainer'); 1246 var SVGNodeContainer = _dereq_('./svgnodecontainer'); 1247 var LinearGradientContainer = _dereq_('./lineargradientcontainer'); 1248 var WebkitGradientContainer = _dereq_('./webkitgradientcontainer'); 1249 var bind = _dereq_('./utils').bind; 1250 1251 function ImageLoader(options, support) { 1252 this.link = null; 1253 this.options = options; 1254 this.support = support; 1255 this.origin = this.getOrigin(window.location.href); 1256 } 1257 1258 ImageLoader.prototype.findImages = function(nodes) { 1259 var images = []; 1260 nodes.reduce(function(imageNodes, container) { 1261 switch(container.node.nodeName) { 1262 case "IMG": 1263 return imageNodes.concat([{ 1264 args: [container.node.src], 1265 method: "url" 1266 }]); 1267 case "svg": 1268 case "IFRAME": 1269 return imageNodes.concat([{ 1270 args: [container.node], 1271 method: container.node.nodeName 1272 }]); 1273 } 1274 return imageNodes; 1275 }
1275, []).forEach(this.addImage(images, this.loadImage), this); 1276 return images; 1277 }; 1278 1279 ImageLoader.prototype.findBackgroundImage = function(images, container) { 1280 container.parseBackgroundImages().filter(this.hasImageBackground).forEach(this.addImage(images, this.loadImage), this); 1281 return images; 1282 }; 1283 1284 ImageLoader.prototype.addImage = function(images, callback) { 1285 return function(newImage) { 1286 newImage.args.forEach(function(image) { 1287 if (!this.imageExists(images, image)) { 1288 images.splice(0, 0, callback.call(this, newImage)); 1289 log('Added image #' + (images.length), typeof(image) === "string" ? image.substring(0, 100) : image); 1290 } 1291 }, this); 1292 }; 1293 }; 1294 1295 ImageLoader.prototype.hasImageBackground = function(imageData) { 1296 return imageData.method !== "none"; 1297 }; 1298 1299 ImageLoader.prototype.loadImage = function(imageData) { 1300 if (imageData.method === "url") { 1301 var src = imageData.args[0]; 1302 if (this.isSVG(src) && !this.support.svg && !this.options.allowTaint) { 1303 return new SVGContainer(src); 1304 } else if (src.match(/data:image\/.*;base64,/i)) { 1305 return new ImageContainer(src.replace(/url\(['"]{0,}|['"]{0,}\)$/ig, ''), false); 1306 } else if (this.isSameOrigin(src) || this.options.allowTaint === true || this.isSVG(src)) { 1307 return new ImageContainer(src, false); 1308 } else if (this.support.cors && !this.options.allowTaint && this.options.useCORS) { 1309 return new ImageContainer(src, true); 1310 } else if (this.options.proxy) { 1311 return new ProxyImageContainer(src, this.options.proxy); 1312 } else { 1313 return new DummyImageContainer(src); 1314 } 1315 } else if (imageData.method === "linear-gradient") { 1316 return new LinearGradientContainer(imageData); 1317 } else if (imageData.method === "gradient") { 1318 return new WebkitGradientContainer(imageData); 1319 } else if (imageData.method === "svg") { 1320 return new SVGNodeContainer(imageData.args[0], this.support.svg); 1321 } else if (imageData.method === "IFRAME") { 1322 return new FrameContainer(imageData.args[0], this.isSameOrigin(imageData.args[0].src), this.options); 1323 } else { 1324 return new DummyImageContainer(imageData); 1325 } 1326 }; 1327 1328 ImageLoader.prototype.isSVG = function(src) { 1329 return src.substring(src.length - 3).toLowerCase() === "svg" || SVGContainer.prototype.isInline(src); 1330 }; 1331 1332 ImageLoader.prototype.imageExists = function(images, src) { 1333 return images.some(function(image) { 1334 return image.src === src; 1335 }); 1336 }; 1337 1338 ImageLoader.prototype.isSameOrigin = function(url) { 1339 return (this.getOrigin(url) === this.origin); 1340 }; 1341 1342 ImageLoader.prototype.getOrigin = function(url) { 1343 var link = this.link || (this.link = document.createElement("a")); 1344 link.href = url; 1345 link.href = link.href; // IE9, LOL! - http://jsfiddle.net/niklasvh/2e48b/ 1346 return link.protocol + link.hostname + link.port; 1347 }; 1348 1349 ImageLoader.prototype.getPromise = function(container) { 1350 return this.timeout(container, this.options.imageTimeout)['catch'](function() { 1351 var dummy = new DummyImageContainer(container.src); 1352 return dummy.promise.then(function(image) { 1353 container.image = image; 1354 }); 1355 }); 1356 }; 1357 1358 ImageLoader.prototype.get = function(src) { 1359 var found = null; 1360 return this.images.some(function(img) { 1361 return (found = img).src === src; 1362 }) ? found : null; 1363 }; 1364 1365 ImageLoader.prototype.fetch = function(nodes) {
1366 this.images = nodes.reduce(bind(this.findBackgroundImage, this), this.findImages(nodes)); 1367 this.images.forEach(function(image, index) { 1368 image.promise.then(function() { 1369 log("Succesfully loaded image #"+ (index+1), image); 1370 }, function(e) { 1371 log("Failed loading image #"+ (index+1), image, e); 1372 }); 1373 }); 1374 this.ready = Promise.all(this.images.map(this.getPromise, this)); 1375 log("Finished searching images"); 1376 return this; 1377 }; 1378 1379 ImageLoader.prototype.timeout = function(container, timeout) { 1380 var timer; 1381 var promise = Promise.race([container.promise, new Promise(function(res, reject) { 1382 timer = setTimeout(function() { 1383 log("Timed out loading image", container); 1384 reject(container); 1385 }, timeout); 1386 })]).then(function(container) { 1387 clearTimeout(timer); 1388 return container; 1389 }); 1390 promise['catch'](function() { 1391 clearTimeout(timer); 1392 }); 1393 return promise; 1394 }; 1395 1396 module.exports = ImageLoader; 1397 1398 },{"./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){ 1399 var GradientContainer = _dereq_('./gradientcontainer'); 1400 var Color = _dereq_('./color'); 1401 1402 function LinearGradientContainer(imageData) { 1403 GradientContainer.apply(this, arguments); 1404 this.type = GradientContainer.TYPES.LINEAR; 1405 1406 var hasDirection = LinearGradientContainer.REGEXP_DIRECTION.test( imageData.args[0] ) || 1407 !GradientContainer.REGEXP_COLORSTOP.test( imageData.args[0] ); 1408 1409 if (hasDirection) { 1410 imageData.args[0].split(/\s+/).reverse().forEach(function(position, index) { 1411 switch(position) { 1412 case "left": 1413 this.x0 = 0; 1414 this.x1 = 1; 1415 break; 1416 case "top": 1417 this.y0 = 0; 1418 this.y1 = 1; 1419 break; 1420 case "right": 1421 this.x0 = 1; 1422 this.x1 = 0; 1423 break; 1424 case "bottom": 1425 this.y0 = 1; 1426 this.y1 = 0; 1427 break; 1428 case "to": 1429 var y0 = this.y0; 1430 var x0 = this.x0; 1431 this.y0 = this.y1; 1432 this.x0 = this.x1; 1433 this.x1 = x0; 1434 this.y1 = y0; 1435 break; 1436 case "center": 1437 break; // centered by default 1438 // Firefox internally converts position keywords to percentages: 1439 // http://www.w3.org/TR/2010/WD-CSS2-20101207/colors.html#propdef-background-position 1440 default: // percentage or absolute length 1441 // TODO: support absolute start point positions (e.g., use bounds to convert px to a ratio) 1442 var ratio = parseFloat(position, 10) * 1e-2; 1443 if (isNaN(ratio)) { // invalid or unhandled value 1444 break; 1445 } 1446 if (index === 0) { 1447 this.y0 = ratio; 1448 this.y1 = 1 - this.y0; 1449 } else { 1450 this.x0 = ratio; 1451 this.x1 = 1 - this.x0; 1452 } 1453 break; 1454 } 1455 }, this); 1456 } else { 1457 this.y0 = 0; 1458 this.y1 = 1; 1459 } 1460 1461 this.colorStops = imageData.args.slice(hasDirection ? 1 : 0).map(function(colorStop) { 1462 var colorStopMatch = colorStop.match(GradientContainer.REGEXP_COLORSTOP); 1463 var value = +colorStopMatch[2]; 1464 var unit = value === 0 ? "%" : colorStopMatch[3]; // treat "0" as "0%" 1465 return { 1466 color: new Color(colorStopMatch[1]), 1467 // TODO: support absolute stop positions (e.g., compute gradient line length & convert px to ratio) 1468 stop: unit === "%" ? value / 100 : null 1469 }; 1470 }); 1471 1472 if (this.colorStops[0].stop === null) { 1473 this.colorStops[0].stop = 0; 1474 } 1475 1476 if (this.colorStops[this.colorStops.length - 1].stop === null) { 1477 this.colorStops[this.colorStops.length - 1].stop = 1; 1478 } 1479 1480 // calculates and fills-in explicit stop positions when omitted from rule 1481 this.colorStops.forEach(function(colorStop, index) { 1482 if (colorStop.stop === null) { 1483 this.colorStops.slice(index).some(function(find, count) { 1484 if (find.stop !== null) { 1485 colorStop.stop = ((find.stop - this.colorStops[index - 1].stop) / (count + 1)) + this.colorStops[index - 1].stop; 1486 return true; 1487 } else { 1488 return false;
1489 } 1490 }, this); 1491 } 1492 }, this); 1493 } 1494 1495 LinearGradientContainer.prototype = Object.create(GradientContainer.prototype); 1496 1497// TODO: support <angle> (e.g. -?\d{1,3}(?:\.\d+)deg, etc. : https://developer.mozilla.org/docs/Web/CSS/angle ) 1498 LinearGradientContainer.REGEXP_DIRECTION = /^\s*(?:to|left|right|top|bottom|center|\d{1,3}(?:\.\d+)?%?)(?:\s|$)/i; 1499 1500 module.exports = LinearGradientContainer; 1501 1502 },{"./color":3,"./gradientcontainer":9}],13:[function(_dereq_,module,exports){ 1503 var logger = function() { 1504 if (logger.options.logging && window.console && window.console.log) { 1505 Function.prototype.bind.call(window.console.log, (window.console)).apply(window.console, [(Date.now() - logger.options.start) + "ms", "html2canvas:"].concat([].slice.call(arguments, 0))); 1506 } 1507 }; 1508 1509 logger.options = {logging: false}; 1510 module.exports = logger; 1511 1512 },{}],14:[function(_dereq_,module,exports){ 1513 var Color = _dereq_('./color'); 1514 var utils = _dereq_('./utils'); 1515 var getBounds = utils.getBounds; 1516 var parseBackgrounds = utils.parseBackgrounds; 1517 var offsetBounds = utils.offsetBounds; 1518 1519 function NodeContainer(node, parent) { 1520 this.node = node; 1521 this.parent = parent; 1522 this.stack = null; 1523 this.bounds = null; 1524 this.borders = null; 1525 this.clip = []; 1526 this.backgroundClip = []; 1527 this.offsetBounds = null; 1528 this.visible = null; 1529 this.computedStyles = null; 1530 this.colors = {}; 1531 this.styles = {}; 1532 this.backgroundImages = null; 1533 this.transformData = null; 1534 this.transformMatrix = null; 1535 this.isPseudoElement = false; 1536 this.opacity = null; 1537 } 1538 1539 NodeContainer.prototype.cloneTo = function(stack) { 1540 stack.visible = this.visible; 1541 stack.borders = this.borders; 1542 stack.bounds = this.bounds; 1543 stack.clip = this.clip; 1544 stack.backgroundClip = this.backgroundClip; 1545 stack.computedStyles = this.computedStyles; 1546 stack.styles = this.styles; 1547 stack.backgroundImages = this.backgroundImages; 1548 stack.opacity = this.opacity; 1549 }; 1550 1551 NodeContainer.prototype.getOpacity = function() { 1552 return this.opacity === null ? (this.opacity = this.cssFloat('opacity')) : this.opacity; 1553 }; 1554 1555 NodeContainer.prototype.assignStack = function(stack) { 1556 this.stack = stack; 1557 stack.children.push(this); 1558 }; 1559 1560 NodeContainer.prototype.isElementVisible = function() { 1561 return this.node.nodeType === Node.TEXT_NODE ? this.parent.visible : ( 1562 this.css('display') !== "none" && 1563 this.css('visibility') !== "hidden" && 1564 !this.node.hasAttribute("data-html2canvas-ignore") && 1565 (this.node.nodeName !== "INPUT" || this.node.getAttribute("type") !== "hidden") 1566 ); 1567 }; 1568 1569 NodeContainer.prototype.css = function(attribute) { 1570 if (!this.computedStyles) { 1571 this.computedStyles = this.isPseudoElement ? this.parent.computedStyle(this.before ? ":before" : ":after") : this.computedStyle(null); 1572 } 1573 1574 return this.styles[attribute] || (this.styles[attribute] = this.computedStyles[attribute]); 1575 }; 1576 1577 NodeContainer.prototype.prefixedCss = function(attribute) { 1578 var prefixes = ["webkit", "moz", "ms", "o"]; 1579 var value = this.css(attribute); 1580 if (value === undefined) { 1581 prefixes.some(function(prefix) { 1582 value = this.css(prefix + attribute.substr(0, 1).toUpperCase() + attribute.substr(1)); 1583 return value !== undefined; 1584 }, this); 1585 } 1586 return value === undefined ? null : value; 1587 }; 1588 1589 NodeContainer.prototype.computedStyle = function(type) { 1590 return this.node.ownerDocument.defaultView.getComputedStyle(this.node, type); 1591 }; 1592 1593 NodeContainer.prototype.cssInt = function(attribute) { 1594 var value = parseInt(this.css(attribute), 10); 1595 return (isNaN(value)) ? 0 : value; // borders in old IE are throwing 'medium' for demo.html 1596 }; 1597 1598 NodeContainer.prototype.color = function(attribute) { 1599 return this.colors[attribute] || (this.colors[attribute] = new Color(this.css(attribute))); 1600 }; 1601 1602 NodeContainer.prototype.cssFloat = function(attribute) { 1603 var value = parseFloat(this.css(attribute)); 1604 return (isNaN(value)) ? 0 : value; 1605 }; 1606 1607 NodeContainer.prototype.fontWeight = function() { 1608 var weight = this.css("fontWeight"); 1609 switch(parseInt(weight, 10)){ 1610 case 401: 1611 weight = "bold"; 1612 break; 1613 case 400: 1614 weight = "normal"; 1615 break; 1616 } 1617 return weight; 1618 }; 1619 1620 NodeContainer.prototype.parseClip = function() { 1621 var matches = this.css('clip').match(this.CLIP); 1622 if (matches) { 1623 return { 1624 top: parseInt(matches[1], 10), 1625 right: parseInt(matches[2], 10), 1626 bottom: parseInt(matches[3], 10), 1627 left: parseInt(matches[4], 10) 1628 }; 1629 } 1630 return null; 1631 }; 1632
1633 NodeContainer.prototype.parseBackgroundImages = function() { 1634 return this.backgroundImages || (this.backgroundImages = parseBackgrounds(this.css("backgroundImage"))); 1635 }; 1636 1637 NodeContainer.prototype.cssList = function(property, index) { 1638 var value = (this.css(property) || '').split(','); 1639 value = value[index || 0] || value[0] || 'auto'; 1640 value = value.trim().split(' '); 1641 if (value.length === 1) { 1642 value = [value[0], isPercentage(value[0]) ? 'auto' : value[0]]; 1643 } 1644 return value; 1645 }; 1646 1647 NodeContainer.prototype.parseBackgroundSize = function(bounds, image, index) { 1648 var size = this.cssList("backgroundSize", index); 1649 var width, height; 1650 1651 if (isPercentage(size[0])) { 1652 width = bounds.width * parseFloat(size[0]) / 100; 1653 } else if (/contain|cover/.test(size[0])) { 1654 var targetRatio = bounds.width / bounds.height, currentRatio = image.width / image.height; 1655 return (targetRatio < currentRatio ^ size[0] === 'contain') ? {width: bounds.height * currentRatio, height: bounds.height} : {width: bounds.width, height: bounds.width / currentRatio}; 1656 } else { 1657 width = parseInt(size[0], 10); 1658 } 1659 1660 if (size[0] === 'auto' && size[1] === 'auto') { 1661 height = image.height; 1662 } else if (size[1] === 'auto') { 1663 height = width / image.width * image.height; 1664 } else if (isPercentage(size[1])) { 1665 height = bounds.height * parseFloat(size[1]) / 100; 1666 } else { 1667 height = parseInt(size[1], 10); 1668 } 1669 1670 if (size[0] === 'auto') { 1671 width = height / image.height * image.width; 1672 } 1673 1674 return {width: width, height: height}; 1675 }; 1676 1677 NodeContainer.prototype.parseBackgroundPosition = function(bounds, image, index, backgroundSize) { 1678 var position = this.cssList('backgroundPosition', index); 1679 var left, top; 1680 1681 if (isPercentage(position[0])){ 1682 left = (bounds.width - (backgroundSize || image).width) * (parseFloat(position[0]) / 100); 1683 } else { 1684 left = parseInt(position[0], 10); 1685 } 1686 1687 if (position[1] === 'auto') { 1688 top = left / image.width * image.height; 1689 } else if (isPercentage(position[1])){ 1690 top = (bounds.height - (backgroundSize || image).height) * parseFloat(position[1]) / 100; 1691 } else { 1692 top = parseInt(position[1], 10); 1693 } 1694 1695 if (position[0] === 'auto') { 1696 left = top / image.height * image.width; 1697 } 1698 1699 return {left: left, top: top}; 1700 }; 1701 1702 NodeContainer.prototype.parseBackgroundRepeat = function(index) { 1703 return this.cssList("backgroundRepeat", index)[0]; 1704 }; 1705 1706 NodeContainer.prototype.parseTextShadows = function() { 1707 var textShadow = this.css("textShadow"); 1708 var results = []; 1709 1710 if (textShadow && textShadow !== 'none') { 1711 var shadows = textShadow.match(this.TEXT_SHADOW_PROPERTY); 1712 for (var i = 0; shadows && (i < shadows.length); i++) { 1713 var s = shadows[i].match(this.TEXT_SHADOW_VALUES); 1714 results.push({ 1715 color: new Color(s[0]), 1716 offsetX: s[1] ? parseFloat(s[1].replace('px', '')) : 0, 1717 offsetY: s[2] ? parseFloat(s[2].replace('px', '')) : 0, 1718 blur: s[3] ? s[3].replace('px', '') : 0 1719 }); 1720 } 1721 } 1722 return results; 1723 }; 1724 1725 NodeContainer.prototype.parseTransform = function() { 1726 if (!this.transformData) { 1727 if (this.hasTransform()) { 1728 var offset = this.parseBounds(); 1729 var origin = this.prefixedCss("transformOrigin").split(" ").map(removePx).map(asFloat); 1730 origin[0] += offset.left; 1731 origin[1] += offset.top; 1732 this.transformData = { 1733 origin: origin, 1734 matrix: this.parseTransformMatrix() 1735 }; 1736 } else { 1737 this.transformData = { 1738 origin: [0, 0], 1739 matrix: [1, 0, 0, 1, 0, 0] 1740 }; 1741 } 1742 } 1743 return this.transformData; 1744 }; 1745 1746 NodeContainer.prototype.parseTransformMatrix = function() { 1747 if (!this.transformMatrix) { 1748 var transform = this.prefixedCss("transform"); 1749 var matrix = transform ? parseMatrix(transform.match(this.MATRIX_PROPERTY)) : null; 1750 this.transformMatrix = matrix ? matrix : [1, 0, 0, 1, 0, 0]; 1751 } 1752 return this.transformMatrix; 1753 }; 1754 1755 NodeContainer.prototype.parseBounds = function() { 1756 return this.bounds || (this.bounds = this.hasTransform() ? offsetBounds(this.node) : getBounds(this.node)); 1757 }; 1758 1759 NodeContainer.prototype.hasTransform = function() { 1760 return this.parseTransformMatrix().join(",") !== "1,0,0,1,0,0" || (this.parent && this.parent.hasTransform()); 1761 }; 1762 1763 NodeContainer.prototype.getValue = function() { 1764 var value = this.node.value || ""; 1765 if (this.node.tagName === "SELECT") { 1766 value = selectionValue(this.node); 1767 } else if (this.node.type === "password") { 1768 value = Array(value.length + 1).join('\u2022'); // jshint ignore:line 1769 } 1770 return value.length === 0 ? (this.node.placeholder || "") : value; 1771 }; 1772 1773 NodeContainer.prototype.MATRIX_PROPERTY = /(matrix|matrix3d)\((.+)\)/; 1774 NodeContainer.prototype.TEXT_SHADOW_PROPERTY = /((rgba|rgb)\([^\)]+\)(\s-?\d+px){0,})/g; 1775 NodeContainer.prototype.TEXT_SHADOW_VALUES = /(-?\d+px)|(#.+)|(rgb\(.+\))|(rgba\(.+\))/g; 1776 NodeContainer.prototype.CLIP = /^rect\((\d+)px,? (\d+)px,? (\d+)px,? (\d+)px\)$/; 1777 1778 function selectionValue(node) { 1779 var option = node.options[node.selectedIndex || 0]; 1780 return option ? (option.text || "") : ""; 1781 } 1782 1783 function parseMatrix(match) { 1784 if (match && match[1] === "matrix") { 1785 return match[2].split(",").map(function(s) { 1786 return parseFloat(s.trim()); 1787 }); 1788 } else if (match && match[1] === "matrix3d") { 1789 var matrix3d = match[2].split(",").map(function(s) { 1790 return parseFloat(s.trim()); 1791 }); 1792 return [matrix3d[0], matrix3d[1], matrix3d[4], matrix3d[5], matrix3d[12], matrix3d[13]]; 1793 } 1794 } 1795 1796 function isPercentage(value) { 1797 return value.toString().indexOf("%") !== -1; 1798 } 1799 1800 function removePx(str) { 1801 return str.replace("px", ""); 1802 } 1803 1804 function asFloat(str) { 1805 return parseFloat(str); 1806 } 1807 1808 module.exports = NodeContainer; 1809 1810 },{"./color":3,"./utils":26}],15:[function(_dereq_,module,exports){ 1811 var log = _dereq_('./log'); 1812 var punycode = _dereq_('punycode'); 1813 var NodeContainer = _dereq_('./nodecontainer'); 1814 var TextContainer = _dereq_('./textcontainer'); 1815 var PseudoElementContainer = _dereq_('./pseudoelementcontainer'); 1816 var FontMetrics = _dereq_('./fontmetrics'); 1817 var Color = _dereq_('./color'); 1818 var StackingContext = _dereq_('./stackingcontext'); 1819 var utils = _dereq_('./utils'); 1820 var bind = utils.bind; 1821 var getBounds = utils.getBounds;
1822 var parseBackgrounds = utils.parseBackgrounds; 1823 var offsetBounds = utils.offsetBounds; 1824 1825 function NodeParser(element, renderer, support, imageLoader, options) { 1826 log("Starting NodeParser"); 1827 this.renderer = renderer; 1828 this.options = options; 1829 this.range = null; 1830 this.support = support; 1831 this.renderQueue = []; 1832 this.stack = new StackingContext(true, 1, element.ownerDocument, null); 1833 var parent = new NodeContainer(element, null); 1834 if (options.background) { 1835 renderer.rectangle(0, 0, renderer.width, renderer.height, new Color(options.background)); 1836 } 1837 if (element === element.ownerDocument.documentElement) { 1838 // http://www.w3.org/TR/css3-background/#special-backgrounds 1839 var canvasBackground = new NodeContainer(parent.color('backgroundColor').isTransparent() ? element.ownerDocument.body : element.ownerDocument.documentElement, null); 1840 renderer.rectangle(0, 0, renderer.width, renderer.height, canvasBackground.color('backgroundColor')); 1841 } 1842 parent.visibile = parent.isElementVisible(); 1843 this.createPseudoHideStyles(element.ownerDocument); 1844 this.disableAnimations(element.ownerDocument); 1845 this.nodes = flatten([parent].concat(this.getChildren(parent)).filter(function(container) { 1846 return container.visible = container.isElementVisible(); 1847 }).map(this.getPseudoElements, this)); 1848 this.fontMetrics = new FontMetrics(); 1849 log("Fetched nodes, total:", this.nodes.length); 1850 log("Calculate overflow clips"); 1851 this.calculateOverflowClips(); 1852 log("Start fetching images"); 1853 this.images = imageLoader.fetch(this.nodes.filter(isElement)); 1854 this.ready = this.images.ready.then(bind(function() { 1855 log("Images loaded, starting parsing"); 1856 log("Creating stacking contexts"); 1857 this.createStackingContexts(); 1858 log("Sorting stacking contexts"); 1859 this.sortStackingContexts(this.stack); 1860 this.parse(this.stack); 1861 log("Render queue created with " + this.renderQueue.length + " items"); 1862 return new Promise(bind(function(resolve) { 1863 if (!options.async) { 1864 this.renderQueue.forEach(this.paint, this); 1865 resolve(); 1866 } else if (typeof(options.async) === "function") { 1867 options.async.call(this, this.renderQueue, resolve); 1868 } else if (this.renderQueue.length > 0){ 1869 this.renderIndex = 0; 1870 this.asyncRenderer(this.renderQueue, resolve); 1871 } else { 1872 resolve(); 1873 } 1874 }, this)); 1875 }, this)); 1876 } 1877 1878 NodeParser.prototype.calculateOverflowClips = function() { 1879 this.nodes.forEach(function(container) { 1880 if (isElement(container)) { 1881 if (isPseudoElement(container)) { 1882 container.appendToDOM(); 1883 } 1884 container.borders = this.parseBorders(container); 1885 var clip = (container.css('overflow') === "hidden") ? [container.borders.clip] : []; 1886 var cssClip = container.parseClip(); 1887 if (cssClip && ["absolute", "fixed"].indexOf(container.css('position')) !== -1) { 1888 clip.push([["rect", 1889 container.bounds.left + cssClip.left, 1890 container.bounds.top + cssClip.top, 1891 cssClip.right - cssClip.left, 1892 cssClip.bottom - cssClip.top 1893 ]]); 1894 } 1895 container.clip = hasParentClip(container) ? container.parent.clip.concat(clip) : clip; 1896 container.backgroundClip = (container.css('overflow') !== "hidden") ? c
1896ontainer.clip.concat([container.borders.clip]) : container.clip; 1897 if (isPseudoElement(container)) { 1898 container.cleanDOM(); 1899 } 1900 } else if (isTextNode(container)) { 1901 container.clip = hasParentClip(container) ? container.parent.clip : []; 1902 } 1903 if (!isPseudoElement(container)) { 1904 container.bounds = null; 1905 } 1906 }, this); 1907 }; 1908 1909 function hasParentClip(container) { 1910 return container.parent && container.parent.clip.length; 1911 } 1912 1913 NodeParser.prototype.asyncRenderer = function(queue, resolve, asyncTimer) { 1914 asyncTimer = asyncTimer || Date.now(); 1915 this.paint(queue[this.renderIndex++]); 1916 if (queue.length === this.renderIndex) { 1917 resolve(); 1918 } else if (asyncTimer + 20 > Date.now()) { 1919 this.asyncRenderer(queue, resolve, asyncTimer); 1920 } else { 1921 setTimeout(bind(function() { 1922 this.asyncRenderer(queue, resolve); 1923 }, this), 0); 1924 } 1925 }; 1926 1927 NodeParser.prototype.createPseudoHideStyles = function(document) { 1928 this.createStyles(document, '.' + PseudoElementContainer.prototype.PSEUDO_HIDE_ELEMENT_CLASS_BEFORE + ':before { content: "" !important; display: none !important; }' + 1929 '.' + PseudoElementContainer.prototype.PSEUDO_HIDE_ELEMENT_CLASS_AFTER + ':after { content: "" !important; display: none !important; }'); 1930 }; 1931 1932 NodeParser.prototype.disableAnimations = function(document) { 1933 this.createStyles(document, '* { -webkit-animation: none !important; -moz-animation: none !important; -o-animation: none !important; animation: none !important; ' + 1934 '-webkit-transition: none !important; -moz-transition: none !important; -o-transition: none !important; transition: none !important;}'); 1935 }; 1936 1937 NodeParser.prototype.createStyles = function(document, styles) { 1938 var hidePseudoElements = document.createElement('style'); 1939 hidePseudoElements.innerHTML = styles; 1940 document.body.appendChild(hidePseudoElements); 1941 }; 1942 1943 NodeParser.prototype.getPseudoElements = function(container) { 1944 var nodes = [[container]]; 1945 if (container.node.nodeType === Node.ELEMENT_NODE) { 1946 var before = this.getPseudoElement(container, ":before"); 1947 var after = this.getPseudoElement(container, ":after"); 1948 1949 if (before) { 1950 nodes.push(before); 1951 } 1952 1953 if (after) { 1954 nodes.push(after); 1955 } 1956 } 1957 return flatten(nodes); 1958 }; 1959 1960 function toCamelCase(str) { 1961 return str.replace(/(\-[a-z])/g, function(match){ 1962 return match.toUpperCase().replace('-',''); 1963 }); 1964 } 1965 1966 NodeParser.prototype.getPseudoElement = function(container, type) { 1967 var style = container.computedStyle(type); 1968 if(!style || !style.content || style.content === "none" || style.content === "-moz-alt-content" || style.display === "none") { 1969 return null; 1970 } 1971 1972 var content = stripQuotes(style.content); 1973 var isImage = content.substr(0, 3) === 'url'; 1974 var pseudoNode = document.createElement(isImage ? 'img' : 'html2canvaspseudoelement'); 1975 var pseudoContainer = new PseudoElementContainer(pseudoNode, container, type); 1976 1977 for (var i = style.length-1; i >= 0; i--) { 1978 var property = toCamelCase(style.item(i)); 1979 pseudoNode.style[property] = style[property]; 1980 } 1981 1982 pseudoNode.className = PseudoElementContainer.prototype.PSEUDO_HIDE_ELEMENT_CLASS_BEFORE + " " + PseudoElementContainer.prototype.PSEUDO_HIDE_ELEMENT_CLASS_AFTER; 1983 1984 if (isImage) { 1985 pseudoNode.src = parseBackgrounds(content)[0].args[0]; 1986 return [pseudoContainer]; 1987 } else { 1988 var text = document.createTextNode(content); 1989 pseudoNode.appendChild(text); 1990 return [pseudoContainer, new TextContainer(text, pseudoContainer)]; 1991 } 1992 }; 1993 1994 1995 NodeParser.prototype.getChildren = function(parentContainer) { 1996 return flatten([].filter.call(parentContainer.node.childNodes, renderableNode).map(function(node) { 1997 var container = [node.nodeType === Node.TEXT_NODE ? new TextContainer(node, parentContainer) : new NodeContainer(node, parentContainer)].filter(nonIgnoredElement); 1998 return node.nodeType === Node.ELEMENT_NODE && container.length && node.tagName !== "TEXTAREA" ? (container[0].isElementVisible() ? container.concat(this.getChildren(container[0])) : []) : container; 1999 }, this)); 2000 }; 2001 2002 NodeParser.prototype.newStackingContext = function(container, hasOwnStacking) { 2003 var stack = new StackingContext(hasOwnStacking, container.getOpacity(), container.node, container.parent); 2004 container.cloneTo(stack); 2005 var parentStack = hasOwnStacking ? stack.getParentStack(this) : stack.parent.stack; 2006 parentStack.contexts.push(stack); 2007 container.stack = stack; 2008 }; 2009 2010 NodeParser.prototype.createStackingContexts = function() {
2011 this.nodes.forEach(function(container) { 2012 if (isElement(container) && (this.isRootElement(container) || hasOpacity(container) || isPositionedForStacking(container) || this.isBodyWithTransparentRoot(container) || container.hasTransform())) { 2013 this.newStackingContext(container, true); 2014 } else if (isElement(container) && ((isPositioned(container) && zIndex0(container)) || isInlineBlock(container) || isFloating(container))) { 2015 this.newStackingContext(container, false); 2016 } else { 2017 container.assignStack(container.parent.stack); 2018 } 2019 }, this); 2020 }; 2021 2022 NodeParser.prototype.isBodyWithTransparentRoot = function(container) { 2023 return container.node.nodeName === "BODY" && container.parent.color('backgroundColor').isTransparent(); 2024 }; 2025 2026 NodeParser.prototype.isRootElement = function(container) { 2027 return container.parent === null; 2028 }; 2029 2030 NodeParser.prototype.sortStackingContexts = function(stack) { 2031 stack.contexts.sort(zIndexSort(stack.contexts.slice(0)));
2032 stack.contexts.forEach(this.sortStackingContexts, this); 2033 }; 2034 2035 NodeParser.prototype.parseTextBounds = function(container) { 2036 return function(text, index, textList) { 2037 if (container.parent.css("textDecoration").substr(0, 4) !== "none" || text.trim().length !== 0) { 2038 if (this.support.rangeBounds && !container.parent.hasTransform()) { 2039 var offset = textList.slice(0, index).join("").length; 2040 return this.getRangeBounds(container.node, offset, text.length); 2041 } else if (container.node && typeof(container.node.data) === "string") { 2042 var replacementNode = container.node.splitText(text.length); 2043 var bounds = this.getWrapperBounds(container.node, container.parent.hasTransform()); 2044 container.node = replacementNode; 2045 return bounds; 2046 } 2047 } else if(!this.support.rangeBounds || container.parent.hasTransform()){ 2048 container.node = container.node.splitText(text.length); 2049 } 2050 return {}; 2051 }; 2052 }; 2053 2054 NodeParser.prototype.getWrapperBounds = function(node, transform) { 2055 var wrapper = node.ownerDocument.createElement('html2canvaswrapper'); 2056 var parent = node.parentNode, 2057 backupText = node.cloneNode(true); 2058 2059 wrapper.appendChild(node.cloneNode(true)); 2060 parent.replaceChild(wrapper, node); 2061 var bounds = transform ? offsetBounds(wrapper) : getBounds(wrapper); 2062 parent.replaceChild(backupText, wrapper); 2063 return bounds; 2064 }; 2065 2066 NodeParser.prototype.getRangeBounds = function(node, offset, length) { 2067 var range = this.range || (this.range = node.ownerDocument.createRange()); 2068 range.setStart(node, offset); 2069 range.setEnd(node, offset + length); 2070 return range.getBoundingClientRect(); 2071 }; 2072 2073 function ClearTransform() {} 2074 2075 NodeParser.prototype.parse = function(stack) { 2076 // http://www.w3.org/TR/CSS21/visuren.html#z-index 2077 var negativeZindex = stack.contexts.filter(negativeZIndex); // 2. the child stacking contexts with negative stack levels (most negative first). 2078 var descendantElements = stack.children.filter(isElement); 2079 var descendantNonFloats = descendantElements.filter(not(isFloating)); 2080 var nonInlineNonPositionedDescendants = descendantNonFloats.filter(not(isPositioned)).filter(not(inlineLevel)); // 3 the in-flow, non-inline-level, non-positioned descendants. 2081 var nonPositionedFloats = descendantElements.filter(not(isPositioned)).filter(isFloating); // 4. the non-positioned floats. 2082 var inFlow = descendantNonFloats.filter(not(isPositioned)).filter(inlineLevel); // 5. the in-flow, inline-level, non-positioned descendants, including inline tables and inline blocks. 2083 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. 2084 var text = stack.children.filter(isTextNode).filter(hasText); 2085 var positiveZindex = stack.contexts.filter(positiveZIndex); // 7. the child stacking contexts with positive stack levels (least positive first). 2086 negativeZindex.concat(nonInlineNonPositionedDescendants).concat(nonPositionedFloats) 2087 .concat(inFlow).concat(stackLevel0).concat(text).concat(positiveZindex).forEach(function(container) { 2088 this.renderQueue.push(container); 2089 if (isStackingContext(container)) { 2090 this.parse(container); 2091 this.renderQueue.push(new ClearTransform()); 2092 } 2093 }, this); 2094 }; 2095 2096 NodeParser.prototype.paint = function(container) { 2097 try { 2098 if (container instanceof ClearTransform) {
2099 this.renderer.ctx.restore(); 2100 } else if (isTextNode(container)) { 2101 if (isPseudoElement(container.parent)) { 2102 container.parent.appendToDOM(); 2103 } 2104 this.paintText(container); 2105 if (isPseudoElement(container.parent)) { 2106 container.parent.cleanDOM(); 2107 } 2108 } else { 2109 this.paintNode(container); 2110 } 2111 } catch(e) { 2112 log(e); 2113 if (this.options.strict) { 2114 throw e; 2115 } 2116 } 2117 }; 2118 2119 NodeParser.prototype.paintNode = function(container) { 2120 if (isStackingContext(container)) { 2121 this.renderer.setOpacity(container.opacity); 2122 this.renderer.ctx.save(); 2123 if (container.hasTransform()) { 2124 this.renderer.setTransform(container.parseTransform()); 2125 } 2126 } 2127 2128 if (container.node.nodeName === "INPUT" && container.node.type === "checkbox") { 2129 this.paintCheckbox(container); 2130 } else if (container.node.nodeName === "INPUT" && container.node.type === "radio") { 2131 this.paintRadio(container); 2132 } else { 2133 this.paintElement(container); 2134 } 2135 }; 2136 2137 NodeParser.prototype.paintElement = function(container) { 2138 var bounds = container.parseBounds(); 2139 this.renderer.clip(container.backgroundClip, function() { 2140 this.renderer.renderBackground(container, bounds, container.borders.borders.map(getWidth)); 2141 }, this); 2142 2143 this.renderer.clip(container.clip, function() { 2144 this.renderer.renderBorders(container.borders.borders); 2145 }, this); 2146 2147 this.renderer.clip(container.backgroundClip, function() { 2148 switch (container.node.nodeName) { 2149 case "svg": 2150 case "IFRAME": 2151 var imgContainer = this.images.get(container.node); 2152 if (imgContainer) { 2153 this.renderer.renderImage(container, bounds, container.borders, imgContainer); 2154 } else { 2155 log("Error loading <" + container.node.nodeName + ">", container.node); 2156 } 2157 break; 2158 case "IMG": 2159 var imageContainer = this.images.get(container.node.src); 2160 if (imageContainer) { 2161 this.renderer.renderImage(container, bounds, container.borders, imageContainer); 2162 } else { 2163 log("Error loading <img>", container.node.src); 2164 } 2165 break; 2166 case "CANVAS": 2167 this.renderer.renderImage(container, bounds, container.borders, {image: container.node}); 2168 break; 2169 case "SELECT": 2170 case "INPUT": 2171 case "TEXTAREA": 2172 this.paintFormValue(container); 2173 break; 2174 } 2175 }, this); 2176 }; 2177 2178 NodeParser.prototype.paintCheckbox = function(container) { 2179 var b = container.parseBounds(); 2180 2181 var size = Math.min(b.width, b.height); 2182 var bounds = {width: size - 1, height: size - 1, top: b.top, left: b.left}; 2183 var r = [3, 3]; 2184 var radius = [r, r, r, r]; 2185 var borders = [1,1,1,1].map(function(w) { 2186 return {color: new Color('#A5A5A5'), width: w}; 2187 }); 2188 2189 var borderPoints = calculateCurvePoints(bounds, radius, borders); 2190 2191 this.renderer.clip(container.backgroundClip, function() { 2192 this.renderer.rectangle(bounds.left + 1, bounds.top + 1, bounds.width - 2, bounds.height - 2, new Color("#DEDEDE")); 2193 this.renderer.renderBorders(calculateBorders(borders, bounds, borderPoints, radius)); 2194 if (container.node.checked) { 2195 this.renderer.font(new Color('#424242'), 'normal', 'normal', 'bold', (size - 3) + "px", 'arial'); 2196 this.renderer.text("\u2714", bounds.left + size / 6, bounds.top + size - 1); 2197 } 2198 }, this); 2199 }; 2200 2201 NodeParser.prototype.paintRadio = function(container) { 2202 var bounds = container.parseBounds(); 2203 2204 var size = Math.min(bounds.width, bounds.height) - 2; 2205 2206 this.renderer.clip(container.backgroundClip, function() { 2207 this.renderer.circleStroke(bounds.left + 1, bounds.top + 1, size, new Color('#DEDEDE'), 1, new Color('#A5A5A5')); 2208 if (container.node.checked) { 2209 this.renderer.circle(Math.ceil(bounds.left + size / 4) + 1, Math.ceil(bounds.top + size / 4) + 1, Math.floor(size / 2), new Color('#424242')); 2210 } 2211 }, this); 2212 }; 2213 2214 NodeParser.prototype.paintFormValue = function(container) { 2215 var value = container.getValue(); 2216 if (value.length > 0) { 2217 var document = container.node.ownerDocument; 2218 var wrapper = document.createElement('html2canvaswrapper'); 2219 var properties = ['lineHeight', 'textAlign', 'fontFamily', 'fontWeight', 'fontSize', 'color', 2220 'paddingLeft', 'paddingTop', 'paddingRight', 'paddingBottom', 2221 'width', 'height', 'borderLeftStyle', 'borderTopStyle', 'borderLeftWidth', 'borderTopWidth', 2222 'boxSizing', 'whiteSpace', 'wordWrap']; 2223
2224 properties.forEach(function(property) { 2225 try { 2226 wrapper.style[property] = container.css(property); 2227 } catch(e) { 2228 // Older IE has issues with "border" 2229 log("html2canvas: Parse: Exception caught in renderFormValue: " + e.message); 2230 } 2231 }); 2232 var bounds = container.parseBounds(); 2233 wrapper.style.position = "fixed"; 2234 wrapper.style.left = bounds.left + "px"; 2235 wrapper.style.top = bounds.top + "px"; 2236 wrapper.textContent = value; 2237 document.body.appendChild(wrapper); 2238 this.paintText(new TextContainer(wrapper.firstChild, container)); 2239 document.body.removeChild(wrapper); 2240 } 2241 }; 2242 2243 NodeParser.prototype.paintText = function(container) { 2244 container.applyTextTransform(); 2245 var characters = punycode.ucs2.decode(container.node.data); 2246 var textList = (!this.options.letterRendering || noLetterSpacing(container)) && !hasUnicode(container.node.data) ? getWords(characters) : characters.map(function(character) { 2247 return punycode.ucs2.encode([character]); 2248 }); 2249 2250 var weight = container.parent.fontWeight(); 2251 var size = container.parent.css('fontSize'); 2252 var family = container.parent.css('fontFamily'); 2253 var shadows = container.parent.parseTextShadows(); 2254 2255 this.renderer.font(container.parent.color('color'), container.parent.css('fontStyle'), container.parent.css('fontVariant'), weight, size, family); 2256 if (shadows.length) { 2257 // TODO: support multiple text shadows 2258 this.renderer.fontShadow(shadows[0].color, shadows[0].offsetX, shadows[0].offsetY, shadows[0].blur); 2259 } else { 2260 this.renderer.clearShadow(); 2261 } 2262 2263 this.renderer.clip(container.parent.clip, function() { 2264 textList.map(this.parseTextBounds(container), this).forEach(function(bounds, index) { 2265 if (bounds) { 2266 this.renderer.text(textList[index], bounds.left, bounds.bottom); 2267 this.renderTextDecoration(container.parent, bounds, this.fontMetrics.getMetrics(family, size)); 2268 } 2269 }, this); 2270 }, this); 2271 }; 2272 2273 NodeParser.prototype.renderTextDecoration = function(container, bounds, metrics) { 2274 switch(container.css("textDecoration").split(" ")[0]) { 2275 case "underline": 2276 // Draws a line at the baseline of the font 2277 // 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 2278 this.renderer.rectangle(bounds.left, Math.round(bounds.top + metrics.baseline + metrics.lineWidth), bounds.width, 1, container.color("color")); 2279 break; 2280 case "overline": 2281 this.renderer.rectangle(bounds.left, Math.round(bounds.top), bounds.width, 1, container.color("color")); 2282 break; 2283 case "line-through": 2284 // TODO try and find exact position for line-through 2285 this.renderer.rectangle(bounds.left, Math.ceil(bounds.top + metrics.middle + metrics.lineWidth), bounds.width, 1, container.color("color")); 2286 break; 2287 } 2288 }; 2289 2290 var borderColorTransforms = { 2291 inset: [ 2292 ["darken", 0.60], 2293 ["darken", 0.10], 2294 ["darken", 0.10], 2295 ["darken", 0.60] 2296 ] 2297 }; 2298 2299 NodeParser.prototype.parseBorders = function(container) { 2300 var nodeBounds = container.parseBounds(); 2301 var radius = getBorderRadiusData(container); 2302 var borders = ["Top", "Right", "Bottom", "Left"].map(function(side, index) { 2303 var style = container.css('border' + side + 'Style'); 2304 var color = container.color('border' + side + 'Color'); 2305 if (style === "inset" && color.isBlack()) { 2306 color = new Color([255, 255, 255, color.a]); // this is wrong, but 2307 } 2308 var colorTransform = borderColorTransforms[style] ? borderColorTransforms[style][index] : null; 2309 return { 2310 width: container.cssInt('border' + side + 'Width'), 2311 color: colorTransform ? color[colorTransform[0]](colorTransform[1]) : color, 2312 args: null 2313 }; 2314 }); 2315 var borderPoints = calculateCurvePoints(nodeBounds, radius, borders); 2316 2317 return {
2318 clip: this.parseBackgroundClip(container, borderPoints, borders, radius, nodeBounds), 2319 borders: calculateBorders(borders, nodeBounds, borderPoints, radius) 2320 }; 2321 }; 2322 2323 function calculateBorders(borders, nodeBounds, borderPoints, radius) { 2324 return borders.map(function(border, borderSide) { 2325 if (border.width > 0) { 2326 var bx = nodeBounds.left; 2327 var by = nodeBounds.top; 2328 var bw = nodeBounds.width; 2329 var bh = nodeBounds.height - (borders[2].width); 2330 2331 switch(borderSide) { 2332 case 0: 2333 // top border 2334 bh = borders[0].width; 2335 border.args = drawSide({ 2336 c1: [bx, by], 2337 c2: [bx + bw, by], 2338 c3: [bx + bw - borders[1].width, by + bh], 2339 c4: [bx + borders[3].width, by + bh] 2340 }, radius[0], radius[1], 2341 borderPoints.topLeftOuter, borderPoints.topLeftInner, borderPoints.topRightOuter, borderPoints.topRightInner); 2342 break; 2343 case 1: 2344 // right border 2345 bx = nodeBounds.left + nodeBounds.width - (borders[1].width); 2346 bw = borders[1].width; 2347 2348 border.args = drawSide({ 2349 c1: [bx + bw, by], 2350 c2: [bx + bw, by + bh + borders[2].width], 2351 c3: [bx, by + bh], 2352 c4: [bx, by + borders[0].width] 2353 }, radius[1], radius[2], 2354 borderPoints.topRightOuter, borderPoints.topRightInner, borderPoints.bottomRightOuter, borderPoints.bottomRightInner); 2355 break; 2356 case 2: 2357 // bottom border 2358 by = (by + nodeBounds.height) - (borders[2].width); 2359 bh = borders[2].width; 2360 border.args = drawSide({ 2361 c1: [bx + bw, by + bh], 2362 c2: [bx, by + bh], 2363 c3: [bx + borders[3].width, by], 2364 c4: [bx + bw - borders[3].width, by] 2365 }, radius[2], radius[3], 2366 borderPoints.bottomRightOuter, borderPoints.bottomRightInner, borderPoints.bottomLeftOuter, borderPoints.bottomLeftInner); 2367 break; 2368 case 3: 2369 // left border 2370 bw = borders[3].width; 2371 border.args = drawSide({ 2372 c1: [bx, by + bh + borders[2].width], 2373 c2: [bx, by], 2374 c3: [bx + bw, by + borders[0].width], 2375 c4: [bx + bw, by + bh] 2376 }, radius[3], radius[0], 2377 borderPoints.bottomLeftOuter, borderPoints.bottomLeftInner, borderPoints.topLeftOuter, borderPoints.topLeftInner); 2378 break; 2379 } 2380 } 2381 return border; 2382 }); 2383 } 2384 2385 NodeParser.prototype.parseBackgroundClip = function(container, borderPoints, borders, radius, bounds) { 2386 var backgroundClip = container.css('backgroundClip'), 2387 borderArgs = []; 2388 2389 switch(backgroundClip) { 2390 case "content-box": 2391 case "padding-box": 2392 parseCorner(borderArgs, radius[0], radius[1], borderPoints.topLeftInner, borderPoints.topRightInner, bounds.left + borders[3].width, bounds.top + borders[0].width); 2393 parseCorner(borderArgs, radius[1], radius[2], borderPoints.topRightInner, borderPoints.bottomRightInner, bounds.left + bounds.width - borders[1].width, bounds.top + borders[0].width); 2394 parseCorner(borderArgs, radius[2], radius[3], borderPoints.bottomRightInner, borderPoints.bottomLeftInner, bounds.left + bounds.width - borders[1].width, bounds.top + bounds.height - borders[2].width); 2395 parseCorner(borderArgs, radius[3], radius[0], borderPoints.bottomLeftInner, borderPoints.topLeftInner, bounds.left + borders[3].width, bounds.top + bounds.height - borders[2].width); 2396 break; 2397 2398 default: 2399 parseCorner(borderArgs, radius[0], radius[1], borderPoints.topLeftOuter, borderPoints.topRightOuter, bounds.left, bounds.top); 2400 parseCorner(borderArgs, radius[1], radius[2], borderPoints.topRightOuter, borderPoints.bottomRightOuter, bounds.left + bounds.width, bounds.top); 2401 parseCorner(borderArgs, radius[2], radius[3], borderPoints.bottomRightOuter, borderPoints.bottomLeftOuter, bounds.left + bounds.width, bounds.top + bounds.height); 2402 parseCorner(borderArgs, radius[3], radius[0], borderPoints.bottomLeftOuter, borderPoints.topLeftOuter, bounds.left, bounds.top + bounds.height); 2403 break; 2404 } 2405 2406 return borderArgs; 2407 }; 2408 2409 function getCurvePoints(x, y, r1, r2) { 2410 var kappa = 4 * ((Math.sqrt(2) - 1) / 3); 2411 var ox = (r1) * kappa, // control point offset horizontal 2412 oy = (r2) * kappa, // control point offset vertical 2413 xm = x + r1, // x-middle 2414 ym = y + r2; // y-middle 2415 return { 2416 topLeft: bezierCurve({x: x, y: ym}, {x: x, y: ym - oy}, {x: xm - ox, y: y}, {x: xm, y: y}), 2417 topRight: bezierCurve({x: x, y: y}, {x: x + ox,y: y}, {x: xm, y: ym - oy}, {x: xm, y: ym}), 2418 bottomRight: bezierCurve({x: xm, y: y}, {x: xm, y: y + oy}, {x: x + ox, y: ym}, {x: x, y: ym}), 2419 bottomLeft: bezierCurve({x: xm, y: ym}, {x: xm - ox, y: ym}, {x: x, y: y + oy}, {x: x, y:y}) 2420 }; 2421 } 2422 2423 function calculateCurvePoints(bounds, borderRadius, borders) { 2424 var x = bounds.left, 2425 y = bounds.top, 2426 width = bounds.width, 2427 height = bounds.height, 2428 2429 tlh = borderRadius[0][0] < width / 2 ? borderRadius[0][0] : width / 2, 2430 tlv = borderRadius[0][1] < height / 2 ? borderRadius[0][1] : height / 2, 2431 trh = borderRadius[1][0] < width / 2 ? borderRadius[1][0] : width / 2, 2432 trv = borderRadius[1][1] < height / 2 ? borderRadius[1][1] : height / 2, 2433 brh = borderRadius[2][0] < width / 2 ? borderRadius[2][0] : width / 2, 2434 brv = borderRadius[2][1] < height / 2 ? borderRadius[2][1] : height / 2, 2435 blh = borderRadius[3][0] < width / 2 ? borderRadius[3][0] : width / 2, 2436 blv = borderRadius[3][1] < height / 2 ? borderRadius[3][1] : height / 2; 2437 2438 var topWidth = width - trh, 2439 rightHeight = height - brv, 2440 bottomWidth = width - brh, 2441 leftHeight = height - blv; 2442 2443 return { 2444 topLeftOuter: getCurvePoints(x, y, tlh, tlv).topLeft.subdivide(0.5), 2445 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), 2446 topRightOuter: getCurvePoints(x + topWidth, y, trh, trv).topRight.subdivide(0.5), 2447 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), 2448 bottomRightOuter: getCurvePoints(x + bottomWidth, y + rightHeight, brh, brv).bottomRight.subdivide(0.5), 2449 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), 2450 bottomLeftOuter: getCurvePoints(x, y + leftHeight, blh, blv).bottomLeft.subdivide(0.5), 2451 bottomLeftInner: getCurvePoints(x + borders[3].width, y + leftHeight, Math.max(0, blh - borders[3].width), blv - borders[2].width).bottomLeft.subdivide(0.5) 2452 }; 2453 } 2454 2455 function bezierCurve(start, startControl, endControl, end) { 2456 var lerp = function (a, b, t) { 2457 return { 2458 x: a.x + (b.x - a.x) * t, 2459 y: a.y + (b.y - a.y) * t 2460 }; 2461 }; 2462 2463 return { 2464 start: start, 2465 startControl: startControl, 2466 endControl: endControl, 2467 end: end, 2468 subdivide: function(t) { 2469 var ab = lerp(start, startControl, t), 2470 bc = lerp(startControl, endControl, t), 2471 cd = lerp(endControl, end, t), 2472 abbc = lerp(ab, bc, t), 2473 bccd = lerp(bc, cd, t), 2474 dest = lerp(abbc, bccd, t); 2475 return [bezierCurve(start, ab, abbc, dest), bezierCurve(dest, bccd, cd, end)]; 2476 }, 2477 curveTo: function(borderArgs) { 2478 borderArgs.push(["bezierCurve", startControl.x, startControl.y, endControl.x, endControl.y, end.x, end.y]); 2479 }, 2480 curveToReversed: function(borderArgs) { 2481 borderArgs.push(["bezierCurve", endControl.x, endControl.y, startControl.x, startControl.y, start.x, start.y]); 2482 } 2483 }; 2484 } 2485 2486 function drawSide(borderData, radius1, radius2, outer1, inner1, outer2, inner2) { 2487 var borderArgs = []; 2488 2489 if (radius1[0] > 0 || radius1[1] > 0) { 2490 borderArgs.push(["line", outer1[1].start.x, outer1[1].start.y]); 2491 outer1[1].curveTo(borderArgs); 2492 } else { 2493 borderArgs.push([ "line", borderData.c1[0], borderData.c1[1]]); 2494 } 2495 2496 if (radius2[0] > 0 || radius2[1] > 0) { 2497 borderArgs.push(["line", outer2[0].start.x, outer2[0].start.y]); 2498 outer2[0].curveTo(borderArgs); 2499 borderArgs.push(["line", inner2[0].end.x, inner2[0].end.y]); 2500 inner2[0].curveToReversed(borderArgs); 2501 } else { 2502 borderArgs.push(["line", borderData.c2[0], borderData.c2[1]]); 2503 borderArgs.push(["line", borderData.c3[0], borderData.c3[1]]); 2504 } 2505 2506 if (radius1[0] > 0 || radius1[1] > 0) { 2507 borderArgs.push(["line", inner1[1].end.x, inner1[1].end.y]); 2508 inner1[1].curveToReversed(borderArgs); 2509 } else { 2510 borderArgs.push(["line", borderData.c4[0], borderData.c4[1]]); 2511 } 2512 2513 return borderArgs; 2514 } 2515 2516 function parseCorner(borderArgs, radius1, radius2, corner1, corner2, x, y) { 2517 if (radius1[0] > 0 || radius1[1] > 0) {
2518 borderArgs.push(["line", corner1[0].start.x, corner1[0].start.y]); 2519 corner1[0].curveTo(borderArgs); 2520 corner1[1].curveTo(borderArgs); 2521 } else { 2522 borderArgs.push(["line", x, y]); 2523 } 2524 2525 if (radius2[0] > 0 || radius2[1] > 0) { 2526 borderArgs.push(["line", corner2[0].start.x, corner2[0].start.y]); 2527 } 2528 } 2529 2530 function negativeZIndex(container) { 2531 return container.cssInt("zIndex") < 0; 2532 } 2533 2534 function positiveZIndex(container) { 2535 return container.cssInt("zIndex") > 0; 2536 } 2537 2538 function zIndex0(container) { 2539 return container.cssInt("zIndex") === 0; 2540 } 2541 2542 function inlineLevel(container) { 2543 return ["inline", "inline-block", "inline-table"].indexOf(container.css("display")) !== -1; 2544 } 2545 2546 function isStackingContext(container) { 2547 return (container instanceof StackingContext); 2548 } 2549 2550 function hasText(container) { 2551 return container.node.data.trim().length > 0; 2552 } 2553 2554 function noLetterSpacing(container) { 2555 return (/^(normal|none|0px)$/.test(container.parent.css("letterSpacing"))); 2556 } 2557 2558 function getBorderRadiusData(container) { 2559 return ["TopLeft", "TopRight", "BottomRight", "BottomLeft"].map(function(side) { 2560 var value = container.css('border' + side + 'Radius'); 2561 var arr = value.split(" "); 2562 if (arr.length <= 1) { 2563 arr[1] = arr[0]; 2564 } 2565 return arr.map(asInt); 2566 }); 2567 } 2568 2569 function renderableNode(node) { 2570 return (node.nodeType === Node.TEXT_NODE || node.nodeType === Node.ELEMENT_NODE); 2571 } 2572 2573 function isPositionedForStacking(container) { 2574 var position = container.css("position"); 2575 var zIndex = (["absolute", "relative", "fixed"].indexOf(position) !== -1) ? container.css("zIndex") : "auto"; 2576 return zIndex !== "auto"; 2577 } 2578 2579 function isPositioned(container) { 2580 return container.css("position") !== "static"; 2581 } 2582 2583 function isFloating(container) { 2584 return container.css("float") !== "none"; 2585 } 2586 2587 function isInlineBlock(container) { 2588 return ["inline-block", "inline-table"].indexOf(container.css("display")) !== -1; 2589 } 2590 2591 function not(callback) { 2592 var context = this; 2593 return function() { 2594 return !callback.apply(context, arguments); 2595 }; 2596 } 2597 2598 function isElement(container) { 2599 return container.node.nodeType === Node.ELEMENT_NODE; 2600 } 2601 2602 function isPseudoElement(container) { 2603 return container.isPseudoElement === true; 2604 } 2605 2606 function isTextNode(container) { 2607 return container.node.nodeType === Node.TEXT_NODE; 2608 } 2609 2610 function zIndexSort(contexts) { 2611 return function(a, b) { 2612 return (a.cssInt("zIndex") + (contexts.indexOf(a) / contexts.length)) - (b.cssInt("zIndex") + (contexts.indexOf(b) / contexts.length)); 2613 }; 2614 } 2615 2616 function hasOpacity(container) { 2617 return container.getOpacity() < 1; 2618 } 2619 2620 function asInt(value) { 2621 return parseInt(value, 10); 2622 } 2623 2624 function getWidth(border) { 2625 return border.width; 2626 } 2627 2628 function nonIgnoredElement(nodeContainer) { 2629 return (nodeContainer.node.nodeType !== Node.ELEMENT_NODE || ["SCRIPT", "HEAD", "TITLE", "OBJECT", "BR", "OPTION"].indexOf(nodeContainer.node.nodeName) === -1); 2630 } 2631 2632 function flatten(arrays) { 2633 return [].concat.apply([], arrays); 2634 } 2635 2636 function stripQuotes(content) { 2637 var first = content.substr(0, 1); 2638 return (first === content.substr(content.length - 1) && first.match(/'|"/)) ? content.substr(1, content.length - 2) : content; 2639 } 2640 2641 function getWords(characters) { 2642 var words = [], i = 0, onWordBoundary = false, word; 2643 while(characters.length) { 2644 if (isWordBoundary(characters[i]) === onWordBoundary) { 2645 word = characters.splice(0, i); 2646 if (word.length) { 2647 words.push(punycode.ucs2.encode(word)); 2648 } 2649 onWordBoundary =! onWordBoundary; 2650 i = 0; 2651 } else { 2652 i++; 2653 } 2654 2655 if (i >= characters.length) { 2656 word = characters.splice(0, i); 2657 if (word.length) { 2658 words.push(punycode.ucs2.encode(word)); 2659 } 2660 } 2661 } 2662 return words; 2663 } 2664 2665 function isWordBoundary(characterCode) { 2666 return [ 2667 32, // <space> 2668 13, // \r 2669 10, // \n 2670 9, // \t 2671 45 // - 2672 ].indexOf(characterCode) !== -1; 2673 } 2674 2675 function hasUnicode(string) { 2676 return (/[^\u0000-\u00ff]/).test(string); 2677 } 2678 2679 module.exports = NodeParser; 2680 2681 },{"./color":3,"./fontmetrics":7,"./log":13,"./nodecontainer":14,"./pseudoelementcontainer":18,"./stackingcontext":21,"./textcontainer":25,"./utils":26,"pu
2681nycode":1}],16:[function(_dereq_,module,exports){ 2682 var XHR = _dereq_('./xhr'); 2683 var utils = _dereq_('./utils'); 2684 var log = _dereq_('./log'); 2685 var createWindowClone = _dereq_('./clone'); 2686 var decode64 = utils.decode64; 2687 2688 function Proxy(src, proxyUrl, document) { 2689 var supportsCORS = ('withCredentials' in new XMLHttpRequest()); 2690 if (!proxyUrl) { 2691 return Promise.reject("No proxy configured"); 2692 } 2693 var callback = createCallback(supportsCORS); 2694 var url = createProxyUrl(proxyUrl, src, callback); 2695 2696 return supportsCORS ? XHR(url) : (jsonp(document, url, callback).then(function(response) { 2697 return decode64(response.content); 2698 })); 2699 } 2700 var proxyCount = 0; 2701 2702 function ProxyURL(src, proxyUrl, document) { 2703 var supportsCORSImage = ('crossOrigin' in new Image()); 2704 var callback = createCallback(supportsCORSImage); 2705 var url = createProxyUrl(proxyUrl, src, callback); 2706 return (supportsCORSImage ? Promise.resolve(url) : jsonp(document, url, callback).then(function(response) { 2707 return "data:" + response.type + ";base64," + response.content; 2708 })); 2709 } 2710 2711 function jsonp(document, url, callback) { 2712 return new Promise(function(resolve, reject) { 2713 var s = document.createElement("script"); 2714 var cleanup = function() { 2715 delete window.html2canvas.proxy[callback]; 2716 document.body.removeChild(s); 2717 }; 2718 window.html2canvas.proxy[callback] = function(response) { 2719 cleanup(); 2720 resolve(response); 2721 }; 2722 s.src = url; 2723 s.onerror = function(e) { 2724 cleanup(); 2725 reject(e); 2726 }; 2727 document.body.appendChild(s); 2728 }); 2729 } 2730 2731 function createCallback(useCORS) { 2732 return !useCORS ? "html2canvas_" + Date.now() + "_" + (++proxyCount) + "_" + Math.round(Math.random() * 100000) : ""; 2733 } 2734 2735 function createProxyUrl(proxyUrl, src, callback) { 2736 return proxyUrl + "?url=" + encodeURIComponent(src) + (callback.length ? "&callback=html2canvas.proxy." + callback : ""); 2737 } 2738 2739 function documentFromHTML(src) { 2740 return function(html) { 2741 var parser = new DOMParser(), doc; 2742 try { 2743 doc = parser.parseFromString(html, "text/html"); 2744 } catch(e) { 2745 log("DOMParser not supported, falling back to createHTMLDocument"); 2746 doc = document.implementation.createHTMLDocument(""); 2747 try { 2748 doc.open(); 2749 doc.write(html); 2750 doc.close(); 2751 } catch(ee) { 2752 log("createHTMLDocument write not supported, falling back to document.body.innerHTML"); 2753 doc.body.innerHTML = html; // ie9 doesnt support writing to documentElement 2754 } 2755 } 2756 2757 var b = doc.querySelector("base"); 2758 if (!b || !b.href.host) { 2759 var base = doc.createElement("base"); 2760 base.href = src; 2761 doc.head.insertBefore(base, doc.head.firstChild); 2762 } 2763 2764 return doc; 2765 }; 2766 } 2767 2768 function loadUrlDocument(src, proxy, document, width, height, options) { 2769 return new Proxy(src, proxy, window.document).then(documentFromHTML(src)).then(function(doc) { 2770 return createWindowClone(doc, document, width, height, options, 0, 0); 2771 }); 2772 } 2773 2774 exports.Proxy = Proxy; 2775 exports.ProxyURL = ProxyURL; 2776 exports.loadUrlDocument = loadUrlDocument; 2777 2778 },{"./clone":2,"./log":13,"./utils":26,"./xhr":28}],17:[function(_dereq_,module,exports){ 2779 var ProxyURL = _dereq_('./proxy').ProxyURL; 2780 2781 function ProxyImageContainer(src, proxy) { 2782 var link = document.createElement("a"); 2783 link.href = src; 2784 src = link.href; 2785 this.src = src; 2786 this.image = new Image(); 2787 var self = this; 2788 this.promise = new Promise(function(resolve, reject) { 2789 self.image.crossOrigin = "Anonymous"; 2790 self.image.onload = resolve; 2791 self.image.onerror = reject; 2792 2793 new ProxyURL(src, proxy, document).then(function(url) { 2794 self.image.src = url; 2795 })['catch'](reject); 2796 }); 2797 } 2798 2799 module.exports = ProxyImageContainer; 2800 2801 },{"./proxy":16}],18:[function(_dereq_,module,exports){ 2802 var NodeContainer = _dereq_('./nodecontainer'); 2803 2804 function PseudoElementContainer(node, parent, type) { 2805 NodeContainer.call(this, node, parent); 2806 this.isPseudoElement = true; 2807 this.before = type === ":before"; 2808 } 2809 2810 PseudoElementContainer.prototype.cloneTo = function(stack) { 2811 PseudoElementContainer.prototype.cloneTo.call(this, stack); 2812 stack.isPseudoElement = true; 2813 stack.before = this.before; 2814 }; 2815 2816 PseudoElementContainer.prototype = Object.create(NodeContainer.prototype); 2817 2818 PseudoElementContainer.prototype.appendToDOM = function() { 2819 if (this.before) { 2820 this.parent.node.insertBefore(this.node, this.parent.node.firstChild); 2821 } else { 2822 this.parent.node.appendChild(this.node); 2823 } 2824 this.parent.node.className += " " + this.getHideClass(); 2825 }; 2826 2827 PseudoElementContainer.prototype.cleanDOM = function() { 2828 this.node.parentNode.removeChild(this.node); 2829 this.parent.node.className = this.parent.node.className.replace(this.getHideClass(), ""); 2830 }; 2831 2832 PseudoElementContainer.prototype.getHideClass = function() { 2833 return this["PSEUDO_HIDE_ELEMENT_CLASS_" + (this.before ? "BEFORE" : "AFTER")]; 2834 }; 2835 2836 PseudoElementContainer.prototype.PSEUDO_HIDE_ELEMENT_CLASS_BEFORE = "___html2canvas___pseudoelement_before"; 2837 PseudoElementContainer.prototype.PSEUDO_HIDE_ELEMENT_CLASS_AFTER = "___html2canvas___pseudoelement_after"; 2838 2839 module.exports = PseudoElementContainer; 2840 2841 },{"./nodecontainer":14}],19:[function(_dereq_,module,exports){ 2842 var log = _dereq_('./log'); 2843
2844 function Renderer(width, height, images, options, document) { 2845 this.width = width; 2846 this.height = height; 2847 this.images = images; 2848 this.options = options; 2849 this.document = document; 2850 } 2851 2852 Renderer.prototype.renderImage = function(container, bounds, borderData, imageContainer) { 2853 var paddingLeft = container.cssInt('paddingLeft'), 2854 paddingTop = container.cssInt('paddingTop'), 2855 paddingRight = container.cssInt('paddingRight'), 2856 paddingBottom = container.cssInt('paddingBottom'), 2857 borders = borderData.borders; 2858 2859 var width = bounds.width - (borders[1].width + borders[3].width + paddingLeft + paddingRight); 2860 var height = bounds.height - (borders[0].width + borders[2].width + paddingTop + paddingBottom); 2861 this.drawImage( 2862 imageContainer, 2863 0, 2864 0, 2865 imageContainer.image.width || width, 2866 imageContainer.image.height || height, 2867 bounds.left + paddingLeft + borders[3].width, 2868 bounds.top + paddingTop + borders[0].width, 2869 width, 2870 height 2871 ); 2872 }; 2873 2874 Renderer.prototype.renderBackground = function(container, bounds, borderData) { 2875 if (bounds.height > 0 && bounds.width > 0) { 2876 this.renderBackgroundColor(container, bounds); 2877 this.renderBackgroundImage(container, bounds, borderData); 2878 } 2879 }; 2880 2881 Renderer.prototype.renderBackgroundColor = function(container, bounds) { 2882 var color = container.color("backgroundColor"); 2883 if (!color.isTransparent()) { 2884 this.rectangle(bounds.left, bounds.top, bounds.width, bounds.height, color); 2885 } 2886 }; 2887 2888 Renderer.prototype.renderBorders = function(borders) { 2889 borders.forEach(this.renderBorder, this); 2890 }; 2891 2892 Renderer.prototype.renderBorder = function(data) { 2893 if (!data.color.isTransparent() && data.args !== null) { 2894 this.drawShape(data.args, data.color); 2895 } 2896 }; 2897 2898 Renderer.prototype.renderBackgroundImage = function(container, bounds, borderData) { 2899 var backgroundImages = container.parseBackgroundImages(); 2900 backgroundImages.reverse().forEach(function(backgroundImage, index, arr) { 2901 switch(backgroundImage.method) { 2902 case "url": 2903 var image = this.images.get(backgroundImage.args[0]); 2904 if (image) { 2905 this.renderBackgroundRepeating(container, bounds, image, arr.length - (index+1), borderData); 2906 } else { 2907 log("Error loading background-image", backgroundImage.args[0]); 2908 } 2909 break; 2910 case "linear-gradient": 2911 case "gradient": 2912 var gradientImage = this.images.get(backgroundImage.value); 2913 if (gradientImage) { 2914 this.renderBackgroundGradient(gradientImage, bounds, borderData); 2915 } else { 2916 log("Error loading background-image", backgroundImage.args[0]); 2917 } 2918 break; 2919 case "none": 2920 break; 2921 default: 2922 log("Unknown background-image type", backgroundImage.args[0]); 2923 } 2924 }, this); 2925 }; 2926 2927 Renderer.prototype.renderBackgroundRepeating = function(container, bounds, imageContainer, index, borderData) { 2928 var size = container.parseBackgroundSize(bounds, imageContainer.image, index); 2929 var position = container.parseBackgroundPosition(bounds, imageContainer.image, index, size); 2930 var repeat = container.parseBackgroundRepeat(index); 2931 switch (repeat) { 2932 case "repeat-x": 2933 case "repeat no-repeat": 2934 this.backgroundRepeatShape(imageContainer, position, size, bounds, bounds.left + borderData[3], bounds.top + position.top + borderData[0], 99999, size.height, borderData); 2935 break; 2936 case "repeat-y": 2937 case "no-repeat repeat": 2938 this.backgroundRepeatShape(imageContainer, position, size, bounds, bounds.left + position.left + borderData[3], bounds.top + borderData[0], size.width, 99999, borderData); 2939 break; 2940 case "no-repeat": 2941 this.backgroundRepeatShape(imageContainer, position, size, bounds, bounds.left + position.left + borderData[3], bounds.top + position.top + borderData[0], size.width, size.height, borderData); 2942 break; 2943 default:
2944 this.renderBackgroundRepeat(imageContainer, position, size, {top: bounds.top, left: bounds.left}, borderData[3], borderData[0]); 2945 break; 2946 } 2947 }; 2948 2949 module.exports = Renderer; 2950 2951 },{"./log":13}],20:[function(_dereq_,module,exports){ 2952 var Renderer = _dereq_('../renderer'); 2953 var LinearGradientContainer = _dereq_('../lineargradientcontainer'); 2954 var log = _dereq_('../log'); 2955 2956 function CanvasRenderer(width, height) { 2957 Renderer.apply(this, arguments); 2958 this.canvas = this.options.canvas || this.document.createElement("canvas"); 2959 if (!this.options.canvas) { 2960 this.canvas.width = width; 2961 this.canvas.height = height; 2962 } 2963 this.ctx = this.canvas.getContext("2d"); 2964 this.taintCtx = this.document.createElement("canvas").getContext("2d"); 2965 this.ctx.textBaseline = "bottom"; 2966 this.variables = {}; 2967 log("Initialized CanvasRenderer with size", width, "x", height); 2968 } 2969 2970 CanvasRenderer.prototype = Object.create(Renderer.prototype); 2971 2972 CanvasRenderer.prototype.setFillStyle = function(fillStyle) { 2973 this.ctx.fillStyle = typeof(fillStyle) === "object" && !!fillStyle.isColor ? fillStyle.toString() : fillStyle; 2974 return this.ctx; 2975 }; 2976 2977 CanvasRenderer.prototype.rectangle = function(left, top, width, height, color) { 2978 this.setFillStyle(color).fillRect(left, top, width, height); 2979 }; 2980 2981 CanvasRenderer.prototype.circle = function(left, top, size, color) { 2982 this.setFillStyle(color); 2983 this.ctx.beginPath(); 2984 this.ctx.arc(left + size / 2, top + size / 2, size / 2, 0, Math.PI*2, true); 2985 this.ctx.closePath(); 2986 this.ctx.fill(); 2987 }; 2988 2989 CanvasRenderer.prototype.circleStroke = function(left, top, size, color, stroke, strokeColor) { 2990 this.circle(left, top, size, color); 2991 this.ctx.strokeStyle = strokeColor.toString(); 2992 this.ctx.stroke(); 2993 }; 2994 2995 CanvasRenderer.prototype.drawShape = function(shape, color) { 2996 this.shape(shape); 2997 this.setFillStyle(color).fill(); 2998 }; 2999 3000 CanvasRenderer.prototype.taints = function(imageContainer) { 3001 if (imageContainer.tainted === null) { 3002 this.taintCtx.drawImage(imageContainer.image, 0, 0); 3003 try { 3004 this.taintCtx.getImageData(0, 0, 1, 1); 3005 imageContainer.tainted = false; 3006 } catch(e) { 3007 this.taintCtx = document.createElement("canvas").getContext("2d"); 3008 imageContainer.tainted = true; 3009 } 3010 } 3011 3012 return imageContainer.tainted; 3013 }; 3014 3015 CanvasRenderer.prototype.drawImage = function(imageContainer, sx, sy, sw, sh, dx, dy, dw, dh) { 3016 if (!this.taints(imageContainer) || this.options.allowTaint) { 3017 this.ctx.drawImage(imageContainer.image, sx, sy, sw, sh, dx, dy, dw, dh); 3018 } 3019 }; 3020 3021 CanvasRenderer.prototype.clip = function(shapes, callback, context) { 3022 this.ctx.save(); 3023 shapes.filter(hasEntries).forEach(function(shape) { 3024 this.shape(shape).clip(); 3025 }, this); 3026 callback.call(context); 3027 this.ctx.restore(); 3028 }; 3029 3030 CanvasRenderer.prototype.shape = function(shape) { 3031 this.ctx.beginPath(); 3032 shape.forEach(function(point, index) { 3033 if (point[0] === "rect") { 3034 this.ctx.rect.apply(this.ctx, point.slice(1)); 3035 } else { 3036 this.ctx[(index === 0) ? "moveTo" : point[0] + "To" ].apply(this.ctx, point.slice(1)); 3037 } 3038 }, this); 3039 this.ctx.closePath(); 3040 return this.ctx; 3041 }; 3042 3043 CanvasRenderer.prototype.font = function(color, style, variant, weight, size, family) { 3044 this.setFillStyle(color).font = [style, variant, weight, size, family].join(" ").split(",")[0]; 3045 }; 3046 3047 CanvasRenderer.prototype.fontShadow = function(color, offsetX, offsetY, blur) { 3048 this.setVariable("shadowColor", color.toString()) 3049 .setVariable("shadowOffsetY", offsetX) 3050 .setVariable("shadowOffsetX", offsetY) 3051 .setVariable("shadowBlur", blur); 3052 }; 3053 3054 CanvasRenderer.prototype.clearShadow = function() { 3055 this.setVariable("shadowColor", "rgba(0,0,0,0)"); 3056 }; 3057 3058 CanvasRenderer.prototype.setOpacity = function(opacity) { 3059 this.ctx.globalAlpha = opacity; 3060 }; 3061 3062 CanvasRenderer.prototype.setTransform = function(transform) { 3063 this.ctx.translate(transform.origin[0], transform.origin[1]); 3064 this.ctx.transform.apply(this.ctx, transform.matrix); 3065 this.ctx.translate(-transform.origin[0], -transform.origin[1]); 3066 }; 3067 3068 CanvasRenderer.prototype.setVariable = function(property, value) { 3069 if (this.variables[property] !== value) { 3070 this.variables[property] = this.ctx[property] = value; 3071 } 3072 3073 return this; 3074 }; 3075 3076 CanvasRenderer.prototype.text = function(text, left, bottom) { 3077 this.ctx.fillText(text, left, bottom); 3078 }; 3079 3080 CanvasRenderer.prototype.backgroundRepeatShape = function(imageContainer, backgroundPosition, size, bounds, left, top, width, height, borderData) { 3081 var shape = [ 3082 ["line", Math.round(left), Math.round(top)], 3083 ["line", Math.round(left + width), Math.round(top)], 3084 ["line", Math.round(left + width), Math.round(height + top)], 3085 ["line", Math.round(left), Math.round(height + top)] 3086 ]; 3087 this.clip([shape], function() {
3088 this.renderBackgroundRepeat(imageContainer, backgroundPosition, size, bounds, borderData[3], borderData[0]); 3089 }, this); 3090 }; 3091 3092 CanvasRenderer.prototype.renderBackgroundRepeat = function(imageContainer, backgroundPosition, size, bounds, borderLeft, borderTop) { 3093 var offsetX = Math.round(bounds.left + backgroundPosition.left + borderLeft), offsetY = Math.round(bounds.top + backgroundPosition.top + borderTop); 3094 this.setFillStyle(this.ctx.createPattern(this.resizeImage(imageContainer, size), "repeat")); 3095 this.ctx.translate(offsetX, offsetY); 3096 this.ctx.fill(); 3097 this.ctx.translate(-offsetX, -offsetY); 3098 }; 3099 3100 CanvasRenderer.prototype.renderBackgroundGradient = function(gradientImage, bounds) { 3101 if (gradientImage instanceof LinearGradientContainer) { 3102 var gradient = this.ctx.createLinearGradient( 3103 bounds.left + bounds.width * gradientImage.x0, 3104 bounds.top + bounds.height * gradientImage.y0, 3105 bounds.left + bounds.width * gradientImage.x1, 3106 bounds.top + bounds.height * gradientImage.y1); 3107 gradientImage.colorStops.forEach(function(colorStop) { 3108 gradient.addColorStop(colorStop.stop, colorStop.color.toString()); 3109 }); 3110 this.rectangle(bounds.left, bounds.top, bounds.width, bounds.height, gradient); 3111 } 3112 }; 3113 3114 CanvasRenderer.prototype.resizeImage = function(imageContainer, size) { 3115 var image = imageContainer.image; 3116 if(image.width === size.width && image.height === size.height) { 3117 return image; 3118 } 3119 3120 var ctx, canvas = document.createElement('canvas'); 3121 canvas.width = size.width; 3122 canvas.height = size.height; 3123 ctx = canvas.getContext("2d"); 3124 ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, size.width, size.height ); 3125 return canvas; 3126 }; 3127 3128 function hasEntries(array) { 3129 return array.length > 0; 3130 } 3131 3132 module.exports = CanvasRenderer; 3133 3134 },{"../lineargradientcontainer":12,"../log":13,"../renderer":19}],21:[function(_dereq_,module,exports){ 3135 var NodeContainer = _dereq_('./nodecontainer'); 3136 3137 function StackingContext(hasOwnStacking, opacity, element, parent) { 3138 NodeContainer.call(this, element, parent); 3139 this.ownStacking = hasOwnStacking; 3140 this.contexts = []; 3141 this.children = []; 3142 this.opacity = (this.parent ? this.parent.stack.opacity : 1) * opacity; 3143 } 3144 3145 StackingContext.prototype = Object.create(NodeContainer.prototype); 3146 3147 StackingContext.prototype.getParentStack = function(context) { 3148 var parentStack = (this.parent) ? this.parent.stack : null; 3149 return parentStack ? (parentStack.ownStacking ? parentStack : parentStack.getParentStack(context)) : context.stack; 3150 }; 3151 3152 module.exports = StackingContext; 3153 3154 },{"./nodecontainer":14}],22:[function(_dereq_,module,exports){ 3155 function Support(document) { 3156 this.rangeBounds = this.testRangeBounds(document); 3157 this.cors = this.testCORS(); 3158 this.svg = this.testSVG(); 3159 } 3160 3161 Support.prototype.testRangeBounds = function(document) { 3162 var range, testElement, rangeBounds, rangeHeight, support = false; 3163 3164 if (document.createRange) { 3165 range = document.createRange(); 3166 if (range.getBoundingClientRect) { 3167 testElement = document.createElement('boundtest'); 3168 testElement.style.height = "123px"; 3169 testElement.style.display = "block"; 3170 document.body.appendChild(testElement); 3171 3172 range.selectNode(testElement); 3173 rangeBounds = range.getBoundingClientRect(); 3174 rangeHeight = rangeBounds.height; 3175 3176 if (rangeHeight === 123) { 3177 support = true; 3178 } 3179 document.body.removeChild(testElement); 3180 } 3181 } 3182 3183 return support; 3184 }; 3185 3186 Support.prototype.testCORS = function() { 3187 return typeof((new Image()).crossOrigin) !== "undefined"; 3188 }; 3189 3190 Support.prototype.testSVG = function() { 3191 var img = new Image(); 3192 var canvas = document.createElement("canvas");
3193 var ctx = canvas.getContext("2d"); 3194 img.src = "data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'></svg>"; 3195 3196 try { 3197 ctx.drawImage(img, 0, 0); 3198 canvas.toDataURL(); 3199 } catch(e) { 3200 return false; 3201 } 3202 return true; 3203 }; 3204 3205 module.exports = Support; 3206 3207 },{}],23:[function(_dereq_,module,exports){ 3208 var XHR = _dereq_('./xhr'); 3209 var decode64 = _dereq_('./utils').decode64; 3210 3211 function SVGContainer(src) { 3212 this.src = src; 3213 this.image = null; 3214 var self = this; 3215 3216 this.promise = this.hasFabric().then(function() { 3217 return (self.isInline(src) ? Promise.resolve(self.inlineFormatting(src)) : XHR(src)); 3218 }).then(function(svg) { 3219 return new Promise(function(resolve) { 3220 window.html2canvas.svg.fabric.loadSVGFromString(svg, self.createCanvas.call(self, resolve)); 3221 }); 3222 }); 3223 } 3224 3225 SVGContainer.prototype.hasFabric = function() { 3226 return !window.html2canvas.svg || !window.html2canvas.svg.fabric ? Promise.reject(new Error("html2canvas.svg.js is not loaded, cannot render svg")) : Promise.resolve(); 3227 }; 3228 3229 SVGContainer.prototype.inlineFormatting = function(src) { 3230 return (/^data:image\/svg\+xml;base64,/.test(src)) ? this.decode64(this.removeContentType(src)) : this.removeContentType(src); 3231 }; 3232 3233 SVGContainer.prototype.removeContentType = function(src) { 3234 return src.replace(/^data:image\/svg\+xml(;base64)?,/,''); 3235 }; 3236 3237 SVGContainer.prototype.isInline = function(src) { 3238 return (/^data:image\/svg\+xml/i.test(src)); 3239 }; 3240 3241 SVGContainer.prototype.createCanvas = function(resolve) { 3242 var self = this; 3243 return function (objects, options) { 3244 var canvas = new window.html2canvas.svg.fabric.StaticCanvas('c'); 3245 self.image = canvas.lowerCanvasEl; 3246 canvas 3247 .setWidth(options.width) 3248 .setHeight(options.height) 3249 .add(window.html2canvas.svg.fabric.util.groupSVGElements(objects, options)) 3250 .renderAll(); 3251 resolve(canvas.lowerCanvasEl); 3252 }; 3253 }; 3254 3255 SVGContainer.prototype.decode64 = function(str) { 3256 return (typeof(window.atob) === "function") ? window.atob(str) : decode64(str); 3257 }; 3258 3259 module.exports = SVGContainer; 3260 3261 },{"./utils":26,"./xhr":28}],24:[function(_dereq_,module,exports){ 3262 var SVGContainer = _dereq_('./svgcontainer'); 3263 3264 function SVGNodeContainer(node, _native) { 3265 this.src = node; 3266 this.image = null; 3267 var self = this; 3268 3269 this.promise = _native ? new Promise(function(resolve, reject) { 3270 self.image = new Image(); 3271 self.image.onload = resolve; 3272 self.image.onerror = reject; 3273 self.image.src = "data:image/svg+xml," + (new XMLSerializer()).serializeToString(node); 3274 if (self.image.complete === true) { 3275 resolve(self.image); 3276 } 3277 }) : this.hasFabric().then(function() { 3278 return new Promise(function(resolve) { 3279 window.html2canvas.svg.fabric.parseSVGDocument(node, self.createCanvas.call(self, resolve)); 3280 }); 3281 }); 3282 } 3283 3284 SVGNodeContainer.prototype = Object.create(SVGContainer.prototype); 3285 3286 module.exports = SVGNodeContainer; 3287 3288 },{"./svgcontainer":23}],25:[function(_dereq_,module,exports){ 3289 var NodeContainer = _dereq_('./nodecontainer'); 3290 3291 function TextContainer(node, parent) { 3292 NodeContainer.call(this, node, parent); 3293 } 3294 3295 TextContainer.prototype = Object.create(NodeContainer.prototype); 3296 3297 TextContainer.prototype.applyTextTransform = function() { 3298 this.node.data = this.transform(this.parent.css("textTransform")); 3299 }; 3300 3301 TextContainer.prototype.transform = function(transform) { 3302 var text = this.node.data; 3303 switch(transform){ 3304 case "lowercase": 3305 return text.toLowerCase(); 3306 case "capitalize": 3307 return text.replace(/(^|\s|:|-|\(|\))([a-z])/g, capitalize); 3308 case "uppercase": 3309 return text.toUpperCase(); 3310 default: 3311 return text; 3312 } 3313 }; 3314 3315 function capitalize(m, p1, p2) { 3316 if (m.length > 0) { 3317 return p1 + p2.toUpperCase(); 3318 } 3319 } 3320 3321 module.exports = TextContainer; 3322 3323 },{"./nodecontainer":14}],26:[function(_dereq_,module,exports){ 3324 exports.smallImage = function smallImage() { 3325 return "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"; 3326 }; 3327 3328 exports.bind = function(callback, context) { 3329 return function() { 3330 return callback.apply(context, arguments); 3331 }; 3332 }; 3333 3334 /* 3335 * base64-arraybuffer 3336 * https://github.com/niklasvh/base64-arraybuffer 3337 * 3338 * Copyright (c) 2012 Niklas von Hertzen 3339 * Licensed under the MIT license. 3340 */ 3341 3342 exports.decode64 = function(base64) { 3343 var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
3343+/"; 3344 var len = base64.length, i, encoded1, encoded2, encoded3, encoded4, byte1, byte2, byte3; 3345 3346 var output = ""; 3347 3348 for (i = 0; i < len; i+=4) { 3349 encoded1 = chars.indexOf(base64[i]); 3350 encoded2 = chars.indexOf(base64[i+1]); 3351 encoded3 = chars.indexOf(base64[i+2]); 3352 encoded4 = chars.indexOf(base64[i+3]); 3353 3354 byte1 = (encoded1 << 2) | (encoded2 >> 4); 3355 byte2 = ((encoded2 & 15) << 4) | (encoded3 >> 2); 3356 byte3 = ((encoded3 & 3) << 6) | encoded4; 3357 if (encoded3 === 64) { 3358 output += String.fromCharCode(byte1); 3359 } else if (encoded4 === 64 || encoded4 === -1) { 3360 output += String.fromCharCode(byte1, byte2); 3361 } else{ 3362 output += String.fromCharCode(byte1, byte2, byte3); 3363 } 3364 } 3365 3366 return output; 3367 }; 3368 3369 exports.getBounds = function(node) { 3370 if (node.getBoundingClientRect) { 3371 var clientRect = node.getBoundingClientRect(); 3372 var width = node.offsetWidth == null ? clientRect.width : node.offsetWidth; 3373 return { 3374 top: clientRect.top, 3375 bottom: clientRect.bottom || (clientRect.top + clientRect.height), 3376 right: clientRect.left + width, 3377 left: clientRect.left, 3378 width: width, 3379 height: node.offsetHeight == null ? clientRect.height : node.offsetHeight 3380 }; 3381 } 3382 return {}; 3383 }; 3384 3385 exports.offsetBounds = function(node) { 3386 var parent = node.offsetParent ? exports.offsetBounds(node.offsetParent) : {top: 0, left: 0}; 3387 3388 return { 3389 top: node.offsetTop + parent.top, 3390 bottom: node.offsetTop + node.offsetHeight + parent.top, 3391 right: node.offsetLeft + parent.left + node.offsetWidth, 3392 left: node.offsetLeft + parent.left, 3393 width: node.offsetWidth, 3394 height: node.offsetHeight 3395 }; 3396 }; 3397 3398 exports.parseBackgrounds = function(backgroundImage) { 3399 var whitespace = ' \r\n\t', 3400 method, definition, prefix, prefix_i, block, results = [], 3401 mode = 0, numParen = 0, quote, args; 3402 var appendResult = function() { 3403 if(method) { 3404 if (definition.substr(0, 1) === '"') { 3405 definition = definition.substr(1, definition.length - 2); 3406 } 3407 if (definition) { 3408 args.push(definition); 3409 } 3410 if (method.substr(0, 1) === '-' && (prefix_i = method.indexOf('-', 1 ) + 1) > 0) { 3411 prefix = method.substr(0, prefix_i); 3412 method = method.substr(prefix_i); 3413 } 3414 results.push({ 3415 prefix: prefix, 3416 method: method.toLowerCase(), 3417 value: block, 3418 args: args, 3419 image: null 3420 }); 3421 } 3422 args = []; 3423 method = prefix = definition = block = ''; 3424 }; 3425 args = []; 3426 method = prefix = definition = block = ''; 3427 backgroundImage.split("").forEach(function(c) { 3428 if (mode === 0 && whitespace.indexOf(c) > -1) { 3429 return; 3430 } 3431 switch(c) { 3432 case '"': 3433 if(!quote) { 3434 quote = c; 3435 } else if(quote === c) { 3436 quote = null; 3437 } 3438 break; 3439 case '(': 3440 if(quote) { 3441 break; 3442 } else if(mode === 0) { 3443 mode = 1; 3444 block += c; 3445 return; 3446 } else { 3447 numParen++; 3448 } 3449 break; 3450 case ')': 3451 if (quote) { 3452 break; 3453 } else if(mode === 1) { 3454 if(numParen === 0) { 3455 mode = 0; 3456 block += c; 3457 appendResult(); 3458 return; 3459 } else { 3460 numParen--; 3461 } 3462 } 3463 break; 3464 3465 case ',': 3466 if (quote) { 3467 break; 3468 } else if(mode === 0) { 3469 appendResult(); 3470 return; 3471 } else if (mode === 1) { 3472 if (numParen === 0 && !method.match(/^url$/i)) { 3473 args.push(definition); 3474 definition = ''; 3475 block += c; 3476 return; 3477 } 3478 } 3479 break; 3480 } 3481 3482 block += c; 3483 if (mode === 0) { 3484 method += c; 3485 } else { 3486 definition += c; 3487 } 3488 }); 3489 3490 appendResult(); 3491 return results; 3492 }; 3493 3494 },{}],27:[function(_dereq_,module,exports){ 3495 var GradientContainer = _dereq_('./gradientcontainer'); 3496 3497 function WebkitGradientContainer(imageData) { 3498 GradientContainer.apply(this, arguments); 3499 this.type = imageData.args[0] === "linear" ? GradientContainer.TYPES.LINEAR
3499: GradientContainer.TYPES.RADIAL; 3500 } 3501 3502 WebkitGradientContainer.prototype = Object.create(GradientContainer.prototype); 3503 3504 module.exports = WebkitGradientContainer; 3505 3506 },{"./gradientcontainer":9}],28:[function(_dereq_,module,exports){ 3507 function XHR(url) { 3508 return new Promise(function(resolve, reject) { 3509 var xhr = new XMLHttpRequest(); 3510 xhr.open('GET', url); 3511 3512 xhr.onload = function() { 3513 if (xhr.status === 200) { 3514 resolve(xhr.responseText); 3515 } else { 3516 reject(new Error(xhr.statusText)); 3517 } 3518 }; 3519 3520 xhr.onerror = function() { 3521 reject(new Error("Network Error")); 3522 }; 3523 3524 xhr.send(); 3525 }); 3526 } 3527 3528 module.exports = XHR; 3529 3530 },{}]},{},[4])(4) 3531});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.