html2canvas.js 123 KB

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