@datalayer/agent-runtimes 1.5.86 → 1.5.88

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 (105) hide show
  1. package/dist-embed/chunks/{DeckComponent-D4X-rpbh.js → DeckComponent-etBrFG87.js} +1 -1
  2. package/dist-embed/chunks/{DocumentView-Aird-zRf.js → DocumentView-LE7AJ2BO.js} +1 -1
  3. package/dist-embed/chunks/{EphemeralDocument-qnhIdhNh.js → EphemeralDocument-YiGgJGkL.js} +1 -1
  4. package/dist-embed/chunks/{ExcalidrawComponent-C33gsDzG.js → ExcalidrawComponent-C5J8Uqqj.js} +1 -1
  5. package/dist-embed/chunks/{ExcalidrawModal-DHCo94OE.js → ExcalidrawModal-D3cbhMgF.js} +1 -1
  6. package/dist-embed/chunks/{JupyterLexicalExtension-Cb2zt9Ki.js → JupyterLexicalExtension-BipHQ8U3.js} +7 -7
  7. package/dist-embed/chunks/{YouTubePlugin-C0a_9VKl.js → YouTubePlugin-BewlFg9c.js} +1 -1
  8. package/dist-embed/chunks/{ar-SA-G6X2FPQ2-DS3Xmdel.js → ar-SA-G6X2FPQ2-BgdfqrVp.js} +1 -1
  9. package/dist-embed/chunks/{az-AZ-76LH7QW2-DIApsK5M.js → az-AZ-76LH7QW2-xUMz4Jqu.js} +1 -1
  10. package/dist-embed/chunks/{bg-BG-XCXSNQG7-X-aS4Onm.js → bg-BG-XCXSNQG7-UR5Ld32v.js} +1 -1
  11. package/dist-embed/chunks/{bn-BD-2XOGV67Q-1YCe_Jnl.js → bn-BD-2XOGV67Q-CCNH7olK.js} +1 -1
  12. package/dist-embed/chunks/{ca-ES-6MX7JW3Y-D26sHSba.js → ca-ES-6MX7JW3Y-DaZb-gMN.js} +1 -1
  13. package/dist-embed/chunks/{cs-CZ-2BRQDIVT-B5pRYPPF.js → cs-CZ-2BRQDIVT-OaROtN46.js} +1 -1
  14. package/dist-embed/chunks/{da-DK-5WZEPLOC-BfajxBtH.js → da-DK-5WZEPLOC-DrcoMVce.js} +1 -1
  15. package/dist-embed/chunks/{de-DE-XR44H4JA-BovBXD5H.js → de-DE-XR44H4JA-b2_lYxS1.js} +1 -1
  16. package/dist-embed/chunks/{el-GR-BZB4AONW-rLXnfS2l.js → el-GR-BZB4AONW-BOT3RaFd.js} +1 -1
  17. package/dist-embed/chunks/{es-ES-U4NZUMDT-Do4MvuPW.js → es-ES-U4NZUMDT-BVlxd_yM.js} +1 -1
  18. package/dist-embed/chunks/{eu-ES-A7QVB2H4-CldbgpdZ.js → eu-ES-A7QVB2H4-BScAWOoO.js} +1 -1
  19. package/dist-embed/chunks/{fa-IR-HGAKTJCU-C988cp8F.js → fa-IR-HGAKTJCU-Kxnh8bHZ.js} +1 -1
  20. package/dist-embed/chunks/{fi-FI-Z5N7JZ37-BYmFVIh7.js → fi-FI-Z5N7JZ37-BOmDZi5v.js} +1 -1
  21. package/dist-embed/chunks/{fr-FR-RHASNOE6-D2Tarz3u.js → fr-FR-RHASNOE6-GOPhqKT4.js} +1 -1
  22. package/dist-embed/chunks/{gl-ES-HMX3MZ6V-BLuuMSHB.js → gl-ES-HMX3MZ6V-BRZS4fho.js} +1 -1
  23. package/dist-embed/chunks/{he-IL-6SHJWFNN-CyDIOeVd.js → he-IL-6SHJWFNN-MQEVUj2T.js} +1 -1
  24. package/dist-embed/chunks/{hi-IN-IWLTKZ5I-DKCduSTz.js → hi-IN-IWLTKZ5I-D_puNbt2.js} +1 -1
  25. package/dist-embed/chunks/{hu-HU-A5ZG7DT2-CFEUsNFV.js → hu-HU-A5ZG7DT2-VTn7BLHk.js} +1 -1
  26. package/dist-embed/chunks/{id-ID-SAP4L64H-DJgKxRp8.js → id-ID-SAP4L64H-DDpkcMxl.js} +1 -1
  27. package/dist-embed/chunks/{index-CaAB7eph.js → index-BnyTIBRs.js} +1 -1
  28. package/dist-embed/chunks/{index-BvYhxJ42.js → index-D4E_ai6G.js} +1 -1
  29. package/dist-embed/chunks/{it-IT-JPQ66NNP-CB1iVsAn.js → it-IT-JPQ66NNP-Dmm1oVBi.js} +1 -1
  30. package/dist-embed/chunks/{ja-JP-DBVTYXUO-BMEokiIe.js → ja-JP-DBVTYXUO-c8yMMjUO.js} +1 -1
  31. package/dist-embed/chunks/{kaa-6HZHGXH3-NDSx8vED.js → kaa-6HZHGXH3-Cr7KlyI3.js} +1 -1
  32. package/dist-embed/chunks/{kab-KAB-ZGHBKWFO-CDD0AUe8.js → kab-KAB-ZGHBKWFO-C5lvSze2.js} +1 -1
  33. package/dist-embed/chunks/{kk-KZ-P5N5QNE5-DiW940Xv.js → kk-KZ-P5N5QNE5-BWzl0srY.js} +1 -1
  34. package/dist-embed/chunks/{km-KH-HSX4SM5Z-D1yNJSuC.js → km-KH-HSX4SM5Z-D0hsReza.js} +1 -1
  35. package/dist-embed/chunks/{ko-KR-MTYHY66A-gxN7WKqI.js → ko-KR-MTYHY66A-BG6oRC2d.js} +1 -1
  36. package/dist-embed/chunks/{ku-TR-6OUDTVRD-AGx6lASh.js → ku-TR-6OUDTVRD-BcZeKYN4.js} +1 -1
  37. package/dist-embed/chunks/{lt-LT-XHIRWOB4-7aG3WRZ7.js → lt-LT-XHIRWOB4-CDMAwSRa.js} +1 -1
  38. package/dist-embed/chunks/{lv-LV-5QDEKY6T-kYU1Z9N2.js → lv-LV-5QDEKY6T-D2MZFbM-.js} +1 -1
  39. package/dist-embed/chunks/{mr-IN-CRQNXWMA-E1I_f_B2.js → mr-IN-CRQNXWMA-C4tnFlhM.js} +1 -1
  40. package/dist-embed/chunks/{my-MM-5M5IBNSE-BLvme-se.js → my-MM-5M5IBNSE-BeA-YSi-.js} +1 -1
  41. package/dist-embed/chunks/{nb-NO-T6EIAALU-CQe3vLx-.js → nb-NO-T6EIAALU-PoKJfg4d.js} +1 -1
  42. package/dist-embed/chunks/{nl-NL-IS3SIHDZ-DQ5lObK-.js → nl-NL-IS3SIHDZ-Cf4_wadm.js} +1 -1
  43. package/dist-embed/chunks/{nn-NO-6E72VCQL-JwOO_c6b.js → nn-NO-6E72VCQL-xgmyjeCA.js} +1 -1
  44. package/dist-embed/chunks/{oc-FR-POXYY2M6-OYZJk3Hj.js → oc-FR-POXYY2M6-CdWNnVCw.js} +1 -1
  45. package/dist-embed/chunks/{pa-IN-N4M65BXN-B7p6nOzS.js → pa-IN-N4M65BXN-QYWCqzud.js} +1 -1
  46. package/dist-embed/chunks/{percentages-BXMCSKIN-Cz9igCrb.js → percentages-BXMCSKIN-azlLrVPY.js} +3 -3
  47. package/dist-embed/chunks/{pl-PL-T2D74RX3-DiIfEp3O.js → pl-PL-T2D74RX3-CR9S6Ibc.js} +1 -1
  48. package/dist-embed/chunks/{pt-BR-5N22H2LF-7rqxomNz.js → pt-BR-5N22H2LF-BdXbK3ya.js} +1 -1
  49. package/dist-embed/chunks/{pt-PT-UZXXM6DQ-DE-uZxHk.js → pt-PT-UZXXM6DQ-2XA1j-L3.js} +1 -1
  50. package/dist-embed/chunks/{ro-RO-JPDTUUEW-BlMk-egr.js → ro-RO-JPDTUUEW-BtXn8ZEx.js} +1 -1
  51. package/dist-embed/chunks/{ru-RU-B4JR7IUQ-caVTslk_.js → ru-RU-B4JR7IUQ-CQX4iIyB.js} +1 -1
  52. package/dist-embed/chunks/{si-LK-N5RQ5JYF-DT4Sk0wC.js → si-LK-N5RQ5JYF-HKjZkrpb.js} +1 -1
  53. package/dist-embed/chunks/{sk-SK-C5VTKIMK-DS8_VUwQ.js → sk-SK-C5VTKIMK-D0qjylR3.js} +1 -1
  54. package/dist-embed/chunks/{sl-SI-NN7IZMDC-Dm37QL2T.js → sl-SI-NN7IZMDC-vxztaOUj.js} +1 -1
  55. package/dist-embed/chunks/{subset-shared.chunk-ByorZVMF.js → subset-shared.chunk-DEWjD_XG.js} +1 -1
  56. package/dist-embed/chunks/{subset-worker.chunk-CDbohCL0.js → subset-worker.chunk-DWTibNnY.js} +1 -1
  57. package/dist-embed/chunks/{sv-SE-XGPEYMSR-Ds2_OJfr.js → sv-SE-XGPEYMSR-N-SacX3h.js} +1 -1
  58. package/dist-embed/chunks/{ta-IN-2NMHFXQM-DalALtL3.js → ta-IN-2NMHFXQM-9GMEN3M3.js} +1 -1
  59. package/dist-embed/chunks/{th-TH-HPSO5L25-Db3wq-Mt.js → th-TH-HPSO5L25-CeESdLid.js} +1 -1
  60. package/dist-embed/chunks/{tr-TR-DEFEU3FU-BwZ2BWFh.js → tr-TR-DEFEU3FU-BjBigRhJ.js} +1 -1
  61. package/dist-embed/chunks/transformers.web-Br6X7w0a.js +42 -0
  62. package/dist-embed/chunks/{uk-UA-QMV73CPH-CvvKxEh4.js → uk-UA-QMV73CPH-v4nMobEN.js} +1 -1
  63. package/dist-embed/chunks/{vi-VN-M7AON7JQ-CWecJG5X.js → vi-VN-M7AON7JQ-D5thvMrO.js} +1 -1
  64. package/dist-embed/chunks/{zh-CN-LNUGB5OW-Bt8FQMA4.js → zh-CN-LNUGB5OW-Cn3ae1JT.js} +1 -1
  65. package/dist-embed/chunks/{zh-HK-E62DVLB3-D-aO7Cxy.js → zh-HK-E62DVLB3-OlNuka00.js} +1 -1
  66. package/dist-embed/chunks/{zh-TW-RAJ6MFWO-DhGr0I8R.js → zh-TW-RAJ6MFWO-DAwaB-Vu.js} +1 -1
  67. package/dist-embed/datalayer-app-main.js +8 -8
  68. package/lib/apps/apps/checks.d.ts +1 -1
  69. package/lib/apps/apps/checks.js +1 -1
  70. package/lib/apps/apps/computer.d.ts +1 -1
  71. package/lib/apps/apps/computer.js +1 -1
  72. package/lib/apps/apps/pluginPair.d.ts +1 -1
  73. package/lib/apps/apps/rules.d.ts +1 -1
  74. package/lib/apps/apps/rules.js +2 -2
  75. package/lib/apps/apps/visitorToken.d.ts +1 -1
  76. package/lib/apps/apps/visitorToken.js +1 -1
  77. package/lib/apps/core/appFiles.js +1 -1
  78. package/lib/apps/plugins/a2ui-surface/toolResult.d.ts +1 -1
  79. package/lib/apps/plugins/a2ui-surface/toolResult.js +1 -1
  80. package/lib/apps/plugins/app-page/appPageModel.d.ts +1 -1
  81. package/lib/apps/plugins/app-page/appPageModel.js +1 -1
  82. package/lib/components/cards/ToolApprovalCard.js +5 -2
  83. package/lib/portable/hosts/client.d.ts +11 -1
  84. package/lib/portable/hosts/client.js +12 -6
  85. package/lib/portable/hosts/contracts.json +9 -3
  86. package/lib/portable/hosts/index.d.ts +1 -1
  87. package/lib/portable/records.d.ts +1 -1
  88. package/lib/portable/records.js +1 -1
  89. package/lib/portable/semantic-events.json +3 -3
  90. package/lib/portable/semanticOfAgUi.d.ts +1 -1
  91. package/lib/runtimes/variants.d.ts +10 -8
  92. package/lib/runtimes/variants.js +14 -9
  93. package/lib/specs/agents/agents.d.ts +1 -0
  94. package/lib/specs/agents/agents.js +49 -0
  95. package/lib/specs/apps.js +32 -32
  96. package/lib/specs/harnesses.d.ts +1 -0
  97. package/lib/specs/harnesses.js +69 -18
  98. package/lib/specs/index.d.ts +1 -1
  99. package/lib/specs/index.js +1 -1
  100. package/lib/types/agentspecs.d.ts +2 -0
  101. package/package.json +1 -1
  102. package/scripts/codegen/generate_apps.py +1 -1
  103. package/scripts/codegen/generate_harnesses.py +2 -0
  104. package/scripts/validate_pap_examples.py +1 -1
  105. package/dist-embed/chunks/transformers.web-CLaqP_Vm.js +0 -42
@@ -88,7 +88,7 @@ summary.Collapsible__title::marker {
88
88
  `),r=[];for(const o of t)r.push("> "+o);return r.join(`
89
89
  `)},regExp:/^>\s/,replace:(n,e,t,r)=>{if(r){const s=n.getPreviousSibling();if(Vn(s)){s.splice(s.getChildrenSize(),0,[vt(),...e]),s.select(0,0),n.remove();return}}const o=Ln();o.append(...e),n.replace(o),o.select(0,0)},type:"element"},Rv={dependencies:[Nt],export:n=>{if(!st(n))return null;const e=n.getTextContent();return"```"+(n.getLanguage()||"")+(e?`
90
90
  `+e:"")+"\n```"},regExp:/^```(\w{1,10})?\s/,replace:rm(n=>qr(n?n[1]:void 0)),type:"element"},Av={dependencies:[Yt,yn],export:(n,e)=>Z(n)?va(n,e,0):null,regExp:/^(\s*)[-*+]\s/,replace:Pu("bullet"),type:"element"},Mv={dependencies:[Yt,yn],export:(n,e)=>Z(n)?va(n,e,0):null,regExp:/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,replace:Pu("check"),type:"element"},$v={dependencies:[Yt,yn],export:(n,e)=>Z(n)?va(n,e,0):null,regExp:/^(\s*)(\d{1,})\.\s/,replace:Pu("number"),type:"element"},Dv={format:["code"],tag:"`",type:"text-format"},Pv={format:["bold","italic"],tag:"***",type:"text-format"},jv={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},Fv={format:["bold"],tag:"**",type:"text-format"},Bv={format:["bold"],intraword:!1,tag:"__",type:"text-format"},Uv={format:["strikethrough"],tag:"~~",type:"text-format"},zv={format:["italic"],tag:"*",type:"text-format"},Kv={format:["italic"],intraword:!1,tag:"_",type:"text-format"},Wv={dependencies:[gn],export:(n,e,t)=>{if(!Pe(n))return null;const r=`[${n.getTextContent()}](${n.getURL()})`,o=n.getFirstChild();return n.getChildrenSize()===1&&oe(o)?t(o,r):r},importRegExp:/(?:\[([^[]+)\])(?:\(([^(]+)\))/,regExp:/(?:\[([^[]+)\])(?:\(([^(]+)\))$/,replace:(n,e)=>{const[,t,r]=e,o=Mo(r),s=De(t);s.setFormat(n.getFormat()),o.append(s),n.replace(o)},trigger:")",type:"text-match"},sm=[Lv,Ov,Rv,Av,$v],im=[Dv,Pv,jv,Fv,Bv,zv,Kv,Uv],am=[Wv],Hv=[...sm,...im,...am];function UM(n,e=Hv){return vv(e)(n)}const Jv={dependencies:[mu],export:n=>ch(n)?"***":null,regExp:/^(---|\*\*\*|___)\s?$/,replace:(n,e,t,r)=>{const o=ba();r||n.getNextSibling()!=null?n.replace(o):n.insertBefore(o)},type:"element"},qv={dependencies:[Jr],export:(n,e,t)=>Hn(n)?`![${n.getAltText()}](${n.getSrc()})`:null,importRegExp:/!(?:\[([^[]*)\])(?:\(([^(]+)\))/,regExp:/!(?:\[([^[]*)\])(?:\(([^(]+)\))$/,replace:(n,e)=>{const[,t,r]=e,o=xa({altText:t,maxWidth:800,src:r});n.replace(o)},trigger:")",type:"text-match"},Vv={dependencies:[ir],export:n=>{if(!ht(n)||n.getChildrenSize()!==1)return null;const e=n.getFirstChild();return!Rr(e)||e.__inline?null:`$$${e.getEquation()}$$`},regExp:/^\$\$(.+?)\$\$\s?$/,replace:(n,e,t)=>{const r=ne();r.append(ya(t[1].trim(),!1)),n.replace(r)},type:"element"},Yv={dependencies:[ir],export:(n,e,t)=>Rr(n)?`$${n.getEquation()}$`:null,importRegExp:/\$([^$].+?)\$/,regExp:/\$([^$].+?)\$$/,replace:(n,e)=>{const[,t]=e,r=ya(t,!0);n.replace(r)},trigger:"$",type:"text-match"},lm=/^(?:\|)(.+)(?:\|)\s?$/,Xv=/^:?-+:?$/,Gv={dependencies:[Gt,Wo,Xt],export:(n,e)=>{if(!be(n))return null;const t=[];for(const r of n.getChildren()){const o=[];if(ce(r))for(const s of r.getChildren())q(s)&&o.push(e(s));t.push(`| ${o.join(" | ")} |`),t.length===1&&ce(r)&&r.getChildrenSize()>0&&r.getChildren().every(s=>J(s)&&s.hasHeader())&&t.push(`| ${o.map(()=>"---").join(" | ")} |`)}return t.join(`
91
- `)},regExp:lm,replace:(n,e,t)=>{const r=Vf(t[0]);if(r==null)return;const o=[r];let s=n.getPreviousSibling(),i=r.length;for(;s&&!(!ht(s)||s.getChildrenSize()!==1);){const f=s.getFirstChild();if(!oe(f))break;const d=Vf(f.getTextContent());if(d==null)break;i=Math.max(i,d.length),o.unshift(d);const g=s.getPreviousSibling();s.remove(),s=g}const a=o.findIndex(f=>f.every(d=>Xv.test(d.getTextContent().trim())));if(a===0){const f=n.getPreviousSibling();if(be(f)){const d=f.getLastChild();ce(d)&&d.getChildren().forEach(g=>{J(g)&&g.setHeaderStyles(te.ROW,te.ROW)}),n.remove();return}}const l=a>0?a:0;if(a>=0&&o.splice(a,1),o.length===0){n.remove();return}const c=Ho();for(const[f,d]of o.entries()){const g=pn();c.append(g);for(let h=0;h<i;h++){const _=h<d.length?d[h]:cm(null);f<l&&_.setHeaderStyles(te.ROW,te.ROW),g.append(_)}}const u=n.getPreviousSibling();be(u)&&Zv(u)===i?(u.append(...c.getChildren()),n.remove()):n.replace(c),c.selectEnd()},type:"element"};function Zv(n){const e=n.getFirstChild();return ce(e)?e.getChildrenSize():0}const cm=n=>{const e=lt(te.NO_STATUS),t=ne();return n!=null&&t.append(De(n.trim())),e.append(t),e},Vf=n=>{const e=n.match(lm);return!e||!e[1]?null:e[1].split("|").map(t=>cm(t))},Qv=[Vv,Gv,Jv,qv,Yv,Mv,...sm,...im,...am],e1=S.lazy(()=>me(()=>import("./ExcalidrawComponent-C33gsDzG.js"),[],import.meta.url));function t1(n){const e=n.getAttribute("data-lexical-excalidraw-json"),t=window.getComputedStyle(n),r=t.getPropertyValue("height"),o=t.getPropertyValue("width"),s=!r||r==="inherit"?"inherit":parseInt(r,10),i=!o||o==="inherit"?"inherit":parseInt(o,10);return e?{node:ju(e,i,s)}:null}class Yn extends Bt{__data;__width;__height;static getType(){return"excalidraw"}static clone(e){return new Yn(e.__data,e.__width,e.__height,e.__key)}static importJSON(e){return new Yn(e.data,e.width??"inherit",e.height??"inherit").updateFromJSON(e)}exportJSON(){return{...super.exportJSON(),data:this.__data,height:this.__height==="inherit"?void 0:this.__height,width:this.__width==="inherit"?void 0:this.__width}}constructor(e="[]",t="inherit",r="inherit",o){super(o),this.__data=e,this.__width=t,this.__height=r}createDOM(e){const t=document.createElement("span"),o=e.theme.image;return o!==void 0&&(t.className=o),t}updateDOM(){return!1}static importDOM(){return{span:e=>e.hasAttribute("data-lexical-excalidraw-json")?{conversion:t1,priority:1}:null}}exportDOM(e){const t=document.createElement("span");t.style.display="inline-block";const r=e.getElementByKey(this.getKey());if(r!==null){const o=r.querySelector("svg");o!==null&&(t.innerHTML=o.outerHTML)}return t.style.width=this.__width==="inherit"?"inherit":`${this.__width}px`,t.style.height=this.__height==="inherit"?"inherit":`${this.__height}px`,t.setAttribute("data-lexical-excalidraw-json",this.__data),{element:t}}setData(e){const t=this.getWritable();t.__data=e}getWidth(){return this.getLatest().__width}setWidth(e){const t=this.getWritable();t.__width=e}getHeight(){return this.getLatest().__height}setHeight(e){const t=this.getWritable();t.__height=e}decorate(e,t){return x.jsx(e1,{nodeKey:this.getKey(),data:this.__data,width:this.__width,height:this.__height})}}function ju(n="[]",e="inherit",t="inherit"){return new Yn(n,e,t)}function Fu(n){return n instanceof Yn}const n1=Object.freeze(Object.defineProperty({__proto__:null,$createExcalidrawNode:ju,$isExcalidrawNode:Fu,ExcalidrawNode:Yn},Symbol.toStringTag,{value:"Module"}));function r1(n,e){const t=n.split(/\s+/).map(r=>parseFloat(r)).filter(r=>!Number.isNaN(r)&&r>0);return t.length===e?t:Array.from({length:e},()=>1)}function cc(n){const e=n.getFormatType();return e==="center"||e==="right"||e==="justify"?e:"left"}function fr(n,e){return Bu(n.getChildren(),e)}function Bu(n,e){const t=[];for(const r of n)if(ue(r))t.push({kind:"break"});else if(bt(r))t.push({kind:"text",text:" ",link:e});else if(oe(r)){const o=r.getTextContent();o&&t.push({kind:"text",text:o,bold:r.hasFormat("bold"),italic:r.hasFormat("italic"),code:r.hasFormat("code"),underline:r.hasFormat("underline"),strikethrough:r.hasFormat("strikethrough"),subscript:r.hasFormat("subscript"),superscript:r.hasFormat("superscript"),highlight:r.hasFormat("highlight"),link:e})}else if(Pe(r))t.push(...fr(r,r.getURL()));else if(Rr(r))t.push({kind:"equation",equation:r.getEquation(),key:r.getKey()});else if(q(r))t.push(...fr(r,e));else if(It(r)){const o=r.getTextContent();o&&t.push({kind:"text",text:o,link:e})}return t}function vi(n){const e=[],t=r=>{e.length&&r.length&&e.push({kind:"break"}),e.push(...r)};for(const r of n)switch(r.kind){case"heading":t(r.inlines.map(o=>o.kind==="text"?{...o,bold:!0}:o));break;case"paragraph":t(r.inlines);break;case"quote":case"collapsible":t(vi(r.blocks));break;case"list":r.items.forEach((o,s)=>{const i=r.ordered?`${r.start+s}. `:"• ";t([{kind:"text",text:i},...vi(o.blocks)])});break;case"code":t([{kind:"text",text:r.text,code:!0}]);break;case"equation":t([{kind:"equation",equation:r.equation,key:r.key}]);break;case"image":t([{kind:"text",text:r.alt||"[image]",italic:!0}]);break;case"embed":t([{kind:"text",text:r.label,link:r.url}]);break;case"table":r.rows.forEach(o=>t(o.flatMap((s,i)=>[...i?[{kind:"text",text:" | "}]:[],...s.inlines])));break;case"columns":r.columns.forEach(o=>t(vi(o)));break}return e}function o1(n){const e=[];for(const t of n.getChildren()){if(!le(t))continue;const r=t.getFirstChild();if(t.getChildrenSize()===1&&Z(r)){const i=Yi(r),a=e[e.length-1];a&&i?a.blocks.push(i):i&&e.push({checked:null,blocks:[i]});continue}const o=[],s=[];for(const i of t.getChildren()){if(q(i)&&!Pe(i)){const a=Yi(i);if(a&&a.kind!=="paragraph"){s.length&&(o.push({kind:"paragraph",inlines:[...s],align:"left",indent:0}),s.length=0),o.push(a);continue}}s.push(...Bu([i]))}(s.length||o.length===0)&&o.unshift({kind:"paragraph",inlines:s,align:"left",indent:0}),e.push({checked:n.getListType()==="check"?t.getChecked()===!0:null,blocks:o})}return e}function Yi(n){if(Wr(n))return{kind:"heading",level:Math.min(6,Math.max(1,Number(n.getTag().slice(1))||1)),inlines:fr(n),align:cc(n),indent:n.getIndent()};if(Vn(n))return{kind:"quote",blocks:[{kind:"paragraph",inlines:fr(n),align:"left",indent:0}]};if(Z(n))return{kind:"list",ordered:n.getListType()==="number",start:n.getStart(),items:o1(n)};if(st(n))return{kind:"code",language:n.getLanguage()??"python",text:n.getTextContent(),executable:!0,key:n.getKey()};if(je(n))return{kind:"code",language:n.getLanguage()??null,text:n.getTextContent(),executable:!1,key:n.getKey()};if(Cu(n))return{kind:"outputs",outputs:n.getOutputs(),key:n.getKey()};if(be(n)){const e=[];for(const t of n.getChildren()){if(!ce(t))continue;const r=[];for(const o of t.getChildren())J(o)&&r.push({header:o.hasHeader(),colSpan:Math.max(1,o.getColSpan()),inlines:vi(cs(o.getChildren()))});e.push(r)}return{kind:"table",rows:e}}if(Ci(n)){const e=n.getChildren().filter(Au),t=n.getTemplateColumns().trim(),r=Math.max(e.length,t?t.split(/\s+/).length:0);return{kind:"columns",weights:r1(n.getTemplateColumns(),r).slice(0,e.length),columns:e.map(o=>cs(o.getChildren()))}}if(Pt(n)){const e=n.getChildren().find(xi),t=n.getChildren().find(Lu);return{kind:"collapsible",title:e?fr(e):[],blocks:t?cs(t.getChildren()):[],open:n.getOpen()}}if(ch(n))return{kind:"rule"};if(Hn(n))return{kind:"image",src:n.getSrc(),alt:n.getAltText(),key:n.getKey()};if(Rr(n))return{kind:"equation",equation:n.getEquation(),key:n.getKey()};if(W_(n)){const e=n.getId();return{kind:"embed",label:`YouTube video ${e}`,url:`https://www.youtube.com/watch?v=${e}`,key:n.getKey()}}if(Fu(n))return{kind:"drawing",key:n.getKey(),label:"Drawing"};if(Du(n)){const{url:e,title:t}=n.getVideo();return Tn(e)?{kind:"embed",label:t?`Loom video: ${t}`:"Loom video",url:e,key:n.getKey()}:null}if(ht(n)){const e=fr(n),t=n.getChildrenSize()===1?n.getFirstChild():null;return t&&Rr(t)&&!t.__inline?{kind:"equation",equation:t.getEquation(),key:t.getKey()}:t&&Hn(t)?{kind:"image",src:t.getSrc(),alt:t.getAltText(),key:t.getKey()}:{kind:"paragraph",inlines:e,align:cc(n),indent:n.getIndent()}}if(q(n)){const e=cs(n.getChildren());if(e.length)return e.length===1?e[0]:{kind:"quote",blocks:e};const t=fr(n);return t.length?{kind:"paragraph",inlines:t,align:"left",indent:0}:null}return It(n)?{kind:"drawing",key:n.getKey(),label:n.getTextContent()||n.getType()}:null}function um(n){return q(n)&&!Pe(n)&&!n.isInline()&&!ht(n)||be(n)||Z(n)||je(n)||Hn(n)||Fu(n)||W_(n)||Du(n)||Rr(n)&&!n.__inline}function s1(n){const e=[];let t=[];const r=()=>{if(t.length){const o=Bu(t);o.length&&e.push({kind:"paragraph",inlines:o,align:cc(n),indent:n.getIndent()}),t=[]}};for(const o of n.getChildren())if(um(o)){r();const s=Yi(o);s&&e.push(s)}else t.push(o);return r(),e}function cs(n){const e=[];for(const t of n){if(ht(t)&&t.getChildren().some(um)){e.push(...s1(t));continue}const r=Yi(t);r&&e.push(r)}return e}function dm(n){return n.map(e=>e.kind==="text"?e.text:e.kind==="break"?`
91
+ `)},regExp:lm,replace:(n,e,t)=>{const r=Vf(t[0]);if(r==null)return;const o=[r];let s=n.getPreviousSibling(),i=r.length;for(;s&&!(!ht(s)||s.getChildrenSize()!==1);){const f=s.getFirstChild();if(!oe(f))break;const d=Vf(f.getTextContent());if(d==null)break;i=Math.max(i,d.length),o.unshift(d);const g=s.getPreviousSibling();s.remove(),s=g}const a=o.findIndex(f=>f.every(d=>Xv.test(d.getTextContent().trim())));if(a===0){const f=n.getPreviousSibling();if(be(f)){const d=f.getLastChild();ce(d)&&d.getChildren().forEach(g=>{J(g)&&g.setHeaderStyles(te.ROW,te.ROW)}),n.remove();return}}const l=a>0?a:0;if(a>=0&&o.splice(a,1),o.length===0){n.remove();return}const c=Ho();for(const[f,d]of o.entries()){const g=pn();c.append(g);for(let h=0;h<i;h++){const _=h<d.length?d[h]:cm(null);f<l&&_.setHeaderStyles(te.ROW,te.ROW),g.append(_)}}const u=n.getPreviousSibling();be(u)&&Zv(u)===i?(u.append(...c.getChildren()),n.remove()):n.replace(c),c.selectEnd()},type:"element"};function Zv(n){const e=n.getFirstChild();return ce(e)?e.getChildrenSize():0}const cm=n=>{const e=lt(te.NO_STATUS),t=ne();return n!=null&&t.append(De(n.trim())),e.append(t),e},Vf=n=>{const e=n.match(lm);return!e||!e[1]?null:e[1].split("|").map(t=>cm(t))},Qv=[Vv,Gv,Jv,qv,Yv,Mv,...sm,...im,...am],e1=S.lazy(()=>me(()=>import("./ExcalidrawComponent-C5J8Uqqj.js"),[],import.meta.url));function t1(n){const e=n.getAttribute("data-lexical-excalidraw-json"),t=window.getComputedStyle(n),r=t.getPropertyValue("height"),o=t.getPropertyValue("width"),s=!r||r==="inherit"?"inherit":parseInt(r,10),i=!o||o==="inherit"?"inherit":parseInt(o,10);return e?{node:ju(e,i,s)}:null}class Yn extends Bt{__data;__width;__height;static getType(){return"excalidraw"}static clone(e){return new Yn(e.__data,e.__width,e.__height,e.__key)}static importJSON(e){return new Yn(e.data,e.width??"inherit",e.height??"inherit").updateFromJSON(e)}exportJSON(){return{...super.exportJSON(),data:this.__data,height:this.__height==="inherit"?void 0:this.__height,width:this.__width==="inherit"?void 0:this.__width}}constructor(e="[]",t="inherit",r="inherit",o){super(o),this.__data=e,this.__width=t,this.__height=r}createDOM(e){const t=document.createElement("span"),o=e.theme.image;return o!==void 0&&(t.className=o),t}updateDOM(){return!1}static importDOM(){return{span:e=>e.hasAttribute("data-lexical-excalidraw-json")?{conversion:t1,priority:1}:null}}exportDOM(e){const t=document.createElement("span");t.style.display="inline-block";const r=e.getElementByKey(this.getKey());if(r!==null){const o=r.querySelector("svg");o!==null&&(t.innerHTML=o.outerHTML)}return t.style.width=this.__width==="inherit"?"inherit":`${this.__width}px`,t.style.height=this.__height==="inherit"?"inherit":`${this.__height}px`,t.setAttribute("data-lexical-excalidraw-json",this.__data),{element:t}}setData(e){const t=this.getWritable();t.__data=e}getWidth(){return this.getLatest().__width}setWidth(e){const t=this.getWritable();t.__width=e}getHeight(){return this.getLatest().__height}setHeight(e){const t=this.getWritable();t.__height=e}decorate(e,t){return x.jsx(e1,{nodeKey:this.getKey(),data:this.__data,width:this.__width,height:this.__height})}}function ju(n="[]",e="inherit",t="inherit"){return new Yn(n,e,t)}function Fu(n){return n instanceof Yn}const n1=Object.freeze(Object.defineProperty({__proto__:null,$createExcalidrawNode:ju,$isExcalidrawNode:Fu,ExcalidrawNode:Yn},Symbol.toStringTag,{value:"Module"}));function r1(n,e){const t=n.split(/\s+/).map(r=>parseFloat(r)).filter(r=>!Number.isNaN(r)&&r>0);return t.length===e?t:Array.from({length:e},()=>1)}function cc(n){const e=n.getFormatType();return e==="center"||e==="right"||e==="justify"?e:"left"}function fr(n,e){return Bu(n.getChildren(),e)}function Bu(n,e){const t=[];for(const r of n)if(ue(r))t.push({kind:"break"});else if(bt(r))t.push({kind:"text",text:" ",link:e});else if(oe(r)){const o=r.getTextContent();o&&t.push({kind:"text",text:o,bold:r.hasFormat("bold"),italic:r.hasFormat("italic"),code:r.hasFormat("code"),underline:r.hasFormat("underline"),strikethrough:r.hasFormat("strikethrough"),subscript:r.hasFormat("subscript"),superscript:r.hasFormat("superscript"),highlight:r.hasFormat("highlight"),link:e})}else if(Pe(r))t.push(...fr(r,r.getURL()));else if(Rr(r))t.push({kind:"equation",equation:r.getEquation(),key:r.getKey()});else if(q(r))t.push(...fr(r,e));else if(It(r)){const o=r.getTextContent();o&&t.push({kind:"text",text:o,link:e})}return t}function vi(n){const e=[],t=r=>{e.length&&r.length&&e.push({kind:"break"}),e.push(...r)};for(const r of n)switch(r.kind){case"heading":t(r.inlines.map(o=>o.kind==="text"?{...o,bold:!0}:o));break;case"paragraph":t(r.inlines);break;case"quote":case"collapsible":t(vi(r.blocks));break;case"list":r.items.forEach((o,s)=>{const i=r.ordered?`${r.start+s}. `:"• ";t([{kind:"text",text:i},...vi(o.blocks)])});break;case"code":t([{kind:"text",text:r.text,code:!0}]);break;case"equation":t([{kind:"equation",equation:r.equation,key:r.key}]);break;case"image":t([{kind:"text",text:r.alt||"[image]",italic:!0}]);break;case"embed":t([{kind:"text",text:r.label,link:r.url}]);break;case"table":r.rows.forEach(o=>t(o.flatMap((s,i)=>[...i?[{kind:"text",text:" | "}]:[],...s.inlines])));break;case"columns":r.columns.forEach(o=>t(vi(o)));break}return e}function o1(n){const e=[];for(const t of n.getChildren()){if(!le(t))continue;const r=t.getFirstChild();if(t.getChildrenSize()===1&&Z(r)){const i=Yi(r),a=e[e.length-1];a&&i?a.blocks.push(i):i&&e.push({checked:null,blocks:[i]});continue}const o=[],s=[];for(const i of t.getChildren()){if(q(i)&&!Pe(i)){const a=Yi(i);if(a&&a.kind!=="paragraph"){s.length&&(o.push({kind:"paragraph",inlines:[...s],align:"left",indent:0}),s.length=0),o.push(a);continue}}s.push(...Bu([i]))}(s.length||o.length===0)&&o.unshift({kind:"paragraph",inlines:s,align:"left",indent:0}),e.push({checked:n.getListType()==="check"?t.getChecked()===!0:null,blocks:o})}return e}function Yi(n){if(Wr(n))return{kind:"heading",level:Math.min(6,Math.max(1,Number(n.getTag().slice(1))||1)),inlines:fr(n),align:cc(n),indent:n.getIndent()};if(Vn(n))return{kind:"quote",blocks:[{kind:"paragraph",inlines:fr(n),align:"left",indent:0}]};if(Z(n))return{kind:"list",ordered:n.getListType()==="number",start:n.getStart(),items:o1(n)};if(st(n))return{kind:"code",language:n.getLanguage()??"python",text:n.getTextContent(),executable:!0,key:n.getKey()};if(je(n))return{kind:"code",language:n.getLanguage()??null,text:n.getTextContent(),executable:!1,key:n.getKey()};if(Cu(n))return{kind:"outputs",outputs:n.getOutputs(),key:n.getKey()};if(be(n)){const e=[];for(const t of n.getChildren()){if(!ce(t))continue;const r=[];for(const o of t.getChildren())J(o)&&r.push({header:o.hasHeader(),colSpan:Math.max(1,o.getColSpan()),inlines:vi(cs(o.getChildren()))});e.push(r)}return{kind:"table",rows:e}}if(Ci(n)){const e=n.getChildren().filter(Au),t=n.getTemplateColumns().trim(),r=Math.max(e.length,t?t.split(/\s+/).length:0);return{kind:"columns",weights:r1(n.getTemplateColumns(),r).slice(0,e.length),columns:e.map(o=>cs(o.getChildren()))}}if(Pt(n)){const e=n.getChildren().find(xi),t=n.getChildren().find(Lu);return{kind:"collapsible",title:e?fr(e):[],blocks:t?cs(t.getChildren()):[],open:n.getOpen()}}if(ch(n))return{kind:"rule"};if(Hn(n))return{kind:"image",src:n.getSrc(),alt:n.getAltText(),key:n.getKey()};if(Rr(n))return{kind:"equation",equation:n.getEquation(),key:n.getKey()};if(W_(n)){const e=n.getId();return{kind:"embed",label:`YouTube video ${e}`,url:`https://www.youtube.com/watch?v=${e}`,key:n.getKey()}}if(Fu(n))return{kind:"drawing",key:n.getKey(),label:"Drawing"};if(Du(n)){const{url:e,title:t}=n.getVideo();return Tn(e)?{kind:"embed",label:t?`Loom video: ${t}`:"Loom video",url:e,key:n.getKey()}:null}if(ht(n)){const e=fr(n),t=n.getChildrenSize()===1?n.getFirstChild():null;return t&&Rr(t)&&!t.__inline?{kind:"equation",equation:t.getEquation(),key:t.getKey()}:t&&Hn(t)?{kind:"image",src:t.getSrc(),alt:t.getAltText(),key:t.getKey()}:{kind:"paragraph",inlines:e,align:cc(n),indent:n.getIndent()}}if(q(n)){const e=cs(n.getChildren());if(e.length)return e.length===1?e[0]:{kind:"quote",blocks:e};const t=fr(n);return t.length?{kind:"paragraph",inlines:t,align:"left",indent:0}:null}return It(n)?{kind:"drawing",key:n.getKey(),label:n.getTextContent()||n.getType()}:null}function um(n){return q(n)&&!Pe(n)&&!n.isInline()&&!ht(n)||be(n)||Z(n)||je(n)||Hn(n)||Fu(n)||W_(n)||Du(n)||Rr(n)&&!n.__inline}function s1(n){const e=[];let t=[];const r=()=>{if(t.length){const o=Bu(t);o.length&&e.push({kind:"paragraph",inlines:o,align:cc(n),indent:n.getIndent()}),t=[]}};for(const o of n.getChildren())if(um(o)){r();const s=Yi(o);s&&e.push(s)}else t.push(o);return r(),e}function cs(n){const e=[];for(const t of n){if(ht(t)&&t.getChildren().some(um)){e.push(...s1(t));continue}const r=Yi(t);r&&e.push(r)}return e}function dm(n){return n.map(e=>e.kind==="text"?e.text:e.kind==="break"?`
92
92
  `:e.equation).join("")}function i1(){const n=cs(se().getChildren()),e=n.find(t=>t.kind==="heading");return{blocks:n,title:e&&e.kind==="heading"?dm(e.inlines):null}}function Uu(n){return n.getEditorState().read(i1)}const fi=["Helvetica","Helvetica-Bold","Helvetica-Oblique","Helvetica-BoldOblique","Courier","Courier-Bold"],Yf=[278,278,355,556,556,889,667,191,333,333,389,584,278,333,278,278,556,556,556,556,556,556,556,556,556,556,278,278,584,584,584,556,1015,667,667,722,722,667,611,778,722,278,500,667,556,833,722,778,667,778,722,667,611,722,667,944,667,667,611,278,278,278,469,556,333,556,556,500,556,556,278,556,556,222,222,500,222,833,556,556,556,556,333,500,278,556,500,722,500,500,500,334,260,334,584],Xf=[278,333,474,556,556,889,722,238,333,333,389,584,278,333,278,278,556,556,556,556,556,556,556,556,556,556,333,333,584,584,584,611,975,722,722,722,722,667,611,778,722,278,556,722,611,833,722,778,667,778,722,667,611,722,667,944,667,667,611,333,278,333,584,556,333,556,611,556,611,556,333,611,611,278,278,556,278,889,611,611,611,611,389,556,333,611,556,778,556,556,500,389,280,389,584],a1={"—":[1e3,1e3],"–":[556,556],"•":[350,350],"‘":[222,278],"’":[222,278],"“":[333,500],"”":[333,500],"…":[1e3,1e3],"€":[556,556],"·":[278,278],"×":[584,584],"°":[400,400],"±":[584,584]," ":[278,278],"©":[737,737],"®":[737,737],"™":[1e3,1e3],"«":[556,556],"»":[556,556],"§":[556,556],"¶":[537,556]},l1={"−":"-","→":"->","←":"<-","⇒":"=>","≤":"<=","≥":">=","≠":"!=","≈":"~","∎":"#","■":"#","□":"[ ]","☐":"[ ]","☑":"[x]","☒":"[x]","✓":"v","✔":"v","▸":">","▾":"v"," ":" "," ":" "," ":" ","​":"","\uFEFF":"","­":""},Gf={"€":128,"‚":130,ƒ:131,"„":132,"…":133,"†":134,"‡":135,"ˆ":136,"‰":137,Š:138,"‹":139,Œ:140,Ž:142,"‘":145,"’":146,"“":147,"”":148,"•":149,"–":150,"—":151,"˜":152,"™":153,š:154,"›":155,œ:156,ž:158,Ÿ:159};function c1(n){const e=[];let t="";for(const r of n){const o=l1[r],s=o!==void 0?o:r;for(const i of s){const a=i.codePointAt(0)??63;if(a<128||a>=160&&a<=255)e.push(a),t+=i;else if(Gf[i]!==void 0)e.push(Gf[i]),t+=i;else{const l=i.normalize("NFD").replace(/[̀-ͯ]/g,""),c=l.codePointAt(0)??63;l.length===1&&c<128?(e.push(c),t+=l):(e.push(63),t+="?")}}}return{bytes:e,text:t}}function u1(n){return n==="Helvetica-Bold"||n==="Helvetica-BoldOblique"}function d1(n,e){if(e==="Courier"||e==="Courier-Bold")return 600;const t=u1(e),r=n.codePointAt(0)??32;if(r>=32&&r<=126)return(t?Xf:Yf)[r-32];const o=a1[n];if(o)return o[t?1:0];const s=n.normalize("NFD").replace(/[̀-ͯ]/g,""),i=s.codePointAt(0)??32;return s.length===1&&i>=32&&i<=126?(t?Xf:Yf)[i-32]:t?611:556}function cr(n,e,t){let r=0;for(const o of n)r+=d1(o,e);return r*t/1e3}function Zf(n){return n.code?n.bold?"Courier-Bold":"Courier":n.bold&&n.italic?"Helvetica-BoldOblique":n.bold?"Helvetica-Bold":n.italic?"Helvetica-Oblique":"Helvetica"}const Rs={a4:{width:595.28,height:841.89},letter:{width:612,height:792}};function gi(n){if(typeof n=="string"){const e=n.replace("#",""),t=e.length===3?e.split("").map(a=>a+a).join(""):e,r=parseInt(t,16),o=(r>>16&255)/255,s=(r>>8&255)/255,i=(r&255)/255;return`${Fe(o)} ${Fe(s)} ${Fe(i)}`}return n.map(Fe).join(" ")}function Fe(n){return Number.isInteger(n)?String(n):n.toFixed(3).replace(/\.?0+$/,"")}function fm(n){let e="";for(const t of n)e+=t.toString(16).padStart(2,"0");return e}function rs(n){const e=[254,255];for(let t=0;t<n.length;t++){const r=n.charCodeAt(t);e.push(r>>8,r&255)}return`<${fm(e)}>`}function f1(n){const e=t=>String(t).padStart(2,"0");return`D:${n.getUTCFullYear()}${e(n.getUTCMonth()+1)}${e(n.getUTCDate())}${e(n.getUTCHours())}${e(n.getUTCMinutes())}${e(n.getUTCSeconds())}Z`}class g1{index;width;height;fontName;ops=[];links=[];images=new Set;constructor(e,t,r,o){this.index=e,this.width=t,this.height=r,this.fontName=o}text(e,t,r,o,s,i="#000000"){const{bytes:a}=c1(r);a.length!==0&&this.ops.push(`BT ${gi(i)} rg /${this.fontName(o)} ${Fe(s)} Tf 1 0 0 1 ${Fe(e)} ${Fe(this.height-t)} Tm <${fm(a)}> Tj ET`)}rect(e,t,r,o,s){const i=["q"];s.fill&&i.push(`${gi(s.fill)} rg`),s.stroke&&i.push(`${gi(s.stroke)} RG ${Fe(s.lineWidth??.5)} w`),i.push(`${Fe(e)} ${Fe(this.height-t-o)} ${Fe(r)} ${Fe(o)} re`),i.push(s.fill&&s.stroke?"B":s.fill?"f":"S","Q"),this.ops.push(i.join(" "))}line(e,t,r,o,s="#000000",i=.5){this.ops.push(`q ${gi(s)} RG ${Fe(i)} w ${Fe(e)} ${Fe(this.height-t)} m ${Fe(r)} ${Fe(this.height-o)} l S Q`)}image(e,t,r,o,s){this.images.add(e.id),this.ops.push(`q ${Fe(o)} 0 0 ${Fe(s)} ${Fe(t)} ${Fe(this.height-r-s)} cm /Im${e.id} Do Q`)}link(e,t,r,o,s){this.links.push({rect:[e,this.height-t-o,e+r,this.height-t],url:s})}}class gm{options;pages=[];size;images=[];fonts=new Map;constructor(e={}){this.options=e,this.size=e.size??Rs.a4,fi.forEach((t,r)=>this.fonts.set(t,`F${r+1}`))}addPage(){const e=new g1(this.pages.length,this.size.width,this.size.height,t=>this.fonts.get(t)??"F1");return this.pages.push(e),e}addJpeg(e,t,r){const o={id:this.images.length+1,width:t,height:r,bytes:e};return this.images.push(o),o}build(){const e=new TextEncoder,t=[];let r=0;const o=C=>{const v=typeof C=="string"?p1(C):C;t.push(v),r+=v.length},s=[],i=(C,v)=>{s[C]=r,o(`${C} 0 obj
93
93
  `),typeof v=="string"?o(v):v.forEach(o),o(`
94
94
  endobj
@@ -179,7 +179,7 @@ ${s} `)}`)}}return i.join(`
179
179
  `)}}async function wm(n,e={}){const t=Uu(n),r=new H1(e,n),o=await r.blocks(t.blocks);return{main:`${r.preamble(t)}
180
180
 
181
181
  ${o}
182
- `,files:r.files}}const xm="0.7.0",J1=`https://cdn.jsdelivr.net/npm/@myriaddreamin/typst.ts@${xm}/dist/esm/contrib/snippet.mjs/+esm`,q1=`https://cdn.jsdelivr.net/npm/@myriaddreamin/typst-ts-web-compiler@${xm}/pkg/typst_ts_web_compiler_bg.wasm`,tl=new Map;function V1(n){return new Function("url","return import(url)")(n)}function Y1(n={}){const e=n.moduleUrl??J1,t=n.wasmUrl??q1,r=tl.get(e);if(r)return r;const o=V1(e).then(({$typst:s})=>{s.setCompilerInitOptions({getModule:()=>t});let i=Promise.resolve();return{compile(l,c){const u=i.then(async()=>{if(s.resetShadow(),c)for(const[f,d]of c)await s.mapShadow(f.startsWith("/")?f:`/${f}`,d);return s.pdf({mainContent:l})});return i=u.catch(()=>{}),u}}});return o.catch(()=>tl.delete(e)),tl.set(e,o),o}function X1(n){return typeof n=="object"&&n!==null&&typeof n.compile=="function"}function G1(n,e,...t){if(!n)throw new Error("Internal Lexical error: invariant() is meant to be replaced at compile time. There is no runtime version. Error: "+e)}function Z1(n,e,t){const r=n.length,o=e.length;let s=0,i=0;for(;s<r&&s<o&&n[s]===e[s]&&s<t;)s++;for(;i+s<r&&i+s<o&&n[r-i-1]===e[o-i-1];)i++;for(;i+s<r&&i+s<o&&n[s]===e[s];)s++;return{index:s,insert:e.slice(s,o-i),remove:r-s-i}}const Q1="lexical-tree";function Wt(n){return Number(n.peerId)}function ek(){return Math.floor(Math.random()*2147483647)}function tk(n,e=Q1){return n.getTree(e)}function so(n,e){return!!(n===e||n.name===e.name||n.prototype&&Object.prototype.isPrototypeOf.call(e,n))}function nk(n,e,t,r){const o=D();let s=r.length;if(F(o)&&o.isCollapsed()){const a=o.anchor;a.key===e&&(s=Math.min(a.offset,r.length))}const i=Z1(t,r,s);n.getTextContent(),n.spliceText(i.index,i.remove,i.insert),n.getTextContent()}function ng(n){const e=n.anchor,t=n.focus;let r=!1;try{const o=e.getNode(),s=t.getNode();(!o.isAttached()||!s.isAttached()||oe(o)&&e.offset>o.getTextContentSize()||oe(s)&&t.offset>s.getTextContentSize())&&(r=!0)}catch{r=!0}return r}function Cm(n,e){const t=e._nodeMap.get(n);if(!t){se().selectStart();return}const r=t.__prev;let o=null;if(r&&(o=Q(r)),o===null&&t.__parent!==null&&(o=Q(t.__parent)),o===null){se().selectStart();return}if(o!==null&&o.isAttached()){o.selectEnd();return}else Cm(o.__key,e)}function qt(n,e){if(!n||!e)return!1;try{return n.has(e)&&!n.isNodeDeleted(e)}catch{return!1}}function Se(n,e,t){const r=n.data.get(e);return e==="createdAt"&&r!==void 0||r!==void 0&&rk(r,t)?!1:(n.data.set(e,t),!0)}function Xi(n,e,t,r){const o=n.getNodeByID(e);if(o){const s=o.parent(),i=s?String(s.id):void 0,a=t===void 0?void 0:String(t);if(i===a&&(r===void 0||(s?s.children()??[]:n.roots()).findIndex(u=>String(u.id)===String(e))===r))return!1}return n.move(e,t,r),!0}function rk(n,e){if(n===e)return!0;try{const t=r=>r&&typeof r.toJSON=="function"?r.toJSON():r;return JSON.stringify(t(n))===JSON.stringify(t(e))}catch{return!1}}function dt(n,e,t){if(!n){const r=t?` ${JSON.stringify(t)}`:"";throw new Error(`[loro-collab] Invariant failed: ${e}${r}`)}}let nl;function ye(...n){nl===void 0&&(nl=Sm()),nl&&console.log(...n)}function Sm(){return typeof window>"u"?!1:new URLSearchParams(window.location.search).get("debug")==="true"}function ok(n){window.debugLoro={binding:null,logStructure:()=>{const e=window.debugLoro.binding;if(e){console.log("=== LORO TREE STRUCTURE DEBUG ===");const r=e.tree.nodes();console.log(`Total nodes in tree: ${r.length}`);const o=(i,a="",l=!0,c=0)=>{const u=Object.fromEntries(i.data.entries()),f=i.id,d=e.nodeMapper?.getLexicalKeyByLoroId(f)||"no-key",g=u.elementType||"no-type",h=c===0?"":l?"└── ":"├── ",_=`TreeID(${f.slice(0,8)}...) → ${d} [${g}]`;console.log(`${a}${h}${_}`);const m=i.children();m&&m.length>0&&m.forEach((y,w)=>{const C=w===m.length-1,v=a+(c===0?"":l?" ":"│ ");o(y,v,C,c+1)})},s=r.filter(i=>{const a=i.parent(),l=Object.fromEntries(i.data.entries());return!a||l.isRoot});console.log(`Root nodes: ${s.length}`),console.log(""),s.length===0?console.log(" No root nodes found!"):s.forEach((i,a)=>{const l=a===s.length-1;o(i,"",l,0)}),console.log("=== END LORO DEBUG ===")}else console.log("Loro binding not available yet")},verifyStructure:()=>{const e=window.debugLoro.binding;if(!e)return console.log(" Loro Binding not available");console.log(" LORO TREE VERIFICATION:");const r=e.tree.nodes();console.log("Total nodes:",r.length),console.log("Peer ID:",e.doc.peerIdStr),console.log("Client ID:",e.clientID),e.nodeMapper,console.log(`
182
+ `,files:r.files}}const xm="0.7.0",J1=`https://cdn.jsdelivr.net/npm/@myriaddreamin/typst.ts@${xm}/dist/esm/contrib/snippet.mjs/+esm`,q1=`https://cdn.jsdelivr.net/npm/@myriaddreamin/typst-ts-web-compiler@${xm}/pkg/typst_ts_web_compiler_bg.wasm`,tl=new Map;function V1(n){return new Function("url","return import(url)")(n)}function Y1(n={}){const e=n.moduleUrl??J1,t=n.wasmUrl??q1,r=tl.get(e);if(r)return r;const o=V1(e).then(({$typst:s})=>{s.setCompilerInitOptions({getModule:()=>t});let i=Promise.resolve();return{compile(l,c){const u=i.then(async()=>{if(s.resetShadow(),c)for(const[f,d]of c)await s.mapShadow(f.startsWith("/")?f:`/${f}`,d);return s.pdf({mainContent:l})});return i=u.catch(()=>{}),u}}});return o.catch(()=>tl.delete(e)),tl.set(e,o),o}function X1(n){return typeof n=="object"&&n!==null&&typeof n.compile=="function"}function G1(n,e,...t){if(!n)throw new Error("Internal Lexical error: invariant() is meant to be replaced at compile time. There is no runtime version. Error: "+e)}function Z1(n,e,t){const r=n.length,o=e.length;let s=0,i=0;for(;s<r&&s<o&&n[s]===e[s]&&s<t;)s++;for(;i+s<r&&i+s<o&&n[r-i-1]===e[o-i-1];)i++;for(;i+s<r&&i+s<o&&n[s]===e[s];)s++;return{index:s,insert:e.slice(s,o-i),remove:r-s-i}}const Q1="lexical-tree";function ek(n,e=Q1){return n.getTree(e)}function so(n,e){return!!(n===e||n.name===e.name||n.prototype&&Object.prototype.isPrototypeOf.call(e,n))}function tk(n,e,t,r){const o=D();let s=r.length;if(F(o)&&o.isCollapsed()){const a=o.anchor;a.key===e&&(s=Math.min(a.offset,r.length))}const i=Z1(t,r,s);n.getTextContent(),n.spliceText(i.index,i.remove,i.insert),n.getTextContent()}function ng(n){const e=n.anchor,t=n.focus;let r=!1;try{const o=e.getNode(),s=t.getNode();(!o.isAttached()||!s.isAttached()||oe(o)&&e.offset>o.getTextContentSize()||oe(s)&&t.offset>s.getTextContentSize())&&(r=!0)}catch{r=!0}return r}function Cm(n,e){const t=e._nodeMap.get(n);if(!t){se().selectStart();return}const r=t.__prev;let o=null;if(r&&(o=Q(r)),o===null&&t.__parent!==null&&(o=Q(t.__parent)),o===null){se().selectStart();return}if(o!==null&&o.isAttached()){o.selectEnd();return}else Cm(o.__key,e)}function qt(n,e){if(!n||!e)return!1;try{return n.has(e)&&!n.isNodeDeleted(e)}catch{return!1}}function Se(n,e,t){const r=n.data.get(e);return e==="createdAt"&&r!==void 0||r!==void 0&&nk(r,t)?!1:(n.data.set(e,t),!0)}function Xi(n,e,t,r){const o=n.getNodeByID(e);if(o){const s=o.parent(),i=s?String(s.id):void 0,a=t===void 0?void 0:String(t);if(i===a&&(r===void 0||(s?s.children()??[]:n.roots()).findIndex(u=>String(u.id)===String(e))===r))return!1}return n.move(e,t,r),!0}function nk(n,e){if(n===e)return!0;try{const t=r=>r&&typeof r.toJSON=="function"?r.toJSON():r;return JSON.stringify(t(n))===JSON.stringify(t(e))}catch{return!1}}function Wt(n){return Number(n.peerId)}function rk(){return Math.floor(Math.random()*2147483647)}function dt(n,e,t){if(!n){const r=t?` ${JSON.stringify(t)}`:"";throw new Error(`[loro-collab] Invariant failed: ${e}${r}`)}}let nl;function ye(...n){nl===void 0&&(nl=Sm()),nl&&console.log(...n)}function Sm(){return typeof window>"u"?!1:new URLSearchParams(window.location.search).get("debug")==="true"}function ok(n){window.debugLoro={binding:null,logStructure:()=>{const e=window.debugLoro.binding;if(e){console.log("=== LORO TREE STRUCTURE DEBUG ===");const r=e.tree.nodes();console.log(`Total nodes in tree: ${r.length}`);const o=(i,a="",l=!0,c=0)=>{const u=Object.fromEntries(i.data.entries()),f=i.id,d=e.nodeMapper?.getLexicalKeyByLoroId(f)||"no-key",g=u.elementType||"no-type",h=c===0?"":l?"└── ":"├── ",_=`TreeID(${f.slice(0,8)}...) → ${d} [${g}]`;console.log(`${a}${h}${_}`);const m=i.children();m&&m.length>0&&m.forEach((y,w)=>{const C=w===m.length-1,v=a+(c===0?"":l?" ":"│ ");o(y,v,C,c+1)})},s=r.filter(i=>{const a=i.parent(),l=Object.fromEntries(i.data.entries());return!a||l.isRoot});console.log(`Root nodes: ${s.length}`),console.log(""),s.length===0?console.log(" No root nodes found!"):s.forEach((i,a)=>{const l=a===s.length-1;o(i,"",l,0)}),console.log("=== END LORO DEBUG ===")}else console.log("Loro binding not available yet")},verifyStructure:()=>{const e=window.debugLoro.binding;if(!e)return console.log(" Loro Binding not available");console.log(" LORO TREE VERIFICATION:");const r=e.tree.nodes();console.log("Total nodes:",r.length),console.log("Peer ID:",e.doc.peerIdStr),console.log("Client ID:",e.clientID),e.nodeMapper,console.log(`
183
183
  Node Mappings:`),r.forEach((s,i)=>{const a=Object.fromEntries(s.data.entries()),l=s.id,c=e.nodeMapper?.getLexicalKeyByLoroId(l)||"no-key";console.log(`
184
184
  Node ${i}:`),console.log(" TreeID:",l),console.log(" Lexical Key:",c),console.log(" Element Type:",a.elementType||"N/A"),console.log(" Created At:",a.createdAt&&typeof a.createdAt=="number"?new Date(a.createdAt).toLocaleTimeString():"N/A"),console.log(" Has Lexical Data:",a.lexical?"Yes":"No");const u=s.parent();console.log(" Parent:",u?u.id:"None (Root)");const f=s.children();if(console.log(" Children Count:",f?f.length:0),a.lexical&&typeof a.lexical=="string")try{const d=JSON.parse(a.lexical);console.log(" Lexical Type:",d.lexicalNode?.type||"Unknown")}catch{console.log(" Lexical Data: Invalid JSON")}});const o=r.filter(s=>{const i=s.parent(),a=Object.fromEntries(s.data.entries());return!i&&!a.isRoot});o.length>0&&(console.log(`
185
185
  WARNING: Found orphaned nodes (no parent, not root):`),o.forEach(s=>{const i=Object.fromEntries(s.data.entries()),a=e.nodeMapper?.getLexicalKeyByLoroId(s.id)||"no-key";console.log(` - ${s.id} (${a}, ${i.elementType})`)})),console.log(`
@@ -203,15 +203,15 @@ ${o}
203
203
  <span onclick="document.getElementById('debug-loro').remove()" style="color: #ff0066; cursor: pointer; text-decoration: underline;"> Close</span>
204
204
  </div>
205
205
  </div>
206
- `,document.body.appendChild(a)},cleanupEphemeralStore:e=>{if(!e){console.log(" No provider passed. Usage: window.debugLoro.cleanupEphemeralStore(provider)"),console.log("You can get the provider from your useCollaboration hook");return}if(typeof e.cleanupStaleStates!="function"){console.log(" Provider does not have cleanupStaleStates method");return}console.log(" Cleaning up stale ephemeral states..."),e.cleanupStaleStates()},resetGlobalEphemeralStore:()=>{try{console.log(" Attempting to reset global EphemeralStore..."),console.log(" You can also refresh the browser to clear the global store"),alert("To reset the global ephemeral store and clear all collaborators, please refresh the browser page.")}catch(e){console.warn(" Reset failed:",e.message)}}},window.debugLoro.binding=n,setTimeout(()=>{window.debugLoro.addDebugToPage()},2e3)}class sk{lexicalToLoro=new Map;loroToLexical=new Map;tree;constructor(e){this.tree=e.tree}createMapping(e,t){this.lexicalToLoro.set(e,t),this.loroToLexical.set(t,e)}removeMapping(e,t){this.lexicalToLoro.delete(e),this.loroToLexical.delete(t)}getLoroNodeByLexicalKey(e,t,r,o){const s=this.lexicalToLoro.get(e);if(s&&qt(this.tree,s))return this.tree.getNodeByID(s);if(e==="root"){const a=this.tree.roots()[0];if(a)return this.createMapping(e,a.id),a;const l=this.createLoroNode(e,t,void 0,0),c=this.tree.getNodeByID(l);return Se(c,"elementType","root"),c}if(!r&&t){const a=t.getParent();if(a){const l=a.getKey();r=this.lexicalToLoro.get(l),r||(r=this.getLoroNodeByLexicalKey(l,a,void 0,void 0).id)}}o===void 0&&t&&(o=t.getIndexWithinParent());const i=this.createLoroNode(e,t,r,o);return this.tree.getNodeByID(i)}getLexicalKeyByLoroId(e){const t=this.loroToLexical.get(e);return t||null}getLexicalNodeByLoroId(e,t){const r=this.getLexicalKeyByLoroId(e);return r&&t._nodeMap.get(r)||null}getLexicalParentByLoroId(e,t){return null}setMapping(e,t){this.lexicalToLoro.set(e,t),this.loroToLexical.set(t,e)}aliasLoroId(e,t){this.loroToLexical.set(e,t)}createLoroNode(e,t,r,o){const s=o;if(s!==void 0){const l=r!==void 0?this.tree.getNodeByID(r):null,c=l?l.children()?.length??0:this.tree.roots().length;dt(s>=0&&s<=c,"createLoroNode: insertion index out of range",{nodeKey:e,parentTreeID:r,insertionIndex:s,childrenLength:c})}const i=this.tree.createNode(r,s),a=i.id;if(r){const l=i.parent();dt(l!=null&&l.id===r,"createLoroNode: parent relationship not established",{nodeKey:e,expected:r,actual:l?.id??null})}if(Se(i,"createdAt",Date.now()),t)try{const l=t.exportJSON();if("key"in l||"__key"in l||"lexicalKey"in l){const{key:c,__key:u,lexicalKey:f,children:d,...g}=l;Se(i,"lexical",g)}else{const{children:c,...u}=l;Se(i,"lexical",u)}}catch(l){console.warn("Failed to export lexical node JSON in NodesMapper:",l)}return this.createMapping(e,a),a}updateMapping(e,t){const r=this.lexicalToLoro.get(e);r&&(this.removeMapping(e,r),this.createMapping(t,r),this.tree.getNodeByID(r))}deleteMapping(e){const t=this.lexicalToLoro.get(e);t&&(this.removeMapping(e,t),qt(this.tree,t)&&this.tree.delete(t))}removeMappingForKey(e){const t=this.lexicalToLoro.get(e);t&&this.removeMapping(e,t)}getTreeIDByLexicalKey(e){return this.lexicalToLoro.get(e)}hasLexicalMapping(e){return this.lexicalToLoro.has(e)}hasLoroMapping(e){return this.loroToLexical.has(e)}getAllMappings(){return{lexicalToLoro:new Map(this.lexicalToLoro),loroToLexical:new Map(this.loroToLexical)}}clearMappings(){this.lexicalToLoro.clear(),this.loroToLexical.clear()}syncExistingNodes(e){ye(" syncExistingNodes: Skipping sync - mappings established through TreeIntegrator")}}let vr=null;function ik(n){return vr=new sk(n),vr}function ak(n,e){const t=vr;vr=n;try{return e()}finally{vr=t}}function ze(){if(!vr)throw new Error("NodeMapper not initialized. Call initializeNodeMapper() first.");return vr}function lk({binding:n,currentUserName:e="Me",currentUserColor:t}){const[r,o]=S.useState(0);S.useEffect(()=>{const g=setInterval(()=>{o(h=>h+1)},1e3);return()=>clearInterval(g)},[]);const s=n.clientID;Array.from(n.cursors.entries()).map(([g,h])=>({clientId:g,name:h.name,color:h.color,isCurrentUser:g===s}));const i=Array.from(n.cursors.entries()).map(([g,h])=>({clientId:g,cursor:h,isCurrentUser:g===s})),a=n.cursors.get(s),l=a?.name||e,c=Hw(l),u=a?.color||t||c,f=i.find(({isCurrentUser:g})=>g),d=i.filter(({isCurrentUser:g})=>!g);return x.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",backgroundColor:"var(--bgColor-muted, #f8f9fa)",borderBottom:"1px solid var(--borderColor-default, #e1e5e9)",fontSize:"14px",fontFamily:"system-ui, -apple-system, sans-serif",gap:"8px",flexWrap:"wrap",color:"var(--fgColor-default, inherit)"},children:[f&&x.jsx(rl,{name:`${f.cursor.name} (me)`,color:u,isCurrentUser:!0,clientId:s}),!f&&x.jsx(rl,{name:`${l} (me)`,color:u,isCurrentUser:!0,clientId:s}),d.length>0&&x.jsx("div",{style:{width:"1px",height:"20px",backgroundColor:"var(--borderColor-muted, #d1d5db)",margin:"0 4px"}}),d.map(({clientId:g,cursor:h})=>x.jsx(rl,{name:h.name,color:h.color,isCurrentUser:!1,clientId:g},g)),d.length===0&&x.jsx("span",{style:{color:"var(--fgColor-muted, #6b7280)",fontStyle:"italic",marginLeft:"8px"},children:"No other collaborators"})]})}function rl({name:n,color:e,isCurrentUser:t,clientId:r}){const o=e,s=e,i=String(r).slice(0,4);return x.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px"},title:`${n} (Client ID: ${r})`,children:[x.jsx("div",{style:{width:"12px",height:"12px",borderRadius:"50%",backgroundColor:o,border:t?"2px solid var(--bgColor-default, #ffffff)":"none",boxShadow:t?"0 0 0 1px var(--borderColor-default, #d1d5db)":"none",flexShrink:0}}),x.jsx("span",{style:{backgroundColor:s,color:"var(--fgColor-onEmphasis, #ffffff)",padding:"3px 8px",borderRadius:"12px",fontSize:"12px",fontWeight:"500",lineHeight:"1.2",whiteSpace:"nowrap",textShadow:"0 1px 2px rgba(0,0,0,0.1)",boxShadow:t?"0 1px 3px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.2)":"0 1px 2px rgba(0,0,0,0.1)",opacity:1},children:`${n} ${i}`})]})}function ck({binding:n,cursorsContainer:e,currentUserName:t="You",currentUserColor:r,showCollaborators:o=!0}){return x.jsxs(x.Fragment,{children:[o&&x.jsx(lk,{binding:n,currentUserName:t,currentUserColor:r}),e]})}function uk(n,e,t,r,o,s){G1(r!=null,"createBinding: doc is null or undefined");const i=tk(r);ye(" Loro tree initialized, content will be populated via server sync");const a=Wt(r);ye("- Creating binding:",{bindingId:t,localPeerId:r.peerId,generatedClientID:a,docPeerIdType:typeof r.peerId,awarenessKey:a.toString()});const l={clientID:a,cursors:new Map,cursorsContainer:null,doc:r,docMap:o,editor:n,tree:i,excludedProperties:s||new Map,id:t,nodeProperties:new Map,nodeMapper:null,commitTimeout:null,pendingCommit:!1};return l.nodeMapper=ik(l),Sm()&&(ok(l),ye(" Loro debugging enabled via ?debug=true URL parameter")),l}function vm(n){const e=n.awarenessData;if(!e||typeof e!="object")return n.name;const t=e,r=t.user,o=r&&typeof r=="object"?r:void 0,s=[o?.display_name,o?.displayName,o?.name,o?.username,o?.handle,t.display_name,t.displayName,t.name,t.username,t.handle,n.name];for(const i of s)if(typeof i=="string"&&i.trim().length>0)return i;return n.name}function rg(n,e){try{const t=Q(n.key);if(!t)return null;const r=e.nodeMapper;if(oe(t)){const s=r.getTreeIDByLexicalKey(n.key);if(!s)return null;const i=t.getTextContent(),a=Math.min(n.offset,i.length);return{treeId:s,offset:a,pointType:"text"}}if(q(t)){const s=t.getChildren();if(s.length===0){const a=r.getTreeIDByLexicalKey(n.key);return a?{treeId:a,offset:n.offset,pointType:"element"}:null}if(n.offset<s.length){const a=s[n.offset];if(a){const l=r.getTreeIDByLexicalKey(a.getKey());if(l)return{treeId:l,offset:0,pointType:oe(a)?"text":"element"}}}const i=r.getTreeIDByLexicalKey(n.key);return i?{treeId:i,offset:n.offset,pointType:"element"}:null}const o=r.getTreeIDByLexicalKey(n.key);return o?{treeId:o,offset:n.offset,pointType:"element"}:null}catch(t){return console.warn("Failed to convert Lexical point to Loro cursor:",t),null}}function km(n,e,t){try{if(!n||!e)return null;const r=n,o=e,s=t.nodeMapper;let i=null,a=null;return r.treeId&&(i=s.getLexicalKeyByLoroId(r.treeId)),o.treeId&&(a=s.getLexicalKeyByLoroId(o.treeId)),!i||!a?null:{anchorKey:i,anchorOffset:r.offset||0,focusKey:a,focusOffset:o.offset||0}}catch(r){return console.warn("Failed to convert Loro cursors to Lexical selection:",r),null}}function og(n,e,t){if(n.key!==e||n.offset!==t){let r=Q(e);if(r!==null&&!q(r)&&!oe(r)){const o=r.getParentOrThrow();e=o.getKey(),t=r.getIndexWithinParent(),r=o}n.set(e,t,q(r)?"element":"text")}}function dk(n,e){return{color:e,name:n,selection:null}}function fk(n,e,t,r,o,s=!1){const i=n.color,a=i,l=i,c=document.createElement("span");c.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:2px;background-color:${a};z-index:10;${s?"opacity:0.8;":""}`;const u=document.createElement("span");return u.textContent=n.name,u.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:${l};color:var(--fgColor-onEmphasis,#fff);line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;${s?"opacity:0.9;":""}`,c.appendChild(u),{anchor:{key:e,offset:t},focus:{key:r,offset:o},caret:c,color:n.color,name:u,selections:[]}}function gk(n,e){const t=e.selection;t!==null&&(Tm(n,t),e.selection=null)}function Tm(n,e){const t=n.cursorsContainer;if(t!==null){const r=e.selections,o=r.length;for(let s=0;s<o;s++)t.removeChild(r[s])}}function Im(n,e,t){const{getAwarenessStates:r=pk}=t??{},o=Array.from(r(n,e)),s=n.clientID,i=n.cursors,l=n.editor._editorState._nodeMap,c=new Set;for(let f=0;f<o.length;f++){const d=o[f],[g,h]=d;c.add(g);const{color:_}=h,m=vm(h),y=g===s;let w=null,C=i.get(g);if(C===void 0){const I=y?`${m} (Me)`:m;C=dk(I,_),i.set(g,C)}else C.name!==m&&(C.name=m,C.selection&&(C.selection.name.textContent=y?`${m} (Me)`:m));const{anchorPos:v,focusPos:k}=h;if(v!==null&&k!==null){const I=km(v,k,n);if(I){const{anchorKey:E,anchorOffset:N,focusKey:O,focusOffset:M}=I;if(w=C.selection,w===null)w=fk(C,E,N,O,M,y);else{const R=w.anchor,$=w.focus;R.key=E,R.offset=N,$.key=O,$.offset=M}}}hk(n,C,w,l,y)}const u=Array.from(i.keys());for(let f=0;f<u.length;f++){const d=u[f];if(!c.has(d)){const g=i.get(d);g!==void 0&&(gk(n,g),i.delete(d))}}}function pk(n,e){return e.awareness.getStates()}function hk(n,e,t,r,o=!1){const s=n.editor,i=s.getRootElement(),a=n.cursorsContainer;if(a===null||i===null)return;const l=a.getBoundingClientRect(),c=e.selection;if(t===null){if(c===null)return;e.selection=null,Tm(n,c);return}else e.selection=t;const u=t.caret,f=t.color,d=t.selections,g=t.anchor,h=t.focus,_=g.key,m=h.key,y=r.get(_),w=r.get(m);if(y==null||w==null)return;const C=_===m&&g.offset===h.offset;let v;if(y===w&&ue(y)){const E=s.getElementByKey(_);E?v=[E.getBoundingClientRect()]:v=[]}else{const E=fh(s,y,g.offset,w,h.offset);if(E===null)return;if(C){if(v=Ml(s,E),v.length===0){const N=E.getBoundingClientRect();N.height>0&&(v=[N])}}else v=Ml(s,E)}const k=d.length,I=v.length;for(let E=0;E<I;E++){const N=v[E];let O=d[E];if(O===void 0){O=document.createElement("span"),d[E]=O;const A=document.createElement("span");O.appendChild(A),a.appendChild(O)}const M=N.top-l.top,R=N.left-l.left,$=C?Math.max(N.width,4):N.width,L=`position:absolute;top:${M}px;left:${R}px;height:${N.height}px;width:${$}px;pointer-events:none;z-index:10;overflow:visible;`;O.style.cssText=L,C?(O.firstChild.style.cssText="position:absolute;left:0;top:0;width:0;height:0;",u.style.cssText=`position:absolute;top:0;left:0;width:2px;height:${N.height}px;background-color:${f};z-index:10;`):o?O.firstChild.style.cssText=`position:absolute;left:0;top:0;width:${N.width}px;height:${N.height}px;background-color:${f};opacity:0.08;border-radius:2px;pointer-events:none;`:O.firstChild.style.cssText=`position:absolute;left:0;top:0;width:${N.width}px;height:${N.height}px;background-color:${f};opacity:0.25;border-radius:2px;pointer-events:none;`,E===I-1&&u.parentNode!==O&&O.appendChild(u)}for(let E=k-1;E>=I;E--){const N=d[E];a.removeChild(N),d.pop()}}function Em(n,e,t,r){const o=e.awareness,s=o.getLocalState();if(s===null)return;const{anchorPos:i,focusPos:a,name:l,color:c,focusing:u,awarenessData:f}=s;let d=null,g=null;if(F(r))d=rg(r.anchor,n),g=rg(r.focus,n);else if(r!==null)return;if(!(sg(i,d)||sg(a,g)))return;const _=d!==null&&g!==null?!0:u;o.setLocalState({...s,anchorPos:d,awarenessData:f,color:c,focusPos:g,focusing:_,name:l})}function sg(n,e){if(n==null)return e!=null;if(e==null)return!0;{const t=n,r=e;return t.treeId!==r.treeId||t.offset!==r.offset||t.pointType!==r.pointType}}function ig(n,e){const r=e.awareness.getLocalState();if(r===null)return;const{anchorPos:o,focusPos:s}=r;if(o!==null&&s!==null){const i=km(o,s,n);if(i){const{anchorKey:a,anchorOffset:l,focusKey:c,focusOffset:u}=i,f=D();if(!F(f))return;og(f.anchor,a,l),og(f.focus,c,u)}}}const _k=(n,e)=>{const t=n.encode(),r=e.encode();return t.length===r.length&&t.every((o,s)=>o===r[s])},mk=n=>{const e=n.awarenessData,t=e&&e.user&&typeof e.user=="object"?e.user:void 0,r=t?.id??t?.uid;return typeof r=="string"&&r.length>0?r:void 0};function bk(n,e){const t=[];for(const[r,o]of n){const s=o.anchorPos,i=o.focusPos;t.push({clientId:r,uid:mk(o),name:vm(o),color:o.color,isCurrentUser:r===e,focusing:!!o.focusing,selecting:s!==null&&i!==null&&!_k(s,i)})}return t.sort((r,o)=>Number(o.isCurrentUser)-Number(r.isCurrentUser)||r.clientId-o.clientId)}const ag=["Cat","Dog","Rabbit","Frog","Fox","Hedgehog","Pigeon","Squirrel","Bear","Tiger","Leopard","Zebra","Wolf","Owl","Gull","Squid","Panda","Lion","Eagle","Shark","Dolphin","Penguin","Koala","Kangaroo"];function Nm(n){const e=Math.abs(n)%ag.length,t=Math.abs(n).toString().slice(-4),r=`${ag[e]}-${t}`,o=Jw(r);return{name:r,color:o}}const lg=Nm(Math.floor(Math.random()*1e5)),yk=S.createContext({clientID:0,color:lg.color,isCollabActive:!1,name:lg.name,docMap:new Map});function Lm(n,e){const t=S.useContext(yk);return n!=null&&(t.name=n),e!=null&&(t.color=e),t}const zu=["Map","List","MovableList","Text","Tree","Counter"];function wk(n,e){if(typeof n!="object"||n===null||Array.isArray(n))throw new Error("Invalid toContainerTree options");for(const t of Object.keys(n))if(t!=="text"&&!(e&&t==="roots"))throw new Error("Unknown toContainerTree option: "+t);if(e&&n.roots!==void 0&&!Array.isArray(n.roots))throw new Error("roots must be an array");return n}function xk(n,e,t){return{cid:n.cid,start:e,totalLength:t,items:n.value}}function Ck(n,e,t){return{type:zu[n],cid:e,value:t}}function Sk(n,e,t){return"cid:"+e+"@"+n+":"+zu[t]}function vk(n,e){return"cid:root-"+n+":"+zu[e]}function kk(n){return{type:"Value",value:n}}function Tk(n){return n.slice()}function Ik(n,e,t){Object.defineProperty(n,e,{value:t,enumerable:!0,writable:!0,configurable:!0})}function Ek(n,e,t){Object.defineProperty(n,e,{value:t,enumerable:!0,writable:!0,configurable:!0})}let p;function Nk(n){p=n}const Be=new Array(128).fill(void 0);Be.push(void 0,null,!0,!1);function W(n){return Be[n]}let G=0,hi=null;function ko(){return(hi===null||hi.byteLength===0)&&(hi=new Uint8Array(p.memory.buffer)),hi}const Lk=typeof TextEncoder>"u"?(0,module.require)("util").TextEncoder:TextEncoder;let Ti=new Lk("utf-8");const Ok=typeof Ti.encodeInto=="function"?function(n,e){return Ti.encodeInto(n,e)}:function(n,e){const t=Ti.encode(n);return e.set(t),{read:n.length,written:t.length}};function _e(n,e,t){if(t===void 0){const a=Ti.encode(n),l=e(a.length,1)>>>0;return ko().subarray(l,l+a.length).set(a),G=a.length,l}let r=n.length,o=e(r,1)>>>0;const s=ko();let i=0;for(;i<r;i++){const a=n.charCodeAt(i);if(a>127)break;s[o+i]=a}if(i!==r){i!==0&&(n=n.slice(i)),o=t(o,r,r=i+n.length*3,1)>>>0;const a=ko().subarray(o+i,o+r),l=Ok(n,a);i+=l.written,o=t(o,r,i,1)>>>0}return G=i,o}let io=null;function b(){return(io===null||io.buffer.detached===!0||io.buffer.detached===void 0&&io.buffer!==p.memory.buffer)&&(io=new DataView(p.memory.buffer)),io}let bs=Be.length;function P(n){bs===Be.length&&Be.push(Be.length+1);const e=bs;return bs=Be[e],Be[e]=n,e}function nt(n,e){try{return n.apply(this,e)}catch(t){p.__wbindgen_exn_store(P(t))}}const Rk=typeof TextDecoder>"u"?(0,module.require)("util").TextDecoder:TextDecoder;let Om=new Rk("utf-8",{ignoreBOM:!0,fatal:!0});Om.decode();function Ue(n,e){return n=n>>>0,Om.decode(ko().subarray(n,n+e))}function Ak(n){n<132||(Be[n]=bs,bs=n)}function T(n){const e=W(n);return Ak(n),e}function hn(n,e){return n=n>>>0,ko().subarray(n/1,n/1+e)}function Ae(n){return n==null}const cg=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>{p.__wbindgen_export_4.get(n.dtor)(n.a,n.b)});function Rm(n,e,t,r){const o={a:n,b:e,cnt:1,dtor:t},s=(...i)=>{o.cnt++;const a=o.a;o.a=0;try{return r(a,o.b,...i)}finally{--o.cnt===0?(p.__wbindgen_export_4.get(o.dtor)(a,o.b),cg.unregister(o)):o.a=a}};return s.original=o,cg.register(s,o,o),s}function dc(n){const e=typeof n;if(e=="number"||e=="boolean"||n==null)return`${n}`;if(e=="string")return`"${n}"`;if(e=="symbol"){const o=n.description;return o==null?"Symbol":`Symbol(${o})`}if(e=="function"){const o=n.name;return typeof o=="string"&&o.length>0?`Function(${o})`:"Function"}if(Array.isArray(n)){const o=n.length;let s="[";o>0&&(s+=dc(n[0]));for(let i=1;i<o;i++)s+=", "+dc(n[i]);return s+="]",s}const t=/\[object ([^\]]+)\]/.exec(toString.call(n));let r;if(t&&t.length>1)r=t[1];else return toString.call(n);if(r=="Object")try{return"Object("+JSON.stringify(n)+")"}catch{return"Object"}return n instanceof Error?`${n.name}: ${n.message}
207
- ${n.stack}`:r}function Mk(){let n,e;try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.LORO_VERSION(o);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);return n=t,e=r,Ue(t,r)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_free(n,e,1)}}function Xn(n,e){const t=e(n.length*1,1)>>>0;return ko().set(n,t/1),G=n.length,t}function fc(n,e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Xn(n,p.__wbindgen_malloc),a=G;p.decodeImportBlobMeta(s,i,a,e);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}function gc(){p.callPendingEvents()}function $k(n,e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.redactJsonUpdates(s,P(n),P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}function Am(n){const e=_e(n,p.__wbindgen_malloc,p.__wbindgen_realloc),t=G;return p.isValidContainerId(e,t)!==0}function Dk(){p.run()}function Tt(n,e){const t=e(n.length*4,4)>>>0,r=b();for(let o=0;o<n.length;o++)r.setUint32(t+4*o,P(n[o]),!0);return G=n.length,t}function Pk(n){try{const i=p.__wbindgen_add_to_stack_pointer(-16),a=Tt(n,p.__wbindgen_malloc),l=G;p.encodeFrontiers(i,a,l);var e=b().getInt32(i+0,!0),t=b().getInt32(i+4,!0),r=b().getInt32(i+8,!0),o=b().getInt32(i+12,!0);if(o)throw T(r);var s=hn(e,t).slice();return p.__wbindgen_free(e,t*1,1),s}finally{p.__wbindgen_add_to_stack_pointer(16)}}function jk(n){try{const o=p.__wbindgen_add_to_stack_pointer(-16),s=Xn(n,p.__wbindgen_malloc),i=G;p.decodeFrontiers(o,s,i);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}function Fk(){p.setDebug()}let et=128;function mt(n){if(et==1)throw new Error("out of js stack");return Be[--et]=n,et}function jo(n,e){if(!(n instanceof e))throw new Error(`expected instance of ${e.name}`)}function jt(n,e){n=n>>>0;const t=b(),r=[];for(let o=n;o<n+4*e;o+=4)r.push(T(t.getUint32(o,!0)));return r}function Bk(n,e,t){p._dyn_core_ed718c3d60ebd546___ops__function__FnMut_______Output______as_wasm_bindgen_cfd5deec16e3bd1c___closure__WasmClosure___describe__invoke___wasm_bindgen_cfd5deec16e3bd1c___JsValue_____(n,e,P(t))}function Uk(n,e){p._dyn_core_ed718c3d60ebd546___ops__function__FnMut_____Output______as_wasm_bindgen_cfd5deec16e3bd1c___closure__WasmClosure___describe__invoke______(n,e)}const ug=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_awarenesswasm_free(n>>>0,1));class zk{__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,ug.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_awarenesswasm_free(e,0)}getAllStates(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.awarenesswasm_getAllStates(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getTimestamp(e){try{const i=p.__wbindgen_add_to_stack_pointer(-32);p.awarenesswasm_getTimestamp(i,this.__wbg_ptr,P(e));var t=b().getInt32(i+0,!0),r=b().getFloat64(i+8,!0),o=b().getInt32(i+16,!0),s=b().getInt32(i+20,!0);if(s)throw T(o);return t===0?void 0:r}finally{p.__wbindgen_add_to_stack_pointer(32)}}setLocalState(e){p.awarenesswasm_setLocalState(this.__wbg_ptr,P(e))}removeOutdated(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.awarenesswasm_removeOutdated(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}constructor(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.awarenesswasm_new(i,P(e),t);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return this.__wbg_ptr=r>>>0,ug.register(this,this.__wbg_ptr,this),this}finally{p.__wbindgen_add_to_stack_pointer(16)}}peer(){const e=p.awarenesswasm_peer(this.__wbg_ptr);return T(e)}apply(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Xn(e,p.__wbindgen_malloc),a=G;p.awarenesswasm_apply(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}peers(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.awarenesswasm_peers(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}encode(e){try{const a=p.__wbindgen_add_to_stack_pointer(-16);p.awarenesswasm_encode(a,this.__wbg_ptr,P(e));var t=b().getInt32(a+0,!0),r=b().getInt32(a+4,!0),o=b().getInt32(a+8,!0),s=b().getInt32(a+12,!0);if(s)throw T(o);var i=hn(t,r).slice();return p.__wbindgen_free(t,r*1,1),i}finally{p.__wbindgen_add_to_stack_pointer(16)}}length(){return p.awarenesswasm_length(this.__wbg_ptr)}isEmpty(){return p.awarenesswasm_isEmpty(this.__wbg_ptr)!==0}getState(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.awarenesswasm_getState(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}encodeAll(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.awarenesswasm_encodeAll(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=hn(e,t).slice();return p.__wbindgen_free(e,t*1,1),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}}const dg=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_changemodifier_free(n>>>0,1));class To{static __wrap(e){e=e>>>0;const t=Object.create(To.prototype);return t.__wbg_ptr=e,dg.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,dg.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_changemodifier_free(e,0)}setMessage(e){const t=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),r=G,o=p.changemodifier_setMessage(this.__wbg_ptr,t,r);return To.__wrap(o)}setTimestamp(e){const t=p.changemodifier_setTimestamp(this.__wbg_ptr,e);return To.__wrap(t)}}const fg=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_cursor_free(n>>>0,1));class In{static __wrap(e){e=e>>>0;const t=Object.create(In.prototype);return t.__wbg_ptr=e,fg.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,fg.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_cursor_free(e,0)}containerId(){const e=p.cursor_containerId(this.__wbg_ptr);return T(e)}pos(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.cursor_pos(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}kind(){const e=p.cursor_kind(this.__wbg_ptr);return T(e)}side(){const e=p.cursor_side(this.__wbg_ptr);return T(e)}static decode(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Xn(e,p.__wbindgen_malloc),a=G;p.cursor_decode(s,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return In.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}encode(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.cursor_encode(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=hn(e,t).slice();return p.__wbindgen_free(e,t*1,1),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}}const gg=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_ephemeralstorewasm_free(n>>>0,1));class Ku{__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,gg.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_ephemeralstorewasm_free(e,0)}getAllStates(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.ephemeralstorewasm_getAllStates(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}removeOutdated(){p.ephemeralstorewasm_removeOutdated(this.__wbg_ptr)}subscribeLocalUpdates(e){const t=p.ephemeralstorewasm_subscribeLocalUpdates(this.__wbg_ptr,P(e));return T(t)}get(e){const t=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),r=G,o=p.ephemeralstorewasm_get(this.__wbg_ptr,t,r);return T(o)}constructor(e){const t=p.ephemeralstorewasm_new(e);return this.__wbg_ptr=t>>>0,gg.register(this,this.__wbg_ptr,this),this}set(e,t){const r=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),o=G;p.ephemeralstorewasm_set(this.__wbg_ptr,r,o,P(t))}keys(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.ephemeralstorewasm_keys(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}apply(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16),s=Xn(e,p.__wbindgen_malloc),i=G;p.ephemeralstorewasm_apply(o,this.__wbg_ptr,s,i);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}delete(e){const t=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),r=G;p.ephemeralstorewasm_delete(this.__wbg_ptr,t,r)}encode(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.ephemeralstorewasm_encode(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=hn(t,r).slice();return p.__wbindgen_free(t,r*1,1),o}finally{p.__wbindgen_add_to_stack_pointer(16)}}isEmpty(){return p.ephemeralstorewasm_isEmpty(this.__wbg_ptr)!==0}encodeAll(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.ephemeralstorewasm_encodeAll(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=hn(e,t).slice();return p.__wbindgen_free(e,t*1,1),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}subscribe(e){const t=p.ephemeralstorewasm_subscribe(this.__wbg_ptr,P(e));return T(t)}}const ol=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_lorocounter_free(n>>>0,1));class Vr{static __wrap(e){e=e>>>0;const t=Object.create(Vr.prototype);return t.__wbg_ptr=e,ol.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,ol.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_lorocounter_free(e,0)}toContainerTree(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorocounter_toContainerTree(s,this.__wbg_ptr,Ae(e)?0:P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}isAttached(){return p.lorocounter_isAttached(this.__wbg_ptr)!==0}getAttached(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorocounter_getAttached(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getShallowValue(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorocounter_getShallowValue(o,this.__wbg_ptr);var e=b().getFloat64(o+0,!0),t=b().getInt32(o+8,!0),r=b().getInt32(o+12,!0);if(r)throw T(t);return e}finally{p.__wbindgen_add_to_stack_pointer(16)}}get id(){const e=p.lorocounter_id(this.__wbg_ptr);return T(e)}constructor(){const e=p.lorocounter_new();return this.__wbg_ptr=e>>>0,ol.register(this,this.__wbg_ptr,this),this}kind(){const e=p.lorocounter_kind(this.__wbg_ptr);return T(e)}parent(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorocounter_parent(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toJSON(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorocounter_getShallowValue(o,this.__wbg_ptr);var e=b().getFloat64(o+0,!0),t=b().getInt32(o+8,!0),r=b().getInt32(o+12,!0);if(r)throw T(t);return e}finally{p.__wbindgen_add_to_stack_pointer(16)}}decrement(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorocounter_decrement(o,this.__wbg_ptr,e);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}get value(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorocounter_getShallowValue(o,this.__wbg_ptr);var e=b().getFloat64(o+0,!0),t=b().getInt32(o+8,!0),r=b().getInt32(o+12,!0);if(r)throw T(t);return e}finally{p.__wbindgen_add_to_stack_pointer(16)}}increment(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorocounter_increment(o,this.__wbg_ptr,e);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}subscribe(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorocounter_subscribe(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}}const sl=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_lorodoc_free(n>>>0,1));class sn{static __wrap(e){e=e>>>0;const t=Object.create(sn.prototype);return t.__wbg_ptr=e,sl.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,sl.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_lorodoc_free(e,0)}applyDiff(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_applyDiff(s,this.__wbg_ptr,P(e),Ae(t)?0:P(t));var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}isShallow(){return p.lorodoc_isShallow(this.__wbg_ptr)!==0}changeCount(){return p.lorodoc_changeCount(this.__wbg_ptr)>>>0}getByPath(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.lorodoc_getByPath(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getCounter(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getCounter(s,this.__wbg_ptr,mt(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Vr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}isDetached(){return p.lorodoc_isDetached(this.__wbg_ptr)!==0}get peerIdStr(){const e=p.lorodoc_peerIdStr(this.__wbg_ptr);return T(e)}setPeerId(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_setPeerId(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getCursorPos(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);jo(e,In),p.lorodoc_getCursorPos(s,this.__wbg_ptr,e.__wbg_ptr);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}hasContainer(e){return p.lorodoc_hasContainer(this.__wbg_ptr,P(e))!==0}importBatch(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_importBatch(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}cmpFrontiers(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16),a=Tt(e,p.__wbindgen_malloc),l=G,c=Tt(t,p.__wbindgen_malloc),u=G;p.lorodoc_cmpFrontiers(i,this.__wbg_ptr,a,l,c,u);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}debugHistory(){p.lorodoc_debugHistory(this.__wbg_ptr)}static fromSnapshot(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Xn(e,p.__wbindgen_malloc),a=G;p.lorodoc_fromSnapshot(s,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return sn.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getChangeAt(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getChangeAt(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}oplogVersion(){const e=p.lorodoc_oplogVersion(this.__wbg_ptr);return At.__wrap(e)}getMovableList(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getMovableList(s,this.__wbg_ptr,mt(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Xr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}frontiersToVV(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Tt(e,p.__wbindgen_malloc),a=G;p.lorodoc_frontiersToVV(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return At.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getAllChanges(){const e=p.lorodoc_getAllChanges(this.__wbg_ptr);return T(e)}oplogFrontiers(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_oplogFrontiers(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}vvToFrontiers(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);jo(e,At),p.lorodoc_vvToFrontiers(s,this.__wbg_ptr,e.__wbg_ptr);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}shallowSinceVV(){const e=p.lorodoc_shallowSinceVV(this.__wbg_ptr);return At.__wrap(e)}configTextStyle(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_configTextStyle(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getOpsInChange(e){try{const a=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getOpsInChange(a,this.__wbg_ptr,P(e));var t=b().getInt32(a+0,!0),r=b().getInt32(a+4,!0),o=b().getInt32(a+8,!0),s=b().getInt32(a+12,!0);if(s)throw T(o);var i=jt(t,r).slice();return p.__wbindgen_free(t,r*4,4),i}finally{p.__wbindgen_add_to_stack_pointer(16)}}getShallowValue(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getShallowValue(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}checkoutToLatest(){try{const r=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_checkoutToLatest(r,this.__wbg_ptr);var e=b().getInt32(r+0,!0),t=b().getInt32(r+4,!0);if(t)throw T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}cmpWithFrontiers(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Tt(e,p.__wbindgen_malloc),a=G;p.lorodoc_cmpWithFrontiers(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return t}finally{p.__wbindgen_add_to_stack_pointer(16)}}exportJsonInIdSpan(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_exportJsonInIdSpan(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}subscribeJsonpath(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16),a=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),l=G;p.lorodoc_subscribeJsonpath(i,this.__wbg_ptr,a,l,P(t));var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}deleteRootContainer(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_deleteRootContainer(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}exportJsonUpdates(e,t,r){try{const a=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_exportJsonUpdates(a,this.__wbg_ptr,P(e),P(t),Ae(r)?16777215:r?1:0);var o=b().getInt32(a+0,!0),s=b().getInt32(a+4,!0),i=b().getInt32(a+8,!0);if(i)throw T(s);return T(o)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getContainerById(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getContainerById(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getPendingTxnLength(){return p.lorodoc_getPendingTxnLength(this.__wbg_ptr)>>>0}importJsonUpdates(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_importJsonUpdates(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}importUpdateBatch(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_importBatch(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}setDetachedEditing(e){p.lorodoc_setDetachedEditing(this.__wbg_ptr,e)}setRecordTimestamp(e){p.lorodoc_setRecordTimestamp(this.__wbg_ptr,e)}subscribePreCommit(e){const t=p.lorodoc_subscribePreCommit(this.__wbg_ptr,P(e));return T(t)}findIdSpansBetween(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16),a=Tt(e,p.__wbindgen_malloc),l=G,c=Tt(t,p.__wbindgen_malloc),u=G;p.lorodoc_findIdSpansBetween(i,this.__wbg_ptr,a,l,c,u);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getChangeAtLamport(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16),a=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),l=G;p.lorodoc_getChangeAtLamport(i,this.__wbg_ptr,a,l,t);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getPathToContainer(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getPathToContainer(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}exportPendingUpdates(){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_exportPendingUpdates(s,this.__wbg_ptr);var e=b().getInt32(s+0,!0),t=b().getInt32(s+4,!0),r=b().getInt32(s+8,!0),o=b().getInt32(s+12,!0);if(o)throw T(r);let i;return e!==0&&(i=hn(e,t).slice(),p.__wbindgen_free(e,t*1,1)),i}finally{p.__wbindgen_add_to_stack_pointer(16)}}getChangedContainersIn(e,t){try{const l=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getChangedContainersIn(l,this.__wbg_ptr,P(e),t);var r=b().getInt32(l+0,!0),o=b().getInt32(l+4,!0),s=b().getInt32(l+8,!0),i=b().getInt32(l+12,!0);if(i)throw T(s);var a=jt(r,o).slice();return p.__wbindgen_free(r,o*4,4),a}finally{p.__wbindgen_add_to_stack_pointer(16)}}getDeepValueWithID(){const e=p.lorodoc_getDeepValueWithID(this.__wbg_ptr);return T(e)}setNextCommitOrigin(e){const t=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),r=G;p.lorodoc_setNextCommitOrigin(this.__wbg_ptr,t,r)}getUncommittedOpsAsJson(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getUncommittedOpsAsJson(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}setNextCommitMessage(e){const t=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),r=G;p.lorodoc_setNextCommitMessage(this.__wbg_ptr,t,r)}setNextCommitOptions(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_setNextCommitOptions(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}shallowSinceFrontiers(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_shallowSinceFrontiers(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}subscribeLocalUpdates(e){const t=p.lorodoc_subscribeLocalUpdates(this.__wbg_ptr,P(e));return T(t)}travelChangeAncestors(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Tt(e,p.__wbindgen_malloc),a=G;p.lorodoc_travelChangeAncestors(s,this.__wbg_ptr,i,a,P(t));var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}clearNextCommitOptions(){p.lorodoc_clearNextCommitOptions(this.__wbg_ptr)}configDefaultTextStyle(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_configDefaultTextStyle(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getDecodedValueCacheLimit(){return p.lorodoc_getDecodedValueCacheLimit(this.__wbg_ptr)>>>0}setChangeMergeInterval(e){p.lorodoc_setChangeMergeInterval(this.__wbg_ptr,e)}setNextCommitTimestamp(e){p.lorodoc_setNextCommitTimestamp(this.__wbg_ptr,e)}setHideEmptyRootContainers(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_setHideEmptyRootContainers(o,this.__wbg_ptr,e);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}isDetachedEditingEnabled(){return p.lorodoc_isDetachedEditingEnabled(this.__wbg_ptr)!==0}setDecodedValueCacheLimit(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_setDecodedValueCacheLimit(o,this.__wbg_ptr,e);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}subscribeFirstCommitFromPeer(e){const t=p.lorodoc_subscribeFirstCommitFromPeer(this.__wbg_ptr,P(e));return T(t)}constructor(){const e=p.lorodoc_new();return this.__wbg_ptr=e>>>0,sl.register(this,this.__wbg_ptr,this),this}diff(e,t,r){try{const a=p.__wbindgen_add_to_stack_pointer(-16),l=Tt(e,p.__wbindgen_malloc),c=G,u=Tt(t,p.__wbindgen_malloc),f=G;p.lorodoc_diff(a,this.__wbg_ptr,l,c,u,f,Ae(r)?16777215:r?1:0);var o=b().getInt32(a+0,!0),s=b().getInt32(a+4,!0),i=b().getInt32(a+8,!0);if(i)throw T(s);return T(o)}finally{p.__wbindgen_add_to_stack_pointer(16)}}fork(){const e=p.lorodoc_fork(this.__wbg_ptr);return sn.__wrap(e)}attach(){p.lorodoc_attach(this.__wbg_ptr)}commit(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_commit(o,this.__wbg_ptr,Ae(e)?0:P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}detach(){p.lorodoc_detach(this.__wbg_ptr)}export(e){try{const a=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_export(a,this.__wbg_ptr,P(e));var t=b().getInt32(a+0,!0),r=b().getInt32(a+4,!0),o=b().getInt32(a+8,!0),s=b().getInt32(a+12,!0);if(s)throw T(o);var i=hn(t,r).slice();return p.__wbindgen_free(t,r*1,1),i}finally{p.__wbindgen_add_to_stack_pointer(16)}}import(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Xn(e,p.__wbindgen_malloc),a=G;p.lorodoc_import(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}forkAt(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Tt(e,p.__wbindgen_malloc),a=G;p.lorodoc_forkAt(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return sn.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getMap(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getMap(s,this.__wbg_ptr,mt(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Gn.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}opCount(){return p.lorodoc_opCount(this.__wbg_ptr)>>>0}get peerId(){const e=p.lorodoc_peerId(this.__wbg_ptr);return BigInt.asUintN(64,e)}toJSON(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_toJSON(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}version(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_version(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return At.__wrap(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}checkout(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16),s=Tt(e,p.__wbindgen_malloc),i=G;p.lorodoc_checkout(o,this.__wbg_ptr,s,i);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getList(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getList(s,this.__wbg_ptr,mt(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Yr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}getText(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getText(s,this.__wbg_ptr,mt(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Gr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}getTree(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getTree(s,this.__wbg_ptr,mt(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Zr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}frontiers(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_frontiers(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}JSONPath(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.lorodoc_JSONPath(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}revertTo(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16),s=Tt(e,p.__wbindgen_malloc),i=G;p.lorodoc_revertTo(o,this.__wbg_ptr,s,i);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}subscribe(e){const t=p.lorodoc_subscribe(this.__wbg_ptr,P(e));return T(t)}toContainerTree(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_toContainerTree(s,this.__wbg_ptr,Ae(e)?0:P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toContainerTreeJson(e){let t,r;try{const u=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_toContainerTreeJson(u,this.__wbg_ptr,Ae(e)?0:P(e));var o=b().getInt32(u+0,!0),s=b().getInt32(u+4,!0),i=b().getInt32(u+8,!0),a=b().getInt32(u+12,!0),l=o,c=s;if(a)throw l=0,c=0,T(i);return t=l,r=c,Ue(l,c)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_free(t,r,1)}}}const il=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_lorolist_free(n>>>0,1));class Yr{static __wrap(e){e=e>>>0;const t=Object.create(Yr.prototype);return t.__wbg_ptr=e,il.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,il.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_lorolist_free(e,0)}isAttached(){return p.lorolist_isAttached(this.__wbg_ptr)!==0}getAttached(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_getAttached(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}pushContainer(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_pushContainer(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getRangeValue(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_getRangeValue(i,this.__wbg_ptr,e,t);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}insertContainer(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_insertContainer(i,this.__wbg_ptr,e,P(t));var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getShallowValue(){const e=p.lorolist_getShallowValue(this.__wbg_ptr);return T(e)}getDeepValueWithID(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_getDeepValueWithID(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getRangeDeepValueWithID(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_getRangeDeepValueWithID(i,this.__wbg_ptr,e,t);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}get id(){const e=p.lorolist_id(this.__wbg_ptr);return T(e)}get(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_get(s,this.__wbg_ptr,e);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}constructor(){const e=p.lorolist_new();return this.__wbg_ptr=e>>>0,il.register(this,this.__wbg_ptr,this),this}pop(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_pop(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}kind(){const e=p.lorolist_kind(this.__wbg_ptr);return T(e)}push(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_push(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}clear(){try{const r=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_clear(r,this.__wbg_ptr);var e=b().getInt32(r+0,!0),t=b().getInt32(r+4,!0);if(t)throw T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}delete(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_delete(s,this.__wbg_ptr,e,t);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}insert(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_insert(s,this.__wbg_ptr,e,P(t));var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}get length(){return p.lorolist_length(this.__wbg_ptr)>>>0}parent(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_parent(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getIdAt(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_getIdAt(s,this.__wbg_ptr,e);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toJSON(){const e=p.lorolist_toJSON(this.__wbg_ptr);return T(e)}toArray(){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_toArray(i,this.__wbg_ptr);var e=b().getInt32(i+0,!0),t=b().getInt32(i+4,!0),r=b().getInt32(i+8,!0),o=b().getInt32(i+12,!0);if(o)throw T(r);var s=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),s}finally{p.__wbindgen_add_to_stack_pointer(16)}}getCursor(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_getCursor(i,this.__wbg_ptr,e,P(t));var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return r===0?void 0:In.__wrap(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}isDeleted(){return p.lorolist_isDeleted(this.__wbg_ptr)!==0}subscribe(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_subscribe(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toContainerTree(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_toContainerTree(s,this.__wbg_ptr,Ae(e)?0:P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toContainerTreeSlice(e,t,r){try{const a=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_toContainerTreeSlice(a,this.__wbg_ptr,e,t,Ae(r)?0:P(r));var o=b().getInt32(a+0,!0),s=b().getInt32(a+4,!0),i=b().getInt32(a+8,!0);if(i)throw T(s);return T(o)}finally{p.__wbindgen_add_to_stack_pointer(16)}}}const al=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_loromap_free(n>>>0,1));class Gn{static __wrap(e){e=e>>>0;const t=Object.create(Gn.prototype);return t.__wbg_ptr=e,al.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,al.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_loromap_free(e,0)}isAttached(){return p.loromap_isAttached(this.__wbg_ptr)!==0}getAttached(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.loromap_getAttached(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getLastEditor(e){const t=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),r=G,o=p.loromap_getLastEditor(this.__wbg_ptr,t,r);return T(o)}setContainer(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16),a=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),l=G;p.loromap_setContainer(i,this.__wbg_ptr,a,l,P(t));var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getShallowValue(){const e=p.loromap_getShallowValue(this.__wbg_ptr);return T(e)}ensureMergeableMap(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.loromap_ensureMergeableMap(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Gn.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}ensureMergeableList(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.loromap_ensureMergeableList(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Yr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}ensureMergeableText(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.loromap_ensureMergeableText(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Gr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}ensureMergeableTree(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.loromap_ensureMergeableTree(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Zr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getDeepValueWithID(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.loromap_getDeepValueWithID(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getOrCreateContainer(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16),a=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),l=G;p.loromap_getOrCreateContainer(i,this.__wbg_ptr,a,l,P(t));var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}ensureMergeableCounter(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.loromap_ensureMergeableCounter(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Vr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}ensureMergeableMovableList(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.loromap_ensureMergeableMovableList(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Xr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}get id(){const e=p.loromap_id(this.__wbg_ptr);return T(e)}get(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.loromap_get(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}constructor(){const e=p.loromap_new();return this.__wbg_ptr=e>>>0,al.register(this,this.__wbg_ptr,this),this}keys(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.loromap_keys(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}kind(){const e=p.loromap_kind(this.__wbg_ptr);return T(e)}get size(){return p.loromap_size(this.__wbg_ptr)>>>0}clear(){try{const r=p.__wbindgen_add_to_stack_pointer(-16);p.loromap_clear(r,this.__wbg_ptr);var e=b().getInt32(r+0,!0),t=b().getInt32(r+4,!0);if(t)throw T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}delete(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16),s=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),i=G;p.loromap_delete(o,this.__wbg_ptr,s,i);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}set(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.loromap_set(s,this.__wbg_ptr,i,a,P(t));var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}parent(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.loromap_parent(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}values(){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.loromap_values(i,this.__wbg_ptr);var e=b().getInt32(i+0,!0),t=b().getInt32(i+4,!0),r=b().getInt32(i+8,!0),o=b().getInt32(i+12,!0);if(o)throw T(r);var s=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),s}finally{p.__wbindgen_add_to_stack_pointer(16)}}entries(){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.loromap_entries(i,this.__wbg_ptr);var e=b().getInt32(i+0,!0),t=b().getInt32(i+4,!0),r=b().getInt32(i+8,!0),o=b().getInt32(i+12,!0);if(o)throw T(r);var s=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),s}finally{p.__wbindgen_add_to_stack_pointer(16)}}toJSON(){const e=p.loromap_toJSON(this.__wbg_ptr);return T(e)}isDeleted(){return p.loromap_isDeleted(this.__wbg_ptr)!==0}subscribe(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromap_subscribe(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toContainerTree(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromap_toContainerTree(s,this.__wbg_ptr,Ae(e)?0:P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}}const ll=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_loromovablelist_free(n>>>0,1));class Xr{static __wrap(e){e=e>>>0;const t=Object.create(Xr.prototype);return t.__wbg_ptr=e,ll.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,ll.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_loromovablelist_free(e,0)}isAttached(){return p.loromovablelist_isAttached(this.__wbg_ptr)!==0}getCreatorAt(e){const t=p.loromovablelist_getCreatorAt(this.__wbg_ptr,e);return T(t)}getAttached(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_getAttached(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}setContainer(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_setContainer(i,this.__wbg_ptr,e,P(t));var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getLastMoverAt(e){const t=p.loromovablelist_getLastMoverAt(this.__wbg_ptr,e);return T(t)}pushContainer(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_pushContainer(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getLastEditorAt(e){const t=p.loromovablelist_getLastEditorAt(this.__wbg_ptr,e);return T(t)}getRangeValue(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_getRangeValue(i,this.__wbg_ptr,e,t);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}insertContainer(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_insertContainer(i,this.__wbg_ptr,e,P(t));var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getShallowValue(){const e=p.loromovablelist_getShallowValue(this.__wbg_ptr);return T(e)}getDeepValueWithID(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_getDeepValueWithID(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getRangeDeepValueWithID(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_getRangeDeepValueWithID(i,this.__wbg_ptr,e,t);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}get id(){const e=p.loromovablelist_id(this.__wbg_ptr);return T(e)}get(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_get(s,this.__wbg_ptr,e);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}move(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_move(s,this.__wbg_ptr,e,t);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}constructor(){const e=p.loromovablelist_new();return this.__wbg_ptr=e>>>0,ll.register(this,this.__wbg_ptr,this),this}pop(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_pop(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}set(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_set(s,this.__wbg_ptr,e,P(t));var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}kind(){const e=p.loromovablelist_kind(this.__wbg_ptr);return T(e)}push(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_push(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}clear(){try{const r=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_clear(r,this.__wbg_ptr);var e=b().getInt32(r+0,!0),t=b().getInt32(r+4,!0);if(t)throw T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}delete(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_delete(s,this.__wbg_ptr,e,t);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}insert(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_insert(s,this.__wbg_ptr,e,P(t));var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}get length(){return p.loromovablelist_length(this.__wbg_ptr)>>>0}parent(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_parent(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toJSON(){const e=p.loromovablelist_toJSON(this.__wbg_ptr);return T(e)}toArray(){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_toArray(i,this.__wbg_ptr);var e=b().getInt32(i+0,!0),t=b().getInt32(i+4,!0),r=b().getInt32(i+8,!0),o=b().getInt32(i+12,!0);if(o)throw T(r);var s=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),s}finally{p.__wbindgen_add_to_stack_pointer(16)}}getCursor(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_getCursor(i,this.__wbg_ptr,e,P(t));var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return r===0?void 0:In.__wrap(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}isDeleted(){return p.loromovablelist_isDeleted(this.__wbg_ptr)!==0}subscribe(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_subscribe(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toContainerTree(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_toContainerTree(s,this.__wbg_ptr,Ae(e)?0:P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toContainerTreeSlice(e,t,r){try{const a=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_toContainerTreeSlice(a,this.__wbg_ptr,e,t,Ae(r)?0:P(r));var o=b().getInt32(a+0,!0),s=b().getInt32(a+4,!0),i=b().getInt32(a+8,!0);if(i)throw T(s);return T(o)}finally{p.__wbindgen_add_to_stack_pointer(16)}}}const cl=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_lorotext_free(n>>>0,1));class Gr{static __wrap(e){e=e>>>0;const t=Object.create(Gr.prototype);return t.__wbg_ptr=e,cl.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,cl.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_lorotext_free(e,0)}applyDelta(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_applyDelta(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}convertPos(e,t,r){const o=_e(t,p.__wbindgen_malloc,p.__wbindgen_realloc),s=G,i=_e(r,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G,l=p.lorotext_convertPos(this.__wbg_ptr,e,o,s,i,a);return T(l)}deleteUtf8(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_deleteUtf8(s,this.__wbg_ptr,e,t);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getEditorOf(e){const t=p.lorotext_getEditorOf(this.__wbg_ptr,e);return T(t)}insertUtf8(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(t,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.lorotext_insertUtf8(s,this.__wbg_ptr,e,i,a);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}isAttached(){return p.lorotext_isAttached(this.__wbg_ptr)!==0}sliceDelta(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_sliceDelta(i,this.__wbg_ptr,e,t);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getAttached(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_getAttached(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}updateByLine(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.lorotext_updateByLine(s,this.__wbg_ptr,i,a,P(t));var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}sliceDeltaUtf8(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_sliceDeltaUtf8(i,this.__wbg_ptr,e,t);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getShallowValue(){let e,t;try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_getShallowValue(s,this.__wbg_ptr);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);return e=r,t=o,Ue(r,o)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_free(e,t,1)}}getDeepValueWithID(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_getDeepValueWithID(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}get id(){const e=p.lorotext_id(this.__wbg_ptr);return T(e)}constructor(){const e=p.lorotext_new();return this.__wbg_ptr=e>>>0,cl.register(this,this.__wbg_ptr,this),this}iter(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_iter(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}kind(){const e=p.lorotext_kind(this.__wbg_ptr);return T(e)}mark(e,t,r){try{const i=p.__wbindgen_add_to_stack_pointer(-16),a=_e(t,p.__wbindgen_malloc,p.__wbindgen_realloc),l=G;p.lorotext_mark(i,this.__wbg_ptr,P(e),a,l,P(r));var o=b().getInt32(i+0,!0),s=b().getInt32(i+4,!0);if(s)throw T(o)}finally{p.__wbindgen_add_to_stack_pointer(16)}}push(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16),s=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),i=G;p.lorotext_push(o,this.__wbg_ptr,s,i);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}slice(e,t){let r,o;try{const f=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_slice(f,this.__wbg_ptr,e,t);var s=b().getInt32(f+0,!0),i=b().getInt32(f+4,!0),a=b().getInt32(f+8,!0),l=b().getInt32(f+12,!0),c=s,u=i;if(l)throw c=0,u=0,T(a);return r=c,o=u,Ue(c,u)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_free(r,o,1)}}delete(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_delete(s,this.__wbg_ptr,e,t);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}insert(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(t,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.lorotext_insert(s,this.__wbg_ptr,e,i,a);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}get length(){return p.lorotext_length(this.__wbg_ptr)>>>0}parent(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_parent(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}splice(e,t,r){let o,s;try{const d=p.__wbindgen_add_to_stack_pointer(-16),g=_e(r,p.__wbindgen_malloc,p.__wbindgen_realloc),h=G;p.lorotext_splice(d,this.__wbg_ptr,e,t,g,h);var i=b().getInt32(d+0,!0),a=b().getInt32(d+4,!0),l=b().getInt32(d+8,!0),c=b().getInt32(d+12,!0),u=i,f=a;if(c)throw u=0,f=0,T(l);return o=u,s=f,Ue(u,f)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_free(o,s,1)}}unmark(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(t,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.lorotext_unmark(s,this.__wbg_ptr,P(e),i,a);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}update(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.lorotext_update(s,this.__wbg_ptr,i,a,P(t));var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}charAt(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_charAt(s,this.__wbg_ptr,e);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return String.fromCodePoint(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toJSON(){const e=p.lorotext_toJSON(this.__wbg_ptr);return T(e)}toDelta(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_toDelta(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getCursor(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_getCursor(i,this.__wbg_ptr,e,P(t));var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return r===0?void 0:In.__wrap(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}isDeleted(){return p.lorotext_isDeleted(this.__wbg_ptr)!==0}subscribe(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_subscribe(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toString(){let e,t;try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_toString(s,this.__wbg_ptr);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);return e=r,t=o,Ue(r,o)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_free(e,t,1)}}toContainerTree(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_toContainerTree(s,this.__wbg_ptr,Ae(e)?0:P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}}const ul=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_lorotree_free(n>>>0,1));class Zr{static __wrap(e){e=e>>>0;const t=Object.create(Zr.prototype);return t.__wbg_ptr=e,ul.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,ul.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_lorotree_free(e,0)}createNode(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_createNode(i,this.__wbg_ptr,mt(e),Ae(t)?4294967297:t>>>0);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return on.__wrap(r)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}isAttached(){return p.lorotree_isAttached(this.__wbg_ptr)!==0}getAttached(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_getAttached(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getNodeByID(e){try{const t=p.lorotree_getNodeByID(this.__wbg_ptr,mt(e));return t===0?void 0:on.__wrap(t)}finally{Be[et++]=void 0}}isNodeDeleted(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_isNodeDeleted(s,this.__wbg_ptr,mt(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return t!==0}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}getShallowValue(){const e=p.lorotree_getShallowValue(this.__wbg_ptr);return T(e)}getDeepValueWithID(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_getDeepValueWithID(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}enableFractionalIndex(e){p.lorotree_enableFractionalIndex(this.__wbg_ptr,e)}disableFractionalIndex(){p.lorotree_disableFractionalIndex(this.__wbg_ptr)}isFractionalIndexEnabled(){return p.lorotree_isFractionalIndexEnabled(this.__wbg_ptr)!==0}get id(){const e=p.lorotree_id(this.__wbg_ptr);return T(e)}move(e,t,r){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_move(i,this.__wbg_ptr,mt(e),mt(t),Ae(r)?4294967297:r>>>0);var o=b().getInt32(i+0,!0),s=b().getInt32(i+4,!0);if(s)throw T(o)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0,Be[et++]=void 0}}constructor(){const e=p.lorotree_new();return this.__wbg_ptr=e>>>0,ul.register(this,this.__wbg_ptr,this),this}kind(){const e=p.lorotree_kind(this.__wbg_ptr);return T(e)}nodes(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_nodes(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}roots(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_roots(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}delete(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_delete(o,this.__wbg_ptr,mt(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}parent(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_parent(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toJSON(){const e=p.lorotree_toJSON(this.__wbg_ptr);return T(e)}has(e){try{return p.lorotree_has(this.__wbg_ptr,mt(e))!==0}finally{Be[et++]=void 0}}toArray(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_toArray(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getNodes(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_getNodes(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}isDeleted(){return p.lorotree_isDeleted(this.__wbg_ptr)!==0}subscribe(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_subscribe(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toContainerTree(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_toContainerTree(s,this.__wbg_ptr,Ae(e)?0:P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}}const pg=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_lorotreenode_free(n>>>0,1));class on{static __wrap(e){e=e>>>0;const t=Object.create(on.prototype);return t.__wbg_ptr=e,pg.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,pg.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_lorotreenode_free(e,0)}__getClassname(){let e,t;try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode___getClassname(s,this.__wbg_ptr);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);return e=r,t=o,Ue(r,o)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_free(e,t,1)}}creationId(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_creationId(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}isDeleted(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_isDeleted(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return e!==0}finally{p.__wbindgen_add_to_stack_pointer(16)}}moveBefore(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);jo(e,on),p.lorotreenode_moveBefore(o,this.__wbg_ptr,e.__wbg_ptr);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}createNode(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_createNode(s,this.__wbg_ptr,Ae(e)?4294967297:e>>>0);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return on.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getLastMoveId(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_getLastMoveId(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toJSON(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_toJSON(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}fractionalIndex(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_fractionalIndex(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}get id(){const e=p.lorotreenode_id(this.__wbg_ptr);return T(e)}move(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_move(s,this.__wbg_ptr,mt(e),Ae(t)?4294967297:t>>>0);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}get data(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_data(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return Gn.__wrap(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}index(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_index(o,this.__wbg_ptr);var e=b().getFloat64(o+0,!0),t=b().getInt32(o+8,!0),r=b().getInt32(o+12,!0);if(r)throw T(t);return e===4294967297?void 0:e}finally{p.__wbindgen_add_to_stack_pointer(16)}}parent(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_parent(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return e===0?void 0:on.__wrap(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}creator(){const e=p.lorotreenode_creator(this.__wbg_ptr);return T(e)}children(){const e=p.lorotreenode_children(this.__wbg_ptr);return T(e)}moveAfter(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);jo(e,on),p.lorotreenode_moveAfter(o,this.__wbg_ptr,e.__wbg_ptr);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}}const hg=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_undomanager_free(n>>>0,1));class Wu{__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,hg.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_undomanager_free(e,0)}groupStart(){try{const r=p.__wbindgen_add_to_stack_pointer(-16);p.undomanager_groupStart(r,this.__wbg_ptr);var e=b().getInt32(r+0,!0),t=b().getInt32(r+4,!0);if(t)throw T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}topRedoValue(){const e=p.undomanager_topRedoValue(this.__wbg_ptr);return T(e)}topUndoValue(){const e=p.undomanager_topUndoValue(this.__wbg_ptr);return T(e)}setMaxUndoSteps(e){p.undomanager_setMaxUndoSteps(this.__wbg_ptr,e)}setMergeInterval(e){p.undomanager_setMergeInterval(this.__wbg_ptr,e)}addExcludeOriginPrefix(e){const t=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),r=G;p.undomanager_addExcludeOriginPrefix(this.__wbg_ptr,t,r)}constructor(e,t){jo(e,sn);const r=p.undomanager_new(e.__wbg_ptr,P(t));return this.__wbg_ptr=r>>>0,hg.register(this,this.__wbg_ptr,this),this}peer(){const e=p.undomanager_peer(this.__wbg_ptr);return T(e)}redo(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.undomanager_redo(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return e!==0}finally{p.__wbindgen_add_to_stack_pointer(16)}}undo(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.undomanager_undo(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return e!==0}finally{p.__wbindgen_add_to_stack_pointer(16)}}clear(){p.undomanager_clear(this.__wbg_ptr)}pause(){p.undomanager_pause(this.__wbg_ptr)}resume(){p.undomanager_resume(this.__wbg_ptr)}canRedo(){return p.undomanager_canRedo(this.__wbg_ptr)!==0}canUndo(){return p.undomanager_canUndo(this.__wbg_ptr)!==0}groupEnd(){p.undomanager_groupEnd(this.__wbg_ptr)}isPaused(){return p.undomanager_isPaused(this.__wbg_ptr)!==0}setOnPop(e){p.undomanager_setOnPop(this.__wbg_ptr,P(e))}clearRedo(){p.undomanager_clearRedo(this.__wbg_ptr)}clearUndo(){p.undomanager_clearUndo(this.__wbg_ptr)}setOnPush(e){p.undomanager_setOnPush(this.__wbg_ptr,P(e))}}const dl=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_versionvector_free(n>>>0,1));class At{static __wrap(e){e=e>>>0;const t=Object.create(At.prototype);return t.__wbg_ptr=e,dl.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,dl.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_versionvector_free(e,0)}get(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.versionvector_get(s,this.__wbg_ptr,P(e));var t=b().getFloat64(s+0,!0),r=b().getInt32(s+8,!0),o=b().getInt32(s+12,!0);if(o)throw T(r);return t===4294967297?void 0:t}finally{p.__wbindgen_add_to_stack_pointer(16)}}constructor(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.versionvector_new(s,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return this.__wbg_ptr=t>>>0,dl.register(this,this.__wbg_ptr,this),this}finally{p.__wbindgen_add_to_stack_pointer(16)}}static decode(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Xn(e,p.__wbindgen_malloc),a=G;p.versionvector_decode(s,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return At.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}encode(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.versionvector_encode(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=hn(e,t).slice();return p.__wbindgen_free(e,t*1,1),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}length(){return p.versionvector_length(this.__wbg_ptr)>>>0}remove(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.versionvector_remove(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}setEnd(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.versionvector_setEnd(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}compare(e){jo(e,At);const t=p.versionvector_compare(this.__wbg_ptr,e.__wbg_ptr);return t===4294967297?void 0:t}setLast(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.versionvector_setLast(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toJSON(){const e=p.versionvector_toJSON(this.__wbg_ptr);return T(e)}static parseJSON(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.versionvector_parseJSON(s,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return At.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}}function Kk(n,e){const t=String(W(e)),r=_e(t,p.__wbindgen_malloc,p.__wbindgen_realloc),o=G;b().setInt32(n+4,o,!0),b().setInt32(n+0,r,!0)}function Wk(){return nt(function(n,e,t){const r=W(n).apply(W(e),W(t));return P(r)},arguments)}function Hk(){return nt(function(n,e,t){const r=Reflect.apply(W(n),W(e),W(t));return P(r)},arguments)}function Jk(n){const e=W(n).buffer;return P(e)}function qk(){return nt(function(n,e){const t=W(n).call(W(e));return P(t)},arguments)}function Vk(){return nt(function(n,e,t){const r=W(n).call(W(e),W(t));return P(r)},arguments)}function Yk(){return nt(function(n,e,t,r){const o=W(n).call(W(e),W(t),W(r));return P(o)},arguments)}function Xk(){return nt(function(n,e,t,r,o){const s=W(n).call(W(e),W(t),W(r),W(o));return P(s)},arguments)}function Gk(n){const e=To.__wrap(n);return P(e)}function Zk(n){const e=W(n).crypto;return P(e)}function Qk(n){const e=In.__wrap(n);return P(e)}function eT(n){return W(n).done}function tT(n){const e=Object.entries(W(n));return P(e)}function nT(n){const e=W(n).entries();return P(e)}function rT(n,e){console.error(Ue(n,e))}function oT(n){const e=Array.from(W(n));return P(e)}function sT(n){const e=Object.getOwnPropertySymbols(W(n));return P(e)}function iT(){return nt(function(n,e){W(n).getRandomValues(W(e))},arguments)}function aT(){return nt(function(n,e){const t=Reflect.get(W(n),W(e));return P(t)},arguments)}function lT(n,e){const t=W(n)[e>>>0];return P(t)}function cT(n,e){return W(n)[e>>>0]}function uT(n,e){const t=W(n)[W(e)];return P(t)}function dT(n){let e;try{e=W(n)instanceof ArrayBuffer}catch{e=!1}return e}function fT(n){let e;try{e=W(n)instanceof Map}catch{e=!1}return e}function gT(n){let e;try{e=W(n)instanceof Object}catch{e=!1}return e}function pT(n){let e;try{e=W(n)instanceof Uint8Array}catch{e=!1}return e}function hT(n){return Array.isArray(W(n))}function _T(n){return Number.isSafeInteger(W(n))}function mT(){return P(Symbol.iterator)}function bT(n){return W(n).length}function yT(n){return W(n).length}function wT(n,e,t,r,o,s,i,a){let l,c;try{l=n,c=e,console.log(Ue(n,e),Ue(t,r),Ue(o,s),Ue(i,a))}finally{p.__wbindgen_free(l,c,1)}}function xT(n,e){console.log(Ue(n,e))}function CT(n,e){let t,r;try{t=n,r=e,console.log(Ue(n,e))}finally{p.__wbindgen_free(t,r,1)}}function ST(n){const e=Vr.__wrap(n);return P(e)}function vT(n){const e=Yr.__wrap(n);return P(e)}function kT(n){const e=Gn.__wrap(n);return P(e)}function TT(n){const e=Xr.__wrap(n);return P(e)}function IT(n){const e=Gr.__wrap(n);return P(e)}function ET(n){const e=Zr.__wrap(n);return P(e)}function NT(n){const e=on.__wrap(n);return P(e)}function LT(n,e){performance.mark(Ue(n,e))}function OT(){return nt(function(n,e,t,r){let o,s,i,a;try{o=n,s=e,i=t,a=r,performance.measure(Ue(n,e),Ue(t,r))}finally{p.__wbindgen_free(o,s,1),p.__wbindgen_free(i,a,1)}},arguments)}function RT(n){const e=W(n).msCrypto;return P(e)}function AT(){const n=new Object;return P(n)}function MT(){return P(new Map)}function $T(){const n=new Array;return P(n)}function DT(n){const e=new Uint8Array(W(n));return P(e)}function PT(n,e){const t=new Error(Ue(n,e));return P(t)}function jT(n,e){const t=new Function(Ue(n,e));return P(t)}function FT(n,e,t){const r=new Uint8Array(W(n),e>>>0,t>>>0);return P(r)}function BT(n){const e=new Uint8Array(n>>>0);return P(e)}function UT(n){const e=new Array(n>>>0);return P(e)}function zT(n){const e=W(n).next;return P(e)}function KT(){return nt(function(n){const e=W(n).next();return P(e)},arguments)}function WT(n){const e=W(n).node;return P(e)}function HT(){return Date.now()}function JT(){return nt(function(n){const e=Reflect.ownKeys(W(n));return P(e)},arguments)}function qT(n){const e=W(n).process;return P(e)}function VT(n,e){return W(n).push(W(e))}function YT(){return nt(function(n,e){W(n).randomFillSync(T(e))},arguments)}function XT(){return nt(function(){const n=module.require;return P(n)},arguments)}function GT(n){const e=Promise.resolve(W(n));return P(e)}function ZT(n,e,t){W(n)[e>>>0]=T(t)}function QT(n,e,t){W(n)[T(e)]=T(t)}function eI(n,e,t){W(n).set(W(e),t>>>0)}function tI(n,e,t){const r=W(n).set(W(e),W(t));return P(r)}function nI(){return nt(function(n,e,t){return Reflect.set(W(n),W(e),W(t))},arguments)}function rI(n,e){const t=Tk(hn(n,e));return P(t)}function oI(n,e,t){const r=Sk(W(n),e,t);return P(r)}function sI(n,e,t){const r=Ck(n,W(e),T(t));return P(r)}function iI(){return nt(function(n,e,t){Ik(W(n),e>>>0,W(t))},arguments)}function aI(){return nt(function(n,e){const t=wk(T(n),e!==0);return P(t)},arguments)}function lI(n,e,t){const r=vk(Ue(n,e),t);return P(r)}function cI(){return nt(function(n,e,t){Ek(W(n),W(e),W(t))},arguments)}function uI(n,e,t){const r=xk(T(n),e>>>0,t>>>0);return P(r)}function dI(n){const e=kk(T(n));return P(e)}function fI(){const n=typeof globalThis>"u"?null:globalThis;return Ae(n)?0:P(n)}function gI(){const n=typeof globalThis>"u"?null:globalThis;return Ae(n)?0:P(n)}function pI(){const n=typeof self>"u"?null:self;return Ae(n)?0:P(n)}function hI(){const n=typeof window>"u"?null:window;return Ae(n)?0:P(n)}function _I(n,e,t){const r=W(n).subarray(e>>>0,t>>>0);return P(r)}function mI(n,e){const t=W(n).then(W(e));return P(t)}function bI(n){const e=W(n).value;return P(e)}function yI(n){const e=W(n).versions;return P(e)}function wI(n){const e=At.__wrap(n);return P(e)}function xI(n,e){console.warn(Ue(n,e))}function CI(n){return+W(n)}function SI(n){return P(n)}function vI(n){const e=BigInt.asUintN(64,n);return P(e)}function kI(n,e){const t=W(e),r=typeof t=="bigint"?t:void 0;b().setBigInt64(n+8,Ae(r)?BigInt(0):r,!0),b().setInt32(n+0,!Ae(r),!0)}function TI(n){const e=W(n);return typeof e=="boolean"?e?1:0:2}function II(n){const e=T(n).original;return e.cnt--==1?(e.a=0,!0):!1}function EI(n,e,t){const r=Rm(n,e,16,Bk);return P(r)}function NI(n,e,t){const r=Rm(n,e,16,Uk);return P(r)}function LI(n,e){const t=dc(W(e)),r=_e(t,p.__wbindgen_malloc,p.__wbindgen_realloc),o=G;b().setInt32(n+4,o,!0),b().setInt32(n+0,r,!0)}function OI(n,e){const t=new Error(Ue(n,e));return P(t)}function RI(n,e){return W(n)in W(e)}function AI(n){return Array.isArray(W(n))}function MI(n){return typeof W(n)=="bigint"}function $I(n){return typeof W(n)=="function"}function DI(n){return W(n)===null}function PI(n){const e=W(n);return typeof e=="object"&&e!==null}function jI(n){return typeof W(n)=="string"}function FI(n){return W(n)===void 0}function BI(n,e){return W(n)===W(e)}function UI(n,e){return W(n)==W(e)}function zI(){const n=p.memory;return P(n)}function KI(n,e){const t=W(e),r=typeof t=="number"?t:void 0;b().setFloat64(n+8,Ae(r)?0:r,!0),b().setInt32(n+0,!Ae(r),!0)}function WI(n){return P(n)}function HI(n){const e=W(n);return P(e)}function JI(n){T(n)}function qI(n){throw T(n)}function VI(n,e){const t=W(e),r=typeof t=="string"?t:void 0;var o=Ae(r)?0:_e(r,p.__wbindgen_malloc,p.__wbindgen_realloc),s=G;b().setInt32(n+4,s,!0),b().setInt32(n+0,o,!0)}function YI(n,e){const t=Ue(n,e);return P(t)}function XI(n,e){throw new Error(Ue(n,e))}function GI(n){const e=typeof W(n);return P(e)}const fl=Symbol("loroContainerId");function ZI(n){const e=n.prototype,t=Object.getOwnPropertyDescriptor(e,"id"),r=t&&t.get,o=Object.getOwnPropertyDescriptor(e,"__destroy_into_raw"),s=o&&o.value;if(!r||!o||!s)throw new Error("Unexpected wasm-bindgen container wrapper shape");Object.defineProperty(e,"id",{...t,get(){if(this.__wbg_ptr===0)return r.call(this);const i=this[fl];if(i!==void 0)return i;const a=r.call(this);try{Object.defineProperty(this,fl,{configurable:!0,value:a})}catch{}return a}}),Object.defineProperty(e,"__destroy_into_raw",{...o,value(){try{delete this[fl]}catch{}return s.call(this)}})}function QI(n){const e=n.prototype,t=Object.getOwnPropertyDescriptor(e,"kind"),r=t&&t.value;if(typeof r!="function")throw new Error("Unexpected wasm-bindgen container wrapper shape");let o;Object.defineProperty(e,"kind",{...t,value(){return this.__wbg_ptr===0?r.call(this):(o===void 0&&(o=r.call(this)),o)}})}for(const n of[Gn,Gr,Yr,Zr,Xr,Vr])ZI(n),QI(n);const Mm={AwarenessWasm:zk,ChangeModifier:To,Cursor:In,EphemeralStoreWasm:Ku,LORO_VERSION:Mk,LoroCounter:Vr,LoroDoc:sn,LoroList:Yr,LoroMap:Gn,LoroMovableList:Xr,LoroText:Gr,LoroTree:Zr,LoroTreeNode:on,UndoManager:Wu,VersionVector:At,__wbg_String_8f0eb39a4a4c2f66:Kk,__wbg_apply_36be6a55257c99bf:Wk,__wbg_apply_eb9e9b97497f91e4:Hk,__wbg_buffer_609cc3eee51ed158:Jk,__wbg_call_672a4d21634d4a24:qk,__wbg_call_7cccdd69e0791ae2:Vk,__wbg_call_833bed5770ea2041:Yk,__wbg_call_b8adc8b1d0a0d8eb:Xk,__wbg_changemodifier_new:Gk,__wbg_crypto_574e78ad8b13b65f:Zk,__wbg_cursor_new:Qk,__wbg_done_769e5ede4b31c67b:eT,__wbg_entries_3265d4158b33e5dc:tT,__wbg_entries_c8a90a7ed73e84ce:nT,__wbg_error_428bae4e36b351e3:rT,__wbg_from_2a5d3e218e67aa85:oT,__wbg_getOwnPropertySymbols_97eebed6fe6e08be:sT,__wbg_getRandomValues_b8f5dbd5f3995a9e:iT,__wbg_get_67b2ba62fc30de12:aT,__wbg_get_b9b93047fe3cf45b:lT,__wbg_getindex_5b00c274b05714aa:cT,__wbg_getwithrefkey_1dc361bd10053bfe:uT,__wbg_instanceof_ArrayBuffer_e14585432e3737fc:dT,__wbg_instanceof_Map_f3469ce2244d2430:fT,__wbg_instanceof_Object_7f2dcef8f78644a4:gT,__wbg_instanceof_Uint8Array_17156bcf118086a9:pT,__wbg_isArray_a1eab7e0d067391b:hT,__wbg_isSafeInteger_343e2beeeece1bb0:_T,__wbg_iterator_9a24c88df860dc65:mT,__wbg_length_a446193dc22c12f8:bT,__wbg_length_e2d2a49132c1b256:yT,__wbg_log_0cc1b7768397bcfe:wT,__wbg_log_882f657276590a29:xT,__wbg_log_cb9e190acc5753fb:CT,__wbg_lorocounter_new:ST,__wbg_lorolist_new:vT,__wbg_loromap_new:kT,__wbg_loromovablelist_new:TT,__wbg_lorotext_new:IT,__wbg_lorotree_new:ET,__wbg_lorotreenode_new:NT,__wbg_mark_7438147ce31e9d4b:LT,__wbg_measure_fb7825c11612c823:OT,__wbg_msCrypto_a61aeb35a24c1329:RT,__wbg_new_405e22f390576ce2:AT,__wbg_new_5e0be73521bc8c17:MT,__wbg_new_78feb108b6472713:$T,__wbg_new_a12002a7f91c75be:DT,__wbg_new_c68d7209be747379:PT,__wbg_newnoargs_105ed471475aaf50:jT,__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a:FT,__wbg_newwithlength_a381634e90c276d4:BT,__wbg_newwithlength_c4c419ef0bc8a1f8:UT,__wbg_next_25feadfc0913fea9:zT,__wbg_next_6574e1a8a62d1055:KT,__wbg_node_905d3e251edff8a2:WT,__wbg_now_2b509d5c9d429404:HT,__wbg_ownKeys_3930041068756f1f:JT,__wbg_process_dc0fbacc7c1c06f7:qT,__wbg_push_737cfc8c1432c2c6:VT,__wbg_randomFillSync_ac0988aba3254290:YT,__wbg_require_60cc747a6bc5215a:XT,__wbg_resolve_4851785c9c5f573d:GT,__wbg_set_37837023f3d740e8:ZT,__wbg_set_3f1d0b984ed272ed:QT,__wbg_set_65595bdd868b3009:eI,__wbg_set_8fc6bf8a5b1071d1:tI,__wbg_set_bb8cecf6a62b9f46:nI,__wbg_set_wasm:Nk,__wbg_stateBinary_bcc49261f5205b9f:rI,__wbg_stateCid_ddf7fe40691e2c8f:oI,__wbg_stateContainer_8b73508686ecac7f:sI,__wbg_stateIndex_985e23155ddc5679:iI,__wbg_stateOptions_234376ac96321e68:aI,__wbg_stateRootCid_92a320b321ddff0a:lI,__wbg_stateSet_9c75457bd566f749:cI,__wbg_stateSlice_4573448d6dfd609f:uI,__wbg_stateValue_32a9721f28b53795:dI,__wbg_static_accessor_GLOBAL_88a902d13a557d07:fI,__wbg_static_accessor_GLOBAL_THIS_56578be7e9f832b0:gI,__wbg_static_accessor_SELF_37c5d418e4bf5819:pI,__wbg_static_accessor_WINDOW_5de37043a91a9c40:hI,__wbg_subarray_aa9065fa9dc5df96:_I,__wbg_then_44b73946d2fb3e7d:mI,__wbg_value_cd1ffa7b1ab794f1:bI,__wbg_versions_c01dfd4722a88165:yI,__wbg_versionvector_new:wI,__wbg_warn_5d1fd3858772ca54:xI,__wbindgen_as_number:CI,__wbindgen_bigint_from_i64:SI,__wbindgen_bigint_from_u64:vI,__wbindgen_bigint_get_as_i64:kI,__wbindgen_boolean_get:TI,__wbindgen_cb_drop:II,__wbindgen_closure_wrapper295:EI,__wbindgen_closure_wrapper551:NI,__wbindgen_debug_string:LI,__wbindgen_error_new:OI,__wbindgen_in:RI,__wbindgen_is_array:AI,__wbindgen_is_bigint:MI,__wbindgen_is_function:$I,__wbindgen_is_null:DI,__wbindgen_is_object:PI,__wbindgen_is_string:jI,__wbindgen_is_undefined:FI,__wbindgen_jsval_eq:BI,__wbindgen_jsval_loose_eq:UI,__wbindgen_memory:zI,__wbindgen_number_get:KI,__wbindgen_number_new:WI,__wbindgen_object_clone_ref:HI,__wbindgen_object_drop_ref:JI,__wbindgen_rethrow:qI,__wbindgen_string_get:VI,__wbindgen_string_new:YI,__wbindgen_throw:XI,__wbindgen_typeof:GI,callPendingEvents:gc,decodeFrontiers:jk,decodeImportBlobMeta:fc,encodeFrontiers:Pk,isValidContainerId:Am,redactJsonUpdates:$k,run:Dk,setDebug:Fk},eE={"./loro_wasm_bg.js":Mm},tE=n=>{Mm.__wbg_set_wasm(n),nE(n)};function nE(n){typeof n.__wbindgen_start=="function"&&n.__wbindgen_start()}function rE(n){if(typeof XMLHttpRequest!="function")throw new Error("loro-crdt browser build requires XMLHttpRequest for synchronous WASM loading. Use the nodejs, web, base64, or bundler entry for this runtime.");const e=new XMLHttpRequest;if(e.open("GET",n,!1),e.overrideMimeType("text/plain; charset=x-user-defined"),e.send(null),e.status!==0&&(e.status<200||e.status>=300))throw new Error(`Failed to load loro-crdt WASM from ${n}: ${e.status} ${e.statusText}`);const t=e.responseText,r=new Uint8Array(t.length);for(let o=0;o<t.length;o++)r[o]=t.charCodeAt(o)&255;return r}function oE(n,e){const t=new WebAssembly.Module(n);return new WebAssembly.Instance(t,e)}const sE=new URL(""+new URL("../assets/loro_wasm_bg-XW642dR7.wasm",import.meta.url).href,import.meta.url),iE=oE(rE(sE.href),eE);tE(iE.exports);const aE=["Map","Text","List","Tree","MovableList","Counter"];function lE(n){return Am(n)}function _g(n){if(typeof n!="object"||n==null)return!1;const e=Object.getPrototypeOf(n);return e==null||typeof e!="object"||typeof e.kind!="function"?!1:aE.includes(n.kind())}class cE{constructor(e=3e4){this.inner=new Ku(e),this.timeout=e}apply(e){this.inner.apply(e),this.startTimerIfNotEmpty()}set(e,t){this.inner.set(e,t),this.startTimerIfNotEmpty()}delete(e){this.inner.delete(e)}get(e){return this.inner.get(e)}getAllStates(){return this.inner.getAllStates()}encode(e){return this.inner.encode(e)}encodeAll(){return this.inner.encodeAll()}keys(){return this.inner.keys()}destroy(){clearInterval(this.timer)}subscribe(e){return this.inner.subscribe(e)}subscribeLocalUpdates(e){return this.inner.subscribeLocalUpdates(e)}startTimerIfNotEmpty(){this.inner.isEmpty()||this.timer!=null||(this.timer=setInterval(()=>{this.inner.removeOutdated(),this.inner.isEmpty()&&(clearInterval(this.timer),this.timer=void 0)},this.timeout/2))}}sn.prototype.toJsonWithReplacer=function(n){const e=new Set,t=this,r=(i,a)=>{if(typeof a=="string"&&lE(a)&&!e.has(a)){e.add(a);const c=t.getContainerById(a);if(c==null)throw new Error(`ContainerID not found: ${a}`);const u=n(i,c);if(u===c){const f=c.getShallowValue();return typeof f=="object"?o(f):f}if(_g(u))throw new Error("Using new container is not allowed in toJsonWithReplacer");return typeof u=="object"&&u!=null?o(u):u}if(typeof a=="object"&&a!=null)return o(a);const l=n(i,a);if(_g(l))throw new Error("Using new container is not allowed in toJsonWithReplacer");return l},o=i=>{if(Array.isArray(i))return i.map((l,c)=>r(c,l)).filter(l=>l!==void 0);const a={};for(const[l,c]of Object.entries(i)){const u=r(l,c);u!==void 0&&(a[l]=u)}return a},s=t.getShallowValue();return o(s)};const mg=Symbol("loro.callPendingEventsWrapped");function uE(n,e){const t=Object.getOwnPropertyDescriptor(n,e);if(!t||typeof t.value!="function")return;const r=t.value;if(r[mg])return;const o=function(...s){let i;try{return i=r.apply(this,s),i}finally{i&&typeof i.then=="function"?i.finally(()=>{gc()}):gc()}};o[mg]=!0,Object.defineProperty(n,e,{...t,value:o})}function Hu(n,e){for(const t of e)uE(n,t)}Hu(sn.prototype,["setDetachedEditing","attach","detach","fork","forkAt","checkoutToLatest","checkout","commit","getCursorPos","revertTo","export","exportJsonUpdates","exportJsonInIdSpan","importJsonUpdates","import","importUpdateBatch","importBatch","travelChangeAncestors","getChangedContainersIn","diff","applyDiff","setPeerId"]);Hu(Ku.prototype,["set","delete","apply","removeOutdated"]);Hu(Wu.prototype,["undo","redo"]);const dE=he("CONNECTED_COMMAND"),fE=he("TOGGLE_CONNECT_COMMAND");function gE(n){return new Wu(n.doc,{mergeInterval:1e3,maxUndoSteps:100,excludeOriginPrefixes:["collab-","sync-"]})}function pE(n,e,t,r,o){n.awareness.setLocalState({anchorPos:null,awarenessData:o,color:t,focusPos:null,focusing:r,name:e})}function bg(n,e,t,r,o){const{awareness:s}=n;let i=s.getLocalState();i===null&&(i={anchorPos:null,awarenessData:o,color:t,focusPos:null,focusing:r,name:e}),i.name=e,i.color=t,i.focusing=r,s.setLocalState(i)}function hE(n,e,t){const{awareness:r}=n;let o=r.getLocalState();o===null?o={anchorPos:null,awarenessData:{},color:t,focusPos:null,focusing:!1,name:e}:(o.name=e,o.color=t),r.setLocalState(o)}function _E(n,e,t){const o=ze().getLoroNodeByLexicalKey(n,void 0,void 0,0);if(e)try{if("key"in e||"__key"in e||"lexicalKey"in e){const{key:s,__key:i,lexicalKey:a,children:l,...c}=e;Se(o,"lexical",c)}else{const{children:s,...i}=e;Se(o,"lexical",i)}}catch(s){console.warn("Failed to store lexical node JSON for RootNode:",s)}return Se(o,"elementType","root"),Se(o,"createdAt",Date.now()),o.id}function mE(n,e,t){const o=ze().getLoroNodeByLexicalKey(n,void 0);if(e)try{if("key"in e||"__key"in e||"lexicalKey"in e){const{key:s,__key:i,lexicalKey:a,children:l,...c}=e;Se(o,"lexical",c)}else{const{children:s,...i}=e;Se(o,"lexical",i)}}catch(s){console.warn("Failed to store lexical node JSON for RootNode update:",s)}Se(o,"elementType","root")}function bE(n,e){ze().deleteMapping(n)}function yE(n,e,t,r){switch(e){case"created":{const o=n.editorState._nodeMap.get(t);if(o){let s;n.editorState.read(()=>{if(o.getType()==="root")try{s=o.exportJSON()}catch(i){console.warn("Failed to export root node JSON:",i)}}),s&&_E(t,s)}break}case"updated":{const o=n.editorState._nodeMap.get(t);if(o){let s;n.editorState.read(()=>{if(o.getType()==="root")try{s=o.exportJSON()}catch(i){console.warn("Failed to export root node JSON for update:",i)}}),s&&mE(t,s)}break}case"destroyed":{bE(t);break}}}function wE(n,e,t,r,o){const i=ze().getLoroNodeByLexicalKey(n,void 0,e,t);if(r){const{key:a,__key:l,lexicalKey:c,children:u,...f}=r;Se(i,"lexical",f)}return Se(i,"elementType","linebreak"),Se(i,"createdAt",Date.now()),i.id}function xE(n,e,t,r,o){const s=ze(),{tree:i}=o,a=s.getLoroNodeByLexicalKey(n,void 0);if(!a)return;const l=a.id;if(r){const{key:c,__key:u,lexicalKey:f,children:d,...g}=r;Se(a,"lexical",g)}(e!==void 0||t!==void 0)&&Xi(i,l,e,t),Se(a,"elementType","linebreak")}function CE(n,e){ze().deleteMapping(n)}function SE(n,e,t,r){switch(e){case"created":{const o=n.editorState._nodeMap.get(t);if(o&&ue(o)){const{parentId:s,index:i,lexicalNodeJSON:a}=n.editorState.read(()=>{const l=o.getParent(),c=ze(),u=l?c.getTreeIDByLexicalKey(l.getKey()):void 0,f=o.getIndexWithinParent();let d;try{d=o.exportJSON()}catch(g){console.warn("Failed to export node JSON in propagateLineBreakNode created:",g)}return{parentId:u,index:f,lexicalNodeJSON:d}});wE(t,s,i,a)}break}case"updated":{const o=n.editorState._nodeMap.get(t);if(o&&ue(o)){const{parentId:s,index:i,lexicalNodeJSON:a}=n.editorState.read(()=>{const l=o.getParent(),c=ze(),u=l?c.getTreeIDByLexicalKey(l.getKey()):void 0,f=o.getIndexWithinParent();let d;try{d=o.exportJSON()}catch(g){console.warn("Failed to export node data in propagateLineBreakNode updated:",g)}return{parentId:u,index:f,lexicalNodeJSON:d}});xE(t,s,i,a,r)}break}case"destroyed":{CE(t);break}}}function vE(n,e,t,r,o,s,i){const l=ze().getLoroNodeByLexicalKey(n,void 0,t,r);if(s){const{key:c,__key:u,lexicalKey:f,children:d,...g}=s;Se(l,"lexical",g)}return Se(l,"elementType",e),Se(l,"createdAt",Date.now()),l.id}function kE(n,e,t,r,o,s,i,a,l){const u=ze().getLoroNodeByLexicalKey(n,void 0);if(a){const{key:f,__key:d,lexicalKey:g,children:h,..._}=a;Se(u,"lexical",_)}if(e!==void 0&&Se(u,"elementType",e),t!==void 0||r!==void 0){const{tree:f}=l;dt(!(t&&u.id===t),"updateElementNodeInLoro: cycle move (node is its own parent)",{nodeKey:n,treeId:u.id});const d=u.parent(),g=d?d.id:void 0,_=(d?d.children()??[]:f.roots()).findIndex(w=>w.id===u.id),m=g===t;if(!m||r!==void 0&&r!==_){const w=t?f.getNodeByID(t):null,C=w?w.children()?.length??0:f.roots().length;if(r!==void 0){let v=r;const k=m?Math.max(C-1,0):C;if(v<0||v>k){const I=w?w.children()??[]:f.roots();if(o){const E=I.findIndex(N=>N.id===o);E>=0&&(v=E+1)}if((v<0||v>k)&&s){const E=I.findIndex(N=>N.id===s);E>=0&&(v=E)}if(v<0||v>k){const E=Math.min(Math.max(v,0),k);console.warn("[loro-collab] updateElementNodeInLoro: clamping out-of-range move index",{nodeKey:n,treeId:u.id,index:r,targetIndex:v,clamped:E,maxIndex:k,sameParent:m,previousSiblingId:o,nextSiblingId:s}),v=E}}Xi(f,u.id,t,v)}else Xi(f,u.id,t,C)}}}function TE(n,e){ze().deleteMapping(n)}function IE(n,e,t,r){const{tree:o}=r;switch(e){case"created":{const s=n.editorState._nodeMap.get(t);if(s&&q(s)){let i,a,l,c;const u={};let f;n.editorState.read(()=>{i=s.getParent();const d=ze();a=i?d.getTreeIDByLexicalKey(i.getKey()):void 0,l=s.getIndexWithinParent(),a&&d.getTreeIDByLexicalKey(t)===a&&(a=void 0),c=s.getType(),i&&!a&&console.warn(` ElementNodePropagator: parent mapping missing for ${c} nodeKey=${t}, parentKey=${i.getKey()}`),typeof s.getFormat=="function"&&(u.format=s.getFormat()),typeof s.getStyle=="function"&&(u.style=s.getStyle()),typeof s.getDirection=="function"&&(u.direction=s.getDirection()),f=s.exportJSON()}),vE(t,c,a,l,u,f)}break}case"updated":{const s=n.editorState._nodeMap.get(t);if(s&&q(s)){let i,a,l,c,u,f;const d={};let g;n.editorState.read(()=>{i=s.getParent();const h=ze();if(a=i?h.getTreeIDByLexicalKey(i.getKey()):void 0,l=s.getIndexWithinParent(),i){const _=i.getChildren();for(let m=l-1;m>=0;m--){const y=_[m],w=h.getTreeIDByLexicalKey(y.getKey());if(w&&qt(o,w)){c=w;break}}for(let m=l+1;m<_.length;m++){const y=_[m],w=h.getTreeIDByLexicalKey(y.getKey());if(w&&qt(o,w)){u=w;break}}}f=s.getType(),typeof s.getFormat=="function"&&(d.format=s.getFormat()),typeof s.getStyle=="function"&&(d.style=s.getStyle()),typeof s.getDirection=="function"&&(d.direction=s.getDirection()),g=s.exportJSON()}),kE(t,f,a,l,c,u,d,g,r)}break}case"destroyed":{TE(t);break}}}function gl(n,e,t,r,o,s,i,a){const l=ze();dt(o!==void 0,"createTextNodeInLoro: text node has no parent in Loro tree",{nodeKey:n});const c=l.getLoroNodeByLexicalKey(n,void 0,o,s);if(i)try{if("key"in i||"__key"in i||"lexicalKey"in i){const{key:u,__key:f,lexicalKey:d,children:g,...h}=i;Se(c,"lexical",h)}else{const{children:u,...f}=i;Se(c,"lexical",f)}}catch(u){console.warn("Failed to store lexical node JSON for TextNode:",u)}return Se(c,"elementType","text"),Se(c,"createdAt",Date.now()),c.id}function EE(n,e,t,r,o,s){const a=ze().getTreeIDByLexicalKey(n);if(!a||!qt(s?.tree,a))return;const l=s.tree.getNodeByID(a);if(l){if(o)if("key"in o||"__key"in o||"lexicalKey"in o){const{key:c,__key:u,lexicalKey:f,children:d,...g}=o;Se(l,"lexical",g)}else{const{children:c,...u}=o;Se(l,"lexical",u)}Se(l,"elementType","text")}}function NE(n,e){ze().deleteMapping(n)}function LE(n,e,t,r){const{tree:o}=r;switch(e){case"created":{const s=n.editorState._nodeMap.get(t),i=ze(),a=i.getTreeIDByLexicalKey(t);if(a&&s&&oe(s)){const{currentParentId:l,expectedParentId:c}=n.editorState.read(()=>{const u=s.getParent(),f=u?i.getTreeIDByLexicalKey(u.getKey()):void 0;let d;try{const g=o.getNodeByID(a);if(g){const h=g.parent();d=h?h.id.toString():void 0}}catch(g){console.warn(` Failed to get parent for existing TreeID ${a}:`,g)}return{currentParentId:d,expectedParentId:f}});if(l===c)return;{let u=a;try{const f=o.getNodeByID(a);f&&(u=f.id)}catch(f){console.warn(` Could not get TreeNode for ${a} during creation:`,f)}i.deleteMapping(t);try{qt(o,u)&&o.delete(u)}catch(f){console.warn(` Failed to delete TreeNode ${u} during creation:`,f)}}}if(s&&oe(s)){const{parent:l,parentId:c,index:u,textContent:f,format:d,mode:g,lexicalNodeJSON:h}=n.editorState.read(()=>{const _=s.getParent(),m=ze(),y=_?m.getTreeIDByLexicalKey(_.getKey()):void 0,w=s.getIndexWithinParent(),C=s.getTextContent(),v=s.getFormat(),k=s.getMode();let I;try{I=s.exportJSON()}catch(E){console.warn("Failed to export node JSON in propagateTextNode created:",E)}return{parent:_,parentId:y,index:w,textContent:C,format:v,mode:k,lexicalNodeJSON:I}});gl(t,f,d,g,c,u,h)}break}case"updated":{const s=n.editorState._nodeMap.get(t);if(s&&oe(s)){const i=ze(),a=i.getTreeIDByLexicalKey(t);if(a){const{currentParentId:d,expectedParentId:g,parent:h}=n.editorState.read(()=>{const _=s.getParent(),m=_?i.getTreeIDByLexicalKey(_.getKey()):void 0;let y;try{const w=o.getNodeByID(a);if(w){const C=w.parent();y=C?C.id.toString():void 0}}catch(w){console.warn(` Failed to get parent for existing TreeID ${a} during update:`,w)}return{currentParentId:y,expectedParentId:m,parent:_}});if(d!==g){let _=a;try{const I=o.getNodeByID(a);I&&(_=I.id)}catch(I){console.warn(` Could not get TreeNode for ${a}:`,I)}i.deleteMapping(t);try{qt(o,_)&&o.delete(_)}catch(I){console.warn(` Failed to delete TreeNode ${_} during update:`,I)}const{parentId:m,index:y,textContent:w,format:C,mode:v,lexicalNodeJSON:k}=n.editorState.read(()=>{const I=h?i.getTreeIDByLexicalKey(h.getKey()):void 0,E=s.getIndexWithinParent(),N=s.getTextContent(),O=s.getFormat(),M=s.getMode();let R;try{R=s.exportJSON()}catch($){console.warn("Failed to export node JSON during TextNode recreation:",$)}return{parentId:I,index:E,textContent:N,format:O,mode:M,lexicalNodeJSON:R}});gl(t,w,C,v,m,y,k);return}}if(!a){const{parent:d,parentId:g,index:h,textContent:_,format:m,mode:y,lexicalNodeJSON:w}=n.editorState.read(()=>{const C=s.getParent(),v=C?i.getTreeIDByLexicalKey(C.getKey()):void 0,k=s.getIndexWithinParent(),I=s.getTextContent(),E=s.getFormat(),N=s.getMode();let O;try{O=s.exportJSON()}catch(M){console.warn("Failed to export node JSON in propagateTextNode updated(create fallback):",M)}return{parent:C,parentId:v,index:k,textContent:I,format:E,mode:N,lexicalNodeJSON:O}});g!==void 0&&gl(t,_,m,y,g,h,w);return}const{textContent:l,format:c,mode:u,lexicalNodeJSON:f}=n.editorState.read(()=>{const d=s.getTextContent(),g=s.getFormat(),h=s.getMode();let _;try{_=s.exportJSON()}catch(m){console.warn("Failed to export node JSON in propagateTextNode updated:",m)}return{textContent:d,format:g,mode:h,lexicalNodeJSON:_}});EE(t,l,c,u,f,r)}break}case"destroyed":{NE(t);break}}}function OE(n,e,t,r,o,s,i,a){const c=ze().getLoroNodeByLexicalKey(n,void 0,r,o);if(i){const{key:u,__key:f,lexicalKey:d,children:g,...h}=i;Se(c,"lexical",h)}return Se(c,"elementType","decorator"),Se(c,"createdAt",Date.now()),c.id}function RE(n,e,t,r,o,s,i,a){const c=ze().getLoroNodeByLexicalKey(n,void 0);if(!c)return;const{tree:u}=a,f=c.id;if(i){const{key:d,__key:g,lexicalKey:h,children:_,...m}=i;Se(c,"lexical",m)}(r!==void 0||o!==void 0)&&Xi(u,f,r,o),Se(c,"elementType","decorator")}function AE(n,e){ze().deleteMapping(n)}function ME(n,e,t,r){switch(e){case"created":{const o=n.editorState._nodeMap.get(t);if(o&&It(o)){const{parentId:s,index:i,decoratorType:a,decoratorData:l,metadata:c,lexicalNodeJSON:u}=n.editorState.read(()=>{const f=o.getParent(),d=ze(),g=f?d.getTreeIDByLexicalKey(f.getKey()):void 0,h=o.getIndexWithinParent(),_=o.getType(),m=o.__decoratorData||{},y={};typeof o.isInline=="function"&&(y.isInline=o.isInline());let w;try{w=o.exportJSON()}catch(C){console.warn("Failed to export node data in propagateDecoratorNode created:",C)}return{parentId:g,index:h,decoratorType:_,decoratorData:m,metadata:y,lexicalNodeJSON:w}});OE(t,a,l,s,i,c,u)}break}case"updated":{const o=n.editorState._nodeMap.get(t);if(o&&It(o)){const{parentId:s,index:i,decoratorType:a,decoratorData:l,metadata:c,lexicalNodeJSON:u}=n.editorState.read(()=>{const f=o.getParent(),d=ze(),g=f?d.getTreeIDByLexicalKey(f.getKey()):void 0,h=o.getIndexWithinParent(),_=o.getType(),m=o.__decoratorData||{},y={};typeof o.isInline=="function"&&(y.isInline=o.isInline());let w;try{w=o.exportJSON()}catch(C){console.warn("Failed to export node data in propagateDecoratorNode updated:",C)}return{parentId:g,index:h,decoratorType:_,decoratorData:m,metadata:y,lexicalNodeJSON:w}});RE(t,a,l,s,i,c,u,r)}break}case"destroyed":{AE(t);break}}}function $E(n,e,t){ak(n.nodeMapper,()=>DE(n,e,t))}function DE(n,e,t){const{prevEditorState:r,editorState:o}=t,{dirtyElements:s,dirtyLeaves:i}=t,a=s.size===0&&i.size===0?null:t.mutatedNodes??PE(t);let l=0;if(a&&a.forEach(c=>{l+=c.size}),ye("[SEED-DEBUG] syncLexicalToLoro: mutatedNodes=",a?"map":"null","totalMutations=",l,"tags=",Array.from(t.tags)),a){const c=n.tree;Wt(n.doc);const u={tree:c};let f=!1;if(a.forEach(d=>{d.size>0&&(f=!0)}),f){a.forEach((h,_)=>{so(_,Dd)&&h.forEach((m,y)=>{yE(t,m,y)})});const d=[];a.forEach((h,_)=>{let m=null;if(so(_,Dd)||(so(_,Oe)?m="element":so(_,cn)?m="text":so(_,lw)?m="linebreak":so(_,Bt)&&(m="decorator"),m===null))return;const y=m;h.forEach((w,C)=>{let v=0,k=0;o.read(()=>{const I=Q(C);if(I){k=I.getIndexWithinParent();let E=I.getParent();for(;E;)v++,E=E.getParent()}}),d.push({mutation:w,nodeKey:C,depth:v,index:k,category:y})})});const g=h=>{switch(h.category){case"element":IE(t,h.mutation,h.nodeKey,u);break;case"text":LE(t,h.mutation,h.nodeKey,u);break;case"linebreak":SE(t,h.mutation,h.nodeKey,u);break;case"decorator":ME(t,h.mutation,h.nodeKey,u);break}};d.filter(h=>h.mutation==="destroyed").sort((h,_)=>_.depth-h.depth).forEach(g),d.filter(h=>h.mutation==="created").sort((h,_)=>h.depth-_.depth||h.index-_.index).forEach(g),d.filter(h=>h.mutation==="updated").sort((h,_)=>h.depth-_.depth||h.index-_.index).forEach(g),n.doc.commit({origin:n.doc.peerIdStr})}}o.read(()=>{const c=D(),u=r._selection;Em(n,e,u,c)})}function PE(n){const{dirtyElements:e,dirtyLeaves:t,prevEditorState:r,editorState:o}=n;if(e.size===0&&t.size===0)return null;const s=r._nodeMap,i=o._nodeMap,a=new Map,l=(c,u)=>{const f=c.constructor;let d=a.get(f);d||(d=new Map,a.set(f,d)),d.set(c.getKey(),u)};return i.forEach((c,u)=>{s.has(u)?(e.has(u)||t.has(u))&&l(c,"updated"):l(c,"created")}),s.forEach((c,u)=>{i.has(u)||l(c,"destroyed")}),a}function yg(n){return n&&typeof n=="object"&&typeof n.toJSON=="function"?n.toJSON():n}function jE(n,e,t,r,o){dt(qt(e,n),"NodeFactory: TreeID not live in Loro tree",{treeId:n});const s=e.getNodeByID(n);let i=yg(o?.lexical);if(i||(i=yg(s?.data.get("lexical"))),!i||typeof i!="object"){const f=s?.data.get("elementType")||s?.data.get("nodeType");dt(typeof f=="string"&&f.length>0,"NodeFactory: no lexical data or elementType for TreeID",{treeId:n}),i={type:f,version:1}}const a=i.type||i.__type;dt(!!a,"NodeFactory: no type field in lexical data for TreeID",{treeId:n});const c=t.editor._nodes.get(a);dt(c!=null,"NodeFactory: node type is not registered in the editor",{treeId:n,nodeType:a});const u={...i};return u.type||(u.type=a),u.version===void 0&&(u.version=1),"children"in u||(u.children=[]),c.klass.importJSON(u)}class FE{integrate(e,t,r){t.editor.update(()=>{this.integrateInternal(e,t,r)})}integrateInternal(e,t,r){const o=[],s=[],i=[];for(const _ of e.diff)switch(_.action){case"delete":o.push(_);break;case"create":s.push(_);break;case"move":i.push(_);break}const a=new Map;for(const _ of i)a.set(String(_.target),_);const l=new Set;for(const _ of s)if(_.parent===void 0){const m=a.get(String(_.target));m&&m.parent!==void 0&&(_.parent=m.parent,_.index=m.index,l.add(String(_.target)))}let c=i.filter(_=>!l.has(String(_.target)));const u=new Set;for(const _ of s)qt(t.tree,_.target)||u.add(String(_.target));for(let _=!0;_;){_=!1;for(const m of s){const y=String(m.target);!u.has(y)&&m.parent!==void 0&&u.has(String(m.parent))&&(u.add(y),_=!0)}}const f=u.size===0?s:s.filter(_=>!u.has(String(_.target)));u.size>0&&(c=c.filter(_=>!u.has(String(_.target))));const d=this.topologicalSortCreates(f,t);o.forEach(_=>this.integrateDelete(_,t,r));const g=new Map;let h=d;for(;h.length>0;){const _=[];for(const m of h)this.integrateCreate(m,t,r,g)==="deferred"&&_.push(m);_.length===h.length&&dt(!1,"TreeIntegrator: create operations reference parents missing from the batch",{pending:_.map(m=>({target:String(m.target),parent:m.parent?String(m.parent):null,parentInTree:m.parent?qt(t.tree,m.parent):null,parentMapped:m.parent?t.nodeMapper.getLexicalKeyByLoroId(m.parent)??null:null})),roots:t.tree.roots().map(m=>String(m.id))}),h=_}c.forEach(_=>this.integrateMove(_,t,r))}integrateCreate(e,t,r,o){if(e.parent==null){const l=t.tree.getNodeByID(e.target),c=l?.data.get("elementType"),u=l?.data.get("lexical")?.type;if(c==="root"||u==="root"||!c){const f=se(),d=t.nodeMapper.getTreeIDByLexicalKey(f.getKey());if(d===void 0||!qt(t.tree,d)){t.nodeMapper.setMapping(f.getKey(),e.target);for(const g of f.getChildren())t.nodeMapper.hasLexicalMapping(g.getKey())||g.remove()}else d!==e.target&&t.nodeMapper.aliasLoroId(e.target,f.getKey());return"created"}}const s=t.nodeMapper.getLexicalKeyByLoroId(e.target);if(s!==null&&Q(s)!==null)return"created";const i=String(e.target);let a=o.get(i);if(a===void 0&&(a=jE(e.target,t.tree,t),o.set(i,a)),dt(a!=null,"integrateCreate: failed to materialise Lexical node from Loro data",{target:i}),e.parent){const l=t.nodeMapper.getLexicalKeyByLoroId(e.parent),c=l?Q(l):null;if(!(c&&q(c)))return"deferred";this.insertChild(c,a,e.index)}else dt(this.canBeRootChild(a),"integrateCreate: inline node has no parent (cannot live at root)",{target:i,nodeType:a.getType()}),this.insertChild(se(),a,e.index);return t.nodeMapper.setMapping(a.getKey(),e.target),"created"}canBeRootChild(e){return q(e)||It(e)}insertChild(e,t,r){r!==void 0?e.splice(r,0,[t]):e.append(t)}integrateMove(e,t,r){const o=t.nodeMapper.getLexicalKeyByLoroId(e.target);dt(o!=null,"integrateMove: no Lexical key for move target",{target:String(e.target)});const s=Q(o);dt(s!=null,"integrateMove: node to move not found",{lexicalKey:o});let i;if(e.parent){const a=t.nodeMapper.getLexicalKeyByLoroId(e.parent),l=a?Q(a):null;dt(l!=null&&q(l),"integrateMove: move target parent is not a mapped element",{target:String(e.target),parent:String(e.parent)}),i=l}else dt(this.canBeRootChild(s),"integrateMove: inline node cannot be moved to the root",{lexicalKey:o,nodeType:s.getType()}),i=se();s.remove(),s.isAttached()&&wg(s),e.index!==void 0?i.splice(e.index,0,[s]):i.append(s)}integrateDelete(e,t,r){const o=t.nodeMapper.getLexicalKeyByLoroId(e.target);if(!o)return;const s=Q(o);if(!s){t.nodeMapper.removeMappingForKey(o);return}if(s===se())return;const i=this.collectDescendantKeys(s);for(const a of i)t.nodeMapper.removeMappingForKey(a);s.remove(),s.isAttached()&&wg(s),t.nodeMapper.removeMappingForKey(o)}collectDescendantKeys(e){if(!q(e))return[];const t=[],r=[...e.getChildren()];for(;r.length>0;){const o=r.pop();t.push(o.getKey()),q(o)&&r.push(...o.getChildren())}return t}topologicalSortCreates(e,t){if(e.length<=1)return e;const r=new Set(e.map(l=>String(l.target))),o=new Map;for(const l of e)l.parent&&o.set(String(l.target),String(l.parent));const s=new Map,i=l=>{if(s.has(l))return s.get(l);let c=0,u=l;const f=new Set;for(;o.has(u);){const d=o.get(u);if(f.has(d))break;if(f.add(d),r.has(d))c++,u=d;else break}return s.set(l,c),c},a=e.map((l,c)=>({op:l,depth:i(String(l.target)),idx:c}));return a.sort((l,c)=>l.depth-c.depth||l.idx-c.idx),a.map(l=>l.op)}}function wg(n){Bt.prototype.remove.call(n,!1)}class BE{integrate(e,t,r){e.updated&&Object.entries(e.updated).forEach(([o,s])=>{this.integratePropertyUpdate(o,s,t,r)}),e.deleted&&e.deleted.forEach(o=>{this.integratePropertyDelete(o,t,r)})}integrateWithContext(e,t,r,o){this.integrateWithContextInternal(e,t,r,o)}integrateInternal(e,t,r){e.updated&&Object.entries(e.updated).forEach(([o,s])=>{this.integratePropertyUpdate(o,s,t,r)}),e.deleted&&e.deleted.forEach(o=>{this.integratePropertyDelete(o,t,r)})}integrateWithContextInternal(e,t,r,o){e.updated&&Object.entries(e.updated).forEach(([s,i])=>{this.integratePropertyUpdateWithContextInternal(s,i,t,r,o)}),e.deleted&&e.deleted.forEach(s=>{this.integratePropertyDelete(s,r,o)})}integratePropertyUpdateWithContext(e,t,r,o,s){e==="lexical"&&this.integrateLexicalDataUpdateWithContext(t,r,o)}integratePropertyUpdateWithContextInternal(e,t,r,o,s){switch(e){case"lexical":let i=r;if(typeof r=="string"&&r.startsWith("cid:")){const l=r.split(":");l.length>=3&&(i=l[1])}const a=o.nodeMapper.getLexicalKeyByLoroId(i);a&&this.integrateLexicalDataUpdateInternal(t,a,i,o);break}}integratePropertyUpdate(e,t,r,o){}integratePropertyDelete(e,t,r){}integrateLexicalDataUpdateWithContext(e,t,r){let o=t;if(typeof t=="string"&&t.startsWith("cid:")){const i=t.split(":");i.length>=3&&(o=i[1])}const s=r.nodeMapper.getLexicalKeyByLoroId(o);s&&e&&typeof e=="object"&&r.editor.update(()=>{this.integrateLexicalDataUpdateInternal(e,s,o,r)})}integrateLexicalDataUpdateInternal(e,t,r,o){let s=e;s&&typeof s=="object"&&typeof s.toJSON=="function"&&(s=s.toJSON());const i=Q(t);if(!i)return;const a=i.getType();if(UE(i,s,a))return;const l=s.__text||s.text||s.textContent;if(a==="text"&&l!==void 0){const c=i,u=c.getTextContent();u!==l&&nk(c,t,u,l),s.format!==void 0&&c.setFormat(s.format),s.style!==void 0&&c.setStyle(s.style)}else if(It(i))try{const u=o.editor._nodes.get(a);if(!u){console.warn(` MapIntegrator: Node type '${a}' not registered`);return}const f={...s};if(f.type||(f.type=a),f.version===void 0&&(f.version=1),"children"in f||(f.children=[]),u.klass.prototype.updateFromJSON!==Bt.prototype.updateFromJSON){i.getWritable().updateFromJSON(f);return}const d=u.klass.importJSON(f);i.replace(d),o.nodeMapper.removeMappingForKey(t),o.nodeMapper.setMapping(d.getKey(),r)}catch(c){console.warn(` MapIntegrator: importJSON+replace failed for decorator ${a} node ${t}:`,c)}else try{const c={...s};c.type||(c.type=a),c.version===void 0&&(c.version=1),"children"in c||(c.children=[]),i.getWritable().updateFromJSON(c)}catch(c){console.warn(` MapIntegrator: updateFromJSON failed for ${a} node ${t}:`,c)}}}function UE(n,e,t){try{const r=n.exportJSON(),o=s=>{const{key:i,__key:a,lexicalKey:l,children:c,...u}=s;return{...u,type:u.type??t,version:u.version??1}};return JSON.stringify(o(r))===JSON.stringify(o(e))}catch{return!1}}class zE{integrate(e,t,r){ye(" Handling ListDiff:",e),this.integrateInternal(e,t,r)}integrateInternal(e,t,r){e.diff&&e.diff.forEach(o=>{switch(o.type){case"insert":this.integrateInsert(o,t,r);break;case"delete":this.integrateDelete(o,t,r);break;case"retain":this.integrateRetain(o,t,r);break;default:console.warn(` Unknown list change type: ${o.type}`)}})}integrateInsert(e,t,r){}integrateDelete(e,t,r){}integrateRetain(e,t,r){e.attributes&&ye(` List retain with attributes at ${e.index}, length: ${e.length}`,e.attributes)}}class KE{integrate(e,t,r){this.integrateInternal(e,t,r)}integrateInternal(e,t,r){e.diff&&e.diff.forEach(o=>{switch(o.type){case"insert":this.integrateTextInsert(o,t,r);break;case"delete":this.integrateTextDelete(o,t,r);break;case"retain":this.integrateTextRetain(o,t,r);break;default:console.warn(` Unknown text change type: ${o.type}`)}})}integrateTextInsert(e,t,r){}integrateTextDelete(e,t,r){}integrateTextRetain(e,t,r){e.attributes&&this.applyTextFormatting({...e,attributes:e.attributes},t,r)}applyTextFormatting(e,t,r){}}class WE{integrate(e,t,r){this.integrateInternal(e,t,r)}integrateInternal(e,t,r){e.increment!==void 0&&this.integrateIncrement(e.increment,t,r),e.value!==void 0&&this.integrateSetValue(e.value,t,r)}integrateIncrement(e,t,r){}integrateSetValue(e,t,r){}updateNodeCounter(e,t,r,o,s){}}const HE=new FE,xg=new BE,JE=new zE,qE=new KE,VE=new WE;function YE(n,e,t,r,o=Im){const s=n.editor,i=s._editorState;n.editor.update(()=>{D()&&Ee(null),t.events.forEach((c,u)=>{try{switch(c.diff.type){case"tree":HE.integrateInternal(c.diff,n,e);break;case"map":c.target?xg.integrateWithContextInternal(c.diff,c.target,n,e):xg.integrateInternal(c.diff,n,e);break;case"list":JE.integrateInternal(c.diff,n,e);break;case"text":qE.integrateInternal(c.diff,n,e);break;case"counter":VE.integrateInternal(c.diff,n,e);break;default:throw new Error(`Unsupported event diff type: ${c.diff.type}. Supported types are: 'tree', 'map', 'list', 'text', 'counter'.`)}}catch(f){console.error("[loro-collab] syncLoroToLexical: integrator threw for event",u,"diffType=",c.diff?.type,"target=",String(c?.target),"diff=",JSON.stringify(c.diff),f)}});const l=D();if(F(l))if(ng(l)){const c=i._selection;if(F(c)&&(ig(n,e),ng(l))){const u=l.anchor.key;Cm(u,i)}Em(n,e,c,D())}else ig(n,e);Ai($l)},{onUpdate:()=>{o(n,e),queueMicrotask(()=>{s.update(()=>{se().getChildrenSize()===0&&se().append(ne())})})},skipTransforms:!0,tag:ca})}function XE(n,e,t,r,o,s,i,a,l,c,u,f,d=Im,g){const h=S.useRef(!1),_=S.useCallback(()=>t.connect(),[t]),m=S.useCallback(()=>{try{t.disconnect()}catch{}},[t]);S.useEffect(()=>{const{awareness:w}=t,C=({status:A})=>{n.dispatchCommand(dE,A==="connected")};let v=!1;const k=A=>{A&&!v&&(v=!0,QE(n,a,u)),ye("[SEED-DEBUG] onSync: isSynced=",A,"shouldBootstrap=",i,"isReloadingDoc=",h.current),i&&A&&h.current===!1&&(eN(n,u),g&&g(!0)),h.current=!1},I=()=>{d(a,t)};pE(t,o,s,document.activeElement===n.getRootElement(),f||{});const E=A=>{tN(n,a),l(A),r.set(e,A),h.current=!0};t.on("reload",E),t.on("status",C),t.on("sync",k),w.on("update",I);const N=A=>{A.origin!==a.doc.peerIdStr&&YE(a,t,A,!1,d)},O=a.doc.subscribe(N),M=[],R=n._nodes;ye("[SEED-DEBUG] registering mutation listeners; registeredNodes=",R?R.size:"undefined"),R&&R.forEach(A=>{A&&A.klass&&M.push(n.registerMutationListener(A.klass,()=>{},{skipInitialization:!0}))}),ye("[SEED-DEBUG] mutation listeners registered=",M.length,"editor._listeners.mutation.size=",n._listeners?.mutation?.size);const $=n.registerUpdateListener(A=>{let B=0;A.mutatedNodes&&A.mutatedNodes.forEach(j=>{B+=j.size}),ye("[SEED-DEBUG] updateListener fired; tags=",Array.from(A.tags),"mutatedNodes=",A.mutatedNodes?"map":"null","count=",B,"dirtyElements=",A.dirtyElements?.size,"dirtyLeaves=",A.dirtyLeaves?.size),v&&A.tags.has(ca)===!1&&$E(a,t,A)}),L=_();return()=>{h.current===!1&&(L?L.then(m):m()),t.off("sync",k),t.off("status",C),t.off("reload",E),w.off("update",I),O?.(),r.delete(e),$(),M.forEach(A=>A())}},[a,s,_,m,r,n,e,u,o,t,i,f,l,d,g]);const y=S.useMemo(()=>{const w=C=>{a.cursorsContainer=C};return St.createPortal(x.jsx("div",{ref:w,style:{position:"fixed",top:0,left:0,width:"100vw",height:"100vh",pointerEvents:"none",zIndex:1e3,overflow:"visible"}}),c&&c.current||document.body)},[a,c]);return S.useEffect(()=>n.registerCommand(fE,w=>(w?_():m(),!0),V),[_,m,n]),y}function GE(n,e,t,r,o){S.useEffect(()=>de(n.registerCommand(oh,()=>(bg(e,t,r,!0,o||{}),!1),V),n.registerCommand(cw,()=>(bg(e,t,r,!1,o||{}),!1),V)),[r,n,t,e,o])}function ZE(n,e){const t=S.useMemo(()=>gE(e),[e]);S.useEffect(()=>{const o=()=>{t.undo()},s=()=>{t.redo()};return de(n.registerCommand(ph,()=>(o(),!0),V),n.registerCommand(gh,()=>(s(),!0),V))});const r=S.useCallback(()=>{t.clear()},[t]);return S.useEffect(()=>(n.dispatchCommand(hh,t.canUndo()),n.dispatchCommand(_h,t.canRedo()),()=>{}),[n,t]),r}function QE(n,e,t){n.update(()=>{const r=se();for(const o of r.getChildren())e.nodeMapper.hasLexicalMapping(o.getKey())||o.remove();r.isEmpty()&&!t&&r.append(ne())},{discrete:!0,tag:ca})}function eN(n,e){const t=new Set(["Lexical with Loro","Welcome to Lexical with Loro","Type something..."]),r=()=>{const i=se().getChildren();if(i.length===0)return!1;for(const a of i){const l=a.getType(),c=a.getTextContent().trim();if(c.length>0){if(!t.has(c))return!0;continue}if(l!=="paragraph"&&l!=="jupyter-output")return!0}return!1};let o=!1;if(n.getEditorState().read(()=>{o=!r()}),ye("[SEED-DEBUG] initializeEditor: shouldSeed=",o,"hasInitialState=",!!e,"type=",typeof e),!(!o||!e)){if(typeof e=="string"){let s=[];try{s=JSON.parse(e)?.root?.children??[]}catch{n.update(()=>{n.setEditorState(n.parseEditorState(e),{tag:$n})},{tag:$n});return}n.update(()=>{},{tag:$n,discrete:!0}),n.update(()=>{Ee(null)},{tag:$n,discrete:!0});let i=[];n.getEditorState().read(()=>{i=se().getChildren().map(l=>l.getKey())}),ye("[SEED-DEBUG] initializeEditor: seeding",s.length,"blocks, removing",i.length,"scaffold blocks first");for(const l of i)n.update(()=>{const c=Q(l);c&&c.remove()},{tag:$n,discrete:!0});let a=0;for(const l of s){const c=a++,u=l?.type,f=Array.isArray(l?.children)?l.children.map(d=>d?.type):[];n.update(()=>{se().append(uw(l))},{tag:$n,discrete:!0}),ye("[SEED-DEBUG] appended block",c,"type=",u,"children=",f)}return}n.update(()=>{r()||(typeof e=="object"?n.setEditorState(e,{tag:$n}):typeof e=="function"&&e(n))},{tag:$n})}}function tN(n,e){if(n.update(()=>{const s=se();s.clear(),s.select()},{tag:ca}),e.cursors==null)return;const t=e.cursors;if(t==null)return;const r=e.cursorsContainer;if(r==null)return;const o=Array.from(t.values());for(let s=0;s<o.length;s++){const a=o[s].selection;if(a&&a.selections!=null){const l=a.selections;for(let c=0;c<l.length;c++)r.removeChild(l[s])}}}function Cg(n,e){if(!n||typeof n!="object")return;const t=n,r=t.user,o=r&&typeof r=="object"?r:void 0;for(const s of e){const i=t[s];if(typeof i=="string"&&i.trim().length>0)return i;if(o){const a=o[s];if(typeof a=="string"&&a.trim().length>0)return a}}}function KM({id:n,providerFactory:e,shouldBootstrap:t,username:r,cursorColor:o,cursorsContainerRef:s,initialEditorState:i,excludedProperties:a,awarenessData:l,syncCursorPositionsFn:c,showCollaborators:u=!0,websocketUrl:f="ws://localhost:3002",onInitialization:d,onIdentityResolved:g,onCollaboratorsChange:h}){const _=S.useRef(!1),m=S.useRef(!1),y=Lm(r,o),w=qw(),C=S.useRef(w);C.current=w;const{docMap:v,name:k,color:I}=y,[E]=fe();S.useEffect(()=>(y.isCollabActive=!0,()=>{E._parentEditor==null&&(y.isCollabActive=!1)}),[y,E]);const[N,O]=S.useState(),[M,R]=S.useState();S.useEffect(()=>{if(m.current)return;m.current=!0;const A=e(n,v,f);return O(A),R(v.get(n)),()=>{A.disconnect()}},[n,e,v,f]);const[$,L]=S.useState();return S.useEffect(()=>{if(!N||_.current)return;_.current=!0;const A=uk(E,N,n,M||v.get(n),v,a),B=Nm(A.clientID),j=Cg(l,["display_name","displayName","name","username","handle"]),U=Cg(l,["color"]),z=r||j||B.name,K=C.current[Vw(z)%C.current.length],H=o||U||K;return y.name=z,y.color=H,y.clientID=A.clientID,g?.({name:z,color:H,clientID:A.clientID}),hE(N,z,H),L(A),()=>{}},[E,N,n,v,M,a,y,r,o,l]),!N||!$?x.jsx(x.Fragment,{}):x.jsx(nN,{awarenessData:l,binding:$,collabContext:y,color:I,cursorsContainerRef:s,editor:E,id:n,initialEditorState:i,name:k,provider:N,setDoc:R,shouldBootstrap:t,docMap:v,syncCursorPositionsFn:c,showCollaborators:u,onInitialization:d,onCollaboratorsChange:h})}function nN({editor:n,id:e,provider:t,docMap:r,name:o,color:s,shouldBootstrap:i,cursorsContainerRef:a,initialEditorState:l,awarenessData:c,collabContext:u,binding:f,setDoc:d,syncCursorPositionsFn:g,showCollaborators:h=!1,onInitialization:_,onCollaboratorsChange:m}){const y=XE(n,e,t,r,o,s,i,f,d,a,l,c,g,_);return u.clientID=f.clientID,ZE(n,f),GE(n,t,o,s,c),S.useEffect(()=>{if(!m)return;const{awareness:w}=t,C=()=>m(bk(w.getStates(),f.clientID));return C(),w.on("update",C),()=>{w.off("update",C)}},[f,m,t]),h?x.jsx(ck,{binding:f,cursorsContainer:y,currentUserName:o,currentUserColor:s,showCollaborators:!0}):y}const Sg=30*1e3,rN="update",oN="ephemeral",sN="query-ephemeral";class iN{ephemeralStore;localClientId;eventHandlers=new Map;constructor(e,t){this.ephemeralStore=e,this.localClientId=t?Wt(t):ek(),ye(" AwarenessAdapter created:",{localClientId:this.localClientId,docPeerId:t?t.peerId:"no-doc",existingStatesCount:Object.keys(e.getAllStates()).length}),this.ephemeralStore.subscribe(r=>{(this.eventHandlers.get("update")||[]).forEach(s=>s())})}getLocalState(){const e=this.localClientId.toString();try{const t=this.ephemeralStore.get(e);return t||null}catch(t){throw console.warn("[Client] AwarenessAdapter.getLocalState() - ephemeralStore.get() FAILED:",{error:t.message,stack:t.stack,localKey:e,peerId:this.localClientId,storeExists:!!this.ephemeralStore}),t}}getStates(){const e=new Map;try{const t=this.ephemeralStore.getAllStates();Math.random()<.001&&this.cleanupStaleStates(t);for(const[r,o]of Object.entries(t)){const s=parseInt(r,10);!isNaN(s)&&o&&e.set(s,o)}}catch(t){console.warn("[Client] AwarenessAdapter.getStates() - ERROR:",t.message);const r=this.getLocalState();r&&e.set(this.localClientId,r)}return e}cleanupStaleStates(e){const t=Date.now(),r=300*1e3;try{for(const[o,s]of Object.entries(e)){const i=parseInt(o,10);if(!isNaN(i)&&s&&typeof s=="object"){const a=s,l=typeof a.lastActivity=="number"?a.lastActivity:0;typeof l=="number"&&t-l>r&&(ye("Cleaning up stale user state:",o,"last activity:",new Date(l).toISOString()),this.ephemeralStore.delete(o))}}}catch(o){console.warn("Error during stale state cleanup:",o.message)}}setLocalState(e){const t=this.localClientId.toString(),r={...e,lastActivity:Date.now()};try{this.ephemeralStore.set(t,r)}catch(o){throw console.warn("[Client] AwarenessAdapter.setLocalState() - ephemeralStore.set() FAILED:",{error:o.message,stack:o.stack,localKey:t,peerId:this.localClientId,stateKeys:Object.keys(e||{}),storeExists:!!this.ephemeralStore}),o}}setLocalStateField(e,t){const r=this.getLocalState()||{anchorPos:null,awarenessData:{},color:"#000000",focusPos:null,focusing:!1,name:"Anonymous"};r[e]=t,this.setLocalState(r)}on(e,t){this.eventHandlers.has(e)||this.eventHandlers.set(e,[]),this.eventHandlers.get(e).push(t)}off(e,t){const r=this.eventHandlers.get(e);if(r){const o=r.indexOf(t);o!==-1&&r.splice(o,1)}}forceCleanupStaleStates(){try{const e=this.ephemeralStore.getAllStates();ye("Force cleanup - total keys before:",Object.keys(e).length),this.cleanupStaleStates(e);const t=this.ephemeralStore.getAllStates();ye("Force cleanup - total keys after:",Object.keys(t).length)}catch(e){console.warn("Force cleanup failed:",e.message)}}}const Ms={};Ms[sN]=(n,e,t)=>{try{const r=n.ephemeralStore.encodeAll(),o={type:"ephemeral",ephemeral:Array.from(r),docId:e.docId};return JSON.stringify(o)}catch(r){return console.warn("Error in messageQueryEphemeral integrater:",r.message),null}};Ms[oN]=(n,e,t)=>{try{if(!e.ephemeral||e.ephemeral.length===0)return console.warn("[Client] messageHandlers[messageEphemeral] - Skipping empty ephemeral data"),null;if(e.ephemeral.length<8)return console.warn("[Client] messageHandlers[messageEphemeral] - Rejecting suspiciously small ephemeral data:",e.ephemeral.length),null;if(e.ephemeral.length===1)return console.warn("[Client] messageHandlers[messageEphemeral] - Rejecting single-byte ephemeral data (likely corrupted):",e.ephemeral),null;const r=e.ephemeral.slice(0,4);if(r.every(s=>s===0)||r.every(s=>s===255))return console.warn("[Client] messageHandlers[messageEphemeral] - Rejecting ephemeral data with suspicious pattern:",r),null;const o=new Uint8Array(e.ephemeral);try{n.ephemeralStore.apply(o)}catch(s){if(console.warn("[Client] messageHandlers[messageEphemeral] - WASM apply() failed:",{error:s.message,ephemeralLength:o.length,ephemeralSample:Array.from(o.slice(0,20))}),s.message&&s.message.includes("memory access out of bounds"))return console.warn("[Client] messageHandlers[messageEphemeral] - CRITICAL: WASM memory corruption in apply(). Stopping ephemeral processing."),null;throw s}return null}catch(r){return console.warn("[Client] messageHandlers[messageEphemeral] - ERROR in ephemeral message integrater:",{error:r.message,stack:r.stack,messageLength:e.ephemeral?.length,ephemeralSample:e.ephemeral?.slice(0,10)}),null}};Ms[rN]=(n,e,t)=>{try{const r=new Uint8Array(e.update),o=n.doc.import(r),s=n.doc.version();return ye("[SEED-DEBUG] messageUpdate: imported",r.length,"bytes; importStatus=",JSON.stringify(o)),n._lastExportedVersion=s,t&&n.snapshotLoaded&&!n._synced&&(n.synced=!0),null}catch(r){return console.warn(" [LORO-UPDATE-ERROR] Failed to apply Loro update:",r),null}};const $m=(n,e,t)=>{if(e instanceof ArrayBuffer)try{const r=new Uint8Array(e),o=fc(r,!1).partialEndVersionVector;n.doc.import(r),n.snapshotLoaded=!0;const s=n.doc.export({mode:"update",from:o});if(fc(s,!1).changeNum>0&&n.ws){const i={type:"update",update:Array.from(s),docId:n.docId};zn(n.ws,i)}return t&&!n._synced&&(n.synced=!0),null}catch(r){return console.warn("Failed to process binary Loro update:",r),null}else if(typeof e=="string")try{const r=JSON.parse(e),o=Ms[r.type];return o?o(n,r,t):(console.warn("Unknown message type:",r.type),null)}catch(r){return console.warn("Failed to process JSON message:",r),null}else if(typeof e=="object"&&e!==null)try{const r=e,o=Ms[r.type];return o?o(n,r,t):(console.warn("Unknown message type:",r.type),null)}catch(r){return console.warn("Failed to process object message:",r),null}return console.warn("Unknown message format:",typeof e),null},pc=(n,e,t)=>{if(e===n.ws){if(n.emit("connection-close",[t,n]),n.ws=null,e.close(),n.wsconnecting=!1,n.wsconnected){n.wsconnected=!1,n.synced=!1,n.ephemeralStore.delete("presence"),n.ephemeralStore.delete("cursor");try{const o=Wt(n.doc).toString();n.ephemeralStore.delete(o),ye("Disconnect cleanup: removed user key:",o)}catch(r){console.warn("Disconnect cleanup failed:",r.message)}n.emit("status",[{status:"disconnected"}])}else n.wsUnsuccessfulReconnects++;setTimeout(Dm,fw(gw(2,n.wsUnsuccessfulReconnects)*100,n.maxBackoffTime),n)}},zn=(n,e)=>{if(n&&n.readyState===n.OPEN)try{const t=JSON.stringify(e);n.send(t)}catch(t){console.warn("Failed to send message over WebSocket:",t)}else console.warn("WebSocket not open, cannot send message")},Dm=n=>{if(n.shouldConnect&&n.ws===null){const e=new n._WS(n.url,n.protocols);e.binaryType="arraybuffer",n.ws=e,n.wsconnecting=!0,n.wsconnected=!1,n.synced=!1,e.onmessage=t=>{n.wsLastMessageReceived=Dl(),$m(n,t.data,!0)},e.onerror=t=>{n.emit("connection-error",[t,n])},e.onclose=t=>{n.snapshotLoaded=!1,pc(n,e,t)},e.onopen=()=>{if(n.wsLastMessageReceived=Dl(),n.wsconnecting=!1,n.wsconnected=!0,n.wsUnsuccessfulReconnects=0,n.emit("status",[{status:"connected"}]),ye(" WebSocket connection established, requesting initial data"),n.snapshotLoaded)ye(" Snapshot already loaded, skipping request");else{const s=Math.random().toString(36).substr(2,9),i=Wt(n.doc).toString(),a={type:"query-snapshot",docId:n.docId,clientId:i};ye(` Requesting initial snapshot from server (ID: ${s}, clientId: ${i}):`,a),ye(` Provider instance ID: ${n.wsServerUrl}/${n.docId}, snapshotLoaded: ${n.snapshotLoaded}`),zn(e,a)}const t=Wt(n.doc).toString(),r={type:"query-ephemeral",docId:n.docId,clientId:t};zn(e,r);const o=n.ephemeralStore.getAllStates();if(Object.keys(o).length>0)try{const s=n.ephemeralStore.encodeAll(),i={type:"ephemeral",ephemeral:Array.from(s),docId:n.docId};zn(e,i)}catch(s){console.warn("[Client] setupWS - MAJOR ERROR in ephemeral process:",{error:s.message,stack:s.stack,localStateKeys:Object.keys(o),storeExists:!!n.ephemeralStore})}if(n._pendingUpdates.length>0){const s=n._pendingUpdates;n._pendingUpdates=[],ye("[SEED-DEBUG] ws.onopen: flushing",s.length,"buffered local updates");for(const i of s)zn(e,{type:"update",update:Array.from(i),docId:n.docId})}},n.emit("status",[{status:"connecting"}])}},vg=(n,e)=>{const t=n.ws;n.wsconnected&&t&&t.readyState===t.OPEN?zn(t,e):ye(" [BROADCAST] WebSocket not ready for sending"),n.bcconnected?is(n.bcChannel,JSON.stringify(e),n):ye(" [BROADCAST] BroadcastChannel not connected")};class gr extends dw{static globalEphemeralStore=null;wsServerUrl="";docId="";doc=null;_WS=null;protocols=[];params={};ephemeralStore=null;awareness=null;ws=null;wsconnected=!1;wsconnecting=!1;bcconnected=!1;disableBc=!1;bcChannel="";maxBackoffTime=2500;wsUnsuccessfulReconnects=0;messageHandlers=[];_synced=!1;wsLastMessageReceived=0;shouldConnect=!1;snapshotLoaded=!1;_checkInterval=null;_resyncInterval=null;_updateHandler=null;_ephemeralUpdateIntegrator=null;_exitIntegrator=null;_bcSubscriber=null;_lastExportedVersion=null;_pendingUpdates=[];constructor(e,t,r,{connect:o=!0,ephemeralStore:s=void 0,params:i={},protocols:a=[],WebSocketPolyfill:l=WebSocket,resyncInterval:c=-1,maxBackoffTime:u=2500,disableBc:f=!1}={}){for(super();e[e.length-1]==="/";)e=e.slice(0,e.length-1);this.wsServerUrl=e,this.bcChannel=e+"/"+t,this.maxBackoffTime=u,this.params=i,this.protocols=a,this.docId=t,this.doc=r,this._WS=l;try{if(s)this.ephemeralStore=s;else{if(!gr.globalEphemeralStore)gr.globalEphemeralStore=new cE(3e5),ye("🆕 Created new global EphemeralStore");else{ye(" Reusing existing global EphemeralStore - cleaning up stale user states");const d=gr.globalEphemeralStore.getAllStates();Object.keys(d).forEach(g=>{const h=parseInt(g,10);isNaN(h)||(gr.globalEphemeralStore.delete(g),ye(" Cleaned up stale user state:",g))})}this.ephemeralStore=gr.globalEphemeralStore}}catch(d){throw console.warn("[Client] WebsocketProvider constructor - ERROR setting up EphemeralStore:",{error:d.message,stack:d.stack,docId:t}),d}this.awareness=new iN(this.ephemeralStore,this.doc),this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=f,this.wsUnsuccessfulReconnects=0,this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=o,this._resyncInterval=0,c>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const d=Wt(this.doc).toString(),g={type:"query-ephemeral",docId:this.docId,clientId:d};zn(this.ws,g)}},c)),this._bcSubscriber=(d,g)=>{if(g!==this){const h=$m(this,d,!1);h&&is(this.bcChannel,h,this)}},this._updateHandler=d=>{const g={type:"update",update:Array.from(d),docId:this.docId},h=this.ws;this.wsconnected&&h&&h.readyState===h.OPEN?(ye("[SEED-DEBUG] _updateHandler: sending local update over WS",d.length,"bytes"),zn(h,g)):(ye("[SEED-DEBUG] _updateHandler: WS not ready, buffering local update",d.length,"bytes (pending now",this._pendingUpdates.length+1,")"),this._pendingUpdates.push(d)),this.bcconnected&&is(this.bcChannel,JSON.stringify(g),this)},this._ephemeralUpdateIntegrator=d=>{if(d.added.length>0||d.updated.length>0||d.removed.length>0)try{const g=this.ephemeralStore.encodeAll(),h={type:"ephemeral",ephemeral:Array.from(g),docId:this.docId};vg(this,h)}catch(g){console.warn("[Client] _ephemeralUpdateIntegrator - ERROR:",g.message)}},this._exitIntegrator=()=>{if(this.ephemeralStore&&this.awareness)try{const g=Wt(this.doc).toString();this.ephemeralStore.delete(g)}catch(d){console.warn("[Client] Process exit - Could not clear user state:",d.message)}},Pd&&typeof process<"u"&&process.on("exit",this._exitIntegrator),this.ephemeralStore.subscribe(this._ephemeralUpdateIntegrator),this._lastExportedVersion=this.doc.version();try{this.doc.subscribeLocalUpdates(d=>{try{this._updateHandler(d)}catch(g){console.warn("[WEBSOCKET-PROVIDER] Error exporting incremental update:",g)}})}catch(d){console.warn("[Client] ERROR setting up Loro document subscription:",d)}this._checkInterval=setInterval(()=>{this.wsconnected&&Sg<Dl()-this.wsLastMessageReceived&&pc(this,this.ws,null)},Sg/10),o&&this.connect()}get url(){const e=Yw(this.params);return this.wsServerUrl+"/"+this.docId+(e.length===0?"":"?"+e)}get synced(){return this._synced}set synced(e){this._synced!==e&&(this._synced=e,super.emit("synced",[e]),super.emit("sync",[e]))}destroy(){if(this._resyncInterval!==0&&clearInterval(this._resyncInterval),clearInterval(this._checkInterval),this.disconnect(),Pd&&typeof process<"u"&&process.off("exit",this._exitIntegrator),this.ephemeralStore&&this.awareness)try{const t=Wt(this.doc).toString();this.ephemeralStore.delete(t)}catch(e){console.warn("[Client] WebsocketProvider.destroy - Could not clear user state:",e.message)}super.destroy()}connectBc(){if(this.disableBc)return;this.bcconnected||(Xw(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const e=Wt(this.doc).toString(),t={type:"query-ephemeral",docId:this.docId,clientId:e};is(this.bcChannel,JSON.stringify(t),this);const r=this.ephemeralStore.getAllStates();if(Object.keys(r).length>0)try{const o=this.ephemeralStore.encodeAll(),s={type:"ephemeral",ephemeral:Array.from(o),docId:this.docId};is(this.bcChannel,JSON.stringify(s),this)}catch(o){console.warn("Error broadcasting ephemeral state in connectBc:",o.message)}}disconnectBc(){this.ephemeralStore.delete("presence"),this.ephemeralStore.delete("cursor");try{const t=Wt(this.doc).toString();this.ephemeralStore.delete(t),ye("Broadcast disconnect cleanup: removed user key:",t)}catch(e){console.warn("Broadcast disconnect cleanup failed:",e.message)}try{const e=this.ephemeralStore.encodeAll(),t={type:"ephemeral",ephemeral:Array.from(e),docId:this.docId};vg(this,t)}catch(e){console.warn("Error broadcasting disconnect in disconnectBc:",e.message)}this.bcconnected&&(Gw(this.bcChannel,this._bcSubscriber),this.bcconnected=!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&pc(this,this.ws,null)}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(Dm(this),this.connectBc())}sendUpdate(e){this._updateHandler(e,null)}cleanupStaleStates(){this.awareness&&typeof this.awareness.forceCleanupStaleStates=="function"?this.awareness.forceCleanupStaleStates():console.warn("Cleanup method not available on awareness provider")}}const aN=new URL(window.location.href),lN=new URLSearchParams(aN.search),kg=parseInt(lN.get("resyncInterval")||"30000",10);function WM(n,e,t){let r=e.get(n);r===void 0&&(r=new sn,e.set(n,r));const o=Math.random().toString(36).substr(2,9);ye(` Creating WebsocketProvider instance (ID: ${o}) for docId: ${n}`);let i=t||(()=>{const u=new URL(window.location.href);return new URLSearchParams(u.search).get("collabEndpoint")||"ws://localhost:3002"})();const a={},l=i.indexOf("?");if(l!==-1){const u=i.slice(l+1);i=i.slice(0,l),new URLSearchParams(u).forEach((f,d)=>{a[d]=f})}const c=new gr(i,n,r,{connect:!1,params:a,resyncInterval:kg});return ye(` WebsocketProvider created for: ${i}/${n} with resyncInterval: ${kg}ms`),c}const cN=qn?S.useLayoutEffect:S.useEffect;class uN{key;ref;icon;title;constructor(e){this.key=e,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(e){this.ref={current:e}}}const Tg=n=>{const e=n.closest("#typeahead-menu");if(!e)return;const t=e.getBoundingClientRect();t.top+t.height>window.innerHeight&&e.scrollIntoView({block:"center"}),t.top<0&&e.scrollIntoView({block:"center"}),n.scrollIntoView({block:"nearest"})};function Ig(n,e){const t=n.getBoundingClientRect(),r=e.getBoundingClientRect();return t.top>=r.top-6&&t.top<=r.bottom+6}const Eg=he("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function dN({index:n,isSelected:e,onClick:t,onMouseEnter:r,option:o}){let s="item";return e&&(s+=" selected"),x.jsxs("li",{tabIndex:-1,className:s,ref:o.setRefElement,role:"option","aria-selected":e,id:"typeahead-item-"+n,onMouseEnter:r,onClick:t,children:[o.icon,x.jsx("span",{className:"text",children:o.title})]},o.key)}function fN({close:n,editor:e,anchorElementRef:t,resolution:r,options:o,menuRenderFn:s,onSelectOption:i,shouldSplitNodeWithQuery:a=!1,commandPriority:l=ee,preselectFirstItem:c=!0}){const[u,f]=S.useState(null),d=u!==null?Math.min(o.length-1,u):null,g=r.match&&r.match.matchingString;S.useEffect(()=>{c&&f(0)},[g,c]);const h=S.useCallback(w=>{e.update(()=>{const C=r.match!=null&&a?(function(v){const k=D();if(!F(k)||!k.isCollapsed())return null;const I=k.anchor;if(I.type!=="text")return null;const E=I.getNode();if(!E.isSimpleText())return null;const N=I.offset,O=E.getTextContent().slice(0,N),M=v.replaceableString.length,R=N-(function(L,A,B){let j=B;for(let U=j;U<=A.length;U++)L.slice(-U)===A.substring(0,U)&&(j=U);return j})(O,v.matchingString,M);if(R<0)return null;let $;return R===0?[$]=E.splitText(N):[,$]=E.splitText(R,N),$})(r.match):null;i(w,C,n,r.match?r.match.matchingString:"")})},[e,a,r.match,i,n]),_=S.useCallback(w=>{const C=e.getRootElement();C!==null&&(C.setAttribute("aria-activedescendant","typeahead-item-"+w),f(w))},[e]),m=S.useCallback(()=>t.current&&o.length?wh.createPortal(x.jsx("div",{className:"typeahead-popover mentions-menu",children:x.jsx("ul",{children:o.map((w,C)=>x.jsx(dN,{index:C,isSelected:d===C,onClick:()=>{f(C),h(w)},onMouseEnter:()=>{f(C)},option:w},w.key))})}),t.current):null,[t,o,d,h,f]);S.useEffect(()=>()=>{const w=e.getRootElement();w!==null&&w.removeAttribute("aria-activedescendant")},[e]),cN(()=>{o===null?f(null):d===null&&c&&_(0)},[o,d,_,c]),S.useEffect(()=>de(e.registerCommand(Eg,({option:w})=>!(!w.ref||w.ref.current==null)&&(Tg(w.ref.current),!0),l)),[e,_,l]),S.useEffect(()=>de(e.registerCommand(Vt,w=>{const C=w;if(o!==null&&o.length){const v=d===null?0:d!==o.length-1?d+1:0;_(v);const k=o[v];if(!k)return _(-1),C.preventDefault(),C.stopImmediatePropagation(),!0;k.ref&&k.ref.current&&e.dispatchCommand(Eg,{index:v,option:k}),C.preventDefault(),C.stopImmediatePropagation()}return!0},l),e.registerCommand(pt,w=>{const C=w;if(o!==null&&o.length){const v=d===null?o.length-1:d!==0?d-1:o.length-1;_(v);const k=o[v];if(!k)return _(-1),C.preventDefault(),C.stopImmediatePropagation(),!0;k.ref&&k.ref.current&&Tg(k.ref.current),C.preventDefault(),C.stopImmediatePropagation()}return!0},l),e.registerCommand(Nn,w=>{const C=w;return C.preventDefault(),C.stopImmediatePropagation(),n(),!0},l),e.registerCommand(Kr,w=>{const C=w;return o!==null&&d!==null&&o[d]!=null&&(C.preventDefault(),C.stopImmediatePropagation(),h(o[d]),!0)},l),e.registerCommand(zr,w=>!(o===null||d===null||o[d]==null||w&&w.shiftKey)&&(w!==null&&(w.preventDefault(),w.stopImmediatePropagation()),h(o[d]),!0),l)),[h,n,e,o,d,_,l]);const y=S.useMemo(()=>({options:o,selectOptionAndCleanUp:h,selectedIndex:d,setHighlightedIndex:f}),[h,d,o]);return s!=null?s(t,y,r.match?r.match.matchingString:""):m()}function Ng(n,e){e!=null&&(n.className=e),n.setAttribute("aria-label","Typeahead menu"),n.setAttribute("role","listbox"),n.style.display="block",n.style.position="absolute"}function gN(n,e,t,r,o=!0){const[s]=fe(),i=r??(function(f){if(!qn)return;const d=f.getRootElement();if(d!==null){const g=d.getRootNode();return jc(g)?g:d.ownerDocument.body}return document.body})(s),a=qn?mh(s.getRootElement()).createElement("div"):null,l=S.useRef(a),c=S.useCallback(()=>{if(l.current===null||i===void 0)return;l.current.style.top=l.current.style.bottom;const f=s.getRootElement(),d=l.current,g=d.firstChild;if(f!==null&&n!==null){const{left:h,top:_,width:m,height:y}=n.getRect(),w=l.current.offsetHeight;if(d.style.top=`${_+w+3+(o?window.pageYOffset:0)}px`,d.style.left=`${h+window.pageXOffset}px`,d.style.height=`${y}px`,d.style.width=`${m}px`,g!==null){g.style.top=`${_}`;const C=g.getBoundingClientRect(),v=C.height,k=C.width,I=f.getBoundingClientRect();h+k>I.right&&(d.style.left=`${I.right-k+window.pageXOffset}px`),(_+v>window.innerHeight||_+v>I.bottom)&&_-I.top>v+y&&(d.style.top=`${_-v-y+(o?window.pageYOffset:0)}px`)}d.isConnected||(Ng(d,t),i.append(d)),d.setAttribute("id","typeahead-menu"),f.setAttribute("aria-controls","typeahead-menu")}},[s,n,o,t,i]);S.useEffect(()=>{const f=s.getRootElement();return n!==null&&c(),()=>{f!==null&&f.removeAttribute("aria-controls");const d=l.current;d!==null&&d.isConnected&&(d.remove(),d.removeAttribute("id"))}},[s,c,n]);const u=S.useCallback(f=>{n!==null&&(f||e(null))},[n,e]);return(function(f,d,g,h){const[_]=fe();S.useEffect(()=>{if(d!=null&&f!=null){const m=_.getRootElement(),y=m!=null?bh(m,!1):document.body;let w=!1,C=Ig(d,y);const v=function(){w||(window.requestAnimationFrame(function(){g(),w=!1}),w=!0);const E=Ig(d,y);E!==C&&(C=E,h?.(E))},k=new ResizeObserver(g),I=yh(m??d);return k.observe(d),de(Jt(window,"resize",g),Jt(document,"scroll",v,{capture:!0,passive:!0}),...I.map(E=>Jt(E,"scroll",v,{capture:!0,passive:!0})),()=>k.unobserve(d))}},[d,_,h,g,f])})(n,l.current,c,u),a!=null&&a===l.current&&(Ng(a,t),i?.append(a)),l}function pN({options:n,nodeKey:e,onClose:t,onOpen:r,onSelectOption:o,menuRenderFn:s,anchorClassName:i,commandPriority:a=ee,parent:l}){const[c]=fe(),[u,f]=S.useState(null),d=gN(u,f,i,l),g=S.useCallback(()=>{f(null),t!=null&&u!==null&&t()},[t,u]),h=S.useCallback(m=>{f(m),r!=null&&u===null&&r(m)},[r,u]),_=S.useCallback(()=>{e?c.update(()=>{const m=Q(e),y=c.getElementByKey(e);m!=null&&y!=null&&u==null&&S.startTransition(()=>h({getRect:()=>y.getBoundingClientRect()}))}):e==null&&u!=null&&g()},[g,c,e,h,u]);return S.useEffect(()=>{_()},[_,e]),S.useEffect(()=>{if(e!=null)return c.registerUpdateListener(({dirtyElements:m})=>{m.get(e)&&_()})},[c,_,e]),d.current===null||u===null||c===null?null:x.jsx(fN,{close:g,resolution:u,editor:c,anchorElementRef:d,options:n,menuRenderFn:s,onSelectOption:o,commandPriority:a})}const hN=/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/,Ju=he("INSERT_EMBED_COMMAND");let Lg=class extends uN{title;onSelect;constructor(e,t){super(e),this.title=e,this.onSelect=t.onSelect.bind(this)}};function _N({embedConfigs:n,onOpenEmbedModalForConfig:e,getMenuOptions:t,menuRenderFn:r,menuCommandPriority:o=ee}){const[s]=fe(),[i,a]=S.useState(null),[l,c]=S.useState(null),u=S.useCallback(()=>{a(null),c(null)},[]),f=S.useCallback(async _=>{const m=s.read("latest",function(){const y=Q(_);if(Pe(y))return y.getURL()});if(m!==void 0)for(const y of n)await Promise.resolve(y.parseUrl(m))!=null&&(c(y),a(_))},[s,n]);S.useEffect(()=>de(...[gn,fa].map(_=>s.registerMutationListener(_,(...m)=>((y,{updateTags:w,dirtyLeaves:C})=>{for(const[v,k]of y)k==="created"&&w.has(Up)&&C.size<=3?f(v):v===i&&u()})(...m),{skipInitialization:!0}))),[f,s,i,u]),S.useEffect(()=>{if(e)return s.registerCommand(Ju,_=>{const m=n.find(({type:y})=>y===_);return!!m&&(e(m),!0)},V)},[s,n,e]);const d=S.useCallback(async function(){if(l!=null&&i!=null){const _=s.read("latest",()=>{const m=Q(i);return Pe(m)?m:null});if(Pe(_)){const m=await Promise.resolve(l.parseUrl(_.__url));m!=null&&s.update(()=>{D()||_.selectEnd(),l.insertNode(s,m),_.isAttached()&&_.remove()})}}},[l,s,i]),g=S.useMemo(()=>l!=null&&i!=null?t(l,d,u):[],[l,d,t,i,u]),h=S.useCallback((_,m,y)=>{s.update(()=>{_.onSelect(m),y()})},[s]);return i!=null?x.jsx(pN,{nodeKey:i,onClose:u,onSelectOption:h,options:g,menuRenderFn:r,commandPriority:o}):null}const Xo=()=>{const[n,e]=S.useState(null),t=S.useCallback(()=>{e(null)},[]),r=S.useMemo(()=>{if(n===null)return null;const{title:s,content:i,closeOnClickOutside:a}=n;return x.jsx(Yx,{onClose:t,title:s,closeOnClickOutside:a,children:i})},[n,t]),o=S.useCallback((s,i,a=!1)=>{e({closeOnClickOutside:a,content:i(t),title:s})},[t]);return[r,o]},Pm=he();function mN(n){if(!n.hasNodes([qo]))throw new Error("YouTubePlugin: YouTubeNode not registered on editor");return n.registerCommand(Pm,e=>{const t=K_(e);return sr(t),!0},V)}const jm=pe({name:"@datalayer/jupyter-lexical/YouTube",nodes:()=>[qo],register:mN}),ka=he("INSERT_LOOM_COMMAND");function bN(n){if(!n.hasNodes([Vo]))throw new Error("LoomExtension: LoomNode not registered on editor");return n.registerCommand(ka,e=>(sr($u(e)),!0),V)}const Fm=pe({name:Q_,config:tr({publicAppId:void 0}),nodes:()=>[Vo],register:bN}),yN={contentName:"Youtube Video",exampleUrl:"https://www.youtube.com/watch?v=jNQXAC9IVRw",icon:x.jsx(Ws,{size:16}),insertNode:(n,e)=>{n.dispatchCommand(Pm,e.id)},keywords:["youtube","video"],parseUrl:async n=>{const e=/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(n),t=e&&e?.[2].length===11?e[2]:null;return t!=null?{id:t,url:n}:null},type:"youtube-video"},wN={contentName:"Loom Video",exampleUrl:"https://www.loom.com/share/c2b5b05f548d4f1492d5c107f0c48dbc",icon:x.jsx(Ws,{size:16}),insertNode:(n,e)=>{tm(e.url).then(t=>n.dispatchCommand(ka,t))},keywords:["loom","video","recording","screen"],parseUrl:async n=>{const e=Tn(n);return e?{id:e,url:Mu(e)}:null},type:"loom-video"},qu=[yN,wN];function xN({index:n,isSelected:e,onClick:t,onMouseEnter:r,option:o}){const s=S.useCallback(i=>o.setRefElement(i),[o]);return x.jsx(Y,{as:"li",tabIndex:-1,ref:s,role:"option","aria-selected":e,id:"typeahead-item-"+n,onMouseEnter:r,onClick:t,sx:{p:2,cursor:"pointer",bg:e?"actionListItem.default.selectedBg":"transparent","&:hover":{bg:"actionListItem.default.hoverBg"},borderRadius:1},children:x.jsx(Le,{sx:{fontSize:1},children:o.title})},o.key)}function CN({options:n,selectedItemIndex:e,onOptionClick:t,onOptionMouseEnter:r}){return x.jsx(Y,{sx:{bg:"var(--overlay-bgColor)",border:"1px solid",borderColor:"var(--borderColor-default)",borderRadius:2,boxShadow:"var(--shadow-floating-large, 0 0 0 1px #d1d9e0, 0 40px 80px 0 #25292e3d)",p:1},children:x.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:n.map((o,s)=>x.jsx(xN,{index:s,isSelected:e===s,onClick:()=>t(o,s),onMouseEnter:()=>r(s),option:o},o.key))})})}const SN=(n,e)=>{let t;return r=>{window.clearTimeout(t),t=window.setTimeout(()=>{n(r)},e)}};function vN({embedConfig:n,onClose:e}){const[t,r]=S.useState(""),[o]=fe(),[s,i]=S.useState(null),a=S.useMemo(()=>SN(u=>{const f=hN.exec(u);n!=null&&u!=null&&f!=null?Promise.resolve(n.parseUrl(u)).then(d=>{i(d)}):s!=null&&i(null)},200),[n,s]),l=()=>{s!=null&&(n.insertNode(o,s),e())},c=S.useRef(null);return S.useEffect(()=>{c.current?.focus()},[]),x.jsxs("div",{children:[x.jsx(kn,{ref:c,type:"text",placeholder:n.exampleUrl,value:t,"data-test-id":`${n.type}-embed-modal-url`,onChange:u=>{const{value:f}=u.target;r(f),a(f)},block:!0}),x.jsx(xu,{children:x.jsx(xr,{disabled:!s,onClick:l,"data-test-id":`${n.type}-embed-modal-submit-btn`,children:"Embed"})})]})}const kN=()=>{const[n,e]=Xo(),t=o=>{e(`Embed ${o.contentName}`,s=>x.jsx(vN,{embedConfig:o,onClose:s}))},r=(o,s,i)=>[new Lg("Dismiss",{onSelect:i}),new Lg(`Embed ${o.contentName}`,{onSelect:s})];return x.jsxs(x.Fragment,{children:[n,x.jsx(_N,{embedConfigs:qu,onOpenEmbedModalForConfig:t,getMenuOptions:r,menuRenderFn:(o,{selectedIndex:s,options:i,selectOptionAndCleanUp:a,setHighlightedIndex:l})=>o.current?St.createPortal(x.jsx(Y,{sx:{position:"relative",zIndex:1e3,bg:"var(--overlay-bgColor)",border:"1px solid",borderColor:"var(--borderColor-default)",borderRadius:2,boxShadow:"var(--shadow-floating-large, 0 0 0 1px #d1d9e0, 0 40px 80px 0 #25292e3d)",marginLeft:o.current.style.width,width:200},children:x.jsx(CN,{options:i,selectedItemIndex:s,onOptionClick:(c,u)=>{l(u),a(c)},onOptionMouseEnter:c=>{l(c)}})}),o.current):null})]})};class Xs extends Bt{__completionText;static getType(){return"inline-completion"}static clone(e){return new Xs(e.__completionText,e.__key)}constructor(e,t){super(t),this.__completionText=e}createDOM(e){const t=document.createElement("span");return t.className="inline-completion-ghost",t.style.cssText=`
206
+ `,document.body.appendChild(a)},cleanupEphemeralStore:e=>{if(!e){console.log(" No provider passed. Usage: window.debugLoro.cleanupEphemeralStore(provider)"),console.log("You can get the provider from your useCollaboration hook");return}if(typeof e.cleanupStaleStates!="function"){console.log(" Provider does not have cleanupStaleStates method");return}console.log(" Cleaning up stale ephemeral states..."),e.cleanupStaleStates()},resetGlobalEphemeralStore:()=>{try{console.log(" Attempting to reset global EphemeralStore..."),console.log(" You can also refresh the browser to clear the global store"),alert("To reset the global ephemeral store and clear all collaborators, please refresh the browser page.")}catch(e){console.warn(" Reset failed:",e.message)}}},window.debugLoro.binding=n,setTimeout(()=>{window.debugLoro.addDebugToPage()},2e3)}class sk{lexicalToLoro=new Map;loroToLexical=new Map;tree;constructor(e){this.tree=e.tree}createMapping(e,t){this.lexicalToLoro.set(e,t),this.loroToLexical.set(t,e)}removeMapping(e,t){this.lexicalToLoro.delete(e),this.loroToLexical.delete(t)}getLoroNodeByLexicalKey(e,t,r,o){const s=this.lexicalToLoro.get(e);if(s&&qt(this.tree,s))return this.tree.getNodeByID(s);if(e==="root"){const a=this.tree.roots()[0];if(a)return this.createMapping(e,a.id),a;const l=this.createLoroNode(e,t,void 0,0),c=this.tree.getNodeByID(l);return Se(c,"elementType","root"),c}if(!r&&t){const a=t.getParent();if(a){const l=a.getKey();r=this.lexicalToLoro.get(l),r||(r=this.getLoroNodeByLexicalKey(l,a,void 0,void 0).id)}}o===void 0&&t&&(o=t.getIndexWithinParent());const i=this.createLoroNode(e,t,r,o);return this.tree.getNodeByID(i)}getLexicalKeyByLoroId(e){const t=this.loroToLexical.get(e);return t||null}getLexicalNodeByLoroId(e,t){const r=this.getLexicalKeyByLoroId(e);return r&&t._nodeMap.get(r)||null}getLexicalParentByLoroId(e,t){return null}setMapping(e,t){this.lexicalToLoro.set(e,t),this.loroToLexical.set(t,e)}aliasLoroId(e,t){this.loroToLexical.set(e,t)}createLoroNode(e,t,r,o){const s=o;if(s!==void 0){const l=r!==void 0?this.tree.getNodeByID(r):null,c=l?l.children()?.length??0:this.tree.roots().length;dt(s>=0&&s<=c,"createLoroNode: insertion index out of range",{nodeKey:e,parentTreeID:r,insertionIndex:s,childrenLength:c})}const i=this.tree.createNode(r,s),a=i.id;if(r){const l=i.parent();dt(l!=null&&l.id===r,"createLoroNode: parent relationship not established",{nodeKey:e,expected:r,actual:l?.id??null})}if(Se(i,"createdAt",Date.now()),t)try{const l=t.exportJSON();if("key"in l||"__key"in l||"lexicalKey"in l){const{key:c,__key:u,lexicalKey:f,children:d,...g}=l;Se(i,"lexical",g)}else{const{children:c,...u}=l;Se(i,"lexical",u)}}catch(l){console.warn("Failed to export lexical node JSON in NodesMapper:",l)}return this.createMapping(e,a),a}updateMapping(e,t){const r=this.lexicalToLoro.get(e);r&&(this.removeMapping(e,r),this.createMapping(t,r),this.tree.getNodeByID(r))}deleteMapping(e){const t=this.lexicalToLoro.get(e);t&&(this.removeMapping(e,t),qt(this.tree,t)&&this.tree.delete(t))}removeMappingForKey(e){const t=this.lexicalToLoro.get(e);t&&this.removeMapping(e,t)}getTreeIDByLexicalKey(e){return this.lexicalToLoro.get(e)}hasLexicalMapping(e){return this.lexicalToLoro.has(e)}hasLoroMapping(e){return this.loroToLexical.has(e)}getAllMappings(){return{lexicalToLoro:new Map(this.lexicalToLoro),loroToLexical:new Map(this.loroToLexical)}}clearMappings(){this.lexicalToLoro.clear(),this.loroToLexical.clear()}syncExistingNodes(e){ye(" syncExistingNodes: Skipping sync - mappings established through TreeIntegrator")}}let vr=null;function ik(n){return vr=new sk(n),vr}function ak(n,e){const t=vr;vr=n;try{return e()}finally{vr=t}}function ze(){if(!vr)throw new Error("NodeMapper not initialized. Call initializeNodeMapper() first.");return vr}function lk({binding:n,currentUserName:e="Me",currentUserColor:t}){const[r,o]=S.useState(0);S.useEffect(()=>{const g=setInterval(()=>{o(h=>h+1)},1e3);return()=>clearInterval(g)},[]);const s=n.clientID;Array.from(n.cursors.entries()).map(([g,h])=>({clientId:g,name:h.name,color:h.color,isCurrentUser:g===s}));const i=Array.from(n.cursors.entries()).map(([g,h])=>({clientId:g,cursor:h,isCurrentUser:g===s})),a=n.cursors.get(s),l=a?.name||e,c=Hw(l),u=a?.color||t||c,f=i.find(({isCurrentUser:g})=>g),d=i.filter(({isCurrentUser:g})=>!g);return x.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",backgroundColor:"var(--bgColor-muted, #f8f9fa)",borderBottom:"1px solid var(--borderColor-default, #e1e5e9)",fontSize:"14px",fontFamily:"system-ui, -apple-system, sans-serif",gap:"8px",flexWrap:"wrap",color:"var(--fgColor-default, inherit)"},children:[f&&x.jsx(rl,{name:`${f.cursor.name} (me)`,color:u,isCurrentUser:!0,clientId:s}),!f&&x.jsx(rl,{name:`${l} (me)`,color:u,isCurrentUser:!0,clientId:s}),d.length>0&&x.jsx("div",{style:{width:"1px",height:"20px",backgroundColor:"var(--borderColor-muted, #d1d5db)",margin:"0 4px"}}),d.map(({clientId:g,cursor:h})=>x.jsx(rl,{name:h.name,color:h.color,isCurrentUser:!1,clientId:g},g)),d.length===0&&x.jsx("span",{style:{color:"var(--fgColor-muted, #6b7280)",fontStyle:"italic",marginLeft:"8px"},children:"No other collaborators"})]})}function rl({name:n,color:e,isCurrentUser:t,clientId:r}){const o=e,s=e,i=String(r).slice(0,4);return x.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px"},title:`${n} (Client ID: ${r})`,children:[x.jsx("div",{style:{width:"12px",height:"12px",borderRadius:"50%",backgroundColor:o,border:t?"2px solid var(--bgColor-default, #ffffff)":"none",boxShadow:t?"0 0 0 1px var(--borderColor-default, #d1d5db)":"none",flexShrink:0}}),x.jsx("span",{style:{backgroundColor:s,color:"var(--fgColor-onEmphasis, #ffffff)",padding:"3px 8px",borderRadius:"12px",fontSize:"12px",fontWeight:"500",lineHeight:"1.2",whiteSpace:"nowrap",textShadow:"0 1px 2px rgba(0,0,0,0.1)",boxShadow:t?"0 1px 3px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.2)":"0 1px 2px rgba(0,0,0,0.1)",opacity:1},children:`${n} ${i}`})]})}function ck({binding:n,cursorsContainer:e,currentUserName:t="You",currentUserColor:r,showCollaborators:o=!0}){return x.jsxs(x.Fragment,{children:[o&&x.jsx(lk,{binding:n,currentUserName:t,currentUserColor:r}),e]})}function uk(n,e,t,r,o,s){G1(r!=null,"createBinding: doc is null or undefined");const i=ek(r);ye(" Loro tree initialized, content will be populated via server sync");const a=Wt(r);ye("- Creating binding:",{bindingId:t,localPeerId:r.peerId,generatedClientID:a,docPeerIdType:typeof r.peerId,awarenessKey:a.toString()});const l={clientID:a,cursors:new Map,cursorsContainer:null,doc:r,docMap:o,editor:n,tree:i,excludedProperties:s||new Map,id:t,nodeProperties:new Map,nodeMapper:null,commitTimeout:null,pendingCommit:!1};return l.nodeMapper=ik(l),Sm()&&(ok(l),ye(" Loro debugging enabled via ?debug=true URL parameter")),l}function vm(n){const e=n.awarenessData;if(!e||typeof e!="object")return n.name;const t=e,r=t.user,o=r&&typeof r=="object"?r:void 0,s=[o?.display_name,o?.displayName,o?.name,o?.username,o?.handle,t.display_name,t.displayName,t.name,t.username,t.handle,n.name];for(const i of s)if(typeof i=="string"&&i.trim().length>0)return i;return n.name}function rg(n,e){try{const t=Q(n.key);if(!t)return null;const r=e.nodeMapper;if(oe(t)){const s=r.getTreeIDByLexicalKey(n.key);if(!s)return null;const i=t.getTextContent(),a=Math.min(n.offset,i.length);return{treeId:s,offset:a,pointType:"text"}}if(q(t)){const s=t.getChildren();if(s.length===0){const a=r.getTreeIDByLexicalKey(n.key);return a?{treeId:a,offset:n.offset,pointType:"element"}:null}if(n.offset<s.length){const a=s[n.offset];if(a){const l=r.getTreeIDByLexicalKey(a.getKey());if(l)return{treeId:l,offset:0,pointType:oe(a)?"text":"element"}}}const i=r.getTreeIDByLexicalKey(n.key);return i?{treeId:i,offset:n.offset,pointType:"element"}:null}const o=r.getTreeIDByLexicalKey(n.key);return o?{treeId:o,offset:n.offset,pointType:"element"}:null}catch(t){return console.warn("Failed to convert Lexical point to Loro cursor:",t),null}}function km(n,e,t){try{if(!n||!e)return null;const r=n,o=e,s=t.nodeMapper;let i=null,a=null;return r.treeId&&(i=s.getLexicalKeyByLoroId(r.treeId)),o.treeId&&(a=s.getLexicalKeyByLoroId(o.treeId)),!i||!a?null:{anchorKey:i,anchorOffset:r.offset||0,focusKey:a,focusOffset:o.offset||0}}catch(r){return console.warn("Failed to convert Loro cursors to Lexical selection:",r),null}}function og(n,e,t){if(n.key!==e||n.offset!==t){let r=Q(e);if(r!==null&&!q(r)&&!oe(r)){const o=r.getParentOrThrow();e=o.getKey(),t=r.getIndexWithinParent(),r=o}n.set(e,t,q(r)?"element":"text")}}function dk(n,e){return{color:e,name:n,selection:null}}function fk(n,e,t,r,o,s=!1){const i=n.color,a=i,l=i,c=document.createElement("span");c.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:2px;background-color:${a};z-index:10;${s?"opacity:0.8;":""}`;const u=document.createElement("span");return u.textContent=n.name,u.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:${l};color:var(--fgColor-onEmphasis,#fff);line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;${s?"opacity:0.9;":""}`,c.appendChild(u),{anchor:{key:e,offset:t},focus:{key:r,offset:o},caret:c,color:n.color,name:u,selections:[]}}function gk(n,e){const t=e.selection;t!==null&&(Tm(n,t),e.selection=null)}function Tm(n,e){const t=n.cursorsContainer;if(t!==null){const r=e.selections,o=r.length;for(let s=0;s<o;s++)t.removeChild(r[s])}}function Im(n,e,t){const{getAwarenessStates:r=pk}=t??{},o=Array.from(r(n,e)),s=n.clientID,i=n.cursors,l=n.editor._editorState._nodeMap,c=new Set;for(let f=0;f<o.length;f++){const d=o[f],[g,h]=d;c.add(g);const{color:_}=h,m=vm(h),y=g===s;let w=null,C=i.get(g);if(C===void 0){const I=y?`${m} (Me)`:m;C=dk(I,_),i.set(g,C)}else C.name!==m&&(C.name=m,C.selection&&(C.selection.name.textContent=y?`${m} (Me)`:m));const{anchorPos:v,focusPos:k}=h;if(v!==null&&k!==null){const I=km(v,k,n);if(I){const{anchorKey:E,anchorOffset:N,focusKey:O,focusOffset:M}=I;if(w=C.selection,w===null)w=fk(C,E,N,O,M,y);else{const R=w.anchor,$=w.focus;R.key=E,R.offset=N,$.key=O,$.offset=M}}}hk(n,C,w,l,y)}const u=Array.from(i.keys());for(let f=0;f<u.length;f++){const d=u[f];if(!c.has(d)){const g=i.get(d);g!==void 0&&(gk(n,g),i.delete(d))}}}function pk(n,e){return e.awareness.getStates()}function hk(n,e,t,r,o=!1){const s=n.editor,i=s.getRootElement(),a=n.cursorsContainer;if(a===null||i===null)return;const l=a.getBoundingClientRect(),c=e.selection;if(t===null){if(c===null)return;e.selection=null,Tm(n,c);return}else e.selection=t;const u=t.caret,f=t.color,d=t.selections,g=t.anchor,h=t.focus,_=g.key,m=h.key,y=r.get(_),w=r.get(m);if(y==null||w==null)return;const C=_===m&&g.offset===h.offset;let v;if(y===w&&ue(y)){const E=s.getElementByKey(_);E?v=[E.getBoundingClientRect()]:v=[]}else{const E=fh(s,y,g.offset,w,h.offset);if(E===null)return;if(C){if(v=Ml(s,E),v.length===0){const N=E.getBoundingClientRect();N.height>0&&(v=[N])}}else v=Ml(s,E)}const k=d.length,I=v.length;for(let E=0;E<I;E++){const N=v[E];let O=d[E];if(O===void 0){O=document.createElement("span"),d[E]=O;const A=document.createElement("span");O.appendChild(A),a.appendChild(O)}const M=N.top-l.top,R=N.left-l.left,$=C?Math.max(N.width,4):N.width,L=`position:absolute;top:${M}px;left:${R}px;height:${N.height}px;width:${$}px;pointer-events:none;z-index:10;overflow:visible;`;O.style.cssText=L,C?(O.firstChild.style.cssText="position:absolute;left:0;top:0;width:0;height:0;",u.style.cssText=`position:absolute;top:0;left:0;width:2px;height:${N.height}px;background-color:${f};z-index:10;`):o?O.firstChild.style.cssText=`position:absolute;left:0;top:0;width:${N.width}px;height:${N.height}px;background-color:${f};opacity:0.08;border-radius:2px;pointer-events:none;`:O.firstChild.style.cssText=`position:absolute;left:0;top:0;width:${N.width}px;height:${N.height}px;background-color:${f};opacity:0.25;border-radius:2px;pointer-events:none;`,E===I-1&&u.parentNode!==O&&O.appendChild(u)}for(let E=k-1;E>=I;E--){const N=d[E];a.removeChild(N),d.pop()}}function Em(n,e,t,r){const o=e.awareness,s=o.getLocalState();if(s===null)return;const{anchorPos:i,focusPos:a,name:l,color:c,focusing:u,awarenessData:f}=s;let d=null,g=null;if(F(r))d=rg(r.anchor,n),g=rg(r.focus,n);else if(r!==null)return;if(!(sg(i,d)||sg(a,g)))return;const _=d!==null&&g!==null?!0:u;o.setLocalState({...s,anchorPos:d,awarenessData:f,color:c,focusPos:g,focusing:_,name:l})}function sg(n,e){if(n==null)return e!=null;if(e==null)return!0;{const t=n,r=e;return t.treeId!==r.treeId||t.offset!==r.offset||t.pointType!==r.pointType}}function ig(n,e){const r=e.awareness.getLocalState();if(r===null)return;const{anchorPos:o,focusPos:s}=r;if(o!==null&&s!==null){const i=km(o,s,n);if(i){const{anchorKey:a,anchorOffset:l,focusKey:c,focusOffset:u}=i,f=D();if(!F(f))return;og(f.anchor,a,l),og(f.focus,c,u)}}}const _k=(n,e)=>{const t=n.encode(),r=e.encode();return t.length===r.length&&t.every((o,s)=>o===r[s])},mk=n=>{const e=n.awarenessData,t=e&&e.user&&typeof e.user=="object"?e.user:void 0,r=t?.id??t?.uid;return typeof r=="string"&&r.length>0?r:void 0};function bk(n,e){const t=[];for(const[r,o]of n){const s=o.anchorPos,i=o.focusPos;t.push({clientId:r,uid:mk(o),name:vm(o),color:o.color,isCurrentUser:r===e,focusing:!!o.focusing,selecting:s!==null&&i!==null&&!_k(s,i)})}return t.sort((r,o)=>Number(o.isCurrentUser)-Number(r.isCurrentUser)||r.clientId-o.clientId)}const ag=["Cat","Dog","Rabbit","Frog","Fox","Hedgehog","Pigeon","Squirrel","Bear","Tiger","Leopard","Zebra","Wolf","Owl","Gull","Squid","Panda","Lion","Eagle","Shark","Dolphin","Penguin","Koala","Kangaroo"];function Nm(n){const e=Math.abs(n)%ag.length,t=Math.abs(n).toString().slice(-4),r=`${ag[e]}-${t}`,o=Jw(r);return{name:r,color:o}}const lg=Nm(Math.floor(Math.random()*1e5)),yk=S.createContext({clientID:0,color:lg.color,isCollabActive:!1,name:lg.name,docMap:new Map});function Lm(n,e){const t=S.useContext(yk);return n!=null&&(t.name=n),e!=null&&(t.color=e),t}const zu=["Map","List","MovableList","Text","Tree","Counter"];function wk(n,e){if(typeof n!="object"||n===null||Array.isArray(n))throw new Error("Invalid toContainerTree options");for(const t of Object.keys(n))if(t!=="text"&&!(e&&t==="roots"))throw new Error("Unknown toContainerTree option: "+t);if(e&&n.roots!==void 0&&!Array.isArray(n.roots))throw new Error("roots must be an array");return n}function xk(n,e,t){return{cid:n.cid,start:e,totalLength:t,items:n.value}}function Ck(n,e,t){return{type:zu[n],cid:e,value:t}}function Sk(n,e,t){return"cid:"+e+"@"+n+":"+zu[t]}function vk(n,e){return"cid:root-"+n+":"+zu[e]}function kk(n){return{type:"Value",value:n}}function Tk(n){return n.slice()}function Ik(n,e,t){Object.defineProperty(n,e,{value:t,enumerable:!0,writable:!0,configurable:!0})}function Ek(n,e,t){Object.defineProperty(n,e,{value:t,enumerable:!0,writable:!0,configurable:!0})}let p;function Nk(n){p=n}const Be=new Array(128).fill(void 0);Be.push(void 0,null,!0,!1);function W(n){return Be[n]}let G=0,hi=null;function ko(){return(hi===null||hi.byteLength===0)&&(hi=new Uint8Array(p.memory.buffer)),hi}const Lk=typeof TextEncoder>"u"?(0,module.require)("util").TextEncoder:TextEncoder;let Ti=new Lk("utf-8");const Ok=typeof Ti.encodeInto=="function"?function(n,e){return Ti.encodeInto(n,e)}:function(n,e){const t=Ti.encode(n);return e.set(t),{read:n.length,written:t.length}};function _e(n,e,t){if(t===void 0){const a=Ti.encode(n),l=e(a.length,1)>>>0;return ko().subarray(l,l+a.length).set(a),G=a.length,l}let r=n.length,o=e(r,1)>>>0;const s=ko();let i=0;for(;i<r;i++){const a=n.charCodeAt(i);if(a>127)break;s[o+i]=a}if(i!==r){i!==0&&(n=n.slice(i)),o=t(o,r,r=i+n.length*3,1)>>>0;const a=ko().subarray(o+i,o+r),l=Ok(n,a);i+=l.written,o=t(o,r,i,1)>>>0}return G=i,o}let io=null;function b(){return(io===null||io.buffer.detached===!0||io.buffer.detached===void 0&&io.buffer!==p.memory.buffer)&&(io=new DataView(p.memory.buffer)),io}let bs=Be.length;function P(n){bs===Be.length&&Be.push(Be.length+1);const e=bs;return bs=Be[e],Be[e]=n,e}function nt(n,e){try{return n.apply(this,e)}catch(t){p.__wbindgen_exn_store(P(t))}}const Rk=typeof TextDecoder>"u"?(0,module.require)("util").TextDecoder:TextDecoder;let Om=new Rk("utf-8",{ignoreBOM:!0,fatal:!0});Om.decode();function Ue(n,e){return n=n>>>0,Om.decode(ko().subarray(n,n+e))}function Ak(n){n<132||(Be[n]=bs,bs=n)}function T(n){const e=W(n);return Ak(n),e}function hn(n,e){return n=n>>>0,ko().subarray(n/1,n/1+e)}function Ae(n){return n==null}const cg=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>{p.__wbindgen_export_4.get(n.dtor)(n.a,n.b)});function Rm(n,e,t,r){const o={a:n,b:e,cnt:1,dtor:t},s=(...i)=>{o.cnt++;const a=o.a;o.a=0;try{return r(a,o.b,...i)}finally{--o.cnt===0?(p.__wbindgen_export_4.get(o.dtor)(a,o.b),cg.unregister(o)):o.a=a}};return s.original=o,cg.register(s,o,o),s}function dc(n){const e=typeof n;if(e=="number"||e=="boolean"||n==null)return`${n}`;if(e=="string")return`"${n}"`;if(e=="symbol"){const o=n.description;return o==null?"Symbol":`Symbol(${o})`}if(e=="function"){const o=n.name;return typeof o=="string"&&o.length>0?`Function(${o})`:"Function"}if(Array.isArray(n)){const o=n.length;let s="[";o>0&&(s+=dc(n[0]));for(let i=1;i<o;i++)s+=", "+dc(n[i]);return s+="]",s}const t=/\[object ([^\]]+)\]/.exec(toString.call(n));let r;if(t&&t.length>1)r=t[1];else return toString.call(n);if(r=="Object")try{return"Object("+JSON.stringify(n)+")"}catch{return"Object"}return n instanceof Error?`${n.name}: ${n.message}
207
+ ${n.stack}`:r}function Mk(){let n,e;try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.LORO_VERSION(o);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);return n=t,e=r,Ue(t,r)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_free(n,e,1)}}function Xn(n,e){const t=e(n.length*1,1)>>>0;return ko().set(n,t/1),G=n.length,t}function fc(n,e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Xn(n,p.__wbindgen_malloc),a=G;p.decodeImportBlobMeta(s,i,a,e);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}function gc(){p.callPendingEvents()}function $k(n,e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.redactJsonUpdates(s,P(n),P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}function Am(n){const e=_e(n,p.__wbindgen_malloc,p.__wbindgen_realloc),t=G;return p.isValidContainerId(e,t)!==0}function Dk(){p.run()}function Tt(n,e){const t=e(n.length*4,4)>>>0,r=b();for(let o=0;o<n.length;o++)r.setUint32(t+4*o,P(n[o]),!0);return G=n.length,t}function Pk(n){try{const i=p.__wbindgen_add_to_stack_pointer(-16),a=Tt(n,p.__wbindgen_malloc),l=G;p.encodeFrontiers(i,a,l);var e=b().getInt32(i+0,!0),t=b().getInt32(i+4,!0),r=b().getInt32(i+8,!0),o=b().getInt32(i+12,!0);if(o)throw T(r);var s=hn(e,t).slice();return p.__wbindgen_free(e,t*1,1),s}finally{p.__wbindgen_add_to_stack_pointer(16)}}function jk(n){try{const o=p.__wbindgen_add_to_stack_pointer(-16),s=Xn(n,p.__wbindgen_malloc),i=G;p.decodeFrontiers(o,s,i);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}function Fk(){p.setDebug()}let et=128;function mt(n){if(et==1)throw new Error("out of js stack");return Be[--et]=n,et}function jo(n,e){if(!(n instanceof e))throw new Error(`expected instance of ${e.name}`)}function jt(n,e){n=n>>>0;const t=b(),r=[];for(let o=n;o<n+4*e;o+=4)r.push(T(t.getUint32(o,!0)));return r}function Bk(n,e,t){p._dyn_core_ed718c3d60ebd546___ops__function__FnMut_______Output______as_wasm_bindgen_cfd5deec16e3bd1c___closure__WasmClosure___describe__invoke___wasm_bindgen_cfd5deec16e3bd1c___JsValue_____(n,e,P(t))}function Uk(n,e){p._dyn_core_ed718c3d60ebd546___ops__function__FnMut_____Output______as_wasm_bindgen_cfd5deec16e3bd1c___closure__WasmClosure___describe__invoke______(n,e)}const ug=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_awarenesswasm_free(n>>>0,1));class zk{__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,ug.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_awarenesswasm_free(e,0)}getAllStates(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.awarenesswasm_getAllStates(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getTimestamp(e){try{const i=p.__wbindgen_add_to_stack_pointer(-32);p.awarenesswasm_getTimestamp(i,this.__wbg_ptr,P(e));var t=b().getInt32(i+0,!0),r=b().getFloat64(i+8,!0),o=b().getInt32(i+16,!0),s=b().getInt32(i+20,!0);if(s)throw T(o);return t===0?void 0:r}finally{p.__wbindgen_add_to_stack_pointer(32)}}setLocalState(e){p.awarenesswasm_setLocalState(this.__wbg_ptr,P(e))}removeOutdated(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.awarenesswasm_removeOutdated(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}constructor(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.awarenesswasm_new(i,P(e),t);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return this.__wbg_ptr=r>>>0,ug.register(this,this.__wbg_ptr,this),this}finally{p.__wbindgen_add_to_stack_pointer(16)}}peer(){const e=p.awarenesswasm_peer(this.__wbg_ptr);return T(e)}apply(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Xn(e,p.__wbindgen_malloc),a=G;p.awarenesswasm_apply(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}peers(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.awarenesswasm_peers(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}encode(e){try{const a=p.__wbindgen_add_to_stack_pointer(-16);p.awarenesswasm_encode(a,this.__wbg_ptr,P(e));var t=b().getInt32(a+0,!0),r=b().getInt32(a+4,!0),o=b().getInt32(a+8,!0),s=b().getInt32(a+12,!0);if(s)throw T(o);var i=hn(t,r).slice();return p.__wbindgen_free(t,r*1,1),i}finally{p.__wbindgen_add_to_stack_pointer(16)}}length(){return p.awarenesswasm_length(this.__wbg_ptr)}isEmpty(){return p.awarenesswasm_isEmpty(this.__wbg_ptr)!==0}getState(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.awarenesswasm_getState(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}encodeAll(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.awarenesswasm_encodeAll(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=hn(e,t).slice();return p.__wbindgen_free(e,t*1,1),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}}const dg=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_changemodifier_free(n>>>0,1));class To{static __wrap(e){e=e>>>0;const t=Object.create(To.prototype);return t.__wbg_ptr=e,dg.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,dg.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_changemodifier_free(e,0)}setMessage(e){const t=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),r=G,o=p.changemodifier_setMessage(this.__wbg_ptr,t,r);return To.__wrap(o)}setTimestamp(e){const t=p.changemodifier_setTimestamp(this.__wbg_ptr,e);return To.__wrap(t)}}const fg=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_cursor_free(n>>>0,1));class In{static __wrap(e){e=e>>>0;const t=Object.create(In.prototype);return t.__wbg_ptr=e,fg.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,fg.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_cursor_free(e,0)}containerId(){const e=p.cursor_containerId(this.__wbg_ptr);return T(e)}pos(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.cursor_pos(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}kind(){const e=p.cursor_kind(this.__wbg_ptr);return T(e)}side(){const e=p.cursor_side(this.__wbg_ptr);return T(e)}static decode(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Xn(e,p.__wbindgen_malloc),a=G;p.cursor_decode(s,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return In.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}encode(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.cursor_encode(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=hn(e,t).slice();return p.__wbindgen_free(e,t*1,1),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}}const gg=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_ephemeralstorewasm_free(n>>>0,1));class Ku{__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,gg.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_ephemeralstorewasm_free(e,0)}getAllStates(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.ephemeralstorewasm_getAllStates(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}removeOutdated(){p.ephemeralstorewasm_removeOutdated(this.__wbg_ptr)}subscribeLocalUpdates(e){const t=p.ephemeralstorewasm_subscribeLocalUpdates(this.__wbg_ptr,P(e));return T(t)}get(e){const t=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),r=G,o=p.ephemeralstorewasm_get(this.__wbg_ptr,t,r);return T(o)}constructor(e){const t=p.ephemeralstorewasm_new(e);return this.__wbg_ptr=t>>>0,gg.register(this,this.__wbg_ptr,this),this}set(e,t){const r=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),o=G;p.ephemeralstorewasm_set(this.__wbg_ptr,r,o,P(t))}keys(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.ephemeralstorewasm_keys(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}apply(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16),s=Xn(e,p.__wbindgen_malloc),i=G;p.ephemeralstorewasm_apply(o,this.__wbg_ptr,s,i);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}delete(e){const t=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),r=G;p.ephemeralstorewasm_delete(this.__wbg_ptr,t,r)}encode(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.ephemeralstorewasm_encode(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=hn(t,r).slice();return p.__wbindgen_free(t,r*1,1),o}finally{p.__wbindgen_add_to_stack_pointer(16)}}isEmpty(){return p.ephemeralstorewasm_isEmpty(this.__wbg_ptr)!==0}encodeAll(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.ephemeralstorewasm_encodeAll(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=hn(e,t).slice();return p.__wbindgen_free(e,t*1,1),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}subscribe(e){const t=p.ephemeralstorewasm_subscribe(this.__wbg_ptr,P(e));return T(t)}}const ol=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_lorocounter_free(n>>>0,1));class Vr{static __wrap(e){e=e>>>0;const t=Object.create(Vr.prototype);return t.__wbg_ptr=e,ol.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,ol.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_lorocounter_free(e,0)}toContainerTree(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorocounter_toContainerTree(s,this.__wbg_ptr,Ae(e)?0:P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}isAttached(){return p.lorocounter_isAttached(this.__wbg_ptr)!==0}getAttached(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorocounter_getAttached(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getShallowValue(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorocounter_getShallowValue(o,this.__wbg_ptr);var e=b().getFloat64(o+0,!0),t=b().getInt32(o+8,!0),r=b().getInt32(o+12,!0);if(r)throw T(t);return e}finally{p.__wbindgen_add_to_stack_pointer(16)}}get id(){const e=p.lorocounter_id(this.__wbg_ptr);return T(e)}constructor(){const e=p.lorocounter_new();return this.__wbg_ptr=e>>>0,ol.register(this,this.__wbg_ptr,this),this}kind(){const e=p.lorocounter_kind(this.__wbg_ptr);return T(e)}parent(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorocounter_parent(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toJSON(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorocounter_getShallowValue(o,this.__wbg_ptr);var e=b().getFloat64(o+0,!0),t=b().getInt32(o+8,!0),r=b().getInt32(o+12,!0);if(r)throw T(t);return e}finally{p.__wbindgen_add_to_stack_pointer(16)}}decrement(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorocounter_decrement(o,this.__wbg_ptr,e);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}get value(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorocounter_getShallowValue(o,this.__wbg_ptr);var e=b().getFloat64(o+0,!0),t=b().getInt32(o+8,!0),r=b().getInt32(o+12,!0);if(r)throw T(t);return e}finally{p.__wbindgen_add_to_stack_pointer(16)}}increment(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorocounter_increment(o,this.__wbg_ptr,e);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}subscribe(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorocounter_subscribe(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}}const sl=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_lorodoc_free(n>>>0,1));class sn{static __wrap(e){e=e>>>0;const t=Object.create(sn.prototype);return t.__wbg_ptr=e,sl.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,sl.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_lorodoc_free(e,0)}applyDiff(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_applyDiff(s,this.__wbg_ptr,P(e),Ae(t)?0:P(t));var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}isShallow(){return p.lorodoc_isShallow(this.__wbg_ptr)!==0}changeCount(){return p.lorodoc_changeCount(this.__wbg_ptr)>>>0}getByPath(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.lorodoc_getByPath(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getCounter(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getCounter(s,this.__wbg_ptr,mt(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Vr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}isDetached(){return p.lorodoc_isDetached(this.__wbg_ptr)!==0}get peerIdStr(){const e=p.lorodoc_peerIdStr(this.__wbg_ptr);return T(e)}setPeerId(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_setPeerId(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getCursorPos(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);jo(e,In),p.lorodoc_getCursorPos(s,this.__wbg_ptr,e.__wbg_ptr);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}hasContainer(e){return p.lorodoc_hasContainer(this.__wbg_ptr,P(e))!==0}importBatch(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_importBatch(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}cmpFrontiers(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16),a=Tt(e,p.__wbindgen_malloc),l=G,c=Tt(t,p.__wbindgen_malloc),u=G;p.lorodoc_cmpFrontiers(i,this.__wbg_ptr,a,l,c,u);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}debugHistory(){p.lorodoc_debugHistory(this.__wbg_ptr)}static fromSnapshot(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Xn(e,p.__wbindgen_malloc),a=G;p.lorodoc_fromSnapshot(s,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return sn.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getChangeAt(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getChangeAt(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}oplogVersion(){const e=p.lorodoc_oplogVersion(this.__wbg_ptr);return At.__wrap(e)}getMovableList(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getMovableList(s,this.__wbg_ptr,mt(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Xr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}frontiersToVV(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Tt(e,p.__wbindgen_malloc),a=G;p.lorodoc_frontiersToVV(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return At.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getAllChanges(){const e=p.lorodoc_getAllChanges(this.__wbg_ptr);return T(e)}oplogFrontiers(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_oplogFrontiers(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}vvToFrontiers(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);jo(e,At),p.lorodoc_vvToFrontiers(s,this.__wbg_ptr,e.__wbg_ptr);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}shallowSinceVV(){const e=p.lorodoc_shallowSinceVV(this.__wbg_ptr);return At.__wrap(e)}configTextStyle(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_configTextStyle(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getOpsInChange(e){try{const a=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getOpsInChange(a,this.__wbg_ptr,P(e));var t=b().getInt32(a+0,!0),r=b().getInt32(a+4,!0),o=b().getInt32(a+8,!0),s=b().getInt32(a+12,!0);if(s)throw T(o);var i=jt(t,r).slice();return p.__wbindgen_free(t,r*4,4),i}finally{p.__wbindgen_add_to_stack_pointer(16)}}getShallowValue(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getShallowValue(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}checkoutToLatest(){try{const r=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_checkoutToLatest(r,this.__wbg_ptr);var e=b().getInt32(r+0,!0),t=b().getInt32(r+4,!0);if(t)throw T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}cmpWithFrontiers(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Tt(e,p.__wbindgen_malloc),a=G;p.lorodoc_cmpWithFrontiers(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return t}finally{p.__wbindgen_add_to_stack_pointer(16)}}exportJsonInIdSpan(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_exportJsonInIdSpan(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}subscribeJsonpath(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16),a=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),l=G;p.lorodoc_subscribeJsonpath(i,this.__wbg_ptr,a,l,P(t));var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}deleteRootContainer(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_deleteRootContainer(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}exportJsonUpdates(e,t,r){try{const a=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_exportJsonUpdates(a,this.__wbg_ptr,P(e),P(t),Ae(r)?16777215:r?1:0);var o=b().getInt32(a+0,!0),s=b().getInt32(a+4,!0),i=b().getInt32(a+8,!0);if(i)throw T(s);return T(o)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getContainerById(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getContainerById(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getPendingTxnLength(){return p.lorodoc_getPendingTxnLength(this.__wbg_ptr)>>>0}importJsonUpdates(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_importJsonUpdates(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}importUpdateBatch(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_importBatch(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}setDetachedEditing(e){p.lorodoc_setDetachedEditing(this.__wbg_ptr,e)}setRecordTimestamp(e){p.lorodoc_setRecordTimestamp(this.__wbg_ptr,e)}subscribePreCommit(e){const t=p.lorodoc_subscribePreCommit(this.__wbg_ptr,P(e));return T(t)}findIdSpansBetween(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16),a=Tt(e,p.__wbindgen_malloc),l=G,c=Tt(t,p.__wbindgen_malloc),u=G;p.lorodoc_findIdSpansBetween(i,this.__wbg_ptr,a,l,c,u);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getChangeAtLamport(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16),a=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),l=G;p.lorodoc_getChangeAtLamport(i,this.__wbg_ptr,a,l,t);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getPathToContainer(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getPathToContainer(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}exportPendingUpdates(){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_exportPendingUpdates(s,this.__wbg_ptr);var e=b().getInt32(s+0,!0),t=b().getInt32(s+4,!0),r=b().getInt32(s+8,!0),o=b().getInt32(s+12,!0);if(o)throw T(r);let i;return e!==0&&(i=hn(e,t).slice(),p.__wbindgen_free(e,t*1,1)),i}finally{p.__wbindgen_add_to_stack_pointer(16)}}getChangedContainersIn(e,t){try{const l=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getChangedContainersIn(l,this.__wbg_ptr,P(e),t);var r=b().getInt32(l+0,!0),o=b().getInt32(l+4,!0),s=b().getInt32(l+8,!0),i=b().getInt32(l+12,!0);if(i)throw T(s);var a=jt(r,o).slice();return p.__wbindgen_free(r,o*4,4),a}finally{p.__wbindgen_add_to_stack_pointer(16)}}getDeepValueWithID(){const e=p.lorodoc_getDeepValueWithID(this.__wbg_ptr);return T(e)}setNextCommitOrigin(e){const t=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),r=G;p.lorodoc_setNextCommitOrigin(this.__wbg_ptr,t,r)}getUncommittedOpsAsJson(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getUncommittedOpsAsJson(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}setNextCommitMessage(e){const t=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),r=G;p.lorodoc_setNextCommitMessage(this.__wbg_ptr,t,r)}setNextCommitOptions(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_setNextCommitOptions(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}shallowSinceFrontiers(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_shallowSinceFrontiers(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}subscribeLocalUpdates(e){const t=p.lorodoc_subscribeLocalUpdates(this.__wbg_ptr,P(e));return T(t)}travelChangeAncestors(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Tt(e,p.__wbindgen_malloc),a=G;p.lorodoc_travelChangeAncestors(s,this.__wbg_ptr,i,a,P(t));var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}clearNextCommitOptions(){p.lorodoc_clearNextCommitOptions(this.__wbg_ptr)}configDefaultTextStyle(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_configDefaultTextStyle(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getDecodedValueCacheLimit(){return p.lorodoc_getDecodedValueCacheLimit(this.__wbg_ptr)>>>0}setChangeMergeInterval(e){p.lorodoc_setChangeMergeInterval(this.__wbg_ptr,e)}setNextCommitTimestamp(e){p.lorodoc_setNextCommitTimestamp(this.__wbg_ptr,e)}setHideEmptyRootContainers(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_setHideEmptyRootContainers(o,this.__wbg_ptr,e);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}isDetachedEditingEnabled(){return p.lorodoc_isDetachedEditingEnabled(this.__wbg_ptr)!==0}setDecodedValueCacheLimit(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_setDecodedValueCacheLimit(o,this.__wbg_ptr,e);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}subscribeFirstCommitFromPeer(e){const t=p.lorodoc_subscribeFirstCommitFromPeer(this.__wbg_ptr,P(e));return T(t)}constructor(){const e=p.lorodoc_new();return this.__wbg_ptr=e>>>0,sl.register(this,this.__wbg_ptr,this),this}diff(e,t,r){try{const a=p.__wbindgen_add_to_stack_pointer(-16),l=Tt(e,p.__wbindgen_malloc),c=G,u=Tt(t,p.__wbindgen_malloc),f=G;p.lorodoc_diff(a,this.__wbg_ptr,l,c,u,f,Ae(r)?16777215:r?1:0);var o=b().getInt32(a+0,!0),s=b().getInt32(a+4,!0),i=b().getInt32(a+8,!0);if(i)throw T(s);return T(o)}finally{p.__wbindgen_add_to_stack_pointer(16)}}fork(){const e=p.lorodoc_fork(this.__wbg_ptr);return sn.__wrap(e)}attach(){p.lorodoc_attach(this.__wbg_ptr)}commit(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_commit(o,this.__wbg_ptr,Ae(e)?0:P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}detach(){p.lorodoc_detach(this.__wbg_ptr)}export(e){try{const a=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_export(a,this.__wbg_ptr,P(e));var t=b().getInt32(a+0,!0),r=b().getInt32(a+4,!0),o=b().getInt32(a+8,!0),s=b().getInt32(a+12,!0);if(s)throw T(o);var i=hn(t,r).slice();return p.__wbindgen_free(t,r*1,1),i}finally{p.__wbindgen_add_to_stack_pointer(16)}}import(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Xn(e,p.__wbindgen_malloc),a=G;p.lorodoc_import(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}forkAt(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Tt(e,p.__wbindgen_malloc),a=G;p.lorodoc_forkAt(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return sn.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getMap(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getMap(s,this.__wbg_ptr,mt(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Gn.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}opCount(){return p.lorodoc_opCount(this.__wbg_ptr)>>>0}get peerId(){const e=p.lorodoc_peerId(this.__wbg_ptr);return BigInt.asUintN(64,e)}toJSON(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_toJSON(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}version(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_version(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return At.__wrap(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}checkout(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16),s=Tt(e,p.__wbindgen_malloc),i=G;p.lorodoc_checkout(o,this.__wbg_ptr,s,i);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getList(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getList(s,this.__wbg_ptr,mt(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Yr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}getText(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getText(s,this.__wbg_ptr,mt(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Gr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}getTree(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_getTree(s,this.__wbg_ptr,mt(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Zr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}frontiers(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_frontiers(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}JSONPath(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.lorodoc_JSONPath(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}revertTo(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16),s=Tt(e,p.__wbindgen_malloc),i=G;p.lorodoc_revertTo(o,this.__wbg_ptr,s,i);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}subscribe(e){const t=p.lorodoc_subscribe(this.__wbg_ptr,P(e));return T(t)}toContainerTree(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_toContainerTree(s,this.__wbg_ptr,Ae(e)?0:P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toContainerTreeJson(e){let t,r;try{const u=p.__wbindgen_add_to_stack_pointer(-16);p.lorodoc_toContainerTreeJson(u,this.__wbg_ptr,Ae(e)?0:P(e));var o=b().getInt32(u+0,!0),s=b().getInt32(u+4,!0),i=b().getInt32(u+8,!0),a=b().getInt32(u+12,!0),l=o,c=s;if(a)throw l=0,c=0,T(i);return t=l,r=c,Ue(l,c)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_free(t,r,1)}}}const il=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_lorolist_free(n>>>0,1));class Yr{static __wrap(e){e=e>>>0;const t=Object.create(Yr.prototype);return t.__wbg_ptr=e,il.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,il.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_lorolist_free(e,0)}isAttached(){return p.lorolist_isAttached(this.__wbg_ptr)!==0}getAttached(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_getAttached(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}pushContainer(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_pushContainer(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getRangeValue(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_getRangeValue(i,this.__wbg_ptr,e,t);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}insertContainer(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_insertContainer(i,this.__wbg_ptr,e,P(t));var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getShallowValue(){const e=p.lorolist_getShallowValue(this.__wbg_ptr);return T(e)}getDeepValueWithID(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_getDeepValueWithID(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getRangeDeepValueWithID(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_getRangeDeepValueWithID(i,this.__wbg_ptr,e,t);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}get id(){const e=p.lorolist_id(this.__wbg_ptr);return T(e)}get(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_get(s,this.__wbg_ptr,e);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}constructor(){const e=p.lorolist_new();return this.__wbg_ptr=e>>>0,il.register(this,this.__wbg_ptr,this),this}pop(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_pop(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}kind(){const e=p.lorolist_kind(this.__wbg_ptr);return T(e)}push(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_push(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}clear(){try{const r=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_clear(r,this.__wbg_ptr);var e=b().getInt32(r+0,!0),t=b().getInt32(r+4,!0);if(t)throw T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}delete(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_delete(s,this.__wbg_ptr,e,t);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}insert(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_insert(s,this.__wbg_ptr,e,P(t));var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}get length(){return p.lorolist_length(this.__wbg_ptr)>>>0}parent(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_parent(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getIdAt(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_getIdAt(s,this.__wbg_ptr,e);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toJSON(){const e=p.lorolist_toJSON(this.__wbg_ptr);return T(e)}toArray(){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_toArray(i,this.__wbg_ptr);var e=b().getInt32(i+0,!0),t=b().getInt32(i+4,!0),r=b().getInt32(i+8,!0),o=b().getInt32(i+12,!0);if(o)throw T(r);var s=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),s}finally{p.__wbindgen_add_to_stack_pointer(16)}}getCursor(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_getCursor(i,this.__wbg_ptr,e,P(t));var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return r===0?void 0:In.__wrap(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}isDeleted(){return p.lorolist_isDeleted(this.__wbg_ptr)!==0}subscribe(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_subscribe(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toContainerTree(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_toContainerTree(s,this.__wbg_ptr,Ae(e)?0:P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toContainerTreeSlice(e,t,r){try{const a=p.__wbindgen_add_to_stack_pointer(-16);p.lorolist_toContainerTreeSlice(a,this.__wbg_ptr,e,t,Ae(r)?0:P(r));var o=b().getInt32(a+0,!0),s=b().getInt32(a+4,!0),i=b().getInt32(a+8,!0);if(i)throw T(s);return T(o)}finally{p.__wbindgen_add_to_stack_pointer(16)}}}const al=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_loromap_free(n>>>0,1));class Gn{static __wrap(e){e=e>>>0;const t=Object.create(Gn.prototype);return t.__wbg_ptr=e,al.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,al.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_loromap_free(e,0)}isAttached(){return p.loromap_isAttached(this.__wbg_ptr)!==0}getAttached(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.loromap_getAttached(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getLastEditor(e){const t=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),r=G,o=p.loromap_getLastEditor(this.__wbg_ptr,t,r);return T(o)}setContainer(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16),a=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),l=G;p.loromap_setContainer(i,this.__wbg_ptr,a,l,P(t));var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getShallowValue(){const e=p.loromap_getShallowValue(this.__wbg_ptr);return T(e)}ensureMergeableMap(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.loromap_ensureMergeableMap(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Gn.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}ensureMergeableList(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.loromap_ensureMergeableList(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Yr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}ensureMergeableText(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.loromap_ensureMergeableText(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Gr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}ensureMergeableTree(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.loromap_ensureMergeableTree(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Zr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getDeepValueWithID(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.loromap_getDeepValueWithID(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getOrCreateContainer(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16),a=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),l=G;p.loromap_getOrCreateContainer(i,this.__wbg_ptr,a,l,P(t));var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}ensureMergeableCounter(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.loromap_ensureMergeableCounter(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Vr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}ensureMergeableMovableList(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.loromap_ensureMergeableMovableList(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return Xr.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}get id(){const e=p.loromap_id(this.__wbg_ptr);return T(e)}get(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.loromap_get(s,this.__wbg_ptr,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}constructor(){const e=p.loromap_new();return this.__wbg_ptr=e>>>0,al.register(this,this.__wbg_ptr,this),this}keys(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.loromap_keys(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}kind(){const e=p.loromap_kind(this.__wbg_ptr);return T(e)}get size(){return p.loromap_size(this.__wbg_ptr)>>>0}clear(){try{const r=p.__wbindgen_add_to_stack_pointer(-16);p.loromap_clear(r,this.__wbg_ptr);var e=b().getInt32(r+0,!0),t=b().getInt32(r+4,!0);if(t)throw T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}delete(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16),s=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),i=G;p.loromap_delete(o,this.__wbg_ptr,s,i);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}set(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.loromap_set(s,this.__wbg_ptr,i,a,P(t));var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}parent(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.loromap_parent(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}values(){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.loromap_values(i,this.__wbg_ptr);var e=b().getInt32(i+0,!0),t=b().getInt32(i+4,!0),r=b().getInt32(i+8,!0),o=b().getInt32(i+12,!0);if(o)throw T(r);var s=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),s}finally{p.__wbindgen_add_to_stack_pointer(16)}}entries(){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.loromap_entries(i,this.__wbg_ptr);var e=b().getInt32(i+0,!0),t=b().getInt32(i+4,!0),r=b().getInt32(i+8,!0),o=b().getInt32(i+12,!0);if(o)throw T(r);var s=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),s}finally{p.__wbindgen_add_to_stack_pointer(16)}}toJSON(){const e=p.loromap_toJSON(this.__wbg_ptr);return T(e)}isDeleted(){return p.loromap_isDeleted(this.__wbg_ptr)!==0}subscribe(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromap_subscribe(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toContainerTree(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromap_toContainerTree(s,this.__wbg_ptr,Ae(e)?0:P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}}const ll=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_loromovablelist_free(n>>>0,1));class Xr{static __wrap(e){e=e>>>0;const t=Object.create(Xr.prototype);return t.__wbg_ptr=e,ll.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,ll.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_loromovablelist_free(e,0)}isAttached(){return p.loromovablelist_isAttached(this.__wbg_ptr)!==0}getCreatorAt(e){const t=p.loromovablelist_getCreatorAt(this.__wbg_ptr,e);return T(t)}getAttached(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_getAttached(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}setContainer(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_setContainer(i,this.__wbg_ptr,e,P(t));var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getLastMoverAt(e){const t=p.loromovablelist_getLastMoverAt(this.__wbg_ptr,e);return T(t)}pushContainer(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_pushContainer(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getLastEditorAt(e){const t=p.loromovablelist_getLastEditorAt(this.__wbg_ptr,e);return T(t)}getRangeValue(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_getRangeValue(i,this.__wbg_ptr,e,t);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}insertContainer(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_insertContainer(i,this.__wbg_ptr,e,P(t));var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getShallowValue(){const e=p.loromovablelist_getShallowValue(this.__wbg_ptr);return T(e)}getDeepValueWithID(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_getDeepValueWithID(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getRangeDeepValueWithID(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_getRangeDeepValueWithID(i,this.__wbg_ptr,e,t);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}get id(){const e=p.loromovablelist_id(this.__wbg_ptr);return T(e)}get(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_get(s,this.__wbg_ptr,e);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}move(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_move(s,this.__wbg_ptr,e,t);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}constructor(){const e=p.loromovablelist_new();return this.__wbg_ptr=e>>>0,ll.register(this,this.__wbg_ptr,this),this}pop(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_pop(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}set(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_set(s,this.__wbg_ptr,e,P(t));var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}kind(){const e=p.loromovablelist_kind(this.__wbg_ptr);return T(e)}push(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_push(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}clear(){try{const r=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_clear(r,this.__wbg_ptr);var e=b().getInt32(r+0,!0),t=b().getInt32(r+4,!0);if(t)throw T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}delete(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_delete(s,this.__wbg_ptr,e,t);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}insert(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_insert(s,this.__wbg_ptr,e,P(t));var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}get length(){return p.loromovablelist_length(this.__wbg_ptr)>>>0}parent(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_parent(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toJSON(){const e=p.loromovablelist_toJSON(this.__wbg_ptr);return T(e)}toArray(){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_toArray(i,this.__wbg_ptr);var e=b().getInt32(i+0,!0),t=b().getInt32(i+4,!0),r=b().getInt32(i+8,!0),o=b().getInt32(i+12,!0);if(o)throw T(r);var s=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),s}finally{p.__wbindgen_add_to_stack_pointer(16)}}getCursor(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_getCursor(i,this.__wbg_ptr,e,P(t));var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return r===0?void 0:In.__wrap(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}isDeleted(){return p.loromovablelist_isDeleted(this.__wbg_ptr)!==0}subscribe(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_subscribe(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toContainerTree(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_toContainerTree(s,this.__wbg_ptr,Ae(e)?0:P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toContainerTreeSlice(e,t,r){try{const a=p.__wbindgen_add_to_stack_pointer(-16);p.loromovablelist_toContainerTreeSlice(a,this.__wbg_ptr,e,t,Ae(r)?0:P(r));var o=b().getInt32(a+0,!0),s=b().getInt32(a+4,!0),i=b().getInt32(a+8,!0);if(i)throw T(s);return T(o)}finally{p.__wbindgen_add_to_stack_pointer(16)}}}const cl=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_lorotext_free(n>>>0,1));class Gr{static __wrap(e){e=e>>>0;const t=Object.create(Gr.prototype);return t.__wbg_ptr=e,cl.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,cl.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_lorotext_free(e,0)}applyDelta(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_applyDelta(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}convertPos(e,t,r){const o=_e(t,p.__wbindgen_malloc,p.__wbindgen_realloc),s=G,i=_e(r,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G,l=p.lorotext_convertPos(this.__wbg_ptr,e,o,s,i,a);return T(l)}deleteUtf8(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_deleteUtf8(s,this.__wbg_ptr,e,t);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getEditorOf(e){const t=p.lorotext_getEditorOf(this.__wbg_ptr,e);return T(t)}insertUtf8(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(t,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.lorotext_insertUtf8(s,this.__wbg_ptr,e,i,a);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}isAttached(){return p.lorotext_isAttached(this.__wbg_ptr)!==0}sliceDelta(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_sliceDelta(i,this.__wbg_ptr,e,t);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getAttached(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_getAttached(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}updateByLine(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.lorotext_updateByLine(s,this.__wbg_ptr,i,a,P(t));var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}sliceDeltaUtf8(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_sliceDeltaUtf8(i,this.__wbg_ptr,e,t);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getShallowValue(){let e,t;try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_getShallowValue(s,this.__wbg_ptr);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);return e=r,t=o,Ue(r,o)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_free(e,t,1)}}getDeepValueWithID(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_getDeepValueWithID(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}get id(){const e=p.lorotext_id(this.__wbg_ptr);return T(e)}constructor(){const e=p.lorotext_new();return this.__wbg_ptr=e>>>0,cl.register(this,this.__wbg_ptr,this),this}iter(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_iter(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}kind(){const e=p.lorotext_kind(this.__wbg_ptr);return T(e)}mark(e,t,r){try{const i=p.__wbindgen_add_to_stack_pointer(-16),a=_e(t,p.__wbindgen_malloc,p.__wbindgen_realloc),l=G;p.lorotext_mark(i,this.__wbg_ptr,P(e),a,l,P(r));var o=b().getInt32(i+0,!0),s=b().getInt32(i+4,!0);if(s)throw T(o)}finally{p.__wbindgen_add_to_stack_pointer(16)}}push(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16),s=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),i=G;p.lorotext_push(o,this.__wbg_ptr,s,i);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}slice(e,t){let r,o;try{const f=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_slice(f,this.__wbg_ptr,e,t);var s=b().getInt32(f+0,!0),i=b().getInt32(f+4,!0),a=b().getInt32(f+8,!0),l=b().getInt32(f+12,!0),c=s,u=i;if(l)throw c=0,u=0,T(a);return r=c,o=u,Ue(c,u)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_free(r,o,1)}}delete(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_delete(s,this.__wbg_ptr,e,t);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}insert(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(t,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.lorotext_insert(s,this.__wbg_ptr,e,i,a);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}get length(){return p.lorotext_length(this.__wbg_ptr)>>>0}parent(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_parent(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}splice(e,t,r){let o,s;try{const d=p.__wbindgen_add_to_stack_pointer(-16),g=_e(r,p.__wbindgen_malloc,p.__wbindgen_realloc),h=G;p.lorotext_splice(d,this.__wbg_ptr,e,t,g,h);var i=b().getInt32(d+0,!0),a=b().getInt32(d+4,!0),l=b().getInt32(d+8,!0),c=b().getInt32(d+12,!0),u=i,f=a;if(c)throw u=0,f=0,T(l);return o=u,s=f,Ue(u,f)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_free(o,s,1)}}unmark(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(t,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.lorotext_unmark(s,this.__wbg_ptr,P(e),i,a);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}update(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),a=G;p.lorotext_update(s,this.__wbg_ptr,i,a,P(t));var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}charAt(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_charAt(s,this.__wbg_ptr,e);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return String.fromCodePoint(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toJSON(){const e=p.lorotext_toJSON(this.__wbg_ptr);return T(e)}toDelta(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_toDelta(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getCursor(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_getCursor(i,this.__wbg_ptr,e,P(t));var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return r===0?void 0:In.__wrap(r)}finally{p.__wbindgen_add_to_stack_pointer(16)}}isDeleted(){return p.lorotext_isDeleted(this.__wbg_ptr)!==0}subscribe(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_subscribe(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toString(){let e,t;try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_toString(s,this.__wbg_ptr);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);return e=r,t=o,Ue(r,o)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_free(e,t,1)}}toContainerTree(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotext_toContainerTree(s,this.__wbg_ptr,Ae(e)?0:P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}}const ul=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_lorotree_free(n>>>0,1));class Zr{static __wrap(e){e=e>>>0;const t=Object.create(Zr.prototype);return t.__wbg_ptr=e,ul.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,ul.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_lorotree_free(e,0)}createNode(e,t){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_createNode(i,this.__wbg_ptr,mt(e),Ae(t)?4294967297:t>>>0);var r=b().getInt32(i+0,!0),o=b().getInt32(i+4,!0),s=b().getInt32(i+8,!0);if(s)throw T(o);return on.__wrap(r)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}isAttached(){return p.lorotree_isAttached(this.__wbg_ptr)!==0}getAttached(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_getAttached(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getNodeByID(e){try{const t=p.lorotree_getNodeByID(this.__wbg_ptr,mt(e));return t===0?void 0:on.__wrap(t)}finally{Be[et++]=void 0}}isNodeDeleted(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_isNodeDeleted(s,this.__wbg_ptr,mt(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return t!==0}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}getShallowValue(){const e=p.lorotree_getShallowValue(this.__wbg_ptr);return T(e)}getDeepValueWithID(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_getDeepValueWithID(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}enableFractionalIndex(e){p.lorotree_enableFractionalIndex(this.__wbg_ptr,e)}disableFractionalIndex(){p.lorotree_disableFractionalIndex(this.__wbg_ptr)}isFractionalIndexEnabled(){return p.lorotree_isFractionalIndexEnabled(this.__wbg_ptr)!==0}get id(){const e=p.lorotree_id(this.__wbg_ptr);return T(e)}move(e,t,r){try{const i=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_move(i,this.__wbg_ptr,mt(e),mt(t),Ae(r)?4294967297:r>>>0);var o=b().getInt32(i+0,!0),s=b().getInt32(i+4,!0);if(s)throw T(o)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0,Be[et++]=void 0}}constructor(){const e=p.lorotree_new();return this.__wbg_ptr=e>>>0,ul.register(this,this.__wbg_ptr,this),this}kind(){const e=p.lorotree_kind(this.__wbg_ptr);return T(e)}nodes(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_nodes(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}roots(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_roots(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=jt(e,t).slice();return p.__wbindgen_free(e,t*4,4),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}delete(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_delete(o,this.__wbg_ptr,mt(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}parent(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_parent(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toJSON(){const e=p.lorotree_toJSON(this.__wbg_ptr);return T(e)}has(e){try{return p.lorotree_has(this.__wbg_ptr,mt(e))!==0}finally{Be[et++]=void 0}}toArray(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_toArray(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getNodes(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_getNodes(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}isDeleted(){return p.lorotree_isDeleted(this.__wbg_ptr)!==0}subscribe(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_subscribe(s,this.__wbg_ptr,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toContainerTree(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotree_toContainerTree(s,this.__wbg_ptr,Ae(e)?0:P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}}const pg=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_lorotreenode_free(n>>>0,1));class on{static __wrap(e){e=e>>>0;const t=Object.create(on.prototype);return t.__wbg_ptr=e,pg.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,pg.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_lorotreenode_free(e,0)}__getClassname(){let e,t;try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode___getClassname(s,this.__wbg_ptr);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);return e=r,t=o,Ue(r,o)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_free(e,t,1)}}creationId(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_creationId(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}isDeleted(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_isDeleted(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return e!==0}finally{p.__wbindgen_add_to_stack_pointer(16)}}moveBefore(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);jo(e,on),p.lorotreenode_moveBefore(o,this.__wbg_ptr,e.__wbg_ptr);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}createNode(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_createNode(s,this.__wbg_ptr,Ae(e)?4294967297:e>>>0);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return on.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}getLastMoveId(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_getLastMoveId(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toJSON(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_toJSON(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}fractionalIndex(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_fractionalIndex(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}get id(){const e=p.lorotreenode_id(this.__wbg_ptr);return T(e)}move(e,t){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_move(s,this.__wbg_ptr,mt(e),Ae(t)?4294967297:t>>>0);var r=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw T(r)}finally{p.__wbindgen_add_to_stack_pointer(16),Be[et++]=void 0}}get data(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_data(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return Gn.__wrap(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}index(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_index(o,this.__wbg_ptr);var e=b().getFloat64(o+0,!0),t=b().getInt32(o+8,!0),r=b().getInt32(o+12,!0);if(r)throw T(t);return e===4294967297?void 0:e}finally{p.__wbindgen_add_to_stack_pointer(16)}}parent(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.lorotreenode_parent(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return e===0?void 0:on.__wrap(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}creator(){const e=p.lorotreenode_creator(this.__wbg_ptr);return T(e)}children(){const e=p.lorotreenode_children(this.__wbg_ptr);return T(e)}moveAfter(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);jo(e,on),p.lorotreenode_moveAfter(o,this.__wbg_ptr,e.__wbg_ptr);var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}}const hg=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_undomanager_free(n>>>0,1));class Wu{__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,hg.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_undomanager_free(e,0)}groupStart(){try{const r=p.__wbindgen_add_to_stack_pointer(-16);p.undomanager_groupStart(r,this.__wbg_ptr);var e=b().getInt32(r+0,!0),t=b().getInt32(r+4,!0);if(t)throw T(e)}finally{p.__wbindgen_add_to_stack_pointer(16)}}topRedoValue(){const e=p.undomanager_topRedoValue(this.__wbg_ptr);return T(e)}topUndoValue(){const e=p.undomanager_topUndoValue(this.__wbg_ptr);return T(e)}setMaxUndoSteps(e){p.undomanager_setMaxUndoSteps(this.__wbg_ptr,e)}setMergeInterval(e){p.undomanager_setMergeInterval(this.__wbg_ptr,e)}addExcludeOriginPrefix(e){const t=_e(e,p.__wbindgen_malloc,p.__wbindgen_realloc),r=G;p.undomanager_addExcludeOriginPrefix(this.__wbg_ptr,t,r)}constructor(e,t){jo(e,sn);const r=p.undomanager_new(e.__wbg_ptr,P(t));return this.__wbg_ptr=r>>>0,hg.register(this,this.__wbg_ptr,this),this}peer(){const e=p.undomanager_peer(this.__wbg_ptr);return T(e)}redo(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.undomanager_redo(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return e!==0}finally{p.__wbindgen_add_to_stack_pointer(16)}}undo(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.undomanager_undo(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=b().getInt32(o+8,!0);if(r)throw T(t);return e!==0}finally{p.__wbindgen_add_to_stack_pointer(16)}}clear(){p.undomanager_clear(this.__wbg_ptr)}pause(){p.undomanager_pause(this.__wbg_ptr)}resume(){p.undomanager_resume(this.__wbg_ptr)}canRedo(){return p.undomanager_canRedo(this.__wbg_ptr)!==0}canUndo(){return p.undomanager_canUndo(this.__wbg_ptr)!==0}groupEnd(){p.undomanager_groupEnd(this.__wbg_ptr)}isPaused(){return p.undomanager_isPaused(this.__wbg_ptr)!==0}setOnPop(e){p.undomanager_setOnPop(this.__wbg_ptr,P(e))}clearRedo(){p.undomanager_clearRedo(this.__wbg_ptr)}clearUndo(){p.undomanager_clearUndo(this.__wbg_ptr)}setOnPush(e){p.undomanager_setOnPush(this.__wbg_ptr,P(e))}}const dl=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>p.__wbg_versionvector_free(n>>>0,1));class At{static __wrap(e){e=e>>>0;const t=Object.create(At.prototype);return t.__wbg_ptr=e,dl.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,dl.unregister(this),e}free(){const e=this.__destroy_into_raw();p.__wbg_versionvector_free(e,0)}get(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.versionvector_get(s,this.__wbg_ptr,P(e));var t=b().getFloat64(s+0,!0),r=b().getInt32(s+8,!0),o=b().getInt32(s+12,!0);if(o)throw T(r);return t===4294967297?void 0:t}finally{p.__wbindgen_add_to_stack_pointer(16)}}constructor(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.versionvector_new(s,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return this.__wbg_ptr=t>>>0,dl.register(this,this.__wbg_ptr,this),this}finally{p.__wbindgen_add_to_stack_pointer(16)}}static decode(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16),i=Xn(e,p.__wbindgen_malloc),a=G;p.versionvector_decode(s,i,a);var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return At.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}encode(){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.versionvector_encode(o,this.__wbg_ptr);var e=b().getInt32(o+0,!0),t=b().getInt32(o+4,!0),r=hn(e,t).slice();return p.__wbindgen_free(e,t*1,1),r}finally{p.__wbindgen_add_to_stack_pointer(16)}}length(){return p.versionvector_length(this.__wbg_ptr)>>>0}remove(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.versionvector_remove(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}setEnd(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.versionvector_setEnd(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}compare(e){jo(e,At);const t=p.versionvector_compare(this.__wbg_ptr,e.__wbg_ptr);return t===4294967297?void 0:t}setLast(e){try{const o=p.__wbindgen_add_to_stack_pointer(-16);p.versionvector_setLast(o,this.__wbg_ptr,P(e));var t=b().getInt32(o+0,!0),r=b().getInt32(o+4,!0);if(r)throw T(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}toJSON(){const e=p.versionvector_toJSON(this.__wbg_ptr);return T(e)}static parseJSON(e){try{const s=p.__wbindgen_add_to_stack_pointer(-16);p.versionvector_parseJSON(s,P(e));var t=b().getInt32(s+0,!0),r=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw T(r);return At.__wrap(t)}finally{p.__wbindgen_add_to_stack_pointer(16)}}}function Kk(n,e){const t=String(W(e)),r=_e(t,p.__wbindgen_malloc,p.__wbindgen_realloc),o=G;b().setInt32(n+4,o,!0),b().setInt32(n+0,r,!0)}function Wk(){return nt(function(n,e,t){const r=W(n).apply(W(e),W(t));return P(r)},arguments)}function Hk(){return nt(function(n,e,t){const r=Reflect.apply(W(n),W(e),W(t));return P(r)},arguments)}function Jk(n){const e=W(n).buffer;return P(e)}function qk(){return nt(function(n,e){const t=W(n).call(W(e));return P(t)},arguments)}function Vk(){return nt(function(n,e,t){const r=W(n).call(W(e),W(t));return P(r)},arguments)}function Yk(){return nt(function(n,e,t,r){const o=W(n).call(W(e),W(t),W(r));return P(o)},arguments)}function Xk(){return nt(function(n,e,t,r,o){const s=W(n).call(W(e),W(t),W(r),W(o));return P(s)},arguments)}function Gk(n){const e=To.__wrap(n);return P(e)}function Zk(n){const e=W(n).crypto;return P(e)}function Qk(n){const e=In.__wrap(n);return P(e)}function eT(n){return W(n).done}function tT(n){const e=Object.entries(W(n));return P(e)}function nT(n){const e=W(n).entries();return P(e)}function rT(n,e){console.error(Ue(n,e))}function oT(n){const e=Array.from(W(n));return P(e)}function sT(n){const e=Object.getOwnPropertySymbols(W(n));return P(e)}function iT(){return nt(function(n,e){W(n).getRandomValues(W(e))},arguments)}function aT(){return nt(function(n,e){const t=Reflect.get(W(n),W(e));return P(t)},arguments)}function lT(n,e){const t=W(n)[e>>>0];return P(t)}function cT(n,e){return W(n)[e>>>0]}function uT(n,e){const t=W(n)[W(e)];return P(t)}function dT(n){let e;try{e=W(n)instanceof ArrayBuffer}catch{e=!1}return e}function fT(n){let e;try{e=W(n)instanceof Map}catch{e=!1}return e}function gT(n){let e;try{e=W(n)instanceof Object}catch{e=!1}return e}function pT(n){let e;try{e=W(n)instanceof Uint8Array}catch{e=!1}return e}function hT(n){return Array.isArray(W(n))}function _T(n){return Number.isSafeInteger(W(n))}function mT(){return P(Symbol.iterator)}function bT(n){return W(n).length}function yT(n){return W(n).length}function wT(n,e,t,r,o,s,i,a){let l,c;try{l=n,c=e,console.log(Ue(n,e),Ue(t,r),Ue(o,s),Ue(i,a))}finally{p.__wbindgen_free(l,c,1)}}function xT(n,e){console.log(Ue(n,e))}function CT(n,e){let t,r;try{t=n,r=e,console.log(Ue(n,e))}finally{p.__wbindgen_free(t,r,1)}}function ST(n){const e=Vr.__wrap(n);return P(e)}function vT(n){const e=Yr.__wrap(n);return P(e)}function kT(n){const e=Gn.__wrap(n);return P(e)}function TT(n){const e=Xr.__wrap(n);return P(e)}function IT(n){const e=Gr.__wrap(n);return P(e)}function ET(n){const e=Zr.__wrap(n);return P(e)}function NT(n){const e=on.__wrap(n);return P(e)}function LT(n,e){performance.mark(Ue(n,e))}function OT(){return nt(function(n,e,t,r){let o,s,i,a;try{o=n,s=e,i=t,a=r,performance.measure(Ue(n,e),Ue(t,r))}finally{p.__wbindgen_free(o,s,1),p.__wbindgen_free(i,a,1)}},arguments)}function RT(n){const e=W(n).msCrypto;return P(e)}function AT(){const n=new Object;return P(n)}function MT(){return P(new Map)}function $T(){const n=new Array;return P(n)}function DT(n){const e=new Uint8Array(W(n));return P(e)}function PT(n,e){const t=new Error(Ue(n,e));return P(t)}function jT(n,e){const t=new Function(Ue(n,e));return P(t)}function FT(n,e,t){const r=new Uint8Array(W(n),e>>>0,t>>>0);return P(r)}function BT(n){const e=new Uint8Array(n>>>0);return P(e)}function UT(n){const e=new Array(n>>>0);return P(e)}function zT(n){const e=W(n).next;return P(e)}function KT(){return nt(function(n){const e=W(n).next();return P(e)},arguments)}function WT(n){const e=W(n).node;return P(e)}function HT(){return Date.now()}function JT(){return nt(function(n){const e=Reflect.ownKeys(W(n));return P(e)},arguments)}function qT(n){const e=W(n).process;return P(e)}function VT(n,e){return W(n).push(W(e))}function YT(){return nt(function(n,e){W(n).randomFillSync(T(e))},arguments)}function XT(){return nt(function(){const n=module.require;return P(n)},arguments)}function GT(n){const e=Promise.resolve(W(n));return P(e)}function ZT(n,e,t){W(n)[e>>>0]=T(t)}function QT(n,e,t){W(n)[T(e)]=T(t)}function eI(n,e,t){W(n).set(W(e),t>>>0)}function tI(n,e,t){const r=W(n).set(W(e),W(t));return P(r)}function nI(){return nt(function(n,e,t){return Reflect.set(W(n),W(e),W(t))},arguments)}function rI(n,e){const t=Tk(hn(n,e));return P(t)}function oI(n,e,t){const r=Sk(W(n),e,t);return P(r)}function sI(n,e,t){const r=Ck(n,W(e),T(t));return P(r)}function iI(){return nt(function(n,e,t){Ik(W(n),e>>>0,W(t))},arguments)}function aI(){return nt(function(n,e){const t=wk(T(n),e!==0);return P(t)},arguments)}function lI(n,e,t){const r=vk(Ue(n,e),t);return P(r)}function cI(){return nt(function(n,e,t){Ek(W(n),W(e),W(t))},arguments)}function uI(n,e,t){const r=xk(T(n),e>>>0,t>>>0);return P(r)}function dI(n){const e=kk(T(n));return P(e)}function fI(){const n=typeof globalThis>"u"?null:globalThis;return Ae(n)?0:P(n)}function gI(){const n=typeof globalThis>"u"?null:globalThis;return Ae(n)?0:P(n)}function pI(){const n=typeof self>"u"?null:self;return Ae(n)?0:P(n)}function hI(){const n=typeof window>"u"?null:window;return Ae(n)?0:P(n)}function _I(n,e,t){const r=W(n).subarray(e>>>0,t>>>0);return P(r)}function mI(n,e){const t=W(n).then(W(e));return P(t)}function bI(n){const e=W(n).value;return P(e)}function yI(n){const e=W(n).versions;return P(e)}function wI(n){const e=At.__wrap(n);return P(e)}function xI(n,e){console.warn(Ue(n,e))}function CI(n){return+W(n)}function SI(n){return P(n)}function vI(n){const e=BigInt.asUintN(64,n);return P(e)}function kI(n,e){const t=W(e),r=typeof t=="bigint"?t:void 0;b().setBigInt64(n+8,Ae(r)?BigInt(0):r,!0),b().setInt32(n+0,!Ae(r),!0)}function TI(n){const e=W(n);return typeof e=="boolean"?e?1:0:2}function II(n){const e=T(n).original;return e.cnt--==1?(e.a=0,!0):!1}function EI(n,e,t){const r=Rm(n,e,16,Bk);return P(r)}function NI(n,e,t){const r=Rm(n,e,16,Uk);return P(r)}function LI(n,e){const t=dc(W(e)),r=_e(t,p.__wbindgen_malloc,p.__wbindgen_realloc),o=G;b().setInt32(n+4,o,!0),b().setInt32(n+0,r,!0)}function OI(n,e){const t=new Error(Ue(n,e));return P(t)}function RI(n,e){return W(n)in W(e)}function AI(n){return Array.isArray(W(n))}function MI(n){return typeof W(n)=="bigint"}function $I(n){return typeof W(n)=="function"}function DI(n){return W(n)===null}function PI(n){const e=W(n);return typeof e=="object"&&e!==null}function jI(n){return typeof W(n)=="string"}function FI(n){return W(n)===void 0}function BI(n,e){return W(n)===W(e)}function UI(n,e){return W(n)==W(e)}function zI(){const n=p.memory;return P(n)}function KI(n,e){const t=W(e),r=typeof t=="number"?t:void 0;b().setFloat64(n+8,Ae(r)?0:r,!0),b().setInt32(n+0,!Ae(r),!0)}function WI(n){return P(n)}function HI(n){const e=W(n);return P(e)}function JI(n){T(n)}function qI(n){throw T(n)}function VI(n,e){const t=W(e),r=typeof t=="string"?t:void 0;var o=Ae(r)?0:_e(r,p.__wbindgen_malloc,p.__wbindgen_realloc),s=G;b().setInt32(n+4,s,!0),b().setInt32(n+0,o,!0)}function YI(n,e){const t=Ue(n,e);return P(t)}function XI(n,e){throw new Error(Ue(n,e))}function GI(n){const e=typeof W(n);return P(e)}const fl=Symbol("loroContainerId");function ZI(n){const e=n.prototype,t=Object.getOwnPropertyDescriptor(e,"id"),r=t&&t.get,o=Object.getOwnPropertyDescriptor(e,"__destroy_into_raw"),s=o&&o.value;if(!r||!o||!s)throw new Error("Unexpected wasm-bindgen container wrapper shape");Object.defineProperty(e,"id",{...t,get(){if(this.__wbg_ptr===0)return r.call(this);const i=this[fl];if(i!==void 0)return i;const a=r.call(this);try{Object.defineProperty(this,fl,{configurable:!0,value:a})}catch{}return a}}),Object.defineProperty(e,"__destroy_into_raw",{...o,value(){try{delete this[fl]}catch{}return s.call(this)}})}function QI(n){const e=n.prototype,t=Object.getOwnPropertyDescriptor(e,"kind"),r=t&&t.value;if(typeof r!="function")throw new Error("Unexpected wasm-bindgen container wrapper shape");let o;Object.defineProperty(e,"kind",{...t,value(){return this.__wbg_ptr===0?r.call(this):(o===void 0&&(o=r.call(this)),o)}})}for(const n of[Gn,Gr,Yr,Zr,Xr,Vr])ZI(n),QI(n);const Mm={AwarenessWasm:zk,ChangeModifier:To,Cursor:In,EphemeralStoreWasm:Ku,LORO_VERSION:Mk,LoroCounter:Vr,LoroDoc:sn,LoroList:Yr,LoroMap:Gn,LoroMovableList:Xr,LoroText:Gr,LoroTree:Zr,LoroTreeNode:on,UndoManager:Wu,VersionVector:At,__wbg_String_8f0eb39a4a4c2f66:Kk,__wbg_apply_36be6a55257c99bf:Wk,__wbg_apply_eb9e9b97497f91e4:Hk,__wbg_buffer_609cc3eee51ed158:Jk,__wbg_call_672a4d21634d4a24:qk,__wbg_call_7cccdd69e0791ae2:Vk,__wbg_call_833bed5770ea2041:Yk,__wbg_call_b8adc8b1d0a0d8eb:Xk,__wbg_changemodifier_new:Gk,__wbg_crypto_574e78ad8b13b65f:Zk,__wbg_cursor_new:Qk,__wbg_done_769e5ede4b31c67b:eT,__wbg_entries_3265d4158b33e5dc:tT,__wbg_entries_c8a90a7ed73e84ce:nT,__wbg_error_428bae4e36b351e3:rT,__wbg_from_2a5d3e218e67aa85:oT,__wbg_getOwnPropertySymbols_97eebed6fe6e08be:sT,__wbg_getRandomValues_b8f5dbd5f3995a9e:iT,__wbg_get_67b2ba62fc30de12:aT,__wbg_get_b9b93047fe3cf45b:lT,__wbg_getindex_5b00c274b05714aa:cT,__wbg_getwithrefkey_1dc361bd10053bfe:uT,__wbg_instanceof_ArrayBuffer_e14585432e3737fc:dT,__wbg_instanceof_Map_f3469ce2244d2430:fT,__wbg_instanceof_Object_7f2dcef8f78644a4:gT,__wbg_instanceof_Uint8Array_17156bcf118086a9:pT,__wbg_isArray_a1eab7e0d067391b:hT,__wbg_isSafeInteger_343e2beeeece1bb0:_T,__wbg_iterator_9a24c88df860dc65:mT,__wbg_length_a446193dc22c12f8:bT,__wbg_length_e2d2a49132c1b256:yT,__wbg_log_0cc1b7768397bcfe:wT,__wbg_log_882f657276590a29:xT,__wbg_log_cb9e190acc5753fb:CT,__wbg_lorocounter_new:ST,__wbg_lorolist_new:vT,__wbg_loromap_new:kT,__wbg_loromovablelist_new:TT,__wbg_lorotext_new:IT,__wbg_lorotree_new:ET,__wbg_lorotreenode_new:NT,__wbg_mark_7438147ce31e9d4b:LT,__wbg_measure_fb7825c11612c823:OT,__wbg_msCrypto_a61aeb35a24c1329:RT,__wbg_new_405e22f390576ce2:AT,__wbg_new_5e0be73521bc8c17:MT,__wbg_new_78feb108b6472713:$T,__wbg_new_a12002a7f91c75be:DT,__wbg_new_c68d7209be747379:PT,__wbg_newnoargs_105ed471475aaf50:jT,__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a:FT,__wbg_newwithlength_a381634e90c276d4:BT,__wbg_newwithlength_c4c419ef0bc8a1f8:UT,__wbg_next_25feadfc0913fea9:zT,__wbg_next_6574e1a8a62d1055:KT,__wbg_node_905d3e251edff8a2:WT,__wbg_now_2b509d5c9d429404:HT,__wbg_ownKeys_3930041068756f1f:JT,__wbg_process_dc0fbacc7c1c06f7:qT,__wbg_push_737cfc8c1432c2c6:VT,__wbg_randomFillSync_ac0988aba3254290:YT,__wbg_require_60cc747a6bc5215a:XT,__wbg_resolve_4851785c9c5f573d:GT,__wbg_set_37837023f3d740e8:ZT,__wbg_set_3f1d0b984ed272ed:QT,__wbg_set_65595bdd868b3009:eI,__wbg_set_8fc6bf8a5b1071d1:tI,__wbg_set_bb8cecf6a62b9f46:nI,__wbg_set_wasm:Nk,__wbg_stateBinary_bcc49261f5205b9f:rI,__wbg_stateCid_ddf7fe40691e2c8f:oI,__wbg_stateContainer_8b73508686ecac7f:sI,__wbg_stateIndex_985e23155ddc5679:iI,__wbg_stateOptions_234376ac96321e68:aI,__wbg_stateRootCid_92a320b321ddff0a:lI,__wbg_stateSet_9c75457bd566f749:cI,__wbg_stateSlice_4573448d6dfd609f:uI,__wbg_stateValue_32a9721f28b53795:dI,__wbg_static_accessor_GLOBAL_88a902d13a557d07:fI,__wbg_static_accessor_GLOBAL_THIS_56578be7e9f832b0:gI,__wbg_static_accessor_SELF_37c5d418e4bf5819:pI,__wbg_static_accessor_WINDOW_5de37043a91a9c40:hI,__wbg_subarray_aa9065fa9dc5df96:_I,__wbg_then_44b73946d2fb3e7d:mI,__wbg_value_cd1ffa7b1ab794f1:bI,__wbg_versions_c01dfd4722a88165:yI,__wbg_versionvector_new:wI,__wbg_warn_5d1fd3858772ca54:xI,__wbindgen_as_number:CI,__wbindgen_bigint_from_i64:SI,__wbindgen_bigint_from_u64:vI,__wbindgen_bigint_get_as_i64:kI,__wbindgen_boolean_get:TI,__wbindgen_cb_drop:II,__wbindgen_closure_wrapper295:EI,__wbindgen_closure_wrapper551:NI,__wbindgen_debug_string:LI,__wbindgen_error_new:OI,__wbindgen_in:RI,__wbindgen_is_array:AI,__wbindgen_is_bigint:MI,__wbindgen_is_function:$I,__wbindgen_is_null:DI,__wbindgen_is_object:PI,__wbindgen_is_string:jI,__wbindgen_is_undefined:FI,__wbindgen_jsval_eq:BI,__wbindgen_jsval_loose_eq:UI,__wbindgen_memory:zI,__wbindgen_number_get:KI,__wbindgen_number_new:WI,__wbindgen_object_clone_ref:HI,__wbindgen_object_drop_ref:JI,__wbindgen_rethrow:qI,__wbindgen_string_get:VI,__wbindgen_string_new:YI,__wbindgen_throw:XI,__wbindgen_typeof:GI,callPendingEvents:gc,decodeFrontiers:jk,decodeImportBlobMeta:fc,encodeFrontiers:Pk,isValidContainerId:Am,redactJsonUpdates:$k,run:Dk,setDebug:Fk},eE={"./loro_wasm_bg.js":Mm},tE=n=>{Mm.__wbg_set_wasm(n),nE(n)};function nE(n){typeof n.__wbindgen_start=="function"&&n.__wbindgen_start()}function rE(n){if(typeof XMLHttpRequest!="function")throw new Error("loro-crdt browser build requires XMLHttpRequest for synchronous WASM loading. Use the nodejs, web, base64, or bundler entry for this runtime.");const e=new XMLHttpRequest;if(e.open("GET",n,!1),e.overrideMimeType("text/plain; charset=x-user-defined"),e.send(null),e.status!==0&&(e.status<200||e.status>=300))throw new Error(`Failed to load loro-crdt WASM from ${n}: ${e.status} ${e.statusText}`);const t=e.responseText,r=new Uint8Array(t.length);for(let o=0;o<t.length;o++)r[o]=t.charCodeAt(o)&255;return r}function oE(n,e){const t=new WebAssembly.Module(n);return new WebAssembly.Instance(t,e)}const sE=new URL(""+new URL("../assets/loro_wasm_bg-XW642dR7.wasm",import.meta.url).href,import.meta.url),iE=oE(rE(sE.href),eE);tE(iE.exports);const aE=["Map","Text","List","Tree","MovableList","Counter"];function lE(n){return Am(n)}function _g(n){if(typeof n!="object"||n==null)return!1;const e=Object.getPrototypeOf(n);return e==null||typeof e!="object"||typeof e.kind!="function"?!1:aE.includes(n.kind())}class cE{constructor(e=3e4){this.inner=new Ku(e),this.timeout=e}apply(e){this.inner.apply(e),this.startTimerIfNotEmpty()}set(e,t){this.inner.set(e,t),this.startTimerIfNotEmpty()}delete(e){this.inner.delete(e)}get(e){return this.inner.get(e)}getAllStates(){return this.inner.getAllStates()}encode(e){return this.inner.encode(e)}encodeAll(){return this.inner.encodeAll()}keys(){return this.inner.keys()}destroy(){clearInterval(this.timer)}subscribe(e){return this.inner.subscribe(e)}subscribeLocalUpdates(e){return this.inner.subscribeLocalUpdates(e)}startTimerIfNotEmpty(){this.inner.isEmpty()||this.timer!=null||(this.timer=setInterval(()=>{this.inner.removeOutdated(),this.inner.isEmpty()&&(clearInterval(this.timer),this.timer=void 0)},this.timeout/2))}}sn.prototype.toJsonWithReplacer=function(n){const e=new Set,t=this,r=(i,a)=>{if(typeof a=="string"&&lE(a)&&!e.has(a)){e.add(a);const c=t.getContainerById(a);if(c==null)throw new Error(`ContainerID not found: ${a}`);const u=n(i,c);if(u===c){const f=c.getShallowValue();return typeof f=="object"?o(f):f}if(_g(u))throw new Error("Using new container is not allowed in toJsonWithReplacer");return typeof u=="object"&&u!=null?o(u):u}if(typeof a=="object"&&a!=null)return o(a);const l=n(i,a);if(_g(l))throw new Error("Using new container is not allowed in toJsonWithReplacer");return l},o=i=>{if(Array.isArray(i))return i.map((l,c)=>r(c,l)).filter(l=>l!==void 0);const a={};for(const[l,c]of Object.entries(i)){const u=r(l,c);u!==void 0&&(a[l]=u)}return a},s=t.getShallowValue();return o(s)};const mg=Symbol("loro.callPendingEventsWrapped");function uE(n,e){const t=Object.getOwnPropertyDescriptor(n,e);if(!t||typeof t.value!="function")return;const r=t.value;if(r[mg])return;const o=function(...s){let i;try{return i=r.apply(this,s),i}finally{i&&typeof i.then=="function"?i.finally(()=>{gc()}):gc()}};o[mg]=!0,Object.defineProperty(n,e,{...t,value:o})}function Hu(n,e){for(const t of e)uE(n,t)}Hu(sn.prototype,["setDetachedEditing","attach","detach","fork","forkAt","checkoutToLatest","checkout","commit","getCursorPos","revertTo","export","exportJsonUpdates","exportJsonInIdSpan","importJsonUpdates","import","importUpdateBatch","importBatch","travelChangeAncestors","getChangedContainersIn","diff","applyDiff","setPeerId"]);Hu(Ku.prototype,["set","delete","apply","removeOutdated"]);Hu(Wu.prototype,["undo","redo"]);const dE=he("CONNECTED_COMMAND"),fE=he("TOGGLE_CONNECT_COMMAND");function gE(n){return new Wu(n.doc,{mergeInterval:1e3,maxUndoSteps:100,excludeOriginPrefixes:["collab-","sync-"]})}function pE(n,e,t,r,o){n.awareness.setLocalState({anchorPos:null,awarenessData:o,color:t,focusPos:null,focusing:r,name:e})}function bg(n,e,t,r,o){const{awareness:s}=n;let i=s.getLocalState();i===null&&(i={anchorPos:null,awarenessData:o,color:t,focusPos:null,focusing:r,name:e}),i.name=e,i.color=t,i.focusing=r,s.setLocalState(i)}function hE(n,e,t){const{awareness:r}=n;let o=r.getLocalState();o===null?o={anchorPos:null,awarenessData:{},color:t,focusPos:null,focusing:!1,name:e}:(o.name=e,o.color=t),r.setLocalState(o)}function _E(n,e,t){const o=ze().getLoroNodeByLexicalKey(n,void 0,void 0,0);if(e)try{if("key"in e||"__key"in e||"lexicalKey"in e){const{key:s,__key:i,lexicalKey:a,children:l,...c}=e;Se(o,"lexical",c)}else{const{children:s,...i}=e;Se(o,"lexical",i)}}catch(s){console.warn("Failed to store lexical node JSON for RootNode:",s)}return Se(o,"elementType","root"),Se(o,"createdAt",Date.now()),o.id}function mE(n,e,t){const o=ze().getLoroNodeByLexicalKey(n,void 0);if(e)try{if("key"in e||"__key"in e||"lexicalKey"in e){const{key:s,__key:i,lexicalKey:a,children:l,...c}=e;Se(o,"lexical",c)}else{const{children:s,...i}=e;Se(o,"lexical",i)}}catch(s){console.warn("Failed to store lexical node JSON for RootNode update:",s)}Se(o,"elementType","root")}function bE(n,e){ze().deleteMapping(n)}function yE(n,e,t,r){switch(e){case"created":{const o=n.editorState._nodeMap.get(t);if(o){let s;n.editorState.read(()=>{if(o.getType()==="root")try{s=o.exportJSON()}catch(i){console.warn("Failed to export root node JSON:",i)}}),s&&_E(t,s)}break}case"updated":{const o=n.editorState._nodeMap.get(t);if(o){let s;n.editorState.read(()=>{if(o.getType()==="root")try{s=o.exportJSON()}catch(i){console.warn("Failed to export root node JSON for update:",i)}}),s&&mE(t,s)}break}case"destroyed":{bE(t);break}}}function wE(n,e,t,r,o){const i=ze().getLoroNodeByLexicalKey(n,void 0,e,t);if(r){const{key:a,__key:l,lexicalKey:c,children:u,...f}=r;Se(i,"lexical",f)}return Se(i,"elementType","linebreak"),Se(i,"createdAt",Date.now()),i.id}function xE(n,e,t,r,o){const s=ze(),{tree:i}=o,a=s.getLoroNodeByLexicalKey(n,void 0);if(!a)return;const l=a.id;if(r){const{key:c,__key:u,lexicalKey:f,children:d,...g}=r;Se(a,"lexical",g)}(e!==void 0||t!==void 0)&&Xi(i,l,e,t),Se(a,"elementType","linebreak")}function CE(n,e){ze().deleteMapping(n)}function SE(n,e,t,r){switch(e){case"created":{const o=n.editorState._nodeMap.get(t);if(o&&ue(o)){const{parentId:s,index:i,lexicalNodeJSON:a}=n.editorState.read(()=>{const l=o.getParent(),c=ze(),u=l?c.getTreeIDByLexicalKey(l.getKey()):void 0,f=o.getIndexWithinParent();let d;try{d=o.exportJSON()}catch(g){console.warn("Failed to export node JSON in propagateLineBreakNode created:",g)}return{parentId:u,index:f,lexicalNodeJSON:d}});wE(t,s,i,a)}break}case"updated":{const o=n.editorState._nodeMap.get(t);if(o&&ue(o)){const{parentId:s,index:i,lexicalNodeJSON:a}=n.editorState.read(()=>{const l=o.getParent(),c=ze(),u=l?c.getTreeIDByLexicalKey(l.getKey()):void 0,f=o.getIndexWithinParent();let d;try{d=o.exportJSON()}catch(g){console.warn("Failed to export node data in propagateLineBreakNode updated:",g)}return{parentId:u,index:f,lexicalNodeJSON:d}});xE(t,s,i,a,r)}break}case"destroyed":{CE(t);break}}}function vE(n,e,t,r,o,s,i){const l=ze().getLoroNodeByLexicalKey(n,void 0,t,r);if(s){const{key:c,__key:u,lexicalKey:f,children:d,...g}=s;Se(l,"lexical",g)}return Se(l,"elementType",e),Se(l,"createdAt",Date.now()),l.id}function kE(n,e,t,r,o,s,i,a,l){const u=ze().getLoroNodeByLexicalKey(n,void 0);if(a){const{key:f,__key:d,lexicalKey:g,children:h,..._}=a;Se(u,"lexical",_)}if(e!==void 0&&Se(u,"elementType",e),t!==void 0||r!==void 0){const{tree:f}=l;dt(!(t&&u.id===t),"updateElementNodeInLoro: cycle move (node is its own parent)",{nodeKey:n,treeId:u.id});const d=u.parent(),g=d?d.id:void 0,_=(d?d.children()??[]:f.roots()).findIndex(w=>w.id===u.id),m=g===t;if(!m||r!==void 0&&r!==_){const w=t?f.getNodeByID(t):null,C=w?w.children()?.length??0:f.roots().length;if(r!==void 0){let v=r;const k=m?Math.max(C-1,0):C;if(v<0||v>k){const I=w?w.children()??[]:f.roots();if(o){const E=I.findIndex(N=>N.id===o);E>=0&&(v=E+1)}if((v<0||v>k)&&s){const E=I.findIndex(N=>N.id===s);E>=0&&(v=E)}if(v<0||v>k){const E=Math.min(Math.max(v,0),k);console.warn("[loro-collab] updateElementNodeInLoro: clamping out-of-range move index",{nodeKey:n,treeId:u.id,index:r,targetIndex:v,clamped:E,maxIndex:k,sameParent:m,previousSiblingId:o,nextSiblingId:s}),v=E}}Xi(f,u.id,t,v)}else Xi(f,u.id,t,C)}}}function TE(n,e){ze().deleteMapping(n)}function IE(n,e,t,r){const{tree:o}=r;switch(e){case"created":{const s=n.editorState._nodeMap.get(t);if(s&&q(s)){let i,a,l,c;const u={};let f;n.editorState.read(()=>{i=s.getParent();const d=ze();a=i?d.getTreeIDByLexicalKey(i.getKey()):void 0,l=s.getIndexWithinParent(),a&&d.getTreeIDByLexicalKey(t)===a&&(a=void 0),c=s.getType(),i&&!a&&console.warn(` ElementNodePropagator: parent mapping missing for ${c} nodeKey=${t}, parentKey=${i.getKey()}`),typeof s.getFormat=="function"&&(u.format=s.getFormat()),typeof s.getStyle=="function"&&(u.style=s.getStyle()),typeof s.getDirection=="function"&&(u.direction=s.getDirection()),f=s.exportJSON()}),vE(t,c,a,l,u,f)}break}case"updated":{const s=n.editorState._nodeMap.get(t);if(s&&q(s)){let i,a,l,c,u,f;const d={};let g;n.editorState.read(()=>{i=s.getParent();const h=ze();if(a=i?h.getTreeIDByLexicalKey(i.getKey()):void 0,l=s.getIndexWithinParent(),i){const _=i.getChildren();for(let m=l-1;m>=0;m--){const y=_[m],w=h.getTreeIDByLexicalKey(y.getKey());if(w&&qt(o,w)){c=w;break}}for(let m=l+1;m<_.length;m++){const y=_[m],w=h.getTreeIDByLexicalKey(y.getKey());if(w&&qt(o,w)){u=w;break}}}f=s.getType(),typeof s.getFormat=="function"&&(d.format=s.getFormat()),typeof s.getStyle=="function"&&(d.style=s.getStyle()),typeof s.getDirection=="function"&&(d.direction=s.getDirection()),g=s.exportJSON()}),kE(t,f,a,l,c,u,d,g,r)}break}case"destroyed":{TE(t);break}}}function gl(n,e,t,r,o,s,i,a){const l=ze();dt(o!==void 0,"createTextNodeInLoro: text node has no parent in Loro tree",{nodeKey:n});const c=l.getLoroNodeByLexicalKey(n,void 0,o,s);if(i)try{if("key"in i||"__key"in i||"lexicalKey"in i){const{key:u,__key:f,lexicalKey:d,children:g,...h}=i;Se(c,"lexical",h)}else{const{children:u,...f}=i;Se(c,"lexical",f)}}catch(u){console.warn("Failed to store lexical node JSON for TextNode:",u)}return Se(c,"elementType","text"),Se(c,"createdAt",Date.now()),c.id}function EE(n,e,t,r,o,s){const a=ze().getTreeIDByLexicalKey(n);if(!a||!qt(s?.tree,a))return;const l=s.tree.getNodeByID(a);if(l){if(o)if("key"in o||"__key"in o||"lexicalKey"in o){const{key:c,__key:u,lexicalKey:f,children:d,...g}=o;Se(l,"lexical",g)}else{const{children:c,...u}=o;Se(l,"lexical",u)}Se(l,"elementType","text")}}function NE(n,e){ze().deleteMapping(n)}function LE(n,e,t,r){const{tree:o}=r;switch(e){case"created":{const s=n.editorState._nodeMap.get(t),i=ze(),a=i.getTreeIDByLexicalKey(t);if(a&&s&&oe(s)){const{currentParentId:l,expectedParentId:c}=n.editorState.read(()=>{const u=s.getParent(),f=u?i.getTreeIDByLexicalKey(u.getKey()):void 0;let d;try{const g=o.getNodeByID(a);if(g){const h=g.parent();d=h?h.id.toString():void 0}}catch(g){console.warn(` Failed to get parent for existing TreeID ${a}:`,g)}return{currentParentId:d,expectedParentId:f}});if(l===c)return;{let u=a;try{const f=o.getNodeByID(a);f&&(u=f.id)}catch(f){console.warn(` Could not get TreeNode for ${a} during creation:`,f)}i.deleteMapping(t);try{qt(o,u)&&o.delete(u)}catch(f){console.warn(` Failed to delete TreeNode ${u} during creation:`,f)}}}if(s&&oe(s)){const{parent:l,parentId:c,index:u,textContent:f,format:d,mode:g,lexicalNodeJSON:h}=n.editorState.read(()=>{const _=s.getParent(),m=ze(),y=_?m.getTreeIDByLexicalKey(_.getKey()):void 0,w=s.getIndexWithinParent(),C=s.getTextContent(),v=s.getFormat(),k=s.getMode();let I;try{I=s.exportJSON()}catch(E){console.warn("Failed to export node JSON in propagateTextNode created:",E)}return{parent:_,parentId:y,index:w,textContent:C,format:v,mode:k,lexicalNodeJSON:I}});gl(t,f,d,g,c,u,h)}break}case"updated":{const s=n.editorState._nodeMap.get(t);if(s&&oe(s)){const i=ze(),a=i.getTreeIDByLexicalKey(t);if(a){const{currentParentId:d,expectedParentId:g,parent:h}=n.editorState.read(()=>{const _=s.getParent(),m=_?i.getTreeIDByLexicalKey(_.getKey()):void 0;let y;try{const w=o.getNodeByID(a);if(w){const C=w.parent();y=C?C.id.toString():void 0}}catch(w){console.warn(` Failed to get parent for existing TreeID ${a} during update:`,w)}return{currentParentId:y,expectedParentId:m,parent:_}});if(d!==g){let _=a;try{const I=o.getNodeByID(a);I&&(_=I.id)}catch(I){console.warn(` Could not get TreeNode for ${a}:`,I)}i.deleteMapping(t);try{qt(o,_)&&o.delete(_)}catch(I){console.warn(` Failed to delete TreeNode ${_} during update:`,I)}const{parentId:m,index:y,textContent:w,format:C,mode:v,lexicalNodeJSON:k}=n.editorState.read(()=>{const I=h?i.getTreeIDByLexicalKey(h.getKey()):void 0,E=s.getIndexWithinParent(),N=s.getTextContent(),O=s.getFormat(),M=s.getMode();let R;try{R=s.exportJSON()}catch($){console.warn("Failed to export node JSON during TextNode recreation:",$)}return{parentId:I,index:E,textContent:N,format:O,mode:M,lexicalNodeJSON:R}});gl(t,w,C,v,m,y,k);return}}if(!a){const{parent:d,parentId:g,index:h,textContent:_,format:m,mode:y,lexicalNodeJSON:w}=n.editorState.read(()=>{const C=s.getParent(),v=C?i.getTreeIDByLexicalKey(C.getKey()):void 0,k=s.getIndexWithinParent(),I=s.getTextContent(),E=s.getFormat(),N=s.getMode();let O;try{O=s.exportJSON()}catch(M){console.warn("Failed to export node JSON in propagateTextNode updated(create fallback):",M)}return{parent:C,parentId:v,index:k,textContent:I,format:E,mode:N,lexicalNodeJSON:O}});g!==void 0&&gl(t,_,m,y,g,h,w);return}const{textContent:l,format:c,mode:u,lexicalNodeJSON:f}=n.editorState.read(()=>{const d=s.getTextContent(),g=s.getFormat(),h=s.getMode();let _;try{_=s.exportJSON()}catch(m){console.warn("Failed to export node JSON in propagateTextNode updated:",m)}return{textContent:d,format:g,mode:h,lexicalNodeJSON:_}});EE(t,l,c,u,f,r)}break}case"destroyed":{NE(t);break}}}function OE(n,e,t,r,o,s,i,a){const c=ze().getLoroNodeByLexicalKey(n,void 0,r,o);if(i){const{key:u,__key:f,lexicalKey:d,children:g,...h}=i;Se(c,"lexical",h)}return Se(c,"elementType","decorator"),Se(c,"createdAt",Date.now()),c.id}function RE(n,e,t,r,o,s,i,a){const c=ze().getLoroNodeByLexicalKey(n,void 0);if(!c)return;const{tree:u}=a,f=c.id;if(i){const{key:d,__key:g,lexicalKey:h,children:_,...m}=i;Se(c,"lexical",m)}(r!==void 0||o!==void 0)&&Xi(u,f,r,o),Se(c,"elementType","decorator")}function AE(n,e){ze().deleteMapping(n)}function ME(n,e,t,r){switch(e){case"created":{const o=n.editorState._nodeMap.get(t);if(o&&It(o)){const{parentId:s,index:i,decoratorType:a,decoratorData:l,metadata:c,lexicalNodeJSON:u}=n.editorState.read(()=>{const f=o.getParent(),d=ze(),g=f?d.getTreeIDByLexicalKey(f.getKey()):void 0,h=o.getIndexWithinParent(),_=o.getType(),m=o.__decoratorData||{},y={};typeof o.isInline=="function"&&(y.isInline=o.isInline());let w;try{w=o.exportJSON()}catch(C){console.warn("Failed to export node data in propagateDecoratorNode created:",C)}return{parentId:g,index:h,decoratorType:_,decoratorData:m,metadata:y,lexicalNodeJSON:w}});OE(t,a,l,s,i,c,u)}break}case"updated":{const o=n.editorState._nodeMap.get(t);if(o&&It(o)){const{parentId:s,index:i,decoratorType:a,decoratorData:l,metadata:c,lexicalNodeJSON:u}=n.editorState.read(()=>{const f=o.getParent(),d=ze(),g=f?d.getTreeIDByLexicalKey(f.getKey()):void 0,h=o.getIndexWithinParent(),_=o.getType(),m=o.__decoratorData||{},y={};typeof o.isInline=="function"&&(y.isInline=o.isInline());let w;try{w=o.exportJSON()}catch(C){console.warn("Failed to export node data in propagateDecoratorNode updated:",C)}return{parentId:g,index:h,decoratorType:_,decoratorData:m,metadata:y,lexicalNodeJSON:w}});RE(t,a,l,s,i,c,u,r)}break}case"destroyed":{AE(t);break}}}function $E(n,e,t){ak(n.nodeMapper,()=>DE(n,e,t))}function DE(n,e,t){const{prevEditorState:r,editorState:o}=t,{dirtyElements:s,dirtyLeaves:i}=t,a=s.size===0&&i.size===0?null:t.mutatedNodes??PE(t);let l=0;if(a&&a.forEach(c=>{l+=c.size}),ye("[SEED-DEBUG] syncLexicalToLoro: mutatedNodes=",a?"map":"null","totalMutations=",l,"tags=",Array.from(t.tags)),a){const c=n.tree;Wt(n.doc);const u={tree:c};let f=!1;if(a.forEach(d=>{d.size>0&&(f=!0)}),f){a.forEach((h,_)=>{so(_,Dd)&&h.forEach((m,y)=>{yE(t,m,y)})});const d=[];a.forEach((h,_)=>{let m=null;if(so(_,Dd)||(so(_,Oe)?m="element":so(_,cn)?m="text":so(_,lw)?m="linebreak":so(_,Bt)&&(m="decorator"),m===null))return;const y=m;h.forEach((w,C)=>{let v=0,k=0;o.read(()=>{const I=Q(C);if(I){k=I.getIndexWithinParent();let E=I.getParent();for(;E;)v++,E=E.getParent()}}),d.push({mutation:w,nodeKey:C,depth:v,index:k,category:y})})});const g=h=>{switch(h.category){case"element":IE(t,h.mutation,h.nodeKey,u);break;case"text":LE(t,h.mutation,h.nodeKey,u);break;case"linebreak":SE(t,h.mutation,h.nodeKey,u);break;case"decorator":ME(t,h.mutation,h.nodeKey,u);break}};d.filter(h=>h.mutation==="destroyed").sort((h,_)=>_.depth-h.depth).forEach(g),d.filter(h=>h.mutation==="created").sort((h,_)=>h.depth-_.depth||h.index-_.index).forEach(g),d.filter(h=>h.mutation==="updated").sort((h,_)=>h.depth-_.depth||h.index-_.index).forEach(g),n.doc.commit({origin:n.doc.peerIdStr})}}o.read(()=>{const c=D(),u=r._selection;Em(n,e,u,c)})}function PE(n){const{dirtyElements:e,dirtyLeaves:t,prevEditorState:r,editorState:o}=n;if(e.size===0&&t.size===0)return null;const s=r._nodeMap,i=o._nodeMap,a=new Map,l=(c,u)=>{const f=c.constructor;let d=a.get(f);d||(d=new Map,a.set(f,d)),d.set(c.getKey(),u)};return i.forEach((c,u)=>{s.has(u)?(e.has(u)||t.has(u))&&l(c,"updated"):l(c,"created")}),s.forEach((c,u)=>{i.has(u)||l(c,"destroyed")}),a}function yg(n){return n&&typeof n=="object"&&typeof n.toJSON=="function"?n.toJSON():n}function jE(n,e,t,r,o){dt(qt(e,n),"NodeFactory: TreeID not live in Loro tree",{treeId:n});const s=e.getNodeByID(n);let i=yg(o?.lexical);if(i||(i=yg(s?.data.get("lexical"))),!i||typeof i!="object"){const f=s?.data.get("elementType")||s?.data.get("nodeType");dt(typeof f=="string"&&f.length>0,"NodeFactory: no lexical data or elementType for TreeID",{treeId:n}),i={type:f,version:1}}const a=i.type||i.__type;dt(!!a,"NodeFactory: no type field in lexical data for TreeID",{treeId:n});const c=t.editor._nodes.get(a);dt(c!=null,"NodeFactory: node type is not registered in the editor",{treeId:n,nodeType:a});const u={...i};return u.type||(u.type=a),u.version===void 0&&(u.version=1),"children"in u||(u.children=[]),c.klass.importJSON(u)}class FE{integrate(e,t,r){t.editor.update(()=>{this.integrateInternal(e,t,r)})}integrateInternal(e,t,r){const o=[],s=[],i=[];for(const _ of e.diff)switch(_.action){case"delete":o.push(_);break;case"create":s.push(_);break;case"move":i.push(_);break}const a=new Map;for(const _ of i)a.set(String(_.target),_);const l=new Set;for(const _ of s)if(_.parent===void 0){const m=a.get(String(_.target));m&&m.parent!==void 0&&(_.parent=m.parent,_.index=m.index,l.add(String(_.target)))}let c=i.filter(_=>!l.has(String(_.target)));const u=new Set;for(const _ of s)qt(t.tree,_.target)||u.add(String(_.target));for(let _=!0;_;){_=!1;for(const m of s){const y=String(m.target);!u.has(y)&&m.parent!==void 0&&u.has(String(m.parent))&&(u.add(y),_=!0)}}const f=u.size===0?s:s.filter(_=>!u.has(String(_.target)));u.size>0&&(c=c.filter(_=>!u.has(String(_.target))));const d=this.topologicalSortCreates(f,t);o.forEach(_=>this.integrateDelete(_,t,r));const g=new Map;let h=d;for(;h.length>0;){const _=[];for(const m of h)this.integrateCreate(m,t,r,g)==="deferred"&&_.push(m);_.length===h.length&&dt(!1,"TreeIntegrator: create operations reference parents missing from the batch",{pending:_.map(m=>({target:String(m.target),parent:m.parent?String(m.parent):null,parentInTree:m.parent?qt(t.tree,m.parent):null,parentMapped:m.parent?t.nodeMapper.getLexicalKeyByLoroId(m.parent)??null:null})),roots:t.tree.roots().map(m=>String(m.id))}),h=_}c.forEach(_=>this.integrateMove(_,t,r))}integrateCreate(e,t,r,o){if(e.parent==null){const l=t.tree.getNodeByID(e.target),c=l?.data.get("elementType"),u=l?.data.get("lexical")?.type;if(c==="root"||u==="root"||!c){const f=se(),d=t.nodeMapper.getTreeIDByLexicalKey(f.getKey());if(d===void 0||!qt(t.tree,d)){t.nodeMapper.setMapping(f.getKey(),e.target);for(const g of f.getChildren())t.nodeMapper.hasLexicalMapping(g.getKey())||g.remove()}else d!==e.target&&t.nodeMapper.aliasLoroId(e.target,f.getKey());return"created"}}const s=t.nodeMapper.getLexicalKeyByLoroId(e.target);if(s!==null&&Q(s)!==null)return"created";const i=String(e.target);let a=o.get(i);if(a===void 0&&(a=jE(e.target,t.tree,t),o.set(i,a)),dt(a!=null,"integrateCreate: failed to materialise Lexical node from Loro data",{target:i}),e.parent){const l=t.nodeMapper.getLexicalKeyByLoroId(e.parent),c=l?Q(l):null;if(!(c&&q(c)))return"deferred";this.insertChild(c,a,e.index)}else dt(this.canBeRootChild(a),"integrateCreate: inline node has no parent (cannot live at root)",{target:i,nodeType:a.getType()}),this.insertChild(se(),a,e.index);return t.nodeMapper.setMapping(a.getKey(),e.target),"created"}canBeRootChild(e){return q(e)||It(e)}insertChild(e,t,r){r!==void 0?e.splice(r,0,[t]):e.append(t)}integrateMove(e,t,r){const o=t.nodeMapper.getLexicalKeyByLoroId(e.target);dt(o!=null,"integrateMove: no Lexical key for move target",{target:String(e.target)});const s=Q(o);dt(s!=null,"integrateMove: node to move not found",{lexicalKey:o});let i;if(e.parent){const a=t.nodeMapper.getLexicalKeyByLoroId(e.parent),l=a?Q(a):null;dt(l!=null&&q(l),"integrateMove: move target parent is not a mapped element",{target:String(e.target),parent:String(e.parent)}),i=l}else dt(this.canBeRootChild(s),"integrateMove: inline node cannot be moved to the root",{lexicalKey:o,nodeType:s.getType()}),i=se();s.remove(),s.isAttached()&&wg(s),e.index!==void 0?i.splice(e.index,0,[s]):i.append(s)}integrateDelete(e,t,r){const o=t.nodeMapper.getLexicalKeyByLoroId(e.target);if(!o)return;const s=Q(o);if(!s){t.nodeMapper.removeMappingForKey(o);return}if(s===se())return;const i=this.collectDescendantKeys(s);for(const a of i)t.nodeMapper.removeMappingForKey(a);s.remove(),s.isAttached()&&wg(s),t.nodeMapper.removeMappingForKey(o)}collectDescendantKeys(e){if(!q(e))return[];const t=[],r=[...e.getChildren()];for(;r.length>0;){const o=r.pop();t.push(o.getKey()),q(o)&&r.push(...o.getChildren())}return t}topologicalSortCreates(e,t){if(e.length<=1)return e;const r=new Set(e.map(l=>String(l.target))),o=new Map;for(const l of e)l.parent&&o.set(String(l.target),String(l.parent));const s=new Map,i=l=>{if(s.has(l))return s.get(l);let c=0,u=l;const f=new Set;for(;o.has(u);){const d=o.get(u);if(f.has(d))break;if(f.add(d),r.has(d))c++,u=d;else break}return s.set(l,c),c},a=e.map((l,c)=>({op:l,depth:i(String(l.target)),idx:c}));return a.sort((l,c)=>l.depth-c.depth||l.idx-c.idx),a.map(l=>l.op)}}function wg(n){Bt.prototype.remove.call(n,!1)}class BE{integrate(e,t,r){e.updated&&Object.entries(e.updated).forEach(([o,s])=>{this.integratePropertyUpdate(o,s,t,r)}),e.deleted&&e.deleted.forEach(o=>{this.integratePropertyDelete(o,t,r)})}integrateWithContext(e,t,r,o){this.integrateWithContextInternal(e,t,r,o)}integrateInternal(e,t,r){e.updated&&Object.entries(e.updated).forEach(([o,s])=>{this.integratePropertyUpdate(o,s,t,r)}),e.deleted&&e.deleted.forEach(o=>{this.integratePropertyDelete(o,t,r)})}integrateWithContextInternal(e,t,r,o){e.updated&&Object.entries(e.updated).forEach(([s,i])=>{this.integratePropertyUpdateWithContextInternal(s,i,t,r,o)}),e.deleted&&e.deleted.forEach(s=>{this.integratePropertyDelete(s,r,o)})}integratePropertyUpdateWithContext(e,t,r,o,s){e==="lexical"&&this.integrateLexicalDataUpdateWithContext(t,r,o)}integratePropertyUpdateWithContextInternal(e,t,r,o,s){switch(e){case"lexical":let i=r;if(typeof r=="string"&&r.startsWith("cid:")){const l=r.split(":");l.length>=3&&(i=l[1])}const a=o.nodeMapper.getLexicalKeyByLoroId(i);a&&this.integrateLexicalDataUpdateInternal(t,a,i,o);break}}integratePropertyUpdate(e,t,r,o){}integratePropertyDelete(e,t,r){}integrateLexicalDataUpdateWithContext(e,t,r){let o=t;if(typeof t=="string"&&t.startsWith("cid:")){const i=t.split(":");i.length>=3&&(o=i[1])}const s=r.nodeMapper.getLexicalKeyByLoroId(o);s&&e&&typeof e=="object"&&r.editor.update(()=>{this.integrateLexicalDataUpdateInternal(e,s,o,r)})}integrateLexicalDataUpdateInternal(e,t,r,o){let s=e;s&&typeof s=="object"&&typeof s.toJSON=="function"&&(s=s.toJSON());const i=Q(t);if(!i)return;const a=i.getType();if(UE(i,s,a))return;const l=s.__text||s.text||s.textContent;if(a==="text"&&l!==void 0){const c=i,u=c.getTextContent();u!==l&&tk(c,t,u,l),s.format!==void 0&&c.setFormat(s.format),s.style!==void 0&&c.setStyle(s.style)}else if(It(i))try{const u=o.editor._nodes.get(a);if(!u){console.warn(` MapIntegrator: Node type '${a}' not registered`);return}const f={...s};if(f.type||(f.type=a),f.version===void 0&&(f.version=1),"children"in f||(f.children=[]),u.klass.prototype.updateFromJSON!==Bt.prototype.updateFromJSON){i.getWritable().updateFromJSON(f);return}const d=u.klass.importJSON(f);i.replace(d),o.nodeMapper.removeMappingForKey(t),o.nodeMapper.setMapping(d.getKey(),r)}catch(c){console.warn(` MapIntegrator: importJSON+replace failed for decorator ${a} node ${t}:`,c)}else try{const c={...s};c.type||(c.type=a),c.version===void 0&&(c.version=1),"children"in c||(c.children=[]),i.getWritable().updateFromJSON(c)}catch(c){console.warn(` MapIntegrator: updateFromJSON failed for ${a} node ${t}:`,c)}}}function UE(n,e,t){try{const r=n.exportJSON(),o=s=>{const{key:i,__key:a,lexicalKey:l,children:c,...u}=s;return{...u,type:u.type??t,version:u.version??1}};return JSON.stringify(o(r))===JSON.stringify(o(e))}catch{return!1}}class zE{integrate(e,t,r){ye(" Handling ListDiff:",e),this.integrateInternal(e,t,r)}integrateInternal(e,t,r){e.diff&&e.diff.forEach(o=>{switch(o.type){case"insert":this.integrateInsert(o,t,r);break;case"delete":this.integrateDelete(o,t,r);break;case"retain":this.integrateRetain(o,t,r);break;default:console.warn(` Unknown list change type: ${o.type}`)}})}integrateInsert(e,t,r){}integrateDelete(e,t,r){}integrateRetain(e,t,r){e.attributes&&ye(` List retain with attributes at ${e.index}, length: ${e.length}`,e.attributes)}}class KE{integrate(e,t,r){this.integrateInternal(e,t,r)}integrateInternal(e,t,r){e.diff&&e.diff.forEach(o=>{switch(o.type){case"insert":this.integrateTextInsert(o,t,r);break;case"delete":this.integrateTextDelete(o,t,r);break;case"retain":this.integrateTextRetain(o,t,r);break;default:console.warn(` Unknown text change type: ${o.type}`)}})}integrateTextInsert(e,t,r){}integrateTextDelete(e,t,r){}integrateTextRetain(e,t,r){e.attributes&&this.applyTextFormatting({...e,attributes:e.attributes},t,r)}applyTextFormatting(e,t,r){}}class WE{integrate(e,t,r){this.integrateInternal(e,t,r)}integrateInternal(e,t,r){e.increment!==void 0&&this.integrateIncrement(e.increment,t,r),e.value!==void 0&&this.integrateSetValue(e.value,t,r)}integrateIncrement(e,t,r){}integrateSetValue(e,t,r){}updateNodeCounter(e,t,r,o,s){}}const HE=new FE,xg=new BE,JE=new zE,qE=new KE,VE=new WE;function YE(n,e,t,r,o=Im){const s=n.editor,i=s._editorState;n.editor.update(()=>{D()&&Ee(null),t.events.forEach((c,u)=>{try{switch(c.diff.type){case"tree":HE.integrateInternal(c.diff,n,e);break;case"map":c.target?xg.integrateWithContextInternal(c.diff,c.target,n,e):xg.integrateInternal(c.diff,n,e);break;case"list":JE.integrateInternal(c.diff,n,e);break;case"text":qE.integrateInternal(c.diff,n,e);break;case"counter":VE.integrateInternal(c.diff,n,e);break;default:throw new Error(`Unsupported event diff type: ${c.diff.type}. Supported types are: 'tree', 'map', 'list', 'text', 'counter'.`)}}catch(f){console.error("[loro-collab] syncLoroToLexical: integrator threw for event",u,"diffType=",c.diff?.type,"target=",String(c?.target),"diff=",JSON.stringify(c.diff),f)}});const l=D();if(F(l))if(ng(l)){const c=i._selection;if(F(c)&&(ig(n,e),ng(l))){const u=l.anchor.key;Cm(u,i)}Em(n,e,c,D())}else ig(n,e);Ai($l)},{onUpdate:()=>{o(n,e),queueMicrotask(()=>{s.update(()=>{se().getChildrenSize()===0&&se().append(ne())})})},skipTransforms:!0,tag:ca})}function XE(n,e,t,r,o,s,i,a,l,c,u,f,d=Im,g){const h=S.useRef(!1),_=S.useCallback(()=>t.connect(),[t]),m=S.useCallback(()=>{try{t.disconnect()}catch{}},[t]);S.useEffect(()=>{const{awareness:w}=t,C=({status:A})=>{n.dispatchCommand(dE,A==="connected")};let v=!1;const k=A=>{A&&!v&&(v=!0,QE(n,a,u)),ye("[SEED-DEBUG] onSync: isSynced=",A,"shouldBootstrap=",i,"isReloadingDoc=",h.current),i&&A&&h.current===!1&&(eN(n,u),g&&g(!0)),h.current=!1},I=()=>{d(a,t)};pE(t,o,s,document.activeElement===n.getRootElement(),f||{});const E=A=>{tN(n,a),l(A),r.set(e,A),h.current=!0};t.on("reload",E),t.on("status",C),t.on("sync",k),w.on("update",I);const N=A=>{A.origin!==a.doc.peerIdStr&&YE(a,t,A,!1,d)},O=a.doc.subscribe(N),M=[],R=n._nodes;ye("[SEED-DEBUG] registering mutation listeners; registeredNodes=",R?R.size:"undefined"),R&&R.forEach(A=>{A&&A.klass&&M.push(n.registerMutationListener(A.klass,()=>{},{skipInitialization:!0}))}),ye("[SEED-DEBUG] mutation listeners registered=",M.length,"editor._listeners.mutation.size=",n._listeners?.mutation?.size);const $=n.registerUpdateListener(A=>{let B=0;A.mutatedNodes&&A.mutatedNodes.forEach(j=>{B+=j.size}),ye("[SEED-DEBUG] updateListener fired; tags=",Array.from(A.tags),"mutatedNodes=",A.mutatedNodes?"map":"null","count=",B,"dirtyElements=",A.dirtyElements?.size,"dirtyLeaves=",A.dirtyLeaves?.size),v&&A.tags.has(ca)===!1&&$E(a,t,A)}),L=_();return()=>{h.current===!1&&(L?L.then(m):m()),t.off("sync",k),t.off("status",C),t.off("reload",E),w.off("update",I),O?.(),r.delete(e),$(),M.forEach(A=>A())}},[a,s,_,m,r,n,e,u,o,t,i,f,l,d,g]);const y=S.useMemo(()=>{const w=C=>{a.cursorsContainer=C};return St.createPortal(x.jsx("div",{ref:w,style:{position:"fixed",top:0,left:0,width:"100vw",height:"100vh",pointerEvents:"none",zIndex:1e3,overflow:"visible"}}),c&&c.current||document.body)},[a,c]);return S.useEffect(()=>n.registerCommand(fE,w=>(w?_():m(),!0),V),[_,m,n]),y}function GE(n,e,t,r,o){S.useEffect(()=>de(n.registerCommand(oh,()=>(bg(e,t,r,!0,o||{}),!1),V),n.registerCommand(cw,()=>(bg(e,t,r,!1,o||{}),!1),V)),[r,n,t,e,o])}function ZE(n,e){const t=S.useMemo(()=>gE(e),[e]);S.useEffect(()=>{const o=()=>{t.undo()},s=()=>{t.redo()};return de(n.registerCommand(ph,()=>(o(),!0),V),n.registerCommand(gh,()=>(s(),!0),V))});const r=S.useCallback(()=>{t.clear()},[t]);return S.useEffect(()=>(n.dispatchCommand(hh,t.canUndo()),n.dispatchCommand(_h,t.canRedo()),()=>{}),[n,t]),r}function QE(n,e,t){n.update(()=>{const r=se();for(const o of r.getChildren())e.nodeMapper.hasLexicalMapping(o.getKey())||o.remove();r.isEmpty()&&!t&&r.append(ne())},{discrete:!0,tag:ca})}function eN(n,e){const t=new Set(["Lexical with Loro","Welcome to Lexical with Loro","Type something..."]),r=()=>{const i=se().getChildren();if(i.length===0)return!1;for(const a of i){const l=a.getType(),c=a.getTextContent().trim();if(c.length>0){if(!t.has(c))return!0;continue}if(l!=="paragraph"&&l!=="jupyter-output")return!0}return!1};let o=!1;if(n.getEditorState().read(()=>{o=!r()}),ye("[SEED-DEBUG] initializeEditor: shouldSeed=",o,"hasInitialState=",!!e,"type=",typeof e),!(!o||!e)){if(typeof e=="string"){let s=[];try{s=JSON.parse(e)?.root?.children??[]}catch{n.update(()=>{n.setEditorState(n.parseEditorState(e),{tag:$n})},{tag:$n});return}n.update(()=>{},{tag:$n,discrete:!0}),n.update(()=>{Ee(null)},{tag:$n,discrete:!0});let i=[];n.getEditorState().read(()=>{i=se().getChildren().map(l=>l.getKey())}),ye("[SEED-DEBUG] initializeEditor: seeding",s.length,"blocks, removing",i.length,"scaffold blocks first");for(const l of i)n.update(()=>{const c=Q(l);c&&c.remove()},{tag:$n,discrete:!0});let a=0;for(const l of s){const c=a++,u=l?.type,f=Array.isArray(l?.children)?l.children.map(d=>d?.type):[];n.update(()=>{se().append(uw(l))},{tag:$n,discrete:!0}),ye("[SEED-DEBUG] appended block",c,"type=",u,"children=",f)}return}n.update(()=>{r()||(typeof e=="object"?n.setEditorState(e,{tag:$n}):typeof e=="function"&&e(n))},{tag:$n})}}function tN(n,e){if(n.update(()=>{const s=se();s.clear(),s.select()},{tag:ca}),e.cursors==null)return;const t=e.cursors;if(t==null)return;const r=e.cursorsContainer;if(r==null)return;const o=Array.from(t.values());for(let s=0;s<o.length;s++){const a=o[s].selection;if(a&&a.selections!=null){const l=a.selections;for(let c=0;c<l.length;c++)r.removeChild(l[s])}}}function Cg(n,e){if(!n||typeof n!="object")return;const t=n,r=t.user,o=r&&typeof r=="object"?r:void 0;for(const s of e){const i=t[s];if(typeof i=="string"&&i.trim().length>0)return i;if(o){const a=o[s];if(typeof a=="string"&&a.trim().length>0)return a}}}function KM({id:n,providerFactory:e,shouldBootstrap:t,username:r,cursorColor:o,cursorsContainerRef:s,initialEditorState:i,excludedProperties:a,awarenessData:l,syncCursorPositionsFn:c,showCollaborators:u=!0,websocketUrl:f="ws://localhost:3002",onInitialization:d,onIdentityResolved:g,onCollaboratorsChange:h}){const _=S.useRef(!1),m=S.useRef(!1),y=Lm(r,o),w=qw(),C=S.useRef(w);C.current=w;const{docMap:v,name:k,color:I}=y,[E]=fe();S.useEffect(()=>(y.isCollabActive=!0,()=>{E._parentEditor==null&&(y.isCollabActive=!1)}),[y,E]);const[N,O]=S.useState(),[M,R]=S.useState();S.useEffect(()=>{if(m.current)return;m.current=!0;const A=e(n,v,f);return O(A),R(v.get(n)),()=>{A.disconnect()}},[n,e,v,f]);const[$,L]=S.useState();return S.useEffect(()=>{if(!N||_.current)return;_.current=!0;const A=uk(E,N,n,M||v.get(n),v,a),B=Nm(A.clientID),j=Cg(l,["display_name","displayName","name","username","handle"]),U=Cg(l,["color"]),z=r||j||B.name,K=C.current[Vw(z)%C.current.length],H=o||U||K;return y.name=z,y.color=H,y.clientID=A.clientID,g?.({name:z,color:H,clientID:A.clientID}),hE(N,z,H),L(A),()=>{}},[E,N,n,v,M,a,y,r,o,l]),!N||!$?x.jsx(x.Fragment,{}):x.jsx(nN,{awarenessData:l,binding:$,collabContext:y,color:I,cursorsContainerRef:s,editor:E,id:n,initialEditorState:i,name:k,provider:N,setDoc:R,shouldBootstrap:t,docMap:v,syncCursorPositionsFn:c,showCollaborators:u,onInitialization:d,onCollaboratorsChange:h})}function nN({editor:n,id:e,provider:t,docMap:r,name:o,color:s,shouldBootstrap:i,cursorsContainerRef:a,initialEditorState:l,awarenessData:c,collabContext:u,binding:f,setDoc:d,syncCursorPositionsFn:g,showCollaborators:h=!1,onInitialization:_,onCollaboratorsChange:m}){const y=XE(n,e,t,r,o,s,i,f,d,a,l,c,g,_);return u.clientID=f.clientID,ZE(n,f),GE(n,t,o,s,c),S.useEffect(()=>{if(!m)return;const{awareness:w}=t,C=()=>m(bk(w.getStates(),f.clientID));return C(),w.on("update",C),()=>{w.off("update",C)}},[f,m,t]),h?x.jsx(ck,{binding:f,cursorsContainer:y,currentUserName:o,currentUserColor:s,showCollaborators:!0}):y}const Sg=30*1e3,rN="update",oN="ephemeral",sN="query-ephemeral";class iN{ephemeralStore;localClientId;eventHandlers=new Map;constructor(e,t){this.ephemeralStore=e,this.localClientId=t?Wt(t):rk(),ye(" AwarenessAdapter created:",{localClientId:this.localClientId,docPeerId:t?t.peerId:"no-doc",existingStatesCount:Object.keys(e.getAllStates()).length}),this.ephemeralStore.subscribe(r=>{(this.eventHandlers.get("update")||[]).forEach(s=>s())})}getLocalState(){const e=this.localClientId.toString();try{const t=this.ephemeralStore.get(e);return t||null}catch(t){throw console.warn("[Client] AwarenessAdapter.getLocalState() - ephemeralStore.get() FAILED:",{error:t.message,stack:t.stack,localKey:e,peerId:this.localClientId,storeExists:!!this.ephemeralStore}),t}}getStates(){const e=new Map;try{const t=this.ephemeralStore.getAllStates();Math.random()<.001&&this.cleanupStaleStates(t);for(const[r,o]of Object.entries(t)){const s=parseInt(r,10);!isNaN(s)&&o&&e.set(s,o)}}catch(t){console.warn("[Client] AwarenessAdapter.getStates() - ERROR:",t.message);const r=this.getLocalState();r&&e.set(this.localClientId,r)}return e}cleanupStaleStates(e){const t=Date.now(),r=300*1e3;try{for(const[o,s]of Object.entries(e)){const i=parseInt(o,10);if(!isNaN(i)&&s&&typeof s=="object"){const a=s,l=typeof a.lastActivity=="number"?a.lastActivity:0;typeof l=="number"&&t-l>r&&(ye("Cleaning up stale user state:",o,"last activity:",new Date(l).toISOString()),this.ephemeralStore.delete(o))}}}catch(o){console.warn("Error during stale state cleanup:",o.message)}}setLocalState(e){const t=this.localClientId.toString(),r={...e,lastActivity:Date.now()};try{this.ephemeralStore.set(t,r)}catch(o){throw console.warn("[Client] AwarenessAdapter.setLocalState() - ephemeralStore.set() FAILED:",{error:o.message,stack:o.stack,localKey:t,peerId:this.localClientId,stateKeys:Object.keys(e||{}),storeExists:!!this.ephemeralStore}),o}}setLocalStateField(e,t){const r=this.getLocalState()||{anchorPos:null,awarenessData:{},color:"#000000",focusPos:null,focusing:!1,name:"Anonymous"};r[e]=t,this.setLocalState(r)}on(e,t){this.eventHandlers.has(e)||this.eventHandlers.set(e,[]),this.eventHandlers.get(e).push(t)}off(e,t){const r=this.eventHandlers.get(e);if(r){const o=r.indexOf(t);o!==-1&&r.splice(o,1)}}forceCleanupStaleStates(){try{const e=this.ephemeralStore.getAllStates();ye("Force cleanup - total keys before:",Object.keys(e).length),this.cleanupStaleStates(e);const t=this.ephemeralStore.getAllStates();ye("Force cleanup - total keys after:",Object.keys(t).length)}catch(e){console.warn("Force cleanup failed:",e.message)}}}const Ms={};Ms[sN]=(n,e,t)=>{try{const r=n.ephemeralStore.encodeAll(),o={type:"ephemeral",ephemeral:Array.from(r),docId:e.docId};return JSON.stringify(o)}catch(r){return console.warn("Error in messageQueryEphemeral integrater:",r.message),null}};Ms[oN]=(n,e,t)=>{try{if(!e.ephemeral||e.ephemeral.length===0)return console.warn("[Client] messageHandlers[messageEphemeral] - Skipping empty ephemeral data"),null;if(e.ephemeral.length<8)return console.warn("[Client] messageHandlers[messageEphemeral] - Rejecting suspiciously small ephemeral data:",e.ephemeral.length),null;if(e.ephemeral.length===1)return console.warn("[Client] messageHandlers[messageEphemeral] - Rejecting single-byte ephemeral data (likely corrupted):",e.ephemeral),null;const r=e.ephemeral.slice(0,4);if(r.every(s=>s===0)||r.every(s=>s===255))return console.warn("[Client] messageHandlers[messageEphemeral] - Rejecting ephemeral data with suspicious pattern:",r),null;const o=new Uint8Array(e.ephemeral);try{n.ephemeralStore.apply(o)}catch(s){if(console.warn("[Client] messageHandlers[messageEphemeral] - WASM apply() failed:",{error:s.message,ephemeralLength:o.length,ephemeralSample:Array.from(o.slice(0,20))}),s.message&&s.message.includes("memory access out of bounds"))return console.warn("[Client] messageHandlers[messageEphemeral] - CRITICAL: WASM memory corruption in apply(). Stopping ephemeral processing."),null;throw s}return null}catch(r){return console.warn("[Client] messageHandlers[messageEphemeral] - ERROR in ephemeral message integrater:",{error:r.message,stack:r.stack,messageLength:e.ephemeral?.length,ephemeralSample:e.ephemeral?.slice(0,10)}),null}};Ms[rN]=(n,e,t)=>{try{const r=new Uint8Array(e.update),o=n.doc.import(r),s=n.doc.version();return ye("[SEED-DEBUG] messageUpdate: imported",r.length,"bytes; importStatus=",JSON.stringify(o)),n._lastExportedVersion=s,t&&n.snapshotLoaded&&!n._synced&&(n.synced=!0),null}catch(r){return console.warn(" [LORO-UPDATE-ERROR] Failed to apply Loro update:",r),null}};const $m=(n,e,t)=>{if(e instanceof ArrayBuffer)try{const r=new Uint8Array(e),o=fc(r,!1).partialEndVersionVector;n.doc.import(r),n.snapshotLoaded=!0;const s=n.doc.export({mode:"update",from:o});if(fc(s,!1).changeNum>0&&n.ws){const i={type:"update",update:Array.from(s),docId:n.docId};zn(n.ws,i)}return t&&!n._synced&&(n.synced=!0),null}catch(r){return console.warn("Failed to process binary Loro update:",r),null}else if(typeof e=="string")try{const r=JSON.parse(e),o=Ms[r.type];return o?o(n,r,t):(console.warn("Unknown message type:",r.type),null)}catch(r){return console.warn("Failed to process JSON message:",r),null}else if(typeof e=="object"&&e!==null)try{const r=e,o=Ms[r.type];return o?o(n,r,t):(console.warn("Unknown message type:",r.type),null)}catch(r){return console.warn("Failed to process object message:",r),null}return console.warn("Unknown message format:",typeof e),null},pc=(n,e,t)=>{if(e===n.ws){if(n.emit("connection-close",[t,n]),n.ws=null,e.close(),n.wsconnecting=!1,n.wsconnected){n.wsconnected=!1,n.synced=!1,n.ephemeralStore.delete("presence"),n.ephemeralStore.delete("cursor");try{const o=Wt(n.doc).toString();n.ephemeralStore.delete(o),ye("Disconnect cleanup: removed user key:",o)}catch(r){console.warn("Disconnect cleanup failed:",r.message)}n.emit("status",[{status:"disconnected"}])}else n.wsUnsuccessfulReconnects++;setTimeout(Dm,fw(gw(2,n.wsUnsuccessfulReconnects)*100,n.maxBackoffTime),n)}},zn=(n,e)=>{if(n&&n.readyState===n.OPEN)try{const t=JSON.stringify(e);n.send(t)}catch(t){console.warn("Failed to send message over WebSocket:",t)}else console.warn("WebSocket not open, cannot send message")},Dm=n=>{if(n.shouldConnect&&n.ws===null){const e=new n._WS(n.url,n.protocols);e.binaryType="arraybuffer",n.ws=e,n.wsconnecting=!0,n.wsconnected=!1,n.synced=!1,e.onmessage=t=>{n.wsLastMessageReceived=Dl(),$m(n,t.data,!0)},e.onerror=t=>{n.emit("connection-error",[t,n])},e.onclose=t=>{n.snapshotLoaded=!1,pc(n,e,t)},e.onopen=()=>{if(n.wsLastMessageReceived=Dl(),n.wsconnecting=!1,n.wsconnected=!0,n.wsUnsuccessfulReconnects=0,n.emit("status",[{status:"connected"}]),ye(" WebSocket connection established, requesting initial data"),n.snapshotLoaded)ye(" Snapshot already loaded, skipping request");else{const s=Math.random().toString(36).substr(2,9),i=Wt(n.doc).toString(),a={type:"query-snapshot",docId:n.docId,clientId:i};ye(` Requesting initial snapshot from server (ID: ${s}, clientId: ${i}):`,a),ye(` Provider instance ID: ${n.wsServerUrl}/${n.docId}, snapshotLoaded: ${n.snapshotLoaded}`),zn(e,a)}const t=Wt(n.doc).toString(),r={type:"query-ephemeral",docId:n.docId,clientId:t};zn(e,r);const o=n.ephemeralStore.getAllStates();if(Object.keys(o).length>0)try{const s=n.ephemeralStore.encodeAll(),i={type:"ephemeral",ephemeral:Array.from(s),docId:n.docId};zn(e,i)}catch(s){console.warn("[Client] setupWS - MAJOR ERROR in ephemeral process:",{error:s.message,stack:s.stack,localStateKeys:Object.keys(o),storeExists:!!n.ephemeralStore})}if(n._pendingUpdates.length>0){const s=n._pendingUpdates;n._pendingUpdates=[],ye("[SEED-DEBUG] ws.onopen: flushing",s.length,"buffered local updates");for(const i of s)zn(e,{type:"update",update:Array.from(i),docId:n.docId})}},n.emit("status",[{status:"connecting"}])}},vg=(n,e)=>{const t=n.ws;n.wsconnected&&t&&t.readyState===t.OPEN?zn(t,e):ye(" [BROADCAST] WebSocket not ready for sending"),n.bcconnected?is(n.bcChannel,JSON.stringify(e),n):ye(" [BROADCAST] BroadcastChannel not connected")};class gr extends dw{static globalEphemeralStore=null;wsServerUrl="";docId="";doc=null;_WS=null;protocols=[];params={};ephemeralStore=null;awareness=null;ws=null;wsconnected=!1;wsconnecting=!1;bcconnected=!1;disableBc=!1;bcChannel="";maxBackoffTime=2500;wsUnsuccessfulReconnects=0;messageHandlers=[];_synced=!1;wsLastMessageReceived=0;shouldConnect=!1;snapshotLoaded=!1;_checkInterval=null;_resyncInterval=null;_updateHandler=null;_ephemeralUpdateIntegrator=null;_exitIntegrator=null;_bcSubscriber=null;_lastExportedVersion=null;_pendingUpdates=[];constructor(e,t,r,{connect:o=!0,ephemeralStore:s=void 0,params:i={},protocols:a=[],WebSocketPolyfill:l=WebSocket,resyncInterval:c=-1,maxBackoffTime:u=2500,disableBc:f=!1}={}){for(super();e[e.length-1]==="/";)e=e.slice(0,e.length-1);this.wsServerUrl=e,this.bcChannel=e+"/"+t,this.maxBackoffTime=u,this.params=i,this.protocols=a,this.docId=t,this.doc=r,this._WS=l;try{if(s)this.ephemeralStore=s;else{if(!gr.globalEphemeralStore)gr.globalEphemeralStore=new cE(3e5),ye("🆕 Created new global EphemeralStore");else{ye(" Reusing existing global EphemeralStore - cleaning up stale user states");const d=gr.globalEphemeralStore.getAllStates();Object.keys(d).forEach(g=>{const h=parseInt(g,10);isNaN(h)||(gr.globalEphemeralStore.delete(g),ye(" Cleaned up stale user state:",g))})}this.ephemeralStore=gr.globalEphemeralStore}}catch(d){throw console.warn("[Client] WebsocketProvider constructor - ERROR setting up EphemeralStore:",{error:d.message,stack:d.stack,docId:t}),d}this.awareness=new iN(this.ephemeralStore,this.doc),this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=f,this.wsUnsuccessfulReconnects=0,this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=o,this._resyncInterval=0,c>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const d=Wt(this.doc).toString(),g={type:"query-ephemeral",docId:this.docId,clientId:d};zn(this.ws,g)}},c)),this._bcSubscriber=(d,g)=>{if(g!==this){const h=$m(this,d,!1);h&&is(this.bcChannel,h,this)}},this._updateHandler=d=>{const g={type:"update",update:Array.from(d),docId:this.docId},h=this.ws;this.wsconnected&&h&&h.readyState===h.OPEN?(ye("[SEED-DEBUG] _updateHandler: sending local update over WS",d.length,"bytes"),zn(h,g)):(ye("[SEED-DEBUG] _updateHandler: WS not ready, buffering local update",d.length,"bytes (pending now",this._pendingUpdates.length+1,")"),this._pendingUpdates.push(d)),this.bcconnected&&is(this.bcChannel,JSON.stringify(g),this)},this._ephemeralUpdateIntegrator=d=>{if(d.added.length>0||d.updated.length>0||d.removed.length>0)try{const g=this.ephemeralStore.encodeAll(),h={type:"ephemeral",ephemeral:Array.from(g),docId:this.docId};vg(this,h)}catch(g){console.warn("[Client] _ephemeralUpdateIntegrator - ERROR:",g.message)}},this._exitIntegrator=()=>{if(this.ephemeralStore&&this.awareness)try{const g=Wt(this.doc).toString();this.ephemeralStore.delete(g)}catch(d){console.warn("[Client] Process exit - Could not clear user state:",d.message)}},Pd&&typeof process<"u"&&process.on("exit",this._exitIntegrator),this.ephemeralStore.subscribe(this._ephemeralUpdateIntegrator),this._lastExportedVersion=this.doc.version();try{this.doc.subscribeLocalUpdates(d=>{try{this._updateHandler(d)}catch(g){console.warn("[WEBSOCKET-PROVIDER] Error exporting incremental update:",g)}})}catch(d){console.warn("[Client] ERROR setting up Loro document subscription:",d)}this._checkInterval=setInterval(()=>{this.wsconnected&&Sg<Dl()-this.wsLastMessageReceived&&pc(this,this.ws,null)},Sg/10),o&&this.connect()}get url(){const e=Yw(this.params);return this.wsServerUrl+"/"+this.docId+(e.length===0?"":"?"+e)}get synced(){return this._synced}set synced(e){this._synced!==e&&(this._synced=e,super.emit("synced",[e]),super.emit("sync",[e]))}destroy(){if(this._resyncInterval!==0&&clearInterval(this._resyncInterval),clearInterval(this._checkInterval),this.disconnect(),Pd&&typeof process<"u"&&process.off("exit",this._exitIntegrator),this.ephemeralStore&&this.awareness)try{const t=Wt(this.doc).toString();this.ephemeralStore.delete(t)}catch(e){console.warn("[Client] WebsocketProvider.destroy - Could not clear user state:",e.message)}super.destroy()}connectBc(){if(this.disableBc)return;this.bcconnected||(Xw(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const e=Wt(this.doc).toString(),t={type:"query-ephemeral",docId:this.docId,clientId:e};is(this.bcChannel,JSON.stringify(t),this);const r=this.ephemeralStore.getAllStates();if(Object.keys(r).length>0)try{const o=this.ephemeralStore.encodeAll(),s={type:"ephemeral",ephemeral:Array.from(o),docId:this.docId};is(this.bcChannel,JSON.stringify(s),this)}catch(o){console.warn("Error broadcasting ephemeral state in connectBc:",o.message)}}disconnectBc(){this.ephemeralStore.delete("presence"),this.ephemeralStore.delete("cursor");try{const t=Wt(this.doc).toString();this.ephemeralStore.delete(t),ye("Broadcast disconnect cleanup: removed user key:",t)}catch(e){console.warn("Broadcast disconnect cleanup failed:",e.message)}try{const e=this.ephemeralStore.encodeAll(),t={type:"ephemeral",ephemeral:Array.from(e),docId:this.docId};vg(this,t)}catch(e){console.warn("Error broadcasting disconnect in disconnectBc:",e.message)}this.bcconnected&&(Gw(this.bcChannel,this._bcSubscriber),this.bcconnected=!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&pc(this,this.ws,null)}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(Dm(this),this.connectBc())}sendUpdate(e){this._updateHandler(e,null)}cleanupStaleStates(){this.awareness&&typeof this.awareness.forceCleanupStaleStates=="function"?this.awareness.forceCleanupStaleStates():console.warn("Cleanup method not available on awareness provider")}}const aN=new URL(window.location.href),lN=new URLSearchParams(aN.search),kg=parseInt(lN.get("resyncInterval")||"30000",10);function WM(n,e,t){let r=e.get(n);r===void 0&&(r=new sn,e.set(n,r));const o=Math.random().toString(36).substr(2,9);ye(` Creating WebsocketProvider instance (ID: ${o}) for docId: ${n}`);let i=t||(()=>{const u=new URL(window.location.href);return new URLSearchParams(u.search).get("collabEndpoint")||"ws://localhost:3002"})();const a={},l=i.indexOf("?");if(l!==-1){const u=i.slice(l+1);i=i.slice(0,l),new URLSearchParams(u).forEach((f,d)=>{a[d]=f})}const c=new gr(i,n,r,{connect:!1,params:a,resyncInterval:kg});return ye(` WebsocketProvider created for: ${i}/${n} with resyncInterval: ${kg}ms`),c}const cN=qn?S.useLayoutEffect:S.useEffect;class uN{key;ref;icon;title;constructor(e){this.key=e,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(e){this.ref={current:e}}}const Tg=n=>{const e=n.closest("#typeahead-menu");if(!e)return;const t=e.getBoundingClientRect();t.top+t.height>window.innerHeight&&e.scrollIntoView({block:"center"}),t.top<0&&e.scrollIntoView({block:"center"}),n.scrollIntoView({block:"nearest"})};function Ig(n,e){const t=n.getBoundingClientRect(),r=e.getBoundingClientRect();return t.top>=r.top-6&&t.top<=r.bottom+6}const Eg=he("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function dN({index:n,isSelected:e,onClick:t,onMouseEnter:r,option:o}){let s="item";return e&&(s+=" selected"),x.jsxs("li",{tabIndex:-1,className:s,ref:o.setRefElement,role:"option","aria-selected":e,id:"typeahead-item-"+n,onMouseEnter:r,onClick:t,children:[o.icon,x.jsx("span",{className:"text",children:o.title})]},o.key)}function fN({close:n,editor:e,anchorElementRef:t,resolution:r,options:o,menuRenderFn:s,onSelectOption:i,shouldSplitNodeWithQuery:a=!1,commandPriority:l=ee,preselectFirstItem:c=!0}){const[u,f]=S.useState(null),d=u!==null?Math.min(o.length-1,u):null,g=r.match&&r.match.matchingString;S.useEffect(()=>{c&&f(0)},[g,c]);const h=S.useCallback(w=>{e.update(()=>{const C=r.match!=null&&a?(function(v){const k=D();if(!F(k)||!k.isCollapsed())return null;const I=k.anchor;if(I.type!=="text")return null;const E=I.getNode();if(!E.isSimpleText())return null;const N=I.offset,O=E.getTextContent().slice(0,N),M=v.replaceableString.length,R=N-(function(L,A,B){let j=B;for(let U=j;U<=A.length;U++)L.slice(-U)===A.substring(0,U)&&(j=U);return j})(O,v.matchingString,M);if(R<0)return null;let $;return R===0?[$]=E.splitText(N):[,$]=E.splitText(R,N),$})(r.match):null;i(w,C,n,r.match?r.match.matchingString:"")})},[e,a,r.match,i,n]),_=S.useCallback(w=>{const C=e.getRootElement();C!==null&&(C.setAttribute("aria-activedescendant","typeahead-item-"+w),f(w))},[e]),m=S.useCallback(()=>t.current&&o.length?wh.createPortal(x.jsx("div",{className:"typeahead-popover mentions-menu",children:x.jsx("ul",{children:o.map((w,C)=>x.jsx(dN,{index:C,isSelected:d===C,onClick:()=>{f(C),h(w)},onMouseEnter:()=>{f(C)},option:w},w.key))})}),t.current):null,[t,o,d,h,f]);S.useEffect(()=>()=>{const w=e.getRootElement();w!==null&&w.removeAttribute("aria-activedescendant")},[e]),cN(()=>{o===null?f(null):d===null&&c&&_(0)},[o,d,_,c]),S.useEffect(()=>de(e.registerCommand(Eg,({option:w})=>!(!w.ref||w.ref.current==null)&&(Tg(w.ref.current),!0),l)),[e,_,l]),S.useEffect(()=>de(e.registerCommand(Vt,w=>{const C=w;if(o!==null&&o.length){const v=d===null?0:d!==o.length-1?d+1:0;_(v);const k=o[v];if(!k)return _(-1),C.preventDefault(),C.stopImmediatePropagation(),!0;k.ref&&k.ref.current&&e.dispatchCommand(Eg,{index:v,option:k}),C.preventDefault(),C.stopImmediatePropagation()}return!0},l),e.registerCommand(pt,w=>{const C=w;if(o!==null&&o.length){const v=d===null?o.length-1:d!==0?d-1:o.length-1;_(v);const k=o[v];if(!k)return _(-1),C.preventDefault(),C.stopImmediatePropagation(),!0;k.ref&&k.ref.current&&Tg(k.ref.current),C.preventDefault(),C.stopImmediatePropagation()}return!0},l),e.registerCommand(Nn,w=>{const C=w;return C.preventDefault(),C.stopImmediatePropagation(),n(),!0},l),e.registerCommand(Kr,w=>{const C=w;return o!==null&&d!==null&&o[d]!=null&&(C.preventDefault(),C.stopImmediatePropagation(),h(o[d]),!0)},l),e.registerCommand(zr,w=>!(o===null||d===null||o[d]==null||w&&w.shiftKey)&&(w!==null&&(w.preventDefault(),w.stopImmediatePropagation()),h(o[d]),!0),l)),[h,n,e,o,d,_,l]);const y=S.useMemo(()=>({options:o,selectOptionAndCleanUp:h,selectedIndex:d,setHighlightedIndex:f}),[h,d,o]);return s!=null?s(t,y,r.match?r.match.matchingString:""):m()}function Ng(n,e){e!=null&&(n.className=e),n.setAttribute("aria-label","Typeahead menu"),n.setAttribute("role","listbox"),n.style.display="block",n.style.position="absolute"}function gN(n,e,t,r,o=!0){const[s]=fe(),i=r??(function(f){if(!qn)return;const d=f.getRootElement();if(d!==null){const g=d.getRootNode();return jc(g)?g:d.ownerDocument.body}return document.body})(s),a=qn?mh(s.getRootElement()).createElement("div"):null,l=S.useRef(a),c=S.useCallback(()=>{if(l.current===null||i===void 0)return;l.current.style.top=l.current.style.bottom;const f=s.getRootElement(),d=l.current,g=d.firstChild;if(f!==null&&n!==null){const{left:h,top:_,width:m,height:y}=n.getRect(),w=l.current.offsetHeight;if(d.style.top=`${_+w+3+(o?window.pageYOffset:0)}px`,d.style.left=`${h+window.pageXOffset}px`,d.style.height=`${y}px`,d.style.width=`${m}px`,g!==null){g.style.top=`${_}`;const C=g.getBoundingClientRect(),v=C.height,k=C.width,I=f.getBoundingClientRect();h+k>I.right&&(d.style.left=`${I.right-k+window.pageXOffset}px`),(_+v>window.innerHeight||_+v>I.bottom)&&_-I.top>v+y&&(d.style.top=`${_-v-y+(o?window.pageYOffset:0)}px`)}d.isConnected||(Ng(d,t),i.append(d)),d.setAttribute("id","typeahead-menu"),f.setAttribute("aria-controls","typeahead-menu")}},[s,n,o,t,i]);S.useEffect(()=>{const f=s.getRootElement();return n!==null&&c(),()=>{f!==null&&f.removeAttribute("aria-controls");const d=l.current;d!==null&&d.isConnected&&(d.remove(),d.removeAttribute("id"))}},[s,c,n]);const u=S.useCallback(f=>{n!==null&&(f||e(null))},[n,e]);return(function(f,d,g,h){const[_]=fe();S.useEffect(()=>{if(d!=null&&f!=null){const m=_.getRootElement(),y=m!=null?bh(m,!1):document.body;let w=!1,C=Ig(d,y);const v=function(){w||(window.requestAnimationFrame(function(){g(),w=!1}),w=!0);const E=Ig(d,y);E!==C&&(C=E,h?.(E))},k=new ResizeObserver(g),I=yh(m??d);return k.observe(d),de(Jt(window,"resize",g),Jt(document,"scroll",v,{capture:!0,passive:!0}),...I.map(E=>Jt(E,"scroll",v,{capture:!0,passive:!0})),()=>k.unobserve(d))}},[d,_,h,g,f])})(n,l.current,c,u),a!=null&&a===l.current&&(Ng(a,t),i?.append(a)),l}function pN({options:n,nodeKey:e,onClose:t,onOpen:r,onSelectOption:o,menuRenderFn:s,anchorClassName:i,commandPriority:a=ee,parent:l}){const[c]=fe(),[u,f]=S.useState(null),d=gN(u,f,i,l),g=S.useCallback(()=>{f(null),t!=null&&u!==null&&t()},[t,u]),h=S.useCallback(m=>{f(m),r!=null&&u===null&&r(m)},[r,u]),_=S.useCallback(()=>{e?c.update(()=>{const m=Q(e),y=c.getElementByKey(e);m!=null&&y!=null&&u==null&&S.startTransition(()=>h({getRect:()=>y.getBoundingClientRect()}))}):e==null&&u!=null&&g()},[g,c,e,h,u]);return S.useEffect(()=>{_()},[_,e]),S.useEffect(()=>{if(e!=null)return c.registerUpdateListener(({dirtyElements:m})=>{m.get(e)&&_()})},[c,_,e]),d.current===null||u===null||c===null?null:x.jsx(fN,{close:g,resolution:u,editor:c,anchorElementRef:d,options:n,menuRenderFn:s,onSelectOption:o,commandPriority:a})}const hN=/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/,Ju=he("INSERT_EMBED_COMMAND");let Lg=class extends uN{title;onSelect;constructor(e,t){super(e),this.title=e,this.onSelect=t.onSelect.bind(this)}};function _N({embedConfigs:n,onOpenEmbedModalForConfig:e,getMenuOptions:t,menuRenderFn:r,menuCommandPriority:o=ee}){const[s]=fe(),[i,a]=S.useState(null),[l,c]=S.useState(null),u=S.useCallback(()=>{a(null),c(null)},[]),f=S.useCallback(async _=>{const m=s.read("latest",function(){const y=Q(_);if(Pe(y))return y.getURL()});if(m!==void 0)for(const y of n)await Promise.resolve(y.parseUrl(m))!=null&&(c(y),a(_))},[s,n]);S.useEffect(()=>de(...[gn,fa].map(_=>s.registerMutationListener(_,(...m)=>((y,{updateTags:w,dirtyLeaves:C})=>{for(const[v,k]of y)k==="created"&&w.has(Up)&&C.size<=3?f(v):v===i&&u()})(...m),{skipInitialization:!0}))),[f,s,i,u]),S.useEffect(()=>{if(e)return s.registerCommand(Ju,_=>{const m=n.find(({type:y})=>y===_);return!!m&&(e(m),!0)},V)},[s,n,e]);const d=S.useCallback(async function(){if(l!=null&&i!=null){const _=s.read("latest",()=>{const m=Q(i);return Pe(m)?m:null});if(Pe(_)){const m=await Promise.resolve(l.parseUrl(_.__url));m!=null&&s.update(()=>{D()||_.selectEnd(),l.insertNode(s,m),_.isAttached()&&_.remove()})}}},[l,s,i]),g=S.useMemo(()=>l!=null&&i!=null?t(l,d,u):[],[l,d,t,i,u]),h=S.useCallback((_,m,y)=>{s.update(()=>{_.onSelect(m),y()})},[s]);return i!=null?x.jsx(pN,{nodeKey:i,onClose:u,onSelectOption:h,options:g,menuRenderFn:r,commandPriority:o}):null}const Xo=()=>{const[n,e]=S.useState(null),t=S.useCallback(()=>{e(null)},[]),r=S.useMemo(()=>{if(n===null)return null;const{title:s,content:i,closeOnClickOutside:a}=n;return x.jsx(Yx,{onClose:t,title:s,closeOnClickOutside:a,children:i})},[n,t]),o=S.useCallback((s,i,a=!1)=>{e({closeOnClickOutside:a,content:i(t),title:s})},[t]);return[r,o]},Pm=he();function mN(n){if(!n.hasNodes([qo]))throw new Error("YouTubePlugin: YouTubeNode not registered on editor");return n.registerCommand(Pm,e=>{const t=K_(e);return sr(t),!0},V)}const jm=pe({name:"@datalayer/jupyter-lexical/YouTube",nodes:()=>[qo],register:mN}),ka=he("INSERT_LOOM_COMMAND");function bN(n){if(!n.hasNodes([Vo]))throw new Error("LoomExtension: LoomNode not registered on editor");return n.registerCommand(ka,e=>(sr($u(e)),!0),V)}const Fm=pe({name:Q_,config:tr({publicAppId:void 0}),nodes:()=>[Vo],register:bN}),yN={contentName:"Youtube Video",exampleUrl:"https://www.youtube.com/watch?v=jNQXAC9IVRw",icon:x.jsx(Ws,{size:16}),insertNode:(n,e)=>{n.dispatchCommand(Pm,e.id)},keywords:["youtube","video"],parseUrl:async n=>{const e=/^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/.exec(n),t=e&&e?.[2].length===11?e[2]:null;return t!=null?{id:t,url:n}:null},type:"youtube-video"},wN={contentName:"Loom Video",exampleUrl:"https://www.loom.com/share/c2b5b05f548d4f1492d5c107f0c48dbc",icon:x.jsx(Ws,{size:16}),insertNode:(n,e)=>{tm(e.url).then(t=>n.dispatchCommand(ka,t))},keywords:["loom","video","recording","screen"],parseUrl:async n=>{const e=Tn(n);return e?{id:e,url:Mu(e)}:null},type:"loom-video"},qu=[yN,wN];function xN({index:n,isSelected:e,onClick:t,onMouseEnter:r,option:o}){const s=S.useCallback(i=>o.setRefElement(i),[o]);return x.jsx(Y,{as:"li",tabIndex:-1,ref:s,role:"option","aria-selected":e,id:"typeahead-item-"+n,onMouseEnter:r,onClick:t,sx:{p:2,cursor:"pointer",bg:e?"actionListItem.default.selectedBg":"transparent","&:hover":{bg:"actionListItem.default.hoverBg"},borderRadius:1},children:x.jsx(Le,{sx:{fontSize:1},children:o.title})},o.key)}function CN({options:n,selectedItemIndex:e,onOptionClick:t,onOptionMouseEnter:r}){return x.jsx(Y,{sx:{bg:"var(--overlay-bgColor)",border:"1px solid",borderColor:"var(--borderColor-default)",borderRadius:2,boxShadow:"var(--shadow-floating-large, 0 0 0 1px #d1d9e0, 0 40px 80px 0 #25292e3d)",p:1},children:x.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:n.map((o,s)=>x.jsx(xN,{index:s,isSelected:e===s,onClick:()=>t(o,s),onMouseEnter:()=>r(s),option:o},o.key))})})}const SN=(n,e)=>{let t;return r=>{window.clearTimeout(t),t=window.setTimeout(()=>{n(r)},e)}};function vN({embedConfig:n,onClose:e}){const[t,r]=S.useState(""),[o]=fe(),[s,i]=S.useState(null),a=S.useMemo(()=>SN(u=>{const f=hN.exec(u);n!=null&&u!=null&&f!=null?Promise.resolve(n.parseUrl(u)).then(d=>{i(d)}):s!=null&&i(null)},200),[n,s]),l=()=>{s!=null&&(n.insertNode(o,s),e())},c=S.useRef(null);return S.useEffect(()=>{c.current?.focus()},[]),x.jsxs("div",{children:[x.jsx(kn,{ref:c,type:"text",placeholder:n.exampleUrl,value:t,"data-test-id":`${n.type}-embed-modal-url`,onChange:u=>{const{value:f}=u.target;r(f),a(f)},block:!0}),x.jsx(xu,{children:x.jsx(xr,{disabled:!s,onClick:l,"data-test-id":`${n.type}-embed-modal-submit-btn`,children:"Embed"})})]})}const kN=()=>{const[n,e]=Xo(),t=o=>{e(`Embed ${o.contentName}`,s=>x.jsx(vN,{embedConfig:o,onClose:s}))},r=(o,s,i)=>[new Lg("Dismiss",{onSelect:i}),new Lg(`Embed ${o.contentName}`,{onSelect:s})];return x.jsxs(x.Fragment,{children:[n,x.jsx(_N,{embedConfigs:qu,onOpenEmbedModalForConfig:t,getMenuOptions:r,menuRenderFn:(o,{selectedIndex:s,options:i,selectOptionAndCleanUp:a,setHighlightedIndex:l})=>o.current?St.createPortal(x.jsx(Y,{sx:{position:"relative",zIndex:1e3,bg:"var(--overlay-bgColor)",border:"1px solid",borderColor:"var(--borderColor-default)",borderRadius:2,boxShadow:"var(--shadow-floating-large, 0 0 0 1px #d1d9e0, 0 40px 80px 0 #25292e3d)",marginLeft:o.current.style.width,width:200},children:x.jsx(CN,{options:i,selectedItemIndex:s,onOptionClick:(c,u)=>{l(u),a(c)},onOptionMouseEnter:c=>{l(c)}})}),o.current):null})]})};class Xs extends Bt{__completionText;static getType(){return"inline-completion"}static clone(e){return new Xs(e.__completionText,e.__key)}constructor(e,t){super(t),this.__completionText=e}createDOM(e){const t=document.createElement("span");return t.className="inline-completion-ghost",t.style.cssText=`
208
208
  opacity: 0.5;
209
209
  color: var(--vscode-editorSuggestWidget-foreground, #999);
210
210
  pointer-events: none;
211
211
  user-select: none;
212
212
  white-space: pre;
213
213
  `,t}updateDOM(){return!1}static importJSON(e){return hc(e.completionText)}exportJSON(){return{completionText:"",type:"inline-completion",version:1}}static importDOM(){return null}exportDOM(){return{element:null}}getCompletionText(){return this.__completionText}setCompletionText(e){const t=this.getWritable();t.__completionText=e}decorate(){return x.jsx(TN,{completionText:this.__completionText})}isInline(){return!0}isKeyboardSelectable(){return!1}}function hc(n){return new Xs(n)}function ds(n){return n instanceof Xs}function TN({completionText:n}){return x.jsx("span",{className:"inline-completion-text",style:{opacity:.5,color:"var(--vscode-editorSuggestWidget-foreground, #999)",pointerEvents:"none",userSelect:"none",whiteSpace:"pre"},children:n})}const IN=/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/,EN=/(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/,NN=[n=>{const e=IN.exec(n);if(e){const t=e[0].startsWith("http")?e[0]:`https://${e[0]}`;return{index:e.index,length:e[0].length,text:e[0],url:t,attributes:{rel:"noopener noreferrer",target:"_blank"}}}return null},n=>{const e=EN.exec(n);return e?{index:e.index,length:e[0].length,text:e[0],url:`mailto:${e[0]}`}:null}],LN=pe({name:"@datalayer/jupyter-lexical/AutoLink",dependencies:[ln(mC,{matchers:NN})]});function Bm(n){const e=n.anchor,t=n.focus,r=n.anchor.getNode(),o=n.focus.getNode();return r===o?r:n.isBackward()?jd(t)?r:o:jd(e)?o:r}const ON=new Set(["http:","https:","mailto:","sms:","tel:"]);function RN(n){try{const e=new URL(n);if(!ON.has(e.protocol))return"about:blank"}catch{return n}return n}const AN=new RegExp(/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[\w]*))?)/);function JM(n){return n==="https://"||AN.test(n)}function Um(n,e,t){const r=S.useRef(null);return r.current=n,S.useMemo(()=>Lx((...o)=>{r.current&&r.current(...o)},e,{maxWait:t}),[e,t])}function pl(n){return n instanceof HTMLElement}class zm{_x;_y;constructor(e,t){this._x=e,this._y=t}get x(){return this._x}get y(){return this._y}equals({x:e,y:t}){return this.x===e&&this.y===t}calcDeltaXTo({x:e}){return this.x-e}calcDeltaYTo({y:e}){return this.y-e}calcHorizontalDistanceTo(e){return Math.abs(this.calcDeltaXTo(e))}calcVerticalDistance(e){return Math.abs(this.calcDeltaYTo(e))}calcDistanceTo(e){return Math.sqrt(Math.pow(this.calcDeltaXTo(e),2)+Math.pow(this.calcDeltaYTo(e),2))}}function MN(n){return n instanceof zm}class pr{_left;_top;_right;_bottom;constructor(e,t,r,o){const[s,i]=t<=o?[t,o]:[o,t],[a,l]=e<=r?[e,r]:[r,e];this._top=s,this._right=l,this._left=a,this._bottom=i}get top(){return this._top}get right(){return this._right}get bottom(){return this._bottom}get left(){return this._left}get width(){return Math.abs(this._left-this._right)}get height(){return Math.abs(this._bottom-this._top)}equals({top:e,left:t,bottom:r,right:o}){return e===this._top&&r===this._bottom&&t===this._left&&o===this._right}contains(e){if(MN(e)){const{x:t,y:r}=e,o=r<this._top,s=r>this._bottom,i=t<this._left,a=t>this._right;return{reason:{isOnBottomSide:s,isOnLeftSide:i,isOnRightSide:a,isOnTopSide:o},result:!o&&!s&&!i&&!a}}else{const{top:t,left:r,bottom:o,right:s}=e;return t>=this._top&&t<=this._bottom&&o>=this._top&&o<=this._bottom&&r>=this._left&&r<=this._right&&s>=this._left&&s<=this._right}}intersectsWith(e){const{left:t,top:r,width:o,height:s}=e,{left:i,top:a,width:l,height:c}=this,u=t+o>=i+l?t+o:i+l,f=r+s>=a+c?r+s:a+c,d=t<=i?t:i,g=r<=a?r:a;return u-d<=o+l&&f-g<=s+c}generateNewRect({left:e=this.left,top:t=this.top,right:r=this.right,bottom:o=this.bottom}){return new pr(e,t,r,o)}static fromLTRB(e,t,r,o){return new pr(e,t,r,o)}static fromLWTH(e,t,r,o){return new pr(e,r,e+t,r+o)}static fromPoints(e,t){const{y:r,x:o}=e,{y:s,x:i}=t;return pr.fromLTRB(o,r,i,s)}static fromDOM(e){const{top:t,width:r,left:o,height:s}=e.getBoundingClientRect();return pr.fromLWTH(o,r,t,s)}}const Gi=new Map,$s=new Map,_c=new Set;function Ii(n,e){e?Gi.set(n,e):Gi.delete(n),_c.forEach(t=>t())}function $N(n){return _c.add(n),()=>_c.delete(n)}function DN(n){return Gi.get(n)}function PN(){return typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():`video-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}function jN(){return typeof MediaRecorder<"u"&&typeof navigator<"u"&&!!navigator.mediaDevices}function FN(){if(!(typeof MediaRecorder>"u"))return["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm","video/mp4"].find(n=>MediaRecorder.isTypeSupported(n))}function BN(n){const e=new Date().toISOString().slice(0,19).replace(/[:T]/g,"-"),t=n.mimeType.startsWith("video/mp4")?"mp4":"webm";return`recording-${e}.${t}`}function UN(n){const e=n instanceof DOMException?n.name:"";return e==="NotAllowedError"?"Recording did not start: the browser was not allowed to capture.":e==="NotFoundError"?"Recording did not start: there is no camera or microphone to record.":`Recording did not start: ${n instanceof Error?n.message:String(n)}`}function zN(n){if(n.length<=1)return{track:n[0],close:()=>{}};const e=new AudioContext,t=e.createMediaStreamDestination();for(const r of n)e.createMediaStreamSource(new MediaStream([r])).connect(t);return{track:t.stream.getAudioTracks()[0],close:()=>{e.close()}}}async function KN(n,{source:e,microphone:t},r){const o=[],s=()=>o.forEach(i=>i.getTracks().forEach(a=>a.stop()));try{const i=navigator.mediaDevices;let a;const l=[];if(e==="screen"){const m=await i.getDisplayMedia({video:!0,audio:!0});if(o.push(m),a=m.getVideoTracks()[0],l.push(...m.getAudioTracks()),t){const y=await i.getUserMedia({audio:!0}).catch(()=>{});y&&(o.push(y),l.push(...y.getAudioTracks()))}}else{const m=await i.getUserMedia({video:!0,audio:t});o.push(m),a=m.getVideoTracks()[0],l.push(...m.getAudioTracks())}if(!a)throw new Error("there was no picture to record");const c=zN(l),u=new MediaStream(c.track?[a,c.track]:[a]),f=FN(),d=new MediaRecorder(u,f?{mimeType:f}:void 0),g=[],h=Date.now();d.ondataavailable=m=>{m.data.size>0&&g.push(m.data)};const _=()=>{s(),c.close()};d.onstop=()=>{_(),$s.delete(n);const m=d.mimeType||f||"video/webm",y=new Blob(g,{type:m}),w={status:"recorded",url:URL.createObjectURL(y),blob:y,mimeType:m,durationMs:Date.now()-h};Ii(n,w),r?.(w)},a.addEventListener("ended",()=>Vu(n)),$s.set(n,{recorder:d,release:_}),d.start(1e3),Ii(n,{status:"recording",startedAt:h,preview:new MediaStream([a])})}catch(i){s(),Ii(n,{status:"failed",message:UN(i)})}}function Vu(n){const e=$s.get(n);e&&e.recorder.state!=="inactive"&&e.recorder.stop()}function WN(n){const e=$s.get(n);e&&(e.recorder.onstop=null,e.recorder.state!=="inactive"&&e.recorder.stop(),e.release(),$s.delete(n));const t=Gi.get(n);t?.status==="recorded"&&URL.revokeObjectURL(t.url),Ii(n,void 0)}function HN(n,e){return e?e.status:n?"lost":"idle"}const Yu=j_?S.useLayoutEffect:S.useEffect;function JN({editor:n,getCodeDOMNode:e}){const[t,r]=S.useState(!1),o=Um(()=>{r(!1)},1e3);async function s(){const i=e();if(!i)return;let a="";n.update(()=>{const l=Me(i);je(l)&&(a=l.getTextContent());const c=D();Ee(c)});try{await navigator.clipboard.writeText(a),r(!0),o()}catch(l){console.error("Failed to copy: ",l)}}return x.jsx(Ft,{icon:t?xh:pw,size:"small",variant:"invisible",onClick:s,"aria-label":"copy",sx:t?{color:"var(--fgColor-success)"}:void 0})}const qN=8;function VN({anchorElem:n}){const[e]=fe(),[t,r]=S.useState(""),[o,s]=S.useState(!1),[i,a]=S.useState(!1),[l,c]=S.useState({right:"0",top:"0"}),u=S.useRef(new Set),f=S.useRef(null);function d(){return f.current}const g=Um(m=>{const{codeDOMNode:y,isOutside:w}=YN(m);if(w){s(!1);return}if(!y)return;f.current=y;let C=null,v="";if(e.update(()=>{const k=Me(y);je(k)&&(C=k,v=C.getLanguage()||"")}),C){const{y:k,right:I}=n.getBoundingClientRect(),{y:E,right:N}=y.getBoundingClientRect();r(v),s(!0),c({right:`${I-N+qN}px`,top:`${E-k}px`})}},50,1e3);S.useEffect(()=>{if(i)return document.addEventListener("mousemove",g),()=>{s(!1),g.cancel(),document.removeEventListener("mousemove",g)}},[i,g]),S.useEffect(()=>e.registerMutationListener(dn,m=>{e.getEditorState().read(()=>{for(const[y,w]of m)switch(w){case"created":u.current.add(y);break;case"destroyed":u.current.delete(y);break}}),a(u.current.size>0)},{skipInitialization:!1}),[e]);const h=C0(t),_=x0(t);return x.jsx(x.Fragment,{children:o?x.jsxs("div",{className:"code-action-menu-container",style:{...l},children:[x.jsx(Le,{sx:{fontSize:0,color:"var(--fgColor-muted)",alignSelf:"center",px:1},children:_}),x.jsx(JN,{editor:e,getCodeDOMNode:d}),E0(h)?x.jsx(L0,{editor:e,getCodeDOMNode:d,lang:h}):null]}):null})}function YN(n){const e=n.target;if(ke(e)){const t=e.closest("code.JupyterLexicalTheme__code"),r=!(t||e.closest("div.code-action-menu-container"));return{codeDOMNode:t,isOutside:r}}else return{codeDOMNode:null,isOutside:!0}}function qM({anchorElem:n=document.body}){return St.createPortal(x.jsx(VN,{anchorElem:n}),n)}function Og(n,e){const t=e.getElementByKey(n.getKey());if(t===null)return;const r=n.getChildren(),o=r.length;if(o===t.__cachedChildrenLength)return;t.__cachedChildrenLength=o;let s="1",i=1;for(let a=0;a<o;a++)ue(r[a])&&(s+=`
214
- `+ ++i);t.setAttribute("data-gutter",s)}function Km(n){const e=[];if(n instanceof dn&&e.push(n),q(n))for(const t of n.getChildren())q(t)&&e.push(...Km(t));return e}function XN(n){const e=de(S0(n),n.registerNodeTransform(dn,t=>{Og(t,n)}));return n.getEditorState().read(()=>{for(const t of Km(se()))Og(t,n)}),e}const GN=pe({name:"@datalayer/jupyter-lexical/CodeBlockHighlight",dependencies:[Vh],register:XN}),Xu=he("INSERT_COLLAPSIBLE_COMMAND"),Rg=()=>{const n=D();if(F(n)&&n.isCollapsed()&&n.anchor.offset===0){const e=re(n.anchor.getNode(),Pt);if(Pt(e)){const t=e.getParent();t!==null&&t.getFirstChild()===e&&n.anchor.key===e.getFirstDescendant()?.getKey()&&e.insertBefore(ne())}}return!1},Ag=()=>{const n=D();if(F(n)&&n.isCollapsed()){const e=re(n.anchor.getNode(),Pt);if(Pt(e)){const t=e.getParent();if(t!==null&&t.getLastChild()===e){const r=e.getFirstDescendant(),o=e.getLastDescendant();(o!==null&&n.anchor.key===o.getKey()&&n.anchor.offset===o.getTextContentSize()||r!==null&&n.anchor.key===r.getKey()&&n.anchor.offset===r.getTextContentSize())&&e.insertAfter(ne())}}}return!1};function ZN(n){if(!n.hasNodes([Mr,Os,$r]))throw new Error("CollapsiblePlugin: CollapsibleContainerNode, CollapsibleTitleNode, or CollapsibleContentNode not registered on editor");return de(n.registerNodeTransform($r,e=>{const t=e.getParent();if(!Pt(t)){const r=e.getChildren();for(const o of r)e.insertBefore(o);e.remove()}}),n.registerNodeTransform(Os,e=>{const t=e.getParent();if(!Pt(t)){e.replace(ne().append(...e.getChildren()));return}}),n.registerNodeTransform(Mr,e=>{const t=e.getChildren();if(t.length!==2||!xi(t[0])||!Lu(t[1])){for(const r of t)e.insertBefore(r);e.remove()}}),n.registerCommand(Vt,Ag,ee),n.registerCommand(ia,Ag,ee),n.registerCommand(pt,Rg,ee),n.registerCommand(zs,Rg,ee),n.registerCommand(Lo,()=>{const e=D();if(F(e)){const t=re(e.anchor.getNode(),r=>xi(r));if(xi(t)){const r=t.getParent();if(r&&Pt(r))return r.getOpen()||r.toggleOpen(),t.getNextSibling()?.selectEnd(),!0}}return!1},ee),n.registerCommand(Xu,()=>(n.update(()=>{const e=Z_(),t=ne();sr(Eu(!0).append(e.append(t),Nu().append(ne()))),t.select()}),!0),ee))}const QN=pe({name:"@datalayer/jupyter-lexical/Collapsible",nodes:()=>[Mr,Os,$r],register:ZN}),e2=qn?S.useLayoutEffect:S.useEffect;class Wm{key;ref;icon;title;constructor(e){this.key=e,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(e){this.ref={current:e}}}const Mg=n=>{const e=n.closest("#typeahead-menu");if(!e)return;const t=e.getBoundingClientRect();t.top+t.height>window.innerHeight&&e.scrollIntoView({block:"center"}),t.top<0&&e.scrollIntoView({block:"center"}),n.scrollIntoView({block:"nearest"})};function $g(n,e){const t=n.getBoundingClientRect(),r=e.getBoundingClientRect();return t.top>=r.top-6&&t.top<=r.bottom+6}function t2(n,e,t,r){const[o]=fe();S.useEffect(()=>{if(e!=null&&n!=null){const s=o.getRootElement(),i=s!=null?bh(s,!1):document.body;let a=!1,l=$g(e,i);const c=function(){a||(window.requestAnimationFrame(function(){t(),a=!1}),a=!0);const d=$g(e,i);d!==l&&(l=d,r?.(d))},u=new ResizeObserver(t),f=yh(s??e);return u.observe(e),de(Jt(window,"resize",t),Jt(document,"scroll",c,{capture:!0,passive:!0}),...f.map(d=>Jt(d,"scroll",c,{capture:!0,passive:!0})),()=>u.unobserve(e))}},[e,o,r,t,n])}const Dg=he("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function n2({index:n,isSelected:e,onClick:t,onMouseEnter:r,option:o}){let s="item";return e&&(s+=" selected"),x.jsxs("li",{tabIndex:-1,className:s,ref:o.setRefElement,role:"option","aria-selected":e,id:"typeahead-item-"+n,onMouseEnter:r,onClick:t,children:[o.icon,x.jsx("span",{className:"text",children:o.title})]},o.key)}function r2({close:n,editor:e,anchorElementRef:t,resolution:r,options:o,menuRenderFn:s,onSelectOption:i,shouldSplitNodeWithQuery:a=!1,commandPriority:l=ee,preselectFirstItem:c=!0}){const[u,f]=S.useState(null),d=u!==null?Math.min(o.length-1,u):null,g=r.match&&r.match.matchingString;S.useEffect(()=>{c&&f(0)},[g,c]);const h=S.useCallback(w=>{e.update(()=>{const C=r.match!=null&&a?(function(v){const k=D();if(!F(k)||!k.isCollapsed())return null;const I=k.anchor;if(I.type!=="text")return null;const E=I.getNode();if(!E.isSimpleText())return null;const N=I.offset,O=E.getTextContent().slice(0,N),M=v.replaceableString.length,R=N-(function(L,A,B){let j=B;for(let U=j;U<=A.length;U++)L.slice(-U)===A.substring(0,U)&&(j=U);return j})(O,v.matchingString,M);if(R<0)return null;let $;return R===0?[$]=E.splitText(N):[,$]=E.splitText(R,N),$})(r.match):null;i(w,C,n,r.match?r.match.matchingString:"")})},[e,a,r.match,i,n]),_=S.useCallback(w=>{const C=e.getRootElement();C!==null&&(C.setAttribute("aria-activedescendant","typeahead-item-"+w),f(w))},[e]),m=S.useCallback(()=>t.current&&o.length?wh.createPortal(x.jsx("div",{className:"typeahead-popover mentions-menu",children:x.jsx("ul",{children:o.map((w,C)=>x.jsx(n2,{index:C,isSelected:d===C,onClick:()=>{f(C),h(w)},onMouseEnter:()=>{f(C)},option:w},w.key))})}),t.current):null,[t,o,d,h,f]);S.useEffect(()=>()=>{const w=e.getRootElement();w!==null&&w.removeAttribute("aria-activedescendant")},[e]),e2(()=>{o===null?f(null):d===null&&c&&_(0)},[o,d,_,c]),S.useEffect(()=>de(e.registerCommand(Dg,({option:w})=>!(!w.ref||w.ref.current==null)&&(Mg(w.ref.current),!0),l)),[e,_,l]),S.useEffect(()=>de(e.registerCommand(Vt,w=>{const C=w;if(o!==null&&o.length){const v=d===null?0:d!==o.length-1?d+1:0;_(v);const k=o[v];if(!k)return _(-1),C.preventDefault(),C.stopImmediatePropagation(),!0;k.ref&&k.ref.current&&e.dispatchCommand(Dg,{index:v,option:k}),C.preventDefault(),C.stopImmediatePropagation()}return!0},l),e.registerCommand(pt,w=>{const C=w;if(o!==null&&o.length){const v=d===null?o.length-1:d!==0?d-1:o.length-1;_(v);const k=o[v];if(!k)return _(-1),C.preventDefault(),C.stopImmediatePropagation(),!0;k.ref&&k.ref.current&&Mg(k.ref.current),C.preventDefault(),C.stopImmediatePropagation()}return!0},l),e.registerCommand(Nn,w=>{const C=w;return C.preventDefault(),C.stopImmediatePropagation(),n(),!0},l),e.registerCommand(Kr,w=>{const C=w;return o!==null&&d!==null&&o[d]!=null&&(C.preventDefault(),C.stopImmediatePropagation(),h(o[d]),!0)},l),e.registerCommand(zr,w=>!(o===null||d===null||o[d]==null||w&&w.shiftKey)&&(w!==null&&(w.preventDefault(),w.stopImmediatePropagation()),h(o[d]),!0),l)),[h,n,e,o,d,_,l]);const y=S.useMemo(()=>({options:o,selectOptionAndCleanUp:h,selectedIndex:d,setHighlightedIndex:f}),[h,d,o]);return s!=null?s(t,y,r.match?r.match.matchingString:""):m()}function Pg(n,e){e!=null&&(n.className=e),n.setAttribute("aria-label","Typeahead menu"),n.setAttribute("role","listbox"),n.style.display="block",n.style.position="absolute"}function o2(n,e,t,r,o=!0){const[s]=fe(),i=r??(function(f){if(!qn)return;const d=f.getRootElement();if(d!==null){const g=d.getRootNode();return jc(g)?g:d.ownerDocument.body}return document.body})(s),a=qn?mh(s.getRootElement()).createElement("div"):null,l=S.useRef(a),c=S.useCallback(()=>{if(l.current===null||i===void 0)return;l.current.style.top=l.current.style.bottom;const f=s.getRootElement(),d=l.current,g=d.firstChild;if(f!==null&&n!==null){const{left:h,top:_,width:m,height:y}=n.getRect(),w=l.current.offsetHeight;if(d.style.top=`${_+w+3+(o?window.pageYOffset:0)}px`,d.style.left=`${h+window.pageXOffset}px`,d.style.height=`${y}px`,d.style.width=`${m}px`,g!==null){g.style.top=`${_}`;const C=g.getBoundingClientRect(),v=C.height,k=C.width,I=f.getBoundingClientRect();h+k>I.right&&(d.style.left=`${I.right-k+window.pageXOffset}px`),(_+v>window.innerHeight||_+v>I.bottom)&&_-I.top>v+y&&(d.style.top=`${_-v-y+(o?window.pageYOffset:0)}px`)}d.isConnected||(Pg(d,t),i.append(d)),d.setAttribute("id","typeahead-menu"),f.setAttribute("aria-controls","typeahead-menu")}},[s,n,o,t,i]);S.useEffect(()=>{const f=s.getRootElement();return n!==null&&c(),()=>{f!==null&&f.removeAttribute("aria-controls");const d=l.current;d!==null&&d.isConnected&&(d.remove(),d.removeAttribute("id"))}},[s,c,n]);const u=S.useCallback(f=>{n!==null&&(f||e(null))},[n,e]);return t2(n,l.current,c,u),a!=null&&a===l.current&&(Pg(a,t),i?.append(a)),l}const s2=`\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'"~=<>_:;`;function Hm(n,{minLength:e=1,maxLength:t=75,punctuation:r=s2,allowWhitespace:o=!1}){return S.useCallback(s=>{const i=new RegExp("(^|\\s|\\()(["+n+"]((?:"+("[^"+n+r+(o?"":"\\s")+"]")+"){0,"+t+"}))$").exec(s);if(i!==null){const a=i[1],l=i[3];if(l.length>=e)return{leadOffset:i.index+a.length,matchingString:l,replaceableString:i[2]}}return null},[o,n,r,t,e])}function Jm({options:n,onQueryChange:e,onSelectOption:t,onOpen:r,onClose:o,menuRenderFn:s,triggerFn:i,anchorClassName:a,commandPriority:l=ee,parent:c,preselectFirstItem:u=!0,ignoreEntityBoundary:f=!1}){const[d]=fe(),[g,h]=S.useState(null),_=o2(g,h,a,c),m=S.useCallback(()=>{if(g===null)return;const w=()=>{h(null)};let C;try{C=o&&o()}finally{C?C.then(w,w):w()}},[o,g]),y=S.useCallback(w=>{h(w),r!=null&&g===null&&r(w)},[r,g]);return S.useEffect(()=>{const w=d.registerUpdateListener(()=>{d.read("latest",()=>{if(!d.isEditable())return void m();if(d.isComposing())return;const C=d._window||window,v=C.document.createRange(),k=D(),I=(function(N){let O=null;return N.read("latest",()=>{const M=D();F(M)&&(O=(function(R){const $=R.anchor;if($.type!=="text")return null;const L=$.getNode();if(!L.isSimpleText())return null;const A=$.offset;return L.getTextContent().slice(0,A)})(M))}),O})(d);if(!F(k)||!k.isCollapsed()||I===null||v===null)return void m();const E=i(I,d);if(e(E?E.matchingString:null),E!==null&&(f||!(function(N,O){return O===0&&N.read("latest",()=>{const M=D();if(F(M)){const R=M.anchor.getNode().getPreviousSibling();return oe(R)&&R.isTextEntity()}return!1})})(d,E.leadOffset))&&(function(O,M,R,$){const L=or(R);if(L===null||!L.isCollapsed)return!1;const A=Pc(L,$),B=A.anchorNode,j=O,U=A.anchorOffset;if(B==null||U==null)return!1;try{M.setStart(B,j),M.setEnd(B,U)}catch{return!1}return!0})(E.leadOffset,v,C,d.getRootElement())!==null)return void S.startTransition(()=>y({getRect:()=>v.getBoundingClientRect(),match:E}));m()})});return()=>{w()}},[d,i,e,g,m,y,f]),S.useEffect(()=>d.registerEditableListener(w=>{w||m()}),[d,m]),g===null||d===null||_.current===null?null:x.jsx(r2,{close:m,resolution:g,editor:d,anchorElementRef:_,options:n,menuRenderFn:s,shouldSplitNodeWithQuery:!0,onSelectOption:t,commandPriority:l,preselectFirstItem:u})}const i2=n=>n.split(/[\s._-]+/).filter(Boolean).slice(0,2).map(e=>e[0].toUpperCase()).join("")||"?";function a2({author:n,size:e}){const t=Jc(n);return n.avatarUrl?x.jsx(ax,{src:n.avatarUrl,size:e,alt:t}):x.jsx(Y,{as:"span","aria-hidden":!0,title:t,sx:{display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,width:e,height:e,borderRadius:"50%",bg:"neutral.muted",color:"fg.muted",fontSize:`${Math.round(e*.45)}px`,fontWeight:"bold"},children:n.kind==="anonymous"?x.jsx(hw,{size:Math.round(e*.65)}):i2(t)})}const jr=S.createContext({}),l2=[],c2=250;function qm(n){const{searchPeople:e}=S.useContext(jr),[t,r]=S.useState(null);return S.useEffect(()=>{if(!e||!n)return;let o=!0;const s=setTimeout(()=>{e(n).then(i=>{o&&r({query:n,people:i})},()=>{o&&r({query:n,people:[]})})},c2);return()=>{o=!1,clearTimeout(s)}},[n,e]),t&&t.query===n?t.people:l2}class u2 extends Wm{person;constructor(e){super(e.uid),this.person=e}}function d2({onMention:n}){const[e]=fe(),{searchPeople:t}=S.useContext(jr),[r,o]=S.useState(null),s=qm(r),i=S.useMemo(()=>s.map(c=>new u2(c)),[s]),a=Hm("@",{minLength:1}),l=S.useCallback((c,u,f)=>{e.update(()=>{const d=De(`@${wo(c.person)} `);u&&u.replace(d),d.select(),f()}),n(c.person)},[e,n]);return t?x.jsx(Jm,{onQueryChange:o,onSelectOption:l,triggerFn:a,options:i,menuRenderFn:(c,{selectedIndex:u,selectOptionAndCleanUp:f,setHighlightedIndex:d})=>c.current&&i.length>0?St.createPortal(x.jsx(Y,{as:"ul",role:"listbox","aria-label":"People to mention",sx:{position:"relative",zIndex:1e3,listStyle:"none",m:0,p:1,bg:"var(--overlay-bgColor)",border:"1px solid",borderColor:"var(--borderColor-default)",borderRadius:2,boxShadow:"var(--shadow-floating-large, 0 0 0 1px #d1d9e0, 0 40px 80px 0 #25292e3d)",minWidth:200},children:i.map((g,h)=>x.jsxs(Y,{as:"li",role:"option","aria-selected":u===h,ref:_=>g.setRefElement(_),onMouseEnter:()=>d(h),onClick:()=>{d(h),f(g)},sx:{px:2,py:1,borderRadius:1,cursor:"pointer",bg:u===h?"actionListItem.default.hoverBg":"transparent"},children:[x.jsx(Le,{children:wo(g.person)}),g.person.handle?x.jsxs(Le,{sx:{color:"var(--fgColor-muted)",ml:1},children:["@",g.person.handle]}):null]},g.key))}),c.current):null}):null}function f2({thread:n}){const{searchPeople:e,assignThread:t}=S.useContext(jr),[r,o]=S.useState(!1),[s,i]=S.useState(""),a=qm(r&&s.trim()?s.trim():null),l=n.assignee??null;if(!t||!e)return l?x.jsxs(Le,{as:"p",sx:{fontSize:0,color:"var(--fgColor-muted)",m:0,mt:1},children:["Assigned to ",wo(l)]}):null;const c=u=>{t(n,u),o(!1),i("")};return x.jsxs(Y,{sx:{mt:1},onClick:u=>u.stopPropagation(),children:[x.jsxs(Y,{sx:{display:"flex",alignItems:"center",gap:1},children:[x.jsx(Le,{sx:{fontSize:0,color:"var(--fgColor-muted)"},children:l?`Assigned to ${wo(l)}`:"Not assigned"}),x.jsx(Ft,{icon:ex,"aria-label":"Assign thread",variant:"invisible",size:"small",onClick:()=>o(!r)}),l?x.jsx(ft,{variant:"invisible",size:"small",onClick:()=>c(null),children:"Unassign"}):null]}),r?x.jsxs(Y,{sx:{mt:1},children:[x.jsx(kn,{"aria-label":"Find a person to assign",placeholder:"Name or handle",size:"small",block:!0,autoFocus:!0,value:s,onChange:u=>i(u.target.value)}),x.jsx(Y,{as:"ul",sx:{listStyle:"none",m:0,p:0,mt:1},children:a.map(u=>x.jsx(Y,{as:"li",children:x.jsx(ft,{variant:"invisible",size:"small",onClick:()=>c(u),children:wo(u)})},u.uid))})]}):null]})}const g2={characterLimit:"JupyterLexicalTheme__characterLimit",code:"JupyterLexicalTheme__code",codeHighlight:{atrule:"JupyterLexicalTheme__tokenAttr",attr:"JupyterLexicalTheme__tokenAttr",boolean:"JupyterLexicalTheme__tokenProperty",builtin:"JupyterLexicalTheme__tokenSelector",cdata:"JupyterLexicalTheme__tokenComment",char:"JupyterLexicalTheme__tokenSelector",class:"JupyterLexicalTheme__tokenFunction","class-name":"JupyterLexicalTheme__tokenFunction",comment:"JupyterLexicalTheme__tokenComment",constant:"JupyterLexicalTheme__tokenProperty",deleted:"JupyterLexicalTheme__tokenProperty",doctype:"JupyterLexicalTheme__tokenComment",entity:"JupyterLexicalTheme__tokenOperator",function:"JupyterLexicalTheme__tokenFunction",important:"JupyterLexicalTheme__tokenVariable",inserted:"JupyterLexicalTheme__tokenSelector",keyword:"JupyterLexicalTheme__tokenAttr",namespace:"JupyterLexicalTheme__tokenVariable",number:"JupyterLexicalTheme__tokenProperty",operator:"JupyterLexicalTheme__tokenOperator",prolog:"JupyterLexicalTheme__tokenComment",property:"JupyterLexicalTheme__tokenProperty",punctuation:"JupyterLexicalTheme__tokenPunctuation",regex:"JupyterLexicalTheme__tokenVariable",selector:"JupyterLexicalTheme__tokenSelector",string:"JupyterLexicalTheme__tokenSelector",symbol:"JupyterLexicalTheme__tokenProperty",tag:"JupyterLexicalTheme__tokenProperty",url:"JupyterLexicalTheme__tokenOperator",variable:"JupyterLexicalTheme__tokenVariable"},embedBlock:{base:"JupyterLexicalTheme__embedBlock",focus:"JupyterLexicalTheme__embedBlockFocus"},hashtag:"JupyterLexicalTheme__hashtag",heading:{h1:"JupyterLexicalTheme__h1",h2:"JupyterLexicalTheme__h2",h3:"JupyterLexicalTheme__h3",h4:"JupyterLexicalTheme__h4",h5:"JupyterLexicalTheme__h5",h6:"JupyterLexicalTheme__h6"},image:"editor-image",link:"JupyterLexicalTheme__link",list:{listitem:"JupyterLexicalTheme__listItem",listitemChecked:"JupyterLexicalTheme__listItemChecked",listitemUnchecked:"JupyterLexicalTheme__listItemUnchecked",nested:{listitem:"JupyterLexicalTheme__nestedListItem"},olDepth:["JupyterLexicalTheme__ol1","JupyterLexicalTheme__ol2","JupyterLexicalTheme__ol3","JupyterLexicalTheme__ol4","JupyterLexicalTheme__ol5"],ul:"JupyterLexicalTheme__ul"},ltr:"JupyterLexicalTheme__ltr",mark:"JupyterLexicalTheme__mark",markOverlap:"JupyterLexicalTheme__markOverlap",layoutContainer:"JupyterLexicalTheme__layoutContainer",layoutItem:"JupyterLexicalTheme__layoutItem",paragraph:"JupyterLexicalTheme__paragraph",quote:"JupyterLexicalTheme__quote",rtl:"JupyterLexicalTheme__rtl",table:"JupyterLexicalTheme__table",tableCell:"JupyterLexicalTheme__tableCell",tableCellHeader:"JupyterLexicalTheme__tableCellHeader",text:{bold:"JupyterLexicalTheme__textBold",code:"JupyterLexicalTheme__textCode",italic:"JupyterLexicalTheme__textItalic",strikethrough:"JupyterLexicalTheme__textStrikethrough",subscript:"JupyterLexicalTheme__textSubscript",superscript:"JupyterLexicalTheme__textSuperscript",underline:"JupyterLexicalTheme__textUnderline",underlineStrikethrough:"JupyterLexicalTheme__textUnderlineStrikethrough"}},p2={...g2,paragraph:"CommentEditorTheme__paragraph"},ys=he();function h2({anchorKey:n,editor:e,onAddComment:t}){const r=S.useRef(null),o=S.useCallback(()=>{const s=r.current,i=e.getRootElement(),a=e.getElementByKey(n);if(s!==null&&i!==null&&a!==null){const{right:l}=i.getBoundingClientRect(),{top:c}=a.getBoundingClientRect();s.style.left=`${l-20}px`,s.style.top=`${c-30}px`}},[n,e]);return S.useEffect(()=>(window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o)}),[e,o]),Yu(()=>{o()},[n,e,o]),x.jsx(Y,{ref:r,sx:{position:"absolute",zIndex:10},children:x.jsx(Ft,{icon:Pi,"aria-label":"Add comment",variant:"invisible",size:"small",onClick:t})})}const Vm=pe({name:"@datalayer/jupyter-lexical/CommentComposer",namespace:"Commenting",theme:p2,dependencies:[Cw,Sh,Sw]}),_2=pe({name:"@datalayer/jupyter-lexical/CommentComposer/Focused",dependencies:[Vm,vw]});function m2({editorRef:n}){const[e]=fe();return Yu(()=>(n.current=e,()=>{n.current=null}),[e,n]),null}function b2({onEscape:n}){const[e]=fe();return S.useEffect(()=>e.registerCommand(Nn,t=>n(t),2),[e,n]),null}function Ym({style:n,autoFocus:e,onEscape:t,onChange:r,onMention:o,editorRef:s,placeholder:i="Type a comment..."}){const a=e===!1?Vm:_2;return x.jsx(ww,{extension:a,contentEditable:null,children:x.jsxs(Y,{sx:{position:"relative",m:"10px",borderRadius:2},children:[x.jsx(Ap,{className:"ContentEditable__root",style:n,placeholder:x.jsx(Bh,{children:i}),"aria-placeholder":i}),x.jsx(xw,{onChange:r}),x.jsx(b2,{onEscape:t}),o!==void 0&&x.jsx(d2,{onMention:o}),s!==void 0&&x.jsx(m2,{editorRef:s})]})})}function Xm(n,e){return S.useCallback((t,r)=>{t.read(()=>{n(bw()),e(!yw(r.isComposing(),!0))})},[e,n])}const jg=256;function y2({editor:n,cancelAddComment:e,submitAddComment:t}){const[r,o]=S.useState(""),[s,i]=S.useState(!1),[a,l]=S.useState(null),c=S.useRef(null),u=S.useMemo(()=>({container:document.createElement("div"),elements:[]}),[]),f=Zm(),d=S.useCallback(()=>{n.getEditorState().read(()=>{const C=D();if(F(C)){const v=C.anchor,k=C.focus,I=fh(n,v.getNode(),v.offset,k.getNode(),k.offset);if(I!==null){const{left:E,bottom:N,width:O}=I.getBoundingClientRect(),M=Ml(n,I);let R=M.length===1?E+O/2-jg/2:E-jg/2;R<10&&(R=10),l({left:R,top:N+20});const $=M.length,{container:L}=u,A=u.elements,B=A.length;for(let j=0;j<$;j++){const U=M[j];let z=A[j];z===void 0&&(z=document.createElement("span"),A[j]=z,L.appendChild(z));const H=`position:absolute;top:${U.top}px;left:${U.left}px;height:${U.height}px;width:${U.width}px;background-color:var(--bgColor-attention-muted, rgba(255, 212, 0, 0.3));pointer-events:none;z-index:5;`;z.style.cssText=H}for(let j=B-1;j>=$;j--){const U=A[j];L.removeChild(U),A.pop()}}}})},[n,u]);Yu(()=>{c.current=n.getRootElement(),d();const C=u.container,v=document.body;if(v!==null)return v.appendChild(C),()=>{v.removeChild(C)}},[n,u.container,d]),S.useEffect(()=>(window.addEventListener("resize",d),()=>{window.removeEventListener("resize",d)}),[d]);const g=C=>(C.preventDefault(),e(),!0),h=S.useRef(new Map),_=S.useCallback(C=>{h.current.set(C.uid,C)},[]),m=()=>{if(s){let C=n.getEditorState().read(()=>{const v=D();return v!==null?v.getTextContent():""});C.length>100&&(C=C.slice(0,99)+"…"),t(Px(C,[Ph(r,f,void 0,void 0,void 0,$h(r,h.current.values()))]),!0)}},y=Xm(o,i),w=C=>{const v=C.target;v instanceof HTMLElement&&v.closest('[role="listbox"]')||e()};return a===null?null:x.jsxs(kl,{role:"dialog","aria-label":"Add a comment",width:"small",position:"fixed",left:a.left,top:a.top,onEscape:e,onClickOutside:w,returnFocusRef:c,preventFocusOnOpen:!0,children:[x.jsx(Ym,{style:{position:"relative",border:"1px solid var(--borderColor-default)",backgroundColor:"var(--bgColor-default)",borderRadius:"6px",fontSize:"15px",caretColor:"var(--fgColor-default)",display:"block",padding:"9px 10px 10px 9px",minHeight:"80px"},onEscape:g,onChange:y,onMention:_}),x.jsxs(Y,{sx:{display:"flex",gap:2,justifyContent:"flex-end",mt:2,px:2,pb:2},children:[x.jsx(ft,{onClick:e,variant:"invisible",size:"small",children:"Cancel"}),x.jsx(ft,{onClick:m,disabled:!s,variant:"primary",size:"small",children:"Comment"})]})]})}function w2({submitAddComment:n,thread:e,placeholder:t}){const[r,o]=S.useState(""),[s,i]=S.useState(!1),a=S.useRef(null),l=Zm(),c=S.useRef(new Map),u=S.useCallback(g=>{c.current.set(g.uid,g)},[]),f=Xm(o,i),d=()=>{if(s){n(Ph(r,l,void 0,void 0,void 0,$h(r,c.current.values())),!1,e),c.current.clear();const g=a.current;g!==null&&g.dispatchCommand(Tw,void 0)}};return x.jsxs(x.Fragment,{children:[x.jsx(Ym,{style:{position:"relative",border:"1px solid",borderColor:"var(--borderColor-default, #ccc)",backgroundColor:"var(--bgColor-default, #fff)",borderRadius:"6px",fontSize:"15px",caretColor:"var(--fgColor-default)",display:"block",padding:"9px 10px 10px 9px",minHeight:"20px"},autoFocus:!1,onEscape:()=>!0,onChange:f,onMention:u,editorRef:a,placeholder:t}),x.jsx(Ft,{icon:kw,"aria-label":"Send comment",variant:"invisible",size:"small",onClick:d,disabled:!s})]})}function Gm({commentOrThread:n,deleteCommentOrThread:e,onClose:t,thread:r=void 0}){return x.jsxs(x.Fragment,{children:["Are you sure you want to delete this ",n.type,"?",x.jsxs(Y,{sx:{display:"flex",gap:2,justifyContent:"flex-end",mt:3},children:[x.jsx(ft,{variant:"invisible",onClick:()=>{t()},children:"Cancel"}),x.jsx(ft,{variant:"danger",onClick:()=>{e(n,r),t()},children:"Delete"})]})]})}function x2(n,e){const t=Math.round((e-Date.now())/1e3);if(t>-10)return"Just now";const r=Math.round(t/60);if(r>-60)return n.format(r,"minute");const o=Math.round(r/60);return o>-24?n.format(o,"hour"):n.format(Math.round(o/24),"day")}function Fg({comment:n,deleteComment:e,thread:t,rtf:r}){const[o,s]=Xo(),{Avatar:i=a2}=S.useContext(jr),a=Dx(n);return x.jsxs(Y,{as:"li",sx:{p:2,borderBottom:"1px solid",borderColor:"var(--borderColor-muted)"},children:[x.jsxs(Y,{sx:{display:"flex",alignItems:"center",gap:1,mb:1},children:[x.jsx(i,{author:a,size:20}),x.jsx(Le,{sx:{fontWeight:"bold",fontSize:1},children:Jc(a)}),a.agentUid&&x.jsx(Le,{sx:{color:"var(--fgColor-muted)",fontSize:0},children:"· with an agent"}),x.jsxs(Le,{sx:{color:"var(--fgColor-muted)",fontSize:0},children:["· ",x2(r,n.timeStamp)]})]}),x.jsx(Le,{as:"p",sx:{fontSize:1,m:0,...n.deleted?{color:"var(--fgColor-muted)",fontStyle:"italic"}:{}},children:n.content}),!n.deleted&&x.jsxs(x.Fragment,{children:[x.jsx(Ft,{icon:Ch,"aria-label":"Delete comment",variant:"invisible",size:"small",sx:{color:"var(--fgColor-danger)",mt:1},onClick:()=>{s("Delete Comment",l=>x.jsx(Gm,{commentOrThread:n,deleteCommentOrThread:e,thread:t,onClose:l}))}}),o]})]})}function C2({activeIDs:n,comments:e,deleteCommentOrThread:t,listRef:r,submitAddComment:o,markNodeMap:s,resolveThread:i}){const[a]=fe(),[l,c]=S.useState(0),[u,f]=Xo(),d=S.useMemo(()=>new Intl.RelativeTimeFormat("en",{localeMatcher:"best fit",numeric:"auto",style:"short"}),[]);return S.useEffect(()=>{const g=setTimeout(()=>{c(l+1)},1e4);return()=>{clearTimeout(g)}},[l]),x.jsx(Y,{as:"ul",ref:r,sx:{listStyle:"none",m:0,p:0},children:e.map(g=>{const h=g.id;if(g.type==="thread"){const _=()=>{const m=s.get(h);if(m!==void 0&&(n===null||n.indexOf(h)===-1)){const y=document.activeElement;a.update(()=>{const w=Array.from(m)[0],C=Q(w);Ro(C)&&C.selectStart()},{onUpdate(){y!==null&&y.focus()}})}};return x.jsxs(Y,{as:"li",onClick:_,sx:{p:2,borderBottom:"1px solid",borderColor:"var(--borderColor-muted)",cursor:s.has(h)?"pointer":"default",bg:n.indexOf(h)===-1?"var(--bgColor-default)":"var(--bgColor-accent-muted)","&:hover":s.has(h)?{bg:"var(--bgColor-muted)"}:{}},children:[x.jsxs(Y,{sx:{display:"flex",alignItems:"flex-start",gap:2},children:[x.jsxs(Y,{as:"blockquote",sx:{flex:1,m:0,pl:2,borderLeft:"3px solid",borderColor:"var(--bgColor-accent-muted)",color:"var(--fgColor-muted)",fontSize:1},children:["> ",x.jsx("span",{children:g.quote})]}),i&&x.jsx(Ft,{icon:xh,"aria-label":"Resolve thread",variant:"invisible",size:"small",onClick:m=>{m.stopPropagation(),i(g)}}),x.jsx(Ft,{icon:Ch,"aria-label":"Delete thread",variant:"invisible",size:"small",sx:{color:"var(--fgColor-danger)"},onClick:()=>{f("Delete Thread",m=>x.jsx(Gm,{commentOrThread:g,deleteCommentOrThread:t,onClose:m}))}}),u]}),x.jsx(f2,{thread:g}),x.jsx(Y,{as:"ul",sx:{listStyle:"none",m:0,p:0,mt:2},children:g.comments.map(m=>x.jsx(Fg,{comment:m,deleteComment:t,thread:g,rtf:d},m.id))}),x.jsx(Y,{sx:{mt:2},children:x.jsx(w2,{submitAddComment:o,thread:g,placeholder:"Reply to comment..."})})]},h)}return x.jsx(Fg,{comment:g,deleteComment:t,rtf:d},h)})})}function S2({activeIDs:n,deleteCommentOrThread:e,comments:t,submitAddComment:r,markNodeMap:o,resolveThread:s}){const i=S.useRef(null),a=t.length===0;return x.jsxs(Y,{sx:{bg:"var(--bgColor-default)",borderRadius:2,overflow:"hidden",width:"100%",flex:1,display:"flex",flexDirection:"column"},children:[x.jsx(mw,{as:"h2",sx:{fontSize:2,p:3,borderBottom:"1px solid",borderColor:"var(--borderColor-muted)",m:0},children:"Comments"}),a?x.jsx(Y,{sx:{p:3,color:"var(--fgColor-muted)",textAlign:"center"},children:"No Comments"}):x.jsx(C2,{activeIDs:n,comments:t,deleteCommentOrThread:e,listRef:i,submitAddComment:r,markNodeMap:o,resolveThread:s})]})}function Zm(){const{author:n}=S.useContext(jr),{name:e}=Lm();return n??qc(e)}function VM({providerFactory:n,showFloatingAddButton:e=!0,commentStore:t,author:r,Avatar:o}){const[s]=fe(),{showComments:i,setShowComments:a}=e_(),l=S.useRef(null),c=S.useRef(null),u=S.useMemo(()=>t??new Bx(s),[s,t]),f=Ux(u),d=S.useMemo(()=>new Map,[]),[g,h]=S.useState(),[_,m]=S.useState([]),[y,w]=S.useState(!1),C=S.useCallback(R=>{a(typeof R=="function"?R(i):R)},[a,i]),v=S.useCallback(()=>{s.update(()=>{const R=D();R!==null&&(R.dirty=!0)}),w(!1)},[s]),k=S.useCallback(R=>{const $=d.get(R);$!==void 0&&setTimeout(()=>{s.update(()=>{for(const L of $){const A=Q(L);Ro(A)&&(A.deleteID(R),A.getIDs().length===0&&Ox(A))}})})},[s,d]),I=S.useCallback((R,$)=>{R.type==="comment"?u.deleteComment(R,$):(u.deleteThread(R),k($!==void 0?$.id:R.id))},[u,k]),E=S.useMemo(()=>{if(u.resolveThread)return R=>{u.resolveThread?.(R),k(R.id)}},[u,k]),N=S.useCallback((R,$,L)=>{u.addComment(R,L),$&&(s.update(()=>{const A=D();if(F(A)){const B=A.focus,j=A.anchor,U=A.isBackward(),z=R.id;Rx(A,U,z),U?B.set(j.key,j.offset,j.type):j.set(B.key,B.offset,B.type)}}),w(!1))},[u,s]);S.useEffect(()=>{const R=[];for(let $=0;$<_.length;$++){const L=_[$],A=d.get(L);if(A!==void 0)for(const B of A){const j=s.getElementByKey(B);j!==null&&(j.classList.add("selected"),R.push(j),a(!0))}}return()=>{for(let $=0;$<R.length;$++)R[$].classList.remove("selected")}},[_,s,d]),S.useEffect(()=>{const R=new Map;return de(_w(s,Ts,$=>Hc($.getIDs()),($,L)=>{$.getIDs().forEach(B=>{L.addID(B)})}),s.registerMutationListener(Ts,$=>{s.getEditorState().read(()=>{for(const[L,A]of $){const B=Q(L);let j=[];A==="destroyed"?j=R.get(L)||[]:Ro(B)&&(j=B.getIDs());for(let U=0;U<j.length;U++){const z=j[U];let K=d.get(z);R.set(L,j),A==="destroyed"?K!==void 0&&(K.delete(L),K.size===0&&d.delete(z)):(K===void 0&&(K=new Set,d.set(z,K)),K.has(L)||K.add(L))}}})}),s.registerUpdateListener(({editorState:$,tags:L})=>{$.read(()=>{const A=D();let B=!1,j=!1;if(F(A)){const U=A.anchor.getNode();if(oe(U)){const z=Ax(U,A.anchor.offset);z!==null&&(m(z),B=!0),A.isCollapsed()||(h(U.getKey()),j=!0)}}B||m(U=>U.length===0?U:[]),j||h(null)}),L.has("collaboration")||w(!1)}),s.registerCommand(ys,()=>{const $=window.getSelection();return $!==null&&$.removeAllRanges(),w(!0),!0},V))},[s,d]);const O=()=>{s.dispatchCommand(ys,void 0)},M=S.useMemo(()=>({searchPeople:u.searchPeople?.bind(u),assignThread:u.assignThread?.bind(u),author:r,Avatar:o}),[u,r,o]);return x.jsxs(jr.Provider,{value:M,children:[y&&x.jsx(jr.Provider,{value:M,children:x.jsx(y2,{editor:s,cancelAddComment:v,submitAddComment:N})}),e&&g!==null&&g!==void 0&&!y&&St.createPortal(x.jsx(h2,{anchorKey:g,editor:s,onAddComment:O}),document.body),x.jsx("button",{ref:l,style:{display:"none"},"aria-hidden":"true"}),x.jsx(vx,{isOpen:i,setIsOpen:C,openButtonRef:l,closeButtonRef:c,direction:"right",width:"350px",content:x.jsx(S2,{comments:f,submitAddComment:N,deleteCommentOrThread:I,activeIDs:_,markNodeMap:d,resolveThread:E})})]})}const Fo=Qe().describe("CSS colour, e.g. '#1e1e1e', '#e03131', 'transparent'"),Qm=Lt({type:wr(["rectangle","ellipse","diamond","text","arrow","line","frame"]).describe("What to draw"),x:We().describe("Left edge, in scene coordinates"),y:We().describe("Top edge, in scene coordinates"),width:We().optional().describe("Width in pixels (shapes only)"),height:We().optional().describe("Height in pixels (shapes only)"),id:Qe().optional().describe("Your own id for this element, so a later arrow can point at it by name. Any string; Excalidraw keeps it."),text:Qe().optional().describe("The text itself, for type 'text'"),label:Qe().optional().describe("Text to put inside the shape. Excalidraw binds it to the shape, so moving the shape moves the label."),fontSize:We().optional().describe("Font size in pixels, e.g. 16, 20, 28"),strokeColor:Fo.optional().describe("Outline colour"),backgroundColor:Fo.optional().describe("Fill colour"),fillStyle:wr(["hachure","cross-hatch","solid"]).optional().describe("How the fill is drawn"),strokeWidth:We().optional().describe("Outline thickness, 1 | 2 | 4"),strokeStyle:wr(["solid","dashed","dotted"]).optional().describe("Outline style"),roughness:We().optional().describe("0 for architect (clean), 1 for artist, 2 for cartoonist"),opacity:We().optional().describe("0-100"),angle:We().optional().describe("Rotation in radians"),startId:Qe().optional().describe("For 'arrow' and 'line': the id of the element the arrow starts at. The arrow stays attached when either element moves."),endId:Qe().optional().describe("For 'arrow' and 'line': the id of the element the arrow points at."),points:yr(yr(We())).optional().describe("For 'arrow' and 'line' without bindings: points relative to x,y, e.g. [[0,0],[120,0]]"),children:yr(Qe()).optional().describe("For 'frame': the ids of the elements it contains"),name:Qe().optional().describe("For 'frame': its name")}),eb=Qe().describe("Where to put the drawing: 'TOP' for the beginning of the document, 'BOTTOM' for the end, or the block_id to insert after"),On=Qe().describe("The block_id of the drawing, from excalidrawListDrawings or readAllBlocks"),tb=Lt({afterId:eb,elements:yr(Qm).optional().describe("The drawing itself. Omit to insert an empty canvas for a person to draw on."),width:We().optional().describe("Rendered width in pixels. Omit to size to the content."),height:We().optional().describe("Rendered height in pixels. Omit to size to the content.")}),nb=Lt({}),rb=Lt({blockId:On,detail:wr(["summary","full"]).optional().describe("'summary' (default) gives each element's id, type, position, size and text — enough to change it. 'full' gives the raw Excalidraw elements, which is large; ask for it only when you need a field the summary omits.")}),ob=Lt({blockId:On,elements:yr(Qm).describe("The elements to add. Existing elements are left alone.")}),sb=Lt({blockId:On,updates:yr(Lt({id:Qe().describe("The element id, from excalidrawReadScene"),x:We().optional(),y:We().optional(),width:We().optional(),height:We().optional(),text:Qe().optional().describe("New text. On a shape this rewrites the label bound inside it; on a 'text' element it rewrites the element."),strokeColor:Fo.optional(),backgroundColor:Fo.optional(),fillStyle:wr(["hachure","cross-hatch","solid"]).optional(),strokeWidth:We().optional(),strokeStyle:wr(["solid","dashed","dotted"]).optional(),opacity:We().optional().describe("0-100"),angle:We().optional().describe("Rotation in radians")})).describe("One entry per element to change. Fields left out are kept.")}),ib=Lt({blockId:On,elementIds:yr(Qe()).describe("The ids to remove, from excalidrawReadScene")}),ab=Lt({blockId:On,fromId:Qe().describe("The element the arrow starts at"),toId:Qe().describe("The element the arrow points at"),label:Qe().optional().describe('Text to sit on the arrow, e.g. "yes", "then"'),strokeColor:Fo.optional(),strokeStyle:wr(["solid","dashed","dotted"]).optional()}),lb=Lt({blockId:On,viewBackgroundColor:Fo.optional().describe("The canvas colour behind the drawing"),gridSize:We().optional().describe("Grid spacing in pixels. 0 turns the grid off.")}),cb=Lt({blockId:On,width:We().optional().describe("Rendered width in pixels. Omit to go back to sizing by content."),height:We().optional().describe("Rendered height in pixels. Omit to go back to sizing by content.")}),ub=Lt({blockId:On}),db=Lt({blockId:On.optional().describe("The drawing to replace. Omit to insert a new drawing instead, positioned by afterId."),afterId:eb.optional().describe("Where a new drawing goes: 'TOP', 'BOTTOM', or a block_id. Ignored when blockId is given."),mermaid:Qe().describe("Mermaid source. Flowcharts, sequence diagrams and class diagrams convert to real shapes; anything else comes across as an image."),fontSize:We().optional().describe("Font size for the generated text, in pixels")}),Qt=n=>`datalayer_${n}`,Qr={requiresConfirmation:!1,canBeReferencedInPrompt:!0,priority:"medium"},en=["lexical","excalidraw","drawing","diagram"],v2={name:Qt("excalidrawInsertNode"),displayName:"Insert Drawing",toolReferenceName:"excalidrawInsertNode",description:"Insert an Excalidraw drawing into the Lexical document, optionally with its contents. This is how you draw a diagram: give the elements you want and they are laid out as you place them, in scene coordinates where x grows right and y grows down. Give a shape an `id` and a later arrow can bind to it with `startId`/`endId`, so the arrow follows the shape when it moves. Put text on a shape with `label` rather than positioning a separate text element on top of it. Returns the new block_id — keep it, every other excalidraw tool needs it. Omit `elements` to insert an empty canvas for a person to draw on themselves.",parameters:Zt(tb),operation:"excalidrawInsertNode",config:{confirmationMessage:n=>`Insert a drawing of ${n.elements?.length??0} element(s)?`,invocationMessage:()=>"Drawing in the lexical document",requiresConfirmation:!0,canBeReferencedInPrompt:!0,priority:"high"},tags:[...en,"insert"]},k2={name:Qt("excalidrawListDrawings"),displayName:"List Drawings",toolReferenceName:"excalidrawListDrawings",description:'List the Excalidraw drawings in the open Lexical document, with the block_id of each and a one-line description of what it holds. Call this first when asked to change "the diagram" and you do not already know its block_id.',parameters:Zt(nb),operation:"excalidrawListDrawings",config:{...Qr,invocationMessage:()=>"Looking for drawings"},tags:[...en,"read"]},T2={name:Qt("excalidrawReadScene"),displayName:"Read Drawing",toolReferenceName:"excalidrawReadScene",description:"Read what is inside one drawing: every element with its id, type, position, size and text. The element ids are the only way to address a shape, so read the scene before updating, deleting or connecting anything. The default 'summary' detail is what you want; 'full' returns the raw Excalidraw elements and is large.",parameters:Zt(rb),operation:"excalidrawReadScene",config:{...Qr,invocationMessage:()=>"Reading the drawing"},tags:[...en,"read"]},I2={name:Qt("excalidrawAddElements"),displayName:"Add to Drawing",toolReferenceName:"excalidrawAddElements",description:"Add elements to a drawing that already exists, leaving what is there alone. Same element format as excalidrawInsertNode. To attach a new arrow to a shape already in the drawing, pass that shape's existing element id as `startId` or `endId`. Read the scene first if you need to know where there is room.",parameters:Zt(ob),operation:"excalidrawAddElements",config:{...Qr,invocationMessage:()=>"Adding to the drawing",priority:"high"},tags:[...en,"edit"]},E2={name:Qt("excalidrawUpdateElements"),displayName:"Update Drawing Elements",toolReferenceName:"excalidrawUpdateElements",description:"Change elements already in a drawing — move them, resize them, recolour them, or rewrite their text. Address each one by the element id from excalidrawReadScene. Fields you leave out are kept as they are. Setting `text` on a shape rewrites the label bound inside it rather than replacing the shape.",parameters:Zt(sb),operation:"excalidrawUpdateElements",config:{...Qr,invocationMessage:()=>"Changing the drawing"},tags:[...en,"edit"]},N2={name:Qt("excalidrawDeleteElements"),displayName:"Delete Drawing Elements",toolReferenceName:"excalidrawDeleteElements",description:"Remove elements from a drawing by their element ids. Deleting a shape also removes the text bound inside it and detaches any arrows that pointed at it, so the drawing stays consistent.",parameters:Zt(ib),operation:"excalidrawDeleteElements",config:{confirmationMessage:n=>`Delete ${n.elementIds?.length??0} element(s) from the drawing?`,invocationMessage:()=>"Removing from the drawing",requiresConfirmation:!0,canBeReferencedInPrompt:!0,priority:"medium"},tags:[...en,"edit","delete"]},L2={name:Qt("excalidrawConnectElements"),displayName:"Connect Drawing Elements",toolReferenceName:"excalidrawConnectElements",description:"Draw an arrow from one element to another and bind it to both, so it follows them when either moves. Excalidraw works out where the arrow should meet each shape. Use this rather than adding an arrow with hand-computed points whenever both ends are existing shapes.",parameters:Zt(ab),operation:"excalidrawConnectElements",config:{...Qr,invocationMessage:()=>"Connecting two shapes"},tags:[...en,"edit"]},O2={name:Qt("excalidrawSetAppState"),displayName:"Set Drawing Canvas",toolReferenceName:"excalidrawSetAppState",description:"Set the canvas behind a drawing: its background colour and its grid. This is about the canvas, not the shapes on it — use excalidrawUpdateElements to recolour a shape.",parameters:Zt(lb),operation:"excalidrawSetAppState",config:{...Qr,invocationMessage:()=>"Setting up the canvas"},tags:[...en,"edit"]},R2={name:Qt("excalidrawResize"),displayName:"Resize Drawing",toolReferenceName:"excalidrawResize",description:"Set how large the drawing is rendered in the document. This scales the picture on the page; it does not move or resize anything inside it. Omit width and height to go back to sizing by content.",parameters:Zt(cb),operation:"excalidrawResize",config:{...Qr,invocationMessage:()=>"Resizing the drawing"},tags:[...en,"edit"]},A2={name:Qt("excalidrawClearScene"),displayName:"Clear Drawing",toolReferenceName:"excalidrawClearScene",description:"Empty a drawing, keeping the block so it can be drawn into again. To remove the drawing from the document altogether, use deleteBlocks with its block_id.",parameters:Zt(ub),operation:"excalidrawClearScene",config:{confirmationMessage:()=>"Empty this drawing?",invocationMessage:()=>"Emptying the drawing",requiresConfirmation:!0,canBeReferencedInPrompt:!0,priority:"low"},tags:[...en,"edit","delete"]},M2={name:Qt("excalidrawFromMermaid"),displayName:"Draw from Mermaid",toolReferenceName:"excalidrawFromMermaid",description:"Turn Mermaid source into a real Excalidraw drawing — shapes and arrows that can then be moved, recoloured and edited like anything else you drew. This is the fastest way to produce a flowchart, sequence diagram or class diagram: write the Mermaid and let the layout be worked out for you, rather than placing boxes by hand. Give blockId to replace an existing drawing, or afterId to insert a new one.",parameters:Zt(db),operation:"excalidrawFromMermaid",config:{confirmationMessage:n=>n.blockId?"Replace this drawing with the Mermaid diagram?":"Insert the Mermaid diagram as a drawing?",invocationMessage:()=>"Drawing the Mermaid diagram",requiresConfirmation:!0,canBeReferencedInPrompt:!0,priority:"high"},tags:[...en,"insert","mermaid"]},fb=[v2,M2,k2,T2,I2,E2,L2,N2,O2,R2,A2],hl=()=>({elements:[],appState:{},files:{}});function Gu(n){if(!n)return hl();let e;try{e=JSON.parse(n)}catch{return hl()}if(Array.isArray(e))return{elements:e,appState:{},files:{}};if(!e||typeof e!="object")return hl();const t=e;return{elements:Array.isArray(t.elements)?t.elements:[],appState:t.appState??{},files:t.files??{}}}function Zu(n){return JSON.stringify({elements:n.elements,appState:n.appState,files:n.files})}const Gs=n=>n.elements.filter(e=>!e?.isDeleted);function $2(n){const e={id:String(n?.id??""),type:String(n?.type??"unknown"),x:Number(n?.x??0),y:Number(n?.y??0),width:Number(n?.width??0),height:Number(n?.height??0)};return typeof n?.text=="string"&&n.text.length>0&&(e.text=n.text),n?.strokeColor&&(e.strokeColor=String(n.strokeColor)),n?.backgroundColor&&(e.backgroundColor=String(n.backgroundColor)),n?.containerId&&(e.containerId=String(n.containerId)),n?.startBinding?.elementId&&(e.startBoundElementId=String(n.startBinding.elementId)),n?.endBinding?.elementId&&(e.endBoundElementId=String(n.endBinding.elementId)),Array.isArray(n?.groupIds)&&n.groupIds.length>0&&(e.groupIds=n.groupIds.map(String)),e}function D2(n){const e=new Map;for(const t of n)t?.type==="text"&&t?.containerId&&t?.text&&e.set(String(t.containerId),String(t.text));return n.map(t=>{const r=$2(t);if(r.text===void 0){const o=e.get(r.id);o&&(r.text=o)}return r})}function Qu(n){const e=Gs(n);if(e.length===0)return"empty drawing";const t=new Map,r=[];for(const i of e){const a=String(i?.type??"unknown");if(a==="text"){const l=String(i?.text??"").trim();if(l&&r.push(l),i?.containerId)continue}t.set(a,(t.get(a)??0)+1)}const o=[...t.entries()].sort((i,a)=>a[1]-i[1]||i[0].localeCompare(a[0])).map(([i,a])=>`${a} ${i}${a>1?"s":""}`).join(", "),s=r.slice(0,3).join(", ");return s?`${o}: ${s}`:o}function ed(n){return{...n,version:Number(n?.version??1)+1,versionNonce:Math.floor(Math.random()*2**31),updated:Date.now()}}const Zi=4;function gb(n,e){let t=null,r;if(n.getEditorState().read(()=>{const o=Q(e);o&&(r=o.getType?.(),r==="excalidraw"&&(t=o))}),!t)throw new Error(r?`Block '${e}' is a '${r}', not a drawing. Call excalidrawListDrawings to find the drawings in this document.`:`No block '${e}' in this document. Call excalidrawListDrawings to find the drawings in this document.`);return t}function Rn(n,e){const t=gb(n,e);let r="";return n.getEditorState().read(()=>{r=t.__data??""}),Gu(r)}function eo(n,e,t){const r=Zu(t);return new Promise(o=>{n.update(()=>{const s=Q(e);s?.setData&&s.setData(r)},{onUpdate:()=>o()})})}const _n=(n,e,t)=>({success:!0,blockId:n,elementCount:Gs(e).length,...t});let P2=0;const j2=()=>`dla-${Date.now().toString(36)}-${(P2+=1).toString(36)}`;function F2(n,e){const{label:t,startId:r,endId:o,fontSize:s,text:i,children:a,name:l,...c}=n,u={...c,id:e};return n.type==="text"?(u.text=i??t??"",s&&(u.fontSize=s)):t&&(u.label=s?{text:t,fontSize:s}:{text:t}),(n.type==="arrow"||n.type==="line")&&(r&&(u.start={id:r}),o&&(u.end={id:o})),(n.type==="frame"||n.type==="magicframe")&&(u.children=a??[],l&&(u.name=l)),u}async function td(n,e){const{convertToExcalidrawElements:t}=await me(async()=>{const{convertToExcalidrawElements:i}=await import("./percentages-BXMCSKIN-Cz9igCrb.js").then(a=>a.i);return{convertToExcalidrawElements:i}},[],import.meta.url),r=[],o=n.map(i=>{let a=String(i.id??"").trim();return(!a||e.has(a))&&(a=j2()),e.add(a),r.push(a),F2(i,a)});return{elements:[...t(o,{regenerateIds:!1})],ids:r}}const mc=n=>({x:Number(n.x??0)+Number(n.width??0)/2,y:Number(n.y??0)+Number(n.height??0)/2});function Bg(n,e){const t=mc(n),r=e.x-t.x,o=e.y-t.y;if(r===0&&o===0)return t;const s=Number(n.width??0)/2+Zi,i=Number(n.height??0)/2+Zi,a=Math.min(r===0?1/0:Math.abs(s/r),o===0?1/0:Math.abs(i/o));return{x:t.x+r*a,y:t.y+o*a}}function B2(n,e){const t=Array.isArray(n.boundElements)?[...n.boundElements]:[];return t.some(r=>r?.id===e)||t.push({id:e,type:"arrow"}),ed({...n,boundElements:t})}function pb(n,e,t,r){const o=n.elements.find(c=>c.id===t),s=n.elements.find(c=>c.id===r);if(!o||!s){const c=o?r:t;throw new Error(`No element '${c}' in this drawing. Call excalidrawReadScene to see the element ids it holds.`)}const i=Bg(o,mc(s)),a=Bg(s,mc(o)),l={...e,x:i.x,y:i.y,width:Math.abs(a.x-i.x),height:Math.abs(a.y-i.y),points:[[0,0],[a.x-i.x,a.y-i.y]],startBinding:{elementId:t,focus:0,gap:Zi},endBinding:{elementId:r,focus:0,gap:Zi}};return n.elements=n.elements.map(c=>c.id===t||c.id===r?B2(c,String(e.id)):c),l}const U2=async(n,e)=>{const t=e.elements??[],r=t.length>0?await td(t,new Set):{elements:[],ids:[]},o={elements:r.elements,appState:{},files:{}},s=await n.insertBlock({block_id:"",block_type:"excalidraw",source:"",metadata:{data:Zu(o),width:e.width,height:e.height}},String(e.afterId??"BOTTOM"));if(!s.success||!s.blockId)throw new Error(s.error||"Failed to insert the drawing");return _n(s.blockId,o,{createdIds:r.ids,message:`Drawing inserted with ${r.elements.length} element(s)`})},z2=async n=>{const t=(await n.getBlocks("detailed")).filter(r=>r.block_type==="excalidraw").map(r=>{const o=Gu(r.metadata?.data);return{blockId:r.block_id,elementCount:Gs(o).length,description:Qu(o),width:r.metadata?.width,height:r.metadata?.height}});return{drawings:t,count:t.length}},K2=async(n,e)=>{const t=String(e.blockId),r=Rn(n.editor,t),o=Gs(r);return{blockId:t,elementCount:o.length,elements:e.detail==="full"?o:D2(o),appState:r.appState,description:Qu(r)}},W2=async(n,e)=>{const t=String(e.blockId),r=Rn(n.editor,t),o=new Set(r.elements.map(u=>String(u.id))),s=e.elements??[],i=new Set(s.map(u=>String(u.id??"")).filter(Boolean)),a=new Map,l=s.map((u,f)=>{const{startId:d,endId:g}=u;if((u.type==="arrow"||u.type==="line")&&d&&g&&(!i.has(String(d))||!i.has(String(g)))){a.set(f,{fromId:String(d),toId:String(g)});const{startId:_,endId:m,...y}=u;return y}return u}),c=await td(l,o);r.elements=[...r.elements,...c.elements];for(const[u,f]of a){const d=c.ids[u],g=r.elements.find(h=>h.id===d);if(g){const h=pb(r,g,f.fromId,f.toId);r.elements=r.elements.map(_=>_.id===d?h:_)}}return await eo(n.editor,t,r),_n(t,r,{createdIds:c.ids,message:`Added ${c.elements.length} element(s)`})},H2=async(n,e)=>{const t=String(e.blockId),r=Rn(n.editor,t),o=e.updates??[],s=new Map;for(const l of r.elements)l?.type==="text"&&l?.containerId&&s.set(String(l.containerId),String(l.id));const i=new Map,a=[];for(const l of o){const c=String(l.id),u=r.elements.find(_=>_.id===c);if(!u){a.push(c);continue}const{id:f,text:d,...g}=l,h=u.type!=="text"&&s.get(c);d!==void 0&&(h?i.set(h,{...i.get(h)??{},text:d,originalText:d}):(g.text=d,g.originalText=d)),Object.keys(g).length>0&&i.set(c,{...i.get(c)??{},...g})}if(a.length>0)throw new Error(`No element(s) ${a.map(l=>`'${l}'`).join(", ")} in this drawing. Call excalidrawReadScene to see the element ids it holds.`);return r.elements=r.elements.map(l=>{const c=i.get(String(l.id));return c?ed({...l,...c}):l}),await eo(n.editor,t,r),_n(t,r,{message:`Updated ${o.length} element(s)`})},J2=async(n,e)=>{const t=String(e.blockId),r=Rn(n.editor,t),o=new Set(e.elementIds.map(String)),s=new Set(o);for(const a of r.elements)a?.containerId&&o.has(String(a.containerId))&&s.add(String(a.id));const i=r.elements.length;return r.elements=r.elements.filter(a=>!s.has(String(a.id))).map(a=>{const l={};if(s.has(String(a.startBinding?.elementId))&&(l.startBinding=null),s.has(String(a.endBinding?.elementId))&&(l.endBinding=null),Array.isArray(a.boundElements)){const c=a.boundElements.filter(u=>!s.has(String(u?.id)));c.length!==a.boundElements.length&&(l.boundElements=c)}return Object.keys(l).length>0?ed({...a,...l}):a}),await eo(n.editor,t,r),_n(t,r,{message:`Removed ${i-r.elements.length} element(s)`})},q2=async(n,e)=>{const t=String(e.blockId),r=Rn(n.editor,t),o=String(e.fromId),s=String(e.toId),i=new Set(r.elements.map(d=>String(d.id))),{elements:a,ids:l}=await td([{type:"arrow",x:0,y:0,...e.label?{label:e.label}:{},...e.strokeColor?{strokeColor:e.strokeColor}:{},...e.strokeStyle?{strokeStyle:e.strokeStyle}:{}}],i),c=l[0];r.elements=[...r.elements,...a];const u=r.elements.find(d=>d.id===c),f=pb(r,u,o,s);return r.elements=r.elements.map(d=>d.id===c?f:d),await eo(n.editor,t,r),_n(t,r,{createdIds:[c],message:`Connected '${o}' to '${s}'`})},V2=async(n,e)=>{const t=String(e.blockId),r=Rn(n.editor,t);return e.viewBackgroundColor!==void 0&&(r.appState.viewBackgroundColor=e.viewBackgroundColor),e.gridSize!==void 0&&(r.appState.gridSize=Number(e.gridSize)||null),await eo(n.editor,t,r),_n(t,r,{message:"Canvas updated"})},Y2=async(n,e)=>{const t=String(e.blockId),r=gb(n.editor,t),o=e.width===void 0?"inherit":Number(e.width),s=e.height===void 0?"inherit":Number(e.height);await new Promise(a=>{n.editor.update(()=>{r.setWidth(o),r.setHeight(s)},{onUpdate:()=>a()})});const i=Rn(n.editor,t);return _n(t,i,{message:o==="inherit"&&s==="inherit"?"Drawing sized to its content":`Drawing sized to ${o} x ${s}`})},X2=async(n,e)=>{const t=String(e.blockId),r=Rn(n.editor,t),o=Gs(r).length;return r.elements=[],r.files={},await eo(n.editor,t,r),_n(t,r,{message:`Emptied the drawing (${o} element(s) removed)`})},G2=async(n,e)=>{const{parseMermaidToExcalidraw:t}=await me(async()=>{const{parseMermaidToExcalidraw:c}=await import("./index-D6EjCeXV.js").then(u=>u.an);return{parseMermaidToExcalidraw:c}},[],import.meta.url),{convertToExcalidrawElements:r}=await me(async()=>{const{convertToExcalidrawElements:c}=await import("./percentages-BXMCSKIN-Cz9igCrb.js").then(u=>u.i);return{convertToExcalidrawElements:c}},[],import.meta.url);let o;try{o=await t(String(e.mermaid),{fontSize:e.fontSize?Number(e.fontSize):void 0})}catch(c){const u=c instanceof Error?c.message:String(c);throw new Error(`That Mermaid source did not parse: ${u}. Flowcharts, sequence diagrams and class diagrams are the ones that convert to shapes.`,{cause:c})}const s=[...r(o.elements)],i=o.files??{};if(e.blockId){const c=String(e.blockId),u=Rn(n.editor,c);return u.elements=s,u.files=i,await eo(n.editor,c,u),_n(c,u,{createdIds:s.map(f=>String(f.id)),message:`Drawing replaced with ${s.length} element(s) from Mermaid`})}const a={elements:s,appState:{},files:i},l=await n.insertBlock({block_id:"",block_type:"excalidraw",source:"",metadata:{data:Zu(a)}},String(e.afterId??"BOTTOM"));if(!l.success||!l.blockId)throw new Error(l.error||"Failed to insert the drawing");return _n(l.blockId,a,{createdIds:s.map(c=>String(c.id)),message:`Drawing inserted with ${s.length} element(s) from Mermaid`})},bc={excalidrawInsertNode:U2,excalidrawListDrawings:z2,excalidrawReadScene:K2,excalidrawAddElements:W2,excalidrawUpdateElements:H2,excalidrawDeleteElements:J2,excalidrawConnectElements:q2,excalidrawSetAppState:V2,excalidrawResize:Y2,excalidrawClearScene:X2,excalidrawFromMermaid:G2};function tn(n,e){return{name:n,async execute(t,r){const o=Iw(e,t??{},n);if(!r.documentId)throw new Error(`Document ID is required for ${n}. Ensure the tool execution context includes a valid documentId.`);if(!r.executor)throw new Error(`Executor is required for ${n}. This should be provided by the platform (DefaultExecutor, BridgeExecutor, etc.)`);try{return await r.executor.execute(n,o)}catch(s){const i=s instanceof Error?s.message:String(s);throw new Error(`Failed to run ${n}: ${i}`,{cause:s})}}}}const Z2=tn("excalidrawInsertNode",tb),Q2=tn("excalidrawListDrawings",nb),eL=tn("excalidrawReadScene",rb),tL=tn("excalidrawAddElements",ob),nL=tn("excalidrawUpdateElements",sb),rL=tn("excalidrawDeleteElements",ib),oL=tn("excalidrawConnectElements",ab),sL=tn("excalidrawSetAppState",lb),iL=tn("excalidrawResize",cb),aL=tn("excalidrawClearScene",ub),lL=tn("excalidrawFromMermaid",db),Ei={excalidrawInsertNode:Z2,excalidrawListDrawings:Q2,excalidrawReadScene:eL,excalidrawAddElements:tL,excalidrawUpdateElements:nL,excalidrawDeleteElements:rL,excalidrawConnectElements:oL,excalidrawSetAppState:sL,excalidrawResize:iL,excalidrawClearScene:aL,excalidrawFromMermaid:lL},Ug={name:"excalidraw",definitions:fb,operations:Ei,handlers:bc};function YM(){const n=[];for(const e of fb)Ei[e.operation]||n.push(`${e.name} points at operation '${e.operation}', which does not exist`),e.toolReferenceName.startsWith("excalidraw")||n.push(`${e.name} is not named for the plugin it belongs to`);for(const e of Object.keys(Ei))bc[e]||n.push(`operation '${e}' has no handler`);for(const e of Object.keys(bc))Ei[e]||n.push(`handler '${e}' has no operation`);return n}const cL=S.lazy(()=>me(()=>import("./ExcalidrawModal-DHCo94OE.js"),[],import.meta.url)),nd=he();function uL(){const[n]=fe(),[e,t]=S.useState(!1),o=M0()?.lexicalId;S.useEffect(()=>{if(!n.hasNodes([Yn]))throw new Error("ExcalidrawPlugin: ExcalidrawNode not registered");return n.registerCommand(nd,()=>(t(!0),!0),V)},[n]),S.useEffect(()=>{if(o)return go.getState().registerPluginTools(o,Ug),()=>{go.getState().unregisterPluginTools(o,Ug.name)}},[o]);const s=(l,c,u)=>{n.update(()=>{const f=ju();f.setData(JSON.stringify({elements:l,appState:c,files:u})),Tr([f]),wt(f.getParentOrThrow())&&Fc(f,ne).selectEnd()}),t(!1)},i=()=>{t(!1)},a=()=>{t(!1)};return e?x.jsx(S.Suspense,{fallback:null,children:x.jsx(cL,{initialElements:[],initialAppState:{},initialFiles:{},isShown:e,onSave:s,onDelete:i,onClose:a,closeOnClickOutside:!1})}):null}const dL=S.lazy(()=>me(()=>import("./DeckComponent-D4X-rpbh.js"),[],import.meta.url));function fL(){return{deck:{title:"Untitled deck",template:"datalayer"},slides:[{type:"title",title:"A new slide",meta:"Double-click to edit its specification"}]}}function gL(n){const e=n.getAttribute("data-lexical-deck");if(!e)return null;try{return{node:rd(JSON.parse(e))}}catch{return null}}class Go extends Jo{__spec;static getType(){return"deck"}static clone(e){return new Go(e.__spec,e.__format,e.__key)}static importJSON(e){const t=rd(e.spec);return t.setFormat(e.format),t}exportJSON(){return{...super.exportJSON(),type:"deck",version:1,spec:this.__spec}}static importDOM(){return{div:e=>e.hasAttribute("data-lexical-deck")?{conversion:gL,priority:2}:null}}exportDOM(){const e=document.createElement("div");e.setAttribute("data-lexical-deck",JSON.stringify(this.__spec));const t=document.createElement("p");return t.textContent=this.__spec.deck?.title||"Deck",e.appendChild(t),{element:e}}constructor(e,t,r){super(t,r),this.__spec=e??fL()}getSpec(){return this.getLatest().__spec}setSpec(e){this.getWritable().__spec=e}getTextContent(){return this.__spec.deck?.title||""}updateDOM(){return!1}decorate(e,t){const r=t.theme.embedBlock||{};return x.jsx(S.Suspense,{fallback:null,children:x.jsx(dL,{className:{base:r.base||"",focus:r.focus||""},format:this.__format,nodeKey:this.getKey(),spec:this.__spec})})}isTopLevel(){return!0}}function rd(n){return new Go(n)}function XM(n){return n instanceof Go}const od=he("INSERT_DECK_COMMAND");function pL(n){if(!n.hasNodes([Go]))throw new Error("DeckExtension: DeckNode not registered on editor");return n.registerCommand(od,e=>(sr(rd(e)),!0),V)}const hL=pe({name:"@datalayer/jupyter-lexical/Deck",nodes:()=>[Go],register:pL}),zg="Kept in this page’s memory only: it is lost when the page reloads, and nobody else sees it. Download it to keep it.",hb={position:"relative",width:"100%",aspectRatio:"16 / 9",borderRadius:2,overflow:"hidden",bg:"black"};function _L(n){const e=Math.max(0,Math.floor(n/1e3));return`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`}function mL(n){const e=n.currentTarget;if(Number.isFinite(e.duration))return;const t=()=>{e.removeEventListener("timeupdate",t),e.currentTime=0};e.addEventListener("timeupdate",t),e.currentTime=Number.MAX_SAFE_INTEGER}function bL({recordingId:n,recording:e}){const t=S.useRef(null),[r,o]=S.useState(()=>Date.now());return S.useEffect(()=>{t.current&&(t.current.srcObject=e.preview)},[e.preview]),S.useEffect(()=>{const s=window.setInterval(()=>o(Date.now()),500);return()=>window.clearInterval(s)},[]),x.jsxs(Y,{sx:{display:"grid",gap:2},children:[x.jsx(Y,{sx:hb,children:x.jsx("video",{ref:t,autoPlay:!0,muted:!0,playsInline:!0,style:{width:"100%",height:"100%",objectFit:"contain"}})}),x.jsxs(Y,{sx:{display:"flex",alignItems:"center",gap:2},children:[x.jsx(Y,{"aria-hidden":!0,sx:{width:10,height:10,borderRadius:"50%",bg:"danger.fg"}}),x.jsx(Le,{sx:{fontFamily:"mono"},"aria-live":"off",children:_L(r-e.startedAt)}),x.jsx(ft,{variant:"danger",leadingVisual:Nw,onClick:()=>Vu(n),sx:{ml:"auto"},children:"Stop"})]})]})}function yL({className:n,format:e,nodeKey:t,recordingId:r,recorded:o}){const[s]=fe(),i=Hr(),a=S.useSyncExternalStore($N,()=>DN(r)),l=HN(o,a),[c,u]=S.useState("screen"),[f,d]=S.useState(!0),g=S.useCallback(w=>{s.update(()=>{const C=Q(t);_b(C)&&C.setRecorded(w)})},[s,t]),h=()=>{KN(r,{source:c,microphone:f},()=>g(!0))},_=()=>{WN(r),g(!1)},m=w=>{const C=document.createElement("a");C.href=w.url,C.download=BN(w),C.click()};let y;return a?.status==="recording"?y=x.jsx(bL,{recordingId:r,recording:a}):a?.status==="recorded"?y=x.jsxs(Y,{sx:{display:"grid",gap:2},children:[x.jsx(Y,{sx:hb,children:x.jsx("video",{src:a.url,controls:!0,playsInline:!0,onLoadedMetadata:mL,style:{width:"100%",height:"100%",objectFit:"contain"}})}),x.jsxs(Y,{sx:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:2},children:[x.jsx(Le,{sx:{color:"fg.muted",fontSize:0,flex:"1 1 240px"},children:zg}),x.jsx(ft,{leadingVisual:Ew,onClick:()=>m(a),children:"Download"}),i&&x.jsx(ft,{onClick:_,children:"Record again"})]})]}):l==="lost"?y=x.jsxs(Y,{sx:{display:"grid",gap:2,justifyItems:"start"},children:[x.jsx(Le,{sx:{color:"fg.muted",fontSize:1},children:"The video recorded here is gone: it was kept in the memory of the page that recorded it, and that page has been reloaded or closed."}),i&&x.jsx(ft,{onClick:()=>g(!1),children:"Record a new one"})]}):i?y=x.jsxs(Y,{sx:{display:"grid",gap:2},children:[x.jsxs(Y,{sx:{display:"flex",alignItems:"center",gap:2},children:[x.jsx(Wc,{size:16}),x.jsx(Le,{sx:{fontWeight:"bold"},children:"Video"})]}),x.jsxs(Le,{sx:{color:"fg.muted",fontSize:0},children:["Recorded by this browser, with no account. ",zg]}),jN()?x.jsxs(Y,{sx:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:3},children:[x.jsxs(Aa,{"aria-label":"What to record",size:"small",children:[x.jsx(Aa.Button,{selected:c==="screen",onClick:()=>u("screen"),children:"Screen"}),x.jsx(Aa.Button,{selected:c==="camera",onClick:()=>u("camera"),children:"Camera"})]}),x.jsxs(Mt,{children:[x.jsx(Mp,{checked:f,onChange:w=>d(w.target.checked)}),x.jsx(Mt.Label,{children:"Microphone"})]}),x.jsx(ft,{variant:"primary",onClick:h,children:"Record"})]}):x.jsx(Le,{sx:{color:"danger.fg",fontSize:1},children:"This browser cannot record video."}),a?.status==="failed"&&x.jsx(Le,{role:"alert",sx:{color:"danger.fg",fontSize:1},children:a.message})]}):y=x.jsx(Le,{as:"p",sx:{color:"fg.muted",fontSize:1,m:0},children:"A video goes here."}),x.jsx(Ls,{className:n,format:e,nodeKey:t,children:x.jsx(Y,{"data-lexical-video":l,onFocusCapture:()=>s.update(()=>Ee(null)),sx:{p:l==="recorded"||l==="recording"?0:3,border:"1px dashed",borderColor:l==="recorded"||l==="recording"?"transparent":"border.default",borderRadius:2,bg:l==="recorded"||l==="recording"?"transparent":"canvas.subtle"},children:y})})}class Zn extends Jo{__recordingId;__recorded;static getType(){return"video"}static clone(e){return new Zn(e.__recordingId,e.__recorded,e.__format,e.__key)}static importJSON(e){const t=new Zn(e.recordingId,e.recorded);return t.setFormat(e.format),t}exportJSON(){return{...super.exportJSON(),type:"video",version:1,recordingId:this.__recordingId,recorded:this.__recorded}}exportDOM(){return{element:null}}constructor(e,t=!1,r,o){super(r,o),this.__recordingId=e||PN(),this.__recorded=t}getRecordingId(){return this.getLatest().__recordingId}isRecorded(){return this.getLatest().__recorded}setRecorded(e){this.getWritable().__recorded=e}getTextContent(){return""}updateDOM(){return!1}decorate(e,t){const r=t.theme.embedBlock||{};return x.jsx(yL,{className:{base:r.base||"",focus:r.focus||""},format:this.__format,nodeKey:this.getKey(),recordingId:this.__recordingId,recorded:this.__recorded})}isTopLevel(){return!0}}function wL(){return new Zn}function _b(n){return n instanceof Zn}const sd=he("INSERT_VIDEO_COMMAND");function xL(n){if(!n.hasNodes([Zn]))throw new Error("VideoExtension: VideoNode not registered on editor");return de(n.registerCommand(sd,()=>(sr(wL()),!0),V),n.registerMutationListener(Zn,(e,{prevEditorState:t})=>{for(const[r,o]of e){if(o!=="destroyed")continue;const s=t.read(()=>{const i=Q(r);return _b(i)?i.__recordingId:void 0});s&&Vu(s)}},{skipInitialization:!0}))}const CL=pe({name:"@datalayer/jupyter-lexical/Video",nodes:()=>[Zn],register:xL});function SL({onConfirm:n,onClose:e}){const[t,r]=S.useState("5"),[o,s]=S.useState("5"),i=S.useRef(null),a=()=>{const c=parseInt(t,10),u=parseInt(o,10);c>0&&c<=500&&u>0&&u<=50&&n(c,u)},l=c=>{c.key==="Enter"&&a()};return x.jsx($p,{title:"Insert Table",onClose:()=>e(),width:"small",height:"auto",initialFocusRef:i,footerButtons:[{buttonType:"default",content:"Cancel",onClick:e},{buttonType:"primary",content:"Confirm",onClick:a}],children:x.jsxs(Y,{sx:{display:"flex",flexDirection:"column",gap:3},onKeyDown:l,children:[x.jsxs(Mt,{children:[x.jsx(Mt.Label,{children:"Rows"}),x.jsx(kn,{ref:i,type:"number",min:1,max:500,value:t,onChange:c=>r(c.target.value),block:!0})]}),x.jsxs(Mt,{children:[x.jsx(Mt.Label,{children:"Columns"}),x.jsx(kn,{type:"number",min:1,max:50,value:o,onChange:c=>s(c.target.value),block:!0})]})]})})}const ws=he();function mb(){const[n]=fe(),[e,t]=S.useState(!1);S.useEffect(()=>n.registerCommand(ws,()=>(t(!0),!0),V),[n]);const r=(s,i)=>{n.dispatchCommand(nu,{rows:s.toString(),columns:i.toString()}),t(!1)},o=()=>{t(!1)};return e?x.jsx(SL,{onConfirm:r,onClose:o}):null}function GM(){return x.jsxs(x.Fragment,{children:[x.jsx(P_,{}),x.jsx(mb,{})]})}const id=he("INSERT_EQUATION_COMMAND");function bb(n){if(!n.hasNodes([ir]))throw new Error("EquationsPlugins: EquationsNode not registered on editor");return n.registerCommand(id,e=>{const{equation:t,inline:r}=e,o=ya(t,r);return Tr([o]),wt(o.getParentOrThrow())&&Fc(o,ne).selectEnd(),!0},V)}const yb=pe({name:"@datalayer/jupyter-lexical/Equations",nodes:()=>[ir],register:bb});function ad({activeEditor:n,onClose:e}){const t=S.useCallback((r,o)=>{n.dispatchCommand(id,{equation:r,inline:o}),e()},[n,e]);return x.jsx(Vx,{onConfirm:t})}const Kg=()=>{const[n]=fe();return S.useEffect(()=>bb(n),[n]),null},vL=Object.freeze(Object.defineProperty({__proto__:null,EquationsPlugin:Kg,INSERT_EQUATION_COMMAND:id,InsertEquationDialog:ad,default:Kg},Symbol.toStringTag,{value:"Module"}));class Ke extends Wm{title;icon;keywords;keyboardShortcut;onSelect;disabled;constructor(e,t){super(e),this.title=e,this.keywords=t.keywords||[],this.icon=t.icon,this.keyboardShortcut=t.keyboardShortcut,this.onSelect=t.onSelect.bind(this),this.disabled=t.disabled||!1}}function kL({index:n,isSelected:e,onClick:t,onMouseEnter:r,option:o}){const s=S.useCallback(l=>o.setRefElement(l),[o]),i=o.disabled?void 0:t,a=o.disabled?void 0:r;return x.jsxs(Y,{as:"li",tabIndex:-1,ref:s,role:"option","aria-selected":e&&!o.disabled,"aria-disabled":o.disabled,id:"typeahead-item-"+n,onMouseEnter:a,onClick:i,sx:{display:"flex",alignItems:"center",gap:2,px:2,py:"6px",borderRadius:2,cursor:o.disabled?"not-allowed":"pointer",opacity:o.disabled?.5:1,bg:e&&!o.disabled?"actionListItem.default.selectedBg":"transparent",color:"var(--fgColor-default)","&:hover":o.disabled?{}:{bg:"actionListItem.default.hoverBg"},listStyle:"none"},children:[x.jsx(Y,{sx:{display:"flex",alignItems:"center",color:"var(--fgColor-muted)",flexShrink:0},children:o.icon}),x.jsx(Le,{sx:{fontSize:1},children:o.title})]},o.key)}const TL=({kernel:n,initCode:e=""}={})=>{const[t]=fe(),[r,o]=Xo(),[s,i]=S.useState(null),a=Hm("/",{minLength:0}),l=S.useCallback(()=>{const f=[];if(s==null)return f;const d=new RegExp(/^([1-9]|10)x([1-9]|10)$/),g=new RegExp(/^([1-9]|10)x?$/),h=d.exec(s),_=g.exec(s);if(h){const[m,y]=h[0].split("x").map(w=>parseInt(w,10));f.push(new Ke(`${m}x${y} Table`,{icon:x.jsx(yi,{size:16}),keywords:["table"],onSelect:()=>t.dispatchCommand(ws,void 0)}))}else if(_){const m=parseInt(_[0],10);f.push(...Array.from({length:5},(y,w)=>w+1).map(y=>new Ke(`${m}x${y} Table`,{icon:x.jsx(yi,{size:16}),keywords:["table"],onSelect:()=>t.dispatchCommand(ws,void 0)})))}return f},[t,s]),c=S.useMemo(()=>{const f=[new Ke("Jupyter Cell",{icon:x.jsx(br,{size:16}),keywords:["javascript","python","js","codeblock","jupyter"],onSelect:()=>{t.dispatchCommand(Vi,{code:e,outputs:ac,loading:"Loading..."})}}),new Ke("Marimo Cell",{icon:x.jsx(br,{size:16}),keywords:["marimo","reactive","python","cell"],onSelect:()=>{t.dispatchCommand(Vi,{code:e,outputs:ac,loading:"Loading...",variant:"marimo"})}}),new Ke("Paragraph",{icon:x.jsx(Ih,{size:16}),keywords:["normal","paragraph","p","text"],onSelect:()=>t.update(()=>{const g=D();F(g)&&Un(g,()=>ne())})}),...Array.from({length:3},(g,h)=>h+1).map(g=>new Ke(`Heading ${g}`,{icon:x.jsx(tx,{size:16}),keywords:["heading","header",`h${g}`],onSelect:()=>t.update(()=>{const h=D();F(h)&&Un(h,()=>fn(`h${g}`))})})),new Ke("Numbered List",{icon:x.jsx(Eh,{size:16}),keywords:["numbered list","ordered list","ol"],onSelect:()=>t.dispatchCommand(eu,void 0)}),new Ke("Bulleted List",{icon:x.jsx(vh,{size:16}),keywords:["bulleted list","unordered list","ul"],onSelect:()=>t.dispatchCommand(Qc,void 0)}),new Ke("Check List",{icon:x.jsx(Lw,{size:16}),keywords:["check list","todo list"],onSelect:()=>t.dispatchCommand(Zc,void 0)}),new Ke("Table",{icon:x.jsx(yi,{size:16}),keywords:["table","grid","spreadsheet"],onSelect:()=>{ge("[ComponentPicker] Table selected, dispatching INSERT_TABLE_WITH_DIALOG_COMMAND"),t.dispatchCommand(ws,void 0)}}),new Ke("Collapsible Container",{icon:x.jsx(zc,{size:16}),keywords:["collapsible","collapse","expand","toggle","accordion","container"],onSelect:()=>t.dispatchCommand(Xu,void 0)}),new Ke("Excalidraw",{icon:x.jsx(Ow,{size:16}),keywords:["excalidraw","drawing","diagram","sketch","whiteboard","draw"],onSelect:()=>t.dispatchCommand(nd,void 0)}),new Ke("Video",{icon:x.jsx(Wc,{size:16}),keywords:["video","record","recording","screen","camera","webcam"],onSelect:()=>t.dispatchCommand(sd,void 0)}),new Ke("Loom Video",{icon:x.jsx(Ws,{size:16}),keywords:["loom","video","record","recording","screen"],onSelect:()=>t.dispatchCommand(ka,void 0)}),new Ke("Deck Slide",{icon:x.jsx(hs,{size:16}),keywords:["deck","slide","slides","presentation","pitch"],onSelect:()=>t.dispatchCommand(od,void 0)}),new Ke("Quote",{icon:x.jsx(Nh,{size:16}),keywords:["block quote"],onSelect:()=>t.update(()=>{const g=D();F(g)&&Un(g,()=>Ln())})}),new Ke("Code",{icon:x.jsx(br,{size:16}),keywords:["javascript","python","js","codeblock"],onSelect:()=>t.update(()=>{const g=D();if(F(g))if(g.isCollapsed())Un(g,()=>Ze());else{const h=g.getTextContent(),_=Ze();g.insertNodes([_]),g.insertRawText(h)}})}),new Ke("Divider",{icon:x.jsx(ji,{size:16}),keywords:["horizontal rule","divider","hr"],onSelect:()=>t.dispatchCommand(Kc,void 0)}),...qu.map(g=>new Ke(`Embed ${g.contentName}`,{icon:g.icon,keywords:[...g.keywords,"embed"],onSelect:()=>t.dispatchCommand(Ju,g.type)})),new Ke("Equation",{icon:x.jsx(Rw,{size:16}),keywords:["equation","latex","math"],onSelect:()=>o("Insert Equation",g=>x.jsx(ad,{activeEditor:t,onClose:g}))}),new Ke("GIF",{icon:x.jsx(hs,{size:16}),keywords:["gif","animate","image","file"],onSelect:()=>{yu().then(g=>{g&&t.dispatchCommand(Ys,g)})}}),new Ke("Image",{icon:x.jsx(hs,{size:16}),keywords:["image","photo","picture","file"],onSelect:()=>o("Insert Image",g=>x.jsx(z_,{activeEditor:t,onClose:g}))}),...["left","center","right","justify"].map(g=>new Ke(`Align ${g}`,{icon:g==="left"?x.jsx(nx,{size:16}):g==="right"?x.jsx(rx,{size:16}):x.jsx(ji,{size:16}),keywords:["align","justify",g],onSelect:()=>t.dispatchCommand(Bn,g)}))],d=l();return s?[...d,...f.filter(g=>new RegExp(s,"gi").exec(g.title)||g.keywords!=null?g.keywords.some(h=>new RegExp(s,"gi").exec(h)):!1)]:f},[t,l,s,o,n,e]),u=S.useCallback((f,d,g,h)=>{f.disabled||t.update(()=>{d&&d.remove(),f.onSelect(h),g()})},[t]);return x.jsxs(x.Fragment,{children:[r,x.jsx(Jm,{onQueryChange:i,onSelectOption:u,triggerFn:a,options:c,menuRenderFn:(f,{selectedIndex:d,selectOptionAndCleanUp:g,setHighlightedIndex:h})=>f.current&&c.length?St.createPortal(x.jsx(Y,{onMouseDown:_=>{_.preventDefault()},sx:{position:"relative",zIndex:1e3,bg:"var(--overlay-bgColor)",border:"1px solid",borderColor:"var(--borderColor-default)",borderRadius:2,boxShadow:"var(--shadow-floating-large, 0 0 0 1px #d1d9e0, 0 40px 80px 0 #25292e3d)",p:1,maxHeight:300,overflow:"auto",minWidth:200},children:x.jsx(Y,{as:"ul",sx:{listStyle:"none",m:0,p:0},children:c.map((_,m)=>x.jsx(kL,{index:m,isSelected:d===m,onClick:()=>{_.disabled||(h(m),g(_))},onMouseEnter:()=>{_.disabled||h(m)},option:_},_.key))})}),f.current):null})]})},yc=4,IL=2,EL="draggable-block-menu",Wg="application/x-lexical-drag-block",Hg=28,NL=1,LL=-1,Jg=0;let Ni=1/0;function OL(n){return n===0?1/0:Ni>=0&&Ni<n?Ni:Math.floor(n/2)}function RL(n){return n.getEditorState().read(()=>se().getChildrenKeys())}function wb(n){const e=(l,c)=>l?parseFloat(window.getComputedStyle(l)[c]):0,{marginTop:t,marginBottom:r}=window.getComputedStyle(n),o=e(n.previousElementSibling,"marginBottom"),s=e(n.nextElementSibling,"marginTop"),i=Math.max(parseFloat(t),o);return{marginBottom:Math.max(parseFloat(r),s),marginTop:i}}function _l(n,e,t,r=!1){const o=n.getBoundingClientRect(),s=RL(e);let i=null;return e.getEditorState().read(()=>{if(r){const[c,u]=[e.getElementByKey(s[0]),e.getElementByKey(s[s.length-1])],[f,d]=[c?.getBoundingClientRect(),u?.getBoundingClientRect()];if(f&&d){const g=Wn(c),h=Wn(u);if(t.y/g<f.top?i=c:t.y/h>d.bottom&&(i=u),i)return}}let a=OL(s.length),l=Jg;for(;a>=0&&a<s.length;){const c=s[a],u=e.getElementByKey(c);if(u===null)break;const f=Wn(u),d=new zm(t.x/f,t.y/f),g=pr.fromDOM(u),{marginTop:h,marginBottom:_}=wb(u),m=g.generateNewRect({bottom:g.bottom+_,left:o.left,right:o.right,top:g.top-h}),{result:y,reason:{isOnTopSide:w,isOnBottomSide:C}}=m.contains(d);if(y){i=u,Ni=a;break}l===Jg&&(w?l=LL:C?l=NL:l=1/0),a+=l}}),i}function AL(n){return!!n.closest(`.${EL}`)}function xb(n){const e=window.getComputedStyle(n),t=e.overflowY==="auto"||e.overflowY==="scroll",r=e.overflowX==="auto"||e.overflowX==="scroll";if(t||r)return{element:n,scrollTop:n.scrollTop||0,scrollLeft:n.scrollLeft||0};const o=n.parentElement;if(o){const s=window.getComputedStyle(o),i=s.overflowY==="auto"||s.overflowY==="scroll",a=s.overflowX==="auto"||s.overflowX==="scroll";if(i||a)return{element:o,scrollTop:o.scrollTop||0,scrollLeft:o.scrollLeft||0}}return{element:n,scrollTop:0,scrollLeft:0}}function ML(n,e,t){if(!n){e.style.opacity="0",e.style.transform="translate(-10000px, -10000px)";return}const r=n.getBoundingClientRect(),o=window.getComputedStyle(n),s=e.getBoundingClientRect(),i=t.getBoundingClientRect(),{scrollTop:a}=xb(t),c=(parseInt(o.lineHeight,10)-s.height)/2,u=r.top+c-i.top+a,f=yc;e.style.opacity="1",e.style.transform=`translate(${f}px, ${u}px)`}function $L(n,e){const{transform:t}=e.style;e.style.transform="translateZ(0)",n.setDragImage(e,0,0),setTimeout(()=>{e.style.transform=t})}function DL(n,e,t,r){const{top:o,height:s}=e.getBoundingClientRect(),{top:i,width:a}=r.getBoundingClientRect(),{marginTop:l,marginBottom:c}=wb(e),{scrollTop:u}=xb(r);let f=o;t>=o?f+=s+c/2:f-=l/2;const d=f-i-IL+u,g=Hg-yc;n.style.transform=`translate(${g}px, ${d}px)`,n.style.width=`${a-(Hg-yc)*2}px`,n.style.opacity=".4"}function PL(n){n&&(n.style.opacity="0",n.style.transform="translate(-10000px, -10000px)")}function jL(n,e,t){const r=S.useRef(null),o=S.useRef(null),s=S.useRef(!1),[i,a]=S.useState(null),l=n._config.theme,c=l.draggableBlockMenu||"",u=l.draggableBlockTargetLine||"";S.useEffect(()=>{function g(_){const m=_.target;if(!pl(m)){a(null);return}if(!e.contains(m)||AL(m))return;const y=_l(e,n,_);a(y)}function h(){a(null)}return document.addEventListener("mousemove",g),document.addEventListener("mouseleave",h),()=>{document.removeEventListener("mousemove",g),document.removeEventListener("mouseleave",h)}},[e,n]),S.useEffect(()=>{r.current&&ML(i,r.current,e)},[e,i]),S.useEffect(()=>{function g(_){if(!s.current)return!1;const[m]=uo(_);if(m)return!1;const{pageY:y,target:w}=_;if(!pl(w))return!1;const C=_l(e,n,_,!0),v=o.current;return C===null||v===null?!1:(DL(v,C,y/Wn(w),e),_.preventDefault(),!0)}function h(_){if(!s.current)return!1;const[m]=uo(_);if(m)return!1;const{target:y,dataTransfer:w,pageY:C}=_,v=w?.getData(Wg)||"",k=Q(v);if(!k||!pl(y))return!1;const I=_l(e,n,_,!0);if(!I)return!1;const E=Me(I);if(!E)return!1;if(E===k)return!0;const N=I.getBoundingClientRect().top;return C/Wn(y)>=N?E.insertAfter(k):E.insertBefore(k),a(null),!0}return de(n.registerCommand(Nc,_=>g(_),ee),n.registerCommand(Lc,_=>h(_),qe))},[e,n]);function f(g){const h=g.dataTransfer;if(!h||!i)return;$L(h,i);let _="";n.update(()=>{const m=Me(i);m&&(_=m.getKey())}),s.current=!0,h.setData(Wg,_)}function d(){s.current=!1,PL(o.current)}return St.createPortal(x.jsxs(x.Fragment,{children:[x.jsx("div",{className:`draggable-block-menu ${c}`,ref:r,draggable:!0,onDragStart:f,onDragEnd:d,children:t?x.jsx(Aw,{size:16}):null}),x.jsx("div",{className:`draggable-block-target-line ${u}`,ref:o})]}),e)}function ZM({anchorElem:n=document.body}){const[e]=fe();return jL(e,n,e._editable)}const FL=()=>x.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor",children:[x.jsx("path",{d:"M4.5 2v5.5a3.5 3.5 0 1 0 7 0V2H13v5.5a5 5 0 0 1-10 0V2h1.5Z"}),x.jsx("rect",{x:"2",y:"14",width:"12",height:"1.5",rx:".75"})]});function BL(n,e,t,r){const[o,s]=S.useState(!1),[i,a]=S.useState(!1),[l,c]=S.useState(!1),[u,f]=S.useState(!1),[d,g]=S.useState(!1),[h,_]=S.useState(!1),[m,y]=S.useState(!1),[w,C]=S.useState(!1),[v,k]=S.useState(!1),I=S.useCallback(()=>{n.getEditorState().read(()=>{if(n.isComposing())return;const M=D(),R=window.getSelection(),$=n.getRootElement();if(R!==null&&(!F(M)||$===null||!$.contains(R.anchorNode))){s(!1);return}if(!F(M))return;const L=Bm(M);c(M.hasFormat("bold")),f(M.hasFormat("italic")),g(M.hasFormat("underline")),_(M.hasFormat("strikethrough")),y(M.hasFormat("subscript")),C(M.hasFormat("superscript")),k(M.hasFormat("code"));const A=L.getParent();Pe(A)||Pe(L)?a(!0):a(!1),!Ve(M.anchor.getNode())&&M.getTextContent()!==""?s(oe(L)):s(!1)})},[n]);S.useEffect(()=>(document.addEventListener("selectionchange",I),()=>{document.removeEventListener("selectionchange",I)}),[I]),S.useEffect(()=>de(n.registerUpdateListener(()=>{I()}),n.registerRootListener(()=>{n.getRootElement()===null&&s(!1)}),n.registerCommand(ys,()=>(s(!1),!1),ee)),[n,I]);const E=S.useCallback(()=>{i?(t(!1),n.dispatchCommand(Lr,null)):(t(!0),n.dispatchCommand(Lr,"https://example.com"))},[n,i,t]),N=S.useMemo(()=>n.isEditable()?[{key:"bold",type:"button",order:0,ariaLabel:"Format text as bold",title:"Bold",icon:Lh,isActive:l,onClick:()=>n.dispatchCommand(Ge,"bold")},{key:"italic",type:"button",order:1,ariaLabel:"Format text as italics",title:"Italic",icon:Oh,isActive:u,onClick:()=>n.dispatchCommand(Ge,"italic")},{key:"underline",type:"button",order:2,ariaLabel:"Format text to underlined",title:"Underline",icon:FL,isActive:d,onClick:()=>n.dispatchCommand(Ge,"underline")},{key:"strikethrough",type:"button",order:3,ariaLabel:"Format text with a strikethrough",title:"Strikethrough",icon:Rh,isActive:h,onClick:()=>n.dispatchCommand(Ge,"strikethrough")},{key:"subscript",type:"button",order:4,ariaLabel:"Format Subscript",title:"Subscript",icon:void 0,label:"x₂",isActive:m,onClick:()=>n.dispatchCommand(Ge,"subscript")},{key:"superscript",type:"button",order:5,ariaLabel:"Format Superscript",title:"Superscript",icon:void 0,label:"x²",isActive:w,onClick:()=>n.dispatchCommand(Ge,"superscript")},{key:"code",type:"button",order:6,ariaLabel:"Insert code block",title:"Code",icon:br,isActive:v,onClick:()=>n.dispatchCommand(Ge,"code")},{key:"link",type:"button",order:7,ariaLabel:"Insert link",title:"Link",icon:Ah,isActive:i,onClick:E},{key:"comment",type:"button",order:8,ariaLabel:"Insert comment",title:"Comment",icon:Pi,onClick:()=>n.dispatchCommand(ys,void 0)}]:[{key:"comment",type:"button",order:100,ariaLabel:"Insert comment",icon:Pi,onClick:()=>n.dispatchCommand(ys,void 0)}],[n,l,u,d,h,m,w,v,i,E]),O=o&&!i;return x.jsx(Tx,{items:N,extraItems:r,anchorElement:e,isVisible:O,ariaLabel:"Floating text format toolbar"})}function QM({anchorElem:n=document.body,setIsLinkEditMode:e,extraItems:t}){const[r]=fe();return BL(r,n,e,t)}function UL(n){return n.registerCommand(Kc,()=>{const e=D();if(!F(e))return!1;if(e.focus.getNode()!==null){const r=ba();e.insertParagraph(),e.focus.getNode().getTopLevelElementOrThrow().insertBefore(r)}return!0},V)}const Cb=pe({name:"@datalayer/jupyter-lexical/HorizontalRule",nodes:()=>[mu],register:UL}),ss={code:{triggerMode:"auto",contextBefore:-1,contextAfter:-1,language:"python"},prose:{triggerMode:"manual",contextBefore:-1,contextAfter:-1},debounceMs:200,manualTriggerKey:"Cmd+Shift+,"};function zL(n){return n?{code:{...ss.code,...n.code},prose:{...ss.prose,...n.prose},debounceMs:n.debounceMs??ss.debounceMs,manualTriggerKey:n.manualTriggerKey??ss.manualTriggerKey}:{...ss}}function e$(n){return n===-1||n>=0}function t$(n){return n.triggerMode==="auto"}function n$(n){return n.triggerMode==="manual"||n.triggerMode==="auto"}function r$(n){return n.triggerMode==="disabled"}const qg="jupyter-cell";class Fr extends Bt{__code;__outputs;__loading;__autoStart;__data;__variant;static getType(){return qg}static clone(e){return console.debug(`clone: node: ${JSON.stringify(e,null,2)}`),new Fr(e.__code,e.__outputs,e.__loading,e.__autoStart,e.__data,e.__key,e.__variant)}constructor(e,t,r,o,s="[]",i,a){super(i),this.__code=e,this.__outputs=t,this.__loading=r,this.__autoStart=o,this.__data=s,this.__variant=a}createDOM(e){const t=document.createElement("div"),o=e.theme.image;return o!==void 0&&(t.className=o),ge("createDOM",t),t}updateDOM(){return!1}decorate(e){return ge(`decorate -> key: ${this.getKey()} outputs: ${this.__outputs} data: ${this.__data}`),x.jsx(_x,{source:this.__code,outputs:this.__outputs,autoStart:this.__autoStart,variant:this.__variant})}setCode(e){const t=this.getWritable();t.__code=e}get code(){return this.__code}setOutputs(e){const t=this.getWritable();t.__outputs=e}get outputs(){return this.__outputs}setLoading(e){const t=this.getWritable();t.__loading=e}get loading(){return this.__loading}setAutostart(e){const t=this.getWritable();t.__autoStart=e}get autoStart(){return this.__autoStart}get variant(){return this.__variant}setData(e){const t=this.getWritable();t.__data=e}get data(){return this.__data}static importJSON(e){const t=e;return new Fr(t.code,t.outputs,t.loading,t.autoStart,t.data,void 0,t.variant)}exportJSON(){return{code:this.__code,outputs:this.__outputs,loading:this.__loading,autoStart:this.__autoStart,data:this.__data,variant:this.__variant,type:qg,version:1}}}function Vg(n){const{code:e,outputs:t,loading:r,autoStart:o}=n;return new Fr(e,t,r,o)}function o$(n){return n instanceof Fr}const KL=he(),WL=he();function HL(n){if(!n.hasNodes([Fr]))throw new Error("JupyterCellNode is not registered.");return de(n.registerCommand(KL,e=>{const t=Vg(e);return Tr([t]),!0},V),n.registerCommand(WL,e=>{const t=Vg({...e});return Tr([t]),!0},V))}const JL=pe({name:"@datalayer/jupyter-lexical/JupyterCell",nodes:()=>[Fr],register:HL}),qL=he("INSERT_LAYOUT_COMMAND");function VL(n){return n.trim().split(/\s+/).length}function s$(n){return Array.from({length:Math.max(1,n)},()=>"1fr").join(" ")}function YL(n){if(!n.hasNodes([Dr,Pr]))throw new Error("LayoutPlugin: LayoutContainerNode, or LayoutItemNode not registered on editor");const e=t=>{const r=D();if(F(r)&&r.isCollapsed()&&r.anchor.offset===0){const o=re(r.anchor.getNode(),Ci);if(Ci(o)){const s=o.getParent(),i=s&&(t?s.getFirstChild():s.getLastChild()),a=t?o.getFirstDescendant()?.getKey():o.getLastDescendant()?.getKey();s!==null&&i===o&&r.anchor.key===a&&(t?o.insertBefore(ne()):o.insertAfter(ne()))}}return!1};return de(n.registerCommand(Vt,()=>e(!1),ee),n.registerCommand(ia,()=>e(!1),ee),n.registerCommand(pt,()=>e(!0),ee),n.registerCommand(zs,()=>e(!0),ee),n.registerCommand(qL,t=>(n.update(()=>{const r=Ou(t);for(let o=0;o<VL(t);o++)r.append(Ru().append(ne()));sr(r),r.selectStart()}),!0),V),n.registerNodeTransform(Pr,t=>{const r=t.getParent();if(!Ci(r)){for(const o of t.getChildren())t.insertBefore(o);t.remove();return}t.isEmpty()&&t.append(ne())}),n.registerNodeTransform(Dr,t=>{const r=t.getChildren();if(!r.every(Au)){for(const o of r)t.insertBefore(o);t.remove();return}r.length===0&&t.remove()}))}const XL=pe({name:"@datalayer/jupyter-lexical/Layout",nodes:()=>[Dr,Pr],register:YL});function Yg(n,e,t,r,o){return n==="code"?GL(e,t):ZL(e,t,r,o)}function GL(n,e){const t=n.getTextContent(),r=tO(n,e),o=t.substring(0,r),s=t.substring(r);return{before:o,after:s,fullText:t}}function ZL(n,e,t,r){const s=se().getChildren(),i=QL(n);if(!i)return{before:"",after:"",fullText:""};const a=s.indexOf(i);if(a===-1)return{before:"",after:"",fullText:""};const l=t===-1?0:Math.max(0,a-t),c=r===-1?s.length-1:Math.min(s.length-1,a+r);let u="";for(let _=l;_<a;_++)u+=s[_].getTextContent()+`
214
+ `+ ++i);t.setAttribute("data-gutter",s)}function Km(n){const e=[];if(n instanceof dn&&e.push(n),q(n))for(const t of n.getChildren())q(t)&&e.push(...Km(t));return e}function XN(n){const e=de(S0(n),n.registerNodeTransform(dn,t=>{Og(t,n)}));return n.getEditorState().read(()=>{for(const t of Km(se()))Og(t,n)}),e}const GN=pe({name:"@datalayer/jupyter-lexical/CodeBlockHighlight",dependencies:[Vh],register:XN}),Xu=he("INSERT_COLLAPSIBLE_COMMAND"),Rg=()=>{const n=D();if(F(n)&&n.isCollapsed()&&n.anchor.offset===0){const e=re(n.anchor.getNode(),Pt);if(Pt(e)){const t=e.getParent();t!==null&&t.getFirstChild()===e&&n.anchor.key===e.getFirstDescendant()?.getKey()&&e.insertBefore(ne())}}return!1},Ag=()=>{const n=D();if(F(n)&&n.isCollapsed()){const e=re(n.anchor.getNode(),Pt);if(Pt(e)){const t=e.getParent();if(t!==null&&t.getLastChild()===e){const r=e.getFirstDescendant(),o=e.getLastDescendant();(o!==null&&n.anchor.key===o.getKey()&&n.anchor.offset===o.getTextContentSize()||r!==null&&n.anchor.key===r.getKey()&&n.anchor.offset===r.getTextContentSize())&&e.insertAfter(ne())}}}return!1};function ZN(n){if(!n.hasNodes([Mr,Os,$r]))throw new Error("CollapsiblePlugin: CollapsibleContainerNode, CollapsibleTitleNode, or CollapsibleContentNode not registered on editor");return de(n.registerNodeTransform($r,e=>{const t=e.getParent();if(!Pt(t)){const r=e.getChildren();for(const o of r)e.insertBefore(o);e.remove()}}),n.registerNodeTransform(Os,e=>{const t=e.getParent();if(!Pt(t)){e.replace(ne().append(...e.getChildren()));return}}),n.registerNodeTransform(Mr,e=>{const t=e.getChildren();if(t.length!==2||!xi(t[0])||!Lu(t[1])){for(const r of t)e.insertBefore(r);e.remove()}}),n.registerCommand(Vt,Ag,ee),n.registerCommand(ia,Ag,ee),n.registerCommand(pt,Rg,ee),n.registerCommand(zs,Rg,ee),n.registerCommand(Lo,()=>{const e=D();if(F(e)){const t=re(e.anchor.getNode(),r=>xi(r));if(xi(t)){const r=t.getParent();if(r&&Pt(r))return r.getOpen()||r.toggleOpen(),t.getNextSibling()?.selectEnd(),!0}}return!1},ee),n.registerCommand(Xu,()=>(n.update(()=>{const e=Z_(),t=ne();sr(Eu(!0).append(e.append(t),Nu().append(ne()))),t.select()}),!0),ee))}const QN=pe({name:"@datalayer/jupyter-lexical/Collapsible",nodes:()=>[Mr,Os,$r],register:ZN}),e2=qn?S.useLayoutEffect:S.useEffect;class Wm{key;ref;icon;title;constructor(e){this.key=e,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(e){this.ref={current:e}}}const Mg=n=>{const e=n.closest("#typeahead-menu");if(!e)return;const t=e.getBoundingClientRect();t.top+t.height>window.innerHeight&&e.scrollIntoView({block:"center"}),t.top<0&&e.scrollIntoView({block:"center"}),n.scrollIntoView({block:"nearest"})};function $g(n,e){const t=n.getBoundingClientRect(),r=e.getBoundingClientRect();return t.top>=r.top-6&&t.top<=r.bottom+6}function t2(n,e,t,r){const[o]=fe();S.useEffect(()=>{if(e!=null&&n!=null){const s=o.getRootElement(),i=s!=null?bh(s,!1):document.body;let a=!1,l=$g(e,i);const c=function(){a||(window.requestAnimationFrame(function(){t(),a=!1}),a=!0);const d=$g(e,i);d!==l&&(l=d,r?.(d))},u=new ResizeObserver(t),f=yh(s??e);return u.observe(e),de(Jt(window,"resize",t),Jt(document,"scroll",c,{capture:!0,passive:!0}),...f.map(d=>Jt(d,"scroll",c,{capture:!0,passive:!0})),()=>u.unobserve(e))}},[e,o,r,t,n])}const Dg=he("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function n2({index:n,isSelected:e,onClick:t,onMouseEnter:r,option:o}){let s="item";return e&&(s+=" selected"),x.jsxs("li",{tabIndex:-1,className:s,ref:o.setRefElement,role:"option","aria-selected":e,id:"typeahead-item-"+n,onMouseEnter:r,onClick:t,children:[o.icon,x.jsx("span",{className:"text",children:o.title})]},o.key)}function r2({close:n,editor:e,anchorElementRef:t,resolution:r,options:o,menuRenderFn:s,onSelectOption:i,shouldSplitNodeWithQuery:a=!1,commandPriority:l=ee,preselectFirstItem:c=!0}){const[u,f]=S.useState(null),d=u!==null?Math.min(o.length-1,u):null,g=r.match&&r.match.matchingString;S.useEffect(()=>{c&&f(0)},[g,c]);const h=S.useCallback(w=>{e.update(()=>{const C=r.match!=null&&a?(function(v){const k=D();if(!F(k)||!k.isCollapsed())return null;const I=k.anchor;if(I.type!=="text")return null;const E=I.getNode();if(!E.isSimpleText())return null;const N=I.offset,O=E.getTextContent().slice(0,N),M=v.replaceableString.length,R=N-(function(L,A,B){let j=B;for(let U=j;U<=A.length;U++)L.slice(-U)===A.substring(0,U)&&(j=U);return j})(O,v.matchingString,M);if(R<0)return null;let $;return R===0?[$]=E.splitText(N):[,$]=E.splitText(R,N),$})(r.match):null;i(w,C,n,r.match?r.match.matchingString:"")})},[e,a,r.match,i,n]),_=S.useCallback(w=>{const C=e.getRootElement();C!==null&&(C.setAttribute("aria-activedescendant","typeahead-item-"+w),f(w))},[e]),m=S.useCallback(()=>t.current&&o.length?wh.createPortal(x.jsx("div",{className:"typeahead-popover mentions-menu",children:x.jsx("ul",{children:o.map((w,C)=>x.jsx(n2,{index:C,isSelected:d===C,onClick:()=>{f(C),h(w)},onMouseEnter:()=>{f(C)},option:w},w.key))})}),t.current):null,[t,o,d,h,f]);S.useEffect(()=>()=>{const w=e.getRootElement();w!==null&&w.removeAttribute("aria-activedescendant")},[e]),e2(()=>{o===null?f(null):d===null&&c&&_(0)},[o,d,_,c]),S.useEffect(()=>de(e.registerCommand(Dg,({option:w})=>!(!w.ref||w.ref.current==null)&&(Mg(w.ref.current),!0),l)),[e,_,l]),S.useEffect(()=>de(e.registerCommand(Vt,w=>{const C=w;if(o!==null&&o.length){const v=d===null?0:d!==o.length-1?d+1:0;_(v);const k=o[v];if(!k)return _(-1),C.preventDefault(),C.stopImmediatePropagation(),!0;k.ref&&k.ref.current&&e.dispatchCommand(Dg,{index:v,option:k}),C.preventDefault(),C.stopImmediatePropagation()}return!0},l),e.registerCommand(pt,w=>{const C=w;if(o!==null&&o.length){const v=d===null?o.length-1:d!==0?d-1:o.length-1;_(v);const k=o[v];if(!k)return _(-1),C.preventDefault(),C.stopImmediatePropagation(),!0;k.ref&&k.ref.current&&Mg(k.ref.current),C.preventDefault(),C.stopImmediatePropagation()}return!0},l),e.registerCommand(Nn,w=>{const C=w;return C.preventDefault(),C.stopImmediatePropagation(),n(),!0},l),e.registerCommand(Kr,w=>{const C=w;return o!==null&&d!==null&&o[d]!=null&&(C.preventDefault(),C.stopImmediatePropagation(),h(o[d]),!0)},l),e.registerCommand(zr,w=>!(o===null||d===null||o[d]==null||w&&w.shiftKey)&&(w!==null&&(w.preventDefault(),w.stopImmediatePropagation()),h(o[d]),!0),l)),[h,n,e,o,d,_,l]);const y=S.useMemo(()=>({options:o,selectOptionAndCleanUp:h,selectedIndex:d,setHighlightedIndex:f}),[h,d,o]);return s!=null?s(t,y,r.match?r.match.matchingString:""):m()}function Pg(n,e){e!=null&&(n.className=e),n.setAttribute("aria-label","Typeahead menu"),n.setAttribute("role","listbox"),n.style.display="block",n.style.position="absolute"}function o2(n,e,t,r,o=!0){const[s]=fe(),i=r??(function(f){if(!qn)return;const d=f.getRootElement();if(d!==null){const g=d.getRootNode();return jc(g)?g:d.ownerDocument.body}return document.body})(s),a=qn?mh(s.getRootElement()).createElement("div"):null,l=S.useRef(a),c=S.useCallback(()=>{if(l.current===null||i===void 0)return;l.current.style.top=l.current.style.bottom;const f=s.getRootElement(),d=l.current,g=d.firstChild;if(f!==null&&n!==null){const{left:h,top:_,width:m,height:y}=n.getRect(),w=l.current.offsetHeight;if(d.style.top=`${_+w+3+(o?window.pageYOffset:0)}px`,d.style.left=`${h+window.pageXOffset}px`,d.style.height=`${y}px`,d.style.width=`${m}px`,g!==null){g.style.top=`${_}`;const C=g.getBoundingClientRect(),v=C.height,k=C.width,I=f.getBoundingClientRect();h+k>I.right&&(d.style.left=`${I.right-k+window.pageXOffset}px`),(_+v>window.innerHeight||_+v>I.bottom)&&_-I.top>v+y&&(d.style.top=`${_-v-y+(o?window.pageYOffset:0)}px`)}d.isConnected||(Pg(d,t),i.append(d)),d.setAttribute("id","typeahead-menu"),f.setAttribute("aria-controls","typeahead-menu")}},[s,n,o,t,i]);S.useEffect(()=>{const f=s.getRootElement();return n!==null&&c(),()=>{f!==null&&f.removeAttribute("aria-controls");const d=l.current;d!==null&&d.isConnected&&(d.remove(),d.removeAttribute("id"))}},[s,c,n]);const u=S.useCallback(f=>{n!==null&&(f||e(null))},[n,e]);return t2(n,l.current,c,u),a!=null&&a===l.current&&(Pg(a,t),i?.append(a)),l}const s2=`\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'"~=<>_:;`;function Hm(n,{minLength:e=1,maxLength:t=75,punctuation:r=s2,allowWhitespace:o=!1}){return S.useCallback(s=>{const i=new RegExp("(^|\\s|\\()(["+n+"]((?:"+("[^"+n+r+(o?"":"\\s")+"]")+"){0,"+t+"}))$").exec(s);if(i!==null){const a=i[1],l=i[3];if(l.length>=e)return{leadOffset:i.index+a.length,matchingString:l,replaceableString:i[2]}}return null},[o,n,r,t,e])}function Jm({options:n,onQueryChange:e,onSelectOption:t,onOpen:r,onClose:o,menuRenderFn:s,triggerFn:i,anchorClassName:a,commandPriority:l=ee,parent:c,preselectFirstItem:u=!0,ignoreEntityBoundary:f=!1}){const[d]=fe(),[g,h]=S.useState(null),_=o2(g,h,a,c),m=S.useCallback(()=>{if(g===null)return;const w=()=>{h(null)};let C;try{C=o&&o()}finally{C?C.then(w,w):w()}},[o,g]),y=S.useCallback(w=>{h(w),r!=null&&g===null&&r(w)},[r,g]);return S.useEffect(()=>{const w=d.registerUpdateListener(()=>{d.read("latest",()=>{if(!d.isEditable())return void m();if(d.isComposing())return;const C=d._window||window,v=C.document.createRange(),k=D(),I=(function(N){let O=null;return N.read("latest",()=>{const M=D();F(M)&&(O=(function(R){const $=R.anchor;if($.type!=="text")return null;const L=$.getNode();if(!L.isSimpleText())return null;const A=$.offset;return L.getTextContent().slice(0,A)})(M))}),O})(d);if(!F(k)||!k.isCollapsed()||I===null||v===null)return void m();const E=i(I,d);if(e(E?E.matchingString:null),E!==null&&(f||!(function(N,O){return O===0&&N.read("latest",()=>{const M=D();if(F(M)){const R=M.anchor.getNode().getPreviousSibling();return oe(R)&&R.isTextEntity()}return!1})})(d,E.leadOffset))&&(function(O,M,R,$){const L=or(R);if(L===null||!L.isCollapsed)return!1;const A=Pc(L,$),B=A.anchorNode,j=O,U=A.anchorOffset;if(B==null||U==null)return!1;try{M.setStart(B,j),M.setEnd(B,U)}catch{return!1}return!0})(E.leadOffset,v,C,d.getRootElement())!==null)return void S.startTransition(()=>y({getRect:()=>v.getBoundingClientRect(),match:E}));m()})});return()=>{w()}},[d,i,e,g,m,y,f]),S.useEffect(()=>d.registerEditableListener(w=>{w||m()}),[d,m]),g===null||d===null||_.current===null?null:x.jsx(r2,{close:m,resolution:g,editor:d,anchorElementRef:_,options:n,menuRenderFn:s,shouldSplitNodeWithQuery:!0,onSelectOption:t,commandPriority:l,preselectFirstItem:u})}const i2=n=>n.split(/[\s._-]+/).filter(Boolean).slice(0,2).map(e=>e[0].toUpperCase()).join("")||"?";function a2({author:n,size:e}){const t=Jc(n);return n.avatarUrl?x.jsx(ax,{src:n.avatarUrl,size:e,alt:t}):x.jsx(Y,{as:"span","aria-hidden":!0,title:t,sx:{display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,width:e,height:e,borderRadius:"50%",bg:"neutral.muted",color:"fg.muted",fontSize:`${Math.round(e*.45)}px`,fontWeight:"bold"},children:n.kind==="anonymous"?x.jsx(hw,{size:Math.round(e*.65)}):i2(t)})}const jr=S.createContext({}),l2=[],c2=250;function qm(n){const{searchPeople:e}=S.useContext(jr),[t,r]=S.useState(null);return S.useEffect(()=>{if(!e||!n)return;let o=!0;const s=setTimeout(()=>{e(n).then(i=>{o&&r({query:n,people:i})},()=>{o&&r({query:n,people:[]})})},c2);return()=>{o=!1,clearTimeout(s)}},[n,e]),t&&t.query===n?t.people:l2}class u2 extends Wm{person;constructor(e){super(e.uid),this.person=e}}function d2({onMention:n}){const[e]=fe(),{searchPeople:t}=S.useContext(jr),[r,o]=S.useState(null),s=qm(r),i=S.useMemo(()=>s.map(c=>new u2(c)),[s]),a=Hm("@",{minLength:1}),l=S.useCallback((c,u,f)=>{e.update(()=>{const d=De(`@${wo(c.person)} `);u&&u.replace(d),d.select(),f()}),n(c.person)},[e,n]);return t?x.jsx(Jm,{onQueryChange:o,onSelectOption:l,triggerFn:a,options:i,menuRenderFn:(c,{selectedIndex:u,selectOptionAndCleanUp:f,setHighlightedIndex:d})=>c.current&&i.length>0?St.createPortal(x.jsx(Y,{as:"ul",role:"listbox","aria-label":"People to mention",sx:{position:"relative",zIndex:1e3,listStyle:"none",m:0,p:1,bg:"var(--overlay-bgColor)",border:"1px solid",borderColor:"var(--borderColor-default)",borderRadius:2,boxShadow:"var(--shadow-floating-large, 0 0 0 1px #d1d9e0, 0 40px 80px 0 #25292e3d)",minWidth:200},children:i.map((g,h)=>x.jsxs(Y,{as:"li",role:"option","aria-selected":u===h,ref:_=>g.setRefElement(_),onMouseEnter:()=>d(h),onClick:()=>{d(h),f(g)},sx:{px:2,py:1,borderRadius:1,cursor:"pointer",bg:u===h?"actionListItem.default.hoverBg":"transparent"},children:[x.jsx(Le,{children:wo(g.person)}),g.person.handle?x.jsxs(Le,{sx:{color:"var(--fgColor-muted)",ml:1},children:["@",g.person.handle]}):null]},g.key))}),c.current):null}):null}function f2({thread:n}){const{searchPeople:e,assignThread:t}=S.useContext(jr),[r,o]=S.useState(!1),[s,i]=S.useState(""),a=qm(r&&s.trim()?s.trim():null),l=n.assignee??null;if(!t||!e)return l?x.jsxs(Le,{as:"p",sx:{fontSize:0,color:"var(--fgColor-muted)",m:0,mt:1},children:["Assigned to ",wo(l)]}):null;const c=u=>{t(n,u),o(!1),i("")};return x.jsxs(Y,{sx:{mt:1},onClick:u=>u.stopPropagation(),children:[x.jsxs(Y,{sx:{display:"flex",alignItems:"center",gap:1},children:[x.jsx(Le,{sx:{fontSize:0,color:"var(--fgColor-muted)"},children:l?`Assigned to ${wo(l)}`:"Not assigned"}),x.jsx(Ft,{icon:ex,"aria-label":"Assign thread",variant:"invisible",size:"small",onClick:()=>o(!r)}),l?x.jsx(ft,{variant:"invisible",size:"small",onClick:()=>c(null),children:"Unassign"}):null]}),r?x.jsxs(Y,{sx:{mt:1},children:[x.jsx(kn,{"aria-label":"Find a person to assign",placeholder:"Name or handle",size:"small",block:!0,autoFocus:!0,value:s,onChange:u=>i(u.target.value)}),x.jsx(Y,{as:"ul",sx:{listStyle:"none",m:0,p:0,mt:1},children:a.map(u=>x.jsx(Y,{as:"li",children:x.jsx(ft,{variant:"invisible",size:"small",onClick:()=>c(u),children:wo(u)})},u.uid))})]}):null]})}const g2={characterLimit:"JupyterLexicalTheme__characterLimit",code:"JupyterLexicalTheme__code",codeHighlight:{atrule:"JupyterLexicalTheme__tokenAttr",attr:"JupyterLexicalTheme__tokenAttr",boolean:"JupyterLexicalTheme__tokenProperty",builtin:"JupyterLexicalTheme__tokenSelector",cdata:"JupyterLexicalTheme__tokenComment",char:"JupyterLexicalTheme__tokenSelector",class:"JupyterLexicalTheme__tokenFunction","class-name":"JupyterLexicalTheme__tokenFunction",comment:"JupyterLexicalTheme__tokenComment",constant:"JupyterLexicalTheme__tokenProperty",deleted:"JupyterLexicalTheme__tokenProperty",doctype:"JupyterLexicalTheme__tokenComment",entity:"JupyterLexicalTheme__tokenOperator",function:"JupyterLexicalTheme__tokenFunction",important:"JupyterLexicalTheme__tokenVariable",inserted:"JupyterLexicalTheme__tokenSelector",keyword:"JupyterLexicalTheme__tokenAttr",namespace:"JupyterLexicalTheme__tokenVariable",number:"JupyterLexicalTheme__tokenProperty",operator:"JupyterLexicalTheme__tokenOperator",prolog:"JupyterLexicalTheme__tokenComment",property:"JupyterLexicalTheme__tokenProperty",punctuation:"JupyterLexicalTheme__tokenPunctuation",regex:"JupyterLexicalTheme__tokenVariable",selector:"JupyterLexicalTheme__tokenSelector",string:"JupyterLexicalTheme__tokenSelector",symbol:"JupyterLexicalTheme__tokenProperty",tag:"JupyterLexicalTheme__tokenProperty",url:"JupyterLexicalTheme__tokenOperator",variable:"JupyterLexicalTheme__tokenVariable"},embedBlock:{base:"JupyterLexicalTheme__embedBlock",focus:"JupyterLexicalTheme__embedBlockFocus"},hashtag:"JupyterLexicalTheme__hashtag",heading:{h1:"JupyterLexicalTheme__h1",h2:"JupyterLexicalTheme__h2",h3:"JupyterLexicalTheme__h3",h4:"JupyterLexicalTheme__h4",h5:"JupyterLexicalTheme__h5",h6:"JupyterLexicalTheme__h6"},image:"editor-image",link:"JupyterLexicalTheme__link",list:{listitem:"JupyterLexicalTheme__listItem",listitemChecked:"JupyterLexicalTheme__listItemChecked",listitemUnchecked:"JupyterLexicalTheme__listItemUnchecked",nested:{listitem:"JupyterLexicalTheme__nestedListItem"},olDepth:["JupyterLexicalTheme__ol1","JupyterLexicalTheme__ol2","JupyterLexicalTheme__ol3","JupyterLexicalTheme__ol4","JupyterLexicalTheme__ol5"],ul:"JupyterLexicalTheme__ul"},ltr:"JupyterLexicalTheme__ltr",mark:"JupyterLexicalTheme__mark",markOverlap:"JupyterLexicalTheme__markOverlap",layoutContainer:"JupyterLexicalTheme__layoutContainer",layoutItem:"JupyterLexicalTheme__layoutItem",paragraph:"JupyterLexicalTheme__paragraph",quote:"JupyterLexicalTheme__quote",rtl:"JupyterLexicalTheme__rtl",table:"JupyterLexicalTheme__table",tableCell:"JupyterLexicalTheme__tableCell",tableCellHeader:"JupyterLexicalTheme__tableCellHeader",text:{bold:"JupyterLexicalTheme__textBold",code:"JupyterLexicalTheme__textCode",italic:"JupyterLexicalTheme__textItalic",strikethrough:"JupyterLexicalTheme__textStrikethrough",subscript:"JupyterLexicalTheme__textSubscript",superscript:"JupyterLexicalTheme__textSuperscript",underline:"JupyterLexicalTheme__textUnderline",underlineStrikethrough:"JupyterLexicalTheme__textUnderlineStrikethrough"}},p2={...g2,paragraph:"CommentEditorTheme__paragraph"},ys=he();function h2({anchorKey:n,editor:e,onAddComment:t}){const r=S.useRef(null),o=S.useCallback(()=>{const s=r.current,i=e.getRootElement(),a=e.getElementByKey(n);if(s!==null&&i!==null&&a!==null){const{right:l}=i.getBoundingClientRect(),{top:c}=a.getBoundingClientRect();s.style.left=`${l-20}px`,s.style.top=`${c-30}px`}},[n,e]);return S.useEffect(()=>(window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o)}),[e,o]),Yu(()=>{o()},[n,e,o]),x.jsx(Y,{ref:r,sx:{position:"absolute",zIndex:10},children:x.jsx(Ft,{icon:Pi,"aria-label":"Add comment",variant:"invisible",size:"small",onClick:t})})}const Vm=pe({name:"@datalayer/jupyter-lexical/CommentComposer",namespace:"Commenting",theme:p2,dependencies:[Cw,Sh,Sw]}),_2=pe({name:"@datalayer/jupyter-lexical/CommentComposer/Focused",dependencies:[Vm,vw]});function m2({editorRef:n}){const[e]=fe();return Yu(()=>(n.current=e,()=>{n.current=null}),[e,n]),null}function b2({onEscape:n}){const[e]=fe();return S.useEffect(()=>e.registerCommand(Nn,t=>n(t),2),[e,n]),null}function Ym({style:n,autoFocus:e,onEscape:t,onChange:r,onMention:o,editorRef:s,placeholder:i="Type a comment..."}){const a=e===!1?Vm:_2;return x.jsx(ww,{extension:a,contentEditable:null,children:x.jsxs(Y,{sx:{position:"relative",m:"10px",borderRadius:2},children:[x.jsx(Ap,{className:"ContentEditable__root",style:n,placeholder:x.jsx(Bh,{children:i}),"aria-placeholder":i}),x.jsx(xw,{onChange:r}),x.jsx(b2,{onEscape:t}),o!==void 0&&x.jsx(d2,{onMention:o}),s!==void 0&&x.jsx(m2,{editorRef:s})]})})}function Xm(n,e){return S.useCallback((t,r)=>{t.read(()=>{n(bw()),e(!yw(r.isComposing(),!0))})},[e,n])}const jg=256;function y2({editor:n,cancelAddComment:e,submitAddComment:t}){const[r,o]=S.useState(""),[s,i]=S.useState(!1),[a,l]=S.useState(null),c=S.useRef(null),u=S.useMemo(()=>({container:document.createElement("div"),elements:[]}),[]),f=Zm(),d=S.useCallback(()=>{n.getEditorState().read(()=>{const C=D();if(F(C)){const v=C.anchor,k=C.focus,I=fh(n,v.getNode(),v.offset,k.getNode(),k.offset);if(I!==null){const{left:E,bottom:N,width:O}=I.getBoundingClientRect(),M=Ml(n,I);let R=M.length===1?E+O/2-jg/2:E-jg/2;R<10&&(R=10),l({left:R,top:N+20});const $=M.length,{container:L}=u,A=u.elements,B=A.length;for(let j=0;j<$;j++){const U=M[j];let z=A[j];z===void 0&&(z=document.createElement("span"),A[j]=z,L.appendChild(z));const H=`position:absolute;top:${U.top}px;left:${U.left}px;height:${U.height}px;width:${U.width}px;background-color:var(--bgColor-attention-muted, rgba(255, 212, 0, 0.3));pointer-events:none;z-index:5;`;z.style.cssText=H}for(let j=B-1;j>=$;j--){const U=A[j];L.removeChild(U),A.pop()}}}})},[n,u]);Yu(()=>{c.current=n.getRootElement(),d();const C=u.container,v=document.body;if(v!==null)return v.appendChild(C),()=>{v.removeChild(C)}},[n,u.container,d]),S.useEffect(()=>(window.addEventListener("resize",d),()=>{window.removeEventListener("resize",d)}),[d]);const g=C=>(C.preventDefault(),e(),!0),h=S.useRef(new Map),_=S.useCallback(C=>{h.current.set(C.uid,C)},[]),m=()=>{if(s){let C=n.getEditorState().read(()=>{const v=D();return v!==null?v.getTextContent():""});C.length>100&&(C=C.slice(0,99)+"…"),t(Px(C,[Ph(r,f,void 0,void 0,void 0,$h(r,h.current.values()))]),!0)}},y=Xm(o,i),w=C=>{const v=C.target;v instanceof HTMLElement&&v.closest('[role="listbox"]')||e()};return a===null?null:x.jsxs(kl,{role:"dialog","aria-label":"Add a comment",width:"small",position:"fixed",left:a.left,top:a.top,onEscape:e,onClickOutside:w,returnFocusRef:c,preventFocusOnOpen:!0,children:[x.jsx(Ym,{style:{position:"relative",border:"1px solid var(--borderColor-default)",backgroundColor:"var(--bgColor-default)",borderRadius:"6px",fontSize:"15px",caretColor:"var(--fgColor-default)",display:"block",padding:"9px 10px 10px 9px",minHeight:"80px"},onEscape:g,onChange:y,onMention:_}),x.jsxs(Y,{sx:{display:"flex",gap:2,justifyContent:"flex-end",mt:2,px:2,pb:2},children:[x.jsx(ft,{onClick:e,variant:"invisible",size:"small",children:"Cancel"}),x.jsx(ft,{onClick:m,disabled:!s,variant:"primary",size:"small",children:"Comment"})]})]})}function w2({submitAddComment:n,thread:e,placeholder:t}){const[r,o]=S.useState(""),[s,i]=S.useState(!1),a=S.useRef(null),l=Zm(),c=S.useRef(new Map),u=S.useCallback(g=>{c.current.set(g.uid,g)},[]),f=Xm(o,i),d=()=>{if(s){n(Ph(r,l,void 0,void 0,void 0,$h(r,c.current.values())),!1,e),c.current.clear();const g=a.current;g!==null&&g.dispatchCommand(Tw,void 0)}};return x.jsxs(x.Fragment,{children:[x.jsx(Ym,{style:{position:"relative",border:"1px solid",borderColor:"var(--borderColor-default, #ccc)",backgroundColor:"var(--bgColor-default, #fff)",borderRadius:"6px",fontSize:"15px",caretColor:"var(--fgColor-default)",display:"block",padding:"9px 10px 10px 9px",minHeight:"20px"},autoFocus:!1,onEscape:()=>!0,onChange:f,onMention:u,editorRef:a,placeholder:t}),x.jsx(Ft,{icon:kw,"aria-label":"Send comment",variant:"invisible",size:"small",onClick:d,disabled:!s})]})}function Gm({commentOrThread:n,deleteCommentOrThread:e,onClose:t,thread:r=void 0}){return x.jsxs(x.Fragment,{children:["Are you sure you want to delete this ",n.type,"?",x.jsxs(Y,{sx:{display:"flex",gap:2,justifyContent:"flex-end",mt:3},children:[x.jsx(ft,{variant:"invisible",onClick:()=>{t()},children:"Cancel"}),x.jsx(ft,{variant:"danger",onClick:()=>{e(n,r),t()},children:"Delete"})]})]})}function x2(n,e){const t=Math.round((e-Date.now())/1e3);if(t>-10)return"Just now";const r=Math.round(t/60);if(r>-60)return n.format(r,"minute");const o=Math.round(r/60);return o>-24?n.format(o,"hour"):n.format(Math.round(o/24),"day")}function Fg({comment:n,deleteComment:e,thread:t,rtf:r}){const[o,s]=Xo(),{Avatar:i=a2}=S.useContext(jr),a=Dx(n);return x.jsxs(Y,{as:"li",sx:{p:2,borderBottom:"1px solid",borderColor:"var(--borderColor-muted)"},children:[x.jsxs(Y,{sx:{display:"flex",alignItems:"center",gap:1,mb:1},children:[x.jsx(i,{author:a,size:20}),x.jsx(Le,{sx:{fontWeight:"bold",fontSize:1},children:Jc(a)}),a.agentUid&&x.jsx(Le,{sx:{color:"var(--fgColor-muted)",fontSize:0},children:"· with an agent"}),x.jsxs(Le,{sx:{color:"var(--fgColor-muted)",fontSize:0},children:["· ",x2(r,n.timeStamp)]})]}),x.jsx(Le,{as:"p",sx:{fontSize:1,m:0,...n.deleted?{color:"var(--fgColor-muted)",fontStyle:"italic"}:{}},children:n.content}),!n.deleted&&x.jsxs(x.Fragment,{children:[x.jsx(Ft,{icon:Ch,"aria-label":"Delete comment",variant:"invisible",size:"small",sx:{color:"var(--fgColor-danger)",mt:1},onClick:()=>{s("Delete Comment",l=>x.jsx(Gm,{commentOrThread:n,deleteCommentOrThread:e,thread:t,onClose:l}))}}),o]})]})}function C2({activeIDs:n,comments:e,deleteCommentOrThread:t,listRef:r,submitAddComment:o,markNodeMap:s,resolveThread:i}){const[a]=fe(),[l,c]=S.useState(0),[u,f]=Xo(),d=S.useMemo(()=>new Intl.RelativeTimeFormat("en",{localeMatcher:"best fit",numeric:"auto",style:"short"}),[]);return S.useEffect(()=>{const g=setTimeout(()=>{c(l+1)},1e4);return()=>{clearTimeout(g)}},[l]),x.jsx(Y,{as:"ul",ref:r,sx:{listStyle:"none",m:0,p:0},children:e.map(g=>{const h=g.id;if(g.type==="thread"){const _=()=>{const m=s.get(h);if(m!==void 0&&(n===null||n.indexOf(h)===-1)){const y=document.activeElement;a.update(()=>{const w=Array.from(m)[0],C=Q(w);Ro(C)&&C.selectStart()},{onUpdate(){y!==null&&y.focus()}})}};return x.jsxs(Y,{as:"li",onClick:_,sx:{p:2,borderBottom:"1px solid",borderColor:"var(--borderColor-muted)",cursor:s.has(h)?"pointer":"default",bg:n.indexOf(h)===-1?"var(--bgColor-default)":"var(--bgColor-accent-muted)","&:hover":s.has(h)?{bg:"var(--bgColor-muted)"}:{}},children:[x.jsxs(Y,{sx:{display:"flex",alignItems:"flex-start",gap:2},children:[x.jsxs(Y,{as:"blockquote",sx:{flex:1,m:0,pl:2,borderLeft:"3px solid",borderColor:"var(--bgColor-accent-muted)",color:"var(--fgColor-muted)",fontSize:1},children:["> ",x.jsx("span",{children:g.quote})]}),i&&x.jsx(Ft,{icon:xh,"aria-label":"Resolve thread",variant:"invisible",size:"small",onClick:m=>{m.stopPropagation(),i(g)}}),x.jsx(Ft,{icon:Ch,"aria-label":"Delete thread",variant:"invisible",size:"small",sx:{color:"var(--fgColor-danger)"},onClick:()=>{f("Delete Thread",m=>x.jsx(Gm,{commentOrThread:g,deleteCommentOrThread:t,onClose:m}))}}),u]}),x.jsx(f2,{thread:g}),x.jsx(Y,{as:"ul",sx:{listStyle:"none",m:0,p:0,mt:2},children:g.comments.map(m=>x.jsx(Fg,{comment:m,deleteComment:t,thread:g,rtf:d},m.id))}),x.jsx(Y,{sx:{mt:2},children:x.jsx(w2,{submitAddComment:o,thread:g,placeholder:"Reply to comment..."})})]},h)}return x.jsx(Fg,{comment:g,deleteComment:t,rtf:d},h)})})}function S2({activeIDs:n,deleteCommentOrThread:e,comments:t,submitAddComment:r,markNodeMap:o,resolveThread:s}){const i=S.useRef(null),a=t.length===0;return x.jsxs(Y,{sx:{bg:"var(--bgColor-default)",borderRadius:2,overflow:"hidden",width:"100%",flex:1,display:"flex",flexDirection:"column"},children:[x.jsx(mw,{as:"h2",sx:{fontSize:2,p:3,borderBottom:"1px solid",borderColor:"var(--borderColor-muted)",m:0},children:"Comments"}),a?x.jsx(Y,{sx:{p:3,color:"var(--fgColor-muted)",textAlign:"center"},children:"No Comments"}):x.jsx(C2,{activeIDs:n,comments:t,deleteCommentOrThread:e,listRef:i,submitAddComment:r,markNodeMap:o,resolveThread:s})]})}function Zm(){const{author:n}=S.useContext(jr),{name:e}=Lm();return n??qc(e)}function VM({providerFactory:n,showFloatingAddButton:e=!0,commentStore:t,author:r,Avatar:o}){const[s]=fe(),{showComments:i,setShowComments:a}=e_(),l=S.useRef(null),c=S.useRef(null),u=S.useMemo(()=>t??new Bx(s),[s,t]),f=Ux(u),d=S.useMemo(()=>new Map,[]),[g,h]=S.useState(),[_,m]=S.useState([]),[y,w]=S.useState(!1),C=S.useCallback(R=>{a(typeof R=="function"?R(i):R)},[a,i]),v=S.useCallback(()=>{s.update(()=>{const R=D();R!==null&&(R.dirty=!0)}),w(!1)},[s]),k=S.useCallback(R=>{const $=d.get(R);$!==void 0&&setTimeout(()=>{s.update(()=>{for(const L of $){const A=Q(L);Ro(A)&&(A.deleteID(R),A.getIDs().length===0&&Ox(A))}})})},[s,d]),I=S.useCallback((R,$)=>{R.type==="comment"?u.deleteComment(R,$):(u.deleteThread(R),k($!==void 0?$.id:R.id))},[u,k]),E=S.useMemo(()=>{if(u.resolveThread)return R=>{u.resolveThread?.(R),k(R.id)}},[u,k]),N=S.useCallback((R,$,L)=>{u.addComment(R,L),$&&(s.update(()=>{const A=D();if(F(A)){const B=A.focus,j=A.anchor,U=A.isBackward(),z=R.id;Rx(A,U,z),U?B.set(j.key,j.offset,j.type):j.set(B.key,B.offset,B.type)}}),w(!1))},[u,s]);S.useEffect(()=>{const R=[];for(let $=0;$<_.length;$++){const L=_[$],A=d.get(L);if(A!==void 0)for(const B of A){const j=s.getElementByKey(B);j!==null&&(j.classList.add("selected"),R.push(j),a(!0))}}return()=>{for(let $=0;$<R.length;$++)R[$].classList.remove("selected")}},[_,s,d]),S.useEffect(()=>{const R=new Map;return de(_w(s,Ts,$=>Hc($.getIDs()),($,L)=>{$.getIDs().forEach(B=>{L.addID(B)})}),s.registerMutationListener(Ts,$=>{s.getEditorState().read(()=>{for(const[L,A]of $){const B=Q(L);let j=[];A==="destroyed"?j=R.get(L)||[]:Ro(B)&&(j=B.getIDs());for(let U=0;U<j.length;U++){const z=j[U];let K=d.get(z);R.set(L,j),A==="destroyed"?K!==void 0&&(K.delete(L),K.size===0&&d.delete(z)):(K===void 0&&(K=new Set,d.set(z,K)),K.has(L)||K.add(L))}}})}),s.registerUpdateListener(({editorState:$,tags:L})=>{$.read(()=>{const A=D();let B=!1,j=!1;if(F(A)){const U=A.anchor.getNode();if(oe(U)){const z=Ax(U,A.anchor.offset);z!==null&&(m(z),B=!0),A.isCollapsed()||(h(U.getKey()),j=!0)}}B||m(U=>U.length===0?U:[]),j||h(null)}),L.has("collaboration")||w(!1)}),s.registerCommand(ys,()=>{const $=window.getSelection();return $!==null&&$.removeAllRanges(),w(!0),!0},V))},[s,d]);const O=()=>{s.dispatchCommand(ys,void 0)},M=S.useMemo(()=>({searchPeople:u.searchPeople?.bind(u),assignThread:u.assignThread?.bind(u),author:r,Avatar:o}),[u,r,o]);return x.jsxs(jr.Provider,{value:M,children:[y&&x.jsx(jr.Provider,{value:M,children:x.jsx(y2,{editor:s,cancelAddComment:v,submitAddComment:N})}),e&&g!==null&&g!==void 0&&!y&&St.createPortal(x.jsx(h2,{anchorKey:g,editor:s,onAddComment:O}),document.body),x.jsx("button",{ref:l,style:{display:"none"},"aria-hidden":"true"}),x.jsx(vx,{isOpen:i,setIsOpen:C,openButtonRef:l,closeButtonRef:c,direction:"right",width:"350px",content:x.jsx(S2,{comments:f,submitAddComment:N,deleteCommentOrThread:I,activeIDs:_,markNodeMap:d,resolveThread:E})})]})}const Fo=Qe().describe("CSS colour, e.g. '#1e1e1e', '#e03131', 'transparent'"),Qm=Lt({type:wr(["rectangle","ellipse","diamond","text","arrow","line","frame"]).describe("What to draw"),x:We().describe("Left edge, in scene coordinates"),y:We().describe("Top edge, in scene coordinates"),width:We().optional().describe("Width in pixels (shapes only)"),height:We().optional().describe("Height in pixels (shapes only)"),id:Qe().optional().describe("Your own id for this element, so a later arrow can point at it by name. Any string; Excalidraw keeps it."),text:Qe().optional().describe("The text itself, for type 'text'"),label:Qe().optional().describe("Text to put inside the shape. Excalidraw binds it to the shape, so moving the shape moves the label."),fontSize:We().optional().describe("Font size in pixels, e.g. 16, 20, 28"),strokeColor:Fo.optional().describe("Outline colour"),backgroundColor:Fo.optional().describe("Fill colour"),fillStyle:wr(["hachure","cross-hatch","solid"]).optional().describe("How the fill is drawn"),strokeWidth:We().optional().describe("Outline thickness, 1 | 2 | 4"),strokeStyle:wr(["solid","dashed","dotted"]).optional().describe("Outline style"),roughness:We().optional().describe("0 for architect (clean), 1 for artist, 2 for cartoonist"),opacity:We().optional().describe("0-100"),angle:We().optional().describe("Rotation in radians"),startId:Qe().optional().describe("For 'arrow' and 'line': the id of the element the arrow starts at. The arrow stays attached when either element moves."),endId:Qe().optional().describe("For 'arrow' and 'line': the id of the element the arrow points at."),points:yr(yr(We())).optional().describe("For 'arrow' and 'line' without bindings: points relative to x,y, e.g. [[0,0],[120,0]]"),children:yr(Qe()).optional().describe("For 'frame': the ids of the elements it contains"),name:Qe().optional().describe("For 'frame': its name")}),eb=Qe().describe("Where to put the drawing: 'TOP' for the beginning of the document, 'BOTTOM' for the end, or the block_id to insert after"),On=Qe().describe("The block_id of the drawing, from excalidrawListDrawings or readAllBlocks"),tb=Lt({afterId:eb,elements:yr(Qm).optional().describe("The drawing itself. Omit to insert an empty canvas for a person to draw on."),width:We().optional().describe("Rendered width in pixels. Omit to size to the content."),height:We().optional().describe("Rendered height in pixels. Omit to size to the content.")}),nb=Lt({}),rb=Lt({blockId:On,detail:wr(["summary","full"]).optional().describe("'summary' (default) gives each element's id, type, position, size and text — enough to change it. 'full' gives the raw Excalidraw elements, which is large; ask for it only when you need a field the summary omits.")}),ob=Lt({blockId:On,elements:yr(Qm).describe("The elements to add. Existing elements are left alone.")}),sb=Lt({blockId:On,updates:yr(Lt({id:Qe().describe("The element id, from excalidrawReadScene"),x:We().optional(),y:We().optional(),width:We().optional(),height:We().optional(),text:Qe().optional().describe("New text. On a shape this rewrites the label bound inside it; on a 'text' element it rewrites the element."),strokeColor:Fo.optional(),backgroundColor:Fo.optional(),fillStyle:wr(["hachure","cross-hatch","solid"]).optional(),strokeWidth:We().optional(),strokeStyle:wr(["solid","dashed","dotted"]).optional(),opacity:We().optional().describe("0-100"),angle:We().optional().describe("Rotation in radians")})).describe("One entry per element to change. Fields left out are kept.")}),ib=Lt({blockId:On,elementIds:yr(Qe()).describe("The ids to remove, from excalidrawReadScene")}),ab=Lt({blockId:On,fromId:Qe().describe("The element the arrow starts at"),toId:Qe().describe("The element the arrow points at"),label:Qe().optional().describe('Text to sit on the arrow, e.g. "yes", "then"'),strokeColor:Fo.optional(),strokeStyle:wr(["solid","dashed","dotted"]).optional()}),lb=Lt({blockId:On,viewBackgroundColor:Fo.optional().describe("The canvas colour behind the drawing"),gridSize:We().optional().describe("Grid spacing in pixels. 0 turns the grid off.")}),cb=Lt({blockId:On,width:We().optional().describe("Rendered width in pixels. Omit to go back to sizing by content."),height:We().optional().describe("Rendered height in pixels. Omit to go back to sizing by content.")}),ub=Lt({blockId:On}),db=Lt({blockId:On.optional().describe("The drawing to replace. Omit to insert a new drawing instead, positioned by afterId."),afterId:eb.optional().describe("Where a new drawing goes: 'TOP', 'BOTTOM', or a block_id. Ignored when blockId is given."),mermaid:Qe().describe("Mermaid source. Flowcharts, sequence diagrams and class diagrams convert to real shapes; anything else comes across as an image."),fontSize:We().optional().describe("Font size for the generated text, in pixels")}),Qt=n=>`datalayer_${n}`,Qr={requiresConfirmation:!1,canBeReferencedInPrompt:!0,priority:"medium"},en=["lexical","excalidraw","drawing","diagram"],v2={name:Qt("excalidrawInsertNode"),displayName:"Insert Drawing",toolReferenceName:"excalidrawInsertNode",description:"Insert an Excalidraw drawing into the Lexical document, optionally with its contents. This is how you draw a diagram: give the elements you want and they are laid out as you place them, in scene coordinates where x grows right and y grows down. Give a shape an `id` and a later arrow can bind to it with `startId`/`endId`, so the arrow follows the shape when it moves. Put text on a shape with `label` rather than positioning a separate text element on top of it. Returns the new block_id — keep it, every other excalidraw tool needs it. Omit `elements` to insert an empty canvas for a person to draw on themselves.",parameters:Zt(tb),operation:"excalidrawInsertNode",config:{confirmationMessage:n=>`Insert a drawing of ${n.elements?.length??0} element(s)?`,invocationMessage:()=>"Drawing in the lexical document",requiresConfirmation:!0,canBeReferencedInPrompt:!0,priority:"high"},tags:[...en,"insert"]},k2={name:Qt("excalidrawListDrawings"),displayName:"List Drawings",toolReferenceName:"excalidrawListDrawings",description:'List the Excalidraw drawings in the open Lexical document, with the block_id of each and a one-line description of what it holds. Call this first when asked to change "the diagram" and you do not already know its block_id.',parameters:Zt(nb),operation:"excalidrawListDrawings",config:{...Qr,invocationMessage:()=>"Looking for drawings"},tags:[...en,"read"]},T2={name:Qt("excalidrawReadScene"),displayName:"Read Drawing",toolReferenceName:"excalidrawReadScene",description:"Read what is inside one drawing: every element with its id, type, position, size and text. The element ids are the only way to address a shape, so read the scene before updating, deleting or connecting anything. The default 'summary' detail is what you want; 'full' returns the raw Excalidraw elements and is large.",parameters:Zt(rb),operation:"excalidrawReadScene",config:{...Qr,invocationMessage:()=>"Reading the drawing"},tags:[...en,"read"]},I2={name:Qt("excalidrawAddElements"),displayName:"Add to Drawing",toolReferenceName:"excalidrawAddElements",description:"Add elements to a drawing that already exists, leaving what is there alone. Same element format as excalidrawInsertNode. To attach a new arrow to a shape already in the drawing, pass that shape's existing element id as `startId` or `endId`. Read the scene first if you need to know where there is room.",parameters:Zt(ob),operation:"excalidrawAddElements",config:{...Qr,invocationMessage:()=>"Adding to the drawing",priority:"high"},tags:[...en,"edit"]},E2={name:Qt("excalidrawUpdateElements"),displayName:"Update Drawing Elements",toolReferenceName:"excalidrawUpdateElements",description:"Change elements already in a drawing — move them, resize them, recolour them, or rewrite their text. Address each one by the element id from excalidrawReadScene. Fields you leave out are kept as they are. Setting `text` on a shape rewrites the label bound inside it rather than replacing the shape.",parameters:Zt(sb),operation:"excalidrawUpdateElements",config:{...Qr,invocationMessage:()=>"Changing the drawing"},tags:[...en,"edit"]},N2={name:Qt("excalidrawDeleteElements"),displayName:"Delete Drawing Elements",toolReferenceName:"excalidrawDeleteElements",description:"Remove elements from a drawing by their element ids. Deleting a shape also removes the text bound inside it and detaches any arrows that pointed at it, so the drawing stays consistent.",parameters:Zt(ib),operation:"excalidrawDeleteElements",config:{confirmationMessage:n=>`Delete ${n.elementIds?.length??0} element(s) from the drawing?`,invocationMessage:()=>"Removing from the drawing",requiresConfirmation:!0,canBeReferencedInPrompt:!0,priority:"medium"},tags:[...en,"edit","delete"]},L2={name:Qt("excalidrawConnectElements"),displayName:"Connect Drawing Elements",toolReferenceName:"excalidrawConnectElements",description:"Draw an arrow from one element to another and bind it to both, so it follows them when either moves. Excalidraw works out where the arrow should meet each shape. Use this rather than adding an arrow with hand-computed points whenever both ends are existing shapes.",parameters:Zt(ab),operation:"excalidrawConnectElements",config:{...Qr,invocationMessage:()=>"Connecting two shapes"},tags:[...en,"edit"]},O2={name:Qt("excalidrawSetAppState"),displayName:"Set Drawing Canvas",toolReferenceName:"excalidrawSetAppState",description:"Set the canvas behind a drawing: its background colour and its grid. This is about the canvas, not the shapes on it — use excalidrawUpdateElements to recolour a shape.",parameters:Zt(lb),operation:"excalidrawSetAppState",config:{...Qr,invocationMessage:()=>"Setting up the canvas"},tags:[...en,"edit"]},R2={name:Qt("excalidrawResize"),displayName:"Resize Drawing",toolReferenceName:"excalidrawResize",description:"Set how large the drawing is rendered in the document. This scales the picture on the page; it does not move or resize anything inside it. Omit width and height to go back to sizing by content.",parameters:Zt(cb),operation:"excalidrawResize",config:{...Qr,invocationMessage:()=>"Resizing the drawing"},tags:[...en,"edit"]},A2={name:Qt("excalidrawClearScene"),displayName:"Clear Drawing",toolReferenceName:"excalidrawClearScene",description:"Empty a drawing, keeping the block so it can be drawn into again. To remove the drawing from the document altogether, use deleteBlocks with its block_id.",parameters:Zt(ub),operation:"excalidrawClearScene",config:{confirmationMessage:()=>"Empty this drawing?",invocationMessage:()=>"Emptying the drawing",requiresConfirmation:!0,canBeReferencedInPrompt:!0,priority:"low"},tags:[...en,"edit","delete"]},M2={name:Qt("excalidrawFromMermaid"),displayName:"Draw from Mermaid",toolReferenceName:"excalidrawFromMermaid",description:"Turn Mermaid source into a real Excalidraw drawing — shapes and arrows that can then be moved, recoloured and edited like anything else you drew. This is the fastest way to produce a flowchart, sequence diagram or class diagram: write the Mermaid and let the layout be worked out for you, rather than placing boxes by hand. Give blockId to replace an existing drawing, or afterId to insert a new one.",parameters:Zt(db),operation:"excalidrawFromMermaid",config:{confirmationMessage:n=>n.blockId?"Replace this drawing with the Mermaid diagram?":"Insert the Mermaid diagram as a drawing?",invocationMessage:()=>"Drawing the Mermaid diagram",requiresConfirmation:!0,canBeReferencedInPrompt:!0,priority:"high"},tags:[...en,"insert","mermaid"]},fb=[v2,M2,k2,T2,I2,E2,L2,N2,O2,R2,A2],hl=()=>({elements:[],appState:{},files:{}});function Gu(n){if(!n)return hl();let e;try{e=JSON.parse(n)}catch{return hl()}if(Array.isArray(e))return{elements:e,appState:{},files:{}};if(!e||typeof e!="object")return hl();const t=e;return{elements:Array.isArray(t.elements)?t.elements:[],appState:t.appState??{},files:t.files??{}}}function Zu(n){return JSON.stringify({elements:n.elements,appState:n.appState,files:n.files})}const Gs=n=>n.elements.filter(e=>!e?.isDeleted);function $2(n){const e={id:String(n?.id??""),type:String(n?.type??"unknown"),x:Number(n?.x??0),y:Number(n?.y??0),width:Number(n?.width??0),height:Number(n?.height??0)};return typeof n?.text=="string"&&n.text.length>0&&(e.text=n.text),n?.strokeColor&&(e.strokeColor=String(n.strokeColor)),n?.backgroundColor&&(e.backgroundColor=String(n.backgroundColor)),n?.containerId&&(e.containerId=String(n.containerId)),n?.startBinding?.elementId&&(e.startBoundElementId=String(n.startBinding.elementId)),n?.endBinding?.elementId&&(e.endBoundElementId=String(n.endBinding.elementId)),Array.isArray(n?.groupIds)&&n.groupIds.length>0&&(e.groupIds=n.groupIds.map(String)),e}function D2(n){const e=new Map;for(const t of n)t?.type==="text"&&t?.containerId&&t?.text&&e.set(String(t.containerId),String(t.text));return n.map(t=>{const r=$2(t);if(r.text===void 0){const o=e.get(r.id);o&&(r.text=o)}return r})}function Qu(n){const e=Gs(n);if(e.length===0)return"empty drawing";const t=new Map,r=[];for(const i of e){const a=String(i?.type??"unknown");if(a==="text"){const l=String(i?.text??"").trim();if(l&&r.push(l),i?.containerId)continue}t.set(a,(t.get(a)??0)+1)}const o=[...t.entries()].sort((i,a)=>a[1]-i[1]||i[0].localeCompare(a[0])).map(([i,a])=>`${a} ${i}${a>1?"s":""}`).join(", "),s=r.slice(0,3).join(", ");return s?`${o}: ${s}`:o}function ed(n){return{...n,version:Number(n?.version??1)+1,versionNonce:Math.floor(Math.random()*2**31),updated:Date.now()}}const Zi=4;function gb(n,e){let t=null,r;if(n.getEditorState().read(()=>{const o=Q(e);o&&(r=o.getType?.(),r==="excalidraw"&&(t=o))}),!t)throw new Error(r?`Block '${e}' is a '${r}', not a drawing. Call excalidrawListDrawings to find the drawings in this document.`:`No block '${e}' in this document. Call excalidrawListDrawings to find the drawings in this document.`);return t}function Rn(n,e){const t=gb(n,e);let r="";return n.getEditorState().read(()=>{r=t.__data??""}),Gu(r)}function eo(n,e,t){const r=Zu(t);return new Promise(o=>{n.update(()=>{const s=Q(e);s?.setData&&s.setData(r)},{onUpdate:()=>o()})})}const _n=(n,e,t)=>({success:!0,blockId:n,elementCount:Gs(e).length,...t});let P2=0;const j2=()=>`dla-${Date.now().toString(36)}-${(P2+=1).toString(36)}`;function F2(n,e){const{label:t,startId:r,endId:o,fontSize:s,text:i,children:a,name:l,...c}=n,u={...c,id:e};return n.type==="text"?(u.text=i??t??"",s&&(u.fontSize=s)):t&&(u.label=s?{text:t,fontSize:s}:{text:t}),(n.type==="arrow"||n.type==="line")&&(r&&(u.start={id:r}),o&&(u.end={id:o})),(n.type==="frame"||n.type==="magicframe")&&(u.children=a??[],l&&(u.name=l)),u}async function td(n,e){const{convertToExcalidrawElements:t}=await me(async()=>{const{convertToExcalidrawElements:i}=await import("./percentages-BXMCSKIN-azlLrVPY.js").then(a=>a.i);return{convertToExcalidrawElements:i}},[],import.meta.url),r=[],o=n.map(i=>{let a=String(i.id??"").trim();return(!a||e.has(a))&&(a=j2()),e.add(a),r.push(a),F2(i,a)});return{elements:[...t(o,{regenerateIds:!1})],ids:r}}const mc=n=>({x:Number(n.x??0)+Number(n.width??0)/2,y:Number(n.y??0)+Number(n.height??0)/2});function Bg(n,e){const t=mc(n),r=e.x-t.x,o=e.y-t.y;if(r===0&&o===0)return t;const s=Number(n.width??0)/2+Zi,i=Number(n.height??0)/2+Zi,a=Math.min(r===0?1/0:Math.abs(s/r),o===0?1/0:Math.abs(i/o));return{x:t.x+r*a,y:t.y+o*a}}function B2(n,e){const t=Array.isArray(n.boundElements)?[...n.boundElements]:[];return t.some(r=>r?.id===e)||t.push({id:e,type:"arrow"}),ed({...n,boundElements:t})}function pb(n,e,t,r){const o=n.elements.find(c=>c.id===t),s=n.elements.find(c=>c.id===r);if(!o||!s){const c=o?r:t;throw new Error(`No element '${c}' in this drawing. Call excalidrawReadScene to see the element ids it holds.`)}const i=Bg(o,mc(s)),a=Bg(s,mc(o)),l={...e,x:i.x,y:i.y,width:Math.abs(a.x-i.x),height:Math.abs(a.y-i.y),points:[[0,0],[a.x-i.x,a.y-i.y]],startBinding:{elementId:t,focus:0,gap:Zi},endBinding:{elementId:r,focus:0,gap:Zi}};return n.elements=n.elements.map(c=>c.id===t||c.id===r?B2(c,String(e.id)):c),l}const U2=async(n,e)=>{const t=e.elements??[],r=t.length>0?await td(t,new Set):{elements:[],ids:[]},o={elements:r.elements,appState:{},files:{}},s=await n.insertBlock({block_id:"",block_type:"excalidraw",source:"",metadata:{data:Zu(o),width:e.width,height:e.height}},String(e.afterId??"BOTTOM"));if(!s.success||!s.blockId)throw new Error(s.error||"Failed to insert the drawing");return _n(s.blockId,o,{createdIds:r.ids,message:`Drawing inserted with ${r.elements.length} element(s)`})},z2=async n=>{const t=(await n.getBlocks("detailed")).filter(r=>r.block_type==="excalidraw").map(r=>{const o=Gu(r.metadata?.data);return{blockId:r.block_id,elementCount:Gs(o).length,description:Qu(o),width:r.metadata?.width,height:r.metadata?.height}});return{drawings:t,count:t.length}},K2=async(n,e)=>{const t=String(e.blockId),r=Rn(n.editor,t),o=Gs(r);return{blockId:t,elementCount:o.length,elements:e.detail==="full"?o:D2(o),appState:r.appState,description:Qu(r)}},W2=async(n,e)=>{const t=String(e.blockId),r=Rn(n.editor,t),o=new Set(r.elements.map(u=>String(u.id))),s=e.elements??[],i=new Set(s.map(u=>String(u.id??"")).filter(Boolean)),a=new Map,l=s.map((u,f)=>{const{startId:d,endId:g}=u;if((u.type==="arrow"||u.type==="line")&&d&&g&&(!i.has(String(d))||!i.has(String(g)))){a.set(f,{fromId:String(d),toId:String(g)});const{startId:_,endId:m,...y}=u;return y}return u}),c=await td(l,o);r.elements=[...r.elements,...c.elements];for(const[u,f]of a){const d=c.ids[u],g=r.elements.find(h=>h.id===d);if(g){const h=pb(r,g,f.fromId,f.toId);r.elements=r.elements.map(_=>_.id===d?h:_)}}return await eo(n.editor,t,r),_n(t,r,{createdIds:c.ids,message:`Added ${c.elements.length} element(s)`})},H2=async(n,e)=>{const t=String(e.blockId),r=Rn(n.editor,t),o=e.updates??[],s=new Map;for(const l of r.elements)l?.type==="text"&&l?.containerId&&s.set(String(l.containerId),String(l.id));const i=new Map,a=[];for(const l of o){const c=String(l.id),u=r.elements.find(_=>_.id===c);if(!u){a.push(c);continue}const{id:f,text:d,...g}=l,h=u.type!=="text"&&s.get(c);d!==void 0&&(h?i.set(h,{...i.get(h)??{},text:d,originalText:d}):(g.text=d,g.originalText=d)),Object.keys(g).length>0&&i.set(c,{...i.get(c)??{},...g})}if(a.length>0)throw new Error(`No element(s) ${a.map(l=>`'${l}'`).join(", ")} in this drawing. Call excalidrawReadScene to see the element ids it holds.`);return r.elements=r.elements.map(l=>{const c=i.get(String(l.id));return c?ed({...l,...c}):l}),await eo(n.editor,t,r),_n(t,r,{message:`Updated ${o.length} element(s)`})},J2=async(n,e)=>{const t=String(e.blockId),r=Rn(n.editor,t),o=new Set(e.elementIds.map(String)),s=new Set(o);for(const a of r.elements)a?.containerId&&o.has(String(a.containerId))&&s.add(String(a.id));const i=r.elements.length;return r.elements=r.elements.filter(a=>!s.has(String(a.id))).map(a=>{const l={};if(s.has(String(a.startBinding?.elementId))&&(l.startBinding=null),s.has(String(a.endBinding?.elementId))&&(l.endBinding=null),Array.isArray(a.boundElements)){const c=a.boundElements.filter(u=>!s.has(String(u?.id)));c.length!==a.boundElements.length&&(l.boundElements=c)}return Object.keys(l).length>0?ed({...a,...l}):a}),await eo(n.editor,t,r),_n(t,r,{message:`Removed ${i-r.elements.length} element(s)`})},q2=async(n,e)=>{const t=String(e.blockId),r=Rn(n.editor,t),o=String(e.fromId),s=String(e.toId),i=new Set(r.elements.map(d=>String(d.id))),{elements:a,ids:l}=await td([{type:"arrow",x:0,y:0,...e.label?{label:e.label}:{},...e.strokeColor?{strokeColor:e.strokeColor}:{},...e.strokeStyle?{strokeStyle:e.strokeStyle}:{}}],i),c=l[0];r.elements=[...r.elements,...a];const u=r.elements.find(d=>d.id===c),f=pb(r,u,o,s);return r.elements=r.elements.map(d=>d.id===c?f:d),await eo(n.editor,t,r),_n(t,r,{createdIds:[c],message:`Connected '${o}' to '${s}'`})},V2=async(n,e)=>{const t=String(e.blockId),r=Rn(n.editor,t);return e.viewBackgroundColor!==void 0&&(r.appState.viewBackgroundColor=e.viewBackgroundColor),e.gridSize!==void 0&&(r.appState.gridSize=Number(e.gridSize)||null),await eo(n.editor,t,r),_n(t,r,{message:"Canvas updated"})},Y2=async(n,e)=>{const t=String(e.blockId),r=gb(n.editor,t),o=e.width===void 0?"inherit":Number(e.width),s=e.height===void 0?"inherit":Number(e.height);await new Promise(a=>{n.editor.update(()=>{r.setWidth(o),r.setHeight(s)},{onUpdate:()=>a()})});const i=Rn(n.editor,t);return _n(t,i,{message:o==="inherit"&&s==="inherit"?"Drawing sized to its content":`Drawing sized to ${o} x ${s}`})},X2=async(n,e)=>{const t=String(e.blockId),r=Rn(n.editor,t),o=Gs(r).length;return r.elements=[],r.files={},await eo(n.editor,t,r),_n(t,r,{message:`Emptied the drawing (${o} element(s) removed)`})},G2=async(n,e)=>{const{parseMermaidToExcalidraw:t}=await me(async()=>{const{parseMermaidToExcalidraw:c}=await import("./index-D6EjCeXV.js").then(u=>u.an);return{parseMermaidToExcalidraw:c}},[],import.meta.url),{convertToExcalidrawElements:r}=await me(async()=>{const{convertToExcalidrawElements:c}=await import("./percentages-BXMCSKIN-azlLrVPY.js").then(u=>u.i);return{convertToExcalidrawElements:c}},[],import.meta.url);let o;try{o=await t(String(e.mermaid),{fontSize:e.fontSize?Number(e.fontSize):void 0})}catch(c){const u=c instanceof Error?c.message:String(c);throw new Error(`That Mermaid source did not parse: ${u}. Flowcharts, sequence diagrams and class diagrams are the ones that convert to shapes.`,{cause:c})}const s=[...r(o.elements)],i=o.files??{};if(e.blockId){const c=String(e.blockId),u=Rn(n.editor,c);return u.elements=s,u.files=i,await eo(n.editor,c,u),_n(c,u,{createdIds:s.map(f=>String(f.id)),message:`Drawing replaced with ${s.length} element(s) from Mermaid`})}const a={elements:s,appState:{},files:i},l=await n.insertBlock({block_id:"",block_type:"excalidraw",source:"",metadata:{data:Zu(a)}},String(e.afterId??"BOTTOM"));if(!l.success||!l.blockId)throw new Error(l.error||"Failed to insert the drawing");return _n(l.blockId,a,{createdIds:s.map(c=>String(c.id)),message:`Drawing inserted with ${s.length} element(s) from Mermaid`})},bc={excalidrawInsertNode:U2,excalidrawListDrawings:z2,excalidrawReadScene:K2,excalidrawAddElements:W2,excalidrawUpdateElements:H2,excalidrawDeleteElements:J2,excalidrawConnectElements:q2,excalidrawSetAppState:V2,excalidrawResize:Y2,excalidrawClearScene:X2,excalidrawFromMermaid:G2};function tn(n,e){return{name:n,async execute(t,r){const o=Iw(e,t??{},n);if(!r.documentId)throw new Error(`Document ID is required for ${n}. Ensure the tool execution context includes a valid documentId.`);if(!r.executor)throw new Error(`Executor is required for ${n}. This should be provided by the platform (DefaultExecutor, BridgeExecutor, etc.)`);try{return await r.executor.execute(n,o)}catch(s){const i=s instanceof Error?s.message:String(s);throw new Error(`Failed to run ${n}: ${i}`,{cause:s})}}}}const Z2=tn("excalidrawInsertNode",tb),Q2=tn("excalidrawListDrawings",nb),eL=tn("excalidrawReadScene",rb),tL=tn("excalidrawAddElements",ob),nL=tn("excalidrawUpdateElements",sb),rL=tn("excalidrawDeleteElements",ib),oL=tn("excalidrawConnectElements",ab),sL=tn("excalidrawSetAppState",lb),iL=tn("excalidrawResize",cb),aL=tn("excalidrawClearScene",ub),lL=tn("excalidrawFromMermaid",db),Ei={excalidrawInsertNode:Z2,excalidrawListDrawings:Q2,excalidrawReadScene:eL,excalidrawAddElements:tL,excalidrawUpdateElements:nL,excalidrawDeleteElements:rL,excalidrawConnectElements:oL,excalidrawSetAppState:sL,excalidrawResize:iL,excalidrawClearScene:aL,excalidrawFromMermaid:lL},Ug={name:"excalidraw",definitions:fb,operations:Ei,handlers:bc};function YM(){const n=[];for(const e of fb)Ei[e.operation]||n.push(`${e.name} points at operation '${e.operation}', which does not exist`),e.toolReferenceName.startsWith("excalidraw")||n.push(`${e.name} is not named for the plugin it belongs to`);for(const e of Object.keys(Ei))bc[e]||n.push(`operation '${e}' has no handler`);for(const e of Object.keys(bc))Ei[e]||n.push(`handler '${e}' has no operation`);return n}const cL=S.lazy(()=>me(()=>import("./ExcalidrawModal-D3cbhMgF.js"),[],import.meta.url)),nd=he();function uL(){const[n]=fe(),[e,t]=S.useState(!1),o=M0()?.lexicalId;S.useEffect(()=>{if(!n.hasNodes([Yn]))throw new Error("ExcalidrawPlugin: ExcalidrawNode not registered");return n.registerCommand(nd,()=>(t(!0),!0),V)},[n]),S.useEffect(()=>{if(o)return go.getState().registerPluginTools(o,Ug),()=>{go.getState().unregisterPluginTools(o,Ug.name)}},[o]);const s=(l,c,u)=>{n.update(()=>{const f=ju();f.setData(JSON.stringify({elements:l,appState:c,files:u})),Tr([f]),wt(f.getParentOrThrow())&&Fc(f,ne).selectEnd()}),t(!1)},i=()=>{t(!1)},a=()=>{t(!1)};return e?x.jsx(S.Suspense,{fallback:null,children:x.jsx(cL,{initialElements:[],initialAppState:{},initialFiles:{},isShown:e,onSave:s,onDelete:i,onClose:a,closeOnClickOutside:!1})}):null}const dL=S.lazy(()=>me(()=>import("./DeckComponent-etBrFG87.js"),[],import.meta.url));function fL(){return{deck:{title:"Untitled deck",template:"datalayer"},slides:[{type:"title",title:"A new slide",meta:"Double-click to edit its specification"}]}}function gL(n){const e=n.getAttribute("data-lexical-deck");if(!e)return null;try{return{node:rd(JSON.parse(e))}}catch{return null}}class Go extends Jo{__spec;static getType(){return"deck"}static clone(e){return new Go(e.__spec,e.__format,e.__key)}static importJSON(e){const t=rd(e.spec);return t.setFormat(e.format),t}exportJSON(){return{...super.exportJSON(),type:"deck",version:1,spec:this.__spec}}static importDOM(){return{div:e=>e.hasAttribute("data-lexical-deck")?{conversion:gL,priority:2}:null}}exportDOM(){const e=document.createElement("div");e.setAttribute("data-lexical-deck",JSON.stringify(this.__spec));const t=document.createElement("p");return t.textContent=this.__spec.deck?.title||"Deck",e.appendChild(t),{element:e}}constructor(e,t,r){super(t,r),this.__spec=e??fL()}getSpec(){return this.getLatest().__spec}setSpec(e){this.getWritable().__spec=e}getTextContent(){return this.__spec.deck?.title||""}updateDOM(){return!1}decorate(e,t){const r=t.theme.embedBlock||{};return x.jsx(S.Suspense,{fallback:null,children:x.jsx(dL,{className:{base:r.base||"",focus:r.focus||""},format:this.__format,nodeKey:this.getKey(),spec:this.__spec})})}isTopLevel(){return!0}}function rd(n){return new Go(n)}function XM(n){return n instanceof Go}const od=he("INSERT_DECK_COMMAND");function pL(n){if(!n.hasNodes([Go]))throw new Error("DeckExtension: DeckNode not registered on editor");return n.registerCommand(od,e=>(sr(rd(e)),!0),V)}const hL=pe({name:"@datalayer/jupyter-lexical/Deck",nodes:()=>[Go],register:pL}),zg="Kept in this page’s memory only: it is lost when the page reloads, and nobody else sees it. Download it to keep it.",hb={position:"relative",width:"100%",aspectRatio:"16 / 9",borderRadius:2,overflow:"hidden",bg:"black"};function _L(n){const e=Math.max(0,Math.floor(n/1e3));return`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`}function mL(n){const e=n.currentTarget;if(Number.isFinite(e.duration))return;const t=()=>{e.removeEventListener("timeupdate",t),e.currentTime=0};e.addEventListener("timeupdate",t),e.currentTime=Number.MAX_SAFE_INTEGER}function bL({recordingId:n,recording:e}){const t=S.useRef(null),[r,o]=S.useState(()=>Date.now());return S.useEffect(()=>{t.current&&(t.current.srcObject=e.preview)},[e.preview]),S.useEffect(()=>{const s=window.setInterval(()=>o(Date.now()),500);return()=>window.clearInterval(s)},[]),x.jsxs(Y,{sx:{display:"grid",gap:2},children:[x.jsx(Y,{sx:hb,children:x.jsx("video",{ref:t,autoPlay:!0,muted:!0,playsInline:!0,style:{width:"100%",height:"100%",objectFit:"contain"}})}),x.jsxs(Y,{sx:{display:"flex",alignItems:"center",gap:2},children:[x.jsx(Y,{"aria-hidden":!0,sx:{width:10,height:10,borderRadius:"50%",bg:"danger.fg"}}),x.jsx(Le,{sx:{fontFamily:"mono"},"aria-live":"off",children:_L(r-e.startedAt)}),x.jsx(ft,{variant:"danger",leadingVisual:Nw,onClick:()=>Vu(n),sx:{ml:"auto"},children:"Stop"})]})]})}function yL({className:n,format:e,nodeKey:t,recordingId:r,recorded:o}){const[s]=fe(),i=Hr(),a=S.useSyncExternalStore($N,()=>DN(r)),l=HN(o,a),[c,u]=S.useState("screen"),[f,d]=S.useState(!0),g=S.useCallback(w=>{s.update(()=>{const C=Q(t);_b(C)&&C.setRecorded(w)})},[s,t]),h=()=>{KN(r,{source:c,microphone:f},()=>g(!0))},_=()=>{WN(r),g(!1)},m=w=>{const C=document.createElement("a");C.href=w.url,C.download=BN(w),C.click()};let y;return a?.status==="recording"?y=x.jsx(bL,{recordingId:r,recording:a}):a?.status==="recorded"?y=x.jsxs(Y,{sx:{display:"grid",gap:2},children:[x.jsx(Y,{sx:hb,children:x.jsx("video",{src:a.url,controls:!0,playsInline:!0,onLoadedMetadata:mL,style:{width:"100%",height:"100%",objectFit:"contain"}})}),x.jsxs(Y,{sx:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:2},children:[x.jsx(Le,{sx:{color:"fg.muted",fontSize:0,flex:"1 1 240px"},children:zg}),x.jsx(ft,{leadingVisual:Ew,onClick:()=>m(a),children:"Download"}),i&&x.jsx(ft,{onClick:_,children:"Record again"})]})]}):l==="lost"?y=x.jsxs(Y,{sx:{display:"grid",gap:2,justifyItems:"start"},children:[x.jsx(Le,{sx:{color:"fg.muted",fontSize:1},children:"The video recorded here is gone: it was kept in the memory of the page that recorded it, and that page has been reloaded or closed."}),i&&x.jsx(ft,{onClick:()=>g(!1),children:"Record a new one"})]}):i?y=x.jsxs(Y,{sx:{display:"grid",gap:2},children:[x.jsxs(Y,{sx:{display:"flex",alignItems:"center",gap:2},children:[x.jsx(Wc,{size:16}),x.jsx(Le,{sx:{fontWeight:"bold"},children:"Video"})]}),x.jsxs(Le,{sx:{color:"fg.muted",fontSize:0},children:["Recorded by this browser, with no account. ",zg]}),jN()?x.jsxs(Y,{sx:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:3},children:[x.jsxs(Aa,{"aria-label":"What to record",size:"small",children:[x.jsx(Aa.Button,{selected:c==="screen",onClick:()=>u("screen"),children:"Screen"}),x.jsx(Aa.Button,{selected:c==="camera",onClick:()=>u("camera"),children:"Camera"})]}),x.jsxs(Mt,{children:[x.jsx(Mp,{checked:f,onChange:w=>d(w.target.checked)}),x.jsx(Mt.Label,{children:"Microphone"})]}),x.jsx(ft,{variant:"primary",onClick:h,children:"Record"})]}):x.jsx(Le,{sx:{color:"danger.fg",fontSize:1},children:"This browser cannot record video."}),a?.status==="failed"&&x.jsx(Le,{role:"alert",sx:{color:"danger.fg",fontSize:1},children:a.message})]}):y=x.jsx(Le,{as:"p",sx:{color:"fg.muted",fontSize:1,m:0},children:"A video goes here."}),x.jsx(Ls,{className:n,format:e,nodeKey:t,children:x.jsx(Y,{"data-lexical-video":l,onFocusCapture:()=>s.update(()=>Ee(null)),sx:{p:l==="recorded"||l==="recording"?0:3,border:"1px dashed",borderColor:l==="recorded"||l==="recording"?"transparent":"border.default",borderRadius:2,bg:l==="recorded"||l==="recording"?"transparent":"canvas.subtle"},children:y})})}class Zn extends Jo{__recordingId;__recorded;static getType(){return"video"}static clone(e){return new Zn(e.__recordingId,e.__recorded,e.__format,e.__key)}static importJSON(e){const t=new Zn(e.recordingId,e.recorded);return t.setFormat(e.format),t}exportJSON(){return{...super.exportJSON(),type:"video",version:1,recordingId:this.__recordingId,recorded:this.__recorded}}exportDOM(){return{element:null}}constructor(e,t=!1,r,o){super(r,o),this.__recordingId=e||PN(),this.__recorded=t}getRecordingId(){return this.getLatest().__recordingId}isRecorded(){return this.getLatest().__recorded}setRecorded(e){this.getWritable().__recorded=e}getTextContent(){return""}updateDOM(){return!1}decorate(e,t){const r=t.theme.embedBlock||{};return x.jsx(yL,{className:{base:r.base||"",focus:r.focus||""},format:this.__format,nodeKey:this.getKey(),recordingId:this.__recordingId,recorded:this.__recorded})}isTopLevel(){return!0}}function wL(){return new Zn}function _b(n){return n instanceof Zn}const sd=he("INSERT_VIDEO_COMMAND");function xL(n){if(!n.hasNodes([Zn]))throw new Error("VideoExtension: VideoNode not registered on editor");return de(n.registerCommand(sd,()=>(sr(wL()),!0),V),n.registerMutationListener(Zn,(e,{prevEditorState:t})=>{for(const[r,o]of e){if(o!=="destroyed")continue;const s=t.read(()=>{const i=Q(r);return _b(i)?i.__recordingId:void 0});s&&Vu(s)}},{skipInitialization:!0}))}const CL=pe({name:"@datalayer/jupyter-lexical/Video",nodes:()=>[Zn],register:xL});function SL({onConfirm:n,onClose:e}){const[t,r]=S.useState("5"),[o,s]=S.useState("5"),i=S.useRef(null),a=()=>{const c=parseInt(t,10),u=parseInt(o,10);c>0&&c<=500&&u>0&&u<=50&&n(c,u)},l=c=>{c.key==="Enter"&&a()};return x.jsx($p,{title:"Insert Table",onClose:()=>e(),width:"small",height:"auto",initialFocusRef:i,footerButtons:[{buttonType:"default",content:"Cancel",onClick:e},{buttonType:"primary",content:"Confirm",onClick:a}],children:x.jsxs(Y,{sx:{display:"flex",flexDirection:"column",gap:3},onKeyDown:l,children:[x.jsxs(Mt,{children:[x.jsx(Mt.Label,{children:"Rows"}),x.jsx(kn,{ref:i,type:"number",min:1,max:500,value:t,onChange:c=>r(c.target.value),block:!0})]}),x.jsxs(Mt,{children:[x.jsx(Mt.Label,{children:"Columns"}),x.jsx(kn,{type:"number",min:1,max:50,value:o,onChange:c=>s(c.target.value),block:!0})]})]})})}const ws=he();function mb(){const[n]=fe(),[e,t]=S.useState(!1);S.useEffect(()=>n.registerCommand(ws,()=>(t(!0),!0),V),[n]);const r=(s,i)=>{n.dispatchCommand(nu,{rows:s.toString(),columns:i.toString()}),t(!1)},o=()=>{t(!1)};return e?x.jsx(SL,{onConfirm:r,onClose:o}):null}function GM(){return x.jsxs(x.Fragment,{children:[x.jsx(P_,{}),x.jsx(mb,{})]})}const id=he("INSERT_EQUATION_COMMAND");function bb(n){if(!n.hasNodes([ir]))throw new Error("EquationsPlugins: EquationsNode not registered on editor");return n.registerCommand(id,e=>{const{equation:t,inline:r}=e,o=ya(t,r);return Tr([o]),wt(o.getParentOrThrow())&&Fc(o,ne).selectEnd(),!0},V)}const yb=pe({name:"@datalayer/jupyter-lexical/Equations",nodes:()=>[ir],register:bb});function ad({activeEditor:n,onClose:e}){const t=S.useCallback((r,o)=>{n.dispatchCommand(id,{equation:r,inline:o}),e()},[n,e]);return x.jsx(Vx,{onConfirm:t})}const Kg=()=>{const[n]=fe();return S.useEffect(()=>bb(n),[n]),null},vL=Object.freeze(Object.defineProperty({__proto__:null,EquationsPlugin:Kg,INSERT_EQUATION_COMMAND:id,InsertEquationDialog:ad,default:Kg},Symbol.toStringTag,{value:"Module"}));class Ke extends Wm{title;icon;keywords;keyboardShortcut;onSelect;disabled;constructor(e,t){super(e),this.title=e,this.keywords=t.keywords||[],this.icon=t.icon,this.keyboardShortcut=t.keyboardShortcut,this.onSelect=t.onSelect.bind(this),this.disabled=t.disabled||!1}}function kL({index:n,isSelected:e,onClick:t,onMouseEnter:r,option:o}){const s=S.useCallback(l=>o.setRefElement(l),[o]),i=o.disabled?void 0:t,a=o.disabled?void 0:r;return x.jsxs(Y,{as:"li",tabIndex:-1,ref:s,role:"option","aria-selected":e&&!o.disabled,"aria-disabled":o.disabled,id:"typeahead-item-"+n,onMouseEnter:a,onClick:i,sx:{display:"flex",alignItems:"center",gap:2,px:2,py:"6px",borderRadius:2,cursor:o.disabled?"not-allowed":"pointer",opacity:o.disabled?.5:1,bg:e&&!o.disabled?"actionListItem.default.selectedBg":"transparent",color:"var(--fgColor-default)","&:hover":o.disabled?{}:{bg:"actionListItem.default.hoverBg"},listStyle:"none"},children:[x.jsx(Y,{sx:{display:"flex",alignItems:"center",color:"var(--fgColor-muted)",flexShrink:0},children:o.icon}),x.jsx(Le,{sx:{fontSize:1},children:o.title})]},o.key)}const TL=({kernel:n,initCode:e=""}={})=>{const[t]=fe(),[r,o]=Xo(),[s,i]=S.useState(null),a=Hm("/",{minLength:0}),l=S.useCallback(()=>{const f=[];if(s==null)return f;const d=new RegExp(/^([1-9]|10)x([1-9]|10)$/),g=new RegExp(/^([1-9]|10)x?$/),h=d.exec(s),_=g.exec(s);if(h){const[m,y]=h[0].split("x").map(w=>parseInt(w,10));f.push(new Ke(`${m}x${y} Table`,{icon:x.jsx(yi,{size:16}),keywords:["table"],onSelect:()=>t.dispatchCommand(ws,void 0)}))}else if(_){const m=parseInt(_[0],10);f.push(...Array.from({length:5},(y,w)=>w+1).map(y=>new Ke(`${m}x${y} Table`,{icon:x.jsx(yi,{size:16}),keywords:["table"],onSelect:()=>t.dispatchCommand(ws,void 0)})))}return f},[t,s]),c=S.useMemo(()=>{const f=[new Ke("Jupyter Cell",{icon:x.jsx(br,{size:16}),keywords:["javascript","python","js","codeblock","jupyter"],onSelect:()=>{t.dispatchCommand(Vi,{code:e,outputs:ac,loading:"Loading..."})}}),new Ke("Marimo Cell",{icon:x.jsx(br,{size:16}),keywords:["marimo","reactive","python","cell"],onSelect:()=>{t.dispatchCommand(Vi,{code:e,outputs:ac,loading:"Loading...",variant:"marimo"})}}),new Ke("Paragraph",{icon:x.jsx(Ih,{size:16}),keywords:["normal","paragraph","p","text"],onSelect:()=>t.update(()=>{const g=D();F(g)&&Un(g,()=>ne())})}),...Array.from({length:3},(g,h)=>h+1).map(g=>new Ke(`Heading ${g}`,{icon:x.jsx(tx,{size:16}),keywords:["heading","header",`h${g}`],onSelect:()=>t.update(()=>{const h=D();F(h)&&Un(h,()=>fn(`h${g}`))})})),new Ke("Numbered List",{icon:x.jsx(Eh,{size:16}),keywords:["numbered list","ordered list","ol"],onSelect:()=>t.dispatchCommand(eu,void 0)}),new Ke("Bulleted List",{icon:x.jsx(vh,{size:16}),keywords:["bulleted list","unordered list","ul"],onSelect:()=>t.dispatchCommand(Qc,void 0)}),new Ke("Check List",{icon:x.jsx(Lw,{size:16}),keywords:["check list","todo list"],onSelect:()=>t.dispatchCommand(Zc,void 0)}),new Ke("Table",{icon:x.jsx(yi,{size:16}),keywords:["table","grid","spreadsheet"],onSelect:()=>{ge("[ComponentPicker] Table selected, dispatching INSERT_TABLE_WITH_DIALOG_COMMAND"),t.dispatchCommand(ws,void 0)}}),new Ke("Collapsible Container",{icon:x.jsx(zc,{size:16}),keywords:["collapsible","collapse","expand","toggle","accordion","container"],onSelect:()=>t.dispatchCommand(Xu,void 0)}),new Ke("Excalidraw",{icon:x.jsx(Ow,{size:16}),keywords:["excalidraw","drawing","diagram","sketch","whiteboard","draw"],onSelect:()=>t.dispatchCommand(nd,void 0)}),new Ke("Video",{icon:x.jsx(Wc,{size:16}),keywords:["video","record","recording","screen","camera","webcam"],onSelect:()=>t.dispatchCommand(sd,void 0)}),new Ke("Loom Video",{icon:x.jsx(Ws,{size:16}),keywords:["loom","video","record","recording","screen"],onSelect:()=>t.dispatchCommand(ka,void 0)}),new Ke("Deck Slide",{icon:x.jsx(hs,{size:16}),keywords:["deck","slide","slides","presentation","pitch"],onSelect:()=>t.dispatchCommand(od,void 0)}),new Ke("Quote",{icon:x.jsx(Nh,{size:16}),keywords:["block quote"],onSelect:()=>t.update(()=>{const g=D();F(g)&&Un(g,()=>Ln())})}),new Ke("Code",{icon:x.jsx(br,{size:16}),keywords:["javascript","python","js","codeblock"],onSelect:()=>t.update(()=>{const g=D();if(F(g))if(g.isCollapsed())Un(g,()=>Ze());else{const h=g.getTextContent(),_=Ze();g.insertNodes([_]),g.insertRawText(h)}})}),new Ke("Divider",{icon:x.jsx(ji,{size:16}),keywords:["horizontal rule","divider","hr"],onSelect:()=>t.dispatchCommand(Kc,void 0)}),...qu.map(g=>new Ke(`Embed ${g.contentName}`,{icon:g.icon,keywords:[...g.keywords,"embed"],onSelect:()=>t.dispatchCommand(Ju,g.type)})),new Ke("Equation",{icon:x.jsx(Rw,{size:16}),keywords:["equation","latex","math"],onSelect:()=>o("Insert Equation",g=>x.jsx(ad,{activeEditor:t,onClose:g}))}),new Ke("GIF",{icon:x.jsx(hs,{size:16}),keywords:["gif","animate","image","file"],onSelect:()=>{yu().then(g=>{g&&t.dispatchCommand(Ys,g)})}}),new Ke("Image",{icon:x.jsx(hs,{size:16}),keywords:["image","photo","picture","file"],onSelect:()=>o("Insert Image",g=>x.jsx(z_,{activeEditor:t,onClose:g}))}),...["left","center","right","justify"].map(g=>new Ke(`Align ${g}`,{icon:g==="left"?x.jsx(nx,{size:16}):g==="right"?x.jsx(rx,{size:16}):x.jsx(ji,{size:16}),keywords:["align","justify",g],onSelect:()=>t.dispatchCommand(Bn,g)}))],d=l();return s?[...d,...f.filter(g=>new RegExp(s,"gi").exec(g.title)||g.keywords!=null?g.keywords.some(h=>new RegExp(s,"gi").exec(h)):!1)]:f},[t,l,s,o,n,e]),u=S.useCallback((f,d,g,h)=>{f.disabled||t.update(()=>{d&&d.remove(),f.onSelect(h),g()})},[t]);return x.jsxs(x.Fragment,{children:[r,x.jsx(Jm,{onQueryChange:i,onSelectOption:u,triggerFn:a,options:c,menuRenderFn:(f,{selectedIndex:d,selectOptionAndCleanUp:g,setHighlightedIndex:h})=>f.current&&c.length?St.createPortal(x.jsx(Y,{onMouseDown:_=>{_.preventDefault()},sx:{position:"relative",zIndex:1e3,bg:"var(--overlay-bgColor)",border:"1px solid",borderColor:"var(--borderColor-default)",borderRadius:2,boxShadow:"var(--shadow-floating-large, 0 0 0 1px #d1d9e0, 0 40px 80px 0 #25292e3d)",p:1,maxHeight:300,overflow:"auto",minWidth:200},children:x.jsx(Y,{as:"ul",sx:{listStyle:"none",m:0,p:0},children:c.map((_,m)=>x.jsx(kL,{index:m,isSelected:d===m,onClick:()=>{_.disabled||(h(m),g(_))},onMouseEnter:()=>{_.disabled||h(m)},option:_},_.key))})}),f.current):null})]})},yc=4,IL=2,EL="draggable-block-menu",Wg="application/x-lexical-drag-block",Hg=28,NL=1,LL=-1,Jg=0;let Ni=1/0;function OL(n){return n===0?1/0:Ni>=0&&Ni<n?Ni:Math.floor(n/2)}function RL(n){return n.getEditorState().read(()=>se().getChildrenKeys())}function wb(n){const e=(l,c)=>l?parseFloat(window.getComputedStyle(l)[c]):0,{marginTop:t,marginBottom:r}=window.getComputedStyle(n),o=e(n.previousElementSibling,"marginBottom"),s=e(n.nextElementSibling,"marginTop"),i=Math.max(parseFloat(t),o);return{marginBottom:Math.max(parseFloat(r),s),marginTop:i}}function _l(n,e,t,r=!1){const o=n.getBoundingClientRect(),s=RL(e);let i=null;return e.getEditorState().read(()=>{if(r){const[c,u]=[e.getElementByKey(s[0]),e.getElementByKey(s[s.length-1])],[f,d]=[c?.getBoundingClientRect(),u?.getBoundingClientRect()];if(f&&d){const g=Wn(c),h=Wn(u);if(t.y/g<f.top?i=c:t.y/h>d.bottom&&(i=u),i)return}}let a=OL(s.length),l=Jg;for(;a>=0&&a<s.length;){const c=s[a],u=e.getElementByKey(c);if(u===null)break;const f=Wn(u),d=new zm(t.x/f,t.y/f),g=pr.fromDOM(u),{marginTop:h,marginBottom:_}=wb(u),m=g.generateNewRect({bottom:g.bottom+_,left:o.left,right:o.right,top:g.top-h}),{result:y,reason:{isOnTopSide:w,isOnBottomSide:C}}=m.contains(d);if(y){i=u,Ni=a;break}l===Jg&&(w?l=LL:C?l=NL:l=1/0),a+=l}}),i}function AL(n){return!!n.closest(`.${EL}`)}function xb(n){const e=window.getComputedStyle(n),t=e.overflowY==="auto"||e.overflowY==="scroll",r=e.overflowX==="auto"||e.overflowX==="scroll";if(t||r)return{element:n,scrollTop:n.scrollTop||0,scrollLeft:n.scrollLeft||0};const o=n.parentElement;if(o){const s=window.getComputedStyle(o),i=s.overflowY==="auto"||s.overflowY==="scroll",a=s.overflowX==="auto"||s.overflowX==="scroll";if(i||a)return{element:o,scrollTop:o.scrollTop||0,scrollLeft:o.scrollLeft||0}}return{element:n,scrollTop:0,scrollLeft:0}}function ML(n,e,t){if(!n){e.style.opacity="0",e.style.transform="translate(-10000px, -10000px)";return}const r=n.getBoundingClientRect(),o=window.getComputedStyle(n),s=e.getBoundingClientRect(),i=t.getBoundingClientRect(),{scrollTop:a}=xb(t),c=(parseInt(o.lineHeight,10)-s.height)/2,u=r.top+c-i.top+a,f=yc;e.style.opacity="1",e.style.transform=`translate(${f}px, ${u}px)`}function $L(n,e){const{transform:t}=e.style;e.style.transform="translateZ(0)",n.setDragImage(e,0,0),setTimeout(()=>{e.style.transform=t})}function DL(n,e,t,r){const{top:o,height:s}=e.getBoundingClientRect(),{top:i,width:a}=r.getBoundingClientRect(),{marginTop:l,marginBottom:c}=wb(e),{scrollTop:u}=xb(r);let f=o;t>=o?f+=s+c/2:f-=l/2;const d=f-i-IL+u,g=Hg-yc;n.style.transform=`translate(${g}px, ${d}px)`,n.style.width=`${a-(Hg-yc)*2}px`,n.style.opacity=".4"}function PL(n){n&&(n.style.opacity="0",n.style.transform="translate(-10000px, -10000px)")}function jL(n,e,t){const r=S.useRef(null),o=S.useRef(null),s=S.useRef(!1),[i,a]=S.useState(null),l=n._config.theme,c=l.draggableBlockMenu||"",u=l.draggableBlockTargetLine||"";S.useEffect(()=>{function g(_){const m=_.target;if(!pl(m)){a(null);return}if(!e.contains(m)||AL(m))return;const y=_l(e,n,_);a(y)}function h(){a(null)}return document.addEventListener("mousemove",g),document.addEventListener("mouseleave",h),()=>{document.removeEventListener("mousemove",g),document.removeEventListener("mouseleave",h)}},[e,n]),S.useEffect(()=>{r.current&&ML(i,r.current,e)},[e,i]),S.useEffect(()=>{function g(_){if(!s.current)return!1;const[m]=uo(_);if(m)return!1;const{pageY:y,target:w}=_;if(!pl(w))return!1;const C=_l(e,n,_,!0),v=o.current;return C===null||v===null?!1:(DL(v,C,y/Wn(w),e),_.preventDefault(),!0)}function h(_){if(!s.current)return!1;const[m]=uo(_);if(m)return!1;const{target:y,dataTransfer:w,pageY:C}=_,v=w?.getData(Wg)||"",k=Q(v);if(!k||!pl(y))return!1;const I=_l(e,n,_,!0);if(!I)return!1;const E=Me(I);if(!E)return!1;if(E===k)return!0;const N=I.getBoundingClientRect().top;return C/Wn(y)>=N?E.insertAfter(k):E.insertBefore(k),a(null),!0}return de(n.registerCommand(Nc,_=>g(_),ee),n.registerCommand(Lc,_=>h(_),qe))},[e,n]);function f(g){const h=g.dataTransfer;if(!h||!i)return;$L(h,i);let _="";n.update(()=>{const m=Me(i);m&&(_=m.getKey())}),s.current=!0,h.setData(Wg,_)}function d(){s.current=!1,PL(o.current)}return St.createPortal(x.jsxs(x.Fragment,{children:[x.jsx("div",{className:`draggable-block-menu ${c}`,ref:r,draggable:!0,onDragStart:f,onDragEnd:d,children:t?x.jsx(Aw,{size:16}):null}),x.jsx("div",{className:`draggable-block-target-line ${u}`,ref:o})]}),e)}function ZM({anchorElem:n=document.body}){const[e]=fe();return jL(e,n,e._editable)}const FL=()=>x.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor",children:[x.jsx("path",{d:"M4.5 2v5.5a3.5 3.5 0 1 0 7 0V2H13v5.5a5 5 0 0 1-10 0V2h1.5Z"}),x.jsx("rect",{x:"2",y:"14",width:"12",height:"1.5",rx:".75"})]});function BL(n,e,t,r){const[o,s]=S.useState(!1),[i,a]=S.useState(!1),[l,c]=S.useState(!1),[u,f]=S.useState(!1),[d,g]=S.useState(!1),[h,_]=S.useState(!1),[m,y]=S.useState(!1),[w,C]=S.useState(!1),[v,k]=S.useState(!1),I=S.useCallback(()=>{n.getEditorState().read(()=>{if(n.isComposing())return;const M=D(),R=window.getSelection(),$=n.getRootElement();if(R!==null&&(!F(M)||$===null||!$.contains(R.anchorNode))){s(!1);return}if(!F(M))return;const L=Bm(M);c(M.hasFormat("bold")),f(M.hasFormat("italic")),g(M.hasFormat("underline")),_(M.hasFormat("strikethrough")),y(M.hasFormat("subscript")),C(M.hasFormat("superscript")),k(M.hasFormat("code"));const A=L.getParent();Pe(A)||Pe(L)?a(!0):a(!1),!Ve(M.anchor.getNode())&&M.getTextContent()!==""?s(oe(L)):s(!1)})},[n]);S.useEffect(()=>(document.addEventListener("selectionchange",I),()=>{document.removeEventListener("selectionchange",I)}),[I]),S.useEffect(()=>de(n.registerUpdateListener(()=>{I()}),n.registerRootListener(()=>{n.getRootElement()===null&&s(!1)}),n.registerCommand(ys,()=>(s(!1),!1),ee)),[n,I]);const E=S.useCallback(()=>{i?(t(!1),n.dispatchCommand(Lr,null)):(t(!0),n.dispatchCommand(Lr,"https://example.com"))},[n,i,t]),N=S.useMemo(()=>n.isEditable()?[{key:"bold",type:"button",order:0,ariaLabel:"Format text as bold",title:"Bold",icon:Lh,isActive:l,onClick:()=>n.dispatchCommand(Ge,"bold")},{key:"italic",type:"button",order:1,ariaLabel:"Format text as italics",title:"Italic",icon:Oh,isActive:u,onClick:()=>n.dispatchCommand(Ge,"italic")},{key:"underline",type:"button",order:2,ariaLabel:"Format text to underlined",title:"Underline",icon:FL,isActive:d,onClick:()=>n.dispatchCommand(Ge,"underline")},{key:"strikethrough",type:"button",order:3,ariaLabel:"Format text with a strikethrough",title:"Strikethrough",icon:Rh,isActive:h,onClick:()=>n.dispatchCommand(Ge,"strikethrough")},{key:"subscript",type:"button",order:4,ariaLabel:"Format Subscript",title:"Subscript",icon:void 0,label:"x₂",isActive:m,onClick:()=>n.dispatchCommand(Ge,"subscript")},{key:"superscript",type:"button",order:5,ariaLabel:"Format Superscript",title:"Superscript",icon:void 0,label:"x²",isActive:w,onClick:()=>n.dispatchCommand(Ge,"superscript")},{key:"code",type:"button",order:6,ariaLabel:"Insert code block",title:"Code",icon:br,isActive:v,onClick:()=>n.dispatchCommand(Ge,"code")},{key:"link",type:"button",order:7,ariaLabel:"Insert link",title:"Link",icon:Ah,isActive:i,onClick:E},{key:"comment",type:"button",order:8,ariaLabel:"Insert comment",title:"Comment",icon:Pi,onClick:()=>n.dispatchCommand(ys,void 0)}]:[{key:"comment",type:"button",order:100,ariaLabel:"Insert comment",icon:Pi,onClick:()=>n.dispatchCommand(ys,void 0)}],[n,l,u,d,h,m,w,v,i,E]),O=o&&!i;return x.jsx(Tx,{items:N,extraItems:r,anchorElement:e,isVisible:O,ariaLabel:"Floating text format toolbar"})}function QM({anchorElem:n=document.body,setIsLinkEditMode:e,extraItems:t}){const[r]=fe();return BL(r,n,e,t)}function UL(n){return n.registerCommand(Kc,()=>{const e=D();if(!F(e))return!1;if(e.focus.getNode()!==null){const r=ba();e.insertParagraph(),e.focus.getNode().getTopLevelElementOrThrow().insertBefore(r)}return!0},V)}const Cb=pe({name:"@datalayer/jupyter-lexical/HorizontalRule",nodes:()=>[mu],register:UL}),ss={code:{triggerMode:"auto",contextBefore:-1,contextAfter:-1,language:"python"},prose:{triggerMode:"manual",contextBefore:-1,contextAfter:-1},debounceMs:200,manualTriggerKey:"Cmd+Shift+,"};function zL(n){return n?{code:{...ss.code,...n.code},prose:{...ss.prose,...n.prose},debounceMs:n.debounceMs??ss.debounceMs,manualTriggerKey:n.manualTriggerKey??ss.manualTriggerKey}:{...ss}}function e$(n){return n===-1||n>=0}function t$(n){return n.triggerMode==="auto"}function n$(n){return n.triggerMode==="manual"||n.triggerMode==="auto"}function r$(n){return n.triggerMode==="disabled"}const qg="jupyter-cell";class Fr extends Bt{__code;__outputs;__loading;__autoStart;__data;__variant;static getType(){return qg}static clone(e){return console.debug(`clone: node: ${JSON.stringify(e,null,2)}`),new Fr(e.__code,e.__outputs,e.__loading,e.__autoStart,e.__data,e.__key,e.__variant)}constructor(e,t,r,o,s="[]",i,a){super(i),this.__code=e,this.__outputs=t,this.__loading=r,this.__autoStart=o,this.__data=s,this.__variant=a}createDOM(e){const t=document.createElement("div"),o=e.theme.image;return o!==void 0&&(t.className=o),ge("createDOM",t),t}updateDOM(){return!1}decorate(e){return ge(`decorate -> key: ${this.getKey()} outputs: ${this.__outputs} data: ${this.__data}`),x.jsx(_x,{source:this.__code,outputs:this.__outputs,autoStart:this.__autoStart,variant:this.__variant})}setCode(e){const t=this.getWritable();t.__code=e}get code(){return this.__code}setOutputs(e){const t=this.getWritable();t.__outputs=e}get outputs(){return this.__outputs}setLoading(e){const t=this.getWritable();t.__loading=e}get loading(){return this.__loading}setAutostart(e){const t=this.getWritable();t.__autoStart=e}get autoStart(){return this.__autoStart}get variant(){return this.__variant}setData(e){const t=this.getWritable();t.__data=e}get data(){return this.__data}static importJSON(e){const t=e;return new Fr(t.code,t.outputs,t.loading,t.autoStart,t.data,void 0,t.variant)}exportJSON(){return{code:this.__code,outputs:this.__outputs,loading:this.__loading,autoStart:this.__autoStart,data:this.__data,variant:this.__variant,type:qg,version:1}}}function Vg(n){const{code:e,outputs:t,loading:r,autoStart:o}=n;return new Fr(e,t,r,o)}function o$(n){return n instanceof Fr}const KL=he(),WL=he();function HL(n){if(!n.hasNodes([Fr]))throw new Error("JupyterCellNode is not registered.");return de(n.registerCommand(KL,e=>{const t=Vg(e);return Tr([t]),!0},V),n.registerCommand(WL,e=>{const t=Vg({...e});return Tr([t]),!0},V))}const JL=pe({name:"@datalayer/jupyter-lexical/JupyterCell",nodes:()=>[Fr],register:HL}),qL=he("INSERT_LAYOUT_COMMAND");function VL(n){return n.trim().split(/\s+/).length}function s$(n){return Array.from({length:Math.max(1,n)},()=>"1fr").join(" ")}function YL(n){if(!n.hasNodes([Dr,Pr]))throw new Error("LayoutPlugin: LayoutContainerNode, or LayoutItemNode not registered on editor");const e=t=>{const r=D();if(F(r)&&r.isCollapsed()&&r.anchor.offset===0){const o=re(r.anchor.getNode(),Ci);if(Ci(o)){const s=o.getParent(),i=s&&(t?s.getFirstChild():s.getLastChild()),a=t?o.getFirstDescendant()?.getKey():o.getLastDescendant()?.getKey();s!==null&&i===o&&r.anchor.key===a&&(t?o.insertBefore(ne()):o.insertAfter(ne()))}}return!1};return de(n.registerCommand(Vt,()=>e(!1),ee),n.registerCommand(ia,()=>e(!1),ee),n.registerCommand(pt,()=>e(!0),ee),n.registerCommand(zs,()=>e(!0),ee),n.registerCommand(qL,t=>(n.update(()=>{const r=Ou(t);for(let o=0;o<VL(t);o++)r.append(Ru().append(ne()));sr(r),r.selectStart()}),!0),V),n.registerNodeTransform(Pr,t=>{const r=t.getParent();if(!Ci(r)){for(const o of t.getChildren())t.insertBefore(o);t.remove();return}t.isEmpty()&&t.append(ne())}),n.registerNodeTransform(Dr,t=>{const r=t.getChildren();if(!r.every(Au)){for(const o of r)t.insertBefore(o);t.remove();return}r.length===0&&t.remove()}))}const XL=pe({name:"@datalayer/jupyter-lexical/Layout",nodes:()=>[Dr,Pr],register:YL});function Yg(n,e,t,r,o){return n==="code"?GL(e,t):ZL(e,t,r,o)}function GL(n,e){const t=n.getTextContent(),r=tO(n,e),o=t.substring(0,r),s=t.substring(r);return{before:o,after:s,fullText:t}}function ZL(n,e,t,r){const s=se().getChildren(),i=QL(n);if(!i)return{before:"",after:"",fullText:""};const a=s.indexOf(i);if(a===-1)return{before:"",after:"",fullText:""};const l=t===-1?0:Math.max(0,a-t),c=r===-1?s.length-1:Math.min(s.length-1,a+r);let u="";for(let _=l;_<a;_++)u+=s[_].getTextContent()+`
215
215
  `;const f=i.getTextContent(),d=eO(i,e);u+=f.substring(0,d);let g=f.substring(d);for(let _=a+1;_<=c;_++)g+=`
216
216
  `+s[_].getTextContent();const h=u+g;return{before:u,after:g,fullText:h}}function QL(n){let e=n;for(;e;){if(ht(e)||e.getType()==="heading"||e.getType()==="listitem")return e;e=e.getParent()}return se()}function eO(n,e){try{const t=n.getFirstDescendant(),r=t?t.getKey():n.getKey(),o=0,s=t?"text":"element",i=e.clone();return i.anchor.set(r,o,s),i.focus.set(e.anchor.key,e.anchor.offset,e.anchor.type),i.getTextContent().length}catch(t){return console.error("[ContextExtractor] Error getting cursor offset:",t),0}}function tO(n,e){try{const t=n.getFirstDescendant(),r=t?t.getKey():n.getKey(),o=0,s=t?"text":"element",i=e.clone();return i.anchor.set(r,o,s),i.focus.set(e.anchor.key,e.anchor.offset,e.anchor.type),i.getTextContent().length}catch(t){return console.error("[ContextExtractor] Error getting cursor offset:",t),0}}function nO(n){switch(n){case 1:case 2:return"𝑓";case 5:return"𝑥";case 6:return"C";case 8:return"M";case 9:return"∙";case 13:return"🔑";default:return"•"}}function rO(n,e){if(!e||e.length===0)return x.jsx(x.Fragment,{children:n});const t=n.toLowerCase(),r=e.toLowerCase(),o=t.indexOf(r);if(o===-1)return x.jsx(x.Fragment,{children:n});const s=n.substring(0,o),i=n.substring(o,o+e.length),a=n.substring(o+e.length);return x.jsxs(x.Fragment,{children:[s,x.jsx("strong",{style:{color:"var(--vscode-editorSuggestWidget-highlightForeground)",fontWeight:"bold"},children:i}),a]})}function oO({items:n,onSelect:e,onClose:t,position:r,filterText:o}){const[s,i]=S.useState(0),[a,l]=S.useState(r),c=S.useRef(null),u=S.useRef([]),f=S.useRef(null);return S.useEffect(()=>{const d=window.getSelection();if(d&&d.rangeCount>0){const g=d.getRangeAt(0);f.current=g.startContainer.parentElement}},[]),S.useEffect(()=>{const d=()=>{const g=window.getSelection();if(!g||g.rangeCount===0)return;const _=g.getRangeAt(0).getBoundingClientRect();l({top:_.bottom+window.scrollY,left:_.left+window.scrollX})};return window.addEventListener("scroll",d,!0),()=>window.removeEventListener("scroll",d,!0)},[]),S.useEffect(()=>{const d=u.current[s];d&&d.scrollIntoView({block:"nearest"})},[s]),S.useEffect(()=>{const d=g=>{switch(g.key){case"ArrowDown":g.preventDefault(),i(h=>Math.min(h+1,n.length-1));break;case"ArrowUp":g.preventDefault(),i(h=>Math.max(h-1,0));break;case"Enter":g.preventDefault(),n[s]&&e(n[s]);break;case"Escape":g.preventDefault(),t();break;case"Tab":g.preventDefault(),n[s]&&e(n[s]);break}};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[s,n,e,t]),S.useEffect(()=>{const d=g=>{c.current&&!c.current.contains(g.target)&&t()};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[t]),n.length===0?x.jsx(x.Fragment,{}):x.jsx("div",{ref:c,style:{position:"fixed",top:`${a.top}px`,left:`${a.left}px`,zIndex:1e4,background:"var(--vscode-editorSuggestWidget-background)",border:"1px solid var(--vscode-editorSuggestWidget-border)",borderRadius:"4px",boxShadow:"var(--shadow-resting-medium, 0 1px 1px 0 #25292e1a, 0 3px 6px 0 #25292e1f)",maxHeight:"300px",overflowY:"auto",minWidth:"300px"},children:x.jsx("ul",{style:{listStyle:"none",margin:0,padding:"4px 0"},children:n.map((d,g)=>{const h=g===s;return x.jsxs("li",{ref:_=>{u.current[g]=_},onClick:()=>e(d),onMouseEnter:()=>i(g),style:{padding:"4px 8px",cursor:"pointer",display:"flex",alignItems:"center",gap:"8px",backgroundColor:h?"var(--vscode-editorSuggestWidget-selectedBackground)":"transparent",color:h?"var(--vscode-editorSuggestWidget-selectedForeground)":"var(--vscode-editorSuggestWidget-foreground)"},children:[x.jsx("span",{style:{opacity:.7,fontSize:"12px",minWidth:"16px",textAlign:"center"},children:nO(d.kind)}),x.jsx("span",{style:{flex:1},children:rO(d.label,o)}),d.detail&&x.jsx("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"auto"},children:d.detail})]},`${d.label}-${g}`)})})})}const wc=he("LSP_MENU_STATE_COMMAND"),xc=he("LSP_COMPLETION_INSERTED_COMMAND");function ml(n,e,t){let r=0;function o(i){if(i===e)return r+=t,!0;if(q(i)){const a=i.getChildren();for(const l of a)if(o(l))return!0}else r+=i.getTextContent().length;return!1}const s=n.getChildren();for(const i of s)if(o(i))break;return r}function sO(n){const e=n.getChildren();for(const t of e)if(ds(t))return!0;return!1}function Xg(n){let e=n;for(;e;){if(st(e))return e;e=e.getParent()}return null}function iO(n,e){let t=0,r=0;for(let o=0;o<e&&o<n.length;o++)n[o]===`
217
217
  `?(t++,r=0):r++;return{line:t,character:r}}function aO(n){const e=n.getLanguage();return!e||e==="python"||e==="py"?"python":e==="markdown"||e==="md"||e==="text"?"markdown":"unknown"}function lO(n,e){if(!e)return n;const t=e.toLowerCase(),r=[],o=[];for(const s of n){const i=(s.filterText||s.label).toLowerCase();i.startsWith(t)?r.push(s):i.includes(t)&&o.push(s)}return[...r,...o]}function i$({providers:n,disabled:e=!1}){const[t]=fe(),[r,o]=S.useState([]),[s,i]=S.useState([]),[a,l]=S.useState(!1),[c,u]=S.useState({top:0,left:0}),[f,d]=S.useState(""),g=S.useRef(0),h=S.useRef(null),_=S.useCallback(()=>{const C=window.getSelection();if(!C||C.rangeCount===0)return{top:0,left:0};const k=C.getRangeAt(0).getBoundingClientRect();return{top:k.bottom+window.scrollY,left:k.left+window.scrollX}},[]),m=S.useCallback(()=>{l(!1),o([]),i([]),d(""),g.current=0,h.current=null,t.dispatchCommand(wc,!1)},[t]),y=S.useCallback(C=>{t.update(()=>{const v=D();if(!F(v))return;const k=v.anchor.getNode(),I=v.anchor.offset,E=h.current;if(E){const O=ml(E,k,I)-g.current;if(O>0){const M=I-O;if(M>=0){const R=k.getKey();v.anchor.set(R,M,"text"),v.focus.set(R,I,"text")}}}v.insertText(C.insertText)}),t.dispatchCommand(xc,void 0),m()},[t,m]);S.useEffect(()=>{if(!(!a||r.length===0))return t.registerUpdateListener(({editorState:C})=>{C.read(()=>{const v=D();if(!F(v)||!v.isCollapsed()){m();return}const k=v.anchor.getNode(),I=h.current;if(!I)return;const E=Xg(k);if(!E){m();return}const N=E.getJupyterInputNodeUuid(),O=I.getJupyterInputNodeUuid();if(N!==O){m();return}h.current=E;const M=v.anchor.offset,R=ml(E,k,M);if(R<g.current){m();return}const L=E.getTextContent().substring(g.current,R),A=lO(r,L);i(A),d(L),A.length===0&&m()})})},[t,a,r,m]);const w=S.useCallback(async(C,v)=>{if(n.length===0||e)return;const k=C.getJupyterInputNodeUuid(),I=C.getTextContent(),E=aO(C);if(E==="unknown")return;const N=iO(I,v),M=(await Promise.all(n.map(R=>R.fetchCompletions(k,I,N,E)))).flat();if(M.length===1){const R=M[0];t.update(()=>{const $=D();if(F($)){const L=$.anchor.getNode(),A=$.anchor.offset,B=L.getTextContent();let j=A;for(;j>0&&/[a-zA-Z0-9_]/.test(B[j-1]);)j--;if(A-j>0){const z=L.getKey();$.anchor.set(z,j,"text"),$.focus.set(z,A,"text")}$.insertText(R.insertText)}}),t.dispatchCommand(xc,void 0)}else if(M.length>1){const R=_();u(R),o(M),i(M),d(""),g.current=v,h.current=C,l(!0),t.dispatchCommand(wc,!0)}},[n,e,_,t]);return S.useEffect(()=>{if(!e)return t.registerCommand(Kr,C=>{const v=D();if(!F(v)||!v.isCollapsed())return!1;const k=v.anchor.getNode(),I=Xg(k);if(!I||sO(I))return!1;if(a)return C?.preventDefault(),!0;C?.preventDefault();const E=v.anchor.getNode(),N=v.anchor.offset,O=ml(I,E,N);return w(I,O),!0},bo)},[t,e,a,w]),e||n.length===0?null:a&&s.length>0?x.jsx(oO,{items:s,onSelect:y,onClose:m,position:c,filterText:f}):null}const Gg=he("TRIGGER_INLINE_COMPLETION_COMMAND");function cO({providers:n,debounceMs:e,enabled:t=!0,config:r}){const[o]=fe(),[s,i]=S.useState(null),[a,l]=S.useState(!1),c=S.useMemo(()=>zL(r),[r]),u=r?.debounceMs??e??Math.max(c.debounceMs,500),f=S.useRef(null),d=S.useRef(""),g=S.useRef(""),h=S.useRef(null),_=S.useRef(null),m=S.useRef(0);S.useEffect(()=>()=>{f.current&&(clearTimeout(f.current),f.current=null)},[]),S.useEffect(()=>{if(t)return o.registerCommand(wc,w=>(l(w),w&&(f.current&&(clearTimeout(f.current),f.current=null),i(null)),!1),ee)},[o,t]),S.useEffect(()=>{if(t)return o.registerCommand(xc,()=>(m.current=Date.now(),i(null),!1),ee)},[o,t]);const y=S.useCallback(async(w,C,v,k="code",I="auto")=>{if(!n||n.length===0)return;const E=n[0];try{const N=w.substring(0,C),O=w.substring(C),M=await E.fetch({text:w,offset:C,language:v,contentType:k},{before:N,after:O,inCodeCell:k==="code",triggerKind:I});if(M&&M.items&&M.items.length>0){const R=M.items[0].insertText;i(R)}else i(null)}catch(N){console.error("[InlineCompletionPlugin] Error requesting completion:",N),i(null)}},[n]);return S.useEffect(()=>{_.current=y},[y]),S.useEffect(()=>{if(t)return o.registerUpdateListener(({editorState:w})=>{w.read(()=>{if(!c){ge("[InlineCompletionPlugin] Config not ready, skipping auto-trigger"),i(null);return}if(a){i(null);return}if(Date.now()-m.current<300){i(null);return}const k=D();if(!F(k)||!k.isCollapsed()){i(null);return}const I=k.anchor.getNode(),E=Zg(I),N=E==="code"?c.code:c.prose;if(ge("[InlineCompletionPlugin] Auto-trigger check:",{contentType:E,triggerMode:N.triggerMode,willTrigger:N.triggerMode==="auto"}),N.triggerMode==="auto")if(E==="code"){const O=bl(I);if(!O){i(null);return}const M=O.getTextContent(),R=Qg(O,k);if(M===g.current)return;g.current=M;const $=M.substring(0,R);if($.trim().length===0){i(null);return}const L=$.lastIndexOf(`
@@ -224,10 +224,10 @@ ${n.stack}`:r}function Mk(){let n,e;try{const o=p.__wbindgen_add_to_stack_pointe
224
224
  `);return{block_id:t,block_type:"table",source:c,metadata:{rows:i,columns:a,data:l}}}if(e==="collapsible-container"){const o=n,s=o.getOpen?.()||o.__open||!1,i=o.getChildren?.()||[];let a="";return i[0]?.getType()==="collapsible-title"&&(a=i[0].getTextContent()),{block_id:t,block_type:"collapsible",source:a,metadata:{open:s,title:a}}}if(e==="collapsible-title")return null;const r=n.getTextContent();return{block_id:t,block_type:e,source:r}}function lo(n){const e=[];let t=!1;const r=n.getTextContent(),o="getChildren"in n?n.getChildren():[];if(o.length>0)for(const s of o)if(s.getType()==="text"){const i=s.getTextContent(),a=s.getFormat?.()||0;e.push({text:i,format:a}),a!==0&&(t=!0)}else{const i=lo(s);i.formatting?(e.push(...i.formatting),t=!0):e.push({text:i.text,format:0})}else{const s="getFormat"in n&&n.getFormat?.()||0;e.push({text:r,format:s}),s!==0&&(t=!0)}return{text:r,formatting:t&&e.length>0?e:void 0}}function tp(n){const s=[];let i=0;const a=[{regex:/\*\*\*(.*?)\*\*\*/g,format:3},{regex:/\*\*(.*?)\*\*/g,format:1},{regex:/\*(.*?)\*/g,format:2},{regex:/~~(.*?)~~/g,format:4},{regex:/`(.*?)`/g,format:16}],l=[];for(const c of a){c.regex.lastIndex=0;let u;for(;(u=c.regex.exec(n))!==null;)l.some(d=>u.index>=d.start&&u.index<d.end||u.index+u[0].length>d.start&&u.index+u[0].length<=d.end)||l.push({start:u.index,end:u.index+u[0].length,text:u[1],format:c.format})}l.sort((c,u)=>c.start-u.start);for(const c of l){if(c.start>i){const u=n.substring(i,c.start);u&&s.push({text:u,format:0})}s.push({text:c.text,format:c.format}),i=c.end}if(i<n.length){const c=n.substring(i);c&&s.push({text:c,format:0})}return s.length===0&&s.push({text:n,format:0}),s}class gO{_editor;_defaultBlockType="paragraph";_serviceManager;_runAllAbortController=null;constructor(e,t){this._editor=e,this._serviceManager=t}get editor(){return this._editor}get serviceManager(){return this._serviceManager}setDefaultBlockType(e){this._defaultBlockType=e}get defaultBlockType(){return this._defaultBlockType}async getBlocks(e="brief"){return new Promise(t=>{const r=yl(this._editor,e);t(r)})}async getBlock(e){return new Promise(t=>{const r=yl(this._editor,"detailed");e>=0&&e<r.length?t(r[e]):t(null)})}async getBlockById(e){return new Promise(t=>{const o=yl(this._editor,"detailed").find(s=>s.block_id===e);t(o||null)})}async getBlockCount(){return(await this.getBlocks()).length}async insertBlock(e,t){const r=Array.isArray(e.source)?e.source.join(`
225
225
  `):e.source;if((e.block_type==="paragraph"||e.block_type==="text")&&this.containsBlockLevelMarkdown(r)){const s=this.parseMarkdownToBlocks(r);if(s.length>1){let i=t,a;for(const l of s){l.metadata={...l.metadata,...e.metadata};const c=await this.insertBlock(l,i);if(!c.success)return c;c.blockId&&(a=c.blockId,i=c.blockId)}return{success:!0,blockId:a,message:`Inserted ${s.length} blocks from markdown`}}}if(e.metadata?.collapsible){const s=e.metadata.collapsible;return s==="TOP"||s==="BOTTOM"?Promise.resolve({success:!1,error:`Invalid collapsible ID: "${s}". To insert blocks inside a collapsible: 1) First insert the collapsible container (returns blockId), 2) Then insert nested blocks with properties.collapsible set to that blockId. Use afterId for positioning (TOP/BOTTOM/blockId), not properties.collapsible.`}):new Promise(i=>{this._editor.update(()=>{const c=se().getChildren().find(g=>g.getKey()===s);if(!c||c.getType()!=="collapsible-container"){i({success:!1,error:`Collapsible container ${s} not found`});return}const f=(c.getChildren?.()||[]).find(g=>g.getType()==="collapsible-content");if(!f){i({success:!1,error:`Collapsible content node not found in ${s}`});return}const d={...e,metadata:{...e.metadata,collapsible:void 0}};this.insertBlock(d,"BOTTOM").then(g=>{if(!g.success||!g.blockId){i({success:!1,error:`Failed to insert ${e.block_type}: ${g.error||"Unknown error"}`});return}setTimeout(()=>{this._editor.update(()=>{const m=se().getChildren().find(y=>y.getKey()===g.blockId);if(!m){i({success:!1,error:`Could not find inserted node ${g.blockId}`});return}m.remove(),f.append(m),i({success:!0,blockId:g.blockId,message:`Block of type '${e.block_type}' inserted inside collapsible ${s}`})})},50)}).catch(g=>{i({success:!1,error:`Failed to insert block: ${g.message||String(g)}`})})})})}return this.requiresCommand(e.block_type)?this.insertViaCommand(e,t):this.insertViaNode(e,t)}async deleteBlock(e){try{const t=await this.getBlocks("detailed"),r=new Set(t.map(a=>a.block_id)),o=[];for(const a of e)r.has(a)||o.push(a);if(o.length>0)return{success:!1,error:`Block ID(s) not found: ${o.join(", ")}. Document has ${t.length} blocks.`};const s=[...e].sort((a,l)=>{const c=t.findIndex(f=>f.block_id===a);return t.findIndex(f=>f.block_id===l)-c}),i=[];for(const a of s){const l=await this._deleteSingleBlock(a);if(l.success)i.push({id:a});else{if(l.error?.includes("not found"))continue;return l}}return{success:!0,deletedBlocks:i}}catch(t){return{success:!1,error:t instanceof Error?t.message:String(t)}}}async _deleteSingleBlock(e){return new Promise(t=>{this._editor.update(()=>{try{const r=se(),o=(l,c)=>{if(l.getKey()===c)return l;if("getChildren"in l){const u=l.getChildren();for(const f of u){const d=o(f,c);if(d)return d}}return null},s=o(r,e);if(!s){t({success:!1,error:`Block with ID ${e} not found`});return}const i=s.getType(),a=s.getParent();(i==="equation"||i==="excalidraw")&&a&&a.getType()==="paragraph"?a.remove():s.remove(),t({success:!0})}catch(r){t({success:!1,error:r instanceof Error?r.message:String(r)})}})})}async updateBlock(e,t){const r=await this.deleteBlock([e]);if(!r.success)return r;const o=await this.getBlocks(),s=o.findIndex(a=>a.block_id===e),i=s>0?o[s-1].block_id:"TOP";return this.insertBlock(t,i)}async runBlock(e){if(!e){let o=null;if(this._editor.getEditorState().read(()=>{const s=D();if(!s)return;const i=s.getNodes();if(i.length===0)return;let l=i[0];for(;l;){const c=l.getType();if(c==="jupyter-cell"||c==="jupyter-input"){o=l.getKey();break}const u=l.getParent();if(!u)break;l=u}}),!o)return{success:!1,error:"No jupyter cell is currently focused"};e=o}const t=await this.getBlockById(e);if(!t)return{success:!1,error:`Block with ID ${e} not found`};if(!["jupyter-cell","jupyter-input"].includes(t.block_type))return{success:!1,error:`Block type ${t.block_type} is not executable`};try{const o=Date.now(),s=await new Promise((c,u)=>{this._editor.update(()=>{try{const f=se();let d=null,g="";const h=m=>{if(m.getType()==="jupyter-cell"&&m.getKey()===e)return m.getChildren().forEach(C=>{C.getType()==="jupyter-input"?g=C.getTextContent():C.getType()==="jupyter-output"&&(d=C)}),!0;if(m.getType()==="jupyter-input"&&m.getKey()===e){g=m.getTextContent();const w=m.getJupyterInputNodeUuid();return d=dr(w),!0}const y=m.getChildren?.()||[];for(const w of y)if(h(w))return!0;return!1};for(const m of f.getChildren())if(h(m))break;if(!d){u(new Error("Could not find jupyter-output node for execution"));return}if(!g||g.trim()===""){u(new Error("No code to execute"));return}d.executeCode(g);const _=d.__outputAdapter;if(!_){u(new Error("No outputAdapter available"));return}c({outputAdapter:_,code:g})}catch(f){u(f)}})});await new Promise(c=>setTimeout(c,500));const i=s.outputAdapter.outputArea.model.toJSON(),a=(Date.now()-o)/1e3;return{success:!0,execution_count:i.length>0?1:null,outputs:i,elapsed_time:a,message:`Block executed in ${a.toFixed(2)}s`}}catch(o){return{success:!1,error:`Failed to execute block: ${o instanceof Error?o.message:String(o)}`}}}async runAllBlocks(){this._runAllAbortController&&this._runAllAbortController.abort(),this._runAllAbortController=new AbortController;const e=this._runAllAbortController.signal;try{const r=(await this.getBlocks()).filter(o=>o.block_type==="jupyter-cell");for(const o of r){if(e.aborted)return{success:!1,error:"Run all blocks was cancelled (new run all started)"};const s=await this.runBlock(o.block_id);if(!s.success)return console.error(`[LexicalAdapter] Block ${o.block_id} failed:`,s.error),{success:!1,error:`Failed to run block ${o.block_id}: ${s.error}`}}return{success:!0,blockId:r.length>0?r[r.length-1].block_id:void 0}}finally{this._runAllAbortController?.signal===e&&(this._runAllAbortController=null)}}async clearAllOutputs(){return new Promise(e=>{this._editor.update(()=>{let t=0;function r(s){if(s.getType&&s.getType()==="jupyter-output"&&s.__outputAdapter&&(s.__outputAdapter.clear(),t++),s.getChildren){const i=s.getChildren();for(const a of i)r(a)}}const o=se();r(o),e({success:!0,message:t>0?`Cleared outputs from ${t} jupyter cells`:"No jupyter cells found to clear"})})})}async restartKernel(){return new Promise(e=>{me(()=>Promise.resolve().then(()=>Uf),void 0,import.meta.url).then(t=>{const{RESTART_JUPYTER_KERNEL_COMMAND:r}=t,o=this._editor.dispatchCommand(r,void 0);e(o?{success:!0,message:"Kernel restart initiated"}:{success:!1,error:"RESTART_JUPYTER_KERNEL_COMMAND was not handled"})}).catch(t=>{e({success:!1,error:`Failed to load restart command: ${t.message}`})})})}requiresCommand(e){return["jupyter-cell","image","equation","youtube","excalidraw","table","collapsible"].includes(e)}async insertViaCommand(e,t){return new Promise(async r=>{try{if(e.block_type==="equation"){const{INSERT_EQUATION_COMMAND:o}=await me(async()=>{const{INSERT_EQUATION_COMMAND:l}=await Promise.resolve().then(()=>vL);return{INSERT_EQUATION_COMMAND:l}},void 0,import.meta.url),s=Array.isArray(e.source)?e.source.join(`
226
226
  `):e.source,i=e.metadata?.equation||e.metadata?.latex||s,a=!1;this._editor.update(()=>{const l=se(),c=l.getChildren(),u=ne();if(u.append(De("__EQUATION_MARKER__")),t==="TOP")c.length>0?c[0].insertBefore(u):l.append(u);else if(t==="BOTTOM"||!t)l.append(u);else{const f=c.find(d=>d.getKey()===t);if(f)f.insertAfter(u);else throw new Error(`Block ID ${t} not found`)}}),setTimeout(()=>{this._editor.update(()=>{const f=se().getChildren().find(d=>d.getType()==="paragraph"&&d.getTextContent()==="__EQUATION_MARKER__");f&&(f.selectEnd(),f.remove())}),this._editor.dispatchCommand(o,{equation:i,inline:a});let l;setTimeout(()=>{this._editor.getEditorState().read(()=>{const u=se().getChildren();for(let f=u.length-1;f>=0;f--)if(u[f].getType()==="equation"){l=u[f].getKey();break}}),r({success:!0,blockId:l})},20)},10)}else if(e.block_type==="jupyter-cell"){const{INSERT_JUPYTER_INPUT_OUTPUT_COMMAND:o}=await me(async()=>{const{INSERT_JUPYTER_INPUT_OUTPUT_COMMAND:l}=await Promise.resolve().then(()=>Uf);return{INSERT_JUPYTER_INPUT_OUTPUT_COMMAND:l}},void 0,import.meta.url),i={code:Array.isArray(e.source)?e.source.join(`
227
- `):e.source,outputs:e.metadata?.outputs||[],loading:""};this._editor.update(()=>{const l=se(),c=l.getChildren(),u=ne();if(t==="TOP")c.length>0?c[0].insertBefore(u):l.append(u);else if(t==="BOTTOM"||!t)l.append(u);else{const f=c.find(d=>d.getKey()===t);if(f)f.insertAfter(u);else throw new Error(`Block ID ${t} not found`)}u.selectStart(),this._editor.dispatchCommand(o,i)});let a;setTimeout(()=>{this._editor.getEditorState().read(()=>{const l=se(),c=(f,d)=>{let g=null;if(f.getType()===d&&(g=f),"getChildren"in f&&typeof f.getChildren=="function")for(const h of f.getChildren()){const _=c(h,d);_&&(g=_)}return g},u=c(l,"jupyter-input");u&&(a=u.getKey())}),r({success:!0,blockId:a})},20)}else if(e.block_type==="youtube"){const{INSERT_YOUTUBE_COMMAND:o}=await me(async()=>{const{INSERT_YOUTUBE_COMMAND:c}=await import("./YouTubePlugin-C0a_9VKl.js");return{INSERT_YOUTUBE_COMMAND:c}},[],import.meta.url),s=Array.isArray(e.source)?e.source.join(`
227
+ `):e.source,outputs:e.metadata?.outputs||[],loading:""};this._editor.update(()=>{const l=se(),c=l.getChildren(),u=ne();if(t==="TOP")c.length>0?c[0].insertBefore(u):l.append(u);else if(t==="BOTTOM"||!t)l.append(u);else{const f=c.find(d=>d.getKey()===t);if(f)f.insertAfter(u);else throw new Error(`Block ID ${t} not found`)}u.selectStart(),this._editor.dispatchCommand(o,i)});let a;setTimeout(()=>{this._editor.getEditorState().read(()=>{const l=se(),c=(f,d)=>{let g=null;if(f.getType()===d&&(g=f),"getChildren"in f&&typeof f.getChildren=="function")for(const h of f.getChildren()){const _=c(h,d);_&&(g=_)}return g},u=c(l,"jupyter-input");u&&(a=u.getKey())}),r({success:!0,blockId:a})},20)}else if(e.block_type==="youtube"){const{INSERT_YOUTUBE_COMMAND:o}=await me(async()=>{const{INSERT_YOUTUBE_COMMAND:c}=await import("./YouTubePlugin-BewlFg9c.js");return{INSERT_YOUTUBE_COMMAND:c}},[],import.meta.url),s=Array.isArray(e.source)?e.source.join(`
228
228
  `):e.source,a=(c=>{const u=c.trim();if(/^[a-zA-Z0-9_-]{11}$/.test(u))return u;const f=u.match(/youtu\.be\/([a-zA-Z0-9_-]{11})/);if(f)return f[1];const d=u.match(/[?&]v=([a-zA-Z0-9_-]{11})/);return d?d[1]:"lO2p9LQB7ds"})(s||"");await this.insertWithMarker(t,()=>{this._editor.dispatchCommand(o,a)});let l;setTimeout(()=>{this._editor.getEditorState().read(()=>{const u=se().getChildren();for(let f=u.length-1;f>=0;f--)if(u[f].getType()==="youtube"){l=u[f].getKey();break}}),r({success:!0,blockId:l})},20)}else if(e.block_type==="excalidraw"){const{$createExcalidrawNode:o}=await me(async()=>{const{$createExcalidrawNode:f}=await Promise.resolve().then(()=>n1);return{$createExcalidrawNode:f}},void 0,import.meta.url),{$wrapNodeInElement:s}=await me(async()=>{const{$wrapNodeInElement:f}=await import("../datalayer-app-main.js").then(d=>d.u3);return{$wrapNodeInElement:f}},[],import.meta.url),{$isRootOrShadowRoot:i}=await me(async()=>{const{$isRootOrShadowRoot:f}=await import("../datalayer-app-main.js").then(d=>d.u2);return{$isRootOrShadowRoot:f}},[],import.meta.url),a=e.metadata?.data||"[]",l=e.metadata?.width,c=e.metadata?.height;let u;this._editor.update(()=>{const f=o(a,l||"inherit",c||"inherit");this.insertNodeAtPosition(f,t),u=f.getKey(),i(f.getParentOrThrow())&&s(f,ne).selectEnd()}),r({success:!0,blockId:u})}else if(e.block_type==="table"){const{INSERT_TABLE_COMMAND:o}=await me(async()=>{const{INSERT_TABLE_COMMAND:g}=await Promise.resolve().then(()=>Tf);return{INSERT_TABLE_COMMAND:g}},void 0,import.meta.url),{$getTableCellNodeFromLexicalNode:s,$getTableNodeFromLexicalNodeOrThrow:i}=await me(async()=>{const{$getTableCellNodeFromLexicalNode:g,$getTableNodeFromLexicalNodeOrThrow:h}=await Promise.resolve().then(()=>Tf);return{$getTableCellNodeFromLexicalNode:g,$getTableNodeFromLexicalNodeOrThrow:h}},void 0,import.meta.url);let a=e.metadata?.rows||2,l=e.metadata?.columns||2,c=e.metadata?.data;const u=e.metadata?.includeHeaders!==!1;c&&Array.isArray(c)&&c.length>0&&(a=c.length,l=c[0].length);const f=Array.isArray(e.source)?e.source.join(`
229
229
  `):e.source;if(f&&typeof f=="string"&&f.includes("|"))try{const g=f.split(`
230
- `).filter(_=>_.trim()),h=[];for(const _ of g){if(_.match(/^\|?[\s-|]+\|?$/))continue;const m=_.split("|").slice(1,-1).map(y=>y.trim());m.length>0&&h.push(m)}h.length>0&&(c=h,a=h.length,l=h[0].length)}catch{}await this.insertWithMarker(t,()=>{this._editor.dispatchCommand(o,{rows:a.toString(),columns:l.toString(),includeHeaders:u})});let d;setTimeout(()=>{this._editor.update(()=>{const h=se().getChildren();for(let _=h.length-1;_>=0;_--)if(h[_].getType()==="table"){if(d=h[_].getKey(),c&&c.length>0)try{const y=i(h[_]).getChildren();for(let w=0;w<Math.min(c.length,y.length);w++){const v=y[w].getChildren();for(let k=0;k<Math.min(c[w].length,v.length);k++){const I=s(v[k]);I&&(I.clear(),I.append(De(c[w][k])))}}}catch{}break}}),r({success:!0,blockId:d})},20)}else if(e.block_type==="collapsible"){const{INSERT_COLLAPSIBLE_COMMAND:o}=await me(async()=>{const{INSERT_COLLAPSIBLE_COMMAND:l}=await import("./index-BvYhxJ42.js");return{INSERT_COLLAPSIBLE_COMMAND:l}},[],import.meta.url),s=e.metadata?.open??!0,i=Array.isArray(e.source)?e.source.join(`
230
+ `).filter(_=>_.trim()),h=[];for(const _ of g){if(_.match(/^\|?[\s-|]+\|?$/))continue;const m=_.split("|").slice(1,-1).map(y=>y.trim());m.length>0&&h.push(m)}h.length>0&&(c=h,a=h.length,l=h[0].length)}catch{}await this.insertWithMarker(t,()=>{this._editor.dispatchCommand(o,{rows:a.toString(),columns:l.toString(),includeHeaders:u})});let d;setTimeout(()=>{this._editor.update(()=>{const h=se().getChildren();for(let _=h.length-1;_>=0;_--)if(h[_].getType()==="table"){if(d=h[_].getKey(),c&&c.length>0)try{const y=i(h[_]).getChildren();for(let w=0;w<Math.min(c.length,y.length);w++){const v=y[w].getChildren();for(let k=0;k<Math.min(c[w].length,v.length);k++){const I=s(v[k]);I&&(I.clear(),I.append(De(c[w][k])))}}}catch{}break}}),r({success:!0,blockId:d})},20)}else if(e.block_type==="collapsible"){const{INSERT_COLLAPSIBLE_COMMAND:o}=await me(async()=>{const{INSERT_COLLAPSIBLE_COMMAND:l}=await import("./index-D4E_ai6G.js");return{INSERT_COLLAPSIBLE_COMMAND:l}},[],import.meta.url),s=e.metadata?.open??!0,i=Array.isArray(e.source)?e.source.join(`
231
231
  `):e.source||"";await this.insertWithMarker(t,()=>{this._editor.dispatchCommand(o,void 0)});let a;setTimeout(()=>{this._editor.update(()=>{const c=se().getChildren();for(let u=c.length-1;u>=0;u--)if(c[u].getType()==="collapsible-container"){const f=c[u];a=f.getKey(),f.setOpen?.(s);const d=f.getChildren();d[0]&&i&&(d[0].clear(),d[0].append(De(i)));break}}),r({success:!0,blockId:a})},20)}else r({success:!1,error:`Unsupported command-based block type: ${e.block_type}`})}catch(o){r({success:!1,error:o instanceof Error?o.message:String(o)})}})}async insertViaNode(e,t){return new Promise(r=>{this._editor.update(()=>{try{const o=se(),s=this.createSimpleNode(e);if(!s){r({success:!1,error:`Failed to create node for type: ${e.block_type}`});return}const i=o.getChildren();if(t==="TOP")i.length>0?i[0].insertBefore(s):o.append(s);else if(t==="BOTTOM"||!t)o.append(s);else{const a=i.find(l=>l.getKey()===t);if(a)a.insertAfter(s);else{r({success:!1,error:`Block ID ${t} not found`});return}}r({success:!0,blockId:s.getKey()})}catch(o){r({success:!1,error:o instanceof Error?o.message:String(o)})}})})}createSimpleNode(e){const t=Array.isArray(e.source)?e.source.join(`
232
232
  `):e.source,r=()=>e.formatting&&e.formatting.length>0?e.formatting.map(o=>{const s=De(o.text);return o.format&&s.setFormat(o.format),s}):tp(t||"").map(s=>{const i=De(s.text);return s.format&&i.setFormat(s.format),i});switch(e.block_type){case"paragraph":{const o=ne();return r().forEach(s=>o.append(s)),o}case"heading":{const s=`h${e.metadata?.level||1}`,i=fn(s);return r().forEach(a=>i.append(a)),i}case"code":{const o=e.metadata?.language||"plaintext",s=Ze(o);return s.append(De(t)),s}case"quote":{const o=Ln();return r().forEach(s=>o.append(s)),o}case"list":{const o=e.metadata?.listType||"bullet",s=Et(o),i=t.split(`
233
233
  `).map(a=>a.trim()).filter(a=>a.length>0);if(i.length===0){const a=xt();s.append(a)}else i.forEach(a=>{const l=xt();tp(a).forEach(u=>{const f=De(u.text);u.format&&f.setFormat(u.format),l.append(f)}),s.append(l)});return s}case"horizontalrule":return ba();case"listitem":{const o=xt();return e.metadata?.checked!==void 0&&o.setChecked(e.metadata.checked),r().forEach(s=>o.append(s)),o}default:return null}}containsBlockLevelMarkdown(e){return!e||typeof e!="string"?!1:!!(/^#{1,6}[ \t]+\S/m.test(e)||/^[ \t]*[-*+][ \t]+\S/m.test(e)||/^[ \t]*\d+\.[ \t]+\S/m.test(e)||/\n\s*\n/.test(e))}parseMarkdownToBlocks(e){const t=[],r=e.split(`