tracer-sh 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/packages/server/dist/index.js +28 -10
- package/packages/web/dist/assets/{SearchableSelect-CvsTUEdo.js → SearchableSelect-B006wjjM.js} +1 -1
- package/packages/web/dist/assets/{Settings-gjgo6xd4.js → Settings-DMPQXaLL.js} +1 -1
- package/packages/web/dist/assets/{highlighted-body-OFNGDK62-DdqoooTx.js → highlighted-body-OFNGDK62-C3igFa7L.js} +1 -1
- package/packages/web/dist/assets/index-B7y1naN3.js +48 -0
- package/packages/web/dist/assets/index-NB5FNsou.js +14 -0
- package/packages/web/dist/assets/mermaid-GHXKKRXX-Cga6EKax.js +191 -0
- package/packages/web/dist/index.html +1 -1
- package/packages/web/dist/assets/index-DqPm6rps.js +0 -48
- package/packages/web/dist/assets/mermaid-GHXKKRXX-DQ_Kyq22.js +0 -204
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function Q(e,t){return e[13]=1,e[14]=t>>8,e[15]=t&255,e[16]=t>>8,e[17]=t&255,e}const Z=112,ee=72,te=89,re=115;let L;function Ce(){const e=new Int32Array(256);for(let t=0;t<256;t++){let r=t;for(let n=0;n<8;n++)r=r&1?3988292384^r>>>1:r>>>1;e[t]=r}return e}function ve(e){let t=-1;L||(L=Ce());for(let r=0;r<e.length;r++)t=L[(t^e[r])&255]^t>>>8;return t^-1}function Te(e){const t=e.length-1;for(let r=t;r>=4;r--)if(e[r-4]===9&&e[r-3]===Z&&e[r-2]===ee&&e[r-1]===te&&e[r]===re)return r-3;return 0}function ne(e,t,r=!1){const n=new Uint8Array(13);t*=39.3701,n[0]=Z,n[1]=ee,n[2]=te,n[3]=re,n[4]=t>>>24,n[5]=t>>>16,n[6]=t>>>8,n[7]=t&255,n[8]=n[4],n[9]=n[5],n[10]=n[6],n[11]=n[7],n[12]=1;const a=ve(n),s=new Uint8Array(4);if(s[0]=a>>>24,s[1]=a>>>16,s[2]=a>>>8,s[3]=a&255,r){const i=Te(e);return e.set(n,i),e.set(s,i+13),e}else{const i=new Uint8Array(4);i[0]=0,i[1]=0,i[2]=0,i[3]=9;const o=new Uint8Array(54);return o.set(e,0),o.set(i,33),o.set(n,37),o.set(s,50),o}}const Ne="AAlwSFlz",Ae="AAAJcEhZ",De="AAAACXBI";function Re(e){let t=e.indexOf(Ne);return t===-1&&(t=e.indexOf(Ae)),t===-1&&(t=e.indexOf(De)),t}const oe="[modern-screenshot]",N=typeof window<"u",Ie=N&&"Worker"in window,se=N&&"atob"in window,ke=N&&"btoa"in window,W=N?window.navigator?.userAgent:"",ae=W.includes("Chrome"),_=W.includes("AppleWebKit")&&!ae,j=W.includes("Firefox"),Fe=e=>e&&"__CONTEXT__"in e,xe=e=>e.constructor.name==="CSSFontFaceRule",Pe=e=>e.constructor.name==="CSSImportRule",_e=e=>e.constructor.name==="CSSLayerBlockRule",E=e=>e.nodeType===1,F=e=>typeof e.className=="object",ie=e=>e.tagName==="image",Ue=e=>e.tagName==="use",R=e=>E(e)&&typeof e.style<"u"&&!F(e),$e=e=>e.nodeType===8,Be=e=>e.nodeType===3,D=e=>e.tagName==="IMG",U=e=>e.tagName==="VIDEO",Le=e=>e.tagName==="CANVAS",Oe=e=>e.tagName==="TEXTAREA",Me=e=>e.tagName==="INPUT",We=e=>e.tagName==="STYLE",je=e=>e.tagName==="SCRIPT",qe=e=>e.tagName==="SELECT",He=e=>e.tagName==="SLOT",Ve=e=>e.tagName==="IFRAME",ze=(...e)=>console.warn(oe,...e);function Xe(e){const t=e?.createElement?.("canvas");return t&&(t.height=t.width=1),!!t&&"toDataURL"in t&&!!t.toDataURL("image/webp").includes("image/webp")}const O=e=>e.startsWith("data:");function le(e,t){if(e.match(/^[a-z]+:\/\//i))return e;if(N&&e.match(/^\/\//))return window.location.protocol+e;if(e.match(/^[a-z]+:/i)||!N)return e;const r=$().implementation.createHTMLDocument(),n=r.createElement("base"),a=r.createElement("a");return r.head.appendChild(n),r.body.appendChild(a),t&&(n.href=t),a.href=e,a.href}function $(e){return(e&&E(e)?e?.ownerDocument:e)??window.document}const B="http://www.w3.org/2000/svg";function ce(e,t,r){const n=$(r).createElementNS(B,"svg");return n.setAttributeNS(null,"width",e.toString()),n.setAttributeNS(null,"height",t.toString()),n.setAttributeNS(null,"viewBox",`0 0 ${e} ${t}`),n}function ue(e,t){let r=new XMLSerializer().serializeToString(e);return t&&(r=r.replace(/[\u0000-\u0008\v\f\u000E-\u001F\uD800-\uDFFF\uFFFE\uFFFF]/gu,"")),`data:image/svg+xml;charset=utf-8,${encodeURIComponent(r)}`}async function Ge(e,t="image/png",r=1){try{return await new Promise((n,a)=>{e.toBlob(s=>{s?n(s):a(new Error("Blob is null"))},t,r)})}catch(n){if(se)return Ye(e.toDataURL(t,r));throw n}}function Ye(e){const[t,r]=e.split(","),n=t.match(/data:(.+);/)?.[1]??void 0,a=window.atob(r),s=a.length,i=new Uint8Array(s);for(let o=0;o<s;o+=1)i[o]=a.charCodeAt(o);return new Blob([i],{type:n})}function fe(e,t){return new Promise((r,n)=>{const a=new FileReader;a.onload=()=>r(a.result),a.onerror=()=>n(a.error),a.onabort=()=>n(new Error(`Failed read blob to ${t}`)),t==="dataUrl"?a.readAsDataURL(e):t==="arrayBuffer"&&a.readAsArrayBuffer(e)})}const Je=e=>fe(e,"dataUrl"),Ke=e=>fe(e,"arrayBuffer");function A(e,t){const r=$(t).createElement("img");return r.decoding="sync",r.loading="eager",r.src=e,r}function I(e,t){return new Promise(r=>{const{timeout:n,ownerDocument:a,onError:s,onWarn:i}=t??{},o=typeof e=="string"?A(e,$(a)):e;let u=null,c=null;function l(){r(o),u&&clearTimeout(u),c?.()}if(n&&(u=setTimeout(l,n)),U(o)){const g=o.currentSrc||o.src;if(!g)return o.poster?I(o.poster,t).then(r):l();if(o.readyState>=2)return l();const d=l,m=h=>{i?.("Failed video load",g,h),s?.(h),l()};c=()=>{o.removeEventListener("loadeddata",d),o.removeEventListener("error",m)},o.addEventListener("loadeddata",d,{once:!0}),o.addEventListener("error",m,{once:!0})}else{const g=ie(o)?o.href.baseVal:o.currentSrc||o.src;if(!g)return l();const d=async()=>{if(D(o)&&"decode"in o)try{await o.decode()}catch(h){i?.("Failed to decode image, trying to render anyway",o.dataset.originalSrc||g,h)}l()},m=h=>{i?.("Failed image load",o.dataset.originalSrc||g,h),l()};if(D(o)&&o.complete)return d();c=()=>{o.removeEventListener("load",d),o.removeEventListener("error",m)},o.addEventListener("load",d,{once:!0}),o.addEventListener("error",m,{once:!0})}})}async function Qe(e,t){R(e)&&(D(e)||U(e)?await I(e,t):await Promise.all(["img","video"].flatMap(r=>Array.from(e.querySelectorAll(r)).map(n=>I(n,t)))))}const de=(function(){let t=0;const r=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(t+=1,`u${r()}${t}`)})();function ge(e){return e?.split(",").map(t=>t.trim().replace(/"|'/g,"").toLowerCase()).filter(Boolean)}let z=0;function Ze(e){const t=`${oe}[#${z}]`;return z++,{time:r=>e&&console.time(`${t} ${r}`),timeEnd:r=>e&&console.timeEnd(`${t} ${r}`),warn:(...r)=>e&&ze(...r)}}function et(e){return{cache:e?"no-cache":"force-cache"}}async function C(e,t){return Fe(e)?e:tt(e,{...t,autoDestruct:!0})}async function tt(e,t){const{scale:r=1,workerUrl:n,workerNumber:a=1}=t||{},s=!!t?.debug,i=t?.features??!0,o=e.ownerDocument??(N?window.document:void 0),u=e.ownerDocument?.defaultView??(N?window:void 0),c=new Map,l={width:0,height:0,quality:1,type:"image/png",scale:r,backgroundColor:null,style:null,filter:null,maximumCanvasSize:0,timeout:3e4,progress:null,debug:s,fetch:{requestInit:et(t?.fetch?.bypassingCache),placeholderImage:"data:image/png;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",bypassingCache:!1,...t?.fetch},fetchFn:null,font:{},drawImageInterval:100,workerUrl:null,workerNumber:a,onCloneEachNode:null,onCloneNode:null,onEmbedNode:null,onCreateForeignObjectSvg:null,includeStyleProperties:null,autoDestruct:!1,...t,__CONTEXT__:!0,log:Ze(s),node:e,ownerDocument:o,ownerWindow:u,dpi:r===1?null:96*r,svgStyleElement:me(o),svgDefsElement:o?.createElementNS(B,"defs"),svgStyles:new Map,defaultComputedStyles:new Map,workers:[...Array.from({length:Ie&&n&&a?a:0})].map(()=>{try{const m=new Worker(n);return m.onmessage=async h=>{const{url:f,result:w}=h.data;w?c.get(f)?.resolve?.(w):c.get(f)?.reject?.(new Error(`Error receiving message from worker: ${f}`))},m.onmessageerror=h=>{const{url:f}=h.data;c.get(f)?.reject?.(new Error(`Error receiving message from worker: ${f}`))},m}catch(m){return l.log.warn("Failed to new Worker",m),null}}).filter(Boolean),fontFamilies:new Map,fontCssTexts:new Map,acceptOfImage:`${[Xe(o)&&"image/webp","image/svg+xml","image/*","*/*"].filter(Boolean).join(",")};q=0.8`,requests:c,drawImageCount:0,tasks:[],features:i,isEnable:m=>m==="restoreScrollPosition"?typeof i=="boolean"?!1:i[m]??!1:typeof i=="boolean"?i:i[m]??!0,shadowRoots:[]};l.log.time("wait until load"),await Qe(e,{timeout:l.timeout,onWarn:l.log.warn}),l.log.timeEnd("wait until load");const{width:g,height:d}=rt(e,l);return l.width=g,l.height=d,l}function me(e){if(!e)return;const t=e.createElement("style"),r=t.ownerDocument.createTextNode(`
|
|
2
|
+
.______background-clip--text {
|
|
3
|
+
background-clip: text;
|
|
4
|
+
-webkit-background-clip: text;
|
|
5
|
+
}
|
|
6
|
+
`);return t.appendChild(r),t}function rt(e,t){let{width:r,height:n}=t;if(E(e)&&(!r||!n)){const a=e.getBoundingClientRect();r=r||a.width||Number(e.getAttribute("width"))||0,n=n||a.height||Number(e.getAttribute("height"))||0}return{width:r,height:n}}async function nt(e,t){const{log:r,timeout:n,drawImageCount:a,drawImageInterval:s}=t;r.time("image to canvas");const i=await I(e,{timeout:n,onWarn:t.log.warn}),{canvas:o,context2d:u}=ot(e.ownerDocument,t),c=()=>{try{u?.drawImage(i,0,0,o.width,o.height)}catch(l){t.log.warn("Failed to drawImage",l)}};if(c(),t.isEnable("fixSvgXmlDecode"))for(let l=0;l<a;l++)await new Promise(g=>{setTimeout(()=>{u?.clearRect(0,0,o.width,o.height),c(),g()},l+s)});return t.drawImageCount=0,r.timeEnd("image to canvas"),o}function ot(e,t){const{width:r,height:n,scale:a,backgroundColor:s,maximumCanvasSize:i}=t,o=e.createElement("canvas");o.width=Math.floor(r*a),o.height=Math.floor(n*a),o.style.width=`${r}px`,o.style.height=`${n}px`,i&&(o.width>i||o.height>i)&&(o.width>i&&o.height>i?o.width>o.height?(o.height*=i/o.width,o.width=i):(o.width*=i/o.height,o.height=i):o.width>i?(o.height*=i/o.width,o.width=i):(o.width*=i/o.height,o.height=i));const u=o.getContext("2d");return u&&s&&(u.fillStyle=s,u.fillRect(0,0,o.width,o.height)),{canvas:o,context2d:u}}function he(e,t){if(e.ownerDocument)try{const s=e.toDataURL();if(s!=="data:,")return A(s,e.ownerDocument)}catch(s){t.log.warn("Failed to clone canvas",s)}const r=e.cloneNode(!1),n=e.getContext("2d"),a=r.getContext("2d");try{return n&&a&&a.putImageData(n.getImageData(0,0,e.width,e.height),0,0),r}catch(s){t.log.warn("Failed to clone canvas",s)}return r}function st(e,t){try{if(e?.contentDocument?.documentElement)return q(e.contentDocument.documentElement,t)}catch(r){t.log.warn("Failed to clone iframe",r)}return e.cloneNode(!1)}function at(e){const t=e.cloneNode(!1);return e.currentSrc&&e.currentSrc!==e.src&&(t.src=e.currentSrc,t.srcset=""),t.loading==="lazy"&&(t.loading="eager"),t}async function it(e,t){if(e.ownerDocument&&!e.currentSrc&&e.poster)return A(e.poster,e.ownerDocument);const r=e.cloneNode(!1);r.crossOrigin="anonymous",e.currentSrc&&e.currentSrc!==e.src&&(r.src=e.currentSrc);const n=r.ownerDocument;if(n){let a=!0;if(await I(r,{onError:()=>a=!1,onWarn:t.log.warn}),!a)return e.poster?A(e.poster,e.ownerDocument):r;r.currentTime=e.currentTime,await new Promise(i=>{r.addEventListener("seeked",i,{once:!0})});const s=n.createElement("canvas");s.width=e.offsetWidth,s.height=e.offsetHeight;try{const i=s.getContext("2d");i&&i.drawImage(r,0,0,s.width,s.height)}catch(i){return t.log.warn("Failed to clone video",i),e.poster?A(e.poster,e.ownerDocument):r}return he(s,t)}return r}function lt(e,t){return Le(e)?he(e,t):Ve(e)?st(e,t):D(e)?at(e):U(e)?it(e,t):e.cloneNode(!1)}function ct(e){let t=e.sandbox;if(!t){const{ownerDocument:r}=e;try{r&&(t=r.createElement("iframe"),t.id=`__SANDBOX__${de()}`,t.width="0",t.height="0",t.style.visibility="hidden",t.style.position="fixed",r.body.appendChild(t),t.srcdoc='<!DOCTYPE html><meta charset="UTF-8"><title></title><body>',e.sandbox=t)}catch(n){e.log.warn("Failed to getSandBox",n)}}return t}const ut=["width","height","-webkit-text-fill-color"],ft=["stroke","fill"];function we(e,t,r){const{defaultComputedStyles:n}=r,a=e.nodeName.toLowerCase(),s=F(e)&&a!=="svg",i=s?ft.map(f=>[f,e.getAttribute(f)]).filter(([,f])=>f!==null):[],o=[s&&"svg",a,i.map((f,w)=>`${f}=${w}`).join(","),t].filter(Boolean).join(":");if(n.has(o))return n.get(o);const c=ct(r)?.contentWindow;if(!c)return new Map;const l=c?.document;let g,d;s?(g=l.createElementNS(B,"svg"),d=g.ownerDocument.createElementNS(g.namespaceURI,a),i.forEach(([f,w])=>{d.setAttributeNS(null,f,w)}),g.appendChild(d)):g=d=l.createElement(a),d.textContent=" ",l.body.appendChild(g);const m=c.getComputedStyle(d,t),h=new Map;for(let f=m.length,w=0;w<f;w++){const p=m.item(w);ut.includes(p)||h.set(p,m.getPropertyValue(p))}return l.body.removeChild(g),n.set(o,h),h}function pe(e,t,r){const n=new Map,a=[],s=new Map;if(r)for(const o of r)i(o);else for(let o=e.length,u=0;u<o;u++){const c=e.item(u);i(c)}for(let o=a.length,u=0;u<o;u++)s.get(a[u])?.forEach((c,l)=>n.set(l,c));function i(o){const u=e.getPropertyValue(o),c=e.getPropertyPriority(o),l=o.lastIndexOf("-"),g=l>-1?o.substring(0,l):void 0;if(g){let d=s.get(g);d||(d=new Map,s.set(g,d)),d.set(o,[u,c])}t.get(o)===u&&!c||(g?a.push(g):n.set(o,[u,c]))}return n}function dt(e,t,r,n){const{ownerWindow:a,includeStyleProperties:s,currentParentNodeStyle:i}=n,o=t.style,u=a.getComputedStyle(e),c=we(e,null,n);i?.forEach((g,d)=>{c.delete(d)});const l=pe(u,c,s);l.delete("transition-property"),l.delete("all"),l.delete("d"),l.delete("content"),r&&(l.delete("position"),l.delete("margin-top"),l.delete("margin-right"),l.delete("margin-bottom"),l.delete("margin-left"),l.delete("margin-block-start"),l.delete("margin-block-end"),l.delete("margin-inline-start"),l.delete("margin-inline-end"),l.set("box-sizing",["border-box",""])),l.get("background-clip")?.[0]==="text"&&t.classList.add("______background-clip--text"),ae&&(l.has("font-kerning")||l.set("font-kerning",["normal",""]),(l.get("overflow-x")?.[0]==="hidden"||l.get("overflow-y")?.[0]==="hidden")&&l.get("text-overflow")?.[0]==="ellipsis"&&e.scrollWidth===e.clientWidth&&l.set("text-overflow",["clip",""]));for(let g=o.length,d=0;d<g;d++)o.removeProperty(o.item(d));return l.forEach(([g,d],m)=>{o.setProperty(m,g,d)}),l}function gt(e,t){(Oe(e)||Me(e)||qe(e))&&t.setAttribute("value",e.value)}const mt=["::before","::after"],ht=["::-webkit-scrollbar","::-webkit-scrollbar-button","::-webkit-scrollbar-thumb","::-webkit-scrollbar-track","::-webkit-scrollbar-track-piece","::-webkit-scrollbar-corner","::-webkit-resizer"];function wt(e,t,r,n,a){const{ownerWindow:s,svgStyleElement:i,svgStyles:o,currentNodeStyle:u}=n;if(!i||!s)return;function c(l){const g=s.getComputedStyle(e,l);let d=g.getPropertyValue("content");if(!d||d==="none")return;a?.(d),d=d.replace(/(')|(")|(counter\(.+\))/g,"");const m=[de()],h=we(e,l,n);u?.forEach((y,S)=>{h.delete(S)});const f=pe(g,h,n.includeStyleProperties);f.delete("content"),f.delete("-webkit-locale"),f.get("background-clip")?.[0]==="text"&&t.classList.add("______background-clip--text");const w=[`content: '${d}';`];if(f.forEach(([y,S],T)=>{w.push(`${T}: ${y}${S?" !important":""};`)}),w.length===1)return;try{t.className=[t.className,...m].join(" ")}catch(y){n.log.warn("Failed to copyPseudoClass",y);return}const p=w.join(`
|
|
7
|
+
`);let b=o.get(p);b||(b=[],o.set(p,b)),b.push(`.${m[0]}${l}`)}mt.forEach(c),r&&ht.forEach(c)}const X=new Set(["symbol"]);async function G(e,t,r,n,a){if(E(r)&&(We(r)||je(r))||n.filter&&!n.filter(r))return;X.has(t.nodeName)||X.has(r.nodeName)?n.currentParentNodeStyle=void 0:n.currentParentNodeStyle=n.currentNodeStyle;const s=await q(r,n,!1,a);n.isEnable("restoreScrollPosition")&&pt(e,s),t.appendChild(s)}async function Y(e,t,r,n){let a=e.firstChild;E(e)&&e.shadowRoot&&(a=e.shadowRoot?.firstChild,r.shadowRoots.push(e.shadowRoot));for(let s=a;s;s=s.nextSibling)if(!$e(s))if(E(s)&&He(s)&&typeof s.assignedNodes=="function"){const i=s.assignedNodes();for(let o=0;o<i.length;o++)await G(e,t,i[o],r,n)}else await G(e,t,s,r,n)}function pt(e,t){if(!R(e)||!R(t))return;const{scrollTop:r,scrollLeft:n}=e;if(!r&&!n)return;const{transform:a}=t.style,s=new DOMMatrix(a),{a:i,b:o,c:u,d:c}=s;s.a=1,s.b=0,s.c=0,s.d=1,s.translateSelf(-n,-r),s.a=i,s.b=o,s.c=u,s.d=c,t.style.transform=s.toString()}function yt(e,t){const{backgroundColor:r,width:n,height:a,style:s}=t,i=e.style;if(r&&i.setProperty("background-color",r,"important"),n&&i.setProperty("width",`${n}px`,"important"),a&&i.setProperty("height",`${a}px`,"important"),s)for(const o in s)i[o]=s[o]}const bt=/^[\w-:]+$/;async function q(e,t,r=!1,n){const{ownerDocument:a,ownerWindow:s,fontFamilies:i,onCloneEachNode:o}=t;if(a&&Be(e))return n&&/\S/.test(e.data)&&n(e.data),a.createTextNode(e.data);if(a&&s&&E(e)&&(R(e)||F(e))){const c=await lt(e,t);if(t.isEnable("removeAbnormalAttributes")){const f=c.getAttributeNames();for(let w=f.length,p=0;p<w;p++){const b=f[p];bt.test(b)||c.removeAttribute(b)}}const l=t.currentNodeStyle=dt(e,c,r,t);r&&yt(c,t);let g=!1;if(t.isEnable("copyScrollbar")){const f=[l.get("overflow-x")?.[0],l.get("overflow-y")?.[0]];g=f.includes("scroll")||(f.includes("auto")||f.includes("overlay"))&&(e.scrollHeight>e.clientHeight||e.scrollWidth>e.clientWidth)}const d=l.get("text-transform")?.[0],m=ge(l.get("font-family")?.[0]),h=m?f=>{d==="uppercase"?f=f.toUpperCase():d==="lowercase"?f=f.toLowerCase():d==="capitalize"&&(f=f[0].toUpperCase()+f.substring(1)),m.forEach(w=>{let p=i.get(w);p||i.set(w,p=new Set),f.split("").forEach(b=>p.add(b))})}:void 0;return wt(e,c,g,t,h),gt(e,c),U(e)||await Y(e,c,t,h),await o?.(c),c}const u=e.cloneNode(!1);return await Y(e,u,t),await o?.(u),u}function St(e){if(e.ownerDocument=void 0,e.ownerWindow=void 0,e.svgStyleElement=void 0,e.svgDefsElement=void 0,e.svgStyles.clear(),e.defaultComputedStyles.clear(),e.sandbox){try{e.sandbox.remove()}catch(t){e.log.warn("Failed to destroyContext",t)}e.sandbox=void 0}e.workers=[],e.fontFamilies.clear(),e.fontCssTexts.clear(),e.requests.clear(),e.tasks=[],e.shadowRoots=[]}function Et(e){const{url:t,timeout:r,responseType:n,...a}=e,s=new AbortController,i=r?setTimeout(()=>s.abort(),r):void 0;return fetch(t,{signal:s.signal,...a}).then(o=>{if(!o.ok)throw new Error("Failed fetch, not 2xx response",{cause:o});switch(n){case"arrayBuffer":return o.arrayBuffer();case"dataUrl":return o.blob().then(Je);default:return o.text()}}).finally(()=>clearTimeout(i))}function k(e,t){const{url:r,requestType:n="text",responseType:a="text",imageDom:s}=t;let i=r;const{timeout:o,acceptOfImage:u,requests:c,fetchFn:l,fetch:{requestInit:g,bypassingCache:d,placeholderImage:m},font:h,workers:f,fontFamilies:w}=e;n==="image"&&(_||j)&&e.drawImageCount++;let p=c.get(r);if(!p){d&&d instanceof RegExp&&d.test(i)&&(i+=(/\?/.test(i)?"&":"?")+new Date().getTime());const b=n.startsWith("font")&&h&&h.minify,y=new Set;b&&n.split(";")[1].split(",").forEach(P=>{w.has(P)&&w.get(P).forEach(V=>y.add(V))});const S=b&&y.size,T={url:i,timeout:o,responseType:S?"arrayBuffer":a,headers:n==="image"?{accept:u}:void 0,...g};p={type:n,resolve:void 0,reject:void 0,response:null},p.response=(async()=>{if(l&&n==="image"){const v=await l(r);if(v)return v}return!_&&r.startsWith("http")&&f.length?new Promise((v,P)=>{f[c.size&f.length-1].postMessage({rawUrl:r,...T}),p.resolve=v,p.reject=P}):Et(T)})().catch(v=>{if(c.delete(r),n==="image"&&m)return e.log.warn("Failed to fetch image base64, trying to use placeholder image",i),typeof m=="string"?m:m(s);throw v}),c.set(r,p)}return p.response}async function ye(e,t,r,n){if(!be(e))return e;for(const[a,s]of Ct(e,t))try{const i=await k(r,{url:s,requestType:n?"image":"text",responseType:"dataUrl"});e=e.replace(vt(a),`$1${i}$3`)}catch(i){r.log.warn("Failed to fetch css data url",a,i)}return e}function be(e){return/url\((['"]?)([^'"]+?)\1\)/.test(e)}const Se=/url\((['"]?)([^'"]+?)\1\)/g;function Ct(e,t){const r=[];return e.replace(Se,(n,a,s)=>(r.push([s,le(s,t)]),n)),r.filter(([n])=>!O(n))}function vt(e){const t=e.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,"g")}const Tt=["background-image","border-image-source","-webkit-border-image","-webkit-mask-image","list-style-image"];function Nt(e,t){return Tt.map(r=>{const n=e.getPropertyValue(r);return!n||n==="none"?null:((_||j)&&t.drawImageCount++,ye(n,null,t,!0).then(a=>{!a||n===a||e.setProperty(r,a,e.getPropertyPriority(r))}))}).filter(Boolean)}function At(e,t){if(D(e)){const r=e.currentSrc||e.src;if(!O(r))return[k(t,{url:r,imageDom:e,requestType:"image",responseType:"dataUrl"}).then(n=>{n&&(e.srcset="",e.dataset.originalSrc=r,e.src=n||"")})];(_||j)&&t.drawImageCount++}else if(F(e)&&!O(e.href.baseVal)){const r=e.href.baseVal;return[k(t,{url:r,imageDom:e,requestType:"image",responseType:"dataUrl"}).then(n=>{n&&(e.dataset.originalSrc=r,e.href.baseVal=n||"")})]}return[]}function Dt(e,t){const{ownerDocument:r,svgDefsElement:n}=t,a=e.getAttribute("href")??e.getAttribute("xlink:href");if(!a)return[];const[s,i]=a.split("#");if(i){const o=`#${i}`,u=t.shadowRoots.reduce((c,l)=>c??l.querySelector(`svg ${o}`),r?.querySelector(`svg ${o}`));if(s&&e.setAttribute("href",o),n?.querySelector(o))return[];if(u)return n?.appendChild(u.cloneNode(!0)),[];if(s)return[k(t,{url:s,responseType:"text"}).then(c=>{n?.insertAdjacentHTML("beforeend",c)})]}return[]}function Ee(e,t){const{tasks:r}=t;E(e)&&((D(e)||ie(e))&&r.push(...At(e,t)),Ue(e)&&r.push(...Dt(e,t))),R(e)&&r.push(...Nt(e.style,t)),e.childNodes.forEach(n=>{Ee(n,t)})}async function Rt(e,t){const{ownerDocument:r,svgStyleElement:n,fontFamilies:a,fontCssTexts:s,tasks:i,font:o}=t;if(!(!r||!n||!a.size))if(o&&o.cssText){const u=K(o.cssText,t);n.appendChild(r.createTextNode(`${u}
|
|
8
|
+
`))}else{const u=Array.from(r.styleSheets).filter(m=>{try{return"cssRules"in m&&!!m.cssRules.length}catch(h){return t.log.warn(`Error while reading CSS rules from ${m.href}`,h),!1}}),c=r.implementation.createHTMLDocument(""),l=c.createElement("style");c.head.appendChild(l);const g=l.sheet;await Promise.all(u.flatMap(m=>Array.from(m.cssRules).map(async h=>{if(Pe(h)){const f=h.href;let w="";try{w=await k(t,{url:f,requestType:"text",responseType:"text"})}catch(b){t.log.warn(`Error fetch remote css import from ${f}`,b)}const p=w.replace(Se,(b,y,S)=>b.replace(S,le(S,f)));for(const b of kt(p))try{g.insertRule(b,g.cssRules.length)}catch(y){t.log.warn("Error inserting rule from remote css import",{rule:b,error:y})}}}))),g.cssRules.length&&u.push(g);const d=[];u.forEach(m=>{M(m.cssRules,d)}),d.filter(m=>xe(m)&&be(m.style.getPropertyValue("src"))&&ge(m.style.getPropertyValue("font-family"))?.some(h=>a.has(h))).forEach(m=>{const h=m,f=s.get(h.cssText);f?n.appendChild(r.createTextNode(`${f}
|
|
9
|
+
`)):i.push(ye(h.cssText,h.parentStyleSheet?h.parentStyleSheet.href:null,t).then(w=>{w=K(w,t),s.set(h.cssText,w),n.appendChild(r.createTextNode(`${w}
|
|
10
|
+
`))}))})}}const It=/(\/\*[\s\S]*?\*\/)/g,J=/((@.*?keyframes [\s\S]*?){([\s\S]*?}\s*?)})/gi;function kt(e){if(e==null)return[];const t=[];let r=e.replace(It,"");for(;;){const s=J.exec(r);if(!s)break;t.push(s[0])}r=r.replace(J,"");const n=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,a=new RegExp("((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})","gi");for(;;){let s=n.exec(r);if(s)a.lastIndex=n.lastIndex;else if(s=a.exec(r),s)n.lastIndex=a.lastIndex;else break;t.push(s[0])}return t}const Ft=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,xt=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function K(e,t){const{font:r}=t,n=r?r?.preferredFormat:void 0;return n?e.replace(xt,a=>{for(;;){const[s,,i]=Ft.exec(a)||[];if(!i)return"";if(i===n)return`src: ${s};`}}):e}function M(e,t=[]){for(const r of Array.from(e))_e(r)?t.push(...M(r.cssRules)):"cssRules"in r?M(r.cssRules,t):t.push(r);return t}const Pt=/\bx?link:?href\s*=\s*["'](?!data:)[^"']+["']/i;function _t(e){return Pt.test(e.innerHTML)}async function Ut(e,t){const r=await C(e,t);if(E(r.node)&&F(r.node)&&!_t(r.node))return r.node;const{ownerDocument:n,log:a,tasks:s,svgStyleElement:i,svgDefsElement:o,svgStyles:u,font:c,progress:l,autoDestruct:g,onCloneNode:d,onEmbedNode:m,onCreateForeignObjectSvg:h}=r;a.time("clone node");const f=await q(r.node,r,!0);if(i&&n){let S="";u.forEach((T,v)=>{S+=`${T.join(`,
|
|
11
|
+
`)} {
|
|
12
|
+
${v}
|
|
13
|
+
}
|
|
14
|
+
`}),i.appendChild(n.createTextNode(S))}a.timeEnd("clone node"),await d?.(f),c!==!1&&E(f)&&(a.time("embed web font"),await Rt(f,r),a.timeEnd("embed web font")),a.time("embed node"),Ee(f,r);const w=s.length;let p=0;const b=async()=>{for(;;){const S=s.pop();if(!S)break;try{await S}catch(T){r.log.warn("Failed to run task",T)}l?.(++p,w)}};l?.(p,w),await Promise.all([...Array.from({length:4})].map(b)),a.timeEnd("embed node"),await m?.(f);const y=$t(f,r);return o&&y.insertBefore(o,y.children[0]),i&&y.insertBefore(i,y.children[0]),g&&St(r),await h?.(y),y}function $t(e,t){const{width:r,height:n}=t,a=ce(r,n,e.ownerDocument),s=a.ownerDocument.createElementNS(a.namespaceURI,"foreignObject");return s.setAttributeNS(null,"x","0%"),s.setAttributeNS(null,"y","0%"),s.setAttributeNS(null,"width","100%"),s.setAttributeNS(null,"height","100%"),s.append(e),a.appendChild(s),a}async function H(e,t){const r=await C(e,t),n=await Ut(r),a=ue(n,r.isEnable("removeControlCharacter"));r.autoDestruct||(r.svgStyleElement=me(r.ownerDocument),r.svgDefsElement=r.ownerDocument?.createElementNS(B,"defs"),r.svgStyles.clear());const s=A(a,n.ownerDocument);return await nt(s,r)}async function Lt(e,t){const r=await C(e,t),{log:n,type:a,quality:s,dpi:i}=r,o=await H(r);n.time("canvas to blob");const u=await Ge(o,a,s);if(["image/png","image/jpeg"].includes(a)&&i){const c=await Ke(u.slice(0,33));let l=new Uint8Array(c);return a==="image/png"?l=ne(l,i):a==="image/jpeg"&&(l=Q(l,i)),n.timeEnd("canvas to blob"),new Blob([l,u.slice(33)],{type:a})}return n.timeEnd("canvas to blob"),u}async function x(e,t){const r=await C(e,t),{log:n,quality:a,type:s,dpi:i}=r,o=await H(r);n.time("canvas to data url");let u=o.toDataURL(s,a);if(["image/png","image/jpeg"].includes(s)&&i&&se&&ke){const[c,l]=u.split(",");let g=0,d=!1;if(s==="image/png"){const y=Re(l);y>=0?(g=Math.ceil((y+28)/3)*4,d=!0):g=33/3*4}else s==="image/jpeg"&&(g=18/3*4);const m=l.substring(0,g),h=l.substring(g),f=window.atob(m),w=new Uint8Array(f.length);for(let y=0;y<w.length;y++)w[y]=f.charCodeAt(y);const p=s==="image/png"?ne(w,i,d):Q(w,i),b=window.btoa(String.fromCharCode(...p));u=[c,",",b,h].join("")}return n.timeEnd("canvas to data url"),u}async function Bt(e,t){const r=await C(e,t),{width:n,height:a,ownerDocument:s}=r,i=await x(r),o=ce(n,a,s),u=o.ownerDocument.createElementNS(o.namespaceURI,"image");return u.setAttributeNS(null,"href",i),u.setAttributeNS(null,"height","100%"),u.setAttributeNS(null,"width","100%"),o.appendChild(u),ue(o,r.isEnable("removeControlCharacter"))}async function Ot(e,t){const r=await C(e,t),{ownerDocument:n,width:a,height:s,scale:i,type:o}=r,u=o==="image/svg+xml"?await Bt(r):await x(r),c=A(u,n);return c.width=Math.floor(a*i),c.height=Math.floor(s*i),c.style.width=`${a}px`,c.style.height=`${s}px`,c}async function Mt(e,t){return x(await C(e,{...t,type:"image/jpeg"}))}async function Wt(e,t){const r=await C(e,t),n=await H(r);return n.getContext("2d").getImageData(0,0,n.width,n.height).data}async function jt(e,t){return x(await C(e,{...t,type:"image/png"}))}async function qt(e,t){return x(await C(e,{...t,type:"image/webp"}))}export{tt as createContext,St as destroyContext,Lt as domToBlob,H as domToCanvas,x as domToDataUrl,Ut as domToForeignObjectSvg,Ot as domToImage,Mt as domToJpeg,Wt as domToPixel,jt as domToPng,Bt as domToSvg,qt as domToWebp,I as loadMedia,Qe as waitUntilLoad};
|