@devgateway/dvz-ui-react
Version:
A modular, embeddable React component library for data visualization and UI, built with TypeScript. Provides reusable components for charts, maps, dashboards, and more, with built-in support for internationalization and Redux integration.
3 lines (2 loc) • 9.74 kB
JavaScript
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=z(),R=K(),k=Q(),F=Y(),j={imagePlaceholder:void 0,cacheBust:!1},b={toSvg:N,toPng:_,toJpeg:X,toBlob:G,toPixelData:V,cloneNode:O,impl:{fontFaces:k,images:F,util:h,inliner:R,options:{}}};typeof module<"u"?module.exports=b:globalThis.domtoimage=b;async function N(o,t){t=t||{},$(t);const n=await Promise.resolve(o),a=await O(n,t.filter,!0),l=await W(a),r=await q(l),s=await d(r);return await J(s,t.width||h.width(o),t.height||h.height(o));function d(m){return t.bgcolor&&(m.style.backgroundColor=t.bgcolor),t.width&&(m.style.width=t.width+"px"),t.height&&(m.style.height=t.height+"px"),t.style&&Object.keys(t.style).forEach(function(g){m.style[g]=t.style[g]}),m}}async function V(o,t){const n=await I(o,t||{});return n?n.getContext("2d").getImageData(0,0,h.width(o),h.height(o)).data:null}async function _(o,t){const n=await I(o,t||{});return n?n.toDataURL():null}async function X(o,t){t=t||{};const n=await I(o,t);return n?n.toDataURL("image/jpeg",t.quality||1):null}function G(o,t){return I(o,t||{}).then(h.canvasToBlob)}function $(o){typeof o.imagePlaceholder>"u"?b.impl.options.imagePlaceholder=j.imagePlaceholder:b.impl.options.imagePlaceholder=o.imagePlaceholder,typeof o.cacheBust>"u"?b.impl.options.cacheBust=j.cacheBust:b.impl.options.cacheBust=o.cacheBust}function I(o,t){return N(o,t).then(h.makeImage).then(h.delay(100)).then(function(a){const l=n(o,t),r=l.getContext("2d");return r?(r.drawImage(a,0,0),l):new HTMLCanvasElement}).catch(function(a){console.error("Failed to draw canvas:",a)});function n(a,l){const r=document.createElement("canvas"),s=a.getBoundingClientRect(),d=window.devicePixelRatio||1;r.width=(l.width||s.width)*d,r.height=(l.height||s.height)*d,r.style.width=(l.width||s.width)+"px",r.style.height=(l.height||s.height)+"px";const m=r.getContext("2d");return m?(m.scale(d,d),l.bgcolor&&(m.fillStyle=l.bgcolor,m.fillRect(0,0,r.width,r.height)),r):new HTMLCanvasElement}}async function O(o,t,n){if(!n&&t&&!t(o))return Promise.resolve();const a=await Promise.resolve(o),l=await s(a),r=await d(o,l,t);return m(o,r);function s(g){return g instanceof HTMLCanvasElement?h.makeImage(g.toDataURL()):g.cloneNode(!1)}async function d(g,c,T){const E=g.childNodes;if(E.length===0)return Promise.resolve(c);return await C(c,h.asArray(E),T),c;function C(S,v,p){let w=Promise.resolve();return v.forEach(function(e){w=w.then(function(){return O(e,p)}).then(function(i){i&&S.appendChild(i)})}),w}}function m(g,c){if(!(c instanceof Element))return c;return Promise.resolve().then(T).then(E).then(C).then(S).then(function(){return c});function T(){v(window.getComputedStyle(g),c.style);function v(p,w){p.cssText?w.cssText=p.cssText:e(p,w);function e(i,f){h.asArray(i).forEach(function(u){f.setProperty(u,i.getPropertyValue(u),i.getPropertyPriority(u))})}}}function E(){[":before",":after"].forEach(function(p){v(p)});function v(p){const w=window.getComputedStyle(g,p),e=w.getPropertyValue("content");if(e===""||e==="none")return;const i=h.uid();c.className=c.className+" "+i;const f=document.createElement("style");f.appendChild(u(i,p,w)),c.appendChild(f);function u(y,x,U){const B="."+y+":"+x,P=U.cssText?L(U):H(U);return document.createTextNode(B+"{"+P+"}");function L(A){const M=A.getPropertyValue("content");return A.cssText+" content: "+M+";"}function H(A){return h.asArray(A).map(M).join("; ")+";";function M(D){return D+": "+A.getPropertyValue(D)+(A.getPropertyPriority(D)?" !important":"")}}}}}function C(){g instanceof HTMLTextAreaElement&&(c.innerHTML=g.value),g instanceof HTMLInputElement&&c.setAttribute("value",g.value)}function S(){c instanceof SVGElement&&(c.setAttribute("xmlns","http://www.w3.org/2000/svg"),c instanceof SVGRectElement&&["width","height"].forEach(function(v){const p=c.getAttribute(v);p&&c.style.setProperty(v,p)}))}}}async function W(o){const t=await k.resolveAll(),n=document.createElement("style");return o.appendChild(n),n.appendChild(document.createTextNode(t)),o}function q(o){return F.inlineAll(o).then(function(){return o})}function J(o,t,n){return Promise.resolve(o).then(function(a){return a.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),new XMLSerializer().serializeToString(a)}).then(h.escapeXhtml).then(function(a){return'<foreignObject x="0" y="0" width="100%" height="100%">'+a+"</foreignObject>"}).then(function(a){return'<svg xmlns="http://www.w3.org/2000/svg" width="'+t+'" height="'+n+'">'+a+"</svg>"}).then(function(a){return"data:image/svg+xml;charset=utf-8,"+a})}function z(){return{escape:T,parseExtension:t,mimeType:n,dataAsUrl:c,isDataUrl:a,canvasToBlob:r,resolveUrl:s,getAndEncode:g,uid:d(),delay:E,asArray:C,escapeXhtml:S,makeImage:m,width:v,height:p};function o(){const e="application/font-woff",i="image/jpeg";return{woff:e,woff2:e,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:i,jpeg:i,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml"}}function t(e){const i=/\.([^\.\/]*?)$/g.exec(e);return i?i[1]:""}function n(e){const i=t(e).toLowerCase();return o()[i]||""}function a(e){return e.search(/^(data:)/)!==-1}function l(e){return new Promise(function(i){const f=window.atob(e.toDataURL().split(",")[1]),u=f.length,y=new Uint8Array(u);for(let x=0;x<u;x++)y[x]=f.charCodeAt(x);i(new Blob([y],{type:"image/png"}))})}function r(e){return e.toBlob?new Promise(function(i){e.toBlob(i)}):l(e)}function s(e,i){const f=document.implementation.createHTMLDocument(),u=f.createElement("base");f.head.appendChild(u);const y=f.createElement("a");return f.body.appendChild(y),u.href=i,y.href=e,y.href}function d(){let e=0;return function(){return"u"+i()+e++;function i(){return("0000"+(Math.random()*Math.pow(36,4)<<0).toString(36)).slice(-4)}}}function m(e){return new Promise(function(i,f){const u=new Image;u.onload=function(){i(u)},u.onerror=f,u.src=e})}function g(e){return b.impl.options.cacheBust&&(e+=(/\?/.test(e)?"&":"?")+new Date().getTime()),new Promise(function(f){const u=new XMLHttpRequest;u.onreadystatechange=x,u.ontimeout=U,u.responseType="blob",u.timeout=3e4,u.open("GET",e,!0),u.send();let y;if(b.impl.options.imagePlaceholder){const P=b.impl.options.imagePlaceholder.split(/,/);P&&P[1]&&(y=P[1])}function x(){if(u.readyState!==4)return;if(u.status!==200){y?f(y):B("cannot fetch resource: "+e+", status: "+u.status);return}const P=new FileReader;P.onloadend=function(){const L=P.result.split(/,/)[1];f(L)},P.readAsDataURL(u.response)}function U(){y?f(y):B("timeout of 30000ms occured while fetching resource: "+e)}function B(P){console.error(P),f("")}})}function c(e,i){return"data:"+i+";base64,"+e}function T(e){return e.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1")}function E(e){return function(i){return new Promise(function(f){setTimeout(function(){f(i)},e)})}}function C(e){const i=[],f=e.length;for(let u=0;u<f;u++)i.push(e[u]);return i}function S(e){return e.replace(/#/g,"%23").replace(/\n/g,"%0A")}function v(e){const i=w(e,"border-left-width"),f=w(e,"border-right-width");return e.scrollWidth+i+f}function p(e){const i=w(e,"border-top-width"),f=w(e,"border-bottom-width");return e.scrollHeight+i+f}function w(e,i){const f=window.getComputedStyle(e).getPropertyValue(i);return parseFloat(f.replace("px",""))}}function K(){const o=/url\(['"]?([^'"]+?)['"]?\)/g;return{inlineAll:l,shouldProcess:t,impl:{readUrls:n,inline:a}};function t(r){return r.search(o)!==-1}function n(r){const s=[];let d;for(;(d=o.exec(r))!==null;)s.push(d[1]);return s.filter(function(m){return!h.isDataUrl(m)})}function a(r,s,d,m){return Promise.resolve(s).then(function(c){return d?h.resolveUrl(c,d):c}).then(m||h.getAndEncode).then(function(c){return h.dataAsUrl(c,h.mimeType(s))}).then(function(c){return r.replace(g(s),"$1"+c+"$3")});function g(c){return new RegExp(`(url\\(['"]?)(`+h.escape(c)+`)(['"]?\\))`,"g")}}function l(r,s,d){if(m())return Promise.resolve(r);return Promise.resolve(r).then(n).then(function(g){let c=Promise.resolve(r);return g.forEach(function(T){c=c.then(function(E){return a(E,T,s,d)})}),c});function m(){return!t(r)}}}function Q(){return{resolveAll:o,impl:{readAll:t}};function o(){return t().then(function(n){return Promise.all(n.map(function(a){return a.resolve()}))}).then(function(n){return n.join(`
`)})}function t(){return Promise.resolve(h.asArray(document.styleSheets)).then(a).then(n).then(function(r){return r.map(l)});function n(r){return r.filter(function(s){return s.type===CSSRule.FONT_FACE_RULE}).filter(function(s){return R.shouldProcess(s.style.getPropertyValue("src"))})}function a(r){const s=[];return r.forEach(function(d){if(Object.prototype.hasOwnProperty.call(d,"cssRules"))try{h.asArray(d.cssRules||[]).forEach(s.push.bind(s))}catch(m){console.log("Error while reading CSS rules from "+d.href,m.toString())}}),s}function l(r){return{resolve:function(){const d=(r.parentStyleSheet||{}).href;return R.inlineAll(r.cssText,d)},src:function(){return r.style.getPropertyValue("src")}}}}}function Y(){return{inlineAll:t,impl:{newImage:o}};function o(n){return{inline:a};function a(l){return h.isDataUrl(n.src)?Promise.resolve():Promise.resolve(n.src).then(l||h.getAndEncode).then(function(r){return h.dataAsUrl(r,h.mimeType(n.src))}).then(function(r){return new Promise(function(s,d){n.onload=s,n.onerror=d,n.src=r,n.srcset=""})})}}function t(n){if(!(n instanceof Element))return Promise.resolve(n);return a(n).then(function(){return n instanceof HTMLImageElement?o(n).inline():Promise.all(h.asArray(n.childNodes).map(function(l){return t(l)}))});function a(l){const r=l.style.getPropertyValue("background");return r?R.inlineAll(r).then(function(s){l.style.setProperty("background",s,l.style.getPropertyPriority("background"))}).then(function(){return l}):Promise.resolve(l)}}}exports.domtoimage=b;
;