html2canvas.min

网页截图

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/388505/724511/html2canvasmin.js

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

QingJ © 2025

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