网页整页截图

Ctrl+F10 网页整页截图,焦点位于输入框时将输入框内文字转换为图片

当前为 2016-11-17 提交的版本,查看 最新版本

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