@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.
@@ -0,0 +1 @@
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,s=!1){let h=e.ownerDocument,c=h.defaultView,d=e.getBoundingClientRect(),u=e.offsetWidth??d.width,m=e.offsetHeight??d.height,g=Math.min(m,2e3);if(!u||!g)throw new p("failed");let w={width:u+32,height:g+32},x=o?{x:b+o.x*u,y:b+o.y*m,width:o.width*u,height:Math.min(o.height*m,g-o.y*m)}:{x:0,y:0,...w};if(x.width<=0||x.height<=0)throw new p("too-large");let $=o?Math.min(3,y/x.width,2e3/x.height):1,M={width:Math.max(1,Math.round(x.width*$)),height:Math.max(1,Math.round(x.height*$))},C=o?$:Math.min(c.devicePixelRatio||1,2,y/w.width),P=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()}}(),E=[],N=new Set,T=new Map,R=[],W="",I=0,L=e=>(e.catch(()=>{}),e),S=e=>{for(let[,,t]of e.matchAll(k))t&&!t.startsWith("data:")&&!T.has(t)&&T.set(t,L(v(t,c)));return e},V=(e,o)=>{if(3===e.nodeType)return h.createTextNode(e.nodeValue??"");if(1!==e.nodeType)return null;let s=e,d=s.localName;if(i.has(d)||s.matches(n))return null;if(++I>3e3)throw new p("too-large");let m,w=c.getComputedStyle(s);if("none"===w.display)return null;if("canvas"===d||"video"===d){m=h.createElement("img");let e=document.createElement("canvas");e.width=s.width||s.videoWidth||1,e.height=s.height||s.videoHeight||1;try{e.getContext("2d").drawImage(s,0,0,e.width,e.height),m.setAttribute("src",e.toDataURL("image/png"))}catch{throw new p("cross-origin")}}else if("iframe"===d||"embed"===d||"object"===d)m=h.createElement("div");else{m=s.cloneNode(!1),f(m);for(let e of["id","class","srcset","sizes","loading","style","popover"])m.removeAttribute(e)}l(s)&&(m.removeAttribute("value"),m.hasAttribute("placeholder")&&t?.(s)&&m.setAttribute("placeholder",r)),"img"===d&&E.push(L(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)}(s,C,c).then(e=>m.setAttribute("src",e)))),N.add(w.fontFamily.split(",")[0].replace(/["']/g,"").trim().toLowerCase());let y=A(w,P.of(s),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:${u}px;height:${g}px;max-width:none;max-height:none;min-width:0;min-height:0;`);let b=a(s)&&!!o;b&&(y+="color:transparent;background:#e5e5e5;background-image:none;"),R.push([m,S(y)]);for(let e of["::before","::after"]){let t=c.getComputedStyle(s,e);b||/^(?:none|normal)$/.test(t.content)||(m.setAttribute("data-snapshot",String(I)),W+=`[data-snapshot="${I}"]${e}{${S(A(t,P.of(s),w))}content:${t.content};}`)}if(b)return m;if(t?.(s))return l(s)||(m.textContent=r),m;if("textarea"===d)return m;for(let e of s.childNodes){if("picture"===d&&"img"!==e.localName)continue;let t=V(e,w);t&&m.append(t)}return m};try{s||await(h.fonts?.ready);let t=V(e),a=new Map(await Promise.all([...T].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 R)e.setAttribute("style",n(t));W=n(W),await Promise.all(E);let r=h.createElement("div");r.setAttribute("style",`width:${u+32}px;height:${g+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,c)}`);let i=h.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("")}(h,N,c)+W,r.append(i,t);let o=`<svg xmlns="http://www.w3.org/2000/svg" width="${M.width}" height="${M.height}" viewBox="${x.x} ${x.y} ${x.width} ${x.height}"><foreignObject x="0" y="0" width="${w.width}" height="${w.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,...M}}finally{P.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,n=!1){let r=a?1:e.ownerDocument.defaultView?.devicePixelRatio||1,{image:i,width:o,height:l}=await P(e,t.redact,a,n);return N(i,{x:0,y:0,width:o,height:l},t.maxBytes??w,r)}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,r=!1){if(!e?.isConnected||m(e))return null;let i={},o=()=>g(e,t.redact,a-120);if(t.html&&(i.html=o()),t.image){r||await new Promise(e=>"function"==typeof requestIdleCallback?requestIdleCallback(e,{timeout:500}):setTimeout(e));try{i.image=await T(e,t,n,r)}catch(e){i.note=e instanceof p?e.reason:"failed","cross-origin"===i.note&&(i.html??=o()),i.html&&(i.html=I(i.note)+i.html)}}return i}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,l=!1){let h=o??V.get(e);if(!h){let r={...a,maxBytes:Math.min(a.maxBytes??w,n.maxImageBytes||1/0)};h=a.image||a.html?L(t(e),r,Math.min(s,n.maxHtmlBytes||1/0),i,l).catch(()=>({note:"failed"})):Promise.resolve(null),V.set(e,h)}return r&&h.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(()=>{})}),h}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};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{b as s,c as t,d as i}from"./chunk-UVWLXKWZ.js";import"./chunk-KLPQTFVH.js";import"./chunk-HHUTDVTM.js";import"./chunk-RBHY7UDS.js";import"./chunk-LMXFSXO6.js";import"./chunk-5HZI7HRR.js";import"./chunk-2BS2OWWH.js";import"./chunk-J47R52WX.js";import"./chunk-VX6XCU4E.js";import"./chunk-4HBBEVFK.js";export{i as initComments,t as initKomo,s as initPalette};
1
+ import{b as s,c as t,d as i}from"./chunk-3SNXBRAS.js";import"./chunk-KLPQTFVH.js";import"./chunk-HHUTDVTM.js";import"./chunk-RBHY7UDS.js";import"./chunk-LMXFSXO6.js";import"./chunk-5HZI7HRR.js";import"./chunk-2BS2OWWH.js";import"./chunk-J47R52WX.js";import"./chunk-VX6XCU4E.js";import"./chunk-4HBBEVFK.js";export{i as initComments,t as initKomo,s as initPalette};