@hyperpuncher/pi-ui 0.43.1 → 0.43.2
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/static/build/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{gc as xe,hc as Te}from"./chunks/main-pq3eh5fy.js";import{ic as Ke}from"./chunks/main-b1kpnx3v.js";import{oc as zt,pc as N}from"./chunks/main-jgbmmpjx.js";function O(e,t){let n=e.toLowerCase(),r=t.toLowerCase(),o=(d)=>{if(d.length===0)return{matches:!0,score:0};if(d.length>r.length)return{matches:!1,score:0};let f=0,y=0,R=-1,ee=0;for(let b=0;b<r.length&&f<d.length;b++)if(r[b]===d[f]){let yt=b===0||/[\s\-_./:]/.test(r[b-1]);if(R===b-1)ee++,y-=ee*5;else if(ee=0,R>=0)y+=(b-R-1)*2;if(yt)y-=10;y+=b*0.1,R=b,f++}if(f<d.length)return{matches:!1,score:0};if(d===r)y-=100;return{matches:!0,score:y}},i=o(n);if(i.matches)return i;let a=n.match(/^(?<letters>[a-z]+)(?<digits>[0-9]+)$/),c=n.match(/^(?<digits>[0-9]+)(?<letters>[a-z]+)$/),s=a?`${a.groups?.digits??""}${a.groups?.letters??""}`:c?`${c.groups?.letters??""}${c.groups?.digits??""}`:"";if(!s)return i;let u=o(s);if(!u.matches)return i;return{matches:!0,score:u.score+5}}function P(e,t,n){if(!t.trim())return e;let r=t.trim().split(/[\s/]+/).filter((i)=>i.length>0);if(r.length===0)return e;let o=[];for(let i of e){let a=n(i),c=0,s=!0;for(let u of r){let d=O(u,a);if(d.matches)c+=d.score;else{s=!1;break}}if(s)o.push({item:i,totalScore:c})}return o.sort((i,a)=>i.totalScore-a.totalScore),o.map((i)=>i.item)}function ge(){document.addEventListener("click",async(e)=>{let t=e.target;if(!(t instanceof Element))return;let n=t.closest("[data-copy-code]");if(!(n instanceof HTMLButtonElement))return;let r=n.closest("[data-code-block]"),o=r?.querySelector("[data-code-source]"),i=r?.querySelector("code"),a=o?.textContent?bt(o.textContent):i?.textContent;if(!a)return;try{await navigator.clipboard.writeText(a),n.dataset.copyState="copied",n.setAttribute("aria-label","Copied"),setTimeout(()=>{delete n.dataset.copyState,n.setAttribute("aria-label","Copy code")},1200)}catch{n.setAttribute("aria-label","Copy failed")}})}function bt(e){let t=document.createElement("textarea");return t.innerHTML=e,t.value}function Ee(){document.addEventListener("input",vt),document.addEventListener("keydown",At),document.addEventListener("mousemove",St),document.addEventListener("click",Lt),k()}function k(e=document){for(let t of wt(e,".command"))Mt(t)}function wt(e,t){let n=[];if(!e)return n;if(e instanceof Element&&e.matches(t))n.push(e);for(let r of e.querySelectorAll?.(t)??[])n.push(r);return n}function U(e){return{input:e.querySelector("header input"),menu:e.querySelector('[role="menu"]')}}function ye(e){return[...e.querySelectorAll('[role="menuitem"]')].filter((t)=>t instanceof HTMLElement&&!Me(t))}function q(e){let{menu:t}=U(e);if(!(t instanceof HTMLElement))return[];return ye(t).filter((n)=>!n.hidden)}function Mt(e){let{input:t,menu:n}=U(e);if(!(t instanceof HTMLInputElement)||!(n instanceof HTMLElement))return;if(e.dataset.filter!=="manual")be(e);else n.scrollTop=0,A(e,q(e)[0])}function be(e){let{input:t,menu:n}=U(e);if(!(t instanceof HTMLInputElement)||!(n instanceof HTMLElement))return;let r=t.value.trim().toLowerCase();for(let i of ye(n)){let a=(i.dataset.filter||i.textContent||"").trim().toLowerCase(),c=(i.dataset.keywords||"").toLowerCase().split(/[\s,]+/),s=i.hasAttribute("data-force")||a.includes(r)||c.some((u)=>u.includes(r));i.hidden=!s}let o=q(e)[0];if(A(e,o),r==="")n.scrollTop=0;else o?.scrollIntoView({block:"nearest"})}function A(e,t){let{input:n,menu:r}=U(e);if(!(n instanceof HTMLInputElement)||!(r instanceof HTMLElement))return;for(let o of r.querySelectorAll('[role="menuitem"].active'))o.classList.remove("active");if(t instanceof HTMLElement)if(t.classList.add("active"),t.id)n.setAttribute("aria-activedescendant",t.id);else n.removeAttribute("aria-activedescendant");else n.removeAttribute("aria-activedescendant")}function xt(e,t){let n=q(e);if(n.length===0)return;let r=n.findIndex((a)=>a.classList.contains("active")),o=r;if(t==="ArrowDown")o=Math.min(r+1,n.length-1);if(t==="ArrowUp")o=Math.max(r<0?0:r-1,0);if(t==="Home")o=0;if(t==="End")o=n.length-1;let i=n[o];A(e,i),i?.scrollIntoView({block:"nearest"})}function we(e){return[...e.querySelectorAll('[role^="menuitem"]')].filter((t)=>t instanceof HTMLElement&&!Me(t))}function Tt(e,t){let n=we(e);if(n.length===0)return;let r=n.indexOf(document.activeElement),o=r;if(t==="ArrowDown")o=Math.min(r+1,n.length-1);if(t==="ArrowUp")o=r<0?n.length-1:Math.max(r-1,0);if(t==="Home")o=0;if(t==="End")o=n.length-1;n[o]?.focus({preventScroll:!0})}function vt(e){if(!(e.target instanceof HTMLInputElement))return;let t=e.target.closest(".command");if(t instanceof HTMLElement&&t.dataset.filter!=="manual")be(t)}function At(e){if(!(e.target instanceof Element))return;let t=e.target.closest(".command");if(t instanceof HTMLElement&&e.target.matches("header input")){if(e.key==="Enter"){let o=q(t).find((i)=>i.classList.contains("active"));if(o)e.preventDefault(),o.click();return}if(["ArrowDown","ArrowUp","Home","End"].includes(e.key)){e.preventDefault(),xt(t,e.key);return}}let n=e.target.closest("[popover][role='menu']");if(n instanceof HTMLElement){if(e.key==="Tab")n.hidePopover();if(["ArrowDown","ArrowUp","Home","End"].includes(e.key))e.preventDefault(),Tt(n,e.key);return}if(!(e.target instanceof HTMLButtonElement))return;let r=e.target.popoverTargetElement;if(r?.matches("[popover][role='menu']")&&["ArrowDown","ArrowUp"].includes(e.key)){e.preventDefault(),e.target.click();let o=we(r);(e.key==="ArrowUp"?o.at(-1):o[0])?.focus({preventScroll:!0})}}function St(e){if(!(e.target instanceof Element))return;let t=e.target.closest('[role="menuitem"]'),n=t?.closest(".command");if(n instanceof HTMLElement&&t instanceof HTMLElement&&!t.hidden)A(n,t)}function Lt(e){if(!(e.target instanceof Element))return;let t=e.target.closest('.command [role="menuitem"]');if(t instanceof HTMLElement&&!t.hasAttribute("data-keep-command-open"))t.closest("dialog")?.close()}function Me(e){return e.hasAttribute("disabled")||e.getAttribute("aria-disabled")==="true"||e.getAttribute("data-disabled")==="true"}function ve(e){let t=new Date(e.dateTime);if(Number.isNaN(t.getTime()))return;e.textContent=xe(t),e.title=Te(t)}var Ht=[60,75,90,100,120,144,165,240];function It(e){if(e.length<9)return;let t=e.slice(6),n=[];for(let s=1;s<t.length;s+=1){let u=t[s]-t[s-1];if(u>=3.666666666666667&&u<=33.333333333333336)n.push(u)}if(n.length<3)return;let r=te(n,0.5),o=n.map((s)=>Math.abs(s-r)),a=te(o,0.5)/r>0.06?te(n,0.25):r,c=Se(1000/a,30,240);return Pt(c)}function Pt(e){let t=Ht.reduce((n,r)=>Math.abs(r-e)<Math.abs(n-e)?r:n);return Math.abs(t-e)/t<=0.08?t:Math.round(Se(e,30,240))}function kt(e){let t=e.sampleFrames??48,n,r,o=[],i,a,c=(f)=>{if(n=void 0,!e.isEligible())return;if(o.push(f),o.length>=t){let y=It(o);if(o=[],y!==void 0)s(y);return}n=e.requestFrame(c)},s=(f)=>{if(i!==void 0&&(Math.abs(i-f)<1||Math.abs(i-f)/i<0.02))return;if(a=f,r!==void 0)e.clearTimer(r);r=e.setTimer(()=>{if(r=void 0,!e.isEligible()||a===void 0)return;i=a,e.send(a),a=void 0},250)};return{restart:()=>{if(n!==void 0)e.cancelFrame(n);if(n=void 0,o=[],e.isEligible())n=e.requestFrame(c)},stop:()=>{if(n!==void 0)e.cancelFrame(n);if(r!==void 0)e.clearTimer(r);n=void 0,r=void 0,o=[],a=void 0}}}function Ae(){let e=kt({requestFrame:(t)=>requestAnimationFrame(t),cancelFrame:(t)=>cancelAnimationFrame(t),isEligible:()=>document.visibilityState==="visible"&&document.hasFocus(),setTimer:(t,n)=>setTimeout(t,n),clearTimer:(t)=>clearTimeout(t),send:(t)=>{document.body.dispatchEvent(new CustomEvent("pi-ui-display-refresh",{detail:{hz:t}}))}});e.restart(),document.addEventListener("visibilitychange",e.restart),window.addEventListener("focus",e.restart),window.addEventListener("pagehide",e.stop,{once:!0})}function te(e,t){let n=[...e].sort((r,o)=>r-o);return n[Math.min(n.length-1,Math.floor((n.length-1)*t))]}function Se(e,t,n){return Math.min(n,Math.max(t,e))}function Le(e){let t=ne(e);return t!==void 0&&/\.html?$/i.test(t)}function ne(e){try{let t=new URL(e);if(t.protocol!=="file:")return;let n=decodeURIComponent(t.pathname);if(t.hostname&&t.hostname.toLowerCase()!=="localhost")return`//${t.hostname}${n}`;if(/^\/[A-Za-z]:(?:\/|$)/.test(n))return n.slice(1);return n}catch{return}}function Ie(){document.addEventListener("click",(e)=>{if(e.button!==0)return;let t=e.target instanceof Element?e.target.closest("a[href]"):null;if(!(t instanceof HTMLAnchorElement))return;let n=t.getAttribute("data-pi-file-link")??"",r=He(n)?n:t.href;if(!He(r))return;if(e.preventDefault(),Le(r)){let o=document.body.dataset.filesOpenEndpoint;if(o)window.open(`${o}?uri=${encodeURIComponent(r)}`,"_blank","noopener,noreferrer")}else Ft(r)},{capture:!0})}function He(e){try{return new URL(e).protocol==="file:"}catch{return!1}}async function Ft(e){let t=document.body.dataset.filesOpenEndpoint;if(!t)return;try{let n=await fetch(t,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({uri:e})});if(!n.ok)throw Error(await Ct(n));let{path:r,workspacePath:o}=await n.json(),{openLinkedWorkspaceFile:i}=await import("./chunks/workspace-review-znycbppp.js");await i(r,o)}catch(n){alert(n instanceof Error?n.message:"Could not open the file.")}}async function Ct(e){try{let t=await e.json();return t.error||t.message||"Could not open the file."}catch{return"Could not open the file."}}var pe={};zt(pe,{canSubmit:()=>ue,composePrompt:()=>Qe,convertAvifToJpeg:()=>Ze,enterDrag:()=>Jt,extractTransferredFilePaths:()=>je,fileWithDetectedMimeType:()=>Je,formatFileReferences:()=>Xe,hasAttachments:()=>We,hasFiles:()=>Yt,insert:()=>Ve,isAvifImageFile:()=>de,isHeicImageFile:()=>fe,jpegFileName:()=>Ge,leaveDrag:()=>Zt,pick:()=>Gt,resetDrag:()=>Xt,submit:()=>Qt});var re={archive:{paths:["M13.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v11.5","M14 2v5a1 1 0 0 0 1 1h5M8 12v-1m0 7v-2m0-9V6"],circle:{cx:8,cy:20,r:2}},audio:{paths:["M17.5 22h.5a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v3","M14 2v4a2 2 0 0 0 2 2h4M2 19a2 2 0 1 1 4 0v1a2 2 0 1 1-4 0v-4a6 6 0 0 1 12 0v4a2 2 0 1 1-4 0v-1a2 2 0 1 1 4 0"]},code:{paths:["M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4","M14 2v4a2 2 0 0 0 2 2h4M5 12l-3 3l3 3m4 0l3-3l-3-3"]},file:{paths:["M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z","M14 2v5a1 1 0 0 0 1 1h5"]},pdf:{paths:["M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4","M14 2v4a2 2 0 0 0 2 2h4M2 13v-1h6v1m-3-1v6m-1 0h2"]},text:{paths:["M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z","M14 2v5a1 1 0 0 0 1 1h5M10 9H8m8 4H8m8 4H8"]},video:{paths:["M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z","M14 2v5a1 1 0 0 0 1 1h5m-4.967 5.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56v-4.704a.645.645 0 0 1 .967-.56z"]}};function Pe(e){return(e.includes(".")?e.split(".").at(-1):"").slice(0,4).toLowerCase()}function ke(e,t){let n=e.split(".").at(-1)?.toLowerCase()??"";if(t==="application/pdf"||n==="pdf")return"pdf";if(t?.startsWith("audio/")||["aac","flac","m4a","mp3","ogg","wav"].includes(n))return"audio";if(t?.startsWith("video/")||["avi","m4v","mkv","mov","mp4","webm"].includes(n))return"video";if(t?.includes("zip")||["7z","bz2","gz","rar","tar","xz","zip"].includes(n))return"archive";if(["c","cpp","css","go","h","html","java","js","json","jsx","py","rs","sh","sql","toml","ts","tsx","xml","yaml","yml"].includes(n)||t==="application/json"||t?.includes("javascript")||t?.includes("xml"))return"code";if(t?.startsWith("text/")||["csv","log","md","rst","txt"].includes(n))return"text";return"file"}function m(){let e=document.getElementById("prompt-input");return e instanceof HTMLTextAreaElement?e:void 0}function _(e){let t=m();if(!t)return;t.value=e,t.dispatchEvent(new Event("input",{bubbles:!0}))}function Fe(){let e=m();if(!e)return;e.focus({preventScroll:!0}),e.selectionStart=e.value.length,e.selectionEnd=e.value.length}function Ce(){document.addEventListener("pointerdown",(e)=>{let t=e.target;if(!(t instanceof Element))return;let n=t.closest("[data-tooltip]");if(!(n instanceof HTMLElement))return;n.setAttribute("data-tooltip-suppressed",""),n.addEventListener("pointerleave",()=>n.removeAttribute("data-tooltip-suppressed"),{once:!0})})}var w,z=!1,oe,De;function Bt(e,t){let n=e.slice(0,t),r=/(?:^|[\s"'=])(@(?:"[^"]*|[^\s"'=]*))$/.exec(n)?.[1];if(!r)return;return{start:t-r.length,end:t,query:r.slice(1)}}function Dt(e,t,n){let r=n.endsWith("/")||n.endsWith('/"'),o=r?"":" ",i=e.slice(t.end),a=t.query.startsWith('"')&&n.endsWith('"')&&i.startsWith('"')?i.slice(1):i,c=`${e.slice(0,t.start)}${n}${o}${a}`,s=r&&n.endsWith('"')?1:0;return{text:c,cursor:t.start+n.length+o.length-s}}function F(){return Ue("prompt-file-popover")}function K(){return F()||Oe()}function Re(e){De=e.fuzzyFilter,document.addEventListener("input",Be),document.addEventListener("selectionchange",Be),document.addEventListener("click",Rt),document.addEventListener("keydown",Ot),document.addEventListener("mousedown",(t)=>{if(t.button===0&&t.target instanceof Element&&t.target.closest("[data-picker-kind]"))t.preventDefault()}),document.addEventListener("focusout",(t)=>{if(t.target===m())T(!0)})}function Be(e){if(!(e.target instanceof HTMLTextAreaElement)||e.target.id!=="prompt-input")return;if(e.isComposing)return;if(e.type==="input")z=!1;ie(e.target)}function ie(e){if(z||document.activeElement!==e)return;let t=Bt(e.value,e.selectionStart);if(!t){se();return}if(w?.start===t.start&&w.end===t.end&&w.query===t.query)return;w=t,clearTimeout(oe),oe=setTimeout(()=>{if(w!==t)return;e.dispatchEvent(new CustomEvent("pi-ui-file-query",{bubbles:!0,detail:{query:t.query}}))},50)}function Rt(e){let t=e.target;if(!(t instanceof Element))return;let n=t.closest('[data-picker-kind="slash"]'),r=t.closest('[data-picker-kind="file"]');if(t.closest("[data-file-trigger]"))e.preventDefault(),qt();else if(t.closest("[data-send-trigger]")||n instanceof HTMLElement)T(!0);else if(r instanceof HTMLElement)e.preventDefault(),Ut(r.dataset.pickerValue??"")}function Ot(e){if(e.target!==m()||e.isComposing||e.ctrlKey||e.metaKey||e.altKey||e.shiftKey||!K())return;if(e.code==="Escape"){e.preventDefault(),T(!0);return}let t=F()?"[data-file-row]":"[data-slash-row]";if(e.code==="ArrowDown"||e.code==="ArrowUp")e.preventDefault(),_t(t,e.code==="ArrowDown"?1:-1);else if(e.code==="Enter")e.preventDefault(),qe(t)?.click()}function Ut(e){let t=m();if(!t||!w)return;let n=Dt(t.value,w,e);if(t.value=n.text,t.selectionStart=n.cursor,t.selectionEnd=n.cursor,t.dispatchEvent(new Event("input",{bubbles:!0})),t.focus(),e.endsWith("/")||e.endsWith('/"'))ie(t);else se()}function qt(){let e=m();if(!e)return;z=!1;let t=e.selectionStart,r=`${t>0&&!/\s/.test(e.value[t-1]??"")?" ":""}@`;e.setRangeText(r,t,e.selectionEnd,"end"),e.dispatchEvent(new Event("input",{bubbles:!0})),e.focus(),ie(e)}function T(e=!1){se(e),m()?.dispatchEvent(new CustomEvent("pi-ui-picker-close",{bubbles:!0}))}function se(e=!1){if(clearTimeout(oe),e)z=!0;w=void 0,m()?.dispatchEvent(new CustomEvent("pi-ui-file-close",{bubbles:!0}))}function Oe(){return Ue("prompt-slash-popover")}function Ue(e){let t=document.getElementById(e);return t instanceof HTMLElement&&t.checkVisibility()}function ae(e){return[...document.querySelectorAll(e)].filter((t)=>t instanceof HTMLElement&&t.checkVisibility())}function qe(e){let t=ae(e);return t.find((n)=>n.getAttribute("aria-selected")==="true")??t[0]}function Nt(e){if(!e.startsWith("/")||e.includes(" "))return;let t=document.getElementById("slash-picker-list");if(!(t instanceof HTMLElement))return;let n=[...t.querySelectorAll("[data-slash-row]")].sort((i,a)=>Number(i.dataset.slashOrder)-Number(a.dataset.slashOrder)),r=De(n,e.slice(1),(i)=>i.dataset.slashName??""),o=new Set(r);t.append(...r,...n.filter((i)=>!o.has(i)))}function $t(e,t,n){if(e<=0)return-1;if(t===-1)return 0;return Math.max(0,Math.min(e-1,t-n))}function _t(e,t){let n=ae(e);if(n.length===0)return;let r=n.findIndex((i)=>i.getAttribute("aria-selected")==="true"),o=$t(n.length,r,t);for(let i of n)i.setAttribute("aria-selected","false");n[o]?.setAttribute("aria-selected","true"),n[o]?.scrollIntoView({block:"nearest",behavior:"instant"}),ce()}function ce(e=!1){queueMicrotask(()=>{let t=m();if(!t)return;let n=F()?"file-picker-list":Oe()?"slash-picker-list":void 0;if(e&&n){if(n==="slash-picker-list")Nt(t.value);document.getElementById(n).scrollTop=0;for(let[o,i]of ae(`#${n} [role="option"]`).entries())i.setAttribute("aria-selected",o===0?"true":"false")}let r=n&&qe(`#${n} [role="option"]`);if(r&&document.activeElement===t)r.setAttribute("aria-selected","true"),t.setAttribute("aria-controls",n),t.setAttribute("aria-activedescendant",r.id);else t.removeAttribute("aria-controls"),t.removeAttribute("aria-activedescendant")})}var Kt=["text/uri-list","x-special/gnome-copied-files","text/plain"],Ne=10,Vt=20971520,Wt=52428800,jt=0.85,C=0,le=!1,g=[];function Yt(e){if(!e)return!1;if(e.files?.length)return!0;return[...e.types].some((t)=>t==="Files"||t==="text/uri-list")}function Gt(){h("");let e=document.createElement("input");e.type="file",e.multiple=!0,e.addEventListener("change",()=>{if(e.files?.length)Ve(e.files)},{once:!0}),e.click()}function Jt(){return C+=1,!0}function Zt(){return C=Math.max(0,C-1),C>0}function Xt(){C=0}async function Ve(e){if(!e)return;h("");let t=Ye(e),n=t.some((s)=>de(s)||fe(s)),r=je(e);if(r.length>0&&!n){let s=tn(r);if(s){h(s);return}on(r);return}if(t.length===0)return;let o=$e(t);if(o){h(o);return}let i;try{i=await en(t)}catch(s){console.error(s),h(s?.message||"Could not prepare the selected images.");return}let a=$e(i);if(a){h(a);return}let c=await rn(i);for(let s=0;s<c.length;s+=1)et({path:c[s].path,file:Je(i[s],c[s].mimeType)})}function We(){return g.length>0}function ue(e){return!le&&(e.trim()!==""||We())}async function Qt(e,t,n){if(!ue(t))return!1;let r=[...g],o=Qe(t,r.map(({path:a})=>a)),i=new FormData;if(i.set("prompt",o),n)i.set("streamingBehavior",n);for(let{file:a}of r)if(a?.type.startsWith("image/"))i.append("image",a,a.name||"pasted-image");le=!0;try{let a=await fetch(e,{method:"POST",body:i});if(await a.text(),!a.ok)throw Error(`Prompt was not accepted (${a.status}).`);return an(r),h(""),!0}catch(a){return sn(t),h(a?.message||"Could not send the prompt."),!1}finally{le=!1,document.getElementById("prompt-box")?.dispatchEvent(new CustomEvent("pi-ui-prompt-submit-finished",{bubbles:!0})),me()}}function je(e){let t="getData"in e?Kt.flatMap((n)=>e.getData(n).split(/\r?\n/)):[];for(let n of Ye(e))t.push(n.path??"",n.webkitRelativePath??"");return[...new Set(t.map(nn).filter(Boolean))]}function Ye(e){if(e.files)return[...e.files];return Array.from(e)}function de(e){return e.type?.toLowerCase()==="image/avif"||/\.avif$/i.test(e.name??"")}function fe(e){return/^(?:image\/)?hei[cf]$/i.test(e.type??"")||/\.hei[cf]$/i.test(e.name??"")}function Ge(e){return/\.avif$/i.test(e)?e.replace(/\.avif$/i,".jpg"):`${e||"image"}.jpg`}function Je(e,t){if(t===void 0||e.type===t)return e;return new File([e],e.name,{type:t??"",lastModified:e.lastModified})}async function en(e){let t=[];for(let n of e){if(fe(n))throw Error("HEIC and HEIF images are not supported. Convert them to JPEG or PNG first.");t.push(de(n)?await Ze(n):n)}return t}async function Ze(e){let t;try{t=await createImageBitmap(e);let n=document.createElement("canvas");n.width=t.width,n.height=t.height;let r=n.getContext("2d");if(!r)throw Error("Canvas image conversion is unavailable.");r.fillStyle="white",r.fillRect(0,0,n.width,n.height),r.drawImage(t,0,0,n.width,n.height);let o=await new Promise((i,a)=>{n.toBlob((c)=>c?i(c):a(Error("JPEG encoding failed.")),"image/jpeg",jt)});return new File([o],Ge(e.name),{type:"image/jpeg",lastModified:e.lastModified})}catch(n){throw Error(`Could not convert ${e.name||"the AVIF image"} to JPEG.`,{cause:n})}finally{t?.close()}}function tn(e){if(e.some((t)=>/\.hei[cf]$/i.test(t)))return"HEIC and HEIF images are not supported. Convert them to JPEG or PNG first.";if(e.some((t)=>/\.avif$/i.test(t)))return"AVIF images must be dropped, pasted, or selected with the browser file picker so they can be converted."}function nn(e){let t=e.trim();if(!t||t.startsWith("#")||t==="copy"||t==="cut")return;let n=ne(t);if(n)return n;if(t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t))return t;return}function $e(e){if(e.length>Ne)return`Attach at most ${Ne} files at a time.`;if(e.some((n)=>n.size>Vt))return"Dropped or pasted files must be 20 MiB or smaller; use the Files button for larger files.";if(e.reduce((n,r)=>n+r.size,0)>Wt)return"Dropped or pasted files must total 50 MiB or less."}async function rn(e){let t=new FormData;for(let n of e)t.append("file",n,n.name||"pasted-file");try{let n=document.body.dataset.filesImportEndpoint,r=await fetch(n,{method:"POST",body:t}),o=await r.json().catch(()=>({}));if(!r.ok)return h(Ke(o.message)?o.message:"Could not transfer the selected files."),[];return h(""),Array.isArray(o.imports)?o.imports:[]}catch{return h("Could not transfer the selected files."),[]}}function h(e){let t=m();if(!t)return;let n=document.getElementById("file-transfer-error");if(!(n instanceof HTMLParagraphElement))n=document.createElement("p"),n.id="file-transfer-error",n.className="file-transfer-error",n.setAttribute("role","alert"),n.setAttribute("aria-live","polite"),t.before(n);n.textContent=e,n.hidden=!e}function Xe(e){return`${e.map((t)=>`@${t}`).join(`
|
|
1
|
+
import{gc as xe,hc as Te}from"./chunks/main-pq3eh5fy.js";import{ic as Ke}from"./chunks/main-b1kpnx3v.js";import{oc as zt,pc as N}from"./chunks/main-jgbmmpjx.js";function O(e,t){let n=e.toLowerCase(),r=t.toLowerCase(),o=(d)=>{if(d.length===0)return{matches:!0,score:0};if(d.length>r.length)return{matches:!1,score:0};let f=0,y=0,R=-1,ee=0;for(let b=0;b<r.length&&f<d.length;b++)if(r[b]===d[f]){let yt=b===0||/[\s\-_./:]/.test(r[b-1]);if(R===b-1)ee++,y-=ee*5;else if(ee=0,R>=0)y+=(b-R-1)*2;if(yt)y-=10;y+=b*0.1,R=b,f++}if(f<d.length)return{matches:!1,score:0};if(d===r)y-=100;return{matches:!0,score:y}},i=o(n);if(i.matches)return i;let a=n.match(/^(?<letters>[a-z]+)(?<digits>[0-9]+)$/),c=n.match(/^(?<digits>[0-9]+)(?<letters>[a-z]+)$/),s=a?`${a.groups?.digits??""}${a.groups?.letters??""}`:c?`${c.groups?.letters??""}${c.groups?.digits??""}`:"";if(!s)return i;let u=o(s);if(!u.matches)return i;return{matches:!0,score:u.score+5}}function P(e,t,n){if(!t.trim())return e;let r=t.trim().split(/[\s/]+/).filter((i)=>i.length>0);if(r.length===0)return e;let o=[];for(let i of e){let a=n(i),c=0,s=!0;for(let u of r){let d=O(u,a);if(d.matches)c+=d.score;else{s=!1;break}}if(s)o.push({item:i,totalScore:c})}return o.sort((i,a)=>i.totalScore-a.totalScore),o.map((i)=>i.item)}function ge(){document.addEventListener("click",async(e)=>{let t=e.target;if(!(t instanceof Element))return;let n=t.closest("[data-copy-code]");if(!(n instanceof HTMLButtonElement))return;let r=n.closest("[data-code-block]"),o=r?.querySelector("[data-code-source]"),i=r?.querySelector("code"),a=o?.textContent?bt(o.textContent):i?.textContent;if(!a)return;try{await navigator.clipboard.writeText(a),n.dataset.copyState="copied",n.setAttribute("aria-label","Copied"),setTimeout(()=>{delete n.dataset.copyState,n.setAttribute("aria-label","Copy code")},1200)}catch{n.setAttribute("aria-label","Copy failed")}})}function bt(e){let t=document.createElement("textarea");return t.innerHTML=e,t.value}function Ee(){document.addEventListener("input",vt),document.addEventListener("keydown",At),document.addEventListener("mousemove",St),document.addEventListener("click",Lt),k()}function k(e=document){for(let t of wt(e,".command"))Mt(t)}function wt(e,t){let n=[];if(!e)return n;if(e instanceof Element&&e.matches(t))n.push(e);for(let r of e.querySelectorAll?.(t)??[])n.push(r);return n}function U(e){return{input:e.querySelector("header input"),menu:e.querySelector('[role="menu"]')}}function ye(e){return[...e.querySelectorAll('[role="menuitem"]')].filter((t)=>t instanceof HTMLElement&&!Me(t))}function q(e){let{menu:t}=U(e);if(!(t instanceof HTMLElement))return[];return ye(t).filter((n)=>!n.hidden)}function Mt(e){let{input:t,menu:n}=U(e);if(!(t instanceof HTMLInputElement)||!(n instanceof HTMLElement))return;if(e.dataset.filter!=="manual")be(e);else n.scrollTop=0,A(e,q(e)[0])}function be(e){let{input:t,menu:n}=U(e);if(!(t instanceof HTMLInputElement)||!(n instanceof HTMLElement))return;let r=t.value.trim().toLowerCase();for(let i of ye(n)){let a=(i.dataset.filter||i.textContent||"").trim().toLowerCase(),c=(i.dataset.keywords||"").toLowerCase().split(/[\s,]+/),s=i.hasAttribute("data-force")||a.includes(r)||c.some((u)=>u.includes(r));i.hidden=!s}let o=q(e)[0];if(A(e,o),r==="")n.scrollTop=0;else o?.scrollIntoView({block:"nearest"})}function A(e,t){let{input:n,menu:r}=U(e);if(!(n instanceof HTMLInputElement)||!(r instanceof HTMLElement))return;for(let o of r.querySelectorAll('[role="menuitem"].active'))o.classList.remove("active");if(t instanceof HTMLElement)if(t.classList.add("active"),t.id)n.setAttribute("aria-activedescendant",t.id);else n.removeAttribute("aria-activedescendant");else n.removeAttribute("aria-activedescendant")}function xt(e,t){let n=q(e);if(n.length===0)return;let r=n.findIndex((a)=>a.classList.contains("active")),o=r;if(t==="ArrowDown")o=Math.min(r+1,n.length-1);if(t==="ArrowUp")o=Math.max(r<0?0:r-1,0);if(t==="Home")o=0;if(t==="End")o=n.length-1;let i=n[o];A(e,i),i?.scrollIntoView({block:"nearest"})}function we(e){return[...e.querySelectorAll('[role^="menuitem"]')].filter((t)=>t instanceof HTMLElement&&!Me(t))}function Tt(e,t){let n=we(e);if(n.length===0)return;let r=n.indexOf(document.activeElement),o=r;if(t==="ArrowDown")o=Math.min(r+1,n.length-1);if(t==="ArrowUp")o=r<0?n.length-1:Math.max(r-1,0);if(t==="Home")o=0;if(t==="End")o=n.length-1;n[o]?.focus({preventScroll:!0})}function vt(e){if(!(e.target instanceof HTMLInputElement))return;let t=e.target.closest(".command");if(t instanceof HTMLElement&&t.dataset.filter!=="manual")be(t)}function At(e){if(!(e.target instanceof Element))return;let t=e.target.closest(".command");if(t instanceof HTMLElement&&e.target.matches("header input")){if(e.key==="Enter"){let o=q(t).find((i)=>i.classList.contains("active"));if(o)e.preventDefault(),o.click();return}if(["ArrowDown","ArrowUp","Home","End"].includes(e.key)){e.preventDefault(),xt(t,e.key);return}}let n=e.target.closest("[popover][role='menu']");if(n instanceof HTMLElement){if(e.key==="Tab")n.hidePopover();if(["ArrowDown","ArrowUp","Home","End"].includes(e.key))e.preventDefault(),Tt(n,e.key);return}if(!(e.target instanceof HTMLButtonElement))return;let r=e.target.popoverTargetElement;if(r?.matches("[popover][role='menu']")&&["ArrowDown","ArrowUp"].includes(e.key)){e.preventDefault(),e.target.click();let o=we(r);(e.key==="ArrowUp"?o.at(-1):o[0])?.focus({preventScroll:!0})}}function St(e){if(!(e.target instanceof Element))return;let t=e.target.closest('[role="menuitem"]'),n=t?.closest(".command");if(n instanceof HTMLElement&&t instanceof HTMLElement&&!t.hidden)A(n,t)}function Lt(e){if(!(e.target instanceof Element))return;let t=e.target.closest('.command [role="menuitem"]');if(t instanceof HTMLElement&&!t.hasAttribute("data-keep-command-open"))t.closest("dialog")?.close()}function Me(e){return e.hasAttribute("disabled")||e.getAttribute("aria-disabled")==="true"||e.getAttribute("data-disabled")==="true"}function ve(e){let t=new Date(e.dateTime);if(Number.isNaN(t.getTime()))return;e.textContent=xe(t),e.title=Te(t)}var Ht=[60,75,90,100,120,144,165,240];function It(e){if(e.length<9)return;let t=e.slice(6),n=[];for(let s=1;s<t.length;s+=1){let u=t[s]-t[s-1];if(u>=3.666666666666667&&u<=33.333333333333336)n.push(u)}if(n.length<3)return;let r=te(n,0.5),o=n.map((s)=>Math.abs(s-r)),a=te(o,0.5)/r>0.06?te(n,0.25):r,c=Se(1000/a,30,240);return Pt(c)}function Pt(e){let t=Ht.reduce((n,r)=>Math.abs(r-e)<Math.abs(n-e)?r:n);return Math.abs(t-e)/t<=0.08?t:Math.round(Se(e,30,240))}function kt(e){let t=e.sampleFrames??48,n,r,o=[],i,a,c=(f)=>{if(n=void 0,!e.isEligible())return;if(o.push(f),o.length>=t){let y=It(o);if(o=[],y!==void 0)s(y);return}n=e.requestFrame(c)},s=(f)=>{if(i!==void 0&&(Math.abs(i-f)<1||Math.abs(i-f)/i<0.02))return;if(a=f,r!==void 0)e.clearTimer(r);r=e.setTimer(()=>{if(r=void 0,!e.isEligible()||a===void 0)return;i=a,e.send(a),a=void 0},250)};return{restart:()=>{if(n!==void 0)e.cancelFrame(n);if(n=void 0,o=[],e.isEligible())n=e.requestFrame(c)},stop:()=>{if(n!==void 0)e.cancelFrame(n);if(r!==void 0)e.clearTimer(r);n=void 0,r=void 0,o=[],a=void 0}}}function Ae(){let e=kt({requestFrame:(t)=>requestAnimationFrame(t),cancelFrame:(t)=>cancelAnimationFrame(t),isEligible:()=>document.visibilityState==="visible"&&document.hasFocus(),setTimer:(t,n)=>setTimeout(t,n),clearTimer:(t)=>clearTimeout(t),send:(t)=>{document.body.dispatchEvent(new CustomEvent("pi-ui-display-refresh",{detail:{hz:t}}))}});e.restart(),document.addEventListener("visibilitychange",e.restart),window.addEventListener("focus",e.restart),window.addEventListener("pagehide",e.stop,{once:!0})}function te(e,t){let n=[...e].sort((r,o)=>r-o);return n[Math.min(n.length-1,Math.floor((n.length-1)*t))]}function Se(e,t,n){return Math.min(n,Math.max(t,e))}function Le(e){let t=ne(e);return t!==void 0&&/\.html?$/i.test(t)}function ne(e){try{let t=new URL(e);if(t.protocol!=="file:")return;let n=decodeURIComponent(t.pathname);if(t.hostname&&t.hostname.toLowerCase()!=="localhost")return`//${t.hostname}${n}`;if(/^\/[A-Za-z]:(?:\/|$)/.test(n))return n.slice(1);return n}catch{return}}function Ie(){document.addEventListener("click",(e)=>{if(e.button!==0)return;let t=e.target instanceof Element?e.target.closest("a[href]"):null;if(!(t instanceof HTMLAnchorElement))return;let n=t.getAttribute("data-pi-file-link")??"",r=He(n)?n:t.href;if(!He(r))return;if(e.preventDefault(),Le(r)){let o=document.body.dataset.filesOpenEndpoint;if(o)window.open(`${o}?uri=${encodeURIComponent(r)}`,"_blank","noopener,noreferrer")}else Ft(r)},{capture:!0})}function He(e){try{return new URL(e).protocol==="file:"}catch{return!1}}async function Ft(e){let t=document.body.dataset.filesOpenEndpoint;if(!t)return;try{let n=await fetch(t,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({uri:e})});if(!n.ok)throw Error(await Ct(n));let{path:r,workspacePath:o}=await n.json(),{openLinkedWorkspaceFile:i}=await import("./chunks/workspace-review-12dvn9pf.js");await i(r,o)}catch(n){alert(n instanceof Error?n.message:"Could not open the file.")}}async function Ct(e){try{let t=await e.json();return t.error||t.message||"Could not open the file."}catch{return"Could not open the file."}}var pe={};zt(pe,{canSubmit:()=>ue,composePrompt:()=>Qe,convertAvifToJpeg:()=>Ze,enterDrag:()=>Jt,extractTransferredFilePaths:()=>je,fileWithDetectedMimeType:()=>Je,formatFileReferences:()=>Xe,hasAttachments:()=>We,hasFiles:()=>Yt,insert:()=>Ve,isAvifImageFile:()=>de,isHeicImageFile:()=>fe,jpegFileName:()=>Ge,leaveDrag:()=>Zt,pick:()=>Gt,resetDrag:()=>Xt,submit:()=>Qt});var re={archive:{paths:["M13.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v11.5","M14 2v5a1 1 0 0 0 1 1h5M8 12v-1m0 7v-2m0-9V6"],circle:{cx:8,cy:20,r:2}},audio:{paths:["M17.5 22h.5a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v3","M14 2v4a2 2 0 0 0 2 2h4M2 19a2 2 0 1 1 4 0v1a2 2 0 1 1-4 0v-4a6 6 0 0 1 12 0v4a2 2 0 1 1-4 0v-1a2 2 0 1 1 4 0"]},code:{paths:["M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4","M14 2v4a2 2 0 0 0 2 2h4M5 12l-3 3l3 3m4 0l3-3l-3-3"]},file:{paths:["M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z","M14 2v5a1 1 0 0 0 1 1h5"]},pdf:{paths:["M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4","M14 2v4a2 2 0 0 0 2 2h4M2 13v-1h6v1m-3-1v6m-1 0h2"]},text:{paths:["M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z","M14 2v5a1 1 0 0 0 1 1h5M10 9H8m8 4H8m8 4H8"]},video:{paths:["M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z","M14 2v5a1 1 0 0 0 1 1h5m-4.967 5.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56v-4.704a.645.645 0 0 1 .967-.56z"]}};function Pe(e){return(e.includes(".")?e.split(".").at(-1):"").slice(0,4).toLowerCase()}function ke(e,t){let n=e.split(".").at(-1)?.toLowerCase()??"";if(t==="application/pdf"||n==="pdf")return"pdf";if(t?.startsWith("audio/")||["aac","flac","m4a","mp3","ogg","wav"].includes(n))return"audio";if(t?.startsWith("video/")||["avi","m4v","mkv","mov","mp4","webm"].includes(n))return"video";if(t?.includes("zip")||["7z","bz2","gz","rar","tar","xz","zip"].includes(n))return"archive";if(["c","cpp","css","go","h","html","java","js","json","jsx","py","rs","sh","sql","toml","ts","tsx","xml","yaml","yml"].includes(n)||t==="application/json"||t?.includes("javascript")||t?.includes("xml"))return"code";if(t?.startsWith("text/")||["csv","log","md","rst","txt"].includes(n))return"text";return"file"}function m(){let e=document.getElementById("prompt-input");return e instanceof HTMLTextAreaElement?e:void 0}function _(e){let t=m();if(!t)return;t.value=e,t.dispatchEvent(new Event("input",{bubbles:!0}))}function Fe(){let e=m();if(!e)return;e.focus({preventScroll:!0}),e.selectionStart=e.value.length,e.selectionEnd=e.value.length}function Ce(){document.addEventListener("pointerdown",(e)=>{let t=e.target;if(!(t instanceof Element))return;let n=t.closest("[data-tooltip]");if(!(n instanceof HTMLElement))return;n.setAttribute("data-tooltip-suppressed",""),n.addEventListener("pointerleave",()=>n.removeAttribute("data-tooltip-suppressed"),{once:!0})})}var w,z=!1,oe,De;function Bt(e,t){let n=e.slice(0,t),r=/(?:^|[\s"'=])(@(?:"[^"]*|[^\s"'=]*))$/.exec(n)?.[1];if(!r)return;return{start:t-r.length,end:t,query:r.slice(1)}}function Dt(e,t,n){let r=n.endsWith("/")||n.endsWith('/"'),o=r?"":" ",i=e.slice(t.end),a=t.query.startsWith('"')&&n.endsWith('"')&&i.startsWith('"')?i.slice(1):i,c=`${e.slice(0,t.start)}${n}${o}${a}`,s=r&&n.endsWith('"')?1:0;return{text:c,cursor:t.start+n.length+o.length-s}}function F(){return Ue("prompt-file-popover")}function K(){return F()||Oe()}function Re(e){De=e.fuzzyFilter,document.addEventListener("input",Be),document.addEventListener("selectionchange",Be),document.addEventListener("click",Rt),document.addEventListener("keydown",Ot),document.addEventListener("mousedown",(t)=>{if(t.button===0&&t.target instanceof Element&&t.target.closest("[data-picker-kind]"))t.preventDefault()}),document.addEventListener("focusout",(t)=>{if(t.target===m())T(!0)})}function Be(e){if(!(e.target instanceof HTMLTextAreaElement)||e.target.id!=="prompt-input")return;if(e.isComposing)return;if(e.type==="input")z=!1;ie(e.target)}function ie(e){if(z||document.activeElement!==e)return;let t=Bt(e.value,e.selectionStart);if(!t){se();return}if(w?.start===t.start&&w.end===t.end&&w.query===t.query)return;w=t,clearTimeout(oe),oe=setTimeout(()=>{if(w!==t)return;e.dispatchEvent(new CustomEvent("pi-ui-file-query",{bubbles:!0,detail:{query:t.query}}))},50)}function Rt(e){let t=e.target;if(!(t instanceof Element))return;let n=t.closest('[data-picker-kind="slash"]'),r=t.closest('[data-picker-kind="file"]');if(t.closest("[data-file-trigger]"))e.preventDefault(),qt();else if(t.closest("[data-send-trigger]")||n instanceof HTMLElement)T(!0);else if(r instanceof HTMLElement)e.preventDefault(),Ut(r.dataset.pickerValue??"")}function Ot(e){if(e.target!==m()||e.isComposing||e.ctrlKey||e.metaKey||e.altKey||e.shiftKey||!K())return;if(e.code==="Escape"){e.preventDefault(),T(!0);return}let t=F()?"[data-file-row]":"[data-slash-row]";if(e.code==="ArrowDown"||e.code==="ArrowUp")e.preventDefault(),_t(t,e.code==="ArrowDown"?1:-1);else if(e.code==="Enter")e.preventDefault(),qe(t)?.click()}function Ut(e){let t=m();if(!t||!w)return;let n=Dt(t.value,w,e);if(t.value=n.text,t.selectionStart=n.cursor,t.selectionEnd=n.cursor,t.dispatchEvent(new Event("input",{bubbles:!0})),t.focus(),e.endsWith("/")||e.endsWith('/"'))ie(t);else se()}function qt(){let e=m();if(!e)return;z=!1;let t=e.selectionStart,r=`${t>0&&!/\s/.test(e.value[t-1]??"")?" ":""}@`;e.setRangeText(r,t,e.selectionEnd,"end"),e.dispatchEvent(new Event("input",{bubbles:!0})),e.focus(),ie(e)}function T(e=!1){se(e),m()?.dispatchEvent(new CustomEvent("pi-ui-picker-close",{bubbles:!0}))}function se(e=!1){if(clearTimeout(oe),e)z=!0;w=void 0,m()?.dispatchEvent(new CustomEvent("pi-ui-file-close",{bubbles:!0}))}function Oe(){return Ue("prompt-slash-popover")}function Ue(e){let t=document.getElementById(e);return t instanceof HTMLElement&&t.checkVisibility()}function ae(e){return[...document.querySelectorAll(e)].filter((t)=>t instanceof HTMLElement&&t.checkVisibility())}function qe(e){let t=ae(e);return t.find((n)=>n.getAttribute("aria-selected")==="true")??t[0]}function Nt(e){if(!e.startsWith("/")||e.includes(" "))return;let t=document.getElementById("slash-picker-list");if(!(t instanceof HTMLElement))return;let n=[...t.querySelectorAll("[data-slash-row]")].sort((i,a)=>Number(i.dataset.slashOrder)-Number(a.dataset.slashOrder)),r=De(n,e.slice(1),(i)=>i.dataset.slashName??""),o=new Set(r);t.append(...r,...n.filter((i)=>!o.has(i)))}function $t(e,t,n){if(e<=0)return-1;if(t===-1)return 0;return Math.max(0,Math.min(e-1,t-n))}function _t(e,t){let n=ae(e);if(n.length===0)return;let r=n.findIndex((i)=>i.getAttribute("aria-selected")==="true"),o=$t(n.length,r,t);for(let i of n)i.setAttribute("aria-selected","false");n[o]?.setAttribute("aria-selected","true"),n[o]?.scrollIntoView({block:"nearest",behavior:"instant"}),ce()}function ce(e=!1){queueMicrotask(()=>{let t=m();if(!t)return;let n=F()?"file-picker-list":Oe()?"slash-picker-list":void 0;if(e&&n){if(n==="slash-picker-list")Nt(t.value);document.getElementById(n).scrollTop=0;for(let[o,i]of ae(`#${n} [role="option"]`).entries())i.setAttribute("aria-selected",o===0?"true":"false")}let r=n&&qe(`#${n} [role="option"]`);if(r&&document.activeElement===t)r.setAttribute("aria-selected","true"),t.setAttribute("aria-controls",n),t.setAttribute("aria-activedescendant",r.id);else t.removeAttribute("aria-controls"),t.removeAttribute("aria-activedescendant")})}var Kt=["text/uri-list","x-special/gnome-copied-files","text/plain"],Ne=10,Vt=20971520,Wt=52428800,jt=0.85,C=0,le=!1,g=[];function Yt(e){if(!e)return!1;if(e.files?.length)return!0;return[...e.types].some((t)=>t==="Files"||t==="text/uri-list")}function Gt(){h("");let e=document.createElement("input");e.type="file",e.multiple=!0,e.addEventListener("change",()=>{if(e.files?.length)Ve(e.files)},{once:!0}),e.click()}function Jt(){return C+=1,!0}function Zt(){return C=Math.max(0,C-1),C>0}function Xt(){C=0}async function Ve(e){if(!e)return;h("");let t=Ye(e),n=t.some((s)=>de(s)||fe(s)),r=je(e);if(r.length>0&&!n){let s=tn(r);if(s){h(s);return}on(r);return}if(t.length===0)return;let o=$e(t);if(o){h(o);return}let i;try{i=await en(t)}catch(s){console.error(s),h(s?.message||"Could not prepare the selected images.");return}let a=$e(i);if(a){h(a);return}let c=await rn(i);for(let s=0;s<c.length;s+=1)et({path:c[s].path,file:Je(i[s],c[s].mimeType)})}function We(){return g.length>0}function ue(e){return!le&&(e.trim()!==""||We())}async function Qt(e,t,n){if(!ue(t))return!1;let r=[...g],o=Qe(t,r.map(({path:a})=>a)),i=new FormData;if(i.set("prompt",o),n)i.set("streamingBehavior",n);for(let{file:a}of r)if(a?.type.startsWith("image/"))i.append("image",a,a.name||"pasted-image");le=!0;try{let a=await fetch(e,{method:"POST",body:i});if(await a.text(),!a.ok)throw Error(`Prompt was not accepted (${a.status}).`);return an(r),h(""),!0}catch(a){return sn(t),h(a?.message||"Could not send the prompt."),!1}finally{le=!1,document.getElementById("prompt-box")?.dispatchEvent(new CustomEvent("pi-ui-prompt-submit-finished",{bubbles:!0})),me()}}function je(e){let t="getData"in e?Kt.flatMap((n)=>e.getData(n).split(/\r?\n/)):[];for(let n of Ye(e))t.push(n.path??"",n.webkitRelativePath??"");return[...new Set(t.map(nn).filter(Boolean))]}function Ye(e){if(e.files)return[...e.files];return Array.from(e)}function de(e){return e.type?.toLowerCase()==="image/avif"||/\.avif$/i.test(e.name??"")}function fe(e){return/^(?:image\/)?hei[cf]$/i.test(e.type??"")||/\.hei[cf]$/i.test(e.name??"")}function Ge(e){return/\.avif$/i.test(e)?e.replace(/\.avif$/i,".jpg"):`${e||"image"}.jpg`}function Je(e,t){if(t===void 0||e.type===t)return e;return new File([e],e.name,{type:t??"",lastModified:e.lastModified})}async function en(e){let t=[];for(let n of e){if(fe(n))throw Error("HEIC and HEIF images are not supported. Convert them to JPEG or PNG first.");t.push(de(n)?await Ze(n):n)}return t}async function Ze(e){let t;try{t=await createImageBitmap(e);let n=document.createElement("canvas");n.width=t.width,n.height=t.height;let r=n.getContext("2d");if(!r)throw Error("Canvas image conversion is unavailable.");r.fillStyle="white",r.fillRect(0,0,n.width,n.height),r.drawImage(t,0,0,n.width,n.height);let o=await new Promise((i,a)=>{n.toBlob((c)=>c?i(c):a(Error("JPEG encoding failed.")),"image/jpeg",jt)});return new File([o],Ge(e.name),{type:"image/jpeg",lastModified:e.lastModified})}catch(n){throw Error(`Could not convert ${e.name||"the AVIF image"} to JPEG.`,{cause:n})}finally{t?.close()}}function tn(e){if(e.some((t)=>/\.hei[cf]$/i.test(t)))return"HEIC and HEIF images are not supported. Convert them to JPEG or PNG first.";if(e.some((t)=>/\.avif$/i.test(t)))return"AVIF images must be dropped, pasted, or selected with the browser file picker so they can be converted."}function nn(e){let t=e.trim();if(!t||t.startsWith("#")||t==="copy"||t==="cut")return;let n=ne(t);if(n)return n;if(t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t))return t;return}function $e(e){if(e.length>Ne)return`Attach at most ${Ne} files at a time.`;if(e.some((n)=>n.size>Vt))return"Dropped or pasted files must be 20 MiB or smaller; use the Files button for larger files.";if(e.reduce((n,r)=>n+r.size,0)>Wt)return"Dropped or pasted files must total 50 MiB or less."}async function rn(e){let t=new FormData;for(let n of e)t.append("file",n,n.name||"pasted-file");try{let n=document.body.dataset.filesImportEndpoint,r=await fetch(n,{method:"POST",body:t}),o=await r.json().catch(()=>({}));if(!r.ok)return h(Ke(o.message)?o.message:"Could not transfer the selected files."),[];return h(""),Array.isArray(o.imports)?o.imports:[]}catch{return h("Could not transfer the selected files."),[]}}function h(e){let t=m();if(!t)return;let n=document.getElementById("file-transfer-error");if(!(n instanceof HTMLParagraphElement))n=document.createElement("p"),n.id="file-transfer-error",n.className="file-transfer-error",n.setAttribute("role","alert"),n.setAttribute("aria-live","polite"),t.before(n);n.textContent=e,n.hidden=!e}function Xe(e){return`${e.map((t)=>`@${t}`).join(`
|
|
2
2
|
`)}
|
|
3
3
|
`}function Qe(e,t){let n=Xe(t);return e.trim()?`${n}${e}`:n.trimEnd()}function on(e){for(let t of e)et({path:t})}function et({path:e,file:t}){if(!e||g.some((n)=>n.path===e))return;g.push({path:e,file:t,previewUrl:t?.type.startsWith("image/")?URL.createObjectURL(t):void 0}),me(),m()?.focus(),T(!0)}function sn(e){let t=m();if(!t||t.value!==""||!e)return;t.value=e,t.dispatchEvent(new Event("input",{bubbles:!0}))}function an(e){for(let t of e){let n=g.indexOf(t);if(n<0)continue;if(g.splice(n,1),t.previewUrl)URL.revokeObjectURL(t.previewUrl)}}function _e(e){let t=g.findIndex((r)=>r.path===e);if(t<0)return;let[n]=g.splice(t,1);if(n.previewUrl)URL.revokeObjectURL(n.previewUrl);me()}function me(){let e=document.getElementById("prompt-attachments");if(!(e instanceof HTMLElement))return;e.replaceChildren(...g.map(cn)),e.hidden=g.length===0;let t=document.querySelector("[data-send-trigger]");if(t instanceof HTMLButtonElement)t.disabled=!ue(m()?.value??"")}function cn(e){let t=e.file?.name||ln(e.path);if(e.previewUrl){let u=document.createElement("button");u.type="button",u.className="prompt-attachment prompt-attachment-image",u.setAttribute("aria-label",`Remove ${t}`),u.addEventListener("click",()=>_e(e.path));let d=document.createElement("span");d.className="prompt-attachment-preview";let f=document.createElement("img");return f.className="prompt-attachment-image-content",f.style.overflowClipMargin="unset",f.src=e.previewUrl,f.alt=t,d.append(f),u.append(d,ze()),u}let n=document.createElement("button");n.type="button",n.className="prompt-attachment prompt-attachment-file",n.setAttribute("aria-label",`Remove ${t}`),n.addEventListener("click",()=>_e(e.path));let r=Pe(t),o=ke(t,e.file?.type),i=document.createElement("span");if(i.className="prompt-attachment-file-icon",i.dataset.fileKind=o,i.append(un(o)),r){let u=document.createElement("span");u.className="prompt-attachment-extension",u.textContent=r,i.append(u)}n.append(i);let a=document.createElement("span");a.className="prompt-attachment-details";let c=document.createElement("span");c.className="prompt-attachment-name",c.textContent=t,a.append(c);let s=document.createElement("span");return s.className="prompt-attachment-meta",s.textContent=e.file?dn(e.file.size):"local file",a.append(s),n.append(a,ze()),n}function ze(){let e=document.createElement("span");return e.className="prompt-attachment-remove",e.textContent="×",e.setAttribute("aria-hidden","true"),e}function ln(e){return e.split(/[\\/]/).filter(Boolean).at(-1)||e}function un(e){let n=re[e]??re.file,r=document.createElementNS("http://www.w3.org/2000/svg","svg");r.setAttribute("class","size-5"),r.setAttribute("viewBox","0 0 24 24"),r.setAttribute("fill","none"),r.setAttribute("stroke","currentColor"),r.setAttribute("stroke-linecap","round"),r.setAttribute("stroke-linejoin","round"),r.setAttribute("stroke-width","2"),r.setAttribute("aria-hidden","true");for(let o of n.paths){let i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d",o),r.append(i)}if(n.circle){let o=document.createElementNS("http://www.w3.org/2000/svg","circle");for(let[i,a]of Object.entries(n.circle))o.setAttribute(i,String(a));r.append(o)}return r}function dn(e){if(e<1024)return`${e} B`;if(e<1048576)return`${(e/1024).toFixed(1)} KiB`;return`${(e/1048576).toFixed(1)} MiB`}var l={middleScrolling:!1,pinnedToBottom:!0,pointerScrolling:!1,rearmOnBottom:!1,scrollTop:0},Y=new Set,M,D=!1,V,W,B,S;function tt(){document.addEventListener("scroll",(t)=>{let n=document.getElementById("messages");if(!(n instanceof HTMLElement)||t.target!==n)return;if((l.middleScrolling||l.pointerScrolling)&&n.scrollTop<l.scrollTop)E();let r=n.scrollHeight-n.scrollTop-n.clientHeight;if(gn(l.pinnedToBottom,l.scrollTop,n.scrollTop,r,l.middleScrolling||l.rearmOnBottom||l.pointerScrolling))l.pinnedToBottom=!0;if(D&&M)M.userScrollDelta+=n.scrollTop-M.lastScrollTop,M.lastScrollTop=n.scrollTop;l.scrollTop=n.scrollTop,l.rearmOnBottom=!1,H()},!0);let e=(t)=>{if(t.button===1)l.middleScrolling=!0,E();else if(t.button===0&&j(t.target)){l.middleScrolling=!1,l.pointerScrolling=!0,S={x:t.clientX,y:t.clientY};let n=document.getElementById("messages");if(n instanceof HTMLElement)l.scrollTop=n.scrollTop}};document.addEventListener("pointerdown",e,{capture:!0,passive:!0}),document.addEventListener("pointermove",(t)=>{if(l.pointerScrolling&&S&&hn(S.x,S.y,t.clientX,t.clientY))S=void 0,E()},{capture:!0,passive:!0});for(let t of["pointerup","pointercancel"])document.addEventListener(t,()=>{l.pointerScrolling=!1,S=void 0},{capture:!0,passive:!0});for(let t of["mousedown","auxclick"])document.addEventListener(t,(n)=>{if(n.button===1)l.middleScrolling=!0,E()},{capture:!0,passive:!0});document.addEventListener("wheel",(t)=>{if(!j(t.target))return;if(l.middleScrolling=!1,t.deltaY<0)E();else if(t.deltaY>0)l.rearmOnBottom=!0},{capture:!0,passive:!0}),document.addEventListener("touchmove",(t)=>{if(j(t.target))E()},{capture:!0,passive:!0}),document.addEventListener("keydown",(t)=>{if(En(t)&&j(t.target))E()},!0),he(),L()}function nt(){if(D)return!1;let e=document.getElementById("messages");if(!(e instanceof HTMLElement))return!1;let t=e.getBoundingClientRect(),n=pn(e,t);return M={lastScrollTop:e.scrollTop,message:n,offset:n?n.getBoundingClientRect().top-t.top:void 0,pinnedToBottom:l.pinnedToBottom,scrollHeight:e.scrollHeight,scrollTop:e.scrollTop,userScrollDelta:0},D=!0,e.style.overflowAnchor="none",H(),!0}function rt(){let e=M;M=void 0,D=!1;let t=document.getElementById("messages");if(!(t instanceof HTMLElement))return;if(!e){t.style.removeProperty("overflow-anchor");return}if(e.pinnedToBottom&&l.pinnedToBottom){t.style.removeProperty("overflow-anchor"),L();return}let n=e.message;if(n instanceof HTMLElement&&t.contains(n)&&e.offset!==void 0){let r=n.getBoundingClientRect().top-t.getBoundingClientRect().top,o=e.offset-e.userScrollDelta;t.scrollTop=fn(t.scrollTop,r,o)}else t.scrollTop=e.scrollTop+e.userScrollDelta+t.scrollHeight-e.scrollHeight;t.style.removeProperty("overflow-anchor"),l.scrollTop=t.scrollTop,H()}function ot(){if(!l.pinnedToBottom)return;let e=document.getElementById("messages"),t=document.getElementById("messages-trim");if(!(e instanceof HTMLElement)||!(t instanceof HTMLButtonElement))return;let n=[...document.querySelectorAll("#message-list > [data-message-id]")],r=n.length-100,o=n[r-1];if(!o||!mn(l.pinnedToBottom,r,o.getBoundingClientRect().bottom,e.getBoundingClientRect().top))return;t.click()}function fn(e,t,n){return e+t-n}function mn(e,t,n,r){return e&&t>0&&n<=r}function pn(e,t){for(let n of[8,32,64,128])for(let r of[0.25,0.5,0.75]){let o=document.elementFromPoint(t.left+t.width*r,t.top+n)?.closest("[data-message-id]");if(o instanceof HTMLElement&&e.contains(o))return o}return[...e.querySelectorAll("[data-message-id]")].find((n)=>n.getBoundingClientRect().bottom>t.top)}function hn(e,t,n,r){return Math.hypot(n-e,r-t)>=8}function gn(e,t,n,r,o){return!e&&o&&n>t&&r<=8}function L(e="auto"){it(),M=void 0,D=!1,l.middleScrolling=!1,l.pinnedToBottom=!0,l.pointerScrolling=!1,l.rearmOnBottom=!1;let t=()=>{let n=document.getElementById("messages");if(!(n instanceof HTMLElement)||!l.pinnedToBottom)return;n.style.removeProperty("overflow-anchor"),n.scrollTo({top:n.scrollHeight,behavior:e}),H()};if(t(),e==="auto")for(let n of[16,80,180]){let r=setTimeout(()=>{Y.delete(r),t()},n);Y.add(r)}}function E(){it(),l.pinnedToBottom=!1,l.rearmOnBottom=!1;let e=document.getElementById("messages");if(e instanceof HTMLElement)l.scrollTop=e.scrollTop;H()}function it(){for(let e of Y)clearTimeout(e);Y.clear()}function j(e){let t=document.getElementById("messages");return t instanceof HTMLElement&&e instanceof Node&&t.contains(e)}function En(e){return e.key==="ArrowUp"||e.key==="PageUp"||e.key==="Home"||e.key===" "&&e.shiftKey}function he(){let e=document.querySelector("#messages > .messages-stack"),t=document.getElementById("prompt-box");if(!(e instanceof HTMLElement)||!(t instanceof HTMLElement))return;if(e===V&&t===W)return;if(B??=new ResizeObserver(()=>{yn();let n=document.getElementById("messages");if(n instanceof HTMLElement&&l.pinnedToBottom)n.scrollTop=n.scrollHeight;H()}),V)B.unobserve(V);if(W)B.unobserve(W);V=e,W=t,B.observe(e),B.observe(t)}function yn(){let e=document.getElementById("prompt-box"),t=document.getElementById("messages-prompt-spacer");if(!(e instanceof HTMLElement)||!(t instanceof HTMLElement))return;let n=`${e.offsetHeight+48}px`;if(t.style.height!==n)t.style.height=n}function H(){let e=document.getElementById("messages"),t=document.getElementById("messages-latest");if(!(e instanceof HTMLElement)||!(t instanceof HTMLButtonElement))return;let n=e.scrollHeight-e.scrollTop-e.clientHeight,r=!l.pinnedToBottom&&n>=48;t.hidden=!r,t.inert=!r,t.tabIndex=r?0:-1}function st(e){if(!(e instanceof HTMLElement))return;let t=e.querySelector('template[shadowrootmode="open"]');if(!(t instanceof HTMLTemplateElement))return;(e.shadowRoot??e.attachShadow({mode:"open"})).append(t.content.cloneNode(!0)),t.remove()}function at(e,t){if(!(e instanceof HTMLInputElement))return;let n=e.closest(".command");if(!(n instanceof HTMLElement))return;let o=[...n.querySelectorAll('[role="menuitem"]')].filter((s)=>s instanceof HTMLElement).toSorted((s,u)=>Number(s.dataset.modelSearchOrder)-Number(u.dataset.modelSearchOrder)),i=P(o,t,(s)=>bn(s.dataset.filter??"",s.dataset.keywords??"")),a=new Set(i),c=t.trim()?[...i,...o.filter((s)=>!a.has(s))]:o;for(let s of c)s.classList.remove("active"),s.hidden=!a.has(s),s.parentElement?.append(s);k(n)}function bn(e,t){return`${t.replace(/([\p{Ll}\d])(\p{Lu})/gu,"$1 $2")} ${e} ${t}`}class ct{#t=[];#e=-1;#n="";#r="";sync(e){let t=JSON.stringify(e);if(t===this.#r)return;this.#r=t,this.#t=e,this.reset()}get browsing(){return this.#e>=0}reset(){this.#e=-1,this.#n=""}navigate(e,t){if(t==="up"){if(!this.browsing){if(e!==""||this.#t.length===0)return;this.#n=e,this.#e=0}else if(this.#e<this.#t.length-1)this.#e+=1;return{value:this.#t[this.#e],cursor:"start"}}if(!this.browsing)return;if(this.#e>0)return this.#e-=1,{value:this.#t[this.#e],cursor:"end"};let n=this.#n;return this.reset(),{value:n,cursor:"end"}}}function lt(){let e=new ct,t=!1;function n(o,i){if(o.isComposing||o.defaultPrevented||o.altKey||o.ctrlKey||o.metaKey||o.shiftKey||o.code!=="ArrowUp"&&o.code!=="ArrowDown")return!1;let a=m();if(o.target!==a||window.piUi.pickers.isOpen())return!1;if(e.sync(Array.isArray(i)?i:[]),e.browsing&&!wn(a,o.code))return!1;let c=e.navigate(a.value,o.code==="ArrowUp"?"up":"down");if(!c)return!1;o.preventDefault(),t=!0,_(c.value),t=!1;let s=c.cursor==="start"?0:a.value.length;return a.selectionStart=s,a.selectionEnd=s,!0}function r(){if(!t)e.reset()}return{handleInput:r,handleKeydown:n}}function wn(e,t){if(e.selectionStart!==e.selectionEnd)return!1;if(t==="ArrowUp"){let r=e.value.indexOf(`
|
|
4
4
|
`);return r<0||e.selectionStart<=r}let n=e.value.lastIndexOf(`
|
|
5
|
-
`)+1;return e.selectionEnd>=n}var x;function ut(){if(!document.getElementById("session-transition")?.hasAttribute("data-session-performance-enabled"))return;x={startedAt:performance.now()}}function dt(e,t){if(!x)return;let n=performance.now();if(e==="loading"){x.generation=Number(t),x.loadingAt??=n;return}if(e!=="idle"||x.generation!==Number(t)||x.loadingAt===void 0)return;let r=x;x=void 0,ft(r,Number(t),n)}function ft(e,t,n){requestAnimationFrame(()=>{let r=document.getElementById("session-transition"),o=document.getElementById("messages");if(r&&o&&getComputedStyle(r).display==="none"&&getComputedStyle(o).display!=="none"){requestAnimationFrame(()=>{let i={generation:t,clickToLoadingMs:e.loadingAt-e.startedAt,clickToMorphMs:n-e.startedAt,clickToPaintMs:performance.now()-e.startedAt};document.body.dispatchEvent(new CustomEvent("pi-ui-session-performance",{detail:i}))});return}if(performance.now()-e.startedAt<60000)ft(e,t,n)})}var X=100,pt=120,Mn=17,xn=33.333333333333336,p,v,G=0,I=0,Q=!1,J=0,Z=0;function ht(){let e=!1;document.addEventListener("keydown",(t)=>{if(t.defaultPrevented||t.ctrlKey||t.metaKey||t.altKey||Tn(t)){e=!1;return}if(document.querySelector(":modal"))return;if(e){if(e=!1,t.code==="KeyG"&&!t.shiftKey){t.preventDefault(),mt("top");return}}if(t.code==="KeyG"&&!t.shiftKey)t.preventDefault(),e=!0;else if(t.code==="KeyG"&&t.shiftKey)t.preventDefault(),mt("bottom");else if(t.code==="KeyJ"||t.code==="KeyK")t.preventDefault(),An(t.code==="KeyJ"?X:-X)}),document.addEventListener("keyup",(t)=>{if(t.code==="KeyJ"||t.code==="KeyK")Q=!1})}function Tn(e){return vn(e.composedPath()[0])}function vn(e){return e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement||e instanceof HTMLElement&&e.isContentEditable}function An(e){if(p&&v!==void 0)cancelAnimationFrame(p),p=void 0,v=void 0;let t=Math.sign(e);if(!p||I!==t)I=t,J=0,Z=0,G=0;Q=!0,Sn(),E()}function mt(e){let t=document.getElementById("messages");if(!(t instanceof HTMLElement))return;if(I=0,Q=!1,v=e==="top"?0:t.scrollHeight-t.clientHeight,Ln(e),e==="top")E()}function Sn(){if(p)return;let e=(t)=>{let n=document.getElementById("messages");if(!(n instanceof HTMLElement)||!I){p=void 0;return}let r=G?Math.min(Math.max(t-G,0),xn):Mn;G=t;let o=n.scrollHeight-n.clientHeight,i=I*(X*r/pt)+Z,a=n.scrollTop,c=Math.max(0,Math.min(a+i,o));n.scrollTop=c;let s=c-a;if(Z=i-s,J+=Math.abs(s),c===0||c===o||!Q&&J>=X){I=0,J=0,Z=0,p=void 0;return}p=requestAnimationFrame(e)};p=requestAnimationFrame(e)}function Ln(e){if(p)cancelAnimationFrame(p);let t=document.getElementById("messages");if(!(t instanceof HTMLElement)||v===void 0)return;let n=t.scrollTop,r=Math.max(0,Math.min(v,t.scrollHeight-t.clientHeight)),o=Math.max(pt,20*Math.log(Math.max(Math.abs(r-n),1))),i=0,a=0,c=(s)=>{let u=document.getElementById("messages");if(!(u instanceof HTMLElement)||v===void 0){p=void 0;return}let d=a?s-a:16.7;a=s,i+=d;let f=Math.min(1,i/o);if(u.scrollTop=n+(r-n)*f,f>=1){if(v=void 0,p=void 0,e==="bottom")L();return}p=requestAnimationFrame(c)};p=requestAnimationFrame(c)}function Hn(e={}){let t=e.activeElement??(()=>document.activeElement),n=e.body??(()=>document.body),r=e.requestFrame??((s)=>requestAnimationFrame(s)),o,i=0;function a(){i+=1;let s=t();if(!gt(s)||s===n()){o=void 0;return}o=s,s.blur()}function c(){let s=o;if(o=void 0,!gt(s)||!s.isConnected)return;let u=i;r(()=>{if(i!==u||!s.isConnected)return;let d=t();if(d===s)return;if(d&&d!==n())return;s.focus({preventScroll:!0})})}return{restore:c,suspend:a}}function gt(e){return Boolean(e&&e.blur instanceof Function&&e.focus instanceof Function)}var Et=Hn();var In=lt();window.piUi={controls:{refresh:k,activate:A},codeTheme:{loadPreviews(){}},dateTime:{hydrate:ve},fonts:{apply(){}},fileTransfer:pe,messageScroll:{bindResize:he,captureAnchor:nt,hydratePierreDiff:st,restoreAnchor:rt,scrollBottom:L,trimOldMessages:ot},modelSearch:{filter:at},pickers:{close:T,fuzzyMatch:O,isFileOpen:F,isOpen:K,sync:ce},prompt:{clear:()=>_("")},promptHistory:In,sessionPerformance:{observe:dt,start:ut},windowFocus:Et,workspaceReview:{applyOpen:()=>{}},shouldAbortOnEscape(e){return!e.defaultPrevented&&!Pn()}};function Pn(){if(K()||document.querySelector(":modal"))return!0;return Boolean(document.querySelector("[popover]:popover-open"))}Ie();window.addEventListener("DOMContentLoaded",async()=>{Ee(),Fe(),Ce(),Re({fuzzyFilter:P}),tt(),ge(),ht(),Ae(),kn(),await Promise.all([import("./chunks/fonts-9524b54h.js"),import("./chunks/code-theme-62gcxxqq.js"),import("./chunks/workspace-review-
|
|
5
|
+
`)+1;return e.selectionEnd>=n}var x;function ut(){if(!document.getElementById("session-transition")?.hasAttribute("data-session-performance-enabled"))return;x={startedAt:performance.now()}}function dt(e,t){if(!x)return;let n=performance.now();if(e==="loading"){x.generation=Number(t),x.loadingAt??=n;return}if(e!=="idle"||x.generation!==Number(t)||x.loadingAt===void 0)return;let r=x;x=void 0,ft(r,Number(t),n)}function ft(e,t,n){requestAnimationFrame(()=>{let r=document.getElementById("session-transition"),o=document.getElementById("messages");if(r&&o&&getComputedStyle(r).display==="none"&&getComputedStyle(o).display!=="none"){requestAnimationFrame(()=>{let i={generation:t,clickToLoadingMs:e.loadingAt-e.startedAt,clickToMorphMs:n-e.startedAt,clickToPaintMs:performance.now()-e.startedAt};document.body.dispatchEvent(new CustomEvent("pi-ui-session-performance",{detail:i}))});return}if(performance.now()-e.startedAt<60000)ft(e,t,n)})}var X=100,pt=120,Mn=17,xn=33.333333333333336,p,v,G=0,I=0,Q=!1,J=0,Z=0;function ht(){let e=!1;document.addEventListener("keydown",(t)=>{if(t.defaultPrevented||t.ctrlKey||t.metaKey||t.altKey||Tn(t)){e=!1;return}if(document.querySelector(":modal"))return;if(e){if(e=!1,t.code==="KeyG"&&!t.shiftKey){t.preventDefault(),mt("top");return}}if(t.code==="KeyG"&&!t.shiftKey)t.preventDefault(),e=!0;else if(t.code==="KeyG"&&t.shiftKey)t.preventDefault(),mt("bottom");else if(t.code==="KeyJ"||t.code==="KeyK")t.preventDefault(),An(t.code==="KeyJ"?X:-X)}),document.addEventListener("keyup",(t)=>{if(t.code==="KeyJ"||t.code==="KeyK")Q=!1})}function Tn(e){return vn(e.composedPath()[0])}function vn(e){return e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement||e instanceof HTMLElement&&e.isContentEditable}function An(e){if(p&&v!==void 0)cancelAnimationFrame(p),p=void 0,v=void 0;let t=Math.sign(e);if(!p||I!==t)I=t,J=0,Z=0,G=0;Q=!0,Sn(),E()}function mt(e){let t=document.getElementById("messages");if(!(t instanceof HTMLElement))return;if(I=0,Q=!1,v=e==="top"?0:t.scrollHeight-t.clientHeight,Ln(e),e==="top")E()}function Sn(){if(p)return;let e=(t)=>{let n=document.getElementById("messages");if(!(n instanceof HTMLElement)||!I){p=void 0;return}let r=G?Math.min(Math.max(t-G,0),xn):Mn;G=t;let o=n.scrollHeight-n.clientHeight,i=I*(X*r/pt)+Z,a=n.scrollTop,c=Math.max(0,Math.min(a+i,o));n.scrollTop=c;let s=c-a;if(Z=i-s,J+=Math.abs(s),c===0||c===o||!Q&&J>=X){I=0,J=0,Z=0,p=void 0;return}p=requestAnimationFrame(e)};p=requestAnimationFrame(e)}function Ln(e){if(p)cancelAnimationFrame(p);let t=document.getElementById("messages");if(!(t instanceof HTMLElement)||v===void 0)return;let n=t.scrollTop,r=Math.max(0,Math.min(v,t.scrollHeight-t.clientHeight)),o=Math.max(pt,20*Math.log(Math.max(Math.abs(r-n),1))),i=0,a=0,c=(s)=>{let u=document.getElementById("messages");if(!(u instanceof HTMLElement)||v===void 0){p=void 0;return}let d=a?s-a:16.7;a=s,i+=d;let f=Math.min(1,i/o);if(u.scrollTop=n+(r-n)*f,f>=1){if(v=void 0,p=void 0,e==="bottom")L();return}p=requestAnimationFrame(c)};p=requestAnimationFrame(c)}function Hn(e={}){let t=e.activeElement??(()=>document.activeElement),n=e.body??(()=>document.body),r=e.requestFrame??((s)=>requestAnimationFrame(s)),o,i=0;function a(){i+=1;let s=t();if(!gt(s)||s===n()){o=void 0;return}o=s,s.blur()}function c(){let s=o;if(o=void 0,!gt(s)||!s.isConnected)return;let u=i;r(()=>{if(i!==u||!s.isConnected)return;let d=t();if(d===s)return;if(d&&d!==n())return;s.focus({preventScroll:!0})})}return{restore:c,suspend:a}}function gt(e){return Boolean(e&&e.blur instanceof Function&&e.focus instanceof Function)}var Et=Hn();var In=lt();window.piUi={controls:{refresh:k,activate:A},codeTheme:{loadPreviews(){}},dateTime:{hydrate:ve},fonts:{apply(){}},fileTransfer:pe,messageScroll:{bindResize:he,captureAnchor:nt,hydratePierreDiff:st,restoreAnchor:rt,scrollBottom:L,trimOldMessages:ot},modelSearch:{filter:at},pickers:{close:T,fuzzyMatch:O,isFileOpen:F,isOpen:K,sync:ce},prompt:{clear:()=>_("")},promptHistory:In,sessionPerformance:{observe:dt,start:ut},windowFocus:Et,workspaceReview:{applyOpen:()=>{}},shouldAbortOnEscape(e){return!e.defaultPrevented&&!Pn()}};function Pn(){if(K()||document.querySelector(":modal"))return!0;return Boolean(document.querySelector("[popover]:popover-open"))}Ie();window.addEventListener("DOMContentLoaded",async()=>{Ee(),Fe(),Ce(),Re({fuzzyFilter:P}),tt(),ge(),ht(),Ae(),kn(),await Promise.all([import("./chunks/fonts-9524b54h.js"),import("./chunks/code-theme-62gcxxqq.js"),import("./chunks/workspace-review-12dvn9pf.js")])});function kn(){let e=document.getElementById("debug-fps");if(!(e instanceof HTMLElement))return;let t=0,n=performance.now(),r=(o)=>{t+=1;let i=o-n;if(i>=500)e.textContent=String(Math.round(t*1000/i)),t=0,n=o;requestAnimationFrame(r)};requestAnimationFrame(r)}
|