ryugi-artifacts 1.121.1 → 1.121.3

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.
Files changed (48) hide show
  1. package/dist/cli.cjs +54 -54
  2. package/dist/document-engine.cjs +2 -2
  3. package/dist/runtime/ryugi-report.js +2 -1
  4. package/dist/viewer/{ArtboardLayout-6tJS23QW.js → ArtboardLayout-C4SfKNrD.js} +3 -3
  5. package/dist/viewer/{DocumentLayout-BjURocqM.js → DocumentLayout-BQvL4hxv.js} +2 -2
  6. package/dist/viewer/{DocumentPage-H6a9SW4D.js → DocumentPage-CevLehCC.js} +1 -1
  7. package/dist/viewer/{PreviewLayout-C-sly_jL.js → PreviewLayout-CgZgREtY.js} +2 -2
  8. package/dist/viewer/{SnapshotDocument-TKnFyGcv.js → SnapshotDocument-wpaV_vFy.js} +1 -1
  9. package/dist/viewer/{VerifyLayout-DgokULV2.js → VerifyLayout-DpZYMcZ_.js} +1 -1
  10. package/dist/viewer/{VirtualizedEditor-uWe43zaI-BlOdeG0b.js → VirtualizedEditor-uWe43zaI-Ygx3kFhs.js} +1 -1
  11. package/dist/viewer/{VirtualizedRenderer-C_d95FXi-Bb6aPJaZ.js → VirtualizedRenderer-C_d95FXi-Cy5kUbtO.js} +1 -1
  12. package/dist/viewer/{channel-DST3ZfoT.js → channel-C4FlYe6r.js} +3 -3
  13. package/dist/viewer/{dist-B7GHMwWJ.js → dist-AtCs8Ac_.js} +1 -1
  14. package/dist/viewer/{dist-CEyDZYnP.js → dist-B1bCPRCC.js} +1 -1
  15. package/dist/viewer/{dist-Dr8Mok4z.js → dist-BCMQBMNV.js} +1 -1
  16. package/dist/viewer/{dist-CAQYce5C.js → dist-BGLWo-yk.js} +1 -1
  17. package/dist/viewer/{dist-CJicYh3N.js → dist-BLB83LMN.js} +1 -1
  18. package/dist/viewer/{dist-gLcMD1Nm.js → dist-Bt8gKTDd.js} +1 -1
  19. package/dist/viewer/{dist-Bw8MOHnL.js → dist-BuGXZft6.js} +1 -1
  20. package/dist/viewer/{dist-D32zdSlG.js → dist-ByWK_S-6.js} +1 -1
  21. package/dist/viewer/{dist-DV8S7O88.js → dist-C-70ebrb.js} +1 -1
  22. package/dist/viewer/dist-C4TwVfMo.js +1 -0
  23. package/dist/viewer/{dist-B9cyrbzi.js → dist-C4gob63X.js} +1 -1
  24. package/dist/viewer/{dist-CrYVEXMn.js → dist-CB0JDkTG.js} +1 -1
  25. package/dist/viewer/{dist-CLdHiTLp.js → dist-CE49yRAi.js} +1 -1
  26. package/dist/viewer/{dist-D26TaXjP.js → dist-CHkJJlnH.js} +1 -1
  27. package/dist/viewer/{dist-462HZ4sr.js → dist-C_cSpv_W.js} +1 -1
  28. package/dist/viewer/{dist-N6Hpo5Ed.js → dist-CaB2nVTP.js} +1 -1
  29. package/dist/viewer/{dist-opUfcW4x.js → dist-DIzctmKk.js} +1 -1
  30. package/dist/viewer/{dist-CNry8POH.js → dist-DWO10Qm_.js} +1 -1
  31. package/dist/viewer/{dist-Cfyg-ZFz.js → dist-DZS8BZv4.js} +1 -1
  32. package/dist/viewer/{dist-Dz80ecx_.js → dist-Dgb15Ckj.js} +1 -1
  33. package/dist/viewer/{dist-DUysbnVD.js → dist-DpjlLiVm.js} +1 -1
  34. package/dist/viewer/{dist-DlFC92UU.js → dist-IYw7p7AW.js} +1 -1
  35. package/dist/viewer/{dist-2resm9Wy.js → dist-Kyn4c3Uq.js} +1 -1
  36. package/dist/viewer/{dist-Bost_p8b.js → dist-jVyrk7pL.js} +1 -1
  37. package/dist/viewer/{editor-rLQcZykK.js → editor-yZwTWy-w.js} +4 -4
  38. package/dist/viewer/index.js +2 -2
  39. package/dist/viewer/{plugin-_bGVeqI0-C4RRMCGb.js → plugin-_bGVeqI0-Bsz7oxOL.js} +2 -2
  40. package/dist/viewer/preview.html +1 -1
  41. package/dist/viewer/preview.js +1 -1
  42. package/dist/viewer/{printDocument-BhGNF0gC.js → printDocument-GFcncwq5.js} +1 -1
  43. package/dist/viewer/route-messages-CxWq6xYk.js +1 -0
  44. package/dist/viewer/{split-CxmPPvad.js → split-Sl7JTYgL.js} +1 -1
  45. package/dist/viewer/{viewport-CFJHn_Y6-B_DJWWd0.js → viewport-CFJHn_Y6-CwlLMc7X.js} +1 -1
  46. package/package.json +1 -1
  47. package/dist/viewer/dist-CkWqj1vB.js +0 -1
  48. package/dist/viewer/route-messages-MxWI01S2.js +0 -1
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{Ft as t,It as n,Lt as r,Mt as i,Nt as a,Pt as o,jt as s}from"./editor-rLQcZykK.js";import{c,i as l,l as u,n as d,o as f,r as p,s as m,t as h}from"./viewport-CFJHn_Y6-B_DJWWd0.js";import{$r as g,Ai as _,Ar as v,Bi as y,Gn as b,Hr as x,Lr as S,Ra as C,Ri as w,Rr as T,Si as E,Wn as D,Zi as O,_i as k,_n as A,ga as j,ia as ee,ir as M,ja as N,ka as P,ni as F,pa as I,pi as L,qn as R,sa as z,xr as B,zi as V,zr as H}from"./WhiteboardEditor-DrHOvXez-DTa-K6Xu.js";import{t as U}from"./react-DlmbjZJV.js";import{A as W}from"./route-i3jkzu-i.js";import{t as G}from"./jsx-runtime-LKYXHABd.js";var K=e(U(),1),q=e(W(),1),J=G(),Y=class{constructor(e){n(this,`host`,void 0),n(this,`range`,void 0),n(this,`listeners`,new Set),this.host=e}get editor(){return this.host.master}keys(){let e=this.bounds();return e?this.host.rows.slice(e[0],e[1]+1).map(e=>e.key):[]}islandKeys(e){let t=this.bounds(),n=this.host.islandIds(e);return!t||!n?[]:e.getEditorState().read(()=>B().getChildren().filter((e,r)=>{let i=n[r]===void 0?void 0:this.host.indexOf(n[r]);return i!==void 0&&i>=t[0]&&i<=t[1]}).map(e=>e.getKey()))}documentKeys(e,t){let n=this.host.islandIds(e);if(!n)return[];let r=e.getEditorState().read(()=>B().getChildren().map(e=>e.getKey()));return t.flatMap(e=>{let t=n[r.indexOf(e)],i=t===void 0?void 0:this.host.indexOf(t);return i===void 0?[]:[this.host.rows[i].key]})}select(e,t,n){let r=this.host.islandIds(e);if(!r)return;let[i,a]=e.getEditorState().read(()=>{let e=B().getChildren().map(e=>e.getKey());return[r[e.indexOf(t)],r[e.indexOf(n)]]});i&&a&&this.set({anchorId:i,focusId:a})}selectAll(){let{rows:e}=this.host;e.length&&this.set({anchorId:e[0].id,focusId:e.at(-1).id})}extend(e){let t=this.range&&this.host.indexOf(this.range.focusId),n=t===void 0?void 0:this.host.rows[t+e];return!this.range||!n?!1:(this.set({anchorId:this.range.anchorId,focusId:n.id}),!0)}clear(){this.range&&this.set(void 0)}prune(){this.range&&(this.host.indexOf(this.range.anchorId)===void 0||this.host.indexOf(this.range.focusId)===void 0)&&this.set(void 0)}focusSelection(){let e=this.host.master.getEditorState().read(()=>{let e=H();if(!L(e))return null;let t=e.anchor.getNode(),n=t.getTopLevelElement()??t,r=(z(n)?n.getLastDescendant():null)??n;return{key:n.getKey(),end:t.is(r)&&e.anchor.offset===t.getTextContentSize()}}),t=e?this.host.rows.findIndex(t=>t.key===e.key):-1;t>=0&&this.host.focusBlock(t,e.end)}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}bounds(){if(!this.range)return null;let e=this.host.indexOf(this.range.anchorId),t=this.host.indexOf(this.range.focusId);return e===void 0||t===void 0?null:[Math.min(e,t),Math.max(e,t)]}set(e){this.range=e,this.listeners.forEach(e=>e())}};function X(e){let t=E(e);z(e)&&(t.children=e.getChildren().map(X));for(let n of _(e))t.$slots??={},t.$slots[n]=X(V(e,n));return t}var Z=class{constructor(e){n(this,`editor`,void 0),n(this,`rows`,[]),n(this,`onChange`,void 0),n(this,`unsubscribe`,void 0),n(this,`lastEdit`,void 0),this.editor=e,this.read(),this.unsubscribe=e.registerUpdateListener(({dirtyElements:e,dirtyLeaves:t,tags:n})=>{if(!e.size&&!t.size)return;this.read(new Set([...e.keys(),...t]));let r=[...n].find(e=>e.startsWith(`virtual-island:`));r||(this.lastEdit=void 0),this.onChange?.(r)})}read(e){let t=new Map(this.rows.map(e=>[e.key,e]));this.rows=this.editor.getEditorState().read(()=>B().getChildren().map(n=>{let r=n.getKey(),i=t.get(r);if(i?.node===n&&!e?.has(r))return i;let a=X(n);return{data:a,key:r,node:n,id:F(n,o)||r,pool:`${a.type}:${a.url??a.tag??a.listType??``}`}}))}replace(e,t,n,r=!1){let i=this.rows.findIndex(t=>t.id===e[0]);if(i<0||e.some((e,t)=>this.rows[i+t]?.id!==e))throw Error(`Virtual editor island is stale or noncontiguous`);let a=this.rows.slice(i,i+e.length).map(e=>e.key),o=Date.now(),s=r||this.lastEdit?.source===n&&this.lastEdit.ids===e.join(`,`)&&this.lastEdit.count===t.length&&t.length===e.length&&o-this.lastEdit.time<600;this.editor.update(()=>{let e=a.map(e=>M(e));if(e.some(e=>!e))throw Error(`Virtual editor block was removed`);let n;for(let r of t){let t=x(r);n?n.insertAfter(t):e[0].insertBefore(t),n=t}for(let t of e)t.remove()},{discrete:!0,tag:[s?`history-merge`:`history-push`,`virtual-island:${n}`]}),this.lastEdit={source:n,ids:e.join(`,`),time:o,count:t.length}}dispose(){this.unsubscribe()}},te=new Set([`paragraph`,`text`,`heading`,`quote`,`list`,`listitem`,`details`,`dynamic`]);function Q(e,t){let n=e.getChildren();t.forEach((t,r)=>{let i=n[r];if(i?.getType()===t.type&&te.has(t.type)){if(i.updateFromJSON(t),t.type===`details`){let e=i;e.setOpen(!!t.open),e.setSummary(t.summary)}else if(t.type===`dynamic`){let e=i;e.setUrl(t.url),e.setProps(t.props),e.setInitialHeight(t.initialHeight)}z(i)&&Q(i,t.children??[])}else{let n=x(t);i?i.replace(n):e.append(n)}});for(let e of n.slice(t.length))e.remove()}function $(e){for(;e?.getParent()&&e.getParent().getType()!==`root`;)e=e.getParent();return e?.getParent()?e:null}function ne(e,t){let n=document.caretPositionFromPoint?.(e,t);if(n)return{node:n.offsetNode,offset:n.offset};let r=document.caretRangeFromPoint?.(e,t);return r?{node:r.startContainer,offset:r.startOffset}:null}var re=class{constructor(e,t,r){if(n(this,`master`,void 0),n(this,`canvas`,void 0),n(this,`options`,void 0),n(this,`document`,void 0),n(this,`pool`,new p),n(this,`islands`,new Map),n(this,`states`,new Map),n(this,`viewport`,void 0),n(this,`preserve`,void 0),n(this,`documentBlocks`,new Y(this)),n(this,`heights`,void 0),n(this,`revision`,0),n(this,`indices`,new Map),n(this,`listeners`,new Set),n(this,`observer`,void 0),n(this,`frame`,0),n(this,`dead`,!1),n(this,`width`,void 0),n(this,`metrics`,new Map),n(this,`firstParagraph`,-1),n(this,`selectionOwner`,void 0),n(this,`splitting`,new Set),n(this,`drag`,void 0),n(this,`previousRows`,[]),n(this,`onScroll`,()=>{this.refresh(),this.drag&&this.dragTo(this.drag.y)}),n(this,`onPointerDown`,e=>{if(e.button!==0)return;this.documentBlocks.clear();let t=this.pool.slots.find(t=>t.active&&t.element?.contains(e.target));if(!t)return;let n=this.pool.slots.find(e=>e.active&&e.id===this.selectionOwner),r=e.shiftKey&&n&&n!==t?n:t,i=this.island(r).editor.getRootElement();if(i){if(r!==t)e.preventDefault(),this.extendToPoint(r,i,e.clientX,e.clientY);else if(e.target.closest?.(`[contenteditable]`)!==i)return;this.drag={slot:r,y:e.clientY},document.addEventListener(`pointermove`,this.onPointerMove),document.addEventListener(`pointerup`,this.endDrag),document.addEventListener(`pointercancel`,this.endDrag)}}),n(this,`onPointerMove`,e=>{if(this.drag){if(!(e.buttons&1))return this.endDrag();this.drag.y=e.clientY,this.dragTo(e.clientY)}}),n(this,`endDrag`,()=>{this.drag=void 0,document.removeEventListener(`pointermove`,this.onPointerMove),document.removeEventListener(`pointerup`,this.endDrag),document.removeEventListener(`pointercancel`,this.endDrag)}),n(this,`onFocusIn`,e=>{let t=this.pool.slots.find(t=>t.element?.contains(e.target));t&&(this.selectionOwner=t.id)}),this.master=e,this.canvas=t,this.options=r,this.viewport=c(t,r.scrollContainer),this.preserve=new d(r.preserveCapacity??32,e=>{this.pool.slots.find(t=>t.id===e)?.beforeRelease?.()}),r.overscan!==void 0&&(!Number.isFinite(r.overscan)||r.overscan<0))throw Error(`Virtual editor overscan must be a nonnegative number`);this.document=new Z(e),this.indices=new Map(this.rows.map((e,t)=>[e.id,t])),this.firstParagraph=this.rows.findIndex(e=>e.data.type===`paragraph`),e.update(()=>B().markDirty(),{discrete:!0,tag:`history-merge`}),this.width=t.clientWidth;try{this.heights=this.buildHeights()}catch(e){throw this.document.dispose(),e}t.style.height=`${this.heights.total}px`,this.document.onChange=e=>{this.reconcileDocument(e)},this.previousRows=this.rows.map(e=>({id:e.id,data:e.data})),this.observer=new ResizeObserver(()=>this.queueMeasure()),this.observer.observe(t),this.viewport instanceof HTMLElement&&this.observer.observe(this.viewport),this.viewport.addEventListener(`scroll`,this.onScroll,{passive:!0}),window.addEventListener(`resize`,this.onScroll),t.addEventListener(`focusin`,this.onFocusIn),t.addEventListener(`pointerdown`,this.onPointerDown),this.refresh(!1)}get rows(){return this.document.rows}get scrollTop(){return this.viewport instanceof HTMLElement?this.viewport.scrollTop:window.scrollY}setScrollTop(e){this.viewport instanceof HTMLElement?this.viewport.scrollTop=e:window.scrollTo(window.scrollX,e)}viewportTop(){return this.viewport instanceof HTMLElement?this.viewport.getBoundingClientRect().top+this.viewport.clientTop:0}viewportHeight(){return this.viewport instanceof HTMLElement?this.viewport.clientHeight:window.innerHeight}canvasTop(){return this.canvas.getBoundingClientRect().top-this.viewportTop()+this.scrollTop}buildHeights(){return new h(this.rows.map(e=>this.estimate(e.data)))}estimate(e){let t=this.options.estimateBlockHeight?.(e,this.width)??f(e,this.width);if(!Number.isFinite(t)||t<=0)throw Error(`Virtual editor estimated height must be positive and finite`);return Math.max(24,t)}reconcileDocument(e){let t=this.anchor(),n=new Map(this.previousRows.map((e,t)=>[e.id,{...e,height:this.heights.values[t]}]));(this.rows.length!==this.previousRows.length||this.rows.some((e,t)=>e.id!==this.previousRows[t].id))&&(this.heights=new h(this.rows.map(e=>n.get(e.id)?.height??this.estimate(e.data))));let r=new Map(this.rows.map((e,t)=>[e.id,t]));this.indices=r,this.documentBlocks.prune(),this.firstParagraph=this.rows.findIndex(e=>e.data.type===`paragraph`);for(let e of this.metrics.keys())r.has(e)||this.metrics.delete(e);for(let t of this.pool.slots){let n=this.islands.get(t.id);if(!n)continue;let i=n.ids.flatMap(e=>r.get(e)??[]);n.ids=i.length>1?this.rows.slice(Math.min(...i),Math.max(...i)+1).map(e=>e.id):i.map(e=>this.rows[e].id),n.source=e===`virtual-island:${t.id}`,n.ids.length?(t.index=r.get(n.ids[0]),t.pool=this.rows[t.index].pool):(t.beforeRelease?.(),t.active=!1)}this.pool.slots=this.pool.slots.filter(e=>{let t=this.islands.get(e.id);return!t||t.ids.length?!0:(t.unsubscribe(),this.preserve.forget(e.id),this.islands.delete(e.id),this.pool.disposed++,!1)}),this.previousRows=this.rows.map(e=>({id:e.id,data:e.data})),this.restore(t),this.refresh(!1),this.publish(),this.queueMeasure()}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}publish(e=!0){if(this.dead||!this.listeners.size)return;this.revision++;let t=()=>this.listeners.forEach(e=>e());e?(0,q.flushSync)(t):t()}indexOf(e){return this.indices.get(e)}islandIds(e){for(let t of this.islands.values())if(t.editor===e)return t.ids}rowAt(e){let t=e-this.canvas.getBoundingClientRect().top-this.leadingMargin;return this.heights.find(Math.max(0,t))}dragTo(e){let t=this.drag?.slot;if(!t?.active)return;let n=this.rowAt(e);(n<t.index||n>=t.index+this.island(t).ids.length)&&this.extendIsland(t,n,!0)}extendToPoint(e,t,n,r){if(!this.extendIsland(e,this.rowAt(r),!0))return;let i=window.getSelection(),a=ne(n,r);i?.anchorNode&&t.contains(i.anchorNode)&&a&&t.contains(a.node)&&i.extend(a.node,a.offset)}holdsSelection(e,t){return e.id===this.selectionOwner&&t.editor.getEditorState().read(()=>H()!==null)}refresh(e=!0){if(this.dead||!this.rows.length)return;let t=Math.max(0,this.scrollTop-this.canvasTop()),n=this.options.overscan??this.viewportHeight()*1.5,r=this.heights.find(Math.max(0,t-n)),i=this.heights.find(t+this.viewportHeight()+n),a=new Set,o=[],s=new Set;for(let e of this.pool.slots){let t=this.islands.get(e.id);if(t&&(e.active||this.preserve.has(e.id))){(t.retained||t.editor.isComposing()||e.element?.contains(document.activeElement)||this.holdsSelection(e,t))&&s.add(e.id);for(let n=1;n<t.ids.length;n++)a.add(e.index+n);t.ids.length>1&&e.index<r&&e.index+t.ids.length>r&&o.push(e.index)}}let c=[...o,...Array.from({length:i-r+1},(e,t)=>r+t)].filter(e=>!a.has(e)),l=new Set(c),u=new Set;for(let e of this.pool.slots)(l.has(e.index)||s.has(e.id))&&this.preserve.activate(e.id)&&u.add(e.id);for(let e of this.pool.slots)e.active&&!l.has(e.index)&&!s.has(e.id)&&this.preserve.park(e.id,this.islands.get(e.id)?.ids.join(`,`)??``);let d=new Set([...this.preserve.ids(),...u]),f=this.pool.update(c,e=>this.rows[e].pool,s,d);for(let[e,t]of this.islands)this.pool.slots.some(t=>t.id===e)||(t.unsubscribe(),t.editor.setRootElement(null),this.preserve.forget(e),this.islands.delete(e));f&&this.publish(e)}island(e){let t=this.islands.get(e.id);if(t)return t;let n=this.master.read(()=>I());return t={editor:n,ids:[],generation:-1,loading:!1,source:!1,data:``,unsubscribe:()=>{},retained:0},this.islands.set(e.id,t),t.unsubscribe=n.registerUpdateListener(({editorState:r,dirtyElements:i,dirtyLeaves:a,tags:s})=>{if(t.ids.length>1&&this.queueSplit(e),t.loading||!t.ids.length||s.has(`virtual-bind`)||!i.size&&!a.size)return;let c=r.toJSON().root.children;if(JSON.stringify(c)===t.data)return;let l=new Set;c.forEach((e,n)=>{let r=e.$?.blockId,i=this.indices.has(r)&&!t.ids.includes(r);(!r||l.has(r)||i)&&(r=n===0?t.ids[0]:R(8)),e.$={...e.$,blockId:r},l.add(r)});let u=[...t.ids];t.ids=c.map(e=>e.$.blockId),t.data=JSON.stringify(c),n.update(()=>B().getChildren().forEach((e,n)=>N(e,o,t.ids[n])),{tag:`virtual-bind`}),this.document.replace(u,c,String(e.id),s.has(`history-merge`))}),t}bind(e){let t=this.island(e),n=t.generation!==e.generation;n&&(t.ids=[this.rows[e.index].id]);let r=t.ids.map(e=>this.rows[this.indices.get(e)??-1]).filter(e=>!!e);if(!r.length)return;let i=r.map(e=>e.data),a=JSON.stringify(i);if(!n&&(t.source||a===t.data))t.source=!1,t.data=a;else{t.generation=e.generation,t.data=a,t.loading=!0;try{t.editor.update(()=>{Q(B(),i),n&&k(null)},{discrete:!0,tag:n?[`virtual-bind`,v]:`virtual-bind`})}finally{t.loading=!1}this.restorePanels(e),this.queueMeasure()}}attach(e,t){e.element&&this.observer.unobserve(e.element),e.element=t??void 0,t&&this.observer.observe(t)}mount(e,t){let n=this.pool.slots.filter(t=>t.active&&t.index>e.index).sort((e,t)=>e.index-t.index).map(e=>this.preserve.host(e.id)).find(e=>e?.parentElement===this.canvas);this.preserve.mount(e.id,t,e.active?this.canvas:null,n??null)}state(e){let t=this.states.get(e);return t||(t=new Map,this.states.set(e,t)),t}nodeState(e,t,n){let r=this.island(e),i=r.editor.getEditorState().read(()=>{let e=t?M(t):B().getFirstChild(),i=[];for(;e?.getParent()&&e.getParent().getType()!==`root`;)i.unshift(e.getIndexWithinParent()),e=e.getParent();let a=e?.getIndexWithinParent()??0;return`${a===0?n:r.ids[a]??n}:${i.join(`.`)}`});return this.state(i)}capturePanels(e){let t=this.islands.get(e.id)?.ids[0];t&&this.state(t).set(`details`,this.panels(e).map(({panel:e})=>e.open))}restorePanels(e){let t=this.state(this.island(e).ids[0]).get(`details`);this.panels(e).forEach(({panel:e,initialOpen:n},r)=>{e.open=t?.[r]??n})}panels(e){let t=this.island(e).editor;return t.getEditorState().read(()=>{let e=[],n=r=>{if(r.getType()===`details`){let n=t.getElementByKey(r.getKey());n instanceof HTMLDetailsElement&&e.push({panel:n,initialOpen:r.getOpen()})}z(r)&&r.getChildren().forEach(n)};return n(B()),e})}anchor(){let e=this.canvas.getBoundingClientRect(),t=document.elementFromPoint(e.left+e.width/2,Math.max(this.viewportTop()+8,e.top+1))?.closest(`[data-virtual-editor-slot]`),n=this.pool.slots.find(e=>e.active&&e.element===t)?.index??this.heights.find(Math.max(0,this.scrollTop-this.canvasTop()));return{id:this.previousRows[n]?.id??this.rows[n]?.id,offset:this.scrollTop-this.canvasTop()-this.blockOffset(n)}}restore(e){this.canvas.style.height=`${this.heights.total+this.leadingMargin}px`;let t=e.id?this.indices.get(e.id)??-1:-1;t>=0&&this.setScrollTop(this.canvasTop()+this.blockOffset(t)+e.offset)}queueMeasure(){!this.dead&&!this.frame&&(this.frame=requestAnimationFrame(()=>this.measure()))}slotOffset(e){return this.blockOffset(e.index)-(this.metrics.get(this.rows[e.index]?.id)?.top??0)}get leadingMargin(){return this.metrics.get(this.rows[0]?.id)?.top??0}blockOffset(e){return this.heights.offset(e)+this.leadingMargin}commitLayout(){cancelAnimationFrame(this.frame),this.measure(!1)}measure(e=!0){if(this.frame=0,this.dead)return;let t=this.anchor(),n=!1;Math.abs(this.canvas.clientWidth-this.width)>.5&&(this.width=this.canvas.clientWidth,this.metrics.clear(),this.heights=this.buildHeights(),n=!0);let r=new Set;for(let e of this.pool.slots){if(!e.active)continue;let t=this.islands.get(e.id),i=t?.editor.getRootElement();if(!i||!t?.ids.length)continue;let a=t.editor.getEditorState().read(()=>B().getChildren().map(e=>t.editor.getElementByKey(e.getKey())));a.forEach((e,n)=>{if(!e)return;let r=this.indices.get(t.ids[n])??-1,a=this.rows[r-1]?.data;e.toggleAttribute(`data-document-first`,r===0&&e===i.firstElementChild),e.toggleAttribute(`data-document-last`,r===this.rows.length-1&&e===i.lastElementChild),e.toggleAttribute(`data-document-first-paragraph`,r===this.firstParagraph),e.dataset.documentPrevTag=a?.type===`heading`?a.tag:a?.type===`horizontalrule`?`hr`:``});let o=i.getBoundingClientRect(),s=a.map(e=>e?.getBoundingClientRect());t.ids.forEach((e,i)=>{let c=this.indices.get(e)??-1,l=a[i];if(c<0||!l)return;l.dataset.blockId=e;let u=s[i],d=getComputedStyle(l),f=i===0?u.top-o.top:parseFloat(d.marginTop)||0,p=i===t.ids.length-1?o.bottom-u.bottom:parseFloat(d.marginBottom)||0;Math.abs(f-(this.metrics.get(e)?.top??0))>.1&&(n=!0),this.metrics.set(e,{height:u.height,top:f,bottom:p,gap:s[i+1]?s[i+1].top-u.bottom:void 0}),r.add(c),c>0&&r.add(c-1)})}for(let e of r){let t=this.metrics.get(this.rows[e].id);if(!t)continue;let r=Math.max(1,m(t,this.metrics.get(this.rows[e+1]?.id)));Math.abs(r-this.heights.values[e])>.1&&(this.heights.update(e,r),n=!0)}n&&(this.restore(t),this.refresh(!1),this.publish(e))}scrollTo(e){this.setScrollTop(this.canvasTop()+this.blockOffset(Math.max(0,Math.min(e,this.rows.length-1)))),this.refresh()}focusBlock(e,t=!1,n=!0){e<0||e>=this.rows.length||(n&&this.scrollTo(e),requestAnimationFrame(()=>{let r=this.pool.slots.find(t=>t.active&&this.islands.get(t.id)?.ids.includes(this.rows[e]?.id));if(!r)return;let{editor:i}=this.island(r);i.getRootElement()?.focus({preventScroll:!0}),i.update(()=>{t?B().selectEnd():B().selectStart()},{tag:n?void 0:T})}))}extendIsland(e,t,n=!1){let r=this.island(e),i=e.index,a=i+r.ids.length-1,o=Math.max(0,Math.min(t,this.rows.length-1));if(o>=i&&o<=a)return!0;let s=o<i,c=s?this.rows.slice(o,i):this.rows.slice(a+1,o+1);if(r.ids.length+c.length>(this.options.selectionMergeLimit??200))return!1;let l=new Set(c.map(e=>e.id)),u=this.pool.slots.filter(t=>t!==e&&this.islands.get(t.id)?.ids.some(e=>l.has(e)));if(u.some(e=>{let t=this.islands.get(e.id);return t.retained>0||t.editor.isComposing()}))return!1;for(let e of u)e.beforeRelease?.(),e.active=!1,this.islands.get(e.id).generation=-1;return r.ids=s?[...l,...r.ids]:[...r.ids,...l],s&&(e.index=o),r.data=JSON.stringify(r.ids.map(e=>this.rows[this.indices.get(e)].data)),r.editor.update(()=>{let e=c.map(e=>x(e.data)),t=B().getFirstChild();s&&t?e.forEach(e=>t.insertBefore(e)):B().append(...e)},{discrete:!0,tag:[`virtual-bind`,v]}),this.refresh(!1),this.publish(n),this.queueMeasure(),!0}extendForKey(e,t){let n=this.island(e),r=t===`down`||t===`right`,i=n.editor.getEditorState().read(()=>{let e=H();if(!L(e))return!1;let n=B(),i=e.focus.getNode();if(t===`up`||t===`down`)return $(i)?.is(r?n.getLastChild():n.getFirstChild())??!1;let a=r?n.getLastDescendant():n.getFirstDescendant();return!!a&&i.is(a)&&e.focus.offset===(r?a.getTextContentSize():0)}),a=r?e.index+n.ids.length:e.index-1;return!i||a<0||a>=this.rows.length?!1:this.extendIsland(e,a)}splitIsland(e){let t=this.islands.get(e.id);if(!t||t.ids.length<2)return;let n=t.editor.getEditorState().read(()=>{let e=H();return $(L(e)?e.focus.getNode():null)?.getIndexWithinParent()??0}),r=t.ids[n]??t.ids[0];t.ids=[r],e.index=this.indices.get(r),t.data=JSON.stringify([this.rows[e.index].data]),t.editor.update(()=>B().getChildren().forEach((e,t)=>{t!==n&&e.remove()}),{discrete:!0,tag:`virtual-bind`}),this.refresh(!1),this.publish(),this.queueMeasure()}queueSplit(e){this.splitting.has(e.id)||(this.splitting.add(e.id),requestAnimationFrame(()=>{this.splitting.delete(e.id);let t=this.islands.get(e.id);if(this.dead||!e.active||!t||t.editor.isComposing())return;let n=window.getSelection(),r=t.editor.getRootElement();n&&!n.isCollapsed&&n.anchorNode&&r?.contains(n.anchorNode)||t.editor.getEditorState().read(()=>{let e=H();return e===null||L(e)&&e.isCollapsed()})&&this.splitIsland(e)}))}joinNeighbor(e,t){let n=this.island(e),r=t?e.index-1:e.index+n.ids.length,i=this.rows[r];if(!i)return!1;for(let t of this.pool.slots)t!==e&&this.islands.get(t.id)?.ids.includes(i.id)&&(t.beforeRelease?.(),t.active=!1);return n.ids=t?[i.id,...n.ids]:[...n.ids,i.id],t&&(e.index=r),n.editor.update(()=>{let e=x(i.data);t?B().getFirstChild().insertBefore(e):B().append(e);let n=H();L(n)&&n.deleteCharacter(t)},{discrete:!0}),!0}dispose(){this.dead=!0,this.document.dispose(),this.observer.disconnect(),cancelAnimationFrame(this.frame),this.viewport.removeEventListener(`scroll`,this.onScroll),window.removeEventListener(`resize`,this.onScroll),this.canvas.removeEventListener(`focusin`,this.onFocusIn),this.canvas.removeEventListener(`pointerdown`,this.onPointerDown),this.endDrag();for(let e of this.islands.values())e.unsubscribe();this.listeners.clear(),this.preserve.clear()}};function ie({controller:e,slot:t}){let[n]=C();return(0,K.useEffect)(()=>{let r=e=>{let t=H();if(!L(t)||!t.isCollapsed())return!1;let n=e?B().getLastDescendant():B().getFirstDescendant();return!!n&&t.anchor.key===n.getKey()&&t.anchor.offset===(e?n.getTextContentSize():0)},i=n=>(e.extendForKey(t,n),!1),a=[n.registerCommand(y,()=>(e.master.dispatchCommand(y,void 0),!0),4),n.registerCommand(w,()=>(e.master.dispatchCommand(w,void 0),!0),4),n.registerCommand(O,n=>!r(!1)||!e.joinNeighbor(t,!0)?!1:(n?.preventDefault(),!0),4),n.registerCommand(S,n=>!r(!0)||!e.joinNeighbor(t,!1)?!1:(n?.preventDefault(),!0),4),n.registerCommand(P,n=>n?.shiftKey?i(`up`):!r(!1)||t.index===0?!1:(n?.preventDefault(),e.focusBlock(t.index-1,!0),!0),4),n.registerCommand(g,n=>{if(n?.shiftKey)return i(`down`);if(!r(!0))return!1;let a=t.index+e.island(t).ids.length;return a>=e.rows.length?!1:(n?.preventDefault(),e.focusBlock(a),!0)},4),n.registerCommand(ee,e=>!!e.shiftKey&&i(`left`),4),n.registerCommand(j,e=>!!e.shiftKey&&i(`right`),4)];return()=>a.forEach(e=>e())},[e,n,t]),null}function ae({controller:e,slot:n,plugins:i,onActiveEditorChange:a,onRelease:o,retainSurface:c,placeholder:l}){let d=e.island(n),f=e.rows[n.index],p=`${n.generation}:${n.active}`,[m,h]=(0,K.useState)(``),[g]=(0,K.useState)(()=>{let e=document.createElement(`div`);return e.style.display=`contents`,e}),_=n.active||e.preserve.has(n.id),v=t(),y=(0,K.useMemo)(()=>({blockId:f.id,active:n.active,editor:d.editor,documentBlocks:e.documentBlocks,nodeState:t=>e.nodeState(n,t,f.id),retain:()=>{d.retained++;let t=c(),n=!1;return()=>{n||(n=!0,d.retained--,t(),e.refresh(!1))}}}),[e,d.editor,c,f.id,n,n.active,n.generation]),x=(0,K.useCallback)(t=>e.attach(n,t),[e,n]);return(0,K.useLayoutEffect)(()=>{e.mount(n,g),_?e.bind(n):d.generation=-1,n.beforeRelease=()=>{e.capturePanels(n),o(d.editor)}}),(0,K.useLayoutEffect)(()=>()=>g.remove(),[g]),(0,K.useLayoutEffect)(()=>{let e=requestAnimationFrame(()=>{e=requestAnimationFrame(()=>h(p))});return()=>cancelAnimationFrame(e)},[p]),(0,q.createPortal)((0,J.jsx)(`div`,{className:u,"data-pool":n.pool,"data-restoring":m===p?void 0:``,"data-virtual-editor-block":n.active?f.id:void 0,"data-virtual-editor-slot":n.id,ref:x,style:{display:n.active?void 0:`none`,transform:`translateY(${e.slotOffset(n)}px)`},onFocusCapture:()=>a(d.editor),children:(0,J.jsx)(r,{value:y,children:_&&(0,J.jsxs)(s,{skipCollabChecks:!0,initialEditor:d.editor,children:[(0,J.jsx)(A,{ErrorBoundary:D,contentEditable:(0,J.jsx)(b,{"aria-label":`Document block`,"aria-placeholder":l??``,className:`rich-editor__content qi8t62`,"data-virtual-editor-content":``,placeholder:(0,J.jsx)(`div`,{className:`b94s952`,style:{top:0,left:0,display:l?void 0:`none`},children:l})})}),n.active&&i,(0,J.jsx)(ie,{controller:e,slot:n}),n.active&&v]})})}),g,String(n.id))}function oe({controller:e,plugins:t,onActiveEditorChange:n,onRelease:r,retainSurface:i,placeholder:a}){let[,o]=(0,K.useState)(0);return(0,K.useLayoutEffect)(()=>e.subscribe(()=>o(e=>e+1)),[e]),(0,K.useLayoutEffect)(()=>e.commitLayout()),(0,J.jsx)(J.Fragment,{children:e.pool.slots.map(o=>(0,J.jsx)(ae,{controller:e,plugins:t,retainSurface:i,slot:o,placeholder:e.rows.length===1&&e.rows[0].data.type===`paragraph`&&!(e.rows[0].data.children??[]).some(e=>e.type!==`text`||e.text)?a:void 0,onActiveEditorChange:n,onRelease:r},o.id))})}function se({options:e,className:t,plugins:n,autoFocus:r,hasHeader:o,onActiveEditorChange:s,retainSurface:c,placeholder:u}){let[d]=C(),{scrollContainer:f,overscan:p,estimateBlockHeight:m,preserveCapacity:h,selectionMergeLimit:g}=e,_=(0,K.useMemo)(()=>({scrollContainer:f,overscan:p,estimateBlockHeight:m,preserveCapacity:h,selectionMergeLimit:g}),[f,p,m,h,g]),v=(0,K.useRef)(null),y=(0,K.useCallback)(e=>{v.current=e,s(e)},[s]),b=(0,K.useCallback)(e=>{v.current===e&&y(null)},[y]),x=(0,K.useRef)(null),[S,w]=(0,K.useState)(null),[T,E]=(0,K.useState)(``);return(0,K.useEffect)(()=>{w(null),E(``);let e=x.current,t;try{t=new re(d,e,_),w(t),Object.assign(e,{virtualEditor:t})}catch(e){E(String(e));return}return()=>{y(null),t.dispose(),Reflect.deleteProperty(e,`virtualEditor`)}},[d,y,_]),(0,K.useEffect)(()=>{S&&r&&S.focusBlock(0,!1,!1)},[r,S]),(0,J.jsxs)(`div`,{className:`rich-editor__content-wrapper ${a}`,style:{"--ce-padding-top":`${o?40:12}px`},children:[T&&(0,J.jsx)(`p`,{role:`alert`,children:T}),(0,J.jsx)(`div`,{className:`${i} ${t??``}`,children:(0,J.jsx)(`div`,{className:l,"data-virtual-editor":``,ref:x,children:S&&(0,J.jsx)(oe,{controller:S,placeholder:u,plugins:n,retainSurface:c,onActiveEditorChange:y,onRelease:b})})})]})}export{se as VirtualizedEditor};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{Ft as t,It as n,Lt as r,Mt as i,Nt as a,Pt as o,jt as s}from"./editor-yZwTWy-w.js";import{c,i as l,l as u,n as d,o as f,r as p,s as m,t as h}from"./viewport-CFJHn_Y6-CwlLMc7X.js";import{$r as g,Ai as _,Ar as v,Bi as y,Gn as b,Hr as x,Lr as S,Ra as C,Ri as w,Rr as T,Si as E,Wn as D,Zi as O,_i as k,_n as A,ga as j,ia as ee,ir as M,ja as N,ka as P,ni as F,pa as I,pi as L,qn as R,sa as z,xr as B,zi as V,zr as H}from"./WhiteboardEditor-DrHOvXez-DTa-K6Xu.js";import{t as U}from"./react-DlmbjZJV.js";import{A as W}from"./route-i3jkzu-i.js";import{t as G}from"./jsx-runtime-LKYXHABd.js";var K=e(U(),1),q=e(W(),1),J=G(),Y=class{constructor(e){n(this,`host`,void 0),n(this,`range`,void 0),n(this,`listeners`,new Set),this.host=e}get editor(){return this.host.master}keys(){let e=this.bounds();return e?this.host.rows.slice(e[0],e[1]+1).map(e=>e.key):[]}islandKeys(e){let t=this.bounds(),n=this.host.islandIds(e);return!t||!n?[]:e.getEditorState().read(()=>B().getChildren().filter((e,r)=>{let i=n[r]===void 0?void 0:this.host.indexOf(n[r]);return i!==void 0&&i>=t[0]&&i<=t[1]}).map(e=>e.getKey()))}documentKeys(e,t){let n=this.host.islandIds(e);if(!n)return[];let r=e.getEditorState().read(()=>B().getChildren().map(e=>e.getKey()));return t.flatMap(e=>{let t=n[r.indexOf(e)],i=t===void 0?void 0:this.host.indexOf(t);return i===void 0?[]:[this.host.rows[i].key]})}select(e,t,n){let r=this.host.islandIds(e);if(!r)return;let[i,a]=e.getEditorState().read(()=>{let e=B().getChildren().map(e=>e.getKey());return[r[e.indexOf(t)],r[e.indexOf(n)]]});i&&a&&this.set({anchorId:i,focusId:a})}selectAll(){let{rows:e}=this.host;e.length&&this.set({anchorId:e[0].id,focusId:e.at(-1).id})}extend(e){let t=this.range&&this.host.indexOf(this.range.focusId),n=t===void 0?void 0:this.host.rows[t+e];return!this.range||!n?!1:(this.set({anchorId:this.range.anchorId,focusId:n.id}),!0)}clear(){this.range&&this.set(void 0)}prune(){this.range&&(this.host.indexOf(this.range.anchorId)===void 0||this.host.indexOf(this.range.focusId)===void 0)&&this.set(void 0)}focusSelection(){let e=this.host.master.getEditorState().read(()=>{let e=H();if(!L(e))return null;let t=e.anchor.getNode(),n=t.getTopLevelElement()??t,r=(z(n)?n.getLastDescendant():null)??n;return{key:n.getKey(),end:t.is(r)&&e.anchor.offset===t.getTextContentSize()}}),t=e?this.host.rows.findIndex(t=>t.key===e.key):-1;t>=0&&this.host.focusBlock(t,e.end)}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}bounds(){if(!this.range)return null;let e=this.host.indexOf(this.range.anchorId),t=this.host.indexOf(this.range.focusId);return e===void 0||t===void 0?null:[Math.min(e,t),Math.max(e,t)]}set(e){this.range=e,this.listeners.forEach(e=>e())}};function X(e){let t=E(e);z(e)&&(t.children=e.getChildren().map(X));for(let n of _(e))t.$slots??={},t.$slots[n]=X(V(e,n));return t}var Z=class{constructor(e){n(this,`editor`,void 0),n(this,`rows`,[]),n(this,`onChange`,void 0),n(this,`unsubscribe`,void 0),n(this,`lastEdit`,void 0),this.editor=e,this.read(),this.unsubscribe=e.registerUpdateListener(({dirtyElements:e,dirtyLeaves:t,tags:n})=>{if(!e.size&&!t.size)return;this.read(new Set([...e.keys(),...t]));let r=[...n].find(e=>e.startsWith(`virtual-island:`));r||(this.lastEdit=void 0),this.onChange?.(r)})}read(e){let t=new Map(this.rows.map(e=>[e.key,e]));this.rows=this.editor.getEditorState().read(()=>B().getChildren().map(n=>{let r=n.getKey(),i=t.get(r);if(i?.node===n&&!e?.has(r))return i;let a=X(n);return{data:a,key:r,node:n,id:F(n,o)||r,pool:`${a.type}:${a.url??a.tag??a.listType??``}`}}))}replace(e,t,n,r=!1){let i=this.rows.findIndex(t=>t.id===e[0]);if(i<0||e.some((e,t)=>this.rows[i+t]?.id!==e))throw Error(`Virtual editor island is stale or noncontiguous`);let a=this.rows.slice(i,i+e.length).map(e=>e.key),o=Date.now(),s=r||this.lastEdit?.source===n&&this.lastEdit.ids===e.join(`,`)&&this.lastEdit.count===t.length&&t.length===e.length&&o-this.lastEdit.time<600;this.editor.update(()=>{let e=a.map(e=>M(e));if(e.some(e=>!e))throw Error(`Virtual editor block was removed`);let n;for(let r of t){let t=x(r);n?n.insertAfter(t):e[0].insertBefore(t),n=t}for(let t of e)t.remove()},{discrete:!0,tag:[s?`history-merge`:`history-push`,`virtual-island:${n}`]}),this.lastEdit={source:n,ids:e.join(`,`),time:o,count:t.length}}dispose(){this.unsubscribe()}},te=new Set([`paragraph`,`text`,`heading`,`quote`,`list`,`listitem`,`details`,`dynamic`]);function Q(e,t){let n=e.getChildren();t.forEach((t,r)=>{let i=n[r];if(i?.getType()===t.type&&te.has(t.type)){if(i.updateFromJSON(t),t.type===`details`){let e=i;e.setOpen(!!t.open),e.setSummary(t.summary)}else if(t.type===`dynamic`){let e=i;e.setUrl(t.url),e.setProps(t.props),e.setInitialHeight(t.initialHeight)}z(i)&&Q(i,t.children??[])}else{let n=x(t);i?i.replace(n):e.append(n)}});for(let e of n.slice(t.length))e.remove()}function $(e){for(;e?.getParent()&&e.getParent().getType()!==`root`;)e=e.getParent();return e?.getParent()?e:null}function ne(e,t){let n=document.caretPositionFromPoint?.(e,t);if(n)return{node:n.offsetNode,offset:n.offset};let r=document.caretRangeFromPoint?.(e,t);return r?{node:r.startContainer,offset:r.startOffset}:null}var re=class{constructor(e,t,r){if(n(this,`master`,void 0),n(this,`canvas`,void 0),n(this,`options`,void 0),n(this,`document`,void 0),n(this,`pool`,new p),n(this,`islands`,new Map),n(this,`states`,new Map),n(this,`viewport`,void 0),n(this,`preserve`,void 0),n(this,`documentBlocks`,new Y(this)),n(this,`heights`,void 0),n(this,`revision`,0),n(this,`indices`,new Map),n(this,`listeners`,new Set),n(this,`observer`,void 0),n(this,`frame`,0),n(this,`dead`,!1),n(this,`width`,void 0),n(this,`metrics`,new Map),n(this,`firstParagraph`,-1),n(this,`selectionOwner`,void 0),n(this,`splitting`,new Set),n(this,`drag`,void 0),n(this,`previousRows`,[]),n(this,`onScroll`,()=>{this.refresh(),this.drag&&this.dragTo(this.drag.y)}),n(this,`onPointerDown`,e=>{if(e.button!==0)return;this.documentBlocks.clear();let t=this.pool.slots.find(t=>t.active&&t.element?.contains(e.target));if(!t)return;let n=this.pool.slots.find(e=>e.active&&e.id===this.selectionOwner),r=e.shiftKey&&n&&n!==t?n:t,i=this.island(r).editor.getRootElement();if(i){if(r!==t)e.preventDefault(),this.extendToPoint(r,i,e.clientX,e.clientY);else if(e.target.closest?.(`[contenteditable]`)!==i)return;this.drag={slot:r,y:e.clientY},document.addEventListener(`pointermove`,this.onPointerMove),document.addEventListener(`pointerup`,this.endDrag),document.addEventListener(`pointercancel`,this.endDrag)}}),n(this,`onPointerMove`,e=>{if(this.drag){if(!(e.buttons&1))return this.endDrag();this.drag.y=e.clientY,this.dragTo(e.clientY)}}),n(this,`endDrag`,()=>{this.drag=void 0,document.removeEventListener(`pointermove`,this.onPointerMove),document.removeEventListener(`pointerup`,this.endDrag),document.removeEventListener(`pointercancel`,this.endDrag)}),n(this,`onFocusIn`,e=>{let t=this.pool.slots.find(t=>t.element?.contains(e.target));t&&(this.selectionOwner=t.id)}),this.master=e,this.canvas=t,this.options=r,this.viewport=c(t,r.scrollContainer),this.preserve=new d(r.preserveCapacity??32,e=>{this.pool.slots.find(t=>t.id===e)?.beforeRelease?.()}),r.overscan!==void 0&&(!Number.isFinite(r.overscan)||r.overscan<0))throw Error(`Virtual editor overscan must be a nonnegative number`);this.document=new Z(e),this.indices=new Map(this.rows.map((e,t)=>[e.id,t])),this.firstParagraph=this.rows.findIndex(e=>e.data.type===`paragraph`),e.update(()=>B().markDirty(),{discrete:!0,tag:`history-merge`}),this.width=t.clientWidth;try{this.heights=this.buildHeights()}catch(e){throw this.document.dispose(),e}t.style.height=`${this.heights.total}px`,this.document.onChange=e=>{this.reconcileDocument(e)},this.previousRows=this.rows.map(e=>({id:e.id,data:e.data})),this.observer=new ResizeObserver(()=>this.queueMeasure()),this.observer.observe(t),this.viewport instanceof HTMLElement&&this.observer.observe(this.viewport),this.viewport.addEventListener(`scroll`,this.onScroll,{passive:!0}),window.addEventListener(`resize`,this.onScroll),t.addEventListener(`focusin`,this.onFocusIn),t.addEventListener(`pointerdown`,this.onPointerDown),this.refresh(!1)}get rows(){return this.document.rows}get scrollTop(){return this.viewport instanceof HTMLElement?this.viewport.scrollTop:window.scrollY}setScrollTop(e){this.viewport instanceof HTMLElement?this.viewport.scrollTop=e:window.scrollTo(window.scrollX,e)}viewportTop(){return this.viewport instanceof HTMLElement?this.viewport.getBoundingClientRect().top+this.viewport.clientTop:0}viewportHeight(){return this.viewport instanceof HTMLElement?this.viewport.clientHeight:window.innerHeight}canvasTop(){return this.canvas.getBoundingClientRect().top-this.viewportTop()+this.scrollTop}buildHeights(){return new h(this.rows.map(e=>this.estimate(e.data)))}estimate(e){let t=this.options.estimateBlockHeight?.(e,this.width)??f(e,this.width);if(!Number.isFinite(t)||t<=0)throw Error(`Virtual editor estimated height must be positive and finite`);return Math.max(24,t)}reconcileDocument(e){let t=this.anchor(),n=new Map(this.previousRows.map((e,t)=>[e.id,{...e,height:this.heights.values[t]}]));(this.rows.length!==this.previousRows.length||this.rows.some((e,t)=>e.id!==this.previousRows[t].id))&&(this.heights=new h(this.rows.map(e=>n.get(e.id)?.height??this.estimate(e.data))));let r=new Map(this.rows.map((e,t)=>[e.id,t]));this.indices=r,this.documentBlocks.prune(),this.firstParagraph=this.rows.findIndex(e=>e.data.type===`paragraph`);for(let e of this.metrics.keys())r.has(e)||this.metrics.delete(e);for(let t of this.pool.slots){let n=this.islands.get(t.id);if(!n)continue;let i=n.ids.flatMap(e=>r.get(e)??[]);n.ids=i.length>1?this.rows.slice(Math.min(...i),Math.max(...i)+1).map(e=>e.id):i.map(e=>this.rows[e].id),n.source=e===`virtual-island:${t.id}`,n.ids.length?(t.index=r.get(n.ids[0]),t.pool=this.rows[t.index].pool):(t.beforeRelease?.(),t.active=!1)}this.pool.slots=this.pool.slots.filter(e=>{let t=this.islands.get(e.id);return!t||t.ids.length?!0:(t.unsubscribe(),this.preserve.forget(e.id),this.islands.delete(e.id),this.pool.disposed++,!1)}),this.previousRows=this.rows.map(e=>({id:e.id,data:e.data})),this.restore(t),this.refresh(!1),this.publish(),this.queueMeasure()}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}publish(e=!0){if(this.dead||!this.listeners.size)return;this.revision++;let t=()=>this.listeners.forEach(e=>e());e?(0,q.flushSync)(t):t()}indexOf(e){return this.indices.get(e)}islandIds(e){for(let t of this.islands.values())if(t.editor===e)return t.ids}rowAt(e){let t=e-this.canvas.getBoundingClientRect().top-this.leadingMargin;return this.heights.find(Math.max(0,t))}dragTo(e){let t=this.drag?.slot;if(!t?.active)return;let n=this.rowAt(e);(n<t.index||n>=t.index+this.island(t).ids.length)&&this.extendIsland(t,n,!0)}extendToPoint(e,t,n,r){if(!this.extendIsland(e,this.rowAt(r),!0))return;let i=window.getSelection(),a=ne(n,r);i?.anchorNode&&t.contains(i.anchorNode)&&a&&t.contains(a.node)&&i.extend(a.node,a.offset)}holdsSelection(e,t){return e.id===this.selectionOwner&&t.editor.getEditorState().read(()=>H()!==null)}refresh(e=!0){if(this.dead||!this.rows.length)return;let t=Math.max(0,this.scrollTop-this.canvasTop()),n=this.options.overscan??this.viewportHeight()*1.5,r=this.heights.find(Math.max(0,t-n)),i=this.heights.find(t+this.viewportHeight()+n),a=new Set,o=[],s=new Set;for(let e of this.pool.slots){let t=this.islands.get(e.id);if(t&&(e.active||this.preserve.has(e.id))){(t.retained||t.editor.isComposing()||e.element?.contains(document.activeElement)||this.holdsSelection(e,t))&&s.add(e.id);for(let n=1;n<t.ids.length;n++)a.add(e.index+n);t.ids.length>1&&e.index<r&&e.index+t.ids.length>r&&o.push(e.index)}}let c=[...o,...Array.from({length:i-r+1},(e,t)=>r+t)].filter(e=>!a.has(e)),l=new Set(c),u=new Set;for(let e of this.pool.slots)(l.has(e.index)||s.has(e.id))&&this.preserve.activate(e.id)&&u.add(e.id);for(let e of this.pool.slots)e.active&&!l.has(e.index)&&!s.has(e.id)&&this.preserve.park(e.id,this.islands.get(e.id)?.ids.join(`,`)??``);let d=new Set([...this.preserve.ids(),...u]),f=this.pool.update(c,e=>this.rows[e].pool,s,d);for(let[e,t]of this.islands)this.pool.slots.some(t=>t.id===e)||(t.unsubscribe(),t.editor.setRootElement(null),this.preserve.forget(e),this.islands.delete(e));f&&this.publish(e)}island(e){let t=this.islands.get(e.id);if(t)return t;let n=this.master.read(()=>I());return t={editor:n,ids:[],generation:-1,loading:!1,source:!1,data:``,unsubscribe:()=>{},retained:0},this.islands.set(e.id,t),t.unsubscribe=n.registerUpdateListener(({editorState:r,dirtyElements:i,dirtyLeaves:a,tags:s})=>{if(t.ids.length>1&&this.queueSplit(e),t.loading||!t.ids.length||s.has(`virtual-bind`)||!i.size&&!a.size)return;let c=r.toJSON().root.children;if(JSON.stringify(c)===t.data)return;let l=new Set;c.forEach((e,n)=>{let r=e.$?.blockId,i=this.indices.has(r)&&!t.ids.includes(r);(!r||l.has(r)||i)&&(r=n===0?t.ids[0]:R(8)),e.$={...e.$,blockId:r},l.add(r)});let u=[...t.ids];t.ids=c.map(e=>e.$.blockId),t.data=JSON.stringify(c),n.update(()=>B().getChildren().forEach((e,n)=>N(e,o,t.ids[n])),{tag:`virtual-bind`}),this.document.replace(u,c,String(e.id),s.has(`history-merge`))}),t}bind(e){let t=this.island(e),n=t.generation!==e.generation;n&&(t.ids=[this.rows[e.index].id]);let r=t.ids.map(e=>this.rows[this.indices.get(e)??-1]).filter(e=>!!e);if(!r.length)return;let i=r.map(e=>e.data),a=JSON.stringify(i);if(!n&&(t.source||a===t.data))t.source=!1,t.data=a;else{t.generation=e.generation,t.data=a,t.loading=!0;try{t.editor.update(()=>{Q(B(),i),n&&k(null)},{discrete:!0,tag:n?[`virtual-bind`,v]:`virtual-bind`})}finally{t.loading=!1}this.restorePanels(e),this.queueMeasure()}}attach(e,t){e.element&&this.observer.unobserve(e.element),e.element=t??void 0,t&&this.observer.observe(t)}mount(e,t){let n=this.pool.slots.filter(t=>t.active&&t.index>e.index).sort((e,t)=>e.index-t.index).map(e=>this.preserve.host(e.id)).find(e=>e?.parentElement===this.canvas);this.preserve.mount(e.id,t,e.active?this.canvas:null,n??null)}state(e){let t=this.states.get(e);return t||(t=new Map,this.states.set(e,t)),t}nodeState(e,t,n){let r=this.island(e),i=r.editor.getEditorState().read(()=>{let e=t?M(t):B().getFirstChild(),i=[];for(;e?.getParent()&&e.getParent().getType()!==`root`;)i.unshift(e.getIndexWithinParent()),e=e.getParent();let a=e?.getIndexWithinParent()??0;return`${a===0?n:r.ids[a]??n}:${i.join(`.`)}`});return this.state(i)}capturePanels(e){let t=this.islands.get(e.id)?.ids[0];t&&this.state(t).set(`details`,this.panels(e).map(({panel:e})=>e.open))}restorePanels(e){let t=this.state(this.island(e).ids[0]).get(`details`);this.panels(e).forEach(({panel:e,initialOpen:n},r)=>{e.open=t?.[r]??n})}panels(e){let t=this.island(e).editor;return t.getEditorState().read(()=>{let e=[],n=r=>{if(r.getType()===`details`){let n=t.getElementByKey(r.getKey());n instanceof HTMLDetailsElement&&e.push({panel:n,initialOpen:r.getOpen()})}z(r)&&r.getChildren().forEach(n)};return n(B()),e})}anchor(){let e=this.canvas.getBoundingClientRect(),t=document.elementFromPoint(e.left+e.width/2,Math.max(this.viewportTop()+8,e.top+1))?.closest(`[data-virtual-editor-slot]`),n=this.pool.slots.find(e=>e.active&&e.element===t)?.index??this.heights.find(Math.max(0,this.scrollTop-this.canvasTop()));return{id:this.previousRows[n]?.id??this.rows[n]?.id,offset:this.scrollTop-this.canvasTop()-this.blockOffset(n)}}restore(e){this.canvas.style.height=`${this.heights.total+this.leadingMargin}px`;let t=e.id?this.indices.get(e.id)??-1:-1;t>=0&&this.setScrollTop(this.canvasTop()+this.blockOffset(t)+e.offset)}queueMeasure(){!this.dead&&!this.frame&&(this.frame=requestAnimationFrame(()=>this.measure()))}slotOffset(e){return this.blockOffset(e.index)-(this.metrics.get(this.rows[e.index]?.id)?.top??0)}get leadingMargin(){return this.metrics.get(this.rows[0]?.id)?.top??0}blockOffset(e){return this.heights.offset(e)+this.leadingMargin}commitLayout(){cancelAnimationFrame(this.frame),this.measure(!1)}measure(e=!0){if(this.frame=0,this.dead)return;let t=this.anchor(),n=!1;Math.abs(this.canvas.clientWidth-this.width)>.5&&(this.width=this.canvas.clientWidth,this.metrics.clear(),this.heights=this.buildHeights(),n=!0);let r=new Set;for(let e of this.pool.slots){if(!e.active)continue;let t=this.islands.get(e.id),i=t?.editor.getRootElement();if(!i||!t?.ids.length)continue;let a=t.editor.getEditorState().read(()=>B().getChildren().map(e=>t.editor.getElementByKey(e.getKey())));a.forEach((e,n)=>{if(!e)return;let r=this.indices.get(t.ids[n])??-1,a=this.rows[r-1]?.data;e.toggleAttribute(`data-document-first`,r===0&&e===i.firstElementChild),e.toggleAttribute(`data-document-last`,r===this.rows.length-1&&e===i.lastElementChild),e.toggleAttribute(`data-document-first-paragraph`,r===this.firstParagraph),e.dataset.documentPrevTag=a?.type===`heading`?a.tag:a?.type===`horizontalrule`?`hr`:``});let o=i.getBoundingClientRect(),s=a.map(e=>e?.getBoundingClientRect());t.ids.forEach((e,i)=>{let c=this.indices.get(e)??-1,l=a[i];if(c<0||!l)return;l.dataset.blockId=e;let u=s[i],d=getComputedStyle(l),f=i===0?u.top-o.top:parseFloat(d.marginTop)||0,p=i===t.ids.length-1?o.bottom-u.bottom:parseFloat(d.marginBottom)||0;Math.abs(f-(this.metrics.get(e)?.top??0))>.1&&(n=!0),this.metrics.set(e,{height:u.height,top:f,bottom:p,gap:s[i+1]?s[i+1].top-u.bottom:void 0}),r.add(c),c>0&&r.add(c-1)})}for(let e of r){let t=this.metrics.get(this.rows[e].id);if(!t)continue;let r=Math.max(1,m(t,this.metrics.get(this.rows[e+1]?.id)));Math.abs(r-this.heights.values[e])>.1&&(this.heights.update(e,r),n=!0)}n&&(this.restore(t),this.refresh(!1),this.publish(e))}scrollTo(e){this.setScrollTop(this.canvasTop()+this.blockOffset(Math.max(0,Math.min(e,this.rows.length-1)))),this.refresh()}focusBlock(e,t=!1,n=!0){e<0||e>=this.rows.length||(n&&this.scrollTo(e),requestAnimationFrame(()=>{let r=this.pool.slots.find(t=>t.active&&this.islands.get(t.id)?.ids.includes(this.rows[e]?.id));if(!r)return;let{editor:i}=this.island(r);i.getRootElement()?.focus({preventScroll:!0}),i.update(()=>{t?B().selectEnd():B().selectStart()},{tag:n?void 0:T})}))}extendIsland(e,t,n=!1){let r=this.island(e),i=e.index,a=i+r.ids.length-1,o=Math.max(0,Math.min(t,this.rows.length-1));if(o>=i&&o<=a)return!0;let s=o<i,c=s?this.rows.slice(o,i):this.rows.slice(a+1,o+1);if(r.ids.length+c.length>(this.options.selectionMergeLimit??200))return!1;let l=new Set(c.map(e=>e.id)),u=this.pool.slots.filter(t=>t!==e&&this.islands.get(t.id)?.ids.some(e=>l.has(e)));if(u.some(e=>{let t=this.islands.get(e.id);return t.retained>0||t.editor.isComposing()}))return!1;for(let e of u)e.beforeRelease?.(),e.active=!1,this.islands.get(e.id).generation=-1;return r.ids=s?[...l,...r.ids]:[...r.ids,...l],s&&(e.index=o),r.data=JSON.stringify(r.ids.map(e=>this.rows[this.indices.get(e)].data)),r.editor.update(()=>{let e=c.map(e=>x(e.data)),t=B().getFirstChild();s&&t?e.forEach(e=>t.insertBefore(e)):B().append(...e)},{discrete:!0,tag:[`virtual-bind`,v]}),this.refresh(!1),this.publish(n),this.queueMeasure(),!0}extendForKey(e,t){let n=this.island(e),r=t===`down`||t===`right`,i=n.editor.getEditorState().read(()=>{let e=H();if(!L(e))return!1;let n=B(),i=e.focus.getNode();if(t===`up`||t===`down`)return $(i)?.is(r?n.getLastChild():n.getFirstChild())??!1;let a=r?n.getLastDescendant():n.getFirstDescendant();return!!a&&i.is(a)&&e.focus.offset===(r?a.getTextContentSize():0)}),a=r?e.index+n.ids.length:e.index-1;return!i||a<0||a>=this.rows.length?!1:this.extendIsland(e,a)}splitIsland(e){let t=this.islands.get(e.id);if(!t||t.ids.length<2)return;let n=t.editor.getEditorState().read(()=>{let e=H();return $(L(e)?e.focus.getNode():null)?.getIndexWithinParent()??0}),r=t.ids[n]??t.ids[0];t.ids=[r],e.index=this.indices.get(r),t.data=JSON.stringify([this.rows[e.index].data]),t.editor.update(()=>B().getChildren().forEach((e,t)=>{t!==n&&e.remove()}),{discrete:!0,tag:`virtual-bind`}),this.refresh(!1),this.publish(),this.queueMeasure()}queueSplit(e){this.splitting.has(e.id)||(this.splitting.add(e.id),requestAnimationFrame(()=>{this.splitting.delete(e.id);let t=this.islands.get(e.id);if(this.dead||!e.active||!t||t.editor.isComposing())return;let n=window.getSelection(),r=t.editor.getRootElement();n&&!n.isCollapsed&&n.anchorNode&&r?.contains(n.anchorNode)||t.editor.getEditorState().read(()=>{let e=H();return e===null||L(e)&&e.isCollapsed()})&&this.splitIsland(e)}))}joinNeighbor(e,t){let n=this.island(e),r=t?e.index-1:e.index+n.ids.length,i=this.rows[r];if(!i)return!1;for(let t of this.pool.slots)t!==e&&this.islands.get(t.id)?.ids.includes(i.id)&&(t.beforeRelease?.(),t.active=!1);return n.ids=t?[i.id,...n.ids]:[...n.ids,i.id],t&&(e.index=r),n.editor.update(()=>{let e=x(i.data);t?B().getFirstChild().insertBefore(e):B().append(e);let n=H();L(n)&&n.deleteCharacter(t)},{discrete:!0}),!0}dispose(){this.dead=!0,this.document.dispose(),this.observer.disconnect(),cancelAnimationFrame(this.frame),this.viewport.removeEventListener(`scroll`,this.onScroll),window.removeEventListener(`resize`,this.onScroll),this.canvas.removeEventListener(`focusin`,this.onFocusIn),this.canvas.removeEventListener(`pointerdown`,this.onPointerDown),this.endDrag();for(let e of this.islands.values())e.unsubscribe();this.listeners.clear(),this.preserve.clear()}};function ie({controller:e,slot:t}){let[n]=C();return(0,K.useEffect)(()=>{let r=e=>{let t=H();if(!L(t)||!t.isCollapsed())return!1;let n=e?B().getLastDescendant():B().getFirstDescendant();return!!n&&t.anchor.key===n.getKey()&&t.anchor.offset===(e?n.getTextContentSize():0)},i=n=>(e.extendForKey(t,n),!1),a=[n.registerCommand(y,()=>(e.master.dispatchCommand(y,void 0),!0),4),n.registerCommand(w,()=>(e.master.dispatchCommand(w,void 0),!0),4),n.registerCommand(O,n=>!r(!1)||!e.joinNeighbor(t,!0)?!1:(n?.preventDefault(),!0),4),n.registerCommand(S,n=>!r(!0)||!e.joinNeighbor(t,!1)?!1:(n?.preventDefault(),!0),4),n.registerCommand(P,n=>n?.shiftKey?i(`up`):!r(!1)||t.index===0?!1:(n?.preventDefault(),e.focusBlock(t.index-1,!0),!0),4),n.registerCommand(g,n=>{if(n?.shiftKey)return i(`down`);if(!r(!0))return!1;let a=t.index+e.island(t).ids.length;return a>=e.rows.length?!1:(n?.preventDefault(),e.focusBlock(a),!0)},4),n.registerCommand(ee,e=>!!e.shiftKey&&i(`left`),4),n.registerCommand(j,e=>!!e.shiftKey&&i(`right`),4)];return()=>a.forEach(e=>e())},[e,n,t]),null}function ae({controller:e,slot:n,plugins:i,onActiveEditorChange:a,onRelease:o,retainSurface:c,placeholder:l}){let d=e.island(n),f=e.rows[n.index],p=`${n.generation}:${n.active}`,[m,h]=(0,K.useState)(``),[g]=(0,K.useState)(()=>{let e=document.createElement(`div`);return e.style.display=`contents`,e}),_=n.active||e.preserve.has(n.id),v=t(),y=(0,K.useMemo)(()=>({blockId:f.id,active:n.active,editor:d.editor,documentBlocks:e.documentBlocks,nodeState:t=>e.nodeState(n,t,f.id),retain:()=>{d.retained++;let t=c(),n=!1;return()=>{n||(n=!0,d.retained--,t(),e.refresh(!1))}}}),[e,d.editor,c,f.id,n,n.active,n.generation]),x=(0,K.useCallback)(t=>e.attach(n,t),[e,n]);return(0,K.useLayoutEffect)(()=>{e.mount(n,g),_?e.bind(n):d.generation=-1,n.beforeRelease=()=>{e.capturePanels(n),o(d.editor)}}),(0,K.useLayoutEffect)(()=>()=>g.remove(),[g]),(0,K.useLayoutEffect)(()=>{let e=requestAnimationFrame(()=>{e=requestAnimationFrame(()=>h(p))});return()=>cancelAnimationFrame(e)},[p]),(0,q.createPortal)((0,J.jsx)(`div`,{className:u,"data-pool":n.pool,"data-restoring":m===p?void 0:``,"data-virtual-editor-block":n.active?f.id:void 0,"data-virtual-editor-slot":n.id,ref:x,style:{display:n.active?void 0:`none`,transform:`translateY(${e.slotOffset(n)}px)`},onFocusCapture:()=>a(d.editor),children:(0,J.jsx)(r,{value:y,children:_&&(0,J.jsxs)(s,{skipCollabChecks:!0,initialEditor:d.editor,children:[(0,J.jsx)(A,{ErrorBoundary:D,contentEditable:(0,J.jsx)(b,{"aria-label":`Document block`,"aria-placeholder":l??``,className:`rich-editor__content qi8t62`,"data-virtual-editor-content":``,placeholder:(0,J.jsx)(`div`,{className:`b94s952`,style:{top:0,left:0,display:l?void 0:`none`},children:l})})}),n.active&&i,(0,J.jsx)(ie,{controller:e,slot:n}),n.active&&v]})})}),g,String(n.id))}function oe({controller:e,plugins:t,onActiveEditorChange:n,onRelease:r,retainSurface:i,placeholder:a}){let[,o]=(0,K.useState)(0);return(0,K.useLayoutEffect)(()=>e.subscribe(()=>o(e=>e+1)),[e]),(0,K.useLayoutEffect)(()=>e.commitLayout()),(0,J.jsx)(J.Fragment,{children:e.pool.slots.map(o=>(0,J.jsx)(ae,{controller:e,plugins:t,retainSurface:i,slot:o,placeholder:e.rows.length===1&&e.rows[0].data.type===`paragraph`&&!(e.rows[0].data.children??[]).some(e=>e.type!==`text`||e.text)?a:void 0,onActiveEditorChange:n,onRelease:r},o.id))})}function se({options:e,className:t,plugins:n,autoFocus:r,hasHeader:o,onActiveEditorChange:s,retainSurface:c,placeholder:u}){let[d]=C(),{scrollContainer:f,overscan:p,estimateBlockHeight:m,preserveCapacity:h,selectionMergeLimit:g}=e,_=(0,K.useMemo)(()=>({scrollContainer:f,overscan:p,estimateBlockHeight:m,preserveCapacity:h,selectionMergeLimit:g}),[f,p,m,h,g]),v=(0,K.useRef)(null),y=(0,K.useCallback)(e=>{v.current=e,s(e)},[s]),b=(0,K.useCallback)(e=>{v.current===e&&y(null)},[y]),x=(0,K.useRef)(null),[S,w]=(0,K.useState)(null),[T,E]=(0,K.useState)(``);return(0,K.useEffect)(()=>{w(null),E(``);let e=x.current,t;try{t=new re(d,e,_),w(t),Object.assign(e,{virtualEditor:t})}catch(e){E(String(e));return}return()=>{y(null),t.dispose(),Reflect.deleteProperty(e,`virtualEditor`)}},[d,y,_]),(0,K.useEffect)(()=>{S&&r&&S.focusBlock(0,!1,!1)},[r,S]),(0,J.jsxs)(`div`,{className:`rich-editor__content-wrapper ${a}`,style:{"--ce-padding-top":`${o?40:12}px`},children:[T&&(0,J.jsx)(`p`,{role:`alert`,children:T}),(0,J.jsx)(`div`,{className:`${i} ${t??``}`,children:(0,J.jsx)(`div`,{className:l,"data-virtual-editor":``,ref:x,children:S&&(0,J.jsx)(oe,{controller:S,placeholder:u,plugins:n,retainSurface:c,onActiveEditorChange:y,onRelease:b})})})]})}export{se as VirtualizedEditor};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{t}from"./plugin-_bGVeqI0-C4RRMCGb.js";import{t as n}from"./react-DlmbjZJV.js";import{t as r}from"./jsx-runtime-LKYXHABd.js";import{Lt as i}from"./editor-rLQcZykK.js";import{A as a}from"./route-i3jkzu-i.js";import{a as o,c as s,i as c,l,n as u,o as d,r as f,s as p,t as m}from"./viewport-CFJHn_Y6-B_DJWWd0.js";var h=e(n(),1),g=r(),_=e(a(),1);function v(e){"@babel/helpers - typeof";return v=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},v(e)}function y(e,t){if(v(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(v(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function b(e){var t=y(e,`string`);return v(t)==`symbol`?t:t+``}function x(e,t,n){return(t=b(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var S=class{constructor(e,t,n){if(x(this,`document`,void 0),x(this,`canvas`,void 0),x(this,`options`,void 0),x(this,`pool`,new f),x(this,`preserve`,void 0),x(this,`viewport`,void 0),x(this,`states`,new Map),x(this,`retained`,new Map),x(this,`heights`,void 0),x(this,`metrics`,new Map),x(this,`listeners`,new Set),x(this,`observer`,void 0),x(this,`width`,void 0),x(this,`frame`,0),x(this,`dead`,!1),x(this,`firstParagraph`,void 0),x(this,`onScroll`,()=>this.refresh()),x(this,`onFocusOut`,()=>queueMicrotask(()=>{this.dead||this.refresh()})),x(this,`queueMeasure`,()=>{!this.dead&&!this.frame&&(this.frame=requestAnimationFrame(()=>this.measure()))}),x(this,`onHash`,()=>{let e;try{e=decodeURIComponent(window.location.hash.slice(1))}catch{return}let t=this.document.headingRows.get(e);if(t!==void 0){this.scrollTo(t);let n=this.canvas.querySelector(`#${CSS.escape(e)}`);n&&this.setScrollTop(this.scrollTop+n.getBoundingClientRect().top-this.viewportTop())}}),this.document=e,this.canvas=t,this.options=n,n.overscan!==void 0&&(!Number.isFinite(n.overscan)||n.overscan<0))throw Error(`Renderer overscan must be a nonnegative number`);this.viewport=s(t,n.scrollContainer),this.preserve=new u(n.preserveCapacity??32,e=>{let t=this.pool.slots.find(t=>t.id===e);t?.beforeRelease?.(),t&&(t.committed=-1)}),this.width=t.clientWidth,this.heights=this.buildHeights(),this.firstParagraph=this.rows.flatMap(e=>e.blocks).find(e=>e.data.type===`paragraph`)?.index??-1,this.canvas.style.height=`${this.heights.total}px`,this.observer=new ResizeObserver(this.queueMeasure),this.observer.observe(t),this.viewport instanceof HTMLElement&&this.observer.observe(this.viewport),this.viewport.addEventListener(`scroll`,this.onScroll,{passive:!0}),this.canvas.addEventListener(`focusout`,this.onFocusOut),window.addEventListener(`resize`,this.onScroll),window.addEventListener(`hashchange`,this.onHash),this.refresh(!1),queueMicrotask(()=>{this.dead||this.onHash()})}get rows(){return this.document.rows}get scrollTop(){return this.viewport instanceof HTMLElement?this.viewport.scrollTop:window.scrollY}setScrollTop(e){this.viewport instanceof HTMLElement?this.viewport.scrollTop=e:window.scrollTo(window.scrollX,e)}viewportTop(){return this.viewport instanceof HTMLElement?this.viewport.getBoundingClientRect().top+this.viewport.clientTop:0}viewportHeight(){return this.viewport instanceof HTMLElement?this.viewport.clientHeight:window.innerHeight}canvasTop(){return this.canvas.getBoundingClientRect().top-this.viewportTop()+this.scrollTop}buildHeights(){return new m(this.rows.map(e=>e.blocks.reduce((e,t)=>{let n=this.options.estimateBlockHeight?.(t.data,this.width)??d(t.data,this.width);if(!Number.isFinite(n)||n<=0)throw Error(`Renderer estimated height must be positive and finite`);return e+n},0)))}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}publish(e=!0){if(this.dead||!this.listeners.size)return;let t=()=>this.listeners.forEach(e=>e());e?(0,_.flushSync)(t):t()}refresh(e=!0){if(this.dead||!this.rows.length)return;let t=Math.max(0,this.scrollTop-this.canvasTop()),n=this.options.overscan??this.viewportHeight()*1.5,r=this.heights.find(Math.max(0,t-n)),i=this.heights.find(t+this.viewportHeight()+n),a=Array.from({length:i-r+1},(e,t)=>r+t),o=new Set(a),s=new Set(this.pool.slots.filter(e=>e.active&&(this.retained.get(e.id)||e.element?.contains(globalThis.document.activeElement))).map(e=>e.id)),c=new Set;for(let e of this.pool.slots)(o.has(e.index)||s.has(e.id))&&this.preserve.activate(e.id)&&c.add(e.id);for(let e of this.pool.slots)e.active&&!o.has(e.index)&&!s.has(e.id)&&this.preserve.park(e.id,this.rows[e.index].id);let l=this.pool.slots.map(e=>e.id),u=this.pool.update(a,e=>this.rows[e].pool,s,new Set([...this.preserve.ids(),...c]));for(let e of l)this.pool.slots.some(t=>t.id===e)||this.preserve.forget(e);u&&this.publish(e)}mount(e,t){let n=this.pool.slots.filter(t=>t.active&&t.index>e.index).sort((e,t)=>e.index-t.index).map(e=>this.preserve.host(e.id)).find(e=>e?.parentElement===this.canvas);this.preserve.mount(e.id,t,e.active?this.canvas:null,n??null)}attach(e,t){e.element&&this.observer.unobserve(e.element),e.element=t??void 0,t&&this.observer.observe(t)}nodeState(e,t){let n=`${e}:${this.document.nodePath(t)}`,r=this.states.get(n);return r||(r=new Map,this.states.set(n,r)),r}capturePanels(e){this.nodeState(this.rows[e.index].id).set(`details`,[...e.element?.querySelectorAll(`details`)??[]].map(e=>e.open))}bind(e){if(e.committed===e.generation)return;e.committed=e.generation;let t=this.nodeState(this.rows[e.index].id).get(`details`),n=[],r=e=>{e.type===`details`&&n.push(!!e.open),e.children?.forEach(r)};r(this.rows[e.index].data),e.element?.querySelectorAll(`details`).forEach((e,r)=>e.open=t?.[r]??n[r]??!1)}get leadingMargin(){return this.metrics.get(this.rows[0]?.id)?.top??0}blockOffset(e){return this.heights.offset(e)+this.leadingMargin}slotOffset(e){return this.blockOffset(e.index)-(this.metrics.get(this.rows[e.index]?.id)?.top??0)}anchor(){let e=this.canvas.getBoundingClientRect(),t=globalThis.document.elementFromPoint(e.left+e.width/2,Math.max(this.viewportTop()+8,e.top+1))?.closest(`[data-virtual-renderer-slot]`),n=this.pool.slots.find(e=>e.active&&e.element===t)?.index??this.heights.find(Math.max(0,this.scrollTop-this.canvasTop()));return{index:n,offset:this.scrollTop-this.canvasTop()-this.blockOffset(n)}}commitLayout(){cancelAnimationFrame(this.frame),this.measure(!1)}measure(e=!0){if(this.frame=0,this.dead)return;let t=this.anchor(),n=!1;Math.abs(this.canvas.clientWidth-this.width)>.5&&(this.width=this.canvas.clientWidth,this.metrics.clear(),this.heights=this.buildHeights(),n=!0);let r=new Set;for(let e of this.pool.slots){if(!e.active)continue;let t=e.element?.firstElementChild;if(!t)continue;t.setAttribute(`data-rich-nested`,this.canvas.closest(`.rich-content`)?.getAttribute(`data-rich-nested`)??`false`);let i=[...t.children],a=this.rows[e.index].blocks;i.forEach((t,n)=>{let r=a[n];if(!r)return;t.dataset.blockId=r.id,t.dataset.rendererBlockIndex=String(r.index),t.toggleAttribute(`data-document-first`,e.index===0&&n===0),t.toggleAttribute(`data-document-last`,e.index===this.rows.length-1&&n===i.length-1),t.toggleAttribute(`data-document-first-paragraph`,r.index===this.firstParagraph);let o=a[n-1]?.data??this.rows[e.index-1]?.blocks.at(-1)?.data;t.dataset.documentPrevTag=o?.type===`heading`?o.tag:o?.type===`horizontalrule`?`hr`:``});let o=t.getBoundingClientRect(),s=i.filter(e=>getComputedStyle(e).display!==`none`).map(e=>e.getBoundingClientRect()),c=s.length?Math.min(...s.map(e=>e.top)):o.top,l=s.length?Math.max(...s.map(e=>e.bottom)):o.bottom,u=c-o.top;Math.abs(u-(this.metrics.get(this.rows[e.index].id)?.top??0))>.1&&(n=!0),this.metrics.set(this.rows[e.index].id,{height:l-c,top:u,bottom:o.bottom-l}),r.add(e.index),e.index>0&&r.add(e.index-1)}for(let e of r){let t=this.metrics.get(this.rows[e].id);if(!t)continue;let r=Math.max(0,p(t,this.metrics.get(this.rows[e+1]?.id)));Math.abs(r-this.heights.values[e])>.1&&(this.heights.update(e,r),n=!0)}n&&(this.canvas.style.height=`${this.heights.total+this.leadingMargin}px`,this.setScrollTop(this.canvasTop()+this.blockOffset(t.index)+t.offset),this.refresh(!1),this.publish(e))}scrollTo(e){this.rows.length&&(this.setScrollTop(this.canvasTop()+this.blockOffset(Math.max(0,Math.min(e,this.rows.length-1)))),this.refresh())}dispose(){this.dead=!0,this.observer.disconnect(),cancelAnimationFrame(this.frame),this.viewport.removeEventListener(`scroll`,this.onScroll),this.canvas.removeEventListener(`focusout`,this.onFocusOut),window.removeEventListener(`resize`,this.onScroll),window.removeEventListener(`hashchange`,this.onHash),this.preserve.clear(),this.listeners.clear()}};function C({controller:e,slot:t}){let n=e.rows[t.index],[r]=(0,h.useState)(()=>{let e=document.createElement(`div`);return e.style.display=`contents`,e}),a=t.active||e.preserve.has(t.id),s=`${t.generation}:${t.active}`,[c,u]=(0,h.useState)(``),d=(0,h.useMemo)(()=>e.document.render(t.index,t.id),[e,t.generation,t.id]),f=(0,h.useMemo)(()=>({active:t.active,blockId:n.id,editor:e.document.editor,nodeState:t=>e.nodeState(n.id,t),retain:()=>{e.retained.set(t.id,(e.retained.get(t.id)??0)+1);let n=!1;return()=>{if(n)return;n=!0;let r=(e.retained.get(t.id)??1)-1;r?e.retained.set(t.id,r):e.retained.delete(t.id),e.refresh(!1)}}}),[e,n.id,t.active,t.generation,t.id]),p=(0,h.useCallback)(n=>e.attach(t,n),[e,t]);return(0,h.useLayoutEffect)(()=>{e.mount(t,r),a?e.bind(t):t.committed=-1,t.beforeRelease=()=>e.capturePanels(t)}),(0,h.useLayoutEffect)(()=>()=>r.remove(),[r]),(0,h.useEffect)(()=>{let e=requestAnimationFrame(()=>{e=requestAnimationFrame(()=>u(s))});return()=>cancelAnimationFrame(e)},[s]),(0,_.createPortal)((0,g.jsx)(`div`,{className:l,"data-pool":n.pool,"data-restoring":s===c?void 0:``,"data-virtual-renderer-block":t.active?n.id:void 0,"data-virtual-renderer-slot":t.id,ref:p,style:{display:t.active?void 0:`none`,transform:`translateY(${e.slotOffset(t)}px)`},children:(0,g.jsx)(`div`,{className:o,"data-virtual-renderer-content":``,children:(0,g.jsx)(i,{value:f,children:a&&d})})}),r,String(t.id))}function w({controller:e}){let[,t]=(0,h.useState)(0);return(0,h.useLayoutEffect)(()=>e.subscribe(()=>t(e=>e+1)),[e]),(0,h.useLayoutEffect)(()=>e.commitLayout()),(0,g.jsx)(g.Fragment,{children:e.pool.slots.map(t=>(0,g.jsx)(C,{controller:e,slot:t},t.id))})}function T({document:e,options:n}){let r=(0,h.useRef)(null),[i,a]=(0,h.useState)(null),[o,s]=(0,h.useState)(``);return(0,h.useEffect)(()=>{let t=r.current,i;try{i=new S(e,t,n),s(``),a(i),Object.assign(t,{virtualRenderer:i})}catch(e){s(String(e)),a(null);return}return()=>{i.dispose(),Reflect.deleteProperty(t,`virtualRenderer`)}},[e,n]),(0,g.jsxs)(g.Fragment,{children:[o&&(0,g.jsx)(`p`,{role:`alert`,children:o}),(0,g.jsx)(`div`,{className:c,"data-virtual-renderer":``,ref:r,children:i?(0,g.jsx)(w,{controller:i}):(0,g.jsx)(t,{document:e})})]})}export{T as VirtualizedRenderer};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{t}from"./plugin-_bGVeqI0-Bsz7oxOL.js";import{t as n}from"./react-DlmbjZJV.js";import{t as r}from"./jsx-runtime-LKYXHABd.js";import{Lt as i}from"./editor-yZwTWy-w.js";import{A as a}from"./route-i3jkzu-i.js";import{a as o,c as s,i as c,l,n as u,o as d,r as f,s as p,t as m}from"./viewport-CFJHn_Y6-CwlLMc7X.js";var h=e(n(),1),g=r(),_=e(a(),1);function v(e){"@babel/helpers - typeof";return v=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},v(e)}function y(e,t){if(v(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(v(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function b(e){var t=y(e,`string`);return v(t)==`symbol`?t:t+``}function x(e,t,n){return(t=b(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var S=class{constructor(e,t,n){if(x(this,`document`,void 0),x(this,`canvas`,void 0),x(this,`options`,void 0),x(this,`pool`,new f),x(this,`preserve`,void 0),x(this,`viewport`,void 0),x(this,`states`,new Map),x(this,`retained`,new Map),x(this,`heights`,void 0),x(this,`metrics`,new Map),x(this,`listeners`,new Set),x(this,`observer`,void 0),x(this,`width`,void 0),x(this,`frame`,0),x(this,`dead`,!1),x(this,`firstParagraph`,void 0),x(this,`onScroll`,()=>this.refresh()),x(this,`onFocusOut`,()=>queueMicrotask(()=>{this.dead||this.refresh()})),x(this,`queueMeasure`,()=>{!this.dead&&!this.frame&&(this.frame=requestAnimationFrame(()=>this.measure()))}),x(this,`onHash`,()=>{let e;try{e=decodeURIComponent(window.location.hash.slice(1))}catch{return}let t=this.document.headingRows.get(e);if(t!==void 0){this.scrollTo(t);let n=this.canvas.querySelector(`#${CSS.escape(e)}`);n&&this.setScrollTop(this.scrollTop+n.getBoundingClientRect().top-this.viewportTop())}}),this.document=e,this.canvas=t,this.options=n,n.overscan!==void 0&&(!Number.isFinite(n.overscan)||n.overscan<0))throw Error(`Renderer overscan must be a nonnegative number`);this.viewport=s(t,n.scrollContainer),this.preserve=new u(n.preserveCapacity??32,e=>{let t=this.pool.slots.find(t=>t.id===e);t?.beforeRelease?.(),t&&(t.committed=-1)}),this.width=t.clientWidth,this.heights=this.buildHeights(),this.firstParagraph=this.rows.flatMap(e=>e.blocks).find(e=>e.data.type===`paragraph`)?.index??-1,this.canvas.style.height=`${this.heights.total}px`,this.observer=new ResizeObserver(this.queueMeasure),this.observer.observe(t),this.viewport instanceof HTMLElement&&this.observer.observe(this.viewport),this.viewport.addEventListener(`scroll`,this.onScroll,{passive:!0}),this.canvas.addEventListener(`focusout`,this.onFocusOut),window.addEventListener(`resize`,this.onScroll),window.addEventListener(`hashchange`,this.onHash),this.refresh(!1),queueMicrotask(()=>{this.dead||this.onHash()})}get rows(){return this.document.rows}get scrollTop(){return this.viewport instanceof HTMLElement?this.viewport.scrollTop:window.scrollY}setScrollTop(e){this.viewport instanceof HTMLElement?this.viewport.scrollTop=e:window.scrollTo(window.scrollX,e)}viewportTop(){return this.viewport instanceof HTMLElement?this.viewport.getBoundingClientRect().top+this.viewport.clientTop:0}viewportHeight(){return this.viewport instanceof HTMLElement?this.viewport.clientHeight:window.innerHeight}canvasTop(){return this.canvas.getBoundingClientRect().top-this.viewportTop()+this.scrollTop}buildHeights(){return new m(this.rows.map(e=>e.blocks.reduce((e,t)=>{let n=this.options.estimateBlockHeight?.(t.data,this.width)??d(t.data,this.width);if(!Number.isFinite(n)||n<=0)throw Error(`Renderer estimated height must be positive and finite`);return e+n},0)))}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}publish(e=!0){if(this.dead||!this.listeners.size)return;let t=()=>this.listeners.forEach(e=>e());e?(0,_.flushSync)(t):t()}refresh(e=!0){if(this.dead||!this.rows.length)return;let t=Math.max(0,this.scrollTop-this.canvasTop()),n=this.options.overscan??this.viewportHeight()*1.5,r=this.heights.find(Math.max(0,t-n)),i=this.heights.find(t+this.viewportHeight()+n),a=Array.from({length:i-r+1},(e,t)=>r+t),o=new Set(a),s=new Set(this.pool.slots.filter(e=>e.active&&(this.retained.get(e.id)||e.element?.contains(globalThis.document.activeElement))).map(e=>e.id)),c=new Set;for(let e of this.pool.slots)(o.has(e.index)||s.has(e.id))&&this.preserve.activate(e.id)&&c.add(e.id);for(let e of this.pool.slots)e.active&&!o.has(e.index)&&!s.has(e.id)&&this.preserve.park(e.id,this.rows[e.index].id);let l=this.pool.slots.map(e=>e.id),u=this.pool.update(a,e=>this.rows[e].pool,s,new Set([...this.preserve.ids(),...c]));for(let e of l)this.pool.slots.some(t=>t.id===e)||this.preserve.forget(e);u&&this.publish(e)}mount(e,t){let n=this.pool.slots.filter(t=>t.active&&t.index>e.index).sort((e,t)=>e.index-t.index).map(e=>this.preserve.host(e.id)).find(e=>e?.parentElement===this.canvas);this.preserve.mount(e.id,t,e.active?this.canvas:null,n??null)}attach(e,t){e.element&&this.observer.unobserve(e.element),e.element=t??void 0,t&&this.observer.observe(t)}nodeState(e,t){let n=`${e}:${this.document.nodePath(t)}`,r=this.states.get(n);return r||(r=new Map,this.states.set(n,r)),r}capturePanels(e){this.nodeState(this.rows[e.index].id).set(`details`,[...e.element?.querySelectorAll(`details`)??[]].map(e=>e.open))}bind(e){if(e.committed===e.generation)return;e.committed=e.generation;let t=this.nodeState(this.rows[e.index].id).get(`details`),n=[],r=e=>{e.type===`details`&&n.push(!!e.open),e.children?.forEach(r)};r(this.rows[e.index].data),e.element?.querySelectorAll(`details`).forEach((e,r)=>e.open=t?.[r]??n[r]??!1)}get leadingMargin(){return this.metrics.get(this.rows[0]?.id)?.top??0}blockOffset(e){return this.heights.offset(e)+this.leadingMargin}slotOffset(e){return this.blockOffset(e.index)-(this.metrics.get(this.rows[e.index]?.id)?.top??0)}anchor(){let e=this.canvas.getBoundingClientRect(),t=globalThis.document.elementFromPoint(e.left+e.width/2,Math.max(this.viewportTop()+8,e.top+1))?.closest(`[data-virtual-renderer-slot]`),n=this.pool.slots.find(e=>e.active&&e.element===t)?.index??this.heights.find(Math.max(0,this.scrollTop-this.canvasTop()));return{index:n,offset:this.scrollTop-this.canvasTop()-this.blockOffset(n)}}commitLayout(){cancelAnimationFrame(this.frame),this.measure(!1)}measure(e=!0){if(this.frame=0,this.dead)return;let t=this.anchor(),n=!1;Math.abs(this.canvas.clientWidth-this.width)>.5&&(this.width=this.canvas.clientWidth,this.metrics.clear(),this.heights=this.buildHeights(),n=!0);let r=new Set;for(let e of this.pool.slots){if(!e.active)continue;let t=e.element?.firstElementChild;if(!t)continue;t.setAttribute(`data-rich-nested`,this.canvas.closest(`.rich-content`)?.getAttribute(`data-rich-nested`)??`false`);let i=[...t.children],a=this.rows[e.index].blocks;i.forEach((t,n)=>{let r=a[n];if(!r)return;t.dataset.blockId=r.id,t.dataset.rendererBlockIndex=String(r.index),t.toggleAttribute(`data-document-first`,e.index===0&&n===0),t.toggleAttribute(`data-document-last`,e.index===this.rows.length-1&&n===i.length-1),t.toggleAttribute(`data-document-first-paragraph`,r.index===this.firstParagraph);let o=a[n-1]?.data??this.rows[e.index-1]?.blocks.at(-1)?.data;t.dataset.documentPrevTag=o?.type===`heading`?o.tag:o?.type===`horizontalrule`?`hr`:``});let o=t.getBoundingClientRect(),s=i.filter(e=>getComputedStyle(e).display!==`none`).map(e=>e.getBoundingClientRect()),c=s.length?Math.min(...s.map(e=>e.top)):o.top,l=s.length?Math.max(...s.map(e=>e.bottom)):o.bottom,u=c-o.top;Math.abs(u-(this.metrics.get(this.rows[e.index].id)?.top??0))>.1&&(n=!0),this.metrics.set(this.rows[e.index].id,{height:l-c,top:u,bottom:o.bottom-l}),r.add(e.index),e.index>0&&r.add(e.index-1)}for(let e of r){let t=this.metrics.get(this.rows[e].id);if(!t)continue;let r=Math.max(0,p(t,this.metrics.get(this.rows[e+1]?.id)));Math.abs(r-this.heights.values[e])>.1&&(this.heights.update(e,r),n=!0)}n&&(this.canvas.style.height=`${this.heights.total+this.leadingMargin}px`,this.setScrollTop(this.canvasTop()+this.blockOffset(t.index)+t.offset),this.refresh(!1),this.publish(e))}scrollTo(e){this.rows.length&&(this.setScrollTop(this.canvasTop()+this.blockOffset(Math.max(0,Math.min(e,this.rows.length-1)))),this.refresh())}dispose(){this.dead=!0,this.observer.disconnect(),cancelAnimationFrame(this.frame),this.viewport.removeEventListener(`scroll`,this.onScroll),this.canvas.removeEventListener(`focusout`,this.onFocusOut),window.removeEventListener(`resize`,this.onScroll),window.removeEventListener(`hashchange`,this.onHash),this.preserve.clear(),this.listeners.clear()}};function C({controller:e,slot:t}){let n=e.rows[t.index],[r]=(0,h.useState)(()=>{let e=document.createElement(`div`);return e.style.display=`contents`,e}),a=t.active||e.preserve.has(t.id),s=`${t.generation}:${t.active}`,[c,u]=(0,h.useState)(``),d=(0,h.useMemo)(()=>e.document.render(t.index,t.id),[e,t.generation,t.id]),f=(0,h.useMemo)(()=>({active:t.active,blockId:n.id,editor:e.document.editor,nodeState:t=>e.nodeState(n.id,t),retain:()=>{e.retained.set(t.id,(e.retained.get(t.id)??0)+1);let n=!1;return()=>{if(n)return;n=!0;let r=(e.retained.get(t.id)??1)-1;r?e.retained.set(t.id,r):e.retained.delete(t.id),e.refresh(!1)}}}),[e,n.id,t.active,t.generation,t.id]),p=(0,h.useCallback)(n=>e.attach(t,n),[e,t]);return(0,h.useLayoutEffect)(()=>{e.mount(t,r),a?e.bind(t):t.committed=-1,t.beforeRelease=()=>e.capturePanels(t)}),(0,h.useLayoutEffect)(()=>()=>r.remove(),[r]),(0,h.useEffect)(()=>{let e=requestAnimationFrame(()=>{e=requestAnimationFrame(()=>u(s))});return()=>cancelAnimationFrame(e)},[s]),(0,_.createPortal)((0,g.jsx)(`div`,{className:l,"data-pool":n.pool,"data-restoring":s===c?void 0:``,"data-virtual-renderer-block":t.active?n.id:void 0,"data-virtual-renderer-slot":t.id,ref:p,style:{display:t.active?void 0:`none`,transform:`translateY(${e.slotOffset(t)}px)`},children:(0,g.jsx)(`div`,{className:o,"data-virtual-renderer-content":``,children:(0,g.jsx)(i,{value:f,children:a&&d})})}),r,String(t.id))}function w({controller:e}){let[,t]=(0,h.useState)(0);return(0,h.useLayoutEffect)(()=>e.subscribe(()=>t(e=>e+1)),[e]),(0,h.useLayoutEffect)(()=>e.commitLayout()),(0,g.jsx)(g.Fragment,{children:e.pool.slots.map(t=>(0,g.jsx)(C,{controller:e,slot:t},t.id))})}function T({document:e,options:n}){let r=(0,h.useRef)(null),[i,a]=(0,h.useState)(null),[o,s]=(0,h.useState)(``);return(0,h.useEffect)(()=>{let t=r.current,i;try{i=new S(e,t,n),s(``),a(i),Object.assign(t,{virtualRenderer:i})}catch(e){s(String(e)),a(null);return}return()=>{i.dispose(),Reflect.deleteProperty(t,`virtualRenderer`)}},[e,n]),(0,g.jsxs)(g.Fragment,{children:[o&&(0,g.jsx)(`p`,{role:`alert`,children:o}),(0,g.jsx)(`div`,{className:c,"data-virtual-renderer":``,ref:r,children:i?(0,g.jsx)(w,{controller:i}):(0,g.jsx)(t,{document:e})})]})}export{T as VirtualizedRenderer};
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./printDocument-BhGNF0gC.js","./rolldown-runtime-XKyaHtl9.js","./react-DlmbjZJV.js","./route-i3jkzu-i.js","./bem-vbke-3KC.js","./jsx-runtime-LKYXHABd.js","./types-BCsOeYI6.js","./index2.css","./shims-s-YVfIlz.js","./editor-rLQcZykK.js","./url-Buh8E05T.js","./useLayerZIndex-C75Wfz8T.js","./MotionConfigContext-BqjwrGj9.js","./is-html-element-DvgHo_1h.js","./WhiteboardEditor-DrHOvXez-DTa-K6Xu.js","./Popover-DxR9Dpf_.js","./chevron-right-DBC0wrKu.js","./stringifyLocale-VcrwrbQl.js","./code-CTMZ5SpG.js","./SelectScrollUpArrow-bXyfVgGf.js","./zoom-out-Cz3087-F.js","./text-align-start-CO9CK_EW.js","./ruler-DmQbsUQf.js","./maximize-2-Deo2WY_L.js","./mouse-pointer-2-naHRayvu.js","./undo-2-BH3P-I_n.js","./plus-C3ivaMGn.js","./MenuSubmenuTrigger-CPcD7vNW.js","./index3.css","./Tooltip-CZKrDYnF.js","./pen-tool-B7HWrrcR.js","./underline-AY5gu1iN.js","./route-messages-MxWI01S2.js","./ref-BrUHq8E2.js","./table-2-F7QzFSYG.js","./video-tvDNJEhe.js","./message-square-BQbestX7.js","./presentation-qzIErT_u.js","./ThreadView-D_g4kidg.js","./comments-CASb0ByE.js","./stable-CK-LXZNI.js","./icons-CDVhjQMS.js","./index5.css","./search-EBZOryv1.js","./shield-check-TdIPOf4j.js","./sliders-horizontal-DZKoxRty.js","./upload-D0s2oA1h.js","./agentLook-60JQrptF.js","./DotGrid-DKKr_PyM.js","./rounds-DC6Dulo5.js","./useMedia-CFebB4XU.js","./BottomSheet-BFtfrr58.js","./motion-Cy65kd7X.js","./preference-oNdcNeml.js","./useSandboxFrame-CJmSnwgG.js","./index4.css","./dist-CkWqj1vB.js","./katex-DuZJ-tFh.js","./ArtifactModal-CH9BY3RJ.js","./SplitFrame-CLquf6QT.js","./clapperboard-iHoLVEUr.js","./embed-src-CmyqZplg.js","./ArtifactModal-BU_PR8k8.css"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{A as t,E as n,S as r,j as i}from"./route-i3jkzu-i.js";/* empty css */import{t as a}from"./react-DlmbjZJV.js";import{C as o,D as s,E as c,Ht as l,_ as u,a as d,b as f,br as p,c as m,d as h,f as g,jr as _,p as v,x as y,xr as b}from"./url-Buh8E05T.js";import{t as x}from"./jsx-runtime-LKYXHABd.js";import{En as S}from"./useLayerZIndex-C75Wfz8T.js";import{Dt as C}from"./MotionConfigContext-BqjwrGj9.js";import{Gt as w,Jr as T,_i as E,bn as D,gn as O,ir as k,ni as A,pa as j,sa as ee,wn as M,xr as N,zr as te}from"./WhiteboardEditor-DrHOvXez-DTa-K6Xu.js";import{An as ne,B as P,D as re,F as ie,H as ae,I as oe,J as se,K as ce,L as le,M as ue,Pt as F,Q as de,R as fe,S as pe,St as me,U as he,V as ge,X as _e,Y as ve,Z as ye,_t as be,at as I,bt as L,ct as xe,dt as Se,et as Ce,ft as we,gt as Te,it as R,lt as z,mt as Ee,nt as De,ot as Oe,pt as ke,q as Ae,rt as je,st as Me,tt as Ne,ut as Pe,vt as Fe,w as Ie,xt as Le,yt as Re,z as ze}from"./editor-rLQcZykK.js";import{t as Be}from"./Popover-DxR9Dpf_.js";import{i as Ve}from"./route-messages-MxWI01S2.js";import{o as He}from"./ThreadView-D_g4kidg.js";import{r as Ue}from"./agentLook-60JQrptF.js";import{n as We}from"./plugin-_bGVeqI0-C4RRMCGb.js";import{i as Ge,r as Ke,t as qe}from"./comments-CASb0ByE.js";import{n as Je,t as Ye}from"./icons-CDVhjQMS.js";import{r as Xe}from"./useDrafts-WX84YtG1.js";import{n as Ze}from"./useMedia-CFebB4XU.js";import{n as Qe}from"./artifact-list-BuB3wom1.js";import{a as B,i as $e,t as et}from"./motion-Cy65kd7X.js";import{t as tt}from"./embed-src-CmyqZplg.js";import{n as nt}from"./preference-oNdcNeml.js";import{a as V,n as rt,o as it,r as at,t as ot}from"./ref-BrUHq8E2.js";import{i as st,n as ct,r as lt}from"./jump-history-Dyva9tQM.js";import{r as ut,t as dt}from"./view-drafts-DXKEb89H.js";var ft={name:`corner-down-right`,size:24,node:[[`path`,{d:`m15 10 5 5-5 5`,key:`qqa56n`}],[`path`,{d:`M4 4v7a4 4 0 0 0 4 4h12`,key:`z08zvw`}]]};ft.node;var pt=C(ft),mt={name:`pilcrow`,size:24,node:[[`path`,{d:`M13 4v16`,key:`8vvj80`}],[`path`,{d:`M17 4v16`,key:`7dpous`}],[`path`,{d:`M19 4H9.5a4.5 4.5 0 0 0 0 9H13`,key:`sh4n9v`}]]};mt.node;var ht=C(mt),H=e(a(),1);function gt(e,t,n){let r=(0,H.useMemo)(()=>f(),[]),[i,a]=(0,H.useState)(!1),s=(0,H.useRef)(t);s.current=t;let c=(0,H.useRef)(n);c.current=n,(0,H.useEffect)(()=>{if(r)return y((e,t)=>{e.kind===`chrome`&&a(e.hosted),e.kind===`history`&&s.current(e.action),t===window.parent&&e.kind===`document-export`&&e.format===`pdf`&&c.current?.()})},[r]);let{activity:l,comments:u,history:d,historyOpen:p,documentExport:m}=e;return(0,H.useEffect)(()=>{r&&o({kind:`header`,activity:l,comments:u,history:d,historyOpen:p,documentExport:m})},[r,l,u,d,p,m]),r&&i}var U=e(t(),1),W=x(),_t=`svg[role="img"] text[font-family*="Excalifont"] { font-family: ${O}; }`;function vt(){let e=nt();return(0,W.jsx)(W.Fragment,{children:e&&(0,U.createPortal)((0,W.jsx)(`style`,{"data-diagram-font-style":!0,children:_t}),document.head)})}var G=(e,t,n,r)=>e.find(e=>t<e.bottom+r&&t+n+r>e.top);function yt(e,t,n,r){for(let i=G(e,t,n,r);i;)t=i.bottom+r,i=G(e,t,n,r);return t}function bt(e,t,n,r){for(let i=G(e,t,n,r);i;)t=i.top-r-n,i=G(e,t,n,r);return t}function xt(e,t,n,r,i){let a=e.top-i-t.height;if(a<0||G(r,a,t.height,i))return null;let o=t.anchorTop-a,s=[],c=a;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t.top+t.height+i<=c)break;let a=c-i-t.height;if(t.fixed||a<0||G(r,a,t.height,i))return null;o+=t.top-a,s.push([e,a]),c=a}return{cost:o,moves:s,top:a}}function St(e,t,n,r=[]){let i=[...e].sort((e,t)=>e.anchorTop-t.anchorTop),a=n?i.findIndex(e=>e.id===n):-1,o=Math.max(a,0),s=[],c=-1/0;for(let e=o;e<i.length;e++){let n=i[e],o=Math.max(n.anchorTop,c),l=G(r,o,n.height,t);if(l){let e=yt(r,o,n.height,t),i=xt(l,n,s,r,t);if(i&&i.cost<=e-n.anchorTop){for(let[e,t]of i.moves)s[e].top=t;o=i.top}else o=e}s.push({id:n.id,top:o,height:n.height,fixed:e===a}),c=o+n.height+t}let l={};for(let e of s)l[e.id]=e.top;if(a>0){let e=l[i[a].id];for(let n=a-1;n>=0;n--){let a=i[n],o=Math.min(a.anchorTop,e-t-a.height),s=G(r,o,a.height,t);if(s){let n=bt(r,o,a.height,t),i=s.bottom+t;o=i+a.height+t<=e&&!G(r,i,a.height,t)&&Math.abs(i-a.anchorTop)<Math.abs(a.anchorTop-n)?i:n}l[a.id]=o,e=o}}return l}function Ct(e,t,n){let r=Math.max(e.x,t.x-n),i=(r+t.x)/2,a=r>e.x?` H${r}`:``;return`M${e.x} ${e.y}${a} C${i} ${e.y} ${i} ${t.y} ${t.x} ${t.y}`}var wt=8,Tt=3,Et=18;function Dt(e){let t=e.right+wt;return{left:t,right:t+Tt,top:e.top,bottom:e.bottom}}function Ot(e){return{x:e.right,y:e.top+Math.min(Et,(e.bottom-e.top)/2)}}var kt=10;function At(e,t,n,r,i){let a=Math.max(t.left,Math.min(e.left,t.right-n)),o=e.bottom+kt;return i.top+o+r<=i.height-i.reserved-8?{left:a,top:o,placement:`below`}:{left:a,top:e.top-r-kt,placement:`above`}}var K=e=>e.kind===`element`?[]:e.blocks??(e.kind===`block`?[{id:e.threadId,element:e.element}]:[]),jt=e=>e?.kind===`block`?K(e).map(e=>_e(e.element)):void 0,q=e=>e.kind===`text`?e.ranges??[e.range]:[],Mt=4;function Nt(e){return[...q(e).flatMap(e=>[...e.getClientRects()]),...K(e).map(e=>Dt(e.element.getBoundingClientRect()))].sort((e,t)=>e.top-t.top||e.left-t.left)}function Pt(e){if(e.kind===`element`)return e.node.isConnected?ce(e.node):null;let t=Nt(e).at(-1);return t?e.kind===`text`?{x:t.right,y:t.bottom}:Ot(t):null}function Ft(e,t,n){let r=document.createRange(),i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),a=0,o=!1;for(let e=i.nextNode();e;e=i.nextNode()){let i=a+e.length;if(!o&&t<=i&&(r.setStart(e,t-a),o=!0),o&&n<=i)return r.setEnd(e,n-a),r;a=i}return r.selectNodeContents(e),r}function It(e,t,n,r=0){let[i,a]=(0,H.useState)([]);return(0,H.useEffect)(()=>{if(!e||!n)return;let r=()=>{let r=e.getEditorState().read(()=>{let e=new Map;for(let t of N().getChildren()){let n=A(t,F);n&&e.set(n,t.getKey())}return e}),i=n.getBoundingClientRect().top-n.scrollTop,o=[];for(let n of t){let t=qe(n.anchor).flatMap(t=>{let n=r.get(t),i=n?e.getElementByKey(n):null;return i?[{id:t,element:i}]:[]}),a=t[0]?.element;if(!a)continue;if(n.anchor.diagram){let e=Ae(a,n.id);if(e){let t=e.getBoundingClientRect(),r=n.anchor.diagram.kind===`edge`?ce(e).y:t.top;o.push({threadId:n.id,top:r-i,kind:`element`,node:e})}else o.push({threadId:n.id,top:a.getBoundingClientRect().top-i,kind:`block`,element:a,blocks:t});continue}if(n.anchor.textRanges){let e=new Map(n.anchor.textRanges.map(e=>[e.blockId,e])),r=[],s=[],c;for(let n of t){let t=e.get(n.id),a=t?ye(n.element.textContent??``,t.quote,t.start):`block`;if(a===`block`)s.push(n),c??=n.element.getBoundingClientRect().top-i;else{let e=Ft(n.element,a.start,a.end);r.push(e);let t=e.getClientRects()[0]??n.element.getBoundingClientRect();c??=t.top-i}}r.length?o.push({threadId:n.id,top:c,kind:`text`,range:r[0],ranges:r,blocks:s}):o.push({threadId:n.id,top:c,kind:`block`,element:a,blocks:s});continue}let s=n.anchor.blockIds?`block`:ye(a.textContent??``,n.anchor.quote);if(s===`block`){o.push({threadId:n.id,top:a.getBoundingClientRect().top-i,kind:`block`,element:a,blocks:t});continue}let c=Ft(a,s.start,s.end),l=c.getClientRects()[0]??a.getBoundingClientRect();o.push({threadId:n.id,top:l.top-i,kind:`text`,range:c})}a(o)};r();let i=0,o=()=>{cancelAnimationFrame(i),i=requestAnimationFrame(r)},s=e.registerUpdateListener(o),c=new ResizeObserver(o);c.observe(n);let l=e.getRootElement();return l&&c.observe(l),()=>{cancelAnimationFrame(i),s(),c.disconnect()}},[e,t,n,r]),i}function Lt(e,t,n){(0,H.useEffect)(()=>{if(typeof CSS>`u`||!(`highlights`in CSS))return;let r=de(t,n),i=new Set(t.filter(Ge).map(e=>e.id)),a=e.filter(e=>r.has(e.threadId)&&e.threadId!==n&&!i.has(e.threadId)).flatMap(q),o=e.filter(e=>i.has(e.threadId)&&e.threadId!==n).flatMap(q),s=e.filter(e=>e.threadId===n).flatMap(q);return CSS.highlights.set(`ryugi-comment`,new Highlight(...a)),CSS.highlights.set(`ryugi-comment-active`,new Highlight(...s)),CSS.highlights.set(`ryugi-comment-queued`,new Highlight(...o)),()=>{CSS.highlights.delete(`ryugi-comment`),CSS.highlights.delete(`ryugi-comment-queued`),CSS.highlights.delete(`ryugi-comment-active`)}},[e,t,n])}function Rt(e,t){(0,H.useEffect)(()=>{if(t?.length){for(let e of t)e.setAttribute(`data-comment-draft`,``);return()=>{for(let e of t)e.removeAttribute(`data-comment-draft`)}}if(e&&typeof CSS<`u`&&`highlights`in CSS)return CSS.highlights.set(`ryugi-comment-draft`,new Highlight(e)),()=>{CSS.highlights.delete(`ryugi-comment-draft`)}},[e,t])}function zt(e,t,n){for(let r of e){if(r.kind===`element`)continue;let e=r.kind===`block`||K(r).length?Mt:0;for(let i of Nt(r))if(t>=i.left-e&&t<=i.right+e&&n>=i.top&&n<=i.bottom)return r.threadId}return null}var Bt=e=>Math.max(0,Math.min(window.scrollY+e.getBoundingClientRect().top-100,document.documentElement.scrollHeight-window.innerHeight));function Vt(e){window.scrollTo({top:Bt(e),behavior:`instant`})}function J(e,t){let n=Bt(e);if(B())return window.scrollTo({top:n,behavior:`instant`}),t?.(),()=>{};let r=()=>{window.removeEventListener(`wheel`,i),window.removeEventListener(`touchmove`,i)},i=()=>{a.stop(),r()},a=l({keyframes:[window.scrollY+1,n],type:`spring`,stiffness:1e3,damping:250,onUpdate:e=>window.scrollTo({top:e,behavior:`instant`}),onComplete:()=>{r(),t?.()}});return window.addEventListener(`wheel`,i,{passive:!0}),window.addEventListener(`touchmove`,i,{passive:!0}),i}var Y=12,Ht=40,Ut=18,X=`\0draft`,Wt=160;function Gt({id:e,onHeight:t,children:n}){let r=(0,H.useRef)(null);return(0,H.useLayoutEffect)(()=>{let n=r.current;if(!n)return;let i=new ResizeObserver(()=>t(e,n.offsetHeight));return i.observe(n),t(e,n.offsetHeight),()=>i.disconnect()},[e,t]),(0,W.jsx)(`div`,{ref:r,children:n})}function Kt({narrow:e,threads:t,anchors:n,blocked:i,activeId:a,actions:o,draft:s,onActivate:c,railRef:l,agent:u}){let[d,f]=(0,H.useState)({}),[p,m]=(0,H.useState)(0),h=(0,H.useCallback)((e,t)=>m(t),[]),[g,_]=(0,H.useState)([]),v=(0,H.useRef)(null),y=(0,H.useRef)(new Map).current,b=(0,H.useRef)((e,t)=>f(n=>n[e]===t?n:{...n,[e]:t})).current,x=(0,H.useCallback)(e=>{v.current=e,l(e)},[l]),S=new Map(n.map(e=>[e.threadId,e.top])),C=new Map(n.map(e=>[e.threadId,e])),w=t.filter(e=>S.has(e.id)),T=t.filter(e=>!S.has(e.id)&&!e.messages.every(e=>e.deleted)),E=s&&!s.leaving?s:null,D=w.map(e=>({id:e.id,anchorTop:S.get(e.id),height:d[e.id]??120}));E&&D.push({id:X,anchorTop:E.anchorTop,height:d[X]??Wt});let O=St(D,Y,E?X:a??void 0,i),k=(0,H.useRef)(0);E&&(k.current=O[X]??E.anchorTop);let A=Math.max(0,...D.map(e=>(O[e.id]??0)+e.height)),j=yt(i??[],A+Y,p,Y),ee=JSON.stringify(O);(0,H.useLayoutEffect)(()=>{let r=v.current;if(e||!r)return _([]);let i=r.getBoundingClientRect(),o=de(t,a),s=[];for(let e of n){let t=O[e.threadId],n=Pt(e);if(t===void 0||!n||!o.has(e.threadId))continue;let r={x:n.x-i.left,y:n.y-i.top};s.push({id:e.threadId,d:Ct(r,{x:0,y:t+Ut},Ht)})}let c=r.closest(`main`);if(E&&c){let e=c.getBoundingClientRect(),t={x:E.from.x+e.left-i.left,y:E.from.y+e.top-i.top};s.push({id:X,d:Ct(t,{x:0,y:k.current+Ut},Ht)})}_(s)},[e,n,t,a,ee,E]),(0,H.useEffect)(()=>{let t=a?y.get(a):void 0;if(e||!t)return;let n=!1,r=()=>{},i=t.getAnimations({subtree:!0}).map(e=>e.finished.catch(()=>void 0));return Promise.all(i).then(()=>{!n&&he(t.getBoundingClientRect(),window.innerHeight)&&(r=J(t))}),()=>{n=!0,r()}},[a,e,y]);let M=e=>(0,W.jsx)(ge,{actions:o,active:e.id===a,agent:u,label:se(e.anchor,jt(C.get(e.id))),thread:e,onActivate:()=>c(e.id)});if(e)return(0,W.jsxs)(`div`,{"aria-label":r(`document.commentsLabel`),ref:x,role:`region`,className:`x78zum5 xdt5ytf x1v2ro7d xh8yej3 x7ep2pv xvueqy4`,children:[[...w].sort((e,t)=>S.get(e.id)-S.get(t.id)).map(e=>(0,W.jsx)(`div`,{children:M(e)},e.id)),T.length>0?(0,W.jsx)(`div`,{className:`xqui205 x1e56ztr xddlp02 xqfszdh x1j6dyjg`,children:r(`document.originalDeleted`)}):null,T.map(e=>(0,W.jsx)(`div`,{children:M(e)},e.id))]});let N=E?X:a;return(0,W.jsxs)(`aside`,{"aria-label":r(`document.commentsLabel`),ref:x,className:`x1n2onr6 xh8yej3 x2lah0s`,style:{minHeight:A},children:[(0,W.jsx)(`svg`,{className:`x10l6tqk x13vifvy xu96u03 x1i1rx1s xjm9jq1 x1rea2x4 x47corl`,children:g.map(e=>(0,W.jsx)(`path`,{d:e.d,fill:`none`,stroke:e.id===N?Ue.warningStrong:`currentColor`,strokeDasharray:e.id===N?void 0:`3 3`,strokeOpacity:e.id===N?1:.25},e.id))}),w.map(e=>(0,W.jsx)(`div`,{"data-active":e.id===a||void 0,"data-thread-slot":e.id,ref:t=>{t?y.set(e.id,t):y.delete(e.id)},className:`x10l6tqk xu96u03 xh8yej3 xhtitgo x14h5d43 xx6bhzk`,style:{top:O[e.id]},children:(0,W.jsx)(Gt,{id:e.id,onHeight:b,children:M(e)})},e.id)),s?(0,W.jsx)(`div`,{"data-draft-slot":``,...{0:{className:`x10l6tqk xu96u03 xh8yej3 xhtitgo x14h5d43 xx6bhzk`},1:{className:`x10l6tqk xu96u03 xh8yej3 x14h5d43 xx6bhzk xzkaem6`}}[!!s.leaving|0],style:{top:k.current},children:(0,W.jsx)(Gt,{id:X,onHeight:b,children:s.node})}):null,T.length>0?(0,W.jsx)(`div`,{style:{position:`absolute`,top:j,left:0,width:`100%`,zIndex:2},children:(0,W.jsxs)(Gt,{id:`orphaned`,onHeight:h,children:[(0,W.jsx)(`div`,{className:`xqui205 x1e56ztr xddlp02 xqfszdh x1j6dyjg`,children:r(`document.originalDeleted`)}),T.map(e=>(0,W.jsx)(`div`,{style:{marginBottom:Y},children:M(e)},e.id))]})}):null]})}function qt({container:e,anchors:t,threads:n,activeId:r}){let[i,a]=(0,H.useState)([]);return(0,H.useLayoutEffect)(()=>{if(!e)return a([]);let i=e.getBoundingClientRect(),o=de(n,r),s=[];for(let e of t)if(o.has(e.threadId))for(let t of K(e)){let n=Dt(t.element.getBoundingClientRect());s.push({id:e.threadId,key:`${e.threadId}:${t.id}`,left:n.left-i.left,top:n.top-i.top,width:n.right-n.left,height:n.bottom-n.top})}a(s)},[e,t,n,r]),i.map(e=>(0,W.jsx)(`div`,{"data-comment-block":e.id,...{0:{className:`x10l6tqk x1cum3z5 x47corl x1f2496h x15406qy xx6bhzk`},1:{className:`x10l6tqk x1cum3z5 x47corl x15406qy xx6bhzk x5hs8br`}}[e.id===r|0],style:{left:e.left,top:e.top,width:e.width,height:e.height}},e.key))}var Jt=/^#([\w-]{4,64})$/,Yt=/^#ryugi-host=/,Xt=e=>Jt.exec(e)?.[1]??null;function Z(e=window){if(e.parent===e||!e.parent)return e;try{return e.parent.location.href,e.parent}catch{return e}}var Zt=(e=Z())=>Xt(e.location.hash);function Qt(e,t=Z()){let{hash:n,pathname:r,search:i}=t.location;if(Yt.test(n))return;let a=e?`#${e}`:``;n!==a&&t.history.replaceState(t.history.state,``,`${r}${i}${a}`)}function $t(e,t){let n=new URL(e);return n.hash=t,n.toString()}var en=new Set([`h2`,`h3`]),tn=160;function nn(e){let t=document.createRange();t.selectNodeContents(e);let n=t.getClientRects?.(),r=n&&n.length>0?n.item(n.length-1):null,i=e.getBoundingClientRect();return r&&r.width>0?r:i}function rn(e,t){e.getEditorState().read(()=>{for(let n of t){let t=k(n),r=e.getElementByKey(n);if(!M(t)||!r)continue;let i=en.has(t.getTag())?A(t,F):``;i?r.id=i:r.removeAttribute(`id`)}})}function an({editor:e,shareBase:t}){let[n,i]=(0,H.useState)(null),[a,o]=(0,H.useState)(!1),s=(0,H.useRef)(void 0);if((0,H.useEffect)(()=>{if(e.hasNodes([D]))return e.registerMutationListener(D,t=>rn(e,[...t].filter(([,e])=>e!==`destroyed`).map(([e])=>e)))},[e]),(0,H.useEffect)(()=>{let t=()=>clearTimeout(s.current),n=()=>{t(),s.current=setTimeout(()=>i(null),tn)},r=r=>{let a=r.target;if(a?.closest?.(`[data-heading-link]`))return t();let s=e.getRootElement(),c=a?.closest?.(`h2[id], h3[id]`);if(!s||!c||!s.contains(c))return n();t();let l=nn(c);o(!1),i({id:c.id,left:l.right+window.scrollX+6,top:l.top+window.scrollY+(l.height-24)/2})};return document.addEventListener(`pointerover`,r),()=>{t(),document.removeEventListener(`pointerover`,r)}},[e]),!n)return null;let c=()=>{let e=$t(t||Z().location.href,n.id);navigator.clipboard?.writeText(e),Qt(n.id),o(!0)},l=r(a?`document.headingLinkCopied`:`document.copyHeadingLink`);return(0,U.createPortal)((0,W.jsx)(`button`,{"aria-label":l,"data-heading-link":``,style:{left:n.left,top:n.top},title:l,type:`button`,onClick:c,onPointerDown:e=>e.preventDefault(),...{0:{className:`x10l6tqk xoegz02 xrvj5dj x1ku5rj1 xvy4d1p xxk0z11 x1717udv xc342km x1kogg8i xjbqb8w xj0l527 xddlp02 x157umkc x1in2gmu x1ypdohk x1de99jn xaatb59 x1y3gkto x1uczgqu x60py1w`},1:{className:`x10l6tqk xoegz02 xrvj5dj x1ku5rj1 xvy4d1p xxk0z11 x1717udv xc342km x1kogg8i xjbqb8w xj0l527 x1ypdohk x1de99jn xaatb59 x1y3gkto x1uczgqu x60py1w x1cge3fn`}}[!!a|0],children:a?(0,W.jsx)(_,{"aria-hidden":`true`,size:14}):(0,W.jsx)(b,{"aria-hidden":`true`,size:14})}),document.body)}var on=620,sn=class extends H.Component{state={leaving:null,shown:null};static getDerivedStateFromProps(e,t){return e.history?.immersive?t.shown===e.history?null:{shown:e.history}:t.shown?{shown:null,leaving:t.shown}:null}host=null;paper=null;viewport=null;shell=null;entry=null;slide=null;exitTimer=null;getSnapshotBeforeUpdate(){return{rect:this.paper?.getBoundingClientRect()??null,x:window.scrollX,y:window.scrollY}}animate(e,t){if(!this.paper||!e||B()||typeof this.paper.animate!=`function`)return;this.slide?.cancel();let n=t??this.paper.getBoundingClientRect(),r=Math.max(56,e.top),i=parseFloat(getComputedStyle(this.paper).borderLeftWidth)||0,a=t?0:i,o=t?i:0;this.slide=this.paper.animate([{left:e.left-a+`px`,top:r-a+`px`,width:e.width+a*2+`px`,height:Math.min(e.height,window.innerHeight-r)+a+`px`},{left:n.left-o+`px`,top:n.top-o+`px`,width:n.width+o*2+`px`,height:n.height+o+`px`}],{duration:on,easing:et,fill:t?`forwards`:`none`}),this.slide.finished.catch(()=>{})}unlock=()=>{if(this.exitTimer&&clearTimeout(this.exitTimer),this.exitTimer=null,this.slide?.cancel(),this.slide=null,this.host&&(this.host.style.height=``),this.entry){let e=this.entry;document.documentElement.style.overflow=e.overflow,document.documentElement.style.scrollbarGutter=e.gutter,window.scrollTo(e.x,e.y)}this.entry=null};componentDidUpdate(e,t,n){let r=!!this.props.history?.immersive,i=!!e.history?.immersive;if(r&&!i)this.exitTimer&&clearTimeout(this.exitTimer),this.exitTimer=null,this.state.leaving&&this.setState({leaving:null}),this.entry||(this.entry={...n,focus:document.activeElement,overflow:document.documentElement.style.overflow,gutter:document.documentElement.style.scrollbarGutter,offset:Math.max(0,56-(n.rect?.top??56))},this.host&&(this.host.style.height=(n.rect?.height??0)+`px`)),n.rect&&this.shell?.style.setProperty(`--history-reading-width`,n.rect.width+`px`),document.documentElement.style.scrollbarGutter=`stable`,document.documentElement.style.overflow=`hidden`,this.viewport&&(this.viewport.scrollTop=this.entry.offset),this.animate(n.rect),this.shell?.querySelector(`[data-history-exit]`)?.focus({preventScroll:!0});else if(!r&&i&&this.entry){let e=this.entry;this.viewport&&(this.viewport.scrollTop=e.offset),window.scrollTo(e.x,e.y),e.focus?.focus({preventScroll:!0});let t=e.rect;t&&this.animate(n.rect,{left:t.left,top:Math.max(56,t.top),width:t.width,height:Math.min(t.height,window.innerHeight-Math.max(56,t.top))});let r=()=>{this.setState({leaving:null},()=>{this.unlock(),e.focus?.focus({preventScroll:!0})})};B()?r():this.exitTimer=setTimeout(r,on)}else!r&&!this.state.leaving&&(!e.history&&this.props.history&&(this.entry={...n,focus:null,overflow:document.documentElement.style.overflow,gutter:document.documentElement.style.scrollbarGutter,offset:0}),e.history&&!this.props.history&&this.entry&&(window.scrollTo(this.entry.x,this.entry.y),this.entry=null))}componentWillUnmount(){this.unlock()}trap=e=>{if(!this.props.history?.immersive||e.key!==`Tab`)return;let t=[...this.shell?.querySelectorAll(`button:not(:disabled),a[href],summary,[tabindex="0"]`)??[]].filter(e=>!e.closest(`[hidden],[aria-hidden="true"],[inert]`)),n=t[0],r=t.at(-1);e.shiftKey&&document.activeElement===n?(e.preventDefault(),r?.focus()):!e.shiftKey&&document.activeElement===r&&(e.preventDefault(),n?.focus())};render(){let{history:e,children:t}=this.props,n=e?.immersive?e:this.state.leaving,i=!!n,a=!!e?.ready;return(0,W.jsx)(`div`,{className:`history-body`,ref:e=>{this.host=e},children:(0,W.jsxs)(`div`,{"aria-label":e?.immersive?r(`history.title`):void 0,"aria-modal":e?.immersive?!0:void 0,className:`history-space-shell`,"data-immersive":i?``:void 0,"data-open":e?.immersive?``:void 0,inert:!(!this.state.leaving||e),role:e?.immersive?`dialog`:void 0,ref:e=>{this.shell=e},onKeyDown:this.trap,children:[n?.space,(0,W.jsx)(`div`,{className:`history-space-paper`,ref:e=>{this.paper=e},children:(0,W.jsxs)(`div`,{className:`history-space-scroll`,tabIndex:i?0:void 0,ref:e=>{this.viewport=e},children:[(0,W.jsx)(`div`,{className:`history-body-comparison`,"data-ready":a,hidden:!a,children:e?.content}),(0,W.jsx)(`div`,{hidden:a,children:t})]})})]})})}};function cn({history:e,children:t}){let[n,r]=(0,H.useState)({current:e,panel:e?.panel??null});return n.current!==e&&r({current:e,panel:e?.panel??n.panel}),(0,H.useEffect)(()=>{if(e)return;let t=setTimeout(()=>{r(e=>e.current?e:{...e,panel:null})},B()?0:280);return()=>clearTimeout(t)},[e]),(0,W.jsx)(`div`,{className:`history-rail`,"data-moving":e||n.panel?``:void 0,"data-open":e?``:void 0,children:(0,W.jsxs)(`div`,{className:`history-rail-track`,children:[(0,W.jsx)(`div`,{"aria-hidden":e?!0:void 0,className:`history-rail-comments`,inert:!!e,children:t}),(0,W.jsx)(`div`,{"aria-hidden":!e||void 0,className:`history-rail-panel`,inert:!e,children:e?.panel??n.panel})]})})}var ln=(0,H.createContext)(!1),un=3e3;function dn(e,t){let n=e.getRootElement()?.closest(`.history-body`)?.querySelector(`.history-body-comparison[data-ready="true"]`);if(n)return[...n.querySelectorAll(`[data-history-block-id]`)].find(e=>e.dataset.historyBlockId===t)?.querySelector(`.history-current :is(h1, h2, h3, h4, h5, h6)`)??null;let r=e.getEditorState().read(()=>N().getChildren().find(e=>A(e,F)===t)?.getKey());return r?e.getElementByKey(r):null}function fn(e,t){let n=(0,H.useContext)(ln)?null:e,[r]=(0,H.useState)(Zt),i=(0,H.useRef)(r),a=(0,H.useRef)(r),o=(0,H.useRef)(void 0),s=(0,H.useRef)(null),c=(0,H.useRef)(null),l=(0,H.useCallback)(e=>{s.current=e,Qt(e)},[]),u=(0,H.useCallback)(e=>{let t=n&&dn(n,e);return t?(o.current?.(),o.current=J(t,()=>{i.current===e&&!a.current&&(i.current=null)}),!0):!1},[n]),d=(0,H.useCallback)(e=>{let t=n&&dn(n,e);return t?(o.current?.(),Vt(t),i.current===e&&!a.current&&(i.current=null),!0):!1},[n]),f=(0,H.useCallback)(e=>{let t={lock:i.current,pending:a.current};i.current=e,a.current=null,u(e)?l(e):(i.current=t.lock,a.current=t.pending)},[u,l]);return(0,H.useEffect)(()=>{if(!n)return;let e=()=>{if(n.getRootElement()?.closest(`.history-space-shell[data-immersive]`))return;let e=a.current;e&&(a.current=null,v()?i.current===e&&(i.current=null):d(e)?c.current={blockId:e,until:Date.now()+un}:a.current=e)};e();let t=()=>{i.current=null,a.current=null,c.current=null},r=new ResizeObserver(()=>{if(n.getRootElement()?.closest(`.history-space-shell[data-immersive]`))return;let e=c.current;e&&(Date.now()>e.until?c.current=null:d(e.blockId))}),l=n.registerRootListener(e=>{r.disconnect(),e&&r.observe(e)}),u=Z(),f=()=>{let t=Zt();t&&t!==s.current&&!lt(u.history.state)&&(i.current=t,a.current=t,e())},p=n.registerUpdateListener(e);return window.addEventListener(`wheel`,t,{passive:!0}),window.addEventListener(`touchmove`,t,{passive:!0}),window.addEventListener(`keydown`,t),u.addEventListener(`hashchange`,f),()=>{p(),l(),r.disconnect(),o.current?.(),window.removeEventListener(`wheel`,t),window.removeEventListener(`touchmove`,t),window.removeEventListener(`keydown`,t),u.removeEventListener(`hashchange`,f)}},[n,d]),(0,H.useEffect)(()=>{if(n){if(i.current){if(a.current||t!==i.current)return;i.current=null}else l(t)}},[t,n,l]),{scrollTo:f}}function pn({editor:e}){return fn(e,null),null}var mn={h2:0,h3:1};function hn(){let e=[],t=null,n=null;for(let r of N().getChildren()){let i=M(r)?r.getTag():void 0,a=A(r,F);if(i===`h1`){t={key:r.getKey(),blockId:a,text:r.getTextContent()},n=null;continue}let o=i===void 0?void 0:mn[i];o!==void 0&&(n={key:r.getKey(),blockId:a,text:r.getTextContent(),depth:o,part:t,blocks:[]},e.push(n)),a&&n?.blocks.push(a)}return e}function gn(e,t){let n=new Map;for(let t of e)for(let e of t.blocks)n.set(e,t.blockId);let r=new Set;for(let e of t)if(e.status===`open`)for(let t of qe(e.anchor)){let e=n.get(t);e&&r.add(e)}return r}function _n(e){let t=new Set(e.map(e=>e.part?.key??null)).size>1,n=[],r;for(let i of e){let e=n.at(-1),a=i.part!==r;i.depth===0||!e||a?n.push({head:i,children:[],index:n.length,partStart:t&&a?i.part:null}):e.children.push(i),r=i.part}return n}var Q={toc:{kVAEAm:`x7wzq59`,kY2c9j:`x1w0boku`,k87sOh:`xossvpg`,kSGwAc:`x1y8v6su`,keoZOQ:`x1tfhste`,k1xSpc:`x78zum5`,kXwgrk:`xdt5ytf`,kskxy:`x1r4ahda`,k7Eaqz:`xeuugli`,kMv6JI:`xqfszdh`,kGuDYH:`x1ct8sxb`,kMwMTN:`x1bo0w0s`,$$css:!0},rail:{kzqmXN:`x1td3qas`,$$css:!0},list:{kAzted:`x2lwn1j`,kORKVm:`x1odjw0f`,kacamN:`x1e4zzel`,k5wCbM:`x1rohswg`,k8WAf4:`xj8oexa`,$$css:!0},item:{kVAEAm:`x1n2onr6`,k1xSpc:`x78zum5`,kGNEyG:`x6s0dn4`,kOIVth:`x167g77z`,kzqmXN:`xh8yej3`,kZKoxP:`xlrawln`,kmVPX3:`x1717udv`,kMzoRj:`xc342km`,kaIpWk:`x1kogg8i`,kWkggS:`xjbqb8w`,kkrTdU:`x1ypdohk`,kMeerF:`x1de99jn`,k3XXqK:`xaatb59`,kInvED:`x1g40iwv`,kjBf7l:`x1uczgqu x60py1w`,$$css:!0},tick:{kmuXW:`x2lah0s`,kzqmXN:`xsmyaan`,kZKoxP:`x36qwtl`,keTefX:`xdwrcjd`,kaIpWk:`x1nj7uno`,kWkggS:`x174nbcu`,kmkexE:`x10iii20`,$$css:!0},tickH2:{kzqmXN:`xw4jnvo`,keTefX:`x1lziwak`,kWkggS:`xxwmxtg`,$$css:!0},tickActive:{kzqmXN:`xw4jnvo`,keTefX:`x1lziwak`,kWkggS:`x15az74h`,$$css:!0},tickDot:{keTefX:`x165d6jo`,$$css:!0},part:{kB7OPa:`x9f619`,kZKoxP:`x10w6t97`,kVQacm:`xb3r6kr`,kLKAdn:`xyinxu5`,kGuDYH:`x1j6dyjg`,k63SB2:`x1s688f`,kLWn49:`x1wfe3co`,kb6lSQ:`x16q24ku`,kMwMTN:`xddlp02`,kg5iWk:`xlyipyv`,khDVqt:`xuxw1ft`,kmkexE:`x1un5det`,$$css:!0},partFirst:{kZKoxP:`xxk0z11`,kLKAdn:`x1yrsyyn`,$$css:!0},row:{k1xSpc:`x78zum5`,kGNEyG:`x6s0dn4`,kOIVth:`x17d4w8g`,kzqmXN:`xh8yej3`,kZKoxP:`xlrawln`,kmVPX3:`x1717udv`,kMzoRj:`xc342km`,kaIpWk:`x12oqio5`,kWkggS:`xjbqb8w`,kMwMTN:`x1bo0w0s xytdrwj`,kVVagm:`xln7xf2`,k9WMMc:`x1yc453h`,kkrTdU:`x1ypdohk`,kmkexE:`x137m0jx x413zg9`,kMeerF:`x1de99jn`,k3XXqK:`xaatb59`,kInvED:`x1g40iwv`,kjBf7l:`x1uczgqu x60py1w`,$$css:!0},rowNested:{kZCmMZ:`x1onr9mi`,kGuDYH:`xfifm61`,kMwMTN:`xddlp02 xytdrwj`,$$css:!0},rowCurrent:{kZKoxP:`x1fgtraw`,kGuDYH:`x2ouz8m`,k63SB2:`x1s688f`,kMwMTN:`xo2rkog xytdrwj`,$$css:!0},rowActive:{k63SB2:`x1s688f`,kMwMTN:`x1cge3fn x157umkc`,$$css:!0},rowText:{kUk6DE:`x98rzlu`,k7Eaqz:`xeuugli`,kVQacm:`xb3r6kr`,kg5iWk:`xlyipyv`,khDVqt:`xuxw1ft`,$$css:!0},count:{kmuXW:`x2lah0s`,kGuDYH:`x1j6dyjg`,k63SB2:`xo1l8bm`,kMwMTN:`xc7n51q`,kcqcaj:`xss6m8b`,$$css:!0},fold:{k1xSpc:`xrvj5dj`,k9llMU:`xihq33y`,k33iCy:`xlshs6z`,kSiTet:`xg01cxk`,kmkexE:`x1u0be13 x9kvfbb`,$$css:!0},foldOpen:{k9llMU:`x1tu4anv`,k33iCy:`xnpuxes`,kSiTet:`x1hc1fzr`,kmkexE:`xjgrksx x9kvfbb`,$$css:!0},foldRows:{kAzted:`x2lwn1j`,kVQacm:`xb3r6kr`,k3aq6I:`x1bvilyr`,kmkexE:`x1pagzdl x9kvfbb`,$$css:!0},foldRowsOpen:{k3aq6I:`x1c071of`,kmkexE:`x94wcrn x9kvfbb`,$$css:!0},fadeNear:{kSiTet:`xiiclqw`,$$css:!0},fadeMid:{kSiTet:`xf9vgkq`,$$css:!0},fadeFar:{kSiTet:`x197sbye`,$$css:!0},dot:{kmuXW:`x2lah0s`,kzqmXN:`x1ftt334`,kZKoxP:`x1ycjhwn`,kaIpWk:`x16rqkct`,kWkggS:`xzkukvh`,$$css:!0},card:{kVAEAm:`x10l6tqk`,kY2c9j:`x1w0boku`,k87sOh:`xn0lweg`,kbCHJM:`x6f9vd5`,kzqmXN:`x1hfn5x7`,kskxy:`x1r4ahda`,kORKVm:`x1odjw0f`,kB7OPa:`x9f619`,k8WAf4:`x1vvogim`,kg3NbH:`xaope02`,kMzoRj:`xmkeg23`,ksu8eU:`x1y0btm7`,kVAM5u:`xgcsv5v`,kaIpWk:`x1q4ynmn`,kWkggS:`x12ilycc`,kGVxlE:`x1d5q07e`,$$css:!0}},vn=120,yn=200,bn=150,xn=new Set;function Sn(e,t){let[n,r]=(0,H.useState)({key:null,reading:!1});return(0,H.useEffect)(()=>{if(!e)return;let n=()=>{if(e.getRootElement()?.closest(`.history-space-shell[data-immersive]`))return;let n=t[0]?.key??null,i=!1;for(let r of t){let t=r.blockId?dn(e,r.blockId):e.getElementByKey(r.key);t&&t.getBoundingClientRect().top<vn&&(n=r.key,i=!0)}r(e=>e.key===n&&e.reading===i?e:{key:n,reading:i})};return n(),window.addEventListener(`scroll`,n,{passive:!0}),()=>window.removeEventListener(`scroll`,n)},[e,t]),n}function Cn(e,t,n){(0,H.useEffect)(()=>{let n=()=>{let n=e.current,r=t.current;if(!n||!r)return;let i=n.getBoundingClientRect(),a=r.getBoundingClientRect();(a.top<i.top||a.bottom>i.bottom)&&(n.scrollTop=Math.max(0,n.scrollTop+a.top-i.top-(n.clientHeight-a.height)/2))};return n(),window.addEventListener(`scroll`,n,{passive:!0}),window.addEventListener(`resize`,n),()=>{window.removeEventListener(`scroll`,n),window.removeEventListener(`resize`,n)}},n)}function wn({editor:e,threads:t=[],variant:n=`column`}){let[a,o]=(0,H.useState)([]),[s,c]=(0,H.useState)(!1),[l,u]=(0,H.useState)(xn),d=(0,H.useRef)(void 0),f=(0,H.useRef)(void 0),p=(0,H.useRef)(null),m=(0,H.useRef)(null);(0,H.useEffect)(()=>{if(!e)return;let t=()=>o(e.getEditorState().read(hn));return t(),e.registerUpdateListener(t)},[e]);let h=Sn(e,a),g=a.find(e=>e.key===h.key),{scrollTo:_}=fn(e,h.reading&&g?.blockId?g.blockId:null),v=(0,H.useMemo)(()=>gn(a,t),[a,t]),y=(0,H.useMemo)(()=>_n(a),[a]);Cn(p,m,[h.key,a]),(0,H.useEffect)(()=>()=>{clearTimeout(d.current),clearTimeout(f.current)},[]);let b=y.find(e=>e.head.key===h.key||e.children.some(e=>e.key===h.key)),x=b?.head.key??null,[S,C]=(0,H.useState)(x),w=e=>u(t=>t.has(e)?t:new Set(t).add(e));S!==x&&(C(x),s&&S&&w(S));let T=()=>{clearTimeout(d.current),c(!0)},E=()=>{clearTimeout(d.current),clearTimeout(f.current),d.current=setTimeout(()=>{c(!1),u(xn)},yn)},D=e=>{clearTimeout(f.current),f.current=setTimeout(()=>w(e),bn)},O=t=>{if(t.blockId)return _(t.blockId);let n=e?.getElementByKey(t.key);n&&J(n)};if(n===`hidden`)return null;if(a.length===0)return(0,W.jsx)(`nav`,{"data-variant":n,...i(Q.toc)});let k=n===`rail`,A=e=>y.map(t=>{let{head:n,children:r}=t,a=t===b,o=a||l.has(n.key),c=b?Math.abs(t.index-b.index):0,u=e!==`column`||s||c===0?null:c===1?Q.fadeNear:c<=3?Q.fadeMid:Q.fadeFar,d=(t,n,r,o,s=!1)=>{let c=t.key===h.key,l=e===`card`,d=o?(0,W.jsx)(`span`,{"data-commented":``,...i(Q.dot,e===`ticks`&&Q.tickDot)}):null;return(0,W.jsxs)(`button`,{"aria-current":c&&!l?`location`:void 0,"aria-label":t.text,ref:c&&!l?m:void 0,tabIndex:l?-1:void 0,type:`button`,onClick:()=>O(t),onFocus:s?()=>w(t.key):void 0,onPointerEnter:s?()=>D(t.key):void 0,onPointerLeave:s?()=>clearTimeout(f.current):void 0,...i(e===`ticks`?Q.item:Q.row,e!==`ticks`&&n&&Q.rowNested,!n&&a&&Q.rowCurrent,e!==`ticks`&&c&&Q.rowActive,!n&&u),children:[e===`ticks`?(0,W.jsx)(`span`,{...i(Q.tick,!n&&Q.tickH2,c&&Q.tickActive)}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{...i(Q.rowText),children:t.text}),r>0?(0,W.jsx)(`span`,{...i(Q.count),children:r}):null]}),d]},t.key)},p=!o&&r.some(e=>v.has(e.blockId));return(0,W.jsxs)(H.Fragment,{children:[t.partStart?(0,W.jsx)(`div`,{"aria-hidden":e===`ticks`||void 0,...i(Q.part,t.index===0&&Q.partFirst,u),children:e===`ticks`?null:t.partStart.text}):null,d(n,!1,o?0:r.length,v.has(n.blockId)||p,r.length>0),r.length>0?(0,W.jsx)(`div`,{inert:!o,...i(Q.fold,o&&Q.foldOpen),children:(0,W.jsx)(`div`,{...i(Q.foldRows,o&&Q.foldRowsOpen),children:r.map(e=>d(e,!0,0,v.has(e.blockId)))})}):null]},n.key)});return(0,W.jsxs)(`nav`,{"aria-label":r(`document.toc`),"data-expanded":s?`true`:`false`,"data-variant":n,onFocus:T,onPointerEnter:T,onPointerLeave:E,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||E()},...i(Q.toc,k&&Q.rail),children:[(0,W.jsx)(`div`,{"data-toc-list":``,ref:p,...i(Q.list),children:A(k?`ticks`:`column`)}),k&&s?(0,W.jsx)(`div`,{"data-toc-card":``,ref:e=>{e&&p.current&&(e.scrollTop=p.current.scrollTop)},...i(Q.card),children:A(`card`)}):null]})}var Tn=`.rich-table-scrollable-wrapper, .ryugi-mermaid-preview`;function En(e,t){let n=e.getBoundingClientRect().right;return[...e.querySelectorAll(Tn)].map(e=>e.getBoundingClientRect()).filter(e=>e.right>n+1).map(e=>({top:e.top-t,bottom:e.bottom-t}))}var Dn=(e,t)=>e.length===t.length&&e.every((e,n)=>e.top===t[n].top&&e.bottom===t[n].bottom);function On(e,t){let[n,r]=(0,H.useState)([]);return(0,H.useEffect)(()=>{let n=e?.getRootElement();if(!e||!t||!n)return;let i=()=>{let e=t.getBoundingClientRect().top-t.scrollTop,i=En(n,e);r(e=>Dn(e,i)?e:i)};i();let a=0,o=()=>{cancelAnimationFrame(a),a=requestAnimationFrame(i)},s=e.registerUpdateListener(o),c=new ResizeObserver(o);return c.observe(t),c.observe(n),()=>{cancelAnimationFrame(a),s(),c.disconnect()}},[e,t]),n}var kn=56,An=40;function jn(e,t,n){return n>=e.top&&n<=Math.max(e.bottom,e.top+An)&&t<=e.right+kn}function Mn(e){return Math.max(e.getBoundingClientRect().right,...[...e.querySelectorAll(Tn)].map(e=>e.getBoundingClientRect().right))}function Nn(e,t){let n=e.getRootElement(),r=t instanceof Element?t:null;for(;r&&r.parentElement!==n;)r=r.parentElement;return n&&r instanceof HTMLElement?r:null}function Pn(e,t){let n=Nn(e,t);return n?Fn(e,n):null}function Fn(e,t){return e.read(()=>{for(let n of N().getChildren())if(e.getElementByKey(n.getKey())===t)return A(n,F)||null;return null})}function In(e,t,n){let[r,i]=(0,H.useState)(null);return(0,H.useEffect)(()=>{if(!e||!t||!n){i(null);return}let r=0,a=null,o=e=>{e?.element!==a?.element&&(a=e,i(e))},s=()=>{cancelAnimationFrame(r),o(null)},c=t=>{if(cancelAnimationFrame(r),t.pointerType!==`mouse`&&t.pointerType!==`pen`||t.buttons!==0)return o(null);let{target:n,clientX:i,clientY:s}=t;r=requestAnimationFrame(()=>{let t=Nn(e,n);if(t){if(t===a?.element)return;let n=Fn(e,t);return o(n?{id:n,element:t}:null)}if(a){let{top:e,bottom:t}=a.element.getBoundingClientRect();if(jn({top:e,bottom:t,right:Mn(a.element)},i,s))return}o(null)})};return document.addEventListener(`pointermove`,c),document.addEventListener(`scroll`,s,!0),document.documentElement.addEventListener(`pointerleave`,s),()=>{cancelAnimationFrame(r),document.removeEventListener(`pointermove`,c),document.removeEventListener(`scroll`,s,!0),document.documentElement.removeEventListener(`pointerleave`,s)}},[e,t,n]),(0,H.useMemo)(()=>{if(!r||!t||!n||!r.element.isConnected)return null;let e=r.element.getBoundingClientRect(),i=t.getBoundingClientRect(),a=document.createRange();return a.selectNodeContents(r.element),{kind:`block`,blockId:r.id,quote:``,elements:[r.element],range:a,left:e.left-i.left,right:Mn(r.element)-i.left,top:e.top-i.top,bottom:e.bottom-i.top}},[r,t,n])}var Ln=80,Rn=240,zn=e=>{let t=/matrix\(([^)]+)\)/.exec(getComputedStyle(e).transform);return t?Number(t[1].split(`,`)[4]):0};function Bn(e,t){let n=t.offsetLeft,r=null,i=()=>{let i=n-t.offsetLeft;if(n=t.offsetLeft,!i||B()||!r&&Math.abs(i)<Ln)return;let a=i+(r?zn(t):0),o={duration:Rn,easing:et};if(r)r.cancel();else for(let n of e.children)n!==t&&$e(n,[{opacity:0},{opacity:1}],o);let s=t.animate([{transform:`translateX(${a}px)`},{transform:`none`}],o);r=s,s.finished.then(()=>{r===s&&(r=null)},()=>void 0)},a=new ResizeObserver(i);return a.observe(e),{settle:i,stop:()=>a.disconnect()}}var Vn=8,Hn=e=>P(e.anchor.blockId,e.anchor.quote,e.anchor.blockIds,e.anchor.textRanges,e.anchor.diagram);function Un({editor:e,threads:t,actions:n,agent:r,diagram:i,draft:a,onMain:o,overlay:s,history:c,shareBase:l,children:u}){let[d,f]=(0,H.useState)(null),[p,m]=(0,H.useState)(null);ut((0,H.useCallback)(()=>{let e=dt(t);e&&(m(e.id),document.querySelector(`[data-thread-slot="${CSS.escape(e.id)}"]`)?.scrollIntoView({block:`center`,behavior:`smooth`}))},[t]));let[h,g]=(0,H.useState)(null),[_,v]=(0,H.useState)(null),y=(0,H.useCallback)(e=>{v(e),o?.(e)},[o]),b=(0,H.useRef)(null);(0,H.useEffect)(()=>{if(!_||!h)return;let e=Bn(_,h);return b.current=e,()=>{b.current=null,e.stop()}},[_,h]);let x=Ze(`(max-width: 1100px)`),S=!Ze(`(max-width: 1480px)`),C=x?`hidden`:S?`column`:`rail`,[w,T]=(0,H.useState)(0),E=It(e,t,d,w),D=(0,H.useMemo)(()=>i&&e&&!c?{threads:t,activeId:p,draft:i.draft,pick:i.pick,readOnly:i.readOnly,blockAction:i.blockAction,viewer:{actions:n,agent:r,create:i.create,drafts:i.drafts},activate:m,marked:()=>T(e=>e+1),blockIdOf:t=>Pn(e,t)}:null,[i,e,c,t,p,n,r]),O=On(e,x||c?null:d),k=!x&&!c,A=(0,H.useRef)(null);A.current=a?a.key:null;let j=(0,H.useRef)(new Set(t.map(e=>e.id)));(0,H.useEffect)(()=>{let e=t.filter(e=>!j.current.has(e.id));j.current=new Set(t.map(e=>e.id));let n=e.find(e=>Hn(e)===A.current);n&&(A.current=null,m(n.id))},[t]);let ee=d&&_?d.getBoundingClientRect().top-_.getBoundingClientRect().top:0,M=a&&k?{anchorTop:a.top-ee,from:a.from,leaving:a.leaving,node:(0,W.jsx)(H.Fragment,{children:a.render({kind:`rail`})},a.key)}:null;return Lt(E,t,p),(0,H.useLayoutEffect)(()=>b.current?.settle(),[C]),(0,W.jsxs)(`main`,{ref:y,...{0:{className:`x1n2onr6 xrvj5dj xc94fvo xl56j7k xwaa2ar x13zrc24 x1ffnkcp x4l9tsp`},2:{className:`x1n2onr6 xrvj5dj xl56j7k xwaa2ar x13zrc24 x1ffnkcp x4l9tsp xoiau2f`},1:{className:`x1n2onr6 xc94fvo xl56j7k xwaa2ar x13zrc24 x1ffnkcp x78zum5 xdt5ytf x1qjc9v5 x17qtykl`},3:{className:`x1n2onr6 xl56j7k xwaa2ar x13zrc24 x1ffnkcp xoiau2f x78zum5 xdt5ytf x1qjc9v5 x17qtykl`}}[(C===`rail`)<<1|!!x],children:[(0,W.jsx)(`div`,{className:`history-space-toc`,inert:!!c?.immersive,children:(0,W.jsx)(wn,{editor:e,threads:t,variant:C})}),e?(0,W.jsx)(an,{editor:e,shareBase:l}):null,(0,W.jsxs)(`article`,{ref:g,className:`x1n2onr6 x1vjfegm xh8yej3 xrgej4m xeuugli`,style:x?{marginInline:`auto`}:c?void 0:{"--ryugi-table-bleed":`368px`},onClick:e=>m(zt(E,e.clientX,e.clientY)),children:[(0,W.jsx)(vt,{}),(0,W.jsx)(fe,{value:D,children:(0,W.jsx)(sn,{history:c,children:u})}),c?null:(0,W.jsx)(qt,{activeId:p,anchors:E,container:h,threads:t})]}),(0,W.jsx)(`div`,{className:`x1n2onr6`,className:`history-space-comments ${{className:`x1n2onr6`}.className??``}`,inert:!!c?.immersive,children:(0,W.jsx)(cn,{history:c?.immersive?null:c,children:(0,W.jsx)(Kt,{actions:n,activeId:p,agent:r,anchors:E,blocked:O,draft:M,narrow:x,railRef:f,threads:t,onActivate:m})})}),h&&s&&!c?s(h):null,h&&a&&!k&&!c?(0,W.jsx)(H.Fragment,{children:a.render({kind:`popover`,left:h.offsetLeft,top:a.bottom+Vn,width:h.offsetWidth})},a.key):null]})}function Wn({placement:e,excerpt:t,initial:n,restored:i,leaving:a,onChange:o,onSubmit:s,onCancel:c,ref:l}){let u=Xe(),d=e.kind===`popover`?e:null;return(0,W.jsx)(`div`,{"data-draft-panel":e.kind,ref:l,...{0:{className:`xowlrko xllfotl xatqbsq x1u6ievf`},2:{className:`xowlrko xllfotl xatqbsq x1u6ievf x10l6tqk x1u8a7rm`},1:{className:`x1u6ievf xxp0q0x x12l1aco xn0cd8s x47corl`},3:{className:`x1u6ievf x10l6tqk x1u8a7rm xxp0q0x x12l1aco xn0cd8s x47corl`}}[!!d<<1|!!a],style:d?{left:d.left,top:d.top,width:d.width}:void 0,children:(0,W.jsx)(ae,{active:!0,children:(0,W.jsx)(He,{autoFocus:!0,delivery:u?.delivery,excerpt:t,initial:n,placeholder:r(`composer.placeholder`),restored:i?{}:void 0,onCancel:c,onChange:o,onSubmit:s})})})}function Gn(e){let t=(0,H.useMemo)(ze,[]),[n,r]=(0,H.useState)(null),[i,a]=(0,H.useState)(!1),o=(0,H.useRef)(``),s=(0,H.useRef)(0),c=(0,H.useRef)(null),l=(0,H.useRef)(null);Rt(i?null:n?.target.range??null,i?void 0:n?.target.elements);let u=(0,H.useCallback)(n=>{window.clearTimeout(s.current);let i=t.take(P(n.blockId,n.quote,n.blockIds,n.textRanges,n.diagram));o.current=i,a(!1),r({target:n,initial:i}),window.getSelection()?.removeAllRanges(),e()},[t,e]),d=(0,H.useCallback)(e=>{n&&(t.save(P(n.target.blockId,n.target.quote,n.target.blockIds,n.target.textRanges,n.target.diagram),e?o.current:``),a(!0),s.current=window.setTimeout(()=>{r(null),a(!1)},120))},[n,t]);return(0,H.useEffect)(()=>{if(!n||i)return;let e=e=>{let t=e.target;c.current?.contains(t)||l.current?.contains(t)||d(!0)};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[n,i,d]),(0,H.useEffect)(()=>()=>window.clearTimeout(s.current),[]),{drafts:t,draft:n,leaving:i,restored:!!n?.initial,open:u,close:d,current:()=>o.current,onText:e=>{o.current=e},panelRef:c,toolbarRef:l}}function Kn(e,t=[]){if(e.diagram)return{kind:`anchor`,icon:ne,label:se(e)};if(e.quote)return{kind:`quote`,text:e.quote};let n=t.length===1?ve(t):null;return n?{kind:`quote`,text:n}:{kind:`anchor`,icon:ht,label:se(e,t)}}var qn=e=>e.elements?.map(_e),Jn=46;function Yn(e,t){return Math.min(e+8,window.innerWidth-(t.offsetParent?.getBoundingClientRect().left??0)-40)}function Xn({article:e,editor:t,enabled:n,onComment:r}){let i=In(t,e.closest(`main`),n);return i?(0,W.jsx)(ie,{left:Yn(i.right,e),top:i.top,onComment:()=>r(i)}):null}function Zn({blockId:e,element:t,node:n,host:r}){let i=r.closest(`main`);if(!i)return null;let a=n.getBoundingClientRect(),o=i.getBoundingClientRect(),s=document.createRange();return s.setStart(r,0),{blockId:e,quote:t.label,diagram:t.target,range:s,left:a.left-o.left,right:a.right-o.left,top:a.top-o.top,bottom:a.bottom-o.top}}function Qn(e){return e.kind===`block`?Ot(Dt(e)):{x:e.right,y:e.bottom}}function $n({editor:e,threads:t,actions:n,agent:r,canComment:i,canCommentDiagram:a=i,selection:o,clearSelection:s,resolveSelection:c,onCreate:l,onMain:u,onToolbar:d,history:f,shareBase:p,children:m}){let h=Gn(s),{draft:g,open:_}=h,[v,y]=(0,H.useState)(null),[b,x]=(0,H.useState)(0);(0,H.useLayoutEffect)(()=>{if(!v||f)return;let t=()=>{let t=v.querySelector(`.ryugi-editor-toolbar`);t?x(t.getBoundingClientRect().height):e?.isEditable()||x(0)};t();let n=new MutationObserver(t);return n.observe(v,{childList:!0}),()=>n.disconnect()},[v,f,e]),(0,H.useEffect)(()=>{if(!v||!d)return;let e=()=>d(v.querySelector(`.ryugi-editor-toolbar, .history-bar`)!==null);e();let t=new MutationObserver(e);return t.observe(v,{childList:!0}),()=>{t.disconnect(),d(!1)}},[v,d]);let S=h.leaving?null:g?.target??null,{drafts:C}=h,w=(0,H.useMemo)(()=>({draft:S,drafts:C,readOnly:!a,blockAction:i,pick:e=>{let t=Zn(e);t&&_(t)},create:(e,t)=>l({...e,range:document.createRange(),left:0,right:0,top:0,bottom:0},t)}),[i,a,S,C,_,l]),T=(0,H.useCallback)(()=>{let e=window.getSelection();navigator.clipboard?.writeText(e?.toString()??``),e?.removeAllRanges(),s()},[s]),E=(0,H.useMemo)(()=>({toolbarSlot:v,selectionActions:g?null:(0,W.jsx)(oe,{onCopy:T,onComment:i?()=>{let e=c();e&&_(e)}:void 0})}),[v,g,i,c,_,T]);return(0,W.jsxs)(me,{value:E,children:[(0,W.jsx)(`div`,{className:`ryugi-editor-toolbar-slot`,ref:y,children:b>0?(0,W.jsx)(`div`,{"aria-hidden":`true`,className:`history-toolbar-space`,style:{height:b}}):null}),(0,W.jsx)(Un,{actions:n,agent:r,diagram:w,editor:e,history:f,shareBase:p,threads:t,draft:g?{key:P(g.target.blockId,g.target.quote,g.target.blockIds,g.target.textRanges,g.target.diagram),top:g.target.top,bottom:g.target.bottom,from:Qn(g.target),leaving:h.leaving,render:e=>(0,W.jsx)(Wn,{excerpt:Kn(g.target,qn(g.target)),initial:h.current(),leaving:h.leaving,placement:e,ref:h.panelRef,restored:h.restored,onCancel:()=>h.close(!0),onChange:h.onText,onSubmit:(e,t)=>(t?l(g.target,e,t):l(g.target,e)).then(e=>(e&&h.close(!1),e))})}:null,overlay:t=>(0,W.jsxs)(W.Fragment,{children:[o&&!g&&o.kind===`block`&&i?(0,W.jsx)(ie,{left:Yn(o.right,t),ref:h.toolbarRef,top:o.top,onComment:()=>h.open(o)}):null,(0,W.jsx)(Xn,{article:t,editor:e,enabled:i&&!g&&!o,onComment:h.open}),o&&!g&&o.kind===`nested`?(0,W.jsx)(le,{left:o.left,ref:h.toolbarRef,top:Math.max(o.top-Jn,0),children:(0,W.jsx)(oe,{onComment:i?()=>h.open(o):void 0,onCopy:T})}):null]}),onMain:u,children:m})]})}function er(e){let t=j(e);return t._headless=!0,[`registerDecoratorListener`,`registerRootListener`,`registerMutationListener`,`getRootElement`,`setRootElement`,`getElementByKey`,`focus`,`blur`].forEach(e=>{t[e]=()=>{(function(e,...t){throw function(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);return n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(e,...t)})(439,e)}}),t}function tr({text:e}){let t=(0,H.useRef)(null),n=(0,H.useRef)(null);return(0,H.useEffect)(()=>{let r=t.current;if(!r)return;let i=r.parentNode;if(!i)return;let a=n.current;return!a||a.parentNode!==i?(a=document.createComment(e),i.insertBefore(a,r),n.current=a):a.data!==e&&(a.data=e),()=>{n.current?.parentNode&&n.current.parentNode.removeChild(n.current),n.current=null}},[e]),(0,W.jsx)(`template`,{suppressHydrationWarning:!0,"data-rich-comment-anchor":``,ref:t})}var $=e=>`${L[e]} ${Le[e]}`,nr={h1:$(`headingH1`),h2:$(`headingH2`),h3:$(`headingH3`),h4:$(`headingH4`),h5:$(`headingH5`),h6:$(`headingH6`)};function rr(e){return e.toLowerCase().trim().replaceAll(/[^\s\w\u3000-\u9FFF\uAC00-\uD7AF\uFF00-\uFFEF-]/g,``).replaceAll(/[\s_]+/g,`-`).replaceAll(/^-+|-+$/g,``)}function ir(e){return e.type===`comment`?``:e.text?e.text:e.children?e.children.map(ir).join(``):``}var ar=/^["'«‘“‹「『"']/,or=/["'»’”›」』"']$/;function sr(e,t,n,r,i,a){switch(e.type){case`root`:return(0,W.jsx)(W.Fragment,{children:n});case`paragraph`:{let r=e.format?{textAlign:e.format}:void 0;return(0,W.jsx)(`p`,{className:$(`paragraph`),style:r,children:n??(0,W.jsx)(`br`,{})},t)}case`heading`:{let o=e.tag,s=rr(i||ir(e)),c=a??s;if(a===void 0&&s){let e=r.get(s);e===void 0?r.set(s,1):(c=`${s}-${e}`,r.set(s,e+1))}return(0,W.jsxs)(o,{className:nr[o],id:c||void 0,children:[c&&(0,W.jsx)(`a`,{className:$(`headingAnchor`),href:`#${c}`,tabIndex:0,children:(0,W.jsx)(p,{"aria-hidden":!0,size:14,strokeWidth:2})}),n]},t)}case`rich-quote`:case`quote`:{let r=(i||ir(e)).trim(),a=ar.test(r),o=or.test(r),s=e.attribution;return(0,W.jsxs)(`blockquote`,{className:$(`quote`),"data-no-close-quote":o?``:void 0,"data-no-open-quote":a?``:void 0,children:[n,s&&(0,W.jsxs)(`footer`,{className:$(`quoteAttribution`),children:[`— `,s]})]},t)}case`list`:{let r=e.listType===`number`?`ol`:`ul`,i=e.listType===`number`?$(`listOl`):e.listType===`check`?`${$(`checklist`)} ${$(`listUl`)}`:$(`listUl`);return(0,W.jsx)(r,{className:i,start:e.start===1?void 0:e.start,children:n},t)}case`listitem`:{let r=e.checked!==void 0,i=e.children?.some(e=>e.type===`list`),a=typeof e.value==`number`&&e.value>1?e.value:void 0,o;return o=i?$(`listNestedItem`):r?e.checked?`${$(`listItem`)} ${$(`listItemChecked`)}`:`${$(`listItem`)} ${$(`listItemUnchecked`)}`:$(`listItem`),(0,W.jsx)(`li`,{className:o,value:a,children:n},t)}case`link`:return(0,W.jsxs)(`a`,{className:$(`link`),href:e.url,rel:e.rel||`noopener`,target:e.target||`_blank`,children:[(0,W.jsx)(Ce,{href:e.url}),n]},t);case`autolink`:return(0,W.jsxs)(`a`,{className:$(`link`),href:e.url,rel:`noopener`,target:`_blank`,children:[(0,W.jsx)(Ce,{href:e.url}),n]},t);case`horizontalrule`:return(0,W.jsx)(`hr`,{className:$(`hr`)},t);case`table`:return(0,W.jsx)(`div`,{className:$(`tableScrollableWrapper`),children:(0,W.jsx)(`table`,{className:$(`table`),children:n})},t);case`tablerow`:return(0,W.jsx)(`tr`,{children:n},t);case`tablecell`:{let r=e.headerState?`th`:`td`,i=e.headerState?$(`tableCellHeader`):$(`tableCell`);return(0,W.jsx)(r,{className:i,colSpan:e.colSpan>1?e.colSpan:void 0,children:n},t)}case`details`:{let r=e.summary||``;return(0,W.jsxs)(`details`,{className:`${R.details} ${I.details}`,open:e.open||void 0,children:[(0,W.jsxs)(`summary`,{className:`${R.summary} ${I.summary}`,children:[(0,W.jsx)(`span`,{"aria-hidden":`true`,className:`${R.chevron} ${I.chevron}`,children:(0,W.jsx)(`svg`,{fill:`none`,height:`20`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,viewBox:`0 0 20 20`,width:`20`,children:(0,W.jsx)(`path`,{d:`M8 6L12 10L8 14`})})}),(0,W.jsx)(`span`,{className:`${R.summaryText} ${I.summaryText}`,children:r})]}),(0,W.jsx)(`div`,{className:`${R.content} ${I.content}`,children:n})]},t)}case`spoiler`:return(0,W.jsx)(`span`,{className:$(`spoiler`),role:`button`,tabIndex:0,children:n},t);case`tag`:return(0,W.jsx)(`span`,{className:$(`tag`),style:{backgroundColor:Pe(e.text)},children:e.text},t);case`comment`:return(0,W.jsx)(tr,{text:e.text??``},t);case`ruby`:return(0,H.createElement)(Fe,{key:t,rendererKey:`Ruby`,defaultRenderer:ue,props:{reading:e.reading??``,children:n}});case`code`:return(0,W.jsx)(`pre`,{className:`rich-code-block`,children:(0,W.jsx)(`code`,{children:n})},t);case`code-highlight`:return(0,W.jsx)(`span`,{children:e.text},t);case`linebreak`:return(0,W.jsx)(`br`,{},t);case`tab`:return(0,W.jsx)(`span`,{children:` `},t);default:return null}}var cr=e=>`${L[e]} ${Le[e]}`,lr=[[1,`textBold`],[2,`textItalic`],[4,`textStrikethrough`],[8,`textUnderline`],[16,`textCode`],[32,`textSubscript`],[64,`textSuperscript`],[128,`textHighlight`]];function ur(e){let t={};for(let n of e.split(`;`)){let e=n.indexOf(`:`);if(e===-1)continue;let r=n.slice(0,e).trim(),i=n.slice(e+1).trim();if(!r||!i)continue;let a=r.replaceAll(/-([a-z])/g,(e,t)=>t.toUpperCase());t[a]=i}return t}function dr(e,t){let n=e.text,r=e.format||0;for(let[e,i]of lr)r&e&&(n=(0,W.jsx)(`span`,{className:cr(i),children:n},`${t}-${e}`));return e.style&&(n=(0,W.jsx)(`span`,{style:ur(e.style),children:n},t)),n}function fr(e,t=!1){let n=[],r=t?e.findIndex(e=>e.type===`paragraph`):-1,i=e=>e.type===`image`&&typeof e.layout==`string`&&e.layout.startsWith(`float-`);for(let t=0;t<e.length;t++){let a=[t];if(t===r&&t+1<e.length&&a.push(++t),i(e[t]))for(;++t<e.length;){a.push(t);let n=e[t];if(!i(n)&&![`paragraph`,`list`,`quote`,`rich-quote`,`comment`].includes(n.type))break}n.push(a)}let a=[];for(let t of n)a.length&&t.every(t=>e[t].type===`comment`)||a.at(-1)?.every(t=>e[t].type===`comment`)?a.at(-1).push(...t):a.push(t);return a}function pr(e){let t={},n=new Set,r={},i=1;function a(e){if(e.type===`footnote`&&e.identifier){let t=e.identifier;n.has(t)||(n.add(t),r[t]=i++)}if(e.type===`footnote-section`&&e.definitions&&Object.assign(t,e.definitions),e.children)for(let t of e.children)a(t);if(e.root&&a(e.root),e.content&&typeof e.content==`object`&&e.content.root&&a(e.content),e.cells&&Array.isArray(e.cells))for(let t of e.cells)t&&t.root&&a(t)}a(e);for(let e of n)e in t||(t[e]=``);return{definitions:t,displayNumberMap:r}}var mr=e=>`${L.alert} ${Le.alert} rich-alert-${e}`;function hr(e,t,n){switch(e.type){case`alert-quote`:return(0,H.createElement)(`div`,{key:t,className:mr(e.alertType)},n);case`banner`:return(0,H.createElement)(`div`,{key:t,className:`rich-banner rich-banner-${e.bannerType}`},n);case`grid-container`:return(0,H.createElement)(`div`,{key:t,className:`${Oe.container} ${Me.container}`},n);default:return(0,H.isValidElement)(n)?(0,H.cloneElement)(n,{key:t}):n}}function gr(e,t,n){return(0,H.isValidElement)(e)&&typeof e.type==`string`?(0,H.cloneElement)(e,{"data-block-id":t}):(0,W.jsx)(`div`,{className:`rich-block-anchor`,"data-block-id":t,children:e},`${n}-block-anchor`)}function _r(e,t,n,r){return t?(r.blockAnchor??gr)(e,t,n):e}function vr(e,t,n,r,i,a,o){let s=o.recycleKeys?i:e.getKey?e.getKey():i,c=o.headingIds?.get(e.getKey?.()),{builtinNodeOverrides:l}=o;if(typeof e.decorate==`function`){let r=null;try{r=e.decorate(t,n)}catch{}if(r!=null){let t=e.exportJSON?e.exportJSON():{},n=l?.[t.type];return _r(n?n(t,s,[r],()=>hr(t,s,r)):hr(t,s,r),a,s,o)}}let u=e.exportJSON?e.exportJSON():{};if(u.type===`text`){let e=l?.text;return e?e(u,s,null,()=>dr(u,s)):dr(u,s)}let d=typeof e.getChildren==`function`?e.getChildren():[];Array.isArray(u.children)&&u.children.length===0&&d.length>0&&(u.children=d.map(e=>({type:typeof e.getType==`function`?e.getType():e.__type})));let f=null;d.length>0&&(f=d.map((e,i)=>vr(e,t,n,r,`${s}-${i}`,void 0,o)));let p=e.getTextContent?e.getTextContent():void 0,m=l?.[u.type];return _r(m?m(u,s,f,()=>sr(u,s,f,r,p,c)):sr(u,s,f,r,p,c),a,s,o)}function yr(e,t,n,r){let i=er({nodes:t,theme:z,editable:!1,onError:e=>{console.error(`[RichRenderer]`,e)}}),a={namespace:`ssr`,theme:z},o=Ne(e),s=i.parseEditorState(o);i.setEditorState(s);let c=pr(o),l=o.root?.children,u=new Map,d=new Map,f=new Map,p=s.read(()=>{let e=new Map,t=(n,r,i)=>{if(f.set(n.getKey(),i),n.getType()===`heading`){let t=rr(n.getTextContent()),i=e.get(t)??0,a=t?`${t}${i?`-${i}`:``}`:``;e.set(t,i+1),u.set(n.getKey(),a),a&&d.set(a,r)}ee(n)&&n.getChildren().forEach((e,n)=>t(e,r,`${i}.${n}`))},n=N().getChildren();return n.forEach((e,n)=>t(e,n,`${n}:0`)),n}),m=new Set,h=p.map((e,t)=>{let n=l?.[t]??{type:e.getType(),version:1},r=n.$?.blockId??`renderer-${t}`;for(;m.has(r);)r=`${r}:${t}`;return m.add(r),{id:r,data:n,index:t,pool:`${n.type}:${n.type===`dynamic`?n.url:n.tag??``}`}}),g=fr(h.map(e=>e.data),r),_=new Map,v=g.map((e,t)=>{let n=e.map(e=>(_.set(e,t),h[e])),r=n[0];return{blocks:n,id:r.id,data:n.length===1?r.data:{type:`flow-group`,version:1,children:n.map(e=>e.data)},pool:n.length===1?r.pool:`flow-group`}});for(let[e,t]of d)d.set(e,_.get(t));let y=(e,t)=>s.read(()=>{let r=v[e];return r?(0,W.jsx)(H.Fragment,{children:r.blocks.map((e,r)=>vr(p[e.index],i,a,new Map,t===void 0?`ssr-${e.index}`:`recycler-${t}-${r}`,l?.[e.index]?.$?.blockId,{...n,headingIds:u,recycleKeys:t!==void 0}))},t===void 0?r.id:`recycler-${t}`):null}),b;return{document:{editor:i,rows:v,headingRows:d,render:y,renderAll:()=>b??=(0,W.jsx)(W.Fragment,{children:v.map((e,t)=>y(t))}),nodePath:e=>e?f.get(e)??e:`0`},footnoteData:c,renderNestedContent:e=>{let r=er({nodes:t,theme:z,editable:!1,onError:e=>{console.error(`[RichRenderer:nested]`,e)}}),i={namespace:`ssr-nested`,theme:z},a=Ne(e),o=r.parseEditorState(a);r.setEditorState(o);let s=null,c=a.root?.children;return o.read(()=>{let e=N(),t=new Map,a=e.getChildren().map((e,a)=>vr(e,r,i,t,`nested-${a}`,c?.[a]?.$?.blockId,n));s=(0,W.jsx)(W.Fragment,{children:a})}),s}}}function br({document:e}){return e.renderAll()}function xr({value:e,variant:t=`article`,theme:n,className:r,style:i,as:a=`div`,nested:o=!1,rendererConfig:s,extraNodes:c,builtinNodeOverrides:l,blockAnchor:u,surface:d,virtualization:f}){let p=Re(t),m=Se(),{document:h,footnoteData:g,renderNestedContent:_}=(0,H.useMemo)(()=>yr(e,c?[...je,...c]:je,{blockAnchor:u,builtinNodeOverrides:l},t===`note`),[u,l,c,e,t]),{scrollContainer:v,overscan:y,estimateBlockHeight:b,preserveCapacity:x}=typeof f==`object`?f:{},S=!!f,C=f===!1,T=(0,H.useMemo)(()=>C?br:S?We({scrollContainer:v,overscan:y,estimateBlockHeight:b,preserveCapacity:x}):d??br,[d,S,C,v,y,b,x]),E=[`rich-content`,p,r].filter(Boolean).join(` `),D=typeof a==`string`?{suppressHydrationWarning:!0,className:E,"data-rich-nested":o?`true`:void 0,"data-theme":n}:{},O=n??`light`;return(0,W.jsx)(w,{className:p,theme:O,children:(0,W.jsx)(De,{colorScheme:O,children:(0,W.jsx)(be,{config:s,mode:`renderer`,variant:t,children:(0,W.jsx)(Ee,{definitions:g.definitions,displayNumberMap:g.displayNumberMap,children:(0,W.jsx)(xe,{value:m??_,children:(0,W.jsx)(a,{...D,style:i,children:(0,W.jsx)(T,{document:h})})})})})})})}var Sr=/^claude-(opus|sonnet|haiku|fable)-(\d+)-(\d+)(?:\[[^\]]*\])?$/;function Cr(e){let t=Sr.exec(e);if(!t)return e;let[,n,r,i]=t;return`${n[0].toUpperCase()}${n.slice(1)} ${r}.${i}`}var wr=16,Tr={content:{"--lobe-popover-viewport-inline-padding":`4px`}},Er=4,Dr=(e,t)=>e.kind===`human`&&e.name===t?r(`common.you`):e.name;function Or({contributor:e,stacked:t=!1}){let[n,r]=(0,H.useState)(!1),i=e.kind===`agent`?Je(e.name):void 0,a=i?Ye[i]:void 0;return(0,W.jsx)(`span`,{"data-byline-face":``,...{0:{className:`xrvj5dj x1ku5rj1 x2lah0s x1kky2od xlup9mm x16rqkct xb3r6kr x7em3ua x15dg6x3 x1bo0w0s xvwhms9 x1s688f`},1:{className:`xrvj5dj x1ku5rj1 x2lah0s x1kky2od xlup9mm x16rqkct xb3r6kr x7em3ua x15dg6x3 x1bo0w0s xvwhms9 x1s688f x165d6jo`}}[!!t|0],children:a?(0,W.jsx)(a.Avatar,{shape:`circle`,size:wr}):e.avatar&&!n?(0,W.jsx)(`img`,{alt:``,src:e.avatar,onError:()=>r(!0),className:`x1kky2od xlup9mm xl1xv1r`}):[...e.name][0]?.toUpperCase()})}function kr({contributors:e,me:t,now:n}){return(0,W.jsx)(`div`,{className:`x78zum5 xdt5ytf x1u2d2a2 xxc7z9f`,children:e.map(e=>(0,W.jsxs)(`div`,{"data-contributor":``,className:`xrvj5dj x1g3yg12 x6s0dn4 x167g77z x1t0vds8 xdqyycr x1ct8sxb x178xt8z x1g31smg x13fuv20 xxu5053`,children:[(0,W.jsx)(Or,{contributor:e}),(0,W.jsx)(`span`,{className:`xo2rkog xb3r6kr xlyipyv xuxw1ft`,children:[Dr(e,t),e.models.map(Cr).join(` / `)].filter(Boolean).join(` · `)}),(0,W.jsxs)(`span`,{className:`xddlp02 x1qt5hsa xss6m8b xuxw1ft`,children:[r(`document.byline.edits`,{count:e.edits}),` ·`,` `,Qe(e.lastAt*1e3,n)]})]},e.kind+e.name))})}function Ar({byline:e,me:t,now:n}){let{contributors:i,last:a}=e;if(!i.length)return null;let o=i.length===1?Dr(i[0],t):r(`document.byline.authors`,{count:i.length});return(0,W.jsx)(Be,{content:(0,W.jsx)(kr,{contributors:i,me:t,now:n}),placement:`bottomLeft`,styles:Tr,trigger:`hover`,children:(0,W.jsxs)(`button`,{"data-byline":``,type:`button`,className:`x3nfvp2 x6s0dn4 x17d4w8g x193iq5w xxk0z11 x14oi46j x165d6jo xc342km x1kogg8i xjbqb8w x9jwiqo xddlp02 xln7xf2 x1ct8sxb xuxw1ft xt0e3qv`,children:[(0,W.jsx)(`span`,{className:`x3nfvp2 x2lah0s`,children:i.slice(0,Er).map((e,t)=>(0,W.jsx)(Or,{contributor:e,stacked:t>0},e.kind+e.name))}),(0,W.jsx)(`span`,{className:`x1bo0w0s xk50ysn`,children:o}),a?(0,W.jsxs)(`span`,{children:[`·`,` `,r(`document.byline.edited`,{name:Dr(a,t),time:Qe(a.at*1e3,n)})]}):null]})})}var jr=32,Mr=6e4;function Nr({editor:e,byline:t,me:n}){let[r,i]=(0,H.useState)(null),[a,o]=(0,H.useState)(Date.now);(0,H.useEffect)(()=>{o(Date.now());let e=setInterval(()=>o(Date.now()),Mr);return()=>clearInterval(e)},[t]);let s=t.contributors.length>0;return(0,H.useLayoutEffect)(()=>{let t=null,n=()=>{t=e.getRootElement();let n=t?.offsetParent;if(!t||!(n instanceof HTMLElement)||!s){t&&delete t.dataset.byline,i(null);return}let r=t.firstElementChild,a=r instanceof HTMLElement&&r.tagName===`H1`?r:null;t.dataset.byline=a?`title`:`top`;let o=n.getBoundingClientRect(),c=(a??t).getBoundingClientRect(),l=a?c.bottom+4:c.top-jr;i(e=>{let t={host:n,left:c.left-o.left,top:l-o.top};return e?.host===t.host&&e.left===t.left&&e.top===t.top?e:t})};n();let r=new ResizeObserver(n),a=e.getRootElement();a&&r.observe(a);let o=e.registerUpdateListener(()=>requestAnimationFrame(n));return window.addEventListener(`resize`,n),()=>{r.disconnect(),o(),window.removeEventListener(`resize`,n),t&&delete t.dataset.byline}},[e,s]),r?(0,U.createPortal)((0,W.jsx)(`div`,{style:{position:`absolute`,zIndex:1,left:r.left,top:r.top,whiteSpace:`nowrap`},onMouseMove:e=>e.stopPropagation(),onPointerMove:e=>e.stopPropagation(),children:(0,W.jsx)(Ar,{byline:t,me:n,now:a})}),r.host):null}function Pr({error:e,onDismiss:t}){return e?(0,U.createPortal)((0,W.jsxs)(`div`,{role:`alert`,className:`xixxii4 xy58vm5 xvf9o5y xvueqy4 xeq5yr9 x27kpxv x11uqc5h x78zum5 x6s0dn4 x1v2ro7d x10dr8xq x1hr3lfm xur7f20 xmkeg23 x1y0btm7 xgcsv5v x1rozbrz xo2rkog xqfszdh x4z9k3i x1pzk2i8`,children:[(0,W.jsx)(`span`,{children:r(`documentExport.failed`)}),(0,W.jsx)(`button`,{"aria-label":r(`common.close`),type:`button`,onClick:t,className:`xrvj5dj x1ku5rj1 xjbqb8w x1bo0w0s xc342km xgd8bvy x1fgtraw x1717udv x1ypdohk x2lah0s`,children:(0,W.jsx)(S,{size:16})})]}),document.body):null}var Fr={[we]:re,[ke]:Ie,[Te]:pe},Ir={claude:`Claude Code`,codex:`Codex`},Lr=e=>String(e).padStart(2,`0`);function Rr(e){let t=new Date(e);return`${t.getMonth()+1}/${t.getDate()} ${Lr(t.getHours())}:${Lr(t.getMinutes())}`}function zr({prompt:e,empty:t,theme:n}){let i=(0,H.useRef)(null),[a,o]=(0,H.useState)(!1),[s,c]=(0,H.useState)(!1);return(0,H.useLayoutEffect)(()=>{let e=i.current;e&&!a&&c(e.scrollHeight>e.clientHeight+1)},[a,e]),(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`aside`,{"aria-label":r(`document.promptLabel`),"data-ryugi-no-comment":``,"data-task-prompt":``,className:`x8o32fp x1onr9mi xyumdvf x1t7ytsu x1awn4rw x1hx0egp`,children:[(0,W.jsxs)(`p`,{className:`x78zum5 x6s0dn4 x17d4w8g x1ghz6dp xddlp02 x1qt5hsa xd4r4e8`,children:[(0,W.jsx)(pt,{"aria-hidden":`true`,size:12}),r(`document.promptMeta`,{time:Rr(e.at),agent:Ir[e.harness]??e.harness})]}),(0,W.jsx)(`div`,{"data-task-prompt-body":``,ref:i,...{0:{className:`x1gslohp x1bo0w0s xif65rj x11m8ghp xb3r6kr`},1:{className:`x1gslohp x1bo0w0s xif65rj x11m8ghp xb3r6kr x1n19c2o`}}[!a|0],children:(0,W.jsx)(xr,{rendererConfig:Fr,theme:n,value:e.state,variant:`comment`})}),(s||a)&&(0,W.jsx)(`button`,{"aria-expanded":a,type:`button`,onClick:()=>o(e=>!e),className:`x1gslohp x1717udv xc342km xjbqb8w xddlp02 x12rs2w1 xjb2p0i xfifm61 x1bvjpef xrys4gj x1ypdohk`,children:r(a?`document.promptCollapse`:`document.promptExpand`)})]}),t&&(0,W.jsx)(`p`,{className:`x103tiuj xddlp02 x2ouz8m`,children:r(`document.promptEmpty`)})]})}var Br=[`wheel`,`touchmove`,`keydown`,`pointerdown`];function Vr(e){return e.getEditorState().read(()=>N().getChildren().map(e=>({id:A(e,F),key:e.getKey()}))).flatMap(({id:t,key:n})=>{let r=t?e.getElementByKey(n):null;return r?[{id:t,element:r}]:[]})}function Hr(e,t){if(t.kind!==`document`)return!1;let n=Vr(e).find(({id:e})=>e===t.blockId);if(!n)return!1;let r=n.element.getBoundingClientRect().top-t.top;return r!==0&&window.scrollBy({top:r,behavior:`instant`}),!0}function Ur(e){(0,H.useEffect)(()=>{if(!e)return;let t=g({read(){let t=null;for(let{id:n,element:r}of Vr(e)){let{top:e,bottom:i}=r.getBoundingClientRect();if(!(i<=0)){if(e>=0&&e<window.innerHeight)return{kind:`document`,blockId:n,top:e};if(t??={kind:`document`,blockId:n,top:e},e>=0)break}}return t},apply:t=>Hr(e,t)}),n=()=>{let t=v();t&&Hr(e,t)};n();let r=e.registerUpdateListener(n);for(let e of Br)window.addEventListener(e,h,{passive:!0});return()=>{t(),r();for(let e of Br)window.removeEventListener(e,h)}},[e])}var Wr=e=>`${V(e)}:${rt(e)}`;async function Gr(e,t){let n=new Map;for(let t of it(e))ot(t)&&n.set(Wr(t),t);let r=await Promise.all([...n].map(async([e,n])=>[e,await t(n).catch(()=>void 0)])),i={};for(let[e,t]of r)t&&(i[e]=t);return i}function Kr(e){let t=structuredClone({...e,comments:e.comments??Ke()}),n=t=>{if(!t||t.startsWith(`#`))return t;try{return new URL(t,e.contentBase||e.sourceUrl).href}catch{return t}},r=e=>{if(!e||typeof e!=`object`)return;let t=e;if(typeof t.type==`string`){for(let e of[`src`,`poster`,`favicon`,`image`])typeof t[e]==`string`&&(t[e]=n(t[e]));if((t.type===`link`||t.type===`autolink`||t.type===`link-card`)&&typeof t.url==`string`&&(t.url=n(t.url)),t.type===`excalidraw`&&typeof t.snapshot==`string`){let[e=``,...r]=t.snapshot.split(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./printDocument-GFcncwq5.js","./rolldown-runtime-XKyaHtl9.js","./react-DlmbjZJV.js","./route-i3jkzu-i.js","./bem-vbke-3KC.js","./jsx-runtime-LKYXHABd.js","./types-BCsOeYI6.js","./index2.css","./shims-s-YVfIlz.js","./editor-yZwTWy-w.js","./url-Buh8E05T.js","./useLayerZIndex-C75Wfz8T.js","./MotionConfigContext-BqjwrGj9.js","./is-html-element-DvgHo_1h.js","./WhiteboardEditor-DrHOvXez-DTa-K6Xu.js","./Popover-DxR9Dpf_.js","./chevron-right-DBC0wrKu.js","./stringifyLocale-VcrwrbQl.js","./code-CTMZ5SpG.js","./SelectScrollUpArrow-bXyfVgGf.js","./zoom-out-Cz3087-F.js","./text-align-start-CO9CK_EW.js","./ruler-DmQbsUQf.js","./maximize-2-Deo2WY_L.js","./mouse-pointer-2-naHRayvu.js","./undo-2-BH3P-I_n.js","./plus-C3ivaMGn.js","./MenuSubmenuTrigger-CPcD7vNW.js","./index3.css","./Tooltip-CZKrDYnF.js","./pen-tool-B7HWrrcR.js","./underline-AY5gu1iN.js","./route-messages-CxWq6xYk.js","./ref-BrUHq8E2.js","./table-2-F7QzFSYG.js","./video-tvDNJEhe.js","./message-square-BQbestX7.js","./presentation-qzIErT_u.js","./ThreadView-D_g4kidg.js","./comments-CASb0ByE.js","./stable-CK-LXZNI.js","./icons-CDVhjQMS.js","./index5.css","./search-EBZOryv1.js","./shield-check-TdIPOf4j.js","./sliders-horizontal-DZKoxRty.js","./upload-D0s2oA1h.js","./agentLook-60JQrptF.js","./DotGrid-DKKr_PyM.js","./rounds-DC6Dulo5.js","./useMedia-CFebB4XU.js","./BottomSheet-BFtfrr58.js","./motion-Cy65kd7X.js","./preference-oNdcNeml.js","./useSandboxFrame-CJmSnwgG.js","./index4.css","./dist-C4TwVfMo.js","./katex-DuZJ-tFh.js","./ArtifactModal-CH9BY3RJ.js","./SplitFrame-CLquf6QT.js","./clapperboard-iHoLVEUr.js","./embed-src-CmyqZplg.js","./ArtifactModal-BU_PR8k8.css"])))=>i.map(i=>d[i]);
2
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{A as t,E as n,S as r,j as i}from"./route-i3jkzu-i.js";/* empty css */import{t as a}from"./react-DlmbjZJV.js";import{C as o,D as s,E as c,Ht as l,_ as u,a as d,b as f,br as p,c as m,d as h,f as g,jr as _,p as v,x as y,xr as b}from"./url-Buh8E05T.js";import{t as x}from"./jsx-runtime-LKYXHABd.js";import{En as S}from"./useLayerZIndex-C75Wfz8T.js";import{Dt as C}from"./MotionConfigContext-BqjwrGj9.js";import{Gt as w,Jr as T,_i as E,bn as D,gn as O,ir as k,ni as A,pa as j,sa as ee,wn as M,xr as N,zr as te}from"./WhiteboardEditor-DrHOvXez-DTa-K6Xu.js";import{An as ne,B as P,D as re,F as ie,H as ae,I as oe,J as se,K as ce,L as le,M as ue,Pt as F,Q as de,R as fe,S as pe,St as me,U as he,V as ge,X as _e,Y as ve,Z as ye,_t as be,at as I,bt as L,ct as xe,dt as Se,et as Ce,ft as we,gt as Te,it as R,lt as z,mt as Ee,nt as De,ot as Oe,pt as ke,q as Ae,rt as je,st as Me,tt as Ne,ut as Pe,vt as Fe,w as Ie,xt as Le,yt as Re,z as ze}from"./editor-yZwTWy-w.js";import{t as Be}from"./Popover-DxR9Dpf_.js";import{i as Ve}from"./route-messages-CxWq6xYk.js";import{o as He}from"./ThreadView-D_g4kidg.js";import{r as Ue}from"./agentLook-60JQrptF.js";import{n as We}from"./plugin-_bGVeqI0-Bsz7oxOL.js";import{i as Ge,r as Ke,t as qe}from"./comments-CASb0ByE.js";import{n as Je,t as Ye}from"./icons-CDVhjQMS.js";import{r as Xe}from"./useDrafts-WX84YtG1.js";import{n as Ze}from"./useMedia-CFebB4XU.js";import{n as Qe}from"./artifact-list-BuB3wom1.js";import{a as B,i as $e,t as et}from"./motion-Cy65kd7X.js";import{t as tt}from"./embed-src-CmyqZplg.js";import{n as nt}from"./preference-oNdcNeml.js";import{a as V,n as rt,o as it,r as at,t as ot}from"./ref-BrUHq8E2.js";import{i as st,n as ct,r as lt}from"./jump-history-Dyva9tQM.js";import{r as ut,t as dt}from"./view-drafts-DXKEb89H.js";var ft={name:`corner-down-right`,size:24,node:[[`path`,{d:`m15 10 5 5-5 5`,key:`qqa56n`}],[`path`,{d:`M4 4v7a4 4 0 0 0 4 4h12`,key:`z08zvw`}]]};ft.node;var pt=C(ft),mt={name:`pilcrow`,size:24,node:[[`path`,{d:`M13 4v16`,key:`8vvj80`}],[`path`,{d:`M17 4v16`,key:`7dpous`}],[`path`,{d:`M19 4H9.5a4.5 4.5 0 0 0 0 9H13`,key:`sh4n9v`}]]};mt.node;var ht=C(mt),H=e(a(),1);function gt(e,t,n){let r=(0,H.useMemo)(()=>f(),[]),[i,a]=(0,H.useState)(!1),s=(0,H.useRef)(t);s.current=t;let c=(0,H.useRef)(n);c.current=n,(0,H.useEffect)(()=>{if(r)return y((e,t)=>{e.kind===`chrome`&&a(e.hosted),e.kind===`history`&&s.current(e.action),t===window.parent&&e.kind===`document-export`&&e.format===`pdf`&&c.current?.()})},[r]);let{activity:l,comments:u,history:d,historyOpen:p,documentExport:m}=e;return(0,H.useEffect)(()=>{r&&o({kind:`header`,activity:l,comments:u,history:d,historyOpen:p,documentExport:m})},[r,l,u,d,p,m]),r&&i}var U=e(t(),1),W=x(),_t=`svg[role="img"] text[font-family*="Excalifont"] { font-family: ${O}; }`;function vt(){let e=nt();return(0,W.jsx)(W.Fragment,{children:e&&(0,U.createPortal)((0,W.jsx)(`style`,{"data-diagram-font-style":!0,children:_t}),document.head)})}var G=(e,t,n,r)=>e.find(e=>t<e.bottom+r&&t+n+r>e.top);function yt(e,t,n,r){for(let i=G(e,t,n,r);i;)t=i.bottom+r,i=G(e,t,n,r);return t}function bt(e,t,n,r){for(let i=G(e,t,n,r);i;)t=i.top-r-n,i=G(e,t,n,r);return t}function xt(e,t,n,r,i){let a=e.top-i-t.height;if(a<0||G(r,a,t.height,i))return null;let o=t.anchorTop-a,s=[],c=a;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t.top+t.height+i<=c)break;let a=c-i-t.height;if(t.fixed||a<0||G(r,a,t.height,i))return null;o+=t.top-a,s.push([e,a]),c=a}return{cost:o,moves:s,top:a}}function St(e,t,n,r=[]){let i=[...e].sort((e,t)=>e.anchorTop-t.anchorTop),a=n?i.findIndex(e=>e.id===n):-1,o=Math.max(a,0),s=[],c=-1/0;for(let e=o;e<i.length;e++){let n=i[e],o=Math.max(n.anchorTop,c),l=G(r,o,n.height,t);if(l){let e=yt(r,o,n.height,t),i=xt(l,n,s,r,t);if(i&&i.cost<=e-n.anchorTop){for(let[e,t]of i.moves)s[e].top=t;o=i.top}else o=e}s.push({id:n.id,top:o,height:n.height,fixed:e===a}),c=o+n.height+t}let l={};for(let e of s)l[e.id]=e.top;if(a>0){let e=l[i[a].id];for(let n=a-1;n>=0;n--){let a=i[n],o=Math.min(a.anchorTop,e-t-a.height),s=G(r,o,a.height,t);if(s){let n=bt(r,o,a.height,t),i=s.bottom+t;o=i+a.height+t<=e&&!G(r,i,a.height,t)&&Math.abs(i-a.anchorTop)<Math.abs(a.anchorTop-n)?i:n}l[a.id]=o,e=o}}return l}function Ct(e,t,n){let r=Math.max(e.x,t.x-n),i=(r+t.x)/2,a=r>e.x?` H${r}`:``;return`M${e.x} ${e.y}${a} C${i} ${e.y} ${i} ${t.y} ${t.x} ${t.y}`}var wt=8,Tt=3,Et=18;function Dt(e){let t=e.right+wt;return{left:t,right:t+Tt,top:e.top,bottom:e.bottom}}function Ot(e){return{x:e.right,y:e.top+Math.min(Et,(e.bottom-e.top)/2)}}var kt=10;function At(e,t,n,r,i){let a=Math.max(t.left,Math.min(e.left,t.right-n)),o=e.bottom+kt;return i.top+o+r<=i.height-i.reserved-8?{left:a,top:o,placement:`below`}:{left:a,top:e.top-r-kt,placement:`above`}}var K=e=>e.kind===`element`?[]:e.blocks??(e.kind===`block`?[{id:e.threadId,element:e.element}]:[]),jt=e=>e?.kind===`block`?K(e).map(e=>_e(e.element)):void 0,q=e=>e.kind===`text`?e.ranges??[e.range]:[],Mt=4;function Nt(e){return[...q(e).flatMap(e=>[...e.getClientRects()]),...K(e).map(e=>Dt(e.element.getBoundingClientRect()))].sort((e,t)=>e.top-t.top||e.left-t.left)}function Pt(e){if(e.kind===`element`)return e.node.isConnected?ce(e.node):null;let t=Nt(e).at(-1);return t?e.kind===`text`?{x:t.right,y:t.bottom}:Ot(t):null}function Ft(e,t,n){let r=document.createRange(),i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),a=0,o=!1;for(let e=i.nextNode();e;e=i.nextNode()){let i=a+e.length;if(!o&&t<=i&&(r.setStart(e,t-a),o=!0),o&&n<=i)return r.setEnd(e,n-a),r;a=i}return r.selectNodeContents(e),r}function It(e,t,n,r=0){let[i,a]=(0,H.useState)([]);return(0,H.useEffect)(()=>{if(!e||!n)return;let r=()=>{let r=e.getEditorState().read(()=>{let e=new Map;for(let t of N().getChildren()){let n=A(t,F);n&&e.set(n,t.getKey())}return e}),i=n.getBoundingClientRect().top-n.scrollTop,o=[];for(let n of t){let t=qe(n.anchor).flatMap(t=>{let n=r.get(t),i=n?e.getElementByKey(n):null;return i?[{id:t,element:i}]:[]}),a=t[0]?.element;if(!a)continue;if(n.anchor.diagram){let e=Ae(a,n.id);if(e){let t=e.getBoundingClientRect(),r=n.anchor.diagram.kind===`edge`?ce(e).y:t.top;o.push({threadId:n.id,top:r-i,kind:`element`,node:e})}else o.push({threadId:n.id,top:a.getBoundingClientRect().top-i,kind:`block`,element:a,blocks:t});continue}if(n.anchor.textRanges){let e=new Map(n.anchor.textRanges.map(e=>[e.blockId,e])),r=[],s=[],c;for(let n of t){let t=e.get(n.id),a=t?ye(n.element.textContent??``,t.quote,t.start):`block`;if(a===`block`)s.push(n),c??=n.element.getBoundingClientRect().top-i;else{let e=Ft(n.element,a.start,a.end);r.push(e);let t=e.getClientRects()[0]??n.element.getBoundingClientRect();c??=t.top-i}}r.length?o.push({threadId:n.id,top:c,kind:`text`,range:r[0],ranges:r,blocks:s}):o.push({threadId:n.id,top:c,kind:`block`,element:a,blocks:s});continue}let s=n.anchor.blockIds?`block`:ye(a.textContent??``,n.anchor.quote);if(s===`block`){o.push({threadId:n.id,top:a.getBoundingClientRect().top-i,kind:`block`,element:a,blocks:t});continue}let c=Ft(a,s.start,s.end),l=c.getClientRects()[0]??a.getBoundingClientRect();o.push({threadId:n.id,top:l.top-i,kind:`text`,range:c})}a(o)};r();let i=0,o=()=>{cancelAnimationFrame(i),i=requestAnimationFrame(r)},s=e.registerUpdateListener(o),c=new ResizeObserver(o);c.observe(n);let l=e.getRootElement();return l&&c.observe(l),()=>{cancelAnimationFrame(i),s(),c.disconnect()}},[e,t,n,r]),i}function Lt(e,t,n){(0,H.useEffect)(()=>{if(typeof CSS>`u`||!(`highlights`in CSS))return;let r=de(t,n),i=new Set(t.filter(Ge).map(e=>e.id)),a=e.filter(e=>r.has(e.threadId)&&e.threadId!==n&&!i.has(e.threadId)).flatMap(q),o=e.filter(e=>i.has(e.threadId)&&e.threadId!==n).flatMap(q),s=e.filter(e=>e.threadId===n).flatMap(q);return CSS.highlights.set(`ryugi-comment`,new Highlight(...a)),CSS.highlights.set(`ryugi-comment-active`,new Highlight(...s)),CSS.highlights.set(`ryugi-comment-queued`,new Highlight(...o)),()=>{CSS.highlights.delete(`ryugi-comment`),CSS.highlights.delete(`ryugi-comment-queued`),CSS.highlights.delete(`ryugi-comment-active`)}},[e,t,n])}function Rt(e,t){(0,H.useEffect)(()=>{if(t?.length){for(let e of t)e.setAttribute(`data-comment-draft`,``);return()=>{for(let e of t)e.removeAttribute(`data-comment-draft`)}}if(e&&typeof CSS<`u`&&`highlights`in CSS)return CSS.highlights.set(`ryugi-comment-draft`,new Highlight(e)),()=>{CSS.highlights.delete(`ryugi-comment-draft`)}},[e,t])}function zt(e,t,n){for(let r of e){if(r.kind===`element`)continue;let e=r.kind===`block`||K(r).length?Mt:0;for(let i of Nt(r))if(t>=i.left-e&&t<=i.right+e&&n>=i.top&&n<=i.bottom)return r.threadId}return null}var Bt=e=>Math.max(0,Math.min(window.scrollY+e.getBoundingClientRect().top-100,document.documentElement.scrollHeight-window.innerHeight));function Vt(e){window.scrollTo({top:Bt(e),behavior:`instant`})}function J(e,t){let n=Bt(e);if(B())return window.scrollTo({top:n,behavior:`instant`}),t?.(),()=>{};let r=()=>{window.removeEventListener(`wheel`,i),window.removeEventListener(`touchmove`,i)},i=()=>{a.stop(),r()},a=l({keyframes:[window.scrollY+1,n],type:`spring`,stiffness:1e3,damping:250,onUpdate:e=>window.scrollTo({top:e,behavior:`instant`}),onComplete:()=>{r(),t?.()}});return window.addEventListener(`wheel`,i,{passive:!0}),window.addEventListener(`touchmove`,i,{passive:!0}),i}var Y=12,Ht=40,Ut=18,X=`\0draft`,Wt=160;function Gt({id:e,onHeight:t,children:n}){let r=(0,H.useRef)(null);return(0,H.useLayoutEffect)(()=>{let n=r.current;if(!n)return;let i=new ResizeObserver(()=>t(e,n.offsetHeight));return i.observe(n),t(e,n.offsetHeight),()=>i.disconnect()},[e,t]),(0,W.jsx)(`div`,{ref:r,children:n})}function Kt({narrow:e,threads:t,anchors:n,blocked:i,activeId:a,actions:o,draft:s,onActivate:c,railRef:l,agent:u}){let[d,f]=(0,H.useState)({}),[p,m]=(0,H.useState)(0),h=(0,H.useCallback)((e,t)=>m(t),[]),[g,_]=(0,H.useState)([]),v=(0,H.useRef)(null),y=(0,H.useRef)(new Map).current,b=(0,H.useRef)((e,t)=>f(n=>n[e]===t?n:{...n,[e]:t})).current,x=(0,H.useCallback)(e=>{v.current=e,l(e)},[l]),S=new Map(n.map(e=>[e.threadId,e.top])),C=new Map(n.map(e=>[e.threadId,e])),w=t.filter(e=>S.has(e.id)),T=t.filter(e=>!S.has(e.id)&&!e.messages.every(e=>e.deleted)),E=s&&!s.leaving?s:null,D=w.map(e=>({id:e.id,anchorTop:S.get(e.id),height:d[e.id]??120}));E&&D.push({id:X,anchorTop:E.anchorTop,height:d[X]??Wt});let O=St(D,Y,E?X:a??void 0,i),k=(0,H.useRef)(0);E&&(k.current=O[X]??E.anchorTop);let A=Math.max(0,...D.map(e=>(O[e.id]??0)+e.height)),j=yt(i??[],A+Y,p,Y),ee=JSON.stringify(O);(0,H.useLayoutEffect)(()=>{let r=v.current;if(e||!r)return _([]);let i=r.getBoundingClientRect(),o=de(t,a),s=[];for(let e of n){let t=O[e.threadId],n=Pt(e);if(t===void 0||!n||!o.has(e.threadId))continue;let r={x:n.x-i.left,y:n.y-i.top};s.push({id:e.threadId,d:Ct(r,{x:0,y:t+Ut},Ht)})}let c=r.closest(`main`);if(E&&c){let e=c.getBoundingClientRect(),t={x:E.from.x+e.left-i.left,y:E.from.y+e.top-i.top};s.push({id:X,d:Ct(t,{x:0,y:k.current+Ut},Ht)})}_(s)},[e,n,t,a,ee,E]),(0,H.useEffect)(()=>{let t=a?y.get(a):void 0;if(e||!t)return;let n=!1,r=()=>{},i=t.getAnimations({subtree:!0}).map(e=>e.finished.catch(()=>void 0));return Promise.all(i).then(()=>{!n&&he(t.getBoundingClientRect(),window.innerHeight)&&(r=J(t))}),()=>{n=!0,r()}},[a,e,y]);let M=e=>(0,W.jsx)(ge,{actions:o,active:e.id===a,agent:u,label:se(e.anchor,jt(C.get(e.id))),thread:e,onActivate:()=>c(e.id)});if(e)return(0,W.jsxs)(`div`,{"aria-label":r(`document.commentsLabel`),ref:x,role:`region`,className:`x78zum5 xdt5ytf x1v2ro7d xh8yej3 x7ep2pv xvueqy4`,children:[[...w].sort((e,t)=>S.get(e.id)-S.get(t.id)).map(e=>(0,W.jsx)(`div`,{children:M(e)},e.id)),T.length>0?(0,W.jsx)(`div`,{className:`xqui205 x1e56ztr xddlp02 xqfszdh x1j6dyjg`,children:r(`document.originalDeleted`)}):null,T.map(e=>(0,W.jsx)(`div`,{children:M(e)},e.id))]});let N=E?X:a;return(0,W.jsxs)(`aside`,{"aria-label":r(`document.commentsLabel`),ref:x,className:`x1n2onr6 xh8yej3 x2lah0s`,style:{minHeight:A},children:[(0,W.jsx)(`svg`,{className:`x10l6tqk x13vifvy xu96u03 x1i1rx1s xjm9jq1 x1rea2x4 x47corl`,children:g.map(e=>(0,W.jsx)(`path`,{d:e.d,fill:`none`,stroke:e.id===N?Ue.warningStrong:`currentColor`,strokeDasharray:e.id===N?void 0:`3 3`,strokeOpacity:e.id===N?1:.25},e.id))}),w.map(e=>(0,W.jsx)(`div`,{"data-active":e.id===a||void 0,"data-thread-slot":e.id,ref:t=>{t?y.set(e.id,t):y.delete(e.id)},className:`x10l6tqk xu96u03 xh8yej3 xhtitgo x14h5d43 xx6bhzk`,style:{top:O[e.id]},children:(0,W.jsx)(Gt,{id:e.id,onHeight:b,children:M(e)})},e.id)),s?(0,W.jsx)(`div`,{"data-draft-slot":``,...{0:{className:`x10l6tqk xu96u03 xh8yej3 xhtitgo x14h5d43 xx6bhzk`},1:{className:`x10l6tqk xu96u03 xh8yej3 x14h5d43 xx6bhzk xzkaem6`}}[!!s.leaving|0],style:{top:k.current},children:(0,W.jsx)(Gt,{id:X,onHeight:b,children:s.node})}):null,T.length>0?(0,W.jsx)(`div`,{style:{position:`absolute`,top:j,left:0,width:`100%`,zIndex:2},children:(0,W.jsxs)(Gt,{id:`orphaned`,onHeight:h,children:[(0,W.jsx)(`div`,{className:`xqui205 x1e56ztr xddlp02 xqfszdh x1j6dyjg`,children:r(`document.originalDeleted`)}),T.map(e=>(0,W.jsx)(`div`,{style:{marginBottom:Y},children:M(e)},e.id))]})}):null]})}function qt({container:e,anchors:t,threads:n,activeId:r}){let[i,a]=(0,H.useState)([]);return(0,H.useLayoutEffect)(()=>{if(!e)return a([]);let i=e.getBoundingClientRect(),o=de(n,r),s=[];for(let e of t)if(o.has(e.threadId))for(let t of K(e)){let n=Dt(t.element.getBoundingClientRect());s.push({id:e.threadId,key:`${e.threadId}:${t.id}`,left:n.left-i.left,top:n.top-i.top,width:n.right-n.left,height:n.bottom-n.top})}a(s)},[e,t,n,r]),i.map(e=>(0,W.jsx)(`div`,{"data-comment-block":e.id,...{0:{className:`x10l6tqk x1cum3z5 x47corl x1f2496h x15406qy xx6bhzk`},1:{className:`x10l6tqk x1cum3z5 x47corl x15406qy xx6bhzk x5hs8br`}}[e.id===r|0],style:{left:e.left,top:e.top,width:e.width,height:e.height}},e.key))}var Jt=/^#([\w-]{4,64})$/,Yt=/^#ryugi-host=/,Xt=e=>Jt.exec(e)?.[1]??null;function Z(e=window){if(e.parent===e||!e.parent)return e;try{return e.parent.location.href,e.parent}catch{return e}}var Zt=(e=Z())=>Xt(e.location.hash);function Qt(e,t=Z()){let{hash:n,pathname:r,search:i}=t.location;if(Yt.test(n))return;let a=e?`#${e}`:``;n!==a&&t.history.replaceState(t.history.state,``,`${r}${i}${a}`)}function $t(e,t){let n=new URL(e);return n.hash=t,n.toString()}var en=new Set([`h2`,`h3`]),tn=160;function nn(e){let t=document.createRange();t.selectNodeContents(e);let n=t.getClientRects?.(),r=n&&n.length>0?n.item(n.length-1):null,i=e.getBoundingClientRect();return r&&r.width>0?r:i}function rn(e,t){e.getEditorState().read(()=>{for(let n of t){let t=k(n),r=e.getElementByKey(n);if(!M(t)||!r)continue;let i=en.has(t.getTag())?A(t,F):``;i?r.id=i:r.removeAttribute(`id`)}})}function an({editor:e,shareBase:t}){let[n,i]=(0,H.useState)(null),[a,o]=(0,H.useState)(!1),s=(0,H.useRef)(void 0);if((0,H.useEffect)(()=>{if(e.hasNodes([D]))return e.registerMutationListener(D,t=>rn(e,[...t].filter(([,e])=>e!==`destroyed`).map(([e])=>e)))},[e]),(0,H.useEffect)(()=>{let t=()=>clearTimeout(s.current),n=()=>{t(),s.current=setTimeout(()=>i(null),tn)},r=r=>{let a=r.target;if(a?.closest?.(`[data-heading-link]`))return t();let s=e.getRootElement(),c=a?.closest?.(`h2[id], h3[id]`);if(!s||!c||!s.contains(c))return n();t();let l=nn(c);o(!1),i({id:c.id,left:l.right+window.scrollX+6,top:l.top+window.scrollY+(l.height-24)/2})};return document.addEventListener(`pointerover`,r),()=>{t(),document.removeEventListener(`pointerover`,r)}},[e]),!n)return null;let c=()=>{let e=$t(t||Z().location.href,n.id);navigator.clipboard?.writeText(e),Qt(n.id),o(!0)},l=r(a?`document.headingLinkCopied`:`document.copyHeadingLink`);return(0,U.createPortal)((0,W.jsx)(`button`,{"aria-label":l,"data-heading-link":``,style:{left:n.left,top:n.top},title:l,type:`button`,onClick:c,onPointerDown:e=>e.preventDefault(),...{0:{className:`x10l6tqk xoegz02 xrvj5dj x1ku5rj1 xvy4d1p xxk0z11 x1717udv xc342km x1kogg8i xjbqb8w xj0l527 xddlp02 x157umkc x1in2gmu x1ypdohk x1de99jn xaatb59 x1y3gkto x1uczgqu x60py1w`},1:{className:`x10l6tqk xoegz02 xrvj5dj x1ku5rj1 xvy4d1p xxk0z11 x1717udv xc342km x1kogg8i xjbqb8w xj0l527 x1ypdohk x1de99jn xaatb59 x1y3gkto x1uczgqu x60py1w x1cge3fn`}}[!!a|0],children:a?(0,W.jsx)(_,{"aria-hidden":`true`,size:14}):(0,W.jsx)(b,{"aria-hidden":`true`,size:14})}),document.body)}var on=620,sn=class extends H.Component{state={leaving:null,shown:null};static getDerivedStateFromProps(e,t){return e.history?.immersive?t.shown===e.history?null:{shown:e.history}:t.shown?{shown:null,leaving:t.shown}:null}host=null;paper=null;viewport=null;shell=null;entry=null;slide=null;exitTimer=null;getSnapshotBeforeUpdate(){return{rect:this.paper?.getBoundingClientRect()??null,x:window.scrollX,y:window.scrollY}}animate(e,t){if(!this.paper||!e||B()||typeof this.paper.animate!=`function`)return;this.slide?.cancel();let n=t??this.paper.getBoundingClientRect(),r=Math.max(56,e.top),i=parseFloat(getComputedStyle(this.paper).borderLeftWidth)||0,a=t?0:i,o=t?i:0;this.slide=this.paper.animate([{left:e.left-a+`px`,top:r-a+`px`,width:e.width+a*2+`px`,height:Math.min(e.height,window.innerHeight-r)+a+`px`},{left:n.left-o+`px`,top:n.top-o+`px`,width:n.width+o*2+`px`,height:n.height+o+`px`}],{duration:on,easing:et,fill:t?`forwards`:`none`}),this.slide.finished.catch(()=>{})}unlock=()=>{if(this.exitTimer&&clearTimeout(this.exitTimer),this.exitTimer=null,this.slide?.cancel(),this.slide=null,this.host&&(this.host.style.height=``),this.entry){let e=this.entry;document.documentElement.style.overflow=e.overflow,document.documentElement.style.scrollbarGutter=e.gutter,window.scrollTo(e.x,e.y)}this.entry=null};componentDidUpdate(e,t,n){let r=!!this.props.history?.immersive,i=!!e.history?.immersive;if(r&&!i)this.exitTimer&&clearTimeout(this.exitTimer),this.exitTimer=null,this.state.leaving&&this.setState({leaving:null}),this.entry||(this.entry={...n,focus:document.activeElement,overflow:document.documentElement.style.overflow,gutter:document.documentElement.style.scrollbarGutter,offset:Math.max(0,56-(n.rect?.top??56))},this.host&&(this.host.style.height=(n.rect?.height??0)+`px`)),n.rect&&this.shell?.style.setProperty(`--history-reading-width`,n.rect.width+`px`),document.documentElement.style.scrollbarGutter=`stable`,document.documentElement.style.overflow=`hidden`,this.viewport&&(this.viewport.scrollTop=this.entry.offset),this.animate(n.rect),this.shell?.querySelector(`[data-history-exit]`)?.focus({preventScroll:!0});else if(!r&&i&&this.entry){let e=this.entry;this.viewport&&(this.viewport.scrollTop=e.offset),window.scrollTo(e.x,e.y),e.focus?.focus({preventScroll:!0});let t=e.rect;t&&this.animate(n.rect,{left:t.left,top:Math.max(56,t.top),width:t.width,height:Math.min(t.height,window.innerHeight-Math.max(56,t.top))});let r=()=>{this.setState({leaving:null},()=>{this.unlock(),e.focus?.focus({preventScroll:!0})})};B()?r():this.exitTimer=setTimeout(r,on)}else!r&&!this.state.leaving&&(!e.history&&this.props.history&&(this.entry={...n,focus:null,overflow:document.documentElement.style.overflow,gutter:document.documentElement.style.scrollbarGutter,offset:0}),e.history&&!this.props.history&&this.entry&&(window.scrollTo(this.entry.x,this.entry.y),this.entry=null))}componentWillUnmount(){this.unlock()}trap=e=>{if(!this.props.history?.immersive||e.key!==`Tab`)return;let t=[...this.shell?.querySelectorAll(`button:not(:disabled),a[href],summary,[tabindex="0"]`)??[]].filter(e=>!e.closest(`[hidden],[aria-hidden="true"],[inert]`)),n=t[0],r=t.at(-1);e.shiftKey&&document.activeElement===n?(e.preventDefault(),r?.focus()):!e.shiftKey&&document.activeElement===r&&(e.preventDefault(),n?.focus())};render(){let{history:e,children:t}=this.props,n=e?.immersive?e:this.state.leaving,i=!!n,a=!!e?.ready;return(0,W.jsx)(`div`,{className:`history-body`,ref:e=>{this.host=e},children:(0,W.jsxs)(`div`,{"aria-label":e?.immersive?r(`history.title`):void 0,"aria-modal":e?.immersive?!0:void 0,className:`history-space-shell`,"data-immersive":i?``:void 0,"data-open":e?.immersive?``:void 0,inert:!(!this.state.leaving||e),role:e?.immersive?`dialog`:void 0,ref:e=>{this.shell=e},onKeyDown:this.trap,children:[n?.space,(0,W.jsx)(`div`,{className:`history-space-paper`,ref:e=>{this.paper=e},children:(0,W.jsxs)(`div`,{className:`history-space-scroll`,tabIndex:i?0:void 0,ref:e=>{this.viewport=e},children:[(0,W.jsx)(`div`,{className:`history-body-comparison`,"data-ready":a,hidden:!a,children:e?.content}),(0,W.jsx)(`div`,{hidden:a,children:t})]})})]})})}};function cn({history:e,children:t}){let[n,r]=(0,H.useState)({current:e,panel:e?.panel??null});return n.current!==e&&r({current:e,panel:e?.panel??n.panel}),(0,H.useEffect)(()=>{if(e)return;let t=setTimeout(()=>{r(e=>e.current?e:{...e,panel:null})},B()?0:280);return()=>clearTimeout(t)},[e]),(0,W.jsx)(`div`,{className:`history-rail`,"data-moving":e||n.panel?``:void 0,"data-open":e?``:void 0,children:(0,W.jsxs)(`div`,{className:`history-rail-track`,children:[(0,W.jsx)(`div`,{"aria-hidden":e?!0:void 0,className:`history-rail-comments`,inert:!!e,children:t}),(0,W.jsx)(`div`,{"aria-hidden":!e||void 0,className:`history-rail-panel`,inert:!e,children:e?.panel??n.panel})]})})}var ln=(0,H.createContext)(!1),un=3e3;function dn(e,t){let n=e.getRootElement()?.closest(`.history-body`)?.querySelector(`.history-body-comparison[data-ready="true"]`);if(n)return[...n.querySelectorAll(`[data-history-block-id]`)].find(e=>e.dataset.historyBlockId===t)?.querySelector(`.history-current :is(h1, h2, h3, h4, h5, h6)`)??null;let r=e.getEditorState().read(()=>N().getChildren().find(e=>A(e,F)===t)?.getKey());return r?e.getElementByKey(r):null}function fn(e,t){let n=(0,H.useContext)(ln)?null:e,[r]=(0,H.useState)(Zt),i=(0,H.useRef)(r),a=(0,H.useRef)(r),o=(0,H.useRef)(void 0),s=(0,H.useRef)(null),c=(0,H.useRef)(null),l=(0,H.useCallback)(e=>{s.current=e,Qt(e)},[]),u=(0,H.useCallback)(e=>{let t=n&&dn(n,e);return t?(o.current?.(),o.current=J(t,()=>{i.current===e&&!a.current&&(i.current=null)}),!0):!1},[n]),d=(0,H.useCallback)(e=>{let t=n&&dn(n,e);return t?(o.current?.(),Vt(t),i.current===e&&!a.current&&(i.current=null),!0):!1},[n]),f=(0,H.useCallback)(e=>{let t={lock:i.current,pending:a.current};i.current=e,a.current=null,u(e)?l(e):(i.current=t.lock,a.current=t.pending)},[u,l]);return(0,H.useEffect)(()=>{if(!n)return;let e=()=>{if(n.getRootElement()?.closest(`.history-space-shell[data-immersive]`))return;let e=a.current;e&&(a.current=null,v()?i.current===e&&(i.current=null):d(e)?c.current={blockId:e,until:Date.now()+un}:a.current=e)};e();let t=()=>{i.current=null,a.current=null,c.current=null},r=new ResizeObserver(()=>{if(n.getRootElement()?.closest(`.history-space-shell[data-immersive]`))return;let e=c.current;e&&(Date.now()>e.until?c.current=null:d(e.blockId))}),l=n.registerRootListener(e=>{r.disconnect(),e&&r.observe(e)}),u=Z(),f=()=>{let t=Zt();t&&t!==s.current&&!lt(u.history.state)&&(i.current=t,a.current=t,e())},p=n.registerUpdateListener(e);return window.addEventListener(`wheel`,t,{passive:!0}),window.addEventListener(`touchmove`,t,{passive:!0}),window.addEventListener(`keydown`,t),u.addEventListener(`hashchange`,f),()=>{p(),l(),r.disconnect(),o.current?.(),window.removeEventListener(`wheel`,t),window.removeEventListener(`touchmove`,t),window.removeEventListener(`keydown`,t),u.removeEventListener(`hashchange`,f)}},[n,d]),(0,H.useEffect)(()=>{if(n){if(i.current){if(a.current||t!==i.current)return;i.current=null}else l(t)}},[t,n,l]),{scrollTo:f}}function pn({editor:e}){return fn(e,null),null}var mn={h2:0,h3:1};function hn(){let e=[],t=null,n=null;for(let r of N().getChildren()){let i=M(r)?r.getTag():void 0,a=A(r,F);if(i===`h1`){t={key:r.getKey(),blockId:a,text:r.getTextContent()},n=null;continue}let o=i===void 0?void 0:mn[i];o!==void 0&&(n={key:r.getKey(),blockId:a,text:r.getTextContent(),depth:o,part:t,blocks:[]},e.push(n)),a&&n?.blocks.push(a)}return e}function gn(e,t){let n=new Map;for(let t of e)for(let e of t.blocks)n.set(e,t.blockId);let r=new Set;for(let e of t)if(e.status===`open`)for(let t of qe(e.anchor)){let e=n.get(t);e&&r.add(e)}return r}function _n(e){let t=new Set(e.map(e=>e.part?.key??null)).size>1,n=[],r;for(let i of e){let e=n.at(-1),a=i.part!==r;i.depth===0||!e||a?n.push({head:i,children:[],index:n.length,partStart:t&&a?i.part:null}):e.children.push(i),r=i.part}return n}var Q={toc:{kVAEAm:`x7wzq59`,kY2c9j:`x1w0boku`,k87sOh:`xossvpg`,kSGwAc:`x1y8v6su`,keoZOQ:`x1tfhste`,k1xSpc:`x78zum5`,kXwgrk:`xdt5ytf`,kskxy:`x1r4ahda`,k7Eaqz:`xeuugli`,kMv6JI:`xqfszdh`,kGuDYH:`x1ct8sxb`,kMwMTN:`x1bo0w0s`,$$css:!0},rail:{kzqmXN:`x1td3qas`,$$css:!0},list:{kAzted:`x2lwn1j`,kORKVm:`x1odjw0f`,kacamN:`x1e4zzel`,k5wCbM:`x1rohswg`,k8WAf4:`xj8oexa`,$$css:!0},item:{kVAEAm:`x1n2onr6`,k1xSpc:`x78zum5`,kGNEyG:`x6s0dn4`,kOIVth:`x167g77z`,kzqmXN:`xh8yej3`,kZKoxP:`xlrawln`,kmVPX3:`x1717udv`,kMzoRj:`xc342km`,kaIpWk:`x1kogg8i`,kWkggS:`xjbqb8w`,kkrTdU:`x1ypdohk`,kMeerF:`x1de99jn`,k3XXqK:`xaatb59`,kInvED:`x1g40iwv`,kjBf7l:`x1uczgqu x60py1w`,$$css:!0},tick:{kmuXW:`x2lah0s`,kzqmXN:`xsmyaan`,kZKoxP:`x36qwtl`,keTefX:`xdwrcjd`,kaIpWk:`x1nj7uno`,kWkggS:`x174nbcu`,kmkexE:`x10iii20`,$$css:!0},tickH2:{kzqmXN:`xw4jnvo`,keTefX:`x1lziwak`,kWkggS:`xxwmxtg`,$$css:!0},tickActive:{kzqmXN:`xw4jnvo`,keTefX:`x1lziwak`,kWkggS:`x15az74h`,$$css:!0},tickDot:{keTefX:`x165d6jo`,$$css:!0},part:{kB7OPa:`x9f619`,kZKoxP:`x10w6t97`,kVQacm:`xb3r6kr`,kLKAdn:`xyinxu5`,kGuDYH:`x1j6dyjg`,k63SB2:`x1s688f`,kLWn49:`x1wfe3co`,kb6lSQ:`x16q24ku`,kMwMTN:`xddlp02`,kg5iWk:`xlyipyv`,khDVqt:`xuxw1ft`,kmkexE:`x1un5det`,$$css:!0},partFirst:{kZKoxP:`xxk0z11`,kLKAdn:`x1yrsyyn`,$$css:!0},row:{k1xSpc:`x78zum5`,kGNEyG:`x6s0dn4`,kOIVth:`x17d4w8g`,kzqmXN:`xh8yej3`,kZKoxP:`xlrawln`,kmVPX3:`x1717udv`,kMzoRj:`xc342km`,kaIpWk:`x12oqio5`,kWkggS:`xjbqb8w`,kMwMTN:`x1bo0w0s xytdrwj`,kVVagm:`xln7xf2`,k9WMMc:`x1yc453h`,kkrTdU:`x1ypdohk`,kmkexE:`x137m0jx x413zg9`,kMeerF:`x1de99jn`,k3XXqK:`xaatb59`,kInvED:`x1g40iwv`,kjBf7l:`x1uczgqu x60py1w`,$$css:!0},rowNested:{kZCmMZ:`x1onr9mi`,kGuDYH:`xfifm61`,kMwMTN:`xddlp02 xytdrwj`,$$css:!0},rowCurrent:{kZKoxP:`x1fgtraw`,kGuDYH:`x2ouz8m`,k63SB2:`x1s688f`,kMwMTN:`xo2rkog xytdrwj`,$$css:!0},rowActive:{k63SB2:`x1s688f`,kMwMTN:`x1cge3fn x157umkc`,$$css:!0},rowText:{kUk6DE:`x98rzlu`,k7Eaqz:`xeuugli`,kVQacm:`xb3r6kr`,kg5iWk:`xlyipyv`,khDVqt:`xuxw1ft`,$$css:!0},count:{kmuXW:`x2lah0s`,kGuDYH:`x1j6dyjg`,k63SB2:`xo1l8bm`,kMwMTN:`xc7n51q`,kcqcaj:`xss6m8b`,$$css:!0},fold:{k1xSpc:`xrvj5dj`,k9llMU:`xihq33y`,k33iCy:`xlshs6z`,kSiTet:`xg01cxk`,kmkexE:`x1u0be13 x9kvfbb`,$$css:!0},foldOpen:{k9llMU:`x1tu4anv`,k33iCy:`xnpuxes`,kSiTet:`x1hc1fzr`,kmkexE:`xjgrksx x9kvfbb`,$$css:!0},foldRows:{kAzted:`x2lwn1j`,kVQacm:`xb3r6kr`,k3aq6I:`x1bvilyr`,kmkexE:`x1pagzdl x9kvfbb`,$$css:!0},foldRowsOpen:{k3aq6I:`x1c071of`,kmkexE:`x94wcrn x9kvfbb`,$$css:!0},fadeNear:{kSiTet:`xiiclqw`,$$css:!0},fadeMid:{kSiTet:`xf9vgkq`,$$css:!0},fadeFar:{kSiTet:`x197sbye`,$$css:!0},dot:{kmuXW:`x2lah0s`,kzqmXN:`x1ftt334`,kZKoxP:`x1ycjhwn`,kaIpWk:`x16rqkct`,kWkggS:`xzkukvh`,$$css:!0},card:{kVAEAm:`x10l6tqk`,kY2c9j:`x1w0boku`,k87sOh:`xn0lweg`,kbCHJM:`x6f9vd5`,kzqmXN:`x1hfn5x7`,kskxy:`x1r4ahda`,kORKVm:`x1odjw0f`,kB7OPa:`x9f619`,k8WAf4:`x1vvogim`,kg3NbH:`xaope02`,kMzoRj:`xmkeg23`,ksu8eU:`x1y0btm7`,kVAM5u:`xgcsv5v`,kaIpWk:`x1q4ynmn`,kWkggS:`x12ilycc`,kGVxlE:`x1d5q07e`,$$css:!0}},vn=120,yn=200,bn=150,xn=new Set;function Sn(e,t){let[n,r]=(0,H.useState)({key:null,reading:!1});return(0,H.useEffect)(()=>{if(!e)return;let n=()=>{if(e.getRootElement()?.closest(`.history-space-shell[data-immersive]`))return;let n=t[0]?.key??null,i=!1;for(let r of t){let t=r.blockId?dn(e,r.blockId):e.getElementByKey(r.key);t&&t.getBoundingClientRect().top<vn&&(n=r.key,i=!0)}r(e=>e.key===n&&e.reading===i?e:{key:n,reading:i})};return n(),window.addEventListener(`scroll`,n,{passive:!0}),()=>window.removeEventListener(`scroll`,n)},[e,t]),n}function Cn(e,t,n){(0,H.useEffect)(()=>{let n=()=>{let n=e.current,r=t.current;if(!n||!r)return;let i=n.getBoundingClientRect(),a=r.getBoundingClientRect();(a.top<i.top||a.bottom>i.bottom)&&(n.scrollTop=Math.max(0,n.scrollTop+a.top-i.top-(n.clientHeight-a.height)/2))};return n(),window.addEventListener(`scroll`,n,{passive:!0}),window.addEventListener(`resize`,n),()=>{window.removeEventListener(`scroll`,n),window.removeEventListener(`resize`,n)}},n)}function wn({editor:e,threads:t=[],variant:n=`column`}){let[a,o]=(0,H.useState)([]),[s,c]=(0,H.useState)(!1),[l,u]=(0,H.useState)(xn),d=(0,H.useRef)(void 0),f=(0,H.useRef)(void 0),p=(0,H.useRef)(null),m=(0,H.useRef)(null);(0,H.useEffect)(()=>{if(!e)return;let t=()=>o(e.getEditorState().read(hn));return t(),e.registerUpdateListener(t)},[e]);let h=Sn(e,a),g=a.find(e=>e.key===h.key),{scrollTo:_}=fn(e,h.reading&&g?.blockId?g.blockId:null),v=(0,H.useMemo)(()=>gn(a,t),[a,t]),y=(0,H.useMemo)(()=>_n(a),[a]);Cn(p,m,[h.key,a]),(0,H.useEffect)(()=>()=>{clearTimeout(d.current),clearTimeout(f.current)},[]);let b=y.find(e=>e.head.key===h.key||e.children.some(e=>e.key===h.key)),x=b?.head.key??null,[S,C]=(0,H.useState)(x),w=e=>u(t=>t.has(e)?t:new Set(t).add(e));S!==x&&(C(x),s&&S&&w(S));let T=()=>{clearTimeout(d.current),c(!0)},E=()=>{clearTimeout(d.current),clearTimeout(f.current),d.current=setTimeout(()=>{c(!1),u(xn)},yn)},D=e=>{clearTimeout(f.current),f.current=setTimeout(()=>w(e),bn)},O=t=>{if(t.blockId)return _(t.blockId);let n=e?.getElementByKey(t.key);n&&J(n)};if(n===`hidden`)return null;if(a.length===0)return(0,W.jsx)(`nav`,{"data-variant":n,...i(Q.toc)});let k=n===`rail`,A=e=>y.map(t=>{let{head:n,children:r}=t,a=t===b,o=a||l.has(n.key),c=b?Math.abs(t.index-b.index):0,u=e!==`column`||s||c===0?null:c===1?Q.fadeNear:c<=3?Q.fadeMid:Q.fadeFar,d=(t,n,r,o,s=!1)=>{let c=t.key===h.key,l=e===`card`,d=o?(0,W.jsx)(`span`,{"data-commented":``,...i(Q.dot,e===`ticks`&&Q.tickDot)}):null;return(0,W.jsxs)(`button`,{"aria-current":c&&!l?`location`:void 0,"aria-label":t.text,ref:c&&!l?m:void 0,tabIndex:l?-1:void 0,type:`button`,onClick:()=>O(t),onFocus:s?()=>w(t.key):void 0,onPointerEnter:s?()=>D(t.key):void 0,onPointerLeave:s?()=>clearTimeout(f.current):void 0,...i(e===`ticks`?Q.item:Q.row,e!==`ticks`&&n&&Q.rowNested,!n&&a&&Q.rowCurrent,e!==`ticks`&&c&&Q.rowActive,!n&&u),children:[e===`ticks`?(0,W.jsx)(`span`,{...i(Q.tick,!n&&Q.tickH2,c&&Q.tickActive)}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{...i(Q.rowText),children:t.text}),r>0?(0,W.jsx)(`span`,{...i(Q.count),children:r}):null]}),d]},t.key)},p=!o&&r.some(e=>v.has(e.blockId));return(0,W.jsxs)(H.Fragment,{children:[t.partStart?(0,W.jsx)(`div`,{"aria-hidden":e===`ticks`||void 0,...i(Q.part,t.index===0&&Q.partFirst,u),children:e===`ticks`?null:t.partStart.text}):null,d(n,!1,o?0:r.length,v.has(n.blockId)||p,r.length>0),r.length>0?(0,W.jsx)(`div`,{inert:!o,...i(Q.fold,o&&Q.foldOpen),children:(0,W.jsx)(`div`,{...i(Q.foldRows,o&&Q.foldRowsOpen),children:r.map(e=>d(e,!0,0,v.has(e.blockId)))})}):null]},n.key)});return(0,W.jsxs)(`nav`,{"aria-label":r(`document.toc`),"data-expanded":s?`true`:`false`,"data-variant":n,onFocus:T,onPointerEnter:T,onPointerLeave:E,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||E()},...i(Q.toc,k&&Q.rail),children:[(0,W.jsx)(`div`,{"data-toc-list":``,ref:p,...i(Q.list),children:A(k?`ticks`:`column`)}),k&&s?(0,W.jsx)(`div`,{"data-toc-card":``,ref:e=>{e&&p.current&&(e.scrollTop=p.current.scrollTop)},...i(Q.card),children:A(`card`)}):null]})}var Tn=`.rich-table-scrollable-wrapper, .ryugi-mermaid-preview`;function En(e,t){let n=e.getBoundingClientRect().right;return[...e.querySelectorAll(Tn)].map(e=>e.getBoundingClientRect()).filter(e=>e.right>n+1).map(e=>({top:e.top-t,bottom:e.bottom-t}))}var Dn=(e,t)=>e.length===t.length&&e.every((e,n)=>e.top===t[n].top&&e.bottom===t[n].bottom);function On(e,t){let[n,r]=(0,H.useState)([]);return(0,H.useEffect)(()=>{let n=e?.getRootElement();if(!e||!t||!n)return;let i=()=>{let e=t.getBoundingClientRect().top-t.scrollTop,i=En(n,e);r(e=>Dn(e,i)?e:i)};i();let a=0,o=()=>{cancelAnimationFrame(a),a=requestAnimationFrame(i)},s=e.registerUpdateListener(o),c=new ResizeObserver(o);return c.observe(t),c.observe(n),()=>{cancelAnimationFrame(a),s(),c.disconnect()}},[e,t]),n}var kn=56,An=40;function jn(e,t,n){return n>=e.top&&n<=Math.max(e.bottom,e.top+An)&&t<=e.right+kn}function Mn(e){return Math.max(e.getBoundingClientRect().right,...[...e.querySelectorAll(Tn)].map(e=>e.getBoundingClientRect().right))}function Nn(e,t){let n=e.getRootElement(),r=t instanceof Element?t:null;for(;r&&r.parentElement!==n;)r=r.parentElement;return n&&r instanceof HTMLElement?r:null}function Pn(e,t){let n=Nn(e,t);return n?Fn(e,n):null}function Fn(e,t){return e.read(()=>{for(let n of N().getChildren())if(e.getElementByKey(n.getKey())===t)return A(n,F)||null;return null})}function In(e,t,n){let[r,i]=(0,H.useState)(null);return(0,H.useEffect)(()=>{if(!e||!t||!n){i(null);return}let r=0,a=null,o=e=>{e?.element!==a?.element&&(a=e,i(e))},s=()=>{cancelAnimationFrame(r),o(null)},c=t=>{if(cancelAnimationFrame(r),t.pointerType!==`mouse`&&t.pointerType!==`pen`||t.buttons!==0)return o(null);let{target:n,clientX:i,clientY:s}=t;r=requestAnimationFrame(()=>{let t=Nn(e,n);if(t){if(t===a?.element)return;let n=Fn(e,t);return o(n?{id:n,element:t}:null)}if(a){let{top:e,bottom:t}=a.element.getBoundingClientRect();if(jn({top:e,bottom:t,right:Mn(a.element)},i,s))return}o(null)})};return document.addEventListener(`pointermove`,c),document.addEventListener(`scroll`,s,!0),document.documentElement.addEventListener(`pointerleave`,s),()=>{cancelAnimationFrame(r),document.removeEventListener(`pointermove`,c),document.removeEventListener(`scroll`,s,!0),document.documentElement.removeEventListener(`pointerleave`,s)}},[e,t,n]),(0,H.useMemo)(()=>{if(!r||!t||!n||!r.element.isConnected)return null;let e=r.element.getBoundingClientRect(),i=t.getBoundingClientRect(),a=document.createRange();return a.selectNodeContents(r.element),{kind:`block`,blockId:r.id,quote:``,elements:[r.element],range:a,left:e.left-i.left,right:Mn(r.element)-i.left,top:e.top-i.top,bottom:e.bottom-i.top}},[r,t,n])}var Ln=80,Rn=240,zn=e=>{let t=/matrix\(([^)]+)\)/.exec(getComputedStyle(e).transform);return t?Number(t[1].split(`,`)[4]):0};function Bn(e,t){let n=t.offsetLeft,r=null,i=()=>{let i=n-t.offsetLeft;if(n=t.offsetLeft,!i||B()||!r&&Math.abs(i)<Ln)return;let a=i+(r?zn(t):0),o={duration:Rn,easing:et};if(r)r.cancel();else for(let n of e.children)n!==t&&$e(n,[{opacity:0},{opacity:1}],o);let s=t.animate([{transform:`translateX(${a}px)`},{transform:`none`}],o);r=s,s.finished.then(()=>{r===s&&(r=null)},()=>void 0)},a=new ResizeObserver(i);return a.observe(e),{settle:i,stop:()=>a.disconnect()}}var Vn=8,Hn=e=>P(e.anchor.blockId,e.anchor.quote,e.anchor.blockIds,e.anchor.textRanges,e.anchor.diagram);function Un({editor:e,threads:t,actions:n,agent:r,diagram:i,draft:a,onMain:o,overlay:s,history:c,shareBase:l,children:u}){let[d,f]=(0,H.useState)(null),[p,m]=(0,H.useState)(null);ut((0,H.useCallback)(()=>{let e=dt(t);e&&(m(e.id),document.querySelector(`[data-thread-slot="${CSS.escape(e.id)}"]`)?.scrollIntoView({block:`center`,behavior:`smooth`}))},[t]));let[h,g]=(0,H.useState)(null),[_,v]=(0,H.useState)(null),y=(0,H.useCallback)(e=>{v(e),o?.(e)},[o]),b=(0,H.useRef)(null);(0,H.useEffect)(()=>{if(!_||!h)return;let e=Bn(_,h);return b.current=e,()=>{b.current=null,e.stop()}},[_,h]);let x=Ze(`(max-width: 1100px)`),S=!Ze(`(max-width: 1480px)`),C=x?`hidden`:S?`column`:`rail`,[w,T]=(0,H.useState)(0),E=It(e,t,d,w),D=(0,H.useMemo)(()=>i&&e&&!c?{threads:t,activeId:p,draft:i.draft,pick:i.pick,readOnly:i.readOnly,blockAction:i.blockAction,viewer:{actions:n,agent:r,create:i.create,drafts:i.drafts},activate:m,marked:()=>T(e=>e+1),blockIdOf:t=>Pn(e,t)}:null,[i,e,c,t,p,n,r]),O=On(e,x||c?null:d),k=!x&&!c,A=(0,H.useRef)(null);A.current=a?a.key:null;let j=(0,H.useRef)(new Set(t.map(e=>e.id)));(0,H.useEffect)(()=>{let e=t.filter(e=>!j.current.has(e.id));j.current=new Set(t.map(e=>e.id));let n=e.find(e=>Hn(e)===A.current);n&&(A.current=null,m(n.id))},[t]);let ee=d&&_?d.getBoundingClientRect().top-_.getBoundingClientRect().top:0,M=a&&k?{anchorTop:a.top-ee,from:a.from,leaving:a.leaving,node:(0,W.jsx)(H.Fragment,{children:a.render({kind:`rail`})},a.key)}:null;return Lt(E,t,p),(0,H.useLayoutEffect)(()=>b.current?.settle(),[C]),(0,W.jsxs)(`main`,{ref:y,...{0:{className:`x1n2onr6 xrvj5dj xc94fvo xl56j7k xwaa2ar x13zrc24 x1ffnkcp x4l9tsp`},2:{className:`x1n2onr6 xrvj5dj xl56j7k xwaa2ar x13zrc24 x1ffnkcp x4l9tsp xoiau2f`},1:{className:`x1n2onr6 xc94fvo xl56j7k xwaa2ar x13zrc24 x1ffnkcp x78zum5 xdt5ytf x1qjc9v5 x17qtykl`},3:{className:`x1n2onr6 xl56j7k xwaa2ar x13zrc24 x1ffnkcp xoiau2f x78zum5 xdt5ytf x1qjc9v5 x17qtykl`}}[(C===`rail`)<<1|!!x],children:[(0,W.jsx)(`div`,{className:`history-space-toc`,inert:!!c?.immersive,children:(0,W.jsx)(wn,{editor:e,threads:t,variant:C})}),e?(0,W.jsx)(an,{editor:e,shareBase:l}):null,(0,W.jsxs)(`article`,{ref:g,className:`x1n2onr6 x1vjfegm xh8yej3 xrgej4m xeuugli`,style:x?{marginInline:`auto`}:c?void 0:{"--ryugi-table-bleed":`368px`},onClick:e=>m(zt(E,e.clientX,e.clientY)),children:[(0,W.jsx)(vt,{}),(0,W.jsx)(fe,{value:D,children:(0,W.jsx)(sn,{history:c,children:u})}),c?null:(0,W.jsx)(qt,{activeId:p,anchors:E,container:h,threads:t})]}),(0,W.jsx)(`div`,{className:`x1n2onr6`,className:`history-space-comments ${{className:`x1n2onr6`}.className??``}`,inert:!!c?.immersive,children:(0,W.jsx)(cn,{history:c?.immersive?null:c,children:(0,W.jsx)(Kt,{actions:n,activeId:p,agent:r,anchors:E,blocked:O,draft:M,narrow:x,railRef:f,threads:t,onActivate:m})})}),h&&s&&!c?s(h):null,h&&a&&!k&&!c?(0,W.jsx)(H.Fragment,{children:a.render({kind:`popover`,left:h.offsetLeft,top:a.bottom+Vn,width:h.offsetWidth})},a.key):null]})}function Wn({placement:e,excerpt:t,initial:n,restored:i,leaving:a,onChange:o,onSubmit:s,onCancel:c,ref:l}){let u=Xe(),d=e.kind===`popover`?e:null;return(0,W.jsx)(`div`,{"data-draft-panel":e.kind,ref:l,...{0:{className:`xowlrko xllfotl xatqbsq x1u6ievf`},2:{className:`xowlrko xllfotl xatqbsq x1u6ievf x10l6tqk x1u8a7rm`},1:{className:`x1u6ievf xxp0q0x x12l1aco xn0cd8s x47corl`},3:{className:`x1u6ievf x10l6tqk x1u8a7rm xxp0q0x x12l1aco xn0cd8s x47corl`}}[!!d<<1|!!a],style:d?{left:d.left,top:d.top,width:d.width}:void 0,children:(0,W.jsx)(ae,{active:!0,children:(0,W.jsx)(He,{autoFocus:!0,delivery:u?.delivery,excerpt:t,initial:n,placeholder:r(`composer.placeholder`),restored:i?{}:void 0,onCancel:c,onChange:o,onSubmit:s})})})}function Gn(e){let t=(0,H.useMemo)(ze,[]),[n,r]=(0,H.useState)(null),[i,a]=(0,H.useState)(!1),o=(0,H.useRef)(``),s=(0,H.useRef)(0),c=(0,H.useRef)(null),l=(0,H.useRef)(null);Rt(i?null:n?.target.range??null,i?void 0:n?.target.elements);let u=(0,H.useCallback)(n=>{window.clearTimeout(s.current);let i=t.take(P(n.blockId,n.quote,n.blockIds,n.textRanges,n.diagram));o.current=i,a(!1),r({target:n,initial:i}),window.getSelection()?.removeAllRanges(),e()},[t,e]),d=(0,H.useCallback)(e=>{n&&(t.save(P(n.target.blockId,n.target.quote,n.target.blockIds,n.target.textRanges,n.target.diagram),e?o.current:``),a(!0),s.current=window.setTimeout(()=>{r(null),a(!1)},120))},[n,t]);return(0,H.useEffect)(()=>{if(!n||i)return;let e=e=>{let t=e.target;c.current?.contains(t)||l.current?.contains(t)||d(!0)};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[n,i,d]),(0,H.useEffect)(()=>()=>window.clearTimeout(s.current),[]),{drafts:t,draft:n,leaving:i,restored:!!n?.initial,open:u,close:d,current:()=>o.current,onText:e=>{o.current=e},panelRef:c,toolbarRef:l}}function Kn(e,t=[]){if(e.diagram)return{kind:`anchor`,icon:ne,label:se(e)};if(e.quote)return{kind:`quote`,text:e.quote};let n=t.length===1?ve(t):null;return n?{kind:`quote`,text:n}:{kind:`anchor`,icon:ht,label:se(e,t)}}var qn=e=>e.elements?.map(_e),Jn=46;function Yn(e,t){return Math.min(e+8,window.innerWidth-(t.offsetParent?.getBoundingClientRect().left??0)-40)}function Xn({article:e,editor:t,enabled:n,onComment:r}){let i=In(t,e.closest(`main`),n);return i?(0,W.jsx)(ie,{left:Yn(i.right,e),top:i.top,onComment:()=>r(i)}):null}function Zn({blockId:e,element:t,node:n,host:r}){let i=r.closest(`main`);if(!i)return null;let a=n.getBoundingClientRect(),o=i.getBoundingClientRect(),s=document.createRange();return s.setStart(r,0),{blockId:e,quote:t.label,diagram:t.target,range:s,left:a.left-o.left,right:a.right-o.left,top:a.top-o.top,bottom:a.bottom-o.top}}function Qn(e){return e.kind===`block`?Ot(Dt(e)):{x:e.right,y:e.bottom}}function $n({editor:e,threads:t,actions:n,agent:r,canComment:i,canCommentDiagram:a=i,selection:o,clearSelection:s,resolveSelection:c,onCreate:l,onMain:u,onToolbar:d,history:f,shareBase:p,children:m}){let h=Gn(s),{draft:g,open:_}=h,[v,y]=(0,H.useState)(null),[b,x]=(0,H.useState)(0);(0,H.useLayoutEffect)(()=>{if(!v||f)return;let t=()=>{let t=v.querySelector(`.ryugi-editor-toolbar`);t?x(t.getBoundingClientRect().height):e?.isEditable()||x(0)};t();let n=new MutationObserver(t);return n.observe(v,{childList:!0}),()=>n.disconnect()},[v,f,e]),(0,H.useEffect)(()=>{if(!v||!d)return;let e=()=>d(v.querySelector(`.ryugi-editor-toolbar, .history-bar`)!==null);e();let t=new MutationObserver(e);return t.observe(v,{childList:!0}),()=>{t.disconnect(),d(!1)}},[v,d]);let S=h.leaving?null:g?.target??null,{drafts:C}=h,w=(0,H.useMemo)(()=>({draft:S,drafts:C,readOnly:!a,blockAction:i,pick:e=>{let t=Zn(e);t&&_(t)},create:(e,t)=>l({...e,range:document.createRange(),left:0,right:0,top:0,bottom:0},t)}),[i,a,S,C,_,l]),T=(0,H.useCallback)(()=>{let e=window.getSelection();navigator.clipboard?.writeText(e?.toString()??``),e?.removeAllRanges(),s()},[s]),E=(0,H.useMemo)(()=>({toolbarSlot:v,selectionActions:g?null:(0,W.jsx)(oe,{onCopy:T,onComment:i?()=>{let e=c();e&&_(e)}:void 0})}),[v,g,i,c,_,T]);return(0,W.jsxs)(me,{value:E,children:[(0,W.jsx)(`div`,{className:`ryugi-editor-toolbar-slot`,ref:y,children:b>0?(0,W.jsx)(`div`,{"aria-hidden":`true`,className:`history-toolbar-space`,style:{height:b}}):null}),(0,W.jsx)(Un,{actions:n,agent:r,diagram:w,editor:e,history:f,shareBase:p,threads:t,draft:g?{key:P(g.target.blockId,g.target.quote,g.target.blockIds,g.target.textRanges,g.target.diagram),top:g.target.top,bottom:g.target.bottom,from:Qn(g.target),leaving:h.leaving,render:e=>(0,W.jsx)(Wn,{excerpt:Kn(g.target,qn(g.target)),initial:h.current(),leaving:h.leaving,placement:e,ref:h.panelRef,restored:h.restored,onCancel:()=>h.close(!0),onChange:h.onText,onSubmit:(e,t)=>(t?l(g.target,e,t):l(g.target,e)).then(e=>(e&&h.close(!1),e))})}:null,overlay:t=>(0,W.jsxs)(W.Fragment,{children:[o&&!g&&o.kind===`block`&&i?(0,W.jsx)(ie,{left:Yn(o.right,t),ref:h.toolbarRef,top:o.top,onComment:()=>h.open(o)}):null,(0,W.jsx)(Xn,{article:t,editor:e,enabled:i&&!g&&!o,onComment:h.open}),o&&!g&&o.kind===`nested`?(0,W.jsx)(le,{left:o.left,ref:h.toolbarRef,top:Math.max(o.top-Jn,0),children:(0,W.jsx)(oe,{onComment:i?()=>h.open(o):void 0,onCopy:T})}):null]}),onMain:u,children:m})]})}function er(e){let t=j(e);return t._headless=!0,[`registerDecoratorListener`,`registerRootListener`,`registerMutationListener`,`getRootElement`,`setRootElement`,`getElementByKey`,`focus`,`blur`].forEach(e=>{t[e]=()=>{(function(e,...t){throw function(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);return n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(e,...t)})(439,e)}}),t}function tr({text:e}){let t=(0,H.useRef)(null),n=(0,H.useRef)(null);return(0,H.useEffect)(()=>{let r=t.current;if(!r)return;let i=r.parentNode;if(!i)return;let a=n.current;return!a||a.parentNode!==i?(a=document.createComment(e),i.insertBefore(a,r),n.current=a):a.data!==e&&(a.data=e),()=>{n.current?.parentNode&&n.current.parentNode.removeChild(n.current),n.current=null}},[e]),(0,W.jsx)(`template`,{suppressHydrationWarning:!0,"data-rich-comment-anchor":``,ref:t})}var $=e=>`${L[e]} ${Le[e]}`,nr={h1:$(`headingH1`),h2:$(`headingH2`),h3:$(`headingH3`),h4:$(`headingH4`),h5:$(`headingH5`),h6:$(`headingH6`)};function rr(e){return e.toLowerCase().trim().replaceAll(/[^\s\w\u3000-\u9FFF\uAC00-\uD7AF\uFF00-\uFFEF-]/g,``).replaceAll(/[\s_]+/g,`-`).replaceAll(/^-+|-+$/g,``)}function ir(e){return e.type===`comment`?``:e.text?e.text:e.children?e.children.map(ir).join(``):``}var ar=/^["'«‘“‹「『"']/,or=/["'»’”›」』"']$/;function sr(e,t,n,r,i,a){switch(e.type){case`root`:return(0,W.jsx)(W.Fragment,{children:n});case`paragraph`:{let r=e.format?{textAlign:e.format}:void 0;return(0,W.jsx)(`p`,{className:$(`paragraph`),style:r,children:n??(0,W.jsx)(`br`,{})},t)}case`heading`:{let o=e.tag,s=rr(i||ir(e)),c=a??s;if(a===void 0&&s){let e=r.get(s);e===void 0?r.set(s,1):(c=`${s}-${e}`,r.set(s,e+1))}return(0,W.jsxs)(o,{className:nr[o],id:c||void 0,children:[c&&(0,W.jsx)(`a`,{className:$(`headingAnchor`),href:`#${c}`,tabIndex:0,children:(0,W.jsx)(p,{"aria-hidden":!0,size:14,strokeWidth:2})}),n]},t)}case`rich-quote`:case`quote`:{let r=(i||ir(e)).trim(),a=ar.test(r),o=or.test(r),s=e.attribution;return(0,W.jsxs)(`blockquote`,{className:$(`quote`),"data-no-close-quote":o?``:void 0,"data-no-open-quote":a?``:void 0,children:[n,s&&(0,W.jsxs)(`footer`,{className:$(`quoteAttribution`),children:[`— `,s]})]},t)}case`list`:{let r=e.listType===`number`?`ol`:`ul`,i=e.listType===`number`?$(`listOl`):e.listType===`check`?`${$(`checklist`)} ${$(`listUl`)}`:$(`listUl`);return(0,W.jsx)(r,{className:i,start:e.start===1?void 0:e.start,children:n},t)}case`listitem`:{let r=e.checked!==void 0,i=e.children?.some(e=>e.type===`list`),a=typeof e.value==`number`&&e.value>1?e.value:void 0,o;return o=i?$(`listNestedItem`):r?e.checked?`${$(`listItem`)} ${$(`listItemChecked`)}`:`${$(`listItem`)} ${$(`listItemUnchecked`)}`:$(`listItem`),(0,W.jsx)(`li`,{className:o,value:a,children:n},t)}case`link`:return(0,W.jsxs)(`a`,{className:$(`link`),href:e.url,rel:e.rel||`noopener`,target:e.target||`_blank`,children:[(0,W.jsx)(Ce,{href:e.url}),n]},t);case`autolink`:return(0,W.jsxs)(`a`,{className:$(`link`),href:e.url,rel:`noopener`,target:`_blank`,children:[(0,W.jsx)(Ce,{href:e.url}),n]},t);case`horizontalrule`:return(0,W.jsx)(`hr`,{className:$(`hr`)},t);case`table`:return(0,W.jsx)(`div`,{className:$(`tableScrollableWrapper`),children:(0,W.jsx)(`table`,{className:$(`table`),children:n})},t);case`tablerow`:return(0,W.jsx)(`tr`,{children:n},t);case`tablecell`:{let r=e.headerState?`th`:`td`,i=e.headerState?$(`tableCellHeader`):$(`tableCell`);return(0,W.jsx)(r,{className:i,colSpan:e.colSpan>1?e.colSpan:void 0,children:n},t)}case`details`:{let r=e.summary||``;return(0,W.jsxs)(`details`,{className:`${R.details} ${I.details}`,open:e.open||void 0,children:[(0,W.jsxs)(`summary`,{className:`${R.summary} ${I.summary}`,children:[(0,W.jsx)(`span`,{"aria-hidden":`true`,className:`${R.chevron} ${I.chevron}`,children:(0,W.jsx)(`svg`,{fill:`none`,height:`20`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,viewBox:`0 0 20 20`,width:`20`,children:(0,W.jsx)(`path`,{d:`M8 6L12 10L8 14`})})}),(0,W.jsx)(`span`,{className:`${R.summaryText} ${I.summaryText}`,children:r})]}),(0,W.jsx)(`div`,{className:`${R.content} ${I.content}`,children:n})]},t)}case`spoiler`:return(0,W.jsx)(`span`,{className:$(`spoiler`),role:`button`,tabIndex:0,children:n},t);case`tag`:return(0,W.jsx)(`span`,{className:$(`tag`),style:{backgroundColor:Pe(e.text)},children:e.text},t);case`comment`:return(0,W.jsx)(tr,{text:e.text??``},t);case`ruby`:return(0,H.createElement)(Fe,{key:t,rendererKey:`Ruby`,defaultRenderer:ue,props:{reading:e.reading??``,children:n}});case`code`:return(0,W.jsx)(`pre`,{className:`rich-code-block`,children:(0,W.jsx)(`code`,{children:n})},t);case`code-highlight`:return(0,W.jsx)(`span`,{children:e.text},t);case`linebreak`:return(0,W.jsx)(`br`,{},t);case`tab`:return(0,W.jsx)(`span`,{children:` `},t);default:return null}}var cr=e=>`${L[e]} ${Le[e]}`,lr=[[1,`textBold`],[2,`textItalic`],[4,`textStrikethrough`],[8,`textUnderline`],[16,`textCode`],[32,`textSubscript`],[64,`textSuperscript`],[128,`textHighlight`]];function ur(e){let t={};for(let n of e.split(`;`)){let e=n.indexOf(`:`);if(e===-1)continue;let r=n.slice(0,e).trim(),i=n.slice(e+1).trim();if(!r||!i)continue;let a=r.replaceAll(/-([a-z])/g,(e,t)=>t.toUpperCase());t[a]=i}return t}function dr(e,t){let n=e.text,r=e.format||0;for(let[e,i]of lr)r&e&&(n=(0,W.jsx)(`span`,{className:cr(i),children:n},`${t}-${e}`));return e.style&&(n=(0,W.jsx)(`span`,{style:ur(e.style),children:n},t)),n}function fr(e,t=!1){let n=[],r=t?e.findIndex(e=>e.type===`paragraph`):-1,i=e=>e.type===`image`&&typeof e.layout==`string`&&e.layout.startsWith(`float-`);for(let t=0;t<e.length;t++){let a=[t];if(t===r&&t+1<e.length&&a.push(++t),i(e[t]))for(;++t<e.length;){a.push(t);let n=e[t];if(!i(n)&&![`paragraph`,`list`,`quote`,`rich-quote`,`comment`].includes(n.type))break}n.push(a)}let a=[];for(let t of n)a.length&&t.every(t=>e[t].type===`comment`)||a.at(-1)?.every(t=>e[t].type===`comment`)?a.at(-1).push(...t):a.push(t);return a}function pr(e){let t={},n=new Set,r={},i=1;function a(e){if(e.type===`footnote`&&e.identifier){let t=e.identifier;n.has(t)||(n.add(t),r[t]=i++)}if(e.type===`footnote-section`&&e.definitions&&Object.assign(t,e.definitions),e.children)for(let t of e.children)a(t);if(e.root&&a(e.root),e.content&&typeof e.content==`object`&&e.content.root&&a(e.content),e.cells&&Array.isArray(e.cells))for(let t of e.cells)t&&t.root&&a(t)}a(e);for(let e of n)e in t||(t[e]=``);return{definitions:t,displayNumberMap:r}}var mr=e=>`${L.alert} ${Le.alert} rich-alert-${e}`;function hr(e,t,n){switch(e.type){case`alert-quote`:return(0,H.createElement)(`div`,{key:t,className:mr(e.alertType)},n);case`banner`:return(0,H.createElement)(`div`,{key:t,className:`rich-banner rich-banner-${e.bannerType}`},n);case`grid-container`:return(0,H.createElement)(`div`,{key:t,className:`${Oe.container} ${Me.container}`},n);default:return(0,H.isValidElement)(n)?(0,H.cloneElement)(n,{key:t}):n}}function gr(e,t,n){return(0,H.isValidElement)(e)&&typeof e.type==`string`?(0,H.cloneElement)(e,{"data-block-id":t}):(0,W.jsx)(`div`,{className:`rich-block-anchor`,"data-block-id":t,children:e},`${n}-block-anchor`)}function _r(e,t,n,r){return t?(r.blockAnchor??gr)(e,t,n):e}function vr(e,t,n,r,i,a,o){let s=o.recycleKeys?i:e.getKey?e.getKey():i,c=o.headingIds?.get(e.getKey?.()),{builtinNodeOverrides:l}=o;if(typeof e.decorate==`function`){let r=null;try{r=e.decorate(t,n)}catch{}if(r!=null){let t=e.exportJSON?e.exportJSON():{},n=l?.[t.type];return _r(n?n(t,s,[r],()=>hr(t,s,r)):hr(t,s,r),a,s,o)}}let u=e.exportJSON?e.exportJSON():{};if(u.type===`text`){let e=l?.text;return e?e(u,s,null,()=>dr(u,s)):dr(u,s)}let d=typeof e.getChildren==`function`?e.getChildren():[];Array.isArray(u.children)&&u.children.length===0&&d.length>0&&(u.children=d.map(e=>({type:typeof e.getType==`function`?e.getType():e.__type})));let f=null;d.length>0&&(f=d.map((e,i)=>vr(e,t,n,r,`${s}-${i}`,void 0,o)));let p=e.getTextContent?e.getTextContent():void 0,m=l?.[u.type];return _r(m?m(u,s,f,()=>sr(u,s,f,r,p,c)):sr(u,s,f,r,p,c),a,s,o)}function yr(e,t,n,r){let i=er({nodes:t,theme:z,editable:!1,onError:e=>{console.error(`[RichRenderer]`,e)}}),a={namespace:`ssr`,theme:z},o=Ne(e),s=i.parseEditorState(o);i.setEditorState(s);let c=pr(o),l=o.root?.children,u=new Map,d=new Map,f=new Map,p=s.read(()=>{let e=new Map,t=(n,r,i)=>{if(f.set(n.getKey(),i),n.getType()===`heading`){let t=rr(n.getTextContent()),i=e.get(t)??0,a=t?`${t}${i?`-${i}`:``}`:``;e.set(t,i+1),u.set(n.getKey(),a),a&&d.set(a,r)}ee(n)&&n.getChildren().forEach((e,n)=>t(e,r,`${i}.${n}`))},n=N().getChildren();return n.forEach((e,n)=>t(e,n,`${n}:0`)),n}),m=new Set,h=p.map((e,t)=>{let n=l?.[t]??{type:e.getType(),version:1},r=n.$?.blockId??`renderer-${t}`;for(;m.has(r);)r=`${r}:${t}`;return m.add(r),{id:r,data:n,index:t,pool:`${n.type}:${n.type===`dynamic`?n.url:n.tag??``}`}}),g=fr(h.map(e=>e.data),r),_=new Map,v=g.map((e,t)=>{let n=e.map(e=>(_.set(e,t),h[e])),r=n[0];return{blocks:n,id:r.id,data:n.length===1?r.data:{type:`flow-group`,version:1,children:n.map(e=>e.data)},pool:n.length===1?r.pool:`flow-group`}});for(let[e,t]of d)d.set(e,_.get(t));let y=(e,t)=>s.read(()=>{let r=v[e];return r?(0,W.jsx)(H.Fragment,{children:r.blocks.map((e,r)=>vr(p[e.index],i,a,new Map,t===void 0?`ssr-${e.index}`:`recycler-${t}-${r}`,l?.[e.index]?.$?.blockId,{...n,headingIds:u,recycleKeys:t!==void 0}))},t===void 0?r.id:`recycler-${t}`):null}),b;return{document:{editor:i,rows:v,headingRows:d,render:y,renderAll:()=>b??=(0,W.jsx)(W.Fragment,{children:v.map((e,t)=>y(t))}),nodePath:e=>e?f.get(e)??e:`0`},footnoteData:c,renderNestedContent:e=>{let r=er({nodes:t,theme:z,editable:!1,onError:e=>{console.error(`[RichRenderer:nested]`,e)}}),i={namespace:`ssr-nested`,theme:z},a=Ne(e),o=r.parseEditorState(a);r.setEditorState(o);let s=null,c=a.root?.children;return o.read(()=>{let e=N(),t=new Map,a=e.getChildren().map((e,a)=>vr(e,r,i,t,`nested-${a}`,c?.[a]?.$?.blockId,n));s=(0,W.jsx)(W.Fragment,{children:a})}),s}}}function br({document:e}){return e.renderAll()}function xr({value:e,variant:t=`article`,theme:n,className:r,style:i,as:a=`div`,nested:o=!1,rendererConfig:s,extraNodes:c,builtinNodeOverrides:l,blockAnchor:u,surface:d,virtualization:f}){let p=Re(t),m=Se(),{document:h,footnoteData:g,renderNestedContent:_}=(0,H.useMemo)(()=>yr(e,c?[...je,...c]:je,{blockAnchor:u,builtinNodeOverrides:l},t===`note`),[u,l,c,e,t]),{scrollContainer:v,overscan:y,estimateBlockHeight:b,preserveCapacity:x}=typeof f==`object`?f:{},S=!!f,C=f===!1,T=(0,H.useMemo)(()=>C?br:S?We({scrollContainer:v,overscan:y,estimateBlockHeight:b,preserveCapacity:x}):d??br,[d,S,C,v,y,b,x]),E=[`rich-content`,p,r].filter(Boolean).join(` `),D=typeof a==`string`?{suppressHydrationWarning:!0,className:E,"data-rich-nested":o?`true`:void 0,"data-theme":n}:{},O=n??`light`;return(0,W.jsx)(w,{className:p,theme:O,children:(0,W.jsx)(De,{colorScheme:O,children:(0,W.jsx)(be,{config:s,mode:`renderer`,variant:t,children:(0,W.jsx)(Ee,{definitions:g.definitions,displayNumberMap:g.displayNumberMap,children:(0,W.jsx)(xe,{value:m??_,children:(0,W.jsx)(a,{...D,style:i,children:(0,W.jsx)(T,{document:h})})})})})})})}var Sr=/^claude-(opus|sonnet|haiku|fable)-(\d+)-(\d+)(?:\[[^\]]*\])?$/;function Cr(e){let t=Sr.exec(e);if(!t)return e;let[,n,r,i]=t;return`${n[0].toUpperCase()}${n.slice(1)} ${r}.${i}`}var wr=16,Tr={content:{"--lobe-popover-viewport-inline-padding":`4px`}},Er=4,Dr=(e,t)=>e.kind===`human`&&e.name===t?r(`common.you`):e.name;function Or({contributor:e,stacked:t=!1}){let[n,r]=(0,H.useState)(!1),i=e.kind===`agent`?Je(e.name):void 0,a=i?Ye[i]:void 0;return(0,W.jsx)(`span`,{"data-byline-face":``,...{0:{className:`xrvj5dj x1ku5rj1 x2lah0s x1kky2od xlup9mm x16rqkct xb3r6kr x7em3ua x15dg6x3 x1bo0w0s xvwhms9 x1s688f`},1:{className:`xrvj5dj x1ku5rj1 x2lah0s x1kky2od xlup9mm x16rqkct xb3r6kr x7em3ua x15dg6x3 x1bo0w0s xvwhms9 x1s688f x165d6jo`}}[!!t|0],children:a?(0,W.jsx)(a.Avatar,{shape:`circle`,size:wr}):e.avatar&&!n?(0,W.jsx)(`img`,{alt:``,src:e.avatar,onError:()=>r(!0),className:`x1kky2od xlup9mm xl1xv1r`}):[...e.name][0]?.toUpperCase()})}function kr({contributors:e,me:t,now:n}){return(0,W.jsx)(`div`,{className:`x78zum5 xdt5ytf x1u2d2a2 xxc7z9f`,children:e.map(e=>(0,W.jsxs)(`div`,{"data-contributor":``,className:`xrvj5dj x1g3yg12 x6s0dn4 x167g77z x1t0vds8 xdqyycr x1ct8sxb x178xt8z x1g31smg x13fuv20 xxu5053`,children:[(0,W.jsx)(Or,{contributor:e}),(0,W.jsx)(`span`,{className:`xo2rkog xb3r6kr xlyipyv xuxw1ft`,children:[Dr(e,t),e.models.map(Cr).join(` / `)].filter(Boolean).join(` · `)}),(0,W.jsxs)(`span`,{className:`xddlp02 x1qt5hsa xss6m8b xuxw1ft`,children:[r(`document.byline.edits`,{count:e.edits}),` ·`,` `,Qe(e.lastAt*1e3,n)]})]},e.kind+e.name))})}function Ar({byline:e,me:t,now:n}){let{contributors:i,last:a}=e;if(!i.length)return null;let o=i.length===1?Dr(i[0],t):r(`document.byline.authors`,{count:i.length});return(0,W.jsx)(Be,{content:(0,W.jsx)(kr,{contributors:i,me:t,now:n}),placement:`bottomLeft`,styles:Tr,trigger:`hover`,children:(0,W.jsxs)(`button`,{"data-byline":``,type:`button`,className:`x3nfvp2 x6s0dn4 x17d4w8g x193iq5w xxk0z11 x14oi46j x165d6jo xc342km x1kogg8i xjbqb8w x9jwiqo xddlp02 xln7xf2 x1ct8sxb xuxw1ft xt0e3qv`,children:[(0,W.jsx)(`span`,{className:`x3nfvp2 x2lah0s`,children:i.slice(0,Er).map((e,t)=>(0,W.jsx)(Or,{contributor:e,stacked:t>0},e.kind+e.name))}),(0,W.jsx)(`span`,{className:`x1bo0w0s xk50ysn`,children:o}),a?(0,W.jsxs)(`span`,{children:[`·`,` `,r(`document.byline.edited`,{name:Dr(a,t),time:Qe(a.at*1e3,n)})]}):null]})})}var jr=32,Mr=6e4;function Nr({editor:e,byline:t,me:n}){let[r,i]=(0,H.useState)(null),[a,o]=(0,H.useState)(Date.now);(0,H.useEffect)(()=>{o(Date.now());let e=setInterval(()=>o(Date.now()),Mr);return()=>clearInterval(e)},[t]);let s=t.contributors.length>0;return(0,H.useLayoutEffect)(()=>{let t=null,n=()=>{t=e.getRootElement();let n=t?.offsetParent;if(!t||!(n instanceof HTMLElement)||!s){t&&delete t.dataset.byline,i(null);return}let r=t.firstElementChild,a=r instanceof HTMLElement&&r.tagName===`H1`?r:null;t.dataset.byline=a?`title`:`top`;let o=n.getBoundingClientRect(),c=(a??t).getBoundingClientRect(),l=a?c.bottom+4:c.top-jr;i(e=>{let t={host:n,left:c.left-o.left,top:l-o.top};return e?.host===t.host&&e.left===t.left&&e.top===t.top?e:t})};n();let r=new ResizeObserver(n),a=e.getRootElement();a&&r.observe(a);let o=e.registerUpdateListener(()=>requestAnimationFrame(n));return window.addEventListener(`resize`,n),()=>{r.disconnect(),o(),window.removeEventListener(`resize`,n),t&&delete t.dataset.byline}},[e,s]),r?(0,U.createPortal)((0,W.jsx)(`div`,{style:{position:`absolute`,zIndex:1,left:r.left,top:r.top,whiteSpace:`nowrap`},onMouseMove:e=>e.stopPropagation(),onPointerMove:e=>e.stopPropagation(),children:(0,W.jsx)(Ar,{byline:t,me:n,now:a})}),r.host):null}function Pr({error:e,onDismiss:t}){return e?(0,U.createPortal)((0,W.jsxs)(`div`,{role:`alert`,className:`xixxii4 xy58vm5 xvf9o5y xvueqy4 xeq5yr9 x27kpxv x11uqc5h x78zum5 x6s0dn4 x1v2ro7d x10dr8xq x1hr3lfm xur7f20 xmkeg23 x1y0btm7 xgcsv5v x1rozbrz xo2rkog xqfszdh x4z9k3i x1pzk2i8`,children:[(0,W.jsx)(`span`,{children:r(`documentExport.failed`)}),(0,W.jsx)(`button`,{"aria-label":r(`common.close`),type:`button`,onClick:t,className:`xrvj5dj x1ku5rj1 xjbqb8w x1bo0w0s xc342km xgd8bvy x1fgtraw x1717udv x1ypdohk x2lah0s`,children:(0,W.jsx)(S,{size:16})})]}),document.body):null}var Fr={[we]:re,[ke]:Ie,[Te]:pe},Ir={claude:`Claude Code`,codex:`Codex`},Lr=e=>String(e).padStart(2,`0`);function Rr(e){let t=new Date(e);return`${t.getMonth()+1}/${t.getDate()} ${Lr(t.getHours())}:${Lr(t.getMinutes())}`}function zr({prompt:e,empty:t,theme:n}){let i=(0,H.useRef)(null),[a,o]=(0,H.useState)(!1),[s,c]=(0,H.useState)(!1);return(0,H.useLayoutEffect)(()=>{let e=i.current;e&&!a&&c(e.scrollHeight>e.clientHeight+1)},[a,e]),(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`aside`,{"aria-label":r(`document.promptLabel`),"data-ryugi-no-comment":``,"data-task-prompt":``,className:`x8o32fp x1onr9mi xyumdvf x1t7ytsu x1awn4rw x1hx0egp`,children:[(0,W.jsxs)(`p`,{className:`x78zum5 x6s0dn4 x17d4w8g x1ghz6dp xddlp02 x1qt5hsa xd4r4e8`,children:[(0,W.jsx)(pt,{"aria-hidden":`true`,size:12}),r(`document.promptMeta`,{time:Rr(e.at),agent:Ir[e.harness]??e.harness})]}),(0,W.jsx)(`div`,{"data-task-prompt-body":``,ref:i,...{0:{className:`x1gslohp x1bo0w0s xif65rj x11m8ghp xb3r6kr`},1:{className:`x1gslohp x1bo0w0s xif65rj x11m8ghp xb3r6kr x1n19c2o`}}[!a|0],children:(0,W.jsx)(xr,{rendererConfig:Fr,theme:n,value:e.state,variant:`comment`})}),(s||a)&&(0,W.jsx)(`button`,{"aria-expanded":a,type:`button`,onClick:()=>o(e=>!e),className:`x1gslohp x1717udv xc342km xjbqb8w xddlp02 x12rs2w1 xjb2p0i xfifm61 x1bvjpef xrys4gj x1ypdohk`,children:r(a?`document.promptCollapse`:`document.promptExpand`)})]}),t&&(0,W.jsx)(`p`,{className:`x103tiuj xddlp02 x2ouz8m`,children:r(`document.promptEmpty`)})]})}var Br=[`wheel`,`touchmove`,`keydown`,`pointerdown`];function Vr(e){return e.getEditorState().read(()=>N().getChildren().map(e=>({id:A(e,F),key:e.getKey()}))).flatMap(({id:t,key:n})=>{let r=t?e.getElementByKey(n):null;return r?[{id:t,element:r}]:[]})}function Hr(e,t){if(t.kind!==`document`)return!1;let n=Vr(e).find(({id:e})=>e===t.blockId);if(!n)return!1;let r=n.element.getBoundingClientRect().top-t.top;return r!==0&&window.scrollBy({top:r,behavior:`instant`}),!0}function Ur(e){(0,H.useEffect)(()=>{if(!e)return;let t=g({read(){let t=null;for(let{id:n,element:r}of Vr(e)){let{top:e,bottom:i}=r.getBoundingClientRect();if(!(i<=0)){if(e>=0&&e<window.innerHeight)return{kind:`document`,blockId:n,top:e};if(t??={kind:`document`,blockId:n,top:e},e>=0)break}}return t},apply:t=>Hr(e,t)}),n=()=>{let t=v();t&&Hr(e,t)};n();let r=e.registerUpdateListener(n);for(let e of Br)window.addEventListener(e,h,{passive:!0});return()=>{t(),r();for(let e of Br)window.removeEventListener(e,h)}},[e])}var Wr=e=>`${V(e)}:${rt(e)}`;async function Gr(e,t){let n=new Map;for(let t of it(e))ot(t)&&n.set(Wr(t),t);let r=await Promise.all([...n].map(async([e,n])=>[e,await t(n).catch(()=>void 0)])),i={};for(let[e,t]of r)t&&(i[e]=t);return i}function Kr(e){let t=structuredClone({...e,comments:e.comments??Ke()}),n=t=>{if(!t||t.startsWith(`#`))return t;try{return new URL(t,e.contentBase||e.sourceUrl).href}catch{return t}},r=e=>{if(!e||typeof e!=`object`)return;let t=e;if(typeof t.type==`string`){for(let e of[`src`,`poster`,`favicon`,`image`])typeof t[e]==`string`&&(t[e]=n(t[e]));if((t.type===`link`||t.type===`autolink`||t.type===`link-card`)&&typeof t.url==`string`&&(t.url=n(t.url)),t.type===`excalidraw`&&typeof t.snapshot==`string`){let[e=``,...r]=t.snapshot.split(`
3
3
  `);!e.trimStart().startsWith(`{`)&&!e.startsWith(`ref:`)&&/(?:\.excalidraw(?:[?#]|$)|^https?:|^blob:)/.test(e)&&(t.snapshot=[n(e),...r].join(`
4
- `))}}for(let e of Object.values(t))typeof e==`object`&&r(e)};return r(t.state),t}function qr(e,t){let n;if(t.cloudOrigin){if(!e.to)return;n=new URL(`/a/${encodeURIComponent(e.to)}`,t.cloudOrigin)}else{n=new URL(`/${at(e)}/${encodeURIComponent(V(e))}`,t.sourceUrl);let r=new URL(t.sourceUrl);n.searchParams.set(`at`,r.searchParams.get(`at`)??r.pathname)}for(let t of m)e[t]&&n.searchParams.set(t,e[t]);return n.href}function Jr(e){let[t,r]=(0,H.useState)(!1),[i,a]=(0,H.useState)(!1),o=(0,H.useRef)(e);o.current=e;let l=(0,H.useRef)(null),u=async()=>{let e=o.current;if(!e.editor||e.available===!1||l.current)return;let t=new AbortController;l.current=t,r(!0),a(!1);try{let r=e.editor.getEditorState().toJSON(),i=e.scenes?await Gr(r,e.scenes.load):void 0;if(t.signal.aborted)return;let a=Kr({state:r,...i?{embeds:i}:{},comments:e.comments,title:e.title,contentBase:e.contentBase,sourceUrl:location.href,cloudOrigin:c()??(e.cloud?location.origin:void 0)}),{printDocument:o}=await n(async()=>{let{printDocument:e}=await import(`./printDocument-BhGNF0gC.js`);return{printDocument:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57]),import.meta.url);await o(a,{signal:t.signal})}catch(e){t.signal.aborted||(a(!0),console.warn(`Document export failed`,e))}finally{l.current===t&&(l.current=null),t.signal.aborted||r(!1)}},d=(0,H.useRef)(u);return d.current=u,(0,H.useEffect)(()=>{r(!1),a(!1);let t=t=>{s(t)&&t.data?.type===`ryugi:document-export`&&t.data.id===e.id&&t.data.format===`pdf`&&d.current()};return window.addEventListener(`message`,t),()=>{window.removeEventListener(`message`,t),l.current?.abort(),l.current=null}},[e.id]),{state:t?`preparing`:e.editor&&e.available!==!1?`ready`:null,error:i,dismiss:()=>a(!1),exportPdf:()=>void u()}}var Yr=2400,Xr=[{boxShadow:`inset 2px 0 0 #0d99ff`,backgroundColor:`rgb(13 153 255 / 0.13)`},{boxShadow:`inset 2px 0 0 transparent`,backgroundColor:`transparent`}];function Zr(e,t){let n=e.getEditorState().read(()=>N().getChildren().find(e=>A(e,F)===t)?.getKey());return n?e.getElementByKey(n):null}var Qr=50,$r=100;function ei(e){let t=e.indexOf(`:`),n=e.slice(0,t),r=e.slice(t+1);return`[data-ref-chip="${n}"][data-ref-key="${r}"], [data-ref-to="${n}"][data-ref-key="${r}"]`}function ti(e){let t=0,n=setInterval(()=>{let r=document.querySelector(ei(e));r&&J(r),(r||++t>=Qr)&&clearInterval(n)},$r);return()=>clearInterval(n)}function ni(e,t){let n=0,r=()=>{let r=Zr(e,t);return r&&(J(r),r.animate(Xr,{duration:Yr,easing:`ease-out`})),!!r||++n>=Qr};if(r())return()=>void 0;let i=setInterval(()=>{r()&&clearInterval(i)},$r);return()=>clearInterval(i)}var ri=(e,t)=>at(e)===`document`&&(e.to===t||V(e)===t);function ii(e,t,r,i,a){let s=!!r,[c,l]=(0,H.useState)(null),p=(0,H.useMemo)(()=>s&&f(),[s]),{role:m}=u(),h=(0,H.useRef)(()=>void 0);return(0,H.useEffect)(()=>{if(!s)return;let e=Z(),n=()=>{let n=ct(e.history.state,t);n!==null&&(h.current(),window.scrollTo({top:n,behavior:`instant`}))};return e.addEventListener(`popstate`,n),()=>e.removeEventListener(`popstate`,n)},[s,t]),(0,H.useEffect)(()=>{if(!p)return;let t,n,r=y(r=>{if(r.kind===`active`&&l(r.key),r.kind===`reveal`&&(l(r.key),t?.(),t=ti(r.key)),r.kind===`focus`&&r.block&&e&&(n?.(),n=ni(e,r.block)),r.kind!==`scroll-to`)return;l(r.key);let i=e&&Zr(e,r.blockId);i&&(J(i),i.animate(Xr,{duration:Yr,easing:`ease-out`}))});return o({kind:`ready`}),()=>{r(),t?.(),n?.()}},[p,e]),(0,H.useMemo)(()=>s?{active:c,isSelf:e=>ri(e,t),useBoard:r,useScene:i,openEmbed:e=>{if(p)return o({kind:`embed-open`,target:e});let t=a?.refId(e);if(!a||!t)return;let r=tt(a.frameSrc(`whiteboard`,t),e);n(async()=>{let{openArtifactModal:e}=await import(`./ArtifactModal-CH9BY3RJ.js`);return{openArtifactModal:e}},__vite__mapDeps([58,1,10,3,4,2,5,6,7,11,12,13,59,30,60,18,37,61,62,42]),import.meta.url).then(({openArtifactModal:t})=>t({allow:a.frameAllow,src:r,title:e.label??V(e)}))},open:n=>{let r=at(n);if(ri(n,t)){let r=e&&n.block?Zr(e,n.block):null;if(!r||!n.block){window.scrollTo({top:0,behavior:`instant`});return}p&&m===`beside`?o({kind:`block-focus`,block:n.block}):st(t,n.block,Z()),h.current(),h.current=J(r),r.animate(Xr,{duration:Yr,easing:`ease-out`})}else p?o({kind:`ref-open`,target:n}):location.assign(`/document/${t}${d(location.search,Ve(V(n),r,n,`document`))}`)}}:null,[s,c,p,m,e,t,r,i,a])}function ai(e){let[t,n]=(0,H.useState)([]);return(0,H.useEffect)(()=>{if(!e)return;let t=()=>{let t=it(e.getEditorState().toJSON());n(e=>JSON.stringify(e)===JSON.stringify(t)?e:t)};return t(),e.registerUpdateListener(t)},[e]),t}function oi(e,t){return N().getChildren().flatMap(n=>{let r=A(n,F),i=e.getElementByKey(n.getKey());if(!r||!i||!t.intersectsNode(i))return[];let a=document.createRange();if(a.selectNodeContents(i),t.compareBoundaryPoints(Range.START_TO_START,a)>0&&a.setStart(t.startContainer,t.startOffset),t.compareBoundaryPoints(Range.END_TO_END,a)<0&&a.setEnd(t.endContainer,t.endOffset),a.collapsed)return[];let o=a.toString();if(!o&&i.textContent)return[];let s=document.createRange();return s.selectNodeContents(i),s.setEnd(a.startContainer,a.startOffset),[{blockId:r,quote:o,start:s.toString().length}]})}var si=200;function ci(e,t){let n=(t instanceof Element?t:t?.parentElement)?.closest(`[contenteditable="true"]`);return!!(n&&n!==e&&e.contains(n))}function li(e,t){let n=e.read(()=>{let t=te();return T(t)?N().getChildren().flatMap(n=>{if(!t.has(n.getKey()))return[];let r=A(n,F),i=e.getElementByKey(n.getKey());return r&&i?[{id:r,element:i}]:[]}):[]});if(n.length){let e=n.map(e=>e.element),r=e.map(e=>e.getBoundingClientRect()),i=t.getBoundingClientRect(),a=document.createRange();return a.selectNodeContents(e[0]),{kind:`block`,blockId:n[0].id,...n.length>1?{blockIds:n.map(e=>e.id)}:{},quote:``,elements:e,range:a,left:Math.min(...r.map(e=>e.left))-i.left,right:Math.max(...r.map(e=>e.right))-i.left,top:r[0].top-i.top,bottom:r.at(-1).bottom-i.top}}let r=window.getSelection(),i=e.getRootElement();if(!r||r.isCollapsed||r.rangeCount===0||!i?.contains(r.anchorNode)||!i.contains(r.focusNode))return null;let a=r.toString().trim(),o=r.getRangeAt(0),s=e.read(()=>oi(e,o));if(!s.length||!a)return null;let c=ci(i,r.anchorNode)&&ci(i,r.focusNode),l=[...o.getClientRects()],u=l[0]??o.getBoundingClientRect(),d=l.at(-1)??u,f=t.getBoundingClientRect();return{blockId:s[0].blockId,...s.length>1?{blockIds:s.map(e=>e.blockId),textRanges:s}:c?{textRanges:s}:{},...c?{kind:`nested`}:{},quote:a.slice(0,500),left:u.left-f.left,bottom:d.bottom-f.top,top:u.top-f.top,right:Math.max(...l.map(e=>e.right),d.right)-f.left,range:o.cloneRange()}}function ui(e,t){let[n,r]=(0,H.useState)(null);return(0,H.useEffect)(()=>{if(!e||!t)return;let n=0,i=()=>{clearTimeout(n),n=window.setTimeout(()=>r(li(e,t)),si)};document.addEventListener(`selectionchange`,i);let a=e.registerUpdateListener(i);window.addEventListener(`scroll`,i,!0),window.addEventListener(`resize`,i);let o=new ResizeObserver(i);return e.getRootElement()&&o.observe(e.getRootElement()),()=>{clearTimeout(n),document.removeEventListener(`selectionchange`,i),a(),window.removeEventListener(`scroll`,i,!0),window.removeEventListener(`resize`,i),o.disconnect()}},[e,t]),[n,(0,H.useCallback)(()=>{r(null),e?.read(()=>T(te()))&&e.update(()=>E(null))},[e]),(0,H.useCallback)(()=>e&&t?li(e,t):null,[e,t])]}function di(){let e=new Set;return{emit:t=>e.forEach(e=>e(t)),subscribe:t=>(e.add(t),()=>e.delete(t))}}export{gt as A,jt as C,Lt as D,Rt as E,At as O,an as S,It as T,qn as _,ai as a,ln as b,qr as c,zr as d,Pr as f,Kn as g,$n as h,ii as i,vt as k,Hr as l,xr as m,ui as n,Jr as o,Nr as p,oi as r,Wr as s,di as t,Ur as u,Un as v,zt as w,sn as x,pn as y};
4
+ `))}}for(let e of Object.values(t))typeof e==`object`&&r(e)};return r(t.state),t}function qr(e,t){let n;if(t.cloudOrigin){if(!e.to)return;n=new URL(`/a/${encodeURIComponent(e.to)}`,t.cloudOrigin)}else{n=new URL(`/${at(e)}/${encodeURIComponent(V(e))}`,t.sourceUrl);let r=new URL(t.sourceUrl);n.searchParams.set(`at`,r.searchParams.get(`at`)??r.pathname)}for(let t of m)e[t]&&n.searchParams.set(t,e[t]);return n.href}function Jr(e){let[t,r]=(0,H.useState)(!1),[i,a]=(0,H.useState)(!1),o=(0,H.useRef)(e);o.current=e;let l=(0,H.useRef)(null),u=async()=>{let e=o.current;if(!e.editor||e.available===!1||l.current)return;let t=new AbortController;l.current=t,r(!0),a(!1);try{let r=e.editor.getEditorState().toJSON(),i=e.scenes?await Gr(r,e.scenes.load):void 0;if(t.signal.aborted)return;let a=Kr({state:r,...i?{embeds:i}:{},comments:e.comments,title:e.title,contentBase:e.contentBase,sourceUrl:location.href,cloudOrigin:c()??(e.cloud?location.origin:void 0)}),{printDocument:o}=await n(async()=>{let{printDocument:e}=await import(`./printDocument-GFcncwq5.js`);return{printDocument:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57]),import.meta.url);await o(a,{signal:t.signal})}catch(e){t.signal.aborted||(a(!0),console.warn(`Document export failed`,e))}finally{l.current===t&&(l.current=null),t.signal.aborted||r(!1)}},d=(0,H.useRef)(u);return d.current=u,(0,H.useEffect)(()=>{r(!1),a(!1);let t=t=>{s(t)&&t.data?.type===`ryugi:document-export`&&t.data.id===e.id&&t.data.format===`pdf`&&d.current()};return window.addEventListener(`message`,t),()=>{window.removeEventListener(`message`,t),l.current?.abort(),l.current=null}},[e.id]),{state:t?`preparing`:e.editor&&e.available!==!1?`ready`:null,error:i,dismiss:()=>a(!1),exportPdf:()=>void u()}}var Yr=2400,Xr=[{boxShadow:`inset 2px 0 0 #0d99ff`,backgroundColor:`rgb(13 153 255 / 0.13)`},{boxShadow:`inset 2px 0 0 transparent`,backgroundColor:`transparent`}];function Zr(e,t){let n=e.getEditorState().read(()=>N().getChildren().find(e=>A(e,F)===t)?.getKey());return n?e.getElementByKey(n):null}var Qr=50,$r=100;function ei(e){let t=e.indexOf(`:`),n=e.slice(0,t),r=e.slice(t+1);return`[data-ref-chip="${n}"][data-ref-key="${r}"], [data-ref-to="${n}"][data-ref-key="${r}"]`}function ti(e){let t=0,n=setInterval(()=>{let r=document.querySelector(ei(e));r&&J(r),(r||++t>=Qr)&&clearInterval(n)},$r);return()=>clearInterval(n)}function ni(e,t){let n=0,r=()=>{let r=Zr(e,t);return r&&(J(r),r.animate(Xr,{duration:Yr,easing:`ease-out`})),!!r||++n>=Qr};if(r())return()=>void 0;let i=setInterval(()=>{r()&&clearInterval(i)},$r);return()=>clearInterval(i)}var ri=(e,t)=>at(e)===`document`&&(e.to===t||V(e)===t);function ii(e,t,r,i,a){let s=!!r,[c,l]=(0,H.useState)(null),p=(0,H.useMemo)(()=>s&&f(),[s]),{role:m}=u(),h=(0,H.useRef)(()=>void 0);return(0,H.useEffect)(()=>{if(!s)return;let e=Z(),n=()=>{let n=ct(e.history.state,t);n!==null&&(h.current(),window.scrollTo({top:n,behavior:`instant`}))};return e.addEventListener(`popstate`,n),()=>e.removeEventListener(`popstate`,n)},[s,t]),(0,H.useEffect)(()=>{if(!p)return;let t,n,r=y(r=>{if(r.kind===`active`&&l(r.key),r.kind===`reveal`&&(l(r.key),t?.(),t=ti(r.key)),r.kind===`focus`&&r.block&&e&&(n?.(),n=ni(e,r.block)),r.kind!==`scroll-to`)return;l(r.key);let i=e&&Zr(e,r.blockId);i&&(J(i),i.animate(Xr,{duration:Yr,easing:`ease-out`}))});return o({kind:`ready`}),()=>{r(),t?.(),n?.()}},[p,e]),(0,H.useMemo)(()=>s?{active:c,isSelf:e=>ri(e,t),useBoard:r,useScene:i,openEmbed:e=>{if(p)return o({kind:`embed-open`,target:e});let t=a?.refId(e);if(!a||!t)return;let r=tt(a.frameSrc(`whiteboard`,t),e);n(async()=>{let{openArtifactModal:e}=await import(`./ArtifactModal-CH9BY3RJ.js`);return{openArtifactModal:e}},__vite__mapDeps([58,1,10,3,4,2,5,6,7,11,12,13,59,30,60,18,37,61,62,42]),import.meta.url).then(({openArtifactModal:t})=>t({allow:a.frameAllow,src:r,title:e.label??V(e)}))},open:n=>{let r=at(n);if(ri(n,t)){let r=e&&n.block?Zr(e,n.block):null;if(!r||!n.block){window.scrollTo({top:0,behavior:`instant`});return}p&&m===`beside`?o({kind:`block-focus`,block:n.block}):st(t,n.block,Z()),h.current(),h.current=J(r),r.animate(Xr,{duration:Yr,easing:`ease-out`})}else p?o({kind:`ref-open`,target:n}):location.assign(`/document/${t}${d(location.search,Ve(V(n),r,n,`document`))}`)}}:null,[s,c,p,m,e,t,r,i,a])}function ai(e){let[t,n]=(0,H.useState)([]);return(0,H.useEffect)(()=>{if(!e)return;let t=()=>{let t=it(e.getEditorState().toJSON());n(e=>JSON.stringify(e)===JSON.stringify(t)?e:t)};return t(),e.registerUpdateListener(t)},[e]),t}function oi(e,t){return N().getChildren().flatMap(n=>{let r=A(n,F),i=e.getElementByKey(n.getKey());if(!r||!i||!t.intersectsNode(i))return[];let a=document.createRange();if(a.selectNodeContents(i),t.compareBoundaryPoints(Range.START_TO_START,a)>0&&a.setStart(t.startContainer,t.startOffset),t.compareBoundaryPoints(Range.END_TO_END,a)<0&&a.setEnd(t.endContainer,t.endOffset),a.collapsed)return[];let o=a.toString();if(!o&&i.textContent)return[];let s=document.createRange();return s.selectNodeContents(i),s.setEnd(a.startContainer,a.startOffset),[{blockId:r,quote:o,start:s.toString().length}]})}var si=200;function ci(e,t){let n=(t instanceof Element?t:t?.parentElement)?.closest(`[contenteditable="true"]`);return!!(n&&n!==e&&e.contains(n))}function li(e,t){let n=e.read(()=>{let t=te();return T(t)?N().getChildren().flatMap(n=>{if(!t.has(n.getKey()))return[];let r=A(n,F),i=e.getElementByKey(n.getKey());return r&&i?[{id:r,element:i}]:[]}):[]});if(n.length){let e=n.map(e=>e.element),r=e.map(e=>e.getBoundingClientRect()),i=t.getBoundingClientRect(),a=document.createRange();return a.selectNodeContents(e[0]),{kind:`block`,blockId:n[0].id,...n.length>1?{blockIds:n.map(e=>e.id)}:{},quote:``,elements:e,range:a,left:Math.min(...r.map(e=>e.left))-i.left,right:Math.max(...r.map(e=>e.right))-i.left,top:r[0].top-i.top,bottom:r.at(-1).bottom-i.top}}let r=window.getSelection(),i=e.getRootElement();if(!r||r.isCollapsed||r.rangeCount===0||!i?.contains(r.anchorNode)||!i.contains(r.focusNode))return null;let a=r.toString().trim(),o=r.getRangeAt(0),s=e.read(()=>oi(e,o));if(!s.length||!a)return null;let c=ci(i,r.anchorNode)&&ci(i,r.focusNode),l=[...o.getClientRects()],u=l[0]??o.getBoundingClientRect(),d=l.at(-1)??u,f=t.getBoundingClientRect();return{blockId:s[0].blockId,...s.length>1?{blockIds:s.map(e=>e.blockId),textRanges:s}:c?{textRanges:s}:{},...c?{kind:`nested`}:{},quote:a.slice(0,500),left:u.left-f.left,bottom:d.bottom-f.top,top:u.top-f.top,right:Math.max(...l.map(e=>e.right),d.right)-f.left,range:o.cloneRange()}}function ui(e,t){let[n,r]=(0,H.useState)(null);return(0,H.useEffect)(()=>{if(!e||!t)return;let n=0,i=()=>{clearTimeout(n),n=window.setTimeout(()=>r(li(e,t)),si)};document.addEventListener(`selectionchange`,i);let a=e.registerUpdateListener(i);window.addEventListener(`scroll`,i,!0),window.addEventListener(`resize`,i);let o=new ResizeObserver(i);return e.getRootElement()&&o.observe(e.getRootElement()),()=>{clearTimeout(n),document.removeEventListener(`selectionchange`,i),a(),window.removeEventListener(`scroll`,i,!0),window.removeEventListener(`resize`,i),o.disconnect()}},[e,t]),[n,(0,H.useCallback)(()=>{r(null),e?.read(()=>T(te()))&&e.update(()=>E(null))},[e]),(0,H.useCallback)(()=>e&&t?li(e,t):null,[e,t])]}function di(){let e=new Set;return{emit:t=>e.forEach(e=>e(t)),subscribe:t=>(e.add(t),()=>e.delete(t))}}export{gt as A,jt as C,Lt as D,Rt as E,At as O,an as S,It as T,qn as _,ai as a,ln as b,qr as c,zr as d,Pr as f,Kn as g,$n as h,ii as i,vt as k,Hr as l,xr as m,ui as n,Jr as o,Nr as p,oi as r,Wr as s,di as t,Ur as u,Un as v,zt as w,sn as x,pn as y};