@hazem3500/palette 0.9.123 → 0.9.124

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/dist/setup.js CHANGED
@@ -1 +1 @@
1
- import{a as n,d as o}from"./chunk-FYQJTQFZ.js";import"./chunk-KLPQTFVH.js";import"./chunk-RBHY7UDS.js";import"./chunk-LMXFSXO6.js";import"./chunk-HHUTDVTM.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};
1
+ import{a as n,d as o}from"./chunk-RZUSE3F5.js";import"./chunk-KLPQTFVH.js";import"./chunk-RBHY7UDS.js";import"./chunk-LMXFSXO6.js";import"./chunk-HHUTDVTM.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
+ import{E as e,G as t}from"./chunk-4HBBEVFK.js";var n=new WeakMap;function a(t){let a=n.get(t);a?.isConnected||(a=e("style","",'.palette-snapshot{display:block;width:fit-content;margin-top:8px;padding:0;border:0;border-radius:6px;background:none;color:inherit;font:inherit;cursor:zoom-in;line-height:0}\n.palette-snapshot img{display:block;width:72px;height:48px;border-radius:6px;object-fit:contain;background:color-mix(in oklab,currentColor 8%,transparent);outline:1px solid color-mix(in oklab,currentColor 16%,transparent);outline-offset:-1px}\n.palette-snapshot:not([data-ready]){background:color-mix(in oklab,currentColor 8%,transparent)}\n.palette-snapshot:not([data-ready]) img{visibility:hidden}\n.palette-snapshot[hidden]{display:none}\n.palette-snapshot:focus-visible{outline:2px solid var(--accent,#bda6ef);outline-offset:2px}\n.palette-snapshot[data-large]{width:auto;max-width:100%}\n.palette-snapshot[data-large] img{width:auto;height:auto;min-width:72px;min-height:48px;max-width:100%;max-height:180px;object-fit:contain}\n.thread-item>.palette-snapshot{margin:6px 12px 0 calc(12px + var(--palette-avatar,20px) + var(--palette-gutter,8px))}\n.dialog:has(.thread-navigation:not([hidden]) .palette-snapshot-view) .message .palette-snapshot{display:none}\n.palette-snapshot-view{margin-top:8px}\n.palette-snapshot-view p{margin:0 0 6px}\n.palette-snapshot-code{box-sizing:border-box;max-height:160px;margin:0;padding:8px;overflow:auto;border-radius:6px;background:color-mix(in oklab,currentColor 8%,transparent);font:11px/1.45 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre-wrap;overflow-wrap:anywhere;scrollbar-width:thin}\n.palette-snapshot-code:focus-visible{outline:2px solid var(--accent,#bda6ef);outline-offset:2px}\n.palette-snapshot-text{justify-self:start;margin-top:8px;padding:4px 8px;border:0;border-radius:6px;background:color-mix(in oklab,currentColor 8%,transparent);color:inherit;font-family:inherit;font-size:11px;line-height:1.4;cursor:pointer}\n.palette-snapshot-draft{display:flex;align-items:center;gap:8px;margin-top:8px;font-size:12px;color:#999}\n.palette-snapshot-draft .palette-snapshot{margin:0}\n.palette-snapshot-draft span{flex:1;min-width:0}\n.palette-snapshot-draft .icon{width:28px;height:28px}\n.palette-snapshot-viewer{box-sizing:border-box;max-width:min(1200px,calc(100vw - 32px));max-height:calc(100dvh - 32px);margin:auto;padding:12px;overflow:hidden;border:0;border-radius:16px;background:#242424;color:#eee;box-shadow:inset 0 0 0 1px #ffffff1f,0 24px 64px -16px rgb(0 0 0/55%);font:12px/1.4 -apple-system,BlinkMacSystemFont,"Inter","Segoe UI",sans-serif;pointer-events:auto;color-scheme:dark}\n.palette-snapshot-viewer[open]{display:flex;flex-direction:column;gap:8px;animation:palette-snapshot-in var(--duration-fast,250ms) var(--ease-smooth-out,cubic-bezier(.22,1,.36,1))}\n.palette-snapshot-viewer::backdrop{background:rgb(0 0 0/40%);pointer-events:auto}\n.palette-snapshot-viewer header{display:flex;align-items:center;gap:8px}\n.palette-snapshot-viewer h2{flex:1;margin:0;padding-left:4px;font-size:13px;font-weight:600}\n.palette-snapshot-viewer .icon{width:28px;height:28px;border-radius:8px;color:#bbb}\n.palette-snapshot-viewer .icon:hover{background:#ffffff14;color:#eee}\n.palette-snapshot-viewer .icon:focus-visible{outline:2px solid var(--accent,#bda6ef);outline-offset:-2px}\n.palette-snapshot-viewer img{display:block;min-height:0;max-width:100%;max-height:calc(100dvh - 104px);margin:auto;border-radius:8px;object-fit:contain}\n.palette-snapshot-viewer .palette-snapshot-code{max-height:calc(100dvh - 104px);width:min(720px,calc(100vw - 56px))}\n@keyframes palette-snapshot-in{from{opacity:0;scale:.98;translate:0 4px}}\n@media (prefers-reduced-motion:reduce){.palette-snapshot-viewer[open]{animation:none}}\n@media (pointer:coarse){.palette-snapshot-viewer .icon,.palette-snapshot-draft .icon{width:44px;height:44px}}'),n.set(t,a),t.append(a))}var o=20,r=[],i=0,s=[],p=0;function l(){let e=performance.now();for(;s.length&&e-s[0]>=6e4;)s.shift();for(;r.length&&i<2&&s.length<20;)i++,s.push(e),r.shift()();r.length&&!p&&s.length>=20&&(p=window.setTimeout(()=>(p=0,l()),6e4-(e-s[0])))}var d=new Map;function c(e,t){let n,a=t.token();try{n=new URL(e)}catch{return Promise.resolve(null)}if(!a||n.origin!==t.origin())return Promise.resolve(null);let o=`${a} ${e}`,s=d.get(o);if(s)return s;s=new Promise(e=>{r.push(()=>e(()=>(i--,l()))),l()}).then(async e=>{try{let e=await fetch(n,{headers:{Authorization:`Bearer ${a}`},credentials:"omit",signal:AbortSignal.timeout(15e3)});if(404===e.status)return null;if(!e.ok)throw new Error(String(e.status));return await e.blob()}finally{e()}}),d.set(o,s),s.catch(()=>d.get(o)===s&&d.delete(o));for(let e of d.keys())d.size>40&&d.delete(e);return s}var h,f=new WeakMap,u=new Map,m=new WeakSet,g="img[data-palette-snapshot]";function x(e){let t=f.get(e);!t||u.has(e)||!e.isConnected||c(t.url,t.context).then(n=>{if(!e.isConnected||u.has(e))return;if(!n)return t.done?.(!1);let a=URL.createObjectURL(n);u.set(e,a),e.src=a,t.done?.(!0)},()=>t.done?.(!1))}function b(e){h?h.observe(e):x(e)}function v(e){m.has(e)||(m.add(e),"function"==typeof IntersectionObserver&&(h??=new IntersectionObserver(e=>{for(let t of e)t.isIntersecting&&x(t.target)})),new MutationObserver(e=>{for(let t of e){for(let e of t.removedNodes)if(e instanceof Element)for(let t of e.matches(g)?[e]:e.querySelectorAll(g))t.isConnected||h?.unobserve(t);for(let e of t.addedNodes)if(e instanceof Element&&e.isConnected)for(let t of e.matches(g)?[e]:e.querySelectorAll(g))b(t)}!function(){for(let[e,t]of u)e.isConnected||(URL.revokeObjectURL(t),u.delete(e),e.removeAttribute("src"))}()}).observe(e,{childList:!0,subtree:!0}))}function w(e){for(let t of[...C.get(e)??[]])t();for(let[t,n]of u)t.getRootNode()===e&&(URL.revokeObjectURL(n),u.delete(t),t.removeAttribute("src"),h?.unobserve(t))}function y(e){let{context:t,text:n}=e.anchor,a=(t?.label||n||"").replace(/\s+/g," ").trim();return`Snapshot of ${a?`“${a.length>60?`${a.slice(0,59)}…`:a}”`:t?.tag?`the ${t.tag} element`:"the commented element"} when the comment was left`}var k=/^<!-- (?:palette|komo): (no image snapshot, [^>]*?)\.? -->\s*/;function L(e){let t=k.exec(e);return t?{note:`${t[1][0].toUpperCase()}${t[1].slice(1)}.`,code:e.slice(t[0].length)}:{note:"",code:e}}function S(t){let n=e("pre","palette-snapshot-code");return n.textContent=t,n.tabIndex=0,n.setAttribute("role","region"),n.setAttribute("aria-label","HTML snapshot"),n}var C=new Map;async function R(n,o,r){a(n);let i=n.activeElement,s=e("dialog","palette-snapshot-viewer");s.setAttribute("aria-modal","true"),s.setAttribute("aria-label",o.alt);let p=e("header"),l=t("Close snapshot",()=>h(),"icon","close");if(l.removeAttribute("title"),p.append(e("h2","",o.src?"Snapshot":"HTML snapshot"),l),s.append(p),o.src){let t=e("img");t.alt=o.alt,t.src=o.src,s.append(t),await t.decode().catch(()=>{})}else{let{note:t,code:n}=L(o.html??"");t&&s.append(e("p","",t)),s.append(S(n))}if(!n.host.isConnected)return r?.();let d=new AbortController,{signal:c}=d,h=()=>{c.aborted||(d.abort(),C.get(n)?.delete(h),s.close(),s.remove(),r?.(),i?.isConnected&&i.focus({preventScroll:!0}))};s.addEventListener("close",h,{signal:c}),C.set(n,(C.get(n)??new Set).add(h)),window.addEventListener("keydown",e=>{e.stopImmediatePropagation(),"Escape"===e.key&&(e.preventDefault(),h())},{capture:!0,signal:c});let f=!1,u=e=>{let t=s.getBoundingClientRect();return e.target===s&&(e.clientX<t.left||e.clientX>t.right||e.clientY<t.top||e.clientY>t.bottom)};return s.addEventListener("pointerdown",e=>f=u(e),{signal:c}),s.addEventListener("click",e=>f&&u(e)&&h(),{signal:c}),n.append(s),s.showModal(),l.focus(),s}function A(t,n,a,o=!1,r){let i=y(n),s=e("img");s.alt=i,s.dataset.paletteSnapshot="",s.decoding="async";let p=e("button","palette-snapshot");return p.type="button",p.setAttribute("aria-haspopup","dialog"),o&&(p.dataset.large=""),p.append(s),f.set(s,{url:t,context:a,done:e=>{e?p.dataset.ready="":p.dataset.ready||(r?r():p.hidden=!0)}}),p.addEventListener("click",()=>{c(t,a).then(e=>{if(!e)return;let t=URL.createObjectURL(e);R(a.root,{src:t,alt:i},()=>URL.revokeObjectURL(t))})}),p}function E(e,t,n){v(n),e.replaceWith(t);let a=t.querySelector(g);a?.isConnected&&b(a)}function M(n,o,r,i,s){let{image:p,html:l}=i.snapshot??{};if(a(o.root),3===r)return void s?.then(a=>{a&&(a.image||a.html)&&n.isConnected&&!o.dropped.has(i.anchor)&&E(n,function(n,a,o){let r=e("div","palette-snapshot-draft"),i=y({anchor:a});if(n.image){let t=e("button","palette-snapshot");t.type="button",t.dataset.ready="",t.setAttribute("aria-haspopup","dialog");let a=e("img");a.alt=i,a.src=n.image,t.append(a),t.addEventListener("click",()=>{R(o.root,{src:n.image,alt:i})}),r.append(t)}r.append(e("span","",n.image?n.html?"Snapshot and HTML attached":"Snapshot attached":"HTML snapshot attached"));let s=t("Remove snapshot",()=>{o.dropped.add(a),r.closest("form")?.querySelector("textarea")?.focus(),r.remove()},"icon","trash");return r.append(s),r}(a,i.anchor,o),o.root)});let d=r>1?(p||l)&&function(t,n){let{image:a,html:o}=t.snapshot,r=e("div","palette-snapshot-view"),i=()=>{if(!o)return r.remove();c(o,n).then(async t=>{if(!t)return r.remove();let{note:n,code:a}=L(await t.text());r.replaceChildren(e("p","",n||"How it looked, as HTML:"),S(a))},()=>r.remove())};return r.append(e("p","","How it looked:")),a?r.append(A(a,t,n,!0,i)):i(),r}(i,o):p?A(p,i,o):r&&l&&function(e,n,a){let o=t("HTML snapshot",()=>{c(e,a).then(async e=>{e&&R(a.root,{html:await e.text(),alt:y(n)})})},"palette-snapshot-text");return o.removeAttribute("title"),o.setAttribute("aria-haspopup","dialog"),o}(l,i,o);if(4===r){let t=e("div");t.append(function(t,n){let a=new URL(t.page,location.origin);a.searchParams.set("comment",t.id);let o=e("a","thread-route",t.page);o.href=a.href,o.addEventListener("click",e=>{e.preventDefault(),n.go(a)});let r=e("p","","Left on ");return r.append(o),r}(i,o),...d?[d]:[]),d=t}d&&E(n,d,o.root)}function U(e,t){t.notify("Remove this comment’s snapshot?",{label:"Remove",run:()=>{t.remove(e),t.notify("Snapshot removed")}})}export{o as READS_PER_MINUTE,U as confirmRemove,w as disposeSnapshots,M as mountSnapshot,R as openSnapshotViewer,c as readSnapshot,y as snapshotAlt,L as splitNote};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hazem3500/palette",
3
- "version": "0.9.123",
3
+ "version": "0.9.124",
4
4
  "description": "Point, area, and threaded comments for website branches.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -63,7 +63,7 @@ ${c.innerHTML}`&&v();let m=WH(u,c)[r.index]??null;(d.parentNode!==u||d.nextEleme
