function de(i){return i.split("/").filter((e,t,n)=>e!==""||t>0&&t<n.length-1).map(encodeURIComponent).join("/")}function I(i){return encodeURIComponent(i.trim().replace(/^\/+|\/+$/g,""))}function ce(i){return i.trim().replace(/^\/+/,"")}function fe(i){let e=I(i);return e?`/${e}/`:"/"}function D(i,e=""){let t=e.trim().replace(/^\/+/,""),n=fe(i);return t?`${n}${de(t)}`:n}function ue(i,e){let t=I(i),n=ce(e);return t?`/_/${t}/${n}`:`/_/${n}`}function H(i){return ue(i,"files/delete")}var R=i=>{if(!i)return null;let e=i.getBoundingClientRect().top,t=i.querySelectorAll(".md-diff-file-section[data-file-path]"),n=null;for(let r of t)if(r.getBoundingClientRect().top<=e+4)n=r.dataset.filePath||n;else break;let s=t[0];return!n&&s&&(n=s.dataset.filePath||null),n},B=i=>{let e=i.querySelector(".md-diff-file-header");return e?e.offsetHeight:48},P=i=>{let e=parseInt(i.dataset.line||"",10);if(Number.isNaN(e))return null;let t=parseInt(i.dataset.lineEnd||"",10);return{start:e,end:Number.isNaN(t)?e:Math.max(e,t)}},v=(i,e)=>{let t=i.getBoundingClientRect().top+B(e)+1,n=null;return e.querySelectorAll("[data-line]").forEach(s=>{if(n!==null)return;let r=s.getBoundingClientRect();if(r.bottom<=t)return;let o=P(s);if(!o)return;let l=r.height>0?Math.min(1,Math.max(0,(t-r.top)/r.height)):0;n=o.start+l*(o.end-o.start)}),n},V=(i,e,t)=>{let n=null;if(t!==null){let o=e.querySelectorAll("[data-line]");for(let l of o){let c=P(l);if(!c)continue;if(c.start>t)break;let d=l.getBoundingClientRect();if(t<=c.end){let a=c.end>c.start?(t-c.start)/(c.end-c.start):0;n=d.top+a*d.height}else n=d.bottom}}let r=(n??e.getBoundingClientRect().top)-i.getBoundingClientRect().top-B(e);i.scrollTop=Math.max(0,i.scrollTop+r)},F=i=>{if(!i)return null;try{return`markon:diff:collapsed:${new URL(i,window.location.origin).pathname}`}catch{return`markon:diff:collapsed:${i}`}},G=i=>{let e=F(i);if(!e)return new Set;try{let t=window.localStorage.getItem(e);if(!t)return new Set;let n=JSON.parse(t);return Array.isArray(n)?new Set(n.filter(s=>typeof s=="string")):new Set}catch{return new Set}},U=(i,e)=>{let t=F(i);if(t)try{window.localStorage.setItem(t,JSON.stringify([...e]))}catch{}},$=i=>{if(!i)return null;try{return`markon:diff:viewed:${new URL(i,window.location.origin).pathname}`}catch{return`markon:diff:viewed:${i}`}},W=i=>{let e=$(i);if(!e)return new Set;try{let t=window.localStorage.getItem(e);if(!t)return new Set;let n=JSON.parse(t);return Array.isArray(n)?new Set(n.filter(s=>typeof s=="string")):new Set}catch{return new Set}},z=(i,e)=>{let t=$(i);if(t)try{window.localStorage.setItem(t,JSON.stringify([...e]))}catch{}},he=i=>{if(!i)return null;try{return`markon:diff:showviewed:${new URL(i,window.location.origin).pathname}`}catch{return`markon:diff:showviewed:${i}`}},j=i=>{let e=he(i);if(!e)return!1;try{let t=window.localStorage.getItem(e);return t===null?!1:t!=="0"}catch{return!1}};var K="markon:diff-viewed-changed",q="markon:diff-showviewed",me='<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path fill="currentColor" d="M12.78 6.22a.75.75 0 0 1 0 1.06l-4.25 4.25a.75.75 0 0 1-1.06 0L3.22 7.28a.75.75 0 0 1 1.06-1.06L8 9.94l3.72-3.72a.75.75 0 0 1 1.06 0Z"/></svg>',pe='<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path fill="currentColor" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 0 1 0 1.5h-1.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-1.5a.75.75 0 0 1 1.5 0v1.5A1.75 1.75 0 0 1 9.25 16h-7.5A1.75 1.75 0 0 1 0 14.25Z"/><path fill="currentColor" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0 1 14.25 11h-7.5A1.75 1.75 0 0 1 5 9.25Zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Z"/></svg>',ge='<svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path fill="currentColor" d="M8 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3ZM1.5 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Zm13 0a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z"/></svg>',we='<svg viewBox="0 0 16 16" width="13" height="13" aria-hidden="true"><path fill="currentColor" d="M5.22 14.78a.75.75 0 0 1 0-1.06L12.44 6.5H7.75a.75.75 0 0 1 0-1.5h6.5a.75.75 0 0 1 .75.75v6.5a.75.75 0 0 1-1.5 0V7.56l-7.22 7.22a.75.75 0 0 1-1.06 0Z"/></svg>',L=()=>document.querySelector('meta[name="workspace-id"]')?.getAttribute("content")||"",Ee=(i,e)=>e&&e!==i?`${e} -> ${i}`:i,be=(i,e,t)=>{let n=D(L(),i);if(!e)return n;let s=t&&t>0?`&line=${t}`:"";return`${n}?edit=1${s}`},Z=(i,e,t)=>{L()&&window.open(be(i,e,t),"_blank","noopener")},ke=i=>{let e=i.closest(".md-diff-file-section");if(!e)return;let t=e.parentElement;for(;t&&t.scrollHeight<=t.clientHeight+1;)t=t.parentElement;if(!t)return;let n=v(t,e);return n!=null?Math.max(1,Math.round(n)):void 0},Te=async(i,e)=>{try{await navigator.clipboard.writeText(i),e.classList.add("is-copied"),window.setTimeout(()=>e.classList.remove("is-copied"),1100)}catch{}},Se=async(i,e)=>{let t=L();if(t&&window.confirm(`Delete ${i}?
This removes the file from disk and cannot be undone.`))try{let n=await fetch(H(t),{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({path:i})}),s=await n.json().catch(()=>null);if(!(n.ok&&!!s&&s.success===!0)){let o=s?.message||"Delete failed";window.alert(`Could not delete ${i}: ${o}`);return}e?.()}catch(n){window.alert(`Could not delete ${i}: ${n instanceof Error?n.message:String(n)}`)}},ye=(i,e)=>{let t=document.createElement("span");t.className="md-diff-stat";let n=document.createElement("span");n.className="md-diff-stat-add",n.textContent=`+${i}`;let s=document.createElement("span");s.className="md-diff-stat-del",s.textContent=`-${e}`;let r=document.createElement("span");r.className="md-diff-stat-bars",r.setAttribute("aria-hidden","true");let o=i+e,l=0,c=0;if(o>0)for(l=i>0?Math.max(1,Math.round(i/o*5)):0,c=e>0?Math.max(1,Math.round(e/o*5)):0;l+c>5;)l>=c?l-=1:c-=1;for(let d=0;d<5;d+=1){let a=document.createElement("span");a.className=d<l?"md-diff-bar is-add":d<l+c?"md-diff-bar is-del":"md-diff-bar",r.appendChild(a)}return t.append(n,s,r),t},Y=(i,e)=>{let t=i.closest(".md-diff-file-header");t&&(t.style.zIndex=e?"6":"")},_=(i,e)=>{let t=i.querySelector(".md-diff-menu-pop");t&&(t.hidden=!0),e.setAttribute("aria-expanded","false"),i.classList.remove("is-open"),Y(i,!1),i.__cleanup?.(),i.__cleanup=void 0},_e=i=>{let e=document.createElement("div");e.className="md-diff-menu";let t=document.createElement("button");t.type="button",t.className="md-diff-menu-btn",t.setAttribute("aria-label","File actions"),t.setAttribute("aria-haspopup","menu"),t.setAttribute("aria-expanded","false"),t.innerHTML=ge;let n=document.createElement("div");n.className="md-diff-menu-pop",n.setAttribute("role","menu"),n.hidden=!0;let s=[{label:"Edit file",action:()=>Z(i.path,!0,ke(e))},{label:"Delete file",action:()=>{Se(i.path,i.onDeleted)},danger:!0}];for(let o of s){let l=document.createElement("button");l.type="button",l.className="md-diff-menu-item"+(o.danger?" is-danger":""),l.setAttribute("role","menuitem"),l.textContent=o.label,l.addEventListener("click",()=>{_(e,t),o.action()}),n.appendChild(l)}let r=o=>{if(n.hidden=!o,t.setAttribute("aria-expanded",o?"true":"false"),e.classList.toggle("is-open",o),Y(e,o),o){let l=d=>{e.contains(d.target)||_(e,t)},c=d=>{d.key==="Escape"&&_(e,t)};e.__cleanup=()=>{document.removeEventListener("mousedown",l,!0),document.removeEventListener("keydown",c,!0)},document.addEventListener("mousedown",l,!0),document.addEventListener("keydown",c,!0)}else e.__cleanup?.(),e.__cleanup=void 0};return t.addEventListener("click",()=>r(!e.classList.contains("is-open"))),e.append(t,n),e};function X(i){let e=document.createElement("header");e.className="md-diff-file-header md-diff-ui",e.classList.toggle("is-collapsed",i.collapsed);let t=document.createElement("div");t.className="md-diff-file-left";let n=document.createElement("button");n.type="button",n.className="md-diff-chevron",n.setAttribute("aria-label",i.collapsed?"Expand file":"Collapse file"),n.innerHTML=me,n.addEventListener("click",()=>i.onToggleCollapse());let s=document.createElement("span");s.className="md-diff-file-title",s.textContent=Ee(i.path,i.oldPath);let r=document.createElement("button");r.type="button",r.className="md-diff-file-copy",r.title="Copy path",r.setAttribute("aria-label","Copy path"),r.innerHTML=pe,r.addEventListener("click",()=>{Te(i.path,r)});let o=document.createElement("button");o.type="button",o.className="md-diff-file-open",o.title="Open file in new window",o.setAttribute("aria-label","Open file in new window"),o.innerHTML=we,o.addEventListener("click",()=>Z(i.path,!1)),t.append(n,s,r,o);let l=document.createElement("div");l.className="md-diff-file-right";let c=document.createElement("label");c.className="md-diff-file-check";let d=document.createElement("input");d.type="checkbox",d.checked=i.viewed,d.addEventListener("change",()=>i.onToggleViewed());let a=document.createElement("span");return a.textContent="Viewed",c.append(d,a),i.status==="renamed"&&!i.additions&&!i.deletions||l.append(ye(i.additions||0,i.deletions||0)),l.append(c,_e(i)),e.append(t,l),e.addEventListener("dblclick",u=>{u.target?.closest(".md-diff-chevron, .md-diff-file-copy, .md-diff-file-check, .md-diff-menu")||(window.getSelection()?.removeAllRanges(),i.onToggleCollapse())}),e}var m=(i,e)=>{let t=i[e];if(t===void 0)throw new RangeError(`Index ${e} is outside array bounds`);return t},Q=i=>{if(!i||typeof i!="object")return!1;let e=i;return!!e.engine&&Array.isArray(e.files)};function O(i,e=3){let t=i.length,n=new Array(t).fill(!1);for(let o=0;o<t;o+=1)if(m(i,o).kind!=="equal")for(let l=Math.max(0,o-e);l<=Math.min(t-1,o+e);l+=1)n[l]=!0;let s=[],r=0;for(;r<t;)if(n[r])s.push({kind:"block",block:m(i,r),index:r}),r+=1;else{let o=r,l=0;for(;r<t&&!n[r];)l+=1,r+=1;s.push({kind:"gap",start:o,count:l})}return s}var M=class{#o=new Map;has(e,t){return this.#o.get(e)?.has(t)??!1}add(e,t){let n=this.#o.get(e);n||(n=new Set,this.#o.set(e,n)),n.add(t)}},ve=()=>{let i=globalThis;return i.__markonDiffExpansion__||(i.__markonDiffExpansion__=new Map),i.__markonDiffExpansion__},Le=i=>{if(!i)return":default";try{return new URL(i,window.location.origin).pathname}catch{return i}};function ee(i){let e=ve(),t=Le(i),n=e.get(t);return n||(n=new M,e.set(t,n)),n}function te(i,e,t){let n=document.createElement("button");n.type="button",n.className=t?.standalone?"md-diff-gap md-diff-gap-standalone":"md-diff-gap";let s=document.createElement("span");s.className="md-diff-gap-label",s.innerHTML='<svg class="md-diff-gap-icon" viewBox="0 0 16 16" width="13" height="13" aria-hidden="true"><path fill="currentColor" d="M8 2.5 11.2 5.7l-1.06 1.06L8 4.62 5.86 6.76 4.8 5.7 8 2.5Z"/><path fill="currentColor" d="M8 13.5 4.8 10.3l1.06-1.06L8 11.38l2.14-2.14 1.06 1.06L8 13.5Z"/></svg>';let r=document.createElement("span"),o=i===1?"Show 1 unchanged block":`Show ${i} unchanged blocks`;return r.textContent=t?.standalone?t.note||o:t?.note?`${t.note} \xB7 ${o}`:o,s.appendChild(r),n.appendChild(s),n.addEventListener("click",()=>e(n)),n}var J=i=>i.match(/\s+|[A-Za-z0-9_]+|[^\s]/gu)??[];function ne(i,e){let t=J(i),n=J(e),s=t.length,r=n.length,o=Array.from({length:s+1},()=>new Array(r+1).fill(0));for(let u=s-1;u>=0;u-=1)for(let g=r-1;g>=0;g-=1){let p=m(o,u),E=m(o,u+1);p[g]=m(t,u)===m(n,g)?m(E,g+1)+1:Math.max(m(E,g),m(p,g+1))}let l=[],c=[],d=(u,g,p)=>{let E=u[u.length-1];E&&E.cls===p?E.text+=g:u.push({text:g,cls:p})},a=0,f=0;for(;a<s&&f<r;){let u=m(t,a),g=m(n,f);u===g?(d(l,u,null),d(c,g,null),a+=1,f+=1):m(m(o,a+1),f)>=m(m(o,a),f+1)?(d(l,u,"del"),a+=1):(d(c,g,"add"),f+=1)}for(;a<s;)d(l,m(t,a),"del"),a+=1;for(;f<r;)d(c,m(n,f),"add"),f+=1;return{old:l,new:c}}function ie(i,e){let t=i.length,n=e.length,s=Array.from({length:t+1},()=>new Array(n+1).fill(0));for(let f=t-1;f>=0;f-=1)for(let u=n-1;u>=0;u-=1){let g=m(s,f),p=m(s,f+1);g[u]=m(i,f)===m(e,u)?m(p,u+1)+1:Math.max(m(p,u),m(g,u+1))}let r=[],o=0,l=0,c=(f,u)=>{let g=Math.min(f.length,u.length);for(let p=0;p<g;p+=1)r.push({type:"replace",oldIndex:m(f,p),newIndex:m(u,p)});for(let p=g;p<f.length;p+=1)r.push({type:"del",oldIndex:m(f,p)});for(let p=g;p<u.length;p+=1)r.push({type:"add",newIndex:m(u,p)})},d=[],a=[];for(;o<t&&l<n;)m(i,o)===m(e,l)?(c(d,a),d=[],a=[],r.push({type:"equal",oldIndex:o,newIndex:l}),o+=1,l+=1):m(m(s,o+1),l)>=m(m(s,o),l+1)?(d.push(o),o+=1):(a.push(l),l+=1);for(;o<t;)d.push(o),o+=1;for(;l<n;)a.push(l),l+=1;return c(d,a),r}function x(i,e,t){if(!i||e==null)return[];let n=i.split(`
`),s=Math.max(1,e),r=Math.max(s,t??e);return n.slice(s-1,r)}var h=typeof window<"u"&&window.__MARKON_I18N__?.t||(i=>i),oe={t(i,...e){let t=typeof window<"u"&&window.__MARKON_I18N__?.t||null;return t?t(i,...e):i}},w={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:h("web.kbd.help"),cat:"global"},THEME_PANEL:{key:"t",ctrl:!1,shift:!1,desc:h("web.kbd.theme"),cat:"global"},UNDO:{key:"z",ctrl:!0,shift:!1,desc:h("web.kbd.undo"),cat:"core"},REDO:{key:"z",ctrl:!0,shift:!0,desc:h("web.kbd.redo"),cat:"core"},REDO_ALT:{key:"y",ctrl:!0,shift:!1,desc:h("web.kbd.redo.alt"),cat:"core"},ESCAPE:{key:"Escape",ctrl:!1,shift:!1,desc:h("web.kbd.escape"),cat:"core"},TOGGLE_TOC:{key:"\\",ctrl:!0,shift:!1,desc:h("web.kbd.toc"),cat:"core"},SEARCH:{key:"/",ctrl:!1,shift:!1,desc:h("web.kbd.search"),cat:"search",feature:"workspace_spotlight"},EXPORT_NOTES:{key:"x",ctrl:!1,shift:!1,desc:h("web.kbd.exportnotes"),cat:"core"},WORKSPACE_NAVIGATOR:{key:"g",ctrl:!1,shift:!1,desc:h("web.kbd.workspace_nav"),cat:"search",feature:"workspace_spotlight"},PREV_HEADING:{key:"k",ctrl:!1,shift:!1,desc:h("web.kbd.prevheading"),cat:"nav"},NEXT_HEADING:{key:"j",ctrl:!1,shift:!1,desc:h("web.kbd.nextheading"),cat:"nav"},PREV_ANNOTATION:{key:"k",ctrl:!0,shift:!1,desc:h("web.kbd.prevanno"),cat:"nav"},NEXT_ANNOTATION:{key:"j",ctrl:!0,shift:!1,desc:h("web.kbd.nextanno"),cat:"nav"},SCROLL_HALF_PAGE_DOWN:{key:" ",ctrl:!1,shift:!1,desc:h("web.kbd.scroll"),cat:"nav"},TOGGLE_SECTION_COLLAPSE:{key:"o",ctrl:!1,shift:!1,desc:h("web.kbd.collapse"),cat:"viewed"},TOGGLE_VIEWED:{key:"v",ctrl:!1,shift:!1,desc:h("web.kbd.viewed"),cat:"viewed"},EDIT:{key:"e",ctrl:!1,shift:!1,desc:h("web.kbd.edit"),cat:"edit"},TOGGLE_LIVE_ACTIVE:{key:"l",ctrl:!1,shift:!1,desc:h("web.kbd.live.active"),cat:"live"},TOGGLE_LIVE_OFF:{key:"l",ctrl:!1,shift:!0,desc:h("web.kbd.live.off"),cat:"live"},TOGGLE_CHAT:{key:"c",ctrl:!1,shift:!1,desc:h("web.kbd.chat"),cat:"chat"},TOGGLE_CHAT_ALT:{key:"c",ctrl:!1,shift:!0,desc:h("web.kbd.chat.alt"),cat:"chat"},DIFF_TOGGLE_VIEW:{key:"m",ctrl:!1,shift:!1,desc:h("web.kbd.diff.view"),cat:"diff"},DIFF_NEXT_FILE:{key:"n",ctrl:!1,shift:!1,desc:h("web.kbd.diff.nextfile"),cat:"diff"},DIFF_PREV_FILE:{key:"p",ctrl:!1,shift:!1,desc:h("web.kbd.diff.prevfile"),cat:"diff"},VISUAL_ZOOM_IN:{key:"+",ctrl:!1,shift:!1,desc:h("web.kbd.visual.zoom_in"),cat:"visual",feature:"visual_zoom_in"},VISUAL_ZOOM_IN_ALT:{key:"=",ctrl:!1,shift:!1,desc:h("web.kbd.visual.zoom_in"),cat:"visual",feature:"visual_zoom_in"},VISUAL_ZOOM_OUT:{key:"-",ctrl:!1,shift:!1,desc:h("web.kbd.visual.zoom_out"),cat:"visual"},VISUAL_ZOOM_RESET:{key:"0",ctrl:!1,shift:!1,desc:h("web.kbd.visual.reset"),cat:"visual",feature:"visual_reset"},VISUAL_ZOOM_RESET_ALT:{key:"r",ctrl:!1,shift:!1,desc:h("web.kbd.visual.reset"),cat:"visual",feature:"visual_reset"},VISUAL_ZOOM_FIT:{key:"f",ctrl:!1,shift:!1,desc:h("web.kbd.visual.fit"),cat:"visual",feature:"visual_fit"},VISUAL_ZOOM_FIT_CMD:{key:"0",ctrl:!0,shift:!1,desc:h("web.kbd.visual.fit"),cat:"visual",feature:"visual_fit"},VISUAL_ZOOM_TOOL:{key:"z",ctrl:!1,shift:!1,desc:h("web.kbd.visual.tool"),cat:"visual"},VISUAL_ZOOM_TOOL_OUT:{key:"z",ctrl:!1,shift:!0,desc:h("web.kbd.visual.tool_out"),cat:"visual"},VISUAL_ZOOM_CLOSE:{key:"Escape",ctrl:!1,shift:!1,desc:h("web.kbd.visual.close"),cat:"visual",feature:"ESCAPE"}},STORAGE_KEYS:{ANNOTATIONS:i=>`markon-annotations-${i}`,VIEWED:i=>`markon-viewed-${i}`,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 i=Object.entries(window.__MARKON_SHORTCUTS__);for(let[e,t]of i)w.SHORTCUTS[e]&&Object.assign(w.SHORTCUTS[e],t)}Object.freeze(w);Object.freeze(w.BREAKPOINTS);Object.freeze(w.DIMENSIONS);Object.freeze(w.THRESHOLDS);Object.freeze(w.WEBSOCKET);Object.freeze(w.ANIMATION);Object.freeze(w.UNDO);Object.freeze(w.SHORTCUTS);Object.freeze(w.SELECTORS);Object.freeze(w.SKIP_ELEMENTS);Object.freeze(w.META_TAGS);Object.freeze(w.WS_MESSAGE_TYPES);Object.freeze(w.COLLABORATION);Object.freeze(w.ANNOTATION_TYPES);Object.freeze(w.HTML_TAGS);var Me=(i,...e)=>oe.t(i,...e),se=i=>`${Me("web.export.label")} (${i})`,Oe=()=>{try{let i=window.location.hash;return i&&decodeURIComponent(i.slice(1))||null}catch{return null}},xe=i=>{try{let e=new URL(i,window.location.origin);return e.searchParams.delete("f"),`${e.pathname}${e.search}${e.hash}`}catch{return i}},y=class{root;#o=null;#l=[];#n=null;#e=new Map;#s=null;#a=null;#t=new Set;#i=new Set;#r=!0;#d=null;#c=null;scrollElement=null;constructor(e){this.root=e,document.addEventListener(q,t=>{let n=t.detail;n&&typeof n.showViewed=="boolean"&&(this.#r=n.showViewed,this.#p())}),document.addEventListener("markon:diff-annotations-ready",()=>{this.#g()}),document.addEventListener("markon:diff-notes-count-changed",()=>{this.#g()})}get bodyClass(){return""}fileLead(e){return null}onRender(e){}onFiles(e){}get emptyBlocksMessage(){return"No content to preview."}afterContentRendered(){}async load(){let e=this.root.dataset.diffDataUrl?xe(this.root.dataset.diffDataUrl):void 0;if(e){if(this.#n===null&&(this.#n=Oe()),this.root.dataset.diffLoadedUrl===e){this.#E();return}if(this.root.dataset.diffLoadingUrl!==e){this.root.dataset.diffLoadingUrl=e;try{let t=await fetch(e,{headers:{Accept:"application/json"}});if(!t.ok)throw new Error(await t.text());let n=await t.json();if(!Q(n))throw new Error("Invalid Markdown diff payload");this.#o=n,this.root.dataset.diffLoadedUrl=e,this.#E()}catch(t){delete this.root.dataset.diffLoadedUrl,this.#w(`Failed to load diff: ${t instanceof Error?t.message:String(t)}`,!0)}finally{delete this.root.dataset.diffLoadingUrl}}}}selectPath(e){this.#n=e||null,this.#e.size&&this.#n?this.scrollToPath(this.#n):this.#o||this.load()}scrollToPath(e){this.#e.get(e)?.section.scrollIntoView({block:"start",behavior:"instant"})}topAnchor(){let e=R(this.scrollElement);if(!e||!this.scrollElement)return null;let t=this.#e.get(e);return{path:e,line:t?v(this.scrollElement,t.section):null}}anchorTo(e){this.#d=e}syncLayout(){}#E(){let e=this.#o;if(e){if(this.onRender(e),!e.engine.enabled){this.#w(e.engine.message||"Markdown engine is not enabled.",!0);return}if(!e.files.length){this.#w("No Markdown files changed in this diff.");return}this.#_(e.files)}}#f(){return this.paneSelector?this.root.querySelector(this.paneSelector):this.root}#_(e){let t=this.#f();if(!t)return;this.#S(),this.onFiles(e),t.textContent="",t.classList.add(this.virtualizedClass),this.#l=e,this.#t=G(this.root.dataset.diffDataUrl),this.#i=W(this.root.dataset.diffDataUrl),this.#r=j(this.root.dataset.diffDataUrl),this.#c=ee(this.root.dataset.diffDataUrl),this.#e=new Map;let n=(this.scrollSelector?this.root.querySelector(this.scrollSelector):this.root)||this.root;this.scrollElement=n;let s=document.createDocumentFragment();for(let r of e){let o=this.#v(r);this.#e.set(r.path,o),s.appendChild(o.section)}if(t.appendChild(s),this.#p(),n.scrollTo({top:0,left:0,behavior:"instant"}),typeof IntersectionObserver<"u"){let r=new IntersectionObserver(o=>{for(let l of o){let c=l.target.dataset.filePath,d=c?this.#e.get(c):void 0;d&&(l.isIntersecting?this.#u(d):this.#M(d))}},{root:n,rootMargin:"1200px 0px"});this.#s=r;for(let o of this.#e.values())r.observe(o.section)}else for(let r of this.#e.values())this.#u(r);if(this.#a=()=>{this.#s?.disconnect(),this.#s=null},this.#d){let r=this.#d;this.#d=null;let o=this.#e.get(r.path);if(o){for(let l of this.#e.values())if(this.#u(l),l===o)break;V(n,o.section,r.line)}}else this.#n&&this.#e.get(this.#n)?.section.scrollIntoView({block:"start",behavior:"instant"});this.afterContentRendered()}#v(e){let t=document.createElement("section");t.className="md-diff-file-section",t.dataset.filePath=e.path,e.abs_path&&(t.dataset.absPath=e.abs_path),e.status==="renamed"&&!e.additions&&!e.deletions&&t.classList.add("is-pure-rename");let n=this.#t.has(e.path);t.classList.toggle("is-collapsed",n);let s=document.createElement("div");s.className=`md-diff-file-body${this.bodyClass?` ${this.bodyClass}`:""}`;let r={file:e,section:t,body:s,rendered:!1,estHeight:this.#O(e)};return t.append(this.#h(e),s),n||(s.style.minHeight=`${r.estHeight}px`),r}#h(e){let t={path:e.path,status:e.status,additions:e.additions||0,deletions:e.deletions||0,collapsed:this.#t.has(e.path),viewed:this.#i.has(e.path),onToggleCollapse:()=>this.#b(e.path),onToggleViewed:()=>this.#x(e.path),onDeleted:()=>{this.#e.get(e.path)?.section.remove(),this.#e.delete(e.path),this.#l=this.#l.filter(s=>s.path!==e.path)}};return X(e.old_path===void 0?t:{...t,oldPath:e.old_path})}#m(e,t){let n=e.blocks[t];if(!n)throw new RangeError(`Diff block index ${t} is outside ${e.path}`);return n}#u(e){if(e.rendered||this.#t.has(e.file.path))return;let t=e.file,n=document.createDocumentFragment(),s=this.fileLead(t);if(s&&n.appendChild(s),!t.blocks.length)n.appendChild(this.#y(this.emptyBlocksMessage));else{let r=this.#c;for(let o of O(t.blocks))if(o.kind==="block")n.appendChild(this.renderBlock(t,o.block,o.index));else if(r?.has(t.path,o.start))for(let l=o.start;l<o.start+o.count;l+=1)n.appendChild(this.renderBlock(t,this.#m(t,l),l));else n.appendChild(this.#L(t,o.start,o.count))}e.body.replaceChildren(n),e.body.style.minHeight="",e.body.style.height="",e.rendered=!0,this.afterBodyRendered(e.body)}afterBodyRendered(e){}#L(e,t,n){let r=e.status==="renamed"&&!e.additions&&!e.deletions?{note:"This file was only renamed or moved \u2014 its content is unchanged.",standalone:!0}:void 0;return te(n,o=>{this.#c?.add(e.path,t);let l=o.parentElement??this.root,c=document.createDocumentFragment();for(let b=t;b<t+n;b+=1)c.appendChild(this.renderBlock(e,this.#m(e,b),b));let d=this.scrollElement,a=o.nextElementSibling,f=a?a.getBoundingClientRect().top:null,u=()=>{d&&a&&f!==null&&(d.scrollTop+=a.getBoundingClientRect().top-f)};if(window.matchMedia?.("(prefers-reduced-motion: reduce)").matches||typeof requestAnimationFrame!="function"){o.replaceWith(c),u(),this.afterBodyRendered(l);return}d&&(d.style.overflowAnchor="none");let p=document.createElement("div");p.className="md-diff-reveal",p.appendChild(c),o.replaceWith(p),u();let E=!1,C=()=>{if(E)return;E=!0;let b=document.createDocumentFragment();for(;p.firstChild;)b.appendChild(p.firstChild);p.replaceWith(b),u(),this.afterBodyRendered(l)};p.addEventListener("transitionend",b=>{b.propertyName==="opacity"&&C()}),window.setTimeout(C,700),requestAnimationFrame(()=>{d&&(d.style.overflowAnchor=""),p.classList.add("is-open")})},r)}#M(e){if(!e.rendered||this.#t.has(e.file.path))return;let t=e.body.offsetHeight;e.body.replaceChildren(),e.body.style.minHeight=`${t||e.estHeight}px`,e.rendered=!1}#O(e){let t=e.diagnostics.length?40:0;if(!e.blocks.length)return t+58;let n=this.#c;for(let s of O(e.blocks))if(s.kind==="block")t+=this.estimateBlock(s.block);else if(n?.has(e.path,s.start))for(let r=s.start;r<s.start+s.count;r+=1)t+=this.estimateBlock(this.#m(e,r));else t+=30;return t}#b(e){let t=this.#e.get(e),n=!this.#t.has(e);if(n?this.#t.add(e):this.#t.delete(e),U(this.root.dataset.diffDataUrl,this.#t),!t)return;let s=this.scrollElement,r=t.section.getBoundingClientRect().top;if(t.section.classList.toggle("is-collapsed",n),t.section.firstElementChild?.replaceWith(this.#h(t.file)),n?(t.body.replaceChildren(),t.body.style.minHeight="",t.body.style.height="",t.rendered=!1):(t.body.style.minHeight=`${t.estHeight}px`,this.#u(t)),s){let o=t.section.getBoundingClientRect().top;s.scrollTop+=o-r}}#x(e){let t=!this.#i.has(e);if(t?this.#i.add(e):this.#i.delete(e),z(this.root.dataset.diffDataUrl,this.#i),t!==this.#t.has(e))this.#b(e);else{let n=this.#e.get(e);n?.section.firstElementChild?.replaceWith(this.#h(n.file))}this.#p(),document.dispatchEvent(new CustomEvent(K,{detail:{viewed:[...this.#i]}}))}#p(){let e=!1;for(let[s,r]of this.#e){let o=!this.#r&&this.#i.has(s);r.section.hidden=o,o||(e=!0)}let t=this.#e.size>0&&[...this.#e.keys()].every(s=>this.#i.has(s)),n=this.#f();n&&(!this.#r&&this.#e.size>0&&!e?(n.querySelector(".md-diff-viewed-done")?.remove(),this.#k("empty")):(n.querySelector(".md-diff-viewed-empty")?.remove(),this.#r&&t?this.#k("done"):n.querySelector(".md-diff-viewed-done")?.remove()))}#k(e){let t=this.#f(),n=e==="empty"?"md-diff-viewed-empty":"md-diff-viewed-done";if(!t)return;if(t.querySelector(`.${n}`)){this.#g();return}let r=document.createElement("div");r.className=n,r.innerHTML='<div class="md-diff-viewed-empty-emoji">\u{1F389}</div><div class="md-diff-viewed-empty-title">All done \u2014 every changed file is marked Viewed.</div>';let o=document.createElement("div");o.className="md-diff-viewed-empty-actions";let l=document.createElement("button");l.type="button",l.className="md-diff-viewed-empty-link",l.textContent=e==="empty"?"Show all files":"Hide all Viewed files",l.addEventListener("click",()=>{let d=document.querySelector("[data-diff-show-viewed]");d&&(d.checked=e==="done",d.dispatchEvent(new Event("change",{bubbles:!0})))});let c=document.createElement("button");c.type="button",c.className="md-diff-viewed-empty-link md-diff-viewed-export-notes",c.textContent=se(0),c.addEventListener("click",()=>{if(c.disabled||c.getAttribute("aria-disabled")==="true")return;let d=window.markonDiffAnnotations?.exportNotes;d&&d(c)}),o.append(l,c),r.appendChild(o),t.appendChild(r),this.#T(c)}#g(){this.root.querySelectorAll(".md-diff-viewed-export-notes").forEach(e=>{this.#T(e)})}async#T(e){let t=Math.max(0,await(window.markonDiffAnnotations?.notesCount?.()??Promise.resolve(0)));if(!e.isConnected)return;e.textContent=se(t);let n=t===0;e.disabled=n,e.classList.toggle("is-disabled",n),e.setAttribute("aria-disabled",n?"true":"false")}#S(){this.#a?.(),this.#a=null,this.#s?.disconnect(),this.#s=null,this.#e=new Map,this.scrollElement=null}#y(e,t=!1){let n=document.createElement("div");return n.className="md-diff-empty",t&&(n.style.color="var(--markon-danger)"),n.textContent=e,n}#w(e,t=!1){this.#S();let n=this.#f();n&&(n.classList.remove(this.virtualizedClass),n.textContent="",n.appendChild(this.#y(e,t)))}text(e,t){let n=this.root.querySelector(e);n&&(n.textContent=t)}};var N="git-diff-empty-side",S=(i,e)=>{let t=i[e];if(t===void 0)throw new RangeError(`Line index ${e} is outside array bounds`);return t},A=class extends y{get scrollSelector(){return null}get paneSelector(){return null}get virtualizedClass(){return"is-virtualized-diff"}get bodyClass(){return"workspace-diff-body"}get emptyBlocksMessage(){return"No source to preview."}#o(){return this.root.dataset.rawLayout==="unified"}estimateBlock(e){let t=this.#r(e.old),n=this.#r(e.new),s=this.#o()?t+n:Math.max(t,n),r=e.kind==="modified"?s:e.kind==="equal"?n||t:e.kind==="deleted"?t:n;return Math.max(24,r*22)}renderBlock(e,t,n){let s=document.createElement("div");s.className=`diff-change-block workspace-diff-block is-${t.kind}`,s.dataset.mdDiffPair=String(n);let r=this.#l(e,t);if(this.#o())for(let o of r)this.#a(s,o);else for(let o of r)s.appendChild(this.#e(o.old,o.new));return s}#l(e,t){let n=x(e.old_source,t.old?.start_line,t.old?.end_line),s=x(e.new_source,t.new?.start_line,t.new?.end_line),r=t.old?.start_line??null,o=t.new?.start_line??null,l=[];if(t.kind==="equal"){let a=Math.max(n.length,s.length);for(let f=0;f<a;f+=1){let u=s[f]??n[f]??"";l.push({old:{no:r!=null?r+f:null,segs:[{text:u,cls:null}],cls:"git-diff-ctx"},new:{no:o!=null?o+f:null,segs:[{text:u,cls:null}],cls:"git-diff-ctx"}})}return l}if(t.kind==="added")return s.forEach((a,f)=>l.push({old:this.#n(),new:{no:o!=null?o+f:null,segs:[{text:a,cls:"add"}],cls:"git-diff-add"}})),l;if(t.kind==="deleted")return n.forEach((a,f)=>l.push({old:{no:r!=null?r+f:null,segs:[{text:a,cls:"del"}],cls:"git-diff-del"},new:this.#n()})),l;let c=a=>r!=null?r+a:null,d=a=>o!=null?o+a:null;for(let a of ie(n,s))if(a.type==="equal"){let f=S(s,a.newIndex);l.push({old:{no:c(a.oldIndex),segs:[{text:f,cls:null}],cls:"git-diff-ctx"},new:{no:d(a.newIndex),segs:[{text:f,cls:null}],cls:"git-diff-ctx"}})}else if(a.type==="replace"){let{old:f,new:u}=ne(S(n,a.oldIndex),S(s,a.newIndex));l.push({old:{no:c(a.oldIndex),segs:f,cls:"git-diff-del"},new:{no:d(a.newIndex),segs:u,cls:"git-diff-add"}})}else a.type==="del"?l.push({old:{no:c(a.oldIndex),segs:[{text:S(n,a.oldIndex),cls:"del"}],cls:"git-diff-del"},new:this.#n()}):l.push({old:this.#n(),new:{no:d(a.newIndex),segs:[{text:S(s,a.newIndex),cls:"add"}],cls:"git-diff-add"}});return l}#n(){return{no:null,segs:[],cls:N}}#e(e,t){let n=document.createElement("div");n.className="workspace-diff-row-line workspace-diff-split-line";let s=t.no??e.no;return s!=null&&(n.dataset.line=String(s)),n.append(this.#s(e),this.#s(t)),n}#s(e){let t=document.createElement("div");t.className=`workspace-diff-split-cell ${e.cls}`;let n=document.createElement("span");return n.className="workspace-diff-line-no",n.textContent=e.no==null?"":String(e.no),t.append(n,this.#i(e.segs)),t}#a(e,t){let n=t.old.cls===N,s=t.new.cls===N;if(!n&&!s&&t.old.cls==="git-diff-ctx"){e.appendChild(this.#t(t.old.no,t.new.no,t.new.segs,"git-diff-ctx","\xA0"));return}n||e.appendChild(this.#t(t.old.no,null,t.old.segs,"git-diff-del","-")),s||e.appendChild(this.#t(null,t.new.no,t.new.segs,"git-diff-add","+"))}#t(e,t,n,s,r){let o=document.createElement("div");o.className=`workspace-diff-row-line workspace-diff-unified-line ${s}`;let l=t??e;l!=null&&(o.dataset.line=String(l));let c=document.createElement("span");c.className="workspace-diff-line-no",c.textContent=e==null?"":String(e);let d=document.createElement("span");d.className="workspace-diff-line-no",d.textContent=t==null?"":String(t);let a=document.createElement("span");return a.className="workspace-diff-sign",a.textContent=r,o.append(c,d,a,this.#i(n)),o}#i(e){let t=document.createElement("code");t.className="workspace-diff-code";for(let n of e)if(n.cls){let s=document.createElement("span");s.className=n.cls==="add"?"git-diff-word-add":"git-diff-word-del",s.textContent=n.text,t.appendChild(s)}else t.appendChild(document.createTextNode(n.text));return t}#r(e){return e?.start_line==null?1:Math.max(1,(e.end_line??e.start_line)-e.start_line+1)}},re=new WeakMap,k=i=>{let e=re.get(i);return e||(e=new A(i),re.set(i,e)),e},T=()=>document.querySelector("[data-virtual-diff]"),le=(i=T())=>{i&&k(i).load()},Ne=(i,e=T())=>{e&&k(e).selectPath(i||null)},ae=()=>{document.querySelectorAll("[data-virtual-diff]").forEach(i=>{k(i),i.dataset.diffAutoload!=="false"&&le(i)}),window.markonSourceDiff={load:()=>le(),selectPath:i=>Ne(i),scrollToPath:i=>{let e=T();e&&k(e).scrollToPath(i)},topAnchor:()=>{let i=T();return i?k(i).topAnchor():null},anchorTo:i=>{let e=T();e&&k(e).anchorTo(i)},setLayout:i=>{let e=T();if(!e||e.dataset.rawLayout===i)return;let t=k(e),n=t.topAnchor();e.dataset.rawLayout=i,n&&t.anchorTo(n),t.load()}}};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",ae,{once:!0}):ae();