openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 3.35 kB
JavaScript
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{Gi as t,Ui as n}from"./ui-CmSP4d14.js";function r(e){if(!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?(?:px)?$/iu.test(e.trim()))return null;let t=Number.parseFloat(e);return Number.isFinite(t)?t:null}function i(e){if(e.namespaceURI&&e.name!==`xmlns`)return!1;let t=e.value.trim();return e.name===`xmlns`?t===h:b.get(e.name)?.test(t)??!1}async function a(e){let n=new Image;return n.decoding=`async`,await t(()=>new Promise((t,r)=>{n.addEventListener(`load`,()=>t(),{once:!0}),n.addEventListener(`error`,()=>r(Error(`plugin SVG decode failed`)),{once:!0}),n.src=e}),u,()=>{throw n.src=``,Error(`plugin SVG decode timed out`)}),n}function o(e){let t=e.getAttribute(`viewBox`),n,i;if(t){let e=t.trim().split(/[\s,]+/u).map(e=>Number(e));if(e.length!==4||e.some(e=>!Number.isFinite(e)))return null;n=e[2],i=e[3]}else n=r(e.getAttribute(`width`)??``),i=r(e.getAttribute(`height`)??``);return!n||!i||n<=0||i<=0||n>m||i>m?null:{width:n,height:i}}async function s(e){let t=await e.text();if(/<!doctype|<!entity/iu.test(t))return null;let n=new DOMParser().parseFromString(t,`image/svg+xml`);if(n.querySelector(`parsererror`))return null;let r=n.documentElement;if(r.namespaceURI!==h||r.localName!==`svg`)return null;let a=[r,...Array.from(r.querySelectorAll(`*`))];if(a.length>d)return null;let s=0;for(let e of a){if(e.namespaceURI!==h||!g.has(e.localName.toLowerCase()))return null;for(let t of Array.from(e.attributes)){if(!i(t))return null;(t.name===`d`||t.name===`points`)&&(s+=t.value.length)}}if(s>f||a.reduce((e,t)=>e+(t.getAttribute(`d`)?.match(/[a-z]/giu)?.length??0),0)>p)return null;let c=o(r);return c?{blob:new Blob([new XMLSerializer().serializeToString(r)],{type:`image/svg+xml`}),...c}:null}async function c(e){let t=await s(e);if(!t)return null;let n=Math.min(l/t.width,l/t.height),r=Math.max(1,Math.round(t.width*n)),i=Math.max(1,Math.round(t.height*n)),o=URL.createObjectURL(t.blob);try{let e=await a(o),t=document.createElement(`canvas`);t.width=l,t.height=l;let n=t.getContext(`2d`);return n?(n.drawImage(e,Math.round((l-r)/2),Math.round((l-i)/2),r,i),await new Promise(e=>{t.toBlob(e,`image/png`)})):null}finally{URL.revokeObjectURL(o)}}var l,u,d,f,p,m,h,g,_,v,y,b;function x(){return(x=e((()=>{n(),l=256,u=5e3,d=4,f=8192,p=1024,m=4096,h=`http://www.w3.org/2000/svg`,g=new Set([`circle`,`desc`,`ellipse`,`g`,`line`,`path`,`polygon`,`polyline`,`rect`,`svg`,`title`]),_=/^(?:none|currentColor|#[0-9a-f]{3,8})$/iu,v=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/iu,y=/^[0-9eE+.,\s-]+$/u,b=new Map([[`d`,/^[0-9a-zA-Z+.,\s-]+$/u],[`points`,y],[`viewBox`,y],[`fill`,_],[`stroke`,_],[`clip-rule`,/^(?:evenodd|nonzero)$/u],[`fill-rule`,/^(?:evenodd|nonzero)$/u],[`stroke-linecap`,/^(?:butt|round|square)$/u],[`stroke-linejoin`,/^(?:bevel|miter|round)$/u],[`transform`,/^(?:\s*(?:matrix|rotate|scale|skewX|skewY|translate)\(\s*[0-9eE+.,\s-]+\)\s*)+$/u],[`cx`,v],[`cy`,v],[`height`,v],[`opacity`,v],[`r`,v],[`rx`,v],[`ry`,v],[`stroke-miterlimit`,v],[`stroke-width`,v],[`width`,v],[`x`,v],[`x1`,v],[`x2`,v],[`y`,v],[`y1`,v],[`y2`,v],[`preserveAspectRatio`,/^(?:none|x(?:Min|Mid|Max)Y(?:Min|Mid|Max)(?:\s+(?:meet|slice))?)$/u],[`aria-hidden`,/^(?:false|true)$/u],[`focusable`,/^(?:false|true)$/u],[`role`,/^img$/u],[`aria-label`,/^[^<>&]{0,256}$/u]])})))()}x();export{c as rasterizeSvg};