Greasy Fork镜像 支持简体中文。

網頁整頁截圖

Ctrl+F10 網頁整頁截圖,焦點位於輸入框時將輸入框内文字轉換為圖片

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址