@hazem3500/palette 0.9.116 → 0.9.118
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/NODE.md +1 -1
- package/README.md +1 -1
- package/dist/{chunk-ZGJYCFAB.js → chunk-3DH4SW3Z.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/node.mjs +3 -3
- package/dist/react.js +1 -1
- package/dist/server.js +3 -3
- package/dist/setup.js +1 -1
- package/dist/snapshot-H5JZR3ES.js +1 -0
- package/dist/snapshot.d.ts +7 -0
- package/package.json +1 -1
- package/server/setup-client.txt +42 -42
- package/server/tokens.ts +2 -2
- package/dist/snapshot-YYM5GW6I.js +0 -1
package/dist/setup.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as n,d as o}from"./chunk-
|
|
1
|
+
import{a as n,d as o}from"./chunk-3DH4SW3Z.js";import"./chunk-KLPQTFVH.js";import"./chunk-RBHY7UDS.js";import"./chunk-LMXFSXO6.js";import"./chunk-DU7H4TEX.js";import"./chunk-5HZI7HRR.js";import"./chunk-2BS2OWWH.js";import"./chunk-J47R52WX.js";import"./chunk-VX6XCU4E.js";import"./chunk-4HBBEVFK.js";function r(r){return(t={})=>o(n({...r,...t}))}var t=r;export{t as defineKomo,r as definePalette};
|
|
@@ -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]",o=new Set(["script","noscript","template","style","link","meta","base","title"]),i=/^(?: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,c=200,d=500,h=(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)||i.test(a)&&/^\s*(?:javascript|vbscript):/i.test(n)?e.removeAttribute(a):n.length>t&&e.setAttribute(a,h(n,t))}function p(e,t,i=s){let c=e.ownerDocument,d=i,m=e=>{if(3===e.nodeType){let t=h(e.nodeValue??"",500);return d-=t.length,c.createTextNode(t)}if(1!==e.nodeType)return null;let i=e;if(o.has(i.localName)||i.matches(n))return null;let s=i.cloneNode(!1);if(f(s,200),l(i)&&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)}(i,s),d-=s.outerHTML.length,a(i))return s;if(t?.(i))return l(i)||(s.textContent=r),s;if("textarea"===i.localName)return s;for(let e of i.childNodes){if(d<=0){s.append(c.createComment(" trimmed "));break}let t=m(e);t&&s.append(t)}return s},p=m(e);if(!p)return"";let g=p.outerHTML;if(u(g)<=i)return g;let w=c.createComment(" trimmed ");p.append(w);for(let e=u(p.outerHTML)-i;e>0&&p.firstChild!==w;e=u(p.outerHTML)-i)for(;e>0&&p.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 g=p.outerHTML,u(g)>i?"":g}var g=class extends Error{constructor(e){super(e),this.reason=e}reason},w=25e4,b=e=>new Promise((t,a)=>{let n=new FileReader;n.onload=()=>t(n.result),n.onerror=()=>a(n.error),n.readAsDataURL(e)});async function y(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 b(await e.blob()):""}catch{if(a.origin!==t.location.origin)throw new g("cross-origin");return""}}var x=["top","right","bottom","left","block-start","block-end","inline-start","inline-end"];function v(e){for(let t of x){let a=e.get(`border-${t}-style`),n=e.get(`border-${t}-width`);("none"===a||"hidden"===a||"0px"===n)&&(e.delete(`border-${t}-style`),e.delete(`border-${t}-width`),e.delete(`border-${t}-color`))}let t=e.get("outline-style"),a=e.get("outline-width");if("none"===t||"hidden"===t||"0px"===a)for(let t of[...e.keys()])t.startsWith("outline")&&e.delete(t)}function $(e,t,a){let n=new Map;for(let r=0;r<e.length;r++){let o=e[r];if(o.startsWith("--"))continue;let i=e.getPropertyValue(o);(i!==t.get(o)||a&&i!==a.getPropertyValue(o))&&n.set(o,i)}v(n);let r="";for(let[e,t]of n)r+=`${e}:${t};`;return r}var M=/url\((['"]?)(.*?)\1\)/g;async function C(e,t,i){let s=e.ownerDocument,c=s.defaultView,d=e.getBoundingClientRect(),h=e.offsetWidth??d.width,u=Math.min(e.offsetHeight??d.height,2e3);if(!h||!u)throw new g("failed");let m=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 o=t.createElementNS(e.namespaceURI,e.localName);(t.body??t.documentElement).append(o);let i=t.defaultView.getComputedStyle(o);r=new Map;for(let e=0;e<i.length;e++)r.set(i[e],i.getPropertyValue(i[e]));o.remove(),a.set(n,r)}return r},dispose:()=>e.remove()}}(),p=[],w=new Set,b=new Map,x=[],v="",C=0,T=e=>(e.catch(()=>{}),e),A=e=>{for(let[,,t]of e.matchAll(M))t&&!t.startsWith("data:")&&!b.has(t)&&b.set(t,T(y(t,c)));return e},I=(e,d)=>{if(3===e.nodeType)return s.createTextNode(e.nodeValue??"");if(1!==e.nodeType)return null;let b=e,M=b.localName;if(o.has(M)||b.matches(n))return null;if(++C>3e3)throw new g("too-large");let k,E=c.getComputedStyle(b);if("none"===E.display)return null;if("canvas"===M||"video"===M){k=s.createElement("img");let e=document.createElement("canvas");e.width=b.width||b.videoWidth||1,e.height=b.height||b.videoHeight||1;try{e.getContext("2d").drawImage(b,0,0,e.width,e.height),k.setAttribute("src",e.toDataURL("image/png"))}catch{throw new g("cross-origin")}}else if("iframe"===M||"embed"===M||"object"===M)k=s.createElement("div");else{k=b.cloneNode(!1),f(k);for(let e of["id","class","srcset","sizes","loading","style"])k.removeAttribute(e)}l(b)&&(k.removeAttribute("value"),k.hasAttribute("placeholder")&&t?.(b)&&k.setAttribute("placeholder",r)),"img"===M&&p.push(T(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),o=Math.round(r*e.naturalHeight/(e.naturalWidth||1));if(r&&o){let t=document.createElement("canvas");t.width=r,t.height=o;try{return t.getContext("2d").drawImage(e,0,0,r,o),t.toDataURL("image/png")}catch{}}return y(n,a)}(b,i,c).then(e=>k.setAttribute("src",e)))),w.add(E.fontFamily.split(",")[0].replace(/["']/g,"").trim().toLowerCase());let L=$(E,m.of(b),d);d||(L+=`${"inline"===E.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:${h}px;height:${u}px;max-width:none;max-height:none;min-width:0;min-height:0;`);let R=a(b)&&!!d;R&&(L+="color:transparent;background:#e5e5e5;background-image:none;"),x.push([k,A(L)]);for(let e of["::before","::after"]){let t=c.getComputedStyle(b,e);R||/^(?:none|normal)$/.test(t.content)||(k.setAttribute("data-snapshot",String(C)),v+=`[data-snapshot="${C}"]${e}{${A($(t,m.of(b),E))}content:${t.content};}`)}if(R)return k;if(t?.(b))return l(b)||(k.textContent=r),k;if("textarea"===M)return k;for(let e of b.childNodes){if("picture"===M&&"img"!==e.localName)continue;let t=I(e,E);t&&k.append(t)}return k};try{await(s.fonts?.ready);let t=I(e),a=new Map(await Promise.all([...b].map(async([e,t])=>[e,await t]))),n=e=>e.replace(M,(e,t,n)=>a.has(n)?`url("${a.get(n)}")`:e);for(let[e,t]of x)e.setAttribute("style",n(t));v=n(v),await Promise.all(p);let r=s.createElement("div");r.setAttribute("style",`width:${h+32}px;height:${u+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 o=s.createElement("style");o.textContent=await async function(e,t,a){let n=[],r=2e6,o=async(e,i)=>{for(let l of e){if(l.cssRules&&await o(l.cssRules,i),!l.cssText.startsWith("@font-face"))continue;let e=l.style,s=e.getPropertyValue("font-family").replace(/["']/g,"").trim().toLowerCase(),c=e.getPropertyValue("src").match(/url\((['"]?)(.*?)\1\)/)?.[2];if(!t.has(s)||!c||r<=0)continue;let d=await y(new URL(c,i).href,a).catch(()=>"");d&&(r-=d.length,n.push(`@font-face{font-family:"${s}";src:url("${d}");${["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 o(a,t.href??e.baseURI)}return n.join("")}(s,w,c)+v,r.append(o,t);let i={width:h+32,height:u+32},l=`<svg xmlns="http://www.w3.org/2000/svg" width="${i.width}" height="${i.height}"><foreignObject x="0" y="0" width="100%" height="100%">${(new XMLSerializer).serializeToString(r)}</foreignObject></svg>`,d=new Image;return d.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(l)}`,await d.decode(),{image:d,...i}}finally{m.dispose()}}var T=(e,t)=>new Promise((a,n)=>{try{e.toBlob(a,"image/webp",t)}catch(e){n(e)}});async function A(e,t={}){let a=t.maxBytes??w,n=e.ownerDocument.defaultView??window,r=e.offsetWidth||e.getBoundingClientRect().width,o=Math.min(n.devicePixelRatio||1,2,1200/(r+32)),i=await C(e,t.redact,o),l=document.createElement("canvas"),s=.8;for(let e=0;e<12&&i.width*o>=48;e++){l.width=Math.max(1,Math.round(i.width*o)),l.height=Math.max(1,Math.round(i.height*o));let e,t=l.getContext("2d");if(!t)throw new g("unsupported");t.drawImage(i.image,0,0,l.width,l.height);try{e=await T(l,s)}catch{throw new g("cross-origin")}if(!e||"image/webp"!==e.type)throw new g("unsupported");if(e.size<=a)return b(e);s>.5?s=Math.round(100*(s-.15))/100:o*=Math.min(.85,Math.max(.3,.95*Math.sqrt(a/e.size)))}throw new g("too-large")}var I={"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"},k=e=>`\x3c!-- palette: no image snapshot, ${I[e]}. --\x3e`;async function E(e,t,a=s){if(!e?.isConnected||m(e))return null;let n={},r=()=>p(e,t.redact,a-120);if(t.html&&(n.html=r()),t.image){await new Promise(e=>"function"==typeof requestIdleCallback?requestIdleCallback(e,{timeout:500}):setTimeout(e));try{n.image=await A(e,t)}catch(e){n.note=e instanceof g?e.reason:"failed","cross-origin"===n.note&&(n.html??=r()),n.html&&(n.html=k(n.note)+n.html)}}return n}var L=e=>{let[t,a]=e.split(","),n=Uint8Array.from(atob(a),e=>e.charCodeAt(0));return new Blob([n],{type:t.slice(5,-7)})},R=new WeakMap;function N(e,t,a,n,r){let o=R.get(e);if(!o){let r={...a,maxBytes:Math.min(a.maxBytes??w,n.maxImageBytes||1/0)};o=a.image||a.html?E(t(e),r,Math.min(s,n.maxHtmlBytes||1/0)).catch(()=>({note:"failed"})):Promise.resolve(null),R.set(e,o)}return r&&o.then(async e=>{let t="failed"===e?.note;for(let a of["image","html"]){let n=e?.[a];n&&await r(a,"image"===a?L(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(()=>{})}),o}export{c as ATTRIBUTE_LIMIT,s as HTML_LIMIT,w as IMAGE_BYTES,e as OPT_OUT,r as PLACEHOLDER,d as TEXT_LIMIT,E as captureSnapshot,k as noteComment,v as omitInvisibleFrameStyles,m as skipped,N as snapshotFor,p as snapshotHtml,A as snapshotImage};
|
package/dist/snapshot.d.ts
CHANGED
|
@@ -24,6 +24,13 @@ export declare const skipped: (element: Element) => boolean;
|
|
|
24
24
|
*/
|
|
25
25
|
export declare function snapshotHtml(element: Element, redact?: (element: Element) => boolean, limit?: number): string;
|
|
26
26
|
export declare const IMAGE_BYTES = 250000;
|
|
27
|
+
/**
|
|
28
|
+
* Drop border and outline longhands that do not paint. Tailwind's preflight (and similar
|
|
29
|
+
* resets) set `border-style: solid` with `border-width: 0`, which differs from a bare tag's
|
|
30
|
+
* `none` baseline. Serialising those into an SVG foreignObject makes engines draw faint gray
|
|
31
|
+
* boxes that are not on the page.
|
|
32
|
+
*/
|
|
33
|
+
export declare function omitInvisibleFrameStyles(styles: Map<string, string>): void;
|
|
27
34
|
/** The element plus padding as WebP, at most 1200px wide and `maxBytes` in size. */
|
|
28
35
|
export declare function snapshotImage(element: Element, options?: PaletteSnapshots): Promise<string>;
|
|
29
36
|
/** The server's snapshot support, from `/config`. */
|