설명 없음
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

html2canvas.debug.js 106KB

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