html2canvas.js 123 KB

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