海鲜小程序

html2canvas.js 123KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520
  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. console.log(stack.children)
  1363. };
  1364. NodeContainer.prototype.isElementVisible = function() {
  1365. return this.node.nodeType === Node.TEXT_NODE ? this.parent.visible : (
  1366. this.css('display') !== "none" &&
  1367. this.css('visibility') !== "hidden" &&
  1368. !this.node.hasAttribute("data-html2canvas-ignore") &&
  1369. (this.node.nodeName !== "INPUT" || this.node.getAttribute("type") !== "hidden")
  1370. );
  1371. };
  1372. NodeContainer.prototype.css = function(attribute) {
  1373. if (!this.computedStyles) {
  1374. this.computedStyles = this.isPseudoElement ? this.parent.computedStyle(this.before ? ":before" : ":after") : this.computedStyle(null);
  1375. }
  1376. return this.styles[attribute] || (this.styles[attribute] = this.computedStyles[attribute]);
  1377. };
  1378. NodeContainer.prototype.prefixedCss = function(attribute) {
  1379. var prefixes = ["webkit", "moz", "ms", "o"];
  1380. var value = this.css(attribute);
  1381. if (value === undefined) {
  1382. prefixes.some(function(prefix) {
  1383. value = this.css(prefix + attribute.substr(0, 1).toUpperCase() + attribute.substr(1));
  1384. return value !== undefined;
  1385. }, this);
  1386. }
  1387. return value === undefined ? null : value;
  1388. };
  1389. NodeContainer.prototype.computedStyle = function(type) {
  1390. return this.node.ownerDocument.defaultView.getComputedStyle(this.node, type);
  1391. };
  1392. NodeContainer.prototype.cssInt = function(attribute) {
  1393. var value = parseInt(this.css(attribute), 10);
  1394. return (isNaN(value)) ? 0 : value; // borders in old IE are throwing 'medium' for demo.html
  1395. };
  1396. NodeContainer.prototype.color = function(attribute) {
  1397. return this.colors[attribute] || (this.colors[attribute] = new Color(this.css(attribute)));
  1398. };
  1399. NodeContainer.prototype.cssFloat = function(attribute) {
  1400. var value = parseFloat(this.css(attribute));
  1401. return (isNaN(value)) ? 0 : value;
  1402. };
  1403. NodeContainer.prototype.fontWeight = function() {
  1404. var weight = this.css("fontWeight");
  1405. switch(parseInt(weight, 10)){
  1406. case 401:
  1407. weight = "bold";
  1408. break;
  1409. case 400:
  1410. weight = "normal";
  1411. break;
  1412. }
  1413. return weight;
  1414. };
  1415. NodeContainer.prototype.parseClip = function() {
  1416. var matches = this.css('clip').match(this.CLIP);
  1417. if (matches) {
  1418. return {
  1419. top: parseInt(matches[1], 10),
  1420. right: parseInt(matches[2], 10),
  1421. bottom: parseInt(matches[3], 10),
  1422. left: parseInt(matches[4], 10)
  1423. };
  1424. }
  1425. return null;
  1426. };
  1427. NodeContainer.prototype.parseBackgroundImages = function() {
  1428. return this.backgroundImages || (this.backgroundImages = parseBackgrounds(this.css("backgroundImage")));
  1429. };
  1430. NodeContainer.prototype.cssList = function(property, index) {
  1431. var value = (this.css(property) || '').split(',');
  1432. value = value[index || 0] || value[0] || 'auto';
  1433. value = value.trim().split(' ');
  1434. if (value.length === 1) {
  1435. value = [value[0], isPercentage(value[0]) ? 'auto' : value[0]];
  1436. }
  1437. return value;
  1438. };
  1439. NodeContainer.prototype.parseBackgroundSize = function(bounds, image, index) {
  1440. var size = this.cssList("backgroundSize", index);
  1441. var width, height;
  1442. if (isPercentage(size[0])) {
  1443. width = bounds.width * parseFloat(size[0]) / 100;
  1444. } else if (/contain|cover/.test(size[0])) {
  1445. var targetRatio = bounds.width / bounds.height, currentRatio = image.width / image.height;
  1446. return (targetRatio < currentRatio ^ size[0] === 'contain') ? {width: bounds.height * currentRatio, height: bounds.height} : {width: bounds.width, height: bounds.width / currentRatio};
  1447. } else {
  1448. width = parseInt(size[0], 10);
  1449. }
  1450. if (size[0] === 'auto' && size[1] === 'auto') {
  1451. height = image.height;
  1452. } else if (size[1] === 'auto') {
  1453. height = width / image.width * image.height;
  1454. } else if (isPercentage(size[1])) {
  1455. height = bounds.height * parseFloat(size[1]) / 100;
  1456. } else {
  1457. height = parseInt(size[1], 10);
  1458. }
  1459. if (size[0] === 'auto') {
  1460. width = height / image.height * image.width;
  1461. }
  1462. return {width: width, height: height};
  1463. };
  1464. NodeContainer.prototype.parseBackgroundPosition = function(bounds, image, index, backgroundSize) {
  1465. var position = this.cssList('backgroundPosition', index);
  1466. var left, top;
  1467. if (isPercentage(position[0])){
  1468. left = (bounds.width - (backgroundSize || image).width) * (parseFloat(position[0]) / 100);
  1469. } else {
  1470. left = parseInt(position[0], 10);
  1471. }
  1472. if (position[1] === 'auto') {
  1473. top = left / image.width * image.height;
  1474. } else if (isPercentage(position[1])){
  1475. top = (bounds.height - (backgroundSize || image).height) * parseFloat(position[1]) / 100;
  1476. } else {
  1477. top = parseInt(position[1], 10);
  1478. }
  1479. if (position[0] === 'auto') {
  1480. left = top / image.height * image.width;
  1481. }
  1482. return {left: left, top: top};
  1483. };
  1484. NodeContainer.prototype.parseBackgroundRepeat = function(index) {
  1485. return this.cssList("backgroundRepeat", index)[0];
  1486. };
  1487. NodeContainer.prototype.parseTextShadows = function() {
  1488. var textShadow = this.css("textShadow");
  1489. var results = [];
  1490. if (textShadow && textShadow !== 'none') {
  1491. var shadows = textShadow.match(this.TEXT_SHADOW_PROPERTY);
  1492. for (var i = 0; shadows && (i < shadows.length); i++) {
  1493. var s = shadows[i].match(this.TEXT_SHADOW_VALUES);
  1494. results.push({
  1495. color: new Color(s[0]),
  1496. offsetX: s[1] ? parseFloat(s[1].replace('px', '')) : 0,
  1497. offsetY: s[2] ? parseFloat(s[2].replace('px', '')) : 0,
  1498. blur: s[3] ? s[3].replace('px', '') : 0
  1499. });
  1500. }
  1501. }
  1502. return results;
  1503. };
  1504. NodeContainer.prototype.parseTransform = function() {
  1505. if (!this.transformData) {
  1506. if (this.hasTransform()) {
  1507. var offset = this.parseBounds();
  1508. var origin = this.prefixedCss("transformOrigin").split(" ").map(removePx).map(asFloat);
  1509. origin[0] += offset.left;
  1510. origin[1] += offset.top;
  1511. this.transformData = {
  1512. origin: origin,
  1513. matrix: this.parseTransformMatrix()
  1514. };
  1515. } else {
  1516. this.transformData = {
  1517. origin: [0, 0],
  1518. matrix: [1, 0, 0, 1, 0, 0]
  1519. };
  1520. }
  1521. }
  1522. return this.transformData;
  1523. };
  1524. NodeContainer.prototype.parseTransformMatrix = function() {
  1525. if (!this.transformMatrix) {
  1526. var transform = this.prefixedCss("transform");
  1527. var matrix = transform ? parseMatrix(transform.match(this.MATRIX_PROPERTY)) : null;
  1528. this.transformMatrix = matrix ? matrix : [1, 0, 0, 1, 0, 0];
  1529. }
  1530. return this.transformMatrix;
  1531. };
  1532. NodeContainer.prototype.parseBounds = function() {
  1533. return this.bounds || (this.bounds = this.hasTransform() ? offsetBounds(this.node) : getBounds(this.node));
  1534. };
  1535. NodeContainer.prototype.hasTransform = function() {
  1536. return this.parseTransformMatrix().join(",") !== "1,0,0,1,0,0" || (this.parent && this.parent.hasTransform());
  1537. };
  1538. NodeContainer.prototype.getValue = function() {
  1539. var value = this.node.value || "";
  1540. if (this.node.tagName === "SELECT") {
  1541. value = selectionValue(this.node);
  1542. } else if (this.node.type === "password") {
  1543. value = Array(value.length + 1).join('\u2022'); // jshint ignore:line
  1544. }
  1545. return value.length === 0 ? (this.node.placeholder || "") : value;
  1546. };
  1547. NodeContainer.prototype.MATRIX_PROPERTY = /(matrix|matrix3d)\((.+)\)/;
  1548. NodeContainer.prototype.TEXT_SHADOW_PROPERTY = /((rgba|rgb)\([^\)]+\)(\s-?\d+px){0,})/g;
  1549. NodeContainer.prototype.TEXT_SHADOW_VALUES = /(-?\d+px)|(#.+)|(rgb\(.+\))|(rgba\(.+\))/g;
  1550. NodeContainer.prototype.CLIP = /^rect\((\d+)px,? (\d+)px,? (\d+)px,? (\d+)px\)$/;
  1551. function selectionValue(node) {
  1552. var option = node.options[node.selectedIndex || 0];
  1553. return option ? (option.text || "") : "";
  1554. }
  1555. function parseMatrix(match) {
  1556. if (match && match[1] === "matrix") {
  1557. return match[2].split(",").map(function(s) {
  1558. return parseFloat(s.trim());
  1559. });
  1560. } else if (match && match[1] === "matrix3d") {
  1561. var matrix3d = match[2].split(",").map(function(s) {
  1562. return parseFloat(s.trim());
  1563. });
  1564. return [matrix3d[0], matrix3d[1], matrix3d[4], matrix3d[5], matrix3d[12], matrix3d[13]];
  1565. }
  1566. }
  1567. function isPercentage(value) {
  1568. return value.toString().indexOf("%") !== -1;
  1569. }
  1570. function removePx(str) {
  1571. return str.replace("px", "");
  1572. }
  1573. function asFloat(str) {
  1574. return parseFloat(str);
  1575. }
  1576. module.exports = NodeContainer;
  1577. },{"./color":3,"./utils":26}],15:[function(_dereq_,module,exports){
  1578. var log = _dereq_('./log');
  1579. var punycode = _dereq_('punycode');
  1580. var NodeContainer = _dereq_('./nodecontainer');
  1581. var TextContainer = _dereq_('./textcontainer');
  1582. var PseudoElementContainer = _dereq_('./pseudoelementcontainer');
  1583. var FontMetrics = _dereq_('./fontmetrics');
  1584. var Color = _dereq_('./color');
  1585. var StackingContext = _dereq_('./stackingcontext');
  1586. var utils = _dereq_('./utils');
  1587. var bind = utils.bind;
  1588. var getBounds = utils.getBounds;
  1589. var parseBackgrounds = utils.parseBackgrounds;
  1590. var offsetBounds = utils.offsetBounds;
  1591. function NodeParser(element, renderer, support, imageLoader, options) {
  1592. log("Starting NodeParser");
  1593. this.renderer = renderer;
  1594. this.options = options;
  1595. this.range = null;
  1596. this.support = support;
  1597. this.renderQueue = [];
  1598. this.stack = new StackingContext(true, 1, element.ownerDocument, null);
  1599. var parent = new NodeContainer(element, null);
  1600. if (options.background) {
  1601. renderer.rectangle(0, 0, renderer.width, renderer.height, new Color(options.background));
  1602. }
  1603. if (element === element.ownerDocument.documentElement) {
  1604. // http://www.w3.org/TR/css3-background/#special-backgrounds
  1605. var canvasBackground = new NodeContainer(parent.color('backgroundColor').isTransparent() ? element.ownerDocument.body : element.ownerDocument.documentElement, null);
  1606. renderer.rectangle(0, 0, renderer.width, renderer.height, canvasBackground.color('backgroundColor'));
  1607. }
  1608. parent.visibile = parent.isElementVisible();
  1609. this.createPseudoHideStyles(element.ownerDocument);
  1610. this.disableAnimations(element.ownerDocument);
  1611. this.nodes = flatten([parent].concat(this.getChildren(parent)).filter(function(container) {
  1612. return container.visible = container.isElementVisible();
  1613. }).map(this.getPseudoElements, this));
  1614. this.fontMetrics = new FontMetrics();
  1615. log("Fetched nodes, total:", this.nodes.length);
  1616. log("Calculate overflow clips");
  1617. this.calculateOverflowClips();
  1618. log("Start fetching images");
  1619. this.images = imageLoader.fetch(this.nodes.filter(isElement));
  1620. this.ready = this.images.ready.then(bind(function() {
  1621. log("Images loaded, starting parsing");
  1622. log("Creating stacking contexts");
  1623. this.createStackingContexts();
  1624. log("Sorting stacking contexts");
  1625. this.sortStackingContexts(this.stack);
  1626. this.parse(this.stack);
  1627. log("Render queue created with " + this.renderQueue.length + " items");
  1628. return new Promise(bind(function(resolve) {
  1629. if (!options.async) {
  1630. this.renderQueue.forEach(this.paint, this);
  1631. resolve();
  1632. } else if (typeof(options.async) === "function") {
  1633. options.async.call(this, this.renderQueue, resolve);
  1634. } else if (this.renderQueue.length > 0){
  1635. this.renderIndex = 0;
  1636. this.asyncRenderer(this.renderQueue, resolve);
  1637. } else {
  1638. resolve();
  1639. }
  1640. }, this));
  1641. }, this));
  1642. }
  1643. NodeParser.prototype.calculateOverflowClips = function() {
  1644. this.nodes.forEach(function(container) {
  1645. if (isElement(container)) {
  1646. if (isPseudoElement(container)) {
  1647. container.appendToDOM();
  1648. }
  1649. container.borders = this.parseBorders(container);
  1650. var clip = (container.css('overflow') === "hidden") ? [container.borders.clip] : [];
  1651. var cssClip = container.parseClip();
  1652. if (cssClip && ["absolute", "fixed"].indexOf(container.css('position')) !== -1) {
  1653. clip.push([["rect",
  1654. container.bounds.left + cssClip.left,
  1655. container.bounds.top + cssClip.top,
  1656. cssClip.right - cssClip.left,
  1657. cssClip.bottom - cssClip.top
  1658. ]]);
  1659. }
  1660. container.clip = hasParentClip(container) ? container.parent.clip.concat(clip) : clip;
  1661. container.backgroundClip = (container.css('overflow') !== "hidden") ? container.clip.concat([container.borders.clip]) : container.clip;
  1662. if (isPseudoElement(container)) {
  1663. container.cleanDOM();
  1664. }
  1665. } else if (isTextNode(container)) {
  1666. container.clip = hasParentClip(container) ? container.parent.clip : [];
  1667. }
  1668. if (!isPseudoElement(container)) {
  1669. container.bounds = null;
  1670. }
  1671. }, this);
  1672. };
  1673. function hasParentClip(container) {
  1674. return container.parent && container.parent.clip.length;
  1675. }
  1676. NodeParser.prototype.asyncRenderer = function(queue, resolve, asyncTimer) {
  1677. asyncTimer = asyncTimer || Date.now();
  1678. this.paint(queue[this.renderIndex++]);
  1679. if (queue.length === this.renderIndex) {
  1680. resolve();
  1681. } else if (asyncTimer + 20 > Date.now()) {
  1682. this.asyncRenderer(queue, resolve, asyncTimer);
  1683. } else {
  1684. setTimeout(bind(function() {
  1685. this.asyncRenderer(queue, resolve);
  1686. }, this), 0);
  1687. }
  1688. };
  1689. NodeParser.prototype.createPseudoHideStyles = function(document) {
  1690. this.createStyles(document, '.' + PseudoElementContainer.prototype.PSEUDO_HIDE_ELEMENT_CLASS_BEFORE + ':before { content: "" !important; display: none !important; }' +
  1691. '.' + PseudoElementContainer.prototype.PSEUDO_HIDE_ELEMENT_CLASS_AFTER + ':after { content: "" !important; display: none !important; }');
  1692. };
  1693. NodeParser.prototype.disableAnimations = function(document) {
  1694. this.createStyles(document, '* { -webkit-animation: none !important; -moz-animation: none !important; -o-animation: none !important; animation: none !important; ' +
  1695. '-webkit-transition: none !important; -moz-transition: none !important; -o-transition: none !important; transition: none !important;}');
  1696. };
  1697. NodeParser.prototype.createStyles = function(document, styles) {
  1698. var hidePseudoElements = document.createElement('style');
  1699. hidePseudoElements.innerHTML = styles;
  1700. document.body.appendChild(hidePseudoElements);
  1701. };
  1702. NodeParser.prototype.getPseudoElements = function(container) {
  1703. var nodes = [[container]];
  1704. if (container.node.nodeType === Node.ELEMENT_NODE) {
  1705. var before = this.getPseudoElement(container, ":before");
  1706. var after = this.getPseudoElement(container, ":after");
  1707. if (before) {
  1708. nodes.push(before);
  1709. }
  1710. if (after) {
  1711. nodes.push(after);
  1712. }
  1713. }
  1714. return flatten(nodes);
  1715. };
  1716. function toCamelCase(str) {
  1717. return str.replace(/(\-[a-z])/g, function(match){
  1718. return match.toUpperCase().replace('-','');
  1719. });
  1720. }
  1721. NodeParser.prototype.getPseudoElement = function(container, type) {
  1722. var style = container.computedStyle(type);
  1723. if(!style || !style.content || style.content === "none" || style.content === "-moz-alt-content" || style.display === "none") {
  1724. return null;
  1725. }
  1726. var content = stripQuotes(style.content);
  1727. var isImage = content.substr(0, 3) === 'url';
  1728. var pseudoNode = document.createElement(isImage ? 'img' : 'html2canvaspseudoelement');
  1729. var pseudoContainer = new PseudoElementContainer(pseudoNode, container, type);
  1730. for (var i = style.length-1; i >= 0; i--) {
  1731. var property = toCamelCase(style.item(i));
  1732. pseudoNode.style[property] = style[property];
  1733. }
  1734. pseudoNode.className = PseudoElementContainer.prototype.PSEUDO_HIDE_ELEMENT_CLASS_BEFORE + " " + PseudoElementContainer.prototype.PSEUDO_HIDE_ELEMENT_CLASS_AFTER;
  1735. if (isImage) {
  1736. pseudoNode.src = parseBackgrounds(content)[0].args[0];
  1737. return [pseudoContainer];
  1738. } else {
  1739. var text = document.createTextNode(content);
  1740. pseudoNode.appendChild(text);
  1741. return [pseudoContainer, new TextContainer(text, pseudoContainer)];
  1742. }
  1743. };
  1744. NodeParser.prototype.getChildren = function(parentContainer) {
  1745. return flatten([].filter.call(parentContainer.node.childNodes, renderableNode).map(function(node) {
  1746. var container = [node.nodeType === Node.TEXT_NODE ? new TextContainer(node, parentContainer) : new NodeContainer(node, parentContainer)].filter(nonIgnoredElement);
  1747. return node.nodeType === Node.ELEMENT_NODE && container.length && node.tagName !== "TEXTAREA" ? (container[0].isElementVisible() ? container.concat(this.getChildren(container[0])) : []) : container;
  1748. }, this));
  1749. };
  1750. NodeParser.prototype.newStackingContext = function(container, hasOwnStacking) {
  1751. var stack = new StackingContext(hasOwnStacking, container.getOpacity(), container.node, container.parent);
  1752. container.cloneTo(stack);
  1753. var parentStack = hasOwnStacking ? stack.getParentStack(this) : stack.parent.stack;
  1754. parentStack.contexts.push(stack);
  1755. container.stack = stack;
  1756. };
  1757. NodeParser.prototype.createStackingContexts = function() {
  1758. this.nodes.forEach(function(container) {
  1759. if (isElement(container) && (this.isRootElement(container) || hasOpacity(container) || isPositionedForStacking(container) || this.isBodyWithTransparentRoot(container) || container.hasTransform())) {
  1760. this.newStackingContext(container, true);
  1761. } else if (isElement(container) && ((isPositioned(container) && zIndex0(container)) || isInlineBlock(container) || isFloating(container))) {
  1762. this.newStackingContext(container, false);
  1763. } else {
  1764. container.assignStack(container.parent.stack);
  1765. }
  1766. }, this);
  1767. };
  1768. NodeParser.prototype.isBodyWithTransparentRoot = function(container) {
  1769. return container.node.nodeName === "BODY" && container.parent.color('backgroundColor').isTransparent();
  1770. };
  1771. NodeParser.prototype.isRootElement = function(container) {
  1772. return container.parent === null;
  1773. };
  1774. NodeParser.prototype.sortStackingContexts = function(stack) {
  1775. stack.contexts.sort(zIndexSort(stack.contexts.slice(0)));
  1776. stack.contexts.forEach(this.sortStackingContexts, this);
  1777. };
  1778. NodeParser.prototype.parseTextBounds = function(container) {
  1779. return function(text, index, textList) {
  1780. if (container.parent.css("textDecoration").substr(0, 4) !== "none" || text.trim().length !== 0) {
  1781. if (this.support.rangeBounds && !container.parent.hasTransform()) {
  1782. var offset = textList.slice(0, index).join("").length;
  1783. return this.getRangeBounds(container.node, offset, text.length);
  1784. } else if (container.node && typeof(container.node.data) === "string") {
  1785. var replacementNode = container.node.splitText(text.length);
  1786. var bounds = this.getWrapperBounds(container.node, container.parent.hasTransform());
  1787. container.node = replacementNode;
  1788. return bounds;
  1789. }
  1790. } else if(!this.support.rangeBounds || container.parent.hasTransform()){
  1791. container.node = container.node.splitText(text.length);
  1792. }
  1793. return {};
  1794. };
  1795. };
  1796. NodeParser.prototype.getWrapperBounds = function(node, transform) {
  1797. var wrapper = node.ownerDocument.createElement('html2canvaswrapper');
  1798. var parent = node.parentNode,
  1799. backupText = node.cloneNode(true);
  1800. wrapper.appendChild(node.cloneNode(true));
  1801. parent.replaceChild(wrapper, node);
  1802. var bounds = transform ? offsetBounds(wrapper) : getBounds(wrapper);
  1803. parent.replaceChild(backupText, wrapper);
  1804. return bounds;
  1805. };
  1806. NodeParser.prototype.getRangeBounds = function(node, offset, length) {
  1807. var range = this.range || (this.range = node.ownerDocument.createRange());
  1808. range.setStart(node, offset);
  1809. range.setEnd(node, offset + length);
  1810. return range.getBoundingClientRect();
  1811. };
  1812. function ClearTransform() {}
  1813. NodeParser.prototype.parse = function(stack) {
  1814. // http://www.w3.org/TR/CSS21/visuren.html#z-index
  1815. var negativeZindex = stack.contexts.filter(negativeZIndex); // 2. the child stacking contexts with negative stack levels (most negative first).
  1816. var descendantElements = stack.children.filter(isElement);
  1817. var descendantNonFloats = descendantElements.filter(not(isFloating));
  1818. var nonInlineNonPositionedDescendants = descendantNonFloats.filter(not(isPositioned)).filter(not(inlineLevel)); // 3 the in-flow, non-inline-level, non-positioned descendants.
  1819. var nonPositionedFloats = descendantElements.filter(not(isPositioned)).filter(isFloating); // 4. the non-positioned floats.
  1820. var inFlow = descendantNonFloats.filter(not(isPositioned)).filter(inlineLevel); // 5. the in-flow, inline-level, non-positioned descendants, including inline tables and inline blocks.
  1821. 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.
  1822. var text = stack.children.filter(isTextNode).filter(hasText);
  1823. var positiveZindex = stack.contexts.filter(positiveZIndex); // 7. the child stacking contexts with positive stack levels (least positive first).
  1824. negativeZindex.concat(nonInlineNonPositionedDescendants).concat(nonPositionedFloats)
  1825. .concat(inFlow).concat(stackLevel0).concat(text).concat(positiveZindex).forEach(function(container) {
  1826. this.renderQueue.push(container);
  1827. if (isStackingContext(container)) {
  1828. this.parse(container);
  1829. this.renderQueue.push(new ClearTransform());
  1830. }
  1831. }, this);
  1832. };
  1833. NodeParser.prototype.paint = function(container) {
  1834. try {
  1835. if (container instanceof ClearTransform) {
  1836. this.renderer.ctx.restore();
  1837. } else if (isTextNode(container)) {
  1838. if (isPseudoElement(container.parent)) {
  1839. container.parent.appendToDOM();
  1840. }
  1841. this.paintText(container);
  1842. if (isPseudoElement(container.parent)) {
  1843. container.parent.cleanDOM();
  1844. }
  1845. } else {
  1846. this.paintNode(container);
  1847. }
  1848. } catch(e) {
  1849. log(e);
  1850. if (this.options.strict) {
  1851. throw e;
  1852. }
  1853. }
  1854. };
  1855. NodeParser.prototype.paintNode = function(container) {
  1856. if (isStackingContext(container)) {
  1857. this.renderer.setOpacity(container.opacity);
  1858. this.renderer.ctx.save();
  1859. if (container.hasTransform()) {
  1860. this.renderer.setTransform(container.parseTransform());
  1861. }
  1862. }
  1863. if (container.node.nodeName === "INPUT" && container.node.type === "checkbox") {
  1864. this.paintCheckbox(container);
  1865. } else if (container.node.nodeName === "INPUT" && container.node.type === "radio") {
  1866. this.paintRadio(container);
  1867. } else {
  1868. this.paintElement(container);
  1869. }
  1870. };
  1871. NodeParser.prototype.paintElement = function(container) {
  1872. var bounds = container.parseBounds();
  1873. this.renderer.clip(container.backgroundClip, function() {
  1874. this.renderer.renderBackground(container, bounds, container.borders.borders.map(getWidth));
  1875. }, this);
  1876. this.renderer.clip(container.clip, function() {
  1877. this.renderer.renderBorders(container.borders.borders);
  1878. }, this);
  1879. this.renderer.clip(container.backgroundClip, function() {
  1880. switch (container.node.nodeName) {
  1881. case "svg":
  1882. case "IFRAME":
  1883. var imgContainer = this.images.get(container.node);
  1884. if (imgContainer) {
  1885. this.renderer.renderImage(container, bounds, container.borders, imgContainer);
  1886. } else {
  1887. log("Error loading <" + container.node.nodeName + ">", container.node);
  1888. }
  1889. break;
  1890. case "IMG":
  1891. var imageContainer = this.images.get(container.node.src);
  1892. if (imageContainer) {
  1893. this.renderer.renderImage(container, bounds, container.borders, imageContainer);
  1894. } else {
  1895. log("Error loading <img>", container.node.src);
  1896. }
  1897. break;
  1898. case "CANVAS":
  1899. this.renderer.renderImage(container, bounds, container.borders, {image: container.node});
  1900. break;
  1901. case "SELECT":
  1902. case "INPUT":
  1903. case "TEXTAREA":
  1904. this.paintFormValue(container);
  1905. break;
  1906. }
  1907. }, this);
  1908. };
  1909. NodeParser.prototype.paintCheckbox = function(container) {
  1910. var b = container.parseBounds();
  1911. var size = Math.min(b.width, b.height);
  1912. var bounds = {width: size - 1, height: size - 1, top: b.top, left: b.left};
  1913. var r = [3, 3];
  1914. var radius = [r, r, r, r];
  1915. var borders = [1,1,1,1].map(function(w) {
  1916. return {color: new Color('#A5A5A5'), width: w};
  1917. });
  1918. var borderPoints = calculateCurvePoints(bounds, radius, borders);
  1919. this.renderer.clip(container.backgroundClip, function() {
  1920. this.renderer.rectangle(bounds.left + 1, bounds.top + 1, bounds.width - 2, bounds.height - 2, new Color("#DEDEDE"));
  1921. this.renderer.renderBorders(calculateBorders(borders, bounds, borderPoints, radius));
  1922. if (container.node.checked) {
  1923. this.renderer.font(new Color('#424242'), 'normal', 'normal', 'bold', (size - 3) + "px", 'arial');
  1924. this.renderer.text("\u2714", bounds.left + size / 6, bounds.top + size - 1);
  1925. }
  1926. }, this);
  1927. };
  1928. NodeParser.prototype.paintRadio = function(container) {
  1929. var bounds = container.parseBounds();
  1930. var size = Math.min(bounds.width, bounds.height) - 2;
  1931. this.renderer.clip(container.backgroundClip, function() {
  1932. this.renderer.circleStroke(bounds.left + 1, bounds.top + 1, size, new Color('#DEDEDE'), 1, new Color('#A5A5A5'));
  1933. if (container.node.checked) {
  1934. this.renderer.circle(Math.ceil(bounds.left + size / 4) + 1, Math.ceil(bounds.top + size / 4) + 1, Math.floor(size / 2), new Color('#424242'));
  1935. }
  1936. }, this);
  1937. };
  1938. NodeParser.prototype.paintFormValue = function(container) {
  1939. var value = container.getValue();
  1940. if (value.length > 0) {
  1941. var document = container.node.ownerDocument;
  1942. var wrapper = document.createElement('html2canvaswrapper');
  1943. var properties = ['lineHeight', 'textAlign', 'fontFamily', 'fontWeight', 'fontSize', 'color',
  1944. 'paddingLeft', 'paddingTop', 'paddingRight', 'paddingBottom',
  1945. 'width', 'height', 'borderLeftStyle', 'borderTopStyle', 'borderLeftWidth', 'borderTopWidth',
  1946. 'boxSizing', 'whiteSpace', 'wordWrap'];
  1947. properties.forEach(function(property) {
  1948. try {
  1949. wrapper.style[property] = container.css(property);
  1950. } catch(e) {
  1951. // Older IE has issues with "border"
  1952. log("html2canvas: Parse: Exception caught in renderFormValue: " + e.message);
  1953. }
  1954. });
  1955. var bounds = container.parseBounds();
  1956. wrapper.style.position = "fixed";
  1957. wrapper.style.left = bounds.left + "px";
  1958. wrapper.style.top = bounds.top + "px";
  1959. wrapper.textContent = value;
  1960. document.body.appendChild(wrapper);
  1961. this.paintText(new TextContainer(wrapper.firstChild, container));
  1962. document.body.removeChild(wrapper);
  1963. }
  1964. };
  1965. NodeParser.prototype.paintText = function(container) {
  1966. container.applyTextTransform();
  1967. var characters = punycode.ucs2.decode(container.node.data);
  1968. var textList = (!this.options.letterRendering || noLetterSpacing(container)) && !hasUnicode(container.node.data) ? getWords(characters) : characters.map(function(character) {
  1969. return punycode.ucs2.encode([character]);
  1970. });
  1971. var weight = container.parent.fontWeight();
  1972. var size = container.parent.css('fontSize');
  1973. var family = container.parent.css('fontFamily');
  1974. var shadows = container.parent.parseTextShadows();
  1975. this.renderer.font(container.parent.color('color'), container.parent.css('fontStyle'), container.parent.css('fontVariant'), weight, size, family);
  1976. if (shadows.length) {
  1977. // TODO: support multiple text shadows
  1978. this.renderer.fontShadow(shadows[0].color, shadows[0].offsetX, shadows[0].offsetY, shadows[0].blur);
  1979. } else {
  1980. this.renderer.clearShadow();
  1981. }
  1982. this.renderer.clip(container.parent.clip, function() {
  1983. textList.map(this.parseTextBounds(container), this).forEach(function(bounds, index) {
  1984. if (bounds) {
  1985. this.renderer.text(textList[index], bounds.left, bounds.bottom);
  1986. this.renderTextDecoration(container.parent, bounds, this.fontMetrics.getMetrics(family, size));
  1987. }
  1988. }, this);
  1989. }, this);
  1990. };
  1991. NodeParser.prototype.renderTextDecoration = function(container, bounds, metrics) {
  1992. switch(container.css("textDecoration").split(" ")[0]) {
  1993. case "underline":
  1994. // Draws a line at the baseline of the font
  1995. // 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
  1996. this.renderer.rectangle(bounds.left, Math.round(bounds.top + metrics.baseline + metrics.lineWidth), bounds.width, 1, container.color("color"));
  1997. break;
  1998. case "overline":
  1999. this.renderer.rectangle(bounds.left, Math.round(bounds.top), bounds.width, 1, container.color("color"));
  2000. break;
  2001. case "line-through":
  2002. // TODO try and find exact position for line-through
  2003. this.renderer.rectangle(bounds.left, Math.ceil(bounds.top + metrics.middle + metrics.lineWidth), bounds.width, 1, container.color("color"));
  2004. break;
  2005. }
  2006. };
  2007. var borderColorTransforms = {
  2008. inset: [
  2009. ["darken", 0.60],
  2010. ["darken", 0.10],
  2011. ["darken", 0.10],
  2012. ["darken", 0.60]
  2013. ]
  2014. };
  2015. NodeParser.prototype.parseBorders = function(container) {
  2016. var nodeBounds = container.parseBounds();
  2017. var radius = getBorderRadiusData(container);
  2018. var borders = ["Top", "Right", "Bottom", "Left"].map(function(side, index) {
  2019. var style = container.css('border' + side + 'Style');
  2020. var color = container.color('border' + side + 'Color');
  2021. if (style === "inset" && color.isBlack()) {
  2022. color = new Color([255, 255, 255, color.a]); // this is wrong, but
  2023. }
  2024. var colorTransform = borderColorTransforms[style] ? borderColorTransforms[style][index] : null;
  2025. return {
  2026. width: container.cssInt('border' + side + 'Width'),
  2027. color: colorTransform ? color[colorTransform[0]](colorTransform[1]) : color,
  2028. args: null
  2029. };
  2030. });
  2031. var borderPoints = calculateCurvePoints(nodeBounds, radius, borders);
  2032. return {
  2033. clip: this.parseBackgroundClip(container, borderPoints, borders, radius, nodeBounds),
  2034. borders: calculateBorders(borders, nodeBounds, borderPoints, radius)
  2035. };
  2036. };
  2037. function calculateBorders(borders, nodeBounds, borderPoints, radius) {
  2038. return borders.map(function(border, borderSide) {
  2039. if (border.width > 0) {
  2040. var bx = nodeBounds.left;
  2041. var by = nodeBounds.top;
  2042. var bw = nodeBounds.width;
  2043. var bh = nodeBounds.height - (borders[2].width);
  2044. switch(borderSide) {
  2045. case 0:
  2046. // top border
  2047. bh = borders[0].width;
  2048. border.args = drawSide({
  2049. c1: [bx, by],
  2050. c2: [bx + bw, by],
  2051. c3: [bx + bw - borders[1].width, by + bh],
  2052. c4: [bx + borders[3].width, by + bh]
  2053. }, radius[0], radius[1],
  2054. borderPoints.topLeftOuter, borderPoints.topLeftInner, borderPoints.topRightOuter, borderPoints.topRightInner);
  2055. break;
  2056. case 1:
  2057. // right border
  2058. bx = nodeBounds.left + nodeBounds.width - (borders[1].width);
  2059. bw = borders[1].width;
  2060. border.args = drawSide({
  2061. c1: [bx + bw, by],
  2062. c2: [bx + bw, by + bh + borders[2].width],
  2063. c3: [bx, by + bh],
  2064. c4: [bx, by + borders[0].width]
  2065. }, radius[1], radius[2],
  2066. borderPoints.topRightOuter, borderPoints.topRightInner, borderPoints.bottomRightOuter, borderPoints.bottomRightInner);
  2067. break;
  2068. case 2:
  2069. // bottom border
  2070. by = (by + nodeBounds.height) - (borders[2].width);
  2071. bh = borders[2].width;
  2072. border.args = drawSide({
  2073. c1: [bx + bw, by + bh],
  2074. c2: [bx, by + bh],
  2075. c3: [bx + borders[3].width, by],
  2076. c4: [bx + bw - borders[3].width, by]
  2077. }, radius[2], radius[3],
  2078. borderPoints.bottomRightOuter, borderPoints.bottomRightInner, borderPoints.bottomLeftOuter, borderPoints.bottomLeftInner);
  2079. break;
  2080. case 3:
  2081. // left border
  2082. bw = borders[3].width;
  2083. border.args = drawSide({
  2084. c1: [bx, by + bh + borders[2].width],
  2085. c2: [bx, by],
  2086. c3: [bx + bw, by + borders[0].width],
  2087. c4: [bx + bw, by + bh]
  2088. }, radius[3], radius[0],
  2089. borderPoints.bottomLeftOuter, borderPoints.bottomLeftInner, borderPoints.topLeftOuter, borderPoints.topLeftInner);
  2090. break;
  2091. }
  2092. }
  2093. return border;
  2094. });
  2095. }
  2096. NodeParser.prototype.parseBackgroundClip = function(container, borderPoints, borders, radius, bounds) {
  2097. var backgroundClip = container.css('backgroundClip'),
  2098. borderArgs = [];
  2099. switch(backgroundClip) {
  2100. case "content-box":
  2101. case "padding-box":
  2102. parseCorner(borderArgs, radius[0], radius[1], borderPoints.topLeftInner, borderPoints.topRightInner, bounds.left + borders[3].width, bounds.top + borders[0].width);
  2103. parseCorner(borderArgs, radius[1], radius[2], borderPoints.topRightInner, borderPoints.bottomRightInner, bounds.left + bounds.width - borders[1].width, bounds.top + borders[0].width);
  2104. parseCorner(borderArgs, radius[2], radius[3], borderPoints.bottomRightInner, borderPoints.bottomLeftInner, bounds.left + bounds.width - borders[1].width, bounds.top + bounds.height - borders[2].width);
  2105. parseCorner(borderArgs, radius[3], radius[0], borderPoints.bottomLeftInner, borderPoints.topLeftInner, bounds.left + borders[3].width, bounds.top + bounds.height - borders[2].width);
  2106. break;
  2107. default:
  2108. parseCorner(borderArgs, radius[0], radius[1], borderPoints.topLeftOuter, borderPoints.topRightOuter, bounds.left, bounds.top);
  2109. parseCorner(borderArgs, radius[1], radius[2], borderPoints.topRightOuter, borderPoints.bottomRightOuter, bounds.left + bounds.width, bounds.top);
  2110. parseCorner(borderArgs, radius[2], radius[3], borderPoints.bottomRightOuter, borderPoints.bottomLeftOuter, bounds.left + bounds.width, bounds.top + bounds.height);
  2111. parseCorner(borderArgs, radius[3], radius[0], borderPoints.bottomLeftOuter, borderPoints.topLeftOuter, bounds.left, bounds.top + bounds.height);
  2112. break;
  2113. }
  2114. return borderArgs;
  2115. };
  2116. function getCurvePoints(x, y, r1, r2) {
  2117. var kappa = 4 * ((Math.sqrt(2) - 1) / 3);
  2118. var ox = (r1) * kappa, // control point offset horizontal
  2119. oy = (r2) * kappa, // control point offset vertical
  2120. xm = x + r1, // x-middle
  2121. ym = y + r2; // y-middle
  2122. return {
  2123. topLeft: bezierCurve({x: x, y: ym}, {x: x, y: ym - oy}, {x: xm - ox, y: y}, {x: xm, y: y}),
  2124. topRight: bezierCurve({x: x, y: y}, {x: x + ox,y: y}, {x: xm, y: ym - oy}, {x: xm, y: ym}),
  2125. bottomRight: bezierCurve({x: xm, y: y}, {x: xm, y: y + oy}, {x: x + ox, y: ym}, {x: x, y: ym}),
  2126. bottomLeft: bezierCurve({x: xm, y: ym}, {x: xm - ox, y: ym}, {x: x, y: y + oy}, {x: x, y:y})
  2127. };
  2128. }
  2129. function calculateCurvePoints(bounds, borderRadius, borders) {
  2130. var x = bounds.left,
  2131. y = bounds.top,
  2132. width = bounds.width,
  2133. height = bounds.height,
  2134. tlh = borderRadius[0][0] < width / 2 ? borderRadius[0][0] : width / 2,
  2135. tlv = borderRadius[0][1] < height / 2 ? borderRadius[0][1] : height / 2,
  2136. trh = borderRadius[1][0] < width / 2 ? borderRadius[1][0] : width / 2,
  2137. trv = borderRadius[1][1] < height / 2 ? borderRadius[1][1] : height / 2,
  2138. brh = borderRadius[2][0] < width / 2 ? borderRadius[2][0] : width / 2,
  2139. brv = borderRadius[2][1] < height / 2 ? borderRadius[2][1] : height / 2,
  2140. blh = borderRadius[3][0] < width / 2 ? borderRadius[3][0] : width / 2,
  2141. blv = borderRadius[3][1] < height / 2 ? borderRadius[3][1] : height / 2;
  2142. var topWidth = width - trh,
  2143. rightHeight = height - brv,
  2144. bottomWidth = width - brh,
  2145. leftHeight = height - blv;
  2146. return {
  2147. topLeftOuter: getCurvePoints(x, y, tlh, tlv).topLeft.subdivide(0.5),
  2148. 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),
  2149. topRightOuter: getCurvePoints(x + topWidth, y, trh, trv).topRight.subdivide(0.5),
  2150. 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),
  2151. bottomRightOuter: getCurvePoints(x + bottomWidth, y + rightHeight, brh, brv).bottomRight.subdivide(0.5),
  2152. 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),
  2153. bottomLeftOuter: getCurvePoints(x, y + leftHeight, blh, blv).bottomLeft.subdivide(0.5),
  2154. bottomLeftInner: getCurvePoints(x + borders[3].width, y + leftHeight, Math.max(0, blh - borders[3].width), blv - borders[2].width).bottomLeft.subdivide(0.5)
  2155. };
  2156. }
  2157. function bezierCurve(start, startControl, endControl, end) {
  2158. var lerp = function (a, b, t) {
  2159. return {
  2160. x: a.x + (b.x - a.x) * t,
  2161. y: a.y + (b.y - a.y) * t
  2162. };
  2163. };
  2164. return {
  2165. start: start,
  2166. startControl: startControl,
  2167. endControl: endControl,
  2168. end: end,
  2169. subdivide: function(t) {
  2170. var ab = lerp(start, startControl, t),
  2171. bc = lerp(startControl, endControl, t),
  2172. cd = lerp(endControl, end, t),
  2173. abbc = lerp(ab, bc, t),
  2174. bccd = lerp(bc, cd, t),
  2175. dest = lerp(abbc, bccd, t);
  2176. return [bezierCurve(start, ab, abbc, dest), bezierCurve(dest, bccd, cd, end)];
  2177. },
  2178. curveTo: function(borderArgs) {
  2179. borderArgs.push(["bezierCurve", startControl.x, startControl.y, endControl.x, endControl.y, end.x, end.y]);
  2180. },
  2181. curveToReversed: function(borderArgs) {
  2182. borderArgs.push(["bezierCurve", endControl.x, endControl.y, startControl.x, startControl.y, start.x, start.y]);
  2183. }
  2184. };
  2185. }
  2186. function drawSide(borderData, radius1, radius2, outer1, inner1, outer2, inner2) {
  2187. var borderArgs = [];
  2188. if (radius1[0] > 0 || radius1[1] > 0) {
  2189. borderArgs.push(["line", outer1[1].start.x, outer1[1].start.y]);
  2190. outer1[1].curveTo(borderArgs);
  2191. } else {
  2192. borderArgs.push([ "line", borderData.c1[0], borderData.c1[1]]);
  2193. }
  2194. if (radius2[0] > 0 || radius2[1] > 0) {
  2195. borderArgs.push(["line", outer2[0].start.x, outer2[0].start.y]);
  2196. outer2[0].curveTo(borderArgs);
  2197. borderArgs.push(["line", inner2[0].end.x, inner2[0].end.y]);
  2198. inner2[0].curveToReversed(borderArgs);
  2199. } else {
  2200. borderArgs.push(["line", borderData.c2[0], borderData.c2[1]]);
  2201. borderArgs.push(["line", borderData.c3[0], borderData.c3[1]]);
  2202. }
  2203. if (radius1[0] > 0 || radius1[1] > 0) {
  2204. borderArgs.push(["line", inner1[1].end.x, inner1[1].end.y]);
  2205. inner1[1].curveToReversed(borderArgs);
  2206. } else {
  2207. borderArgs.push(["line", borderData.c4[0], borderData.c4[1]]);
  2208. }
  2209. return borderArgs;
  2210. }
  2211. function parseCorner(borderArgs, radius1, radius2, corner1, corner2, x, y) {
  2212. if (radius1[0] > 0 || radius1[1] > 0) {
  2213. borderArgs.push(["line", corner1[0].start.x, corner1[0].start.y]);
  2214. corner1[0].curveTo(borderArgs);
  2215. corner1[1].curveTo(borderArgs);
  2216. } else {
  2217. borderArgs.push(["line", x, y]);
  2218. }
  2219. if (radius2[0] > 0 || radius2[1] > 0) {
  2220. borderArgs.push(["line", corner2[0].start.x, corner2[0].start.y]);
  2221. }
  2222. }
  2223. function negativeZIndex(container) {
  2224. return container.cssInt("zIndex") < 0;
  2225. }
  2226. function positiveZIndex(container) {
  2227. return container.cssInt("zIndex") > 0;
  2228. }
  2229. function zIndex0(container) {
  2230. return container.cssInt("zIndex") === 0;
  2231. }
  2232. function inlineLevel(container) {
  2233. return ["inline", "inline-block", "inline-table"].indexOf(container.css("display")) !== -1;
  2234. }
  2235. function isStackingContext(container) {
  2236. return (container instanceof StackingContext);
  2237. }
  2238. function hasText(container) {
  2239. return container.node.data.trim().length > 0;
  2240. }
  2241. function noLetterSpacing(container) {
  2242. return (/^(normal|none|0px)$/.test(container.parent.css("letterSpacing")));
  2243. }
  2244. function getBorderRadiusData(container) {
  2245. return ["TopLeft", "TopRight", "BottomRight", "BottomLeft"].map(function(side) {
  2246. var value = container.css('border' + side + 'Radius');
  2247. var arr = value.split(" ");
  2248. if (arr.length <= 1) {
  2249. arr[1] = arr[0];
  2250. }
  2251. return arr.map(asInt);
  2252. });
  2253. }
  2254. function renderableNode(node) {
  2255. return (node.nodeType === Node.TEXT_NODE || node.nodeType === Node.ELEMENT_NODE);
  2256. }
  2257. function isPositionedForStacking(container) {
  2258. var position = container.css("position");
  2259. var zIndex = (["absolute", "relative", "fixed"].indexOf(position) !== -1) ? container.css("zIndex") : "auto";
  2260. return zIndex !== "auto";
  2261. }
  2262. function isPositioned(container) {
  2263. return container.css("position") !== "static";
  2264. }
  2265. function isFloating(container) {
  2266. return container.css("float") !== "none";
  2267. }
  2268. function isInlineBlock(container) {
  2269. return ["inline-block", "inline-table"].indexOf(container.css("display")) !== -1;
  2270. }
  2271. function not(callback) {
  2272. var context = this;
  2273. return function() {
  2274. return !callback.apply(context, arguments);
  2275. };
  2276. }
  2277. function isElement(container) {
  2278. return container.node.nodeType === Node.ELEMENT_NODE;
  2279. }
  2280. function isPseudoElement(container) {
  2281. return container.isPseudoElement === true;
  2282. }
  2283. function isTextNode(container) {
  2284. return container.node.nodeType === Node.TEXT_NODE;
  2285. }
  2286. function zIndexSort(contexts) {
  2287. return function(a, b) {
  2288. return (a.cssInt("zIndex") + (contexts.indexOf(a) / contexts.length)) - (b.cssInt("zIndex") + (contexts.indexOf(b) / contexts.length));
  2289. };
  2290. }
  2291. function hasOpacity(container) {
  2292. return container.getOpacity() < 1;
  2293. }
  2294. function asInt(value) {
  2295. return parseInt(value, 10);
  2296. }
  2297. function getWidth(border) {
  2298. return border.width;
  2299. }
  2300. function nonIgnoredElement(nodeContainer) {
  2301. return (nodeContainer.node.nodeType !== Node.ELEMENT_NODE || ["SCRIPT", "HEAD", "TITLE", "OBJECT", "BR", "OPTION"].indexOf(nodeContainer.node.nodeName) === -1);
  2302. }
  2303. function flatten(arrays) {
  2304. return [].concat.apply([], arrays);
  2305. }
  2306. function stripQuotes(content) {
  2307. var first = content.substr(0, 1);
  2308. return (first === content.substr(content.length - 1) && first.match(/'|"/)) ? content.substr(1, content.length - 2) : content;
  2309. }
  2310. function getWords(characters) {
  2311. var words = [], i = 0, onWordBoundary = false, word;
  2312. while(characters.length) {
  2313. if (isWordBoundary(characters[i]) === onWordBoundary) {
  2314. word = characters.splice(0, i);
  2315. if (word.length) {
  2316. words.push(punycode.ucs2.encode(word));
  2317. }
  2318. onWordBoundary =! onWordBoundary;
  2319. i = 0;
  2320. } else {
  2321. i++;
  2322. }
  2323. if (i >= characters.length) {
  2324. word = characters.splice(0, i);
  2325. if (word.length) {
  2326. words.push(punycode.ucs2.encode(word));
  2327. }
  2328. }
  2329. }
  2330. return words;
  2331. }
  2332. function isWordBoundary(characterCode) {
  2333. return [
  2334. 32, // <space>
  2335. 13, // \r
  2336. 10, // \n
  2337. 9, // \t
  2338. 45 // -
  2339. ].indexOf(characterCode) !== -1;
  2340. }
  2341. function hasUnicode(string) {
  2342. return (/[^\u0000-\u00ff]/).test(string);
  2343. }
  2344. module.exports = NodeParser;
  2345. },{"./color":3,"./fontmetrics":7,"./log":13,"./nodecontainer":14,"./pseudoelementcontainer":18,"./stackingcontext":21,"./textcontainer":25,"./utils":26,"punycode":1}],16:[function(_dereq_,module,exports){
  2346. var XHR = _dereq_('./xhr');
  2347. var utils = _dereq_('./utils');
  2348. var log = _dereq_('./log');
  2349. var createWindowClone = _dereq_('./clone');
  2350. var decode64 = utils.decode64;
  2351. function Proxy(src, proxyUrl, document) {
  2352. var supportsCORS = ('withCredentials' in new XMLHttpRequest());
  2353. if (!proxyUrl) {
  2354. return Promise.reject("No proxy configured");
  2355. }
  2356. var callback = createCallback(supportsCORS);
  2357. var url = createProxyUrl(proxyUrl, src, callback);
  2358. return supportsCORS ? XHR(url) : (jsonp(document, url, callback).then(function(response) {
  2359. return decode64(response.content);
  2360. }));
  2361. }
  2362. var proxyCount = 0;
  2363. function ProxyURL(src, proxyUrl, document) {
  2364. var supportsCORSImage = ('crossOrigin' in new Image());
  2365. var callback = createCallback(supportsCORSImage);
  2366. var url = createProxyUrl(proxyUrl, src, callback);
  2367. return (supportsCORSImage ? Promise.resolve(url) : jsonp(document, url, callback).then(function(response) {
  2368. return "data:" + response.type + ";base64," + response.content;
  2369. }));
  2370. }
  2371. function jsonp(document, url, callback) {
  2372. return new Promise(function(resolve, reject) {
  2373. var s = document.createElement("script");
  2374. var cleanup = function() {
  2375. delete window.html2canvas.proxy[callback];
  2376. document.body.removeChild(s);
  2377. };
  2378. window.html2canvas.proxy[callback] = function(response) {
  2379. cleanup();
  2380. resolve(response);
  2381. };
  2382. s.src = url;
  2383. s.onerror = function(e) {
  2384. cleanup();
  2385. reject(e);
  2386. };
  2387. document.body.appendChild(s);
  2388. });
  2389. }
  2390. function createCallback(useCORS) {
  2391. return !useCORS ? "html2canvas_" + Date.now() + "_" + (++proxyCount) + "_" + Math.round(Math.random() * 100000) : "";
  2392. }
  2393. function createProxyUrl(proxyUrl, src, callback) {
  2394. return proxyUrl + "?url=" + encodeURIComponent(src) + (callback.length ? "&callback=html2canvas.proxy." + callback : "");
  2395. }
  2396. function documentFromHTML(src) {
  2397. return function(html) {
  2398. var parser = new DOMParser(), doc;
  2399. try {
  2400. doc = parser.parseFromString(html, "text/html");
  2401. } catch(e) {
  2402. log("DOMParser not supported, falling back to createHTMLDocument");
  2403. doc = document.implementation.createHTMLDocument("");
  2404. try {
  2405. doc.open();
  2406. doc.write(html);
  2407. doc.close();
  2408. } catch(ee) {
  2409. log("createHTMLDocument write not supported, falling back to document.body.innerHTML");
  2410. doc.body.innerHTML = html; // ie9 doesnt support writing to documentElement
  2411. }
  2412. }
  2413. var b = doc.querySelector("base");
  2414. if (!b || !b.href.host) {
  2415. var base = doc.createElement("base");
  2416. base.href = src;
  2417. doc.head.insertBefore(base, doc.head.firstChild);
  2418. }
  2419. return doc;
  2420. };
  2421. }
  2422. function loadUrlDocument(src, proxy, document, width, height, options) {
  2423. return new Proxy(src, proxy, window.document).then(documentFromHTML(src)).then(function(doc) {
  2424. return createWindowClone(doc, document, width, height, options, 0, 0);
  2425. });
  2426. }
  2427. exports.Proxy = Proxy;
  2428. exports.ProxyURL = ProxyURL;
  2429. exports.loadUrlDocument = loadUrlDocument;
  2430. },{"./clone":2,"./log":13,"./utils":26,"./xhr":28}],17:[function(_dereq_,module,exports){
  2431. var ProxyURL = _dereq_('./proxy').ProxyURL;
  2432. function ProxyImageContainer(src, proxy) {
  2433. var link = document.createElement("a");
  2434. link.href = src;
  2435. src = link.href;
  2436. this.src = src;
  2437. this.image = new Image();
  2438. var self = this;
  2439. this.promise = new Promise(function(resolve, reject) {
  2440. self.image.crossOrigin = "Anonymous";
  2441. self.image.onload = resolve;
  2442. self.image.onerror = reject;
  2443. new ProxyURL(src, proxy, document).then(function(url) {
  2444. self.image.src = url;
  2445. })['catch'](reject);
  2446. });
  2447. }
  2448. module.exports = ProxyImageContainer;
  2449. },{"./proxy":16}],18:[function(_dereq_,module,exports){
  2450. var NodeContainer = _dereq_('./nodecontainer');
  2451. function PseudoElementContainer(node, parent, type) {
  2452. NodeContainer.call(this, node, parent);
  2453. this.isPseudoElement = true;
  2454. this.before = type === ":before";
  2455. }
  2456. PseudoElementContainer.prototype.cloneTo = function(stack) {
  2457. PseudoElementContainer.prototype.cloneTo.call(this, stack);
  2458. stack.isPseudoElement = true;
  2459. stack.before = this.before;
  2460. };
  2461. PseudoElementContainer.prototype = Object.create(NodeContainer.prototype);
  2462. PseudoElementContainer.prototype.appendToDOM = function() {
  2463. if (this.before) {
  2464. this.parent.node.insertBefore(this.node, this.parent.node.firstChild);
  2465. } else {
  2466. this.parent.node.appendChild(this.node);
  2467. }
  2468. this.parent.node.className += " " + this.getHideClass();
  2469. };
  2470. PseudoElementContainer.prototype.cleanDOM = function() {
  2471. this.node.parentNode.removeChild(this.node);
  2472. this.parent.node.className = this.parent.node.className.replace(this.getHideClass(), "");
  2473. };
  2474. PseudoElementContainer.prototype.getHideClass = function() {
  2475. return this["PSEUDO_HIDE_ELEMENT_CLASS_" + (this.before ? "BEFORE" : "AFTER")];
  2476. };
  2477. PseudoElementContainer.prototype.PSEUDO_HIDE_ELEMENT_CLASS_BEFORE = "___html2canvas___pseudoelement_before";
  2478. PseudoElementContainer.prototype.PSEUDO_HIDE_ELEMENT_CLASS_AFTER = "___html2canvas___pseudoelement_after";
  2479. module.exports = PseudoElementContainer;
  2480. },{"./nodecontainer":14}],19:[function(_dereq_,module,exports){
  2481. var log = _dereq_('./log');
  2482. function Renderer(width, height, images, options, document) {
  2483. this.width = width;
  2484. this.height = height;
  2485. this.images = images;
  2486. this.options = options;
  2487. this.document = document;
  2488. }
  2489. Renderer.prototype.renderImage = function(container, bounds, borderData, imageContainer) {
  2490. var paddingLeft = container.cssInt('paddingLeft'),
  2491. paddingTop = container.cssInt('paddingTop'),
  2492. paddingRight = container.cssInt('paddingRight'),
  2493. paddingBottom = container.cssInt('paddingBottom'),
  2494. borders = borderData.borders;
  2495. var width = bounds.width - (borders[1].width + borders[3].width + paddingLeft + paddingRight);
  2496. var height = bounds.height - (borders[0].width + borders[2].width + paddingTop + paddingBottom);
  2497. this.drawImage(
  2498. imageContainer,
  2499. 0,
  2500. 0,
  2501. imageContainer.image.width || width,
  2502. imageContainer.image.height || height,
  2503. bounds.left + paddingLeft + borders[3].width,
  2504. bounds.top + paddingTop + borders[0].width,
  2505. width,
  2506. height
  2507. );
  2508. };
  2509. Renderer.prototype.renderBackground = function(container, bounds, borderData) {
  2510. if (bounds.height > 0 && bounds.width > 0) {
  2511. this.renderBackgroundColor(container, bounds);
  2512. this.renderBackgroundImage(container, bounds, borderData);
  2513. }
  2514. };
  2515. Renderer.prototype.renderBackgroundColor = function(container, bounds) {
  2516. var color = container.color("backgroundColor");
  2517. if (!color.isTransparent()) {
  2518. this.rectangle(bounds.left, bounds.top, bounds.width, bounds.height, color);
  2519. }
  2520. };
  2521. Renderer.prototype.renderBorders = function(borders) {
  2522. borders.forEach(this.renderBorder, this);
  2523. };
  2524. Renderer.prototype.renderBorder = function(data) {
  2525. if (!data.color.isTransparent() && data.args !== null) {
  2526. this.drawShape(data.args, data.color);
  2527. }
  2528. };
  2529. Renderer.prototype.renderBackgroundImage = function(container, bounds, borderData) {
  2530. var backgroundImages = container.parseBackgroundImages();
  2531. backgroundImages.reverse().forEach(function(backgroundImage, index, arr) {
  2532. switch(backgroundImage.method) {
  2533. case "url":
  2534. var image = this.images.get(backgroundImage.args[0]);
  2535. if (image) {
  2536. this.renderBackgroundRepeating(container, bounds, image, arr.length - (index+1), borderData);
  2537. } else {
  2538. log("Error loading background-image", backgroundImage.args[0]);
  2539. }
  2540. break;
  2541. case "linear-gradient":
  2542. case "gradient":
  2543. var gradientImage = this.images.get(backgroundImage.value);
  2544. if (gradientImage) {
  2545. this.renderBackgroundGradient(gradientImage, bounds, borderData);
  2546. } else {
  2547. log("Error loading background-image", backgroundImage.args[0]);
  2548. }
  2549. break;
  2550. case "none":
  2551. break;
  2552. default:
  2553. log("Unknown background-image type", backgroundImage.args[0]);
  2554. }
  2555. }, this);
  2556. };
  2557. Renderer.prototype.renderBackgroundRepeating = function(container, bounds, imageContainer, index, borderData) {
  2558. var size = container.parseBackgroundSize(bounds, imageContainer.image, index);
  2559. var position = container.parseBackgroundPosition(bounds, imageContainer.image, index, size);
  2560. var repeat = container.parseBackgroundRepeat(index);
  2561. switch (repeat) {
  2562. case "repeat-x":
  2563. case "repeat no-repeat":
  2564. this.backgroundRepeatShape(imageContainer, position, size, bounds, bounds.left + borderData[3], bounds.top + position.top + borderData[0], 99999, size.height, borderData);
  2565. break;
  2566. case "repeat-y":
  2567. case "no-repeat repeat":
  2568. this.backgroundRepeatShape(imageContainer, position, size, bounds, bounds.left + position.left + borderData[3], bounds.top + borderData[0], size.width, 99999, borderData);
  2569. break;
  2570. case "no-repeat":
  2571. this.backgroundRepeatShape(imageContainer, position, size, bounds, bounds.left + position.left + borderData[3], bounds.top + position.top + borderData[0], size.width, size.height, borderData);
  2572. break;
  2573. default:
  2574. this.renderBackgroundRepeat(imageContainer, position, size, {top: bounds.top, left: bounds.left}, borderData[3], borderData[0]);
  2575. break;
  2576. }
  2577. };
  2578. module.exports = Renderer;
  2579. },{"./log":13}],20:[function(_dereq_,module,exports){
  2580. var Renderer = _dereq_('../renderer');
  2581. var LinearGradientContainer = _dereq_('../lineargradientcontainer');
  2582. var log = _dereq_('../log');
  2583. function CanvasRenderer(width, height) {
  2584. Renderer.apply(this, arguments);
  2585. this.canvas = this.options.canvas || this.document.createElement("canvas");
  2586. if (!this.options.canvas) {
  2587. this.canvas.width = width;
  2588. this.canvas.height = height;
  2589. }
  2590. this.ctx = this.canvas.getContext("2d");
  2591. this.taintCtx = this.document.createElement("canvas").getContext("2d");
  2592. this.ctx.textBaseline = "bottom";
  2593. this.variables = {};
  2594. log("Initialized CanvasRenderer with size", width, "x", height);
  2595. }
  2596. CanvasRenderer.prototype = Object.create(Renderer.prototype);
  2597. CanvasRenderer.prototype.setFillStyle = function(fillStyle) {
  2598. this.ctx.fillStyle = typeof(fillStyle) === "object" && !!fillStyle.isColor ? fillStyle.toString() : fillStyle;
  2599. return this.ctx;
  2600. };
  2601. CanvasRenderer.prototype.rectangle = function(left, top, width, height, color) {
  2602. this.setFillStyle(color).fillRect(left, top, width, height);
  2603. };
  2604. CanvasRenderer.prototype.circle = function(left, top, size, color) {
  2605. this.setFillStyle(color);
  2606. this.ctx.beginPath();
  2607. this.ctx.arc(left + size / 2, top + size / 2, size / 2, 0, Math.PI*2, true);
  2608. this.ctx.closePath();
  2609. this.ctx.fill();
  2610. };
  2611. CanvasRenderer.prototype.circleStroke = function(left, top, size, color, stroke, strokeColor) {
  2612. this.circle(left, top, size, color);
  2613. this.ctx.strokeStyle = strokeColor.toString();
  2614. this.ctx.stroke();
  2615. };
  2616. CanvasRenderer.prototype.drawShape = function(shape, color) {
  2617. this.shape(shape);
  2618. this.setFillStyle(color).fill();
  2619. };
  2620. CanvasRenderer.prototype.taints = function(imageContainer) {
  2621. if (imageContainer.tainted === null) {
  2622. this.taintCtx.drawImage(imageContainer.image, 0, 0);
  2623. try {
  2624. this.taintCtx.getImageData(0, 0, 1, 1);
  2625. imageContainer.tainted = false;
  2626. } catch(e) {
  2627. this.taintCtx = document.createElement("canvas").getContext("2d");
  2628. imageContainer.tainted = true;
  2629. }
  2630. }
  2631. return imageContainer.tainted;
  2632. };
  2633. CanvasRenderer.prototype.drawImage = function(imageContainer, sx, sy, sw, sh, dx, dy, dw, dh) {
  2634. if (!this.taints(imageContainer) || this.options.allowTaint) {
  2635. this.ctx.drawImage(imageContainer.image, sx, sy, sw, sh, dx, dy, dw, dh);
  2636. }
  2637. };
  2638. CanvasRenderer.prototype.clip = function(shapes, callback, context) {
  2639. this.ctx.save();
  2640. shapes.filter(hasEntries).forEach(function(shape) {
  2641. this.shape(shape).clip();
  2642. }, this);
  2643. callback.call(context);
  2644. this.ctx.restore();
  2645. };
  2646. CanvasRenderer.prototype.shape = function(shape) {
  2647. this.ctx.beginPath();
  2648. shape.forEach(function(point, index) {
  2649. if (point[0] === "rect") {
  2650. this.ctx.rect.apply(this.ctx, point.slice(1));
  2651. } else {
  2652. this.ctx[(index === 0) ? "moveTo" : point[0] + "To" ].apply(this.ctx, point.slice(1));
  2653. }
  2654. }, this);
  2655. this.ctx.closePath();
  2656. return this.ctx;
  2657. };
  2658. CanvasRenderer.prototype.font = function(color, style, variant, weight, size, family) {
  2659. this.setFillStyle(color).font = [style, variant, weight, size, family].join(" ").split(",")[0];
  2660. };
  2661. CanvasRenderer.prototype.fontShadow = function(color, offsetX, offsetY, blur) {
  2662. this.setVariable("shadowColor", color.toString())
  2663. .setVariable("shadowOffsetY", offsetX)
  2664. .setVariable("shadowOffsetX", offsetY)
  2665. .setVariable("shadowBlur", blur);
  2666. };
  2667. CanvasRenderer.prototype.clearShadow = function() {
  2668. this.setVariable("shadowColor", "rgba(0,0,0,0)");
  2669. };
  2670. CanvasRenderer.prototype.setOpacity = function(opacity) {
  2671. this.ctx.globalAlpha = opacity;
  2672. };
  2673. CanvasRenderer.prototype.setTransform = function(transform) {
  2674. this.ctx.translate(transform.origin[0], transform.origin[1]);
  2675. this.ctx.transform.apply(this.ctx, transform.matrix);
  2676. this.ctx.translate(-transform.origin[0], -transform.origin[1]);
  2677. };
  2678. CanvasRenderer.prototype.setVariable = function(property, value) {
  2679. if (this.variables[property] !== value) {
  2680. this.variables[property] = this.ctx[property] = value;
  2681. }
  2682. return this;
  2683. };
  2684. CanvasRenderer.prototype.text = function(text, left, bottom) {
  2685. this.ctx.fillText(text, left, bottom);
  2686. };
  2687. CanvasRenderer.prototype.backgroundRepeatShape = function(imageContainer, backgroundPosition, size, bounds, left, top, width, height, borderData) {
  2688. var shape = [
  2689. ["line", Math.round(left), Math.round(top)],
  2690. ["line", Math.round(left + width), Math.round(top)],
  2691. ["line", Math.round(left + width), Math.round(height + top)],
  2692. ["line", Math.round(left), Math.round(height + top)]
  2693. ];
  2694. this.clip([shape], function() {
  2695. this.renderBackgroundRepeat(imageContainer, backgroundPosition, size, bounds, borderData[3], borderData[0]);
  2696. }, this);
  2697. };
  2698. CanvasRenderer.prototype.renderBackgroundRepeat = function(imageContainer, backgroundPosition, size, bounds, borderLeft, borderTop) {
  2699. var offsetX = Math.round(bounds.left + backgroundPosition.left + borderLeft), offsetY = Math.round(bounds.top + backgroundPosition.top + borderTop);
  2700. this.setFillStyle(this.ctx.createPattern(this.resizeImage(imageContainer, size), "repeat"));
  2701. this.ctx.translate(offsetX, offsetY);
  2702. this.ctx.fill();
  2703. this.ctx.translate(-offsetX, -offsetY);
  2704. };
  2705. CanvasRenderer.prototype.renderBackgroundGradient = function(gradientImage, bounds) {
  2706. if (gradientImage instanceof LinearGradientContainer) {
  2707. var gradient = this.ctx.createLinearGradient(
  2708. bounds.left + bounds.width * gradientImage.x0,
  2709. bounds.top + bounds.height * gradientImage.y0,
  2710. bounds.left + bounds.width * gradientImage.x1,
  2711. bounds.top + bounds.height * gradientImage.y1);
  2712. gradientImage.colorStops.forEach(function(colorStop) {
  2713. gradient.addColorStop(colorStop.stop, colorStop.color.toString());
  2714. });
  2715. this.rectangle(bounds.left, bounds.top, bounds.width, bounds.height, gradient);
  2716. }
  2717. };
  2718. CanvasRenderer.prototype.resizeImage = function(imageContainer, size) {
  2719. var image = imageContainer.image;
  2720. if(image.width === size.width && image.height === size.height) {
  2721. return image;
  2722. }
  2723. var ctx, canvas = document.createElement('canvas');
  2724. canvas.width = size.width;
  2725. canvas.height = size.height;
  2726. ctx = canvas.getContext("2d");
  2727. ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, size.width, size.height );
  2728. return canvas;
  2729. };
  2730. function hasEntries(array) {
  2731. return array.length > 0;
  2732. }
  2733. module.exports = CanvasRenderer;
  2734. },{"../lineargradientcontainer":12,"../log":13,"../renderer":19}],21:[function(_dereq_,module,exports){
  2735. var NodeContainer = _dereq_('./nodecontainer');
  2736. function StackingContext(hasOwnStacking, opacity, element, parent) {
  2737. NodeContainer.call(this, element, parent);
  2738. this.ownStacking = hasOwnStacking;
  2739. this.contexts = [];
  2740. this.children = [];
  2741. this.opacity = (this.parent ? this.parent.stack.opacity : 1) * opacity;
  2742. }
  2743. StackingContext.prototype = Object.create(NodeContainer.prototype);
  2744. StackingContext.prototype.getParentStack = function(context) {
  2745. var parentStack = (this.parent) ? this.parent.stack : null;
  2746. return parentStack ? (parentStack.ownStacking ? parentStack : parentStack.getParentStack(context)) : context.stack;
  2747. };
  2748. module.exports = StackingContext;
  2749. },{"./nodecontainer":14}],22:[function(_dereq_,module,exports){
  2750. function Support(document) {
  2751. this.rangeBounds = this.testRangeBounds(document);
  2752. this.cors = this.testCORS();
  2753. this.svg = this.testSVG();
  2754. }
  2755. Support.prototype.testRangeBounds = function(document) {
  2756. var range, testElement, rangeBounds, rangeHeight, support = false;
  2757. if (document.createRange) {
  2758. range = document.createRange();
  2759. if (range.getBoundingClientRect) {
  2760. testElement = document.createElement('boundtest');
  2761. testElement.style.height = "123px";
  2762. testElement.style.display = "block";
  2763. document.body.appendChild(testElement);
  2764. range.selectNode(testElement);
  2765. rangeBounds = range.getBoundingClientRect();
  2766. rangeHeight = rangeBounds.height;
  2767. if (rangeHeight === 123) {
  2768. support = true;
  2769. }
  2770. document.body.removeChild(testElement);
  2771. }
  2772. }
  2773. return support;
  2774. };
  2775. Support.prototype.testCORS = function() {
  2776. return typeof((new Image()).crossOrigin) !== "undefined";
  2777. };
  2778. Support.prototype.testSVG = function() {
  2779. var img = new Image();
  2780. var canvas = document.createElement("canvas");
  2781. var ctx = canvas.getContext("2d");
  2782. img.src = "data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'></svg>";
  2783. try {
  2784. ctx.drawImage(img, 0, 0);
  2785. canvas.toDataURL();
  2786. } catch(e) {
  2787. return false;
  2788. }
  2789. return true;
  2790. };
  2791. module.exports = Support;
  2792. },{}],23:[function(_dereq_,module,exports){
  2793. var XHR = _dereq_('./xhr');
  2794. var decode64 = _dereq_('./utils').decode64;
  2795. function SVGContainer(src) {
  2796. this.src = src;
  2797. this.image = null;
  2798. var self = this;
  2799. this.promise = this.hasFabric().then(function() {
  2800. return (self.isInline(src) ? Promise.resolve(self.inlineFormatting(src)) : XHR(src));
  2801. }).then(function(svg) {
  2802. return new Promise(function(resolve) {
  2803. window.html2canvas.svg.fabric.loadSVGFromString(svg, self.createCanvas.call(self, resolve));
  2804. });
  2805. });
  2806. }
  2807. SVGContainer.prototype.hasFabric = function() {
  2808. return !window.html2canvas.svg || !window.html2canvas.svg.fabric ? Promise.reject(new Error("html2canvas.svg.js is not loaded, cannot render svg")) : Promise.resolve();
  2809. };
  2810. SVGContainer.prototype.inlineFormatting = function(src) {
  2811. return (/^data:image\/svg\+xml;base64,/.test(src)) ? this.decode64(this.removeContentType(src)) : this.removeContentType(src);
  2812. };
  2813. SVGContainer.prototype.removeContentType = function(src) {
  2814. return src.replace(/^data:image\/svg\+xml(;base64)?,/,'');
  2815. };
  2816. SVGContainer.prototype.isInline = function(src) {
  2817. return (/^data:image\/svg\+xml/i.test(src));
  2818. };
  2819. SVGContainer.prototype.createCanvas = function(resolve) {
  2820. var self = this;
  2821. return function (objects, options) {
  2822. var canvas = new window.html2canvas.svg.fabric.StaticCanvas('c');
  2823. self.image = canvas.lowerCanvasEl;
  2824. canvas
  2825. .setWidth(options.width)
  2826. .setHeight(options.height)
  2827. .add(window.html2canvas.svg.fabric.util.groupSVGElements(objects, options))
  2828. .renderAll();
  2829. resolve(canvas.lowerCanvasEl);
  2830. };
  2831. };
  2832. SVGContainer.prototype.decode64 = function(str) {
  2833. return (typeof(window.atob) === "function") ? window.atob(str) : decode64(str);
  2834. };
  2835. module.exports = SVGContainer;
  2836. },{"./utils":26,"./xhr":28}],24:[function(_dereq_,module,exports){
  2837. var SVGContainer = _dereq_('./svgcontainer');
  2838. function SVGNodeContainer(node, _native) {
  2839. this.src = node;
  2840. this.image = null;
  2841. var self = this;
  2842. this.promise = _native ? new Promise(function(resolve, reject) {
  2843. self.image = new Image();
  2844. self.image.onload = resolve;
  2845. self.image.onerror = reject;
  2846. self.image.src = "data:image/svg+xml," + (new XMLSerializer()).serializeToString(node);
  2847. if (self.image.complete === true) {
  2848. resolve(self.image);
  2849. }
  2850. }) : this.hasFabric().then(function() {
  2851. return new Promise(function(resolve) {
  2852. window.html2canvas.svg.fabric.parseSVGDocument(node, self.createCanvas.call(self, resolve));
  2853. });
  2854. });
  2855. }
  2856. SVGNodeContainer.prototype = Object.create(SVGContainer.prototype);
  2857. module.exports = SVGNodeContainer;
  2858. },{"./svgcontainer":23}],25:[function(_dereq_,module,exports){
  2859. var NodeContainer = _dereq_('./nodecontainer');
  2860. function TextContainer(node, parent) {
  2861. NodeContainer.call(this, node, parent);
  2862. }
  2863. TextContainer.prototype = Object.create(NodeContainer.prototype);
  2864. TextContainer.prototype.applyTextTransform = function() {
  2865. this.node.data = this.transform(this.parent.css("textTransform"));
  2866. };
  2867. TextContainer.prototype.transform = function(transform) {
  2868. var text = this.node.data;
  2869. switch(transform){
  2870. case "lowercase":
  2871. return text.toLowerCase();
  2872. case "capitalize":
  2873. return text.replace(/(^|\s|:|-|\(|\))([a-z])/g, capitalize);
  2874. case "uppercase":
  2875. return text.toUpperCase();
  2876. default:
  2877. return text;
  2878. }
  2879. };
  2880. function capitalize(m, p1, p2) {
  2881. if (m.length > 0) {
  2882. return p1 + p2.toUpperCase();
  2883. }
  2884. }
  2885. module.exports = TextContainer;
  2886. },{"./nodecontainer":14}],26:[function(_dereq_,module,exports){
  2887. exports.smallImage = function smallImage() {
  2888. return "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
  2889. };
  2890. exports.bind = function(callback, context) {
  2891. return function() {
  2892. return callback.apply(context, arguments);
  2893. };
  2894. };
  2895. /*
  2896. * base64-arraybuffer
  2897. * https://github.com/niklasvh/base64-arraybuffer
  2898. *
  2899. * Copyright (c) 2012 Niklas von Hertzen
  2900. * Licensed under the MIT license.
  2901. */
  2902. exports.decode64 = function(base64) {
  2903. var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  2904. var len = base64.length, i, encoded1, encoded2, encoded3, encoded4, byte1, byte2, byte3;
  2905. var output = "";
  2906. for (i = 0; i < len; i+=4) {
  2907. encoded1 = chars.indexOf(base64[i]);
  2908. encoded2 = chars.indexOf(base64[i+1]);
  2909. encoded3 = chars.indexOf(base64[i+2]);
  2910. encoded4 = chars.indexOf(base64[i+3]);
  2911. byte1 = (encoded1 << 2) | (encoded2 >> 4);
  2912. byte2 = ((encoded2 & 15) << 4) | (encoded3 >> 2);
  2913. byte3 = ((encoded3 & 3) << 6) | encoded4;
  2914. if (encoded3 === 64) {
  2915. output += String.fromCharCode(byte1);
  2916. } else if (encoded4 === 64 || encoded4 === -1) {
  2917. output += String.fromCharCode(byte1, byte2);
  2918. } else{
  2919. output += String.fromCharCode(byte1, byte2, byte3);
  2920. }
  2921. }
  2922. return output;
  2923. };
  2924. exports.getBounds = function(node) {
  2925. if (node.getBoundingClientRect) {
  2926. var clientRect = node.getBoundingClientRect();
  2927. var width = node.offsetWidth == null ? clientRect.width : node.offsetWidth;
  2928. return {
  2929. top: clientRect.top,
  2930. bottom: clientRect.bottom || (clientRect.top + clientRect.height),
  2931. right: clientRect.left + width,
  2932. left: clientRect.left,
  2933. width: width,
  2934. height: node.offsetHeight == null ? clientRect.height : node.offsetHeight
  2935. };
  2936. }
  2937. return {};
  2938. };
  2939. exports.offsetBounds = function(node) {
  2940. var parent = node.offsetParent ? exports.offsetBounds(node.offsetParent) : {top: 0, left: 0};
  2941. return {
  2942. top: node.offsetTop + parent.top,
  2943. bottom: node.offsetTop + node.offsetHeight + parent.top,
  2944. right: node.offsetLeft + parent.left + node.offsetWidth,
  2945. left: node.offsetLeft + parent.left,
  2946. width: node.offsetWidth,
  2947. height: node.offsetHeight
  2948. };
  2949. };
  2950. exports.parseBackgrounds = function(backgroundImage) {
  2951. var whitespace = ' \r\n\t',
  2952. method, definition, prefix, prefix_i, block, results = [],
  2953. mode = 0, numParen = 0, quote, args;
  2954. var appendResult = function() {
  2955. if(method) {
  2956. if (definition.substr(0, 1) === '"') {
  2957. definition = definition.substr(1, definition.length - 2);
  2958. }
  2959. if (definition) {
  2960. args.push(definition);
  2961. }
  2962. if (method.substr(0, 1) === '-' && (prefix_i = method.indexOf('-', 1 ) + 1) > 0) {
  2963. prefix = method.substr(0, prefix_i);
  2964. method = method.substr(prefix_i);
  2965. }
  2966. results.push({
  2967. prefix: prefix,
  2968. method: method.toLowerCase(),
  2969. value: block,
  2970. args: args,
  2971. image: null
  2972. });
  2973. }
  2974. args = [];
  2975. method = prefix = definition = block = '';
  2976. };
  2977. args = [];
  2978. method = prefix = definition = block = '';
  2979. backgroundImage.split("").forEach(function(c) {
  2980. if (mode === 0 && whitespace.indexOf(c) > -1) {
  2981. return;
  2982. }
  2983. switch(c) {
  2984. case '"':
  2985. if(!quote) {
  2986. quote = c;
  2987. } else if(quote === c) {
  2988. quote = null;
  2989. }
  2990. break;
  2991. case '(':
  2992. if(quote) {
  2993. break;
  2994. } else if(mode === 0) {
  2995. mode = 1;
  2996. block += c;
  2997. return;
  2998. } else {
  2999. numParen++;
  3000. }
  3001. break;
  3002. case ')':
  3003. if (quote) {
  3004. break;
  3005. } else if(mode === 1) {
  3006. if(numParen === 0) {
  3007. mode = 0;
  3008. block += c;
  3009. appendResult();
  3010. return;
  3011. } else {
  3012. numParen--;
  3013. }
  3014. }
  3015. break;
  3016. case ',':
  3017. if (quote) {
  3018. break;
  3019. } else if(mode === 0) {
  3020. appendResult();
  3021. return;
  3022. } else if (mode === 1) {
  3023. if (numParen === 0 && !method.match(/^url$/i)) {
  3024. args.push(definition);
  3025. definition = '';
  3026. block += c;
  3027. return;
  3028. }
  3029. }
  3030. break;
  3031. }
  3032. block += c;
  3033. if (mode === 0) {
  3034. method += c;
  3035. } else {
  3036. definition += c;
  3037. }
  3038. });
  3039. appendResult();
  3040. return results;
  3041. };
  3042. },{}],27:[function(_dereq_,module,exports){
  3043. var GradientContainer = _dereq_('./gradientcontainer');
  3044. function WebkitGradientContainer(imageData) {
  3045. GradientContainer.apply(this, arguments);
  3046. this.type = imageData.args[0] === "linear" ? GradientContainer.TYPES.LINEAR : GradientContainer.TYPES.RADIAL;
  3047. }
  3048. WebkitGradientContainer.prototype = Object.create(GradientContainer.prototype);
  3049. module.exports = WebkitGradientContainer;
  3050. },{"./gradientcontainer":9}],28:[function(_dereq_,module,exports){
  3051. function XHR(url) {
  3052. return new Promise(function(resolve, reject) {
  3053. var xhr = new XMLHttpRequest();
  3054. xhr.open('GET', url);
  3055. xhr.onload = function() {
  3056. if (xhr.status === 200) {
  3057. resolve(xhr.responseText);
  3058. } else {
  3059. reject(new Error(xhr.statusText));
  3060. }
  3061. };
  3062. xhr.onerror = function() {
  3063. reject(new Error("Network Error"));
  3064. };
  3065. xhr.send();
  3066. });
  3067. }
  3068. module.exports = XHR;
  3069. },{}]},{},[4])(4)
  3070. });