@zumer/snapdom 1.9.6-dev.1 → 1.9.6-dev.2
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 +3 -4
- package/dist/snapdom.min.js +5 -5
- package/dist/snapdom.min.mjs +5 -5
- package/dist/snapdom.mjs +3 -4
- package/package.json +1 -1
package/dist/snapdom.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
/*
|
|
3
3
|
* snapdom
|
|
4
|
-
* v.1.9.6-dev.
|
|
4
|
+
* v.1.9.6-dev.2
|
|
5
5
|
* Author Juan Martin Muda
|
|
6
6
|
* License MIT
|
|
7
7
|
**/
|
|
@@ -589,9 +589,8 @@
|
|
|
589
589
|
img.src = dataURL;
|
|
590
590
|
img.width = node.width;
|
|
591
591
|
img.height = node.height;
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
img.style.height = node.style.height || `${node.height}px`;
|
|
592
|
+
cache.preNodeMap.set(img, node);
|
|
593
|
+
inlineAllStyles(node, img, compress);
|
|
595
594
|
return img;
|
|
596
595
|
}
|
|
597
596
|
let clone;
|
package/dist/snapdom.min.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
(()=>{var _e=Object.defineProperty;var X=Object.getOwnPropertySymbols;var ce=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var ie=(e,t,r)=>t in e?_e(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,L=(e,t)=>{for(var r in t||(t={}))ce.call(t,r)&&ie(e,r,t[r]);if(X)for(var r of X(t))le.call(t,r)&&ie(e,r,t[r]);return e};var fe=(e,t)=>{var r={};for(var i in e)ce.call(e,i)&&t.indexOf(i)<0&&(r[i]=e[i]);if(e!=null&&X)for(var i of X(e))t.indexOf(i)<0&&le.call(e,i)&&(r[i]=e[i]);return r};var $=(e,t)=>()=>(e&&(t=e(e=0)),t);var qe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var
|
|
2
|
-
`;return r}function me(){let e=new Set(f.preStyleMap.values()),t=new Map,r=1;for(let i of e)t.set(i,`c${r++}`);return t}var He,U=$(()=>{I();He=["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 B(r){return m(this,arguments,function*(e,t={}){let i=V(e),c=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(e);if(i){let n=G(i);if(f.background.has(n))return t.skipInline?void 0:`url(${f.background.get(n)})`;{let s=yield F(n,{useProxy:t.useProxy});return f.background.set(n,s),t.skipInline?void 0:`url("${s}")`}}return e})}function D(e,{fast:t=!1}={}){if(t)return e();"requestIdleCallback"in window?requestIdleCallback(e,{timeout:50}):setTimeout(e,1)}function M(e,t=null){if(!(e instanceof Element))return window.getComputedStyle(e,t);let r=f.computedStyle.get(e);if(r||(r=new Map,f.computedStyle.set(e,r)),!r.has(t)){let i=window.getComputedStyle(e,t);r.set(t,i)}return r.get(t)}function ge(e){let t=e.replace(/^['"]|['"]$/g,"");if(t.startsWith("\\"))try{return String.fromCharCode(parseInt(t.replace("\\",""),16))}catch(r){return t}return t}function V(e){let t=e.indexOf("url(");if(t===-1)return null;let r=e.slice(t+4).trim();return r.endsWith(")")&&(r=r.slice(0,-1).trim()),(r.startsWith('"')&&r.endsWith('"')||r.startsWith("'")&&r.endsWith("'"))&&(r=r.slice(1,-1)),r}function F(e,{timeout:t=3e3,useProxy:r=""}={}){function i(o){try{return new URL(o,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch(l){return"anonymous"}}function c(o){return m(this,null,function*(){let l=d=>fetch(d,{mode:"cors",credentials:i(d)==="use-credentials"?"include":"omit"}).then(p=>p.blob()).then(p=>new Promise((g,h)=>{let u=new FileReader;u.onloadend=()=>{let y=u.result;if(typeof y!="string"||!y.startsWith("data:image/")){h(new Error("Invalid image data URL"));return}g(y)},u.onerror=()=>h(new Error("FileReader error")),u.readAsDataURL(p)}));try{return yield l(o)}catch(d){if(r&&typeof r=="string"){let p=r.replace(/\/$/,"")+G(o);try{return yield l(p)}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}`),f.image.has(e)?(console.log(`[SnapDOM - fetchImage] Cache hit for: ${e}`),Promise.resolve(f.image.get(e))):e.startsWith("data:image/")?(f.image.set(e,e),Promise.resolve(e)):/\.svg(\?.*)?$/i.test(e)?m(null,null,function*(){try{let l=yield(yield fetch(e,{mode:"cors",credentials:n==="use-credentials"?"include":"omit"})).text(),d=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(l)}`;return f.image.set(e,d),d}catch(o){return c(e)}}):new Promise((o,l)=>{let d=setTimeout(()=>{console.log(`[SnapDOM - fetchImage] Timeout after ${t}ms for image: ${e}`),l(new Error("Image load timed out"))},t),p=new Image;p.crossOrigin=n,p.onload=()=>m(null,null,function*(){clearTimeout(d);try{yield p.decode();let g=document.createElement("canvas");g.width=p.width,g.height=p.height,g.getContext("2d").drawImage(p,0,0,g.width,g.height);let u=g.toDataURL("image/png");f.image.set(e,u),o(u)}catch(g){try{let h=yield c(e);f.image.set(e,h),o(h)}catch(h){l(h)}}}),p.onerror=()=>m(null,null,function*(){clearTimeout(d),console.error(`[SnapDOM - fetchImage] Image failed to load: ${e}`);try{let g=yield c(e);f.image.set(e,g),o(g)}catch(g){l(g)}}),p.src=e})}function te(e){let t={};for(let r of e)t[r]=e.getPropertyValue(r);return t}function Y(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function ye(e){if(!e||e==="none")return"";let t=e.replace(/translate[XY]?\([^)]*\)/g,"");return t=t.replace(/matrix\(([^)]+)\)/g,(r,i)=>{let c=i.split(",").map(n=>n.trim());return c.length!==6?`matrix(${i})`:(c[4]="0",c[5]="0",`matrix(${c.join(", ")})`)}),t=t.replace(/matrix3d\(([^)]+)\)/g,(r,i)=>{let c=i.split(",").map(n=>n.trim());return c.length!==16?`matrix3d(${i})`:(c[12]="0",c[13]="0",`matrix3d(${c.join(", ")})`)}),t.trim().replace(/\s{2,}/g," ")}function G(e){if(/%[0-9A-Fa-f]{2}/.test(e))return e;try{return encodeURI(e)}catch(t){return e}}function W(e){let t=[],r=0,i=0;for(let c=0;c<e.length;c++){let n=e[c];n==="("&&r++,n===")"&&r--,n===","&&r===0&&(t.push(e.slice(i,c).trim()),i=c+1)}return t.push(e.slice(i).trim()),t}var A=$(()=>{I()});function Ke(e){let t={};for(let r=0;r<e.length;r++){let i=e[r],c=e.getPropertyValue(i);(i==="background-image"||i==="content")&&c.includes("url(")&&!c.includes("data:")&&(c="none"),t[i]=c}return t}function ne(e,t,r){var o;if(e.tagName==="STYLE")return;f.preStyle.has(e)||f.preStyle.set(e,M(e));let i=f.preStyle.get(e);if(!f.snapshot.has(e)){let l=Ke(i);f.snapshot.set(e,l)}let c=f.snapshot.get(e),n=Object.entries(c).sort(([l],[d])=>l.localeCompare(d)).map(([l,d])=>`${l}:${d}`).join(";");if(f.snapshotKey.has(n)){f.preStyleMap.set(t,f.snapshotKey.get(n));return}let s=((o=e.tagName)==null?void 0:o.toLowerCase())||"div",a=O(c,s,r);f.snapshotKey.set(n,a),f.preStyleMap.set(t,a)}var we=$(()=>{U();A();I()});function Xe(e){return e.nodeType===Node.ELEMENT_NODE&&e.tagName==="SLOT"}function _(e,t,r={},i){var c,n;if(!e)throw new Error("Invalid node: node is null or undefined");try{if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return e.cloneNode(!0);if(e.getAttribute("data-capture")==="exclude"){let a=document.createElement("div"),o=e.getBoundingClientRect();return a.style.cssText=`display: inline-block; width: ${o.width}px; height: ${o.height}px; visibility: hidden;`,a}if(r.exclude&&Array.isArray(r.exclude))for(let a of r.exclude)try{if((c=e.matches)!=null&&c.call(e,a)){let o=document.createElement("div"),l=e.getBoundingClientRect();return o.style.cssText=`display: inline-block; width: ${l.width}px; height: ${l.height}px; visibility: hidden;`,o}}catch(o){console.warn(`Invalid selector in exclude option: ${a}`,o)}if(typeof r.filter=="function")try{if(!r.filter(e,i||e)){let a=document.createElement("div"),o=e.getBoundingClientRect();return a.style.cssText=`display: inline-block; width: ${o.width}px; height: ${o.height}px; visibility: hidden;`,a}}catch(a){console.warn("Error in filter function:",a)}if(e.tagName==="IFRAME"){let a=document.createElement("div");return a.textContent="",a.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;`,a}if(e.getAttribute("data-capture")==="placeholder"){let a=e.cloneNode(!1);f.preNodeMap.set(a,e),ne(e,a,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;",a.appendChild(o),a}if(e.tagName==="CANVAS"){let a=e.toDataURL(),o=document.createElement("img");return o.src=a,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;try{if(s=e.cloneNode(!1),!s)throw new Error("Failed to clone node: cloneNode returned null");f.preNodeMap.set(s,e)}catch(a){throw console.error("[Snapdom] Failed to clone node:",e,a),a}if(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 a=e.getBoundingClientRect();s.textContent=e.value,s.style.width=`${a.width}px`,s.style.height=`${a.height}px`}else e instanceof HTMLSelectElement&&(s.value=e.value,Array.from(s.options).forEach(a=>{a.value===e.value?a.setAttribute("selected",""):a.removeAttribute("selected")}));ne(e,s,t);try{if(Xe(e)){let a=((n=e.assignedNodes)==null?void 0:n.call(e,{flatten:!0}))||[],o=a.length>0?a:Array.from(e.childNodes),l=document.createDocumentFragment();for(let d of o)try{let p=_(d,t,r,i||e);p&&l.appendChild(p)}catch(p){console.warn("[Snapdom] Failed to clone slot content:",d,p)}return l}else{let a=e.shadowRoot?e.shadowRoot.childNodes:e.childNodes;for(let o of a)try{let l=_(o,t,r,i||e);l&&s.appendChild(l)}catch(l){console.warn("[Snapdom] Failed to clone child node:",o,l)}if(e.shadowRoot&&e.childNodes.length>0&&!e.shadowRoot.querySelector("slot")){let o=document.createDocumentFragment();for(let l of e.childNodes)try{let d=_(l,t,r,i||e);d&&o.appendChild(d)}catch(d){console.warn("[Snapdom] Failed to clone light DOM child:",l,d)}s.appendChild(o)}}}catch(a){throw console.error("[Snapdom] Error cloning children:",a),a}return s}catch(s){throw console.error("[Snapdom] Error in deepClone:",s),s}}var xe=$(()=>{we();I()});function Se(e){let t=Array.isArray(e)?e:[e];for(let r of t)r instanceof RegExp?oe.push(r):typeof r=="string"?oe.push(new RegExp(r,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",r)}function N(e){let t=typeof e=="string"?e:"",r=[...Ye,...oe];for(let i of r)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))}var Ye,oe,J=$(()=>{Ye=[/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],oe=[]});function be(e,t,r,i=32,c="#000"){return m(this,null,function*(){t=t.replace(/^['"]+|['"]+$/g,"");let n=window.devicePixelRatio||1,a=document.createElement("canvas").getContext("2d");a.font=r?`${r} ${i}px "${t}"`:`${i}px "${t}"`;let o=a.measureText(e),l=o.actualBoundingBoxAscent||i*.8,d=o.actualBoundingBoxDescent||i*.2,p=l+d,g=o.width,h=document.createElement("canvas");h.width=Math.ceil(g*n),h.height=Math.ceil(p*n);let u=h.getContext("2d");return u.scale(n,n),u.font=a.font,u.textAlign="left",u.textBaseline="alphabetic",u.fillStyle=c,u.fillText(e,0,l),h.toDataURL()})}function Ce(e){return Array.from(document.styleSheets).some(t=>t.href===e)}function Ge(e){return new Promise(t=>{if(Ce(e))return t(null);let r=document.createElement("link");r.rel="stylesheet",r.href=e,r.setAttribute("data-snapdom","injected-import"),r.onload=()=>t(r),r.onerror=()=>t(null),document.head.appendChild(r)})}function Q(){return m(this,arguments,function*({preCached:e=!1}={}){if(f.resource.has("fonts-embed-css")){if(e){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=f.resource.get("fonts-embed-css"),document.head.appendChild(n)}return f.resource.get("fonts-embed-css")}let t=/@import\s+url\(["']?([^"')]+)["']?\)/g,r=[];for(let n of document.querySelectorAll("style")){let s=n.textContent||"",a=Array.from(s.matchAll(t));for(let o of a){let l=o[1];N(l)||Ce(l)||r.push(l)}}yield Promise.all(r.map(Ge));let i=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(n=>n.href),c="";for(let n of i)try{let a=yield(yield fetch(n.href)).text();if(N(n.href)||N(a))continue;let o=/url\((["']?)([^"')]+)\1\)/g,l=yield Promise.all(Array.from(a.matchAll(o)).map(p=>m(null,null,function*(){let g=V(p[0]);if(!g)return null;let h=g;if(!h.startsWith("http")&&!h.startsWith("data:")&&(h=new URL(h,n.href).href),N(h))return null;if(f.resource.has(h))return f.font.add(h),{original:p[0],inlined:`url(${f.resource.get(h)})`};if(f.font.has(h))return null;try{let y=yield(yield fetch(h)).blob(),b=yield new Promise(w=>{let C=new FileReader;C.onload=()=>w(C.result),C.readAsDataURL(y)});return f.resource.set(h,b),f.font.add(h),{original:p[0],inlined:`url(${b})`}}catch(u){return console.warn("[snapdom] Failed to fetch font resource:",h),null}}))),d=a;for(let p of l)p&&(d=d.replace(p.original,p.inlined));c+=d+`
|
|
3
|
-
`}catch(s){console.warn("[snapdom] Failed to fetch CSS:",n.href)}for(let n of document.styleSheets)try{if(!n.href||i.every(s=>s.href!==n.href)){for(let s of n.cssRules)if(s.type===CSSRule.FONT_FACE_RULE){let a=s.style.getPropertyValue("src"),o=s.style.getPropertyValue("font-family");if(!a||
|
|
1
|
+
(()=>{var _e=Object.defineProperty;var X=Object.getOwnPropertySymbols;var ce=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var ie=(e,t,r)=>t in e?_e(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,L=(e,t)=>{for(var r in t||(t={}))ce.call(t,r)&&ie(e,r,t[r]);if(X)for(var r of X(t))le.call(t,r)&&ie(e,r,t[r]);return e};var fe=(e,t)=>{var r={};for(var i in e)ce.call(e,i)&&t.indexOf(i)<0&&(r[i]=e[i]);if(e!=null&&X)for(var i of X(e))t.indexOf(i)<0&&le.call(e,i)&&(r[i]=e[i]);return r};var $=(e,t)=>()=>(e&&(t=e(e=0)),t);var qe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var h=(e,t,r)=>new Promise((i,c)=>{var n=o=>{try{a(r.next(o))}catch(l){c(l)}},s=o=>{try{a(r.throw(o))}catch(l){c(l)}},a=o=>o.done?i(o.value):Promise.resolve(o.value).then(n,s);a((r=r.apply(e,t)).next())});function ze(){f.computedStyle=new WeakMap,f.snapshot=new WeakMap,f.snapshotKey.clear(),f.preStyleMap.clear(),f.preStyle=new WeakMap,f.preNodeMap.clear()}var f,I=$(()=>{f={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:ze}});function de(){for(let e of He)pe(e)}function pe(e){if(f.defaultStyle.has(e))return f.defaultStyle.get(e);if(new Set(["script","style","meta","link","noscript","template"]).has(e)){let s={};return f.defaultStyle.set(e,s),s}let r=document.getElementById("snapdom-sandbox");r||(r=document.createElement("div"),r.id="snapdom-sandbox",r.style.position="absolute",r.style.left="-9999px",r.style.top="-9999px",r.style.width="0",r.style.height="0",r.style.overflow="hidden",document.body.appendChild(r));let i=document.createElement(e);i.style.all="initial",r.appendChild(i);let c=getComputedStyle(i),n={};for(let s of c)n[s]=c.getPropertyValue(s);return r.removeChild(i),f.defaultStyle.set(e,n),n}function O(e,t,r=!1){let i=[],c=pe(t);for(let[n,s]of Object.entries(e))if(!r)s&&i.push(`${n}:${s}`);else{let a=c[n];s&&s!==a&&i.push(`${n}:${s}`)}return i.sort().join(";")}function ue(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(r=>t.add(r.tagName.toLowerCase())),Array.from(t))}function me(e){let t=new Map;for(let i of e){let c=f.defaultStyle.get(i);if(!c)continue;let n=Object.entries(c).map(([s,a])=>`${s}:${a};`).sort().join("");t.has(n)||t.set(n,[]),t.get(n).push(i)}let r="";for(let[i,c]of t.entries())r+=`${c.join(",")} { ${i} }
|
|
2
|
+
`;return r}function he(){let e=new Set(f.preStyleMap.values()),t=new Map,r=1;for(let i of e)t.set(i,`c${r++}`);return t}var He,U=$(()=>{I();He=["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 B(r){return h(this,arguments,function*(e,t={}){let i=V(e),c=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(e);if(i){let n=G(i);if(f.background.has(n))return t.skipInline?void 0:`url(${f.background.get(n)})`;{let s=yield F(n,{useProxy:t.useProxy});return f.background.set(n,s),t.skipInline?void 0:`url("${s}")`}}return e})}function D(e,{fast:t=!1}={}){if(t)return e();"requestIdleCallback"in window?requestIdleCallback(e,{timeout:50}):setTimeout(e,1)}function M(e,t=null){if(!(e instanceof Element))return window.getComputedStyle(e,t);let r=f.computedStyle.get(e);if(r||(r=new Map,f.computedStyle.set(e,r)),!r.has(t)){let i=window.getComputedStyle(e,t);r.set(t,i)}return r.get(t)}function ge(e){let t=e.replace(/^['"]|['"]$/g,"");if(t.startsWith("\\"))try{return String.fromCharCode(parseInt(t.replace("\\",""),16))}catch(r){return t}return t}function V(e){let t=e.indexOf("url(");if(t===-1)return null;let r=e.slice(t+4).trim();return r.endsWith(")")&&(r=r.slice(0,-1).trim()),(r.startsWith('"')&&r.endsWith('"')||r.startsWith("'")&&r.endsWith("'"))&&(r=r.slice(1,-1)),r}function F(e,{timeout:t=3e3,useProxy:r=""}={}){function i(o){try{return new URL(o,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch(l){return"anonymous"}}function c(o){return h(this,null,function*(){let l=d=>fetch(d,{mode:"cors",credentials:i(d)==="use-credentials"?"include":"omit"}).then(p=>p.blob()).then(p=>new Promise((g,u)=>{let m=new FileReader;m.onloadend=()=>{let y=m.result;if(typeof y!="string"||!y.startsWith("data:image/")){u(new Error("Invalid image data URL"));return}g(y)},m.onerror=()=>u(new Error("FileReader error")),m.readAsDataURL(p)}));try{return yield l(o)}catch(d){if(r&&typeof r=="string"){let p=r.replace(/\/$/,"")+G(o);try{return yield l(p)}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}`),f.image.has(e)?(console.log(`[SnapDOM - fetchImage] Cache hit for: ${e}`),Promise.resolve(f.image.get(e))):e.startsWith("data:image/")?(f.image.set(e,e),Promise.resolve(e)):/\.svg(\?.*)?$/i.test(e)?h(null,null,function*(){try{let l=yield(yield fetch(e,{mode:"cors",credentials:n==="use-credentials"?"include":"omit"})).text(),d=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(l)}`;return f.image.set(e,d),d}catch(o){return c(e)}}):new Promise((o,l)=>{let d=setTimeout(()=>{console.log(`[SnapDOM - fetchImage] Timeout after ${t}ms for image: ${e}`),l(new Error("Image load timed out"))},t),p=new Image;p.crossOrigin=n,p.onload=()=>h(null,null,function*(){clearTimeout(d);try{yield p.decode();let g=document.createElement("canvas");g.width=p.width,g.height=p.height,g.getContext("2d").drawImage(p,0,0,g.width,g.height);let m=g.toDataURL("image/png");f.image.set(e,m),o(m)}catch(g){try{let u=yield c(e);f.image.set(e,u),o(u)}catch(u){l(u)}}}),p.onerror=()=>h(null,null,function*(){clearTimeout(d),console.error(`[SnapDOM - fetchImage] Image failed to load: ${e}`);try{let g=yield c(e);f.image.set(e,g),o(g)}catch(g){l(g)}}),p.src=e})}function ne(e){let t={};for(let r of e)t[r]=e.getPropertyValue(r);return t}function Y(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function ye(e){if(!e||e==="none")return"";let t=e.replace(/translate[XY]?\([^)]*\)/g,"");return t=t.replace(/matrix\(([^)]+)\)/g,(r,i)=>{let c=i.split(",").map(n=>n.trim());return c.length!==6?`matrix(${i})`:(c[4]="0",c[5]="0",`matrix(${c.join(", ")})`)}),t=t.replace(/matrix3d\(([^)]+)\)/g,(r,i)=>{let c=i.split(",").map(n=>n.trim());return c.length!==16?`matrix3d(${i})`:(c[12]="0",c[13]="0",`matrix3d(${c.join(", ")})`)}),t.trim().replace(/\s{2,}/g," ")}function G(e){if(/%[0-9A-Fa-f]{2}/.test(e))return e;try{return encodeURI(e)}catch(t){return e}}function W(e){let t=[],r=0,i=0;for(let c=0;c<e.length;c++){let n=e[c];n==="("&&r++,n===")"&&r--,n===","&&r===0&&(t.push(e.slice(i,c).trim()),i=c+1)}return t.push(e.slice(i).trim()),t}var N=$(()=>{I()});function Ke(e){let t={};for(let r=0;r<e.length;r++){let i=e[r],c=e.getPropertyValue(i);(i==="background-image"||i==="content")&&c.includes("url(")&&!c.includes("data:")&&(c="none"),t[i]=c}return t}function J(e,t,r){var o;if(e.tagName==="STYLE")return;f.preStyle.has(e)||f.preStyle.set(e,M(e));let i=f.preStyle.get(e);if(!f.snapshot.has(e)){let l=Ke(i);f.snapshot.set(e,l)}let c=f.snapshot.get(e),n=Object.entries(c).sort(([l],[d])=>l.localeCompare(d)).map(([l,d])=>`${l}:${d}`).join(";");if(f.snapshotKey.has(n)){f.preStyleMap.set(t,f.snapshotKey.get(n));return}let s=((o=e.tagName)==null?void 0:o.toLowerCase())||"div",a=O(c,s,r);f.snapshotKey.set(n,a),f.preStyleMap.set(t,a)}var we=$(()=>{U();N();I()});function Xe(e){return e.nodeType===Node.ELEMENT_NODE&&e.tagName==="SLOT"}function _(e,t,r={},i){var c,n;if(!e)throw new Error("Invalid node: node is null or undefined");try{if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return e.cloneNode(!0);if(e.getAttribute("data-capture")==="exclude"){let a=document.createElement("div"),o=e.getBoundingClientRect();return a.style.cssText=`display: inline-block; width: ${o.width}px; height: ${o.height}px; visibility: hidden;`,a}if(r.exclude&&Array.isArray(r.exclude))for(let a of r.exclude)try{if((c=e.matches)!=null&&c.call(e,a)){let o=document.createElement("div"),l=e.getBoundingClientRect();return o.style.cssText=`display: inline-block; width: ${l.width}px; height: ${l.height}px; visibility: hidden;`,o}}catch(o){console.warn(`Invalid selector in exclude option: ${a}`,o)}if(typeof r.filter=="function")try{if(!r.filter(e,i||e)){let a=document.createElement("div"),o=e.getBoundingClientRect();return a.style.cssText=`display: inline-block; width: ${o.width}px; height: ${o.height}px; visibility: hidden;`,a}}catch(a){console.warn("Error in filter function:",a)}if(e.tagName==="IFRAME"){let a=document.createElement("div");return a.textContent="",a.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;`,a}if(e.getAttribute("data-capture")==="placeholder"){let a=e.cloneNode(!1);f.preNodeMap.set(a,e),J(e,a,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;",a.appendChild(o),a}if(e.tagName==="CANVAS"){let a=e.toDataURL(),o=document.createElement("img");return o.src=a,o.width=e.width,o.height=e.height,f.preNodeMap.set(o,e),J(e,o,t),o}let s;try{if(s=e.cloneNode(!1),!s)throw new Error("Failed to clone node: cloneNode returned null");f.preNodeMap.set(s,e)}catch(a){throw console.error("[Snapdom] Failed to clone node:",e,a),a}if(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 a=e.getBoundingClientRect();s.textContent=e.value,s.style.width=`${a.width}px`,s.style.height=`${a.height}px`}else e instanceof HTMLSelectElement&&(s.value=e.value,Array.from(s.options).forEach(a=>{a.value===e.value?a.setAttribute("selected",""):a.removeAttribute("selected")}));J(e,s,t);try{if(Xe(e)){let a=((n=e.assignedNodes)==null?void 0:n.call(e,{flatten:!0}))||[],o=a.length>0?a:Array.from(e.childNodes),l=document.createDocumentFragment();for(let d of o)try{let p=_(d,t,r,i||e);p&&l.appendChild(p)}catch(p){console.warn("[Snapdom] Failed to clone slot content:",d,p)}return l}else{let a=e.shadowRoot?e.shadowRoot.childNodes:e.childNodes;for(let o of a)try{let l=_(o,t,r,i||e);l&&s.appendChild(l)}catch(l){console.warn("[Snapdom] Failed to clone child node:",o,l)}if(e.shadowRoot&&e.childNodes.length>0&&!e.shadowRoot.querySelector("slot")){let o=document.createDocumentFragment();for(let l of e.childNodes)try{let d=_(l,t,r,i||e);d&&o.appendChild(d)}catch(d){console.warn("[Snapdom] Failed to clone light DOM child:",l,d)}s.appendChild(o)}}}catch(a){throw console.error("[Snapdom] Error cloning children:",a),a}return s}catch(s){throw console.error("[Snapdom] Error in deepClone:",s),s}}var xe=$(()=>{we();I()});function Se(e){let t=Array.isArray(e)?e:[e];for(let r of t)r instanceof RegExp?oe.push(r):typeof r=="string"?oe.push(new RegExp(r,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",r)}function A(e){let t=typeof e=="string"?e:"",r=[...Ye,...oe];for(let i of r)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))}var Ye,oe,Q=$(()=>{Ye=[/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],oe=[]});function be(e,t,r,i=32,c="#000"){return h(this,null,function*(){t=t.replace(/^['"]+|['"]+$/g,"");let n=window.devicePixelRatio||1,a=document.createElement("canvas").getContext("2d");a.font=r?`${r} ${i}px "${t}"`:`${i}px "${t}"`;let o=a.measureText(e),l=o.actualBoundingBoxAscent||i*.8,d=o.actualBoundingBoxDescent||i*.2,p=l+d,g=o.width,u=document.createElement("canvas");u.width=Math.ceil(g*n),u.height=Math.ceil(p*n);let m=u.getContext("2d");return m.scale(n,n),m.font=a.font,m.textAlign="left",m.textBaseline="alphabetic",m.fillStyle=c,m.fillText(e,0,l),u.toDataURL()})}function Ce(e){return Array.from(document.styleSheets).some(t=>t.href===e)}function Ge(e){return new Promise(t=>{if(Ce(e))return t(null);let r=document.createElement("link");r.rel="stylesheet",r.href=e,r.setAttribute("data-snapdom","injected-import"),r.onload=()=>t(r),r.onerror=()=>t(null),document.head.appendChild(r)})}function Z(){return h(this,arguments,function*({preCached:e=!1}={}){if(f.resource.has("fonts-embed-css")){if(e){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=f.resource.get("fonts-embed-css"),document.head.appendChild(n)}return f.resource.get("fonts-embed-css")}let t=/@import\s+url\(["']?([^"')]+)["']?\)/g,r=[];for(let n of document.querySelectorAll("style")){let s=n.textContent||"",a=Array.from(s.matchAll(t));for(let o of a){let l=o[1];A(l)||Ce(l)||r.push(l)}}yield Promise.all(r.map(Ge));let i=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(n=>n.href),c="";for(let n of i)try{let a=yield(yield fetch(n.href)).text();if(A(n.href)||A(a))continue;let o=/url\((["']?)([^"')]+)\1\)/g,l=yield Promise.all(Array.from(a.matchAll(o)).map(p=>h(null,null,function*(){let g=V(p[0]);if(!g)return null;let u=g;if(!u.startsWith("http")&&!u.startsWith("data:")&&(u=new URL(u,n.href).href),A(u))return null;if(f.resource.has(u))return f.font.add(u),{original:p[0],inlined:`url(${f.resource.get(u)})`};if(f.font.has(u))return null;try{let y=yield(yield fetch(u)).blob(),b=yield new Promise(w=>{let C=new FileReader;C.onload=()=>w(C.result),C.readAsDataURL(y)});return f.resource.set(u,b),f.font.add(u),{original:p[0],inlined:`url(${b})`}}catch(m){return console.warn("[snapdom] Failed to fetch font resource:",u),null}}))),d=a;for(let p of l)p&&(d=d.replace(p.original,p.inlined));c+=d+`
|
|
3
|
+
`}catch(s){console.warn("[snapdom] Failed to fetch CSS:",n.href)}for(let n of document.styleSheets)try{if(!n.href||i.every(s=>s.href!==n.href)){for(let s of n.cssRules)if(s.type===CSSRule.FONT_FACE_RULE){let a=s.style.getPropertyValue("src"),o=s.style.getPropertyValue("font-family");if(!a||A(o))continue;let l=/url\((["']?)([^"')]+)\1\)/g,d=a,p=Array.from(a.matchAll(l));for(let g of p){let u=g[2].trim();if(!u)continue;let m=u;if(!m.startsWith("http")&&!m.startsWith("data:")&&(m=new URL(m,n.href||location.href).href),!A(m)){if(f.resource.has(m)){f.font.add(m),d=d.replace(g[0],`url(${f.resource.get(m)})`);continue}if(!f.font.has(m))try{let b=yield(yield fetch(m)).blob(),w=yield new Promise(C=>{let x=new FileReader;x.onload=()=>C(x.result),x.readAsDataURL(b)});f.resource.set(m,w),f.font.add(m),d=d.replace(g[0],`url(${w})`)}catch(y){console.warn("[snapdom] Failed to fetch font URL:",m)}}}c+=`@font-face {
|
|
4
4
|
font-family: ${o};
|
|
5
5
|
src: ${d};
|
|
6
6
|
font-style: ${s.style.getPropertyValue("font-style")||"normal"};
|
|
7
7
|
font-weight: ${s.style.getPropertyValue("font-weight")||"normal"};
|
|
8
8
|
}
|
|
9
|
-
`}}}catch(s){console.warn("[snapdom] Cannot access stylesheet",n.href,s)}for(let n of document.fonts)if(n.family&&n.status==="loaded"&&n._snapdomSrc){if(
|
|
9
|
+
`}}}catch(s){console.warn("[snapdom] Cannot access stylesheet",n.href,s)}for(let n of document.fonts)if(n.family&&n.status==="loaded"&&n._snapdomSrc){if(A(n.family))continue;let s=n._snapdomSrc;if(!s.startsWith("data:")){if(f.resource.has(n._snapdomSrc))s=f.resource.get(n._snapdomSrc),f.font.add(n._snapdomSrc);else if(!f.font.has(n._snapdomSrc))try{let o=yield(yield fetch(n._snapdomSrc)).blob();s=yield new Promise(l=>{let d=new FileReader;d.onload=()=>l(d.result),d.readAsDataURL(o)}),f.resource.set(n._snapdomSrc,s),f.font.add(n._snapdomSrc)}catch(a){console.warn("[snapdom] Failed to fetch dynamic font src:",n._snapdomSrc);continue}}c+=`@font-face {
|
|
10
10
|
font-family: '${n.family}';
|
|
11
11
|
src: url(${s});
|
|
12
12
|
font-style: ${n.style||"normal"};
|
|
13
13
|
font-weight: ${n.weight||"normal"};
|
|
14
14
|
}
|
|
15
|
-
`}if(c&&(f.resource.set("fonts-embed-css",c),e)){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=c,document.head.appendChild(n)}return c})}var Z=$(()=>{A();I();J()});function re(e,t,r,i=!1,c){return m(this,null,function*(){if(!(e instanceof Element)||!(t instanceof Element))return;for(let a of["::before","::after","::first-letter"])try{let o=M(e,a);if(!o||typeof o[Symbol.iterator]!="function")continue;if(a==="::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 C=w.textContent,x=C.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u),k=x==null?void 0:x[0],P=C.slice((k==null?void 0:k.length)||0);if(!k||/[\uD800-\uDFFF]/.test(k))continue;let R=document.createElement("span");R.textContent=k,R.dataset.snapdomPseudo="::first-letter";let v=te(o),j=O(v,"span",r);f.preStyleMap.set(R,j);let z=document.createTextNode(P);t.replaceChild(z,w),t.insertBefore(R,z);continue}let l=o.getPropertyValue("content"),d=o.getPropertyValue("background-image"),p=o.getPropertyValue("background-color"),g=l!=="none",h=d&&d!=="none",u=p&&p!=="transparent"&&p!=="rgba(0, 0, 0, 0)";if(g||h||u){let y=o.getPropertyValue("font-family"),b=parseInt(o.getPropertyValue("font-size"))||32,w=parseInt(o.getPropertyValue("font-weight"))||!1,C=o.getPropertyValue("color")||"#000",x=document.createElement("span");x.dataset.snapdomPseudo=a;let k=te(o),P=O(k,"span",r);f.preStyleMap.set(x,P);let R=N(y),v=ge(l);if(R&&v.length===1){let E=document.createElement("img");E.src=yield be(v,y,w,b,C),E.style=`width:${b}px;height:auto;object-fit:contain;`,x.appendChild(E)}else if(v.startsWith("url(")){let E=V(v);if(E&&E.trim()!=="")try{let T=document.createElement("img"),H=yield F(G(E,{useProxy:c}));T.src=H,T.style=`width:${b}px;height:auto;object-fit:contain;`,x.appendChild(T)}catch(T){console.error(`[snapdom] Error in pseudo ${a} for`,e,T)}}else!R&&v&&v!=="none"&&(x.textContent=v);if(h)try{let E=W(d),T=yield Promise.all(E.map(H=>B(H)));x.style.backgroundImage=T.join(", ")}catch(E){console.warn(`[snapdom] Failed to inline background-image for ${a}`,E)}if(u&&(x.style.backgroundColor=p),!(x.childNodes.length>0||x.textContent&&x.textContent.trim()!==""||h||u))continue;a==="::before"?t.insertBefore(x,t.firstChild):t.appendChild(x)}}catch(o){console.warn(`[snapdom] Failed to capture ${a} for`,e,o)}let n=Array.from(e.children),s=Array.from(t.children).filter(a=>!a.dataset.snapdomPseudo);for(let a=0;a<Math.min(n.length,s.length);a++)yield re(n[a],s[a],r,i,c)})}var Ee=$(()=>{A();U();Z();J();I()});function ve(e){if(!e)return;let t=document.querySelectorAll("svg > defs");t.length&&e.querySelectorAll("svg").forEach(r=>{let i=r.querySelectorAll("use");if(!i.length)return;let c=new Set;if(i.forEach(s=>{let a=s.getAttribute("xlink:href")||s.getAttribute("href");a&&a.startsWith("#")&&c.add(a.slice(1))}),!c.size)return;let n=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let s of c)for(let a of t){let o=a.querySelector(`#${CSS.escape(s)}`);if(o){n.appendChild(o.cloneNode(!0));break}}n.childNodes.length&&r.insertBefore(n,r.firstChild)})}var $e=$(()=>{});function ke(c){return m(this,arguments,function*(e,t=!1,r=!1,i={}){var a;let n,s="";try{n=_(e,t,i,e)}catch(o){throw console.warn("deepClone failed:",o),o}try{yield re(e,n,t,r,i.useProxy)}catch(o){console.warn("inlinePseudoElements failed:",o)}try{ve(n)}catch(o){console.warn("inlineExternalDef failed:",o)}if(t){let o=me();s=Array.from(o.entries()).map(([l,d])=>`.${d}{${l}}`).join("");for(let[l,d]of f.preStyleMap.entries()){if(l.tagName==="STYLE")continue;let p=o.get(d);p&&l.classList.add(p);let g=(a=l.style)==null?void 0:a.backgroundImage;l.removeAttribute("style"),g&&g!=="none"&&(l.style.backgroundImage=g)}}else for(let[o,l]of f.preStyleMap.entries())o.tagName!=="STYLE"&&o.setAttribute("style",l.replace(/;/g,"; "));for(let[o,l]of f.preNodeMap.entries()){let d=l.scrollLeft,p=l.scrollTop;if((d||p)&&o instanceof HTMLElement){o.style.overflow="hidden",o.style.scrollbarWidth="none",o.style.msOverflowStyle="none";let h=document.createElement("div");for(h.style.transform=`translate(${-d}px, ${-p}px)`,h.style.willChange="transform",h.style.display="inline-block",h.style.width="100%";o.firstChild;)h.appendChild(o.firstChild);o.appendChild(h)}}if(e===f.preNodeMap.get(n)){let o=f.preStyle.get(e)||window.getComputedStyle(e);f.preStyle.set(e,o);let l=ye(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=l||""}for(let[o,l]of f.preNodeMap.entries())l.tagName==="PRE"&&(o.style.marginTop="0",o.style.marginBlockStart="0");return{clone:n,classCSS:s}})}var Ie=$(()=>{U();A();xe();Ee();$e();I()});function Re(r){return m(this,arguments,function*(e,t={}){let i=Array.from(e.querySelectorAll("img")),c=n=>m(null,null,function*(){let s=n.src;try{let a=yield F(s,{useProxy:t.useProxy});n.src=a,n.width||(n.width=n.naturalWidth||100),n.height||(n.height=n.naturalHeight||100)}catch(a){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 s=i.slice(n,n+4).map(c);yield Promise.allSettled(s)}})}var Ae=$(()=>{A()});function Ne(i,c){return m(this,arguments,function*(e,t,r={}){let n=[[e,t]],s=["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[a,o]=n.shift(),l=f.preStyle.get(a)||M(a);f.preStyle.has(a)||f.preStyle.set(a,l);for(let h of s){let u=l.getPropertyValue(h);if(!u||u==="none")continue;let y=W(u),b=yield Promise.all(y.map(w=>B(w,r)));b.some(w=>w&&w!=="none"&&!/^url\(undefined/.test(w))&&o.style.setProperty(h,b.join(", "))}let d=l.getPropertyValue("background-color");d&&d!=="transparent"&&d!=="rgba(0, 0, 0, 0)"&&(o.style.backgroundColor=d);let p=Array.from(a.children),g=Array.from(o.children);for(let h=0;h<Math.min(p.length,g.length);h++)n.push([p[h],g[h]])}})}var Te=$(()=>{A();I()});function Me(r){return m(this,arguments,function*(e,t={}){if(!e)throw new Error("Element cannot be null or undefined");f.reset();let{compress:i=!0,embedFonts:c=!1,fast:n=!0,scale:s=1,useProxy:a=""}=t,o,l,d="",p="",g,h;if({clone:o,classCSS:l}=yield ke(e,i,c,t),yield new Promise(y=>{D(()=>m(null,null,function*(){yield Re(o,t),y()}),{fast:n})}),yield new Promise(y=>{D(()=>m(null,null,function*(){yield Ne(e,o,t),y()}),{fast:n})}),c&&(yield new Promise(y=>{D(()=>m(null,null,function*(){d=yield Q(),y()}),{fast:n})})),i){let y=he(o).sort(),b=y.join(",");f.baseStyle.has(b)?p=f.baseStyle.get(b):yield new Promise(w=>{D(()=>{p=ue(y),f.baseStyle.set(b,p),w()},{fast:n})})}yield new Promise(y=>{D(()=>{let b=e.getBoundingClientRect(),w=b.width,C=b.height,x=Number.isFinite(t.width),k=Number.isFinite(t.height),P=typeof s=="number"&&s!==1;if(!P){let K=b.width/b.height;x&&k?(w=t.width,C=t.height):x?(w=t.width,C=w/K):k&&(C=t.height,w=C*K)}if(w=Math.ceil(w),C=Math.ceil(C),o.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),o.style.transformOrigin="top left",!P&&(x||k)){let K=b.width,De=b.height,We=w/K,je=C/De,Oe=o.style.transform||"",Ve=`scale(${We}, ${je})`;o.style.transform=`${Ve} ${Oe}`.trim()}else P&&Y()&&(o.style.scale=`${s}`);let R="http://www.w3.org/2000/svg",v=document.createElementNS(R,"foreignObject");v.setAttribute("width","100%"),v.setAttribute("height","100%");let j=document.createElement("style");j.textContent=p+d+"svg{overflow:visible;}"+l,v.appendChild(j),v.appendChild(o);let E=new XMLSerializer().serializeToString(v);h=`<svg xmlns="${R}" width="${w}" height="${C}" viewBox="0 0 ${w} ${C}">`+E+"</svg>",g=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(h)}`,y()},{fast:n})});let u=document.getElementById("snapdom-sandbox");return u&&u.style.position==="absolute"&&u.remove(),g})}var Pe=$(()=>{Ie();Ae();Te();A();U();Z();I()});function Je(i,c){return m(this,arguments,function*(e,{dpr:t=1,scale:r=1}){let n=new Image;return n.src=e,yield n.decode(),Y?(n.width=n.width*r,n.height=n.height*r):(n.width=n.width/r,n.height=n.height/r),n})}function Fe(i){return m(this,arguments,function*(e,{dpr:t=1,scale:r=1}={}){let c=new Image;c.src=e,yield c.decode();let n=document.createElement("canvas"),s=c.width*r,a=c.height*r;n.width=Math.ceil(s*t),n.height=Math.ceil(a*t);let o=n.getContext("2d");return o.scale(t,t),o.drawImage(c,0,0,s,a),n.style.width=`${s}px`,n.style.height=`${a}px`,n})}function Le(n){return m(this,arguments,function*(e,{type:t="svg",scale:r=1,backgroundColor:i="#fff",quality:c}={}){let s={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 a=yield se(e,{dpr:1,scale:r},i);return new Promise(o=>{a.toBlob(l=>o(l),`${s}`,c)})})}function se(c,n,s){return m(this,arguments,function*(e,{dpr:t=1,scale:r=1},i){let a=yield Fe(e,{dpr:t,scale:r});if(!i)return a;let o=document.createElement("canvas");o.width=a.width,o.height=a.height;let l=o.getContext("2d");return l.fillStyle=i,l.fillRect(0,0,o.width,o.height),l.drawImage(a,0,0),o})}function ae(s,a){return m(this,arguments,function*(e,{dpr:t=1,scale:r=1,backgroundColor:i,quality:c},n="png"){let o=["jpg","jpeg","webp"].includes(n)?"#fff":void 0,l=i!=null?i:o,d=yield se(e,{dpr:t,scale:r},l),p=new Image;return p.src=d.toDataURL(`image/${n}`,c),yield p.decode(),p.style.width=`${d.width/t}px`,p.style.height=`${d.height/t}px`,p})}function Qe(s){return m(this,arguments,function*(e,{dpr:t=1,scale:r=1,backgroundColor:i="#fff",format:c="png",filename:n="capture"}={}){if(c==="svg"){let h=yield Le(e),u=URL.createObjectURL(h),y=document.createElement("a");y.href=u,y.download=`${n}.svg`,y.click(),URL.revokeObjectURL(u);return}let a=["jpg","jpeg","webp"].includes(c)?"#fff":void 0,o=i!=null?i:a,l=yield se(e,{dpr:t,scale:r},o),d={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[c]||"image/png",p=l.toDataURL(d),g=document.createElement("a");g.href=p,g.download=`${n}.${c}`,g.click()})}function S(r){return m(this,arguments,function*(e,t={}){if(t=L({scale:1},t),!e)throw new Error("Element cannot be null or undefined");return t.iconFonts&&Se(t.iconFonts),yield S.capture(e,t)})}var Ue=$(()=>{Pe();A();J();S.capture=(r,...i)=>m(null,[r,...i],function*(e,t={}){let c=yield Me(e,t),n=window.devicePixelRatio||1,s=t.scale||1;return{url:c,options:t,toRaw:()=>c,toImg:()=>Je(c,{dpr:n,scale:s}),toCanvas:()=>Fe(c,{dpr:n,scale:s}),toBlob:a=>Le(c,L({dpr:n,scale:s},a)),toPng:a=>ae(c,L({dpr:n,scale:s},a),"png"),toJpg:a=>ae(c,L({dpr:n,scale:s},a),"jpeg"),toWebp:a=>ae(c,L({dpr:n,scale:s},a),"webp"),download:({format:a="png",filename:o="capture",backgroundColor:l}={})=>Qe(c,{dpr:n,scale:s,backgroundColor:l,format:a,filename:o})}});S.toRaw=(e,t)=>m(null,null,function*(){return(yield S.capture(e,t)).toRaw()});S.toImg=(e,t)=>m(null,null,function*(){return(yield S.capture(e,t)).toImg()});S.toCanvas=(e,t)=>m(null,null,function*(){return(yield S.capture(e,t)).toCanvas()});S.toBlob=(e,t)=>m(null,null,function*(){return(yield S.capture(e,t)).toBlob(t)});S.toPng=(e,t)=>m(null,null,function*(){return(yield S.capture(e,t)).toPng(t)});S.toJpg=(e,t)=>m(null,null,function*(){return(yield S.capture(e,t)).toJpg(t)});S.toWebp=(e,t)=>m(null,null,function*(){return(yield S.capture(e,t)).toWebp(t)});S.download=(r,...i)=>m(null,[r,...i],function*(e,t={}){let l=t,{format:c="png",filename:n="capture",backgroundColor:s}=l,a=fe(l,["format","filename","backgroundColor"]);return yield(yield S.capture(e,a)).download({format:c,filename:n,backgroundColor:s})})});function q(){return m(this,arguments,function*(e=document,t={}){let{embedFonts:r=!0,reset:i=!1}=t;if(i){f.reset();return}yield document.fonts.ready,de();let c=[],n=[];e!=null&&e.querySelectorAll&&(c=Array.from(e.querySelectorAll("img[src]")),n=Array.from(e.querySelectorAll("*")));let s=[];for(let a of c){let o=a.src;f.image.has(o)||s.push(F(o,{useProxy:t.useProxy}).then(l=>f.image.set(o,l)).catch(()=>{}))}for(let a of n){let o=M(a).backgroundImage;if(o&&o!=="none"){let l=W(o);for(let d of l)d.startsWith("url(")&&s.push(B(d,t).catch(()=>{}))}}r&&(yield Q({preCached:!0})),yield Promise.all(s)})}var Be=$(()=>{A();Z();U();I()});var Ze=qe((pn,ee)=>{Ue();Be();window.snapdom=S;typeof window!="undefined"&&(window.snapdom=S,window.preCache=q);typeof ee!="undefined"&&typeof ee.exports!="undefined"&&(ee.exports={snapdom:S,preCache:q});typeof define=="function"&&define.amd&&define([],function(){return{snapdom:S,preCache:q}});typeof globalThis!="undefined"&&(globalThis.snapdom=S,globalThis.preCache=q)});Ze();})();
|
|
15
|
+
`}if(c&&(f.resource.set("fonts-embed-css",c),e)){let n=document.createElement("style");n.setAttribute("data-snapdom","embedFonts"),n.textContent=c,document.head.appendChild(n)}return c})}var ee=$(()=>{N();I();Q()});function re(e,t,r,i=!1,c){return h(this,null,function*(){if(!(e instanceof Element)||!(t instanceof Element))return;for(let a of["::before","::after","::first-letter"])try{let o=M(e,a);if(!o||typeof o[Symbol.iterator]!="function")continue;if(a==="::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 C=w.textContent,x=C.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u),k=x==null?void 0:x[0],P=C.slice((k==null?void 0:k.length)||0);if(!k||/[\uD800-\uDFFF]/.test(k))continue;let R=document.createElement("span");R.textContent=k,R.dataset.snapdomPseudo="::first-letter";let v=ne(o),j=O(v,"span",r);f.preStyleMap.set(R,j);let z=document.createTextNode(P);t.replaceChild(z,w),t.insertBefore(R,z);continue}let l=o.getPropertyValue("content"),d=o.getPropertyValue("background-image"),p=o.getPropertyValue("background-color"),g=l!=="none",u=d&&d!=="none",m=p&&p!=="transparent"&&p!=="rgba(0, 0, 0, 0)";if(g||u||m){let y=o.getPropertyValue("font-family"),b=parseInt(o.getPropertyValue("font-size"))||32,w=parseInt(o.getPropertyValue("font-weight"))||!1,C=o.getPropertyValue("color")||"#000",x=document.createElement("span");x.dataset.snapdomPseudo=a;let k=ne(o),P=O(k,"span",r);f.preStyleMap.set(x,P);let R=A(y),v=ge(l);if(R&&v.length===1){let E=document.createElement("img");E.src=yield be(v,y,w,b,C),E.style=`width:${b}px;height:auto;object-fit:contain;`,x.appendChild(E)}else if(v.startsWith("url(")){let E=V(v);if(E&&E.trim()!=="")try{let T=document.createElement("img"),H=yield F(G(E,{useProxy:c}));T.src=H,T.style=`width:${b}px;height:auto;object-fit:contain;`,x.appendChild(T)}catch(T){console.error(`[snapdom] Error in pseudo ${a} for`,e,T)}}else!R&&v&&v!=="none"&&(x.textContent=v);if(u)try{let E=W(d),T=yield Promise.all(E.map(H=>B(H)));x.style.backgroundImage=T.join(", ")}catch(E){console.warn(`[snapdom] Failed to inline background-image for ${a}`,E)}if(m&&(x.style.backgroundColor=p),!(x.childNodes.length>0||x.textContent&&x.textContent.trim()!==""||u||m))continue;a==="::before"?t.insertBefore(x,t.firstChild):t.appendChild(x)}}catch(o){console.warn(`[snapdom] Failed to capture ${a} for`,e,o)}let n=Array.from(e.children),s=Array.from(t.children).filter(a=>!a.dataset.snapdomPseudo);for(let a=0;a<Math.min(n.length,s.length);a++)yield re(n[a],s[a],r,i,c)})}var Ee=$(()=>{N();U();ee();Q();I()});function ve(e){if(!e)return;let t=document.querySelectorAll("svg > defs");t.length&&e.querySelectorAll("svg").forEach(r=>{let i=r.querySelectorAll("use");if(!i.length)return;let c=new Set;if(i.forEach(s=>{let a=s.getAttribute("xlink:href")||s.getAttribute("href");a&&a.startsWith("#")&&c.add(a.slice(1))}),!c.size)return;let n=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let s of c)for(let a of t){let o=a.querySelector(`#${CSS.escape(s)}`);if(o){n.appendChild(o.cloneNode(!0));break}}n.childNodes.length&&r.insertBefore(n,r.firstChild)})}var $e=$(()=>{});function ke(c){return h(this,arguments,function*(e,t=!1,r=!1,i={}){var a;let n,s="";try{n=_(e,t,i,e)}catch(o){throw console.warn("deepClone failed:",o),o}try{yield re(e,n,t,r,i.useProxy)}catch(o){console.warn("inlinePseudoElements failed:",o)}try{ve(n)}catch(o){console.warn("inlineExternalDef failed:",o)}if(t){let o=he();s=Array.from(o.entries()).map(([l,d])=>`.${d}{${l}}`).join("");for(let[l,d]of f.preStyleMap.entries()){if(l.tagName==="STYLE")continue;let p=o.get(d);p&&l.classList.add(p);let g=(a=l.style)==null?void 0:a.backgroundImage;l.removeAttribute("style"),g&&g!=="none"&&(l.style.backgroundImage=g)}}else for(let[o,l]of f.preStyleMap.entries())o.tagName!=="STYLE"&&o.setAttribute("style",l.replace(/;/g,"; "));for(let[o,l]of f.preNodeMap.entries()){let d=l.scrollLeft,p=l.scrollTop;if((d||p)&&o instanceof HTMLElement){o.style.overflow="hidden",o.style.scrollbarWidth="none",o.style.msOverflowStyle="none";let u=document.createElement("div");for(u.style.transform=`translate(${-d}px, ${-p}px)`,u.style.willChange="transform",u.style.display="inline-block",u.style.width="100%";o.firstChild;)u.appendChild(o.firstChild);o.appendChild(u)}}if(e===f.preNodeMap.get(n)){let o=f.preStyle.get(e)||window.getComputedStyle(e);f.preStyle.set(e,o);let l=ye(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=l||""}for(let[o,l]of f.preNodeMap.entries())l.tagName==="PRE"&&(o.style.marginTop="0",o.style.marginBlockStart="0");return{clone:n,classCSS:s}})}var Ie=$(()=>{U();N();xe();Ee();$e();I()});function Re(r){return h(this,arguments,function*(e,t={}){let i=Array.from(e.querySelectorAll("img")),c=n=>h(null,null,function*(){let s=n.src;try{let a=yield F(s,{useProxy:t.useProxy});n.src=a,n.width||(n.width=n.naturalWidth||100),n.height||(n.height=n.naturalHeight||100)}catch(a){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 s=i.slice(n,n+4).map(c);yield Promise.allSettled(s)}})}var Ne=$(()=>{N()});function Ae(i,c){return h(this,arguments,function*(e,t,r={}){let n=[[e,t]],s=["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[a,o]=n.shift(),l=f.preStyle.get(a)||M(a);f.preStyle.has(a)||f.preStyle.set(a,l);for(let u of s){let m=l.getPropertyValue(u);if(!m||m==="none")continue;let y=W(m),b=yield Promise.all(y.map(w=>B(w,r)));b.some(w=>w&&w!=="none"&&!/^url\(undefined/.test(w))&&o.style.setProperty(u,b.join(", "))}let d=l.getPropertyValue("background-color");d&&d!=="transparent"&&d!=="rgba(0, 0, 0, 0)"&&(o.style.backgroundColor=d);let p=Array.from(a.children),g=Array.from(o.children);for(let u=0;u<Math.min(p.length,g.length);u++)n.push([p[u],g[u]])}})}var Te=$(()=>{N();I()});function Me(r){return h(this,arguments,function*(e,t={}){if(!e)throw new Error("Element cannot be null or undefined");f.reset();let{compress:i=!0,embedFonts:c=!1,fast:n=!0,scale:s=1,useProxy:a=""}=t,o,l,d="",p="",g,u;if({clone:o,classCSS:l}=yield ke(e,i,c,t),yield new Promise(y=>{D(()=>h(null,null,function*(){yield Re(o,t),y()}),{fast:n})}),yield new Promise(y=>{D(()=>h(null,null,function*(){yield Ae(e,o,t),y()}),{fast:n})}),c&&(yield new Promise(y=>{D(()=>h(null,null,function*(){d=yield Z(),y()}),{fast:n})})),i){let y=ue(o).sort(),b=y.join(",");f.baseStyle.has(b)?p=f.baseStyle.get(b):yield new Promise(w=>{D(()=>{p=me(y),f.baseStyle.set(b,p),w()},{fast:n})})}yield new Promise(y=>{D(()=>{let b=e.getBoundingClientRect(),w=b.width,C=b.height,x=Number.isFinite(t.width),k=Number.isFinite(t.height),P=typeof s=="number"&&s!==1;if(!P){let K=b.width/b.height;x&&k?(w=t.width,C=t.height):x?(w=t.width,C=w/K):k&&(C=t.height,w=C*K)}if(w=Math.ceil(w),C=Math.ceil(C),o.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),o.style.transformOrigin="top left",!P&&(x||k)){let K=b.width,De=b.height,We=w/K,je=C/De,Oe=o.style.transform||"",Ve=`scale(${We}, ${je})`;o.style.transform=`${Ve} ${Oe}`.trim()}else P&&Y()&&(o.style.scale=`${s}`);let R="http://www.w3.org/2000/svg",v=document.createElementNS(R,"foreignObject");v.setAttribute("width","100%"),v.setAttribute("height","100%");let j=document.createElement("style");j.textContent=p+d+"svg{overflow:visible;}"+l,v.appendChild(j),v.appendChild(o);let E=new XMLSerializer().serializeToString(v);u=`<svg xmlns="${R}" width="${w}" height="${C}" viewBox="0 0 ${w} ${C}">`+E+"</svg>",g=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(u)}`,y()},{fast:n})});let m=document.getElementById("snapdom-sandbox");return m&&m.style.position==="absolute"&&m.remove(),g})}var Pe=$(()=>{Ie();Ne();Te();N();U();ee();I()});function Je(i,c){return h(this,arguments,function*(e,{dpr:t=1,scale:r=1}){let n=new Image;return n.src=e,yield n.decode(),Y?(n.width=n.width*r,n.height=n.height*r):(n.width=n.width/r,n.height=n.height/r),n})}function Fe(i){return h(this,arguments,function*(e,{dpr:t=1,scale:r=1}={}){let c=new Image;c.src=e,yield c.decode();let n=document.createElement("canvas"),s=c.width*r,a=c.height*r;n.width=Math.ceil(s*t),n.height=Math.ceil(a*t);let o=n.getContext("2d");return o.scale(t,t),o.drawImage(c,0,0,s,a),n.style.width=`${s}px`,n.style.height=`${a}px`,n})}function Le(n){return h(this,arguments,function*(e,{type:t="svg",scale:r=1,backgroundColor:i="#fff",quality:c}={}){let s={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 a=yield se(e,{dpr:1,scale:r},i);return new Promise(o=>{a.toBlob(l=>o(l),`${s}`,c)})})}function se(c,n,s){return h(this,arguments,function*(e,{dpr:t=1,scale:r=1},i){let a=yield Fe(e,{dpr:t,scale:r});if(!i)return a;let o=document.createElement("canvas");o.width=a.width,o.height=a.height;let l=o.getContext("2d");return l.fillStyle=i,l.fillRect(0,0,o.width,o.height),l.drawImage(a,0,0),o})}function ae(s,a){return h(this,arguments,function*(e,{dpr:t=1,scale:r=1,backgroundColor:i,quality:c},n="png"){let o=["jpg","jpeg","webp"].includes(n)?"#fff":void 0,l=i!=null?i:o,d=yield se(e,{dpr:t,scale:r},l),p=new Image;return p.src=d.toDataURL(`image/${n}`,c),yield p.decode(),p.style.width=`${d.width/t}px`,p.style.height=`${d.height/t}px`,p})}function Qe(s){return h(this,arguments,function*(e,{dpr:t=1,scale:r=1,backgroundColor:i="#fff",format:c="png",filename:n="capture"}={}){if(c==="svg"){let u=yield Le(e),m=URL.createObjectURL(u),y=document.createElement("a");y.href=m,y.download=`${n}.svg`,y.click(),URL.revokeObjectURL(m);return}let a=["jpg","jpeg","webp"].includes(c)?"#fff":void 0,o=i!=null?i:a,l=yield se(e,{dpr:t,scale:r},o),d={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[c]||"image/png",p=l.toDataURL(d),g=document.createElement("a");g.href=p,g.download=`${n}.${c}`,g.click()})}function S(r){return h(this,arguments,function*(e,t={}){if(t=L({scale:1},t),!e)throw new Error("Element cannot be null or undefined");return t.iconFonts&&Se(t.iconFonts),yield S.capture(e,t)})}var Ue=$(()=>{Pe();N();Q();S.capture=(r,...i)=>h(null,[r,...i],function*(e,t={}){let c=yield Me(e,t),n=window.devicePixelRatio||1,s=t.scale||1;return{url:c,options:t,toRaw:()=>c,toImg:()=>Je(c,{dpr:n,scale:s}),toCanvas:()=>Fe(c,{dpr:n,scale:s}),toBlob:a=>Le(c,L({dpr:n,scale:s},a)),toPng:a=>ae(c,L({dpr:n,scale:s},a),"png"),toJpg:a=>ae(c,L({dpr:n,scale:s},a),"jpeg"),toWebp:a=>ae(c,L({dpr:n,scale:s},a),"webp"),download:({format:a="png",filename:o="capture",backgroundColor:l}={})=>Qe(c,{dpr:n,scale:s,backgroundColor:l,format:a,filename:o})}});S.toRaw=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toRaw()});S.toImg=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toImg()});S.toCanvas=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toCanvas()});S.toBlob=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toBlob(t)});S.toPng=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toPng(t)});S.toJpg=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toJpg(t)});S.toWebp=(e,t)=>h(null,null,function*(){return(yield S.capture(e,t)).toWebp(t)});S.download=(r,...i)=>h(null,[r,...i],function*(e,t={}){let l=t,{format:c="png",filename:n="capture",backgroundColor:s}=l,a=fe(l,["format","filename","backgroundColor"]);return yield(yield S.capture(e,a)).download({format:c,filename:n,backgroundColor:s})})});function q(){return h(this,arguments,function*(e=document,t={}){let{embedFonts:r=!0,reset:i=!1}=t;if(i){f.reset();return}yield document.fonts.ready,de();let c=[],n=[];e!=null&&e.querySelectorAll&&(c=Array.from(e.querySelectorAll("img[src]")),n=Array.from(e.querySelectorAll("*")));let s=[];for(let a of c){let o=a.src;f.image.has(o)||s.push(F(o,{useProxy:t.useProxy}).then(l=>f.image.set(o,l)).catch(()=>{}))}for(let a of n){let o=M(a).backgroundImage;if(o&&o!=="none"){let l=W(o);for(let d of l)d.startsWith("url(")&&s.push(B(d,t).catch(()=>{}))}}r&&(yield Z({preCached:!0})),yield Promise.all(s)})}var Be=$(()=>{N();ee();U();I()});var Ze=qe((pn,te)=>{Ue();Be();window.snapdom=S;typeof window!="undefined"&&(window.snapdom=S,window.preCache=q);typeof te!="undefined"&&typeof te.exports!="undefined"&&(te.exports={snapdom:S,preCache:q});typeof define=="function"&&define.amd&&define([],function(){return{snapdom:S,preCache:q}});typeof globalThis!="undefined"&&(globalThis.snapdom=S,globalThis.preCache=q)});Ze();})();
|
package/dist/snapdom.min.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
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:ye};function ye(){l.computedStyle=new WeakMap,l.snapshot=new WeakMap,l.snapshotKey.clear(),l.preStyleMap.clear(),l.preStyle=new WeakMap,l.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(l.defaultStyle.has(e))return l.defaultStyle.get(e);if(new Set(["script","style","meta","link","noscript","template"]).has(e)){let a={};return l.defaultStyle.set(e,a),a}let r=document.getElementById("snapdom-sandbox");r||(r=document.createElement("div"),r.id="snapdom-sandbox",r.style.position="absolute",r.style.left="-9999px",r.style.top="-9999px",r.style.width="0",r.style.height="0",r.style.overflow="hidden",document.body.appendChild(r));let s=document.createElement(e);s.style.all="initial",r.appendChild(s);let o=getComputedStyle(s),t={};for(let a of o)t[a]=o.getPropertyValue(a);return r.removeChild(s),l.defaultStyle.set(e,t),t}function U(e,n,r=!1){let s=[],o=G(n);for(let[t,a]of Object.entries(e))if(!r)a&&s.push(`${t}:${a}`);else{let i=o[t];a&&a!==i&&s.push(`${t}:${a}`)}return s.sort().join(";")}function J(e){let n=new Set;return e.nodeType!==Node.ELEMENT_NODE&&e.nodeType!==Node.DOCUMENT_FRAGMENT_NODE?[]:(e.tagName&&n.add(e.tagName.toLowerCase()),typeof e.querySelectorAll=="function"&&e.querySelectorAll("*").forEach(r=>n.add(r.tagName.toLowerCase())),Array.from(n))}function Q(e){let n=new Map;for(let s of e){let o=l.defaultStyle.get(s);if(!o)continue;let t=Object.entries(o).map(([a,i])=>`${a}:${i};`).sort().join("");n.has(t)||n.set(t,[]),n.get(t).push(s)}let r="";for(let[s,o]of n.entries())r+=`${o.join(",")} { ${s} }
|
|
2
|
-
`;return r}function Z(){let e=new Set(l.preStyleMap.values()),n=new Map,r=1;for(let s of e)n.set(s,`c${r++}`);return n}async function T(e,n={}){let r=B(e),s=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(e);if(r){let o=j(r);if(l.background.has(o))return n.skipInline?void 0:`url(${l.background.get(o)})`;{let t=await N(o,{useProxy:n.useProxy});return l.background.set(o,t),n.skipInline?void 0:`url("${t}")`}}return e}function P(e,{fast:n=!1}={}){if(n)return e();"requestIdleCallback"in window?requestIdleCallback(e,{timeout:50}):setTimeout(e,1)}function A(e,n=null){if(!(e instanceof Element))return window.getComputedStyle(e,n);let r=l.computedStyle.get(e);if(r||(r=new Map,l.computedStyle.set(e,r)),!r.has(n)){let s=window.getComputedStyle(e,n);r.set(n,s)}return r.get(n)}function ee(e){let n=e.replace(/^['"]|['"]$/g,"");if(n.startsWith("\\"))try{return String.fromCharCode(parseInt(n.replace("\\",""),16))}catch{return n}return n}function B(e){let n=e.indexOf("url(");if(n===-1)return null;let r=e.slice(n+4).trim();return r.endsWith(")")&&(r=r.slice(0,-1).trim()),(r.startsWith('"')&&r.endsWith('"')||r.startsWith("'")&&r.endsWith("'"))&&(r=r.slice(1,-1)),r}function N(e,{timeout:n=3e3,useProxy:r=""}={}){function s(c){try{return new URL(c,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch{return"anonymous"}}async function o(c){let f=u=>fetch(u,{mode:"cors",credentials:s(u)==="use-credentials"?"include":"omit"}).then(d=>d.blob()).then(d=>new Promise((p,m)=>{let h=new FileReader;h.onloadend=()=>{let g=h.result;if(typeof g!="string"||!g.startsWith("data:image/")){m(new Error("Invalid image data URL"));return}p(g)},h.onerror=()=>m(new Error("FileReader error")),h.readAsDataURL(d)}));try{return await f(c)}catch{if(r&&typeof r=="string"){let d=r.replace(/\/$/,"")+j(c);try{return await f(d)}catch{throw console.error(`[SnapDOM - fetchImage] Proxy fallback failed for: ${c}`),new Error("CORS restrictions prevented image capture (even via proxy)")}}else throw console.error(`[SnapDOM - fetchImage] No valid proxy URL provided for fallback: ${c}`),new Error("Fetch fallback failed and no proxy provided")}}let t=s(e);return console.log(`[SnapDOM - fetchImage] Start loading image: ${e} with crossOrigin=${t}`),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)?(async()=>{try{let f=await(await fetch(e,{mode:"cors",credentials:t==="use-credentials"?"include":"omit"})).text(),u=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(f)}`;return l.image.set(e,u),u}catch{return o(e)}})():new Promise((c,f)=>{let u=setTimeout(()=>{console.log(`[SnapDOM - fetchImage] Timeout after ${n}ms for image: ${e}`),f(new Error("Image load timed out"))},n),d=new Image;d.crossOrigin=t,d.onload=async()=>{clearTimeout(u);try{await d.decode();let p=document.createElement("canvas");p.width=d.width,p.height=d.height,p.getContext("2d").drawImage(d,0,0,p.width,p.height);let h=p.toDataURL("image/png");l.image.set(e,h),c(h)}catch{try{let p=await o(e);l.image.set(e,p),c(p)}catch(p){f(p)}}},d.onerror=async()=>{clearTimeout(u),console.error(`[SnapDOM - fetchImage] Image failed to load: ${e}`);try{let p=await o(e);l.image.set(e,p),c(p)}catch(p){f(p)}},d.src=e})}function _(e){let n={};for(let r of e)n[r]=e.getPropertyValue(r);return n}function W(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function te(e){if(!e||e==="none")return"";let n=e.replace(/translate[XY]?\([^)]*\)/g,"");return n=n.replace(/matrix\(([^)]+)\)/g,(r,s)=>{let o=s.split(",").map(t=>t.trim());return o.length!==6?`matrix(${s})`:(o[4]="0",o[5]="0",`matrix(${o.join(", ")})`)}),n=n.replace(/matrix3d\(([^)]+)\)/g,(r,s)=>{let o=s.split(",").map(t=>t.trim());return o.length!==16?`matrix3d(${s})`:(o[12]="0",o[13]="0",`matrix3d(${o.join(", ")})`)}),n.trim().replace(/\s{2,}/g," ")}function j(e){if(/%[0-9A-Fa-f]{2}/.test(e))return e;try{return encodeURI(e)}catch{return e}}function F(e){let n=[],r=0,s=0;for(let o=0;o<e.length;o++){let t=e[o];t==="("&&r++,t===")"&&r--,t===","&&r===0&&(n.push(e.slice(s,o).trim()),s=o+1)}return n.push(e.slice(s).trim()),n}function xe(e){let n={};for(let r=0;r<e.length;r++){let s=e[r],o=e.getPropertyValue(s);(s==="background-image"||s==="content")&&o.includes("url(")&&!o.includes("data:")&&(o="none"),n[s]=o}return n}function q(e,n,r){if(e.tagName==="STYLE")return;l.preStyle.has(e)||l.preStyle.set(e,A(e));let s=l.preStyle.get(e);if(!l.snapshot.has(e)){let c=xe(s);l.snapshot.set(e,c)}let o=l.snapshot.get(e),t=Object.entries(o).sort(([c],[f])=>c.localeCompare(f)).map(([c,f])=>`${c}:${f}`).join(";");if(l.snapshotKey.has(t)){l.preStyleMap.set(n,l.snapshotKey.get(t));return}let a=e.tagName?.toLowerCase()||"div",i=U(o,a,r);l.snapshotKey.set(t,i),l.preStyleMap.set(n,i)}function Se(e){return e.nodeType===Node.ELEMENT_NODE&&e.tagName==="SLOT"}function D(e,n,r={},s){if(!e)throw new Error("Invalid node: node is null or undefined");try{if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return e.cloneNode(!0);if(e.getAttribute("data-capture")==="exclude"){let t=document.createElement("div"),a=e.getBoundingClientRect();return t.style.cssText=`display: inline-block; width: ${a.width}px; height: ${a.height}px; visibility: hidden;`,t}if(r.exclude&&Array.isArray(r.exclude))for(let t of r.exclude)try{if(e.matches?.(t)){let a=document.createElement("div"),i=e.getBoundingClientRect();return a.style.cssText=`display: inline-block; width: ${i.width}px; height: ${i.height}px; visibility: hidden;`,a}}catch(a){console.warn(`Invalid selector in exclude option: ${t}`,a)}if(typeof r.filter=="function")try{if(!r.filter(e,s||e)){let t=document.createElement("div"),a=e.getBoundingClientRect();return t.style.cssText=`display: inline-block; width: ${a.width}px; height: ${a.height}px; visibility: hidden;`,t}}catch(t){console.warn("Error in filter function:",t)}if(e.tagName==="IFRAME"){let t=document.createElement("div");return t.textContent="",t.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;`,t}if(e.getAttribute("data-capture")==="placeholder"){let t=e.cloneNode(!1);l.preNodeMap.set(t,e),q(e,t,n);let a=document.createElement("div");return a.textContent=e.getAttribute("data-placeholder-text")||"",a.style.cssText="color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;",t.appendChild(a),t}if(e.tagName==="CANVAS"){let t=e.toDataURL(),a=document.createElement("img");return a.src=t,a.width=e.width,a.height=e.height,a.style.display="inline-block",a.style.width=e.style.width||`${e.width}px`,a.style.height=e.style.height||`${e.height}px`,a}let o;try{if(o=e.cloneNode(!1),!o)throw new Error("Failed to clone node: cloneNode returned null");l.preNodeMap.set(o,e)}catch(t){throw console.error("[Snapdom] Failed to clone node:",e,t),t}if(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 t=e.getBoundingClientRect();o.textContent=e.value,o.style.width=`${t.width}px`,o.style.height=`${t.height}px`}else e instanceof HTMLSelectElement&&(o.value=e.value,Array.from(o.options).forEach(t=>{t.value===e.value?t.setAttribute("selected",""):t.removeAttribute("selected")}));q(e,o,n);try{if(Se(e)){let t=e.assignedNodes?.({flatten:!0})||[],a=t.length>0?t:Array.from(e.childNodes),i=document.createDocumentFragment();for(let c of a)try{let f=D(c,n,r,s||e);f&&i.appendChild(f)}catch(f){console.warn("[Snapdom] Failed to clone slot content:",c,f)}return i}else{let t=e.shadowRoot?e.shadowRoot.childNodes:e.childNodes;for(let a of t)try{let i=D(a,n,r,s||e);i&&o.appendChild(i)}catch(i){console.warn("[Snapdom] Failed to clone child node:",a,i)}if(e.shadowRoot&&e.childNodes.length>0&&!e.shadowRoot.querySelector("slot")){let a=document.createDocumentFragment();for(let i of e.childNodes)try{let c=D(i,n,r,s||e);c&&a.appendChild(c)}catch(c){console.warn("[Snapdom] Failed to clone light DOM child:",i,c)}o.appendChild(a)}}}catch(t){throw console.error("[Snapdom] Error cloning children:",t),t}return o}catch(o){throw console.error("[Snapdom] Error in deepClone:",o),o}}var be=[/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 n=Array.isArray(e)?e:[e];for(let r of n)r instanceof RegExp?z.push(r):typeof r=="string"?z.push(new RegExp(r,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",r)}function k(e){let n=typeof e=="string"?e:"",r=[...be,...z];for(let s of r)if(s instanceof RegExp&&s.test(n))return!0;return!!(/icon/i.test(n)||/glyph/i.test(n)||/symbols/i.test(n)||/feather/i.test(n)||/fontawesome/i.test(n))}async function oe(e,n,r,s=32,o="#000"){n=n.replace(/^['"]+|['"]+$/g,"");let t=window.devicePixelRatio||1,i=document.createElement("canvas").getContext("2d");i.font=r?`${r} ${s}px "${n}"`:`${s}px "${n}"`;let c=i.measureText(e),f=c.actualBoundingBoxAscent||s*.8,u=c.actualBoundingBoxDescent||s*.2,d=f+u,p=c.width,m=document.createElement("canvas");m.width=Math.ceil(p*t),m.height=Math.ceil(d*t);let h=m.getContext("2d");return h.scale(t,t),h.font=i.font,h.textAlign="left",h.textBaseline="alphabetic",h.fillStyle=o,h.fillText(e,0,f),m.toDataURL()}function re(e){return Array.from(document.styleSheets).some(n=>n.href===e)}function Ce(e){return new Promise(n=>{if(re(e))return n(null);let r=document.createElement("link");r.rel="stylesheet",r.href=e,r.setAttribute("data-snapdom","injected-import"),r.onload=()=>n(r),r.onerror=()=>n(null),document.head.appendChild(r)})}async function O({preCached:e=!1}={}){if(l.resource.has("fonts-embed-css")){if(e){let t=document.createElement("style");t.setAttribute("data-snapdom","embedFonts"),t.textContent=l.resource.get("fonts-embed-css"),document.head.appendChild(t)}return l.resource.get("fonts-embed-css")}let n=/@import\s+url\(["']?([^"')]+)["']?\)/g,r=[];for(let t of document.querySelectorAll("style")){let a=t.textContent||"",i=Array.from(a.matchAll(n));for(let c of i){let f=c[1];k(f)||re(f)||r.push(f)}}await Promise.all(r.map(Ce));let s=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(t=>t.href),o="";for(let t of s)try{let i=await(await fetch(t.href)).text();if(k(t.href)||k(i))continue;let c=/url\((["']?)([^"')]+)\1\)/g,f=await Promise.all(Array.from(i.matchAll(c)).map(async d=>{let p=B(d[0]);if(!p)return null;let m=p;if(!m.startsWith("http")&&!m.startsWith("data:")&&(m=new URL(m,t.href).href),k(m))return null;if(l.resource.has(m))return l.font.add(m),{original:d[0],inlined:`url(${l.resource.get(m)})`};if(l.font.has(m))return null;try{let g=await(await fetch(m)).blob(),y=await new Promise(x=>{let C=new FileReader;C.onload=()=>x(C.result),C.readAsDataURL(g)});return l.resource.set(m,y),l.font.add(m),{original:d[0],inlined:`url(${y})`}}catch{return console.warn("[snapdom] Failed to fetch font resource:",m),null}})),u=i;for(let d of f)d&&(u=u.replace(d.original,d.inlined));o+=u+`
|
|
3
|
-
`}catch{console.warn("[snapdom] Failed to fetch CSS:",t.href)}for(let t of document.styleSheets)try{if(!t.href||s.every(a=>a.href!==t.href)){for(let a of t.cssRules)if(a.type===CSSRule.FONT_FACE_RULE){let i=a.style.getPropertyValue("src"),c=a.style.getPropertyValue("font-family");if(!i
|
|
2
|
+
`;return r}function Z(){let e=new Set(l.preStyleMap.values()),n=new Map,r=1;for(let s of e)n.set(s,`c${r++}`);return n}async function T(e,n={}){let r=B(e),s=/^((repeating-)?(linear|radial|conic)-gradient)\(/i.test(e);if(r){let o=j(r);if(l.background.has(o))return n.skipInline?void 0:`url(${l.background.get(o)})`;{let t=await A(o,{useProxy:n.useProxy});return l.background.set(o,t),n.skipInline?void 0:`url("${t}")`}}return e}function P(e,{fast:n=!1}={}){if(n)return e();"requestIdleCallback"in window?requestIdleCallback(e,{timeout:50}):setTimeout(e,1)}function N(e,n=null){if(!(e instanceof Element))return window.getComputedStyle(e,n);let r=l.computedStyle.get(e);if(r||(r=new Map,l.computedStyle.set(e,r)),!r.has(n)){let s=window.getComputedStyle(e,n);r.set(n,s)}return r.get(n)}function ee(e){let n=e.replace(/^['"]|['"]$/g,"");if(n.startsWith("\\"))try{return String.fromCharCode(parseInt(n.replace("\\",""),16))}catch{return n}return n}function B(e){let n=e.indexOf("url(");if(n===-1)return null;let r=e.slice(n+4).trim();return r.endsWith(")")&&(r=r.slice(0,-1).trim()),(r.startsWith('"')&&r.endsWith('"')||r.startsWith("'")&&r.endsWith("'"))&&(r=r.slice(1,-1)),r}function A(e,{timeout:n=3e3,useProxy:r=""}={}){function s(c){try{return new URL(c,window.location.href).origin===window.location.origin?"use-credentials":"anonymous"}catch{return"anonymous"}}async function o(c){let f=p=>fetch(p,{mode:"cors",credentials:s(p)==="use-credentials"?"include":"omit"}).then(d=>d.blob()).then(d=>new Promise((m,h)=>{let u=new FileReader;u.onloadend=()=>{let g=u.result;if(typeof g!="string"||!g.startsWith("data:image/")){h(new Error("Invalid image data URL"));return}m(g)},u.onerror=()=>h(new Error("FileReader error")),u.readAsDataURL(d)}));try{return await f(c)}catch{if(r&&typeof r=="string"){let d=r.replace(/\/$/,"")+j(c);try{return await f(d)}catch{throw console.error(`[SnapDOM - fetchImage] Proxy fallback failed for: ${c}`),new Error("CORS restrictions prevented image capture (even via proxy)")}}else throw console.error(`[SnapDOM - fetchImage] No valid proxy URL provided for fallback: ${c}`),new Error("Fetch fallback failed and no proxy provided")}}let t=s(e);return console.log(`[SnapDOM - fetchImage] Start loading image: ${e} with crossOrigin=${t}`),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)?(async()=>{try{let f=await(await fetch(e,{mode:"cors",credentials:t==="use-credentials"?"include":"omit"})).text(),p=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(f)}`;return l.image.set(e,p),p}catch{return o(e)}})():new Promise((c,f)=>{let p=setTimeout(()=>{console.log(`[SnapDOM - fetchImage] Timeout after ${n}ms for image: ${e}`),f(new Error("Image load timed out"))},n),d=new Image;d.crossOrigin=t,d.onload=async()=>{clearTimeout(p);try{await d.decode();let m=document.createElement("canvas");m.width=d.width,m.height=d.height,m.getContext("2d").drawImage(d,0,0,m.width,m.height);let u=m.toDataURL("image/png");l.image.set(e,u),c(u)}catch{try{let m=await o(e);l.image.set(e,m),c(m)}catch(m){f(m)}}},d.onerror=async()=>{clearTimeout(p),console.error(`[SnapDOM - fetchImage] Image failed to load: ${e}`);try{let m=await o(e);l.image.set(e,m),c(m)}catch(m){f(m)}},d.src=e})}function q(e){let n={};for(let r of e)n[r]=e.getPropertyValue(r);return n}function W(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function te(e){if(!e||e==="none")return"";let n=e.replace(/translate[XY]?\([^)]*\)/g,"");return n=n.replace(/matrix\(([^)]+)\)/g,(r,s)=>{let o=s.split(",").map(t=>t.trim());return o.length!==6?`matrix(${s})`:(o[4]="0",o[5]="0",`matrix(${o.join(", ")})`)}),n=n.replace(/matrix3d\(([^)]+)\)/g,(r,s)=>{let o=s.split(",").map(t=>t.trim());return o.length!==16?`matrix3d(${s})`:(o[12]="0",o[13]="0",`matrix3d(${o.join(", ")})`)}),n.trim().replace(/\s{2,}/g," ")}function j(e){if(/%[0-9A-Fa-f]{2}/.test(e))return e;try{return encodeURI(e)}catch{return e}}function F(e){let n=[],r=0,s=0;for(let o=0;o<e.length;o++){let t=e[o];t==="("&&r++,t===")"&&r--,t===","&&r===0&&(n.push(e.slice(s,o).trim()),s=o+1)}return n.push(e.slice(s).trim()),n}function xe(e){let n={};for(let r=0;r<e.length;r++){let s=e[r],o=e.getPropertyValue(s);(s==="background-image"||s==="content")&&o.includes("url(")&&!o.includes("data:")&&(o="none"),n[s]=o}return n}function O(e,n,r){if(e.tagName==="STYLE")return;l.preStyle.has(e)||l.preStyle.set(e,N(e));let s=l.preStyle.get(e);if(!l.snapshot.has(e)){let c=xe(s);l.snapshot.set(e,c)}let o=l.snapshot.get(e),t=Object.entries(o).sort(([c],[f])=>c.localeCompare(f)).map(([c,f])=>`${c}:${f}`).join(";");if(l.snapshotKey.has(t)){l.preStyleMap.set(n,l.snapshotKey.get(t));return}let a=e.tagName?.toLowerCase()||"div",i=U(o,a,r);l.snapshotKey.set(t,i),l.preStyleMap.set(n,i)}function Se(e){return e.nodeType===Node.ELEMENT_NODE&&e.tagName==="SLOT"}function D(e,n,r={},s){if(!e)throw new Error("Invalid node: node is null or undefined");try{if(e.nodeType===Node.TEXT_NODE||e.nodeType!==Node.ELEMENT_NODE)return e.cloneNode(!0);if(e.getAttribute("data-capture")==="exclude"){let t=document.createElement("div"),a=e.getBoundingClientRect();return t.style.cssText=`display: inline-block; width: ${a.width}px; height: ${a.height}px; visibility: hidden;`,t}if(r.exclude&&Array.isArray(r.exclude))for(let t of r.exclude)try{if(e.matches?.(t)){let a=document.createElement("div"),i=e.getBoundingClientRect();return a.style.cssText=`display: inline-block; width: ${i.width}px; height: ${i.height}px; visibility: hidden;`,a}}catch(a){console.warn(`Invalid selector in exclude option: ${t}`,a)}if(typeof r.filter=="function")try{if(!r.filter(e,s||e)){let t=document.createElement("div"),a=e.getBoundingClientRect();return t.style.cssText=`display: inline-block; width: ${a.width}px; height: ${a.height}px; visibility: hidden;`,t}}catch(t){console.warn("Error in filter function:",t)}if(e.tagName==="IFRAME"){let t=document.createElement("div");return t.textContent="",t.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;`,t}if(e.getAttribute("data-capture")==="placeholder"){let t=e.cloneNode(!1);l.preNodeMap.set(t,e),O(e,t,n);let a=document.createElement("div");return a.textContent=e.getAttribute("data-placeholder-text")||"",a.style.cssText="color: #666;font-size: 12px;text-align: center;line-height: 1.4;padding: 0.5em;box-sizing: border-box;",t.appendChild(a),t}if(e.tagName==="CANVAS"){let t=e.toDataURL(),a=document.createElement("img");return a.src=t,a.width=e.width,a.height=e.height,l.preNodeMap.set(a,e),O(e,a,n),a}let o;try{if(o=e.cloneNode(!1),!o)throw new Error("Failed to clone node: cloneNode returned null");l.preNodeMap.set(o,e)}catch(t){throw console.error("[Snapdom] Failed to clone node:",e,t),t}if(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 t=e.getBoundingClientRect();o.textContent=e.value,o.style.width=`${t.width}px`,o.style.height=`${t.height}px`}else e instanceof HTMLSelectElement&&(o.value=e.value,Array.from(o.options).forEach(t=>{t.value===e.value?t.setAttribute("selected",""):t.removeAttribute("selected")}));O(e,o,n);try{if(Se(e)){let t=e.assignedNodes?.({flatten:!0})||[],a=t.length>0?t:Array.from(e.childNodes),i=document.createDocumentFragment();for(let c of a)try{let f=D(c,n,r,s||e);f&&i.appendChild(f)}catch(f){console.warn("[Snapdom] Failed to clone slot content:",c,f)}return i}else{let t=e.shadowRoot?e.shadowRoot.childNodes:e.childNodes;for(let a of t)try{let i=D(a,n,r,s||e);i&&o.appendChild(i)}catch(i){console.warn("[Snapdom] Failed to clone child node:",a,i)}if(e.shadowRoot&&e.childNodes.length>0&&!e.shadowRoot.querySelector("slot")){let a=document.createDocumentFragment();for(let i of e.childNodes)try{let c=D(i,n,r,s||e);c&&a.appendChild(c)}catch(c){console.warn("[Snapdom] Failed to clone light DOM child:",i,c)}o.appendChild(a)}}}catch(t){throw console.error("[Snapdom] Error cloning children:",t),t}return o}catch(o){throw console.error("[Snapdom] Error in deepClone:",o),o}}var be=[/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 n=Array.isArray(e)?e:[e];for(let r of n)r instanceof RegExp?z.push(r):typeof r=="string"?z.push(new RegExp(r,"i")):console.warn("[snapdom] Ignored invalid iconFont value:",r)}function $(e){let n=typeof e=="string"?e:"",r=[...be,...z];for(let s of r)if(s instanceof RegExp&&s.test(n))return!0;return!!(/icon/i.test(n)||/glyph/i.test(n)||/symbols/i.test(n)||/feather/i.test(n)||/fontawesome/i.test(n))}async function oe(e,n,r,s=32,o="#000"){n=n.replace(/^['"]+|['"]+$/g,"");let t=window.devicePixelRatio||1,i=document.createElement("canvas").getContext("2d");i.font=r?`${r} ${s}px "${n}"`:`${s}px "${n}"`;let c=i.measureText(e),f=c.actualBoundingBoxAscent||s*.8,p=c.actualBoundingBoxDescent||s*.2,d=f+p,m=c.width,h=document.createElement("canvas");h.width=Math.ceil(m*t),h.height=Math.ceil(d*t);let u=h.getContext("2d");return u.scale(t,t),u.font=i.font,u.textAlign="left",u.textBaseline="alphabetic",u.fillStyle=o,u.fillText(e,0,f),h.toDataURL()}function re(e){return Array.from(document.styleSheets).some(n=>n.href===e)}function Ce(e){return new Promise(n=>{if(re(e))return n(null);let r=document.createElement("link");r.rel="stylesheet",r.href=e,r.setAttribute("data-snapdom","injected-import"),r.onload=()=>n(r),r.onerror=()=>n(null),document.head.appendChild(r)})}async function V({preCached:e=!1}={}){if(l.resource.has("fonts-embed-css")){if(e){let t=document.createElement("style");t.setAttribute("data-snapdom","embedFonts"),t.textContent=l.resource.get("fonts-embed-css"),document.head.appendChild(t)}return l.resource.get("fonts-embed-css")}let n=/@import\s+url\(["']?([^"')]+)["']?\)/g,r=[];for(let t of document.querySelectorAll("style")){let a=t.textContent||"",i=Array.from(a.matchAll(n));for(let c of i){let f=c[1];$(f)||re(f)||r.push(f)}}await Promise.all(r.map(Ce));let s=Array.from(document.querySelectorAll('link[rel="stylesheet"]')).filter(t=>t.href),o="";for(let t of s)try{let i=await(await fetch(t.href)).text();if($(t.href)||$(i))continue;let c=/url\((["']?)([^"')]+)\1\)/g,f=await Promise.all(Array.from(i.matchAll(c)).map(async d=>{let m=B(d[0]);if(!m)return null;let h=m;if(!h.startsWith("http")&&!h.startsWith("data:")&&(h=new URL(h,t.href).href),$(h))return null;if(l.resource.has(h))return l.font.add(h),{original:d[0],inlined:`url(${l.resource.get(h)})`};if(l.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 l.resource.set(h,y),l.font.add(h),{original:d[0],inlined:`url(${y})`}}catch{return console.warn("[snapdom] Failed to fetch font resource:",h),null}})),p=i;for(let d of f)d&&(p=p.replace(d.original,d.inlined));o+=p+`
|
|
3
|
+
`}catch{console.warn("[snapdom] Failed to fetch CSS:",t.href)}for(let t of document.styleSheets)try{if(!t.href||s.every(a=>a.href!==t.href)){for(let a of t.cssRules)if(a.type===CSSRule.FONT_FACE_RULE){let i=a.style.getPropertyValue("src"),c=a.style.getPropertyValue("font-family");if(!i||$(c))continue;let f=/url\((["']?)([^"')]+)\1\)/g,p=i,d=Array.from(i.matchAll(f));for(let m of d){let h=m[2].trim();if(!h)continue;let u=h;if(!u.startsWith("http")&&!u.startsWith("data:")&&(u=new URL(u,t.href||location.href).href),!$(u)){if(l.resource.has(u)){l.font.add(u),p=p.replace(m[0],`url(${l.resource.get(u)})`);continue}if(!l.font.has(u))try{let y=await(await fetch(u)).blob(),x=await new Promise(C=>{let w=new FileReader;w.onload=()=>C(w.result),w.readAsDataURL(y)});l.resource.set(u,x),l.font.add(u),p=p.replace(m[0],`url(${x})`)}catch{console.warn("[snapdom] Failed to fetch font URL:",u)}}}o+=`@font-face {
|
|
4
4
|
font-family: ${c};
|
|
5
|
-
src: ${
|
|
5
|
+
src: ${p};
|
|
6
6
|
font-style: ${a.style.getPropertyValue("font-style")||"normal"};
|
|
7
7
|
font-weight: ${a.style.getPropertyValue("font-weight")||"normal"};
|
|
8
8
|
}
|
|
9
|
-
`}}}catch(a){console.warn("[snapdom] Cannot access stylesheet",t.href,a)}for(let t of document.fonts)if(t.family&&t.status==="loaded"&&t._snapdomSrc){if(
|
|
9
|
+
`}}}catch(a){console.warn("[snapdom] Cannot access stylesheet",t.href,a)}for(let t of document.fonts)if(t.family&&t.status==="loaded"&&t._snapdomSrc){if($(t.family))continue;let a=t._snapdomSrc;if(!a.startsWith("data:")){if(l.resource.has(t._snapdomSrc))a=l.resource.get(t._snapdomSrc),l.font.add(t._snapdomSrc);else if(!l.font.has(t._snapdomSrc))try{let c=await(await fetch(t._snapdomSrc)).blob();a=await new Promise(f=>{let p=new FileReader;p.onload=()=>f(p.result),p.readAsDataURL(c)}),l.resource.set(t._snapdomSrc,a),l.font.add(t._snapdomSrc)}catch{console.warn("[snapdom] Failed to fetch dynamic font src:",t._snapdomSrc);continue}}o+=`@font-face {
|
|
10
10
|
font-family: '${t.family}';
|
|
11
11
|
src: url(${a});
|
|
12
12
|
font-style: ${t.style||"normal"};
|
|
13
13
|
font-weight: ${t.weight||"normal"};
|
|
14
14
|
}
|
|
15
|
-
`}if(o&&(l.resource.set("fonts-embed-css",o),e)){let t=document.createElement("style");t.setAttribute("data-snapdom","embedFonts"),t.textContent=o,document.head.appendChild(t)}return o}async function H(e,n,r,s=!1,o){if(!(e instanceof Element)||!(n instanceof Element))return;for(let i of["::before","::after","::first-letter"])try{let c=A(e,i);if(!c||typeof c[Symbol.iterator]!="function")continue;if(i==="::first-letter"){let g=getComputedStyle(e);if(!(c.color!==g.color||c.fontSize!==g.fontSize||c.fontWeight!==g.fontWeight))continue;let x=Array.from(n.childNodes).find(b=>b.nodeType===Node.TEXT_NODE&&b.textContent&&b.textContent.trim().length>0);if(!x)continue;let C=x.textContent,$=C.match(/^([^\p{L}\p{N}\s]*[\p{L}\p{N}](?:['’])?)/u)?.[0],M=C.slice($?.length||0);if(!$||/[\uD800-\uDFFF]/.test($))continue;let E=document.createElement("span");E.textContent=$,E.dataset.snapdomPseudo="::first-letter";let v=_(c),V=U(v,"span",r);l.preStyleMap.set(E,V);let L=document.createTextNode(M);n.replaceChild(L,x),n.insertBefore(E,L);continue}let f=c.getPropertyValue("content"),u=c.getPropertyValue("background-image"),d=c.getPropertyValue("background-color"),p=f!=="none",m=u&&u!=="none",h=d&&d!=="transparent"&&d!=="rgba(0, 0, 0, 0)";if(p||m||h){let g=c.getPropertyValue("font-family"),y=parseInt(c.getPropertyValue("font-size"))||32,x=parseInt(c.getPropertyValue("font-weight"))||!1,C=c.getPropertyValue("color")||"#000",w=document.createElement("span");w.dataset.snapdomPseudo=i;let $=_(c),M=U($,"span",r);l.preStyleMap.set(w,M);let E=k(g),v=ee(f);if(E&&v.length===1){let b=document.createElement("img");b.src=await oe(v,g,x,y,C),b.style=`width:${y}px;height:auto;object-fit:contain;`,w.appendChild(b)}else if(v.startsWith("url(")){let b=B(v);if(b&&b.trim()!=="")try{let I=document.createElement("img"),R=await N(j(b,{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&&v&&v!=="none"&&(w.textContent=v);if(m)try{let b=F(u),I=await Promise.all(b.map(R=>T(R)));w.style.backgroundImage=I.join(", ")}catch(b){console.warn(`[snapdom] Failed to inline background-image for ${i}`,b)}if(h&&(w.style.backgroundColor=d),!(w.childNodes.length>0||w.textContent&&w.textContent.trim()!==""||m||h))continue;i==="::before"?n.insertBefore(w,n.firstChild):n.appendChild(w)}}catch(c){console.warn(`[snapdom] Failed to capture ${i} for`,e,c)}let t=Array.from(e.children),a=Array.from(n.children).filter(i=>!i.dataset.snapdomPseudo);for(let i=0;i<Math.min(t.length,a.length);i++)await H(t[i],a[i],r,s,o)}function ae(e){if(!e)return;let n=document.querySelectorAll("svg > defs");n.length&&e.querySelectorAll("svg").forEach(r=>{let s=r.querySelectorAll("use");if(!s.length)return;let o=new Set;if(s.forEach(a=>{let i=a.getAttribute("xlink:href")||a.getAttribute("href");i&&i.startsWith("#")&&o.add(i.slice(1))}),!o.size)return;let t=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let a of o)for(let i of n){let c=i.querySelector(`#${CSS.escape(a)}`);if(c){t.appendChild(c.cloneNode(!0));break}}t.childNodes.length&&r.insertBefore(t,r.firstChild)})}async function se(e,n=!1,r=!1,s={}){let o,t="";try{o=D(e,n,s,e)}catch(a){throw console.warn("deepClone failed:",a),a}try{await H(e,o,n,r,s.useProxy)}catch(a){console.warn("inlinePseudoElements failed:",a)}try{ae(o)}catch(a){console.warn("inlineExternalDef failed:",a)}if(n){let a=Z();t=Array.from(a.entries()).map(([i,c])=>`.${c}{${i}}`).join("");for(let[i,c]of l.preStyleMap.entries()){if(i.tagName==="STYLE")continue;let f=a.get(c);f&&i.classList.add(f);let u=i.style?.backgroundImage;i.removeAttribute("style"),u&&u!=="none"&&(i.style.backgroundImage=u)}}else for(let[a,i]of l.preStyleMap.entries())a.tagName!=="STYLE"&&a.setAttribute("style",i.replace(/;/g,"; "));for(let[a,i]of l.preNodeMap.entries()){let c=i.scrollLeft,f=i.scrollTop;if((c||f)&&a instanceof HTMLElement){a.style.overflow="hidden",a.style.scrollbarWidth="none",a.style.msOverflowStyle="none";let d=document.createElement("div");for(d.style.transform=`translate(${-c}px, ${-f}px)`,d.style.willChange="transform",d.style.display="inline-block",d.style.width="100%";a.firstChild;)d.appendChild(a.firstChild);a.appendChild(d)}}if(e===l.preNodeMap.get(o)){let a=l.preStyle.get(e)||window.getComputedStyle(e);l.preStyle.set(e,a);let i=te(a.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[a,i]of l.preNodeMap.entries())i.tagName==="PRE"&&(a.style.marginTop="0",a.style.marginBlockStart="0");return{clone:o,classCSS:t}}async function ie(e,n={}){let r=Array.from(e.querySelectorAll("img")),s=async o=>{let t=o.src;try{let a=await N(t,{useProxy:n.useProxy});o.src=a,o.width||(o.width=o.naturalWidth||100),o.height||(o.height=o.naturalHeight||100)}catch{let a=document.createElement("div");a.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;`,a.innerText="img",o.replaceWith(a)}};for(let o=0;o<r.length;o+=4){let t=r.slice(o,o+4).map(s);await Promise.allSettled(t)}}async function ce(e,n,r={}){let s=[[e,n]],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[t,a]=s.shift(),i=l.preStyle.get(t)||A(t);l.preStyle.has(t)||l.preStyle.set(t,i);for(let d of o){let p=i.getPropertyValue(d);if(!p||p==="none")continue;let m=F(p),h=await Promise.all(m.map(g=>T(g,r)));h.some(g=>g&&g!=="none"&&!/^url\(undefined/.test(g))&&a.style.setProperty(d,h.join(", "))}let c=i.getPropertyValue("background-color");c&&c!=="transparent"&&c!=="rgba(0, 0, 0, 0)"&&(a.style.backgroundColor=c);let f=Array.from(t.children),u=Array.from(a.children);for(let d=0;d<Math.min(f.length,u.length);d++)s.push([f[d],u[d]])}}async function le(e,n={}){if(!e)throw new Error("Element cannot be null or undefined");l.reset();let{compress:r=!0,embedFonts:s=!1,fast:o=!0,scale:t=1,useProxy:a=""}=n,i,c,f="",u="",d,p;if({clone:i,classCSS:c}=await se(e,r,s,n),await new Promise(h=>{P(async()=>{await ie(i,n),h()},{fast:o})}),await new Promise(h=>{P(async()=>{await ce(e,i,n),h()},{fast:o})}),s&&await new Promise(h=>{P(async()=>{f=await O(),h()},{fast:o})}),r){let h=J(i).sort(),g=h.join(",");l.baseStyle.has(g)?u=l.baseStyle.get(g):await new Promise(y=>{P(()=>{u=Q(h),l.baseStyle.set(g,u),y()},{fast:o})})}await new Promise(h=>{P(()=>{let g=e.getBoundingClientRect(),y=g.width,x=g.height,C=Number.isFinite(n.width),w=Number.isFinite(n.height),$=typeof t=="number"&&t!==1;if(!$){let R=g.width/g.height;C&&w?(y=n.width,x=n.height):C?(y=n.width,x=y/R):w&&(x=n.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",!$&&(C||w)){let R=g.width,he=g.height,ue=y/R,pe=x/he,me=i.style.transform||"",ge=`scale(${ue}, ${pe})`;i.style.transform=`${ge} ${me}`.trim()}else $&&W()&&(i.style.scale=`${t}`);let M="http://www.w3.org/2000/svg",E=document.createElementNS(M,"foreignObject");E.setAttribute("width","100%"),E.setAttribute("height","100%");let v=document.createElement("style");v.textContent=u+f+"svg{overflow:visible;}"+c,E.appendChild(v),E.appendChild(i);let L=new XMLSerializer().serializeToString(E);p=`<svg xmlns="${M}" width="${y}" height="${x}" viewBox="0 0 ${y} ${x}">`+L+"</svg>",d=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(p)}`,h()},{fast:o})});let m=document.getElementById("snapdom-sandbox");return m&&m.style.position==="absolute"&&m.remove(),d}async function Ee(e,{dpr:n=1,scale:r=1}){let s=new Image;return s.src=e,await s.decode(),W?(s.width=s.width*r,s.height=s.height*r):(s.width=s.width/r,s.height=s.height/r),s}async function fe(e,{dpr:n=1,scale:r=1}={}){let s=new Image;s.src=e,await s.decode();let o=document.createElement("canvas"),t=s.width*r,a=s.height*r;o.width=Math.ceil(t*n),o.height=Math.ceil(a*n);let i=o.getContext("2d");return i.scale(n,n),i.drawImage(s,0,0,t,a),o.style.width=`${t}px`,o.style.height=`${a}px`,o}async function de(e,{type:n="svg",scale:r=1,backgroundColor:s="#fff",quality:o}={}){let t={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[n]||"image/png";if(n==="svg"){let i=decodeURIComponent(e.split(",")[1]);return new Blob([i],{type:"image/svg+xml"})}let a=await X(e,{dpr:1,scale:r},s);return new Promise(i=>{a.toBlob(c=>i(c),`${t}`,o)})}async function X(e,{dpr:n=1,scale:r=1},s){let o=await fe(e,{dpr:n,scale:r});if(!s)return o;let t=document.createElement("canvas");t.width=o.width,t.height=o.height;let a=t.getContext("2d");return a.fillStyle=s,a.fillRect(0,0,t.width,t.height),a.drawImage(o,0,0),t}async function K(e,{dpr:n=1,scale:r=1,backgroundColor:s,quality:o},t="png"){let a=["jpg","jpeg","webp"].includes(t)?"#fff":void 0,c=await X(e,{dpr:n,scale:r},s??a),f=new Image;return f.src=c.toDataURL(`image/${t}`,o),await f.decode(),f.style.width=`${c.width/n}px`,f.style.height=`${c.height/n}px`,f}async function ve(e,{dpr:n=1,scale:r=1,backgroundColor:s="#fff",format:o="png",filename:t="capture"}={}){if(o==="svg"){let p=await de(e),m=URL.createObjectURL(p),h=document.createElement("a");h.href=m,h.download=`${t}.svg`,h.click(),URL.revokeObjectURL(m);return}let a=["jpg","jpeg","webp"].includes(o)?"#fff":void 0,c=await X(e,{dpr:n,scale:r},s??a),f={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[o]||"image/png",u=c.toDataURL(f),d=document.createElement("a");d.href=u,d.download=`${t}.${o}`,d.click()}async function S(e,n={}){if(n={scale:1,...n},!e)throw new Error("Element cannot be null or undefined");return n.iconFonts&&ne(n.iconFonts),await S.capture(e,n)}S.capture=async(e,n={})=>{let r=await le(e,n),s=window.devicePixelRatio||1,o=n.scale||1;return{url:r,options:n,toRaw:()=>r,toImg:()=>Ee(r,{dpr:s,scale:o}),toCanvas:()=>fe(r,{dpr:s,scale:o}),toBlob:t=>de(r,{dpr:s,scale:o,...t}),toPng:t=>K(r,{dpr:s,scale:o,...t},"png"),toJpg:t=>K(r,{dpr:s,scale:o,...t},"jpeg"),toWebp:t=>K(r,{dpr:s,scale:o,...t},"webp"),download:({format:t="png",filename:a="capture",backgroundColor:i}={})=>ve(r,{dpr:s,scale:o,backgroundColor:i,format:t,filename:a})}};S.toRaw=async(e,n)=>(await S.capture(e,n)).toRaw();S.toImg=async(e,n)=>(await S.capture(e,n)).toImg();S.toCanvas=async(e,n)=>(await S.capture(e,n)).toCanvas();S.toBlob=async(e,n)=>(await S.capture(e,n)).toBlob(n);S.toPng=async(e,n)=>(await S.capture(e,n)).toPng(n);S.toJpg=async(e,n)=>(await S.capture(e,n)).toJpg(n);S.toWebp=async(e,n)=>(await S.capture(e,n)).toWebp(n);S.download=async(e,n={})=>{let{format:r="png",filename:s="capture",backgroundColor:o,...t}=n;return await(await S.capture(e,t)).download({format:r,filename:s,backgroundColor:o})};async function $e(e=document,n={}){let{embedFonts:r=!0,reset:s=!1}=n;if(s){l.reset();return}await document.fonts.ready,Y();let o=[],t=[];e?.querySelectorAll&&(o=Array.from(e.querySelectorAll("img[src]")),t=Array.from(e.querySelectorAll("*")));let a=[];for(let i of o){let c=i.src;l.image.has(c)||a.push(N(c,{useProxy:n.useProxy}).then(f=>l.image.set(c,f)).catch(()=>{}))}for(let i of t){let c=A(i).backgroundImage;if(c&&c!=="none"){let f=F(c);for(let u of f)u.startsWith("url(")&&a.push(T(u,n).catch(()=>{}))}}r&&await O({preCached:!0}),await Promise.all(a)}export{$e as preCache,S as snapdom};
|
|
15
|
+
`}if(o&&(l.resource.set("fonts-embed-css",o),e)){let t=document.createElement("style");t.setAttribute("data-snapdom","embedFonts"),t.textContent=o,document.head.appendChild(t)}return o}async function H(e,n,r,s=!1,o){if(!(e instanceof Element)||!(n instanceof Element))return;for(let i of["::before","::after","::first-letter"])try{let c=N(e,i);if(!c||typeof c[Symbol.iterator]!="function")continue;if(i==="::first-letter"){let g=getComputedStyle(e);if(!(c.color!==g.color||c.fontSize!==g.fontSize||c.fontWeight!==g.fontWeight))continue;let x=Array.from(n.childNodes).find(b=>b.nodeType===Node.TEXT_NODE&&b.textContent&&b.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],M=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 v=q(c),_=U(v,"span",r);l.preStyleMap.set(E,_);let L=document.createTextNode(M);n.replaceChild(L,x),n.insertBefore(E,L);continue}let f=c.getPropertyValue("content"),p=c.getPropertyValue("background-image"),d=c.getPropertyValue("background-color"),m=f!=="none",h=p&&p!=="none",u=d&&d!=="transparent"&&d!=="rgba(0, 0, 0, 0)";if(m||h||u){let g=c.getPropertyValue("font-family"),y=parseInt(c.getPropertyValue("font-size"))||32,x=parseInt(c.getPropertyValue("font-weight"))||!1,C=c.getPropertyValue("color")||"#000",w=document.createElement("span");w.dataset.snapdomPseudo=i;let k=q(c),M=U(k,"span",r);l.preStyleMap.set(w,M);let E=$(g),v=ee(f);if(E&&v.length===1){let b=document.createElement("img");b.src=await oe(v,g,x,y,C),b.style=`width:${y}px;height:auto;object-fit:contain;`,w.appendChild(b)}else if(v.startsWith("url(")){let b=B(v);if(b&&b.trim()!=="")try{let I=document.createElement("img"),R=await A(j(b,{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&&v&&v!=="none"&&(w.textContent=v);if(h)try{let b=F(p),I=await Promise.all(b.map(R=>T(R)));w.style.backgroundImage=I.join(", ")}catch(b){console.warn(`[snapdom] Failed to inline background-image for ${i}`,b)}if(u&&(w.style.backgroundColor=d),!(w.childNodes.length>0||w.textContent&&w.textContent.trim()!==""||h||u))continue;i==="::before"?n.insertBefore(w,n.firstChild):n.appendChild(w)}}catch(c){console.warn(`[snapdom] Failed to capture ${i} for`,e,c)}let t=Array.from(e.children),a=Array.from(n.children).filter(i=>!i.dataset.snapdomPseudo);for(let i=0;i<Math.min(t.length,a.length);i++)await H(t[i],a[i],r,s,o)}function ae(e){if(!e)return;let n=document.querySelectorAll("svg > defs");n.length&&e.querySelectorAll("svg").forEach(r=>{let s=r.querySelectorAll("use");if(!s.length)return;let o=new Set;if(s.forEach(a=>{let i=a.getAttribute("xlink:href")||a.getAttribute("href");i&&i.startsWith("#")&&o.add(i.slice(1))}),!o.size)return;let t=document.createElementNS("http://www.w3.org/2000/svg","defs");for(let a of o)for(let i of n){let c=i.querySelector(`#${CSS.escape(a)}`);if(c){t.appendChild(c.cloneNode(!0));break}}t.childNodes.length&&r.insertBefore(t,r.firstChild)})}async function se(e,n=!1,r=!1,s={}){let o,t="";try{o=D(e,n,s,e)}catch(a){throw console.warn("deepClone failed:",a),a}try{await H(e,o,n,r,s.useProxy)}catch(a){console.warn("inlinePseudoElements failed:",a)}try{ae(o)}catch(a){console.warn("inlineExternalDef failed:",a)}if(n){let a=Z();t=Array.from(a.entries()).map(([i,c])=>`.${c}{${i}}`).join("");for(let[i,c]of l.preStyleMap.entries()){if(i.tagName==="STYLE")continue;let f=a.get(c);f&&i.classList.add(f);let p=i.style?.backgroundImage;i.removeAttribute("style"),p&&p!=="none"&&(i.style.backgroundImage=p)}}else for(let[a,i]of l.preStyleMap.entries())a.tagName!=="STYLE"&&a.setAttribute("style",i.replace(/;/g,"; "));for(let[a,i]of l.preNodeMap.entries()){let c=i.scrollLeft,f=i.scrollTop;if((c||f)&&a instanceof HTMLElement){a.style.overflow="hidden",a.style.scrollbarWidth="none",a.style.msOverflowStyle="none";let d=document.createElement("div");for(d.style.transform=`translate(${-c}px, ${-f}px)`,d.style.willChange="transform",d.style.display="inline-block",d.style.width="100%";a.firstChild;)d.appendChild(a.firstChild);a.appendChild(d)}}if(e===l.preNodeMap.get(o)){let a=l.preStyle.get(e)||window.getComputedStyle(e);l.preStyle.set(e,a);let i=te(a.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[a,i]of l.preNodeMap.entries())i.tagName==="PRE"&&(a.style.marginTop="0",a.style.marginBlockStart="0");return{clone:o,classCSS:t}}async function ie(e,n={}){let r=Array.from(e.querySelectorAll("img")),s=async o=>{let t=o.src;try{let a=await A(t,{useProxy:n.useProxy});o.src=a,o.width||(o.width=o.naturalWidth||100),o.height||(o.height=o.naturalHeight||100)}catch{let a=document.createElement("div");a.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;`,a.innerText="img",o.replaceWith(a)}};for(let o=0;o<r.length;o+=4){let t=r.slice(o,o+4).map(s);await Promise.allSettled(t)}}async function ce(e,n,r={}){let s=[[e,n]],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[t,a]=s.shift(),i=l.preStyle.get(t)||N(t);l.preStyle.has(t)||l.preStyle.set(t,i);for(let d of o){let m=i.getPropertyValue(d);if(!m||m==="none")continue;let h=F(m),u=await Promise.all(h.map(g=>T(g,r)));u.some(g=>g&&g!=="none"&&!/^url\(undefined/.test(g))&&a.style.setProperty(d,u.join(", "))}let c=i.getPropertyValue("background-color");c&&c!=="transparent"&&c!=="rgba(0, 0, 0, 0)"&&(a.style.backgroundColor=c);let f=Array.from(t.children),p=Array.from(a.children);for(let d=0;d<Math.min(f.length,p.length);d++)s.push([f[d],p[d]])}}async function le(e,n={}){if(!e)throw new Error("Element cannot be null or undefined");l.reset();let{compress:r=!0,embedFonts:s=!1,fast:o=!0,scale:t=1,useProxy:a=""}=n,i,c,f="",p="",d,m;if({clone:i,classCSS:c}=await se(e,r,s,n),await new Promise(u=>{P(async()=>{await ie(i,n),u()},{fast:o})}),await new Promise(u=>{P(async()=>{await ce(e,i,n),u()},{fast:o})}),s&&await new Promise(u=>{P(async()=>{f=await V(),u()},{fast:o})}),r){let u=J(i).sort(),g=u.join(",");l.baseStyle.has(g)?p=l.baseStyle.get(g):await new Promise(y=>{P(()=>{p=Q(u),l.baseStyle.set(g,p),y()},{fast:o})})}await new Promise(u=>{P(()=>{let g=e.getBoundingClientRect(),y=g.width,x=g.height,C=Number.isFinite(n.width),w=Number.isFinite(n.height),k=typeof t=="number"&&t!==1;if(!k){let R=g.width/g.height;C&&w?(y=n.width,x=n.height):C?(y=n.width,x=y/R):w&&(x=n.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,pe=y/R,me=x/ue,he=i.style.transform||"",ge=`scale(${pe}, ${me})`;i.style.transform=`${ge} ${he}`.trim()}else k&&W()&&(i.style.scale=`${t}`);let M="http://www.w3.org/2000/svg",E=document.createElementNS(M,"foreignObject");E.setAttribute("width","100%"),E.setAttribute("height","100%");let v=document.createElement("style");v.textContent=p+f+"svg{overflow:visible;}"+c,E.appendChild(v),E.appendChild(i);let L=new XMLSerializer().serializeToString(E);m=`<svg xmlns="${M}" width="${y}" height="${x}" viewBox="0 0 ${y} ${x}">`+L+"</svg>",d=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(m)}`,u()},{fast:o})});let h=document.getElementById("snapdom-sandbox");return h&&h.style.position==="absolute"&&h.remove(),d}async function Ee(e,{dpr:n=1,scale:r=1}){let s=new Image;return s.src=e,await s.decode(),W?(s.width=s.width*r,s.height=s.height*r):(s.width=s.width/r,s.height=s.height/r),s}async function fe(e,{dpr:n=1,scale:r=1}={}){let s=new Image;s.src=e,await s.decode();let o=document.createElement("canvas"),t=s.width*r,a=s.height*r;o.width=Math.ceil(t*n),o.height=Math.ceil(a*n);let i=o.getContext("2d");return i.scale(n,n),i.drawImage(s,0,0,t,a),o.style.width=`${t}px`,o.style.height=`${a}px`,o}async function de(e,{type:n="svg",scale:r=1,backgroundColor:s="#fff",quality:o}={}){let t={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[n]||"image/png";if(n==="svg"){let i=decodeURIComponent(e.split(",")[1]);return new Blob([i],{type:"image/svg+xml"})}let a=await X(e,{dpr:1,scale:r},s);return new Promise(i=>{a.toBlob(c=>i(c),`${t}`,o)})}async function X(e,{dpr:n=1,scale:r=1},s){let o=await fe(e,{dpr:n,scale:r});if(!s)return o;let t=document.createElement("canvas");t.width=o.width,t.height=o.height;let a=t.getContext("2d");return a.fillStyle=s,a.fillRect(0,0,t.width,t.height),a.drawImage(o,0,0),t}async function K(e,{dpr:n=1,scale:r=1,backgroundColor:s,quality:o},t="png"){let a=["jpg","jpeg","webp"].includes(t)?"#fff":void 0,c=await X(e,{dpr:n,scale:r},s??a),f=new Image;return f.src=c.toDataURL(`image/${t}`,o),await f.decode(),f.style.width=`${c.width/n}px`,f.style.height=`${c.height/n}px`,f}async function ve(e,{dpr:n=1,scale:r=1,backgroundColor:s="#fff",format:o="png",filename:t="capture"}={}){if(o==="svg"){let m=await de(e),h=URL.createObjectURL(m),u=document.createElement("a");u.href=h,u.download=`${t}.svg`,u.click(),URL.revokeObjectURL(h);return}let a=["jpg","jpeg","webp"].includes(o)?"#fff":void 0,c=await X(e,{dpr:n,scale:r},s??a),f={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp"}[o]||"image/png",p=c.toDataURL(f),d=document.createElement("a");d.href=p,d.download=`${t}.${o}`,d.click()}async function S(e,n={}){if(n={scale:1,...n},!e)throw new Error("Element cannot be null or undefined");return n.iconFonts&&ne(n.iconFonts),await S.capture(e,n)}S.capture=async(e,n={})=>{let r=await le(e,n),s=window.devicePixelRatio||1,o=n.scale||1;return{url:r,options:n,toRaw:()=>r,toImg:()=>Ee(r,{dpr:s,scale:o}),toCanvas:()=>fe(r,{dpr:s,scale:o}),toBlob:t=>de(r,{dpr:s,scale:o,...t}),toPng:t=>K(r,{dpr:s,scale:o,...t},"png"),toJpg:t=>K(r,{dpr:s,scale:o,...t},"jpeg"),toWebp:t=>K(r,{dpr:s,scale:o,...t},"webp"),download:({format:t="png",filename:a="capture",backgroundColor:i}={})=>ve(r,{dpr:s,scale:o,backgroundColor:i,format:t,filename:a})}};S.toRaw=async(e,n)=>(await S.capture(e,n)).toRaw();S.toImg=async(e,n)=>(await S.capture(e,n)).toImg();S.toCanvas=async(e,n)=>(await S.capture(e,n)).toCanvas();S.toBlob=async(e,n)=>(await S.capture(e,n)).toBlob(n);S.toPng=async(e,n)=>(await S.capture(e,n)).toPng(n);S.toJpg=async(e,n)=>(await S.capture(e,n)).toJpg(n);S.toWebp=async(e,n)=>(await S.capture(e,n)).toWebp(n);S.download=async(e,n={})=>{let{format:r="png",filename:s="capture",backgroundColor:o,...t}=n;return await(await S.capture(e,t)).download({format:r,filename:s,backgroundColor:o})};async function ke(e=document,n={}){let{embedFonts:r=!0,reset:s=!1}=n;if(s){l.reset();return}await document.fonts.ready,Y();let o=[],t=[];e?.querySelectorAll&&(o=Array.from(e.querySelectorAll("img[src]")),t=Array.from(e.querySelectorAll("*")));let a=[];for(let i of o){let c=i.src;l.image.has(c)||a.push(A(c,{useProxy:n.useProxy}).then(f=>l.image.set(c,f)).catch(()=>{}))}for(let i of t){let c=N(i).backgroundImage;if(c&&c!=="none"){let f=F(c);for(let p of f)p.startsWith("url(")&&a.push(T(p,n).catch(()=>{}))}}r&&await V({preCached:!0}),await Promise.all(a)}export{ke as preCache,S as snapdom};
|
package/dist/snapdom.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
/*
|
|
3
3
|
* snapdom
|
|
4
|
-
* v.1.9.6-dev.
|
|
4
|
+
* v.1.9.6-dev.2
|
|
5
5
|
* Author Juan Martin Muda
|
|
6
6
|
* License MIT
|
|
7
7
|
**/
|
|
@@ -504,9 +504,8 @@ function deepClone(node, compress, options = {}, originalRoot) {
|
|
|
504
504
|
img.src = dataURL;
|
|
505
505
|
img.width = node.width;
|
|
506
506
|
img.height = node.height;
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
img.style.height = node.style.height || `${node.height}px`;
|
|
507
|
+
cache.preNodeMap.set(img, node);
|
|
508
|
+
inlineAllStyles(node, img, compress);
|
|
510
509
|
return img;
|
|
511
510
|
}
|
|
512
511
|
let clone;
|
package/package.json
CHANGED