Free javascript Hosting


html-to-image.js

Uploaded on Oct 12 2021 02:54 by its.ankita09

!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).htmlToImage={})}(this,(function(t){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function n(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function c(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,c)}a((r=r.apply(t,n||[])).next())}))}function e(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=n.call(t,u)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function r(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))}var o,i,u="application/font-woff",c="image/jpeg",a={woff:u,woff2:u,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:c,jpeg:c,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml"},f=(o=0,function(){return o+=1,"u"+("0000"+(Math.random()*Math.pow(36,4)<<0).toString(36)).slice(-4)+o});function s(t){var n=function(t){var n=/\.([^./]*?)$/g.exec(t);return n?n[1]:""}(t).toLowerCase();return a[n]||""}function l(t){return-1!==t.search(/^(data:)/)}function h(t,n){return"data:"+n+";base64,"+t}function d(t){return t.split(/,/)[1]}function v(t){return t.toBlob?new Promise((function(n){return t.toBlob(n)})):function(t){return new Promise((function(n){for(var e=window.atob(t.toDataURL().split(",")[1]),r=e.length,o=new Uint8Array(r),i=0;i<r;i+=1)o[i]=e.charCodeAt(i);n(new Blob([o],{type:"image/png"}))}))}(t)}function p(t){for(var n=[],e=0,r=t.length;e<r;e+=1)n.push(t[e]);return n}function g(t,n){var e=window.getComputedStyle(t).getPropertyValue(n);return parseFloat(e.replace("px",""))}function m(t){return new Promise((function(n,e){var r=new Image;r.onload=function(){return n(r)},r.onerror=e,r.crossOrigin="anonymous",r.src=t}))}function w(t){return n(this,void 0,void 0,(function(){var n;return e(this,(function(e){return t instanceof HTMLCanvasElement?"data:,"===(n=t.toDataURL())?[2,Promise.resolve(t.cloneNode(!1))]:[2,m(n)]:[2,Promise.resolve(t.cloneNode(!1))]}))}))}!function(t){t.clonePseudoElement=function(t,n,e){var r=window.getComputedStyle(t,e),o=r.getPropertyValue("content");if(""!==o&&"none"!==o){var i=f();try{n.className=n.className+" "+i}catch(t){return}var u=document.createElement("style");u.appendChild(function(t,n,e){var r="."+t+":"+n,o=e.cssText?function(t){var n=t.getPropertyValue("content");return t.cssText+" content: "+n+";"}(e):function(t){return p(t).map((function(n){return n+": "+t.getPropertyValue(n)+(t.getPropertyPriority(n)?" !important":"")+";"})).join(" ")}(e);return document.createTextNode(r+"{"+o+"}")}(i,e,r)),n.appendChild(u)}}}(i||(i={}));var y=function(t){return"SLOT"===t.tagName};function P(t,o,i){return n(this,void 0,void 0,(function(){var n;return e(this,(function(e){return 0===(n=function(t){for(var n=t.shadowRoot?p(t.shadowRoot.childNodes):p(t.childNodes),e=0;e<n.length;e+=1){var o=n[e];if(y(o)){var i=o.assignedNodes();i.length>0&&(n.splice.apply(n,r([e,1],i,!1)),e-=1)}}return n}(t)).length?[2,Promise.resolve(o)]:[2,n.reduce((function(t,n){return t.then((function(){return S(n,i)})).then((function(t){t&&o.appendChild(t)}))}),Promise.resolve()).then((function(){return o}))]}))}))}function b(t,r){return n(this,void 0,void 0,(function(){return e(this,(function(n){return r instanceof Element?[2,Promise.resolve().then((function(){return function(t,n){var e=window.getComputedStyle(t),r=n.style;e.cssText?r.cssText=e.cssText:p(e).forEach((function(t){r.setProperty(t,e.getPropertyValue(t),e.getPropertyPriority(t))}))}(t,r)})).then((function(){return function(t,n){[":before",":after"].forEach((function(e){return i.clonePseudoElement(t,n,e)}))}(t,r)})).then((function(){return function(t,n){t instanceof HTMLTextAreaElement&&(n.innerHTML=t.value);t instanceof HTMLInputElement&&n.setAttribute("value",t.value)}(t,r)})).then((function(){return r}))]:[2,r]}))}))}function S(t,r,o){return n(this,void 0,void 0,(function(){return e(this,(function(n){return o||!r||r(t)?[2,Promise.resolve(t).then(w).then((function(n){return P(t,n,r)})).then((function(n){return b(t,n)}))]:[2,Promise.resolve(null)]}))}))}var E={};function R(t,n){var e=t.replace(/\?.*/,"");if(/ttf|otf|eot|woff2?/i.test(e)&&(e=e.replace(/.*\//,"")),E[e])return E[e];n.cacheBust&&(t+=(/\?/.test(t)?"&":"?")+(new Date).getTime());var r=(window.fetch?window.fetch(t).then((function(t){return t.blob()})).then((function(t){return new Promise((function(n,e){var r=new FileReader;r.onloadend=function(){return n(r.result)},r.onerror=e,r.readAsDataURL(t)}))})).then(d).catch((function(){return new Promise((function(t,n){return n()}))})):new Promise((function(n,e){var r=new XMLHttpRequest;r.onreadystatechange=function(){if(4===r.readyState)if(200===r.status){var o=new FileReader;o.onloadend=function(){n(d(o.result))},o.readAsDataURL(r.response)}else e(new Error("Failed to fetch resource: "+t+", status: "+r.status))},r.ontimeout=function(){e(new Error("Timeout of 30000ms occured while fetching resource: "+t))},r.responseType="blob",r.timeout=3e4,r.open("GET",t,!0),r.send()}))).catch((function(e){var r="";if(n.imagePlaceholder){var o=n.imagePlaceholder.split(/,/);o&&o[1]&&(r=o[1])}var i="Failed to fetch resource: "+t;return e&&(i="string"==typeof e?e:e.message),i&&console.error(i),r}));return E[e]=r,r}var x=/url\((['"]?)([^'"]+?)\1\)/g;function C(t){return-1!==t.search(x)}function T(t,n,e){return C(t)?Promise.resolve(t).then(N).then((function(r){return r.reduce((function(t,r){return t.then((function(t){return function(t,n,e,r,o){var i=e?function(t,n){if(t.match(/^[a-z]+:\/\//i))return t;if(t.match(/^\/\//))return window.location.protocol+t;if(t.match(/^[a-z]+:/i))return t;var e=document.implementation.createHTMLDocument(),r=e.createElement("base"),o=e.createElement("a");e.head.appendChild(r),e.body.appendChild(o),n&&(r.href=n);return o.href=t,o.href}(n,e):n;return Promise.resolve(i).then((function(t){return o?o(t):R(t,r)})).then((function(t){return h(t,s(n))})).then((function(e){return t.replace(function(t){return new RegExp("(url\\(['\"]?)("+function(t){return t.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1")}(t)+")(['\"]?\\))","g")}(n),"$1"+e+"$3")})).then((function(t){return t}),(function(){return i}))}(t,r,n,e)}))}),Promise.resolve(t))})):Promise.resolve(t)}function N(t){var n=[];return t.replace(x,(function(t,e,r){return n.push(r),t})),n.filter((function(t){return!l(t)}))}function L(t,r){return n(this,void 0,void 0,(function(){return e(this,(function(o){return t instanceof Element?[2,Promise.resolve(t).then((function(t){return function(t,r){return n(this,void 0,void 0,(function(){var n;return e(this,(function(e){return(n=t.style.getPropertyValue("background"))?[2,Promise.resolve(n).then((function(t){return T(t,null,r)})).then((function(n){return t.style.setProperty("background",n,t.style.getPropertyPriority("background")),t}))]:[2,Promise.resolve(t)]}))}))}(t,r)})).then((function(t){return function(t,n){if(!(t instanceof HTMLImageElement)||l(t.src))return Promise.resolve(t);return Promise.resolve(t.src).then((function(t){return R(t,n)})).then((function(n){return h(n,s(t.src))})).then((function(n){return new Promise((function(e,r){t.onload=e,t.onerror=r,t.src=n}))})).then((function(){return t}),(function(){return t}))}(t,r)})).then((function(t){return function(t,r){return n(this,void 0,void 0,(function(){var n,o;return e(this,(function(e){return n=p(t.childNodes),o=n.map((function(t){return L(t,r)})),[2,Promise.all(o).then((function(){return t}))]}))}))}(t,r)}))]:[2,Promise.resolve(t)]}))}))}var A={};function D(t){return n(this,void 0,void 0,(function(){return e(this,(function(n){return[2,new Promise((function(n,e){t.ownerDocument||e(new Error("Provided element is not within a Document")),n(p(t.ownerDocument.styleSheets))})).then(k).then(U)]}))}))}function k(t){return n(this,void 0,void 0,(function(){var n,r;return e(this,(function(e){return n=[],r=[],t.forEach((function(n){if("cssRules"in n)try{p(n.cssRules).forEach((function(t){t.type===CSSRule.IMPORT_RULE&&r.push(j(t.href,n).then(I).then((function(t){M(t).forEach((function(t){n.insertRule(t,n.cssRules.length)}))})).catch((function(t){console.log("Error loading remote css",t.toString())})))}))}catch(o){var e=t.find((function(t){return null===t.href}))||document.styleSheets[0];null!=n.href&&r.push(j(n.href).then(I).then((function(t){M(t).forEach((function(t){e.insertRule(t,n.cssRules.length)}))})).catch((function(t){console.log("Error loading remote stylesheet",t.toString())}))),console.log("Error inlining remote css file",o.toString())}})),[2,Promise.all(r).then((function(){return t.forEach((function(t){if("cssRules"in t)try{p(t.cssRules).forEach((function(t){n.push(t)}))}catch(n){console.log("Error while reading CSS rules from "+t.href,n.toString())}})),n}))]}))}))}function U(t){return t.filter((function(t){return t.type===CSSRule.FONT_FACE_RULE})).filter((function(t){return C(t.style.getPropertyValue("src"))}))}function M(t){if(void 0===t)return[];var n=t,e=[],r=new RegExp("(\\/\\*[\\s\\S]*?\\*\\/)","gi");n=n.replace(r,"");for(var o,i=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");null!==(o=i.exec(n));)e.push(o[0]);n=n.replace(i,"");for(var u=new RegExp("((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})","gi");null!==(o=u.exec(n));)e.push(o[0]);return e}function j(t,n){if(A[t])return A[t];var e=fetch(t).then((function(n){return{url:t,cssText:n.text()}}),(function(t){console.log("ERROR FETCHING CSS: ",t.toString())}));return A[t]=e,e}function I(t){return n(this,void 0,void 0,(function(){return e(this,(function(n){return[2,t.cssText.then((function(n){var e=n,r=/url\(["']?([^"')]+)["']?\)/g,o=(e.match(/url\([^)]+\)/g)||[]).map((function(n){var o=n.replace(r,"$1");if(!o.startsWith("https://")){var i=t.url;o=new URL(o,i).href}return new Promise((function(t,r){fetch(o).then((function(t){return t.blob()})).then((function(r){var o=new FileReader;o.addEventListener("load",(function(r){e=e.replace(n,"url("+o.result+")"),t([n,o.result])})),o.readAsDataURL(r)})).catch(r)}))}));return Promise.all(o).then((function(){return e}))}))]}))}))}function F(t,r,o){var i="http://www.w3.org/2000/svg",u=document.createElementNS(i,"svg"),c=document.createElementNS(i,"foreignObject");return u.setAttributeNS("","width",""+r),u.setAttributeNS("","height",""+o),c.setAttributeNS("","width","100%"),c.setAttributeNS("","height","100%"),c.setAttributeNS("","x","0"),c.setAttributeNS("","y","0"),c.setAttributeNS("","externalResourcesRequired","true"),u.appendChild(c),c.appendChild(t),function(t){return n(this,void 0,void 0,(function(){return e(this,(function(n){return[2,Promise.resolve().then((function(){return(new XMLSerializer).serializeToString(t)})).then(encodeURIComponent).then((function(t){return"data:image/svg+xml;charset=utf-8,"+t}))]}))}))}(u)}function H(t,n){void 0===n&&(n={});var e,r,o,i=n.width||(r=g(e=t,"border-left-width"),o=g(e,"border-right-width"),e.scrollWidth+r+o),u=n.height||function(t){var n=g(t,"border-top-width"),e=g(t,"border-bottom-width");return t.scrollHeight+n+e}(t);return{width:i,height:u}}function O(t,r){return void 0===r&&(r={}),n(this,void 0,void 0,(function(){var o,i,u;return e(this,(function(c){return o=H(t,r),i=o.width,u=o.height,[2,S(t,r.filter,!0).then((function(t){return function(t,r){return n(this,void 0,void 0,(function(){return e(this,(function(n){return[2,D(t).then((function(t){return Promise.all(t.map((function(t){var n=t.parentStyleSheet?t.parentStyleSheet.href:null;return T(t.cssText,n,r)})))})).then((function(t){return t.join("\n")})).then((function(n){var e=document.createElement("style"),r=document.createTextNode(n);return e.appendChild(r),t.firstChild?t.insertBefore(e,t.firstChild):t.appendChild(e),t}))]}))}))}(t,r)})).then((function(t){return L(t,r)})).then((function(t){return function(t,n){var e=t.style;n.backgroundColor&&(e.backgroundColor=n.backgroundColor),n.width&&(e.width=n.width+"px"),n.height&&(e.height=n.height+"px");var r=n.style;return null!=r&&Object.keys(r).forEach((function(t){e[t]=r[t]})),t}(t,r)})).then((function(t){return F(t,i,u)}))]}))}))}var V=O;function B(t,r){return void 0===r&&(r={}),n(this,void 0,void 0,(function(){return e(this,(function(n){return[2,O(t,r).then(m).then((e=100,function(t){return new Promise((function(n){setTimeout((function(){n(t)}),e)}))})).then((function(n){var e=document.createElement("canvas"),o=e.getContext("2d"),i=r.pixelRatio||function(){var t,n;try{n=process}catch(t){}var e=n&&n.env?n.env.devicePixelRatio:null;return e&&(t=parseInt(e,10),isNaN(t)&&(t=1)),t||window.devicePixelRatio||1}(),u=H(t,r),c=u.width,a=u.height;return e.width=c*i,e.height=a*i,e.style.width=""+c,e.style.height=""+a,r.backgroundColor&&(o.fillStyle=r.backgroundColor,o.fillRect(0,0,e.width,e.height)),o.drawImage(n,0,0),e}))];var e}))}))}t.toBlob=function(t,r){return void 0===r&&(r={}),n(this,void 0,void 0,(function(){return e(this,(function(n){return[2,B(t,r).then(v)]}))}))},t.toCanvas=B,t.toJpeg=function(t,r){return void 0===r&&(r={}),n(this,void 0,void 0,(function(){return e(this,(function(n){return[2,B(t,r).then((function(t){return t.toDataURL("image/jpeg",r.quality||1)}))]}))}))},t.toPixelData=function(t,r){return void 0===r&&(r={}),n(this,void 0,void 0,(function(){var n,o,i;return e(this,(function(e){return n=H(t,r),o=n.width,i=n.height,[2,B(t,r).then((function(t){return t.getContext("2d").getImageData(0,0,o,i).data}))]}))}))},t.toPng=function(t,r){return void 0===r&&(r={}),n(this,void 0,void 0,(function(){return e(this,(function(n){return[2,B(t,r).then((function(t){return t.toDataURL()}))]}))}))},t.toSvg=O,t.toSvgDataURL=V,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=html-to-image.js.map

Back to list