@hazem3500/palette 0.9.132 → 0.9.133

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.
@@ -1 +0,0 @@
1
- var e="data-palette-no-snapshot",t=`[${e}],[data-komo-no-snapshot]`,a=e=>e.matches(t),n="[data-branch-comments],[data-palette-move-clone],[data-palette-viewport],[data-palette-snapshot-sandbox]",r="[redacted]",i=new Set(["script","noscript","template","style","link","meta","base","title"]),o=/^(?:href|src|action|formaction|xlink:href|poster|data|background)$/i,l=e=>"textarea"===e.localName||"input"===e.localName&&!/^(?:button|submit|reset|image|checkbox|radio|range|color)$/i.test(e.getAttribute("type")??""),s=2e4,h=200,c=500,d=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e,u=e=>(new TextEncoder).encode(e).length,m=e=>!!e.closest(`${t},${n}`);function f(e,t=1/0){for(let{name:a,value:n}of[...e.attributes])/^on/i.test(a)||"srcdoc"===a||/^data-(palette|komo)-/.test(a)&&!/-no-snapshot$/.test(a)||o.test(a)&&/^\s*(?:javascript|vbscript):/i.test(n)?e.removeAttribute(a):n.length>t&&e.setAttribute(a,d(n,t))}function g(e,t,o=s){let h=e.ownerDocument,c=o,m=e=>{if(3===e.nodeType){let t=d(e.nodeValue??"",500);return c-=t.length,h.createTextNode(t)}if(1!==e.nodeType)return null;let o=e;if(i.has(o.localName)||o.matches(n))return null;let s=o.cloneNode(!1);if(f(s,200),l(o)&&function(e,t){let a=e.value??e.getAttribute("value")??"";"textarea"===e.localName?t.textContent=a?r:"":(a||t.hasAttribute("value"))&&t.setAttribute("value",r)}(o,s),c-=s.outerHTML.length,a(o))return s;if(t?.(o))return l(o)||(s.textContent=r),s;if("textarea"===o.localName)return s;for(let e of o.childNodes){if(c<=0){s.append(h.createComment(" trimmed "));break}let t=m(e);t&&s.append(t)}return s},g=m(e);if(!g)return"";let p=g.outerHTML;if(u(p)<=o)return p;let w=h.createComment(" trimmed ");g.append(w);for(let e=u(g.outerHTML)-o;e>0&&g.firstChild!==w;e=u(g.outerHTML)-o)for(;e>0&&g.firstChild!==w;){let t=w.previousSibling;for(;t.lastChild;)t=t.lastChild;e-=1===t.nodeType?t.outerHTML.length:(t.nodeValue?.length??0)+7,t.parentNode.removeChild(t)}return p=g.outerHTML,u(p)>o?"":p}var p=class extends Error{constructor(e){super(e),this.reason=e}reason},w=25e4,y=1200,b=16,x=e=>new Promise((t,a)=>{let n=new FileReader;n.onload=()=>t(n.result),n.onerror=()=>a(n.error),n.readAsDataURL(e)});async function v(e,t){if(e.startsWith("data:"))return e;let a=new URL(e,t.document.baseURI);try{let e=await fetch(a,{mode:"cors",signal:AbortSignal.timeout(5e3)});return e.ok?await x(await e.blob()):""}catch{if(a.origin!==t.location.origin)throw new p("cross-origin");return""}}var $=["top","right","bottom","left","block-start","block-end","inline-start","inline-end"],M=(e,t)=>"none"===e||"hidden"===e||"0px"===t;function C(e,t=t=>e.get(t),a){for(let n of $){let r=`border-${n}-style`,i=`border-${n}-width`;M(t(r),t(i))&&(e.delete(r),e.delete(i),e.delete(`border-${n}-color`),a?.has(r)&&!M(a.get(r),a.get(i))&&e.set(r,"none"))}if(M(t("outline-style"),t("outline-width"))){for(let t of[...e.keys()])t.startsWith("outline")&&e.delete(t);a?.has("outline-style")&&!M(a.get("outline-style"),a.get("outline-width"))&&e.set("outline-style","none")}}function A(e,t,a){let n=new Map;for(let r=0;r<e.length;r++){let i=e[r];if(i.startsWith("--"))continue;let o=e.getPropertyValue(i);(o!==t.get(i)||a&&o!==a.getPropertyValue(i))&&n.set(i,o)}C(n,t=>e.getPropertyValue(t),t);let r="";for(let[e,t]of n)r+=`${e}:${t};`;return r}var k=/url\((['"]?)(.*?)\1\)/g;async function P(e,t,o){let s=e.ownerDocument,h=s.defaultView,c=e.getBoundingClientRect(),d=e.offsetWidth??c.width,u=e.offsetHeight??c.height,m=Math.min(u,2e3);if(!d||!m)throw new p("failed");let g={width:d+32,height:m+32},w=o?{x:b+o.x*d,y:b+o.y*u,width:o.width*d,height:Math.min(o.height*u,m-o.y*u)}:{x:0,y:0,...g};if(w.width<=0||w.height<=0)throw new p("too-large");let x=o?Math.min(3,y/w.width,2e3/w.height):1,$={width:Math.max(1,Math.round(w.width*x)),height:Math.max(1,Math.round(w.height*x))},M=o?x:Math.min(h.devicePixelRatio||1,2,y/g.width),C=function(){let e=document.createElement("iframe");e.setAttribute("data-palette-snapshot-sandbox",""),e.setAttribute("aria-hidden","true"),e.tabIndex=-1,e.style.cssText="position:fixed;left:-10px;top:0;width:1px;height:1px;border:0;opacity:0;pointer-events:none",document.documentElement.append(e);let t=e.contentDocument;try{t.open(),t.write("<!doctype html><html><head></head><body></body></html>"),t.close()}catch{}let a=new Map;return{of(e){let n=`${e.namespaceURI} ${e.localName}`,r=a.get(n);if(!r){let i=t.createElementNS(e.namespaceURI,e.localName);(t.body??t.documentElement).append(i);let o=t.defaultView.getComputedStyle(i);r=new Map;for(let e=0;e<o.length;e++)r.set(o[e],o.getPropertyValue(o[e]));i.remove(),a.set(n,r)}return r},dispose:()=>e.remove()}}(),P=[],E=new Set,N=new Map,T=[],R="",W=0,I=e=>(e.catch(()=>{}),e),L=e=>{for(let[,,t]of e.matchAll(k))t&&!t.startsWith("data:")&&!N.has(t)&&N.set(t,I(v(t,h)));return e},S=(e,o)=>{if(3===e.nodeType)return s.createTextNode(e.nodeValue??"");if(1!==e.nodeType)return null;let c=e,u=c.localName;if(i.has(u)||c.matches(n))return null;if(++W>3e3)throw new p("too-large");let g,w=h.getComputedStyle(c);if("none"===w.display)return null;if("canvas"===u||"video"===u){g=s.createElement("img");let e=document.createElement("canvas");e.width=c.width||c.videoWidth||1,e.height=c.height||c.videoHeight||1;try{e.getContext("2d").drawImage(c,0,0,e.width,e.height),g.setAttribute("src",e.toDataURL("image/png"))}catch{throw new p("cross-origin")}}else if("iframe"===u||"embed"===u||"object"===u)g=s.createElement("div");else{g=c.cloneNode(!1),f(g);for(let e of["id","class","srcset","sizes","loading","style"])g.removeAttribute(e)}l(c)&&(g.removeAttribute("value"),g.hasAttribute("placeholder")&&t?.(c)&&g.setAttribute("placeholder",r)),"img"===u&&P.push(I(async function(e,t,a){let n=e.currentSrc||e.src;if(!n||n.startsWith("data:"))return n;await e.decode().catch(()=>{});let r=Math.min(e.naturalWidth,Math.ceil(e.offsetWidth*t)||e.naturalWidth),i=Math.round(r*e.naturalHeight/(e.naturalWidth||1));if(r&&i){let t=document.createElement("canvas");t.width=r,t.height=i;try{return t.getContext("2d").drawImage(e,0,0,r,i),t.toDataURL("image/png")}catch{}}return v(n,a)}(c,M,h).then(e=>g.setAttribute("src",e)))),E.add(w.fontFamily.split(",")[0].replace(/["']/g,"").trim().toLowerCase());let y=A(w,C.of(c),o);o||(y+=`${"inline"===w.display?"display:inline-block;":""}margin:0;position:relative;inset:auto;float:none;transform:none;translate:none;rotate:none;scale:none;flex:none;box-sizing:border-box;width:${d}px;height:${m}px;max-width:none;max-height:none;min-width:0;min-height:0;`);let b=a(c)&&!!o;b&&(y+="color:transparent;background:#e5e5e5;background-image:none;"),T.push([g,L(y)]);for(let e of["::before","::after"]){let t=h.getComputedStyle(c,e);b||/^(?:none|normal)$/.test(t.content)||(g.setAttribute("data-snapshot",String(W)),R+=`[data-snapshot="${W}"]${e}{${L(A(t,C.of(c),w))}content:${t.content};}`)}if(b)return g;if(t?.(c))return l(c)||(g.textContent=r),g;if("textarea"===u)return g;for(let e of c.childNodes){if("picture"===u&&"img"!==e.localName)continue;let t=S(e,w);t&&g.append(t)}return g};try{await(s.fonts?.ready);let t=S(e),a=new Map(await Promise.all([...N].map(async([e,t])=>[e,await t]))),n=e=>e.replace(k,(e,t,n)=>a.has(n)?`url("${a.get(n)}")`:e);for(let[e,t]of T)e.setAttribute("style",n(t));R=n(R),await Promise.all(P);let r=s.createElement("div");r.setAttribute("style",`width:${d+32}px;height:${m+32}px;padding:16px;box-sizing:border-box;overflow:hidden;background:${function(e,t){for(let a=e.parentElement;a;a=a.parentElement){let e=t.getComputedStyle(a).backgroundColor;if(e&&!/^(?:transparent|rgba\(.*,\s*0\))$/.test(e))return e}return"#fff"}(e,h)}`);let i=s.createElement("style");i.textContent=await async function(e,t,a){let n=[],r=2e6,i=async(e,o)=>{for(let l of e){if(l.cssRules&&await i(l.cssRules,o),!l.cssText.startsWith("@font-face"))continue;let e=l.style,s=e.getPropertyValue("font-family").replace(/["']/g,"").trim().toLowerCase(),h=e.getPropertyValue("src").match(/url\((['"]?)(.*?)\1\)/)?.[2];if(!t.has(s)||!h||r<=0)continue;let c=await v(new URL(h,o).href,a).catch(()=>"");c&&(r-=c.length,n.push(`@font-face{font-family:"${s}";src:url("${c}");${["font-weight","font-style","font-stretch","unicode-range"].map(t=>e.getPropertyValue(t)?`${t}:${e.getPropertyValue(t)};`:"").join("")}}`))}};for(let t of e.styleSheets){let a;try{a=t.cssRules}catch{continue}await i(a,t.href??e.baseURI)}return n.join("")}(s,E,h)+R,r.append(i,t);let o=`<svg xmlns="http://www.w3.org/2000/svg" width="${$.width}" height="${$.height}" viewBox="${w.x} ${w.y} ${w.width} ${w.height}"><foreignObject x="0" y="0" width="${g.width}" height="${g.height}">${(new XMLSerializer).serializeToString(r)}</foreignObject></svg>`,l=new Image;return l.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(o)}`,await l.decode(),{image:l,...$}}finally{C.dispose()}}var E=(e,t)=>new Promise((a,n)=>{try{e.toBlob(a,"image/webp",t)}catch(e){n(e)}});async function N(e,t,a,n=1){let r=Math.min(n,2,y/t.width),i=document.createElement("canvas"),o=.8;for(let n=0;n<12;n++){i.width=Math.max(1,Math.round(t.width*r)),i.height=Math.max(1,Math.round(t.height*r));let n,l=i.getContext("2d");if(!l)throw new p("unsupported");l.drawImage(e,t.x,t.y,t.width,t.height,0,0,i.width,i.height);try{n=await E(i,o)}catch{throw new p("cross-origin")}if(!n||"image/webp"!==n.type)throw new p("unsupported");if(n.size<=a)return x(n);o>.5?o=Math.round(100*(o-.15))/100:r*=Math.min(.85,Math.max(.3,.95*Math.sqrt(a/n.size)))}throw new p("too-large")}async function T(e,t={},a){let n=a?1:e.ownerDocument.defaultView?.devicePixelRatio||1,{image:r,width:i,height:o}=await P(e,t.redact,a);return N(r,{x:0,y:0,width:i,height:o},t.maxBytes??w,n)}async function R(e,t){if(!["image/png","image/jpeg","image/webp"].includes(e.type)||e.size>20971520)throw new Error("Choose a PNG, JPEG or WebP image under 20 MB.");let a=await createImageBitmap(e);try{if(a.width*a.height>4e7)throw new Error("Choose an image with fewer than 40 megapixels.");return{image:await N(a,{x:0,y:0,width:a.width,height:a.height},t)}}finally{a.close()}}var W={"cross-origin":"cross-origin images","too-large":"the element is too large to draw",unsupported:"this browser can't encode WebP",failed:"it couldn't be drawn"},I=e=>`\x3c!-- palette: no image snapshot, ${W[e]}. --\x3e`;async function L(e,t,a=s,n){if(!e?.isConnected||m(e))return null;let r={},i=()=>g(e,t.redact,a-120);if(t.html&&(r.html=i()),t.image){await new Promise(e=>"function"==typeof requestIdleCallback?requestIdleCallback(e,{timeout:500}):setTimeout(e));try{r.image=await T(e,t,n)}catch(e){r.note=e instanceof p?e.reason:"failed","cross-origin"===r.note&&(r.html??=i()),r.html&&(r.html=I(r.note)+r.html)}}return r}var S=e=>{let[t,a]=e.split(","),n=Uint8Array.from(atob(a),e=>e.charCodeAt(0));return new Blob([n],{type:t.slice(5,-7)})},V=new WeakMap;function B(e,t,a,n,r,i,o){let l=o??V.get(e);if(!l){let r={...a,maxBytes:Math.min(a.maxBytes??w,n.maxImageBytes||1/0)};l=a.image||a.html?L(t(e),r,Math.min(s,n.maxHtmlBytes||1/0),i).catch(()=>({note:"failed"})):Promise.resolve(null),V.set(e,l)}return r&&l.then(async e=>{let t="failed"===e?.note;for(let a of["image","html"]){let n=e?.[a];n&&await r(a,"image"===a?S(n):new Blob([n],{type:"text/html;charset=utf-8"})).catch(()=>t=!0)}if(n.readiness&&(t||!e?.image&&!e?.html))return r("status",new Blob([`{"status":"${t?"failed":"skipped"}"}`],{type:"application/json"})).catch(()=>{})}),l}export{e as a,r as b,s as c,h as d,c as e,m as f,g,w as h,C as i,N as j,T as k,R as l,I as m,L as n,B as o};