markon-core 0.15.13

markon core - Mark it on.
1
var a=typeof window<"u"&&window.__MARKON_I18N__?.t||(o=>o);var f={BREAKPOINTS:{WIDE_SCREEN:1400},DIMENSIONS:{NOTE_CARD_WIDTH:280,NOTE_CARD_RIGHT_MARGIN:40,HEADING_TOP_MARGIN:64,HEADING_TOP_MARGIN_TIGHT:5,POPOVER_OFFSET:10},THRESHOLDS:{NOTE_CLUSTER:50,NOTE_MIN_SPACING:32,HEADING_SCROLL_THRESHOLD:40},WEBSOCKET:{INITIAL_RECONNECT_DELAY:1e3,MAX_RECONNECT_DELAY:3e4,STABLE_CONNECTION_THRESHOLD:5e3},ANIMATION:{RESIZE_DEBOUNCE:150,PANEL_TRANSITION:200},UNDO:{MAX_STACK_SIZE:50},SHORTCUTS:{HELP:{key:"?",ctrl:!1,shift:!1,desc:a("web.kbd.help"),cat:"global"},THEME_PANEL:{key:"t",ctrl:!1,shift:!1,desc:a("web.kbd.theme"),cat:"global"},UNDO:{key:"z",ctrl:!0,shift:!1,desc:a("web.kbd.undo"),cat:"core"},REDO:{key:"z",ctrl:!0,shift:!0,desc:a("web.kbd.redo"),cat:"core"},REDO_ALT:{key:"y",ctrl:!0,shift:!1,desc:a("web.kbd.redo.alt"),cat:"core"},ESCAPE:{key:"Escape",ctrl:!1,shift:!1,desc:a("web.kbd.escape"),cat:"core"},TOGGLE_TOC:{key:"\\",ctrl:!0,shift:!1,desc:a("web.kbd.toc"),cat:"core"},SEARCH:{key:"/",ctrl:!1,shift:!1,desc:a("web.kbd.search"),cat:"search",feature:"workspace_spotlight"},EXPORT_NOTES:{key:"x",ctrl:!1,shift:!1,desc:a("web.kbd.exportnotes"),cat:"core"},WORKSPACE_NAVIGATOR:{key:"g",ctrl:!1,shift:!1,desc:a("web.kbd.workspace_nav"),cat:"search",feature:"workspace_spotlight"},PREV_HEADING:{key:"k",ctrl:!1,shift:!1,desc:a("web.kbd.prevheading"),cat:"nav"},NEXT_HEADING:{key:"j",ctrl:!1,shift:!1,desc:a("web.kbd.nextheading"),cat:"nav"},PREV_ANNOTATION:{key:"k",ctrl:!0,shift:!1,desc:a("web.kbd.prevanno"),cat:"nav"},NEXT_ANNOTATION:{key:"j",ctrl:!0,shift:!1,desc:a("web.kbd.nextanno"),cat:"nav"},SCROLL_HALF_PAGE_DOWN:{key:" ",ctrl:!1,shift:!1,desc:a("web.kbd.scroll"),cat:"nav"},TOGGLE_SECTION_COLLAPSE:{key:"o",ctrl:!1,shift:!1,desc:a("web.kbd.collapse"),cat:"viewed"},TOGGLE_VIEWED:{key:"v",ctrl:!1,shift:!1,desc:a("web.kbd.viewed"),cat:"viewed"},EDIT:{key:"e",ctrl:!1,shift:!1,desc:a("web.kbd.edit"),cat:"edit"},TOGGLE_LIVE_ACTIVE:{key:"l",ctrl:!1,shift:!1,desc:a("web.kbd.live.active"),cat:"live"},TOGGLE_LIVE_OFF:{key:"l",ctrl:!1,shift:!0,desc:a("web.kbd.live.off"),cat:"live"},TOGGLE_CHAT:{key:"c",ctrl:!1,shift:!1,desc:a("web.kbd.chat"),cat:"chat"},TOGGLE_CHAT_ALT:{key:"c",ctrl:!1,shift:!0,desc:a("web.kbd.chat.alt"),cat:"chat"},DIFF_TOGGLE_VIEW:{key:"m",ctrl:!1,shift:!1,desc:a("web.kbd.diff.view"),cat:"diff"},DIFF_NEXT_FILE:{key:"n",ctrl:!1,shift:!1,desc:a("web.kbd.diff.nextfile"),cat:"diff"},DIFF_PREV_FILE:{key:"p",ctrl:!1,shift:!1,desc:a("web.kbd.diff.prevfile"),cat:"diff"},VISUAL_ZOOM_IN:{key:"+",ctrl:!1,shift:!1,desc:a("web.kbd.visual.zoom_in"),cat:"visual",feature:"visual_zoom_in"},VISUAL_ZOOM_IN_ALT:{key:"=",ctrl:!1,shift:!1,desc:a("web.kbd.visual.zoom_in"),cat:"visual",feature:"visual_zoom_in"},VISUAL_ZOOM_OUT:{key:"-",ctrl:!1,shift:!1,desc:a("web.kbd.visual.zoom_out"),cat:"visual"},VISUAL_ZOOM_RESET:{key:"0",ctrl:!1,shift:!1,desc:a("web.kbd.visual.reset"),cat:"visual",feature:"visual_reset"},VISUAL_ZOOM_RESET_ALT:{key:"r",ctrl:!1,shift:!1,desc:a("web.kbd.visual.reset"),cat:"visual",feature:"visual_reset"},VISUAL_ZOOM_FIT:{key:"f",ctrl:!1,shift:!1,desc:a("web.kbd.visual.fit"),cat:"visual",feature:"visual_fit"},VISUAL_ZOOM_FIT_CMD:{key:"0",ctrl:!0,shift:!1,desc:a("web.kbd.visual.fit"),cat:"visual",feature:"visual_fit"},VISUAL_ZOOM_TOOL:{key:"z",ctrl:!1,shift:!1,desc:a("web.kbd.visual.tool"),cat:"visual"},VISUAL_ZOOM_TOOL_OUT:{key:"z",ctrl:!1,shift:!0,desc:a("web.kbd.visual.tool_out"),cat:"visual"},VISUAL_ZOOM_CLOSE:{key:"Escape",ctrl:!1,shift:!1,desc:a("web.kbd.visual.close"),cat:"visual",feature:"ESCAPE"}},STORAGE_KEYS:{ANNOTATIONS:o=>`markon-annotations-${o}`,VIEWED:o=>`markon-viewed-${o}`,LIVE_POS:"markon-live-pos",LIVE_COLOR:"markon-user-color",IDENTITY_NAME:"markon-user-name",LIVE_MODE:"markon-live-mode",CLIENT_ID:"markon-client-id",CHAT_POS:"markon-chat-pos",CHAT_SIZE:"markon-chat-size",NOTE_INPUT_OFFSET:"markon-note-input-offset",NOTE_INPUT_SIZE:"markon-note-input-size",POPOVER_OFFSET:"markon-popover-offset",SHORTCUTS_HELP_POS:"markon-shortcuts-help-pos",WORKSPACE_SPOTLIGHT_POS:"markon-workspace-spotlight-pos"},SELECTORS:{MARKDOWN_BODY:".markdown-body",HEADINGS:"h1, h2, h3, h4, h5, h6",TOC_CONTAINER:"#toc-container",TOC_ICON:"#toc-icon",HIGHLIGHT_CLASSES:".highlight-orange, .highlight-green, .highlight-yellow, .strikethrough"},SKIP_ELEMENTS:{IDS:new Set(["toc"]),CLASSES:new Set(["back-link","toc","selection-popover","note-card-margin","note-popup"])},META_TAGS:{FILE_PATH:"file-path",WORKSPACE_ID:"workspace-id",SHARED_ANNOTATION:"shared-annotation",ENABLE_SEARCH:"enable-search",ENABLE_VIEWED:"enable-viewed",ENABLE_EDIT:"enable-edit",ENABLE_LIVE:"enable-live",ENABLE_CHAT:"enable-chat",DEFAULT_CHAT_MODE:"default-chat-mode",CHAT_ONLY:"chat-only"},WS_MESSAGE_TYPES:{ALL_ANNOTATIONS:"all_annotations",NEW_ANNOTATION:"new_annotation",DELETE_ANNOTATION:"delete_annotation",CLEAR_ANNOTATIONS:"clear_annotations",VIEWED_STATE:"viewed_state",UPDATE_VIEWED_STATE:"update_viewed_state",LIVE_ACTION:"live_action",FILE_CHANGED:"file_changed"},COLLABORATION:{COLORS:["#3451B2","#E64560","#27AE60","#F39C12","#8E44AD","#0EA5E9","#EC4899","#14B8A6"],SYNC_DEBOUNCE:100},ANNOTATION_TYPES:{STRIKETHROUGH:"strikethrough",HAS_NOTE:"has-note"},HTML_TAGS:{HIGHLIGHT:"span",STRIKETHROUGH:"s"},BLOCK_TAGS:["P","DIV","LI","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","TD","TH"]};if(typeof window<"u"&&window.__MARKON_SHORTCUTS__){let o=Object.entries(window.__MARKON_SHORTCUTS__);for(let[e,t]of o)f.SHORTCUTS[e]&&Object.assign(f.SHORTCUTS[e],t)}Object.freeze(f);Object.freeze(f.BREAKPOINTS);Object.freeze(f.DIMENSIONS);Object.freeze(f.THRESHOLDS);Object.freeze(f.WEBSOCKET);Object.freeze(f.ANIMATION);Object.freeze(f.UNDO);Object.freeze(f.SHORTCUTS);Object.freeze(f.SELECTORS);Object.freeze(f.SKIP_ELEMENTS);Object.freeze(f.META_TAGS);Object.freeze(f.WS_MESSAGE_TYPES);Object.freeze(f.COLLABORATION);Object.freeze(f.ANNOTATION_TYPES);Object.freeze(f.HTML_TAGS);var w=class o{static#e=!0;static enable(){o.#e=!0}static disable(){o.#e=!1}static log(e,t,...s){o.#e&&console.log(`[${e}]`,t,...s)}static warn(e,t,...s){o.#e&&console.warn(`[${e}]`,t,...s)}static error(e,t,...s){console.error(`[${e}]`,t,...s)}};var L={getAbsolute(o){let e=o.getBoundingClientRect(),t=window.scrollY||window.pageYOffset,s=window.scrollX||window.pageXOffset;return{left:e.left+s,top:e.top+t,right:e.right+s,bottom:e.bottom+t}},constrainToViewport(o,e,t,s,n={}){let i=n.margin??10,r=n.fixed?0:window.scrollX||window.pageXOffset,d=n.fixed?0:window.scrollY||window.pageYOffset,m=o,g=e;return m<r+i&&(m=r+i),m+t>window.innerWidth+r-i&&(m=window.innerWidth+r-t-i),g<d+i&&(g=d+i),g+s>window.innerHeight+d-i&&(g=window.innerHeight+d-s-i),{left:m,top:g}},smartScrollToHeading(o){let e=o.closest(".heading-section")??o;if(!(e instanceof HTMLElement))return;let t=e.offsetHeight,s=window.innerHeight;if(t<=s){let n=s-t,i=n>=f.DIMENSIONS.HEADING_TOP_MARGIN?f.DIMENSIONS.HEADING_TOP_MARGIN:n/2,r=e.getBoundingClientRect().top+window.scrollY-i;window.scrollTo({top:r,behavior:"smooth"})}else{let n=e.getBoundingClientRect().top+window.scrollY-f.DIMENSIONS.HEADING_TOP_MARGIN_TIGHT;window.scrollTo({top:n,behavior:"smooth"})}}};var _=["button","input","textarea","select","option","a[href]",'[contenteditable="true"]',"[data-no-drag]"].join(", "),te=(o,e=_)=>!e||!(o instanceof Node)?!1:!!(o instanceof Element?o:o.parentElement)?.closest(e),C=class{#e;#o=[];#t;#n=!1;#a=0;#r=0;#l=0;#c=0;#s={};#u="";#i=!1;constructor(e,t={}){this.#e=e,this.#t={storageKey:null,handle:null,onDragEnd:null,saveOffset:!1,restoreOffset:!1,savePosition:!1,restorePosition:!1,fixed:!1,margin:10,nonDragSelector:_,handleClassName:null,...t},this.#E()}#E(){if(typeof this.#t.handle=="string"?this.#o=Array.from(this.#e.querySelectorAll(this.#t.handle)):this.#o=[this.#t.handle??this.#e],this.#o.length===0){w.warn("Draggable","Handle element not found");return}if(this.#t.handleClassName)for(let e of this.#o)e.classList.add(this.#t.handleClassName);this.#t.restorePosition?this.#O():this.#t.restoreOffset&&this.#v(),this.#s.mousedown=e=>this.#f(e),this.#s.mousemove=e=>this.#h(e),this.#s.mouseup=()=>this.#m(),this.#s.touchstart=e=>this.#f(e),this.#s.touchmove=e=>this.#h(e),this.#s.touchend=()=>this.#m();for(let e of this.#o)e.addEventListener("mousedown",this.#s.mousedown),e.addEventListener("touchstart",this.#s.touchstart,{passive:!1})}#f(e){if(e instanceof MouseEvent&&e.button!==0||te(e.target,this.#t.nonDragSelector))return;this.#n=!0;let t=this.#g(e);this.#a=t.x,this.#r=t.y;let s=this.#p();this.#l=s.left,this.#c=s.top,this.#e.style.cursor="grabbing";for(let n of this.#o)n.classList.add("is-dragging");this.#u=document.body.style.userSelect,this.#i=!0,document.body.style.userSelect="none",this.#s.mousemove&&document.addEventListener("mousemove",this.#s.mousemove),this.#s.mouseup&&document.addEventListener("mouseup",this.#s.mouseup),this.#s.touchmove&&document.addEventListener("touchmove",this.#s.touchmove,{passive:!1}),this.#s.touchend&&document.addEventListener("touchend",this.#s.touchend),e.preventDefault()}#h(e){if(!this.#n)return;let t=this.#g(e),s=t.x-this.#a,n=t.y-this.#r,i=this.#l+s,r=this.#c+n;({left:i,top:r}=L.constrainToViewport(i,r,this.#e.offsetWidth,this.#e.offsetHeight,{fixed:this.#t.fixed,margin:this.#t.margin})),this.#d(i,r)}#m(){if(this.#n){this.#n=!1,this.#e.style.cursor="";for(let e of this.#o)e.classList.remove("is-dragging");if(this.#i&&(document.body.style.userSelect=this.#u,this.#i=!1),this.#s.mousemove&&document.removeEventListener("mousemove",this.#s.mousemove),this.#s.mouseup&&document.removeEventListener("mouseup",this.#s.mouseup),this.#s.touchmove&&document.removeEventListener("touchmove",this.#s.touchmove),this.#s.touchend&&document.removeEventListener("touchend",this.#s.touchend),this.#t.saveOffset&&this.#t.storageKey&&this.#b(),this.#t.savePosition&&this.#t.storageKey&&this.#T(),this.#t.onDragEnd){let e=parseFloat(this.#e.style.left)||0,t=parseFloat(this.#e.style.top)||0;this.#t.onDragEnd(e,t)}}}#b(){let e=parseFloat(this.#e.style.left)||0,t=parseFloat(this.#e.style.top)||0,s=parseFloat(this.#e.dataset.originalLeft??""),n=parseFloat(this.#e.dataset.originalTop??"");if(!isNaN(s)&&!isNaN(n)&&this.#t.storageKey){let i={dx:e-s,dy:t-n};localStorage.setItem(this.#t.storageKey,JSON.stringify(i)),w.log("Draggable",`Saved offset to ${this.#t.storageKey}:`,i)}}#v(){if(!this.#t.storageKey)return;let e=parseFloat(this.#e.dataset.originalLeft??""),t=parseFloat(this.#e.dataset.originalTop??"");if(!(!Number.isFinite(e)||!Number.isFinite(t)))try{let s=JSON.parse(localStorage.getItem(this.#t.storageKey)||"null");if(!s||typeof s!="object")return;let n=s,i=typeof n.dx=="number"?n.dx:0,r=typeof n.dy=="number"?n.dy:0;if(!Number.isFinite(i)||!Number.isFinite(r))return;let d=L.constrainToViewport(e+i,t+r,this.#e.offsetWidth,this.#e.offsetHeight,{fixed:this.#t.fixed,margin:this.#t.margin});this.#d(d.left,d.top)}catch{}}#T(){if(!this.#t.storageKey)return;let e=parseFloat(this.#e.style.left),t=parseFloat(this.#e.style.top);!Number.isFinite(e)||!Number.isFinite(t)||(localStorage.setItem(this.#t.storageKey,JSON.stringify({left:e,top:t})),w.log("Draggable",`Saved position to ${this.#t.storageKey}`))}#O(){if(this.#t.storageKey)try{let e=JSON.parse(localStorage.getItem(this.#t.storageKey)||"null");if(!e||typeof e!="object")return;let t=e,s=typeof t.left=="number"?t.left:t.x,n=typeof t.top=="number"?t.top:t.y;if(typeof s!="number"||typeof n!="number")return;let i=L.constrainToViewport(s,n,this.#e.offsetWidth,this.#e.offsetHeight,{fixed:this.#t.fixed,margin:this.#t.margin});this.#d(i.left,i.top)}catch{}}#p(){let e=this.#e.getBoundingClientRect(),t=this.#t.fixed?0:window.scrollX||window.pageXOffset,s=this.#t.fixed?0:window.scrollY||window.pageYOffset,n=parseFloat(this.#e.style.left),i=parseFloat(this.#e.style.top),r=Number.isFinite(n)?n:e.left+t,d=Number.isFinite(i)?i:e.top+s;return this.#d(r,d),{left:r,top:d}}#d(e,t){this.#e.style.position=this.#t.fixed?"fixed":"absolute",this.#e.style.left=`${e}px`,this.#e.style.top=`${t}px`,this.#e.style.right="auto",this.#e.style.bottom="auto",this.#e.style.margin="0",this.#e.style.transform="none"}#g(e){if(e.type==="touchstart"||e.type==="touchmove"){let s=e,n=s.touches[0]??s.changedTouches[0];if(!n){let i=this.#p();return{x:i.left,y:i.top}}return this.#t.fixed?{x:n.clientX,y:n.clientY}:{x:n.pageX,y:n.pageY}}let t=e;return this.#t.fixed?{x:t.clientX,y:t.clientY}:{x:t.pageX,y:t.pageY}}destroy(){for(let e of this.#o)this.#s.mousedown&&e.removeEventListener("mousedown",this.#s.mousedown),this.#s.touchstart&&e.removeEventListener("touchstart",this.#s.touchstart),this.#t.handleClassName&&e.classList.remove(this.#t.handleClassName),e.classList.remove("is-dragging");this.#n&&(this.#s.mousemove&&document.removeEventListener("mousemove",this.#s.mousemove),this.#s.mouseup&&document.removeEventListener("mouseup",this.#s.mouseup),this.#s.touchmove&&document.removeEventListener("touchmove",this.#s.touchmove),this.#s.touchend&&document.removeEventListener("touchend",this.#s.touchend)),this.#e.style.cursor="",this.#i&&(document.body.style.userSelect=this.#u,this.#i=!1),w.log("Draggable","Destroyed")}};var ye=window.__MARKON_I18N__?.t||(o=>o),se="markon-modal-drag-handle";var oe=`${_}, .markon-modal-frame > *`;var ne=(o,e)=>new C(o,{handle:e.handle,storageKey:e.storageKey??null,saveOffset:e.storageMode==="offset"&&!!e.storageKey,restoreOffset:e.storageMode==="offset"&&!!e.storageKey,savePosition:(e.storageMode??"position")==="position"&&!!e.storageKey,restorePosition:(e.storageMode??"position")==="position"&&!!e.storageKey,fixed:!0,margin:e.margin??10,nonDragSelector:e.nonDragSelector??_,handleClassName:se}),I=class{#e=null;#o;#t={};#n=null;constructor(e){this.#o={className:"",closeOnOutsideClick:!0,closeOnEscape:!0,draggable:!0,dragHandle:null,dragStorageKey:null,dragStorageMode:"position",...e}}show(e=null){if(this.#a(),this.#e=this.create(),this.#e.hasAttribute("role")||this.#e.setAttribute("role","dialog"),this.#e.hasAttribute("aria-modal")||this.#e.setAttribute("aria-modal","true"),document.body.appendChild(this.#e),e&&this.#r(e),this.#o.draggable){let t=this.#o.dragHandle??this.#e;this.#n=ne(this.#e,{handle:t,storageKey:this.#o.dragStorageKey,storageMode:this.#o.dragStorageMode,nonDragSelector:this.#o.dragHandle?_:oe})}this.#l(),setTimeout(()=>this.#s(),0),w.log("Modal",`Showed ${this.#o.className}`)}close(){this.#e&&(this.#n?.destroy(),this.#n=null,this.#e.remove(),this.#e=null),this.#c(),w.log("Modal",`Closed ${this.#o.className}`)}getElement(){return this.#e}#a(){let e=document.querySelector(`.${this.#o.className}`);e&&e.remove()}#r(e){if(!this.#e)return;let t=e.getBoundingClientRect(),s=this.#e.offsetWidth,n=this.#e.offsetHeight,i=getComputedStyle(this.#e).position==="fixed",r=i?0:window.pageXOffset||document.documentElement.scrollLeft,d=i?0:window.pageYOffset||document.documentElement.scrollTop,m=t.left+r,g=t.bottom+d+5;window.innerHeight-t.bottom<n+10&&(g=t.top+d-n-5),{left:m,top:g}=L.constrainToViewport(m,g,s,n,{fixed:i}),this.#e.style.left=`${m}px`,this.#e.style.top=`${g}px`,this.#e.dataset.originalLeft=String(m),this.#e.dataset.originalTop=String(g)}#l(){this.#o.closeOnEscape&&(this.#t.keydown=e=>{e.key==="Escape"&&(e.preventDefault(),typeof this.cancel=="function"?this.cancel():this.close())},document.addEventListener("keydown",this.#t.keydown)),this.#o.closeOnOutsideClick&&(this.#t.click=e=>{this.#e&&(this.#e.contains(e.target)||(typeof this.cancel=="function"?this.cancel():this.close()))},setTimeout(()=>{this.#t.click&&document.addEventListener("click",this.#t.click)},0))}#c(){this.#t.keydown&&document.removeEventListener("keydown",this.#t.keydown),this.#t.click&&document.removeEventListener("click",this.#t.click)}#s(){if(!this.#e)return;let e=this.#e.querySelector("input, textarea, button");e&&e.focus({preventScroll:!0})}};var K=o=>{if(!o||typeof o!="object")return!1;let e=o;return typeof e.value=="string"&&typeof e.label=="string"&&typeof e.kind=="string"},ie=o=>{if(!o||typeof o!="object")return null;let e=o,t=Array.isArray(e.base)?e.base.filter(K):[],s=Array.isArray(e.compare)?e.compare.filter(K):[];return{base:t,compare:s,baseValue:typeof e.baseValue=="string"?e.baseValue:"",compareValue:typeof e.compareValue=="string"?e.compareValue:""}},ae=o=>{if(!o||typeof o!="object")return null;let e=o,t={};return Array.isArray(e.base)&&(t.base=e.base),Array.isArray(e.compare)&&(t.compare=e.compare),t},re=["worktree","head","branch","tag","commit"],le={worktree:"Working tree",head:"HEAD",branch:"Branches",tag:"Tags",commit:"Commits"},ce={worktree:"WT",head:"HEAD",branch:"BR",tag:"TAG",commit:"#"},V=(o,e)=>{let t=o.find(s=>s.value===e);return t?t.kind==="commit"?t.detail||t.label:t.label.replace(" (current)",""):e},D=class extends I{#e;#o;constructor(e,t){super({className:"git-compare-panel"}),this.#e=e,this.#o=t}create(){let e=this.#e();return e.classList.add("markon-modal-frame"),e.setAttribute("aria-label","Choose compared revisions"),e}close(){let e=!!this.getElement();super.close(),e&&this.#o()}};function U(){let o=document.querySelector("[data-compare-control]"),e=document.querySelector("[data-compare-picker]"),t=document.querySelector("[data-compare-trigger]");if(!o||!e||!t)return;let s;try{s=ie(JSON.parse(e.textContent||"{}"))}catch{return}if(!s)return;let n=o.getAttribute("data-compare-path-base")||"",i=o.getAttribute("data-compare-status-url")||"",r=s.baseValue,d=s.compareValue,m=null,g=t.querySelector("[data-compare-base-label]"),x=t.querySelector("[data-compare-compare-label]");g&&(g.textContent=V(s.base,r)),x&&(x.textContent=V(s.compare,d));let $=()=>document.querySelector("[data-diff-shell]")?.getAttribute("data-current-diff-view")==="rendered"?"rendered":"raw",P=l=>l.split("/").map(encodeURIComponent).join("/"),W=()=>location.pathname+location.search+location.hash,F=(l,p)=>{if(!l||!p||!n||l===p)return;let E=`${n}/${P(l)}...${P(p)}?view=${$()}`;try{location.hash&&(E+=location.hash)}catch{}E!==W()&&(location.href=E)};(()=>{let l=o.querySelector("[data-compare-quick]");if(!l)return;l.replaceChildren();let p=(b,T,y)=>{if(!s.base.some(h=>h.value===T)&&T!=="HEAD"||!s.compare.some(h=>h.value===y))return;let u=document.createElement("button");u.type="button",u.className="git-compare-preset",u.textContent=b,u.addEventListener("click",()=>F(T,y)),l.appendChild(u)};s.compare.some(b=>b.kind==="worktree")&&p("Uncommitted changes","HEAD","worktree");let O=s.base.filter(b=>b.kind==="commit")[1];O&&p("Latest commit",O.value,"HEAD")})();let j=()=>m?.close(),M=(l,p,E,O)=>{let b=O.trim().toLowerCase(),T=u=>!b||`${u.label} ${u.alias||""} ${u.subject} ${u.value}`.toLowerCase().includes(b),y=E==="base"?r:d;l.replaceChildren();for(let u of re){let h=p.filter(c=>c.kind===u&&T(c));if(!h.length)continue;let v=document.createElement("div");v.className="git-compare-group",v.textContent=le[u]||u,l.appendChild(v);for(let c of h){let S=document.createElement("button");S.type="button",S.className="git-compare-row",S.dataset.value=c.value,S.classList.toggle("is-selected",c.value===y),c.disabled&&S.classList.add("is-disabled");let q=`<span class="git-compare-badge git-compare-badge-${c.kind}">${ce[c.kind]||""}</span>`,X=c.kind==="commit"?c.detail||"":c.label.replace(" (current)",""),Z=c.alias?`<span class="git-compare-row-alias">${A(c.alias)}</span>`:"",J=c.subject?`<span class="git-compare-row-sub">${A(c.subject)}</span>`:"",Q=c.kind==="commit"&&c.detail?"":c.detail?`<span class="git-compare-row-detail">${A(c.detail)}</span>`:"",ee=c.date?`<span class="git-compare-row-date">${A(c.date)}</span>`:"";S.innerHTML=`${q}<span class="git-compare-row-main"><span class="git-compare-row-name"><span class="git-compare-row-name-text">${A(X)}</span>${Z}</span>${J}</span>${Q}${ee}`,S.addEventListener("click",()=>{S.classList.contains("is-disabled")||(E==="base"?r=c.value:d=c.value,G(),r&&d&&r!==d?F(r,d):B())}),l.appendChild(S)}}if(!l.childElementCount){let u=document.createElement("div");u.className="git-compare-empty",u.textContent="No matches",l.appendChild(u)}},N,k,H,R,G=()=>{N.querySelectorAll(".git-compare-row").forEach(l=>l.classList.toggle("is-selected",l.dataset.value===r)),k.querySelectorAll(".git-compare-row").forEach(l=>l.classList.toggle("is-selected",l.dataset.value===d))},B=async()=>{if(!(!i||!r||!d))try{let l=`${i}?base=${encodeURIComponent(r)}&compare=${encodeURIComponent(d)}`,p=await fetch(l,{headers:{Accept:"application/json"}});if(!p.ok)return;let E=ae(await p.json()),O=(b,T,y)=>{if(!Array.isArray(T))return;let u=new Map(T.filter(h=>typeof h.value=="string").map(h=>[h.value,!!h.disabled]));b.querySelectorAll(".git-compare-row").forEach(h=>{let v=h.dataset.value||"";if(v===y){h.classList.remove("is-disabled");return}u.has(v)&&h.classList.toggle("is-disabled",!!u.get(v))})};m?.getElement()&&E&&(O(N,E.base,r),O(k,E.compare,d))}catch{}},Y=()=>{let l=document.createElement("div");l.className="git-compare-panel";let p=document.createElement("div");p.className="git-compare-cols";let E=y=>{let u=document.createElement("div");u.className="git-compare-col";let h=document.createElement("div");h.className="git-compare-col-title",h.textContent=y;let v=document.createElement("input");v.type="search",v.className="git-compare-search",v.placeholder="Filter\u2026";let c=document.createElement("div");return c.className="git-compare-list",u.append(h,v,c),{col:u,list:c,search:v}},O=E("Base"),b=E("Compare");N=O.list,k=b.list,H=O.search,R=b.search,H.addEventListener("input",()=>M(N,s.base,"base",H.value)),R.addEventListener("input",()=>M(k,s.compare,"compare",R.value)),p.append(O.col,b.col);let T=document.createElement("div");return T.className="git-compare-surface",T.appendChild(p),l.appendChild(T),M(N,s.base,"base",""),M(k,s.compare,"compare",""),G(),l},z=()=>{if(m){j();return}r=s.baseValue,d=s.compareValue,m=new D(Y,()=>{m=null,t.setAttribute("aria-expanded","false")}),m.show(t),t.setAttribute("aria-expanded","true"),B()};t.addEventListener("click",l=>{l.preventDefault(),z()})}function A(o){return o.replace(/[&<>"']/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[e]||e)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",U,{once:!0}):U();export{U as initCompareRefPicker};