网页整页截图

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

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

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