Files
ONE-OS/axhub-make/admin/assets/chunks/fills-generator.js
王冕 a27e3b8e43 feat: sync full workspace including web modules, docs, and configurations to Gitea
Optimized the root .gitignore to exclude virtual environments, node modules,
and temp folders to ensure clean and lightweight version tracking.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-09 18:12:25 +08:00

3 lines
30 KiB
JavaScript

const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/chunks/vendor-common.js","assets/chunks/vendor-react.js","assets/chunks/_commonjsHelpers.js","assets/chunks/preload-helper.js","assets/chunks/_commonjs-dynamic-modules.js"])))=>i.map(i=>d[i]);
import{_ as tt}from"./preload-helper.js?v=1775123024591";const ne=t=>{if(!t)return null;const e=t.match(/([\d\.]+(?:e[+-]?\d+)?)px/i),n=e==null?void 0:e[1];return n?{unit:"PIXELS",value:parseFloat(n)}:null},re=(t,e=0,n=0)=>{if(!t)return null;const r=t.match(/([\d\.]+(?:e[+-]?\d+)?)px/i);if(r){const i=parseFloat(r[1]);return{unit:"PIXELS",value:Math.min(i,1e4)}}const o=t.match(/([\d\.]+(?:e[+-]?\d+)?)%/i);if(o){const i=parseFloat(o[1]),s=Math.max(e,n),l=i/100*s;return{unit:"PIXELS",value:Math.min(l,1e4)}}const a=t.match(/^([\d\.]+(?:e[+-]?\d+)?)$/i);if(a){const i=parseFloat(a[1]);return{unit:"PIXELS",value:Math.min(i,1e4)}}return null};function et(t,e,n){let r=(t+16)/116,o=e/500+r,a=r-n/200;const i=u=>u>.206897?Math.pow(u,3):(u-16/116)/7.787;o=i(o)*95.047,r=i(r)*100,a=i(a)*108.883,o=o/100,r=r/100,a=a/100;let s=o*3.2406+r*-1.5372+a*-.4986,l=o*-.9689+r*1.8758+a*.0415,c=o*.0557+r*-.204+a*1.057;const d=u=>u>.0031308?1.055*Math.pow(u,1/2.4)-.055:12.92*u;return s=d(s),l=d(l),c=d(c),s=Math.max(0,Math.min(1,s)),l=Math.max(0,Math.min(1,l)),c=Math.max(0,Math.min(1,c)),{r:s,g:l,b:c}}const T=t=>Math.max(0,Math.min(1,t)),E=(t,e=null)=>{if(typeof t!="string")return null;const r=t.trim().match(/^([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(%)?$/i);if(!r)return null;let o=parseFloat(r[1]);if(!Number.isFinite(o))return null;if(r[2]){if(e===null)return null;o=o/100*e}return o},nt=t=>{if(t==null||t==="")return 1;const e=E(t,1);return e===null?null:T(e)},V=t=>{if(typeof t!="string")return null;const e=t.trim(),n=e.endsWith("%"),r=E(e,1);return r===null||!n&&(r<0||r>1)?null:T(r)},rt=t=>{if(typeof t!="string")return null;const n=t.trim().toLowerCase().match(/^([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(deg|rad|grad|turn)?$/);if(!n)return null;let r=parseFloat(n[1]);if(!Number.isFinite(r))return null;const o=n[2]||"deg";return o==="rad"?r=r*180/Math.PI:o==="grad"?r=r*.9:o==="turn"&&(r=r*360),(r%360+360)%360},Y=t=>{const e=t.split("/");if(e.length>2)return null;const n=e[0].trim().split(/[\s,]+/).filter(Boolean);if(n.length!==3)return null;const r=nt(e[1]?e[1].trim():void 0);return r===null?null:{channels:n,alpha:r}};function ot(t,e,n){const r=n*Math.PI/180;return{L:t,a:e*Math.cos(r),b:e*Math.sin(r)}}function at(t,e,n){const r=t+.3963377774*e+.2158037573*n,o=t-.1055613458*e-.0638541728*n,a=t-.0894841775*e-1.291485548*n,i=r*r*r,s=o*o*o,l=a*a*a;return{r:4.0767416621*i-3.3077115913*s+.2309699292*l,g:-1.2684380046*i+2.6097574011*s-.3413193965*l,b:-.0041960863*i-.7034186147*s+1.707614701*l}}function v(t){return t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055}function z(t,e,n){const r=at(t,e,n);return{r:T(v(r.r)),g:T(v(r.g)),b:T(v(r.b))}}function it(t,e,n){const r=ot(t,e,n);return z(r.L,r.a,r.b)}const st=t=>{const e=t.match(/^oklab\(\s*([^)]+)\s*\)$/i);if(!e)return null;const n=Y(e[1]);if(!n)return null;const r=V(n.channels[0]),o=E(n.channels[1],1),a=E(n.channels[2],1);if(r===null||o===null||a===null)return null;const i=z(r,o,a);return{r:i.r,g:i.g,b:i.b,a:n.alpha}},ct=t=>{const e=t.match(/^oklch\(\s*([^)]+)\s*\)$/i);if(!e)return null;const n=Y(e[1]);if(!n)return null;const r=V(n.channels[0]),o=E(n.channels[1],1),a=rt(n.channels[2]);if(r===null||o===null||a===null)return null;const i=it(r,o,a);return{r:i.r,g:i.g,b:i.b,a:n.alpha}};function j(t){if(!t)return null;const e=t.trim();if(e.toLowerCase()==="transparent")return{r:0,g:0,b:0,a:0};const n=ct(e);if(n)return n;const r=st(e);if(r)return r;const o=e.match(/^lab\(\s*([0-9.]+%?)\s+([+-]?[0-9.]+)\s+([+-]?[0-9.]+)(?:\s*\/\s*([0-9.]+%?))?\s*\)$/i);if(o){const s=parseFloat(o[1]),l=parseFloat(o[2]),c=parseFloat(o[3]);let d=1;if(o[4]){const f=parseFloat(o[4]);d=o[4].includes("%")?f/100:f}const u=et(s,l,c);return{r:u.r,g:u.g,b:u.b,a:d}}const a=e.match(/rgba?\(([\d\.]+),\s*([\d\.]+),\s*([\d\.]+)(?:,\s*([\d\.]+))?\)/);if(a){const[s,l,c,d,u]=a;if(l&&c&&d)return{r:parseInt(l)/255,g:parseInt(c)/255,b:parseInt(d)/255,a:u?parseFloat(u):1}}const i=e.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);if(i){let s=i[1];return s.length===3&&(s=s.split("").map(l=>l+l).join("")),{r:parseInt(s.slice(0,2),16)/255,g:parseInt(s.slice(2,4),16)/255,b:parseInt(s.slice(4,6),16)/255,a:1}}return null}const lt=/^[0-9]+[a-zA-Z%]+?$/,K=t=>{if(!/px$/.test(t)&&t!=="0")return 0;const e=parseFloat(t);return isNaN(e)?0:e},X=t=>t==="0"||lt.test(t),ut=/^(transparent|currentcolor|#[0-9a-f]{3,8}|(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)\([^)]*\))\s+/i,Q=t=>{const e=t.match(ut);if(!e)return t;const n=e[1],r=t.slice(e[0].length).trim();return r?`${r} ${n}`.trim():t},U=t=>{t=Q(t);const e=/\s(?![^(]*\))/,n=t.split(e),r=n.includes("inset"),o=n.slice(-1)[0],a=X(o)?"rgba(0, 0, 0, 1)":o,i=n.filter(u=>u!=="inset").filter(u=>u!==a).map(K),[s=0,l=0,c=0,d=0]=i;return{inset:r,offsetX:s,offsetY:l,blurRadius:c,spreadRadius:d,color:a}},oe=t=>{if(!t||t==="none")return[];const e=[];let n="",r=0;for(let o=0;o<t.length;o++){const a=t[o];if(a==="(")r++;else if(a===")")r--;else if(a===","&&r===0&&n.trim()){e.push(U(n.trim())),n="";continue}n+=a}return n.trim()&&e.push(U(n.trim())),e},B=t=>{t=Q(t);const e=/\s(?![^(]*\))/,n=t.split(e),r=n.slice(-1)[0],o=X(r)?"rgba(0, 0, 0, 1)":r,a=n.filter(c=>c!==o).map(K),[i=0,s=0,l=0]=a;return{offsetX:i,offsetY:s,blurRadius:l,color:o}},ae=t=>{if(!t||t==="none")return[];const e=[];let n="",r=0;for(let o=0;o<t.length;o++){const a=t[o];if(a==="(")r++;else if(a===")")r--;else if(a===","&&r===0&&n.trim()){e.push(B(n.trim())),n="";continue}n+=a}return n.trim()&&e.push(B(n.trim())),e},ie=t=>{if(!t||t==="none")return[];const e=[],n=/(\w+)\(([^)]+)\)/g;let r;for(;(r=n.exec(t))!==null;){const[,o,a]=r;switch(o){case"blur":const i=parseFloat(a);isNaN(i)||e.push({type:"LAYER_BLUR",radius:i,visible:!0});break;case"brightness":case"contrast":case"saturate":case"hue-rotate":case"invert":case"sepia":case"opacity":e.push({type:"CUSTOM_FILTER",filterType:o,value:parseFloat(a)||1,visible:!0});break}}return e},se=t=>{if(!t||t==="none")return[];const e=[],n=/(\w+)\(([^)]+)\)/g;let r;for(;(r=n.exec(t))!==null;){const[,o,a]=r;if(o==="blur"){const i=parseFloat(a);isNaN(i)||e.push({type:"BACKGROUND_BLUR",radius:i,visible:!0})}}return e},dt={fill:"FILL",contain:"FIT",cover:"CROP","scale-down":"FIT",none:"TILE"},N="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAG0lEQVQImWNgYGD4z8DAwMgABYwMjAxQAKkGBgA66gJx4f4x5QAAAABJRU5ErkJggg==";function ft(t){if(!t||t==="none")return"TILE";if(t==="contain")return"FIT";if(t==="cover")return"CROP";if(t==="auto")return"TILE";const e=t.split(/\s+/);if(e.length>=1){const[n,r]=e;if(n==="100%"&&r==="100%")return"FILL";if(e.length===1)return n==="100%"?"FILL":n==="auto"?"TILE":"CROP";if(e.length>=2){if(r==="auto"&&(n.includes("%")||n.includes("px"))||n==="auto"&&(r.includes("%")||r.includes("px"))||(n.includes("%")||n.includes("px"))&&(r.includes("%")||r.includes("px")))return"CROP";if(n==="auto"&&r==="auto")return"TILE"}}return"FILL"}function gt(t){let e=t.parentElement;for(;e;){const r=getComputedStyle(e).overflow;if(r!=="visible")return r;e=e.parentElement}return"visible"}function ht(t,e){return(e==="hidden"||e==="scroll"||e==="auto")&&(t==="FIT"||t==="TILE")?"CROP":t}function A(t,e,n){let r;if(e==="background")r=ft(t.backgroundSize);else{const a=t.objectFit||"fill";r=dt[a]||"FILL"}const o=gt(n);return ht(r,o)}const mt=({computedStyle:t,el:e})=>{if(e instanceof SVGSVGElement){const n=`data:image/svg+xml,${encodeURIComponent(e.outerHTML.replace(/\s+/g," "))}`,r=A(t,"image",e);return{url:n,type:"IMAGE",scaleMode:r,imageHash:null}}else if(e instanceof HTMLImageElement){const n=e.src;if(n){const r=A(t,"image",e);e.getAttribute("data-from-canvas");const o=n.startsWith("data:"),a={type:"IMAGE",scaleMode:r,imageHash:null};if(o){const i=k(n);i.byteLength>0&&(a.intArr=Array.from(i))}return Object.assign({url:n},a)}else{if(e.getAttribute("data-canvas-tainted")==="true"){const r=A(t,"image",e),o={url:N,type:"IMAGE",scaleMode:r,imageHash:null},a=k(N);return a.byteLength>0&&(o.intArr=Array.from(a)),o}console.warn("⚠️ [getImagePaintWithUrl] IMG 元素没有 src:",e)}}else if(e instanceof HTMLVideoElement){const n=e.poster;if(n){const o={type:"IMAGE",scaleMode:A(t,"image",e),imageHash:null};if(n.startsWith("data:")){const a=k(n);a.byteLength>0&&(o.intArr=Array.from(a))}return Object.assign({url:n},o)}}if(t.backgroundImage&&t.backgroundImage!=="none"){const n=t.backgroundImage.match(/url\(['"]?(.*?)['"]?\)/),r=n==null?void 0:n[1];if(r){if(r.includes(".svg")||r.includes("data:image/svg+xml"))return;const o=A(t,"background",e);return{url:r,type:"IMAGE",scaleMode:o,imageHash:null}}}},O=";base64,";function k(t){try{const e=t.indexOf(O)+O.length,n=t.substring(e);if(!n||n.trim()==="")return console.warn("⚠️ [convertDataURIToBinary] base64 内容为空"),new Uint8Array(0);const r=window.atob(n),o=r.length,a=new Uint8Array(new ArrayBuffer(o));for(let i=0;i<o;i++)a[i]=r.charCodeAt(i);return a}catch(e){return console.warn("⚠️ [convertDataURIToBinary] base64 解码失败:",e),new Uint8Array(0)}}const pt=t=>{var e;if(typeof window>"u"||!((e=window.location)!=null&&e.origin))return null;try{return`${window.location.origin}/api/export/image-proxy?url=${encodeURIComponent(t)}`}catch{return null}},bt=t=>{var e;if(typeof window>"u"||!((e=window.location)!=null&&e.origin))return!1;try{return new URL(t,document.baseURI).origin!==window.location.origin}catch{return!1}},yt=async t=>{const e=await fetch(t,{method:"GET",mode:"cors"});if(!e.ok)throw new Error(`Image request failed with status ${e.status}`);return await e.blob()};async function C(t){const e=[],n=pt(t);n&&bt(t)&&e.push({url:n,viaProxy:!0}),e.push({url:t,viaProxy:!1});let r=null;for(const o of e)try{const a=await yt(o.url),i=a.type;return i!=="image/png"&&i!=="image/jpeg"?await L(await G(a),i):`data:${i};base64,${await G(a)}`}catch(a){r=a}return console.error("Failed to load image as base64:",r),null}const F=t=>typeof t=="string"&&t.startsWith("data:"),wt=t=>{try{return new URL(t,document.baseURI).href}catch{return t}},At=async t=>{var n,r,o;if(!(typeof globalThis<"u"&&((r=(n=globalThis.chrome)==null?void 0:n.runtime)==null?void 0:r.sendMessage)))return null;try{const a=await Promise.race([globalThis.chrome.runtime.sendMessage({type:"getResourceContent",src:t}),new Promise(l=>setTimeout(()=>l(null),8e3))]);if(!((o=a==null?void 0:a.data)!=null&&o.content))return null;const i=a.data.mimeType||"application/octet-stream",s=a.data.content;if(a.data.base64Encoded){if(i==="image/webp")try{return await L(s,i)}catch{}return`data:${i};base64,${s}`}return typeof s=="string"&&i.includes("svg")?`data:${i};utf8,${encodeURIComponent(s)}`:null}catch{return null}},It=async t=>{if(!t)return t;if(F(t))return await q(t);const e=wt(t),n=await At(e);return n||await C(e)},Tt=t=>{const e=/^data:([^;,]+)/i.exec(t||"");return(e&&e[1]?e[1].toLowerCase():"").trim()},Et=t=>t==="image/png"||t==="image/jpeg"||t==="image/jpg"||t==="image/gif",Lt=t=>new Promise((e,n)=>{const r=new Image,o=setTimeout(()=>n(new Error("Image load timeout")),1e4);r.onload=()=>{clearTimeout(o);try{const a=document.createElement("canvas"),i=a.getContext("2d");if(!i){n(new Error("Failed to get canvas context"));return}a.width=r.width,a.height=r.height,i.drawImage(r,0,0),e(a.toDataURL("image/png"))}catch(a){n(a)}},r.onerror=()=>{clearTimeout(o),n(new Error("Failed to load data URL image"))},r.src=t}),q=async t=>{if(!F(t))return t;const e=Tt(t);if(!e||Et(e)||!e.startsWith("image/"))return t;try{return await Lt(t)}catch{return t}},Mt=t=>{const e=[];if(!t||t==="none")return e;const n=/url\((['"]?)(.*?)\1\)/g;let r;for(;(r=n.exec(t))!==null;){const o=(r[2]||"").trim();o&&e.push({fullMatch:r[0],rawUrl:o})}return e},I=t=>{t.removeAttribute("srcset"),t.removeAttribute("sizes"),t.srcset="",t.sizes="",t.parentElement instanceof HTMLPictureElement&&t.parentElement.querySelectorAll("source").forEach(n=>{n.removeAttribute("srcset"),n.removeAttribute("sizes")})};async function Ct(t){const e=[t,...Array.from(t.querySelectorAll("*"))];for(const n of e){if(!(n instanceof HTMLElement))continue;let r;try{r=window.getComputedStyle(n)}catch{continue}const o=r.backgroundImage;if(!o||o==="none")continue;const a=Mt(o);if(a.length===0)continue;let i=o,s=!1;for(const l of a){const c=await It(l.rawUrl);if(!c||!F(c))continue;const d=`url("${c}")`;i.includes(l.fullMatch)&&(i=i.replace(l.fullMatch,d),s=!0)}s&&n.style.setProperty("background-image",i,"important")}}function G(t){return new Promise((e,n)=>{const r=new FileReader;r.onload=()=>{const a=r.result.split(",")[1];e(a)},r.onerror=n,r.readAsDataURL(t)})}function L(t,e){return new Promise((n,r)=>{const o=new Image,a=setTimeout(()=>{r(new Error("Image load timeout"))},1e4);o.onload=()=>{clearTimeout(a);const s=document.createElement("canvas"),l=s.getContext("2d");if(!l){const c=new Error("Failed to get canvas context");console.error("❌ [imgToPng]",c),r(c);return}s.width=o.width,s.height=o.height;try{l.drawImage(o,0,0);const c=s.toDataURL("image/png");n(c)}catch(c){console.error("❌ [imgToPng] Canvas 绘制失败:",c),r(c)}},o.onerror=s=>{clearTimeout(a),r(new Error(`Failed to load image: ${s.type||"unknown error"}`))};const i=`data:${e};base64,${t}`;o.src=i})}function D(){const t=arguments.length>0?arguments[0]:document,e=arguments.length>1?arguments[1]:void 0,n=e&&typeof e.timeoutMs=="number"?e.timeoutMs:8e3,r=t&&typeof t.querySelectorAll=="function"?t:document;return new Promise(o=>{const a=r.querySelectorAll("img");if(a.length===0){o();return}let i=0;const s=a.length,l=typeof performance<"u"?performance.now():Date.now(),c=new Set,d=()=>{i++,i===s&&o()};a.forEach(u=>{c.add(u);const f=()=>{c.has(u)&&c.delete(u),d()};if(u.complete)f();else{const h=()=>{b(),f()},p=()=>{b(),f()},b=()=>{u.removeEventListener("load",h),u.removeEventListener("error",p),clearTimeout(m)},m=setTimeout(()=>{b(),f()},n);u.addEventListener("load",h,{once:!0}),u.addEventListener("error",p,{once:!0})}}),setTimeout(()=>{if(i!==s){const u=Math.round((typeof performance<"u"?performance.now():Date.now())-l);console.warn("⚠️ [areAllImagesLoaded] timeout, continue anyway",{elapsedMs:u,totalImages:s,remaining:c.size}),o()}},n+50)})}const P=!1,_="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAG0lEQVQImWNgYGD4z8DAwMgABYwMjAxQAKkGBgA66gJx4f4x5QAAAABJRU5ErkJggg==",Rt=(t,e,n)=>{try{const r=document.createElement("canvas"),o=Math.max(1,Math.min(32,Math.round(t)||2)),a=Math.max(1,Math.min(32,Math.round(e)||2));r.width=o,r.height=a;const i=r.getContext("2d");return i?(i.fillStyle=n||"#f0f0f0",i.fillRect(0,0,o,a),r.toDataURL("image/png")):_}catch{return _}};async function xt(t){t.querySelectorAll("canvas").forEach((n,r)=>{try{if(n.width===0||n.height===0)return;const o=window.getComputedStyle(n),a=Rt(n.width,n.height,o.backgroundColor);let i;try{i=n.toDataURL("image/png")}catch{const c=document.createElement("img");c.src=a,c.style.width=n.style.width||n.width+"px",c.style.height=n.style.height||n.height+"px",c.style.backgroundColor="#f0f0f0",c.setAttribute("data-canvas-tainted","true"),c.setAttribute("data-from-canvas","true"),c.setAttribute("alt","Canvas (跨域限制)"),c.setAttribute("data-canvas-width",String(n.width||0)),c.setAttribute("data-canvas-height",String(n.height||0)),c.style.display=o.display,c.style.position=o.position,c.style.objectFit="fill",n.parentNode&&n.parentNode.replaceChild(c,n);return}const s=document.createElement("img");s.src=i||a,s.style.width=n.style.width||n.width+"px",s.style.height=n.style.height||n.height+"px",s.style.display=o.display,s.style.position=o.position,s.style.top=o.top,s.style.left=o.left,s.style.right=o.right,s.style.bottom=o.bottom,s.style.margin=o.margin,s.style.padding=o.padding,n.className&&(s.className=n.className),n.id&&(s.id=n.id),s.setAttribute("data-from-canvas","true"),n.parentNode&&n.parentNode.replaceChild(s,n)}catch(o){console.error(`❌ [convertCanvasToImage] Canvas ${r+1} 转换失败:`,o),console.error("❌ [convertCanvasToImage] 错误堆栈:",o.stack)}})}async function ce(t){try{await xt(t),await Ct(t),await D(t);const e=[],n=t.querySelectorAll("img");for(let r=0;r<n.length;r++){const o=n[r],a=o.currentSrc||o.src;if(a){if(a.startsWith("data:image/")){const i=(async()=>{try{const s=await q(a);s&&s!==a&&(o.setAttribute("src",s),I(o))}catch{}return!0})();e.push(i);continue}if(a&&!a.startsWith("data")){const i=(async()=>{var s,l,c;try{const d=new URL(a,document.baseURI).href,f=typeof globalThis<"u"&&((l=(s=globalThis.chrome)==null?void 0:s.runtime)==null?void 0:l.sendMessage)?await Promise.race([globalThis.chrome.runtime.sendMessage({type:"getResourceContent",src:d}),new Promise(h=>setTimeout(()=>h(null),8e3))]):null;if((c=f==null?void 0:f.data)!=null&&c.base64Encoded){if(f.data.mimeType!=="image/png"&&f.data.mimeType!=="image/jpeg")try{const h=await L(f.data.content,f.data.mimeType);o.setAttribute("src",h),I(o)}catch{try{const p=`data:${f.data.mimeType};base64,${f.data.content}`;o.setAttribute("src",p),I(o)}catch{}}else{const h=`data:${f.data.mimeType};base64,${f.data.content}`;o.setAttribute("src",h),I(o)}return!0}else{try{const h=await C(d);if(h)return o.setAttribute("src",h),I(o),!0}catch{}return!1}}catch{return!1}})();e.push(i)}}}if(e.length>0)try{const r=new Promise(o=>{setTimeout(()=>{o(new Array(e.length).fill(!1))},3e4)});await Promise.race([Promise.allSettled(e),r])}catch{}await D(t,{timeoutMs:8e3})}catch{}}const $=!1;function vt(){try{return $||!!window.__AXHUB_HTML_TO_FIGMA_DEBUG__||!!window.__AXHUB_FILL_DEBUG__}catch{return $}}function kt(t){return!t||!(t instanceof Element)?{name:"unknown",className:""}:{name:t.tagName.toLowerCase(),id:t.id||"",className:t.className||""}}function Pt(t){if(!t||t==="none")return[];const e=[];let n="",r=0,o=!1,a="";for(let i=0;i<t.length;i++){const s=t[i],l=i>0?t[i-1]:"";if((s==='"'||s==="'")&&l!=="\\"&&(o?s===a&&(o=!1,a=""):(o=!0,a=s)),o||(s==="("?r++:s===")"&&r--),s===","&&!o&&r===0){const c=n.trim();c&&e.push(c),n=""}else n+=s}return n.trim()&&e.push(n.trim()),e}function Ft(t){return t?t.split(",").map(e=>e.trim()).filter(Boolean):[]}function Ut(t){switch((t||"").toLowerCase()){case"normal":case"src-over":return"NORMAL";case"multiply":return"MULTIPLY";case"screen":return"SCREEN";case"overlay":return"OVERLAY";case"darken":return"DARKEN";case"lighten":return"LIGHTEN";case"color-dodge":return"COLOR_DODGE";case"color-burn":return"COLOR_BURN";case"hard-light":return"HARD_LIGHT";case"soft-light":return"SOFT_LIGHT";case"difference":return"DIFFERENCE";case"exclusion":return"EXCLUSION";case"hue":return"HUE";case"saturation":return"SATURATION";case"color":return"COLOR";case"luminosity":return"LUMINOSITY";default:return"NORMAL"}}function W(t){if(!t||t==="none"||t==="auto")return"TILE";if(t==="contain")return"FIT";if(t==="cover")return"CROP";const e=t.split(/\s+/);if(e.length>=1){const[n,r]=e;if(n==="100%"&&r==="100%")return"FILL";if(e.length===1)return n==="100%"?"FILL":n==="auto"?"TILE":"CROP";if(e.length>=2){if(r==="auto"&&(n.includes("%")||n.includes("px"))||n==="auto"&&(r.includes("%")||r.includes("px"))||(n.includes("%")||n.includes("px"))&&(r.includes("%")||r.includes("px")))return"CROP";if(n==="auto"&&r==="auto")return"TILE"}}return"FILL"}function Bt(t,e=1){let n=1;if(t.opacity&&t.opacity!==""){const r=parseFloat(t.opacity);isNaN(r)||(n=r)}return e!==void 0&&e!==1&&(n=n*e),n}function Nt(t){if(!t||t==="none")return[];const e=[];let n="",r=0,o=!1,a="";for(let i=0;i<t.length;i++){const s=t[i],l=i>0?t[i-1]:"";if((s==='"'||s==="'")&&l!=="\\"&&(o?s===a&&(o=!1,a=""):(o=!0,a=s)),o||(s==="("?r++:s===")"&&r--),s===","&&!o&&r===0){const c=n.trim();c&&e.push(S(c)),n=""}else n+=s}return n.trim()&&e.push(S(n.trim())),e}function S(t){if(t.includes("linear-gradient")||t.includes("radial-gradient")||t.includes("conic-gradient")||t.includes("repeating-linear-gradient")||t.includes("repeating-radial-gradient"))return{type:"gradient",value:t};if(t.includes("url(")){const e=t.match(/url\(['"]?(.*?)['"]?\)/);if(e&&e[1]){const n=e[1];return n.includes(".svg")||n.includes("data:image/svg+xml")?{type:"svg",value:n}:{type:"image",value:n}}}return t.includes("data:image/")&&!t.includes("data:image/svg+xml")?{type:"image",value:t.trim()}:{type:"unknown",value:t}}async function le(t,e=null,n={}){const r=vt(),o=kt(e),{includeImageFills:a=!0,includeBackgroundColor:i=!0,includeComplexBackgrounds:s=!0}=n,l=[];if(s&&Ot(t)){if(r&&console.log("[fills] complex-background-screenshot",{trace:o,backgroundImage:t.backgroundImage,background:t.background}),i&&M(l,t),e)try{const c=await Ht(e,t,{ignoreBackgroundColor:!0});if(c)return l.push(c),r&&console.log("[fills] screenshot-image-added",{trace:o,fillTypes:l.map(d=>d.type)}),l}catch(c){console.error("❌ [generateFillsFromStyles] 复杂背景转换出错:",c)}return l.length===0&&M(l,t),l}if(a&&e){const c=mt({computedStyle:t,el:e});if(c)return l.push(c),l}if(a||s){const c=t.backgroundImage,d=Ft(t.backgroundBlendMode||"");if(c&&c!=="none"){let u=1,f=1;if(e){const p=e.getBoundingClientRect(),b=p.width||1,m=p.height||1;b>=m?(u=1,f=m/b):(u=b/m,f=1)}const h=Nt(c);if(h.length>0){r&&console.log("[fills] parsed-background-layers",{trace:o,backgroundImage:c,layerTypes:h.map(m=>m.type)});const p=Pt(t.backgroundSize||"auto");i&&M(l,t);const b=[];for(let m=h.length-1;m>=0;m--){const y=h[m];let g=null;const R=d.length>0?Ut(d[Math.min(m,d.length-1)]):"NORMAL";if(y.type==="gradient"){const w=Vt(y.value,u,f);w&&(g={...w,blendMode:R})}else if(y.type==="image"){const w=p[m]||p[p.length-1]||"auto",x=W(w);g=await H(y.value,x,null),g&&(g={...g,blendMode:R})}else if(y.type==="svg"){const w=p[m]||p[p.length-1]||"auto",x=W(w);g=await H(y.value,x,null),g&&(g={...g,blendMode:R})}g&&b.push(g)}if(l.push(...b),r){const m=l.some(g=>g.type==="IMAGE"),y=l.some(g=>g.type==="GRADIENT_LINEAR"||g.type==="GRADIENT_RADIAL");console.log("[fills] final-fills",{trace:o,fillTypes:l.map(g=>g.type),hasImageFill:m,hasGradientFill:y})}return l}}}return i&&!$t(t)&&!St(t)&&M(l,t),l}function M(t,e){const n=j(e.backgroundColor);if(n&&n.a>0){const r=Bt(e,n.a),o={type:"SOLID",color:{r:n.r,g:n.g,b:n.b},opacity:r};t.push(o)}}function Ot(t){const e=t.backgroundImage,n=t.background;if(e&&e!=="none"&&e.includes("conic-gradient")||n&&n!=="none"&&n.includes("conic-gradient")||Wt(t))return!0;const r=t.maskImage||t.webkitMaskImage;return!!(r&&r!=="none"||Gt(t)||Dt(t)||_t(t))}function Gt(t){const e={top:t.borderTop,right:t.borderRight,bottom:t.borderBottom,left:t.borderLeft};if(!Object.values(e).some(i=>i&&i!=="none"))return!1;const r={};for(const[i,s]of Object.entries(e))if(s&&s!=="none"){const l=s.match(/^([\d\.]+)px\s*(\w+)\s*(.*)$/);if(l){const[c,d,u,f]=l;r[i]={borderWidth:d,borderType:u,borderColor:f}}}else r[i]={borderWidth:"0",borderType:"none",borderColor:"transparent"};const o=Object.values(r).find(i=>i.borderWidth!=="0");return o?!Object.values(r).every(i=>i.borderWidth===o.borderWidth&&i.borderType===o.borderType&&i.borderColor===o.borderColor):!1}function Dt(t){const e=t.clipPath,n=t.webkitClipPath;return e&&e!=="none"||n&&n!=="none"}function _t(t){const e=t.backgroundImage;if(!e||e==="none")return!1;const n=t.backgroundAttachment;if(n&&n==="fixed")return!0;const r=t.backgroundOrigin;if(r&&r!=="padding-box")return!0;const o=t.backgroundRepeat;if(o&&(o==="repeat-x"||o==="repeat-y"))return!0;const a=t.backgroundPositionX,i=t.backgroundPositionY;if(a&&a!=="0%"&&a!=="left"&&a!=="50%"&&a!=="center"||i&&i!=="0%"&&i!=="top"&&i!=="50%"&&i!=="center")return!0;const c=t.backgroundSize;return!!(c&&c!=="auto"&&c!=="cover"&&c!=="contain"&&c!=="100% 100%"&&c!=="100%"&&(c.includes("px")||c.includes("%")&&!c.startsWith("100%")))}function $t(t){const e=t.backgroundImage,n=t.background;return!!(e&&e!=="none"&&(e.includes("linear-gradient")||e.includes("radial-gradient")||e.includes("conic-gradient")||e.includes("repeating-linear-gradient")||e.includes("repeating-radial-gradient"))||n&&n!=="none"&&(n.includes("linear-gradient")||n.includes("radial-gradient")||n.includes("conic-gradient")||n.includes("repeating-linear-gradient")||n.includes("repeating-radial-gradient")))}function Wt(t){const e=t.backgroundImage,n=t.background;return!!(e&&e!=="none"&&(e.includes("repeating-linear-gradient")||e.includes("repeating-radial-gradient"))||n&&n!=="none"&&(n.includes("repeating-linear-gradient")||n.includes("repeating-radial-gradient")))}function St(t){const e=t.backgroundImage,n=t.background;if(e&&e!=="none"&&(e.includes("url(")||e.includes("data:"))){const r=e.match(/url\(['"]?(.*?)['"]?\)/);if(r&&r[1]){const o=r[1];return!(o.includes(".svg")||o.includes("data:image/svg+xml"))}}if(n&&n!=="none"&&(n.includes("url(")||n.includes("data:"))){const r=n.match(/url\(['"]?(.*?)['"]?\)/);if(r&&r[1]){const o=r[1];return!(o.includes(".svg")||o.includes("data:image/svg+xml"))}}return!1}async function Ht(t,e,n={}){try{const r=t.getBoundingClientRect(),o=4096;if(r.width>o||r.height>o)return null;const{snapdom:a}=await tt(async()=>{const{snapdom:l}=await import("./vendor-common.js?v=1775123024591").then(c=>c.dj);return{snapdom:l}},__vite__mapDeps([0,1,2,3,4])),i=t.cloneNode(!0);i.removeAttribute("id");for(let l=0;l<e.length;l++){const c=e[l],d=e.getPropertyValue(c);d&&i.style.setProperty(c,d)}n.ignoreBackgroundColor&&(i.style.backgroundColor="transparent"),i.style.width=`${r.width}px`,i.style.height=`${r.height}px`,i.style.boxSizing="border-box",i.style.margin="0",i.style.position="fixed",i.style.top="0",i.style.left="0",i.style.zIndex="99999",i.style.pointerEvents="none",i.style.visibility="visible",i.style.opacity="1",i.style.color="transparent",i.style.webkitTextFillColor="transparent",i.style.textShadow="none",Array.from(i.children).forEach(l=>{l.style.visibility="hidden"}),document.body.appendChild(i);const s=await a.toPng(i,{fast:!1,embedFonts:!0,scale:1,dpr:1,width:r.width,height:r.height});return document.body.removeChild(i),!s||!s.src?(console.error("❌ [convertElementToBase64Image] snapdom 返回无效的图片元素"),null):{type:"IMAGE",url:s.src,scaleMode:"FILL",imageHash:null}}catch(r){return console.error("❌ [convertElementToBase64Image] 转换失败:",r),null}}function Vt(t,e=1,n=1){if(!t)return null;const r=t.replace(/\s+/g," ").trim(),o=r.match(/linear-gradient\s*\((.+)\)/i);if(o)return Yt(o[1],e,n);const a=r.match(/radial-gradient\s*\((.+)\)/i);return a?zt(a[1]):(r.match(/conic-gradient\s*\((.+)\)/i),null)}function Yt(t,e=1,n=1){const r=J(t);let o="to bottom",a=[];jt(r[0])?(o=r[0],a=r.slice(1)):a=r;const i=Z(a);return i.length?{type:"GRADIENT_LINEAR",gradientTransform:qt(o,e,n),gradientStops:i,opacity:1,visible:!0,blendMode:"NORMAL"}:null}function zt(t){const e=J(t);let n=[];Kt(e[0])||Xt(e[0])?(e[0],n=e.slice(1)):n=e;const r=Z(n);return r.length?{type:"GRADIENT_RADIAL",gradientTransform:Jt(),gradientStops:r,opacity:1,visible:!0,blendMode:"NORMAL"}:null}function J(t){const e=[];let n=0,r=0;for(let o=0;o<t.length;o++){const a=t[o];a==="("?n++:a===")"?n--:a===","&&n===0&&(e.push(t.slice(r,o).trim()),r=o+1)}return e.push(t.slice(r).trim()),e}function jt(t){return!!(/to (top|bottom|left|right)/i.test(t)||/\d+deg/i.test(t))}function Kt(t){return/(circle|ellipse)/i.test(t)}function Xt(t){return/(center|top|bottom|left|right)/i.test(t)}function Z(t){const e=t.map((o,a)=>{const i=o.trim(),s=i.match(/\s+(\d*\.?\d+%?)\s*$/);let l=i,c;if(s){const u=s[1],f=parseFloat(u);isNaN(f)||(c=u.includes("%")?f/100:f),l=i.substring(0,s.index).trim()}const d=Qt(l);return{position:c,color:d}}),n=e.filter(o=>o.position!==void 0),r=e.filter(o=>o.position===void 0);if(r.length>0&&(n.length===0?e.forEach((o,a)=>{o.position=e.length>1?a/(e.length-1):0}):r.forEach((o,a)=>{const i=e.length;o.position=(n.length+a)/(i-1)})),e.sort((o,a)=>(o.position||0)-(a.position||0)),e.forEach(o=>{o.position=Math.max(0,Math.min(1,o.position||0))}),e.length===1){const o=e[0];e.push({position:1,color:{...o.color}}),e[0].position=0}return e.map(o=>({position:o.position,color:o.color}))}function Qt(t){const e=j(t);return e||{r:0,g:0,b:0,a:1}}function qt(t,e=1,n=1){const r={"to top":0,"to top right":45,"to right top":45,"to right":90,"to bottom right":135,"to right bottom":135,"to bottom":180,"to bottom left":225,"to left bottom":225,"to left":270,"to top left":315,"to left top":315};let o;const a=t.trim().toLowerCase();a.endsWith("deg")?o=parseFloat(a):r[a]!==void 0?o=r[a]:o=180;const i=o*Math.PI/180,s=Math.cos(i),l=Math.sin(i);return[[s,-l,.5],[l,s,.5]]}function Jt(t,e){return[[.5,0,.5],[0,.5,.5]]}function Zt(t){return t?!!(t.includes(".svg")&&!t.includes(".svg?")&&t.split("?")[0].endsWith(".svg")||t.startsWith("data:image/svg+xml")):!1}async function te(t){var e,n;try{let r="",o="image/svg+xml";if(t.startsWith("data:image/svg+xml"))if(t.includes(";base64,")){const s=t.match(/data:image\/svg\+xml;base64,(.+)/);if(s&&s[1])try{r=atob(s[1])}catch{return null}}else{const s=t.match(/data:image\/svg\+xml,(.+)/);s&&s[1]&&(r=decodeURIComponent(s[1]))}else try{const s=new URL(t,document.baseURI).href,c=typeof chrome<"u"&&((e=chrome==null?void 0:chrome.runtime)==null?void 0:e.sendMessage)?await chrome.runtime.sendMessage({type:"getResourceContent",src:s}):null;if((n=c==null?void 0:c.data)!=null&&n.content){if(r=c.data.content,c.data.base64Encoded)try{r=atob(r)}catch{return null}o=c.data.mimeType||"image/svg+xml"}else{const d=await fetch(s,{method:"GET",mode:"cors"});if(!d.ok)throw new Error(`Failed to load SVG: ${d.statusText}`);r=await d.text()}}catch{const l=new URL(t,document.baseURI).href,c=await fetch(l,{method:"GET",mode:"cors"});if(!c.ok)throw new Error(`Failed to load SVG: ${c.statusText}`);r=await c.text()}if(!r)throw new Error("无法获取 SVG 内容");r=r.replace(/\\"/g,'"').replace(/\\\\/g,"");const a=btoa(unescape(encodeURIComponent(r)));return await L(a,o)}catch(r){return console.error("❌ [convertSvgToPng] SVG 转 PNG 失败:",r),t}}async function H(t,e="FILL",n=null){let r=t;const o=(t||"").toLowerCase();if(t!=null&&t.startsWith("data:image/webp")){const a=t.split(";base64,")[1];if(a)try{r=await L(a,"image/webp")}catch{}}else if(/\.(webp)(\?|#|$)/i.test(o))try{const a=await C(t);a&&(r=a)}catch{}if(Zt(r))return{type:"IMAGE",url:await te(r),scaleMode:e,imageHash:n};if(typeof r=="string"&&r&&!r.startsWith("data:"))try{const a=await C(r);a&&(r=a)}catch{}return{type:"IMAGE",url:r,scaleMode:e,imageHash:n}}export{ae as a,ie as b,se as c,re as d,le as e,ne as f,j as g,ce as h,Ot as n,oe as p};