@zumer/snapdom 1.9.5 → 1.9.6-dev.0
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/dist/snapdom.js +114 -109
- package/dist/snapdom.min.js +7 -7
- package/dist/snapdom.min.mjs +12 -12
- package/dist/snapdom.mjs +113 -108
- package/package.json +1 -1
package/dist/snapdom.min.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
(()=>{var
|
|
2
|
-
`;return o}function gt(t){let e=new Set(t.values()),o=new Map,i=1;for(let r of e)o.set(r,`c${i++}`);return o}function j(o){return p(this,arguments,function*(t,e={}){let i=t.match(/url\(["']?(.*?)["']?\)/),r=i==null?void 0:i[1],n=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t);if(r){let f=G(r);if(M.has(f))return e.skipInline?void 0:`url(${M.get(f)})`;{let c=yield F(f,{useProxy:e.useProxy});return M.set(f,c),e.skipInline?void 0:`url("${c}")`}}return t})}function V(t,{fast:e=!1}={}){if(e)return t();"requestIdleCallback"in window?requestIdleCallback(t,{timeout:50}):setTimeout(t,1)}function U(t,e=null){if(!(t instanceof Element))return window.getComputedStyle(t,e);let o=Z.get(t);if(o||(o=new Map,Z.set(t,o)),!o.has(e)){let i=window.getComputedStyle(t,e);o.set(e,i)}return o.get(e)}function yt(t){let e=t.replace(/^['"]|['"]$/g,"");if(e.startsWith("\\"))try{return String.fromCharCode(parseInt(e.replace("\\",""),16))}catch(o){return e}return e}function Y(t){let e=t.indexOf("url(");if(e===-1)return null;let o=t.slice(e+4).trim();return o.endsWith(")")&&(o=o.slice(0,-1).trim()),(o.startsWith('"')&&o.endsWith('"')||o.startsWith("'")&&o.endsWith("'"))&&(o=o.slice(1,-1)),o}function F(t,{timeout:e=3e3,useProxy:o=""}={}){function i(a){try{return new URL(a,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch(d){return"anonymous"}}function r(a){return p(this,null,function*(){let d=l=>fetch(l,{mode:"cors",credentials:i(l)==="use-credentials"?"include":"omit"}).then(s=>s.blob()).then(s=>new Promise((h,m)=>{let u=new FileReader;u.onloadend=()=>{let g=u.result;if(typeof g!="string"||!g.startsWith("data:image/")){m(new Error("Invalid image data URL"));return}h(g)},u.onerror=()=>m(new Error("FileReader error")),u.readAsDataURL(s)}));try{return yield d(a)}catch(l){if(o&&typeof o=="string"){let s=o.replace(/\/$/,"")+G(a);try{return yield d(s)}catch(h){throw console.error(`[SnapDOM - fetchImage] Proxy fallback failed for: ${a}`),new Error("CORS restrictions prevented image capture (even via proxy)")}}else throw console.error(`[SnapDOM - fetchImage] No valid proxy URL provided for fallback: ${a}`),new Error("Fetch fallback failed and no proxy provided")}})}let n=i(t);return console.log(`[SnapDOM - fetchImage] Start loading image: ${t} with crossOrigin=${n}`),R.has(t)?(console.log(`[SnapDOM - fetchImage] Cache hit for: ${t}`),Promise.resolve(R.get(t))):t.startsWith("data:image/")?(R.set(t,t),Promise.resolve(t)):/\.svg(\?.*)?$/i.test(t)?p(null,null,function*(){try{let d=yield(yield fetch(t,{mode:"cors",credentials:n==="use-credentials"?"include":"omit"})).text(),l=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(d)}`;return R.set(t,l),l}catch(a){return r(t)}}):new Promise((a,d)=>{let l=setTimeout(()=>{console.log(`[SnapDOM - fetchImage] Timeout after ${e}ms for image: ${t}`),d(new Error("Image load timed out"))},e),s=new Image;s.crossOrigin=n,s.onload=()=>p(null,null,function*(){clearTimeout(l);try{yield s.decode();let h=document.createElement("canvas");h.width=s.width,h.height=s.height,h.getContext("2d").drawImage(s,0,0,h.width,h.height);let u=h.toDataURL("image/png");R.set(t,u),a(u)}catch(h){try{let m=yield r(t);R.set(t,m),a(m)}catch(m){d(m)}}}),s.onerror=()=>p(null,null,function*(){clearTimeout(l),console.error(`[SnapDOM - fetchImage] Image failed to load: ${t}`);try{let h=yield r(t);R.set(t,h),a(h)}catch(h){d(h)}}),s.src=t})}function tt(t){let e={};for(let o of t)e[o]=t.getPropertyValue(o);return e}function K(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function wt(t){if(!t||t==="none")return"";let e=t.replace(/translate[XY]?\([^)]*\)/g,"");return e=e.replace(/matrix\(([^)]+)\)/g,(o,i)=>{let r=i.split(",").map(n=>n.trim());return r.length!==6?`matrix(${i})`:(r[4]="0",r[5]="0",`matrix(${r.join(", ")})`)}),e=e.replace(/matrix3d\(([^)]+)\)/g,(o,i)=>{let r=i.split(",").map(n=>n.trim());return r.length!==16?`matrix3d(${i})`:(r[12]="0",r[13]="0",`matrix3d(${r.join(", ")})`)}),e.trim().replace(/\s{2,}/g," ")}function G(t){if(/%[0-9A-Fa-f]{2}/.test(t))return t;try{return encodeURI(t)}catch(e){return t}}function _(t){let e=[],o=0,i=0;for(let r=0;r<t.length;r++){let n=t[r];n==="("&&o++,n===")"&&o--,n===","&&o===0&&(e.push(t.slice(i,r).trim()),i=r+1)}return e.push(t.slice(i).trim()),e}var et=new WeakMap,nt=new Map;function Dt(t){let e={};for(let o=0;o<t.length;o++){let i=t[o],r=t.getPropertyValue(i);(i==="background-image"||i==="content")&&r.includes("url(")&&!r.includes("data:")&&(r="none"),e[i]=r}return e}function ot(t,e,o,i,r){var l;if(t.tagName==="STYLE")return;i.has(t)||i.set(t,U(t));let n=i.get(t);if(!et.has(t)){let s=Dt(n);et.set(t,s)}let f=et.get(t),c=Object.entries(f).sort(([s],[h])=>s.localeCompare(h)).map(([s,h])=>`${s}:${h}`).join(";");if(nt.has(c)){o.set(e,nt.get(c));return}let a=((l=t.tagName)==null?void 0:l.toLowerCase())||"div",d=z(f,a,r);nt.set(c,d),o.set(e,d)}function Mt(t){return t.nodeType===Node.ELEMENT_NODE&&t.tagName==="SLOT"}function H(t,e,o,i,r,n={},f){var a,d;if(t.nodeType===Node.TEXT_NODE||t.nodeType!==Node.ELEMENT_NODE)return t.cloneNode(!0);if(t.getAttribute("data-capture")==="exclude"){let l=document.createElement("div"),s=t.getBoundingClientRect();return l.style.cssText=`display: inline-block; width: ${s.width}px; height: ${s.height}px; visibility: hidden;`,l}if(n.exclude&&Array.isArray(n.exclude))for(let l of n.exclude)try{if((a=t.matches)!=null&&a.call(t,l)){let s=document.createElement("div"),h=t.getBoundingClientRect();return s.style.cssText=`display: inline-block; width: ${h.width}px; height: ${h.height}px; visibility: hidden;`,s}}catch(s){console.warn(`Invalid selector in exclude option: ${l}`,s)}if(typeof n.filter=="function")try{if(!n.filter(t,f||t)){let l=document.createElement("div"),s=t.getBoundingClientRect();return l.style.cssText=`display: inline-block; width: ${s.width}px; height: ${s.height}px; visibility: hidden;`,l}}catch(l){console.warn("Error in filter function:",l)}if(t.tagName==="IFRAME"){let l=document.createElement("div");return l.textContent="",l.style.cssText=`width: ${t.offsetWidth}px; height: ${t.offsetHeight}px; background-image: repeating-linear-gradient(45deg, #ddd, #ddd 5px, #f9f9f9 5px, #f9f9f9 10px);display: flex;align-items: center;justify-content: center;font-size: 12px;color: #555; border: 1px solid #aaa;`,l}if(t.getAttribute("data-capture")==="placeholder"){let l=t.cloneNode(!1);i.set(l,t),ot(t,l,e,o,r);let s=document.createElement("div");return s.textContent=t.getAttribute("data-placeholder-text")||"",s.style.cssText="color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;",l.appendChild(s),l}if(t.tagName==="CANVAS"){let l=t.toDataURL(),s=document.createElement("img");return s.src=l,s.width=t.width,s.height=t.height,s.style.display="inline-block",s.style.width=t.style.width||`${t.width}px`,s.style.height=t.style.height||`${t.height}px`,s}let c=t.cloneNode(!1);if(i.set(c,t),t instanceof HTMLInputElement)c.value=t.value,c.setAttribute("value",t.value),t.checked!==void 0&&(c.checked=t.checked,t.checked&&c.setAttribute("checked",""));else if(t instanceof HTMLTextAreaElement){let l=t.getBoundingClientRect();c.textContent=t.value,c.style.width=`${l.width}px`,c.style.height=`${l.height}px`}else t instanceof HTMLSelectElement&&(c.value=t.value,Array.from(c.options).forEach(l=>{l.value===t.value?l.setAttribute("selected",""):l.removeAttribute("selected")}));if(ot(t,c,e,o,r),Mt(t)){let l=((d=t.assignedNodes)==null?void 0:d.call(t,{flatten:!0}))||[],s=l.length>0?l:Array.from(t.childNodes),h=document.createDocumentFragment();for(let m of s){let u=H(m,e,o,i,r,n,f||t);u&&h.appendChild(u)}return h}else if(!(t instanceof HTMLTextAreaElement)){let l=t.shadowRoot?t.shadowRoot.childNodes:t.childNodes;for(let s of l){let h=H(s,e,o,i,r,n,f||t);h&&c.appendChild(h)}if(t.shadowRoot&&t.childNodes.length>0&&!t.shadowRoot.querySelector("slot")){let s=document.createDocumentFragment();for(let h of t.childNodes){let m=H(h,e,o,i,r,n,f||t);m&&s.appendChild(m)}c.appendChild(s)}}return c}var Ot=[/font\s*awesome/i,/material\s*icons/i,/ionicons/i,/glyphicons/i,/feather/i,/bootstrap\s*icons/i,/remix\s*icons/i,/heroicons/i,/layui/i,/lucide/i],at=[];function xt(t){let e=Array.isArray(t)?t:[t];for(let o of e)o instanceof RegExp?at.push(o):typeof o=="string"?at.push(new RegExp(o,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",o)}function T(t){let e=typeof t=="string"?t:"",o=[...Ot,...at];for(let i of o)if(i instanceof RegExp&&i.test(e))return!0;return!!(/icon/i.test(e)||/glyph/i.test(e)||/symbols/i.test(e)||/feather/i.test(e)||/fontawesome/i.test(e))}function bt(t,e,o,i=32,r="#000"){return p(this,null,function*(){e=e.replace(/^['"]+|['"]+$/g,"");let n=window.devicePixelRatio||1,c=document.createElement("canvas").getContext("2d");c.font=o?`${o} ${i}px "${e}"`:`${i}px "${e}"`;let a=c.measureText(t),d=a.actualBoundingBoxAscent||i*.8,l=a.actualBoundingBoxDescent||i*.2,s=d+l,h=a.width,m=document.createElement("canvas");m.width=Math.ceil(h*n),m.height=Math.ceil(s*n);let u=m.getContext("2d");return u.scale(n,n),u.font=c.font,u.textAlign="left",u.textBaseline="alphabetic",u.fillStyle=r,u.fillText(t,0,d),m.toDataURL()})}function Ct(t){return Array.from(document.styleSheets).some(e=>e.href===t)}function Wt(t){return new Promise(e=>{if(Ct(t))return e(null);let o=document.createElement("link");o.rel="stylesheet",o.href=t,o.setAttribute("data-snapdom","injected-import"),o.onload=()=>e(o),o.onerror=()=>e(null),document.head.appendChild(o)})}function J(){return p(this,arguments,function*({preCached:t=!1}={}){if($.has("fonts-embed-css")){if(t){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=$.get("fonts-embed-css"),document.head.appendChild(n)}return $.get("fonts-embed-css")}let e=/@import\s+url\(["']?([^"')]+)["']?\)/g,o=[];for(let n of document.querySelectorAll("style")){let f=n.textContent||"",c=Array.from(f.matchAll(e));for(let a of c){let d=a[1];T(d)||Ct(d)||o.push(d)}}yield Promise.all(o.map(Wt));let i=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(n=>n.href),r="";for(let n of i)try{let c=yield(yield fetch(n.href)).text();if(T(n.href)||T(c))continue;let a=/url\((["']?)([^"')]+)\1\)/g,d=yield Promise.all(Array.from(c.matchAll(a)).map(s=>p(null,null,function*(){let h=Y(s[0]);if(!h)return null;let m=h;if(!m.startsWith("http")&&!m.startsWith("data:")&&(m=new URL(m,n.href).href),T(m))return null;if($.has(m))return A.add(m),{original:s[0],inlined:`url(${$.get(m)})`};if(A.has(m))return null;try{let g=yield(yield fetch(m)).blob(),y=yield new Promise(b=>{let w=new FileReader;w.onload=()=>b(w.result),w.readAsDataURL(g)});return $.set(m,y),A.add(m),{original:s[0],inlined:`url(${y})`}}catch(u){return console.warn("[snapdom] Failed to fetch font resource:",m),null}}))),l=c;for(let s of d)s&&(l=l.replace(s.original,s.inlined));r+=l+`
|
|
3
|
-
`}catch(f){console.warn("[snapdom] Failed to fetch CSS:",n.href)}for(let n of document.styleSheets)try{if(!n.href||i.every(f=>f.href!==n.href)){for(let f of n.cssRules)if(f.type===CSSRule.FONT_FACE_RULE){let
|
|
4
|
-
font-family: ${
|
|
5
|
-
src: ${
|
|
1
|
+
(()=>{var ke=Object.defineProperty;var _=Object.getOwnPropertySymbols;var ee=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable;var Z=(e,t,a)=>t in e?ke(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,M=(e,t)=>{for(var a in t||(t={}))ee.call(t,a)&&Z(e,a,t[a]);if(_)for(var a of _(t))te.call(t,a)&&Z(e,a,t[a]);return e};var ne=(e,t)=>{var a={};for(var i in e)ee.call(e,i)&&t.indexOf(i)<0&&(a[i]=e[i]);if(e!=null&&_)for(var i of _(e))t.indexOf(i)<0&&te.call(e,i)&&(a[i]=e[i]);return a};var h=(e,t,a)=>new Promise((i,s)=>{var n=o=>{try{r(a.next(o))}catch(c){s(c)}},f=o=>{try{r(a.throw(o))}catch(c){s(c)}},r=o=>o.done?i(o.value):Promise.resolve(o.value).then(n,f);r((a=a.apply(e,t)).next())});var l={image:new Map,background:new Map,resource:new Map,defaultStyle:new Map,baseStyle:new Map,computedStyle:new WeakMap,font:new Set,snapshot:new WeakMap,snapshotKey:new Map,preStyleMap:new Map,preStyle:new WeakMap,preNodeMap:new Map,reset:Ie};function Ie(){l.computedStyle=new WeakMap,l.snapshot=new WeakMap,l.snapshotKey.clear(),l.preStyleMap.clear(),l.preStyle=new WeakMap,l.preNodeMap.clear()}var Re=["div","span","p","a","img","ul","li","button","input","select","textarea","label","section","article","header","footer","nav","main","aside","h1","h2","h3","h4","h5","h6","svg","path","circle","rect","line","g","table","thead","tbody","tr","td","th"];function oe(){for(let e of Re)ae(e)}function ae(e){if(l.defaultStyle.has(e))return l.defaultStyle.get(e);if(new Set(["script","style","meta","link","noscript","template"]).has(e)){let f={};return l.defaultStyle.set(e,f),f}let a=document.getElementById("snapdom-sandbox");a||(a=document.createElement("div"),a.id="snapdom-sandbox",a.style.position="absolute",a.style.left="-9999px",a.style.top="-9999px",a.style.width="0",a.style.height="0",a.style.overflow="hidden",document.body.appendChild(a));let i=document.createElement(e);i.style.all="initial",a.appendChild(i);let s=getComputedStyle(i),n={};for(let f of s)n[f]=s.getPropertyValue(f);return a.removeChild(i),l.defaultStyle.set(e,n),n}function B(e,t,a=!1){let i=[],s=ae(t);for(let[n,f]of Object.entries(e))if(!a)f&&i.push(`${n}:${f}`);else{let r=s[n];f&&f!==r&&i.push(`${n}:${f}`)}return i.sort().join(";")}function re(e){let t=new Set;return e.nodeType!==Node.ELEMENT_NODE&&e.nodeType!==Node.DOCUMENT_FRAGMENT_NODE?[]:(e.tagName&&t.add(e.tagName.toLowerCase()),typeof e.querySelectorAll=="function"&&e.querySelectorAll("*").forEach(a=>t.add(a.tagName.toLowerCase())),Array.from(t))}function se(e){let t=new Map;for(let i of e){let s=l.defaultStyle.get(i);if(!s)continue;let n=Object.entries(s).map(([f,r])=>`${f}:${r};`).sort().join("");t.has(n)||t.set(n,[]),t.get(n).push(i)}let a="";for(let[i,s]of t.entries())a+=`${s.join(",")} { ${i} }
|
|
2
|
+
`;return a}function ie(){let e=new Set(l.preStyleMap.values()),t=new Map,a=1;for(let i of e)t.set(i,`c${a++}`);return t}function P(a){return h(this,arguments,function*(e,t={}){let i=D(e),s=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(e);if(i){let n=z(i);if(l.background.has(n))return t.skipInline?void 0:`url(${l.background.get(n)})`;{let f=yield T(n,{useProxy:t.useProxy});return l.background.set(n,f),t.skipInline?void 0:`url("${f}")`}}return e})}function L(e,{fast:t=!1}={}){if(t)return e();"requestIdleCallback"in window?requestIdleCallback(e,{timeout:50}):setTimeout(e,1)}function A(e,t=null){if(!(e instanceof Element))return window.getComputedStyle(e,t);let a=l.computedStyle.get(e);if(a||(a=new Map,l.computedStyle.set(e,a)),!a.has(t)){let i=window.getComputedStyle(e,t);a.set(t,i)}return a.get(t)}function ce(e){let t=e.replace(/^['"]|['"]$/g,"");if(t.startsWith("\\"))try{return String.fromCharCode(parseInt(t.replace("\\",""),16))}catch(a){return t}return t}function D(e){let t=e.indexOf("url(");if(t===-1)return null;let a=e.slice(t+4).trim();return a.endsWith(")")&&(a=a.slice(0,-1).trim()),(a.startsWith('"')&&a.endsWith('"')||a.startsWith("'")&&a.endsWith("'"))&&(a=a.slice(1,-1)),a}function T(e,{timeout:t=3e3,useProxy:a=""}={}){function i(o){try{return new URL(o,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch(c){return"anonymous"}}function s(o){return h(this,null,function*(){let c=d=>fetch(d,{mode:"cors",credentials:i(d)==="use-credentials"?"include":"omit"}).then(m=>m.blob()).then(m=>new Promise((g,p)=>{let u=new FileReader;u.onloadend=()=>{let y=u.result;if(typeof y!="string"||!y.startsWith("data:image/")){p(new Error("Invalid image data URL"));return}g(y)},u.onerror=()=>p(new Error("FileReader error")),u.readAsDataURL(m)}));try{return yield c(o)}catch(d){if(a&&typeof a=="string"){let m=a.replace(/\/$/,"")+z(o);try{return yield c(m)}catch(g){throw console.error(`[SnapDOM - fetchImage] Proxy fallback failed for: ${o}`),new Error("CORS restrictions prevented image capture (even via proxy)")}}else throw console.error(`[SnapDOM - fetchImage] No valid proxy URL provided for fallback: ${o}`),new Error("Fetch fallback failed and no proxy provided")}})}let n=i(e);return console.log(`[SnapDOM - fetchImage] Start loading image: ${e} with crossOrigin=${n}`),l.image.has(e)?(console.log(`[SnapDOM - fetchImage] Cache hit for: ${e}`),Promise.resolve(l.image.get(e))):e.startsWith("data:image/")?(l.image.set(e,e),Promise.resolve(e)):/\.svg(\?.*)?$/i.test(e)?h(null,null,function*(){try{let c=yield(yield fetch(e,{mode:"cors",credentials:n==="use-credentials"?"include":"omit"})).text(),d=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(c)}`;return l.image.set(e,d),d}catch(o){return s(e)}}):new Promise((o,c)=>{let d=setTimeout(()=>{console.log(`[SnapDOM - fetchImage] Timeout after ${t}ms for image: ${e}`),c(new Error("Image load timed out"))},t),m=new Image;m.crossOrigin=n,m.onload=()=>h(null,null,function*(){clearTimeout(d);try{yield m.decode();let g=document.createElement("canvas");g.width=m.width,g.height=m.height,g.getContext("2d").drawImage(m,0,0,g.width,g.height);let u=g.toDataURL("image/png");l.image.set(e,u),o(u)}catch(g){try{let p=yield s(e);l.image.set(e,p),o(p)}catch(p){c(p)}}}),m.onerror=()=>h(null,null,function*(){clearTimeout(d),console.error(`[SnapDOM - fetchImage] Image failed to load: ${e}`);try{let g=yield s(e);l.image.set(e,g),o(g)}catch(g){c(g)}}),m.src=e})}function K(e){let t={};for(let a of e)t[a]=e.getPropertyValue(a);return t}function q(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function le(e){if(!e||e==="none")return"";let t=e.replace(/translate[XY]?\([^)]*\)/g,"");return t=t.replace(/matrix\(([^)]+)\)/g,(a,i)=>{let s=i.split(",").map(n=>n.trim());return s.length!==6?`matrix(${i})`:(s[4]="0",s[5]="0",`matrix(${s.join(", ")})`)}),t=t.replace(/matrix3d\(([^)]+)\)/g,(a,i)=>{let s=i.split(",").map(n=>n.trim());return s.length!==16?`matrix3d(${i})`:(s[12]="0",s[13]="0",`matrix3d(${s.join(", ")})`)}),t.trim().replace(/\s{2,}/g," ")}function z(e){if(/%[0-9A-Fa-f]{2}/.test(e))return e;try{return encodeURI(e)}catch(t){return e}}function U(e){let t=[],a=0,i=0;for(let s=0;s<e.length;s++){let n=e[s];n==="("&&a++,n===")"&&a--,n===","&&a===0&&(t.push(e.slice(i,s).trim()),i=s+1)}return t.push(e.slice(i).trim()),t}function Ae(e){let t={};for(let a=0;a<e.length;a++){let i=e[a],s=e.getPropertyValue(i);(i==="background-image"||i==="content")&&s.includes("url(")&&!s.includes("data:")&&(s="none"),t[i]=s}return t}function X(e,t,a){var o;if(e.tagName==="STYLE")return;l.preStyle.has(e)||l.preStyle.set(e,A(e));let i=l.preStyle.get(e);if(!l.snapshot.has(e)){let c=Ae(i);l.snapshot.set(e,c)}let s=l.snapshot.get(e),n=Object.entries(s).sort(([c],[d])=>c.localeCompare(d)).map(([c,d])=>`${c}:${d}`).join(";");if(l.snapshotKey.has(n)){l.preStyleMap.set(t,l.snapshotKey.get(n));return}let f=((o=e.tagName)==null?void 0:o.toLowerCase())||"div",r=B(s,f,a);l.snapshotKey.set(n,r),l.preStyleMap.set(t,r)}function Ne(e){return e.nodeType===Node.ELEMENT_NODE&&e.tagName==="SLOT"}function W(e,t,a={},i){var n,f;if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return e.cloneNode(!0);if(e.getAttribute("data-capture")==="exclude"){let r=document.createElement("div"),o=e.getBoundingClientRect();return r.style.cssText=`display: inline-block; width: ${o.width}px; height: ${o.height}px; visibility: hidden;`,r}if(a.exclude&&Array.isArray(a.exclude))for(let r of a.exclude)try{if((n=e.matches)!=null&&n.call(e,r)){let o=document.createElement("div"),c=e.getBoundingClientRect();return o.style.cssText=`display: inline-block; width: ${c.width}px; height: ${c.height}px; visibility: hidden;`,o}}catch(o){console.warn(`Invalid selector in exclude option: ${r}`,o)}if(typeof a.filter=="function")try{if(!a.filter(e,i||e)){let r=document.createElement("div"),o=e.getBoundingClientRect();return r.style.cssText=`display: inline-block; width: ${o.width}px; height: ${o.height}px; visibility: hidden;`,r}}catch(r){console.warn("Error in filter function:",r)}if(e.tagName==="IFRAME"){let r=document.createElement("div");return r.textContent="",r.style.cssText=`width: ${e.offsetWidth}px; height: ${e.offsetHeight}px; background-image: repeating-linear-gradient(45deg, #ddd, #ddd 5px, #f9f9f9 5px, #f9f9f9 10px);display: flex;align-items: center;justify-content: center;font-size: 12px;color: #555; border: 1px solid #aaa;`,r}if(e.getAttribute("data-capture")==="placeholder"){let r=e.cloneNode(!1);l.preNodeMap.set(r,e),X(e,r,t);let o=document.createElement("div");return o.textContent=e.getAttribute("data-placeholder-text")||"",o.style.cssText="color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;",r.appendChild(o),r}if(e.tagName==="CANVAS"){let r=e.toDataURL(),o=document.createElement("img");return o.src=r,o.width=e.width,o.height=e.height,o.style.display="inline-block",o.style.width=e.style.width||`${e.width}px`,o.style.height=e.style.height||`${e.height}px`,o}let s=e.cloneNode(!1);if(l.preNodeMap.set(s,e),e instanceof HTMLInputElement)s.value=e.value,s.setAttribute("value",e.value),e.checked!==void 0&&(s.checked=e.checked,e.checked&&s.setAttribute("checked",""));else if(e instanceof HTMLTextAreaElement){let r=e.getBoundingClientRect();s.textContent=e.value,s.style.width=`${r.width}px`,s.style.height=`${r.height}px`}else e instanceof HTMLSelectElement&&(s.value=e.value,Array.from(s.options).forEach(r=>{r.value===e.value?r.setAttribute("selected",""):r.removeAttribute("selected")}));if(X(e,s,t),Ne(e)){let r=((f=e.assignedNodes)==null?void 0:f.call(e,{flatten:!0}))||[],o=r.length>0?r:Array.from(e.childNodes),c=document.createDocumentFragment();for(let d of o){let m=W(d,t,a,i||e);m&&c.appendChild(m)}return c}else if(!(e instanceof HTMLTextAreaElement)){let r=e.shadowRoot?e.shadowRoot.childNodes:e.childNodes;for(let o of r){let c=W(o,t,a,i||e);c&&s.appendChild(c)}if(e.shadowRoot&&e.childNodes.length>0&&!e.shadowRoot.querySelector("slot")){let o=document.createDocumentFragment();for(let c of e.childNodes){let d=W(c,t,a,i||e);d&&o.appendChild(d)}s.appendChild(o)}}return s}var Te=[/font\s*awesome/i,/material\s*icons/i,/ionicons/i,/glyphicons/i,/feather/i,/bootstrap\s*icons/i,/remix\s*icons/i,/heroicons/i,/layui/i,/lucide/i],Y=[];function fe(e){let t=Array.isArray(e)?e:[e];for(let a of t)a instanceof RegExp?Y.push(a):typeof a=="string"?Y.push(new RegExp(a,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",a)}function I(e){let t=typeof e=="string"?e:"",a=[...Te,...Y];for(let i of a)if(i instanceof RegExp&&i.test(t))return!0;return!!(/icon/i.test(t)||/glyph/i.test(t)||/symbols/i.test(t)||/feather/i.test(t)||/fontawesome/i.test(t))}function de(e,t,a,i=32,s="#000"){return h(this,null,function*(){t=t.replace(/^['"]+|['"]+$/g,"");let n=window.devicePixelRatio||1,r=document.createElement("canvas").getContext("2d");r.font=a?`${a} ${i}px "${t}"`:`${i}px "${t}"`;let o=r.measureText(e),c=o.actualBoundingBoxAscent||i*.8,d=o.actualBoundingBoxDescent||i*.2,m=c+d,g=o.width,p=document.createElement("canvas");p.width=Math.ceil(g*n),p.height=Math.ceil(m*n);let u=p.getContext("2d");return u.scale(n,n),u.font=r.font,u.textAlign="left",u.textBaseline="alphabetic",u.fillStyle=s,u.fillText(e,0,c),p.toDataURL()})}function pe(e){return Array.from(document.styleSheets).some(t=>t.href===e)}function Me(e){return new Promise(t=>{if(pe(e))return t(null);let a=document.createElement("link");a.rel="stylesheet",a.href=e,a.setAttribute("data-snapdom","injected-import"),a.onload=()=>t(a),a.onerror=()=>t(null),document.head.appendChild(a)})}function H(){return h(this,arguments,function*({preCached:e=!1}={}){if(l.resource.has("fonts-embed-css")){if(e){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=l.resource.get("fonts-embed-css"),document.head.appendChild(n)}return l.resource.get("fonts-embed-css")}let t=/@import\s+url\(["']?([^"')]+)["']?\)/g,a=[];for(let n of document.querySelectorAll("style")){let f=n.textContent||"",r=Array.from(f.matchAll(t));for(let o of r){let c=o[1];I(c)||pe(c)||a.push(c)}}yield Promise.all(a.map(Me));let i=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(n=>n.href),s="";for(let n of i)try{let r=yield(yield fetch(n.href)).text();if(I(n.href)||I(r))continue;let o=/url\((["']?)([^"')]+)\1\)/g,c=yield Promise.all(Array.from(r.matchAll(o)).map(m=>h(null,null,function*(){let g=D(m[0]);if(!g)return null;let p=g;if(!p.startsWith("http")&&!p.startsWith("data:")&&(p=new URL(p,n.href).href),I(p))return null;if(l.resource.has(p))return l.font.add(p),{original:m[0],inlined:`url(${l.resource.get(p)})`};if(l.font.has(p))return null;try{let y=yield(yield fetch(p)).blob(),b=yield new Promise(w=>{let S=new FileReader;S.onload=()=>w(S.result),S.readAsDataURL(y)});return l.resource.set(p,b),l.font.add(p),{original:m[0],inlined:`url(${b})`}}catch(u){return console.warn("[snapdom] Failed to fetch font resource:",p),null}}))),d=r;for(let m of c)m&&(d=d.replace(m.original,m.inlined));s+=d+`
|
|
3
|
+
`}catch(f){console.warn("[snapdom] Failed to fetch CSS:",n.href)}for(let n of document.styleSheets)try{if(!n.href||i.every(f=>f.href!==n.href)){for(let f of n.cssRules)if(f.type===CSSRule.FONT_FACE_RULE){let r=f.style.getPropertyValue("src"),o=f.style.getPropertyValue("font-family");if(!r||I(o))continue;let c=/url\((["']?)([^"')]+)\1\)/g,d=r,m=Array.from(r.matchAll(c));for(let g of m){let p=g[2].trim();if(!p)continue;let u=p;if(!u.startsWith("http")&&!u.startsWith("data:")&&(u=new URL(u,n.href||location.href).href),!I(u)){if(l.resource.has(u)){l.font.add(u),d=d.replace(g[0],`url(${l.resource.get(u)})`);continue}if(!l.font.has(u))try{let b=yield(yield fetch(u)).blob(),w=yield new Promise(S=>{let x=new FileReader;x.onload=()=>S(x.result),x.readAsDataURL(b)});l.resource.set(u,w),l.font.add(u),d=d.replace(g[0],`url(${w})`)}catch(y){console.warn("[snapdom] Failed to fetch font URL:",u)}}}s+=`@font-face {
|
|
4
|
+
font-family: ${o};
|
|
5
|
+
src: ${d};
|
|
6
6
|
font-style: ${f.style.getPropertyValue("font-style")||"normal"};
|
|
7
7
|
font-weight: ${f.style.getPropertyValue("font-weight")||"normal"};
|
|
8
8
|
}
|
|
9
|
-
`}}}catch(f){console.warn("[snapdom] Cannot access stylesheet",n.href,f)}for(let n of document.fonts)if(n.family&&n.status==="loaded"&&n._snapdomSrc){if(
|
|
9
|
+
`}}}catch(f){console.warn("[snapdom] Cannot access stylesheet",n.href,f)}for(let n of document.fonts)if(n.family&&n.status==="loaded"&&n._snapdomSrc){if(I(n.family))continue;let f=n._snapdomSrc;if(!f.startsWith("data:")){if(l.resource.has(n._snapdomSrc))f=l.resource.get(n._snapdomSrc),l.font.add(n._snapdomSrc);else if(!l.font.has(n._snapdomSrc))try{let o=yield(yield fetch(n._snapdomSrc)).blob();f=yield new Promise(c=>{let d=new FileReader;d.onload=()=>c(d.result),d.readAsDataURL(o)}),l.resource.set(n._snapdomSrc,f),l.font.add(n._snapdomSrc)}catch(r){console.warn("[snapdom] Failed to fetch dynamic font src:",n._snapdomSrc);continue}}s+=`@font-face {
|
|
10
10
|
font-family: '${n.family}';
|
|
11
11
|
src: url(${f});
|
|
12
12
|
font-style: ${n.style||"normal"};
|
|
13
13
|
font-weight: ${n.weight||"normal"};
|
|
14
14
|
}
|
|
15
|
-
`}if(r&&($.set("fonts-embed-css",r),t)){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=r,document.head.appendChild(n)}return r})}function rt(t,e,o,i,r,n=!1,f){return p(this,null,function*(){if(!(t instanceof Element)||!(e instanceof Element))return;for(let d of["::before","::after","::first-letter"])try{let l=U(t,d);if(!l||typeof l[Symbol.iterator]!="function")continue;if(d==="::first-letter"){let b=getComputedStyle(t);if(!(l.color!==b.color||l.fontSize!==b.fontSize||l.fontWeight!==b.fontWeight))continue;let x=Array.from(e.childNodes).find(E=>E.nodeType===Node.TEXT_NODE&&E.textContent&&E.textContent.trim().length>0);if(!x)continue;let N=x.textContent,C=N.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u),k=C==null?void 0:C[0],B=N.slice((k==null?void 0:k.length)||0);if(!k||/[\uD800-\uDFFF]/.test(k))continue;let v=document.createElement("span");v.textContent=k,v.dataset.snapdomPseudo="::first-letter";let I=tt(l),Q=z(I,"span",r);o.set(v,Q);let q=document.createTextNode(B);e.replaceChild(q,x),e.insertBefore(v,q);continue}let s=l.getPropertyValue("content"),h=l.getPropertyValue("background-image"),m=l.getPropertyValue("background-color"),u=s!=="none",g=h&&h!=="none",y=m&&m!=="transparent"&&m!=="rgba(0, 0, 0, 0)";if(u||g||y){let b=l.getPropertyValue("font-family"),w=parseInt(l.getPropertyValue("font-size"))||32,x=parseInt(l.getPropertyValue("font-weight"))||!1,N=l.getPropertyValue("color")||"#000",C=document.createElement("span");C.dataset.snapdomPseudo=d;let k=tt(l),B=z(k,"span",r);o.set(C,B);let v=T(b),I=yt(s);if(v&&I.length===1){let E=document.createElement("img");E.src=yield bt(I,b,x,w,N),E.style=`width:${w}px;height:auto;object-fit:contain;`,C.appendChild(E)}else if(I.startsWith("url(")){let E=Y(I);if(E&&E.trim()!=="")try{let P=document.createElement("img"),L=yield F(G(E,{useProxy:f}));P.src=L,P.style=`width:${w}px;height:auto;object-fit:contain;`,C.appendChild(P)}catch(P){console.error(`[snapdom] Error in pseudo ${d} for`,t,P)}}else!v&&I&&I!=="none"&&(C.textContent=I);if(g)try{let E=_(h),P=yield Promise.all(E.map(L=>j(L)));C.style.backgroundImage=P.join(", ")}catch(E){console.warn(`[snapdom] Failed to inline background-image for ${d}`,E)}if(y&&(C.style.backgroundColor=m),!(C.childNodes.length>0||C.textContent&&C.textContent.trim()!==""||g||y))continue;d==="::before"?e.insertBefore(C,e.firstChild):e.appendChild(C)}}catch(l){console.warn(`[snapdom] Failed to capture ${d} for`,t,l)}let c=Array.from(t.children),a=Array.from(e.children).filter(d=>!d.dataset.snapdomPseudo);for(let d=0;d<Math.min(c.length,a.length);d++)yield rt(c[d],a[d],o,i,r,n,f)})}function St(t){if(!t)return;let e=document.querySelectorAll("svg > defs");e.length&&t.querySelectorAll("svg").forEach(o=>{let i=o.querySelectorAll("use");if(!i.length)return;let r=new Set;if(i.forEach(f=>{let c=f.getAttribute("xlink:href")||f.getAttribute("href");c&&c.startsWith("#")&&r.add(c.slice(1))}),!r.size)return;let n=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let f of r)for(let c of e){let a=c.querySelector(`#${CSS.escape(f)}`);if(a){n.appendChild(a.cloneNode(!0));break}}n.childNodes.length&&o.insertBefore(n,o.firstChild)})}function Et(r){return p(this,arguments,function*(t,e=!1,o=!1,i={}){var l;let n=new Map,f=new WeakMap,c=new Map,a;try{a=H(t,n,f,c,e,i,t)}catch(s){throw console.warn("deepClone failed:",s),s}try{yield rt(t,a,n,f,e,o,i.useProxy)}catch(s){console.warn("inlinePseudoElements failed:",s)}try{St(a)}catch(s){console.warn("inlineExternalDef failed:",s)}let d="";if(e){let s=gt(n);d=Array.from(s.entries()).map(([h,m])=>`.${m}{${h}}`).join("");for(let[h,m]of n.entries()){if(h.tagName==="STYLE")continue;let u=s.get(m);u&&h.classList.add(u);let g=(l=h.style)==null?void 0:l.backgroundImage;h.removeAttribute("style"),g&&g!=="none"&&(h.style.backgroundImage=g)}}else for(let[s,h]of n.entries())s.tagName!=="STYLE"&&s.setAttribute("style",h.replace(/;/g,"; "));for(let[s,h]of c.entries()){let m=h.scrollLeft,u=h.scrollTop;if((m||u)&&s instanceof HTMLElement){s.style.overflow="hidden",s.style.scrollbarWidth="none",s.style.msOverflowStyle="none";let y=document.createElement("div");for(y.style.transform=`translate(${-m}px, ${-u}px)`,y.style.willChange="transform",y.style.display="inline-block",y.style.width="100%";s.firstChild;)y.appendChild(s.firstChild);s.appendChild(y)}}if(t===c.get(a)){let s=f.get(t)||window.getComputedStyle(t);f.set(t,s);let h=wt(s.transform);a.style.margin="0",a.style.position="static",a.style.top="auto",a.style.left="auto",a.style.right="auto",a.style.bottom="auto",a.style.zIndex="auto",a.style.float="none",a.style.clear="none",a.style.transform=h||""}for(let[s,h]of c.entries())h.tagName==="PRE"&&(s.style.marginTop="0",s.style.marginBlockStart="0");return{clone:a,classCSS:d,styleCache:f}})}function $t(o){return p(this,arguments,function*(t,e={}){let i=Array.from(t.querySelectorAll("img")),r=n=>p(null,null,function*(){let f=n.src;try{let c=yield F(f,{useProxy:e.useProxy});n.src=c,n.width||(n.width=n.naturalWidth||100),n.height||(n.height=n.naturalHeight||100)}catch(c){let a=document.createElement("div");a.style=`width: ${n.width||100}px; height: ${n.height||100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${n.height||100}px; color: #666; font-size: 12px;`,a.innerText="img",n.replaceWith(a)}});for(let n=0;n<i.length;n+=4){let f=i.slice(n,n+4).map(r);yield Promise.allSettled(f)}})}function vt(r,n,f){return p(this,arguments,function*(t,e,o,i={}){let c=[[t,e]],a=["background-image","mask","mask-image","-webkit-mask-image","mask-source","mask-box-image-source","mask-border-source","-webkit-mask-box-image-source"];for(;c.length;){let[d,l]=c.shift(),s=o.get(d)||U(d);o.has(d)||o.set(d,s);for(let g of a){let y=s.getPropertyValue(g);if(!y||y==="none")continue;let b=_(y),w=yield Promise.all(b.map(x=>j(x,i)));w.some(x=>x&&x!=="none"&&!/^url\(undefined/.test(x))&&l.style.setProperty(g,w.join(", "))}let h=s.getPropertyValue("background-color");h&&h!=="transparent"&&h!=="rgba(0, 0, 0, 0)"&&(l.style.backgroundColor=h);let m=Array.from(d.children),u=Array.from(l.children);for(let g=0;g<Math.min(m.length,u.length);g++)c.push([m[g],u[g]])}})}function kt(o){return p(this,arguments,function*(t,e={}){if(!t)throw new Error("Element cannot be null or undefined");let{compress:i=!0,embedFonts:r=!1,fast:n=!0,scale:f=1,useProxy:c=""}=e,a,d,l,s="",h="",m,u;if({clone:a,classCSS:d,styleCache:l}=yield Et(t,i,r,e),yield new Promise(y=>{V(()=>p(null,null,function*(){yield $t(a,e),y()}),{fast:n})}),yield new Promise(y=>{V(()=>p(null,null,function*(){yield vt(t,a,l,e),y()}),{fast:n})}),r&&(yield new Promise(y=>{V(()=>p(null,null,function*(){s=yield J(),y()}),{fast:n})})),i){let y=ut(a).sort(),b=y.join(",");W.has(b)?h=W.get(b):yield new Promise(w=>{V(()=>{h=pt(y),W.set(b,h),w()},{fast:n})})}yield new Promise(y=>{V(()=>{let b=t.getBoundingClientRect(),w=b.width,x=b.height,N=Number.isFinite(e.width),C=Number.isFinite(e.height),k=typeof f=="number"&&f!==1;if(!k){let L=b.width/b.height;N&&C?(w=e.width,x=e.height):N?(w=e.width,x=w/L):C&&(x=e.height,w=x*L)}if(w=Math.ceil(w),x=Math.ceil(x),a.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),a.style.transformOrigin="top left",!k&&(N||C)){let L=b.width,Tt=b.height,Nt=w/L,Pt=x/Tt,Lt=a.style.transform||"",Ut=`scale(${Nt}, ${Pt})`;a.style.transform=`${Ut} ${Lt}`.trim()}else k&&K()&&(a.style.scale=`${f}`);let B="http://www.w3.org/2000/svg",v=document.createElementNS(B,"foreignObject");v.setAttribute("width","100%"),v.setAttribute("height","100%");let I=document.createElement("style");I.textContent=h+s+"svg{overflow:visible;}"+d,v.appendChild(I),v.appendChild(a);let q=new XMLSerializer().serializeToString(v);u=`<svg xmlns="${B}" width="${w}" height="${x}" viewBox="0 0 ${w} ${x}">`+q+"</svg>",m=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(u)}`,y()},{fast:n})});let g=document.getElementById("snapdom-sandbox");return g&&g.style.position==="absolute"&&g.remove(),m})}function jt(i,r){return p(this,arguments,function*(t,{dpr:e=1,scale:o=1}){let n=new Image;return n.src=t,yield n.decode(),K?(n.width=n.width*o,n.height=n.height*o):(n.width=n.width/o,n.height=n.height/o),n})}function It(i){return p(this,arguments,function*(t,{dpr:e=1,scale:o=1}={}){let r=new Image;r.src=t,yield r.decode();let n=document.createElement("canvas"),f=r.width*o,c=r.height*o;n.width=Math.ceil(f*e),n.height=Math.ceil(c*e);let a=n.getContext("2d");return a.scale(e,e),a.drawImage(r,0,0,f,c),n.style.width=`${f}px`,n.style.height=`${c}px`,n})}function Rt(n){return p(this,arguments,function*(t,{type:e="svg",scale:o=1,backgroundColor:i="#fff",quality:r}={}){let f={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[e]||"image/png";if(e==="svg"){let a=decodeURIComponent(t.split(",")[1]);return new Blob([a],{type:"image/svg+xml"})}let c=yield it(t,{dpr:1,scale:o},i);return new Promise(a=>{c.toBlob(d=>a(d),`${f}`,r)})})}function it(r,n,f){return p(this,arguments,function*(t,{dpr:e=1,scale:o=1},i){let c=yield It(t,{dpr:e,scale:o});if(!i)return c;let a=document.createElement("canvas");a.width=c.width,a.height=c.height;let d=a.getContext("2d");return d.fillStyle=i,d.fillRect(0,0,a.width,a.height),d.drawImage(c,0,0),a})}function st(f,c){return p(this,arguments,function*(t,{dpr:e=1,scale:o=1,backgroundColor:i="#fff",quality:r},n="png"){let a=yield it(t,{dpr:e,scale:o},i),d=new Image;return d.src=a.toDataURL(`image/${n}`,r),yield d.decode(),d.style.width=`${a.width/e}px`,d.style.height=`${a.height/e}px`,d})}function Vt(f){return p(this,arguments,function*(t,{dpr:e=1,scale:o=1,backgroundColor:i="#fff",format:r="png",filename:n="capture"}={}){if(r==="svg"){let m=yield Rt(t),u=URL.createObjectURL(m),g=document.createElement("a");g.href=u,g.download=`${n}.svg`,g.click(),URL.revokeObjectURL(u);return}let c=["jpg","jpeg","webp"].includes(r)?"#fff":void 0,a=i!=null?i:c,d=yield it(t,{dpr:e,scale:o},a),l={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[r]||"image/png",s=d.toDataURL(l),h=document.createElement("a");h.href=s,h.download=`${n}.${r}`,h.click()})}function S(o){return p(this,arguments,function*(t,e={}){if(e=D({scale:1},e),!t)throw new Error("Element cannot be null or undefined");return e.iconFonts&&xt(e.iconFonts),yield S.capture(t,e)})}S.capture=(o,...i)=>p(null,[o,...i],function*(t,e={}){let r=yield kt(t,e),n=window.devicePixelRatio||1,f=e.scale||1;return{url:r,options:e,toRaw:()=>r,toImg:()=>jt(r,{dpr:n,scale:f}),toCanvas:()=>It(r,{dpr:n,scale:f}),toBlob:c=>Rt(r,D({dpr:n,scale:f},c)),toPng:c=>st(r,D({dpr:n,scale:f},c),"png"),toJpg:c=>st(r,D({dpr:n,scale:f},c),"jpeg"),toWebp:c=>st(r,D({dpr:n,scale:f},c),"webp"),download:({format:c="png",filename:a="capture",backgroundColor:d}={})=>Vt(r,{dpr:n,scale:f,backgroundColor:d,format:c,filename:a})}});S.toRaw=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toRaw()});S.toImg=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toImg()});S.toCanvas=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toCanvas()});S.toBlob=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toBlob(e)});S.toPng=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toPng(e)});S.toJpg=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toJpg(e)});S.toWebp=(t,e)=>p(null,null,function*(){return(yield S.capture(t,e)).toWebp(e)});S.download=(o,...i)=>p(null,[o,...i],function*(t,e={}){let d=e,{format:r="png",filename:n="capture",backgroundColor:f}=d,c=dt(d,["format","filename","backgroundColor"]);return yield(yield S.capture(t,c)).download({format:r,filename:n,backgroundColor:f})});function At(){return p(this,arguments,function*(t=document,e={}){let{embedFonts:o=!0,reset:i=!1}=e;if(i){R.clear(),M.clear(),$.clear(),W.clear();return}yield document.fonts.ready,ht();let r=[],n=[];t!=null&&t.querySelectorAll&&(r=Array.from(t.querySelectorAll("img[src]")),n=Array.from(t.querySelectorAll("*")));let f=[];for(let c of r){let a=c.src;R.has(a)||f.push(F(a,{useProxy:e.useProxy}).then(d=>R.set(a,d)).catch(()=>{}))}for(let c of n){let a=U(c).backgroundImage;if(a&&a!=="none"){let d=_(a);for(let l of d)l.startsWith("url(")&&f.push(j(l,e).catch(()=>{}))}}o&&(yield J({preCached:!0})),yield Promise.all(f)})}window.snapdom=S;window.preCache=At;})();
|
|
15
|
+
`}if(s&&(l.resource.set("fonts-embed-css",s),e)){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=s,document.head.appendChild(n)}return s})}function G(e,t,a,i=!1,s){return h(this,null,function*(){if(!(e instanceof Element)||!(t instanceof Element))return;for(let r of["::before","::after","::first-letter"])try{let o=A(e,r);if(!o||typeof o[Symbol.iterator]!="function")continue;if(r==="::first-letter"){let y=getComputedStyle(e);if(!(o.color!==y.color||o.fontSize!==y.fontSize||o.fontWeight!==y.fontWeight))continue;let w=Array.from(t.childNodes).find(E=>E.nodeType===Node.TEXT_NODE&&E.textContent&&E.textContent.trim().length>0);if(!w)continue;let S=w.textContent,x=S.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u),v=x==null?void 0:x[0],N=S.slice((v==null?void 0:v.length)||0);if(!v||/[\uD800-\uDFFF]/.test(v))continue;let k=document.createElement("span");k.textContent=v,k.dataset.snapdomPseudo="::first-letter";let $=K(o),F=B($,"span",a);l.preStyleMap.set(k,F);let O=document.createTextNode(N);t.replaceChild(O,w),t.insertBefore(k,O);continue}let c=o.getPropertyValue("content"),d=o.getPropertyValue("background-image"),m=o.getPropertyValue("background-color"),g=c!=="none",p=d&&d!=="none",u=m&&m!=="transparent"&&m!=="rgba(0, 0, 0, 0)";if(g||p||u){let y=o.getPropertyValue("font-family"),b=parseInt(o.getPropertyValue("font-size"))||32,w=parseInt(o.getPropertyValue("font-weight"))||!1,S=o.getPropertyValue("color")||"#000",x=document.createElement("span");x.dataset.snapdomPseudo=r;let v=K(o),N=B(v,"span",a);l.preStyleMap.set(x,N);let k=I(y),$=ce(c);if(k&&$.length===1){let E=document.createElement("img");E.src=yield de($,y,w,b,S),E.style=`width:${b}px;height:auto;object-fit:contain;`,x.appendChild(E)}else if($.startsWith("url(")){let E=D($);if(E&&E.trim()!=="")try{let R=document.createElement("img"),j=yield T(z(E,{useProxy:s}));R.src=j,R.style=`width:${b}px;height:auto;object-fit:contain;`,x.appendChild(R)}catch(R){console.error(`[snapdom] Error in pseudo ${r} for`,e,R)}}else!k&&$&&$!=="none"&&(x.textContent=$);if(p)try{let E=U(d),R=yield Promise.all(E.map(j=>P(j)));x.style.backgroundImage=R.join(", ")}catch(E){console.warn(`[snapdom] Failed to inline background-image for ${r}`,E)}if(u&&(x.style.backgroundColor=m),!(x.childNodes.length>0||x.textContent&&x.textContent.trim()!==""||p||u))continue;r==="::before"?t.insertBefore(x,t.firstChild):t.appendChild(x)}}catch(o){console.warn(`[snapdom] Failed to capture ${r} for`,e,o)}let n=Array.from(e.children),f=Array.from(t.children).filter(r=>!r.dataset.snapdomPseudo);for(let r=0;r<Math.min(n.length,f.length);r++)yield G(n[r],f[r],a,i,s)})}function me(e){if(!e)return;let t=document.querySelectorAll("svg > defs");t.length&&e.querySelectorAll("svg").forEach(a=>{let i=a.querySelectorAll("use");if(!i.length)return;let s=new Set;if(i.forEach(f=>{let r=f.getAttribute("xlink:href")||f.getAttribute("href");r&&r.startsWith("#")&&s.add(r.slice(1))}),!s.size)return;let n=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let f of s)for(let r of t){let o=r.querySelector(`#${CSS.escape(f)}`);if(o){n.appendChild(o.cloneNode(!0));break}}n.childNodes.length&&a.insertBefore(n,a.firstChild)})}function ue(s){return h(this,arguments,function*(e,t=!1,a=!1,i={}){var r;let n,f;try{n=W(e,t,i,e)}catch(o){throw console.warn("deepClone failed:",o),o}try{yield G(e,n,t,a,i.useProxy)}catch(o){console.warn("inlinePseudoElements failed:",o)}try{me(n)}catch(o){console.warn("inlineExternalDef failed:",o)}if(t){let o=ie();f=Array.from(o.entries()).map(([c,d])=>`.${d}{${c}}`).join("");for(let[c,d]of l.preStyleMap.entries()){if(c.tagName==="STYLE")continue;let m=o.get(d);m&&c.classList.add(m);let g=(r=c.style)==null?void 0:r.backgroundImage;c.removeAttribute("style"),g&&g!=="none"&&(c.style.backgroundImage=g)}}else for(let[o,c]of l.preStyleMap.entries())o.tagName!=="STYLE"&&o.setAttribute("style",c.replace(/;/g,"; "));for(let[o,c]of l.preNodeMap.entries()){let d=c.scrollLeft,m=c.scrollTop;if((d||m)&&o instanceof HTMLElement){o.style.overflow="hidden",o.style.scrollbarWidth="none",o.style.msOverflowStyle="none";let p=document.createElement("div");for(p.style.transform=`translate(${-d}px, ${-m}px)`,p.style.willChange="transform",p.style.display="inline-block",p.style.width="100%";o.firstChild;)p.appendChild(o.firstChild);o.appendChild(p)}}if(e===l.preNodeMap.get(n)){let o=l.preStyle.get(e)||window.getComputedStyle(e);l.preStyle.set(e,o);let c=le(o.transform);n.style.margin="0",n.style.position="static",n.style.top="auto",n.style.left="auto",n.style.right="auto",n.style.bottom="auto",n.style.zIndex="auto",n.style.float="none",n.style.clear="none",n.style.transform=c||""}for(let[o,c]of l.preNodeMap.entries())c.tagName==="PRE"&&(o.style.marginTop="0",o.style.marginBlockStart="0");return{clone:n,classCSS:f}})}function he(a){return h(this,arguments,function*(e,t={}){let i=Array.from(e.querySelectorAll("img")),s=n=>h(null,null,function*(){let f=n.src;try{let r=yield T(f,{useProxy:t.useProxy});n.src=r,n.width||(n.width=n.naturalWidth||100),n.height||(n.height=n.naturalHeight||100)}catch(r){let o=document.createElement("div");o.style=`width: ${n.width||100}px; height: ${n.height||100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${n.height||100}px; color: #666; font-size: 12px;`,o.innerText="img",n.replaceWith(o)}});for(let n=0;n<i.length;n+=4){let f=i.slice(n,n+4).map(s);yield Promise.allSettled(f)}})}function ge(i,s){return h(this,arguments,function*(e,t,a={}){let n=[[e,t]],f=["background-image","mask","mask-image","-webkit-mask-image","mask-source","mask-box-image-source","mask-border-source","-webkit-mask-box-image-source"];for(;n.length;){let[r,o]=n.shift(),c=l.preStyle.get(r)||A(r);l.preStyle.has(r)||l.preStyle.set(r,c);for(let p of f){let u=c.getPropertyValue(p);if(!u||u==="none")continue;let y=U(u),b=yield Promise.all(y.map(w=>P(w,a)));b.some(w=>w&&w!=="none"&&!/^url\(undefined/.test(w))&&o.style.setProperty(p,b.join(", "))}let d=c.getPropertyValue("background-color");d&&d!=="transparent"&&d!=="rgba(0, 0, 0, 0)"&&(o.style.backgroundColor=d);let m=Array.from(r.children),g=Array.from(o.children);for(let p=0;p<Math.min(m.length,g.length);p++)n.push([m[p],g[p]])}})}function ye(a){return h(this,arguments,function*(e,t={}){if(!e)throw new Error("Element cannot be null or undefined");l.reset();let{compress:i=!0,embedFonts:s=!1,fast:n=!0,scale:f=1,useProxy:r=""}=t,o,c,d="",m="",g,p;if({clone:o,classCSS:c}=yield ue(e,i,s,t),yield new Promise(y=>{L(()=>h(null,null,function*(){yield he(o,t),y()}),{fast:n})}),yield new Promise(y=>{L(()=>h(null,null,function*(){yield ge(e,o,t),y()}),{fast:n})}),s&&(yield new Promise(y=>{L(()=>h(null,null,function*(){d=yield H(),y()}),{fast:n})})),i){let y=re(o).sort(),b=y.join(",");l.baseStyle.has(b)?m=l.baseStyle.get(b):yield new Promise(w=>{L(()=>{m=se(y),l.baseStyle.set(b,m),w()},{fast:n})})}yield new Promise(y=>{L(()=>{let b=e.getBoundingClientRect(),w=b.width,S=b.height,x=Number.isFinite(t.width),v=Number.isFinite(t.height),N=typeof f=="number"&&f!==1;if(!N){let V=b.width/b.height;x&&v?(w=t.width,S=t.height):x?(w=t.width,S=w/V):v&&(S=t.height,w=S*V)}if(w=Math.ceil(w),S=Math.ceil(S),o.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),o.style.transformOrigin="top left",!N&&(x||v)){let V=b.width,Se=b.height,Ce=w/V,Ee=S/Se,$e=o.style.transform||"",ve=`scale(${Ce}, ${Ee})`;o.style.transform=`${ve} ${$e}`.trim()}else N&&q()&&(o.style.scale=`${f}`);let k="http://www.w3.org/2000/svg",$=document.createElementNS(k,"foreignObject");$.setAttribute("width","100%"),$.setAttribute("height","100%");let F=document.createElement("style");F.textContent=m+d+"svg{overflow:visible;}"+c,$.appendChild(F),$.appendChild(o);let E=new XMLSerializer().serializeToString($);p=`<svg xmlns="${k}" width="${w}" height="${S}" viewBox="0 0 ${w} ${S}">`+E+"</svg>",g=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(p)}`,y()},{fast:n})});let u=document.getElementById("snapdom-sandbox");return u&&u.style.position==="absolute"&&u.remove(),g})}function Pe(i,s){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1}){let n=new Image;return n.src=e,yield n.decode(),q?(n.width=n.width*a,n.height=n.height*a):(n.width=n.width/a,n.height=n.height/a),n})}function we(i){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1}={}){let s=new Image;s.src=e,yield s.decode();let n=document.createElement("canvas"),f=s.width*a,r=s.height*a;n.width=Math.ceil(f*t),n.height=Math.ceil(r*t);let o=n.getContext("2d");return o.scale(t,t),o.drawImage(s,0,0,f,r),n.style.width=`${f}px`,n.style.height=`${r}px`,n})}function xe(n){return h(this,arguments,function*(e,{type:t="svg",scale:a=1,backgroundColor:i="#fff",quality:s}={}){let f={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[t]||"image/png";if(t==="svg"){let o=decodeURIComponent(e.split(",")[1]);return new Blob([o],{type:"image/svg+xml"})}let r=yield Q(e,{dpr:1,scale:a},i);return new Promise(o=>{r.toBlob(c=>o(c),`${f}`,s)})})}function Q(s,n,f){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1},i){let r=yield we(e,{dpr:t,scale:a});if(!i)return r;let o=document.createElement("canvas");o.width=r.width,o.height=r.height;let c=o.getContext("2d");return c.fillStyle=i,c.fillRect(0,0,o.width,o.height),c.drawImage(r,0,0),o})}function J(f,r){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1,backgroundColor:i="#fff",quality:s},n="png"){let o=yield Q(e,{dpr:t,scale:a},i),c=new Image;return c.src=o.toDataURL(`image/${n}`,s),yield c.decode(),c.style.width=`${o.width/t}px`,c.style.height=`${o.height/t}px`,c})}function Le(f){return h(this,arguments,function*(e,{dpr:t=1,scale:a=1,backgroundColor:i="#fff",format:s="png",filename:n="capture"}={}){if(s==="svg"){let p=yield xe(e),u=URL.createObjectURL(p),y=document.createElement("a");y.href=u,y.download=`${n}.svg`,y.click(),URL.revokeObjectURL(u);return}let r=["jpg","jpeg","webp"].includes(s)?"#fff":void 0,o=i!=null?i:r,c=yield Q(e,{dpr:t,scale:a},o),d={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[s]||"image/png",m=c.toDataURL(d),g=document.createElement("a");g.href=m,g.download=`${n}.${s}`,g.click()})}function C(a){return h(this,arguments,function*(e,t={}){if(t=M({scale:1},t),!e)throw new Error("Element cannot be null or undefined");return t.iconFonts&&fe(t.iconFonts),yield C.capture(e,t)})}C.capture=(a,...i)=>h(null,[a,...i],function*(e,t={}){let s=yield ye(e,t),n=window.devicePixelRatio||1,f=t.scale||1;return{url:s,options:t,toRaw:()=>s,toImg:()=>Pe(s,{dpr:n,scale:f}),toCanvas:()=>we(s,{dpr:n,scale:f}),toBlob:r=>xe(s,M({dpr:n,scale:f},r)),toPng:r=>J(s,M({dpr:n,scale:f},r),"png"),toJpg:r=>J(s,M({dpr:n,scale:f},r),"jpeg"),toWebp:r=>J(s,M({dpr:n,scale:f},r),"webp"),download:({format:r="png",filename:o="capture",backgroundColor:c}={})=>Le(s,{dpr:n,scale:f,backgroundColor:c,format:r,filename:o})}});C.toRaw=(e,t)=>h(null,null,function*(){return(yield C.capture(e,t)).toRaw()});C.toImg=(e,t)=>h(null,null,function*(){return(yield C.capture(e,t)).toImg()});C.toCanvas=(e,t)=>h(null,null,function*(){return(yield C.capture(e,t)).toCanvas()});C.toBlob=(e,t)=>h(null,null,function*(){return(yield C.capture(e,t)).toBlob(t)});C.toPng=(e,t)=>h(null,null,function*(){return(yield C.capture(e,t)).toPng(t)});C.toJpg=(e,t)=>h(null,null,function*(){return(yield C.capture(e,t)).toJpg(t)});C.toWebp=(e,t)=>h(null,null,function*(){return(yield C.capture(e,t)).toWebp(t)});C.download=(a,...i)=>h(null,[a,...i],function*(e,t={}){let c=t,{format:s="png",filename:n="capture",backgroundColor:f}=c,r=ne(c,["format","filename","backgroundColor"]);return yield(yield C.capture(e,r)).download({format:s,filename:n,backgroundColor:f})});function be(){return h(this,arguments,function*(e=document,t={}){let{embedFonts:a=!0,reset:i=!1}=t;if(i){l.reset();return}yield document.fonts.ready,oe();let s=[],n=[];e!=null&&e.querySelectorAll&&(s=Array.from(e.querySelectorAll("img[src]")),n=Array.from(e.querySelectorAll("*")));let f=[];for(let r of s){let o=r.src;l.image.has(o)||f.push(T(o,{useProxy:t.useProxy}).then(c=>l.image.set(o,c)).catch(()=>{}))}for(let r of n){let o=A(r).backgroundImage;if(o&&o!=="none"){let c=U(o);for(let d of c)d.startsWith("url(")&&f.push(P(d,t).catch(()=>{}))}}a&&(yield H({preCached:!0})),yield Promise.all(f)})}window.snapdom=C;window.preCache=be;})();
|
package/dist/snapdom.min.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var
|
|
2
|
-
`;return n}function lt(t){let e=new Set(t.values()),n=new Map,r=1;for(let a of e)n.set(a,`c${r++}`);return n}async function M(t,e={}){let r=t.match(/url\(["']?(.*?)["']?\)/)?.[1],a=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(t);if(r){let o=Y(r);if(F.has(o))return e.skipInline?void 0:`url(${F.get(o)})`;{let c=await U(o,{useProxy:e.useProxy});return F.set(o,c),e.skipInline?void 0:`url("${c}")`}}return t}function O(t,{fast:e=!1}={}){if(e)return t();"requestIdleCallback"in window?requestIdleCallback(t,{timeout:50}):setTimeout(t,1)}function L(t,e=null){if(!(t instanceof Element))return window.getComputedStyle(t,e);let n=G.get(t);if(n||(n=new Map,G.set(t,n)),!n.has(e)){let r=window.getComputedStyle(t,e);n.set(e,r)}return n.get(e)}function ft(t){let e=t.replace(/^['"]|['"]$/g,"");if(e.startsWith("\\"))try{return String.fromCharCode(parseInt(e.replace("\\",""),16))}catch{return e}return e}function H(t){let e=t.indexOf("url(");if(e===-1)return null;let n=t.slice(e+4).trim();return n.endsWith(")")&&(n=n.slice(0,-1).trim()),(n.startsWith('"')&&n.endsWith('"')||n.startsWith("'")&&n.endsWith("'"))&&(n=n.slice(1,-1)),n}function U(t,{timeout:e=3e3,useProxy:n=""}={}){function r(l){try{return new URL(l,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch{return"anonymous"}}async function a(l){let s=f=>fetch(f,{mode:"cors",credentials:r(f)==="use-credentials"?"include":"omit"}).then(d=>d.blob()).then(d=>new Promise((h,u)=>{let m=new FileReader;m.onloadend=()=>{let g=m.result;if(typeof g!="string"||!g.startsWith("data:image/")){u(new Error("Invalid image data URL"));return}h(g)},m.onerror=()=>u(new Error("FileReader error")),m.readAsDataURL(d)}));try{return await s(l)}catch{if(n&&typeof n=="string"){let d=n.replace(/\/$/,"")+Y(l);try{return await s(d)}catch{throw console.error(`[SnapDOM - fetchImage] Proxy fallback failed for: ${l}`),new Error("CORS restrictions prevented image capture (even via proxy)")}}else throw console.error(`[SnapDOM - fetchImage] No valid proxy URL provided for fallback: ${l}`),new Error("Fetch fallback failed and no proxy provided")}}let o=r(t);return console.log(`[SnapDOM - fetchImage] Start loading image: ${t} with crossOrigin=${o}`),v.has(t)?(console.log(`[SnapDOM - fetchImage] Cache hit for: ${t}`),Promise.resolve(v.get(t))):t.startsWith("data:image/")?(v.set(t,t),Promise.resolve(t)):/\.svg(\?.*)?$/i.test(t)?(async()=>{try{let s=await(await fetch(t,{mode:"cors",credentials:o==="use-credentials"?"include":"omit"})).text(),f=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(s)}`;return v.set(t,f),f}catch{return a(t)}})():new Promise((l,s)=>{let f=setTimeout(()=>{console.log(`[SnapDOM - fetchImage] Timeout after ${e}ms for image: ${t}`),s(new Error("Image load timed out"))},e),d=new Image;d.crossOrigin=o,d.onload=async()=>{clearTimeout(f);try{await d.decode();let h=document.createElement("canvas");h.width=d.width,h.height=d.height,h.getContext("2d").drawImage(d,0,0,h.width,h.height);let m=h.toDataURL("image/png");v.set(t,m),l(m)}catch{try{let h=await a(t);v.set(t,h),l(h)}catch(h){s(h)}}},d.onerror=async()=>{clearTimeout(f),console.error(`[SnapDOM - fetchImage] Image failed to load: ${t}`);try{let h=await a(t);v.set(t,h),l(h)}catch(h){s(h)}},d.src=t})}function J(t){let e={};for(let n of t)e[n]=t.getPropertyValue(n);return e}function X(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function dt(t){if(!t||t==="none")return"";let e=t.replace(/translate[XY]?\([^)]*\)/g,"");return e=e.replace(/matrix\(([^)]+)\)/g,(n,r)=>{let a=r.split(",").map(o=>o.trim());return a.length!==6?`matrix(${r})`:(a[4]="0",a[5]="0",`matrix(${a.join(", ")})`)}),e=e.replace(/matrix3d\(([^)]+)\)/g,(n,r)=>{let a=r.split(",").map(o=>o.trim());return a.length!==16?`matrix3d(${r})`:(a[12]="0",a[13]="0",`matrix3d(${a.join(", ")})`)}),e.trim().replace(/\s{2,}/g," ")}function Y(t){if(/%[0-9A-Fa-f]{2}/.test(t))return t;try{return encodeURI(t)}catch{return t}}function W(t){let e=[],n=0,r=0;for(let a=0;a<t.length;a++){let o=t[a];o==="("&&n++,o===")"&&n--,o===","&&n===0&&(e.push(t.slice(r,a).trim()),r=a+1)}return e.push(t.slice(r).trim()),e}var Q=new WeakMap,Z=new Map;function It(t){let e={};for(let n=0;n<t.length;n++){let r=t[n],a=t.getPropertyValue(r);(r==="background-image"||r==="content")&&a.includes("url(")&&!a.includes("data:")&&(a="none"),e[r]=a}return e}function tt(t,e,n,r,a){if(t.tagName==="STYLE")return;r.has(t)||r.set(t,L(t));let o=r.get(t);if(!Q.has(t)){let f=It(o);Q.set(t,f)}let c=Q.get(t),i=Object.entries(c).sort(([f],[d])=>f.localeCompare(d)).map(([f,d])=>`${f}:${d}`).join(";");if(Z.has(i)){n.set(e,Z.get(i));return}let l=t.tagName?.toLowerCase()||"div",s=V(c,l,a);Z.set(i,s),n.set(e,s)}function Rt(t){return t.nodeType===Node.ELEMENT_NODE&&t.tagName==="SLOT"}function _(t,e,n,r,a,o={},c){if(t.nodeType===Node.TEXT_NODE||t.nodeType!==Node.ELEMENT_NODE)return t.cloneNode(!0);if(t.getAttribute("data-capture")==="exclude"){let l=document.createElement("div"),s=t.getBoundingClientRect();return l.style.cssText=`display: inline-block; width: ${s.width}px; height: ${s.height}px; visibility: hidden;`,l}if(o.exclude&&Array.isArray(o.exclude))for(let l of o.exclude)try{if(t.matches?.(l)){let s=document.createElement("div"),f=t.getBoundingClientRect();return s.style.cssText=`display: inline-block; width: ${f.width}px; height: ${f.height}px; visibility: hidden;`,s}}catch(s){console.warn(`Invalid selector in exclude option: ${l}`,s)}if(typeof o.filter=="function")try{if(!o.filter(t,c||t)){let l=document.createElement("div"),s=t.getBoundingClientRect();return l.style.cssText=`display: inline-block; width: ${s.width}px; height: ${s.height}px; visibility: hidden;`,l}}catch(l){console.warn("Error in filter function:",l)}if(t.tagName==="IFRAME"){let l=document.createElement("div");return l.textContent="",l.style.cssText=`width: ${t.offsetWidth}px; height: ${t.offsetHeight}px; background-image: repeating-linear-gradient(45deg, #ddd, #ddd 5px, #f9f9f9 5px, #f9f9f9 10px);display: flex;align-items: center;justify-content: center;font-size: 12px;color: #555; border: 1px solid #aaa;`,l}if(t.getAttribute("data-capture")==="placeholder"){let l=t.cloneNode(!1);r.set(l,t),tt(t,l,e,n,a);let s=document.createElement("div");return s.textContent=t.getAttribute("data-placeholder-text")||"",s.style.cssText="color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;",l.appendChild(s),l}if(t.tagName==="CANVAS"){let l=t.toDataURL(),s=document.createElement("img");return s.src=l,s.width=t.width,s.height=t.height,s.style.display="inline-block",s.style.width=t.style.width||`${t.width}px`,s.style.height=t.style.height||`${t.height}px`,s}let i=t.cloneNode(!1);if(r.set(i,t),t instanceof HTMLInputElement)i.value=t.value,i.setAttribute("value",t.value),t.checked!==void 0&&(i.checked=t.checked,t.checked&&i.setAttribute("checked",""));else if(t instanceof HTMLTextAreaElement){let l=t.getBoundingClientRect();i.textContent=t.value,i.style.width=`${l.width}px`,i.style.height=`${l.height}px`}else t instanceof HTMLSelectElement&&(i.value=t.value,Array.from(i.options).forEach(l=>{l.value===t.value?l.setAttribute("selected",""):l.removeAttribute("selected")}));if(tt(t,i,e,n,a),Rt(t)){let l=t.assignedNodes?.({flatten:!0})||[],s=l.length>0?l:Array.from(t.childNodes),f=document.createDocumentFragment();for(let d of s){let h=_(d,e,n,r,a,o,c||t);h&&f.appendChild(h)}return f}else if(!(t instanceof HTMLTextAreaElement)){let l=t.shadowRoot?t.shadowRoot.childNodes:t.childNodes;for(let s of l){let f=_(s,e,n,r,a,o,c||t);f&&i.appendChild(f)}if(t.shadowRoot&&t.childNodes.length>0&&!t.shadowRoot.querySelector("slot")){let s=document.createDocumentFragment();for(let f of t.childNodes){let d=_(f,e,n,r,a,o,c||t);d&&s.appendChild(d)}i.appendChild(s)}}return i}var At=[/font\s*awesome/i,/material\s*icons/i,/ionicons/i,/glyphicons/i,/feather/i,/bootstrap\s*icons/i,/remix\s*icons/i,/heroicons/i,/layui/i,/lucide/i],et=[];function ht(t){let e=Array.isArray(t)?t:[t];for(let n of e)n instanceof RegExp?et.push(n):typeof n=="string"?et.push(new RegExp(n,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",n)}function A(t){let e=typeof t=="string"?t:"",n=[...At,...et];for(let r of n)if(r instanceof RegExp&&r.test(e))return!0;return!!(/icon/i.test(e)||/glyph/i.test(e)||/symbols/i.test(e)||/feather/i.test(e)||/fontawesome/i.test(e))}async function mt(t,e,n,r=32,a="#000"){e=e.replace(/^['"]+|['"]+$/g,"");let o=window.devicePixelRatio||1,i=document.createElement("canvas").getContext("2d");i.font=n?`${n} ${r}px "${e}"`:`${r}px "${e}"`;let l=i.measureText(t),s=l.actualBoundingBoxAscent||r*.8,f=l.actualBoundingBoxDescent||r*.2,d=s+f,h=l.width,u=document.createElement("canvas");u.width=Math.ceil(h*o),u.height=Math.ceil(d*o);let m=u.getContext("2d");return m.scale(o,o),m.font=i.font,m.textAlign="left",m.textBaseline="alphabetic",m.fillStyle=a,m.fillText(t,0,s),u.toDataURL()}function ut(t){return Array.from(document.styleSheets).some(e=>e.href===t)}function Tt(t){return new Promise(e=>{if(ut(t))return e(null);let n=document.createElement("link");n.rel="stylesheet",n.href=t,n.setAttribute("data-snapdom","injected-import"),n.onload=()=>e(n),n.onerror=()=>e(null),document.head.appendChild(n)})}async function K({preCached:t=!1}={}){if(S.has("fonts-embed-css")){if(t){let o=document.createElement("style");o.setAttribute("data-snapdom","embedFonts"),o.textContent=S.get("fonts-embed-css"),document.head.appendChild(o)}return S.get("fonts-embed-css")}let e=/@import\s+url\(["']?([^"')]+)["']?\)/g,n=[];for(let o of document.querySelectorAll("style")){let c=o.textContent||"",i=Array.from(c.matchAll(e));for(let l of i){let s=l[1];A(s)||ut(s)||n.push(s)}}await Promise.all(n.map(Tt));let r=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(o=>o.href),a="";for(let o of r)try{let i=await(await fetch(o.href)).text();if(A(o.href)||A(i))continue;let l=/url\((["']?)([^"')]+)\1\)/g,s=await Promise.all(Array.from(i.matchAll(l)).map(async d=>{let h=H(d[0]);if(!h)return null;let u=h;if(!u.startsWith("http")&&!u.startsWith("data:")&&(u=new URL(u,o.href).href),A(u))return null;if(S.has(u))return R.add(u),{original:d[0],inlined:`url(${S.get(u)})`};if(R.has(u))return null;try{let g=await(await fetch(u)).blob(),p=await new Promise(y=>{let w=new FileReader;w.onload=()=>y(w.result),w.readAsDataURL(g)});return S.set(u,p),R.add(u),{original:d[0],inlined:`url(${p})`}}catch{return console.warn("[snapdom] Failed to fetch font resource:",u),null}})),f=i;for(let d of s)d&&(f=f.replace(d.original,d.inlined));a+=f+`
|
|
3
|
-
`}catch{console.warn("[snapdom] Failed to fetch CSS:",
|
|
1
|
+
var c={image:new Map,background:new Map,resource:new Map,defaultStyle:new Map,baseStyle:new Map,computedStyle:new WeakMap,font:new Set,snapshot:new WeakMap,snapshotKey:new Map,preStyleMap:new Map,preStyle:new WeakMap,preNodeMap:new Map,reset:ye};function ye(){c.computedStyle=new WeakMap,c.snapshot=new WeakMap,c.snapshotKey.clear(),c.preStyleMap.clear(),c.preStyle=new WeakMap,c.preNodeMap.clear()}var we=["div","span","p","a","img","ul","li","button","input","select","textarea","label","section","article","header","footer","nav","main","aside","h1","h2","h3","h4","h5","h6","svg","path","circle","rect","line","g","table","thead","tbody","tr","td","th"];function Y(){for(let e of we)G(e)}function G(e){if(c.defaultStyle.has(e))return c.defaultStyle.get(e);if(new Set(["script","style","meta","link","noscript","template"]).has(e)){let r={};return c.defaultStyle.set(e,r),r}let a=document.getElementById("snapdom-sandbox");a||(a=document.createElement("div"),a.id="snapdom-sandbox",a.style.position="absolute",a.style.left="-9999px",a.style.top="-9999px",a.style.width="0",a.style.height="0",a.style.overflow="hidden",document.body.appendChild(a));let s=document.createElement(e);s.style.all="initial",a.appendChild(s);let o=getComputedStyle(s),n={};for(let r of o)n[r]=o.getPropertyValue(r);return a.removeChild(s),c.defaultStyle.set(e,n),n}function F(e,t,a=!1){let s=[],o=G(t);for(let[n,r]of Object.entries(e))if(!a)r&&s.push(`${n}:${r}`);else{let i=o[n];r&&r!==i&&s.push(`${n}:${r}`)}return s.sort().join(";")}function J(e){let t=new Set;return e.nodeType!==Node.ELEMENT_NODE&&e.nodeType!==Node.DOCUMENT_FRAGMENT_NODE?[]:(e.tagName&&t.add(e.tagName.toLowerCase()),typeof e.querySelectorAll=="function"&&e.querySelectorAll("*").forEach(a=>t.add(a.tagName.toLowerCase())),Array.from(t))}function Q(e){let t=new Map;for(let s of e){let o=c.defaultStyle.get(s);if(!o)continue;let n=Object.entries(o).map(([r,i])=>`${r}:${i};`).sort().join("");t.has(n)||t.set(n,[]),t.get(n).push(s)}let a="";for(let[s,o]of t.entries())a+=`${o.join(",")} { ${s} }
|
|
2
|
+
`;return a}function Z(){let e=new Set(c.preStyleMap.values()),t=new Map,a=1;for(let s of e)t.set(s,`c${a++}`);return t}async function M(e,t={}){let a=B(e),s=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(e);if(a){let o=O(a);if(c.background.has(o))return t.skipInline?void 0:`url(${c.background.get(o)})`;{let n=await N(o,{useProxy:t.useProxy});return c.background.set(o,n),t.skipInline?void 0:`url("${n}")`}}return e}function P(e,{fast:t=!1}={}){if(t)return e();"requestIdleCallback"in window?requestIdleCallback(e,{timeout:50}):setTimeout(e,1)}function A(e,t=null){if(!(e instanceof Element))return window.getComputedStyle(e,t);let a=c.computedStyle.get(e);if(a||(a=new Map,c.computedStyle.set(e,a)),!a.has(t)){let s=window.getComputedStyle(e,t);a.set(t,s)}return a.get(t)}function ee(e){let t=e.replace(/^['"]|['"]$/g,"");if(t.startsWith("\\"))try{return String.fromCharCode(parseInt(t.replace("\\",""),16))}catch{return t}return t}function B(e){let t=e.indexOf("url(");if(t===-1)return null;let a=e.slice(t+4).trim();return a.endsWith(")")&&(a=a.slice(0,-1).trim()),(a.startsWith('"')&&a.endsWith('"')||a.startsWith("'")&&a.endsWith("'"))&&(a=a.slice(1,-1)),a}function N(e,{timeout:t=3e3,useProxy:a=""}={}){function s(l){try{return new URL(l,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch{return"anonymous"}}async function o(l){let u=m=>fetch(m,{mode:"cors",credentials:s(m)==="use-credentials"?"include":"omit"}).then(f=>f.blob()).then(f=>new Promise((p,h)=>{let d=new FileReader;d.onloadend=()=>{let g=d.result;if(typeof g!="string"||!g.startsWith("data:image/")){h(new Error("Invalid image data URL"));return}p(g)},d.onerror=()=>h(new Error("FileReader error")),d.readAsDataURL(f)}));try{return await u(l)}catch{if(a&&typeof a=="string"){let f=a.replace(/\/$/,"")+O(l);try{return await u(f)}catch{throw console.error(`[SnapDOM - fetchImage] Proxy fallback failed for: ${l}`),new Error("CORS restrictions prevented image capture (even via proxy)")}}else throw console.error(`[SnapDOM - fetchImage] No valid proxy URL provided for fallback: ${l}`),new Error("Fetch fallback failed and no proxy provided")}}let n=s(e);return console.log(`[SnapDOM - fetchImage] Start loading image: ${e} with crossOrigin=${n}`),c.image.has(e)?(console.log(`[SnapDOM - fetchImage] Cache hit for: ${e}`),Promise.resolve(c.image.get(e))):e.startsWith("data:image/")?(c.image.set(e,e),Promise.resolve(e)):/\.svg(\?.*)?$/i.test(e)?(async()=>{try{let u=await(await fetch(e,{mode:"cors",credentials:n==="use-credentials"?"include":"omit"})).text(),m=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(u)}`;return c.image.set(e,m),m}catch{return o(e)}})():new Promise((l,u)=>{let m=setTimeout(()=>{console.log(`[SnapDOM - fetchImage] Timeout after ${t}ms for image: ${e}`),u(new Error("Image load timed out"))},t),f=new Image;f.crossOrigin=n,f.onload=async()=>{clearTimeout(m);try{await f.decode();let p=document.createElement("canvas");p.width=f.width,p.height=f.height,p.getContext("2d").drawImage(f,0,0,p.width,p.height);let d=p.toDataURL("image/png");c.image.set(e,d),l(d)}catch{try{let p=await o(e);c.image.set(e,p),l(p)}catch(p){u(p)}}},f.onerror=async()=>{clearTimeout(m),console.error(`[SnapDOM - fetchImage] Image failed to load: ${e}`);try{let p=await o(e);c.image.set(e,p),l(p)}catch(p){u(p)}},f.src=e})}function _(e){let t={};for(let a of e)t[a]=e.getPropertyValue(a);return t}function W(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function te(e){if(!e||e==="none")return"";let t=e.replace(/translate[XY]?\([^)]*\)/g,"");return t=t.replace(/matrix\(([^)]+)\)/g,(a,s)=>{let o=s.split(",").map(n=>n.trim());return o.length!==6?`matrix(${s})`:(o[4]="0",o[5]="0",`matrix(${o.join(", ")})`)}),t=t.replace(/matrix3d\(([^)]+)\)/g,(a,s)=>{let o=s.split(",").map(n=>n.trim());return o.length!==16?`matrix3d(${s})`:(o[12]="0",o[13]="0",`matrix3d(${o.join(", ")})`)}),t.trim().replace(/\s{2,}/g," ")}function O(e){if(/%[0-9A-Fa-f]{2}/.test(e))return e;try{return encodeURI(e)}catch{return e}}function L(e){let t=[],a=0,s=0;for(let o=0;o<e.length;o++){let n=e[o];n==="("&&a++,n===")"&&a--,n===","&&a===0&&(t.push(e.slice(s,o).trim()),s=o+1)}return t.push(e.slice(s).trim()),t}function xe(e){let t={};for(let a=0;a<e.length;a++){let s=e[a],o=e.getPropertyValue(s);(s==="background-image"||s==="content")&&o.includes("url(")&&!o.includes("data:")&&(o="none"),t[s]=o}return t}function q(e,t,a){if(e.tagName==="STYLE")return;c.preStyle.has(e)||c.preStyle.set(e,A(e));let s=c.preStyle.get(e);if(!c.snapshot.has(e)){let l=xe(s);c.snapshot.set(e,l)}let o=c.snapshot.get(e),n=Object.entries(o).sort(([l],[u])=>l.localeCompare(u)).map(([l,u])=>`${l}:${u}`).join(";");if(c.snapshotKey.has(n)){c.preStyleMap.set(t,c.snapshotKey.get(n));return}let r=e.tagName?.toLowerCase()||"div",i=F(o,r,a);c.snapshotKey.set(n,i),c.preStyleMap.set(t,i)}function be(e){return e.nodeType===Node.ELEMENT_NODE&&e.tagName==="SLOT"}function D(e,t,a={},s){if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return e.cloneNode(!0);if(e.getAttribute("data-capture")==="exclude"){let n=document.createElement("div"),r=e.getBoundingClientRect();return n.style.cssText=`display: inline-block; width: ${r.width}px; height: ${r.height}px; visibility: hidden;`,n}if(a.exclude&&Array.isArray(a.exclude))for(let n of a.exclude)try{if(e.matches?.(n)){let r=document.createElement("div"),i=e.getBoundingClientRect();return r.style.cssText=`display: inline-block; width: ${i.width}px; height: ${i.height}px; visibility: hidden;`,r}}catch(r){console.warn(`Invalid selector in exclude option: ${n}`,r)}if(typeof a.filter=="function")try{if(!a.filter(e,s||e)){let n=document.createElement("div"),r=e.getBoundingClientRect();return n.style.cssText=`display: inline-block; width: ${r.width}px; height: ${r.height}px; visibility: hidden;`,n}}catch(n){console.warn("Error in filter function:",n)}if(e.tagName==="IFRAME"){let n=document.createElement("div");return n.textContent="",n.style.cssText=`width: ${e.offsetWidth}px; height: ${e.offsetHeight}px; background-image: repeating-linear-gradient(45deg, #ddd, #ddd 5px, #f9f9f9 5px, #f9f9f9 10px);display: flex;align-items: center;justify-content: center;font-size: 12px;color: #555; border: 1px solid #aaa;`,n}if(e.getAttribute("data-capture")==="placeholder"){let n=e.cloneNode(!1);c.preNodeMap.set(n,e),q(e,n,t);let r=document.createElement("div");return r.textContent=e.getAttribute("data-placeholder-text")||"",r.style.cssText="color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;",n.appendChild(r),n}if(e.tagName==="CANVAS"){let n=e.toDataURL(),r=document.createElement("img");return r.src=n,r.width=e.width,r.height=e.height,r.style.display="inline-block",r.style.width=e.style.width||`${e.width}px`,r.style.height=e.style.height||`${e.height}px`,r}let o=e.cloneNode(!1);if(c.preNodeMap.set(o,e),e instanceof HTMLInputElement)o.value=e.value,o.setAttribute("value",e.value),e.checked!==void 0&&(o.checked=e.checked,e.checked&&o.setAttribute("checked",""));else if(e instanceof HTMLTextAreaElement){let n=e.getBoundingClientRect();o.textContent=e.value,o.style.width=`${n.width}px`,o.style.height=`${n.height}px`}else e instanceof HTMLSelectElement&&(o.value=e.value,Array.from(o.options).forEach(n=>{n.value===e.value?n.setAttribute("selected",""):n.removeAttribute("selected")}));if(q(e,o,t),be(e)){let n=e.assignedNodes?.({flatten:!0})||[],r=n.length>0?n:Array.from(e.childNodes),i=document.createDocumentFragment();for(let l of r){let u=D(l,t,a,s||e);u&&i.appendChild(u)}return i}else if(!(e instanceof HTMLTextAreaElement)){let n=e.shadowRoot?e.shadowRoot.childNodes:e.childNodes;for(let r of n){let i=D(r,t,a,s||e);i&&o.appendChild(i)}if(e.shadowRoot&&e.childNodes.length>0&&!e.shadowRoot.querySelector("slot")){let r=document.createDocumentFragment();for(let i of e.childNodes){let l=D(i,t,a,s||e);l&&r.appendChild(l)}o.appendChild(r)}}return o}var Se=[/font\s*awesome/i,/material\s*icons/i,/ionicons/i,/glyphicons/i,/feather/i,/bootstrap\s*icons/i,/remix\s*icons/i,/heroicons/i,/layui/i,/lucide/i],z=[];function ne(e){let t=Array.isArray(e)?e:[e];for(let a of t)a instanceof RegExp?z.push(a):typeof a=="string"?z.push(new RegExp(a,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",a)}function v(e){let t=typeof e=="string"?e:"",a=[...Se,...z];for(let s of a)if(s instanceof RegExp&&s.test(t))return!0;return!!(/icon/i.test(t)||/glyph/i.test(t)||/symbols/i.test(t)||/feather/i.test(t)||/fontawesome/i.test(t))}async function oe(e,t,a,s=32,o="#000"){t=t.replace(/^['"]+|['"]+$/g,"");let n=window.devicePixelRatio||1,i=document.createElement("canvas").getContext("2d");i.font=a?`${a} ${s}px "${t}"`:`${s}px "${t}"`;let l=i.measureText(e),u=l.actualBoundingBoxAscent||s*.8,m=l.actualBoundingBoxDescent||s*.2,f=u+m,p=l.width,h=document.createElement("canvas");h.width=Math.ceil(p*n),h.height=Math.ceil(f*n);let d=h.getContext("2d");return d.scale(n,n),d.font=i.font,d.textAlign="left",d.textBaseline="alphabetic",d.fillStyle=o,d.fillText(e,0,u),h.toDataURL()}function ae(e){return Array.from(document.styleSheets).some(t=>t.href===e)}function Ce(e){return new Promise(t=>{if(ae(e))return t(null);let a=document.createElement("link");a.rel="stylesheet",a.href=e,a.setAttribute("data-snapdom","injected-import"),a.onload=()=>t(a),a.onerror=()=>t(null),document.head.appendChild(a)})}async function j({preCached:e=!1}={}){if(c.resource.has("fonts-embed-css")){if(e){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=c.resource.get("fonts-embed-css"),document.head.appendChild(n)}return c.resource.get("fonts-embed-css")}let t=/@import\s+url\(["']?([^"')]+)["']?\)/g,a=[];for(let n of document.querySelectorAll("style")){let r=n.textContent||"",i=Array.from(r.matchAll(t));for(let l of i){let u=l[1];v(u)||ae(u)||a.push(u)}}await Promise.all(a.map(Ce));let s=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(n=>n.href),o="";for(let n of s)try{let i=await(await fetch(n.href)).text();if(v(n.href)||v(i))continue;let l=/url\((["']?)([^"')]+)\1\)/g,u=await Promise.all(Array.from(i.matchAll(l)).map(async f=>{let p=B(f[0]);if(!p)return null;let h=p;if(!h.startsWith("http")&&!h.startsWith("data:")&&(h=new URL(h,n.href).href),v(h))return null;if(c.resource.has(h))return c.font.add(h),{original:f[0],inlined:`url(${c.resource.get(h)})`};if(c.font.has(h))return null;try{let g=await(await fetch(h)).blob(),y=await new Promise(x=>{let C=new FileReader;C.onload=()=>x(C.result),C.readAsDataURL(g)});return c.resource.set(h,y),c.font.add(h),{original:f[0],inlined:`url(${y})`}}catch{return console.warn("[snapdom] Failed to fetch font resource:",h),null}})),m=i;for(let f of u)f&&(m=m.replace(f.original,f.inlined));o+=m+`
|
|
3
|
+
`}catch{console.warn("[snapdom] Failed to fetch CSS:",n.href)}for(let n of document.styleSheets)try{if(!n.href||s.every(r=>r.href!==n.href)){for(let r of n.cssRules)if(r.type===CSSRule.FONT_FACE_RULE){let i=r.style.getPropertyValue("src"),l=r.style.getPropertyValue("font-family");if(!i||v(l))continue;let u=/url\((["']?)([^"')]+)\1\)/g,m=i,f=Array.from(i.matchAll(u));for(let p of f){let h=p[2].trim();if(!h)continue;let d=h;if(!d.startsWith("http")&&!d.startsWith("data:")&&(d=new URL(d,n.href||location.href).href),!v(d)){if(c.resource.has(d)){c.font.add(d),m=m.replace(p[0],`url(${c.resource.get(d)})`);continue}if(!c.font.has(d))try{let y=await(await fetch(d)).blob(),x=await new Promise(C=>{let w=new FileReader;w.onload=()=>C(w.result),w.readAsDataURL(y)});c.resource.set(d,x),c.font.add(d),m=m.replace(p[0],`url(${x})`)}catch{console.warn("[snapdom] Failed to fetch font URL:",d)}}}o+=`@font-face {
|
|
4
4
|
font-family: ${l};
|
|
5
|
-
src: ${
|
|
6
|
-
font-style: ${
|
|
7
|
-
font-weight: ${
|
|
5
|
+
src: ${m};
|
|
6
|
+
font-style: ${r.style.getPropertyValue("font-style")||"normal"};
|
|
7
|
+
font-weight: ${r.style.getPropertyValue("font-weight")||"normal"};
|
|
8
8
|
}
|
|
9
|
-
`}}}catch(
|
|
10
|
-
font-family: '${
|
|
11
|
-
src: url(${
|
|
12
|
-
font-style: ${
|
|
13
|
-
font-weight: ${
|
|
9
|
+
`}}}catch(r){console.warn("[snapdom] Cannot access stylesheet",n.href,r)}for(let n of document.fonts)if(n.family&&n.status==="loaded"&&n._snapdomSrc){if(v(n.family))continue;let r=n._snapdomSrc;if(!r.startsWith("data:")){if(c.resource.has(n._snapdomSrc))r=c.resource.get(n._snapdomSrc),c.font.add(n._snapdomSrc);else if(!c.font.has(n._snapdomSrc))try{let l=await(await fetch(n._snapdomSrc)).blob();r=await new Promise(u=>{let m=new FileReader;m.onload=()=>u(m.result),m.readAsDataURL(l)}),c.resource.set(n._snapdomSrc,r),c.font.add(n._snapdomSrc)}catch{console.warn("[snapdom] Failed to fetch dynamic font src:",n._snapdomSrc);continue}}o+=`@font-face {
|
|
10
|
+
font-family: '${n.family}';
|
|
11
|
+
src: url(${r});
|
|
12
|
+
font-style: ${n.style||"normal"};
|
|
13
|
+
font-weight: ${n.weight||"normal"};
|
|
14
14
|
}
|
|
15
|
-
`}if(a&&(S.set("fonts-embed-css",a),t)){let o=document.createElement("style");o.setAttribute("data-snapdom","embedFonts"),o.textContent=a,document.head.appendChild(o)}return a}async function nt(t,e,n,r,a,o=!1,c){if(!(t instanceof Element)||!(e instanceof Element))return;for(let s of["::before","::after","::first-letter"])try{let f=L(t,s);if(!f||typeof f[Symbol.iterator]!="function")continue;if(s==="::first-letter"){let y=getComputedStyle(t);if(!(f.color!==y.color||f.fontSize!==y.fontSize||f.fontWeight!==y.fontWeight))continue;let E=Array.from(e.childNodes).find(C=>C.nodeType===Node.TEXT_NODE&&C.textContent&&C.textContent.trim().length>0);if(!E)continue;let P=E.textContent,T=P.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0],N=P.slice(T?.length||0);if(!T||/[\uD800-\uDFFF]/.test(T))continue;let k=document.createElement("span");k.textContent=T,k.dataset.snapdomPseudo="::first-letter";let I=J(f),q=V(I,"span",a);n.set(k,q);let z=document.createTextNode(N);e.replaceChild(z,E),e.insertBefore(k,z);continue}let d=f.getPropertyValue("content"),h=f.getPropertyValue("background-image"),u=f.getPropertyValue("background-color"),m=d!=="none",g=h&&h!=="none",p=u&&u!=="transparent"&&u!=="rgba(0, 0, 0, 0)";if(m||g||p){let y=f.getPropertyValue("font-family"),w=parseInt(f.getPropertyValue("font-size"))||32,E=parseInt(f.getPropertyValue("font-weight"))||!1,P=f.getPropertyValue("color")||"#000",b=document.createElement("span");b.dataset.snapdomPseudo=s;let T=J(f),N=V(T,"span",a);n.set(b,N);let k=A(y),I=ft(d);if(k&&I.length===1){let C=document.createElement("img");C.src=await mt(I,y,E,w,P),C.style=`width:${w}px;height:auto;object-fit:contain;`,b.appendChild(C)}else if(I.startsWith("url(")){let C=H(I);if(C&&C.trim()!=="")try{let $=document.createElement("img"),j=await U(Y(C,{useProxy:c}));$.src=j,$.style=`width:${w}px;height:auto;object-fit:contain;`,b.appendChild($)}catch($){console.error(`[snapdom] Error in pseudo ${s} for`,t,$)}}else!k&&I&&I!=="none"&&(b.textContent=I);if(g)try{let C=W(h),$=await Promise.all(C.map(j=>M(j)));b.style.backgroundImage=$.join(", ")}catch(C){console.warn(`[snapdom] Failed to inline background-image for ${s}`,C)}if(p&&(b.style.backgroundColor=u),!(b.childNodes.length>0||b.textContent&&b.textContent.trim()!==""||g||p))continue;s==="::before"?e.insertBefore(b,e.firstChild):e.appendChild(b)}}catch(f){console.warn(`[snapdom] Failed to capture ${s} for`,t,f)}let i=Array.from(t.children),l=Array.from(e.children).filter(s=>!s.dataset.snapdomPseudo);for(let s=0;s<Math.min(i.length,l.length);s++)await nt(i[s],l[s],n,r,a,o,c)}function gt(t){if(!t)return;let e=document.querySelectorAll("svg > defs");e.length&&t.querySelectorAll("svg").forEach(n=>{let r=n.querySelectorAll("use");if(!r.length)return;let a=new Set;if(r.forEach(c=>{let i=c.getAttribute("xlink:href")||c.getAttribute("href");i&&i.startsWith("#")&&a.add(i.slice(1))}),!a.size)return;let o=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let c of a)for(let i of e){let l=i.querySelector(`#${CSS.escape(c)}`);if(l){o.appendChild(l.cloneNode(!0));break}}o.childNodes.length&&n.insertBefore(o,n.firstChild)})}async function pt(t,e=!1,n=!1,r={}){let a=new Map,o=new WeakMap,c=new Map,i;try{i=_(t,a,o,c,e,r,t)}catch(s){throw console.warn("deepClone failed:",s),s}try{await nt(t,i,a,o,e,n,r.useProxy)}catch(s){console.warn("inlinePseudoElements failed:",s)}try{gt(i)}catch(s){console.warn("inlineExternalDef failed:",s)}let l="";if(e){let s=lt(a);l=Array.from(s.entries()).map(([f,d])=>`.${d}{${f}}`).join("");for(let[f,d]of a.entries()){if(f.tagName==="STYLE")continue;let h=s.get(d);h&&f.classList.add(h);let u=f.style?.backgroundImage;f.removeAttribute("style"),u&&u!=="none"&&(f.style.backgroundImage=u)}}else for(let[s,f]of a.entries())s.tagName!=="STYLE"&&s.setAttribute("style",f.replace(/;/g,"; "));for(let[s,f]of c.entries()){let d=f.scrollLeft,h=f.scrollTop;if((d||h)&&s instanceof HTMLElement){s.style.overflow="hidden",s.style.scrollbarWidth="none",s.style.msOverflowStyle="none";let m=document.createElement("div");for(m.style.transform=`translate(${-d}px, ${-h}px)`,m.style.willChange="transform",m.style.display="inline-block",m.style.width="100%";s.firstChild;)m.appendChild(s.firstChild);s.appendChild(m)}}if(t===c.get(i)){let s=o.get(t)||window.getComputedStyle(t);o.set(t,s);let f=dt(s.transform);i.style.margin="0",i.style.position="static",i.style.top="auto",i.style.left="auto",i.style.right="auto",i.style.bottom="auto",i.style.zIndex="auto",i.style.float="none",i.style.clear="none",i.style.transform=f||""}for(let[s,f]of c.entries())f.tagName==="PRE"&&(s.style.marginTop="0",s.style.marginBlockStart="0");return{clone:i,classCSS:l,styleCache:o}}async function yt(t,e={}){let n=Array.from(t.querySelectorAll("img")),r=async a=>{let o=a.src;try{let c=await U(o,{useProxy:e.useProxy});a.src=c,a.width||(a.width=a.naturalWidth||100),a.height||(a.height=a.naturalHeight||100)}catch{let c=document.createElement("div");c.style=`width: ${a.width||100}px; height: ${a.height||100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${a.height||100}px; color: #666; font-size: 12px;`,c.innerText="img",a.replaceWith(c)}};for(let a=0;a<n.length;a+=4){let o=n.slice(a,a+4).map(r);await Promise.allSettled(o)}}async function wt(t,e,n,r={}){let a=[[t,e]],o=["background-image","mask","mask-image","-webkit-mask-image","mask-source","mask-box-image-source","mask-border-source","-webkit-mask-box-image-source"];for(;a.length;){let[c,i]=a.shift(),l=n.get(c)||L(c);n.has(c)||n.set(c,l);for(let h of o){let u=l.getPropertyValue(h);if(!u||u==="none")continue;let m=W(u),g=await Promise.all(m.map(p=>M(p,r)));g.some(p=>p&&p!=="none"&&!/^url\(undefined/.test(p))&&i.style.setProperty(h,g.join(", "))}let s=l.getPropertyValue("background-color");s&&s!=="transparent"&&s!=="rgba(0, 0, 0, 0)"&&(i.style.backgroundColor=s);let f=Array.from(c.children),d=Array.from(i.children);for(let h=0;h<Math.min(f.length,d.length);h++)a.push([f[h],d[h]])}}async function xt(t,e={}){if(!t)throw new Error("Element cannot be null or undefined");let{compress:n=!0,embedFonts:r=!1,fast:a=!0,scale:o=1,useProxy:c=""}=e,i,l,s,f="",d="",h,u;if({clone:i,classCSS:l,styleCache:s}=await pt(t,n,r,e),await new Promise(g=>{O(async()=>{await yt(i,e),g()},{fast:a})}),await new Promise(g=>{O(async()=>{await wt(t,i,s,e),g()},{fast:a})}),r&&await new Promise(g=>{O(async()=>{f=await K(),g()},{fast:a})}),n){let g=it(i).sort(),p=g.join(",");D.has(p)?d=D.get(p):await new Promise(y=>{O(()=>{d=ct(g),D.set(p,d),y()},{fast:a})})}await new Promise(g=>{O(()=>{let p=t.getBoundingClientRect(),y=p.width,w=p.height,E=Number.isFinite(e.width),P=Number.isFinite(e.height),b=typeof o=="number"&&o!==1;if(!b){let $=p.width/p.height;E&&P?(y=e.width,w=e.height):E?(y=e.width,w=y/$):P&&(w=e.height,y=w*$)}if(y=Math.ceil(y),w=Math.ceil(w),i.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),i.style.transformOrigin="top left",!b&&(E||P)){let $=p.width,j=p.height,St=y/$,Et=w/j,$t=i.style.transform||"",vt=`scale(${St}, ${Et})`;i.style.transform=`${vt} ${$t}`.trim()}else b&&X()&&(i.style.scale=`${o}`);let T="http://www.w3.org/2000/svg",N=document.createElementNS(T,"foreignObject");N.setAttribute("width","100%"),N.setAttribute("height","100%");let k=document.createElement("style");k.textContent=d+f+"svg{overflow:visible;}"+l,N.appendChild(k),N.appendChild(i);let q=new XMLSerializer().serializeToString(N);u=`<svg xmlns="${T}" width="${y}" height="${w}" viewBox="0 0 ${y} ${w}">`+q+"</svg>",h=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(u)}`,g()},{fast:a})});let m=document.getElementById("snapdom-sandbox");return m&&m.style.position==="absolute"&&m.remove(),h}async function Nt(t,{dpr:e=1,scale:n=1}){let r=new Image;return r.src=t,await r.decode(),X?(r.width=r.width*n,r.height=r.height*n):(r.width=r.width/n,r.height=r.height/n),r}async function bt(t,{dpr:e=1,scale:n=1}={}){let r=new Image;r.src=t,await r.decode();let a=document.createElement("canvas"),o=r.width*n,c=r.height*n;a.width=Math.ceil(o*e),a.height=Math.ceil(c*e);let i=a.getContext("2d");return i.scale(e,e),i.drawImage(r,0,0,o,c),a.style.width=`${o}px`,a.style.height=`${c}px`,a}async function Ct(t,{type:e="svg",scale:n=1,backgroundColor:r="#fff",quality:a}={}){let o={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[e]||"image/png";if(e==="svg"){let i=decodeURIComponent(t.split(",")[1]);return new Blob([i],{type:"image/svg+xml"})}let c=await at(t,{dpr:1,scale:n},r);return new Promise(i=>{c.toBlob(l=>i(l),`${o}`,a)})}async function at(t,{dpr:e=1,scale:n=1},r){let a=await bt(t,{dpr:e,scale:n});if(!r)return a;let o=document.createElement("canvas");o.width=a.width,o.height=a.height;let c=o.getContext("2d");return c.fillStyle=r,c.fillRect(0,0,o.width,o.height),c.drawImage(a,0,0),o}async function ot(t,{dpr:e=1,scale:n=1,backgroundColor:r="#fff",quality:a},o="png"){let c=await at(t,{dpr:e,scale:n},r),i=new Image;return i.src=c.toDataURL(`image/${o}`,a),await i.decode(),i.style.width=`${c.width/e}px`,i.style.height=`${c.height/e}px`,i}async function Pt(t,{dpr:e=1,scale:n=1,backgroundColor:r="#fff",format:a="png",filename:o="capture"}={}){if(a==="svg"){let h=await Ct(t),u=URL.createObjectURL(h),m=document.createElement("a");m.href=u,m.download=`${o}.svg`,m.click(),URL.revokeObjectURL(u);return}let c=["jpg","jpeg","webp"].includes(a)?"#fff":void 0,l=await at(t,{dpr:e,scale:n},r??c),s={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[a]||"image/png",f=l.toDataURL(s),d=document.createElement("a");d.href=f,d.download=`${o}.${a}`,d.click()}async function x(t,e={}){if(e={scale:1,...e},!t)throw new Error("Element cannot be null or undefined");return e.iconFonts&&ht(e.iconFonts),await x.capture(t,e)}x.capture=async(t,e={})=>{let n=await xt(t,e),r=window.devicePixelRatio||1,a=e.scale||1;return{url:n,options:e,toRaw:()=>n,toImg:()=>Nt(n,{dpr:r,scale:a}),toCanvas:()=>bt(n,{dpr:r,scale:a}),toBlob:o=>Ct(n,{dpr:r,scale:a,...o}),toPng:o=>ot(n,{dpr:r,scale:a,...o},"png"),toJpg:o=>ot(n,{dpr:r,scale:a,...o},"jpeg"),toWebp:o=>ot(n,{dpr:r,scale:a,...o},"webp"),download:({format:o="png",filename:c="capture",backgroundColor:i}={})=>Pt(n,{dpr:r,scale:a,backgroundColor:i,format:o,filename:c})}};x.toRaw=async(t,e)=>(await x.capture(t,e)).toRaw();x.toImg=async(t,e)=>(await x.capture(t,e)).toImg();x.toCanvas=async(t,e)=>(await x.capture(t,e)).toCanvas();x.toBlob=async(t,e)=>(await x.capture(t,e)).toBlob(e);x.toPng=async(t,e)=>(await x.capture(t,e)).toPng(e);x.toJpg=async(t,e)=>(await x.capture(t,e)).toJpg(e);x.toWebp=async(t,e)=>(await x.capture(t,e)).toWebp(e);x.download=async(t,e={})=>{let{format:n="png",filename:r="capture",backgroundColor:a,...o}=e;return await(await x.capture(t,o)).download({format:n,filename:r,backgroundColor:a})};async function Lt(t=document,e={}){let{embedFonts:n=!0,reset:r=!1}=e;if(r){v.clear(),F.clear(),S.clear(),D.clear();return}await document.fonts.ready,rt();let a=[],o=[];t?.querySelectorAll&&(a=Array.from(t.querySelectorAll("img[src]")),o=Array.from(t.querySelectorAll("*")));let c=[];for(let i of a){let l=i.src;v.has(l)||c.push(U(l,{useProxy:e.useProxy}).then(s=>v.set(l,s)).catch(()=>{}))}for(let i of o){let l=L(i).backgroundImage;if(l&&l!=="none"){let s=W(l);for(let f of s)f.startsWith("url(")&&c.push(M(f,e).catch(()=>{}))}}n&&await K({preCached:!0}),await Promise.all(c)}export{Lt as preCache,x as snapdom};
|
|
15
|
+
`}if(o&&(c.resource.set("fonts-embed-css",o),e)){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=o,document.head.appendChild(n)}return o}async function H(e,t,a,s=!1,o){if(!(e instanceof Element)||!(t instanceof Element))return;for(let i of["::before","::after","::first-letter"])try{let l=A(e,i);if(!l||typeof l[Symbol.iterator]!="function")continue;if(i==="::first-letter"){let g=getComputedStyle(e);if(!(l.color!==g.color||l.fontSize!==g.fontSize||l.fontWeight!==g.fontWeight))continue;let x=Array.from(t.childNodes).find(S=>S.nodeType===Node.TEXT_NODE&&S.textContent&&S.textContent.trim().length>0);if(!x)continue;let C=x.textContent,k=C.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0],T=C.slice(k?.length||0);if(!k||/[\uD800-\uDFFF]/.test(k))continue;let E=document.createElement("span");E.textContent=k,E.dataset.snapdomPseudo="::first-letter";let $=_(l),V=F($,"span",a);c.preStyleMap.set(E,V);let U=document.createTextNode(T);t.replaceChild(U,x),t.insertBefore(E,U);continue}let u=l.getPropertyValue("content"),m=l.getPropertyValue("background-image"),f=l.getPropertyValue("background-color"),p=u!=="none",h=m&&m!=="none",d=f&&f!=="transparent"&&f!=="rgba(0, 0, 0, 0)";if(p||h||d){let g=l.getPropertyValue("font-family"),y=parseInt(l.getPropertyValue("font-size"))||32,x=parseInt(l.getPropertyValue("font-weight"))||!1,C=l.getPropertyValue("color")||"#000",w=document.createElement("span");w.dataset.snapdomPseudo=i;let k=_(l),T=F(k,"span",a);c.preStyleMap.set(w,T);let E=v(g),$=ee(u);if(E&&$.length===1){let S=document.createElement("img");S.src=await oe($,g,x,y,C),S.style=`width:${y}px;height:auto;object-fit:contain;`,w.appendChild(S)}else if($.startsWith("url(")){let S=B($);if(S&&S.trim()!=="")try{let I=document.createElement("img"),R=await N(O(S,{useProxy:o}));I.src=R,I.style=`width:${y}px;height:auto;object-fit:contain;`,w.appendChild(I)}catch(I){console.error(`[snapdom] Error in pseudo ${i} for`,e,I)}}else!E&&$&&$!=="none"&&(w.textContent=$);if(h)try{let S=L(m),I=await Promise.all(S.map(R=>M(R)));w.style.backgroundImage=I.join(", ")}catch(S){console.warn(`[snapdom] Failed to inline background-image for ${i}`,S)}if(d&&(w.style.backgroundColor=f),!(w.childNodes.length>0||w.textContent&&w.textContent.trim()!==""||h||d))continue;i==="::before"?t.insertBefore(w,t.firstChild):t.appendChild(w)}}catch(l){console.warn(`[snapdom] Failed to capture ${i} for`,e,l)}let n=Array.from(e.children),r=Array.from(t.children).filter(i=>!i.dataset.snapdomPseudo);for(let i=0;i<Math.min(n.length,r.length);i++)await H(n[i],r[i],a,s,o)}function re(e){if(!e)return;let t=document.querySelectorAll("svg > defs");t.length&&e.querySelectorAll("svg").forEach(a=>{let s=a.querySelectorAll("use");if(!s.length)return;let o=new Set;if(s.forEach(r=>{let i=r.getAttribute("xlink:href")||r.getAttribute("href");i&&i.startsWith("#")&&o.add(i.slice(1))}),!o.size)return;let n=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let r of o)for(let i of t){let l=i.querySelector(`#${CSS.escape(r)}`);if(l){n.appendChild(l.cloneNode(!0));break}}n.childNodes.length&&a.insertBefore(n,a.firstChild)})}async function se(e,t=!1,a=!1,s={}){let o,n;try{o=D(e,t,s,e)}catch(r){throw console.warn("deepClone failed:",r),r}try{await H(e,o,t,a,s.useProxy)}catch(r){console.warn("inlinePseudoElements failed:",r)}try{re(o)}catch(r){console.warn("inlineExternalDef failed:",r)}if(t){let r=Z();n=Array.from(r.entries()).map(([i,l])=>`.${l}{${i}}`).join("");for(let[i,l]of c.preStyleMap.entries()){if(i.tagName==="STYLE")continue;let u=r.get(l);u&&i.classList.add(u);let m=i.style?.backgroundImage;i.removeAttribute("style"),m&&m!=="none"&&(i.style.backgroundImage=m)}}else for(let[r,i]of c.preStyleMap.entries())r.tagName!=="STYLE"&&r.setAttribute("style",i.replace(/;/g,"; "));for(let[r,i]of c.preNodeMap.entries()){let l=i.scrollLeft,u=i.scrollTop;if((l||u)&&r instanceof HTMLElement){r.style.overflow="hidden",r.style.scrollbarWidth="none",r.style.msOverflowStyle="none";let f=document.createElement("div");for(f.style.transform=`translate(${-l}px, ${-u}px)`,f.style.willChange="transform",f.style.display="inline-block",f.style.width="100%";r.firstChild;)f.appendChild(r.firstChild);r.appendChild(f)}}if(e===c.preNodeMap.get(o)){let r=c.preStyle.get(e)||window.getComputedStyle(e);c.preStyle.set(e,r);let i=te(r.transform);o.style.margin="0",o.style.position="static",o.style.top="auto",o.style.left="auto",o.style.right="auto",o.style.bottom="auto",o.style.zIndex="auto",o.style.float="none",o.style.clear="none",o.style.transform=i||""}for(let[r,i]of c.preNodeMap.entries())i.tagName==="PRE"&&(r.style.marginTop="0",r.style.marginBlockStart="0");return{clone:o,classCSS:n}}async function ie(e,t={}){let a=Array.from(e.querySelectorAll("img")),s=async o=>{let n=o.src;try{let r=await N(n,{useProxy:t.useProxy});o.src=r,o.width||(o.width=o.naturalWidth||100),o.height||(o.height=o.naturalHeight||100)}catch{let r=document.createElement("div");r.style=`width: ${o.width||100}px; height: ${o.height||100}px; background: #ccc; display: inline-block; text-align: center; line-height: ${o.height||100}px; color: #666; font-size: 12px;`,r.innerText="img",o.replaceWith(r)}};for(let o=0;o<a.length;o+=4){let n=a.slice(o,o+4).map(s);await Promise.allSettled(n)}}async function ce(e,t,a={}){let s=[[e,t]],o=["background-image","mask","mask-image","-webkit-mask-image","mask-source","mask-box-image-source","mask-border-source","-webkit-mask-box-image-source"];for(;s.length;){let[n,r]=s.shift(),i=c.preStyle.get(n)||A(n);c.preStyle.has(n)||c.preStyle.set(n,i);for(let f of o){let p=i.getPropertyValue(f);if(!p||p==="none")continue;let h=L(p),d=await Promise.all(h.map(g=>M(g,a)));d.some(g=>g&&g!=="none"&&!/^url\(undefined/.test(g))&&r.style.setProperty(f,d.join(", "))}let l=i.getPropertyValue("background-color");l&&l!=="transparent"&&l!=="rgba(0, 0, 0, 0)"&&(r.style.backgroundColor=l);let u=Array.from(n.children),m=Array.from(r.children);for(let f=0;f<Math.min(u.length,m.length);f++)s.push([u[f],m[f]])}}async function le(e,t={}){if(!e)throw new Error("Element cannot be null or undefined");c.reset();let{compress:a=!0,embedFonts:s=!1,fast:o=!0,scale:n=1,useProxy:r=""}=t,i,l,u="",m="",f,p;if({clone:i,classCSS:l}=await se(e,a,s,t),await new Promise(d=>{P(async()=>{await ie(i,t),d()},{fast:o})}),await new Promise(d=>{P(async()=>{await ce(e,i,t),d()},{fast:o})}),s&&await new Promise(d=>{P(async()=>{u=await j(),d()},{fast:o})}),a){let d=J(i).sort(),g=d.join(",");c.baseStyle.has(g)?m=c.baseStyle.get(g):await new Promise(y=>{P(()=>{m=Q(d),c.baseStyle.set(g,m),y()},{fast:o})})}await new Promise(d=>{P(()=>{let g=e.getBoundingClientRect(),y=g.width,x=g.height,C=Number.isFinite(t.width),w=Number.isFinite(t.height),k=typeof n=="number"&&n!==1;if(!k){let R=g.width/g.height;C&&w?(y=t.width,x=t.height):C?(y=t.width,x=y/R):w&&(x=t.height,y=x*R)}if(y=Math.ceil(y),x=Math.ceil(x),i.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),i.style.transformOrigin="top left",!k&&(C||w)){let R=g.width,ue=g.height,me=y/R,pe=x/ue,he=i.style.transform||"",ge=`scale(${me}, ${pe})`;i.style.transform=`${ge} ${he}`.trim()}else k&&W()&&(i.style.scale=`${n}`);let T="http://www.w3.org/2000/svg",E=document.createElementNS(T,"foreignObject");E.setAttribute("width","100%"),E.setAttribute("height","100%");let $=document.createElement("style");$.textContent=m+u+"svg{overflow:visible;}"+l,E.appendChild($),E.appendChild(i);let U=new XMLSerializer().serializeToString(E);p=`<svg xmlns="${T}" width="${y}" height="${x}" viewBox="0 0 ${y} ${x}">`+U+"</svg>",f=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(p)}`,d()},{fast:o})});let h=document.getElementById("snapdom-sandbox");return h&&h.style.position==="absolute"&&h.remove(),f}async function Ee(e,{dpr:t=1,scale:a=1}){let s=new Image;return s.src=e,await s.decode(),W?(s.width=s.width*a,s.height=s.height*a):(s.width=s.width/a,s.height=s.height/a),s}async function fe(e,{dpr:t=1,scale:a=1}={}){let s=new Image;s.src=e,await s.decode();let o=document.createElement("canvas"),n=s.width*a,r=s.height*a;o.width=Math.ceil(n*t),o.height=Math.ceil(r*t);let i=o.getContext("2d");return i.scale(t,t),i.drawImage(s,0,0,n,r),o.style.width=`${n}px`,o.style.height=`${r}px`,o}async function de(e,{type:t="svg",scale:a=1,backgroundColor:s="#fff",quality:o}={}){let n={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[t]||"image/png";if(t==="svg"){let i=decodeURIComponent(e.split(",")[1]);return new Blob([i],{type:"image/svg+xml"})}let r=await X(e,{dpr:1,scale:a},s);return new Promise(i=>{r.toBlob(l=>i(l),`${n}`,o)})}async function X(e,{dpr:t=1,scale:a=1},s){let o=await fe(e,{dpr:t,scale:a});if(!s)return o;let n=document.createElement("canvas");n.width=o.width,n.height=o.height;let r=n.getContext("2d");return r.fillStyle=s,r.fillRect(0,0,n.width,n.height),r.drawImage(o,0,0),n}async function K(e,{dpr:t=1,scale:a=1,backgroundColor:s="#fff",quality:o},n="png"){let r=await X(e,{dpr:t,scale:a},s),i=new Image;return i.src=r.toDataURL(`image/${n}`,o),await i.decode(),i.style.width=`${r.width/t}px`,i.style.height=`${r.height/t}px`,i}async function $e(e,{dpr:t=1,scale:a=1,backgroundColor:s="#fff",format:o="png",filename:n="capture"}={}){if(o==="svg"){let p=await de(e),h=URL.createObjectURL(p),d=document.createElement("a");d.href=h,d.download=`${n}.svg`,d.click(),URL.revokeObjectURL(h);return}let r=["jpg","jpeg","webp"].includes(o)?"#fff":void 0,l=await X(e,{dpr:t,scale:a},s??r),u={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[o]||"image/png",m=l.toDataURL(u),f=document.createElement("a");f.href=m,f.download=`${n}.${o}`,f.click()}async function b(e,t={}){if(t={scale:1,...t},!e)throw new Error("Element cannot be null or undefined");return t.iconFonts&&ne(t.iconFonts),await b.capture(e,t)}b.capture=async(e,t={})=>{let a=await le(e,t),s=window.devicePixelRatio||1,o=t.scale||1;return{url:a,options:t,toRaw:()=>a,toImg:()=>Ee(a,{dpr:s,scale:o}),toCanvas:()=>fe(a,{dpr:s,scale:o}),toBlob:n=>de(a,{dpr:s,scale:o,...n}),toPng:n=>K(a,{dpr:s,scale:o,...n},"png"),toJpg:n=>K(a,{dpr:s,scale:o,...n},"jpeg"),toWebp:n=>K(a,{dpr:s,scale:o,...n},"webp"),download:({format:n="png",filename:r="capture",backgroundColor:i}={})=>$e(a,{dpr:s,scale:o,backgroundColor:i,format:n,filename:r})}};b.toRaw=async(e,t)=>(await b.capture(e,t)).toRaw();b.toImg=async(e,t)=>(await b.capture(e,t)).toImg();b.toCanvas=async(e,t)=>(await b.capture(e,t)).toCanvas();b.toBlob=async(e,t)=>(await b.capture(e,t)).toBlob(t);b.toPng=async(e,t)=>(await b.capture(e,t)).toPng(t);b.toJpg=async(e,t)=>(await b.capture(e,t)).toJpg(t);b.toWebp=async(e,t)=>(await b.capture(e,t)).toWebp(t);b.download=async(e,t={})=>{let{format:a="png",filename:s="capture",backgroundColor:o,...n}=t;return await(await b.capture(e,n)).download({format:a,filename:s,backgroundColor:o})};async function ke(e=document,t={}){let{embedFonts:a=!0,reset:s=!1}=t;if(s){c.reset();return}await document.fonts.ready,Y();let o=[],n=[];e?.querySelectorAll&&(o=Array.from(e.querySelectorAll("img[src]")),n=Array.from(e.querySelectorAll("*")));let r=[];for(let i of o){let l=i.src;c.image.has(l)||r.push(N(l,{useProxy:t.useProxy}).then(u=>c.image.set(l,u)).catch(()=>{}))}for(let i of n){let l=A(i).backgroundImage;if(l&&l!=="none"){let u=L(l);for(let m of u)m.startsWith("url(")&&r.push(M(m,t).catch(()=>{}))}}a&&await j({preCached:!0}),await Promise.all(r)}export{ke as preCache,b as snapdom};
|