63
63
  [data-compact] .design-card-head, [data-compact] .design-row, [data-compact] > .design-source { min-height: 0; padding: 4px 10px; }
64
64
  [data-compact]:hover > .design-source { color: #eee; text-decoration: underline; }
65
65
  `;IH=e=>`<svg viewBox="0 0 12 12" aria-hidden="true"><path d="${e}"/></svg>`,Jq=[IH("M2.5 6.5a3.5 3.5 0 1 0 1.2-2.6M3 1.8v2.4h2.4"),IH("M1 6s1.8-3.5 5-3.5S11 6 11 6s-1.8 3.5-5 3.5S1 6 1 6Zm5 1.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z")],QH=e=>(e?.themes??[]).filter(t=>t.options?.length>1).map(t=>ri(e)[t.id]).join("+")||void 0;GH=!1,FH=new WeakSet});var xz={};Wt(xz,{ATTRIBUTE_LIMIT:()=>lz,HTML_LIMIT:()=>Yy,IMAGE_BYTES:()=>MT,OPT_OUT:()=>iz,PLACEHOLDER:()=>mu,TEXT_LIMIT:()=>cz,captureSnapshot:()=>yz,noteComment:()=>bz,omitInvisibleFrameStyles:()=>gz,skipped:()=>uz,snapshotFor:()=>yK,snapshotHtml:()=>fz,snapshotImage:()=>hz});function pz(e,t=1/0){for(let{name:n,value:o}of[...e.attributes])/^on/i.test(n)||n==="srcdoc"||/^data-(palette|komo)-/.test(n)&&!/-no-snapshot$/.test(n)||oK.test(n)&&/^\s*(?:javascript|vbscript):/i.test(o)?e.removeAttribute(n):o.length>t&&e.setAttribute(n,dz(o,t))}function iK(e,t){let n=e.value??e.getAttribute("value")??"";e.localName==="textarea"?t.textContent=n?mu:"":(n||t.hasAttribute("value"))&&t.setAttribute("value",mu)}function fz(e,t,n=Yy){let o=e.ownerDocument,i=n,r=c=>{if(c.nodeType===3){let p=dz(c.nodeValue??"",cz);return i-=p.length,o.createTextNode(p)}if(c.nodeType!==1)return null;let u=c;if(sz.has(u.localName)||u.matches(CT))return null;let d=u.cloneNode(!1);if(pz(d,lz),Fy(u)&&iK(u,d),i-=d.outerHTML.length,az(u))return d;if(t?.(u))return Fy(u)||(d.textContent=mu),d;if(u.localName==="textarea")return d;for(let p of u.childNodes){if(i<=0){d.append(o.createComment(" trimmed "));break}let g=r(p);g&&d.append(g)}return d},a=r(e);if(!a)return"";let s=a.outerHTML;if(Iy(s)<=n)return s;let l=o.createComment(" trimmed ");a.append(l);for(let c=Iy(a.outerHTML)-n;c>0&&a.firstChild!==l;c=Iy(a.outerHTML)-n)for(;c>0&&a.firstChild!==l;){let u=l.previousSibling;for(;u.lastChild;)u=u.lastChild;c-=u.nodeType===1?u.outerHTML.length:(u.nodeValue?.length??0)+7,u.parentNode.removeChild(u)}return s=a.outerHTML,Iy(s)>n?"":s}async function LT(e,t){if(e.startsWith("data:"))return e;let n=new URL(e,t.document.baseURI);try{let o=await fetch(n,{mode:"cors",signal:AbortSignal.timeout(5e3)});return o.ok?await mz(await o.blob()):""}catch{if(n.origin!==t.location.origin)throw new Tr("cross-origin");return""}}async function cK(e,t,n){let o=e.currentSrc||e.src;if(!o||o.startsWith("data:"))return o;await e.decode().catch(()=>{});let i=Math.min(e.naturalWidth,Math.ceil(e.offsetWidth*t)||e.naturalWidth),r=Math.round(i*e.naturalHeight/(e.naturalWidth||1));if(i&&r){let a=document.createElement("canvas");a.width=i,a.height=r;try{return a.getContext("2d").drawImage(e,0,0,i,r),a.toDataURL("image/png")}catch{}}return LT(o,n)}function dK(){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 n=new Map;return{of(o){let i=`${o.namespaceURI} ${o.localName}`,r=n.get(i);if(!r){let a=t.createElementNS(o.namespaceURI,o.localName);(t.body??t.documentElement).append(a);let s=t.defaultView.getComputedStyle(a);r=new Map;for(let l=0;l<s.length;l++)r.set(s[l],s.getPropertyValue(s[l]));a.remove(),n.set(i,r)}return r},dispose:()=>e.remove()}}function gz(e,t=o=>e.get(o),n){for(let o of uK){let i=`border-${o}-style`,r=`border-${o}-width`;Gy(t(i),t(r))&&(e.delete(i),e.delete(r),e.delete(`border-${o}-color`),n?.has(i)&&!Gy(n.get(i),n.get(r))&&e.set(i,"none"))}if(Gy(t("outline-style"),t("outline-width"))){for(let o of[...e.keys()])o.startsWith("outline")&&e.delete(o);n?.has("outline-style")&&!Gy(n.get("outline-style"),n.get("outline-width"))&&e.set("outline-style","none")}}function tz(e,t,n){let o=new Map;for(let r=0;r<e.length;r++){let a=e[r];if(a.startsWith("--"))continue;let s=e.getPropertyValue(a);(s!==t.get(a)||n&&s!==n.getPropertyValue(a))&&o.set(a,s)}gz(o,r=>e.getPropertyValue(r),t);let i="";for(let[r,a]of o)i+=`${r}:${a};`;return i}async function pK(e,t,n){let o=[],i=lK,r=async(a,s)=>{for(let l of a){if(l.cssRules&&await r(l.cssRules,s),!l.cssText.startsWith("@font-face"))continue;let c=l.style,u=c.getPropertyValue("font-family").replace(/["']/g,"").trim().toLowerCase(),d=c.getPropertyValue("src").match(/url\((['"]?)(.*?)\1\)/)?.[2];if(!t.has(u)||!d||i<=0)continue;let p=await LT(new URL(d,s).href,n).catch(()=>"");p&&(i-=p.length,o.push(`@font-face{font-family:"${u}";src:url("${p}");${["font-weight","font-style","font-stretch","unicode-range"].map(g=>c.getPropertyValue(g)?`${g}:${c.getPropertyValue(g)};`:"").join("")}}`))}};for(let a of e.styleSheets){let s;try{s=a.cssRules}catch{continue}await r(s,a.href??e.baseURI)}return o.join("")}function fK(e,t){for(let n=e.parentElement;n;n=n.parentElement){let o=t.getComputedStyle(n).backgroundColor;if(o&&!/^(?:transparent|rgba\(.*,\s*0\))$/.test(o))return o}return"#fff"}async function mK(e,t,n){let o=e.ownerDocument,i=o.defaultView,r=e.getBoundingClientRect(),a=e.offsetWidth??r.width,s=Math.min(e.offsetHeight??r.height,aK);if(!a||!s)throw new Tr("failed");let l=dK(),c=[],u=new Set,d=new Map,p=[],g="",y=0,v=m=>(m.catch(()=>{}),m),x=m=>{for(let[,,b]of m.matchAll(nz))b&&!b.startsWith("data:")&&!d.has(b)&&d.set(b,v(LT(b,i)));return m},h=(m,b)=>{if(m.nodeType===3)return o.createTextNode(m.nodeValue??"");if(m.nodeType!==1)return null;let E=m,S=E.localName;if(sz.has(S)||E.matches(CT))return null;if(++y>sK)throw new Tr("too-large");let C=i.getComputedStyle(E);if(C.display==="none")return null;let _;if(S==="canvas"||S==="video"){_=o.createElement("img");let R=document.createElement("canvas");R.width=E.width||E.videoWidth||1,R.height=E.height||E.videoHeight||1;try{R.getContext("2d").drawImage(E,0,0,R.width,R.height),_.setAttribute("src",R.toDataURL("image/png"))}catch{throw new Tr("cross-origin")}}else if(S==="iframe"||S==="embed"||S==="object")_=o.createElement("div");else{_=E.cloneNode(!1),pz(_);for(let R of["id","class","srcset","sizes","loading","style"])_.removeAttribute(R)}Fy(E)&&(_.removeAttribute("value"),_.hasAttribute("placeholder")&&t?.(E)&&_.setAttribute("placeholder",mu)),S==="img"&&c.push(v(cK(E,n,i).then(R=>_.setAttribute("src",R)))),u.add(C.fontFamily.split(",")[0].replace(/["']/g,"").trim().toLowerCase());let A=tz(C,l.of(E),b);b||(A+=`${C.display==="inline"?"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:${a}px;height:${s}px;max-width:none;max-height:none;min-width:0;min-height:0;`);let H=az(E)&&!!b;H&&(A+="color:transparent;background:#e5e5e5;background-image:none;"),p.push([_,x(A)]);for(let R of["::before","::after"]){let z=i.getComputedStyle(E,R);H||/^(?:none|normal)$/.test(z.content)||(_.setAttribute("data-snapshot",String(y)),g+=`[data-snapshot="${y}"]${R}{${x(tz(z,l.of(E),C))}content:${z.content};}`)}if(H)return _;if(t?.(E))return Fy(E)||(_.textContent=mu),_;if(S==="textarea")return _;for(let R of E.childNodes){if(S==="picture"&&R.localName!=="img")continue;let z=h(R,C);z&&_.append(z)}return _};try{await o.fonts?.ready;let m=h(e),b=new Map(await Promise.all([...d].map(async([R,z])=>[R,await z]))),E=R=>R.replace(nz,(z,F,B)=>b.has(B)?`url("${b.get(B)}")`:z);for(let[R,z]of p)R.setAttribute("style",E(z));g=E(g),await Promise.all(c);let S=o.createElement("div");S.setAttribute("style",`width:${a+fu*2}px;height:${s+fu*2}px;padding:${fu}px;box-sizing:border-box;overflow:hidden;background:${fK(e,i)}`);let C=o.createElement("style");C.textContent=await pK(o,u,i)+g,S.append(C,m);let _={width:a+fu*2,height:s+fu*2},A=`<svg xmlns="http://www.w3.org/2000/svg" width="${_.width}" height="${_.height}"><foreignObject x="0" y="0" width="100%" height="100%">${new XMLSerializer().serializeToString(S)}</foreignObject></svg>`,H=new Image;return H.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(A)}`,await H.decode(),{image:H,..._}}finally{l.dispose()}}async function hz(e,t={}){let n=t.maxBytes??MT,o=e.ownerDocument.defaultView??window,i=e.offsetWidth||e.getBoundingClientRect().width,r=Math.min(o.devicePixelRatio||1,2,rK/(i+fu*2)),a=await mK(e,t.redact,r),s=document.createElement("canvas"),l=.8;for(let c=0;c<12&&a.width*r>=48;c++){s.width=Math.max(1,Math.round(a.width*r)),s.height=Math.max(1,Math.round(a.height*r));let u=s.getContext("2d");if(!u)throw new Tr("unsupported");u.drawImage(a.image,0,0,s.width,s.height);let d;try{d=await gK(s,l)}catch{throw new Tr("cross-origin")}if(!d||d.type!=="image/webp")throw new Tr("unsupported");if(d.size<=n)return mz(d);l>.5?l=Math.round((l-.15)*100)/100:r*=Math.min(.85,Math.max(.3,Math.sqrt(n/d.size)*.95))}throw new Tr("too-large")}async function yz(e,t,n=Yy){if(!e?.isConnected||uz(e))return null;let o={},i=()=>fz(e,t.redact,n-120);if(t.html&&(o.html=i()),t.image){await new Promise(r=>typeof requestIdleCallback=="function"?requestIdleCallback(r,{timeout:500}):setTimeout(r));try{o.image=await hz(e,t)}catch(r){o.note=r instanceof Tr?r.reason:"failed",o.note==="cross-origin"&&(o.html??=i()),o.html&&(o.html=bz(o.note)+o.html)}}return o}function yK(e,t,n,o,i){let r=oz.get(e);if(!r){let a={...n,maxBytes:Math.min(n.maxBytes??MT,o.maxImageBytes||1/0)};r=n.image||n.html?yz(t(e),a,Math.min(Yy,o.maxHtmlBytes||1/0)).catch(()=>({note:"failed"})):Promise.resolve(null),oz.set(e,r)}return i&&r.then(async a=>{let s=a?.note==="failed";for(let l of["image","html"]){let c=a?.[l];c&&await i(l,l==="image"?bK(c):new Blob([c],{type:"text/html;charset=utf-8"})).catch(()=>s=!0)}if(o.readiness&&(s||!(a?.image||a?.html)))return i("status",new Blob([`{"status":"${s?"failed":"skipped"}"}`],{type:"application/json"})).catch(()=>{})}),r}var iz,rz,az,CT,mu,sz,oK,Fy,Yy,lz,cz,dz,Iy,uz,Tr,MT,rK,aK,fu,sK,lK,mz,uK,Gy,nz,gK,hK,bz,bK,oz,vz=$(()=>{"use strict";iz="data-palette-no-snapshot",rz=`[${iz}],[data-komo-no-snapshot]`,az=e=>e.matches(rz),CT="[data-branch-comments],[data-palette-move-clone],[data-palette-viewport],[data-palette-snapshot-sandbox]",mu="[redacted]",sz=new Set(["script","noscript","template","style","link","meta","base","title"]),oK=/^(?:href|src|action|formaction|xlink:href|poster|data|background)$/i,Fy=e=>e.localName==="textarea"||e.localName==="input"&&!/^(?:button|submit|reset|image|checkbox|radio|range|color)$/i.test(e.getAttribute("type")??""),Yy=2e4,lz=200,cz=500,dz=(e,t)=>e.length>t?`${e.slice(0,t-1)}\u2026`:e,Iy=e=>new TextEncoder().encode(e).length,uz=e=>!!e.closest(`${rz},${CT}`);Tr=class extends Error{constructor(n){super(n);this.reason=n}reason},MT=25e4,rK=1200,aK=2e3,fu=16,sK=3e3,lK=2e6,mz=e=>new Promise((t,n)=>{let o=new FileReader;o.onload=()=>t(o.result),o.onerror=()=>n(o.error),o.readAsDataURL(e)});uK=["top","right","bottom","left","block-start","block-end","inline-start","inline-end"],Gy=(e,t)=>e==="none"||e==="hidden"||t==="0px";nz=/url\((['"]?)(.*?)\1\)/g;gK=(e,t)=>new Promise((n,o)=>{try{e.toBlob(n,"image/webp",t)}catch(i){o(i)}});hK={"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"},bz=e=>`<!-- palette: no image snapshot, ${hK[e]}. -->`;bK=e=>{let[t,n]=e.split(","),o=Uint8Array.from(atob(n),i=>i.charCodeAt(0));return new Blob([o],{type:t.slice(5,-7)})},oz=new WeakMap});var _z={};Wt(_z,{READS_PER_MINUTE:()=>DT,confirmRemove:()=>_K,disposeSnapshots:()=>kK,mountSnapshot:()=>LK,openSnapshotViewer:()=>Qy,readSnapshot:()=>sm,snapshotAlt:()=>Zy,splitNote:()=>zT});function Sz(e){let t=wz.get(e);t?.isConnected||(t=w("style","",xK),wz.set(e,t),e.append(t))}function HT(){let e=performance.now();for(;pc.length&&e-pc[0]>=6e4;)pc.shift();for(;Xy.length&&RT<2&&pc.length<DT;)RT++,pc.push(e),Xy.shift()();Xy.length&&!_T&&pc.length>=DT&&(_T=window.setTimeout(()=>(_T=0,HT()),6e4-(e-pc[0])))}function sm(e,t){let n=t.token(),o;try{o=new URL(e)}catch{return Promise.resolve(null)}if(!n||o.origin!==t.origin())return Promise.resolve(null);let i=`${n} ${e}`,r=fc.get(i);if(r)return r;r=vK().then(async a=>{try{let s=await fetch(o,{headers:{Authorization:`Bearer ${n}`},credentials:"omit",signal:AbortSignal.timeout(15e3)});if(s.status===404)return null;if(!s.ok)throw new Error(String(s.status));return await s.blob()}finally{a()}}),fc.set(i,r),r.catch(()=>fc.get(i)===r&&fc.delete(i));for(let a of fc.keys())fc.size>40&&fc.delete(a);return r}function Az(e){let t=Tz.get(e);!t||mc.has(e)||!e.isConnected||sm(t.url,t.context).then(n=>{if(!e.isConnected||mc.has(e))return;if(!n)return t.done?.(!1);let o=URL.createObjectURL(n);mc.set(e,o),e.src=o,t.done?.(!0)},()=>t.done?.(!1))}function wK(){for(let[e,t]of mc)e.isConnected||(URL.revokeObjectURL(t),mc.delete(e),e.removeAttribute("src"))}function Cz(e){am?am.observe(e):Az(e)}function EK(e){Ez.has(e)||(Ez.add(e),typeof IntersectionObserver=="function"&&(am??=new IntersectionObserver(t=>{for(let n of t)n.isIntersecting&&Az(n.target)})),new MutationObserver(t=>{for(let n of t){for(let o of n.removedNodes)if(o instanceof Element)for(let i of o.matches(rm)?[o]:o.querySelectorAll(rm))i.isConnected||am?.unobserve(i);for(let o of n.addedNodes)if(o instanceof Element&&o.isConnected)for(let i of o.matches(rm)?[o]:o.querySelectorAll(rm))Cz(i)}wK()}).observe(e,{childList:!0,subtree:!0}))}function kK(e){for(let t of[...Wy.get(e)??[]])t();for(let[t,n]of mc)t.getRootNode()===e&&(URL.revokeObjectURL(n),mc.delete(t),t.removeAttribute("src"),am?.unobserve(t))}function Zy(e){let{context:t,text:n}=e.anchor,o=(t?.label||n||"").replace(/\s+/g," ").trim();return`Snapshot of ${o?`\u201C${o.length>60?`${o.slice(0,59)}\u2026`:o}\u201D`:t?.tag?`the ${t.tag} element`:"the commented element"} when the comment was left`}function zT(e){let t=SK.exec(e);return t?{note:`${t[1][0].toUpperCase()}${t[1].slice(1)}.`,code:e.slice(t[0].length)}:{note:"",code:e}}function Mz(e){let t=w("pre","palette-snapshot-code");return t.textContent=e,t.tabIndex=0,t.setAttribute("role","region"),t.setAttribute("aria-label","HTML snapshot"),t}async function Qy(e,t,n){Sz(e);let o=e.activeElement,i=w("dialog","palette-snapshot-viewer");i.setAttribute("aria-modal","true"),i.setAttribute("aria-label",t.alt);let r=w("header"),a=Oe("Close snapshot",()=>c(),"icon","close");if(a.removeAttribute("title"),r.append(w("h2","",t.src?"Snapshot":"HTML snapshot"),a),i.append(r),t.src){let p=w("img");p.alt=t.alt,p.src=t.src,i.append(p),await p.decode().catch(()=>{})}else{let{note:p,code:g}=zT(t.html??"");p&&i.append(w("p","",p)),i.append(Mz(g))}if(!e.host.isConnected)return n?.();let s=new AbortController,{signal:l}=s,c=()=>{l.aborted||(s.abort(),Wy.get(e)?.delete(c),i.close(),i.remove(),n?.(),o?.isConnected&&o.focus({preventScroll:!0}))};i.addEventListener("close",c,{signal:l}),Wy.set(e,(Wy.get(e)??new Set).add(c)),window.addEventListener("keydown",p=>{p.stopImmediatePropagation(),p.key==="Escape"&&(p.preventDefault(),c())},{capture:!0,signal:l});let u=!1,d=p=>{let g=i.getBoundingClientRect();return p.target===i&&(p.clientX<g.left||p.clientX>g.right||p.clientY<g.top||p.clientY>g.bottom)};return i.addEventListener("pointerdown",p=>u=d(p),{signal:l}),i.addEventListener("click",p=>u&&d(p)&&c(),{signal:l}),e.append(i),i.showModal(),a.focus(),i}function Lz(e,t,n,o=!1,i){let r=Zy(t),a=w("img");a.alt=r,a.dataset.paletteSnapshot="",a.decoding="async";let s=w("button","palette-snapshot");return s.type="button",s.setAttribute("aria-haspopup","dialog"),o&&(s.dataset.large=""),s.append(a),Tz.set(a,{url:e,context:n,done:l=>{l?s.dataset.ready="":s.dataset.ready||(i?i():s.hidden=!0)}}),s.addEventListener("click",()=>{sm(e,n).then(l=>{if(!l)return;let c=URL.createObjectURL(l);Qy(n.root,{src:c,alt:r},()=>URL.revokeObjectURL(c))})}),s}function kz(e,t,n){EK(n),e.replaceWith(t);let o=t.querySelector(rm);o?.isConnected&&Cz(o)}function TK(e,t,n){let o=Oe("HTML snapshot",()=>{sm(e,n).then(async i=>{i&&Qy(n.root,{html:await i.text(),alt:Zy(t)})})},"palette-snapshot-text");return o.removeAttribute("title"),o.setAttribute("aria-haspopup","dialog"),o}function AK(e,t){let{image:n,html:o}=e.snapshot,i=w("div","palette-snapshot-view"),r=()=>{if(!o)return i.remove();sm(o,t).then(async a=>{if(!a)return i.remove();let{note:s,code:l}=zT(await a.text());i.replaceChildren(w("p","",s||"How it looked, as HTML:"),Mz(l))},()=>i.remove())};return i.append(w("p","","How it looked:")),n?i.append(Lz(n,e,t,!0,r)):r(),i}function CK(e,t,n){let o=w("div","palette-snapshot-draft"),i=Zy({anchor:t});if(e.image){let a=w("button","palette-snapshot");a.type="button",a.dataset.ready="",a.setAttribute("aria-haspopup","dialog");let s=w("img");s.alt=i,s.src=e.image,a.append(s),a.addEventListener("click",()=>{Qy(n.root,{src:e.image,alt:i})}),o.append(a)}o.append(w("span","",e.image?e.html?"Snapshot and HTML attached":"Snapshot attached":"HTML snapshot attached"));let r=Oe("Remove snapshot",()=>{n.dropped.add(t),o.closest("form")?.querySelector("textarea")?.focus(),o.remove()},"icon","trash");return o.append(r),o}function MK(e,t){let n=new URL(e.page,location.origin);n.searchParams.set("comment",e.id);let o=w("a","thread-route",e.page);o.href=n.href,o.addEventListener("click",r=>{r.preventDefault(),t.go(n)});let i=w("p","","Left on ");return i.append(o),i}function LK(e,t,n,o,i){let{image:r,html:a}=o.snapshot??{};if(Sz(t.root),n===3)return void i?.then(l=>{l&&(l.image||l.html)&&e.isConnected&&!t.dropped.has(o.anchor)&&kz(e,CK(l,o.anchor,t),t.root)});let s=n>1?(r||a)&&AK(o,t):r?Lz(r,o,t):n&&a&&TK(a,o,t);if(n===4){let l=w("div");l.append(MK(o,t),...s?[s]:[]),s=l}s&&kz(e,s,t.root)}function _K(e,t){t.notify("Remove this comment\u2019s snapshot?",{label:"Remove",run:()=>{t.remove(e),t.notify("Snapshot removed")}})}var xK,wz,DT,Xy,RT,pc,_T,vK,fc,Tz,mc,Ez,am,rm,SK,Wy,Dz=$(()=>{"use strict";Ft();xK=`.palette-snapshot{display:block;width:fit-content;margin-top:8px;padding:0;border:0;border-radius:6px;background:none;color:inherit;font:inherit;cursor:zoom-in;line-height:0}
66
- .palette-snapshot img{display:block;width:72px;height:48px;border-radius:6px;object-fit:cover;object-position:left top;background:color-mix(in oklab,currentColor 8%,transparent);outline:1px solid color-mix(in oklab,currentColor 16%,transparent);outline-offset:-1px}
66
+ .palette-snapshot img{display:block;width:72px;height:48px;border-radius:6px;object-fit:contain;background:color-mix(in oklab,currentColor 8%,transparent);outline:1px solid color-mix(in oklab,currentColor 16%,transparent);outline-offset:-1px}
67
67
  .palette-snapshot:not([data-ready]){background:color-mix(in oklab,currentColor 8%,transparent)}
68
68
  .palette-snapshot:not([data-ready]) img{visibility:hidden}
69
69
  .palette-snapshot[hidden]{display:none}
@@ -1 +0,0 @@
1
- import{E as e,G as t}from"./chunk-4HBBEVFK.js";var n=new WeakMap;function a(t){let a=n.get(t);a?.isConnected||(a=e("style","",'.palette-snapshot{display:block;width:fit-content;margin-top:8px;padding:0;border:0;border-radius:6px;background:none;color:inherit;font:inherit;cursor:zoom-in;line-height:0}\n.palette-snapshot img{display:block;width:72px;height:48px;border-radius:6px;object-fit:cover;object-position:left top;background:color-mix(in oklab,currentColor 8%,transparent);outline:1px solid color-mix(in oklab,currentColor 16%,transparent);outline-offset:-1px}\n.palette-snapshot:not([data-ready]){background:color-mix(in oklab,currentColor 8%,transparent)}\n.palette-snapshot:not([data-ready]) img{visibility:hidden}\n.palette-snapshot[hidden]{display:none}\n.palette-snapshot:focus-visible{outline:2px solid var(--accent,#bda6ef);outline-offset:2px}\n.palette-snapshot[data-large]{width:auto;max-width:100%}\n.palette-snapshot[data-large] img{width:auto;height:auto;min-width:72px;min-height:48px;max-width:100%;max-height:180px;object-fit:contain}\n.thread-item>.palette-snapshot{margin:6px 12px 0 calc(12px + var(--palette-avatar,20px) + var(--palette-gutter,8px))}\n.dialog:has(.thread-navigation:not([hidden]) .palette-snapshot-view) .message .palette-snapshot{display:none}\n.palette-snapshot-view{margin-top:8px}\n.palette-snapshot-view p{margin:0 0 6px}\n.palette-snapshot-code{box-sizing:border-box;max-height:160px;margin:0;padding:8px;overflow:auto;border-radius:6px;background:color-mix(in oklab,currentColor 8%,transparent);font:11px/1.45 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre-wrap;overflow-wrap:anywhere;scrollbar-width:thin}\n.palette-snapshot-code:focus-visible{outline:2px solid var(--accent,#bda6ef);outline-offset:2px}\n.palette-snapshot-text{justify-self:start;margin-top:8px;padding:4px 8px;border:0;border-radius:6px;background:color-mix(in oklab,currentColor 8%,transparent);color:inherit;font-family:inherit;font-size:11px;line-height:1.4;cursor:pointer}\n.palette-snapshot-draft{display:flex;align-items:center;gap:8px;margin-top:8px;font-size:12px;color:#999}\n.palette-snapshot-draft .palette-snapshot{margin:0}\n.palette-snapshot-draft span{flex:1;min-width:0}\n.palette-snapshot-draft .icon{width:28px;height:28px}\n.palette-snapshot-viewer{box-sizing:border-box;max-width:min(1200px,calc(100vw - 32px));max-height:calc(100dvh - 32px);margin:auto;padding:12px;overflow:hidden;border:0;border-radius:16px;background:#242424;color:#eee;box-shadow:inset 0 0 0 1px #ffffff1f,0 24px 64px -16px rgb(0 0 0/55%);font:12px/1.4 -apple-system,BlinkMacSystemFont,"Inter","Segoe UI",sans-serif;pointer-events:auto;color-scheme:dark}\n.palette-snapshot-viewer[open]{display:flex;flex-direction:column;gap:8px;animation:palette-snapshot-in var(--duration-fast,250ms) var(--ease-smooth-out,cubic-bezier(.22,1,.36,1))}\n.palette-snapshot-viewer::backdrop{background:rgb(0 0 0/40%);pointer-events:auto}\n.palette-snapshot-viewer header{display:flex;align-items:center;gap:8px}\n.palette-snapshot-viewer h2{flex:1;margin:0;padding-left:4px;font-size:13px;font-weight:600}\n.palette-snapshot-viewer .icon{width:28px;height:28px;border-radius:8px;color:#bbb}\n.palette-snapshot-viewer .icon:hover{background:#ffffff14;color:#eee}\n.palette-snapshot-viewer .icon:focus-visible{outline:2px solid var(--accent,#bda6ef);outline-offset:-2px}\n.palette-snapshot-viewer img{display:block;min-height:0;max-width:100%;max-height:calc(100dvh - 104px);margin:auto;border-radius:8px;object-fit:contain}\n.palette-snapshot-viewer .palette-snapshot-code{max-height:calc(100dvh - 104px);width:min(720px,calc(100vw - 56px))}\n@keyframes palette-snapshot-in{from{opacity:0;scale:.98;translate:0 4px}}\n@media (prefers-reduced-motion:reduce){.palette-snapshot-viewer[open]{animation:none}}\n@media (pointer:coarse){.palette-snapshot-viewer .icon,.palette-snapshot-draft .icon{width:44px;height:44px}}'),n.set(t,a),t.append(a))}var o=20,r=[],i=0,s=[],p=0;function l(){let e=performance.now();for(;s.length&&e-s[0]>=6e4;)s.shift();for(;r.length&&i<2&&s.length<20;)i++,s.push(e),r.shift()();r.length&&!p&&s.length>=20&&(p=window.setTimeout(()=>(p=0,l()),6e4-(e-s[0])))}var d=new Map;function c(e,t){let n,a=t.token();try{n=new URL(e)}catch{return Promise.resolve(null)}if(!a||n.origin!==t.origin())return Promise.resolve(null);let o=`${a} ${e}`,s=d.get(o);if(s)return s;s=new Promise(e=>{r.push(()=>e(()=>(i--,l()))),l()}).then(async e=>{try{let e=await fetch(n,{headers:{Authorization:`Bearer ${a}`},credentials:"omit",signal:AbortSignal.timeout(15e3)});if(404===e.status)return null;if(!e.ok)throw new Error(String(e.status));return await e.blob()}finally{e()}}),d.set(o,s),s.catch(()=>d.get(o)===s&&d.delete(o));for(let e of d.keys())d.size>40&&d.delete(e);return s}var h,f=new WeakMap,u=new Map,m=new WeakSet,g="img[data-palette-snapshot]";function x(e){let t=f.get(e);!t||u.has(e)||!e.isConnected||c(t.url,t.context).then(n=>{if(!e.isConnected||u.has(e))return;if(!n)return t.done?.(!1);let a=URL.createObjectURL(n);u.set(e,a),e.src=a,t.done?.(!0)},()=>t.done?.(!1))}function b(e){h?h.observe(e):x(e)}function v(e){m.has(e)||(m.add(e),"function"==typeof IntersectionObserver&&(h??=new IntersectionObserver(e=>{for(let t of e)t.isIntersecting&&x(t.target)})),new MutationObserver(e=>{for(let t of e){for(let e of t.removedNodes)if(e instanceof Element)for(let t of e.matches(g)?[e]:e.querySelectorAll(g))t.isConnected||h?.unobserve(t);for(let e of t.addedNodes)if(e instanceof Element&&e.isConnected)for(let t of e.matches(g)?[e]:e.querySelectorAll(g))b(t)}!function(){for(let[e,t]of u)e.isConnected||(URL.revokeObjectURL(t),u.delete(e),e.removeAttribute("src"))}()}).observe(e,{childList:!0,subtree:!0}))}function w(e){for(let t of[...C.get(e)??[]])t();for(let[t,n]of u)t.getRootNode()===e&&(URL.revokeObjectURL(n),u.delete(t),t.removeAttribute("src"),h?.unobserve(t))}function y(e){let{context:t,text:n}=e.anchor,a=(t?.label||n||"").replace(/\s+/g," ").trim();return`Snapshot of ${a?`“${a.length>60?`${a.slice(0,59)}…`:a}”`:t?.tag?`the ${t.tag} element`:"the commented element"} when the comment was left`}var k=/^<!-- (?:palette|komo): (no image snapshot, [^>]*?)\.? -->\s*/;function L(e){let t=k.exec(e);return t?{note:`${t[1][0].toUpperCase()}${t[1].slice(1)}.`,code:e.slice(t[0].length)}:{note:"",code:e}}function S(t){let n=e("pre","palette-snapshot-code");return n.textContent=t,n.tabIndex=0,n.setAttribute("role","region"),n.setAttribute("aria-label","HTML snapshot"),n}var C=new Map;async function R(n,o,r){a(n);let i=n.activeElement,s=e("dialog","palette-snapshot-viewer");s.setAttribute("aria-modal","true"),s.setAttribute("aria-label",o.alt);let p=e("header"),l=t("Close snapshot",()=>h(),"icon","close");if(l.removeAttribute("title"),p.append(e("h2","",o.src?"Snapshot":"HTML snapshot"),l),s.append(p),o.src){let t=e("img");t.alt=o.alt,t.src=o.src,s.append(t),await t.decode().catch(()=>{})}else{let{note:t,code:n}=L(o.html??"");t&&s.append(e("p","",t)),s.append(S(n))}if(!n.host.isConnected)return r?.();let d=new AbortController,{signal:c}=d,h=()=>{c.aborted||(d.abort(),C.get(n)?.delete(h),s.close(),s.remove(),r?.(),i?.isConnected&&i.focus({preventScroll:!0}))};s.addEventListener("close",h,{signal:c}),C.set(n,(C.get(n)??new Set).add(h)),window.addEventListener("keydown",e=>{e.stopImmediatePropagation(),"Escape"===e.key&&(e.preventDefault(),h())},{capture:!0,signal:c});let f=!1,u=e=>{let t=s.getBoundingClientRect();return e.target===s&&(e.clientX<t.left||e.clientX>t.right||e.clientY<t.top||e.clientY>t.bottom)};return s.addEventListener("pointerdown",e=>f=u(e),{signal:c}),s.addEventListener("click",e=>f&&u(e)&&h(),{signal:c}),n.append(s),s.showModal(),l.focus(),s}function A(t,n,a,o=!1,r){let i=y(n),s=e("img");s.alt=i,s.dataset.paletteSnapshot="",s.decoding="async";let p=e("button","palette-snapshot");return p.type="button",p.setAttribute("aria-haspopup","dialog"),o&&(p.dataset.large=""),p.append(s),f.set(s,{url:t,context:a,done:e=>{e?p.dataset.ready="":p.dataset.ready||(r?r():p.hidden=!0)}}),p.addEventListener("click",()=>{c(t,a).then(e=>{if(!e)return;let t=URL.createObjectURL(e);R(a.root,{src:t,alt:i},()=>URL.revokeObjectURL(t))})}),p}function E(e,t,n){v(n),e.replaceWith(t);let a=t.querySelector(g);a?.isConnected&&b(a)}function M(n,o,r,i,s){let{image:p,html:l}=i.snapshot??{};if(a(o.root),3===r)return void s?.then(a=>{a&&(a.image||a.html)&&n.isConnected&&!o.dropped.has(i.anchor)&&E(n,function(n,a,o){let r=e("div","palette-snapshot-draft"),i=y({anchor:a});if(n.image){let t=e("button","palette-snapshot");t.type="button",t.dataset.ready="",t.setAttribute("aria-haspopup","dialog");let a=e("img");a.alt=i,a.src=n.image,t.append(a),t.addEventListener("click",()=>{R(o.root,{src:n.image,alt:i})}),r.append(t)}r.append(e("span","",n.image?n.html?"Snapshot and HTML attached":"Snapshot attached":"HTML snapshot attached"));let s=t("Remove snapshot",()=>{o.dropped.add(a),r.closest("form")?.querySelector("textarea")?.focus(),r.remove()},"icon","trash");return r.append(s),r}(a,i.anchor,o),o.root)});let d=r>1?(p||l)&&function(t,n){let{image:a,html:o}=t.snapshot,r=e("div","palette-snapshot-view"),i=()=>{if(!o)return r.remove();c(o,n).then(async t=>{if(!t)return r.remove();let{note:n,code:a}=L(await t.text());r.replaceChildren(e("p","",n||"How it looked, as HTML:"),S(a))},()=>r.remove())};return r.append(e("p","","How it looked:")),a?r.append(A(a,t,n,!0,i)):i(),r}(i,o):p?A(p,i,o):r&&l&&function(e,n,a){let o=t("HTML snapshot",()=>{c(e,a).then(async e=>{e&&R(a.root,{html:await e.text(),alt:y(n)})})},"palette-snapshot-text");return o.removeAttribute("title"),o.setAttribute("aria-haspopup","dialog"),o}(l,i,o);if(4===r){let t=e("div");t.append(function(t,n){let a=new URL(t.page,location.origin);a.searchParams.set("comment",t.id);let o=e("a","thread-route",t.page);o.href=a.href,o.addEventListener("click",e=>{e.preventDefault(),n.go(a)});let r=e("p","","Left on ");return r.append(o),r}(i,o),...d?[d]:[]),d=t}d&&E(n,d,o.root)}function U(e,t){t.notify("Remove this comment’s snapshot?",{label:"Remove",run:()=>{t.remove(e),t.notify("Snapshot removed")}})}export{o as READS_PER_MINUTE,U as confirmRemove,w as disposeSnapshots,M as mountSnapshot,R as openSnapshotViewer,c as readSnapshot,y as snapshotAlt,L as splitNote};