@datalayer/agent-runtimes 1.3.103 → 1.3.104

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 (139) hide show
  1. package/dist-embed/chunks/{AgentDetails-CO9iM59C.js → AgentDetails-eWkEnFI1.js} +1 -1
  2. package/dist-embed/chunks/{AgentDetailsDialog-DmD6xm6k.js → AgentDetailsDialog-BXJek5nf.js} +1 -1
  3. package/dist-embed/chunks/{AgentInspector-kDMuvh45.js → AgentInspector-B1wLMu4Z.js} +1 -1
  4. package/dist-embed/chunks/{AgentInspectorDialog-fT96Pb4Z.js → AgentInspectorDialog-DcLrhdWo.js} +1 -1
  5. package/dist-embed/chunks/Avatar-BrPfm89P.js +1 -0
  6. package/dist-embed/chunks/{CellSidebarExtension-B-vao30u.js → CellSidebarExtension-BWsHtuqs.js} +2 -2
  7. package/dist-embed/chunks/ChatView-ef0jot57.js +32 -0
  8. package/dist-embed/chunks/DatalayerAgentBridge-DvlGUOdE.js +1 -0
  9. package/dist-embed/chunks/{DeckComponent-Fp6Vw8vN.js → DeckComponent-BfOXdQhk.js} +1 -1
  10. package/dist-embed/chunks/{DocumentView-DKUbyyJg.js → DocumentView-DCgaQoOU.js} +1 -1
  11. package/dist-embed/chunks/{EphemeralDocument-CgYPEfGC.js → EphemeralDocument-DVAfnQWS.js} +1 -1
  12. package/dist-embed/chunks/{EphemeralNotebook-DvDbCKnr.js → EphemeralNotebook-C1ANS_1u.js} +1 -1
  13. package/dist-embed/chunks/{ExcalidrawComponent-BehqBpwC.js → ExcalidrawComponent-0e3KqmKJ.js} +1 -1
  14. package/dist-embed/chunks/{ExcalidrawModal-B2sXbVJB.js → ExcalidrawModal-C5Or1sZ5.js} +1 -1
  15. package/dist-embed/chunks/{Flash-DdFxPtBI.js → Flash-C3nF3s4G.js} +1 -1
  16. package/dist-embed/chunks/{JupyterLexicalExtension-CUsjvchq.js → JupyterLexicalExtension-CEjN8cLT.js} +7 -7
  17. package/dist-embed/chunks/{KernelVariables-BUmOt4yF.js → KernelVariables-DyYN9sSS.js} +1 -1
  18. package/dist-embed/chunks/{NotebookSkeleton-D9WNoiWD.js → NotebookSkeleton-z8GKB7Tb.js} +1 -1
  19. package/dist-embed/chunks/{NotebookToolbar-C2_ZC9Ej.js → NotebookToolbar-Dv7QkxKA.js} +1 -1
  20. package/dist-embed/chunks/{NotebookView-BActuABH.js → NotebookView-CNHzc28A.js} +1 -1
  21. package/dist-embed/chunks/{SandboxDetailsDialog-C0afmOA7.js → SandboxDetailsDialog-D4HA7PZA.js} +1 -1
  22. package/dist-embed/chunks/{SchemaForm-B351kd79.js → SchemaForm-bWlj1cVy.js} +1 -1
  23. package/dist-embed/chunks/{Toolbar-B6ROXJ-2.js → Toolbar-BxAi9T92.js} +1 -1
  24. package/dist-embed/chunks/{YouTubePlugin-CqA-IwCx.js → YouTubePlugin-ZawlUPsx.js} +1 -1
  25. package/dist-embed/chunks/{ar-SA-G6X2FPQ2-DhQlC4AZ.js → ar-SA-G6X2FPQ2-DqE6ftcU.js} +1 -1
  26. package/dist-embed/chunks/{az-AZ-76LH7QW2-CDvJeI6H.js → az-AZ-76LH7QW2-8y_pqJhn.js} +1 -1
  27. package/dist-embed/chunks/{bg-BG-XCXSNQG7-B_2t7dwS.js → bg-BG-XCXSNQG7-4NX5jouU.js} +1 -1
  28. package/dist-embed/chunks/{bn-BD-2XOGV67Q-B7nTDj-4.js → bn-BD-2XOGV67Q-BB87_pS6.js} +1 -1
  29. package/dist-embed/chunks/{ca-ES-6MX7JW3Y-llJD_i9l.js → ca-ES-6MX7JW3Y-B9gyglRE.js} +1 -1
  30. package/dist-embed/chunks/{cs-CZ-2BRQDIVT-Cm_uiYT0.js → cs-CZ-2BRQDIVT-CmZhtHam.js} +1 -1
  31. package/dist-embed/chunks/{da-DK-5WZEPLOC-B0lo6-wZ.js → da-DK-5WZEPLOC-CU6rP6vm.js} +1 -1
  32. package/dist-embed/chunks/{de-DE-XR44H4JA-DZrN-mJo.js → de-DE-XR44H4JA-wk6_Fx0e.js} +1 -1
  33. package/dist-embed/chunks/{el-GR-BZB4AONW-C4D5ZbOc.js → el-GR-BZB4AONW-Cy5yeukb.js} +1 -1
  34. package/dist-embed/chunks/{es-ES-U4NZUMDT-D1yiS-ZI.js → es-ES-U4NZUMDT-Ccr3g95I.js} +1 -1
  35. package/dist-embed/chunks/{eu-ES-A7QVB2H4-Zm3lJsL6.js → eu-ES-A7QVB2H4-u0DKk40F.js} +1 -1
  36. package/dist-embed/chunks/{fa-IR-HGAKTJCU-Dhv2lg_O.js → fa-IR-HGAKTJCU-BYSSU2Gx.js} +1 -1
  37. package/dist-embed/chunks/{fi-FI-Z5N7JZ37-QeFFEfyg.js → fi-FI-Z5N7JZ37-98vDI-0h.js} +1 -1
  38. package/dist-embed/chunks/{fr-FR-RHASNOE6-DjbRpOS6.js → fr-FR-RHASNOE6-D2BvErn0.js} +1 -1
  39. package/dist-embed/chunks/{gl-ES-HMX3MZ6V-C-ev9dqC.js → gl-ES-HMX3MZ6V-DP7FRXtT.js} +1 -1
  40. package/dist-embed/chunks/{he-IL-6SHJWFNN-DHoNpuA6.js → he-IL-6SHJWFNN-B92ZDKBK.js} +1 -1
  41. package/dist-embed/chunks/{hi-IN-IWLTKZ5I-JZJZPoWj.js → hi-IN-IWLTKZ5I-Dw2EhOq2.js} +1 -1
  42. package/dist-embed/chunks/{hu-HU-A5ZG7DT2-RzCikyBW.js → hu-HU-A5ZG7DT2-CVh5JW9n.js} +1 -1
  43. package/dist-embed/chunks/{id-ID-SAP4L64H-Bn08nS9B.js → id-ID-SAP4L64H-CaKn7Yw0.js} +1 -1
  44. package/dist-embed/chunks/{index-DIHzcHI1.js → index-5Mm_lDnH.js} +1 -1
  45. package/dist-embed/chunks/{index-B1StFYI5.js → index-B46RcdCt.js} +1 -1
  46. package/dist-embed/chunks/{index-qzUKNibz.js → index-B6RMWdb4.js} +1 -1
  47. package/dist-embed/chunks/{index-88CEdMmU.js → index-BI_ojvKX.js} +1 -1
  48. package/dist-embed/chunks/{index-uutAM7NJ.js → index-BWxQD9cP.js} +1 -1
  49. package/dist-embed/chunks/{index-DCX_IqLg.js → index-B_WAs-60.js} +1 -1
  50. package/dist-embed/chunks/{index-BYofH50G.js → index-BaEB7wmN.js} +1 -1
  51. package/dist-embed/chunks/{index-C0iUgNwj.js → index-BmSB4k4X.js} +1 -1
  52. package/dist-embed/chunks/{index-KWzHwvvN.js → index-BsGIdntV.js} +4 -4
  53. package/dist-embed/chunks/{index-DgnVcOqG.js → index-BsP7mWx7.js} +1 -1
  54. package/dist-embed/chunks/{index-aX9x7qni.js → index-BzZvBTsd.js} +1 -1
  55. package/dist-embed/chunks/{index-BA2STD4N.js → index-C0ac25cM.js} +2 -2
  56. package/dist-embed/chunks/{index-DLk6Znxv.js → index-C0fJQ9v3.js} +1 -1
  57. package/dist-embed/chunks/{index-Bs1pVq7E.js → index-C0p6TrSH.js} +1 -1
  58. package/dist-embed/chunks/{index-DZN9JYOE.js → index-C9mAUugR.js} +1 -1
  59. package/dist-embed/chunks/{index-B1Egld01.js → index-CNBMan5A.js} +1 -1
  60. package/dist-embed/chunks/{index-1Ekpl0uC.js → index-CawAyW3R.js} +1 -1
  61. package/dist-embed/chunks/{index-DeYQGrTz.js → index-Cb-91zWU.js} +1 -1
  62. package/dist-embed/chunks/{index-B2dtLxcg.js → index-CkMGJGPw.js} +1 -1
  63. package/dist-embed/chunks/{index-Cqur_rhw.js → index-CsbfZWj5.js} +1 -1
  64. package/dist-embed/chunks/{index-DsX9nIHt.js → index-D1HhRyAi.js} +1 -1
  65. package/dist-embed/chunks/{index-C5xKtdLU.js → index-D3ml5vHy.js} +1 -1
  66. package/dist-embed/chunks/{index-CqKV027P.js → index-D7SzNRox.js} +1 -1
  67. package/dist-embed/chunks/{index-BUbwVG__.js → index-DAwoO3Uu.js} +1 -1
  68. package/dist-embed/chunks/{index-DHVYKZ44.js → index-DQaxtq0S.js} +1 -1
  69. package/dist-embed/chunks/{index-BbsUSk_Q.js → index-DbPtsB38.js} +1 -1
  70. package/dist-embed/chunks/{index-DJomc4za.js → index-DoYPeIKg.js} +1 -1
  71. package/dist-embed/chunks/{index-hqa_ODOD.js → index-Dr_NppDz.js} +1 -1
  72. package/dist-embed/chunks/{index-D7rnWGLu.js → index-DuDsMDnx.js} +3 -3
  73. package/dist-embed/chunks/{index-B5MiaXUV.js → index-IIxS-G5t.js} +1 -1
  74. package/dist-embed/chunks/{index-90Ss7516.js → index-W7nq_bBb.js} +1 -1
  75. package/dist-embed/chunks/{index-Cjx6uk6z.js → index-r_7Z9Uyr.js} +1 -1
  76. package/dist-embed/chunks/{index.esm-DlPZAW-m.js → index.esm-D5bfliIL.js} +1 -1
  77. package/dist-embed/chunks/{it-IT-JPQ66NNP-C2vJMuKM.js → it-IT-JPQ66NNP-CJGzhajv.js} +1 -1
  78. package/dist-embed/chunks/{ja-JP-DBVTYXUO-C8KOKQt9.js → ja-JP-DBVTYXUO-Jm7LgxUu.js} +1 -1
  79. package/dist-embed/chunks/{kaa-6HZHGXH3-CvxJbmMB.js → kaa-6HZHGXH3-DH21E_2q.js} +1 -1
  80. package/dist-embed/chunks/{kab-KAB-ZGHBKWFO-CQJhf9Nn.js → kab-KAB-ZGHBKWFO-2Cx_3mmx.js} +1 -1
  81. package/dist-embed/chunks/{kk-KZ-P5N5QNE5-Dl6YC0GH.js → kk-KZ-P5N5QNE5-C2v01t5f.js} +1 -1
  82. package/dist-embed/chunks/{km-KH-HSX4SM5Z-QYB-tJ4i.js → km-KH-HSX4SM5Z-WL_JAugw.js} +1 -1
  83. package/dist-embed/chunks/{ko-KR-MTYHY66A-D6yzBqJ5.js → ko-KR-MTYHY66A-DWjrj8WD.js} +1 -1
  84. package/dist-embed/chunks/{ku-TR-6OUDTVRD-C43l2362.js → ku-TR-6OUDTVRD-CwTRLeeu.js} +1 -1
  85. package/dist-embed/chunks/{lt-LT-XHIRWOB4-BG1v5NwF.js → lt-LT-XHIRWOB4-GVGjjS1d.js} +1 -1
  86. package/dist-embed/chunks/{lv-LV-5QDEKY6T-CAwm1y_0.js → lv-LV-5QDEKY6T-C29ftTES.js} +1 -1
  87. package/dist-embed/chunks/{markdown-CH2i4TVR.js → markdown-Bf4-A1yl.js} +1 -1
  88. package/dist-embed/chunks/{mr-IN-CRQNXWMA-DSk6q1fp.js → mr-IN-CRQNXWMA-Cyym_1yB.js} +1 -1
  89. package/dist-embed/chunks/{my-MM-5M5IBNSE-BRiKXulk.js → my-MM-5M5IBNSE-BOkGbWeI.js} +1 -1
  90. package/dist-embed/chunks/{nb-NO-T6EIAALU-CCDnctVd.js → nb-NO-T6EIAALU-BjaVTNUf.js} +1 -1
  91. package/dist-embed/chunks/{nl-NL-IS3SIHDZ-DwStD_Ch.js → nl-NL-IS3SIHDZ-DSVCFPQj.js} +1 -1
  92. package/dist-embed/chunks/{nn-NO-6E72VCQL-DNcfjETk.js → nn-NO-6E72VCQL-D5-_rRv0.js} +1 -1
  93. package/dist-embed/chunks/{oc-FR-POXYY2M6-BOjjS12P.js → oc-FR-POXYY2M6-CxKcn1R4.js} +1 -1
  94. package/dist-embed/chunks/{pa-IN-N4M65BXN-B4y5cv2_.js → pa-IN-N4M65BXN-D9r6O5PP.js} +1 -1
  95. package/dist-embed/chunks/{percentages-BXMCSKIN-BpahO1D1.js → percentages-BXMCSKIN-917PkDRT.js} +3 -3
  96. package/dist-embed/chunks/{pl-PL-T2D74RX3-CfuLoYHB.js → pl-PL-T2D74RX3-CFXCTA5m.js} +1 -1
  97. package/dist-embed/chunks/{plugin-BMH63P5M.js → plugin-CA_0EWiO.js} +1 -1
  98. package/dist-embed/chunks/plugin-LDJjixuG.js +1 -0
  99. package/dist-embed/chunks/{pt-BR-5N22H2LF-Fk60PfdA.js → pt-BR-5N22H2LF-7A-3KOon.js} +1 -1
  100. package/dist-embed/chunks/{pt-PT-UZXXM6DQ-SNAgJ5Vr.js → pt-PT-UZXXM6DQ-BJLo5w79.js} +1 -1
  101. package/dist-embed/chunks/{ro-RO-JPDTUUEW-YkxpKkWn.js → ro-RO-JPDTUUEW-DtvOR1_K.js} +1 -1
  102. package/dist-embed/chunks/{ru-RU-B4JR7IUQ-CaI1rtvc.js → ru-RU-B4JR7IUQ-CGQ0z7l6.js} +1 -1
  103. package/dist-embed/chunks/{sessions-ZDYLkdi_.js → sessions-By2lggFS.js} +2 -2
  104. package/dist-embed/chunks/{si-LK-N5RQ5JYF-CQz29xmh.js → si-LK-N5RQ5JYF-D13wg56d.js} +1 -1
  105. package/dist-embed/chunks/{sk-SK-C5VTKIMK-CZg7PVzd.js → sk-SK-C5VTKIMK-BqAZ0R3f.js} +1 -1
  106. package/dist-embed/chunks/{sl-SI-NN7IZMDC-D-EjMWyZ.js → sl-SI-NN7IZMDC-BjPUGdws.js} +1 -1
  107. package/dist-embed/chunks/{standalone-oyxre9MX.js → standalone-DyCMuq_1.js} +1 -1
  108. package/dist-embed/chunks/{subset-shared.chunk-BIvvzzX2.js → subset-shared.chunk-D-GUkcCO.js} +1 -1
  109. package/dist-embed/chunks/{subset-worker.chunk-DGgI6iRY.js → subset-worker.chunk-Bz8aK3Nt.js} +1 -1
  110. package/dist-embed/chunks/{sv-SE-XGPEYMSR-D8CsNMON.js → sv-SE-XGPEYMSR-DrXTnEWd.js} +1 -1
  111. package/dist-embed/chunks/{ta-IN-2NMHFXQM-CvuxKO7t.js → ta-IN-2NMHFXQM-bK104VxM.js} +1 -1
  112. package/dist-embed/chunks/{th-TH-HPSO5L25-NgQJigwq.js → th-TH-HPSO5L25-BSo6r7L4.js} +1 -1
  113. package/dist-embed/chunks/{tr-TR-DEFEU3FU-eu9-qLmi.js → tr-TR-DEFEU3FU-pYKvN-ro.js} +1 -1
  114. package/dist-embed/chunks/{uk-UA-QMV73CPH-CbjmuLVL.js → uk-UA-QMV73CPH-DFR0z9gx.js} +1 -1
  115. package/dist-embed/chunks/{usePrimerThemeBridge-LgREOVgz.js → usePrimerThemeBridge-CuRRiOcg.js} +1 -1
  116. package/dist-embed/chunks/{vi-VN-M7AON7JQ-u84yOuJ-.js → vi-VN-M7AON7JQ-BwMeNi1s.js} +1 -1
  117. package/dist-embed/chunks/{zh-CN-LNUGB5OW-ojkSgl-t.js → zh-CN-LNUGB5OW-QC_JIHYo.js} +1 -1
  118. package/dist-embed/chunks/{zh-HK-E62DVLB3-C6M89-Da.js → zh-HK-E62DVLB3-BHs8J1Gl.js} +1 -1
  119. package/dist-embed/chunks/{zh-TW-RAJ6MFWO-BaTtFORh.js → zh-TW-RAJ6MFWO-DpqpYlIS.js} +1 -1
  120. package/dist-embed/datalayer-app-main.js +330 -59
  121. package/lib/apps/apps/AppBrowserSandbox.d.ts +7 -0
  122. package/lib/apps/apps/AppBrowserSandbox.js +52 -0
  123. package/lib/apps/apps/AppRenderer.js +11 -2
  124. package/lib/apps/apps/appspec.js +31 -0
  125. package/lib/apps/apps/browserSandbox.d.ts +69 -0
  126. package/lib/apps/apps/browserSandbox.js +159 -0
  127. package/lib/apps/apps/index.d.ts +2 -0
  128. package/lib/apps/apps/index.js +2 -0
  129. package/lib/apps/plugins/chat/ChatView.js +59 -7
  130. package/lib/components/inspector/a2aSpans.js +5 -1
  131. package/lib/specs/apps.js +345 -8
  132. package/lib/specs/appspecSchema.js +79 -0
  133. package/lib/types/agentspecs.d.ts +28 -0
  134. package/package.json +1 -1
  135. package/scripts/codegen/generate_apps.py +3 -2
  136. package/dist-embed/chunks/Avatar-Dqz3ZWjZ.js +0 -1
  137. package/dist-embed/chunks/ChatView-CubqJum2.js +0 -288
  138. package/dist-embed/chunks/DatalayerAgentBridge-BmJbZ2Lk.js +0 -1
  139. package/dist-embed/chunks/plugin-DZPXm2dP.js +0 -1
@@ -1,4 +1,4 @@
1
- import{r as S,az as Gb,aA as Xb,j as x,bp as Y,cL as vn,T as Le,dt as Zb,bq as bd,fz as Qb,oy as ey,B as co,I as Ft,eK as Rp,oz as kl,bk as St,ay as pe,oA as Oe,oB as Je,oC as Ie,oD as $t,kY as F,oE as Ot,oF as kr,kD as q,kI as oe,kJ as It,oG as Bt,aL as se,c as ft,aE as Ap,dv as Zs,ds as ty,fO as Mt,_ as me,k5 as Mp,fQ as ny,D as $p,oH as ry,oI as _o,oJ as Tc,oK as zo,kL as bt,oL as Kn,kC as vt,aM as ne,oM as js,c8 as de,oN as oy,k_ as zr,kX as D,cb as ee,oO as ln,oP as Dp,oQ as sy,oR as Fs,l9 as cn,lc as ke,kK as ue,oS as Ye,oT as Ge,oU as Pp,oV as yd,oW as gt,oX as iy,l0 as Kr,kW as wn,oY as Tl,k$ as Dt,oZ as un,o_ as Tr,o$ as pt,p0 as Vt,p1 as Ir,p2 as xs,p3 as jp,p4 as Ri,p5 as ay,p6 as mi,p7 as Jn,p8 as ly,p9 as cy,cc as Q,pa as uy,kz as $e,ff as Fp,n as br,lb as Ae,pb as dy,pc as fy,pd as gy,pe as zt,pf as Eo,pg as tr,ph as nr,pi as Cs,pj as xn,pk as Bs,pl as rr,pm as mn,pn as Us,l4 as ve,l1 as re,po as V,pp as Bp,pq as Ic,pr as uo,ca as No,ps as py,pt as fo,pu as wd,pv as Up,pw as zp,px as Il,py as hy,pz as Kp,pA as Ec,pB as _y,pC as my,pD as Nc,pE as El,pF as Wp,pG as by,pH as Hp,pI as yy,pJ as Lc,pK as Ss,kU as Ee,pL as wy,l6 as Nn,pM as xd,pN as xy,pO as Cy,pP as Cd,pQ as Nl,kV as Lo,pR as Oc,pS as bi,pT as sa,pU as Jp,pV as Rc,pW as ia,pX as Qs,pY as Sd,pZ as vd,p_ as zs,p$ as kd,q0 as Bn,q1 as Sy,q2 as vy,q3 as Xe,q4 as ky,q5 as Ty,q6 as qp,q7 as Vp,q8 as Yp,c9 as Ks,q9 as Ac,qa as Iy,qb as he,qc as Gp,qd as vs,qe as Ra,qf as Xp,qg as Mc,qh as Ll,qi as Ey,qj as Er,qk as wt,l5 as or,ql as aa,qm as Ny,qn as $c,qo as Zp,qp as Dc,qq as ps,qr as Td,qs as it,kA as ht,qt as Id,qu as Jt,qv as la,qw as Qp,qx as eh,qy as th,qz as Wn,qA as Ly,qB as Oy,qC as Ai,qD as Ry,qE as Ay,qF as My,qG as Ol,qH as hr,qI as nh,qJ as $y,qK as Rl,qL as Mi,qM as rh,l2 as Ht,qN as Oo,kZ as qe,qO as oh,qP as Dy,qQ as Py,ky as jy,qR as mo,qS as sr,qT as sh,qU as Fy,qV as By,qW as Pc,qX as ih,qY as Uy,qZ as Ed,q_ as zy,q$ as Nd,r0 as Ky,r1 as Wy,r2 as jc,r3 as Hy,r4 as Ld,kS as Jy,kR as qy,kQ as Vy,r5 as Od,kT as Yy,r6 as Rd,r7 as ah,G as fe,l7 as Gy,r8 as Xy,r9 as Zy,ra as Qy,rb as Ad,rc as ew,rd as tw,re as Md,rf as $d,rg as qn,rh as nw,ri as rw,rj as ow,rk as sw,rl as Fc,rm as iw,rn as aw,nt as Al,jF as Ml,eV as ks,ns as lw,l3 as bo,ro as lh,rp as $i,kB as ch,kG as Bc,kF as Uc,kE as uh,kH as dh,rq as fh,rr as $l,rs as Dd,rt as cw,ru as Dl,rv as ca,rw as gh,rx as ph,ry as uw,rz as hh,rA as _h,rB as $n,rC as dw,me as fw,mk as Pd,ml as Pl,mn as gw,mo as pw,rD as mh,rE as bh,rF as yh,rG as wh,rH as jd,C as xh,f as hw,rI as _w,rJ as mw,H as bw,rK as yw,rL as ww,aD as xw,aF as Cw,k as Ch,rM as Sw,aN as Sh,rN as vw,aJ as kw,rO as Tw,rP as Iw,kb as Lt,kj as Ke,kh as yr,ke as Qe,ki as wr,kg as Zt,kl as Ew,eN as Nw,e$ as Aa,i as Lw,rQ as yi,rR as Un,f0 as vh,rS as Ow,bm as zc,cd as Rw,rT as Kc,fo as Aw,rU as Mw,ms as $w,rV as Dw,rW as Pw,rX as jw,rY as Fw,rZ as kh,r_ as we,dx as yo,bd as Te,r$ as Th,m as Di,s0 as Bw,s1 as Uw,s2 as ei,s3 as zw,fE as Kw,s4 as Ww,s5 as Ko}from"../datalayer-app-main.js";import{d as Hw,b as Jw,E as qw,u as Vw,c as Yw,e as Gw,f as Xw}from"./NotebookSkeleton-D9WNoiWD.js";import{p as is,e as Zw,s as Qw,u as ex}from"./url-DEeTWrO-.js";import{r as tx,a as nx}from"./isSymbol-BLtK9CV6.js";import{t as Fd}from"./toNumber-B1wj8-wx.js";import{V as Ws,P as rx,C as Pi,D as Wc,T as Ih,H as ox,L as Eh,F as hs,Q as Nh,a as ji,M as sx,b as ix,B as Lh,I as Oh,S as Rh,R as ax,c as lx,d as cx}from"./VideoIcon-BjP_LDa4.js";import{L as Ah}from"./LinkIcon-DUI0jw25.js";import{A as ux}from"./Avatar-Dqz3ZWjZ.js";import{a as dx,T as fx}from"./Toolbar-B6ROXJ-2.js";import{A as gx,a as px}from"./ArrowUpIcon-BUCpIXDR.js";import{S as hx}from"./SortDescIcon-CS4EzHeS.js";import{P as jl,p as _x}from"./PrismCss-u5utqjht.js";import{d as ge,l as go}from"./LexicalToolRegistry-DoZIM1lF.js";const Fi=(n,e,t)=>Math.min(t,Math.max(e,n));function ts(n){const e=n.trim(),t=/^rgba?\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)/i.exec(e);if(t){const[,o,s,i]=t;return{r:Number(o),g:Number(s),b:Number(i)}}let r=e.replace(/^#/,"");return r.length===3&&(r=r.split("").map(o=>o+o).join("")),/^[0-9a-f]{6}$/i.test(r)?{r:parseInt(r.slice(0,2),16),g:parseInt(r.slice(2,4),16),b:parseInt(r.slice(4,6),16)}:{r:0,g:0,b:0}}function lr({r:n,g:e,b:t}){const r=o=>Fi(Math.round(o),0,255).toString(16).padStart(2,"0");return`#${r(n)}${r(e)}${r(t)}`}function Ma({r:n,g:e,b:t}){const r=n/255,o=e/255,s=t/255,i=Math.max(r,o,s),a=Math.min(r,o,s),l=i-a;let c=0;return l!==0&&(i===r?c=60*((o-s)/l%6):i===o?c=60*((s-r)/l+2):c=60*((r-o)/l+4)),c<0&&(c+=360),{h:c,s:i===0?0:l/i*100,v:i*100}}function ti({h:n,s:e,v:t}){const r=e/100,o=t/100,s=o*r,i=s*(1-Math.abs(n/60%2-1)),a=o-s,l=Math.floor((n%360+360)%360/60),[c,u,f]=[[s,i,0],[i,s,0],[0,s,i],[0,i,s],[i,0,s],[s,0,i]][l];return{r:Math.round((c+a)*255),g:Math.round((u+a)*255),b:Math.round((f+a)*255)}}function Bd(n){const e=n.trim();return/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(e)||/^rgba?\(\s*\d+[,\s]+\d+[,\s]+\d+/i.test(e)}const mx=["#cf222e","#bc4c00","#9a6700","#1a7f37","#0969da","#8250df","#bf3989","#24292f","#57606a","#8c959f","#d0d7de","#ffffff"];function bx(n="datalayer",e="light"){const t=Zb(n,e),r=bd[n]??bd.datalayer,s=(e==="auto"?typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":e)==="dark"?r.themeStyles.dark:r.themeStyles.light,i=a=>s[a];return{label:r.label,colors:[i("--bgColor-default"),i("--bgColor-muted"),i("--fgColor-default"),i("--fgColor-muted"),i("--fgColor-accent"),i("--fgColor-success"),i("--fgColor-attention"),i("--fgColor-danger"),t.glow,t.pop,t.spark,t.blaze,t.surge,t.flame,t.gold].filter(Boolean)}}function yx(n="datalayer",e="dark"){return{label:"Collaborators",colors:Hw(n,e)}}const wx=150,xx=12;function Ud(n){const e=S.useRef(null),t=S.useRef(!1),r=S.useCallback(s=>{const i=e.current;if(!i)return;const a=i.getBoundingClientRect();n(Fi((s.clientX-a.left)/a.width,0,1),Fi((s.clientY-a.top)/a.height,0,1))},[n]);return S.useEffect(()=>{const s=a=>t.current&&r(a),i=()=>{t.current=!1};return window.addEventListener("pointermove",s),window.addEventListener("pointerup",i),window.addEventListener("pointercancel",i),()=>{window.removeEventListener("pointermove",s),window.removeEventListener("pointerup",i),window.removeEventListener("pointercancel",i)}},[r]),{ref:e,onPointerDown:s=>{t.current=!0,r(s)}}}function Cx({color:n,onChange:e,presets:t=mx,showPresets:r=!0,presetGroups:o,showThemeColors:s=!0,showCollaboratorColors:i=!1,showInput:a=!0,width:l=232,"aria-label":c="Colour picker"}){const[u,f]=S.useState(()=>Ma(ts(n))),[d,g]=S.useState(()=>lr(ts(n))),h=S.useRef(!1);S.useEffect(()=>{if(h.current){h.current=!1;return}const L=ts(n);f(Ma(L)),g(lr(L))},[n]);const _=S.useMemo(()=>ti(u),[u]),m=S.useMemo(()=>lr(_),[_]),b=S.useCallback(L=>{h.current=!0,f(L);const A=lr(ti(L));g(A),e?.(A)},[e]),w=Ud(S.useCallback((L,A)=>b({...u,s:L*100,v:(1-A)*100}),[b,u])),C=Ud(S.useCallback(L=>b({...u,h:L*360}),[b,u])),{theme:v,colorMode:k}=Gb(),I=Xb(),E=k==="auto"?I:k,N=S.useMemo(()=>{const L=[];return r&&t.length>0&&L.push({label:"Presets",colors:t}),s&&L.push(bx(v,E)),i&&L.push(yx(v,E)),L.concat(o??[])},[v,o,t,E,i,r,s]),O=S.useId(),M=L=>{if(g(L),Bd(L)){const A=Ma(ts(L));h.current=!0,f(A),e?.(lr(ts(L)))}},R=(L,A)=>{const B=L.shiftKey?10:1,j=L.key==="ArrowLeft"||L.key==="ArrowDown",U=L.key==="ArrowRight"||L.key==="ArrowUp";if(!j&&!U)return;L.preventDefault();const z=U?B:-B,K=A==="h"?360:100;b({...u,[A]:Fi(u[A]+z,0,K)})},$={position:"absolute",width:14,height:14,borderRadius:"50%",border:"2px solid #ffffff",boxShadow:"0 0 0 1px rgba(0, 0, 0, 0.35)",transform:"translate(-50%, -50%)",pointerEvents:"none"};return x.jsxs(Y,{role:"group","aria-label":c,sx:{display:"grid",gap:2,width:l,minWidth:0},children:[x.jsx(Y,{ref:w.ref,role:"slider",tabIndex:0,"aria-label":"Saturation and brightness","aria-valuetext":`saturation ${Math.round(u.s)}%, brightness ${Math.round(u.v)}%`,onPointerDown:w.onPointerDown,onKeyDown:L=>R(L,L.key==="ArrowUp"||L.key==="ArrowDown"?"v":"s"),sx:{position:"relative",height:wx,borderRadius:"var(--theme-radius-card)",border:"1px solid",borderColor:"var(--borderColor-default)",cursor:"crosshair",touchAction:"none",backgroundColor:lr(ti({h:u.h,s:100,v:100})),backgroundImage:"linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, transparent)",backgroundOrigin:"border-box","&:focus-visible":{outline:"2px solid var(--borderColor-accent-emphasis)",outlineOffset:"1px"}},children:x.jsx(Y,{sx:{...$,left:`${u.s}%`,top:`${100-u.v}%`,backgroundColor:m}})}),x.jsx(Y,{ref:C.ref,role:"slider",tabIndex:0,"aria-label":"Hue","aria-valuemin":0,"aria-valuemax":360,"aria-valuenow":Math.round(u.h),onPointerDown:C.onPointerDown,onKeyDown:L=>R(L,"h"),sx:{position:"relative",height:xx,borderRadius:"var(--theme-radius-control)",border:"1px solid",borderColor:"var(--borderColor-default)",cursor:"ew-resize",touchAction:"none",backgroundImage:"linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%)","&:focus-visible":{outline:"2px solid var(--borderColor-accent-emphasis)",outlineOffset:"1px"}},children:x.jsx(Y,{sx:{...$,left:`${u.h/360*100}%`,top:"50%",backgroundColor:lr(ti({h:u.h,s:100,v:100}))}})}),a?x.jsxs(Y,{sx:{display:"flex",gap:2,alignItems:"center"},children:[x.jsx(Y,{"aria-hidden":"true",sx:{width:28,height:28,flex:"0 0 auto",borderRadius:"var(--borderRadius-medium)",border:"1px solid",borderColor:"var(--borderColor-default)",backgroundColor:m}}),x.jsx(vn,{"aria-label":"Colour, as hex",value:d,onChange:L=>M(L.target.value),onBlur:()=>g(m),size:"small",sx:{flex:"1 1 auto",fontFamily:"mono"},validationStatus:Bd(d)?void 0:"error"})]}):null,N.map(L=>x.jsxs(Y,{children:[x.jsx(Le,{id:`${O}-${L.label}`,sx:{fontSize:0,color:"var(--fgColor-muted)",display:"block",mb:1},children:L.label}),x.jsx(Y,{role:"group","aria-labelledby":`${O}-${L.label}`,sx:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(22px, 1fr))",gap:1},children:L.colors.map((A,B)=>{const j=A.toLowerCase()===m.toLowerCase();return x.jsx(Y,{as:"button",type:"button","aria-label":A,"aria-pressed":j,onClick:()=>M(A),sx:{height:22,borderRadius:"var(--theme-radius-control)",cursor:"pointer",backgroundColor:A,border:"1px solid",borderColor:j?"var(--borderColor-accent-emphasis)":"var(--borderColor-default)",boxShadow:j?"inset 0 0 0 2px var(--bgColor-default)":"none","&:focus-visible":{outline:"2px solid var(--borderColor-accent-emphasis)",outlineOffset:"1px"}}},`${A}-${B}`)})})]},L.label))]})}const Sx=n=>{const{closeButtonRef:e,content:t,direction:r,headingRef:o,isOpen:s,openButtonRef:i,setIsOpen:a,width:l,zIndex:c}=n,{theme:u,colorMode:f}=Qb(),[d,g]=S.useState(r),[h,_]=S.useState(0);S.useEffect(()=>{_(o?.current?.getBoundingClientRect().bottom??0)},[o]);const m=()=>a(!1),b=C=>{C.target instanceof HTMLElement&&C.target.closest('[role="dialog"]')||m()},w=x.jsx(ey,{theme:u,colorMode:f,children:x.jsxs(co,{sx:{height:`calc(100vh - ${h}px - 8px)`,width:l,display:"flex",flexDirection:"column",alignItems:"center",padding:"4px"},children:[x.jsx(co,{sx:{display:"flex",justifyContent:"right",width:"100%"},children:x.jsx(Ft,{variant:"invisible",ref:e,onClick:m,icon:Rp,"aria-label":"Close"})}),t]})});return e&&i?x.jsx(x.Fragment,{children:s?d==="left"?x.jsx(co,{sx:{zIndex:c},children:x.jsx(kl,{initialFocusRef:e,returnFocusRef:i,ignoreClickRefs:[i],onEscape:m,onClickOutside:b,width:"auto",anchorSide:"inside-right",left:0,position:"fixed",top:h,children:w})}):x.jsx(co,{sx:{zIndex:c},children:x.jsx(kl,{initialFocusRef:e,returnFocusRef:i,ignoreClickRefs:[i],onEscape:m,onClickOutside:b,width:"auto",anchorSide:"inside-left",right:0,position:"fixed",top:h,children:w})}):x.jsx(x.Fragment,{})}):x.jsx(x.Fragment,{})},vx=({width:n="500px",direction:e="left",zIndex:t=100,...r})=>x.jsx(Sx,{width:n,direction:e,zIndex:t,...r});function kx(n,e,t,r=10,o=5){if(n===null){e.style.opacity="0",e.style.transform="translateY(-4px)",e.style.top="-10000px",e.style.left="-10000px";return}const s=e.getBoundingClientRect(),i=t.getBoundingClientRect();let a=n.top-i.top-s.height-r,l=n.left-i.left-o;a<0&&(a=n.bottom-i.top+r),l+s.width>i.width&&(l=i.width-s.width-o),l<o&&(l=o),e.style.opacity="1",e.style.transform="translateY(0)",e.style.top=`${a}px`,e.style.left=`${l}px`}function Tx({items:n,extraItems:e,anchorElement:t,isVisible:r,className:o,disabled:s,ariaLabel:i="Floating toolbar",portalContainer:a}){const l=S.useRef(null),c=S.useMemo(()=>e?.length?[...n,...e]:n,[n,e]),u=S.useCallback(()=>{const g=l.current;if(!g||!t)return;const h=window.getSelection();if(!h||h.isCollapsed||!r){g.style.opacity="0",g.style.transform="translateY(-4px)";return}const m=h.getRangeAt(0).getBoundingClientRect();kx(m,g,t)},[t,r]);if(S.useEffect(()=>{if(!r)return;const g=()=>u();window.addEventListener("resize",g),window.addEventListener("scroll",g,!0);const h=t?.parentElement;return h&&h.addEventListener("scroll",g),g(),()=>{window.removeEventListener("resize",g),window.removeEventListener("scroll",g,!0),h&&h.removeEventListener("scroll",g)}},[r,u,t]),!r||c.length===0)return null;const f=a||t||document.body,d=x.jsx(co,{ref:l,className:o,role:"toolbar","aria-label":i,sx:{display:"flex",alignItems:"center",gap:"2px",px:1,py:"4px",bg:"var(--overlay-bgColor, var(--bgColor-default))",border:"1px solid",borderColor:"var(--borderColor-muted, transparent)",borderRadius:2,boxShadow:"shadow.large",position:"absolute",zIndex:10,top:"-10000px",left:"-10000px",opacity:0,transition:"opacity 0.15s ease, transform 0.15s ease",transform:"translateY(-4px)"},children:x.jsx(dx,{items:c,disabled:s,size:"small"})});return St.createPortal(d,f)}var $a=function(){return tx.Date.now()},Ix="Expected a function",Ex=Math.max,Nx=Math.min;function Lx(n,e,t){var r,o,s,i,a,l,c=0,u=!1,f=!1,d=!0;if(typeof n!="function")throw new TypeError(Ix);e=Fd(e)||0,nx(t)&&(u=!!t.leading,f="maxWait"in t,s=f?Ex(Fd(t.maxWait)||0,e):s,d="trailing"in t?!!t.trailing:d);function g(I){var E=r,N=o;return r=o=void 0,c=I,i=n.apply(N,E),i}function h(I){return c=I,a=setTimeout(b,e),u?g(I):i}function _(I){var E=I-l,N=I-c,O=e-E;return f?Nx(O,s-N):O}function m(I){var E=I-l,N=I-c;return l===void 0||E>=e||E<0||f&&N>=s}function b(){var I=$a();if(m(I))return w(I);a=setTimeout(b,_(I))}function w(I){return a=void 0,d&&r?g(I):(r=o=void 0,i)}function C(){a!==void 0&&clearTimeout(a),c=0,r=l=o=a=void 0}function v(){return a===void 0?i:w($a())}function k(){var I=$a(),E=m(I);if(r=arguments,o=this,l=I,E){if(a===void 0)return h(l);if(f)return clearTimeout(a),a=setTimeout(b,e),g(l)}return a===void 0&&(a=setTimeout(b,e)),i}return k.cancel=C,k.flush=v,k}const Mh=[];let Ts=class extends Oe{__ids;$config(){return this.config("mark",{extends:Oe})}afterCloneFrom(e){super.afterCloneFrom(e),this.__ids=e.__ids}updateFromJSON(e){return super.updateFromJSON(e).setIDs(e.ids)}exportJSON(){return{...super.exportJSON(),ids:this.getIDs()}}constructor(e=Mh,t){super(t),this.__ids=e}createDOM(e){const t=Je().createElement("mark");return Ie(t,e.theme.mark),this.__ids.length>1&&Ie(t,e.theme.markOverlap),t}updateDOM(e,t,r){const o=e.__ids,s=this.__ids,i=o.length,a=s.length,l=r.theme.markOverlap;return i!==a&&(i===1?a===2&&Ie(t,l):a===1&&$t(t,l)),!1}hasID(e){return this.getIDs().includes(e)}getIDs(){return Array.from(this.getLatest().__ids)}setIDs(e){const t=this.getWritable();return t.__ids=e,t}addID(e){const t=this.getWritable();return t.__ids.includes(e)?t:t.setIDs([...t.__ids,e])}deleteID(e){const t=this.getWritable(),r=t.__ids.indexOf(e);if(r===-1)return t;const o=Array.from(t.__ids);return o.splice(r,1),t.setIDs(o)}insertNewAfter(e,t=!0){const r=Hc(this.__ids);return this.insertAfter(r,t),r}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(e,t,r){if(!F(t)||r==="html")return!1;const o=t.anchor,s=t.focus,i=o.getNode(),a=s.getNode(),l=t.isBackward()?o.offset-s.offset:s.offset-o.offset;return this.isParentOf(i)&&this.isParentOf(a)&&this.getTextContent().length===l}excludeFromCopy(e){return e!=="clone"}};function Hc(n=Mh){return Ot(new Ts(n))}function Ro(n){return n instanceof Ts}function Ox(n){const e=n.getChildren();let t=null;for(let r=0;r<e.length;r++){const o=e[r];t===null?n.insertBefore(o):t.insertAfter(o),t=o}n.remove()}function Rx(n,e,t,r){const o=kr(),[s,i]=n.isBackward()?[n.focus,n.anchor]:[n.anchor,n.focus];let a,l;o.anchor.set(s.key,s.offset,s.type),o.focus.set(i.key,i.offset,i.type);const c=o.extract();for(const u of c){if(q(l)&&l.isParentOf(u))continue;let f=null;if(oe(u))f=u;else{if(Ro(u))continue;(q(u)||It(u))&&u.isInline()&&(f=u)}if(f!==null){if(f&&f.is(a))continue;const d=f.getParent();d!=null&&d.is(a)||(l=void 0),a=d,l===void 0&&(l=Hc([t]),f.insertBefore(l)),l.append(f)}else a=void 0,l=void 0}q(l)&&(e?l.selectStart():l.selectEnd())}function Ax(n,e){let t=n;for(;t!==null;){if(Ro(t))return t.getIDs();if(oe(t)&&e===t.getTextContentSize()){const r=t.getNextSibling();if(Ro(r))return r.getIDs()}t=t.getParent()}return null}const Mx=pe({name:"@lexical/mark",nodes:()=>[Ts]});class Ao extends Bt{__id;__quote;__comments;static getType(){return"comment-thread"}static clone(e){return new Ao(e.__id,e.__quote,e.__comments,e.__key)}static importJSON(e){return new Ao(e.id,e.quote,e.comments)}exportJSON(){return{type:"comment-thread",version:1,id:this.__id,quote:this.__quote,comments:this.__comments}}constructor(e,t,r,o){super(o),this.__id=e,this.__quote=t,this.__comments=r}createDOM(e){const t=document.createElement("div");return t.style.display="none",t}updateDOM(){return!1}isInline(){return!1}getId(){return this.__id}getQuote(){return this.__quote}getComments(){return this.__comments}addComment(e){const t=this.getWritable();t.__comments=[...t.__comments,e]}deleteComment(e){const t=this.getWritable();t.__comments=t.__comments.map(r=>r.id===e?{...r,deleted:!0,content:"[Deleted Comment]"}:r)}decorate(e){return x.jsx(x.Fragment,{})}}function $x(n,e,t){return new Ao(n,e,t)}function ni(n){return n instanceof Ao}const wo=n=>n.name||n.handle||n.uid,Jc=n=>n.name||n.handle||n.uid||"Anonymous",qc=n=>({kind:"anonymous",name:n||"Anonymous"}),Dx=n=>n.authorPrincipal??qc(n.author);function $h(n,e){const t=[];for(const r of e)n.includes(`@${wo(r)}`)&&!t.includes(r.uid)&&t.push(r.uid);return t}function Dh(){return Math.random().toString(36).replace(/[^a-z]+/g,"").substr(0,5)}function Ph(n,e,t,r,o,s){const i=typeof e=="string"?qc(e):e;return{author:Jc(i),authorPrincipal:i,content:n,deleted:o===void 0?!1:o,id:t===void 0?Dh():t,...s&&s.length>0?{mentions:s}:{},timeStamp:r===void 0?Date.now():r,type:"comment"}}function Px(n,e,t){return{comments:e,id:t===void 0?Dh():t,quote:n,type:"thread"}}function jx(n){return{author:n.author,...n.authorPrincipal?{authorPrincipal:n.authorPrincipal}:{},content:"[Deleted Comment]",deleted:!0,id:n.id,timeStamp:n.timeStamp,type:"comment"}}function Fx(n){const e=n._changeListeners;for(const t of e)t()}class Bx{_editor;_changeListeners;constructor(e){this._editor=e,this._changeListeners=new Set,this._editor.registerUpdateListener(()=>{Fx(this)})}getComments(){const e=[];return this._editor.getEditorState().read(()=>{se().getChildren().forEach(r=>{if(ni(r)){const o=r;e.push({type:"thread",id:o.getId(),quote:o.getQuote(),comments:o.getComments()})}})}),e}addComment(e,t,r){this._editor.update(()=>{if(t!==void 0&&e.type==="comment")se().getChildren().forEach(s=>{if(ni(s)){const i=s;i.getId()===t.id&&i.addComment(e)}});else if(e.type==="thread"){const o=$x(e.id,e.quote,e.comments);se().append(o)}})}deleteComment(e,t){const r=this.deleteCommentOrThread(e,t);r!==null&&this.addComment(r.markedComment,t,r.index)}deleteThread(e){this.deleteCommentOrThread(e)}deleteCommentOrThread(e,t){let r=null;return this._editor.update(()=>{t!==void 0&&e.type==="comment"?se().getChildren().forEach(s=>{if(ni(s)){const i=s;i.getId()===t.id&&(r=i.getComments().findIndex(l=>l.id===e.id),i.deleteComment(e.id))}}):se().getChildren().forEach(s=>{ni(s)&&s.getId()===e.id&&s.remove()})}),e.type==="comment"?{index:r!==null?r:0,markedComment:jx(e)}:null}registerOnChange(e){const t=this._changeListeners;return t.add(e),()=>{t.delete(e)}}}function Ux(n){const[e,t]=S.useState(n.getComments());return S.useEffect(()=>(t(n.getComments()),n.registerOnChange(()=>{t(n.getComments())})),[n]),e}const xr=({"data-test-id":n,children:e,className:t,onClick:r,disabled:o,small:s,title:i})=>x.jsx(ft,{disabled:o,onClick:r,title:i,"aria-label":i,size:s?"small":"medium",variant:"default",className:t,...n&&{"data-test-id":n},children:e}),zx=({className:n,style:e})=>x.jsx(Ap,{className:n||"ContentEditable__root",style:e});function kM({label:n="Loading the document",header:e=!1,maxWidth:t=760}={}){return x.jsxs(Jw,{label:n,sx:{flex:1,minHeight:0,width:"100%",overflow:"hidden"},children:[e?x.jsx(qw,{}):null,x.jsxs(co,{sx:{px:4,py:e?0:4,pb:4,display:"grid",gap:4,maxWidth:t,mx:"auto",width:"100%"},children:[x.jsx(Zs,{size:"titleLarge",lines:1,maxWidth:"22rem"}),x.jsx(Zs,{size:"bodyMedium",lines:3}),x.jsx(Zs,{size:"bodyMedium",lines:4,maxWidth:"92%"}),x.jsx(ty,{width:"100%",height:"120px"}),x.jsx(Zs,{size:"bodyMedium",lines:3,maxWidth:"88%"})]})]})}function Kx({equation:n,setEquation:e,inline:t,inputRef:r}){const s={equation:n,inputRef:r,onChange:i=>{e(i.target.value)}};return t?x.jsx(Wx,{...s,inputRef:r}):x.jsx(Hx,{...s,inputRef:r})}function Wx({equation:n,onChange:e,inputRef:t}){return x.jsxs("span",{className:"EquationEditor_inputBackground",children:[x.jsx("span",{className:"EquationEditor_dollarSign",children:"$"}),x.jsx("input",{className:"EquationEditor_inlineEditor",value:n,onChange:e,autoFocus:!0,ref:t}),x.jsx("span",{className:"EquationEditor_dollarSign",children:"$"})]})}function Hx({equation:n,onChange:e,inputRef:t}){return x.jsxs("div",{className:"EquationEditor_inputBackground",children:[x.jsx("span",{className:"EquationEditor_dollarSign",children:`$$
1
+ import{r as S,az as Gb,aA as Xb,j as x,bw as Y,cL as vn,T as Le,dt as Zb,bx as bd,gS as Qb,oy as ey,B as co,I as Ft,eK as Rp,oz as kl,br as St,ay as pe,oA as Oe,oB as Je,oC as Ie,oD as $t,kY as F,oE as Ot,oF as kr,kD as q,kI as oe,kJ as It,oG as Bt,aL as se,c as ft,aE as Ap,dv as Zs,ds as ty,fw as Mt,_ as me,k5 as Mp,fy as ny,D as $p,oH as ry,oI as _o,oJ as Tc,oK as zo,kL as bt,oL as Kn,kC as vt,aM as ne,oM as js,c8 as de,oN as oy,k_ as zr,kX as D,cb as ee,oO as ln,oP as Dp,oQ as sy,oR as Fs,l9 as cn,lc as ke,kK as ue,oS as Ye,oT as Ge,oU as Pp,oV as yd,oW as gt,oX as iy,l0 as Kr,kW as wn,oY as Tl,k$ as Dt,oZ as un,o_ as Tr,o$ as pt,p0 as Vt,p1 as Ir,p2 as xs,p3 as jp,p4 as Ri,p5 as ay,p6 as mi,p7 as Jn,p8 as ly,p9 as cy,cc as Q,pa as uy,kz as $e,ff as Fp,n as br,lb as Ae,pb as dy,pc as fy,pd as gy,pe as zt,pf as Eo,pg as tr,ph as nr,pi as Cs,pj as xn,pk as Bs,pl as rr,pm as mn,pn as Us,l4 as ve,l1 as re,po as V,pp as Bp,pq as Ic,pr as uo,ca as No,ps as py,pt as fo,pu as wd,pv as Up,pw as zp,px as Il,py as hy,pz as Kp,pA as Ec,pB as _y,pC as my,pD as Nc,pE as El,pF as Wp,pG as by,pH as Hp,pI as yy,pJ as Lc,pK as Ss,kU as Ee,pL as wy,l6 as Nn,pM as xd,pN as xy,pO as Cy,pP as Cd,pQ as Nl,kV as Lo,pR as Oc,pS as bi,pT as sa,pU as Jp,pV as Rc,pW as ia,pX as Qs,pY as Sd,pZ as vd,p_ as zs,p$ as kd,q0 as Bn,q1 as Sy,q2 as vy,q3 as Xe,q4 as ky,q5 as Ty,q6 as qp,q7 as Vp,q8 as Yp,c9 as Ks,q9 as Ac,qa as Iy,qb as he,qc as Gp,qd as vs,qe as Ra,qf as Xp,qg as Mc,qh as Ll,qi as Ey,qj as Er,qk as wt,l5 as or,ql as aa,qm as Ny,qn as $c,qo as Zp,qp as Dc,qq as ps,qr as Td,qs as it,kA as ht,qt as Id,qu as Jt,qv as la,qw as Qp,qx as eh,qy as th,qz as Wn,qA as Ly,qB as Oy,qC as Ai,qD as Ry,qE as Ay,qF as My,qG as Ol,qH as hr,qI as nh,qJ as $y,qK as Rl,qL as Mi,qM as rh,l2 as Ht,qN as Oo,kZ as qe,qO as oh,qP as Dy,qQ as Py,ky as jy,qR as mo,qS as sr,qT as sh,qU as Fy,qV as By,qW as Pc,qX as ih,qY as Uy,qZ as Ed,q_ as zy,q$ as Nd,r0 as Ky,r1 as Wy,r2 as jc,r3 as Hy,r4 as Ld,kS as Jy,kR as qy,kQ as Vy,r5 as Od,kT as Yy,r6 as Rd,r7 as ah,G as fe,l7 as Gy,r8 as Xy,r9 as Zy,ra as Qy,rb as Ad,rc as ew,rd as tw,re as Md,rf as $d,rg as qn,rh as nw,ri as rw,rj as ow,rk as sw,rl as Fc,rm as iw,rn as aw,nt as Al,jF as Ml,eV as ks,ns as lw,l3 as bo,ro as lh,rp as $i,kB as ch,kG as Bc,kF as Uc,kE as uh,kH as dh,rq as fh,rr as $l,rs as Dd,rt as cw,ru as Dl,rv as ca,rw as gh,rx as ph,ry as uw,rz as hh,rA as _h,rB as $n,rC as dw,me as fw,mk as Pd,ml as Pl,mn as gw,mo as pw,rD as mh,rE as bh,rF as yh,rG as wh,rH as jd,C as xh,f as hw,rI as _w,rJ as mw,H as bw,rK as yw,rL as ww,aD as xw,aF as Cw,k as Ch,rM as Sw,aN as Sh,rN as vw,aJ as kw,rO as Tw,rP as Iw,kb as Lt,kj as Ke,kh as yr,ke as Qe,ki as wr,kg as Zt,kl as Ew,eN as Nw,e$ as Aa,i as Lw,rQ as yi,rR as Un,f0 as vh,rS as Ow,bt as zc,cd as Rw,rT as Kc,fo as Aw,rU as Mw,ms as $w,rV as Dw,rW as Pw,rX as jw,rY as Fw,rZ as kh,r_ as we,dx as yo,bk as Te,r$ as Th,m as Di,s0 as Bw,s1 as Uw,s2 as ei,s3 as zw,gX as Kw,s4 as Ww,s5 as Ko}from"../datalayer-app-main.js";import{d as Hw,b as Jw,E as qw,u as Vw,c as Yw,e as Gw,f as Xw}from"./NotebookSkeleton-z8GKB7Tb.js";import{p as is,e as Zw,s as Qw,u as ex}from"./url-DEeTWrO-.js";import{r as tx,a as nx}from"./isSymbol-BLtK9CV6.js";import{t as Fd}from"./toNumber-B1wj8-wx.js";import{V as Ws,P as rx,C as Pi,D as Wc,T as Ih,H as ox,L as Eh,F as hs,Q as Nh,a as ji,M as sx,b as ix,B as Lh,I as Oh,S as Rh,R as ax,c as lx,d as cx}from"./VideoIcon-BjP_LDa4.js";import{L as Ah}from"./LinkIcon-DUI0jw25.js";import{A as ux}from"./Avatar-BrPfm89P.js";import{a as dx,T as fx}from"./Toolbar-BxAi9T92.js";import{A as gx,a as px}from"./ArrowUpIcon-BUCpIXDR.js";import{S as hx}from"./SortDescIcon-CS4EzHeS.js";import{P as jl,p as _x}from"./PrismCss-u5utqjht.js";import{d as ge,l as go}from"./LexicalToolRegistry-DoZIM1lF.js";const Fi=(n,e,t)=>Math.min(t,Math.max(e,n));function ts(n){const e=n.trim(),t=/^rgba?\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)/i.exec(e);if(t){const[,o,s,i]=t;return{r:Number(o),g:Number(s),b:Number(i)}}let r=e.replace(/^#/,"");return r.length===3&&(r=r.split("").map(o=>o+o).join("")),/^[0-9a-f]{6}$/i.test(r)?{r:parseInt(r.slice(0,2),16),g:parseInt(r.slice(2,4),16),b:parseInt(r.slice(4,6),16)}:{r:0,g:0,b:0}}function lr({r:n,g:e,b:t}){const r=o=>Fi(Math.round(o),0,255).toString(16).padStart(2,"0");return`#${r(n)}${r(e)}${r(t)}`}function Ma({r:n,g:e,b:t}){const r=n/255,o=e/255,s=t/255,i=Math.max(r,o,s),a=Math.min(r,o,s),l=i-a;let c=0;return l!==0&&(i===r?c=60*((o-s)/l%6):i===o?c=60*((s-r)/l+2):c=60*((r-o)/l+4)),c<0&&(c+=360),{h:c,s:i===0?0:l/i*100,v:i*100}}function ti({h:n,s:e,v:t}){const r=e/100,o=t/100,s=o*r,i=s*(1-Math.abs(n/60%2-1)),a=o-s,l=Math.floor((n%360+360)%360/60),[c,u,f]=[[s,i,0],[i,s,0],[0,s,i],[0,i,s],[i,0,s],[s,0,i]][l];return{r:Math.round((c+a)*255),g:Math.round((u+a)*255),b:Math.round((f+a)*255)}}function Bd(n){const e=n.trim();return/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(e)||/^rgba?\(\s*\d+[,\s]+\d+[,\s]+\d+/i.test(e)}const mx=["#cf222e","#bc4c00","#9a6700","#1a7f37","#0969da","#8250df","#bf3989","#24292f","#57606a","#8c959f","#d0d7de","#ffffff"];function bx(n="datalayer",e="light"){const t=Zb(n,e),r=bd[n]??bd.datalayer,s=(e==="auto"?typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":e)==="dark"?r.themeStyles.dark:r.themeStyles.light,i=a=>s[a];return{label:r.label,colors:[i("--bgColor-default"),i("--bgColor-muted"),i("--fgColor-default"),i("--fgColor-muted"),i("--fgColor-accent"),i("--fgColor-success"),i("--fgColor-attention"),i("--fgColor-danger"),t.glow,t.pop,t.spark,t.blaze,t.surge,t.flame,t.gold].filter(Boolean)}}function yx(n="datalayer",e="dark"){return{label:"Collaborators",colors:Hw(n,e)}}const wx=150,xx=12;function Ud(n){const e=S.useRef(null),t=S.useRef(!1),r=S.useCallback(s=>{const i=e.current;if(!i)return;const a=i.getBoundingClientRect();n(Fi((s.clientX-a.left)/a.width,0,1),Fi((s.clientY-a.top)/a.height,0,1))},[n]);return S.useEffect(()=>{const s=a=>t.current&&r(a),i=()=>{t.current=!1};return window.addEventListener("pointermove",s),window.addEventListener("pointerup",i),window.addEventListener("pointercancel",i),()=>{window.removeEventListener("pointermove",s),window.removeEventListener("pointerup",i),window.removeEventListener("pointercancel",i)}},[r]),{ref:e,onPointerDown:s=>{t.current=!0,r(s)}}}function Cx({color:n,onChange:e,presets:t=mx,showPresets:r=!0,presetGroups:o,showThemeColors:s=!0,showCollaboratorColors:i=!1,showInput:a=!0,width:l=232,"aria-label":c="Colour picker"}){const[u,f]=S.useState(()=>Ma(ts(n))),[d,g]=S.useState(()=>lr(ts(n))),h=S.useRef(!1);S.useEffect(()=>{if(h.current){h.current=!1;return}const L=ts(n);f(Ma(L)),g(lr(L))},[n]);const _=S.useMemo(()=>ti(u),[u]),m=S.useMemo(()=>lr(_),[_]),b=S.useCallback(L=>{h.current=!0,f(L);const A=lr(ti(L));g(A),e?.(A)},[e]),w=Ud(S.useCallback((L,A)=>b({...u,s:L*100,v:(1-A)*100}),[b,u])),C=Ud(S.useCallback(L=>b({...u,h:L*360}),[b,u])),{theme:v,colorMode:k}=Gb(),I=Xb(),E=k==="auto"?I:k,N=S.useMemo(()=>{const L=[];return r&&t.length>0&&L.push({label:"Presets",colors:t}),s&&L.push(bx(v,E)),i&&L.push(yx(v,E)),L.concat(o??[])},[v,o,t,E,i,r,s]),O=S.useId(),M=L=>{if(g(L),Bd(L)){const A=Ma(ts(L));h.current=!0,f(A),e?.(lr(ts(L)))}},R=(L,A)=>{const B=L.shiftKey?10:1,j=L.key==="ArrowLeft"||L.key==="ArrowDown",U=L.key==="ArrowRight"||L.key==="ArrowUp";if(!j&&!U)return;L.preventDefault();const z=U?B:-B,K=A==="h"?360:100;b({...u,[A]:Fi(u[A]+z,0,K)})},$={position:"absolute",width:14,height:14,borderRadius:"50%",border:"2px solid #ffffff",boxShadow:"0 0 0 1px rgba(0, 0, 0, 0.35)",transform:"translate(-50%, -50%)",pointerEvents:"none"};return x.jsxs(Y,{role:"group","aria-label":c,sx:{display:"grid",gap:2,width:l,minWidth:0},children:[x.jsx(Y,{ref:w.ref,role:"slider",tabIndex:0,"aria-label":"Saturation and brightness","aria-valuetext":`saturation ${Math.round(u.s)}%, brightness ${Math.round(u.v)}%`,onPointerDown:w.onPointerDown,onKeyDown:L=>R(L,L.key==="ArrowUp"||L.key==="ArrowDown"?"v":"s"),sx:{position:"relative",height:wx,borderRadius:"var(--theme-radius-card)",border:"1px solid",borderColor:"var(--borderColor-default)",cursor:"crosshair",touchAction:"none",backgroundColor:lr(ti({h:u.h,s:100,v:100})),backgroundImage:"linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, transparent)",backgroundOrigin:"border-box","&:focus-visible":{outline:"2px solid var(--borderColor-accent-emphasis)",outlineOffset:"1px"}},children:x.jsx(Y,{sx:{...$,left:`${u.s}%`,top:`${100-u.v}%`,backgroundColor:m}})}),x.jsx(Y,{ref:C.ref,role:"slider",tabIndex:0,"aria-label":"Hue","aria-valuemin":0,"aria-valuemax":360,"aria-valuenow":Math.round(u.h),onPointerDown:C.onPointerDown,onKeyDown:L=>R(L,"h"),sx:{position:"relative",height:xx,borderRadius:"var(--theme-radius-control)",border:"1px solid",borderColor:"var(--borderColor-default)",cursor:"ew-resize",touchAction:"none",backgroundImage:"linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%)","&:focus-visible":{outline:"2px solid var(--borderColor-accent-emphasis)",outlineOffset:"1px"}},children:x.jsx(Y,{sx:{...$,left:`${u.h/360*100}%`,top:"50%",backgroundColor:lr(ti({h:u.h,s:100,v:100}))}})}),a?x.jsxs(Y,{sx:{display:"flex",gap:2,alignItems:"center"},children:[x.jsx(Y,{"aria-hidden":"true",sx:{width:28,height:28,flex:"0 0 auto",borderRadius:"var(--borderRadius-medium)",border:"1px solid",borderColor:"var(--borderColor-default)",backgroundColor:m}}),x.jsx(vn,{"aria-label":"Colour, as hex",value:d,onChange:L=>M(L.target.value),onBlur:()=>g(m),size:"small",sx:{flex:"1 1 auto",fontFamily:"mono"},validationStatus:Bd(d)?void 0:"error"})]}):null,N.map(L=>x.jsxs(Y,{children:[x.jsx(Le,{id:`${O}-${L.label}`,sx:{fontSize:0,color:"var(--fgColor-muted)",display:"block",mb:1},children:L.label}),x.jsx(Y,{role:"group","aria-labelledby":`${O}-${L.label}`,sx:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(22px, 1fr))",gap:1},children:L.colors.map((A,B)=>{const j=A.toLowerCase()===m.toLowerCase();return x.jsx(Y,{as:"button",type:"button","aria-label":A,"aria-pressed":j,onClick:()=>M(A),sx:{height:22,borderRadius:"var(--theme-radius-control)",cursor:"pointer",backgroundColor:A,border:"1px solid",borderColor:j?"var(--borderColor-accent-emphasis)":"var(--borderColor-default)",boxShadow:j?"inset 0 0 0 2px var(--bgColor-default)":"none","&:focus-visible":{outline:"2px solid var(--borderColor-accent-emphasis)",outlineOffset:"1px"}}},`${A}-${B}`)})})]},L.label))]})}const Sx=n=>{const{closeButtonRef:e,content:t,direction:r,headingRef:o,isOpen:s,openButtonRef:i,setIsOpen:a,width:l,zIndex:c}=n,{theme:u,colorMode:f}=Qb(),[d,g]=S.useState(r),[h,_]=S.useState(0);S.useEffect(()=>{_(o?.current?.getBoundingClientRect().bottom??0)},[o]);const m=()=>a(!1),b=C=>{C.target instanceof HTMLElement&&C.target.closest('[role="dialog"]')||m()},w=x.jsx(ey,{theme:u,colorMode:f,children:x.jsxs(co,{sx:{height:`calc(100vh - ${h}px - 8px)`,width:l,display:"flex",flexDirection:"column",alignItems:"center",padding:"4px"},children:[x.jsx(co,{sx:{display:"flex",justifyContent:"right",width:"100%"},children:x.jsx(Ft,{variant:"invisible",ref:e,onClick:m,icon:Rp,"aria-label":"Close"})}),t]})});return e&&i?x.jsx(x.Fragment,{children:s?d==="left"?x.jsx(co,{sx:{zIndex:c},children:x.jsx(kl,{initialFocusRef:e,returnFocusRef:i,ignoreClickRefs:[i],onEscape:m,onClickOutside:b,width:"auto",anchorSide:"inside-right",left:0,position:"fixed",top:h,children:w})}):x.jsx(co,{sx:{zIndex:c},children:x.jsx(kl,{initialFocusRef:e,returnFocusRef:i,ignoreClickRefs:[i],onEscape:m,onClickOutside:b,width:"auto",anchorSide:"inside-left",right:0,position:"fixed",top:h,children:w})}):x.jsx(x.Fragment,{})}):x.jsx(x.Fragment,{})},vx=({width:n="500px",direction:e="left",zIndex:t=100,...r})=>x.jsx(Sx,{width:n,direction:e,zIndex:t,...r});function kx(n,e,t,r=10,o=5){if(n===null){e.style.opacity="0",e.style.transform="translateY(-4px)",e.style.top="-10000px",e.style.left="-10000px";return}const s=e.getBoundingClientRect(),i=t.getBoundingClientRect();let a=n.top-i.top-s.height-r,l=n.left-i.left-o;a<0&&(a=n.bottom-i.top+r),l+s.width>i.width&&(l=i.width-s.width-o),l<o&&(l=o),e.style.opacity="1",e.style.transform="translateY(0)",e.style.top=`${a}px`,e.style.left=`${l}px`}function Tx({items:n,extraItems:e,anchorElement:t,isVisible:r,className:o,disabled:s,ariaLabel:i="Floating toolbar",portalContainer:a}){const l=S.useRef(null),c=S.useMemo(()=>e?.length?[...n,...e]:n,[n,e]),u=S.useCallback(()=>{const g=l.current;if(!g||!t)return;const h=window.getSelection();if(!h||h.isCollapsed||!r){g.style.opacity="0",g.style.transform="translateY(-4px)";return}const m=h.getRangeAt(0).getBoundingClientRect();kx(m,g,t)},[t,r]);if(S.useEffect(()=>{if(!r)return;const g=()=>u();window.addEventListener("resize",g),window.addEventListener("scroll",g,!0);const h=t?.parentElement;return h&&h.addEventListener("scroll",g),g(),()=>{window.removeEventListener("resize",g),window.removeEventListener("scroll",g,!0),h&&h.removeEventListener("scroll",g)}},[r,u,t]),!r||c.length===0)return null;const f=a||t||document.body,d=x.jsx(co,{ref:l,className:o,role:"toolbar","aria-label":i,sx:{display:"flex",alignItems:"center",gap:"2px",px:1,py:"4px",bg:"var(--overlay-bgColor, var(--bgColor-default))",border:"1px solid",borderColor:"var(--borderColor-muted, transparent)",borderRadius:2,boxShadow:"shadow.large",position:"absolute",zIndex:10,top:"-10000px",left:"-10000px",opacity:0,transition:"opacity 0.15s ease, transform 0.15s ease",transform:"translateY(-4px)"},children:x.jsx(dx,{items:c,disabled:s,size:"small"})});return St.createPortal(d,f)}var $a=function(){return tx.Date.now()},Ix="Expected a function",Ex=Math.max,Nx=Math.min;function Lx(n,e,t){var r,o,s,i,a,l,c=0,u=!1,f=!1,d=!0;if(typeof n!="function")throw new TypeError(Ix);e=Fd(e)||0,nx(t)&&(u=!!t.leading,f="maxWait"in t,s=f?Ex(Fd(t.maxWait)||0,e):s,d="trailing"in t?!!t.trailing:d);function g(I){var E=r,N=o;return r=o=void 0,c=I,i=n.apply(N,E),i}function h(I){return c=I,a=setTimeout(b,e),u?g(I):i}function _(I){var E=I-l,N=I-c,O=e-E;return f?Nx(O,s-N):O}function m(I){var E=I-l,N=I-c;return l===void 0||E>=e||E<0||f&&N>=s}function b(){var I=$a();if(m(I))return w(I);a=setTimeout(b,_(I))}function w(I){return a=void 0,d&&r?g(I):(r=o=void 0,i)}function C(){a!==void 0&&clearTimeout(a),c=0,r=l=o=a=void 0}function v(){return a===void 0?i:w($a())}function k(){var I=$a(),E=m(I);if(r=arguments,o=this,l=I,E){if(a===void 0)return h(l);if(f)return clearTimeout(a),a=setTimeout(b,e),g(l)}return a===void 0&&(a=setTimeout(b,e)),i}return k.cancel=C,k.flush=v,k}const Mh=[];let Ts=class extends Oe{__ids;$config(){return this.config("mark",{extends:Oe})}afterCloneFrom(e){super.afterCloneFrom(e),this.__ids=e.__ids}updateFromJSON(e){return super.updateFromJSON(e).setIDs(e.ids)}exportJSON(){return{...super.exportJSON(),ids:this.getIDs()}}constructor(e=Mh,t){super(t),this.__ids=e}createDOM(e){const t=Je().createElement("mark");return Ie(t,e.theme.mark),this.__ids.length>1&&Ie(t,e.theme.markOverlap),t}updateDOM(e,t,r){const o=e.__ids,s=this.__ids,i=o.length,a=s.length,l=r.theme.markOverlap;return i!==a&&(i===1?a===2&&Ie(t,l):a===1&&$t(t,l)),!1}hasID(e){return this.getIDs().includes(e)}getIDs(){return Array.from(this.getLatest().__ids)}setIDs(e){const t=this.getWritable();return t.__ids=e,t}addID(e){const t=this.getWritable();return t.__ids.includes(e)?t:t.setIDs([...t.__ids,e])}deleteID(e){const t=this.getWritable(),r=t.__ids.indexOf(e);if(r===-1)return t;const o=Array.from(t.__ids);return o.splice(r,1),t.setIDs(o)}insertNewAfter(e,t=!0){const r=Hc(this.__ids);return this.insertAfter(r,t),r}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(e,t,r){if(!F(t)||r==="html")return!1;const o=t.anchor,s=t.focus,i=o.getNode(),a=s.getNode(),l=t.isBackward()?o.offset-s.offset:s.offset-o.offset;return this.isParentOf(i)&&this.isParentOf(a)&&this.getTextContent().length===l}excludeFromCopy(e){return e!=="clone"}};function Hc(n=Mh){return Ot(new Ts(n))}function Ro(n){return n instanceof Ts}function Ox(n){const e=n.getChildren();let t=null;for(let r=0;r<e.length;r++){const o=e[r];t===null?n.insertBefore(o):t.insertAfter(o),t=o}n.remove()}function Rx(n,e,t,r){const o=kr(),[s,i]=n.isBackward()?[n.focus,n.anchor]:[n.anchor,n.focus];let a,l;o.anchor.set(s.key,s.offset,s.type),o.focus.set(i.key,i.offset,i.type);const c=o.extract();for(const u of c){if(q(l)&&l.isParentOf(u))continue;let f=null;if(oe(u))f=u;else{if(Ro(u))continue;(q(u)||It(u))&&u.isInline()&&(f=u)}if(f!==null){if(f&&f.is(a))continue;const d=f.getParent();d!=null&&d.is(a)||(l=void 0),a=d,l===void 0&&(l=Hc([t]),f.insertBefore(l)),l.append(f)}else a=void 0,l=void 0}q(l)&&(e?l.selectStart():l.selectEnd())}function Ax(n,e){let t=n;for(;t!==null;){if(Ro(t))return t.getIDs();if(oe(t)&&e===t.getTextContentSize()){const r=t.getNextSibling();if(Ro(r))return r.getIDs()}t=t.getParent()}return null}const Mx=pe({name:"@lexical/mark",nodes:()=>[Ts]});class Ao extends Bt{__id;__quote;__comments;static getType(){return"comment-thread"}static clone(e){return new Ao(e.__id,e.__quote,e.__comments,e.__key)}static importJSON(e){return new Ao(e.id,e.quote,e.comments)}exportJSON(){return{type:"comment-thread",version:1,id:this.__id,quote:this.__quote,comments:this.__comments}}constructor(e,t,r,o){super(o),this.__id=e,this.__quote=t,this.__comments=r}createDOM(e){const t=document.createElement("div");return t.style.display="none",t}updateDOM(){return!1}isInline(){return!1}getId(){return this.__id}getQuote(){return this.__quote}getComments(){return this.__comments}addComment(e){const t=this.getWritable();t.__comments=[...t.__comments,e]}deleteComment(e){const t=this.getWritable();t.__comments=t.__comments.map(r=>r.id===e?{...r,deleted:!0,content:"[Deleted Comment]"}:r)}decorate(e){return x.jsx(x.Fragment,{})}}function $x(n,e,t){return new Ao(n,e,t)}function ni(n){return n instanceof Ao}const wo=n=>n.name||n.handle||n.uid,Jc=n=>n.name||n.handle||n.uid||"Anonymous",qc=n=>({kind:"anonymous",name:n||"Anonymous"}),Dx=n=>n.authorPrincipal??qc(n.author);function $h(n,e){const t=[];for(const r of e)n.includes(`@${wo(r)}`)&&!t.includes(r.uid)&&t.push(r.uid);return t}function Dh(){return Math.random().toString(36).replace(/[^a-z]+/g,"").substr(0,5)}function Ph(n,e,t,r,o,s){const i=typeof e=="string"?qc(e):e;return{author:Jc(i),authorPrincipal:i,content:n,deleted:o===void 0?!1:o,id:t===void 0?Dh():t,...s&&s.length>0?{mentions:s}:{},timeStamp:r===void 0?Date.now():r,type:"comment"}}function Px(n,e,t){return{comments:e,id:t===void 0?Dh():t,quote:n,type:"thread"}}function jx(n){return{author:n.author,...n.authorPrincipal?{authorPrincipal:n.authorPrincipal}:{},content:"[Deleted Comment]",deleted:!0,id:n.id,timeStamp:n.timeStamp,type:"comment"}}function Fx(n){const e=n._changeListeners;for(const t of e)t()}class Bx{_editor;_changeListeners;constructor(e){this._editor=e,this._changeListeners=new Set,this._editor.registerUpdateListener(()=>{Fx(this)})}getComments(){const e=[];return this._editor.getEditorState().read(()=>{se().getChildren().forEach(r=>{if(ni(r)){const o=r;e.push({type:"thread",id:o.getId(),quote:o.getQuote(),comments:o.getComments()})}})}),e}addComment(e,t,r){this._editor.update(()=>{if(t!==void 0&&e.type==="comment")se().getChildren().forEach(s=>{if(ni(s)){const i=s;i.getId()===t.id&&i.addComment(e)}});else if(e.type==="thread"){const o=$x(e.id,e.quote,e.comments);se().append(o)}})}deleteComment(e,t){const r=this.deleteCommentOrThread(e,t);r!==null&&this.addComment(r.markedComment,t,r.index)}deleteThread(e){this.deleteCommentOrThread(e)}deleteCommentOrThread(e,t){let r=null;return this._editor.update(()=>{t!==void 0&&e.type==="comment"?se().getChildren().forEach(s=>{if(ni(s)){const i=s;i.getId()===t.id&&(r=i.getComments().findIndex(l=>l.id===e.id),i.deleteComment(e.id))}}):se().getChildren().forEach(s=>{ni(s)&&s.getId()===e.id&&s.remove()})}),e.type==="comment"?{index:r!==null?r:0,markedComment:jx(e)}:null}registerOnChange(e){const t=this._changeListeners;return t.add(e),()=>{t.delete(e)}}}function Ux(n){const[e,t]=S.useState(n.getComments());return S.useEffect(()=>(t(n.getComments()),n.registerOnChange(()=>{t(n.getComments())})),[n]),e}const xr=({"data-test-id":n,children:e,className:t,onClick:r,disabled:o,small:s,title:i})=>x.jsx(ft,{disabled:o,onClick:r,title:i,"aria-label":i,size:s?"small":"medium",variant:"default",className:t,...n&&{"data-test-id":n},children:e}),zx=({className:n,style:e})=>x.jsx(Ap,{className:n||"ContentEditable__root",style:e});function kM({label:n="Loading the document",header:e=!1,maxWidth:t=760}={}){return x.jsxs(Jw,{label:n,sx:{flex:1,minHeight:0,width:"100%",overflow:"hidden"},children:[e?x.jsx(qw,{}):null,x.jsxs(co,{sx:{px:4,py:e?0:4,pb:4,display:"grid",gap:4,maxWidth:t,mx:"auto",width:"100%"},children:[x.jsx(Zs,{size:"titleLarge",lines:1,maxWidth:"22rem"}),x.jsx(Zs,{size:"bodyMedium",lines:3}),x.jsx(Zs,{size:"bodyMedium",lines:4,maxWidth:"92%"}),x.jsx(ty,{width:"100%",height:"120px"}),x.jsx(Zs,{size:"bodyMedium",lines:3,maxWidth:"88%"})]})]})}function Kx({equation:n,setEquation:e,inline:t,inputRef:r}){const s={equation:n,inputRef:r,onChange:i=>{e(i.target.value)}};return t?x.jsx(Wx,{...s,inputRef:r}):x.jsx(Hx,{...s,inputRef:r})}function Wx({equation:n,onChange:e,inputRef:t}){return x.jsxs("span",{className:"EquationEditor_inputBackground",children:[x.jsx("span",{className:"EquationEditor_dollarSign",children:"$"}),x.jsx("input",{className:"EquationEditor_inlineEditor",value:n,onChange:e,autoFocus:!0,ref:t}),x.jsx("span",{className:"EquationEditor_dollarSign",children:"$"})]})}function Hx({equation:n,onChange:e,inputRef:t}){return x.jsxs("div",{className:"EquationEditor_inputBackground",children:[x.jsx("span",{className:"EquationEditor_dollarSign",children:`$$
2
2
  `}),x.jsx("textarea",{className:"EquationEditor_blockEditor",value:n,onChange:e,ref:t}),x.jsx("span",{className:"EquationEditor_dollarSign",children:`
3
3
  $$`})]})}const Jx=({accept:n,label:e,onChange:t,"data-test-id":r})=>x.jsxs(Mt,{children:[x.jsx(Mt.Label,{children:e}),x.jsx(vn,{type:"file",accept:n,onChange:o=>t(o.target.files),"data-test-id":r,block:!0})]});function Da(n,e,t){return Math.min(Math.max(n,e),t)}const Re={east:1,north:8,south:2,west:4},qx=({onResizeStart:n,onResizeEnd:e,buttonRef:t,imageRef:r,maxWidth:o,editor:s,showCaption:i,setShowCaption:a})=>{const l=S.useRef(null),c=S.useRef({priority:"",value:"default"}),u=S.useRef({currentHeight:0,currentWidth:0,direction:0,isResizing:!1,ratio:0,startHeight:0,startWidth:0,startX:0,startY:0}),f=s.getRootElement(),d=o||(f!==null?f.getBoundingClientRect().width-20:100),g=f!==null?f.getBoundingClientRect().height-20:100,h=100,_=100,m=k=>{const I=k===Re.east||k===Re.west,E=k===Re.north||k===Re.south,N=k&Re.north&&k&Re.west||k&Re.south&&k&Re.east,O=I?"ew":E?"ns":N?"nwse":"nesw";f!==null&&f.style.setProperty("cursor",`${O}-resize`,"important"),document.body!==null&&(document.body.style.setProperty("cursor",`${O}-resize`,"important"),c.current.value=document.body.style.getPropertyValue("-webkit-user-select"),c.current.priority=document.body.style.getPropertyPriority("-webkit-user-select"),document.body.style.setProperty("-webkit-user-select","none","important"))},b=()=>{f!==null&&f.style.setProperty("cursor","default"),document.body!==null&&(document.body.style.setProperty("cursor","default"),document.body.style.setProperty("-webkit-user-select",c.current.value,c.current.priority))},w=(k,I)=>{const E=r.current,N=l.current;if(E!==null&&N!==null){const{width:O,height:M}=E.getBoundingClientRect(),R=u.current;R.startWidth=O,R.startHeight=M,R.ratio=O/M,R.currentWidth=O,R.currentHeight=M,R.startX=k.clientX,R.startY=k.clientY,R.isResizing=!0,R.direction=I,m(I),n(),N.classList.add("image-control-wrapper--resizing"),E.style.height=`${M}px`,E.style.width=`${O}px`,document.addEventListener("pointermove",C),document.addEventListener("pointerup",v)}},C=k=>{const I=r.current,E=u.current,N=E.direction&(Re.east|Re.west),O=E.direction&(Re.south|Re.north);if(I!==null&&E.isResizing)if(N&&O){let M=Math.floor(E.startX-k.clientX);M=E.direction&Re.east?-M:M;const R=Da(E.startWidth+M,h,d),$=R/E.ratio;I.style.width=`${R}px`,I.style.height=`${$}px`,E.currentHeight=$,E.currentWidth=R}else if(O){let M=Math.floor(E.startY-k.clientY);M=E.direction&Re.south?-M:M;const R=Da(E.startHeight+M,_,g);I.style.height=`${R}px`,E.currentHeight=R}else{let M=Math.floor(E.startX-k.clientX);M=E.direction&Re.east?-M:M;const R=Da(E.startWidth+M,h,d);I.style.width=`${R}px`,E.currentWidth=R}},v=()=>{const k=r.current,I=u.current,E=l.current;if(k!==null&&E!==null&&I.isResizing){const N=I.currentWidth,O=I.currentHeight;I.startWidth=0,I.startHeight=0,I.ratio=0,I.startX=0,I.startY=0,I.currentWidth=0,I.currentHeight=0,I.isResizing=!1,E.classList.remove("image-control-wrapper--resizing"),b(),e(N,O),document.removeEventListener("pointermove",C),document.removeEventListener("pointerup",v)}};return x.jsxs("div",{ref:l,children:[!i&&x.jsx(ft,{ref:t,size:"small",sx:{position:"absolute",bottom:12,left:"50%",transform:"translateX(-50%)",zIndex:10},onClick:()=>{a(!i)},children:"Add Caption"}),x.jsx("div",{className:"image-resizer image-resizer-n",onPointerDown:k=>{w(k,Re.north)}}),x.jsx("div",{className:"image-resizer image-resizer-ne",onPointerDown:k=>{w(k,Re.north|Re.east)}}),x.jsx("div",{className:"image-resizer image-resizer-e",onPointerDown:k=>{w(k,Re.east)}}),x.jsx("div",{className:"image-resizer image-resizer-se",onPointerDown:k=>{w(k,Re.south|Re.east)}}),x.jsx("div",{className:"image-resizer image-resizer-s",onPointerDown:k=>{w(k,Re.south)}}),x.jsx("div",{className:"image-resizer image-resizer-sw",onPointerDown:k=>{w(k,Re.south|Re.west)}}),x.jsx("div",{className:"image-resizer image-resizer-w",onPointerDown:k=>{w(k,Re.west)}}),x.jsx("div",{className:"image-resizer image-resizer-nw",onPointerDown:k=>{w(k,Re.north|Re.west)}})]})};let ri;function jh(){return ri||(ri=Promise.all([me(()=>import("../datalayer-app-main.js").then(n=>n.uo),[],import.meta.url),me(()=>Promise.resolve({}),[],import.meta.url)]).then(([n])=>n.default,n=>{throw ri=void 0,n})),ri}function Fh({equation:n,inline:e,onClick:t}){const r=S.useRef(null);return S.useEffect(()=>{let o=!1;return jh().then(s=>{const i=r.current;o||i===null||s.render(n,i,{displayMode:!e,errorColor:"var(--fgColor-danger, #cc0000)",output:"html",strict:"warn",throwOnError:!1,trust:!1})}).catch(s=>{console.debug("KaTeX could not be loaded",s)}),()=>{o=!0}},[n,e]),x.jsxs(x.Fragment,{children:[x.jsx("span",{children:" "}),x.jsx("span",{role:"button",tabIndex:-1,onClick:t,ref:r}),x.jsx("span",{children:" "})]})}const Vx=({onConfirm:n,initialEquation:e=""})=>{const[t,r]=S.useState(e),[o,s]=S.useState(!0),i=S.useCallback(()=>{n(t,o)},[n,t,o]),a=S.useCallback(()=>{s(!o)},[s,o]);return x.jsxs(x.Fragment,{children:[x.jsx(Y,{sx:{mb:2},children:x.jsxs(Mt,{children:[x.jsx(Mp,{checked:o,onChange:a}),x.jsx(Mt.Label,{children:"Inline"})]})}),x.jsx(Le,{sx:{fontSize:1,fontWeight:"bold",mb:1},children:"Equation"}),x.jsx(Y,{sx:{mb:2},children:o?x.jsx(vn,{onChange:l=>{r(l.target.value)},value:t,block:!0}):x.jsx(ny,{onChange:l=>{r(l.target.value)},value:t,block:!0,rows:6})}),x.jsx(Le,{sx:{fontSize:1,fontWeight:"bold",mb:1},children:"Visualization"}),x.jsx(Y,{sx:{mb:2,p:2,border:"1px solid",borderColor:"var(--borderColor-default)",borderRadius:2,textAlign:"center"},children:x.jsx(Fh,{equation:t,inline:!1,onClick:()=>null})}),x.jsx(Y,{sx:{display:"flex",justifyContent:"flex-end"},children:x.jsx(xr,{onClick:i,children:"Confirm"})})]})},Yx=({onClose:n,children:e,title:t,closeOnClickOutside:r=!1})=>x.jsx($p,{title:t,onClose:()=>n(),width:"medium",height:"auto",children:e}),Bh=({children:n,className:e})=>x.jsx("div",{className:e||"Placeholder__root",children:n});function ua(n,...e){const t=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",n);for(const o of e)r.append("v",o);throw t.search=r.toString(),Error(`Minified Lexical error #${n}; visit ${t.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function Uh(n,e){let t=n;for(let r=gt(n,e);r&&(Ve(r.origin)||bt(r.origin));r=r.getAdjacentCaret())t=r.origin;return t}function Cr(n){return Uh(n,"previous")}function xo(n){return Uh(n,"next")}function Gx(n){const e=Cr(n),t=xo(n);let r=e;for(;r!==null;){if(Ve(r)){const s=cy(r.getTextContent());if(s!==null)return s}if(r===t)break;r=r.getNextSibling()}const o=e.getParent();if(q(o)){const s=o.getDirection();if(s==="ltr"||s==="rtl")return s}return null}function Xx(n,e){let t=null,r=null,o=n,s=e,i=n.getTextContent();for(;;){if(s===0){const c=o.getPreviousSibling();if(c===null){o=null;break}if(Ve(c)||bt(c)||ue(c)||ua(167),o=c,ue(o)){t={node:o,offset:1};break}s=Math.max(0,o.getTextContentSize()-1),i=o.getTextContent()}else s--;const l=i[s];Ve(o)&&l!==" "&&(r={node:o,offset:s})}if(r!==null)return r;let a=null;if(e<n.getTextContentSize())Ve(n)&&(a=n.getTextContent()[e]);else{const l=n.getNextSibling();Ve(l)&&(a=l.getTextContent()[0])}if(a!==null&&a!==" ")return t;{const l=(function(c,u){let f=c,d=u,g=c.getTextContent(),h=c.getTextContentSize();for(;;){if(!Ve(f)||d===h){if(f=f.getNextSibling(),f===null||ue(f))return null;Ve(f)&&(d=0,g=f.getTextContent(),h=f.getTextContentSize())}if(Ve(f)){if(g[d]!==" ")return{node:f,offset:d};d++}}})(n,e);return l!==null?l:t}}function Zx(n){const e=xo(n);return ue(e)&&ua(168),e}function Qx(n){const e=[];return jp(n,{linebreak:()=>e.push(vt()),tab:()=>e.push(Kn()),text:t=>e.push(Vc(t))}),e}const e0="javascript";function zh(n,e){for(const t of n.childNodes)if(ke(t)&&t.tagName===e||zh(t,e))return!0;return!1}const as="data-language",ns="data-highlight-language",oi="data-theme";class dn extends Oe{__language;__theme;__isSyntaxHighlightSupported;$config(){return this.config("code",{extends:Oe,importDOM:{code:e=>e.textContent!=null&&(/\r?\n/.test(e.textContent)||zh(e,"BR"))?{conversion:zd,priority:1}:null,div:()=>({conversion:t0,priority:1}),pre:()=>({conversion:zd,priority:0}),table:e=>Pa(e)?{conversion:n0,priority:3}:null,td:e=>{const t=e,r=t.closest("table");return t.classList.contains("js-file-line")||r&&Pa(r)?{conversion:Kd,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&Pa(t)?{conversion:Kd,priority:3}:null}}})}constructor(e=void 0,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(e){super.afterCloneFrom(e),this.__language=e.__language,this.__theme=e.__theme,this.__isSyntaxHighlightSupported=e.__isSyntaxHighlightSupported}createDOM(e){const t=Je().createElement("code");Ie(t,e.theme.code),t.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(t.setAttribute(as,r),this.getIsSyntaxHighlightSupported()&&t.setAttribute(ns,r));const o=this.getTheme();o&&t.setAttribute(oi,o);const s=this.getStyle();return s&&_o(t.style,s),t}updateDOM(e,t,r){const o=this.__language,s=e.__language;o?o!==s&&t.setAttribute(as,o):s&&t.removeAttribute(as);const i=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&s?i&&o?o!==s&&t.setAttribute(ns,o):t.removeAttribute(ns):i&&o&&t.setAttribute(ns,o);const a=this.__theme,l=e.__theme;a?a!==l&&t.setAttribute(oi,a):l&&t.removeAttribute(oi);const c=this.__style,u=e.__style;return c!==u&&_o(t.style,c,u),!1}exportDOM(e){const t=Je().createElement("pre");Ie(t,e._config.theme.code),t.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(t.setAttribute(as,r),this.getIsSyntaxHighlightSupported()&&t.setAttribute(ns,r));const o=this.getTheme();o&&t.setAttribute(oi,o);const s=this.getStyle();return s&&_o(t.style,s),{element:t}}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language).setTheme(e.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(e,t=!0){if(!Tc(zo(),"@lexical/code")){const i=Kh(e);if(i)return i}const{anchor:r,focus:o}=e,s=(r.isBefore(o)?r:o).getNode();if(oe(s)){let i=Cr(s);const a=[];for(;;)if(bt(i))a.push(Kn()),i=i.getNextSibling();else{if(!Ve(i))break;{let h=0;const _=i.getTextContent(),m=i.getTextContentSize();for(;h<m&&_[h]===" ";)h++;if(h!==0&&a.push(Vc(" ".repeat(h))),h!==m)break;i=i.getNextSibling()}}const l=s.splitText(r.offset)[0],c=r.offset===0?0:1,u=l.getIndexWithinParent()+c,f=s.getParentOrThrow(),d=[vt(),...a];f.splice(u,0,d);const g=a[a.length-1];g?g.select():r.offset===0?l.selectPrevious():l.getNextSibling().selectNext(0,0)}if(je(s)){const{offset:i}=e.anchor;s.splice(i,0,[vt()]),s.select(i+1,i+1)}return null}canIndent(){return!1}collapseAtStart(){const e=ne();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}setLanguage(e){const t=this.getWritable();return t.__language=e||void 0,t}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(e){const t=this.getWritable();return t.__isSyntaxHighlightSupported=e,t}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(e){const t=this.getWritable();return t.__theme=e||void 0,t}getTheme(){return this.getLatest().__theme}}function Ze(n,e){return ry(dn).setLanguage(n).setTheme(e)}function je(n){return n instanceof dn}function zd(n){return{node:Ze(n.getAttribute(as))}}function t0(n){const e=n,t=Wd(e);return t||(function(r){let o=r.parentElement;for(;o!==null;){if(Wd(o))return!0;o=o.parentElement}return!1})(e)?{node:t?Ze():null}:{node:null}}function n0(){return{node:Ze()}}function Kd(){return{node:null}}function Wd(n){return n.style.fontFamily.match("monospace")!==null}function Pa(n){return n.classList.contains("js-file-line-container")}function Kh(n){const{anchor:e}=n;if(n.isCollapsed()&&e.type==="element"){const t=e.getNode();if(je(t)){const r=t.getChildrenSize();if(r>=2&&e.offset===r){const o=t.getLastChild();if(ue(o)&&ue(o.getPreviousSibling())){const s=ne();return t.splice(r-2,2,[]).insertAfter(s,!1),s.select(),s}}}}return null}class Hs extends cn{__highlightType;constructor(e="",t,r){super(e,r),this.__highlightType=t}$config(){return this.config("code-highlight",{extends:cn})}afterCloneFrom(e){super.afterCloneFrom(e),this.__highlightType=e.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(e){const t=super.createDOM(e),r=ja(e.theme,this.__highlightType);return Ie(t,r),t}updateDOM(e,t,r){const o=super.updateDOM(e,t,r),s=ja(r.theme,e.__highlightType),i=ja(r.theme,this.__highlightType);return s!==i&&(s&&$t(t,s),i&&Ie(t,i)),o}updateFromJSON(e){return super.updateFromJSON(e).setHighlightType(e.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(e){return this}isParentRequired(){return!0}createParentElementNode(){return Ze()}}function ja(n,e){return e&&n&&n.codeHighlight&&n.codeHighlight[e]}function Vc(n="",e){return Ot(new Hs(n,e))}function Ve(n){return n instanceof Hs}const Wh="data-language";function Hh(n){return n.style.fontFamily.match("monospace")!==null}function Fl(n){let e=n.parentElement;for(;e!==null;){if(Hh(e))return!0;e=e.parentElement}return!1}const r0=Pp([Ye({$import:(n,e)=>n.$importChildren(e),match:Ge.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),o0=Ye({$import:(n,e)=>[Ze(e.getAttribute(Wh)).splice(0,0,n.$importChildren(e))],match:Ge.tag("pre"),name:"@lexical/code/pre"}),s0=Ye({$import:(n,e,t)=>{const r=e.textContent||"";return/\r?\n/.test(r)||e.querySelector("br")!==null?[Ze(e.getAttribute(Wh)).splice(0,0,n.$importChildren(e))]:t()},match:Ge.tag("code"),name:"@lexical/code/code-multiline"});function po(n){if(!ke(n))return!1;const e=n.style.fontFamily,t=n.style.whiteSpace;return typeof e=="string"&&/monospace/i.test(e)&&typeof t=="string"&&t.startsWith("pre")}function Jh(n){let e=!1;const t=[];let r="",o=!1;const s=()=>{o&&(t.push(r),r="",o=!1)};for(const i of Array.from(n.childNodes))if(ke(i))i.tagName==="DIV"?(s(),t.push(i.textContent||""),e=!0):i.tagName==="BR"?(s(),t.push(""),e=!0):(r+=i.textContent||"",o=!0);else if(iy(i)){const a=i.textContent||"";a.length>0&&(r+=a,o=!0)}return s(),e?t:null}function qh(n){for(const e of Array.from(n.children)){if(ke(e)&&po(e)){if(Jh(e)!==null)return!0;const t=e.nextElementSibling;if(t&&po(t))return!0;continue}if(qh(e))return!0}return!1}const i0=Pp([Ye({$import:(n,e,t)=>{if(!po(e)||Fl(e))return t();const r=Jh(e);return r===null||r.length===0?t():[Ze().splice(0,0,yd(r.join(`
4
4
  `)))]},match:Ge.tag("div"),name:"@lexical/code/vscode-wrapper"}),Ye({$import:(n,e,t)=>{if(!po(e)||Fl(e))return t();const r=e.previousElementSibling;if(r&&po(r))return[];const o=[];let s=e;for(;s&&po(s);)o.push(s.tagName==="BR"?"":s.textContent||""),s=s.nextElementSibling;return o.length<2?t():[Ze().splice(0,0,yd(o.join(`
@@ -6,7 +6,7 @@ $$`})]})}const Jx=({accept:n,label:e,onChange:t,"data-test-id":r})=>x.jsxs(Mt,{c
6
6
  `){const s=Kn(),i=vt(),a=t.isBackward()?"previous":"next";return t.insertNodes([s,i]),Ri(ay(mi(ly(s,"next",0),Jn(gt(i,"next"))),a)),!0}for(let s=0;s<o;s++){const i=r[s];if(i.length>0){let a=i[0];if(s===0&&(a=Cr(a)),n===Dt){const l=Kn();if(a.insertBefore(l),s===0){const c=t.isBackward()?"focus":"anchor",u=un(a.getKey(),0,"text");t[c].is(u)&&t[c].set(l.getKey(),0,"text")}}else bt(a)&&a.remove()}}return!0}function Jd(n,e){const t=D();if(!F(t))return!1;const{anchor:r,focus:o}=t,s=r.offset,i=o.offset,a=r.getNode(),l=o.getNode(),c=n===pt;if(!_r(t)||!Ve(a)&&!bt(a)||!Ve(l)&&!bt(l))return!1;if(!e.altKey){if(t.isCollapsed()){const b=a.getParentOrThrow();if(c&&s===0&&a.getPreviousSibling()===null){if(b.getPreviousSibling()===null)return b.selectPrevious(),e.preventDefault(),!1}else if(!c&&s===a.getTextContentSize()&&a.getNextSibling()===null&&b.getNextSibling()===null)return b.selectNext(),e.preventDefault(),!1}return!1}let u,f;if(a.isBefore(l)?(u=Cr(a),f=xo(l)):(u=Cr(l),f=xo(a)),u==null||f==null)return!1;const d=u.getNodesBetween(f);for(let b=0;b<d.length;b++){const w=d[b];if(!Ve(w)&&!bt(w)&&!ue(w))return!1}e.preventDefault(),e.stopPropagation();const g=c?u.getPreviousSibling():f.getNextSibling();if(!ue(g))return!0;const h=c?g.getPreviousSibling():g.getNextSibling();if(h==null)return!0;const _=Ve(h)||bt(h)||ue(h)?c?Cr(h):xo(h):null;let m=_??h;return g.remove(),d.forEach(b=>b.remove()),n===pt?(d.forEach(b=>m.insertBefore(b)),m.insertBefore(g)):(m.insertAfter(g),m=g,d.forEach(b=>{m.insertAfter(b),m=b})),t.setTextNodeRange(a,s,l,i),!0}function qd(n,e){const t=D();if(!F(t))return!1;const{anchor:r,focus:o}=t,s=r.getNode(),i=o.getNode(),a=n===Ir;if(!_r(t)||!Ve(s)&&!bt(s)||!Ve(i)&&!bt(i))return!1;const l=i,c=Gx(l)==="rtl"?!a:a,u=r.key,f=r.offset,d=r.type;if(c){const g=Xx(l,o.offset);if(g!==null){const{node:h,offset:_}=g;ue(h)?h.selectNext(0,0):t.setTextNodeRange(h,_,h,_)}else l.getParentOrThrow().selectStart()}else Zx(l).select();return e.shiftKey&&t.anchor.set(u,f,d),e.preventDefault(),e.stopPropagation(),!0}function c0(n,e,t){return de(n.registerCommand(Kr,r=>{const o=(function(s){const i=D();if(!F(i)||!_r(i))return null;const a=s?wn:Dt,l=s?wn:Tl,c=i.anchor,u=i.focus;if(c.is(u))return l;const f=Yh(i);if(f.length!==1)return a;const d=f[0];let g,h;d.length===0&&ua(285),i.isBackward()?(g=u,h=c):(g=c,h=u);const _=Cr(d[0]),m=xo(d[0]),b=un(_.getKey(),0,"text"),w=un(m.getKey(),m.getTextContentSize(),"text");return g.isBefore(b)||w.isBefore(h)?a:b.isBefore(g)||h.isBefore(w)?l:a})(r.shiftKey);return o!==null&&(r.preventDefault(),n.dispatchCommand(o),!0)},ee),n.registerCommand(Tl,()=>!!_r(D())&&(Tr([Kn()]),!0),ee),n.registerCommand(Dt,()=>Hd(Dt),ee),n.registerCommand(wn,()=>Hd(wn,e),ee),n.registerCommand(pt,r=>{const o=D();if(!F(o))return!1;const{anchor:s}=o,i=s.getNode();if(!_r(o))return!1;const a=i.getParent();return o.isCollapsed()&&s.offset===0&&i.getPreviousSibling()===null&&je(a)&&a.getPreviousSibling()===null?(r.preventDefault(),!0):Jd(pt,r)},ee),n.registerCommand(Vt,r=>{const o=D();if(!F(o))return!1;const{anchor:s}=o,i=s.getNode();return!!_r(o)&&(o.isCollapsed()&&s.offset===i.getTextContentSize()&&i.getNextSibling()===null&&je(i.getParentOrThrow())&&i.getParentOrThrow().getNextSibling()===null?(r.preventDefault(),!0):Jd(Vt,r))},ee),n.registerCommand(Ir,r=>qd(Ir,r),ee),n.registerCommand(xs,r=>qd(xs,r),ee))}(function(n){n.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d.*$/m]};var e={"deleted-sign":"-","deleted-arrow":"<","inserted-sign":"+","inserted-arrow":">",unchanged:" ",diff:"!"};Object.keys(e).forEach(function(t){var r=e[t],o=[];/^\w+$/.test(t)||o.push(/\w+/.exec(t)[0]),t==="diff"&&o.push("bold"),n.languages.diff[t]={pattern:RegExp("^(?:["+r+`].*(?:\r
7
7
  ?|
8
8
  |(?![\\s\\S])))+`,"m"),alias:o,inside:{line:{pattern:/(.)(?=[\s\S]).*(?:\r\n?|\n)?/,lookbehind:!0},prefix:{pattern:/[\s\S]/,alias:/\w+/.exec(t)[0]}}}}),Object.defineProperty(n.languages.diff,"PREFIXES",{value:e})})(Prism),Prism.languages.go=Prism.languages.extend("clike",{string:{pattern:/(^|[^\\])"(?:\\.|[^"\\\r\n])*"|`[^`]*`/,lookbehind:!0,greedy:!0},keyword:/\b(?:break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go(?:to)?|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b/,boolean:/\b(?:_|false|iota|nil|true)\b/,number:[/\b0(?:b[01_]+|o[0-7_]+)i?\b/i,/\b0x(?:[a-f\d_]+(?:\.[a-f\d_]*)?|\.[a-f\d_]+)(?:p[+-]?\d+(?:_\d+)*)?i?(?!\w)/i,/(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?[\d_]+)?i?(?!\w)/i],operator:/[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,builtin:/\b(?:append|bool|byte|cap|close|complex|complex(?:64|128)|copy|delete|error|float(?:32|64)|u?int(?:8|16|32|64)?|imag|len|make|new|panic|print(?:ln)?|real|recover|rune|string|uintptr)\b/}),Prism.languages.insertBefore("go","string",{char:{pattern:/'(?:\\.|[^'\\\r\n]){0,10}'/,greedy:!0}}),delete Prism.languages.go["class-name"];const rn=globalThis.Prism||window.Prism,Gh={c:"C",clike:"C-like",cpp:"C++",css:"CSS",go:"Go",html:"HTML",java:"Java",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",powershell:"PowerShell",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",typescript:"TypeScript",xml:"XML"},u0={cpp:"cpp",golang:"go",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function Yc(n){return u0[n]||n}function d0(n){const e=Yc(n);return Gh[e]||e}function f0(){const n=[];for(const[e,t]of Object.entries(Gh))n.push([e,t]);return n}function g0(n){const e=(function(r){const o=/^diff-([\w-]+)/i.exec(r);return o?o[1]:null})(n),t=e||n;try{return!!t&&rn.languages.hasOwnProperty(t)}catch{return!1}}async function p0(n,e,t){}function Bl(n){return typeof n=="string"?n:Array.isArray(n)?n.map(Bl).join(""):Bl(n.content)}function h0(n,e){const t=/^diff-([\w-]+)/i.exec(e),r=n.getTextContent();let o=rn.tokenize(r,rn.languages[t?"diff":e]);return t&&(o=(function(s,i){const a=i,l=rn.languages[a],c={tokens:s},u=rn.languages.diff.PREFIXES;for(const f of c.tokens){if(typeof f=="string"||!(f.type in u)||!Array.isArray(f.content))continue;const d=f.type;let g=0;const h=()=>(g++,new rn.Token("prefix",u[d],d.replace(/^(\w+).*/,"$1"))),_=f.content.filter(k=>typeof k=="string"||k.type!=="prefix"),m=f.content.length-_.length,b=rn.tokenize(Bl(_),l);b.unshift(h());const w=/\r\n|\n/g,C=k=>{const I=[];w.lastIndex=0;let E,N=0;for(;g<m&&(E=w.exec(k));){const O=E.index+E[0].length;I.push(k.slice(N,O)),N=O,I.push(h())}if(I.length!==0)return N<k.length&&I.push(k.slice(N)),I},v=k=>{for(let I=0;I<k.length&&g<m;I++){const E=k[I];if(typeof E=="string"){const N=C(E);N&&(k.splice(I,1,...N),I+=N.length-1)}else if(typeof E.content=="string"){const N=C(E.content);N&&(E.content=N)}else Array.isArray(E.content)?v(E.content):v([E.content])}};v(b),g<m&&b.push(h()),f.content=b}return c.tokens})(o,t[1])),Ul(o)}function Ul(n,e){const t=[];for(const r of n)if(typeof r=="string")jp(r,{linebreak:()=>t.push(vt()),tab:()=>t.push(Kn()),text:o=>t.push(Vc(o,e))});else{const{content:o,alias:s}=r;typeof o=="string"?t.push(...Ul([o],r.type==="prefix"&&typeof s=="string"?s:r.type)):Array.isArray(o)&&t.push(...Ul(o,r.type==="unchanged"?void 0:r.type))}return t}const _0={$tokenize(n,e){const t=e||this.defaultLanguage;return t===null?Qx(n.getTextContent()):h0(n,t)},defaultLanguage:e0,tokenize(n,e){const t=this.defaultLanguage;return rn.tokenize(n,rn.languages[e||""]||(t===null?void 0:rn.languages[t]))}};function Vd(n,e,t,r){const o=r.getParent();je(o)?Xh(n,e,t,o):Ve(r)&&r.replace($e(r.__text))}function m0(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+=`
9
- `+ ++i);t.setAttribute("data-gutter",s)}function Xh(n,e,t,r){const{nodesCurrentlyHighlighting:o}=t,s=r.getKey();r.getLanguage()===void 0&&e.defaultLanguage!==null&&r.setLanguage(e.defaultLanguage);const i=r.getLanguage()||e.defaultLanguage;if(i){if(!g0(i))return r.getIsSyntaxHighlightSupported()&&r.setIsSyntaxHighlightSupported(!1),void p0();r.getIsSyntaxHighlightSupported()||r.setIsSyntaxHighlightSupported(!0)}else r.getIsSyntaxHighlightSupported()&&r.setIsSyntaxHighlightSupported(!1);o.has(s)||(o.add(s),t.didTransform||(t.didTransform=!0,uy(()=>{t.didTransform=!1,o.clear()})),(function(a,l){const c=Q(a);if(!je(c)||!c.isAttached())return;const u=D();if(!F(u))return void l();const f=u.anchor,d=f.offset,g=f.type==="element"&&ue(c.getChildAtIndex(f.offset-1));let h=0;if(!g){const _=f.getNode();h=d+_.getPreviousSiblings().reduce((m,b)=>m+b.getTextContentSize(),0)}if(l()){if(g)return void f.getNode().select(d,d);c.getChildren().some(_=>{const m=oe(_);if(m||ue(_)){const b=_.getTextContentSize();if(m&&b>=h)return _.select(h,h),!0;h-=b}return!1})}})(s,()=>{const a=Q(s);if(!je(a)||!a.isAttached())return!1;const l=a.getLanguage()||e.defaultLanguage,c=e.$tokenize(a,l??void 0),u=(function(h,_){let m=0;for(;m<h.length&&Yd(h[m],_[m]);)m++;const b=h.length,w=_.length,C=Math.min(b,w)-m;let v=0;for(;v<C;)if(v++,!Yd(h[b-v],_[w-v])){v--;break}const k=m,I=b-v,E=_.slice(m,w-v);return{from:k,nodesForReplacement:E,to:I}})(a.getChildren(),c),{from:f,to:d,nodesForReplacement:g}=u;return!(f===d&&!g.length)&&(r.splice(f,d-f,g),!0)}))}function Yd(n,e){return Ve(n)&&Ve(e)&&n.__text===e.__text&&n.__highlightType===e.__highlightType||bt(n)&&bt(e)||ue(n)&&ue(e)}function b0(n,e){const t=[];n._headless!==!0&&t.push(n.registerMutationListener(dn,o=>{n.read("latest",()=>{for(const[s,i]of o)if(i!=="destroyed"){const a=Q(s);a!==null&&m0(a,n)}})},{skipInitialization:!1}));const r={didTransform:!1,nodesCurrentlyHighlighting:new Set};return t.push(n.registerNodeTransform(dn,Xh.bind(null,n,e,r)),n.registerNodeTransform(cn,Vd.bind(null,n,e,r)),n.registerNodeTransform(Hs,Vd.bind(null,n,e,r))),de(...t)}function y0(n,e=_0){if(!n.hasNodes([dn,Hs]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");return de(b0(n,e),c0(n))}const w0=f0,x0=d0,C0=Yc,zl=Yc,S0=y0,v0={css:[()=>me(()=>import("./postcss-v_maFVrK.js").then(n=>n.p),[],import.meta.url)],html:[()=>me(()=>import("./html-DuSbEcJO.js").then(n=>n.h),[],import.meta.url)],js:[()=>me(()=>import("./babel-CWCo1FDM.js").then(n=>n.b),[],import.meta.url),()=>me(()=>import("./estree-C_HWBWad.js"),[],import.meta.url)],markdown:[()=>me(()=>import("./markdown-CH2i4TVR.js").then(n=>n.m),[],import.meta.url)],typescript:[()=>me(()=>import("./typescript-DNMQUFQg.js").then(n=>n.t),[],import.meta.url),()=>me(()=>import("./estree-C_HWBWad.js"),[],import.meta.url)]};async function k0(n){const e=v0[n];return await Promise.all(e.map(r=>r()))}async function T0(){const{format:n}=await me(async()=>{const{format:e}=await import("./standalone-oyxre9MX.js");return{format:e}},[],import.meta.url);return n}const Zh={css:{parser:"css"},html:{parser:"html"},js:{parser:"babel"},markdown:{parser:"markdown"},typescript:{parser:"typescript"}},I0=Object.keys(Zh);function E0(n){return I0.includes(n)}function N0(n){const e=Zh[n];if(!e)throw new Error(`CodeActionMenuPlugin: Prettier does not support this language: ${n}`);return e}function L0({lang:n,editor:e,getCodeDOMNode:t}){const[r,o]=S.useState(""),[s,i]=S.useState(!1);async function a(){const f=t();if(!f)return;let d="";if(e.update(()=>{const g=Ae(f);je(g)&&(d=g.getTextContent())}),d!=="")try{const g=await T0(),h=N0(n),_=await k0(n);h.plugins=_.map(b=>b.default||b);const m=await g(d,h);e.update(()=>{const b=Ae(f);je(b)&&(b.select(0).insertText(m),o(""),i(!1))})}catch(g){l(g)}}function l(f){f instanceof Error?(o(f.message),i(!0)):console.error("Unexpected error: ",f)}function c(){r!==""&&i(!0)}function u(){r!==""&&i(!1)}return x.jsxs(Y,{sx:{position:"relative",display:"inline-flex"},children:[x.jsx(Ft,{icon:r?Fp:br,size:"small",variant:"invisible",onClick:a,onMouseEnter:c,onMouseLeave:u,"aria-label":"prettier",sx:r?{color:"var(--fgColor-danger)"}:void 0}),s?x.jsx(Y,{as:"pre",sx:{position:"absolute",top:"100%",left:0,zIndex:10,p:2,mt:1,fontSize:0,bg:"var(--bgColor-danger-muted)",color:"var(--fgColor-danger)",borderRadius:2,borderWidth:1,borderStyle:"solid",borderColor:"var(--bgColor-danger-muted)",maxWidth:"300px",whiteSpace:"pre-wrap"},children:r}):null]})}const Kl=({label:n,value:e,onChange:t,placeholder:r="","data-test-id":o})=>x.jsxs(Mt,{children:[x.jsx(Mt.Label,{children:n}),x.jsx(vn,{type:"text",placeholder:r,value:e,onChange:s=>{t(s.target.value)},"data-test-id":o,block:!0})]}),Qh=S.createContext(void 0),TM=({children:n})=>{const[e,t]=S.useState(!1),r=()=>t(o=>!o);return x.jsx(Qh.Provider,{value:{showComments:e,toggleComments:r,setShowComments:t},children:n})},e_=()=>{const n=S.useContext(Qh);if(!n)throw new Error("useComments must be used within CommentsProvider");return n},O0=S.createContext({});function R0(){return S.useContext(O0)}const Gc=S.createContext(void 0);function A0(){const n=S.useContext(Gc);if(!n)throw new Error("useLexicalConfig must be used within a LexicalConfigProvider");return n}function M0(){return S.useContext(Gc)}function IM({lexicalId:n,serviceManager:e,children:t}){return x.jsx(Gc.Provider,{value:{lexicalId:n,serviceManager:e},children:t})}const $0=S.createContext({});function D0(){return S.useContext($0)}const Gd=window.location.hostname,P0=Gd!=="playground.lexical.dev"&&Gd!=="lexical-playground.vercel.app",t_={disableBeforeInput:!1,emptyEditor:P0,hasLinkAttributes:!1,isAutocomplete:!1,isCharLimit:!1,isCharLimitUtf8:!1,isCodeHighlighted:!0,isCodeShiki:!1,isCollab:!1,isMaxLength:!1,isRichText:!0,listStrictIndent:!1,measureTypingPerf:!1,selectionAlwaysOnDisplay:!1,shouldAllowHighlightingWithBrackets:!1,shouldPreserveNewLinesInMarkdown:!1,shouldUseLexicalContextMenu:!1,showNestedEditorTreeView:!1,showTableOfContents:!1,showTreeView:!0,tableCellBackgroundColor:!0,tableCellMerge:!0,tableHorizontalScroll:!0},n_={...t_},r_=S.createContext({setOption:(n,e)=>{},settings:n_}),EM=({children:n})=>{const[e,t]=S.useState(n_),r=S.useCallback((s,i)=>{t(a=>({...a,[s]:i})),F0(s,i)},[]),o=S.useMemo(()=>({setOption:r,settings:e}),[r,e]);return x.jsx(r_.Provider,{value:o,children:n})},j0=()=>S.useContext(r_);function F0(n,e){const t=new URL(window.location.href),r=new URLSearchParams(t.search);e!==t_[n]?r.set(n,String(e)):r.delete(n),t.search=r.toString(),window.history.pushState(null,"",t.toString())}const Fa=8,Ba=72,Wl=15,Ua={bullet:"Bulleted List",check:"Check List",code:"Code Block",h1:"Heading 1",h2:"Heading 2",h3:"Heading 3",h4:"Heading 4",h5:"Heading 5",h6:"Heading 6",number:"Numbered List",paragraph:"Normal",quote:"Quote"},B0={bgColor:"#fff",blockType:"paragraph",canRedo:!1,canUndo:!1,codeLanguage:"",codeTheme:"",elementFormat:"left",fontColor:"#000",fontFamily:"Arial",fontSize:`${Wl}px`,fontSizeInputValue:`${Wl}`,isBold:!1,isCode:!1,isHighlight:!1,isImageCaption:!1,isItalic:!1,isLink:!1,isRTL:!1,isStrikethrough:!1,isSubscript:!1,isSuperscript:!1,isUnderline:!1,isLowercase:!1,isUppercase:!1,isCapitalize:!1,rootType:"root",listStartNumber:null},o_=S.createContext(void 0),NM=({children:n})=>{const[e,t]=S.useState(B0),r=e.fontSize,o=S.useCallback((i,a)=>{t(l=>({...l,[i]:a}))},[]);S.useEffect(()=>{o("fontSizeInputValue",r.slice(0,-2))},[r,o]);const s=S.useMemo(()=>({toolbarState:e,updateToolbarState:o}),[e,o]);return x.jsx(o_.Provider,{value:s,children:n})},U0=()=>{const n=S.useContext(o_);if(n===void 0)throw new Error("useToolbarState must be used within a ToolbarProvider");return n},z0=Ye({$import:(n,e)=>{const t=fn(e.nodeName.toLowerCase());return Bs(e,t),rr(t,e),mn(t,e),[t.splice(0,0,n.$importChildren(e))]},match:Ge.tag("h1","h2","h3","h4","h5","h6"),name:"@lexical/rich-text/heading"}),K0=Ye({$import:(n,e)=>{const t=Ln();return rr(t,e),Bs(e,t),mn(t,e),[t.splice(0,0,n.$importChildren(e))]},match:Ge.tag("blockquote"),name:"@lexical/rich-text/blockquote"});Ge.tag("blockquote");const W0=[z0,K0,Ye({$import:(n,e,t)=>{const r=e.firstChild;return r&&ke(o=r)&&o.nodeName==="SPAN"&&o.style.fontSize==="26pt"?n.$importChildren(e):t();var o},match:Ge.tag("p"),name:"@lexical/rich-text/google-docs-title-p"}),Ye({$import:(n,e,t)=>e.style.fontSize!=="26pt"?t():[fn("h1").splice(0,0,n.$importChildren(e))],match:Ge.tag("span"),name:"@lexical/rich-text/google-docs-title-span"})];function H0(n,e){return n&&e!==null?Eo(n,e):e}const s_=pe({build:(n,e)=>nr(e),config:tr({escapeFormatTriggers:{capitalize:{enter:!0,space:!0,tab:!0},lowercase:{enter:!0,space:!0,tab:!0},uppercase:{enter:!0,space:!0,tab:!0}}}),conflictsWith:["@lexical/plain-text"],dependencies:[dy,fy,gy,js,ln(Fs,{rules:W0})],mergeConfig:function(n,e){const t=Eo(n,e);return e.escapeFormatTriggers&&(t.escapeFormatTriggers=(function(r,o){const s=Eo(r,o);for(const i of Object.keys(o))s[i]=H0(r[i],o[i]);return s})(n.escapeFormatTriggers,e.escapeFormatTriggers)),t},name:"@lexical/rich-text",nodes:()=>[qs,Js],register:(n,e,t)=>zt(()=>i_(n,t.getOutput().escapeFormatTriggers))}),Xd=he("DRAG_DROP_PASTE_FILE"),za=Us("shadowRoot",{parse:Boolean});let Js=class extends Oe{$config(){return this.config("quote",{extends:Oe,importDOM:{blockquote:()=>({conversion:J0,priority:0})},stateConfigs:[{flat:!0,stateConfig:za}]})}isShadowRoot(){return Cs(this,za)}setIsShadowRoot(e){return xn(this,za,e)}createDOM(e){const t=Je().createElement("blockquote");return Ie(t,e.theme.quote),t}updateDOM(e,t,r){return!1}exportDOM(e){const{element:t}=super.exportDOM(e);if(ke(t)){this.isEmpty()&&t.append(Je().createElement("br"));const r=this.getFormatType();r&&(t.style.textAlign=r);const o=this.getDirection();o&&(t.dir=o)}return{element:t}}exportJSON(){return super.exportJSON()}static importJSON(e){return Ln().updateFromJSON(e)}insertNewAfter(e,t){const r=ne(),o=this.getDirection();return r.setDirection(o),this.insertAfter(r,t),r}collapseAtStart(){if(this.isShadowRoot()){for(const t of this.getChildren())this.insertBefore(t);return this.remove(),!0}const e=ne();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}canMergeWhenEmpty(){return!0}};function Ln(n){const e=Ot(new Js);return n&&n.shadowRoot?e.setIsShadowRoot(!0):e}function Vn(n){return n instanceof Js}let qs=class extends Oe{__tag;$config(){return this.config("heading",{extends:Oe,importDOM:{h1:()=>({conversion:to,priority:0}),h2:()=>({conversion:to,priority:0}),h3:()=>({conversion:to,priority:0}),h4:()=>({conversion:to,priority:0}),h5:()=>({conversion:to,priority:0}),h6:()=>({conversion:to,priority:0}),p:e=>{const t=e.firstChild;return t!==null&&Zd(t)?{conversion:()=>({node:null}),priority:3}:null},span:e=>Zd(e)?{conversion:()=>({node:fn("h1")}),priority:3}:null}})}afterCloneFrom(e){super.afterCloneFrom(e),this.__tag=e.__tag}constructor(e="h1",t){super(t),this.__tag=e}getTag(){return this.getLatest().__tag}setTag(e){const t=this.getWritable();return t.__tag=e,t}createDOM(e){const t=this.__tag,r=Je().createElement(t),o=e.theme.heading;if(o!==void 0){const s=o[t];Ie(r,s)}return r}updateDOM(e,t,r){return e.__tag!==this.__tag}exportDOM(e){const{element:t}=super.exportDOM(e);if(ke(t)){this.isEmpty()&&t.append(Je().createElement("br"));const r=this.getFormatType();r&&(t.style.textAlign=r);const o=this.getDirection();o&&(t.dir=o)}return{element:t}}updateFromJSON(e){return super.updateFromJSON(e).setTag(e.tag)}exportJSON(){return{...super.exportJSON(),tag:this.getTag()}}insertNewAfter(e,t=!0){const r=e?e.anchor.offset:0,o=this.getLastDescendant(),s=!o||e&&e.anchor.key===o.getKey()&&r===o.getTextContentSize()||!e?ne():fn(this.getTag()),i=this.getDirection();if(s.setDirection(i),this.insertAfter(s,t),r===0&&!this.isEmpty()&&e){const a=ne();a.select(),this.replace(a,!0)}return s}collapseAtStart(){if(this.isEmpty()){const e=ne();this.getChildren().forEach(t=>e.append(t)),this.replace(e)}return!0}extractWithChild(){return!0}};function Zd(n){return n.nodeName.toLowerCase()==="span"&&n.style.fontSize==="26pt"}function to(n){const e=n.nodeName.toLowerCase();let t=null;return e!=="h1"&&e!=="h2"&&e!=="h3"&&e!=="h4"&&e!=="h5"&&e!=="h6"||(t=fn(e),Bs(n,t),rr(t,n),mn(t,n)),{node:t}}function J0(n){const e=Ln();return rr(e,n),Bs(n,e),mn(e,n),{node:e}}function fn(n="h1"){return Ot(new qs(n))}function Wr(n){return n instanceof qs}function Qd(n){const e=Ae(n);return It(e)}function no(n,e,t,r){let o=!1,s=null;if(n.isCollapsed()&&n.anchor.type==="text"){const a=n.anchor.getNode();if(oe(a)){s=a;const l=n.anchor.offset,c=l===a.getTextContentSize()&&a.getNextSibling()===null,u=l===0&&a.getPreviousSibling()===null;o=t==="end"&&c||t==="start"&&u||t==="both"&&(c||u)}}let i=!1;for(const[a,l]of Object.entries(r)){if(l==null||!l[e])continue;const c=a;if(l.onlyAtBoundary){if(!(o&&s&&oe(s)&&s.hasFormat(c)))continue;i=!0}n.hasFormat(c)&&n.toggleFormat(c)}i&&n.setStyle("")}const q0={capitalize:{enter:!0,space:!0,tab:!0},lowercase:{enter:!0,space:!0,tab:!0},uppercase:{enter:!0,space:!0,tab:!0}};function si(n,e){return(function(t,r){if(!t.isCollapsed())return!1;const o=vs(t.focus,r),s=re(o.origin,Ra);if(!s)return!1;const i=t.focus.getNode();if(!s.is(i)&&!Xp(i,s))return!1;const a=mi(o,gt(s,r));if(a.getTextSlices().some(f=>f&&f.getTextContentSize()>0))return!1;const l=mi(a.anchor.getSiblingCaret(),a.focus);let c=l.anchor.origin;for(const f of l){if(!Mc(f)||!f.origin.is(c.getParent()))return!1;c=f.origin}let u=s;for(const f of Ll(gt(s,r))){if(!f.origin.is(u.getParent())){if(Ey(f.origin)){const d=gt(u,r);return Ri(mi(d,d)),!0}break}if(!Ra(f.origin))break;u=f.origin}return!1})(n,e)||(function(t,r){if(!t.isCollapsed()||t.anchor.type!=="element")return!1;const o=vs(t.anchor,r).getNodeAtCaret();return!(!Ra(o)||o.isInline()||(Ri(Gp(Jn(Er(o,r)))),0))})(n,e)}function ef(n){return It(n)&&!n.isInline()&&!n.isIsolated()&&n.isKeyboardSelectable()}function ii(n){const e=aa();e.add(n),Ee(e)}function tf(n,e){if(!n.isCollapsed())return!1;const t=n.focus,r=t.getNode(),o=e?"previous":"next",s=vs(t,o);if(t.type==="element"&&q(r)&&wt(r)){const b=s.getNodeAtCaret();return!(b===null||!ef(b))&&(ii(b.__key),!0)}const i=re(q(r)?r:r.getParentOrThrow(),b=>q(b)&&!b.isInline()&&wt(b.getParent()));if(i===null)return!1;const a=gt(i,o).getNodeAtCaret();if(a===null||!ef(a))return!1;if(i.getTextContentSize()===0)return ii(a.__key),!0;const l=zo().getRootElement();if(l===null)return!1;const c=or(l.ownerDocument.defaultView);if(c===null||c.rangeCount===0)return!1;const u=c.anchorNode,f=c.anchorOffset,d=c.focusNode,g=c.focusOffset;c.modify("move",e?"backward":"forward","line");const h=c.anchorNode,_=c.anchorOffset;if(h===null)return nf(c,u,f,d,g),!1;const m=Ae(h);return nf(c,u,f,d,g),m===null?!1:(h===u&&_===f||!m.is(i)&&!Xp(m,i))&&(ii(a.__key),!0)}function nf(n,e,t,r,o){e!==null&&r!==null&&n.setBaseAndExtent(e,t,r,o)}function rf(n,e){if(!n.isCollapsed())return!1;const t=n.focus.getNode(),r=re(q(t)?t:t.getParentOrThrow(),m=>q(m)&&!m.isInline());if(r===null)return!1;const o=zo(),s=o.getRootElement();if(s===null)return!1;const i=s.ownerDocument.defaultView;if(i===null)return!1;let a=!1;for(const m of r.getChildren())if(q(m)&&m.isInline()){const b=o.getElementByKey(m.getKey());if(b!==null){const w=i.getComputedStyle(b).display;if(w==="inline-grid"||w==="inline-flex"){a=!0;break}}}if(!a)return!1;const l=gt(r,e?"previous":"next").getNodeAtCaret();if(l===null||!q(l)){if(e){const m=r.getFirstDescendant();oe(m)?m.select(0,0):r.select(0,0)}else{const m=r.getLastDescendant();if(oe(m)){const b=m.getTextContentSize();m.select(b,b)}else{const b=r.getChildrenSize();r.select(b,b)}}return!0}const c=o.getElementByKey(l.getKey());if(c===null)return!1;const u=or(i);if(u===null||u.rangeCount===0)return!1;const f=u.getRangeAt(0).cloneRange();f.collapse(!0);const d=f.getBoundingClientRect(),g=c.getBoundingClientRect(),h=g.top+g.height/2;if(d.height>0){const m=El(d.left,h,s);if(m!==null&&c.contains(m.node)){const b=s.ownerDocument.createRange();return b.setStart(m.node,m.offset),b.collapse(!0),n.applyDOMRange(b),n.dirty=!0,!0}}const _=e?l.getLastDescendant():l.getFirstDescendant();if(oe(_)){const m=e?_.getTextContentSize():0;_.select(m,m)}else{const m=l.getChildrenSize();l.select(e?m:0,e?m:0)}return!0}function ai(n,e){const t=gt(n,e),r=t.getAdjacentCaret();r!==null&&q(r.origin)&&!r.origin.isInline()&&r.origin.isShadowRoot()?Ri(Gp(t)):e==="next"?n.selectNext(0,0):n.selectPrevious()}function of(n,e,t){t.preventDefault(),t.stopPropagation();const r=n.getNodes();if(r.length===0)return!0;const o=r.map(l=>gt(l,"next")).sort(Iy),s=(e?o[0]:o[o.length-1]).origin,i=re(s,l=>l!==s&&q(l)&&!l.isInline())??se(),a=e?0:i.getChildrenSize();return i.select(a,a),!0}function i_(n,e=Ac(q0)){return de(n.registerCommand(Ks,()=>{const t=D();return ve(t)?(t.clear(),!0):(F(t)&&no(t,"click","both",e.peek()),!1)},V),n.registerCommand(bi,t=>{const r=D();return F(r)?(r.deleteCharacter(t),!0):!!ve(r)&&(r.deleteNodes(),!0)},V),n.registerCommand(Yp,t=>{const r=D();return!!F(r)&&(r.deleteWord(t),!0)},V),n.registerCommand(Vp,t=>{const r=D();return!!F(r)&&(r.deleteLine(t),!0)},V),n.registerCommand(qp,t=>{const r=D();if(typeof t=="string")r!==null&&r.insertText(t);else{if(r===null)return!1;const o=t.dataTransfer;if(o!=null)wd(o,r);else if(F(r)){const s=t.data;return s&&r.insertText(s),!0}}return!0},V),n.registerCommand(Ty,()=>{const t=D();return!!F(t)&&(t.removeText(),!0)},V),n.registerCommand(Xe,t=>{const r=D();return!(!F(r)&&!ve(r))&&(ky(r,t),!0)},V),n.registerCommand(Sy,t=>{const r=D();return!(!F(r)&&!ve(r))&&(vy(r,t),!0)},V),n.registerCommand(Bn,t=>{const r=D();if(!F(r)&&!ve(r))return!1;const o=r.getNodes();for(const s of o){const i=re(s,a=>q(a)&&!a.isInline());i!==null&&i.setFormat(t)}return!0},V),n.registerCommand(Nl,t=>{const r=D();return!!F(r)&&(r.insertLineBreak(t),!0)},V),n.registerCommand(Lo,()=>{const t=D();return!!F(t)&&(t.insertParagraph(),!0)},V),n.registerCommand(Tl,()=>{const t=Kn(),r=D();return F(r)&&(t.setFormat(r.format),t.setStyle(r.style)),Tr([t]),!0},V),n.registerCommand(Dt,()=>kd(t=>{const r=t.getIndent();t.setIndent(r+1)}),V),n.registerCommand(wn,()=>kd(t=>{const r=t.getIndent();r>0&&t.setIndent(Math.max(0,r-1))}),V),n.registerCommand(pt,t=>{const r=D();if(ve(r)){const o=r.getNodes();if(o.length>0)return t.preventDefault(),ai(o[0],"previous"),!0}else if(F(r)&&((function(o){const s=o.focus;return s.key==="root"&&s.offset===0})(r)||!t.shiftKey&&si(r,"previous")||!t.shiftKey&&tf(r,!0)||!t.shiftKey&&rf(r,!0)))return t.preventDefault(),!0;return!1},V),n.registerCommand(Vt,t=>{const r=D();if(ve(r)){const o=r.getNodes();if(o.length>0)return t.preventDefault(),ai(o[0],"next"),!0}else if(F(r)&&((function(o){const s=o.focus;return s.key==="root"&&s.offset===se().getChildrenSize()})(r)||!t.shiftKey&&si(r,"next")||!t.shiftKey&&tf(r,!1)||!t.shiftKey&&rf(r,!1)))return t.preventDefault(),!0;return!1},V),n.registerCommand(zs,t=>{const r=D();if(ve(r)){const o=r.getNodes();if(o.length>0)return t.preventDefault(),ai(o[0],Qs(o[0])?"next":"previous"),!0}if(!F(r))return!1;if(!t.shiftKey&&si(r,Qs(r.anchor.getNode())?"next":"previous"))return t.preventDefault(),!0;if(t.shiftKey||no(r,"arrow","start",e.peek()),Sd(r,!0)){const o=t.shiftKey;return t.preventDefault(),vd(r,o,!0),!0}return!1},V),n.registerCommand(ia,t=>{const r=D();if(ve(r)){const o=r.getNodes();if(o.length>0)return t.preventDefault(),ai(o[0],Qs(o[0])?"previous":"next"),!0}if(!F(r))return!1;if(!t.shiftKey&&si(r,Qs(r.anchor.getNode())?"previous":"next"))return t.preventDefault(),!0;if(t.shiftKey||no(r,"arrow","end",e.peek()),Sd(r,!1)){const o=t.shiftKey;return t.preventDefault(),vd(r,o,!1),!0}return!1},V),n.registerCommand(sa,t=>{const r=D();if(!ve(r)&&Qd(t.target))return!1;if(F(r)){if((function(o){if(!o.isCollapsed())return!1;const{anchor:s}=o;if(s.offset!==0)return!1;const i=s.getNode();if(Jp(i))return!1;const a=Rc(i);return a.getIndent()>0&&(a.is(i)||i.is(a.getFirstDescendant()))})(r))return t.preventDefault(),n.dispatchCommand(wn);if(xd&&Cd)return!1}else if(!ve(r))return!1;return t.preventDefault(),n.dispatchCommand(bi,!0)},V),n.registerCommand(Oc,t=>{const r=D();return!(!ve(r)&&Qd(t.target))&&!(!F(r)&&!ve(r))&&(t.preventDefault(),n.dispatchCommand(bi,!1))},V),n.registerCommand(zr,t=>{let r=D();if(ve(r)){const o=r.getNodes();o.length===1&&It(o[0])&&!o[0].isInline()&&(r=o[0].selectNext())}if(!F(r))return!1;if(no(r,"enter","both",e.peek()),t!==null){if((xd||xy||Cy)&&Cd)return!1;if(t.preventDefault(),t.shiftKey)return n.dispatchCommand(Nl,!1)}return n.dispatchCommand(Lo)},V),n.registerCommand(Nn,()=>{const t=D();return!!F(t)&&(n.blur(),!0)},V),n.registerCommand(Lc,t=>{const[,r]=uo(t);if(r.length>0){const o=t.clientX,s=t.clientY,i=El(o,s,n.getRootElement());if(i!==null){const{offset:a,node:l}=i,c=Ae(l);if(c!==null){const u=kr();if(oe(c))u.anchor.set(c.getKey(),a,"text"),u.focus.set(c.getKey(),a,"text");else{const d=c.getParentOrThrow().getKey(),g=c.getIndexWithinParent()+1;u.anchor.set(d,g,"element"),u.focus.set(d,g,"element")}const f=Ss(u);Ee(f)}n.dispatchCommand(Xd,r)}return t.preventDefault(),!0}return wy(t,n)},V),n.registerCommand(Wp,t=>{const[r]=uo(t),o=D();return!(r&&!F(o))&&(F(o)&&!o.isCollapsed()&&t.dataTransfer!==null&&(by(t.dataTransfer,Hp(o)),yy(t.dataTransfer,n)),!0)},V),n.registerCommand(Nc,t=>{const[r]=uo(t),o=D();if(r&&!F(o))return!1;const s=t.clientX,i=t.clientY,a=El(s,i,n.getRootElement());if(a!==null){const l=Ae(a.node);It(l)&&t.preventDefault()}return!0},V),n.registerCommand(Ec,()=>{const t=D();return _y(F(t)&&my(t.anchor.getNode())!==null?t:null),!0},V),n.registerCommand(Kp,t=>(Il(n,fo(t,ClipboardEvent)?t:null),!0),V),n.registerCommand(zp,t=>((async function(r,o){await Il(o,fo(r,ClipboardEvent)?r:null),o.update(()=>{const s=D();F(s)?s.removeText():ve(s)&&s.getNodes().forEach(i=>i.remove())},{tag:hy})})(t,n),!0),V),n.registerCommand(Ic,t=>{const[,r,o]=uo(t);return r.length>0&&!o?(n.dispatchCommand(Xd,r),!0):No(t.target)&&py(t.target)?!1:D()!==null&&((function(s,i){s.preventDefault(),i.update(()=>{const a=D(),l=fo(s,InputEvent)||fo(s,KeyboardEvent)?null:s.clipboardData;l!=null&&a!==null&&wd(l,a)},{tag:Up})})(t,n),!0)},V),n.registerCommand(Bp,()=>{const t=D();return F(t)&&no(t,"space","both",e.peek()),!1},V),n.registerCommand(Kr,()=>{const t=D();return F(t)&&no(t,"tab","both",e.peek()),!1},V),n.registerCommand(xs,t=>{const r=D();if(ve(r))return of(r,!1,t);if(!F(r))return!1;const{anchor:o}=r;if(o.type!=="element"||o.offset!==0)return!1;const s=o.getNode();if(!q(s))return!1;const i=s.getFirstChild();if(!It(i)||!i.isInline())return!1;const a=s.getKey(),l=s.selectEnd();return t.shiftKey&&l.anchor.set(a,0,"element"),t.preventDefault(),t.stopPropagation(),!0},V),n.registerCommand(Ir,t=>{const r=D();if(ve(r))return of(r,!0,t);if(!F(r))return!1;const{anchor:o,focus:s}=r,i=re(s.getNode(),c=>q(c)&&!c.isInline());if(i===null)return!1;const a=i.getFirstChild();if(!It(a)||!a.isInline()||re(o.getNode(),c=>q(c)&&!c.isInline())!==i)return!1;const l=i.getKey();return(s.type!=="element"||s.key!==l||s.offset!==0)&&(r.focus.set(l,0,"element"),t.shiftKey||r.anchor.set(l,0,"element"),t.preventDefault(),t.stopPropagation(),!0)},V))}function jn(n,...e){const t=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",n);for(const o of e)r.append("v",o);throw t.search=r.toString(),Error(`Minified Lexical error #${n}; visit ${t.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function Is(n){let e=1,t=n.getParent();for(;t!=null;){if(le(t)){const r=t.getParent();if(Z(r)){e++,t=r.getParent();continue}jn(40)}return e}return e}function Hl(n){const e=n.getParent();Z(e)||jn(40);let t=e,r=e;for(;r!==null;)r=r.getParent(),Z(r)&&(t=r);return t}function a_(n){let e=[];const t=n.getChildren().filter(le);for(let r=0;r<t.length;r++){const o=t[r],s=o.getFirstChild();Z(s)?e=e.concat(a_(s)):e.push(o)}return e}function Rt(n){return le(n)&&Z(n.getFirstChild())}function l_(n,e){return le(n)&&(e.length===0||e.length===1&&n.is(e[0])&&n.getChildrenSize()===0)}function Jl(n){const e=D();if(e!==null){let t=e.getNodes();if(F(e)){const[o]=e.getStartEndPoints(),s=o.getNode(),i=s.getParent();if(wt(s)){const a=s.getFirstChild();if(a)t=a.selectStart().getNodes();else{const l=ne();s.append(l),t=l.select().getNodes()}}else if(l_(s,t)){const a=Et(n);if(wt(i)){s.replace(a);const l=xt();q(s)&&(l.setFormat(s.getFormatType()),l.setIndent(s.getIndent())),a.append(l)}else if(le(s)){const l=s.getParentOrThrow();Nr(a,l.getChildren()),l.replace(a)}return}}const r=new Set;for(let o=0;o<t.length;o++){const s=t[o];if(q(s)&&s.isEmpty()&&!le(s)&&!r.has(s.getKey())){sf(s,n);continue}let i=Qp(s)?s.getParent():le(s)&&s.isEmpty()?s:null;for(;i!=null;){const a=i.getKey();if(Z(i)){if(!r.has(a)){const l=Et(n);Nr(l,i.getChildren()),i.replace(l),r.add(a)}break}{const l=i.getParent();if(wt(l)&&!r.has(a)){r.add(a),sf(i,n);break}i=l}}}}}function Nr(n,e){n.splice(n.getChildrenSize(),0,e)}function sf(n,e){if(Z(n))return n;const t=n.getPreviousSibling(),r=n.getNextSibling(),o=xt();let s;if(Nr(o,n.getChildren()),Z(t)&&e===t.getListType())t.append(o),Z(r)&&e===r.getListType()&&(Nr(t,r.getChildren()),r.remove()),s=t;else if(Z(r)&&e===r.getListType())r.getFirstChildOrThrow().insertBefore(o),s=r;else{const a=Et(e);a.append(o),n.replace(a),s=a}o.setFormat(n.getFormatType()),o.setIndent(n.getIndent());const i=D();return F(i)&&(s.getKey()===i.anchor.key&&i.anchor.set(o.getKey(),i.anchor.offset,"element"),s.getKey()===i.focus.key&&i.focus.set(o.getKey(),i.focus.offset,"element")),n.remove(),s}function Xc(n,e){const t=n.getLastChild(),r=e.getFirstChild();t&&r&&Rt(t)&&Rt(r)&&(Xc(t.getFirstChild(),r.getFirstChild()),r.remove());const o=e.getChildren();o.length>0&&n.append(...o),e.remove()}function V0(){const n=D();if(F(n)){const e=new Set,t=n.getNodes(),r=n.anchor.getNode();if(l_(r,t))e.add(Hl(r));else for(let o=0;o<t.length;o++){const s=t[o];if(Qp(s)){const i=Ol(s,bn);i!=null&&e.add(Hl(i))}}for(const o of e){let s=o;const i=a_(o);for(const a of i){const l=ne().setTextStyle(n.style).setTextFormat(n.format);Nr(l,a.getChildren()),s.insertAfter(l),s=l,a.__key===n.anchor.key&&hr(n.anchor,Jn(Er(l,"next"))),a.__key===n.focus.key&&hr(n.focus,Jn(Er(l,"next"))),a.remove()}o.remove()}}}function c_(n){const e=n.getListType()!=="check";let t=n.getStart();for(const r of n.getChildren())le(r)&&(r.getValue()!==t&&r.setValue(t),e&&r.getLatest().__checked!=null&&r.setChecked(void 0),Z(r.getFirstChild())||t++)}function Y0(n){const e=new Set;if(Rt(n)||e.has(n.getKey()))return;const t=n.getParent(),r=n.getNextSibling(),o=n.getPreviousSibling();if(Rt(r)&&Rt(o)){const s=o.getFirstChild();if(Z(s)){s.append(n);const i=r.getFirstChild();Z(i)&&(Nr(s,i.getChildren()),r.remove(),e.add(r.getKey()))}}else if(Rt(r)){const s=r.getFirstChild();if(Z(s)){const i=s.getFirstChild();i!==null&&i.insertBefore(n)}}else if(Rt(o)){const s=o.getFirstChild();Z(s)&&s.append(n)}else if(Z(t)){const s=it(n),i=it(t);s.append(i),i.append(n),o?o.insertAfter(s):r?r.insertBefore(s):t.append(s)}}function af(n){if(Rt(n))return;const e=n.getParent(),t=e?e.getParent():void 0;if(Z(t?t.getParent():void 0)&&le(t)&&Z(e)){const r=e?e.getFirstChild():void 0,o=e?e.getLastChild():void 0;if(n.is(r))t.insertBefore(n),e.isEmpty()&&t.remove();else if(n.is(o))t.insertAfter(n),e.isEmpty()&&t.remove();else{const s=it(n),i=it(e);s.append(i),n.getPreviousSiblings().forEach(c=>i.append(c));const a=it(n),l=it(e);a.append(l),Nr(l,n.getNextSiblings()),t.insertBefore(s),t.insertAfter(a),t.replace(n)}}}function G0(n=!1){const e=D();if(!F(e)||!e.isCollapsed())return!1;const t=e.anchor.getNode();let r=null;if(le(t)&&t.getChildrenSize()===0)r=t;else if(oe(t)){const c=t.getParent();le(c)&&c.getChildren().every(u=>oe(u)&&u.getTextContent().trim()==="")&&(r=c)}if(r===null)return!1;const o=Hl(r),s=r.getParent();Z(s)||jn(40);const i=s.getParent();let a;if(wt(i))a=ne(),o.insertAfter(a);else{if(!le(i))return!1;a=it(i),i.insertAfter(a)}a.setTextStyle(e.style).setTextFormat(e.format).select();const l=r.getNextSiblings();if(l.length>0){const c=n?(function(f,d){return f.getStart()+d.getIndexWithinParent()})(s,r):1,u=it(s).setStart(c);if(le(a)){const f=it(a);f.append(u),a.insertAfter(f)}else a.insertAfter(u);u.append(...l)}return(function(c){let u=c;for(;u.getNextSibling()==null&&u.getPreviousSibling()==null;){const f=u.getParent();if(f==null||!le(f)&&!Z(f))break;u=f}u.remove()})(r),!0}let bn=class extends Oe{__value;__checked;$config(){return this.config("listitem",{$transform:e=>{const t=e.getParent();if(Z(t))t.getListType()!=="check"&&e.getChecked()!=null&&e.setChecked(void 0);else if(t){const r=e.createParentElementNode();Z(r)||jn(340);const o=[e];for(const s of["previous","next"]){o.reverse();for(const{origin:i}of gt(e,s)){if(!le(i))break;o.push(i)}}e.insertBefore(r),r.splice(0,0,o),wt(t)||(Zp(r,Dc(gt(r,"next")),{$shouldSplit:()=>!1,removeEmptyDestination:!0}),t.isEmpty()&&t.isAttached()&&t.remove())}},extends:Oe,importDOM:$c({li:()=>({conversion:X0,priority:0})})})}constructor(e=1,t=void 0,r){super(r),this.__value=e===void 0?1:e,this.__checked=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__value=e.__value,this.__checked=e.__checked}createDOM(e){const t=Je().createElement("li");return this.updateListItemDOM(null,t,e),t}updateListItemDOM(e,t,r){(function(i,a){const l=a.getParent();!Z(l)||l.getListType()!=="check"||Z(a.getFirstChild())?(i.removeAttribute("role"),i.removeAttribute("tabIndex"),i.removeAttribute("aria-checked")):(i.setAttribute("role","checkbox"),i.setAttribute("tabIndex","-1"),i.setAttribute("aria-checked",a.getChecked()?"true":"false"))})(t,this),t.value=this.__value,(function(i,a,l){const c=a.list;if(!c)return;const u=c.listitem,f=c.nested&&c.nested.listitem,d=l.getParent(),g=Z(d)&&d.getListType()==="check",h=l.getChecked(),_=l.getChildren().some(w=>Z(w)),m=[];c.listitemChecked!==void 0&&m.push(c.listitemChecked),c.listitemUnchecked!==void 0&&m.push(c.listitemUnchecked),f!==void 0&&m.push(...ps(f)),m.length>0&&$t(i,...m);const b=[];if(u!==void 0&&b.push(...ps(u)),g){const w=h?c.listitemChecked:c.listitemUnchecked;w!==void 0&&b.push(w)}f!==void 0&&_&&b.push(...ps(f)),b.length>0&&Ie(i,...b)})(t,r.theme,this);const o=e?e.__style:"",s=this.__style;o!==s&&_o(t.style,s,o),(function(i,a,l){const c=a.__textStyle,u=l?l.__textStyle:"";if(l!==null&&u===c)return;const f=Td(c);for(const d in f)i.style.setProperty(`--listitem-marker-${d}`,f[d]);if(u!=="")for(const d in Td(u))d in f||i.style.removeProperty(`--listitem-marker-${d}`)})(t,this,e)}updateDOM(e,t,r){const o=t;return this.updateListItemDOM(e,o,r),!1}updateFromJSON(e){return super.updateFromJSON(e).setValue(e.value).setChecked(e.checked)}exportDOM(e){const t=this.createDOM(e._config),r=this.getFormatType();r&&(t.style.textAlign=r);const o=this.getDirection();return o&&(t.dir=o),Rt(this)?{after(s){if(ke(s)){const i=s.previousElementSibling;if(ke(i)&&i.nodeName==="LI"){for(;s.firstChild;)i.append(s.firstChild);s.remove()}}return s},element:t}:{element:t}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...e){for(let t=0;t<e.length;t++){const r=e[t];if(q(r)&&this.canMergeWith(r)){const o=r.getChildren();this.append(...o),r.remove()}else super.append(r)}return this}replace(e,t){if(le(e))return super.replace(e);this.setIndent(0);const r=this.getParentOrThrow();if(!Z(r))return e;if(r.__first===this.getKey())r.insertBefore(e);else if(r.__last===this.getKey())r.insertAfter(e);else{const i=it(r);let a=this.getNextSibling();for(;a;){const l=a;a=a.getNextSibling(),i.append(l)}r.insertAfter(e),e.insertAfter(i)}const o=this.__key;let s=0;if(t&&(q(e)||jn(139),s=e.getChildrenSize(),e.splice(s,0,this.getChildren())),t&&q(e)){const i=D();if(F(i))for(const a of i.getStartEndPoints())a.key===o&&a.type==="element"&&a.set(e.getKey(),s+a.offset,"element")}return this.remove(),r.getChildrenSize()===0&&r.remove(),e}insertAfter(e,t=!0){const r=this.getParentOrThrow();if(Z(r)||jn(39),le(e))return super.insertAfter(e,t);const o=this.getNextSiblings();if(r.insertAfter(e,t),o.length!==0){const s=it(r);o.forEach(i=>s.append(i)),e.insertAfter(s,t)}return e}remove(e){const t=this.getPreviousSibling(),r=this.getNextSibling();super.remove(e),t&&r&&Rt(t)&&Rt(r)&&(Xc(t.getFirstChild(),r.getFirstChild()),r.remove())}resetOnCopyNodeFrom(e){super.resetOnCopyNodeFrom(e),e.getChecked()&&this.setChecked(!1)}insertNewAfter(e,t=!0){const r=it(this);return this.insertAfter(r,t),r}collapseAtStart(e){if(Rt(this))return!1;const t=this.getParentOrThrow();if(le(t.getParentOrThrow()))return af(this),!0;const r=ne().append(...this.getChildren()),o=this.getNextSiblings();if(o.length>0){const s=it(t);s.append(...o),t.insertAfter(s)}return t.insertAfter(r),this.remove(),t.getChildrenSize()===0&&t.remove(),r.selectStart(),!0}getValue(){return this.getLatest().__value}setValue(e){const t=this.getWritable();return t.__value=e,t}getChecked(){const e=this.getLatest();let t;const r=this.getParent();return Z(r)&&(t=r.getListType()),t==="check"?!!e.__checked:void 0}setChecked(e){const t=this.getWritable();return t.__checked=e,t}toggleChecked(){const e=this.getWritable();return e.setChecked(!e.__checked)}getIndent(){const e=this.getParent();if(e===null||!this.isAttached())return this.getLatest().__indent;let t=e.getParentOrThrow(),r=0;for(;le(t);)t=t.getParentOrThrow().getParentOrThrow(),r++;return r}setIndent(e){typeof e!="number"&&jn(117),(e=Math.floor(e))>=0||jn(199);let t=this.getIndent();for(;t!==e;)t<e?(Y0(this),t++):(af(this),t--);return this}canInsertAfter(e){return le(e)}canReplaceWith(e){return le(e)}canMergeWith(e){return le(e)||ht(e)}extractWithChild(e,t){if(!F(t))return!1;const r=t.anchor.getNode(),o=t.focus.getNode();return this.isParentOf(r)&&this.isParentOf(o)&&this.getTextContent().length===t.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return Et("bullet")}canMergeWhenEmpty(){return!0}};function X0(n){if(n.classList.contains("task-list-item")){for(const r of n.children)if(r.tagName==="INPUT")return lf(r)}if(n.classList.contains("joplin-checkbox")){for(const r of n.children)if(r.classList.contains("checkbox-wrapper")&&r.children.length>0&&r.children[0].tagName==="INPUT")return lf(r.children[0])}const e=n.getAttribute("aria-checked"),t=xt(e==="true"||e!=="false"&&void 0);return rr(t,n),{after:u_.bind(null,t),node:mn(t,n)}}function lf(n){if(n.getAttribute("type")!=="checkbox")return{node:null};const e=xt(n.hasAttribute("checked"));return{after:u_.bind(null,e),node:e}}function u_(n,e){const t=e[0];return e.length===1&&ht(t)&&!n.getFormatType()&&t.getFormatType()?(n.setFormat(t.getFormatType()),t.getChildren()):e}function xt(n){return Ot(new bn(void 0,n))}function le(n){return n instanceof bn}let Yt=class extends Oe{__tag;__start;__listType;$config(){return this.config("list",{$transform:e=>{(function(t){const r=t.getNextSibling();Z(r)&&t.getListType()===r.getListType()&&Xc(t,r)})(e),c_(e)},extends:Oe,importDOM:$c({ol:()=>({conversion:uf,priority:0}),ul:()=>({conversion:uf,priority:0})})})}constructor(e="number",t=1,r){super(r);const o=Z0[e]||e;this.__listType=o,this.__tag=o==="number"?"ol":"ul",this.__start=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__listType=e.__listType,this.__tag=e.__tag,this.__start=e.__start}getTag(){return this.getLatest().__tag}setListType(e){const t=this.getWritable();return t.__listType=e,t.__tag=e==="number"?"ol":"ul",t}getListType(){return this.getLatest().__listType}getStart(){return this.getLatest().__start}setStart(e){const t=this.getWritable();return t.__start=e,t}createDOM(e,t){const r=this.__tag,o=Je().createElement(r);return this.__start!==1&&o.setAttribute("start",String(this.__start)),o.__lexicalListType=this.__listType,cf(o,e.theme,this),o}updateDOM(e,t,r){return e.__tag!==this.__tag||e.__listType!==this.__listType||(cf(t,r.theme,this),e.__start!==this.__start&&t.setAttribute("start",String(this.__start)),!1)}updateFromJSON(e){return super.updateFromJSON(e).setListType(e.listType).setStart(e.start)}exportDOM(e){const t=this.createDOM(e._config,e);return ke(t)&&(this.__start!==1&&t.setAttribute("start",String(this.__start)),this.__listType==="check"&&t.setAttribute("__lexicalListType","check")),{element:t}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag()}}canBeEmpty(){return!1}canIndent(){return!1}splice(e,t,r){let o=r;for(let s=0;s<r.length;s++){const i=r[s];le(i)||(o===r&&(o=[...r]),o[s]=this.createListItemNode().append(!q(i)||Z(i)||i.isInline()?i:$e(i.getTextContent())))}return super.splice(e,t,o)}extractWithChild(e){return le(e)}createListItemNode(){return xt()}};function cf(n,e,t){const r=[],o=[],s=e.list;if(s!==void 0){const i=s[`${t.__tag}Depth`]||[],a=Is(t)-1,l=a%i.length,c=i[l],u=s[t.__tag];let f;const d=s.nested,g=s.checklist;if(d!==void 0&&d.list&&(f=d.list),u!==void 0&&r.push(u),g!==void 0&&t.__listType==="check"&&r.push(g),c!==void 0){r.push(...ps(c));for(let h=0;h<i.length;h++)h!==l&&o.push(t.__tag+h)}if(f!==void 0){const h=ps(f);a>1?r.push(...h):o.push(...h)}}o.length>0&&$t(n,...o),r.length>0&&Ie(n,...r)}function uf(n){let e;if((function(t){return ke(t)&&t.nodeName.toLowerCase()==="ol"})(n)){const t=n.start;e=Et("number",t)}else e=(function(t){if(t.getAttribute("__lexicallisttype")==="check"||t.classList.contains("contains-task-list")||t.getAttribute("data-is-checklist")==="1")return!0;for(const r of t.childNodes)if(ke(r)&&r.hasAttribute("aria-checked"))return!0;return!1})(n)?Et("check"):Et("bullet");return mn(e,n),{after:t=>(function(r,o){const s=o.createListItemNode.bind(o),i=[];for(let a=0;a<r.length;a++){const l=r[a];if(le(l)){i.push(l);const c=l.getChildren();c.length>1&&c.forEach(u=>{Z(u)&&i.push(s().append(u))})}else i.push(s().append(l))}return i})(t,e),node:e}}const Z0={ol:"number",ul:"bullet"};function Et(n="number",e=1){return Ot(new Yt(n,e))}function Z(n){return n instanceof Yt}const Zc=he("INSERT_CHECK_LIST_COMMAND");function Q0(n,e){const t=e&&e.disableTakeFocusOnClick||!1,r=typeof t=="boolean"?()=>t:t.peek.bind(t),o=c=>{const u=c.target;if(!ke(u))return!1;const f=u.__lexicalCheckListLastHandled;return f!==void 0&&c.timeStamp-f<500},s=c=>{const u=c.target;ke(u)&&(u.__lexicalCheckListLastHandled=c.timeStamp)},i=c=>{o(c)||(s(c),df(c,r()))},a=c=>{c.pointerType==="touch"&&(o(c)||(s(c),df(c,r())))},l=c=>{(function(u,f){d_(u,()=>{u.preventDefault(),f&&u.stopPropagation()})})(c,r())};return de(n.registerCommand(Zc,()=>(Jl("check"),!0),ee),n.registerCommand(Vt,c=>ff(c,n,!1),ee),n.registerCommand(pt,c=>ff(c,n,!0),ee),n.registerCommand(Nn,()=>{if(ql(n)!=null){const c=n.getRootElement();return c?.focus(),!0}return!1},ee),n.registerCommand(Bp,c=>{const u=ql(n);return!(u==null||!n.isEditable())&&(n.update(()=>{const f=Ae(u);le(f)&&(c.preventDefault(),f.toggleChecked())}),!0)},ee),n.registerCommand(zs,c=>n.read("latest",()=>{const u=D();if(F(u)&&u.isCollapsed()){const{anchor:f}=u,d=f.type==="element";if(d||f.offset===0){const g=f.getNode(),h=re(g,_=>q(_)&&!_.isInline());if(le(h)){const _=h.getParent();if(Z(_)&&_.getListType()==="check"&&(d||h.getFirstDescendant()===g)){const m=n.getElementByKey(h.__key);if(m!=null&&la(m)!==m)return m.focus(),c.preventDefault(),!0}}}}return!1}),ee),n.registerRootListener(c=>{if(c!==null)return de(Id(c,{click:i,pointerup:a}),Id(c,{mousedown:l,pointerdown:l},{capture:!0}),Jt(c,"touchstart",l,{capture:!0,passive:!1}))}))}function d_(n,e){const t=n.target;if(!ke(t))return;const r=t.firstChild;if(ke(r)&&(r.tagName==="UL"||r.tagName==="OL"))return;const o=t.parentNode;if(!o||o.__lexicalListType!=="check")return;let s=null,i=null;if("clientX"in n)s=n.clientX;else if("touches"in n){const g=n.touches;g.length>0&&(s=g[0].clientX,i="touch")}if(s==null)return;const a=t.getBoundingClientRect(),l=s/Wn(t),c=t.ownerDocument.defaultView,u=c?c.getComputedStyle(t,"::before"):{width:"0px"},f=parseFloat(u.width),d=i==="touch"||"pointerType"in n&&n.pointerType==="touch"?32:0;(t.dir==="rtl"?l<a.right+d&&l>a.right-f-d:l>a.left-d&&l<a.left+f+d)&&e()}function df(n,e){d_(n,()=>{if(ke(n.target)){const t=n.target,r=Oy(t);r!=null&&r.isEditable()&&r.update(()=>{const o=Ae(t);le(o)&&(e?(Ai(Ry),Ai(Ay)):t.focus(),o.toggleChecked())})}})}function ql(n){const e=n.getRootElement(),t=e?la(e):null;return ke(t)&&t.tagName==="LI"&&t.parentNode!=null&&t.parentNode.__lexicalListType==="check"?t:null}function ff(n,e,t){const r=ql(e);return r!=null&&e.update(()=>{const o=Ae(r);if(!le(o))return;const s=(function(i,a){let l=a?i.getPreviousSibling():i.getNextSibling(),c=i;for(;l==null&&le(c);)c=c.getParentOrThrow().getParent(),c!=null&&(l=a?c.getPreviousSibling():c.getNextSibling());for(;le(l);){const u=a?l.getLastChild():l.getFirstChild();if(!Z(u))return l;l=a?u.getLastChild():u.getFirstChild()}return null})(o,t);if(s!=null){s.selectStart();const i=e.getElementByKey(s.__key);i!=null&&(n.preventDefault(),setTimeout(()=>{i.focus()},0))}}),!1}function eC(n){const e=[];for(const t of n)if(le(t)){e.push(t);const r=t.getChildren();if(r.length>1)for(const o of r)Z(o)&&e.push(xt().append(o))}else e.push(xt().append(t));return e}const tC=Ye({$import:(n,e)=>{let t;var r;return eh(e,"ol")?t=Et("number",e.start):t=(r=e).matches('[__lexicallisttype="check"], .contains-task-list, [data-is-checklist="1"]')||r.querySelector(":scope > [aria-checked]")!==null?Et("check"):Et("bullet"),mn(t,e),[t.splice(0,0,th(eC(n.$importChildren(e)),e))]},match:Ge.tag("ol","ul"),name:"@lexical/list/list"});function f_(n,e){if(e.length!==1)return e;const t=e[0];return ht(t)&&!n.getFormatType()&&t.getFormatType()?(n.setFormat(t.getFormatType()),t.getChildren()):e}function g_(n){const e=i=>Ly(i)&&!Z(i);if(!n.some(e))return n;const t=[];let r=[];const o=()=>{r.length>0&&(t.push(r),r=[])};for(const i of n)e(i)?(o(),t.push(q(i)?i.getChildren():[i])):r.push(i);o();const s=[];for(const i of t)s.length>0&&s.push(vt()),s.push(...i);return s}const nC=Ye({$import:(n,e)=>{const t=e.getAttribute("aria-checked"),r=xt(t==="true"||t!=="false"&&void 0);return rr(r,e),mn(r,e),[r.splice(0,0,g_(f_(r,n.$importChildren(e))))]},match:Ge.tag("li"),name:"@lexical/list/li"});function gf(n,e,t){const r=eh(t,"input")?t:t.querySelector('input[type="checkbox"]');if(!r||r.getAttribute("type")!=="checkbox")return[];const o=xt(r.hasAttribute("checked"));return rr(o,e),mn(o,e),[o.splice(0,0,g_(f_(o,n.$importChildren(e))))]}const rC=[Ye({$import:(n,e,t)=>{const r=e.querySelector(':scope > input[type="checkbox"]');return r?gf(n,e,r):t()},match:Ge.tag("li").classAll("task-list-item"),name:"@lexical/list/li-task-list-item"}),Ye({$import:(n,e,t)=>{const r=e.querySelector(":scope > .checkbox-wrapper");if(!r)return t();const o=r.querySelector(':scope > input[type="checkbox"]');return o?gf(n,e,o):t()},match:Ge.tag("li").classAll("joplin-checkbox"),name:"@lexical/list/li-joplin-checkbox"}),tC,nC],oC=he("UPDATE_LIST_START_COMMAND"),Qc=he("INSERT_UNORDERED_LIST_COMMAND"),eu=he("INSERT_ORDERED_LIST_COMMAND"),sC=he("REMOVE_LIST_COMMAND");function iC(n,e){return de(n.registerCommand(eu,()=>(Jl("number"),!0),ee),n.registerCommand(oC,t=>{const{listNodeKey:r,newStart:o}=t,s=Q(r);return!!Z(s)&&(s.getListType()==="number"&&(s.setStart(o),c_(s)),!0)},ee),n.registerCommand(Qc,()=>(Jl("bullet"),!0),ee),n.registerCommand(sC,()=>(V0(),!0),ee),n.registerCommand(Lo,()=>G0(!!(e&&e.restoreNumbering)),ee),n.registerCommand(sa,t=>{const r=D();if(!F(r)||!r.isCollapsed())return!1;const{anchor:o}=r;if(o.offset!==0)return!1;let s=o.getNode();for(;!le(s);){if(s.getPreviousSibling()!==null)return!1;const i=s.getParent();if(i===null)return!1;s=i}return!(!le(s)||!s.collapseAtStart(r))&&(t.preventDefault(),!0)},My),n.registerNodeTransform(bn,t=>{const r=t.getFirstChild();if(r){if(oe(r)){const o=r.getStyle(),s=r.getFormat();t.getTextStyle()!==o&&t.setTextStyle(o),t.getTextFormat()!==s&&t.setTextFormat(s)}}else{const o=D();F(o)&&(o.style!==t.getTextStyle()||o.format!==t.getTextFormat())&&o.isCollapsed()&&t.is(o.anchor.getNode())&&t.setTextStyle(o.style).setTextFormat(o.format)}}),n.registerNodeTransform(cn,t=>{const r=t.getParent();if(le(r)&&t.is(r.getFirstChild())){const o=t.getStyle(),s=t.getFormat();o===r.getTextStyle()&&s===r.getTextFormat()||r.setTextStyle(o).setTextFormat(s)}}))}function aC(n){const e=t=>{const r=t.getParent();if(Z(t.getFirstChild())||!Z(r))return;const o=re(t,s=>le(s)&&Z(s.getParent())&&le(s.getPreviousSibling()));if(o===null&&t.getIndent()>0)t.setIndent(0);else if(le(o)){const s=o.getPreviousSibling();if(le(s)){const i=(function(l){let c=l,u=c.getFirstChild();for(;Z(u);){const f=u.getLastChild();if(!le(f))break;c=f,u=c.getFirstChild()}return c})(s),a=i.getParent();if(Z(a)){const l=Is(a);l+1<Is(r)&&t.setIndent(l)}}}};return n.registerNodeTransform(Yt,t=>{const r=[t];for(;r.length>0;){const o=r.shift();if(Z(o)){for(const s of o.getChildren())if(le(s)){e(s);const i=s.getFirstChild();Z(i)&&r.push(i)}}}})}const da=pe({build:(n,e,t)=>nr(e),config:tr({hasStrictIndent:!1,shouldPreserveNumbering:!1}),dependencies:[js,ln(Fs,{rules:rC})],name:"@lexical/list/List",nodes:()=>[Yt,bn],register(n,e,t){const r=t.getOutput();return de(zt(()=>iC(n,{restoreNumbering:r.shouldPreserveNumbering.value})),zt(()=>r.hasStrictIndent.value?aC(n):void 0))}}),lC=pe({build:(n,e)=>nr(e),config:tr({disableTakeFocusOnClick:!1}),dependencies:[da],name:"@lexical/list/CheckList",register:(n,e,t)=>Q0(n,t.getOutput())}),pf=new Set(["http:","https:","mailto:","sms:","tel:"]);class gn extends Oe{__url;__target;__rel;__title;$config(){return this.config("link",{extends:Oe,importDOM:{a:()=>({conversion:uC,priority:1})}})}constructor(e="",t={},r){super(r);const{target:o=null,rel:s=null,title:i=null}=t;this.__url=e,this.__target=o,this.__rel=s,this.__title=i}afterCloneFrom(e){super.afterCloneFrom(e),this.__url=e.__url,this.__rel=e.__rel,this.__target=e.__target,this.__title=e.__title}createDOM(e){const t=Je().createElement("a");return this.updateLinkDOM(null,t,e),Ie(t,e.theme.link),t}updateLinkDOM(e,t,r){if(nh(t)){e&&e.__url===this.__url||(t.href=this.sanitizeUrl(this.__url));for(const o of["target","rel","title"]){const s=`__${o}`,i=this[s];e&&e[s]===i||(i?t[o]=i:t.removeAttribute(o))}}}updateDOM(e,t,r){return this.updateLinkDOM(e,t,r),!1}updateFromJSON(e){return super.updateFromJSON(e).setURL(e.url).setRel(e.rel||null).setTarget(e.target||null).setTitle(e.title||null)}sanitizeUrl(e){const t=e;e=bf(e);try{const r=new URL(bf(e));if(!pf.has(r.protocol))return"about:blank"}catch{const o=t.replace(/[\u0000-\u001F\u007F\s]/g,"").match(/^([a-z][a-z0-9+.-]*):/i);if(o!=null&&!pf.has(`${o[1].toLowerCase()}:`))return"about:blank"}return e}exportJSON(){return{...super.exportJSON(),rel:this.getRel(),target:this.getTarget(),title:this.getTitle(),url:this.getURL()}}getURL(){return this.getLatest().__url}setURL(e){const t=this.getWritable();return t.__url=e,t}getTarget(){return this.getLatest().__target}setTarget(e){const t=this.getWritable();return t.__target=e,t}getRel(){return this.getLatest().__rel}setRel(e){const t=this.getWritable();return t.__rel=e,t}getTitle(){return this.getLatest().__title}setTitle(e){const t=this.getWritable();return t.__title=e,t}insertNewAfter(e,t=!0){const r=it(this);return this.insertAfter(r,t),r}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(e,t,r){if(!F(t))return!1;const o=t.anchor.getNode(),s=t.focus.getNode();return(this.is(o)||this.isParentOf(o))&&(this.is(s)||this.isParentOf(s))&&t.getTextContent().length>0}isEmailURI(){return this.__url.startsWith("mailto:")}isWebSiteURI(){return this.__url.startsWith("https://")||this.__url.startsWith("http://")}shouldMergeAdjacentLink(e){return this.getType()===e.getType()&&this.__url===e.__url&&this.__target===e.__target&&this.__rel===e.__rel&&this.__title===e.__title}}function hf(n){const e=vs(n,"next");return[e,e.getFlipped()]}function _f(n,e){for(const t of e)if(t.origin.isAttached()){const r=Jn(t);return void hr(n,r)}}function cC(n){const e=D();let t=null,r=null;function o(){F(e)&&(_f(e.anchor,t),_f(e.focus,r),Ss(e))}F(e)&&(t=hf(e.anchor),r=hf(e.focus));let s=!1;for(const a of Er(n,"next")){const l=a.origin;if(q(l)&&!l.isInline()){const c=l.getChildren();if(c.length>0){const u=it(n);u.append(...c),l.append(u),s=!0}Zp(l,Dc(a),{$shouldSplit:()=>!1})}}function i(a,l,c){const[u,f]=a,d=h=>Mc(h)&&h.origin.is(l);if(!d(u)&&!d(f))return a;const g=Jn(Er(c,"next"));return[g,g.getFlipped()]}if(n.isAttached()){const a=n.getPreviousSibling();if(Pe(a)&&a.shouldMergeAdjacentLink(n))return t&&(t=i(t,a,n)),r&&(r=i(r,a,n)),a.append(...n.getChildren()),n.remove(),void o();const l=n.getNextSibling();Pe(l)&&n.shouldMergeAdjacentLink(l)&&(t&&(t=i(t,n,l)),r&&(r=i(r,n,l)),n.append(...l.getChildren()),l.remove(),s=!0)}if(s){if(!n.canBeEmpty()&&n.isEmpty()){const a=n.getParent();n.remove(),a&&a.isEmpty()&&a.remove()}o()}}function uC(n){let e=null;if(nh(n)){const t=n.textContent;(t!==null&&t!==""||n.children.length>0)&&(e=Mo(n.getAttribute("href")||"",{rel:n.getAttribute("rel"),target:n.getAttribute("target"),title:n.getAttribute("title")}))}return{node:e}}function Mo(n="",e){return Ot(new gn(n,e))}function Pe(n){return n instanceof gn}let fa=class extends gn{__isUnlinked;constructor(e="",t={},r){super(e,t,r),this.__isUnlinked=t.isUnlinked!==void 0&&t.isUnlinked!==null&&t.isUnlinked}afterCloneFrom(e){super.afterCloneFrom(e),this.__isUnlinked=e.__isUnlinked}$config(){return this.config("autolink",{extends:gn})}shouldMergeAdjacentLink(e){return!1}getIsUnlinked(){return this.__isUnlinked}setIsUnlinked(e){const t=this.getWritable();return t.__isUnlinked=e,t}createDOM(e){return this.__isUnlinked?Je().createElement("span"):super.createDOM(e)}updateDOM(e,t,r){return super.updateDOM(e,t,r)||e.__isUnlinked!==this.__isUnlinked}updateFromJSON(e){return super.updateFromJSON(e).setIsUnlinked(e.isUnlinked||!1)}exportJSON(){return{...super.exportJSON(),isUnlinked:this.__isUnlinked}}insertNewAfter(e,t=!0){const r=p_(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return this.insertAfter(r,t),r}};function p_(n="",e){return Ot(new fa(n,e))}function _t(n){return n instanceof fa}const Lr=he("TOGGLE_LINK_COMMAND");function mf(n,e){if(n.type==="element"){const t=n.getNode();return q(t)||(function(r,...o){const s=new URL("https://lexical.dev/docs/error"),i=new URLSearchParams;i.append("code",r);for(const a of o)i.append("v",a);throw s.search=i.toString(),Error(`Minified Lexical error #${r}; visit ${s.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)})(252),t.getChildren()[n.offset+e]||null}return null}function Ka(n,e={}){let t;if(n&&typeof n=="object"){const{url:u,...f}=n;t=u,e={...f,...e}}else t=n;const{target:r,title:o}=e,s=e.rel===void 0?"noreferrer":e.rel,i=D();if(i===null||!F(i)&&!ve(i))return;if(ve(i)){const u=i.getNodes();return u.length===0?void 0:void u.forEach(f=>{if(t===null){const d=re(f,g=>!_t(g)&&Pe(g));d&&(d.insertBefore(f),d.getChildren().length===0&&d.remove())}else{const d=re(f,g=>!_t(g)&&Pe(g));if(d)d.setURL(t),r!==void 0&&d.setTarget(r),s!==void 0&&d.setRel(s);else{const g=Mo(t,{rel:s,target:r});f.insertBefore(g),g.append(f)}}})}if(i.isCollapsed()&&t===null)for(const u of i.getNodes()){const f=re(u,d=>!_t(d)&&Pe(d));return void(f!==null&&(f.getParentOrThrow().splice(f.getIndexWithinParent(),0,f.getChildren()),f.remove()))}const a=i.extract();if(t===null){const u=new Set;return void a.forEach(f=>{const d=re(f,g=>!_t(g)&&Pe(g));if(d!==null){const g=d.getKey();if(u.has(g))return;(function(h,_){const m=new Set(_.filter(N=>h.isParentOf(N)).map(N=>N.getKey())),b=h.getChildren(),w=N=>m.has(N.getKey())||q(N)&&_.some(O=>h.isParentOf(O)&&N.isParentOf(O)),C=b.filter(w);if(C.length===b.length)return b.forEach(N=>h.insertBefore(N)),void h.remove();const v=b.findIndex(w),k=b.findLastIndex(w),I=v===0,E=k===b.length-1;if(I)C.forEach(N=>h.insertBefore(N));else if(E)for(let N=C.length-1;N>=0;N--)h.insertAfter(C[N]);else{for(let O=C.length-1;O>=0;O--)h.insertAfter(C[O]);const N=b.slice(k+1);if(N.length>0){const O=it(h);C[C.length-1].insertAfter(O),N.forEach(M=>O.append(M))}}})(d,a),u.add(g)}})}const l=new Set,c=u=>{l.has(u.getKey())||(l.add(u.getKey()),u.setURL(t),r!==void 0&&u.setTarget(r),s!==void 0&&u.setRel(s),o!==void 0&&u.setTitle(o))};if(a.length===1){const u=a[0],f=re(u,Pe);if(f!==null)return c(f)}(function(u){const f=D();if(!F(f))return u();const d=Ss(f),g=d.isBackward(),h=mf(d.anchor,g?-1:0),_=mf(d.focus,g?0:-1);if(u(),h||_){const m=D();if(F(m)){const b=m.clone();if(h){const w=h.getParent();w&&b.anchor.set(w.getKey(),h.getIndexWithinParent()+(g?1:0),"element")}if(_){const w=_.getParent();w&&b.focus.set(w.getKey(),_.getIndexWithinParent()+(g?0:1),"element")}Ee(Ss(b))}}})(()=>{let u=null;for(const f of a){if(!f.isAttached())continue;const d=re(f,Pe);if(d){c(d);continue}if(q(f)){if(!f.isInline())continue;if(Pe(f)){if(!(_t(f)||u!==null&&u.getParentOrThrow().isParentOf(f))){c(f),u=f;continue}for(const h of f.getChildren())f.insertBefore(h);f.remove();continue}}const g=f.getPreviousSibling();Pe(g)&&g.is(u)?g.append(f):(u=Mo(t,{rel:s,target:r,title:o}),f.insertAfter(u),u.append(f))}})}const dC=/^\+?[0-9\s()-]{5,}$/;function bf(n){return n.match(/^[a-z][a-z0-9+.-]*:/i)||n.match(/^[/#.]/)?n:n.includes("@")?`mailto:${n}`:dC.test(n)?`tel:${n}`:`https://${n}`}const fC=[Ye({$import:(n,e)=>{if(!e.textContent&&e.children.length===0)return[];const t=e.getAttribute("href")||"",r={rel:e.getAttribute("rel"),target:e.getAttribute("target"),title:e.getAttribute("title")};return $y(n.$importChildren(e),()=>Mo(t,r))},match:Ge.tag("a"),name:"@lexical/link/a"})];function h_(n,e){return de(n.registerNodeTransform(gn,cC),n.registerCommand(Lr,t=>{const r=e.validateUrl.peek(),o=e.attributes.peek();if(t===null)return Ka(null),!0;if(typeof t=="string")return!(r!==void 0&&!r(t))&&(Ka(t,o),!0);{const{url:s,target:i,rel:a,title:l}=t;return Ka(s,{...o,rel:a,target:i,title:l}),!0}},V),zt(()=>{const t=e.validateUrl.value;if(!t)return;const r=e.attributes.value;return n.registerCommand(Ic,o=>{const s=D();if(!F(s)||s.isCollapsed()||!fo(o,ClipboardEvent)||o.clipboardData===null)return!1;const i=o.clipboardData.getData("text");return t(i)?!s.getNodes().some(a=>q(a)||oe(a)&&!a.isSimpleText())&&(n.dispatchCommand(Lr,{...r,url:i}),o.preventDefault(),!0):!1},ee)}))}const tu=pe({build:(n,e,t)=>nr(e),config:{attributes:void 0,validateUrl:void 0},dependencies:[js,ln(Fs,{rules:fC})],mergeConfig(n,e){const t=Eo(n,e);return n.attributes&&(t.attributes=Eo(n.attributes,t.attributes)),t},name:"@lexical/link/Link",nodes:()=>[gn],register:(n,e,t)=>h_(n,t.getOutput())});function Vl(n,e){for(let t=0;t<e.length;t++){const r=e[t](n);if(r)return r}return null}const __=/[.,;\s]/;function Bi(n,e){return e.test(n)}function m_(n,e){return Bi(n[n.length-1],e)}function Yl(n,e){return Bi(n[0],e)}function b_(n,e){let t=n.getPreviousSibling();return q(t)&&(t=t.getLastDescendant()),t===null||ue(t)||oe(t)&&m_(t.getTextContent(),e)}function y_(n,e){let t=n.getNextSibling();return q(t)&&(t=t.getFirstDescendant()),t===null||ue(t)||oe(t)&&Yl(t.getTextContent(),e)}function gC(n,e,t,r,o){return(n>0?Bi(r[n-1],t):b_(o[0],t))?e<r.length?Bi(r[e],t):y_(o[o.length-1],t):!1}function pC(n,e,t){const r=[],o=[],s=[];let i=0,a=0;const l=[...n];for(;l.length>0;){const c=l[0],u=c.getTextContent().length,f=a;a+u<=e?(r.push(c),i+=u):f>=t?s.push(c):o.push(c),a+=u,l.shift()}return[i,r,o,s]}function hC(n,e,t,r){const o=p_(r.url,r.attributes);if(n.length===1){let s,i=n[0];e===0?[s,i]=i.splitText(t):[,s,i]=i.splitText(e,t);const a=$e(r.text);return a.setFormat(s.getFormat()),a.setDetail(s.getDetail()),a.setStyle(s.getStyle()),o.append(a),s.replace(o),i}if(n.length>1){const s=n[0];let i,a=s.getTextContent().length;e===0?i=s:[,i]=s.splitText(e);const l=[];let c;for(let g=1;g<n.length;g++){const h=n[g],_=h.getTextContent().length,m=a;if(m<t)if(a+_<=t)l.push(h);else{const[b,w]=h.splitText(t-m);l.push(b),c=w}a+=_}const u=D(),f=u?u.getNodes().find(oe):void 0,d=$e(i.getTextContent());return d.setFormat(i.getFormat()),d.setDetail(i.getDetail()),d.setStyle(i.getStyle()),o.append(d,...l),f&&f===i&&(F(u)?d.select(u.anchor.offset,u.focus.offset):ve(u)&&d.select(0,d.getTextContent().length)),i.replace(o),c}}function yf(n,e,t,r){const o=n.getChildren(),s=o.length;for(let c=0;c<s;c++){const u=o[c];if(!oe(u)||!u.isSimpleText())return _s(n),void t(null,n.getURL())}const i=n.getTextContent(),a=Vl(i,e);if(a===null||a.text!==i||!b_(n,r)||!y_(n,r))return _s(n),void t(null,n.getURL());const l=n.getURL();if(l!==a.url&&(n.setURL(a.url),t(a.url,l)),a.attributes){const c=n.getRel();c!==a.attributes.rel&&(n.setRel(a.attributes.rel||null),t(a.attributes.rel||null,c));const u=n.getTarget();u!==a.attributes.target&&(n.setTarget(a.attributes.target||null),t(a.attributes.target||null,u))}}function _s(n){const e=n.getChildren();for(let t=e.length-1;t>=0;t--)n.insertAfter(e[t]);return n.remove(),e.map(t=>t.getLatest())}const w_={changeHandlers:[],excludeParents:[],matchers:[],separatorRegex:__};function _C(n,e=w_){const{matchers:t,changeHandlers:r,excludeParents:o,separatorRegex:s=__}=e,i=(a,l)=>{for(const c of r)c(a,l)};return de(n.registerNodeTransform(cn,a=>{const l=a.getParentOrThrow(),c=a.getPreviousSibling();if(_t(l))yf(l,t,i,s);else if(!Pe(l)&&!o.some(u=>u(l))){if(a.isSimpleText()&&(Yl(a.getTextContent(),s)||!_t(c))){const u=(function(f){const d=[f];let g=f.getNextSibling();for(;g!==null&&oe(g)&&g.isSimpleText()&&(d.push(g),!/[\s]/.test(g.getTextContent()));)g=g.getNextSibling();return d})(a);(function(f,d,g,h){for(const v of f){const k=v.getParent();if(_t(k)&&!k.getIsUnlinked())return}let _=[...f];const m=_.map(v=>v.getTextContent()).join("");let b,w=m,C=0;for(;(b=Vl(w,d))&&b!==null;){const v=b.index,k=v+b.length;if(gC(C+v,C+k,h,m,_)){const[I,,E,N]=pC(_,C+v,C+k);let O=!1;for(const R of E){const $=R.getParent();if(_t($)&&!$.getIsUnlinked()){O=!0;break}}if(O){C+=k,w=w.substring(k);continue}const M=hC(E,C+v-I,C+k-I,b);_=M?[M,...N]:N,g(b.url,null),C=0}else C+=k;w=w.substring(k)}})(u,t,i,s)}(function(u,f,d,g){const h=u.getParent(),_=u.getPreviousSibling(),m=u.getNextSibling(),b=u.getTextContent();if(!_t(h)||h.getIsUnlinked()){if(_t(_)&&!_.getIsUnlinked()&&_.is(u.getPreviousSibling())&&u.getParent()===_.getParent()){if(!Yl(b,g))return _s(_),void d(null,_.getURL());if(w=b,_.isEmailURI()?/^\.[a-zA-Z]{2,}/.test(w):/^\.[a-zA-Z0-9]{1,}/.test(w)){const C=_.getTextContent()+b,v=Vl(C,f);v!==null&&v.text===C&&(_.append(u),yf(_,f,d,g),d(null,_.getURL()))}}var w;!_t(m)||m.getIsUnlinked()||m_(b,g)||m.is(u.getNextSibling())&&u.getParent()===m.getParent()&&(_s(m),d(null,m.getURL()))}})(a,t,i,s)}}),n.registerCommand(Lr,a=>{const l=D();return a!==null||!F(l)||l.extract().forEach(c=>{const u=c.getParent();_t(u)&&(u.setIsUnlinked(!u.getIsUnlinked()),u.markDirty())}),!1},ee))}const mC=pe({config:w_,dependencies:[tu],mergeConfig(n,e){const t=Eo(n,e);for(const r of["matchers","changeHandlers","excludeParents"]){const o=e[r];Array.isArray(o)&&(t[r]=[...n[r],...o])}return t},name:"@lexical/link/AutoLink",nodes:[fa],register:_C}),Co=/^(\d+(?:\.\d+)?)px$/,te={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};let Gt=class extends Oe{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;$config(){return this.config("tablecell",{extends:Oe,importDOM:{td:()=>({conversion:wf,priority:0}),th:()=>({conversion:wf,priority:0})}})}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign,this.__colSpan=e.__colSpan,this.__headerState=e.__headerState,this.__width=e.__width}updateFromJSON(e){return super.updateFromJSON(e).setHeaderStyles(e.headerState).setColSpan(e.colSpan||1).setRowSpan(e.rowSpan||1).setWidth(e.width||void 0).setBackgroundColor(e.backgroundColor||null).setVerticalAlign(e.verticalAlign||void 0)}constructor(e=te.NO_STATUS,t=1,r,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=r,this.__backgroundColor=null,this.__verticalAlign=void 0}createDOM(e){const t=Je().createElement(this.getTag());return this.__width&&(t.style.width=`${this.__width}px`),this.__colSpan>1&&(t.colSpan=this.__colSpan),this.__rowSpan>1&&(t.rowSpan=this.__rowSpan),this.__backgroundColor!==null&&(t.style.backgroundColor=this.__backgroundColor),Gl(this.__verticalAlign)&&(t.style.verticalAlign=this.__verticalAlign),Ie(t,e.theme.tableCell,this.hasHeader()&&e.theme.tableCellHeader),t}exportDOM(e){const t=super.exportDOM(e);if(ke(t.element)){const r=t.element;r.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),r.style.border="1px solid black",this.__colSpan>1&&(r.colSpan=this.__colSpan),this.__rowSpan>1&&(r.rowSpan=this.__rowSpan),r.style.width=`${this.getWidth()||75}px`,r.style.verticalAlign=this.getVerticalAlign()||"top",r.style.textAlign="start",this.__backgroundColor===null&&this.hasHeader()&&(r.style.backgroundColor="#f2f3f5")}return t}exportJSON(){return{...super.exportJSON(),...Gl(this.__verticalAlign)&&{verticalAlign:this.__verticalAlign},backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=te.BOTH){const r=this.getWritable();return r.__headerState=e&t|r.__headerState&~t,r}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}getVerticalAlign(){return this.getLatest().__verticalAlign}setVerticalAlign(e){const t=this.getWritable();return t.__verticalAlign=e||void 0,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==te.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor||e.__verticalAlign!==this.__verticalAlign}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}};function Gl(n){return n==="middle"||n==="bottom"}function wf(n){const e=n,t=n.nodeName.toLowerCase();let r;Co.test(e.style.width)&&(r=parseFloat(e.style.width));let o=te.NO_STATUS;if(t==="th"){const _=e.getAttribute("scope");if(_==="col")o=te.COLUMN;else if(_==="row")o=te.ROW;else{const m=e.parentElement,b=ke(m)&&m.nodeName.toLowerCase()==="tr"&&ke(m.parentElement)&&(m.parentElement.nodeName.toLowerCase()==="thead"||m.rowIndex===0),w=e.cellIndex===0;b&&(o|=te.ROW),w&&(o|=te.COLUMN),o===te.NO_STATUS&&(o=te.ROW)}}const s=lt(o,e.colSpan,r);s.__rowSpan=e.rowSpan;const i=e.style.backgroundColor;i!==""&&(s.__backgroundColor=i);const a=e.style.verticalAlign;Gl(a)&&(s.__verticalAlign=a);const l=e.style,c=(l&&l.textDecoration||"").split(" "),u=l.fontWeight==="700"||l.fontWeight==="bold",f=c.includes("line-through"),d=l.fontStyle==="italic",g=c.includes("underline"),h=l.color;return{after:_=>{const m=[];let b=null;const w=()=>{if(b){const C=b.getFirstChild();ue(C)&&b.getChildrenSize()===1&&C.remove()}};for(const C of _)if(sh(C)||oe(C)||ue(C)){if(oe(C)&&(u&&C.toggleFormat("bold"),f&&C.toggleFormat("strikethrough"),d&&C.toggleFormat("italic"),g&&C.toggleFormat("underline"),h)){const v=C.getStyle();v.includes("color:")||C.setStyle(v+`color: ${h};`)}b?b.append(C):(b=ne().append(C),m.push(b))}else m.push(C),w(),b=null;return w(),m.length===0&&m.push(ne()),m},node:s}}function lt(n=te.NO_STATUS,e=1,t){return Ot(new Gt(n,e,t))}function J(n){return n instanceof Gt}const nu=he("INSERT_TABLE_COMMAND");function G(n,...e){const t=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",n);for(const o of e)r.append("v",o);throw t.search=r.toString(),Error(`Minified Lexical error #${n}; visit ${t.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class Wo extends Oe{__height;$config(){return this.config("tablerow",{extends:Oe,importDOM:{tr:()=>({conversion:bC,priority:0})}})}afterCloneFrom(e){super.afterCloneFrom(e),this.__height=e.__height}updateFromJSON(e){return super.updateFromJSON(e).setHeight(e.height)}constructor(e=void 0,t){super(t),this.__height=e}exportJSON(){const e=this.getHeight();return{...super.exportJSON(),...e===void 0?void 0:{height:e}}}createDOM(e){const t=Je().createElement("tr");return this.__height&&(t.style.height=`${this.__height}px`),Ie(t,e.theme.tableRow),t}extractWithChild(e,t,r){return r==="html"}isShadowRoot(){return!0}setHeight(e){const t=this.getWritable();return t.__height=e,t}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function bC(n){const e=n;let t;return Co.test(e.style.height)&&(t=parseFloat(e.style.height)),{after:r=>Mi(r,J),node:pn(t)}}function pn(n){return Ot(new Wo(n))}function ce(n){return n instanceof Wo}function x_(n,e,t=!0){const r=Ho();for(let o=0;o<n;o++){const s=pn();for(let i=0;i<e;i++){let a=te.NO_STATUS;typeof t=="object"?(o===0&&t.rows&&(a|=te.ROW),i===0&&t.columns&&(a|=te.COLUMN)):t&&(o===0&&(a|=te.ROW),i===0&&(a|=te.COLUMN));const l=lt(a),c=ne();c.append($e()),l.append(c),s.append(l)}r.append(s)}return r}function Xl(n){const e=re(n,t=>J(t));return J(e)?e:null}function ru(n){const e=re(n,t=>ce(t));if(ce(e))return e;throw new Error("Expected table cell to be inside of table row.")}function ot(n){const e=re(n,t=>be(t));if(be(e))return e;throw new Error("Expected table cell to be inside of table.")}function ou(n){const e=ru(n);return ot(e).getChildren().findIndex(t=>t.is(e))}function C_(n){return ru(n).getChildren().findIndex(e=>e.is(n))}function S_(n,e){const t=ot(n),{x:r,y:o}=t.getCordsFromCellNode(n,e);return{above:t.getCellNodeFromCords(r,o-1,e),below:t.getCellNodeFromCords(r,o+1,e),left:t.getCellNodeFromCords(r-1,o,e),right:t.getCellNodeFromCords(r+1,o,e)}}function yC(n,e){const t=n.getChildren();if(e>=t.length||e<0)throw new Error("Expected table cell to be inside of table row.");return t[e].remove(),n}function wC(n,e,t=!0,r,o){const s=n.getChildren();if(e>=s.length||e<0)throw new Error("Table row target index out of range");const i=s[e];if(!ce(i))throw new Error("Row before insertion index does not exist.");for(let a=0;a<r;a++){const l=i.getChildren(),c=l.length,u=pn();for(let f=0;f<c;f++){const d=l[f];J(d)||G(12);const{above:g,below:h}=S_(d,o);let _=te.NO_STATUS;const m=g&&g.getWidth()||h&&h.getWidth()||void 0;(g&&g.hasHeaderState(te.COLUMN)||h&&h.hasHeaderState(te.COLUMN))&&(_|=te.COLUMN);const b=lt(_,1,m);b.append(ne()),u.append(b)}t?i.insertAfter(u):i.insertBefore(u)}return n}const Zl=(n,e)=>n===te.BOTH||n===e?e:te.NO_STATUS;function ga(n=!0){const e=D();F(e)||ae(e)||G(188);const t=e.anchor.getNode(),r=e.focus.getNode(),[o]=We(t),[s,,i]=We(r),[,a,l]=ct(i,s,o),{startRow:c}=l,{startRow:u}=a;return n?Ui(c+o.__rowSpan>u+s.__rowSpan?o:s,!0):Ui(u<c?s:o,!1)}const xC=ga;function Ui(n,e=!0){const[,,t]=We(n),[r,o]=ct(t,n,n),s=r[0].length,{startRow:i}=o;let a=null;if(e){const l=i+n.__rowSpan-1,c=r[l],u=pn();for(let d=0;d<s;d++){const{cell:g,startRow:h}=c[d];if(h+g.__rowSpan-1<=l){const _=c[d].cell.__headerState,m=Zl(_,te.COLUMN);u.append(lt(m).append(ne()))}else g.setRowSpan(g.__rowSpan+1)}const f=t.getChildAtIndex(l);ce(f)||G(256),f.insertAfter(u),a=u}else{const l=i,c=r[l],u=pn();for(let d=0;d<s;d++){const{cell:g,startRow:h}=c[d];if(h===l){const _=c[d].cell.__headerState,m=Zl(_,te.COLUMN);u.append(lt(m).append(ne()))}else g.setRowSpan(g.__rowSpan+1)}const f=t.getChildAtIndex(l);ce(f)||G(257),f.insertBefore(u),a=u}return a}function CC(n,e,t=!0,r,o){const s=n.getChildren(),i=[];for(let a=0;a<s.length;a++){const l=s[a];if(ce(l))for(let c=0;c<r;c++){const u=l.getChildren();if(e>=u.length||e<0)throw new Error("Table column target index out of range");const f=u[e];J(f)||G(12);const{left:d,right:g}=S_(f,o);let h=te.NO_STATUS;(d&&d.hasHeaderState(te.ROW)||g&&g.hasHeaderState(te.ROW))&&(h|=te.ROW);const _=lt(h);_.append(ne()),i.push({newTableCell:_,targetCell:f})}}return i.forEach(({newTableCell:a,targetCell:l})=>{t?l.insertAfter(a):l.insertBefore(a)}),n}function pa(n=!0){const e=D();F(e)||ae(e)||G(188);const t=e.anchor.getNode(),r=e.focus.getNode(),[o]=We(t),[s,,i]=We(r),[,a,l]=ct(i,s,o),{startColumn:c}=l,{startColumn:u}=a;return n?zi(c+o.__colSpan>u+s.__colSpan?o:s,!0):zi(u<c?s:o,!1)}const SC=pa;function zi(n,e=!0,t=!0){const[,,r]=We(n),[o,s]=ct(r,n,n),i=o.length,{startColumn:a}=s,l=e?a+n.__colSpan-1:a-1,c=r.getFirstChild();ce(c)||G(120);let u=null;function f(h=te.NO_STATUS){const _=lt(h).append(ne());return u===null&&(u=_),_}let d=c;e:for(let h=0;h<i;h++){if(h!==0){const k=d.getNextSibling();ce(k)||G(121),d=k}const _=o[h],m=_[l<0?0:l].cell.__headerState,b=Zl(m,te.ROW);if(l<0){au(d,f(b));continue}const{cell:w,startColumn:C,startRow:v}=_[l];if(C+w.__colSpan-1<=l){let k=w,I=v,E=l;for(;I!==h&&k.__rowSpan>1;){if(E-=w.__colSpan,!(E>=0)){d.append(f(b));continue e}{const{cell:N,startRow:O}=_[E];k=N,I=O}}k.insertAfter(f(b))}else w.setColSpan(w.__colSpan+1)}u!==null&&t&&Es(u);const g=r.getColWidths();if(g){const h=[...g],_=l<0?0:l,m=h[_];h.splice(_,0,m),r.setColWidths(h)}return u}function vC(n,e){const t=n.getChildren();for(let r=0;r<t.length;r++){const o=t[r];if(ce(o)){const s=o.getChildren();if(e>=s.length||e<0)throw new Error("Table column target index out of range");s[e].remove()}}return n}function su(){const n=D();F(n)||ae(n)||G(188);const[e,t]=n.isBackward()?[n.focus.getNode(),n.anchor.getNode()]:[n.anchor.getNode(),n.focus.getNode()],[r,,o]=We(e),[s]=We(t),[i,a,l]=ct(o,r,s),{startRow:c}=a,{startRow:u}=l,f=u+s.__rowSpan-1;if(i.length===f-c+1)return void o.remove();const d=i[0].length,g=i[f+1],h=o.getChildAtIndex(f+1);for(let _=f;_>=c;_--){for(let b=d-1;b>=0;b--){const{cell:w,startRow:C,startColumn:v}=i[_][b];if(v===b){if(C<c||C+w.__rowSpan-1>f){const k=Math.max(C,c),I=Math.min(w.__rowSpan+C-1,f),E=k<=I?I-k+1:0;w.setRowSpan(w.__rowSpan-E)}if(C>=c&&C+w.__rowSpan-1>f&&_===f){ce(h)||G(387);let k=null;for(let I=0;I<b;I++){const E=g[I],N=E.cell;E.startRow===_+1&&(k=N),N.__colSpan>1&&(I+=N.__colSpan-1)}k===null?au(h,w):k.insertAfter(w)}}}const m=o.getChildAtIndex(_);ce(m)||G(206,String(_)),m.remove()}if(g!==void 0){const{cell:_}=g[0];Es(_)}else{const _=i[c-1],{cell:m}=_[0];Es(m)}}const kC=su;function iu(){const n=D();F(n)||ae(n)||G(188);const e=n.anchor.getNode(),t=n.focus.getNode(),[r,,o]=We(e),[s]=We(t),[i,a,l]=ct(o,r,s),{startColumn:c}=a,{startRow:u,startColumn:f}=l,d=Math.min(c,f),g=Math.max(c+r.__colSpan-1,f+s.__colSpan-1),h=g-d+1;if(i[0].length===g-d+1)return o.selectPrevious(),void o.remove();const _=i.length;for(let C=0;C<_;C++)for(let v=d;v<=g;v++){const{cell:k,startColumn:I}=i[C][v];if(I<d){if(v===d){const E=d-I;k.setColSpan(k.__colSpan-Math.min(h,k.__colSpan-E))}}else if(I+k.__colSpan-1>g){if(v===g){const E=g-I+1;k.setColSpan(k.__colSpan-E)}}else k.remove()}const m=i[u],b=c>f?m[c+r.__colSpan]:m[f+s.__colSpan];if(b!==void 0){const{cell:C}=b;Es(C)}else{const C=f<c?m[f-1]:m[c-1],{cell:v}=C;Es(v)}const w=o.getColWidths();if(w){const C=[...w];C.splice(d,h),o.setColWidths(C)}}const TC=iu;function Es(n){const e=n.getFirstDescendant();e==null?n.selectStart():e.getParentOrThrow().selectStart()}function au(n,e){const t=n.getFirstChild();t!==null?t.insertBefore(e):n.append(e)}function lu(n){if(n.length===0)return null;const e=ot(n[0]),[t]=at(e,null,null);let r=1/0,o=-1/0,s=1/0,i=-1/0;const a=new Set;for(const g of t)for(const h of g){if(!h||!h.cell)continue;const _=h.cell.getKey();if(!a.has(_)&&n.some(m=>m.is(h.cell))){a.add(_);const m=h.startRow,b=h.startColumn,w=h.cell.__rowSpan||1,C=h.cell.__colSpan||1;r=Math.min(r,m),o=Math.max(o,m+w-1),s=Math.min(s,b),i=Math.max(i,b+C-1)}}if(r===1/0||s===1/0)return null;const l=o-r+1,c=i-s+1,u=t[r][s];if(!u.cell)return null;const f=u.cell;f.setColSpan(c),f.setRowSpan(l);const d=new Set([f.getKey()]);for(let g=r;g<=o;g++)for(let h=s;h<=i;h++){const _=t[g][h];if(!_.cell)continue;const m=_.cell,b=m.getKey();d.has(b)||(d.add(b),IC(m)||f.append(...m.getChildren()),m.remove())}return f.getChildrenSize()===0&&f.append(ne()),f}function IC(n){if(n.getChildrenSize()!==1)return!1;const e=n.getFirstChildOrThrow();return!(!ht(e)||!e.isEmpty())}function v_(){const n=D();F(n)||ae(n)||G(188);const e=n.anchor.getNode(),t=re(e,J);return J(t)||G(148),cu(t)}function cu(n){const[e,t,r]=We(n),o=e.__colSpan,s=e.__rowSpan;if(o===1&&s===1)return;const[i,a]=ct(r,e,e),{startColumn:l,startRow:c}=a,u=e.__headerState&te.COLUMN,f=Array.from({length:o},(h,_)=>{let m=u;for(let b=0;m!==0&&b<i.length;b++)m&=i[b][_+l].cell.__headerState;return m}),d=e.__headerState&te.ROW,g=Array.from({length:s},(h,_)=>{let m=d;for(let b=0;m!==0&&b<i[0].length;b++)m&=i[_+c][b].cell.__headerState;return m});if(o>1){for(let h=1;h<o;h++)e.insertAfter(lt(f[h]|g[0]).append(ne()));e.setColSpan(1)}if(s>1){let h;for(let _=1;_<s;_++){const m=c+_,b=i[m];h=(h||t).getNextSibling(),ce(h)||G(125);let w=null;for(let C=0;C<l;C++){const v=b[C],k=v.cell;v.startRow===m&&(w=k),k.__colSpan>1&&(C+=k.__colSpan-1)}if(w===null)for(let C=o-1;C>=0;C--)au(h,lt(f[C]|g[_]).append(ne()));else for(let C=o-1;C>=0;C--)w.insertAfter(lt(f[C]|g[_]).append(ne()))}e.setRowSpan(1)}}function ct(n,e,t){const[r,o,s]=at(n,e,t);return o===null&&G(207),s===null&&G(208),[r,o,s]}function at(n,e,t){const r=[];let o=null,s=null;function i(l){let c=r[l];return c===void 0&&(r[l]=c=[]),c}const a=n.getChildren();for(let l=0;l<a.length;l++){const c=a[l];ce(c)||G(209);const u=i(l);for(let f=c.getFirstChild(),d=0;f!=null;f=f.getNextSibling()){for(J(f)||G(147);u[d]!==void 0;)d++;const g={cell:f,startColumn:d,startRow:l},{__rowSpan:h,__colSpan:_}=f;for(let m=0;m<h&&!(l+m>=a.length);m++){const b=i(l+m);for(let w=0;w<_;w++)b[d+w]=g}e!==null&&o===null&&e.is(f)&&(o=g),t!==null&&s===null&&t.is(f)&&(s=g)}}return[r,o,s]}function We(n){let e;if(n instanceof Gt)e=n;else if("__type"in n){const o=re(n,J);J(o)||G(148),e=o}else{const o=re(n.getNode(),J);J(o)||G(148),e=o}const t=e.getParent();ce(t)||G(149);const r=t.getParent();return be(r)||G(210),[e,t,r]}function Ns(n,e,t){let r,o=Math.min(e.startColumn,t.startColumn),s=Math.min(e.startRow,t.startRow),i=Math.max(e.startColumn+e.cell.__colSpan-1,t.startColumn+t.cell.__colSpan-1),a=Math.max(e.startRow+e.cell.__rowSpan-1,t.startRow+t.cell.__rowSpan-1);do{r=!1;for(let l=0;l<n.length;l++)for(let c=0;c<n[0].length;c++){const u=n[l][c];if(!u)continue;const f=u.startColumn+u.cell.__colSpan-1,d=u.startRow+u.cell.__rowSpan-1,g=u.startColumn<=i&&f>=o,h=u.startRow<=a&&d>=s;if(g&&h){const _=Math.min(o,u.startColumn),m=Math.max(i,f),b=Math.min(s,u.startRow),w=Math.max(a,d);_===o&&m===i&&b===s&&w===a||(o=_,i=m,s=b,a=w,r=!0)}}}while(r);return{maxColumn:i,maxRow:a,minColumn:o,minRow:s}}function uu(n){const e=n.getChildren();let t=null;for(const r of e){if(!ce(r)||(t===null&&(t=r.getChildrenSize()),r.getChildrenSize()!==t))return!1;const o=r.getChildren();for(const s of o)if(!J(s)||s.getRowSpan()!==1||s.getColSpan()!==1)return!1}return(t||0)>0}function EC(n,e,t){if(e===t)return;const r=n.getColumnCount();if(e<0||e>=r||t<0||t>=r||!uu(n))return;n.getChildren().filter(ce).forEach(s=>{const i=s.getChildren(),[a]=i.splice(e,1);i.splice(t,0,a),s.splice(0,i.length,i)});const o=n.getColWidths();if(o&&o.length===r){const s=[...o],[i]=s.splice(e,1);s.splice(t,0,i),n.setColWidths(s)}}function NC(n,e,t){if(e===t)return;const r=n.getChildren().filter(ce),o=r.length;if(e<0||e>=o||t<0||t>=o||!uu(n))return;const s=r[e],i=r[t];t>e?i.insertAfter(s):i.insertBefore(s)}function Ql(n){const[e,,t]=We(n),r=t.getChildren().filter(ce),o=r.length,s=r[0].getChildren().length,i=new Array(o);for(let a=0;a<o;a++)i[a]=new Array(s);for(let a=0;a<o;a++){const l=r[a].getChildren().filter(J);let c=0;for(let u=0;u<l.length;u++){for(;i[a][c];)c++;const f=l[u],d=f.__rowSpan||1,g=f.__colSpan||1;for(let h=0;h<d;h++)for(let _=0;_<g;_++)i[a+h][c+_]=f;if(e===f)return{colSpan:g,columnIndex:c,rowIndex:a,rowSpan:d};c+=g}}return null}function k_(n,e){const t=e.getStartEndPoints(),r=ae(e);if(t===null)return!1;const[o,s]=t,[i,a,l]=We(o),c=re(s.getNode(),R=>J(R));if(!(J(i)&&J(c)&&ce(a)&&be(l)))return!1;const[u,f,d]=ct(l,i,c),[g]=at(n,null,null),h=u.length,_=h>0?u[0].length:0;let m=f.startRow,b=f.startColumn,w=g.length,C=w>0?g[0].length:0;if(r){const R=Ns(u,f,d),$=R.maxRow-R.minRow+1,L=R.maxColumn-R.minColumn+1;m=R.minRow,b=R.minColumn,w=Math.min(w,$),C=Math.min(C,L)}let v=!1;const k=Math.min(h,m+w)-1,I=Math.min(_,b+C)-1,E=new Set;for(let R=m;R<=k;R++)for(let $=b;$<=I;$++){const L=u[R][$];E.has(L.cell.getKey())||L.cell.__rowSpan===1&&L.cell.__colSpan===1||(cu(L.cell),E.add(L.cell.getKey()),v=!0)}let[N]=at(l.getWritable(),null,null);const O=w-h+m;for(let R=0;R<O;R++)Ui(N[h-1][0].cell);const M=C-_+b;for(let R=0;R<M;R++)zi(N[0][_-1].cell,!0,!1);[N]=at(l.getWritable(),null,null);for(let R=m;R<m+w;R++)for(let $=b;$<b+C;$++){const L=R-m,A=$-b,B=g[L][A];if(B.startRow!==L||B.startColumn!==A)continue;const j=B.cell;if(j.__rowSpan!==1||j.__colSpan!==1){const H=[],ie=Math.min(R+j.__rowSpan,m+w)-1,Ne=Math.min($+j.__colSpan,b+C)-1;for(let Ce=R;Ce<=ie;Ce++)for(let ut=$;ut<=Ne;ut++){const Mn=N[Ce][ut];H.push(Mn.cell)}lu(H),v=!0}const{cell:U}=N[R][$],z=j.getBackgroundColor();z!=null&&U.setBackgroundColor(z);const K=U.getChildren();j.getChildren().forEach(H=>{oe(H)&&ne().append(H),U.append(H)}),K.forEach(H=>H.remove())}if(r&&v){const[R]=at(l.getWritable(),null,null);R[f.startRow][f.startColumn].cell.selectEnd()}return!0}function LC(n,e,t){const[r]=at(n,null,null);e>=0&&e<r.length||G(396,String(e));const o=r[e],s=t?te.ROW:te.NO_STATUS,i=new Set;for(let a=0;a<o.length;a++){const l=o[a];l!=null&&(i.has(l.cell)||(i.add(l.cell),l.cell.setHeaderStyles(s,te.ROW)))}}function OC(n,e,t){const[r]=at(n,null,null);r.length>0&&e>=0&&e<r[0].length||G(397,String(e));const o=t?te.COLUMN:te.NO_STATUS,s=new Set;for(let i=0;i<r.length;i++){const a=r[i][e];a!=null&&(s.has(a.cell)||(s.add(a.cell),a.cell.setHeaderStyles(o,te.COLUMN)))}}function Wa(n){const[[e,t,r,o],[s,i,a,l]]=["anchor","focus"].map(c=>{const u=n[c].getNode(),f=re(u,J);J(f)||G(238,c,u.getKey(),u.getType());const d=f.getParent();ce(d)||G(239,c);const g=d.getParent();return be(g)||G(240,c),[u,f,d,g]});return o.is(l)||G(241),{anchorCell:t,anchorNode:e,anchorRow:r,anchorTable:o,focusCell:i,focusNode:s,focusRow:a,focusTable:l}}class Vs{tableKey;anchor;focus;_cachedNodes;dirty;constructor(e,t,r){this.anchor=t,this.focus=r,t._selection=this,r._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){if(this.tableKey==="root"||this.anchor.key==="root"||this.anchor.type!=="element"||this.focus.key==="root"||this.focus.type!=="element")return!1;const e=Q(this.tableKey),t=Q(this.anchor.key),r=Q(this.focus.key);return e!==null&&t!==null&&r!==null}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return ae(e)&&this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus)}set(e,t,r){this.dirty=this.dirty||e!==this.tableKey||t!==this.anchor.key||r!==this.focus.key,this.tableKey=e,this.anchor.key=t,this.focus.key=r,this._cachedNodes=null}clone(){return new Vs(this.tableKey,un(this.anchor.key,this.anchor.offset,this.anchor.type),un(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){if(e==="")return;const t=(e.endsWith(`
9
+ `+ ++i);t.setAttribute("data-gutter",s)}function Xh(n,e,t,r){const{nodesCurrentlyHighlighting:o}=t,s=r.getKey();r.getLanguage()===void 0&&e.defaultLanguage!==null&&r.setLanguage(e.defaultLanguage);const i=r.getLanguage()||e.defaultLanguage;if(i){if(!g0(i))return r.getIsSyntaxHighlightSupported()&&r.setIsSyntaxHighlightSupported(!1),void p0();r.getIsSyntaxHighlightSupported()||r.setIsSyntaxHighlightSupported(!0)}else r.getIsSyntaxHighlightSupported()&&r.setIsSyntaxHighlightSupported(!1);o.has(s)||(o.add(s),t.didTransform||(t.didTransform=!0,uy(()=>{t.didTransform=!1,o.clear()})),(function(a,l){const c=Q(a);if(!je(c)||!c.isAttached())return;const u=D();if(!F(u))return void l();const f=u.anchor,d=f.offset,g=f.type==="element"&&ue(c.getChildAtIndex(f.offset-1));let h=0;if(!g){const _=f.getNode();h=d+_.getPreviousSiblings().reduce((m,b)=>m+b.getTextContentSize(),0)}if(l()){if(g)return void f.getNode().select(d,d);c.getChildren().some(_=>{const m=oe(_);if(m||ue(_)){const b=_.getTextContentSize();if(m&&b>=h)return _.select(h,h),!0;h-=b}return!1})}})(s,()=>{const a=Q(s);if(!je(a)||!a.isAttached())return!1;const l=a.getLanguage()||e.defaultLanguage,c=e.$tokenize(a,l??void 0),u=(function(h,_){let m=0;for(;m<h.length&&Yd(h[m],_[m]);)m++;const b=h.length,w=_.length,C=Math.min(b,w)-m;let v=0;for(;v<C;)if(v++,!Yd(h[b-v],_[w-v])){v--;break}const k=m,I=b-v,E=_.slice(m,w-v);return{from:k,nodesForReplacement:E,to:I}})(a.getChildren(),c),{from:f,to:d,nodesForReplacement:g}=u;return!(f===d&&!g.length)&&(r.splice(f,d-f,g),!0)}))}function Yd(n,e){return Ve(n)&&Ve(e)&&n.__text===e.__text&&n.__highlightType===e.__highlightType||bt(n)&&bt(e)||ue(n)&&ue(e)}function b0(n,e){const t=[];n._headless!==!0&&t.push(n.registerMutationListener(dn,o=>{n.read("latest",()=>{for(const[s,i]of o)if(i!=="destroyed"){const a=Q(s);a!==null&&m0(a,n)}})},{skipInitialization:!1}));const r={didTransform:!1,nodesCurrentlyHighlighting:new Set};return t.push(n.registerNodeTransform(dn,Xh.bind(null,n,e,r)),n.registerNodeTransform(cn,Vd.bind(null,n,e,r)),n.registerNodeTransform(Hs,Vd.bind(null,n,e,r))),de(...t)}function y0(n,e=_0){if(!n.hasNodes([dn,Hs]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");return de(b0(n,e),c0(n))}const w0=f0,x0=d0,C0=Yc,zl=Yc,S0=y0,v0={css:[()=>me(()=>import("./postcss-v_maFVrK.js").then(n=>n.p),[],import.meta.url)],html:[()=>me(()=>import("./html-DuSbEcJO.js").then(n=>n.h),[],import.meta.url)],js:[()=>me(()=>import("./babel-CWCo1FDM.js").then(n=>n.b),[],import.meta.url),()=>me(()=>import("./estree-C_HWBWad.js"),[],import.meta.url)],markdown:[()=>me(()=>import("./markdown-Bf4-A1yl.js").then(n=>n.m),[],import.meta.url)],typescript:[()=>me(()=>import("./typescript-DNMQUFQg.js").then(n=>n.t),[],import.meta.url),()=>me(()=>import("./estree-C_HWBWad.js"),[],import.meta.url)]};async function k0(n){const e=v0[n];return await Promise.all(e.map(r=>r()))}async function T0(){const{format:n}=await me(async()=>{const{format:e}=await import("./standalone-DyCMuq_1.js");return{format:e}},[],import.meta.url);return n}const Zh={css:{parser:"css"},html:{parser:"html"},js:{parser:"babel"},markdown:{parser:"markdown"},typescript:{parser:"typescript"}},I0=Object.keys(Zh);function E0(n){return I0.includes(n)}function N0(n){const e=Zh[n];if(!e)throw new Error(`CodeActionMenuPlugin: Prettier does not support this language: ${n}`);return e}function L0({lang:n,editor:e,getCodeDOMNode:t}){const[r,o]=S.useState(""),[s,i]=S.useState(!1);async function a(){const f=t();if(!f)return;let d="";if(e.update(()=>{const g=Ae(f);je(g)&&(d=g.getTextContent())}),d!=="")try{const g=await T0(),h=N0(n),_=await k0(n);h.plugins=_.map(b=>b.default||b);const m=await g(d,h);e.update(()=>{const b=Ae(f);je(b)&&(b.select(0).insertText(m),o(""),i(!1))})}catch(g){l(g)}}function l(f){f instanceof Error?(o(f.message),i(!0)):console.error("Unexpected error: ",f)}function c(){r!==""&&i(!0)}function u(){r!==""&&i(!1)}return x.jsxs(Y,{sx:{position:"relative",display:"inline-flex"},children:[x.jsx(Ft,{icon:r?Fp:br,size:"small",variant:"invisible",onClick:a,onMouseEnter:c,onMouseLeave:u,"aria-label":"prettier",sx:r?{color:"var(--fgColor-danger)"}:void 0}),s?x.jsx(Y,{as:"pre",sx:{position:"absolute",top:"100%",left:0,zIndex:10,p:2,mt:1,fontSize:0,bg:"var(--bgColor-danger-muted)",color:"var(--fgColor-danger)",borderRadius:2,borderWidth:1,borderStyle:"solid",borderColor:"var(--bgColor-danger-muted)",maxWidth:"300px",whiteSpace:"pre-wrap"},children:r}):null]})}const Kl=({label:n,value:e,onChange:t,placeholder:r="","data-test-id":o})=>x.jsxs(Mt,{children:[x.jsx(Mt.Label,{children:n}),x.jsx(vn,{type:"text",placeholder:r,value:e,onChange:s=>{t(s.target.value)},"data-test-id":o,block:!0})]}),Qh=S.createContext(void 0),TM=({children:n})=>{const[e,t]=S.useState(!1),r=()=>t(o=>!o);return x.jsx(Qh.Provider,{value:{showComments:e,toggleComments:r,setShowComments:t},children:n})},e_=()=>{const n=S.useContext(Qh);if(!n)throw new Error("useComments must be used within CommentsProvider");return n},O0=S.createContext({});function R0(){return S.useContext(O0)}const Gc=S.createContext(void 0);function A0(){const n=S.useContext(Gc);if(!n)throw new Error("useLexicalConfig must be used within a LexicalConfigProvider");return n}function M0(){return S.useContext(Gc)}function IM({lexicalId:n,serviceManager:e,children:t}){return x.jsx(Gc.Provider,{value:{lexicalId:n,serviceManager:e},children:t})}const $0=S.createContext({});function D0(){return S.useContext($0)}const Gd=window.location.hostname,P0=Gd!=="playground.lexical.dev"&&Gd!=="lexical-playground.vercel.app",t_={disableBeforeInput:!1,emptyEditor:P0,hasLinkAttributes:!1,isAutocomplete:!1,isCharLimit:!1,isCharLimitUtf8:!1,isCodeHighlighted:!0,isCodeShiki:!1,isCollab:!1,isMaxLength:!1,isRichText:!0,listStrictIndent:!1,measureTypingPerf:!1,selectionAlwaysOnDisplay:!1,shouldAllowHighlightingWithBrackets:!1,shouldPreserveNewLinesInMarkdown:!1,shouldUseLexicalContextMenu:!1,showNestedEditorTreeView:!1,showTableOfContents:!1,showTreeView:!0,tableCellBackgroundColor:!0,tableCellMerge:!0,tableHorizontalScroll:!0},n_={...t_},r_=S.createContext({setOption:(n,e)=>{},settings:n_}),EM=({children:n})=>{const[e,t]=S.useState(n_),r=S.useCallback((s,i)=>{t(a=>({...a,[s]:i})),F0(s,i)},[]),o=S.useMemo(()=>({setOption:r,settings:e}),[r,e]);return x.jsx(r_.Provider,{value:o,children:n})},j0=()=>S.useContext(r_);function F0(n,e){const t=new URL(window.location.href),r=new URLSearchParams(t.search);e!==t_[n]?r.set(n,String(e)):r.delete(n),t.search=r.toString(),window.history.pushState(null,"",t.toString())}const Fa=8,Ba=72,Wl=15,Ua={bullet:"Bulleted List",check:"Check List",code:"Code Block",h1:"Heading 1",h2:"Heading 2",h3:"Heading 3",h4:"Heading 4",h5:"Heading 5",h6:"Heading 6",number:"Numbered List",paragraph:"Normal",quote:"Quote"},B0={bgColor:"#fff",blockType:"paragraph",canRedo:!1,canUndo:!1,codeLanguage:"",codeTheme:"",elementFormat:"left",fontColor:"#000",fontFamily:"Arial",fontSize:`${Wl}px`,fontSizeInputValue:`${Wl}`,isBold:!1,isCode:!1,isHighlight:!1,isImageCaption:!1,isItalic:!1,isLink:!1,isRTL:!1,isStrikethrough:!1,isSubscript:!1,isSuperscript:!1,isUnderline:!1,isLowercase:!1,isUppercase:!1,isCapitalize:!1,rootType:"root",listStartNumber:null},o_=S.createContext(void 0),NM=({children:n})=>{const[e,t]=S.useState(B0),r=e.fontSize,o=S.useCallback((i,a)=>{t(l=>({...l,[i]:a}))},[]);S.useEffect(()=>{o("fontSizeInputValue",r.slice(0,-2))},[r,o]);const s=S.useMemo(()=>({toolbarState:e,updateToolbarState:o}),[e,o]);return x.jsx(o_.Provider,{value:s,children:n})},U0=()=>{const n=S.useContext(o_);if(n===void 0)throw new Error("useToolbarState must be used within a ToolbarProvider");return n},z0=Ye({$import:(n,e)=>{const t=fn(e.nodeName.toLowerCase());return Bs(e,t),rr(t,e),mn(t,e),[t.splice(0,0,n.$importChildren(e))]},match:Ge.tag("h1","h2","h3","h4","h5","h6"),name:"@lexical/rich-text/heading"}),K0=Ye({$import:(n,e)=>{const t=Ln();return rr(t,e),Bs(e,t),mn(t,e),[t.splice(0,0,n.$importChildren(e))]},match:Ge.tag("blockquote"),name:"@lexical/rich-text/blockquote"});Ge.tag("blockquote");const W0=[z0,K0,Ye({$import:(n,e,t)=>{const r=e.firstChild;return r&&ke(o=r)&&o.nodeName==="SPAN"&&o.style.fontSize==="26pt"?n.$importChildren(e):t();var o},match:Ge.tag("p"),name:"@lexical/rich-text/google-docs-title-p"}),Ye({$import:(n,e,t)=>e.style.fontSize!=="26pt"?t():[fn("h1").splice(0,0,n.$importChildren(e))],match:Ge.tag("span"),name:"@lexical/rich-text/google-docs-title-span"})];function H0(n,e){return n&&e!==null?Eo(n,e):e}const s_=pe({build:(n,e)=>nr(e),config:tr({escapeFormatTriggers:{capitalize:{enter:!0,space:!0,tab:!0},lowercase:{enter:!0,space:!0,tab:!0},uppercase:{enter:!0,space:!0,tab:!0}}}),conflictsWith:["@lexical/plain-text"],dependencies:[dy,fy,gy,js,ln(Fs,{rules:W0})],mergeConfig:function(n,e){const t=Eo(n,e);return e.escapeFormatTriggers&&(t.escapeFormatTriggers=(function(r,o){const s=Eo(r,o);for(const i of Object.keys(o))s[i]=H0(r[i],o[i]);return s})(n.escapeFormatTriggers,e.escapeFormatTriggers)),t},name:"@lexical/rich-text",nodes:()=>[qs,Js],register:(n,e,t)=>zt(()=>i_(n,t.getOutput().escapeFormatTriggers))}),Xd=he("DRAG_DROP_PASTE_FILE"),za=Us("shadowRoot",{parse:Boolean});let Js=class extends Oe{$config(){return this.config("quote",{extends:Oe,importDOM:{blockquote:()=>({conversion:J0,priority:0})},stateConfigs:[{flat:!0,stateConfig:za}]})}isShadowRoot(){return Cs(this,za)}setIsShadowRoot(e){return xn(this,za,e)}createDOM(e){const t=Je().createElement("blockquote");return Ie(t,e.theme.quote),t}updateDOM(e,t,r){return!1}exportDOM(e){const{element:t}=super.exportDOM(e);if(ke(t)){this.isEmpty()&&t.append(Je().createElement("br"));const r=this.getFormatType();r&&(t.style.textAlign=r);const o=this.getDirection();o&&(t.dir=o)}return{element:t}}exportJSON(){return super.exportJSON()}static importJSON(e){return Ln().updateFromJSON(e)}insertNewAfter(e,t){const r=ne(),o=this.getDirection();return r.setDirection(o),this.insertAfter(r,t),r}collapseAtStart(){if(this.isShadowRoot()){for(const t of this.getChildren())this.insertBefore(t);return this.remove(),!0}const e=ne();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}canMergeWhenEmpty(){return!0}};function Ln(n){const e=Ot(new Js);return n&&n.shadowRoot?e.setIsShadowRoot(!0):e}function Vn(n){return n instanceof Js}let qs=class extends Oe{__tag;$config(){return this.config("heading",{extends:Oe,importDOM:{h1:()=>({conversion:to,priority:0}),h2:()=>({conversion:to,priority:0}),h3:()=>({conversion:to,priority:0}),h4:()=>({conversion:to,priority:0}),h5:()=>({conversion:to,priority:0}),h6:()=>({conversion:to,priority:0}),p:e=>{const t=e.firstChild;return t!==null&&Zd(t)?{conversion:()=>({node:null}),priority:3}:null},span:e=>Zd(e)?{conversion:()=>({node:fn("h1")}),priority:3}:null}})}afterCloneFrom(e){super.afterCloneFrom(e),this.__tag=e.__tag}constructor(e="h1",t){super(t),this.__tag=e}getTag(){return this.getLatest().__tag}setTag(e){const t=this.getWritable();return t.__tag=e,t}createDOM(e){const t=this.__tag,r=Je().createElement(t),o=e.theme.heading;if(o!==void 0){const s=o[t];Ie(r,s)}return r}updateDOM(e,t,r){return e.__tag!==this.__tag}exportDOM(e){const{element:t}=super.exportDOM(e);if(ke(t)){this.isEmpty()&&t.append(Je().createElement("br"));const r=this.getFormatType();r&&(t.style.textAlign=r);const o=this.getDirection();o&&(t.dir=o)}return{element:t}}updateFromJSON(e){return super.updateFromJSON(e).setTag(e.tag)}exportJSON(){return{...super.exportJSON(),tag:this.getTag()}}insertNewAfter(e,t=!0){const r=e?e.anchor.offset:0,o=this.getLastDescendant(),s=!o||e&&e.anchor.key===o.getKey()&&r===o.getTextContentSize()||!e?ne():fn(this.getTag()),i=this.getDirection();if(s.setDirection(i),this.insertAfter(s,t),r===0&&!this.isEmpty()&&e){const a=ne();a.select(),this.replace(a,!0)}return s}collapseAtStart(){if(this.isEmpty()){const e=ne();this.getChildren().forEach(t=>e.append(t)),this.replace(e)}return!0}extractWithChild(){return!0}};function Zd(n){return n.nodeName.toLowerCase()==="span"&&n.style.fontSize==="26pt"}function to(n){const e=n.nodeName.toLowerCase();let t=null;return e!=="h1"&&e!=="h2"&&e!=="h3"&&e!=="h4"&&e!=="h5"&&e!=="h6"||(t=fn(e),Bs(n,t),rr(t,n),mn(t,n)),{node:t}}function J0(n){const e=Ln();return rr(e,n),Bs(n,e),mn(e,n),{node:e}}function fn(n="h1"){return Ot(new qs(n))}function Wr(n){return n instanceof qs}function Qd(n){const e=Ae(n);return It(e)}function no(n,e,t,r){let o=!1,s=null;if(n.isCollapsed()&&n.anchor.type==="text"){const a=n.anchor.getNode();if(oe(a)){s=a;const l=n.anchor.offset,c=l===a.getTextContentSize()&&a.getNextSibling()===null,u=l===0&&a.getPreviousSibling()===null;o=t==="end"&&c||t==="start"&&u||t==="both"&&(c||u)}}let i=!1;for(const[a,l]of Object.entries(r)){if(l==null||!l[e])continue;const c=a;if(l.onlyAtBoundary){if(!(o&&s&&oe(s)&&s.hasFormat(c)))continue;i=!0}n.hasFormat(c)&&n.toggleFormat(c)}i&&n.setStyle("")}const q0={capitalize:{enter:!0,space:!0,tab:!0},lowercase:{enter:!0,space:!0,tab:!0},uppercase:{enter:!0,space:!0,tab:!0}};function si(n,e){return(function(t,r){if(!t.isCollapsed())return!1;const o=vs(t.focus,r),s=re(o.origin,Ra);if(!s)return!1;const i=t.focus.getNode();if(!s.is(i)&&!Xp(i,s))return!1;const a=mi(o,gt(s,r));if(a.getTextSlices().some(f=>f&&f.getTextContentSize()>0))return!1;const l=mi(a.anchor.getSiblingCaret(),a.focus);let c=l.anchor.origin;for(const f of l){if(!Mc(f)||!f.origin.is(c.getParent()))return!1;c=f.origin}let u=s;for(const f of Ll(gt(s,r))){if(!f.origin.is(u.getParent())){if(Ey(f.origin)){const d=gt(u,r);return Ri(mi(d,d)),!0}break}if(!Ra(f.origin))break;u=f.origin}return!1})(n,e)||(function(t,r){if(!t.isCollapsed()||t.anchor.type!=="element")return!1;const o=vs(t.anchor,r).getNodeAtCaret();return!(!Ra(o)||o.isInline()||(Ri(Gp(Jn(Er(o,r)))),0))})(n,e)}function ef(n){return It(n)&&!n.isInline()&&!n.isIsolated()&&n.isKeyboardSelectable()}function ii(n){const e=aa();e.add(n),Ee(e)}function tf(n,e){if(!n.isCollapsed())return!1;const t=n.focus,r=t.getNode(),o=e?"previous":"next",s=vs(t,o);if(t.type==="element"&&q(r)&&wt(r)){const b=s.getNodeAtCaret();return!(b===null||!ef(b))&&(ii(b.__key),!0)}const i=re(q(r)?r:r.getParentOrThrow(),b=>q(b)&&!b.isInline()&&wt(b.getParent()));if(i===null)return!1;const a=gt(i,o).getNodeAtCaret();if(a===null||!ef(a))return!1;if(i.getTextContentSize()===0)return ii(a.__key),!0;const l=zo().getRootElement();if(l===null)return!1;const c=or(l.ownerDocument.defaultView);if(c===null||c.rangeCount===0)return!1;const u=c.anchorNode,f=c.anchorOffset,d=c.focusNode,g=c.focusOffset;c.modify("move",e?"backward":"forward","line");const h=c.anchorNode,_=c.anchorOffset;if(h===null)return nf(c,u,f,d,g),!1;const m=Ae(h);return nf(c,u,f,d,g),m===null?!1:(h===u&&_===f||!m.is(i)&&!Xp(m,i))&&(ii(a.__key),!0)}function nf(n,e,t,r,o){e!==null&&r!==null&&n.setBaseAndExtent(e,t,r,o)}function rf(n,e){if(!n.isCollapsed())return!1;const t=n.focus.getNode(),r=re(q(t)?t:t.getParentOrThrow(),m=>q(m)&&!m.isInline());if(r===null)return!1;const o=zo(),s=o.getRootElement();if(s===null)return!1;const i=s.ownerDocument.defaultView;if(i===null)return!1;let a=!1;for(const m of r.getChildren())if(q(m)&&m.isInline()){const b=o.getElementByKey(m.getKey());if(b!==null){const w=i.getComputedStyle(b).display;if(w==="inline-grid"||w==="inline-flex"){a=!0;break}}}if(!a)return!1;const l=gt(r,e?"previous":"next").getNodeAtCaret();if(l===null||!q(l)){if(e){const m=r.getFirstDescendant();oe(m)?m.select(0,0):r.select(0,0)}else{const m=r.getLastDescendant();if(oe(m)){const b=m.getTextContentSize();m.select(b,b)}else{const b=r.getChildrenSize();r.select(b,b)}}return!0}const c=o.getElementByKey(l.getKey());if(c===null)return!1;const u=or(i);if(u===null||u.rangeCount===0)return!1;const f=u.getRangeAt(0).cloneRange();f.collapse(!0);const d=f.getBoundingClientRect(),g=c.getBoundingClientRect(),h=g.top+g.height/2;if(d.height>0){const m=El(d.left,h,s);if(m!==null&&c.contains(m.node)){const b=s.ownerDocument.createRange();return b.setStart(m.node,m.offset),b.collapse(!0),n.applyDOMRange(b),n.dirty=!0,!0}}const _=e?l.getLastDescendant():l.getFirstDescendant();if(oe(_)){const m=e?_.getTextContentSize():0;_.select(m,m)}else{const m=l.getChildrenSize();l.select(e?m:0,e?m:0)}return!0}function ai(n,e){const t=gt(n,e),r=t.getAdjacentCaret();r!==null&&q(r.origin)&&!r.origin.isInline()&&r.origin.isShadowRoot()?Ri(Gp(t)):e==="next"?n.selectNext(0,0):n.selectPrevious()}function of(n,e,t){t.preventDefault(),t.stopPropagation();const r=n.getNodes();if(r.length===0)return!0;const o=r.map(l=>gt(l,"next")).sort(Iy),s=(e?o[0]:o[o.length-1]).origin,i=re(s,l=>l!==s&&q(l)&&!l.isInline())??se(),a=e?0:i.getChildrenSize();return i.select(a,a),!0}function i_(n,e=Ac(q0)){return de(n.registerCommand(Ks,()=>{const t=D();return ve(t)?(t.clear(),!0):(F(t)&&no(t,"click","both",e.peek()),!1)},V),n.registerCommand(bi,t=>{const r=D();return F(r)?(r.deleteCharacter(t),!0):!!ve(r)&&(r.deleteNodes(),!0)},V),n.registerCommand(Yp,t=>{const r=D();return!!F(r)&&(r.deleteWord(t),!0)},V),n.registerCommand(Vp,t=>{const r=D();return!!F(r)&&(r.deleteLine(t),!0)},V),n.registerCommand(qp,t=>{const r=D();if(typeof t=="string")r!==null&&r.insertText(t);else{if(r===null)return!1;const o=t.dataTransfer;if(o!=null)wd(o,r);else if(F(r)){const s=t.data;return s&&r.insertText(s),!0}}return!0},V),n.registerCommand(Ty,()=>{const t=D();return!!F(t)&&(t.removeText(),!0)},V),n.registerCommand(Xe,t=>{const r=D();return!(!F(r)&&!ve(r))&&(ky(r,t),!0)},V),n.registerCommand(Sy,t=>{const r=D();return!(!F(r)&&!ve(r))&&(vy(r,t),!0)},V),n.registerCommand(Bn,t=>{const r=D();if(!F(r)&&!ve(r))return!1;const o=r.getNodes();for(const s of o){const i=re(s,a=>q(a)&&!a.isInline());i!==null&&i.setFormat(t)}return!0},V),n.registerCommand(Nl,t=>{const r=D();return!!F(r)&&(r.insertLineBreak(t),!0)},V),n.registerCommand(Lo,()=>{const t=D();return!!F(t)&&(t.insertParagraph(),!0)},V),n.registerCommand(Tl,()=>{const t=Kn(),r=D();return F(r)&&(t.setFormat(r.format),t.setStyle(r.style)),Tr([t]),!0},V),n.registerCommand(Dt,()=>kd(t=>{const r=t.getIndent();t.setIndent(r+1)}),V),n.registerCommand(wn,()=>kd(t=>{const r=t.getIndent();r>0&&t.setIndent(Math.max(0,r-1))}),V),n.registerCommand(pt,t=>{const r=D();if(ve(r)){const o=r.getNodes();if(o.length>0)return t.preventDefault(),ai(o[0],"previous"),!0}else if(F(r)&&((function(o){const s=o.focus;return s.key==="root"&&s.offset===0})(r)||!t.shiftKey&&si(r,"previous")||!t.shiftKey&&tf(r,!0)||!t.shiftKey&&rf(r,!0)))return t.preventDefault(),!0;return!1},V),n.registerCommand(Vt,t=>{const r=D();if(ve(r)){const o=r.getNodes();if(o.length>0)return t.preventDefault(),ai(o[0],"next"),!0}else if(F(r)&&((function(o){const s=o.focus;return s.key==="root"&&s.offset===se().getChildrenSize()})(r)||!t.shiftKey&&si(r,"next")||!t.shiftKey&&tf(r,!1)||!t.shiftKey&&rf(r,!1)))return t.preventDefault(),!0;return!1},V),n.registerCommand(zs,t=>{const r=D();if(ve(r)){const o=r.getNodes();if(o.length>0)return t.preventDefault(),ai(o[0],Qs(o[0])?"next":"previous"),!0}if(!F(r))return!1;if(!t.shiftKey&&si(r,Qs(r.anchor.getNode())?"next":"previous"))return t.preventDefault(),!0;if(t.shiftKey||no(r,"arrow","start",e.peek()),Sd(r,!0)){const o=t.shiftKey;return t.preventDefault(),vd(r,o,!0),!0}return!1},V),n.registerCommand(ia,t=>{const r=D();if(ve(r)){const o=r.getNodes();if(o.length>0)return t.preventDefault(),ai(o[0],Qs(o[0])?"previous":"next"),!0}if(!F(r))return!1;if(!t.shiftKey&&si(r,Qs(r.anchor.getNode())?"previous":"next"))return t.preventDefault(),!0;if(t.shiftKey||no(r,"arrow","end",e.peek()),Sd(r,!1)){const o=t.shiftKey;return t.preventDefault(),vd(r,o,!1),!0}return!1},V),n.registerCommand(sa,t=>{const r=D();if(!ve(r)&&Qd(t.target))return!1;if(F(r)){if((function(o){if(!o.isCollapsed())return!1;const{anchor:s}=o;if(s.offset!==0)return!1;const i=s.getNode();if(Jp(i))return!1;const a=Rc(i);return a.getIndent()>0&&(a.is(i)||i.is(a.getFirstDescendant()))})(r))return t.preventDefault(),n.dispatchCommand(wn);if(xd&&Cd)return!1}else if(!ve(r))return!1;return t.preventDefault(),n.dispatchCommand(bi,!0)},V),n.registerCommand(Oc,t=>{const r=D();return!(!ve(r)&&Qd(t.target))&&!(!F(r)&&!ve(r))&&(t.preventDefault(),n.dispatchCommand(bi,!1))},V),n.registerCommand(zr,t=>{let r=D();if(ve(r)){const o=r.getNodes();o.length===1&&It(o[0])&&!o[0].isInline()&&(r=o[0].selectNext())}if(!F(r))return!1;if(no(r,"enter","both",e.peek()),t!==null){if((xd||xy||Cy)&&Cd)return!1;if(t.preventDefault(),t.shiftKey)return n.dispatchCommand(Nl,!1)}return n.dispatchCommand(Lo)},V),n.registerCommand(Nn,()=>{const t=D();return!!F(t)&&(n.blur(),!0)},V),n.registerCommand(Lc,t=>{const[,r]=uo(t);if(r.length>0){const o=t.clientX,s=t.clientY,i=El(o,s,n.getRootElement());if(i!==null){const{offset:a,node:l}=i,c=Ae(l);if(c!==null){const u=kr();if(oe(c))u.anchor.set(c.getKey(),a,"text"),u.focus.set(c.getKey(),a,"text");else{const d=c.getParentOrThrow().getKey(),g=c.getIndexWithinParent()+1;u.anchor.set(d,g,"element"),u.focus.set(d,g,"element")}const f=Ss(u);Ee(f)}n.dispatchCommand(Xd,r)}return t.preventDefault(),!0}return wy(t,n)},V),n.registerCommand(Wp,t=>{const[r]=uo(t),o=D();return!(r&&!F(o))&&(F(o)&&!o.isCollapsed()&&t.dataTransfer!==null&&(by(t.dataTransfer,Hp(o)),yy(t.dataTransfer,n)),!0)},V),n.registerCommand(Nc,t=>{const[r]=uo(t),o=D();if(r&&!F(o))return!1;const s=t.clientX,i=t.clientY,a=El(s,i,n.getRootElement());if(a!==null){const l=Ae(a.node);It(l)&&t.preventDefault()}return!0},V),n.registerCommand(Ec,()=>{const t=D();return _y(F(t)&&my(t.anchor.getNode())!==null?t:null),!0},V),n.registerCommand(Kp,t=>(Il(n,fo(t,ClipboardEvent)?t:null),!0),V),n.registerCommand(zp,t=>((async function(r,o){await Il(o,fo(r,ClipboardEvent)?r:null),o.update(()=>{const s=D();F(s)?s.removeText():ve(s)&&s.getNodes().forEach(i=>i.remove())},{tag:hy})})(t,n),!0),V),n.registerCommand(Ic,t=>{const[,r,o]=uo(t);return r.length>0&&!o?(n.dispatchCommand(Xd,r),!0):No(t.target)&&py(t.target)?!1:D()!==null&&((function(s,i){s.preventDefault(),i.update(()=>{const a=D(),l=fo(s,InputEvent)||fo(s,KeyboardEvent)?null:s.clipboardData;l!=null&&a!==null&&wd(l,a)},{tag:Up})})(t,n),!0)},V),n.registerCommand(Bp,()=>{const t=D();return F(t)&&no(t,"space","both",e.peek()),!1},V),n.registerCommand(Kr,()=>{const t=D();return F(t)&&no(t,"tab","both",e.peek()),!1},V),n.registerCommand(xs,t=>{const r=D();if(ve(r))return of(r,!1,t);if(!F(r))return!1;const{anchor:o}=r;if(o.type!=="element"||o.offset!==0)return!1;const s=o.getNode();if(!q(s))return!1;const i=s.getFirstChild();if(!It(i)||!i.isInline())return!1;const a=s.getKey(),l=s.selectEnd();return t.shiftKey&&l.anchor.set(a,0,"element"),t.preventDefault(),t.stopPropagation(),!0},V),n.registerCommand(Ir,t=>{const r=D();if(ve(r))return of(r,!0,t);if(!F(r))return!1;const{anchor:o,focus:s}=r,i=re(s.getNode(),c=>q(c)&&!c.isInline());if(i===null)return!1;const a=i.getFirstChild();if(!It(a)||!a.isInline()||re(o.getNode(),c=>q(c)&&!c.isInline())!==i)return!1;const l=i.getKey();return(s.type!=="element"||s.key!==l||s.offset!==0)&&(r.focus.set(l,0,"element"),t.shiftKey||r.anchor.set(l,0,"element"),t.preventDefault(),t.stopPropagation(),!0)},V))}function jn(n,...e){const t=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",n);for(const o of e)r.append("v",o);throw t.search=r.toString(),Error(`Minified Lexical error #${n}; visit ${t.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function Is(n){let e=1,t=n.getParent();for(;t!=null;){if(le(t)){const r=t.getParent();if(Z(r)){e++,t=r.getParent();continue}jn(40)}return e}return e}function Hl(n){const e=n.getParent();Z(e)||jn(40);let t=e,r=e;for(;r!==null;)r=r.getParent(),Z(r)&&(t=r);return t}function a_(n){let e=[];const t=n.getChildren().filter(le);for(let r=0;r<t.length;r++){const o=t[r],s=o.getFirstChild();Z(s)?e=e.concat(a_(s)):e.push(o)}return e}function Rt(n){return le(n)&&Z(n.getFirstChild())}function l_(n,e){return le(n)&&(e.length===0||e.length===1&&n.is(e[0])&&n.getChildrenSize()===0)}function Jl(n){const e=D();if(e!==null){let t=e.getNodes();if(F(e)){const[o]=e.getStartEndPoints(),s=o.getNode(),i=s.getParent();if(wt(s)){const a=s.getFirstChild();if(a)t=a.selectStart().getNodes();else{const l=ne();s.append(l),t=l.select().getNodes()}}else if(l_(s,t)){const a=Et(n);if(wt(i)){s.replace(a);const l=xt();q(s)&&(l.setFormat(s.getFormatType()),l.setIndent(s.getIndent())),a.append(l)}else if(le(s)){const l=s.getParentOrThrow();Nr(a,l.getChildren()),l.replace(a)}return}}const r=new Set;for(let o=0;o<t.length;o++){const s=t[o];if(q(s)&&s.isEmpty()&&!le(s)&&!r.has(s.getKey())){sf(s,n);continue}let i=Qp(s)?s.getParent():le(s)&&s.isEmpty()?s:null;for(;i!=null;){const a=i.getKey();if(Z(i)){if(!r.has(a)){const l=Et(n);Nr(l,i.getChildren()),i.replace(l),r.add(a)}break}{const l=i.getParent();if(wt(l)&&!r.has(a)){r.add(a),sf(i,n);break}i=l}}}}}function Nr(n,e){n.splice(n.getChildrenSize(),0,e)}function sf(n,e){if(Z(n))return n;const t=n.getPreviousSibling(),r=n.getNextSibling(),o=xt();let s;if(Nr(o,n.getChildren()),Z(t)&&e===t.getListType())t.append(o),Z(r)&&e===r.getListType()&&(Nr(t,r.getChildren()),r.remove()),s=t;else if(Z(r)&&e===r.getListType())r.getFirstChildOrThrow().insertBefore(o),s=r;else{const a=Et(e);a.append(o),n.replace(a),s=a}o.setFormat(n.getFormatType()),o.setIndent(n.getIndent());const i=D();return F(i)&&(s.getKey()===i.anchor.key&&i.anchor.set(o.getKey(),i.anchor.offset,"element"),s.getKey()===i.focus.key&&i.focus.set(o.getKey(),i.focus.offset,"element")),n.remove(),s}function Xc(n,e){const t=n.getLastChild(),r=e.getFirstChild();t&&r&&Rt(t)&&Rt(r)&&(Xc(t.getFirstChild(),r.getFirstChild()),r.remove());const o=e.getChildren();o.length>0&&n.append(...o),e.remove()}function V0(){const n=D();if(F(n)){const e=new Set,t=n.getNodes(),r=n.anchor.getNode();if(l_(r,t))e.add(Hl(r));else for(let o=0;o<t.length;o++){const s=t[o];if(Qp(s)){const i=Ol(s,bn);i!=null&&e.add(Hl(i))}}for(const o of e){let s=o;const i=a_(o);for(const a of i){const l=ne().setTextStyle(n.style).setTextFormat(n.format);Nr(l,a.getChildren()),s.insertAfter(l),s=l,a.__key===n.anchor.key&&hr(n.anchor,Jn(Er(l,"next"))),a.__key===n.focus.key&&hr(n.focus,Jn(Er(l,"next"))),a.remove()}o.remove()}}}function c_(n){const e=n.getListType()!=="check";let t=n.getStart();for(const r of n.getChildren())le(r)&&(r.getValue()!==t&&r.setValue(t),e&&r.getLatest().__checked!=null&&r.setChecked(void 0),Z(r.getFirstChild())||t++)}function Y0(n){const e=new Set;if(Rt(n)||e.has(n.getKey()))return;const t=n.getParent(),r=n.getNextSibling(),o=n.getPreviousSibling();if(Rt(r)&&Rt(o)){const s=o.getFirstChild();if(Z(s)){s.append(n);const i=r.getFirstChild();Z(i)&&(Nr(s,i.getChildren()),r.remove(),e.add(r.getKey()))}}else if(Rt(r)){const s=r.getFirstChild();if(Z(s)){const i=s.getFirstChild();i!==null&&i.insertBefore(n)}}else if(Rt(o)){const s=o.getFirstChild();Z(s)&&s.append(n)}else if(Z(t)){const s=it(n),i=it(t);s.append(i),i.append(n),o?o.insertAfter(s):r?r.insertBefore(s):t.append(s)}}function af(n){if(Rt(n))return;const e=n.getParent(),t=e?e.getParent():void 0;if(Z(t?t.getParent():void 0)&&le(t)&&Z(e)){const r=e?e.getFirstChild():void 0,o=e?e.getLastChild():void 0;if(n.is(r))t.insertBefore(n),e.isEmpty()&&t.remove();else if(n.is(o))t.insertAfter(n),e.isEmpty()&&t.remove();else{const s=it(n),i=it(e);s.append(i),n.getPreviousSiblings().forEach(c=>i.append(c));const a=it(n),l=it(e);a.append(l),Nr(l,n.getNextSiblings()),t.insertBefore(s),t.insertAfter(a),t.replace(n)}}}function G0(n=!1){const e=D();if(!F(e)||!e.isCollapsed())return!1;const t=e.anchor.getNode();let r=null;if(le(t)&&t.getChildrenSize()===0)r=t;else if(oe(t)){const c=t.getParent();le(c)&&c.getChildren().every(u=>oe(u)&&u.getTextContent().trim()==="")&&(r=c)}if(r===null)return!1;const o=Hl(r),s=r.getParent();Z(s)||jn(40);const i=s.getParent();let a;if(wt(i))a=ne(),o.insertAfter(a);else{if(!le(i))return!1;a=it(i),i.insertAfter(a)}a.setTextStyle(e.style).setTextFormat(e.format).select();const l=r.getNextSiblings();if(l.length>0){const c=n?(function(f,d){return f.getStart()+d.getIndexWithinParent()})(s,r):1,u=it(s).setStart(c);if(le(a)){const f=it(a);f.append(u),a.insertAfter(f)}else a.insertAfter(u);u.append(...l)}return(function(c){let u=c;for(;u.getNextSibling()==null&&u.getPreviousSibling()==null;){const f=u.getParent();if(f==null||!le(f)&&!Z(f))break;u=f}u.remove()})(r),!0}let bn=class extends Oe{__value;__checked;$config(){return this.config("listitem",{$transform:e=>{const t=e.getParent();if(Z(t))t.getListType()!=="check"&&e.getChecked()!=null&&e.setChecked(void 0);else if(t){const r=e.createParentElementNode();Z(r)||jn(340);const o=[e];for(const s of["previous","next"]){o.reverse();for(const{origin:i}of gt(e,s)){if(!le(i))break;o.push(i)}}e.insertBefore(r),r.splice(0,0,o),wt(t)||(Zp(r,Dc(gt(r,"next")),{$shouldSplit:()=>!1,removeEmptyDestination:!0}),t.isEmpty()&&t.isAttached()&&t.remove())}},extends:Oe,importDOM:$c({li:()=>({conversion:X0,priority:0})})})}constructor(e=1,t=void 0,r){super(r),this.__value=e===void 0?1:e,this.__checked=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__value=e.__value,this.__checked=e.__checked}createDOM(e){const t=Je().createElement("li");return this.updateListItemDOM(null,t,e),t}updateListItemDOM(e,t,r){(function(i,a){const l=a.getParent();!Z(l)||l.getListType()!=="check"||Z(a.getFirstChild())?(i.removeAttribute("role"),i.removeAttribute("tabIndex"),i.removeAttribute("aria-checked")):(i.setAttribute("role","checkbox"),i.setAttribute("tabIndex","-1"),i.setAttribute("aria-checked",a.getChecked()?"true":"false"))})(t,this),t.value=this.__value,(function(i,a,l){const c=a.list;if(!c)return;const u=c.listitem,f=c.nested&&c.nested.listitem,d=l.getParent(),g=Z(d)&&d.getListType()==="check",h=l.getChecked(),_=l.getChildren().some(w=>Z(w)),m=[];c.listitemChecked!==void 0&&m.push(c.listitemChecked),c.listitemUnchecked!==void 0&&m.push(c.listitemUnchecked),f!==void 0&&m.push(...ps(f)),m.length>0&&$t(i,...m);const b=[];if(u!==void 0&&b.push(...ps(u)),g){const w=h?c.listitemChecked:c.listitemUnchecked;w!==void 0&&b.push(w)}f!==void 0&&_&&b.push(...ps(f)),b.length>0&&Ie(i,...b)})(t,r.theme,this);const o=e?e.__style:"",s=this.__style;o!==s&&_o(t.style,s,o),(function(i,a,l){const c=a.__textStyle,u=l?l.__textStyle:"";if(l!==null&&u===c)return;const f=Td(c);for(const d in f)i.style.setProperty(`--listitem-marker-${d}`,f[d]);if(u!=="")for(const d in Td(u))d in f||i.style.removeProperty(`--listitem-marker-${d}`)})(t,this,e)}updateDOM(e,t,r){const o=t;return this.updateListItemDOM(e,o,r),!1}updateFromJSON(e){return super.updateFromJSON(e).setValue(e.value).setChecked(e.checked)}exportDOM(e){const t=this.createDOM(e._config),r=this.getFormatType();r&&(t.style.textAlign=r);const o=this.getDirection();return o&&(t.dir=o),Rt(this)?{after(s){if(ke(s)){const i=s.previousElementSibling;if(ke(i)&&i.nodeName==="LI"){for(;s.firstChild;)i.append(s.firstChild);s.remove()}}return s},element:t}:{element:t}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...e){for(let t=0;t<e.length;t++){const r=e[t];if(q(r)&&this.canMergeWith(r)){const o=r.getChildren();this.append(...o),r.remove()}else super.append(r)}return this}replace(e,t){if(le(e))return super.replace(e);this.setIndent(0);const r=this.getParentOrThrow();if(!Z(r))return e;if(r.__first===this.getKey())r.insertBefore(e);else if(r.__last===this.getKey())r.insertAfter(e);else{const i=it(r);let a=this.getNextSibling();for(;a;){const l=a;a=a.getNextSibling(),i.append(l)}r.insertAfter(e),e.insertAfter(i)}const o=this.__key;let s=0;if(t&&(q(e)||jn(139),s=e.getChildrenSize(),e.splice(s,0,this.getChildren())),t&&q(e)){const i=D();if(F(i))for(const a of i.getStartEndPoints())a.key===o&&a.type==="element"&&a.set(e.getKey(),s+a.offset,"element")}return this.remove(),r.getChildrenSize()===0&&r.remove(),e}insertAfter(e,t=!0){const r=this.getParentOrThrow();if(Z(r)||jn(39),le(e))return super.insertAfter(e,t);const o=this.getNextSiblings();if(r.insertAfter(e,t),o.length!==0){const s=it(r);o.forEach(i=>s.append(i)),e.insertAfter(s,t)}return e}remove(e){const t=this.getPreviousSibling(),r=this.getNextSibling();super.remove(e),t&&r&&Rt(t)&&Rt(r)&&(Xc(t.getFirstChild(),r.getFirstChild()),r.remove())}resetOnCopyNodeFrom(e){super.resetOnCopyNodeFrom(e),e.getChecked()&&this.setChecked(!1)}insertNewAfter(e,t=!0){const r=it(this);return this.insertAfter(r,t),r}collapseAtStart(e){if(Rt(this))return!1;const t=this.getParentOrThrow();if(le(t.getParentOrThrow()))return af(this),!0;const r=ne().append(...this.getChildren()),o=this.getNextSiblings();if(o.length>0){const s=it(t);s.append(...o),t.insertAfter(s)}return t.insertAfter(r),this.remove(),t.getChildrenSize()===0&&t.remove(),r.selectStart(),!0}getValue(){return this.getLatest().__value}setValue(e){const t=this.getWritable();return t.__value=e,t}getChecked(){const e=this.getLatest();let t;const r=this.getParent();return Z(r)&&(t=r.getListType()),t==="check"?!!e.__checked:void 0}setChecked(e){const t=this.getWritable();return t.__checked=e,t}toggleChecked(){const e=this.getWritable();return e.setChecked(!e.__checked)}getIndent(){const e=this.getParent();if(e===null||!this.isAttached())return this.getLatest().__indent;let t=e.getParentOrThrow(),r=0;for(;le(t);)t=t.getParentOrThrow().getParentOrThrow(),r++;return r}setIndent(e){typeof e!="number"&&jn(117),(e=Math.floor(e))>=0||jn(199);let t=this.getIndent();for(;t!==e;)t<e?(Y0(this),t++):(af(this),t--);return this}canInsertAfter(e){return le(e)}canReplaceWith(e){return le(e)}canMergeWith(e){return le(e)||ht(e)}extractWithChild(e,t){if(!F(t))return!1;const r=t.anchor.getNode(),o=t.focus.getNode();return this.isParentOf(r)&&this.isParentOf(o)&&this.getTextContent().length===t.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return Et("bullet")}canMergeWhenEmpty(){return!0}};function X0(n){if(n.classList.contains("task-list-item")){for(const r of n.children)if(r.tagName==="INPUT")return lf(r)}if(n.classList.contains("joplin-checkbox")){for(const r of n.children)if(r.classList.contains("checkbox-wrapper")&&r.children.length>0&&r.children[0].tagName==="INPUT")return lf(r.children[0])}const e=n.getAttribute("aria-checked"),t=xt(e==="true"||e!=="false"&&void 0);return rr(t,n),{after:u_.bind(null,t),node:mn(t,n)}}function lf(n){if(n.getAttribute("type")!=="checkbox")return{node:null};const e=xt(n.hasAttribute("checked"));return{after:u_.bind(null,e),node:e}}function u_(n,e){const t=e[0];return e.length===1&&ht(t)&&!n.getFormatType()&&t.getFormatType()?(n.setFormat(t.getFormatType()),t.getChildren()):e}function xt(n){return Ot(new bn(void 0,n))}function le(n){return n instanceof bn}let Yt=class extends Oe{__tag;__start;__listType;$config(){return this.config("list",{$transform:e=>{(function(t){const r=t.getNextSibling();Z(r)&&t.getListType()===r.getListType()&&Xc(t,r)})(e),c_(e)},extends:Oe,importDOM:$c({ol:()=>({conversion:uf,priority:0}),ul:()=>({conversion:uf,priority:0})})})}constructor(e="number",t=1,r){super(r);const o=Z0[e]||e;this.__listType=o,this.__tag=o==="number"?"ol":"ul",this.__start=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__listType=e.__listType,this.__tag=e.__tag,this.__start=e.__start}getTag(){return this.getLatest().__tag}setListType(e){const t=this.getWritable();return t.__listType=e,t.__tag=e==="number"?"ol":"ul",t}getListType(){return this.getLatest().__listType}getStart(){return this.getLatest().__start}setStart(e){const t=this.getWritable();return t.__start=e,t}createDOM(e,t){const r=this.__tag,o=Je().createElement(r);return this.__start!==1&&o.setAttribute("start",String(this.__start)),o.__lexicalListType=this.__listType,cf(o,e.theme,this),o}updateDOM(e,t,r){return e.__tag!==this.__tag||e.__listType!==this.__listType||(cf(t,r.theme,this),e.__start!==this.__start&&t.setAttribute("start",String(this.__start)),!1)}updateFromJSON(e){return super.updateFromJSON(e).setListType(e.listType).setStart(e.start)}exportDOM(e){const t=this.createDOM(e._config,e);return ke(t)&&(this.__start!==1&&t.setAttribute("start",String(this.__start)),this.__listType==="check"&&t.setAttribute("__lexicalListType","check")),{element:t}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag()}}canBeEmpty(){return!1}canIndent(){return!1}splice(e,t,r){let o=r;for(let s=0;s<r.length;s++){const i=r[s];le(i)||(o===r&&(o=[...r]),o[s]=this.createListItemNode().append(!q(i)||Z(i)||i.isInline()?i:$e(i.getTextContent())))}return super.splice(e,t,o)}extractWithChild(e){return le(e)}createListItemNode(){return xt()}};function cf(n,e,t){const r=[],o=[],s=e.list;if(s!==void 0){const i=s[`${t.__tag}Depth`]||[],a=Is(t)-1,l=a%i.length,c=i[l],u=s[t.__tag];let f;const d=s.nested,g=s.checklist;if(d!==void 0&&d.list&&(f=d.list),u!==void 0&&r.push(u),g!==void 0&&t.__listType==="check"&&r.push(g),c!==void 0){r.push(...ps(c));for(let h=0;h<i.length;h++)h!==l&&o.push(t.__tag+h)}if(f!==void 0){const h=ps(f);a>1?r.push(...h):o.push(...h)}}o.length>0&&$t(n,...o),r.length>0&&Ie(n,...r)}function uf(n){let e;if((function(t){return ke(t)&&t.nodeName.toLowerCase()==="ol"})(n)){const t=n.start;e=Et("number",t)}else e=(function(t){if(t.getAttribute("__lexicallisttype")==="check"||t.classList.contains("contains-task-list")||t.getAttribute("data-is-checklist")==="1")return!0;for(const r of t.childNodes)if(ke(r)&&r.hasAttribute("aria-checked"))return!0;return!1})(n)?Et("check"):Et("bullet");return mn(e,n),{after:t=>(function(r,o){const s=o.createListItemNode.bind(o),i=[];for(let a=0;a<r.length;a++){const l=r[a];if(le(l)){i.push(l);const c=l.getChildren();c.length>1&&c.forEach(u=>{Z(u)&&i.push(s().append(u))})}else i.push(s().append(l))}return i})(t,e),node:e}}const Z0={ol:"number",ul:"bullet"};function Et(n="number",e=1){return Ot(new Yt(n,e))}function Z(n){return n instanceof Yt}const Zc=he("INSERT_CHECK_LIST_COMMAND");function Q0(n,e){const t=e&&e.disableTakeFocusOnClick||!1,r=typeof t=="boolean"?()=>t:t.peek.bind(t),o=c=>{const u=c.target;if(!ke(u))return!1;const f=u.__lexicalCheckListLastHandled;return f!==void 0&&c.timeStamp-f<500},s=c=>{const u=c.target;ke(u)&&(u.__lexicalCheckListLastHandled=c.timeStamp)},i=c=>{o(c)||(s(c),df(c,r()))},a=c=>{c.pointerType==="touch"&&(o(c)||(s(c),df(c,r())))},l=c=>{(function(u,f){d_(u,()=>{u.preventDefault(),f&&u.stopPropagation()})})(c,r())};return de(n.registerCommand(Zc,()=>(Jl("check"),!0),ee),n.registerCommand(Vt,c=>ff(c,n,!1),ee),n.registerCommand(pt,c=>ff(c,n,!0),ee),n.registerCommand(Nn,()=>{if(ql(n)!=null){const c=n.getRootElement();return c?.focus(),!0}return!1},ee),n.registerCommand(Bp,c=>{const u=ql(n);return!(u==null||!n.isEditable())&&(n.update(()=>{const f=Ae(u);le(f)&&(c.preventDefault(),f.toggleChecked())}),!0)},ee),n.registerCommand(zs,c=>n.read("latest",()=>{const u=D();if(F(u)&&u.isCollapsed()){const{anchor:f}=u,d=f.type==="element";if(d||f.offset===0){const g=f.getNode(),h=re(g,_=>q(_)&&!_.isInline());if(le(h)){const _=h.getParent();if(Z(_)&&_.getListType()==="check"&&(d||h.getFirstDescendant()===g)){const m=n.getElementByKey(h.__key);if(m!=null&&la(m)!==m)return m.focus(),c.preventDefault(),!0}}}}return!1}),ee),n.registerRootListener(c=>{if(c!==null)return de(Id(c,{click:i,pointerup:a}),Id(c,{mousedown:l,pointerdown:l},{capture:!0}),Jt(c,"touchstart",l,{capture:!0,passive:!1}))}))}function d_(n,e){const t=n.target;if(!ke(t))return;const r=t.firstChild;if(ke(r)&&(r.tagName==="UL"||r.tagName==="OL"))return;const o=t.parentNode;if(!o||o.__lexicalListType!=="check")return;let s=null,i=null;if("clientX"in n)s=n.clientX;else if("touches"in n){const g=n.touches;g.length>0&&(s=g[0].clientX,i="touch")}if(s==null)return;const a=t.getBoundingClientRect(),l=s/Wn(t),c=t.ownerDocument.defaultView,u=c?c.getComputedStyle(t,"::before"):{width:"0px"},f=parseFloat(u.width),d=i==="touch"||"pointerType"in n&&n.pointerType==="touch"?32:0;(t.dir==="rtl"?l<a.right+d&&l>a.right-f-d:l>a.left-d&&l<a.left+f+d)&&e()}function df(n,e){d_(n,()=>{if(ke(n.target)){const t=n.target,r=Oy(t);r!=null&&r.isEditable()&&r.update(()=>{const o=Ae(t);le(o)&&(e?(Ai(Ry),Ai(Ay)):t.focus(),o.toggleChecked())})}})}function ql(n){const e=n.getRootElement(),t=e?la(e):null;return ke(t)&&t.tagName==="LI"&&t.parentNode!=null&&t.parentNode.__lexicalListType==="check"?t:null}function ff(n,e,t){const r=ql(e);return r!=null&&e.update(()=>{const o=Ae(r);if(!le(o))return;const s=(function(i,a){let l=a?i.getPreviousSibling():i.getNextSibling(),c=i;for(;l==null&&le(c);)c=c.getParentOrThrow().getParent(),c!=null&&(l=a?c.getPreviousSibling():c.getNextSibling());for(;le(l);){const u=a?l.getLastChild():l.getFirstChild();if(!Z(u))return l;l=a?u.getLastChild():u.getFirstChild()}return null})(o,t);if(s!=null){s.selectStart();const i=e.getElementByKey(s.__key);i!=null&&(n.preventDefault(),setTimeout(()=>{i.focus()},0))}}),!1}function eC(n){const e=[];for(const t of n)if(le(t)){e.push(t);const r=t.getChildren();if(r.length>1)for(const o of r)Z(o)&&e.push(xt().append(o))}else e.push(xt().append(t));return e}const tC=Ye({$import:(n,e)=>{let t;var r;return eh(e,"ol")?t=Et("number",e.start):t=(r=e).matches('[__lexicallisttype="check"], .contains-task-list, [data-is-checklist="1"]')||r.querySelector(":scope > [aria-checked]")!==null?Et("check"):Et("bullet"),mn(t,e),[t.splice(0,0,th(eC(n.$importChildren(e)),e))]},match:Ge.tag("ol","ul"),name:"@lexical/list/list"});function f_(n,e){if(e.length!==1)return e;const t=e[0];return ht(t)&&!n.getFormatType()&&t.getFormatType()?(n.setFormat(t.getFormatType()),t.getChildren()):e}function g_(n){const e=i=>Ly(i)&&!Z(i);if(!n.some(e))return n;const t=[];let r=[];const o=()=>{r.length>0&&(t.push(r),r=[])};for(const i of n)e(i)?(o(),t.push(q(i)?i.getChildren():[i])):r.push(i);o();const s=[];for(const i of t)s.length>0&&s.push(vt()),s.push(...i);return s}const nC=Ye({$import:(n,e)=>{const t=e.getAttribute("aria-checked"),r=xt(t==="true"||t!=="false"&&void 0);return rr(r,e),mn(r,e),[r.splice(0,0,g_(f_(r,n.$importChildren(e))))]},match:Ge.tag("li"),name:"@lexical/list/li"});function gf(n,e,t){const r=eh(t,"input")?t:t.querySelector('input[type="checkbox"]');if(!r||r.getAttribute("type")!=="checkbox")return[];const o=xt(r.hasAttribute("checked"));return rr(o,e),mn(o,e),[o.splice(0,0,g_(f_(o,n.$importChildren(e))))]}const rC=[Ye({$import:(n,e,t)=>{const r=e.querySelector(':scope > input[type="checkbox"]');return r?gf(n,e,r):t()},match:Ge.tag("li").classAll("task-list-item"),name:"@lexical/list/li-task-list-item"}),Ye({$import:(n,e,t)=>{const r=e.querySelector(":scope > .checkbox-wrapper");if(!r)return t();const o=r.querySelector(':scope > input[type="checkbox"]');return o?gf(n,e,o):t()},match:Ge.tag("li").classAll("joplin-checkbox"),name:"@lexical/list/li-joplin-checkbox"}),tC,nC],oC=he("UPDATE_LIST_START_COMMAND"),Qc=he("INSERT_UNORDERED_LIST_COMMAND"),eu=he("INSERT_ORDERED_LIST_COMMAND"),sC=he("REMOVE_LIST_COMMAND");function iC(n,e){return de(n.registerCommand(eu,()=>(Jl("number"),!0),ee),n.registerCommand(oC,t=>{const{listNodeKey:r,newStart:o}=t,s=Q(r);return!!Z(s)&&(s.getListType()==="number"&&(s.setStart(o),c_(s)),!0)},ee),n.registerCommand(Qc,()=>(Jl("bullet"),!0),ee),n.registerCommand(sC,()=>(V0(),!0),ee),n.registerCommand(Lo,()=>G0(!!(e&&e.restoreNumbering)),ee),n.registerCommand(sa,t=>{const r=D();if(!F(r)||!r.isCollapsed())return!1;const{anchor:o}=r;if(o.offset!==0)return!1;let s=o.getNode();for(;!le(s);){if(s.getPreviousSibling()!==null)return!1;const i=s.getParent();if(i===null)return!1;s=i}return!(!le(s)||!s.collapseAtStart(r))&&(t.preventDefault(),!0)},My),n.registerNodeTransform(bn,t=>{const r=t.getFirstChild();if(r){if(oe(r)){const o=r.getStyle(),s=r.getFormat();t.getTextStyle()!==o&&t.setTextStyle(o),t.getTextFormat()!==s&&t.setTextFormat(s)}}else{const o=D();F(o)&&(o.style!==t.getTextStyle()||o.format!==t.getTextFormat())&&o.isCollapsed()&&t.is(o.anchor.getNode())&&t.setTextStyle(o.style).setTextFormat(o.format)}}),n.registerNodeTransform(cn,t=>{const r=t.getParent();if(le(r)&&t.is(r.getFirstChild())){const o=t.getStyle(),s=t.getFormat();o===r.getTextStyle()&&s===r.getTextFormat()||r.setTextStyle(o).setTextFormat(s)}}))}function aC(n){const e=t=>{const r=t.getParent();if(Z(t.getFirstChild())||!Z(r))return;const o=re(t,s=>le(s)&&Z(s.getParent())&&le(s.getPreviousSibling()));if(o===null&&t.getIndent()>0)t.setIndent(0);else if(le(o)){const s=o.getPreviousSibling();if(le(s)){const i=(function(l){let c=l,u=c.getFirstChild();for(;Z(u);){const f=u.getLastChild();if(!le(f))break;c=f,u=c.getFirstChild()}return c})(s),a=i.getParent();if(Z(a)){const l=Is(a);l+1<Is(r)&&t.setIndent(l)}}}};return n.registerNodeTransform(Yt,t=>{const r=[t];for(;r.length>0;){const o=r.shift();if(Z(o)){for(const s of o.getChildren())if(le(s)){e(s);const i=s.getFirstChild();Z(i)&&r.push(i)}}}})}const da=pe({build:(n,e,t)=>nr(e),config:tr({hasStrictIndent:!1,shouldPreserveNumbering:!1}),dependencies:[js,ln(Fs,{rules:rC})],name:"@lexical/list/List",nodes:()=>[Yt,bn],register(n,e,t){const r=t.getOutput();return de(zt(()=>iC(n,{restoreNumbering:r.shouldPreserveNumbering.value})),zt(()=>r.hasStrictIndent.value?aC(n):void 0))}}),lC=pe({build:(n,e)=>nr(e),config:tr({disableTakeFocusOnClick:!1}),dependencies:[da],name:"@lexical/list/CheckList",register:(n,e,t)=>Q0(n,t.getOutput())}),pf=new Set(["http:","https:","mailto:","sms:","tel:"]);class gn extends Oe{__url;__target;__rel;__title;$config(){return this.config("link",{extends:Oe,importDOM:{a:()=>({conversion:uC,priority:1})}})}constructor(e="",t={},r){super(r);const{target:o=null,rel:s=null,title:i=null}=t;this.__url=e,this.__target=o,this.__rel=s,this.__title=i}afterCloneFrom(e){super.afterCloneFrom(e),this.__url=e.__url,this.__rel=e.__rel,this.__target=e.__target,this.__title=e.__title}createDOM(e){const t=Je().createElement("a");return this.updateLinkDOM(null,t,e),Ie(t,e.theme.link),t}updateLinkDOM(e,t,r){if(nh(t)){e&&e.__url===this.__url||(t.href=this.sanitizeUrl(this.__url));for(const o of["target","rel","title"]){const s=`__${o}`,i=this[s];e&&e[s]===i||(i?t[o]=i:t.removeAttribute(o))}}}updateDOM(e,t,r){return this.updateLinkDOM(e,t,r),!1}updateFromJSON(e){return super.updateFromJSON(e).setURL(e.url).setRel(e.rel||null).setTarget(e.target||null).setTitle(e.title||null)}sanitizeUrl(e){const t=e;e=bf(e);try{const r=new URL(bf(e));if(!pf.has(r.protocol))return"about:blank"}catch{const o=t.replace(/[\u0000-\u001F\u007F\s]/g,"").match(/^([a-z][a-z0-9+.-]*):/i);if(o!=null&&!pf.has(`${o[1].toLowerCase()}:`))return"about:blank"}return e}exportJSON(){return{...super.exportJSON(),rel:this.getRel(),target:this.getTarget(),title:this.getTitle(),url:this.getURL()}}getURL(){return this.getLatest().__url}setURL(e){const t=this.getWritable();return t.__url=e,t}getTarget(){return this.getLatest().__target}setTarget(e){const t=this.getWritable();return t.__target=e,t}getRel(){return this.getLatest().__rel}setRel(e){const t=this.getWritable();return t.__rel=e,t}getTitle(){return this.getLatest().__title}setTitle(e){const t=this.getWritable();return t.__title=e,t}insertNewAfter(e,t=!0){const r=it(this);return this.insertAfter(r,t),r}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(e,t,r){if(!F(t))return!1;const o=t.anchor.getNode(),s=t.focus.getNode();return(this.is(o)||this.isParentOf(o))&&(this.is(s)||this.isParentOf(s))&&t.getTextContent().length>0}isEmailURI(){return this.__url.startsWith("mailto:")}isWebSiteURI(){return this.__url.startsWith("https://")||this.__url.startsWith("http://")}shouldMergeAdjacentLink(e){return this.getType()===e.getType()&&this.__url===e.__url&&this.__target===e.__target&&this.__rel===e.__rel&&this.__title===e.__title}}function hf(n){const e=vs(n,"next");return[e,e.getFlipped()]}function _f(n,e){for(const t of e)if(t.origin.isAttached()){const r=Jn(t);return void hr(n,r)}}function cC(n){const e=D();let t=null,r=null;function o(){F(e)&&(_f(e.anchor,t),_f(e.focus,r),Ss(e))}F(e)&&(t=hf(e.anchor),r=hf(e.focus));let s=!1;for(const a of Er(n,"next")){const l=a.origin;if(q(l)&&!l.isInline()){const c=l.getChildren();if(c.length>0){const u=it(n);u.append(...c),l.append(u),s=!0}Zp(l,Dc(a),{$shouldSplit:()=>!1})}}function i(a,l,c){const[u,f]=a,d=h=>Mc(h)&&h.origin.is(l);if(!d(u)&&!d(f))return a;const g=Jn(Er(c,"next"));return[g,g.getFlipped()]}if(n.isAttached()){const a=n.getPreviousSibling();if(Pe(a)&&a.shouldMergeAdjacentLink(n))return t&&(t=i(t,a,n)),r&&(r=i(r,a,n)),a.append(...n.getChildren()),n.remove(),void o();const l=n.getNextSibling();Pe(l)&&n.shouldMergeAdjacentLink(l)&&(t&&(t=i(t,n,l)),r&&(r=i(r,n,l)),n.append(...l.getChildren()),l.remove(),s=!0)}if(s){if(!n.canBeEmpty()&&n.isEmpty()){const a=n.getParent();n.remove(),a&&a.isEmpty()&&a.remove()}o()}}function uC(n){let e=null;if(nh(n)){const t=n.textContent;(t!==null&&t!==""||n.children.length>0)&&(e=Mo(n.getAttribute("href")||"",{rel:n.getAttribute("rel"),target:n.getAttribute("target"),title:n.getAttribute("title")}))}return{node:e}}function Mo(n="",e){return Ot(new gn(n,e))}function Pe(n){return n instanceof gn}let fa=class extends gn{__isUnlinked;constructor(e="",t={},r){super(e,t,r),this.__isUnlinked=t.isUnlinked!==void 0&&t.isUnlinked!==null&&t.isUnlinked}afterCloneFrom(e){super.afterCloneFrom(e),this.__isUnlinked=e.__isUnlinked}$config(){return this.config("autolink",{extends:gn})}shouldMergeAdjacentLink(e){return!1}getIsUnlinked(){return this.__isUnlinked}setIsUnlinked(e){const t=this.getWritable();return t.__isUnlinked=e,t}createDOM(e){return this.__isUnlinked?Je().createElement("span"):super.createDOM(e)}updateDOM(e,t,r){return super.updateDOM(e,t,r)||e.__isUnlinked!==this.__isUnlinked}updateFromJSON(e){return super.updateFromJSON(e).setIsUnlinked(e.isUnlinked||!1)}exportJSON(){return{...super.exportJSON(),isUnlinked:this.__isUnlinked}}insertNewAfter(e,t=!0){const r=p_(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return this.insertAfter(r,t),r}};function p_(n="",e){return Ot(new fa(n,e))}function _t(n){return n instanceof fa}const Lr=he("TOGGLE_LINK_COMMAND");function mf(n,e){if(n.type==="element"){const t=n.getNode();return q(t)||(function(r,...o){const s=new URL("https://lexical.dev/docs/error"),i=new URLSearchParams;i.append("code",r);for(const a of o)i.append("v",a);throw s.search=i.toString(),Error(`Minified Lexical error #${r}; visit ${s.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)})(252),t.getChildren()[n.offset+e]||null}return null}function Ka(n,e={}){let t;if(n&&typeof n=="object"){const{url:u,...f}=n;t=u,e={...f,...e}}else t=n;const{target:r,title:o}=e,s=e.rel===void 0?"noreferrer":e.rel,i=D();if(i===null||!F(i)&&!ve(i))return;if(ve(i)){const u=i.getNodes();return u.length===0?void 0:void u.forEach(f=>{if(t===null){const d=re(f,g=>!_t(g)&&Pe(g));d&&(d.insertBefore(f),d.getChildren().length===0&&d.remove())}else{const d=re(f,g=>!_t(g)&&Pe(g));if(d)d.setURL(t),r!==void 0&&d.setTarget(r),s!==void 0&&d.setRel(s);else{const g=Mo(t,{rel:s,target:r});f.insertBefore(g),g.append(f)}}})}if(i.isCollapsed()&&t===null)for(const u of i.getNodes()){const f=re(u,d=>!_t(d)&&Pe(d));return void(f!==null&&(f.getParentOrThrow().splice(f.getIndexWithinParent(),0,f.getChildren()),f.remove()))}const a=i.extract();if(t===null){const u=new Set;return void a.forEach(f=>{const d=re(f,g=>!_t(g)&&Pe(g));if(d!==null){const g=d.getKey();if(u.has(g))return;(function(h,_){const m=new Set(_.filter(N=>h.isParentOf(N)).map(N=>N.getKey())),b=h.getChildren(),w=N=>m.has(N.getKey())||q(N)&&_.some(O=>h.isParentOf(O)&&N.isParentOf(O)),C=b.filter(w);if(C.length===b.length)return b.forEach(N=>h.insertBefore(N)),void h.remove();const v=b.findIndex(w),k=b.findLastIndex(w),I=v===0,E=k===b.length-1;if(I)C.forEach(N=>h.insertBefore(N));else if(E)for(let N=C.length-1;N>=0;N--)h.insertAfter(C[N]);else{for(let O=C.length-1;O>=0;O--)h.insertAfter(C[O]);const N=b.slice(k+1);if(N.length>0){const O=it(h);C[C.length-1].insertAfter(O),N.forEach(M=>O.append(M))}}})(d,a),u.add(g)}})}const l=new Set,c=u=>{l.has(u.getKey())||(l.add(u.getKey()),u.setURL(t),r!==void 0&&u.setTarget(r),s!==void 0&&u.setRel(s),o!==void 0&&u.setTitle(o))};if(a.length===1){const u=a[0],f=re(u,Pe);if(f!==null)return c(f)}(function(u){const f=D();if(!F(f))return u();const d=Ss(f),g=d.isBackward(),h=mf(d.anchor,g?-1:0),_=mf(d.focus,g?0:-1);if(u(),h||_){const m=D();if(F(m)){const b=m.clone();if(h){const w=h.getParent();w&&b.anchor.set(w.getKey(),h.getIndexWithinParent()+(g?1:0),"element")}if(_){const w=_.getParent();w&&b.focus.set(w.getKey(),_.getIndexWithinParent()+(g?0:1),"element")}Ee(Ss(b))}}})(()=>{let u=null;for(const f of a){if(!f.isAttached())continue;const d=re(f,Pe);if(d){c(d);continue}if(q(f)){if(!f.isInline())continue;if(Pe(f)){if(!(_t(f)||u!==null&&u.getParentOrThrow().isParentOf(f))){c(f),u=f;continue}for(const h of f.getChildren())f.insertBefore(h);f.remove();continue}}const g=f.getPreviousSibling();Pe(g)&&g.is(u)?g.append(f):(u=Mo(t,{rel:s,target:r,title:o}),f.insertAfter(u),u.append(f))}})}const dC=/^\+?[0-9\s()-]{5,}$/;function bf(n){return n.match(/^[a-z][a-z0-9+.-]*:/i)||n.match(/^[/#.]/)?n:n.includes("@")?`mailto:${n}`:dC.test(n)?`tel:${n}`:`https://${n}`}const fC=[Ye({$import:(n,e)=>{if(!e.textContent&&e.children.length===0)return[];const t=e.getAttribute("href")||"",r={rel:e.getAttribute("rel"),target:e.getAttribute("target"),title:e.getAttribute("title")};return $y(n.$importChildren(e),()=>Mo(t,r))},match:Ge.tag("a"),name:"@lexical/link/a"})];function h_(n,e){return de(n.registerNodeTransform(gn,cC),n.registerCommand(Lr,t=>{const r=e.validateUrl.peek(),o=e.attributes.peek();if(t===null)return Ka(null),!0;if(typeof t=="string")return!(r!==void 0&&!r(t))&&(Ka(t,o),!0);{const{url:s,target:i,rel:a,title:l}=t;return Ka(s,{...o,rel:a,target:i,title:l}),!0}},V),zt(()=>{const t=e.validateUrl.value;if(!t)return;const r=e.attributes.value;return n.registerCommand(Ic,o=>{const s=D();if(!F(s)||s.isCollapsed()||!fo(o,ClipboardEvent)||o.clipboardData===null)return!1;const i=o.clipboardData.getData("text");return t(i)?!s.getNodes().some(a=>q(a)||oe(a)&&!a.isSimpleText())&&(n.dispatchCommand(Lr,{...r,url:i}),o.preventDefault(),!0):!1},ee)}))}const tu=pe({build:(n,e,t)=>nr(e),config:{attributes:void 0,validateUrl:void 0},dependencies:[js,ln(Fs,{rules:fC})],mergeConfig(n,e){const t=Eo(n,e);return n.attributes&&(t.attributes=Eo(n.attributes,t.attributes)),t},name:"@lexical/link/Link",nodes:()=>[gn],register:(n,e,t)=>h_(n,t.getOutput())});function Vl(n,e){for(let t=0;t<e.length;t++){const r=e[t](n);if(r)return r}return null}const __=/[.,;\s]/;function Bi(n,e){return e.test(n)}function m_(n,e){return Bi(n[n.length-1],e)}function Yl(n,e){return Bi(n[0],e)}function b_(n,e){let t=n.getPreviousSibling();return q(t)&&(t=t.getLastDescendant()),t===null||ue(t)||oe(t)&&m_(t.getTextContent(),e)}function y_(n,e){let t=n.getNextSibling();return q(t)&&(t=t.getFirstDescendant()),t===null||ue(t)||oe(t)&&Yl(t.getTextContent(),e)}function gC(n,e,t,r,o){return(n>0?Bi(r[n-1],t):b_(o[0],t))?e<r.length?Bi(r[e],t):y_(o[o.length-1],t):!1}function pC(n,e,t){const r=[],o=[],s=[];let i=0,a=0;const l=[...n];for(;l.length>0;){const c=l[0],u=c.getTextContent().length,f=a;a+u<=e?(r.push(c),i+=u):f>=t?s.push(c):o.push(c),a+=u,l.shift()}return[i,r,o,s]}function hC(n,e,t,r){const o=p_(r.url,r.attributes);if(n.length===1){let s,i=n[0];e===0?[s,i]=i.splitText(t):[,s,i]=i.splitText(e,t);const a=$e(r.text);return a.setFormat(s.getFormat()),a.setDetail(s.getDetail()),a.setStyle(s.getStyle()),o.append(a),s.replace(o),i}if(n.length>1){const s=n[0];let i,a=s.getTextContent().length;e===0?i=s:[,i]=s.splitText(e);const l=[];let c;for(let g=1;g<n.length;g++){const h=n[g],_=h.getTextContent().length,m=a;if(m<t)if(a+_<=t)l.push(h);else{const[b,w]=h.splitText(t-m);l.push(b),c=w}a+=_}const u=D(),f=u?u.getNodes().find(oe):void 0,d=$e(i.getTextContent());return d.setFormat(i.getFormat()),d.setDetail(i.getDetail()),d.setStyle(i.getStyle()),o.append(d,...l),f&&f===i&&(F(u)?d.select(u.anchor.offset,u.focus.offset):ve(u)&&d.select(0,d.getTextContent().length)),i.replace(o),c}}function yf(n,e,t,r){const o=n.getChildren(),s=o.length;for(let c=0;c<s;c++){const u=o[c];if(!oe(u)||!u.isSimpleText())return _s(n),void t(null,n.getURL())}const i=n.getTextContent(),a=Vl(i,e);if(a===null||a.text!==i||!b_(n,r)||!y_(n,r))return _s(n),void t(null,n.getURL());const l=n.getURL();if(l!==a.url&&(n.setURL(a.url),t(a.url,l)),a.attributes){const c=n.getRel();c!==a.attributes.rel&&(n.setRel(a.attributes.rel||null),t(a.attributes.rel||null,c));const u=n.getTarget();u!==a.attributes.target&&(n.setTarget(a.attributes.target||null),t(a.attributes.target||null,u))}}function _s(n){const e=n.getChildren();for(let t=e.length-1;t>=0;t--)n.insertAfter(e[t]);return n.remove(),e.map(t=>t.getLatest())}const w_={changeHandlers:[],excludeParents:[],matchers:[],separatorRegex:__};function _C(n,e=w_){const{matchers:t,changeHandlers:r,excludeParents:o,separatorRegex:s=__}=e,i=(a,l)=>{for(const c of r)c(a,l)};return de(n.registerNodeTransform(cn,a=>{const l=a.getParentOrThrow(),c=a.getPreviousSibling();if(_t(l))yf(l,t,i,s);else if(!Pe(l)&&!o.some(u=>u(l))){if(a.isSimpleText()&&(Yl(a.getTextContent(),s)||!_t(c))){const u=(function(f){const d=[f];let g=f.getNextSibling();for(;g!==null&&oe(g)&&g.isSimpleText()&&(d.push(g),!/[\s]/.test(g.getTextContent()));)g=g.getNextSibling();return d})(a);(function(f,d,g,h){for(const v of f){const k=v.getParent();if(_t(k)&&!k.getIsUnlinked())return}let _=[...f];const m=_.map(v=>v.getTextContent()).join("");let b,w=m,C=0;for(;(b=Vl(w,d))&&b!==null;){const v=b.index,k=v+b.length;if(gC(C+v,C+k,h,m,_)){const[I,,E,N]=pC(_,C+v,C+k);let O=!1;for(const R of E){const $=R.getParent();if(_t($)&&!$.getIsUnlinked()){O=!0;break}}if(O){C+=k,w=w.substring(k);continue}const M=hC(E,C+v-I,C+k-I,b);_=M?[M,...N]:N,g(b.url,null),C=0}else C+=k;w=w.substring(k)}})(u,t,i,s)}(function(u,f,d,g){const h=u.getParent(),_=u.getPreviousSibling(),m=u.getNextSibling(),b=u.getTextContent();if(!_t(h)||h.getIsUnlinked()){if(_t(_)&&!_.getIsUnlinked()&&_.is(u.getPreviousSibling())&&u.getParent()===_.getParent()){if(!Yl(b,g))return _s(_),void d(null,_.getURL());if(w=b,_.isEmailURI()?/^\.[a-zA-Z]{2,}/.test(w):/^\.[a-zA-Z0-9]{1,}/.test(w)){const C=_.getTextContent()+b,v=Vl(C,f);v!==null&&v.text===C&&(_.append(u),yf(_,f,d,g),d(null,_.getURL()))}}var w;!_t(m)||m.getIsUnlinked()||m_(b,g)||m.is(u.getNextSibling())&&u.getParent()===m.getParent()&&(_s(m),d(null,m.getURL()))}})(a,t,i,s)}}),n.registerCommand(Lr,a=>{const l=D();return a!==null||!F(l)||l.extract().forEach(c=>{const u=c.getParent();_t(u)&&(u.setIsUnlinked(!u.getIsUnlinked()),u.markDirty())}),!1},ee))}const mC=pe({config:w_,dependencies:[tu],mergeConfig(n,e){const t=Eo(n,e);for(const r of["matchers","changeHandlers","excludeParents"]){const o=e[r];Array.isArray(o)&&(t[r]=[...n[r],...o])}return t},name:"@lexical/link/AutoLink",nodes:[fa],register:_C}),Co=/^(\d+(?:\.\d+)?)px$/,te={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};let Gt=class extends Oe{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;$config(){return this.config("tablecell",{extends:Oe,importDOM:{td:()=>({conversion:wf,priority:0}),th:()=>({conversion:wf,priority:0})}})}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign,this.__colSpan=e.__colSpan,this.__headerState=e.__headerState,this.__width=e.__width}updateFromJSON(e){return super.updateFromJSON(e).setHeaderStyles(e.headerState).setColSpan(e.colSpan||1).setRowSpan(e.rowSpan||1).setWidth(e.width||void 0).setBackgroundColor(e.backgroundColor||null).setVerticalAlign(e.verticalAlign||void 0)}constructor(e=te.NO_STATUS,t=1,r,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=r,this.__backgroundColor=null,this.__verticalAlign=void 0}createDOM(e){const t=Je().createElement(this.getTag());return this.__width&&(t.style.width=`${this.__width}px`),this.__colSpan>1&&(t.colSpan=this.__colSpan),this.__rowSpan>1&&(t.rowSpan=this.__rowSpan),this.__backgroundColor!==null&&(t.style.backgroundColor=this.__backgroundColor),Gl(this.__verticalAlign)&&(t.style.verticalAlign=this.__verticalAlign),Ie(t,e.theme.tableCell,this.hasHeader()&&e.theme.tableCellHeader),t}exportDOM(e){const t=super.exportDOM(e);if(ke(t.element)){const r=t.element;r.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),r.style.border="1px solid black",this.__colSpan>1&&(r.colSpan=this.__colSpan),this.__rowSpan>1&&(r.rowSpan=this.__rowSpan),r.style.width=`${this.getWidth()||75}px`,r.style.verticalAlign=this.getVerticalAlign()||"top",r.style.textAlign="start",this.__backgroundColor===null&&this.hasHeader()&&(r.style.backgroundColor="#f2f3f5")}return t}exportJSON(){return{...super.exportJSON(),...Gl(this.__verticalAlign)&&{verticalAlign:this.__verticalAlign},backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=te.BOTH){const r=this.getWritable();return r.__headerState=e&t|r.__headerState&~t,r}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}getVerticalAlign(){return this.getLatest().__verticalAlign}setVerticalAlign(e){const t=this.getWritable();return t.__verticalAlign=e||void 0,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==te.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor||e.__verticalAlign!==this.__verticalAlign}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}};function Gl(n){return n==="middle"||n==="bottom"}function wf(n){const e=n,t=n.nodeName.toLowerCase();let r;Co.test(e.style.width)&&(r=parseFloat(e.style.width));let o=te.NO_STATUS;if(t==="th"){const _=e.getAttribute("scope");if(_==="col")o=te.COLUMN;else if(_==="row")o=te.ROW;else{const m=e.parentElement,b=ke(m)&&m.nodeName.toLowerCase()==="tr"&&ke(m.parentElement)&&(m.parentElement.nodeName.toLowerCase()==="thead"||m.rowIndex===0),w=e.cellIndex===0;b&&(o|=te.ROW),w&&(o|=te.COLUMN),o===te.NO_STATUS&&(o=te.ROW)}}const s=lt(o,e.colSpan,r);s.__rowSpan=e.rowSpan;const i=e.style.backgroundColor;i!==""&&(s.__backgroundColor=i);const a=e.style.verticalAlign;Gl(a)&&(s.__verticalAlign=a);const l=e.style,c=(l&&l.textDecoration||"").split(" "),u=l.fontWeight==="700"||l.fontWeight==="bold",f=c.includes("line-through"),d=l.fontStyle==="italic",g=c.includes("underline"),h=l.color;return{after:_=>{const m=[];let b=null;const w=()=>{if(b){const C=b.getFirstChild();ue(C)&&b.getChildrenSize()===1&&C.remove()}};for(const C of _)if(sh(C)||oe(C)||ue(C)){if(oe(C)&&(u&&C.toggleFormat("bold"),f&&C.toggleFormat("strikethrough"),d&&C.toggleFormat("italic"),g&&C.toggleFormat("underline"),h)){const v=C.getStyle();v.includes("color:")||C.setStyle(v+`color: ${h};`)}b?b.append(C):(b=ne().append(C),m.push(b))}else m.push(C),w(),b=null;return w(),m.length===0&&m.push(ne()),m},node:s}}function lt(n=te.NO_STATUS,e=1,t){return Ot(new Gt(n,e,t))}function J(n){return n instanceof Gt}const nu=he("INSERT_TABLE_COMMAND");function G(n,...e){const t=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",n);for(const o of e)r.append("v",o);throw t.search=r.toString(),Error(`Minified Lexical error #${n}; visit ${t.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class Wo extends Oe{__height;$config(){return this.config("tablerow",{extends:Oe,importDOM:{tr:()=>({conversion:bC,priority:0})}})}afterCloneFrom(e){super.afterCloneFrom(e),this.__height=e.__height}updateFromJSON(e){return super.updateFromJSON(e).setHeight(e.height)}constructor(e=void 0,t){super(t),this.__height=e}exportJSON(){const e=this.getHeight();return{...super.exportJSON(),...e===void 0?void 0:{height:e}}}createDOM(e){const t=Je().createElement("tr");return this.__height&&(t.style.height=`${this.__height}px`),Ie(t,e.theme.tableRow),t}extractWithChild(e,t,r){return r==="html"}isShadowRoot(){return!0}setHeight(e){const t=this.getWritable();return t.__height=e,t}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function bC(n){const e=n;let t;return Co.test(e.style.height)&&(t=parseFloat(e.style.height)),{after:r=>Mi(r,J),node:pn(t)}}function pn(n){return Ot(new Wo(n))}function ce(n){return n instanceof Wo}function x_(n,e,t=!0){const r=Ho();for(let o=0;o<n;o++){const s=pn();for(let i=0;i<e;i++){let a=te.NO_STATUS;typeof t=="object"?(o===0&&t.rows&&(a|=te.ROW),i===0&&t.columns&&(a|=te.COLUMN)):t&&(o===0&&(a|=te.ROW),i===0&&(a|=te.COLUMN));const l=lt(a),c=ne();c.append($e()),l.append(c),s.append(l)}r.append(s)}return r}function Xl(n){const e=re(n,t=>J(t));return J(e)?e:null}function ru(n){const e=re(n,t=>ce(t));if(ce(e))return e;throw new Error("Expected table cell to be inside of table row.")}function ot(n){const e=re(n,t=>be(t));if(be(e))return e;throw new Error("Expected table cell to be inside of table.")}function ou(n){const e=ru(n);return ot(e).getChildren().findIndex(t=>t.is(e))}function C_(n){return ru(n).getChildren().findIndex(e=>e.is(n))}function S_(n,e){const t=ot(n),{x:r,y:o}=t.getCordsFromCellNode(n,e);return{above:t.getCellNodeFromCords(r,o-1,e),below:t.getCellNodeFromCords(r,o+1,e),left:t.getCellNodeFromCords(r-1,o,e),right:t.getCellNodeFromCords(r+1,o,e)}}function yC(n,e){const t=n.getChildren();if(e>=t.length||e<0)throw new Error("Expected table cell to be inside of table row.");return t[e].remove(),n}function wC(n,e,t=!0,r,o){const s=n.getChildren();if(e>=s.length||e<0)throw new Error("Table row target index out of range");const i=s[e];if(!ce(i))throw new Error("Row before insertion index does not exist.");for(let a=0;a<r;a++){const l=i.getChildren(),c=l.length,u=pn();for(let f=0;f<c;f++){const d=l[f];J(d)||G(12);const{above:g,below:h}=S_(d,o);let _=te.NO_STATUS;const m=g&&g.getWidth()||h&&h.getWidth()||void 0;(g&&g.hasHeaderState(te.COLUMN)||h&&h.hasHeaderState(te.COLUMN))&&(_|=te.COLUMN);const b=lt(_,1,m);b.append(ne()),u.append(b)}t?i.insertAfter(u):i.insertBefore(u)}return n}const Zl=(n,e)=>n===te.BOTH||n===e?e:te.NO_STATUS;function ga(n=!0){const e=D();F(e)||ae(e)||G(188);const t=e.anchor.getNode(),r=e.focus.getNode(),[o]=We(t),[s,,i]=We(r),[,a,l]=ct(i,s,o),{startRow:c}=l,{startRow:u}=a;return n?Ui(c+o.__rowSpan>u+s.__rowSpan?o:s,!0):Ui(u<c?s:o,!1)}const xC=ga;function Ui(n,e=!0){const[,,t]=We(n),[r,o]=ct(t,n,n),s=r[0].length,{startRow:i}=o;let a=null;if(e){const l=i+n.__rowSpan-1,c=r[l],u=pn();for(let d=0;d<s;d++){const{cell:g,startRow:h}=c[d];if(h+g.__rowSpan-1<=l){const _=c[d].cell.__headerState,m=Zl(_,te.COLUMN);u.append(lt(m).append(ne()))}else g.setRowSpan(g.__rowSpan+1)}const f=t.getChildAtIndex(l);ce(f)||G(256),f.insertAfter(u),a=u}else{const l=i,c=r[l],u=pn();for(let d=0;d<s;d++){const{cell:g,startRow:h}=c[d];if(h===l){const _=c[d].cell.__headerState,m=Zl(_,te.COLUMN);u.append(lt(m).append(ne()))}else g.setRowSpan(g.__rowSpan+1)}const f=t.getChildAtIndex(l);ce(f)||G(257),f.insertBefore(u),a=u}return a}function CC(n,e,t=!0,r,o){const s=n.getChildren(),i=[];for(let a=0;a<s.length;a++){const l=s[a];if(ce(l))for(let c=0;c<r;c++){const u=l.getChildren();if(e>=u.length||e<0)throw new Error("Table column target index out of range");const f=u[e];J(f)||G(12);const{left:d,right:g}=S_(f,o);let h=te.NO_STATUS;(d&&d.hasHeaderState(te.ROW)||g&&g.hasHeaderState(te.ROW))&&(h|=te.ROW);const _=lt(h);_.append(ne()),i.push({newTableCell:_,targetCell:f})}}return i.forEach(({newTableCell:a,targetCell:l})=>{t?l.insertAfter(a):l.insertBefore(a)}),n}function pa(n=!0){const e=D();F(e)||ae(e)||G(188);const t=e.anchor.getNode(),r=e.focus.getNode(),[o]=We(t),[s,,i]=We(r),[,a,l]=ct(i,s,o),{startColumn:c}=l,{startColumn:u}=a;return n?zi(c+o.__colSpan>u+s.__colSpan?o:s,!0):zi(u<c?s:o,!1)}const SC=pa;function zi(n,e=!0,t=!0){const[,,r]=We(n),[o,s]=ct(r,n,n),i=o.length,{startColumn:a}=s,l=e?a+n.__colSpan-1:a-1,c=r.getFirstChild();ce(c)||G(120);let u=null;function f(h=te.NO_STATUS){const _=lt(h).append(ne());return u===null&&(u=_),_}let d=c;e:for(let h=0;h<i;h++){if(h!==0){const k=d.getNextSibling();ce(k)||G(121),d=k}const _=o[h],m=_[l<0?0:l].cell.__headerState,b=Zl(m,te.ROW);if(l<0){au(d,f(b));continue}const{cell:w,startColumn:C,startRow:v}=_[l];if(C+w.__colSpan-1<=l){let k=w,I=v,E=l;for(;I!==h&&k.__rowSpan>1;){if(E-=w.__colSpan,!(E>=0)){d.append(f(b));continue e}{const{cell:N,startRow:O}=_[E];k=N,I=O}}k.insertAfter(f(b))}else w.setColSpan(w.__colSpan+1)}u!==null&&t&&Es(u);const g=r.getColWidths();if(g){const h=[...g],_=l<0?0:l,m=h[_];h.splice(_,0,m),r.setColWidths(h)}return u}function vC(n,e){const t=n.getChildren();for(let r=0;r<t.length;r++){const o=t[r];if(ce(o)){const s=o.getChildren();if(e>=s.length||e<0)throw new Error("Table column target index out of range");s[e].remove()}}return n}function su(){const n=D();F(n)||ae(n)||G(188);const[e,t]=n.isBackward()?[n.focus.getNode(),n.anchor.getNode()]:[n.anchor.getNode(),n.focus.getNode()],[r,,o]=We(e),[s]=We(t),[i,a,l]=ct(o,r,s),{startRow:c}=a,{startRow:u}=l,f=u+s.__rowSpan-1;if(i.length===f-c+1)return void o.remove();const d=i[0].length,g=i[f+1],h=o.getChildAtIndex(f+1);for(let _=f;_>=c;_--){for(let b=d-1;b>=0;b--){const{cell:w,startRow:C,startColumn:v}=i[_][b];if(v===b){if(C<c||C+w.__rowSpan-1>f){const k=Math.max(C,c),I=Math.min(w.__rowSpan+C-1,f),E=k<=I?I-k+1:0;w.setRowSpan(w.__rowSpan-E)}if(C>=c&&C+w.__rowSpan-1>f&&_===f){ce(h)||G(387);let k=null;for(let I=0;I<b;I++){const E=g[I],N=E.cell;E.startRow===_+1&&(k=N),N.__colSpan>1&&(I+=N.__colSpan-1)}k===null?au(h,w):k.insertAfter(w)}}}const m=o.getChildAtIndex(_);ce(m)||G(206,String(_)),m.remove()}if(g!==void 0){const{cell:_}=g[0];Es(_)}else{const _=i[c-1],{cell:m}=_[0];Es(m)}}const kC=su;function iu(){const n=D();F(n)||ae(n)||G(188);const e=n.anchor.getNode(),t=n.focus.getNode(),[r,,o]=We(e),[s]=We(t),[i,a,l]=ct(o,r,s),{startColumn:c}=a,{startRow:u,startColumn:f}=l,d=Math.min(c,f),g=Math.max(c+r.__colSpan-1,f+s.__colSpan-1),h=g-d+1;if(i[0].length===g-d+1)return o.selectPrevious(),void o.remove();const _=i.length;for(let C=0;C<_;C++)for(let v=d;v<=g;v++){const{cell:k,startColumn:I}=i[C][v];if(I<d){if(v===d){const E=d-I;k.setColSpan(k.__colSpan-Math.min(h,k.__colSpan-E))}}else if(I+k.__colSpan-1>g){if(v===g){const E=g-I+1;k.setColSpan(k.__colSpan-E)}}else k.remove()}const m=i[u],b=c>f?m[c+r.__colSpan]:m[f+s.__colSpan];if(b!==void 0){const{cell:C}=b;Es(C)}else{const C=f<c?m[f-1]:m[c-1],{cell:v}=C;Es(v)}const w=o.getColWidths();if(w){const C=[...w];C.splice(d,h),o.setColWidths(C)}}const TC=iu;function Es(n){const e=n.getFirstDescendant();e==null?n.selectStart():e.getParentOrThrow().selectStart()}function au(n,e){const t=n.getFirstChild();t!==null?t.insertBefore(e):n.append(e)}function lu(n){if(n.length===0)return null;const e=ot(n[0]),[t]=at(e,null,null);let r=1/0,o=-1/0,s=1/0,i=-1/0;const a=new Set;for(const g of t)for(const h of g){if(!h||!h.cell)continue;const _=h.cell.getKey();if(!a.has(_)&&n.some(m=>m.is(h.cell))){a.add(_);const m=h.startRow,b=h.startColumn,w=h.cell.__rowSpan||1,C=h.cell.__colSpan||1;r=Math.min(r,m),o=Math.max(o,m+w-1),s=Math.min(s,b),i=Math.max(i,b+C-1)}}if(r===1/0||s===1/0)return null;const l=o-r+1,c=i-s+1,u=t[r][s];if(!u.cell)return null;const f=u.cell;f.setColSpan(c),f.setRowSpan(l);const d=new Set([f.getKey()]);for(let g=r;g<=o;g++)for(let h=s;h<=i;h++){const _=t[g][h];if(!_.cell)continue;const m=_.cell,b=m.getKey();d.has(b)||(d.add(b),IC(m)||f.append(...m.getChildren()),m.remove())}return f.getChildrenSize()===0&&f.append(ne()),f}function IC(n){if(n.getChildrenSize()!==1)return!1;const e=n.getFirstChildOrThrow();return!(!ht(e)||!e.isEmpty())}function v_(){const n=D();F(n)||ae(n)||G(188);const e=n.anchor.getNode(),t=re(e,J);return J(t)||G(148),cu(t)}function cu(n){const[e,t,r]=We(n),o=e.__colSpan,s=e.__rowSpan;if(o===1&&s===1)return;const[i,a]=ct(r,e,e),{startColumn:l,startRow:c}=a,u=e.__headerState&te.COLUMN,f=Array.from({length:o},(h,_)=>{let m=u;for(let b=0;m!==0&&b<i.length;b++)m&=i[b][_+l].cell.__headerState;return m}),d=e.__headerState&te.ROW,g=Array.from({length:s},(h,_)=>{let m=d;for(let b=0;m!==0&&b<i[0].length;b++)m&=i[_+c][b].cell.__headerState;return m});if(o>1){for(let h=1;h<o;h++)e.insertAfter(lt(f[h]|g[0]).append(ne()));e.setColSpan(1)}if(s>1){let h;for(let _=1;_<s;_++){const m=c+_,b=i[m];h=(h||t).getNextSibling(),ce(h)||G(125);let w=null;for(let C=0;C<l;C++){const v=b[C],k=v.cell;v.startRow===m&&(w=k),k.__colSpan>1&&(C+=k.__colSpan-1)}if(w===null)for(let C=o-1;C>=0;C--)au(h,lt(f[C]|g[_]).append(ne()));else for(let C=o-1;C>=0;C--)w.insertAfter(lt(f[C]|g[_]).append(ne()))}e.setRowSpan(1)}}function ct(n,e,t){const[r,o,s]=at(n,e,t);return o===null&&G(207),s===null&&G(208),[r,o,s]}function at(n,e,t){const r=[];let o=null,s=null;function i(l){let c=r[l];return c===void 0&&(r[l]=c=[]),c}const a=n.getChildren();for(let l=0;l<a.length;l++){const c=a[l];ce(c)||G(209);const u=i(l);for(let f=c.getFirstChild(),d=0;f!=null;f=f.getNextSibling()){for(J(f)||G(147);u[d]!==void 0;)d++;const g={cell:f,startColumn:d,startRow:l},{__rowSpan:h,__colSpan:_}=f;for(let m=0;m<h&&!(l+m>=a.length);m++){const b=i(l+m);for(let w=0;w<_;w++)b[d+w]=g}e!==null&&o===null&&e.is(f)&&(o=g),t!==null&&s===null&&t.is(f)&&(s=g)}}return[r,o,s]}function We(n){let e;if(n instanceof Gt)e=n;else if("__type"in n){const o=re(n,J);J(o)||G(148),e=o}else{const o=re(n.getNode(),J);J(o)||G(148),e=o}const t=e.getParent();ce(t)||G(149);const r=t.getParent();return be(r)||G(210),[e,t,r]}function Ns(n,e,t){let r,o=Math.min(e.startColumn,t.startColumn),s=Math.min(e.startRow,t.startRow),i=Math.max(e.startColumn+e.cell.__colSpan-1,t.startColumn+t.cell.__colSpan-1),a=Math.max(e.startRow+e.cell.__rowSpan-1,t.startRow+t.cell.__rowSpan-1);do{r=!1;for(let l=0;l<n.length;l++)for(let c=0;c<n[0].length;c++){const u=n[l][c];if(!u)continue;const f=u.startColumn+u.cell.__colSpan-1,d=u.startRow+u.cell.__rowSpan-1,g=u.startColumn<=i&&f>=o,h=u.startRow<=a&&d>=s;if(g&&h){const _=Math.min(o,u.startColumn),m=Math.max(i,f),b=Math.min(s,u.startRow),w=Math.max(a,d);_===o&&m===i&&b===s&&w===a||(o=_,i=m,s=b,a=w,r=!0)}}}while(r);return{maxColumn:i,maxRow:a,minColumn:o,minRow:s}}function uu(n){const e=n.getChildren();let t=null;for(const r of e){if(!ce(r)||(t===null&&(t=r.getChildrenSize()),r.getChildrenSize()!==t))return!1;const o=r.getChildren();for(const s of o)if(!J(s)||s.getRowSpan()!==1||s.getColSpan()!==1)return!1}return(t||0)>0}function EC(n,e,t){if(e===t)return;const r=n.getColumnCount();if(e<0||e>=r||t<0||t>=r||!uu(n))return;n.getChildren().filter(ce).forEach(s=>{const i=s.getChildren(),[a]=i.splice(e,1);i.splice(t,0,a),s.splice(0,i.length,i)});const o=n.getColWidths();if(o&&o.length===r){const s=[...o],[i]=s.splice(e,1);s.splice(t,0,i),n.setColWidths(s)}}function NC(n,e,t){if(e===t)return;const r=n.getChildren().filter(ce),o=r.length;if(e<0||e>=o||t<0||t>=o||!uu(n))return;const s=r[e],i=r[t];t>e?i.insertAfter(s):i.insertBefore(s)}function Ql(n){const[e,,t]=We(n),r=t.getChildren().filter(ce),o=r.length,s=r[0].getChildren().length,i=new Array(o);for(let a=0;a<o;a++)i[a]=new Array(s);for(let a=0;a<o;a++){const l=r[a].getChildren().filter(J);let c=0;for(let u=0;u<l.length;u++){for(;i[a][c];)c++;const f=l[u],d=f.__rowSpan||1,g=f.__colSpan||1;for(let h=0;h<d;h++)for(let _=0;_<g;_++)i[a+h][c+_]=f;if(e===f)return{colSpan:g,columnIndex:c,rowIndex:a,rowSpan:d};c+=g}}return null}function k_(n,e){const t=e.getStartEndPoints(),r=ae(e);if(t===null)return!1;const[o,s]=t,[i,a,l]=We(o),c=re(s.getNode(),R=>J(R));if(!(J(i)&&J(c)&&ce(a)&&be(l)))return!1;const[u,f,d]=ct(l,i,c),[g]=at(n,null,null),h=u.length,_=h>0?u[0].length:0;let m=f.startRow,b=f.startColumn,w=g.length,C=w>0?g[0].length:0;if(r){const R=Ns(u,f,d),$=R.maxRow-R.minRow+1,L=R.maxColumn-R.minColumn+1;m=R.minRow,b=R.minColumn,w=Math.min(w,$),C=Math.min(C,L)}let v=!1;const k=Math.min(h,m+w)-1,I=Math.min(_,b+C)-1,E=new Set;for(let R=m;R<=k;R++)for(let $=b;$<=I;$++){const L=u[R][$];E.has(L.cell.getKey())||L.cell.__rowSpan===1&&L.cell.__colSpan===1||(cu(L.cell),E.add(L.cell.getKey()),v=!0)}let[N]=at(l.getWritable(),null,null);const O=w-h+m;for(let R=0;R<O;R++)Ui(N[h-1][0].cell);const M=C-_+b;for(let R=0;R<M;R++)zi(N[0][_-1].cell,!0,!1);[N]=at(l.getWritable(),null,null);for(let R=m;R<m+w;R++)for(let $=b;$<b+C;$++){const L=R-m,A=$-b,B=g[L][A];if(B.startRow!==L||B.startColumn!==A)continue;const j=B.cell;if(j.__rowSpan!==1||j.__colSpan!==1){const H=[],ie=Math.min(R+j.__rowSpan,m+w)-1,Ne=Math.min($+j.__colSpan,b+C)-1;for(let Ce=R;Ce<=ie;Ce++)for(let ut=$;ut<=Ne;ut++){const Mn=N[Ce][ut];H.push(Mn.cell)}lu(H),v=!0}const{cell:U}=N[R][$],z=j.getBackgroundColor();z!=null&&U.setBackgroundColor(z);const K=U.getChildren();j.getChildren().forEach(H=>{oe(H)&&ne().append(H),U.append(H)}),K.forEach(H=>H.remove())}if(r&&v){const[R]=at(l.getWritable(),null,null);R[f.startRow][f.startColumn].cell.selectEnd()}return!0}function LC(n,e,t){const[r]=at(n,null,null);e>=0&&e<r.length||G(396,String(e));const o=r[e],s=t?te.ROW:te.NO_STATUS,i=new Set;for(let a=0;a<o.length;a++){const l=o[a];l!=null&&(i.has(l.cell)||(i.add(l.cell),l.cell.setHeaderStyles(s,te.ROW)))}}function OC(n,e,t){const[r]=at(n,null,null);r.length>0&&e>=0&&e<r[0].length||G(397,String(e));const o=t?te.COLUMN:te.NO_STATUS,s=new Set;for(let i=0;i<r.length;i++){const a=r[i][e];a!=null&&(s.has(a.cell)||(s.add(a.cell),a.cell.setHeaderStyles(o,te.COLUMN)))}}function Wa(n){const[[e,t,r,o],[s,i,a,l]]=["anchor","focus"].map(c=>{const u=n[c].getNode(),f=re(u,J);J(f)||G(238,c,u.getKey(),u.getType());const d=f.getParent();ce(d)||G(239,c);const g=d.getParent();return be(g)||G(240,c),[u,f,d,g]});return o.is(l)||G(241),{anchorCell:t,anchorNode:e,anchorRow:r,anchorTable:o,focusCell:i,focusNode:s,focusRow:a,focusTable:l}}class Vs{tableKey;anchor;focus;_cachedNodes;dirty;constructor(e,t,r){this.anchor=t,this.focus=r,t._selection=this,r._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){if(this.tableKey==="root"||this.anchor.key==="root"||this.anchor.type!=="element"||this.focus.key==="root"||this.focus.type!=="element")return!1;const e=Q(this.tableKey),t=Q(this.anchor.key),r=Q(this.focus.key);return e!==null&&t!==null&&r!==null}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return ae(e)&&this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus)}set(e,t,r){this.dirty=this.dirty||e!==this.tableKey||t!==this.anchor.key||r!==this.focus.key,this.tableKey=e,this.anchor.key=t,this.focus.key=r,this._cachedNodes=null}clone(){return new Vs(this.tableKey,un(this.anchor.key,this.anchor.offset,this.anchor.type),un(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){if(e==="")return;const t=(e.endsWith(`
10
10
  `)?e.slice(0,-1):e).split(`
11
11
  `).map(s=>s.split(" ")),r=Ho();for(const s of t){const i=pn();for(const a of s){const l=lt(te.NO_STATUS),c=ne();a&&c.append($e(a)),l.append(c),i.append(l)}r.append(i)}const{anchorCell:o}=Wa(this);k_(r,o.select(0,o.getChildrenSize()))}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(J).forEach(o=>{const s=o.getFirstChild();ht(s)&&(t|=s.getTextFormat())});const r=rh[e];return(t&r)!==0}insertNodes(e){const t=this.focus.getNode();q(t)||G(151),Ss(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=Wa(this),r=Ql(e);r===null&&G(153);const o=Ql(t);o===null&&G(155);const s=Math.min(r.columnIndex,o.columnIndex),i=Math.max(r.columnIndex+r.colSpan-1,o.columnIndex+o.colSpan-1),a=Math.min(r.rowIndex,o.rowIndex),l=Math.max(r.rowIndex+r.rowSpan-1,o.rowIndex+o.rowSpan-1);return{fromX:Math.min(s,i),fromY:Math.min(a,l),toX:Math.max(s,i),toY:Math.max(a,l)}}getNodes(){if(!this.isValid())return[];const e=this._cachedNodes;if(e!==null)return e;const{anchorTable:t,anchorCell:r,focusCell:o}=Wa(this),s=o.getParents()[1];if(s!==t){if(t.isParentOf(o)){const m=s.getParent();m==null&&G(159),this.set(this.tableKey,o.getKey(),m.getKey())}else{const m=t.getParent();m==null&&G(158),this.set(this.tableKey,m.getKey(),o.getKey())}return this.getNodes()}const[i,a,l]=ct(t,r,o),{minColumn:c,maxColumn:u,minRow:f,maxRow:d}=Ns(i,a,l),g=new Map([[t.getKey(),t]]);let h=null;for(let m=f;m<=d;m++)for(let b=c;b<=u;b++){const{cell:w}=i[m][b],C=w.getParent();ce(C)||G(160),C!==h&&(g.set(C.getKey(),C),h=C),g.has(w.getKey())||AC(w,v=>{g.set(v.getKey(),v)})}const _=Array.from(g.values());return Fy()||(this._cachedNodes=_),_}getTextContent(){const e=this.getNodes().filter(r=>J(r));let t="";for(let r=0;r<e.length;r++){const o=e[r],s=o.__parent,i=(e[r+1]||{}).__parent;t+=o.getTextContent()+(i!==s?`
12
12
  `:" ")}return t}}function ae(n){return n instanceof Vs}function RC(){const n=un("root",0,"element"),e=un("root",0,"element");return new Vs("root",n,e)}function Ki(n,e,t){n.getKey(),e.getKey(),t.getKey();const r=D(),o=ae(r)?r.clone():new Vs("root",un("root",0,"element"),un("root",0,"element"));return o.set(n.getKey(),e.getKey(),t.getKey()),o}function AC(n,e){const t=[[n]];for(let r=t.at(-1);r!==void 0&&t.length>0;r=t.at(-1)){const o=r.pop();o===void 0?t.pop():e(o)!==!1&&q(o)&&t.push(o.getChildren())}}function du(n,e=zo()){const t=Q(n);be(t)||G(231,n);const r=kt(t,e.getElementByKey(n));return r===null&&G(232,n),{tableElement:r,tableNode:t}}class MC{observers;nextFocus;shouldCheckSelectionForTable;constructor(){this.observers=new Map,this.nextFocus=null,this.shouldCheckSelectionForTable=null}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return e!==null&&(this.nextFocus=null),e}setShouldCheckSelectionForTable(e){this.shouldCheckSelectionForTable=e}getAndClearShouldCheckSelectionForTable(){const{shouldCheckSelectionForTable:e}=this;return e?(this.shouldCheckSelectionForTable=null,e):null}removeObserver(e){const t=this.observers.get(e);return t!==void 0&&(t[0].removeListeners(),this.observers.delete(e),!0)}removeAllObservers(){for(const e of Array.from(this.observers.keys()))this.removeObserver(e)}$getTableNodesAndObservers(){const e=[];for(const[t,[r]]of Array.from(this.observers.entries())){const o=Q(t);be(o)?e.push([o,r]):this.removeObserver(t)}return e}}class T_{focusX;focusY;listenersToRemove;table;isHighlightingCells;anchorX;anchorY;tableNodeKey;anchorCell;focusCell;anchorCellNodeKey;focusCellNodeKey;editor;tableSelection;hasHijackedSelectionStyles;isSelecting;pointerType;abortController;listenerOptions;constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.pointerType=null,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach(e=>e()),this.listenersToRemove.clear()}$lookup(){return du(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver(t=>{this.editor.read("latest",()=>{let r=!1;for(let i=0;i<t.length;i++){const a=t[i].target.nodeName;if(a==="TABLE"||a==="TBODY"||a==="THEAD"||a==="TR"){r=!0;break}}if(!r)return;const{tableNode:o,tableElement:s}=this.$lookup();this.table=vo(o,s)})});this.editor.read("latest",()=>{const{tableNode:t,tableElement:r}=this.$lookup();this.table=vo(t,r),e.observe(r,{attributes:!0,childList:!0,subtree:!0})})}$clearHighlight(e=!0){const t=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:r,tableElement:o}=this.$lookup();li(t,vo(r,o),null),e&&D()!==null&&(Ee(null),t.dispatchCommand(Ht))}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();$t(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:e}=this.$lookup();Ie(e,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(e!==null){e.tableKey!==this.tableNodeKey&&G(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),li(t,this.table,this.tableSelection)}else this.$clearHighlight()}updateDOMSelection(){if(this.anchorCell!==null&&this.focusCell!==null){const e=or(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,t=!1){const r=this.editor,{tableNode:o}=this.$lookup(),s=e.x,i=e.y;if(this.focusCell=e,!this.isHighlightingCells&&(t||this.anchorX!==s||this.anchorY!==i||this.tableSelection!=null&&this.anchorCellNodeKey!=null)&&(this.isHighlightingCells=!0,this.$disableHighlightStyle()),this.focusX!==-1&&this.focusY!==-1&&s===this.focusX&&i===this.focusY)return!1;if(this.focusX=s,this.focusY=i,this.isHighlightingCells){const a=tc(o,e.elem);if(this.tableSelection!=null&&this.anchorCellNodeKey!=null){let l=a;if(l===null&&t&&(l=o.getCellNodeFromCords(s,i,this.table)),l!==null){const c=this.$getAnchorTableCellOrThrow();return this.focusCellNodeKey=l.getKey(),this.tableSelection=Ki(o,c,l),Ee(this.tableSelection),r.dispatchCommand(Ht),li(r,this.table,this.tableSelection),!0}}}return!1}$getAnchorTableCell(){const e=this.anchorCellNodeKey?Q(this.anchorCellNodeKey):null;return J(e)?e:null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return e===null&&G(234),e}$getFocusTableCell(){const e=this.focusCellNodeKey?Q(this.focusCellNodeKey):null;return J(e)?e:null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return e===null&&G(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.focusX=-1,this.focusY=-1,this.focusCell=null,this.focusCellNodeKey=null;const{tableNode:t}=this.$lookup(),r=tc(t,e.elem);if(r!==null){const o=r.getKey();this.tableSelection!=null?(this.tableSelection=this.tableSelection.clone(),this.tableSelection.set(t.getKey(),o,o)):this.tableSelection=Ki(t,r,r),this.anchorCellNodeKey=o}}$formatCells(e){const t=D();ae(t)||G(236);const r=kr(),o=r.anchor,s=r.focus,i=t.getNodes().filter(J);i.length>0||G(237);const a=i[0].getFirstChild(),l=ht(a)?a.getFormatFlags(e,null):null;i.forEach(c=>{o.set(c.getKey(),0,"element"),s.set(c.getKey(),c.getChildrenSize(),"element"),r.formatText(e,l)}),Ee(t),this.editor.dispatchCommand(Ht)}$clearText(){const{editor:e}=this,t=Q(this.tableNodeKey);if(!be(t))throw new Error("Expected TableNode.");const r=D();ae(r)||G(253);const o=r.getNodes().filter(J),s=t.getFirstChild(),i=t.getLastChild();if(o.length>0&&s!==null&&i!==null&&ce(s)&&ce(i)&&o[0]===s.getFirstChild()&&o[o.length-1]===i.getLastChild()){t.selectPrevious();const a=t.getParent();return t.remove(),void(Jp(a)&&a.isEmpty()&&e.dispatchCommand(Lo))}o.forEach(a=>{if(q(a)){const l=ne(),c=$e();l.append(c),a.append(l),a.getChildren().forEach(u=>{u!==l&&u.remove()})}}),li(e,this.table,null),Ee(null),e.dispatchCommand(Ht)}}const So="__lexicalTableSelection";function I_(n){const e=Wy(n);return be(e)||G(386,n),e}const ro=40;function Ha(n,e,t){const r=o=>Math.max(1,Math.ceil(Math.min(ro,o)/ro*18));return n<=e+ro?-r(e+ro-n):n>=t-ro?r(n-(t-ro)):0}function Fn(n){return ke(n)&&n.nodeName==="TABLE"}function kt(n,e){if(!e)return e;const t=Fn(e)?e:e.querySelector("table");return Fn(t)||G(341,n.constructor.name,n.getType(),n.getKey(),e.nodeName),t}function ha(n){return n._window}function _a(n,e){for(let t=e,r=null;t!==null;t=t.getParent()){if(n.is(t))return r;J(t)&&(r=t)}return null}const $C=[[Vt,"down"],[pt,"up"],[zs,"backward"],[ia,"forward"]],DC=[Yp,Vp,bi],PC=[sa,Oc];function jC(n,e){return n.registerRootListener(t=>{if(t===null)return;const r=n._window;if(r!==null)return Jt(r,"pointerdown",o=>{const s=Oo(o);if(o.button!==0||!No(s)||!t.contains(s))return;const i=(function(a){const l=Do(a);if(l===null)return null;let c=l.elem;for(;c!=null;){if(c.nodeName==="TABLE"&&So in c&&c[So])return{cellElement:l,tableElement:c,tableObserver:c[So]};c=c.parentNode}return null})(s);n.update(()=>{if(ae(D())){for(const[u]of e.observers.values())u.$clearHighlight(!1);Ee(null),n.dispatchCommand(Ht)}if(!i)return;const{tableObserver:a,tableElement:l,cellElement:c}=i;(function(u,f,d,g,h,_){const m=u._window;if(!m)return;const b=v=>{if(h.isSelecting)return;h.isSelecting=!0,v!==null&&h.anchorCell===null&&u.update(()=>{h.$setAnchorCellForSelection(v)});let k=f.clientX,I=f.clientY,E=null;const N=()=>{h.isSelecting=!1,E!==null&&(m.cancelAnimationFrame(E),E=null),m.removeEventListener("pointerup",U),m.removeEventListener("pointermove",z)},O=(K,H)=>{const ie=g.getRootNode();if(!Dp(ie)&&!jc(ie))return null;for(const Ne of ie.elementsFromPoint(K,H)){const Ce=xf(g,Ne);if(Ce)return Ce}return null},M=(K,H)=>{h.anchorCell===null&&u.update(()=>{h.$setAnchorCellForSelection(K)}),h.focusCell!==null&&K.elem===h.focusCell.elem||(_.setNextFocus({focusCell:K,override:H,tableKey:h.tableNodeKey}),u.dispatchCommand(Ht))},R=K=>{for(let H=g.parentElement;H;H=H.parentElement)if(K==="x"?H.scrollWidth>H.clientWidth:H.scrollHeight>H.clientHeight){const ie=m.getComputedStyle(H),Ne=K==="x"?ie.overflowX:ie.overflowY;if(Ne==="auto"||Ne==="scroll")return H}return null},$=(K,H,ie)=>{let Ne,Ce;if(K===null)Ne=0,Ce=ie==="x"?m.innerWidth:m.innerHeight;else{const nn=K.getBoundingClientRect();Ne=ie==="x"?nn.left:nn.top,Ce=ie==="x"?nn.right:nn.bottom}const ut=Ha(H,Ne,Ce);if(ut===0)return!1;if(K===null){const nn=ie==="x"?m.scrollX:m.scrollY;return m.scrollBy(ie==="x"?ut:0,ie==="x"?0:ut),(ie==="x"?m.scrollX:m.scrollY)!==nn}if(ie==="x"){const nn=K.scrollLeft;return K.scrollLeft+=ut,K.scrollLeft!==nn}const Mn=K.scrollTop;return K.scrollTop+=ut,K.scrollTop!==Mn},L=(K,H)=>{let ie=k,Ne=I;if(K===null)ie=Math.min(Math.max(ie,1),m.innerWidth-1);else{const Ce=K.getBoundingClientRect();ie=Math.min(Math.max(ie,Ce.left+1),Ce.right-1)}if(H===null)Ne=Math.min(Math.max(Ne,1),m.innerHeight-1);else{const Ce=H.getBoundingClientRect();Ne=Math.min(Math.max(Ne,Ce.top+1),Ce.bottom-1)}return[ie,Ne]},A=()=>{const K=R("x");if(K!==null){const Ce=K.getBoundingClientRect();if(Ha(k,Ce.left,Ce.right)!==0)return!0}const H=R("y"),ie=H===null?0:H.getBoundingClientRect().top,Ne=H===null?m.innerHeight:H.getBoundingClientRect().bottom;return Ha(I,ie,Ne)!==0},B=()=>{if(E=null,!h.isSelecting)return;const K=R("x"),H=R("y"),ie=K!==null&&$(K,k,"x"),Ne=$(H,I,"y");if(ie||Ne){const[Ce,ut]=L(K,H),Mn=O(Ce,ut);Mn&&M(Mn,!1),E=m.requestAnimationFrame(B)}},j=()=>{E===null&&h.pointerType!=="touch"&&A()&&(E=m.requestAnimationFrame(B))},U=()=>{N()},z=K=>{if(!(Ce=>!(1&~Ce.buttons))(K)&&h.isSelecting)return void N();const H=Oo(K);if(!No(H))return;k=K.clientX,I=K.clientY;let ie=null;const Ne=!(Ed||g.contains(H));ie=Ne?xf(g,H):O(K.clientX,K.clientY),ie&&M(ie,Ne),j()};m.addEventListener("pointerup",U,h.listenerOptions),m.addEventListener("pointermove",z,h.listenerOptions)};h.pointerType=f.pointerType;const w=I_(h.tableNodeKey),C=mo();if(Ed&&f.shiftKey&&Ut(C,w)&&(F(C)||ae(C))){const v=C.anchor.getNode(),k=_a(w,C.anchor.getNode());k?(h.$setAnchorCellForSelection(mr(h,k)),h.$setFocusCellForSelection(d),yn(f)):(w.isBefore(v)?w.selectStart():w.selectEnd()).anchor.set(C.anchor.key,C.anchor.offset,C.anchor.type)}else f.pointerType!=="touch"&&h.$setAnchorCellForSelection(d);b(d)})(n,o,c,l,a,e)})})})}function E_(n,e,t,r,o){const s=t.getRootElement(),i=ha(t);s!==null&&i!==null||G(246);const a=new T_(t,n.getKey()),l=kt(n,e);(function(d,g){$o(d)!==null&&G(205),d[So]=g})(l,a),a.listenersToRemove.add(()=>(function(d,g){$o(d)===g&&delete d[So]})(l,a)),a.listenersToRemove.add(Jt(l,"mousedown",d=>{const g=Oo(d);d.detail>=3&&No(g)&&Do(g)!==null&&d.preventDefault()},a.listenerOptions));for(const[d,g]of $C)a.listenersToRemove.add(t.registerCommand(d,h=>O_(t,h,g,n,a,o),qe));a.listenersToRemove.add(t.registerCommand(Nn,d=>{const g=D();if(ae(g)){const h=_a(n,g.focus.getNode());if(h!==null)return yn(d),h.selectEnd(),!0}return!1},qe));const c=()=>{const d=D();return!!Ut(d,n)&&!!ae(d)&&(a.$clearText(),!0)};for(const d of DC)a.listenersToRemove.add(t.registerCommand(d,c,qe));const u=d=>{const g=D();if(!ae(g)&&!F(g))return!1;const h=n.isParentOf(g.anchor.getNode());if(h!==n.isParentOf(g.focus.getNode())){const _=h?"anchor":"focus",m=h?"focus":"anchor",{key:b,offset:w,type:C}=g[m];return n[g[_].isBefore(g[m])?"selectPrevious":"selectNext"]()[m].set(b,w,C),!1}return!!Ut(g,n)&&!!ae(g)&&(d&&(d.preventDefault(),d.stopPropagation()),a.$clearText(),!0)};for(const d of PC)a.listenersToRemove.add(t.registerCommand(d,u,qe));a.listenersToRemove.add(t.registerCommand(zp,d=>{const g=D();if(g){if(!ae(g)&&!F(g))return!1;Il(t,fo(d,ClipboardEvent)?d:null,Hp(g));const h=u(d);return F(g)?(g.removeText(),!0):h}return!1},qe));const f=s.ownerDocument;return a.listenersToRemove.add(Jt(f,"paste",d=>{d.defaultPrevented||t.read("latest",()=>{const g=D();return s.contains(f.activeElement)&&ae(g)&&Ut(g,n)})&&(d.preventDefault(),t.dispatchCommand(Ic,d))})),a.listenersToRemove.add(Jt(f,"copy",d=>{if(d.defaultPrevented)return;const g=Oo(d);g===s||No(g)&&s.contains(g)||t.read("latest",()=>{const h=D();return s.contains(la(s))&&ae(h)&&Ut(h,n)})&&(d.preventDefault(),t.dispatchCommand(Kp,d))})),a.listenersToRemove.add(t.registerCommand(Xe,d=>{const g=D();return!!Ut(g,n)&&!!ae(g)&&(a.$formatCells(d),!0)},qe)),a.listenersToRemove.add(t.registerCommand(Bn,d=>{const g=D();if(!ae(g)||!Ut(g,n))return!1;const h=g.anchor.getNode(),_=g.focus.getNode();if(!J(h)||!J(_))return!1;const[m,b,w]=ct(n,h,_),C=Math.max(b.startRow+b.cell.__rowSpan-1,w.startRow+w.cell.__rowSpan-1),v=Math.max(b.startColumn+b.cell.__colSpan-1,w.startColumn+w.cell.__colSpan-1),k=Math.min(b.startRow,w.startRow),I=Math.min(b.startColumn,w.startColumn);if(k===0&&I===0&&C===m.length-1&&v===m[0].length-1)return n.setFormat(d),!0;const E=new Set;for(let N=k;N<=C;N++)for(let O=I;O<=v;O++){const M=m[N][O].cell;if(E.has(M))continue;E.add(M),M.setFormat(d);const R=M.getChildren();for(let $=0;$<R.length;$++){const L=R[$];q(L)&&!L.isInline()&&L.setFormat(d)}}return!0},qe)),a.listenersToRemove.add(t.registerCommand(qp,d=>{const g=D();if(!Ut(g,n))return!1;if(ae(g))return a.$clearHighlight(),!1;if(F(g)){const h=re(g.anchor.getNode(),_=>J(_));if(!J(h))return!1;if(typeof d=="string"){const _=Sf(t,g,n);if(_)return Cf(_,n,[$e(d)]),!0}}return!1},qe)),r&&a.listenersToRemove.add(t.registerCommand(Kr,d=>{const g=D();if(!F(g)||!g.isCollapsed()||!Ut(g,n))return!1;const h=ho(g.anchor.getNode());return!(h===null||!n.is(Or(h)))&&(yn(d),(function(_,m){const b=m==="next"?"getNextSibling":"getPreviousSibling",w=m==="next"?"getFirstChild":"getLastChild",C=_[b]();if(q(C))return C.selectEnd();const v=re(_,ce);v===null&&G(247);for(let I=v[b]();ce(I);I=I[b]()){const E=I[w]();if(q(E))return E.selectEnd()}const k=re(v,be);k===null&&G(248),m==="next"?k.selectNext():k.selectPrevious()})(h,d.shiftKey?"previous":"next"),!0)},qe)),a.listenersToRemove.add(t.registerCommand(oh,d=>n.isSelected(),qe)),a.listenersToRemove.add(t.registerCommand(Lo,()=>{const d=D();if(!F(d)||!d.isCollapsed()||!Ut(d,n))return!1;const g=Sf(t,d,n);return!!g&&(Cf(g,n),!0)},qe)),a}function FC(n,e){const t=D(),r=mo(),o=n.getAndClearNextFocus();if(o!==null){const{tableKey:i,focusCell:a}=o,l=n.observers.get(i);l||G(335,i);const[c]=l;if(ae(t)&&t.tableKey===c.tableNodeKey)return(a.x!==c.focusX||a.y!==c.focusY)&&(c.$setFocusCellForSelection(a),!0);if(c.anchorCell!==null&&c.anchorCellNodeKey!==null&&a.elem!==c.anchorCell.elem&&c.tableSelection!==null)return c.$setFocusCellForSelection(a,!0),!0}const s=n.getAndClearShouldCheckSelectionForTable();if(s&&F(r)&&F(t)&&t.isCollapsed()){const i=Q(s);if(be(i)){const a=t.anchor.getNode(),l=i.getFirstChild(),c=ho(a);if(c!==null&&ce(l)){const u=l.getFirstChild();if(J(u)&&i.is(re(c,f=>f.is(i)||f.is(u))))return u.selectStart(),!0}}}ae(t)&&(function(i,a){const l=ha(i),c=mo();if(!a.is(c))return;const u=I_(a.tableKey),f=or(l),d=f&&Pc(f,i.getRootElement());if(f&&d&&d.anchorNode&&d.focusNode){const g=Ae(d.focusNode),h=g&&!u.isParentOf(g),_=Ae(d.anchorNode),m=_&&u.isParentOf(_);if(h&&m&&f.rangeCount>0){const b=Uy(f,i);b&&(b.anchor.set(u.getKey(),a.isBackward()?u.getChildrenSize():0,"element"),f.removeAllRanges(),Ee(b))}}})(e,t),F(t)&&(function(i,a){const l=mo(),{anchor:c,focus:u}=i,f=c.getNode(),d=u.getNode(),g=ho(f),h=ho(d),_=g?Or(g):null,m=h?Or(h):null,b=i.isBackward(),w=g&&h&&_&&m&&_.is(m),C=m&&(!_||_.isParentOf(m)),v=_&&(!m||m.isParentOf(_));if(C){const k=i.clone(),[I]=ct(m,h,h),E=I[0][0].cell,N=I[I.length-1].at(-1).cell;k.focus.set(b?E.getKey():N.getKey(),b?0:N.getChildrenSize(),"element"),Ee(k)}else if(v){const k=i.clone(),[I]=ct(_,g,g),E=I[0][0].cell,N=I[I.length-1].at(-1).cell;k.anchor.set(b?N.getKey():E.getKey(),b?N.getChildrenSize():0,"element"),Ee(k)}else if(w){const k=a.observers.get(_.getKey());k||G(335,_.getKey());const[I]=k;if(g.is(h)||(I.$setAnchorCellForSelection(mr(I,g)),I.$setFocusCellForSelection(mr(I,h),!0)),I.pointerType==="touch"&&I.isSelecting&&i.isCollapsed()&&F(l)&&l.isCollapsed()){const E=ho(l.anchor.getNode());E&&!E.is(h)&&(I.$setAnchorCellForSelection(mr(I,E)),I.$setFocusCellForSelection(mr(I,h),!0),I.pointerType=null)}}})(t,n);for(const[i,a]of n.$getTableNodesAndObservers())BC(e,i,a);return!1}function BC(n,e,t){const r=D(),o=mo();r&&!r.is(o)&&(ae(r)||ae(o))&&t.tableSelection&&!t.tableSelection.is(o)&&(ae(r)&&r.tableKey===t.tableNodeKey?t.$updateTableTableSelection(r):!ae(r)&&ae(o)&&o.tableKey===t.tableNodeKey&&t.$updateTableTableSelection(null)),t.hasHijackedSelectionStyles&&!e.isSelected()?(function(s,i){i.$enableHighlightStyle(),ec(i.table,a=>{const l=a.elem;a.highlighted=!1,L_(s,a),l.getAttribute("style")||l.removeAttribute("style")})})(n,t):!t.hasHijackedSelectionStyles&&e.isSelected()&&(function(s,i){i.$disableHighlightStyle(),ec(i.table,a=>{a.highlighted=!0,N_(s,a)})})(n,t)}function $o(n){return n[So]||null}function Do(n){let e=n;for(;e!=null;){const t=e.nodeName;if(t==="TD"||t==="TH"){const r=e._cell;return r===void 0?null:r}e=e.parentNode}return null}function xf(n,e){if(!n.contains(e))return null;let t=null;for(let r=e;r!=null;r=r.parentNode){if(r===n)return t;const o=r.nodeName;o!=="TD"&&o!=="TH"||(t=r._cell||null)}return null}function vo(n,e){const t=[],r={columns:0,domRows:t,rows:0};let o=kt(n,e).querySelector("tr"),s=0,i=0;for(t.length=0;o!=null;){const a=o.nodeName;if(a==="TD"||a==="TH"){const u={elem:o,hasBackgroundColor:o.style.backgroundColor!=="",highlighted:!1,x:s,y:i};o._cell=u;let f=t[i];f===void 0&&(f=t[i]=[]),f[s]=u}else{const u=o.firstChild;if(u!=null){o=u;continue}}const l=o.nextSibling;if(l!=null){s++,o=l;continue}const c=o.parentNode;if(c!=null){const u=c.nextSibling;if(u==null)break;i++,s=0,o=u}}return r.columns=s+1,r.rows=i+1,r}function li(n,e,t){const r=new Set(t?t.getNodes():[]);ec(e,(o,s)=>{const i=o.elem;r.has(s)?(o.highlighted=!0,N_(n,o)):(o.highlighted=!1,L_(n,o),i.getAttribute("style")||i.removeAttribute("style"))})}function ec(n,e){const{domRows:t}=n;for(let r=0;r<t.length;r++){const o=t[r];if(o)for(let s=0;s<o.length;s++){const i=o[s];if(!i)continue;const a=Ae(i.elem);a!==null&&e(i,a,{x:s,y:r})}}}const UC=(n,e,t,r,o)=>{const s=o==="forward";switch(o){case"backward":case"forward":return t!==(s?n.table.columns-1:0)?ui(e.getCellNodeFromCordsOrThrow(t+(s?1:-1),r,n.table),s):r!==(s?n.table.rows-1:0)?ui(e.getCellNodeFromCordsOrThrow(s?0:n.table.columns-1,r+(s?1:-1),n.table),s):s?e.selectNext():e.selectPrevious(),!0;case"up":return r!==0?ui(e.getCellNodeFromCordsOrThrow(t,r-1,n.table),!1):e.selectPrevious(),!0;case"down":return r!==n.table.rows-1?ui(e.getCellNodeFromCordsOrThrow(t,r+1,n.table),!0):e.selectNext(),!0;default:return!1}};function Ja(n,e){let t,r;if(e.startColumn===n.minColumn)t="minColumn";else{if(e.startColumn+e.cell.__colSpan-1!==n.maxColumn)return null;t="maxColumn"}if(e.startRow===n.minRow)r="minRow";else{if(e.startRow+e.cell.__rowSpan-1!==n.maxRow)return null;r="maxRow"}return[t,r]}function ci([n,e]){return[n==="minColumn"?"maxColumn":"minColumn",e==="minRow"?"maxRow":"minRow"]}function oo(n,e,[t,r]){const o=e[r],s=n[o];s===void 0&&G(250,r,String(o));const i=e[t],a=s[i];return a===void 0&&G(250,t,String(i)),a}function zC(n,e,t,r,o){const s=Ns(e,t,r),i=(function(I,E){const{minColumn:N,maxColumn:O,minRow:M,maxRow:R}=E;let $=1,L=1,A=1,B=1;const j=I[M],U=I[R];for(let z=N;z<=O;z++)$=Math.max($,j[z].cell.__rowSpan),B=Math.max(B,U[z].cell.__rowSpan);for(let z=M;z<=R;z++)L=Math.max(L,I[z][N].cell.__colSpan),A=Math.max(A,I[z][O].cell.__colSpan);return{bottomSpan:B,leftSpan:L,rightSpan:A,topSpan:$}})(e,s),{topSpan:a,leftSpan:l,bottomSpan:c,rightSpan:u}=i,f=(function(I,E){const N=Ja(I,E);return N===null&&G(249,E.cell.getKey()),N})(s,t),[d,g]=ci(f);let h=s[d],_=s[g];o==="forward"?h+=d==="maxColumn"?1:l:o==="backward"?h-=d==="minColumn"?1:u:o==="down"?_+=g==="maxRow"?1:a:o==="up"&&(_-=g==="minRow"?1:c);const m=e[_];if(m===void 0)return!1;const b=m[h];if(b===void 0)return!1;const[w,C]=(function(I,E,N){const O=Ns(I,E,N),M=Ja(O,E);if(M)return[oo(I,O,M),oo(I,O,ci(M))];const R=Ja(O,N);if(R)return[oo(I,O,ci(R)),oo(I,O,R)];const $=["minColumn","minRow"];return[oo(I,O,$),oo(I,O,ci($))]})(e,t,b),v=mr(n,w.cell),k=mr(n,C.cell);return n.$setAnchorCellForSelection(v),n.$setFocusCellForSelection(k,!0),!0}function Ut(n,e){if(F(n)||ae(n)){const t=e.isParentOf(n.anchor.getNode()),r=e.isParentOf(n.focus.getNode());return t&&r}return!1}function ui(n,e){e?n.selectStart():n.selectEnd()}function N_(n,e){const t=e.elem,r=n._config.theme;J(Ae(t))||G(131),Ie(t,r.tableCellSelected)}function L_(n,e){const t=e.elem;J(Ae(t))||G(131);const r=n._config.theme;$t(t,r.tableCellSelected)}function ho(n){const e=re(n,J);return J(e)?e:null}function Or(n){const e=re(n,be);return be(e)?e:null}function KC(n,e,t,r,o,s,i){const a=vs(t.focus,o?"previous":"next");if(zy(a))return!1;let l=a;for(const m of Ll(a).iterNodeCarets("shadowRoot")){if(!Mc(m)||!q(m.origin))return!1;l=m}const c=l.getParentAtCaret();if(!J(c))return!1;const u=c,f=(function(m){for(const b of Ll(m).iterNodeCarets("root")){const{origin:w}=b;if(J(w)){if(Nd(b))return Er(w,m.direction)}else if(!ce(w))break}return null})(gt(u,l.direction)),d=re(u,be);if(!d||!d.is(s))return!1;const g=n.getElementByKey(u.getKey()),h=Do(g);if(!g||!h)return!1;const _=A_(n,d);if(i.table=_,f)if(r==="extend"){const m=Do(n.getElementByKey(f.origin.getKey()));if(!m)return!1;i.$setAnchorCellForSelection(h),i.$setFocusCellForSelection(m,!0)}else{const m=Jn(f);hr(t.anchor,m),hr(t.focus,m)}else if(r==="extend")i.$setAnchorCellForSelection(h),i.$setFocusCellForSelection(h,!0);else{const m=(function(b){const w=Ky(b);return Nd(w)?Jn(w):b})(gt(d,a.direction));hr(t.anchor,m),hr(t.focus,m)}return yn(e),!0}function O_(n,e,t,r,o,s){if((t==="up"||t==="down")&&(function(a){const l=a.getRootElement();return l?l.hasAttribute("aria-controls")&&l.getAttribute("aria-controls")==="typeahead-menu":!1})(n))return!1;const i=D();if(!Ut(i,r)){if(F(i)){if(t==="backward"){if(i.focus.offset>0)return!1;const a=(function(c){for(let u=c,f=c;f!==null;u=f,f=f.getParent())if(q(f)){if(f!==u&&f.getFirstChild()!==u)return null;if(!f.isInline())return f}return null})(i.focus.getNode());if(!a)return!1;const l=a.getPreviousSibling();return!!be(l)&&(yn(e),e.shiftKey?i.focus.set(l.getParentOrThrow().getKey(),l.getIndexWithinParent(),"element"):l.selectEnd(),!0)}if(e.shiftKey&&(t==="up"||t==="down")){const a=i.focus.getNode();if(!i.isCollapsed()&&(t==="up"&&!i.isBackward()||t==="down"&&i.isBackward())){let l=re(a,g=>be(g));if(J(l)&&(l=re(l,be)),l!==r||!l)return!1;const c=t==="down"?l.getNextSibling():l.getPreviousSibling();if(!c)return!1;let u=0;t==="up"&&q(c)&&(u=c.getChildrenSize());let f=c;t==="up"&&q(c)&&(f=c.getLastChild()||c,u=oe(f)?f.getTextContentSize():0);const d=i.clone();return d.focus.set(f.getKey(),u,oe(f)?"text":"element"),Ee(d),yn(e),!0}if(wt(a)){const l=t==="up"?i.getNodes()[i.getNodes().length-1]:i.getNodes()[0];if(l&&_a(r,l)!==null){const c=r.getFirstDescendant(),u=r.getLastDescendant();if(!c||!u)return!1;const[f]=We(c),[d]=We(u),g=r.getCordsFromCellNode(f,o.table),h=r.getCordsFromCellNode(d,o.table),_=r.getDOMCellFromCordsOrThrow(g.x,g.y,o.table),m=r.getDOMCellFromCordsOrThrow(h.x,h.y,o.table);return o.$setAnchorCellForSelection(_),o.$setFocusCellForSelection(m,!0),!0}return!1}{let l=re(a,u=>q(u)&&!u.isInline());if(J(l)&&(l=re(l,be)),!l)return!1;const c=t==="down"?l.getNextSibling():l.getPreviousSibling();if(be(c)&&o.tableNodeKey===c.getKey()){const u=c.getFirstDescendant(),f=c.getLastDescendant();if(!u||!f)return!1;const[d]=We(u),[g]=We(f),h=i.clone();return h.focus.set((t==="up"?d:g).getKey(),t==="up"?0:g.getChildrenSize(),"element"),yn(e),Ee(h),!0}}}}return t==="down"&&Po(n)&&s.setShouldCheckSelectionForTable(r.getKey()),!1}if(F(i)){if(t==="backward"||t==="forward")return KC(n,e,i,e.shiftKey?"extend":"move",t==="backward",r,o);if(i.isCollapsed()){const{anchor:a,focus:l}=i,c=re(a.getNode(),J),u=re(l.getNode(),J);if(!J(c)||!c.is(u))return!1;const f=Or(c);if(f!==r&&f!=null){const w=kt(f,n.getElementByKey(f.getKey()));if(w!=null)return o.table=vo(f,w),O_(n,e,t,f,o,s)}const d=n.getElementByKey(c.__key),g=n.getElementByKey(a.key);if(g==null||d==null)return!1;let h;if(a.type==="element")h=g.getBoundingClientRect();else{const w=or(ha(n));if(w===null||w.rangeCount===0)return!1;const C=By(w,n.getRootElement());if(C===null)return!1;h=C.getBoundingClientRect()}const _=t==="up"?c.getFirstChild():c.getLastChild();if(_==null)return!1;const m=n.getElementByKey(_.__key);if(m==null)return!1;const b=m.getBoundingClientRect();if(t==="up"?b.top>h.top-h.height:h.bottom+h.height>b.bottom){yn(e);const w=r.getCordsFromCellNode(c,o.table);if(!e.shiftKey)return UC(o,r,w.x,w.y,t);{const C=r.getDOMCellFromCordsOrThrow(w.x,w.y,o.table);o.$setAnchorCellForSelection(C),o.$setFocusCellForSelection(C,!0)}return!0}}}else if(ae(i)){const{anchor:a,focus:l,tableKey:c}=i;if(c!==r.getKey())return!1;const u=re(a.getNode(),J),f=re(l.getNode(),J),[d]=i.getNodes();be(d)||G(251);const g=kt(d,n.getElementByKey(d.getKey()));if(!J(u)||!J(f)||!be(d)||g==null)return!1;o.$updateTableTableSelection(i);const h=vo(d,g),_=r.getCordsFromCellNode(u,h),m=r.getDOMCellFromCordsOrThrow(_.x,_.y,h);if(o.$setAnchorCellForSelection(m),yn(e),e.shiftKey){const[b,w,C]=ct(r,u,f);return zC(o,b,w,C,t)}return f.selectEnd(),!0}return!1}function yn(n){n.preventDefault(),n.stopImmediatePropagation(),n.stopPropagation()}function Cf(n,e,t){const r=ne();n==="first"?e.insertBefore(r):e.insertAfter(r),r.append(...t||[]),r.selectEnd()}function Sf(n,e,t){const r=t.getParent();if(!r)return;const o=or(ha(n));if(!o)return;const s=Pc(o,n.getRootElement()).anchorNode,i=n.getElementByKey(r.getKey()),a=kt(t,n.getElementByKey(t.getKey()));if(!s||!i||!a||!i.contains(s)||a.contains(s))return;const l=re(e.anchor.getNode(),w=>J(w));if(!l)return;const c=re(l,w=>be(w));if(!be(c)||!c.is(t))return;const[u,f]=ct(t,l,l),d=u[0][0],g=u[u.length-1][u[0].length-1],{startRow:h,startColumn:_}=f,m=h===d.startRow&&_===d.startColumn,b=h===g.startRow&&_===g.startColumn;return m?"first":b?"last":void 0}function mr(n,e){const{tableNode:t}=n.$lookup(),r=t.getCordsFromCellNode(e,n.table);return t.getDOMCellFromCordsOrThrow(r.x,r.y,n.table)}function tc(n,e,t){return _a(n,Ae(e,t))}function Wi(n){return ke(n)&&n.nodeName==="DIV"}function vf(n,e,t){let r=n.querySelector(":scope > colgroup");if(!t)return void(r&&r.remove());r||(r=Je().createElement("colgroup"),Rl(r),n.insertBefore(r,n.firstChild));const o=[];for(let s=0;s<e;s++){const i=Je().createElement("col"),a=t[s];a&&(i.style.width=`${a}px`),o.push(i)}r.replaceChildren(...o)}function kf(n,e,t){if(!e.theme.tableAlignment)return;const r=[],o=[];for(const s of["center","right"]){const i=e.theme.tableAlignment[s];i&&(s===t?o:r).push(i)}$t(n,...r),Ie(n,...o)}const R_=new WeakSet;function WC(n){const{scrollable:e,scrollbar:t,tableElement:r}=n;if(t.classList.length===0&&(function(a){const l=a.style.display;a.style.display="";const c=a.offsetHeight-a.clientHeight;return a.style.display=l,c})(t)===0)return R_.add(t),t.style.display="none",e.style.scrollbarWidth="auto",()=>{};const o=()=>{t.scrollLeft!==e.scrollLeft&&(t.scrollLeft=e.scrollLeft)},s=()=>{e.scrollLeft!==t.scrollLeft&&(e.scrollLeft=t.scrollLeft)};e.addEventListener("scroll",o,{passive:!0}),t.addEventListener("scroll",s,{passive:!0});let i=null;return typeof ResizeObserver<"u"&&(i=new ResizeObserver(()=>{nc(e,t)}),i.observe(e),i.observe(r)),nc(e,t),()=>{e.removeEventListener("scroll",o),t.removeEventListener("scroll",s),i&&i.disconnect()}}function nc(n,e){if(R_.has(e))return;const t=e.firstElementChild;if(!t||!ke(t)||!n.isConnected)return;const r=n.ownerDocument.defaultView;if(!r)return void(e.style.display="none");const o=r.getComputedStyle(n).overflowX,s=o==="auto"||o==="scroll",i=n.scrollWidth,a=n.clientWidth,l=i+"px";t.style.width!==l&&(t.style.width=l);const c=s&&i>a;e.style.display=c?"":"none"}function HC(n){if(!n.hasAttribute("data-lexical-sticky-scrollbar"))return null;const e=n.firstElementChild;if(!Wi(e))return null;const t=e.querySelector(":scope > table");if(!Fn(t))return null;const r=e.nextElementSibling;return Wi(r)?{scrollable:e,scrollbar:r,tableElement:t}:null}const rc=new WeakSet;function Po(n=zo()){return rc.has(n)}function oc(n=zo()){const e=Tc(n,"@lexical/table/Table");return!!e&&e.output.hasStickyScrollbar.peek()&&e.output.hasHorizontalScroll.peek()}function fu(n,e){e?rc.add(n):rc.delete(n)}class Xt extends Oe{__rowStriping=!1;__frozenColumnCount=0;__frozenRowCount=0;__colWidths=void 0;$config(){return this.config("table",{extends:Oe,importDOM:{table:()=>({conversion:JC,priority:1})}})}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping,this.__frozenColumnCount=e.__frozenColumnCount,this.__frozenRowCount=e.__frozenRowCount}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setFrozenColumns(e.frozenColumnCount||0).setFrozenRows(e.frozenRowCount||0).setColWidths(e.colWidths)}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),frozenColumnCount:this.__frozenColumnCount?this.__frozenColumnCount:void 0,frozenRowCount:this.__frozenRowCount?this.__frozenRowCount:void 0,rowStriping:this.__rowStriping?this.__rowStriping:void 0}}extractWithChild(e,t,r){return r==="html"}getDOMSlot(e){const t=Fn(e)?e:e.querySelector("table");return Fn(t)||G(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector(":scope > colgroup"))}createDOM(e,t){const r=Je().createElement("table");if(this.__style&&_o(r.style,this.__style),this.getColWidths()){const o=Je().createElement("colgroup");r.appendChild(o),Rl(o)}if(Ie(r,e.theme.table),this.updateTableElement(null,r,e),Po(t)){const o=oc(t),s=(function(i,a,l){const c=Je().createElement("div"),u=a.theme.tableScrollableWrapper;return u?Ie(c,u):c.style.overflowX="auto",l&&(c.style.scrollbarWidth="none"),c.appendChild(i),c})(r,e,o);if(this.updateTableWrapper(null,s,r,e),o){const i=(function(l){const c=Je(),u=c.createElement("div"),f=l.theme.tableStickyScrollbar;f?Ie(u,f):(u.style.position="sticky",u.style.bottom="0",u.style.overflowX="scroll",u.style.overflowY="hidden"),u.style.display="none",u.setAttribute("aria-hidden","true"),u.tabIndex=-1;const d=c.createElement("div");return d.style.height="1px",d.style.width="0px",u.appendChild(d),u})(e),a=Je().createElement("div");return a.setAttribute("data-lexical-sticky-scrollbar","true"),a.appendChild(s),a.appendChild(i),Rl(i),a}return s}return r}updateTableWrapper(e,t,r,o){this.__frozenColumnCount!==(e?e.__frozenColumnCount:0)&&(function(s,i,a,l){l>0?(Ie(s,a.theme.tableFrozenColumn),i.setAttribute("data-lexical-frozen-column","true")):($t(s,a.theme.tableFrozenColumn),i.removeAttribute("data-lexical-frozen-column"))})(t,r,o,this.__frozenColumnCount),this.__frozenRowCount!==(e?e.__frozenRowCount:0)&&(function(s,i,a,l){l>0?(Ie(s,a.theme.tableFrozenRow),i.setAttribute("data-lexical-frozen-row","true")):($t(s,a.theme.tableFrozenRow),i.removeAttribute("data-lexical-frozen-row"))})(t,r,o,this.__frozenRowCount)}updateTableElement(e,t,r){this.__style!==(e?e.__style:"")&&_o(t.style,this.__style,e?e.__style:""),this.__rowStriping!==(!!e&&e.__rowStriping)&&(function(i,a,l){l?(Ie(i,a.theme.tableRowStriping),i.setAttribute("data-lexical-row-striping","true")):($t(i,a.theme.tableRowStriping),i.removeAttribute("data-lexical-row-striping"))})(t,r,this.__rowStriping);const o=e?e.getColumnCount():0,s=e?e.__colWidths:void 0;this.getColumnCount()===o&&this.getColWidths()===s||vf(t,this.getColumnCount(),this.getColWidths()),kf(t,r,this.getFormatType())}updateDOM(e,t,r){const o=kt(this,t);if(t===o===Po())return!0;if(Wi(t)){if(t.hasAttribute("data-lexical-sticky-scrollbar")!==oc())return!0;const s=o.parentElement;Wi(s)&&this.updateTableWrapper(e,s,o,r)}return this.updateTableElement(e,o,r),!1}scaleDOMColWidths(e,t){const r=this.getColWidths();r&&vf(kt(this,e),this.getColumnCount(),r.map(o=>o*t))}exportDOM(e){const t=super.exportDOM(e),{element:r}=t;return{after:o=>{if(t.after&&(o=t.after(o)),!Fn(o)&&ke(o)&&(o=o.querySelector("table")),!Fn(o))return null;kf(o,e._config,this.getFormatType());const[s]=at(this,null,null),i=new Map;for(const u of s)for(const f of u){const d=f.cell.getKey();i.has(d)||i.set(d,{colSpan:f.cell.getColSpan(),startColumn:f.startColumn})}const a=new Set;for(const u of o.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const f=u.getAttribute("data-temporary-table-cell-lexical-key");if(f){const d=i.get(f);if(u.removeAttribute("data-temporary-table-cell-lexical-key"),d){i.delete(f);for(let g=0;g<d.colSpan;g++)a.add(g+d.startColumn)}}}const l=o.querySelector(":scope > colgroup");if(l){const u=Array.from(o.querySelectorAll(":scope > colgroup > col")).filter((f,d)=>a.has(d));l.replaceChildren(...u)}const c=o.querySelectorAll(":scope > tr");if(c.length>0){const u=Je().createElement("tbody");for(const f of c)u.appendChild(f);o.append(u)}return o},element:!Fn(r)&&ke(r)?r.querySelector("table"):r}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:r,domRows:o}=t;for(let s=0;s<r;s++){const i=o[s];if(i!=null)for(let a=0;a<i.length;a++){const l=i[a];if(l==null)continue;const{elem:c}=l,u=tc(this,c);if(u!==null&&e.is(u))return{x:a,y:s}}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,r){const{domRows:o}=r,s=o[t];if(s==null)return null;const i=s[e<s.length?e:s.length-1];return i??null}getDOMCellFromCordsOrThrow(e,t,r){const o=this.getDOMCellFromCords(e,t,r);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,r){const o=this.getDOMCellFromCords(e,t,r);if(o==null)return null;const s=Ae(o.elem);return J(s)?s:null}getCellNodeFromCordsOrThrow(e,t,r){const o=this.getCellNodeFromCords(e,t,r);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return!!this.getLatest().__rowStriping}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}setFrozenRows(e){const t=this.getWritable();return t.__frozenRowCount=e,t}getFrozenRows(){return this.getLatest().__frozenRowCount}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!ce(e))return 0;let t=0;return e.getChildren().forEach(r=>{J(r)&&(t+=r.getColSpan())}),t}}function A_(n,e){const t=n.getElementByKey(e.getKey());return t===null&&G(230),vo(e,t)}function JC(n){const e=Ho();n.hasAttribute("data-lexical-row-striping")&&e.setRowStriping(!0),n.hasAttribute("data-lexical-frozen-column")&&e.setFrozenColumns(1),n.hasAttribute("data-lexical-frozen-row")&&e.setFrozenRows(1);const t=n.querySelector(":scope > colgroup");if(t){let r=[];for(const o of t.querySelectorAll(":scope > col")){let s=o.style.width||"";if(!Co.test(s)&&(s=o.getAttribute("width")||"",!/^\d+$/.test(s))){r=void 0;break}r.push(parseFloat(s))}r&&e.setColWidths(r)}return{after:r=>Mi(r,ce),node:e}}function Ho(){return Ot(new Xt)}function be(n){return n instanceof Xt}function qC(n){ce(n.getParent())?n.isEmpty()&&n.append(ne()):n.remove()}function VC(n){be(n.getParent())?ih(n,J):n.remove()}function YC(n){ih(n,ce);const[e]=at(n,null,null),t=e.reduce((i,a)=>Math.max(i,a.length),0),r=n.getChildren();for(let i=0;i<e.length;++i){const a=r[i];if(!a)continue;ce(a)||G(254,a.constructor.name,a.getType());const l=e[i].reduce((c,u)=>u?1+c:c,0);if(l!==t)for(let c=l;c<t;++c){const u=lt();u.append(ne()),a.append(u)}}const o=n.getColWidths(),s=n.getColumnCount();if(o&&o.length!==s){let i;if(s<o.length)i=o.slice(0,s);else if(o.length>0){const a=o[o.length-1];i=[...o,...Array(s-o.length).fill(a)]}n.setColWidths(i)}}function GC(n){if(n.detail<3||!No(n.target))return!1;const e=Ae(n.target);if(e===null)return!1;const t=re(e,r=>q(r)&&!r.isInline());return t===null?!1:!!J(t.getParent())&&(t.select(0),!0)}function XC(){const n=D();if(!F(n))return!1;const e=Or(n.anchor.getNode());if(e===null)return!1;const t=se();if(!t.is(e.getParent())||t.getChildrenSize()!==1)return!1;const[r]=at(e,null,null);if(r.length===0||r[0].length===0)return!1;const o=r[0][0];if(!o||!o.cell)return!1;const s=r[r.length-1],i=s[s.length-1];if(!i||!i.cell)return!1;const a=Ki(e,o.cell,i.cell);return Ee(a),!0}function gu(n){return n.registerNodeTransform(Gt,e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=We(e),[r]=ct(t,e,e),o=r.length,s=r[0].length;let i=t.getFirstChild();ce(i)||G(175);const a=[];for(let l=0;l<o;l++){l!==0&&(i=i.getNextSibling(),ce(i)||G(175));let c=null;for(let u=0;u<s;u++){const f=r[l][u],d=f.cell;if(f.startRow===l&&f.startColumn===u)c=d,a.push(d);else if(d.getColSpan()>1||d.getRowSpan()>1){J(d)||G(176);const g=lt(d.__headerState);c!==null?c.insertAfter(g):Dy(i,g)}}}for(const l of a)l.setColSpan(1),l.setRowSpan(1)}})}function pu(n,e=!0){const t=new MC,r=(o,s,i)=>{const a=kt(o,i),l=E_(o,a,n,e,t);t.observers.set(s,[l,a])};return de(jC(n,t),n.registerCommand(Ht,()=>FC(t,n),qe),n.registerMutationListener(Xt,o=>{n.read("latest",()=>{for(const[s,i]of o){const a=t.observers.get(s);if(i==="created"||i==="updated"){const{tableNode:l,tableElement:c}=du(s);a===void 0?r(l,s,c):c!==a[1]&&(t.removeObserver(s),r(l,s,c))}else i==="destroyed"&&t.removeObserver(s)}})},{skipInitialization:!1}),()=>{t.removeAllObservers()})}function hu(n,e){n.hasNodes([Xt])||G(255);const{hasNestedTables:t=Ac(!1)}=e??{};return de(n.registerCommand(nu,r=>(function({rows:o,columns:s,includeHeaders:i},a){const l=D()||mo();if(!l||!F(l)||!a&&Or(l.anchor.getNode()))return!1;const c=x_(Number(o),Number(s),i);sr(c);const u=c.getFirstDescendant();return oe(u)&&u.select(),!0})(r,t.peek()),V),n.registerCommand(Py,(r,o)=>n===o&&(function(s,i){const{nodes:a,selection:l}=s;if(!a.some(f=>be(f)||jy(f).some(d=>be(d.node)))){if(ae(l)){let f="",d=!1;for(const g of a){const h=q(g)&&!g.isInline();f.length>0&&(h||d)&&(f+=`
@@ -81,14 +81,14 @@ summary.Collapsible__title::marker {
81
81
  display: none;
82
82
  user-select: none;
83
83
  }
84
- `;let Xa=!1;function Tu(){if(Xa||typeof document>"u")return;if(document.getElementById(Hf)){Xa=!0;return}const n=document.createElement("style");n.id=Hf,n.textContent=rv,document.head.appendChild(n),Xa=!0}const ov={background:"var(--bgColor-muted, #f8f8f8)",border:"1px solid var(--borderColor-default, #e0e0e0)",borderRadius:"6px",margin:"12px 0",padding:"0",overflow:"hidden"},sv={cursor:"pointer",padding:"12px 12px 12px 36px",position:"relative",fontWeight:"600",fontSize:"14px",listStyle:"none",display:"block",outline:"none",color:"var(--fgColor-default, #333)",userSelect:"none",transition:"background-color 0.15s ease",margin:"0",WebkitAppearance:"none"},iv={padding:"12px 16px 16px 36px"};function Iu(n,e){for(const[t,r]of Object.entries(e))r!=null&&(n.style[t]=r)}function av(n){const e=n.open!==void 0?n.open:!0;return{node:Eu(e)}}class Mr extends Oe{__open;constructor(e,t){super(t),this.__open=e}static getType(){return"collapsible-container"}static clone(e){return new Mr(e.__open,e.__key)}isShadowRoot(){return!0}collapseAtStart(e){const t=[];for(const s of this.getChildren())q(s)&&t.push(...s.getChildren());Dc(gt(this,"previous")).splice(1,t);const[o]=t;return o&&o.selectStart().deleteCharacter(!0),!0}createDOM(e,t){Tu();let r;if($i)r=document.createElement("div"),r.setAttribute("open","");else{const o=document.createElement("details");o.open=this.__open,o.addEventListener("toggle",()=>{t.getEditorState().read(()=>this.getOpen())!==o.open&&t.update(()=>this.toggleOpen())}),r=o}return r.classList.add("Collapsible__container"),Iu(r,ov),r}updateDOM(e,t){const r=this.__open;if(e.__open!==r)if($i){const o=t.children[1];if(!ke(o))throw new Error("Expected contentDom to be an HTMLElement");r?(t.setAttribute("open",""),o.hidden=!1):(t.removeAttribute("open"),X_(o))}else t.open=this.__open;return!1}static importDOM(){return{details:e=>({conversion:av,priority:1})}}static importJSON(e){return Eu(e.open).updateFromJSON(e)}exportDOM(){const e=document.createElement("details");return e.classList.add("Collapsible__container"),e.setAttribute("open",this.__open.toString()),{element:e}}exportJSON(){return{...super.exportJSON(),open:this.__open}}setOpen(e){const t=this.getWritable();t.__open=e}getOpen(){return this.getLatest().__open}toggleOpen(){this.setOpen(!this.getOpen())}}function Eu(n){return new Mr(n)}function Pt(n){return n instanceof Mr}function lv(n){return{node:Nu()}}class $r extends Oe{static getType(){return"collapsible-content"}static clone(e){return new $r(e.__key)}createDOM(e,t){Tu();const r=document.createElement("div");return r.classList.add("Collapsible__content"),Iu(r,iv),$i&&(t.getEditorState().read(()=>{const o=this.getParentOrThrow();if(!Pt(o))throw new Error("Expected parent node to be a CollapsibleContainerNode");o.__open||X_(r)}),nv(r,()=>{t.update(()=>{const o=this.getParentOrThrow().getLatest();if(!Pt(o))throw new Error("Expected parent node to be a CollapsibleContainerNode");o.__open||o.toggleOpen()})})),r}updateDOM(e,t){return!1}static importDOM(){return{div:e=>e.hasAttribute("data-lexical-collapsible-content")?{conversion:lv,priority:2}:null}}exportDOM(){const e=document.createElement("div");return e.classList.add("Collapsible__content"),e.setAttribute("data-lexical-collapsible-content","true"),{element:e}}static importJSON(e){return Nu().updateFromJSON(e)}isShadowRoot(){return!0}}function Nu(){return new $r}function Lu(n){return n instanceof $r}function cv(n){return{node:Z_()}}class Os extends Oe{$config(){return this.config("collapsible-title",{$transform(e){e.isEmpty()&&e.remove()},extends:Oe,importDOM:$c({summary:()=>({conversion:cv,priority:1})})})}createDOM(e,t){Tu();const r=document.createElement("summary");return r.classList.add("Collapsible__title"),Iu(r,sv),$i&&r.addEventListener("click",()=>{t.update(()=>{const o=this.getLatest().getParentOrThrow();if(!Pt(o))throw new Error("Expected parent node to be a CollapsibleContainerNode");o.toggleOpen()})}),r}updateDOM(e,t){return!1}insertNewAfter(e,t=!0){const r=this.getParentOrThrow();if(!Pt(r))throw new Error("CollapsibleTitleNode expects to be child of CollapsibleContainerNode");if(r.getOpen()){const o=this.getNextSibling();if(!Lu(o))throw new Error("CollapsibleTitleNode expects to have CollapsibleContentNode sibling");const s=o.getFirstChild();if(q(s))return s;{const i=ne();return o.append(i),i}}else{const o=ne();return r.insertAfter(o,t),o}}}function Z_(){return new Os}function xi(n){return n instanceof Os}function uv(n){const t=window.getComputedStyle(n).getPropertyValue("grid-template-columns");return t?{node:Ou(t)}:null}class Dr extends Oe{__templateColumns;constructor(e,t){super(t),this.__templateColumns=e}static getType(){return"layout-container"}static clone(e){return new Dr(e.__templateColumns,e.__key)}createDOM(e){const t=document.createElement("div");return t.style.gridTemplateColumns=this.__templateColumns,typeof e.theme.layoutContainer=="string"&&Ie(t,e.theme.layoutContainer),t}exportDOM(){const e=document.createElement("div");return e.style.gridTemplateColumns=this.__templateColumns,e.setAttribute("data-lexical-layout-container","true"),{element:e}}updateDOM(e,t){return e.__templateColumns!==this.__templateColumns&&(t.style.gridTemplateColumns=this.__templateColumns),!1}static importDOM(){return{div:e=>e.hasAttribute("data-lexical-layout-container")?{conversion:uv,priority:2}:null}}static importJSON(e){return Ou().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setTemplateColumns(e.templateColumns)}isShadowRoot(){return!0}canBeEmpty(){return!1}exportJSON(){return{...super.exportJSON(),templateColumns:this.__templateColumns}}getTemplateColumns(){return this.getLatest().__templateColumns}setTemplateColumns(e){const t=this.getWritable();return t.__templateColumns=e,t}}function Ou(n=""){return new Dr(n)}function Ci(n){return n instanceof Dr}function dv(){return{node:Ru()}}function fv(n){if(!Au(n)||n.getChildrenSize()!==1)return!1;const e=n.getFirstChild();return ht(e)&&e.isEmpty()}class Pr extends Oe{constructor(e){super(e)}static getType(){return"layout-item"}static clone(e){return new Pr(e.__key)}createDOM(e){const t=document.createElement("div");return t.setAttribute("data-lexical-layout-item","true"),typeof e.theme.layoutItem=="string"&&Ie(t,e.theme.layoutItem),t}updateDOM(){return!1}collapseAtStart(){const e=this.getParentOrThrow();return this.is(e.getFirstChild())&&e.getChildren().every(fv)?(e.remove(),!0):!1}static importDOM(){return{div:e=>e.hasAttribute("data-lexical-layout-item")?{conversion:dv,priority:2}:null}}static importJSON(e){return Ru().updateFromJSON(e)}isShadowRoot(){return!0}}function Ru(){return new Pr}function Au(n){return n instanceof Pr}const Q_="@datalayer/jupyter-lexical/Loom",ls=new WeakMap;function FM(n,e){return e?ls.set(n,e):ls.delete(n),()=>{ls.get(n)===e&&ls.delete(n)}}function gv(n){return ls.get(n)}const pv=/^https?:\/\/(?:www\.)?loom\.com\/(?:share|embed)\/(?:[^/?#]*-)?([0-9a-f]{32})(?:[/?#].*)?$/i;function kn(n){const e=pv.exec(n.trim());return e?e[1].toLowerCase():null}function Mu(n){return`https://www.loom.com/share/${n}`}function em(n){return`https://www.loom.com/embed/${n}`}async function tm(n){const e=kn(n);if(!e)throw new Error(`Not a Loom video address: ${n}`);const t=Mu(e);try{const{oembed:r}=await me(async()=>{const{oembed:a}=await import("./index-BSpvs9Ep.js");return{oembed:a}},[],import.meta.url),{title:o,width:s,height:i}=await r(t);return{url:t,title:o||void 0,width:Number(s)||void 0,height:Number(i)||void 0}}catch{return{url:t}}}const Za=new Map;function hv(n){const e=n instanceof Error?n.message:String(n),t=e.toLowerCase(),r=t.indexOf("is not a function");return t.includes("render is not a function")||r>=0&&t.includes("render",r)?"The Loom recorder needs React 18 and this page runs React 19. See the Loom notes in the jupyter-lexical README to give it one.":`Loom could not start recording: ${e}`}function _v(n){let e=Za.get(n);return e||(e=(async()=>{const{isSupported:t}=await me(async()=>{const{isSupported:f}=await import("./is-supported-Dl0_Lu_Y.js");return{isSupported:f}},[],import.meta.url),{supported:r,error:o}=await t();if(!r)throw new Error(`this browser cannot record with Loom (${o})`);const{setup:s}=await me(async()=>{const{setup:f}=await import("./index-1Ekpl0uC.js");return{setup:f}},[],import.meta.url),{configureButton:i}=await s({publicAppId:n}),a=i();let l;const c=new Map,u=f=>{let d=c.get(f.id);!d&&l&&(d=l,c.set(f.id,d)),d?.(f)};return a.on("recording-complete",u),a.on("upload-complete",u),a.on("insert-click",u),{record:f=>{l=f,a.openPreRecordPanel()}}})(),e.catch(()=>Za.delete(n)),Za.set(n,e)),e}function mv({video:n}){const e=kn(n.url);return e?x.jsx("div",{"data-lexical-loom-player":e,style:{position:"relative",width:"100%",aspectRatio:`${n.width||16} / ${n.height||9}`,borderRadius:6,overflow:"hidden",background:"var(--bgColor-muted, #f6f8fa)"},children:x.jsx("iframe",{src:em(e),title:n.title||"Loom video",allow:"fullscreen; picture-in-picture",style:{position:"absolute",inset:0,width:"100%",height:"100%",border:0}})}):null}function bv({nodeKey:n}){const[e]=fe(),t=Hr(),[r,o]=S.useState(""),[s,i]=S.useState(),[a,l]=S.useState(),c=Tc(e,Q_)?.config.publicAppId??gv(e),u=S.useCallback(g=>{e.update(()=>{const h=Q(n);Du(h)&&h.setVideo(g)})},[e,n]),f=S.useCallback(async()=>{if(c){l(void 0),i("recording");try{(await _v(c)).record(h=>u({url:h.sharedUrl,title:h.title,width:h.width,height:h.height}))}catch(g){l(hv(g))}finally{i(void 0)}}},[c,u]),d=S.useCallback(async()=>{if(!kn(r)){l("That is not the address of a Loom video: it looks like https://www.loom.com/share/…");return}l(void 0),i("embedding");try{u(await tm(r))}finally{i(void 0)}},[r,u]);return t?x.jsxs(Y,{"data-lexical-loom-placeholder":"",sx:{display:"grid",gap:2,p:3,border:"1px dashed",borderColor:"border.default",borderRadius:2,bg:"canvas.subtle"},children:[x.jsxs(Y,{sx:{display:"flex",alignItems:"center",gap:2},children:[x.jsx(Ws,{size:16}),x.jsx(Le,{sx:{fontWeight:"bold"},children:"Loom Video"})]}),x.jsx(Le,{sx:{color:"fg.muted",fontSize:0},children:"Recorded with Loom: Loom asks you to sign in to your Loom account, and the video is saved there, so it stays in the document."}),x.jsxs(Y,{sx:{display:"flex",flexWrap:"wrap",gap:2,alignItems:"center"},children:[x.jsx(ft,{variant:"primary",onClick:()=>{f()},disabled:!c||s!==void 0,children:s==="recording"?"Starting…":"Record"}),x.jsx(Le,{sx:{color:"fg.muted",fontSize:1},children:"or"}),x.jsx(vn,{"aria-label":"Address of a Loom video",placeholder:"https://www.loom.com/share/…",value:r,onChange:g=>o(g.target.value),onFocus:()=>e.update(()=>Ee(null)),onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),d())},sx:{flex:"1 1 240px"}}),x.jsx(ft,{onClick:()=>{d()},disabled:!r.trim()||s!==void 0,children:s==="embedding"?"Embedding…":"Embed"})]}),!c&&x.jsxs(Y,{"data-lexical-loom-no-app-id":"",sx:{display:"flex",gap:2,alignItems:"flex-start",color:"attention.fg",fontSize:1},children:[x.jsx(Fp,{size:16}),x.jsxs(Le,{children:["Recording with Loom is off in this editor: it was given no Loom public app id, and without one Loom cannot open to let you sign in. Its host passes the id to ",x.jsx("code",{children:"LoomExtension"}),". A Loom video can still be embedded by its address."]})]}),a&&x.jsx(Le,{role:"alert",sx:{color:"danger.fg",fontSize:1},children:a})]}):x.jsx(Le,{as:"p",sx:{color:"fg.muted",fontSize:1,m:0},children:"A Loom video goes here."})}function yv({className:n,format:e,nodeKey:t,video:r}){return x.jsx(Ls,{className:n,format:e,nodeKey:t,children:kn(r.url)?x.jsx(mv,{video:r}):x.jsx(bv,{nodeKey:t})})}function wv(n){const e=n.getAttribute("data-lexical-loom"),t=kn(e||n.getAttribute("src")||"");return t?{node:$u({url:Mu(t),title:n.getAttribute("title")||void 0})}:null}class Vo extends Jo{__url;__title;__width;__height;static getType(){return"loom"}static clone(e){return new Vo({url:e.__url,title:e.__title,width:e.__width,height:e.__height},e.__format,e.__key)}static importJSON(e){const t=$u({url:e.url,title:e.title,width:e.width,height:e.height});return t.setFormat(e.format),t}exportJSON(){return{...super.exportJSON(),type:"loom",version:1,url:this.__url,...this.__title?{title:this.__title}:{},...this.__width?{width:this.__width}:{},...this.__height?{height:this.__height}:{}}}static importDOM(){return{iframe:e=>e.hasAttribute("data-lexical-loom")||kn(e.getAttribute("src")||"")?{conversion:wv,priority:1}:null}}exportDOM(){const e=kn(this.__url);if(!e)return{element:null};const t=document.createElement("iframe");return t.setAttribute("data-lexical-loom",this.__url),t.setAttribute("src",em(e)),t.setAttribute("title",this.__title||"Loom video"),t.setAttribute("width",String(this.__width||640)),t.setAttribute("height",String(this.__height||360)),t.setAttribute("frameborder","0"),t.setAttribute("allowfullscreen","true"),{element:t}}constructor(e={url:""},t,r){super(t,r),this.__url=e.url,this.__title=e.title,this.__width=e.width,this.__height=e.height}getVideo(){const e=this.getLatest();return{url:e.__url,title:e.__title,width:e.__width,height:e.__height}}setVideo(e){const t=this.getWritable();t.__url=e.url,t.__title=e.title,t.__width=e.width,t.__height=e.height}getTextContent(){return this.__url}updateDOM(){return!1}decorate(e,t){const r=t.theme.embedBlock||{};return x.jsx(yv,{className:{base:r.base||"",focus:r.focus||""},format:this.__format,nodeKey:this.getKey(),video:{url:this.__url,title:this.__title,width:this.__width,height:this.__height}})}isTopLevel(){return!0}}function $u(n){return new Vo(n)}function Du(n){return n instanceof Vo}function xv(n,e){const t={};for(const r of n){const o=e(r);t[o]?t[o].push(r):t[o]=[r]}return t}function Cv(n){const e=xv(n,t=>t.type);return{element:e.element||[],textFormat:e["text-format"]||[],textMatch:e["text-match"]||[]}}const Jf=/[!-/:-@[-`{-~\s]/,Sv=/^\s{0,3}$/,qf=/^```(\w{1,10})?\s?$/;function vv(n){const e=Cv(n),t=Nv(e.textFormat);return r=>{const o=r.split(`
84
+ `;let Xa=!1;function Tu(){if(Xa||typeof document>"u")return;if(document.getElementById(Hf)){Xa=!0;return}const n=document.createElement("style");n.id=Hf,n.textContent=rv,document.head.appendChild(n),Xa=!0}const ov={background:"var(--bgColor-muted, #f8f8f8)",border:"1px solid var(--borderColor-default, #e0e0e0)",borderRadius:"6px",margin:"12px 0",padding:"0",overflow:"hidden"},sv={cursor:"pointer",padding:"12px 12px 12px 36px",position:"relative",fontWeight:"600",fontSize:"14px",listStyle:"none",display:"block",outline:"none",color:"var(--fgColor-default, #333)",userSelect:"none",transition:"background-color 0.15s ease",margin:"0",WebkitAppearance:"none"},iv={padding:"12px 16px 16px 36px"};function Iu(n,e){for(const[t,r]of Object.entries(e))r!=null&&(n.style[t]=r)}function av(n){const e=n.open!==void 0?n.open:!0;return{node:Eu(e)}}class Mr extends Oe{__open;constructor(e,t){super(t),this.__open=e}static getType(){return"collapsible-container"}static clone(e){return new Mr(e.__open,e.__key)}isShadowRoot(){return!0}collapseAtStart(e){const t=[];for(const s of this.getChildren())q(s)&&t.push(...s.getChildren());Dc(gt(this,"previous")).splice(1,t);const[o]=t;return o&&o.selectStart().deleteCharacter(!0),!0}createDOM(e,t){Tu();let r;if($i)r=document.createElement("div"),r.setAttribute("open","");else{const o=document.createElement("details");o.open=this.__open,o.addEventListener("toggle",()=>{t.getEditorState().read(()=>this.getOpen())!==o.open&&t.update(()=>this.toggleOpen())}),r=o}return r.classList.add("Collapsible__container"),Iu(r,ov),r}updateDOM(e,t){const r=this.__open;if(e.__open!==r)if($i){const o=t.children[1];if(!ke(o))throw new Error("Expected contentDom to be an HTMLElement");r?(t.setAttribute("open",""),o.hidden=!1):(t.removeAttribute("open"),X_(o))}else t.open=this.__open;return!1}static importDOM(){return{details:e=>({conversion:av,priority:1})}}static importJSON(e){return Eu(e.open).updateFromJSON(e)}exportDOM(){const e=document.createElement("details");return e.classList.add("Collapsible__container"),e.setAttribute("open",this.__open.toString()),{element:e}}exportJSON(){return{...super.exportJSON(),open:this.__open}}setOpen(e){const t=this.getWritable();t.__open=e}getOpen(){return this.getLatest().__open}toggleOpen(){this.setOpen(!this.getOpen())}}function Eu(n){return new Mr(n)}function Pt(n){return n instanceof Mr}function lv(n){return{node:Nu()}}class $r extends Oe{static getType(){return"collapsible-content"}static clone(e){return new $r(e.__key)}createDOM(e,t){Tu();const r=document.createElement("div");return r.classList.add("Collapsible__content"),Iu(r,iv),$i&&(t.getEditorState().read(()=>{const o=this.getParentOrThrow();if(!Pt(o))throw new Error("Expected parent node to be a CollapsibleContainerNode");o.__open||X_(r)}),nv(r,()=>{t.update(()=>{const o=this.getParentOrThrow().getLatest();if(!Pt(o))throw new Error("Expected parent node to be a CollapsibleContainerNode");o.__open||o.toggleOpen()})})),r}updateDOM(e,t){return!1}static importDOM(){return{div:e=>e.hasAttribute("data-lexical-collapsible-content")?{conversion:lv,priority:2}:null}}exportDOM(){const e=document.createElement("div");return e.classList.add("Collapsible__content"),e.setAttribute("data-lexical-collapsible-content","true"),{element:e}}static importJSON(e){return Nu().updateFromJSON(e)}isShadowRoot(){return!0}}function Nu(){return new $r}function Lu(n){return n instanceof $r}function cv(n){return{node:Z_()}}class Os extends Oe{$config(){return this.config("collapsible-title",{$transform(e){e.isEmpty()&&e.remove()},extends:Oe,importDOM:$c({summary:()=>({conversion:cv,priority:1})})})}createDOM(e,t){Tu();const r=document.createElement("summary");return r.classList.add("Collapsible__title"),Iu(r,sv),$i&&r.addEventListener("click",()=>{t.update(()=>{const o=this.getLatest().getParentOrThrow();if(!Pt(o))throw new Error("Expected parent node to be a CollapsibleContainerNode");o.toggleOpen()})}),r}updateDOM(e,t){return!1}insertNewAfter(e,t=!0){const r=this.getParentOrThrow();if(!Pt(r))throw new Error("CollapsibleTitleNode expects to be child of CollapsibleContainerNode");if(r.getOpen()){const o=this.getNextSibling();if(!Lu(o))throw new Error("CollapsibleTitleNode expects to have CollapsibleContentNode sibling");const s=o.getFirstChild();if(q(s))return s;{const i=ne();return o.append(i),i}}else{const o=ne();return r.insertAfter(o,t),o}}}function Z_(){return new Os}function xi(n){return n instanceof Os}function uv(n){const t=window.getComputedStyle(n).getPropertyValue("grid-template-columns");return t?{node:Ou(t)}:null}class Dr extends Oe{__templateColumns;constructor(e,t){super(t),this.__templateColumns=e}static getType(){return"layout-container"}static clone(e){return new Dr(e.__templateColumns,e.__key)}createDOM(e){const t=document.createElement("div");return t.style.gridTemplateColumns=this.__templateColumns,typeof e.theme.layoutContainer=="string"&&Ie(t,e.theme.layoutContainer),t}exportDOM(){const e=document.createElement("div");return e.style.gridTemplateColumns=this.__templateColumns,e.setAttribute("data-lexical-layout-container","true"),{element:e}}updateDOM(e,t){return e.__templateColumns!==this.__templateColumns&&(t.style.gridTemplateColumns=this.__templateColumns),!1}static importDOM(){return{div:e=>e.hasAttribute("data-lexical-layout-container")?{conversion:uv,priority:2}:null}}static importJSON(e){return Ou().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setTemplateColumns(e.templateColumns)}isShadowRoot(){return!0}canBeEmpty(){return!1}exportJSON(){return{...super.exportJSON(),templateColumns:this.__templateColumns}}getTemplateColumns(){return this.getLatest().__templateColumns}setTemplateColumns(e){const t=this.getWritable();return t.__templateColumns=e,t}}function Ou(n=""){return new Dr(n)}function Ci(n){return n instanceof Dr}function dv(){return{node:Ru()}}function fv(n){if(!Au(n)||n.getChildrenSize()!==1)return!1;const e=n.getFirstChild();return ht(e)&&e.isEmpty()}class Pr extends Oe{constructor(e){super(e)}static getType(){return"layout-item"}static clone(e){return new Pr(e.__key)}createDOM(e){const t=document.createElement("div");return t.setAttribute("data-lexical-layout-item","true"),typeof e.theme.layoutItem=="string"&&Ie(t,e.theme.layoutItem),t}updateDOM(){return!1}collapseAtStart(){const e=this.getParentOrThrow();return this.is(e.getFirstChild())&&e.getChildren().every(fv)?(e.remove(),!0):!1}static importDOM(){return{div:e=>e.hasAttribute("data-lexical-layout-item")?{conversion:dv,priority:2}:null}}static importJSON(e){return Ru().updateFromJSON(e)}isShadowRoot(){return!0}}function Ru(){return new Pr}function Au(n){return n instanceof Pr}const Q_="@datalayer/jupyter-lexical/Loom",ls=new WeakMap;function FM(n,e){return e?ls.set(n,e):ls.delete(n),()=>{ls.get(n)===e&&ls.delete(n)}}function gv(n){return ls.get(n)}const pv=/^https?:\/\/(?:www\.)?loom\.com\/(?:share|embed)\/(?:[^/?#]*-)?([0-9a-f]{32})(?:[/?#].*)?$/i;function kn(n){const e=pv.exec(n.trim());return e?e[1].toLowerCase():null}function Mu(n){return`https://www.loom.com/share/${n}`}function em(n){return`https://www.loom.com/embed/${n}`}async function tm(n){const e=kn(n);if(!e)throw new Error(`Not a Loom video address: ${n}`);const t=Mu(e);try{const{oembed:r}=await me(async()=>{const{oembed:a}=await import("./index-BSpvs9Ep.js");return{oembed:a}},[],import.meta.url),{title:o,width:s,height:i}=await r(t);return{url:t,title:o||void 0,width:Number(s)||void 0,height:Number(i)||void 0}}catch{return{url:t}}}const Za=new Map;function hv(n){const e=n instanceof Error?n.message:String(n),t=e.toLowerCase(),r=t.indexOf("is not a function");return t.includes("render is not a function")||r>=0&&t.includes("render",r)?"The Loom recorder needs React 18 and this page runs React 19. See the Loom notes in the jupyter-lexical README to give it one.":`Loom could not start recording: ${e}`}function _v(n){let e=Za.get(n);return e||(e=(async()=>{const{isSupported:t}=await me(async()=>{const{isSupported:f}=await import("./is-supported-Dl0_Lu_Y.js");return{isSupported:f}},[],import.meta.url),{supported:r,error:o}=await t();if(!r)throw new Error(`this browser cannot record with Loom (${o})`);const{setup:s}=await me(async()=>{const{setup:f}=await import("./index-CawAyW3R.js");return{setup:f}},[],import.meta.url),{configureButton:i}=await s({publicAppId:n}),a=i();let l;const c=new Map,u=f=>{let d=c.get(f.id);!d&&l&&(d=l,c.set(f.id,d)),d?.(f)};return a.on("recording-complete",u),a.on("upload-complete",u),a.on("insert-click",u),{record:f=>{l=f,a.openPreRecordPanel()}}})(),e.catch(()=>Za.delete(n)),Za.set(n,e)),e}function mv({video:n}){const e=kn(n.url);return e?x.jsx("div",{"data-lexical-loom-player":e,style:{position:"relative",width:"100%",aspectRatio:`${n.width||16} / ${n.height||9}`,borderRadius:6,overflow:"hidden",background:"var(--bgColor-muted, #f6f8fa)"},children:x.jsx("iframe",{src:em(e),title:n.title||"Loom video",allow:"fullscreen; picture-in-picture",style:{position:"absolute",inset:0,width:"100%",height:"100%",border:0}})}):null}function bv({nodeKey:n}){const[e]=fe(),t=Hr(),[r,o]=S.useState(""),[s,i]=S.useState(),[a,l]=S.useState(),c=Tc(e,Q_)?.config.publicAppId??gv(e),u=S.useCallback(g=>{e.update(()=>{const h=Q(n);Du(h)&&h.setVideo(g)})},[e,n]),f=S.useCallback(async()=>{if(c){l(void 0),i("recording");try{(await _v(c)).record(h=>u({url:h.sharedUrl,title:h.title,width:h.width,height:h.height}))}catch(g){l(hv(g))}finally{i(void 0)}}},[c,u]),d=S.useCallback(async()=>{if(!kn(r)){l("That is not the address of a Loom video: it looks like https://www.loom.com/share/…");return}l(void 0),i("embedding");try{u(await tm(r))}finally{i(void 0)}},[r,u]);return t?x.jsxs(Y,{"data-lexical-loom-placeholder":"",sx:{display:"grid",gap:2,p:3,border:"1px dashed",borderColor:"border.default",borderRadius:2,bg:"canvas.subtle"},children:[x.jsxs(Y,{sx:{display:"flex",alignItems:"center",gap:2},children:[x.jsx(Ws,{size:16}),x.jsx(Le,{sx:{fontWeight:"bold"},children:"Loom Video"})]}),x.jsx(Le,{sx:{color:"fg.muted",fontSize:0},children:"Recorded with Loom: Loom asks you to sign in to your Loom account, and the video is saved there, so it stays in the document."}),x.jsxs(Y,{sx:{display:"flex",flexWrap:"wrap",gap:2,alignItems:"center"},children:[x.jsx(ft,{variant:"primary",onClick:()=>{f()},disabled:!c||s!==void 0,children:s==="recording"?"Starting…":"Record"}),x.jsx(Le,{sx:{color:"fg.muted",fontSize:1},children:"or"}),x.jsx(vn,{"aria-label":"Address of a Loom video",placeholder:"https://www.loom.com/share/…",value:r,onChange:g=>o(g.target.value),onFocus:()=>e.update(()=>Ee(null)),onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),d())},sx:{flex:"1 1 240px"}}),x.jsx(ft,{onClick:()=>{d()},disabled:!r.trim()||s!==void 0,children:s==="embedding"?"Embedding…":"Embed"})]}),!c&&x.jsxs(Y,{"data-lexical-loom-no-app-id":"",sx:{display:"flex",gap:2,alignItems:"flex-start",color:"attention.fg",fontSize:1},children:[x.jsx(Fp,{size:16}),x.jsxs(Le,{children:["Recording with Loom is off in this editor: it was given no Loom public app id, and without one Loom cannot open to let you sign in. Its host passes the id to ",x.jsx("code",{children:"LoomExtension"}),". A Loom video can still be embedded by its address."]})]}),a&&x.jsx(Le,{role:"alert",sx:{color:"danger.fg",fontSize:1},children:a})]}):x.jsx(Le,{as:"p",sx:{color:"fg.muted",fontSize:1,m:0},children:"A Loom video goes here."})}function yv({className:n,format:e,nodeKey:t,video:r}){return x.jsx(Ls,{className:n,format:e,nodeKey:t,children:kn(r.url)?x.jsx(mv,{video:r}):x.jsx(bv,{nodeKey:t})})}function wv(n){const e=n.getAttribute("data-lexical-loom"),t=kn(e||n.getAttribute("src")||"");return t?{node:$u({url:Mu(t),title:n.getAttribute("title")||void 0})}:null}class Vo extends Jo{__url;__title;__width;__height;static getType(){return"loom"}static clone(e){return new Vo({url:e.__url,title:e.__title,width:e.__width,height:e.__height},e.__format,e.__key)}static importJSON(e){const t=$u({url:e.url,title:e.title,width:e.width,height:e.height});return t.setFormat(e.format),t}exportJSON(){return{...super.exportJSON(),type:"loom",version:1,url:this.__url,...this.__title?{title:this.__title}:{},...this.__width?{width:this.__width}:{},...this.__height?{height:this.__height}:{}}}static importDOM(){return{iframe:e=>e.hasAttribute("data-lexical-loom")||kn(e.getAttribute("src")||"")?{conversion:wv,priority:1}:null}}exportDOM(){const e=kn(this.__url);if(!e)return{element:null};const t=document.createElement("iframe");return t.setAttribute("data-lexical-loom",this.__url),t.setAttribute("src",em(e)),t.setAttribute("title",this.__title||"Loom video"),t.setAttribute("width",String(this.__width||640)),t.setAttribute("height",String(this.__height||360)),t.setAttribute("frameborder","0"),t.setAttribute("allowfullscreen","true"),{element:t}}constructor(e={url:""},t,r){super(t,r),this.__url=e.url,this.__title=e.title,this.__width=e.width,this.__height=e.height}getVideo(){const e=this.getLatest();return{url:e.__url,title:e.__title,width:e.__width,height:e.__height}}setVideo(e){const t=this.getWritable();t.__url=e.url,t.__title=e.title,t.__width=e.width,t.__height=e.height}getTextContent(){return this.__url}updateDOM(){return!1}decorate(e,t){const r=t.theme.embedBlock||{};return x.jsx(yv,{className:{base:r.base||"",focus:r.focus||""},format:this.__format,nodeKey:this.getKey(),video:{url:this.__url,title:this.__title,width:this.__width,height:this.__height}})}isTopLevel(){return!0}}function $u(n){return new Vo(n)}function Du(n){return n instanceof Vo}function xv(n,e){const t={};for(const r of n){const o=e(r);t[o]?t[o].push(r):t[o]=[r]}return t}function Cv(n){const e=xv(n,t=>t.type);return{element:e.element||[],textFormat:e["text-format"]||[],textMatch:e["text-match"]||[]}}const Jf=/[!-/:-@[-`{-~\s]/,Sv=/^\s{0,3}$/,qf=/^```(\w{1,10})?\s?$/;function vv(n){const e=Cv(n),t=Nv(e.textFormat);return r=>{const o=r.split(`
85
85
  `),s=o.length,i=se();for(let l=0;l<s;l++){const c=o[l],[u,f]=Iv(o,l,i);if(u!=null){l=f;continue}Tv(c,i,e.element,t,e.textMatch)}const a=i.getChildren();for(const l of a)kv(l)&&l.remove();i.selectEnd()}}function kv(n){if(!ht(n))return!1;const e=n.getFirstChild();return e==null||n.getChildrenSize()===1&&oe(e)&&Sv.test(e.getTextContent())}function Tv(n,e,t,r,o){const s=n.trim(),i=$e(s),a=ne();a.append(i),e.append(a);for(const{regExp:l,replace:c}of t){const u=n.match(l);if(u){i.setTextContent(n.slice(u[0].length)),c(a,[i],u,!0);break}}if(Si(i,r,o),a.isAttached()&&s.length>0){const l=a.getPreviousSibling();if(ht(l)||Vn(l)||Z(l)){let c=l;if(Z(l)){const u=l.getLastDescendant();u==null?c=null:c=re(u,le)}c!=null&&c.getTextContentSize()>0&&(c.splice(c.getChildrenSize(),0,[vt(),...a.getChildren()]),a.remove())}}}function Iv(n,e,t){const r=n[e].match(qf);if(r){let o=e;const s=n.length;for(;++o<s;)if(n[o].match(qf)){const a=qr(r[1]),l=$e(n.slice(e+1,o).join(`
86
86
  `));return a.append(l),t.append(a),[a,o]}}return[null,e]}function Si(n,e,t){const r=n.getTextContent(),o=Ev(r,e);if(!o){nm(n,t);return}let s,i,a;if(o[0]===r)s=n;else{const c=o.index||0,u=c+o[0].length;c===0?[s,i]=n.splitText(u):[a,s,i]=n.splitText(c,u)}s.setTextContent(o[2]);const l=e.transformersByTag[o[1]];if(l)for(const c of l.format)s.hasFormat(c)||s.toggleFormat(c);s.hasFormat("code")||Si(s,e,t),a&&Si(a,e,t),i&&Si(i,e,t)}function nm(n,e){let t=n;e:for(;t;){for(const r of e){const o=t.getTextContent().match(r.importRegExp);if(!o)continue;const s=o.index||0,i=s+o[0].length;let a,l;s===0?[a,t]=t.splitText(i):[,a,l]=t.splitText(s,i),l&&nm(l,e),r.replace(a,o);continue e}break}}function Ev(n,e){const t=n.match(e.openTagsRegExp);if(t==null)return null;for(const r of t){const o=r.replace(/^\s/,""),s=e.fullMatchRegExpByTag[o];if(s==null)continue;const i=n.match(s),a=e.transformersByTag[o];if(i!=null&&a!=null){if(a.intraword!==!1)return i;const{index:l=0}=i,c=n[l-1],u=n[l+i[0].length];if((!c||Jf.test(c))&&(!u||Jf.test(u)))return i}}return null}function Nv(n){const e={},t={},r=[];for(const o of n){const{tag:s}=o;e[s]=o;const i=s.replace(/(\*|\^)/g,"\\$1");r.push(i),t[s]=new RegExp(`(${i})(?![${i}\\s])(.*?[^${i}\\s])${i}(?!${i})`)}return{fullMatchRegExpByTag:t,openTagsRegExp:new RegExp("("+r.join("|")+")","g"),transformersByTag:e}}const rm=n=>(e,t,r)=>{const o=n(r);o.append(...t),e.replace(o),o.select(0,0)},om=4,Pu=n=>(e,t,r)=>{const o=e.getPreviousSibling(),s=xt(n==="check"?r[3]==="x":void 0);if(Z(o)&&o.getListType()===n)o.append(s),e.remove();else{const a=Et(n,n==="number"?Number(r[2]):void 0);a.append(s),e.replace(a)}s.append(...t),s.select(0,0);const i=Math.floor(r[1].length/om);i&&s.setIndent(i)},va=(n,e,t)=>{const r=[],o=n.getChildren();let s=0;for(const i of o)if(le(i)){if(i.getChildrenSize()===1){const u=i.getFirstChild();if(Z(u)){r.push(va(u,e,t+1));continue}}const a=" ".repeat(t*om),l=n.getListType(),c=l==="number"?`${n.getStart()+s}. `:l==="check"?`- [${i.getChecked()?"x":" "}] `:"- ";r.push(a+c+e(i)),s++}return r.join(`
87
87
  `)},Lv={dependencies:[qs],export:(n,e)=>{if(!Wr(n))return null;const t=Number(n.getTag().slice(1));return"#".repeat(t)+" "+e(n)},regExp:/^(#{1,6})\s/,replace:rm(n=>{const e="h"+n[1].length;return fn(e)}),type:"element"},Ov={dependencies:[Js],export:(n,e)=>{if(!Vn(n))return null;const t=e(n).split(`
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,bn],export:(n,e)=>Z(n)?va(n,e,0):null,regExp:/^(\s*)[-*+]\s/,replace:Pu("bullet"),type:"element"},Mv={dependencies:[Yt,bn],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,bn],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=$e(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 BM(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?$/,Gv=/^:?-+:?$/,Xv={dependencies:[Xt,Wo,Gt],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=>Gv.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($e(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,Xv,Jv,qv,Yv,Mv,...sm,...im,...am],e1=S.lazy(()=>me(()=>import("./ExcalidrawComponent-BehqBpwC.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 kn(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=>Gv.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($e(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,Xv,Jv,qv,Yv,Mv,...sm,...im,...am],e1=S.lazy(()=>me(()=>import("./ExcalidrawComponent-0e3KqmKJ.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 kn(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],Gf=[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":"","­":""},Xf={"€":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(Xf[i]!==void 0)e.push(Xf[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?Gf: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?Gf: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
@@ -211,7 +211,7 @@ ${n.stack}`:r}function Mk(){let n,e;try{const o=p.__wbindgen_add_to_stack_pointe
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(IN,{completionText:this.__completionText})}isInline(){return!0}isKeyboardSelectable(){return!1}}function hc(n){return new Gs(n)}function ds(n){return n instanceof Gs}function IN({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 EN=/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/,NN=/(([^<>()[\]\\.,;:\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,}))/,LN=[n=>{const e=EN.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=NN.exec(n);return e?{index:e.index,length:e[0].length,text:e[0],url:`mailto:${e[0]}`}:null}],ON=pe({name:"@datalayer/jupyter-lexical/AutoLink",dependencies:[ln(mC,{matchers:LN})]});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 RN=new Set(["http:","https:","mailto:","sms:","tel:"]);function AN(n){try{const e=new URL(n);if(!RN.has(e.protocol))return"about:blank"}catch{return n}return n}const MN=new RegExp(/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[\w]*))?)/);function HM(n){return n==="https://"||MN.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 $N(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($N(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 Xi=new Map,$s=new Map,_c=new Set;function Ii(n,e){e?Xi.set(n,e):Xi.delete(n),_c.forEach(t=>t())}function DN(n){return _c.add(n),()=>_c.delete(n)}function PN(n){return Xi.get(n)}function jN(){return typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():`video-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}function FN(){return typeof MediaRecorder<"u"&&typeof navigator<"u"&&!!navigator.mediaDevices}function BN(){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 UN(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 zN(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 KN(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 WN(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 b=await i.getUserMedia({audio:!0}).catch(()=>{});b&&(o.push(b),l.push(...b.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=KN(l),u=new MediaStream(c.track?[a,c.track]:[a]),f=BN(),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",b=new Blob(g,{type:m}),w={status:"recorded",url:URL.createObjectURL(b),blob:b,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:zN(i)})}}function Vu(n){const e=$s.get(n);e&&e.recorder.state!=="inactive"&&e.recorder.stop()}function HN(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=Xi.get(n);t?.status==="recorded"&&URL.revokeObjectURL(t.url),Ii(n,void 0)}function JN(n,e){return e?e.status:n?"lost":"idle"}const Yu=j_?S.useLayoutEffect:S.useEffect;function qN({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=Ae(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:hw,size:"small",variant:"invisible",onClick:s,"aria-label":"copy",sx:t?{color:"var(--fgColor-success)"}:void 0})}const VN=8;function YN({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:b,isOutside:w}=GN(m);if(w){s(!1);return}if(!b)return;f.current=b;let C=null,v="";if(e.update(()=>{const k=Ae(b);je(k)&&(C=k,v=C.getLanguage()||"")}),C){const{y:k,right:I}=n.getBoundingClientRect(),{y:E,right:N}=b.getBoundingClientRect();r(v),s(!0),c({right:`${I-N+VN}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[b,w]of m)switch(w){case"created":u.current.add(b);break;case"destroyed":u.current.delete(b);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(qN,{editor:e,getCodeDOMNode:d}),E0(h)?x.jsx(L0,{editor:e,getCodeDOMNode:d,lang:h}):null]}):null})}function GN(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 JM({anchorElem:n=document.body}){return St.createPortal(x.jsx(YN,{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 ZN=pe({name:"@datalayer/jupyter-lexical/CodeBlockHighlight",dependencies:[Vh],register:XN}),Gu=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 QN(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(Gu,()=>(n.update(()=>{const e=Z_(),t=ne();sr(Eu(!0).append(e.append(t),Nu().append(ne()))),t.select()}),!0),ee))}const e2=pe({name:"@datalayer/jupyter-lexical/Collapsible",nodes:()=>[Mr,Os,$r],register:QN}),t2=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 n2(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 r2({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 o2({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(r2,{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]),t2(()=>{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 b=S.useMemo(()=>({options:o,selectOptionAndCleanUp:h,selectedIndex:d,setHighlightedIndex:f}),[h,d,o]);return s!=null?s(t,b,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 s2(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:b}=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=`${b}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+b&&(d.style.top=`${_-v-b+(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 n2(n,l.current,c,u),a!=null&&a===l.current&&(Pg(a,t),i?.append(a)),l}const i2=`\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'"~=<>_:;`;function Hm(n,{minLength:e=1,maxLength:t=75,punctuation:r=i2,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),_=s2(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]),b=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(()=>b({getRect:()=>v.getBoundingClientRect(),match:E}));m()})});return()=>{w()}},[d,i,e,g,m,b,f]),S.useEffect(()=>d.registerEditableListener(w=>{w||m()}),[d,m]),g===null||d===null||_.current===null?null:x.jsx(o2,{close:m,resolution:g,editor:d,anchorElementRef:_,options:n,menuRenderFn:s,shouldSplitNodeWithQuery:!0,onSelectOption:t,commandPriority:l,preselectFirstItem:u})}const a2=n=>n.split(/[\s._-]+/).filter(Boolean).slice(0,2).map(e=>e[0].toUpperCase()).join("")||"?";function l2({author:n,size:e}){const t=Jc(n);return n.avatarUrl?x.jsx(ux,{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(_w,{size:Math.round(e*.65)}):a2(t)})}const jr=S.createContext({}),c2=[],u2=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:[]})})},u2);return()=>{o=!1,clearTimeout(s)}},[n,e]),t&&t.query===n?t.people:c2}class d2 extends Wm{person;constructor(e){super(e.uid),this.person=e}}function f2({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 d2(c)),[s]),a=Hm("@",{minLength:1}),l=S.useCallback((c,u,f)=>{e.update(()=>{const d=$e(`@${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 g2({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:rx,"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(vn,{"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 p2={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"}},h2={...p2,paragraph:"CommentEditorTheme__paragraph"},ys=he();function _2({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:h2,dependencies:[Sw,Sh,vw]}),m2=pe({name:"@datalayer/jupyter-lexical/CommentComposer/Focused",dependencies:[Vm,kw]});function b2({editorRef:n}){const[e]=fe();return Yu(()=>(n.current=e,()=>{n.current=null}),[e,n]),null}function y2({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:m2;return x.jsx(xw,{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(Cw,{onChange:r}),x.jsx(y2,{onEscape:t}),o!==void 0&&x.jsx(f2,{onMention:o}),s!==void 0&&x.jsx(b2,{editorRef:s})]})})}function Gm(n,e){return S.useCallback((t,r)=>{t.read(()=>{n(yw()),e(!ww(r.isComposing(),!0))})},[e,n])}const jg=256;function w2({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=$l(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)}},b=Gm(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:b,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 x2({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=Gm(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(Iw,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:Tw,"aria-label":"Send comment",variant:"invisible",size:"small",onClick:d,disabled:!s})]})}function Xm({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 C2(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]=Go(),{Avatar:i=l2}=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:["· ",C2(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(Xm,{commentOrThread:n,deleteCommentOrThread:e,thread:t,onClose:l}))}}),o]})]})}function S2({activeIDs:n,comments:e,deleteCommentOrThread:t,listRef:r,submitAddComment:o,markNodeMap:s,resolveThread:i}){const[a]=fe(),[l,c]=S.useState(0),[u,f]=Go(),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 b=document.activeElement;a.update(()=>{const w=Array.from(m)[0],C=Q(w);Ro(C)&&C.selectStart()},{onUpdate(){b!==null&&b.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(Xm,{commentOrThread:g,deleteCommentOrThread:t,onClose:m}))}}),u]}),x.jsx(g2,{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(x2,{submitAddComment:o,thread:g,placeholder:"Reply to comment..."})})]},h)}return x.jsx(Fg,{comment:g,deleteComment:t,rtf:d},h)})})}function v2({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(bw,{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(S2,{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 qM({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([]),[b,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(mw(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:[b&&x.jsx(jr.Provider,{value:M,children:x.jsx(w2,{editor:s,cancelAddComment:v,submitAddComment:N})}),e&&g!==null&&g!==void 0&&!b&&St.createPortal(x.jsx(_2,{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(v2,{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:Ke().describe("Left edge, in scene coordinates"),y:Ke().describe("Top edge, in scene coordinates"),width:Ke().optional().describe("Width in pixels (shapes only)"),height:Ke().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:Ke().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:Ke().optional().describe("Outline thickness, 1 | 2 | 4"),strokeStyle:wr(["solid","dashed","dotted"]).optional().describe("Outline style"),roughness:Ke().optional().describe("0 for architect (clean), 1 for artist, 2 for cartoonist"),opacity:Ke().optional().describe("0-100"),angle:Ke().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(Ke())).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:Ke().optional().describe("Rendered width in pixels. Omit to size to the content."),height:Ke().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:Ke().optional(),y:Ke().optional(),width:Ke().optional(),height:Ke().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:Ke().optional(),strokeStyle:wr(["solid","dashed","dotted"]).optional(),opacity:Ke().optional().describe("0-100"),angle:Ke().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:Ke().optional().describe("Grid spacing in pixels. 0 turns the grid off.")}),cb=Lt({blockId:On,width:Ke().optional().describe("Rendered width in pixels. Omit to go back to sizing by content."),height:Ke().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:Ke().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"],k2={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"]},T2={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"]},I2={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"]},E2={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"]},N2={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"]},L2={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"]},O2={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"]},R2={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"]},A2={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"]},M2={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"]},$2={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=[k2,$2,T2,I2,E2,N2,O2,L2,R2,A2,M2],hl=()=>({elements:[],appState:{},files:{}});function Xu(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 Xs=n=>n.elements.filter(e=>!e?.isDeleted);function D2(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 P2(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=D2(t);if(r.text===void 0){const o=e.get(r.id);o&&(r.text=o)}return r})}function Qu(n){const e=Xs(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??""}),Xu(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 hn=(n,e,t)=>({success:!0,blockId:n,elementCount:Xs(e).length,...t});let j2=0;const F2=()=>`dla-${Date.now().toString(36)}-${(j2+=1).toString(36)}`;function B2(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-BpahO1D1.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=F2()),e.add(a),r.push(a),B2(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 U2(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?U2(c,String(e.id)):c),l}const z2=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 hn(s.blockId,o,{createdIds:r.ids,message:`Drawing inserted with ${r.elements.length} element(s)`})},K2=async n=>{const t=(await n.getBlocks("detailed")).filter(r=>r.block_type==="excalidraw").map(r=>{const o=Xu(r.metadata?.data);return{blockId:r.block_id,elementCount:Xs(o).length,description:Qu(o),width:r.metadata?.width,height:r.metadata?.height}});return{drawings:t,count:t.length}},W2=async(n,e)=>{const t=String(e.blockId),r=Rn(n.editor,t),o=Xs(r);return{blockId:t,elementCount:o.length,elements:e.detail==="full"?o:P2(o),appState:r.appState,description:Qu(r)}},H2=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,...b}=u;return b}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),hn(t,r,{createdIds:c.ids,message:`Added ${c.elements.length} element(s)`})},J2=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),hn(t,r,{message:`Updated ${o.length} element(s)`})},q2=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),hn(t,r,{message:`Removed ${i-r.elements.length} element(s)`})},V2=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),hn(t,r,{createdIds:[c],message:`Connected '${o}' to '${s}'`})},Y2=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),hn(t,r,{message:"Canvas updated"})},G2=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 hn(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=Xs(r).length;return r.elements=[],r.files={},await eo(n.editor,t,r),hn(t,r,{message:`Emptied the drawing (${o} element(s) removed)`})},Z2=async(n,e)=>{const{parseMermaidToExcalidraw:t}=await me(async()=>{const{parseMermaidToExcalidraw:c}=await import("./index-DtYYe0Cw.js").then(u=>u.an);return{parseMermaidToExcalidraw:c}},[],import.meta.url),{convertToExcalidrawElements:r}=await me(async()=>{const{convertToExcalidrawElements:c}=await import("./percentages-BXMCSKIN-BpahO1D1.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),hn(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 hn(l.blockId,a,{createdIds:s.map(c=>String(c.id)),message:`Drawing inserted with ${s.length} element(s) from Mermaid`})},bc={excalidrawInsertNode:z2,excalidrawListDrawings:K2,excalidrawReadScene:W2,excalidrawAddElements:H2,excalidrawUpdateElements:J2,excalidrawDeleteElements:q2,excalidrawConnectElements:V2,excalidrawSetAppState:Y2,excalidrawResize:G2,excalidrawClearScene:X2,excalidrawFromMermaid:Z2};function tn(n,e){return{name:n,async execute(t,r){const o=Ew(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 Q2=tn("excalidrawInsertNode",tb),eL=tn("excalidrawListDrawings",nb),tL=tn("excalidrawReadScene",rb),nL=tn("excalidrawAddElements",ob),rL=tn("excalidrawUpdateElements",sb),oL=tn("excalidrawDeleteElements",ib),sL=tn("excalidrawConnectElements",ab),iL=tn("excalidrawSetAppState",lb),aL=tn("excalidrawResize",cb),lL=tn("excalidrawClearScene",ub),cL=tn("excalidrawFromMermaid",db),Ei={excalidrawInsertNode:Q2,excalidrawListDrawings:eL,excalidrawReadScene:tL,excalidrawAddElements:nL,excalidrawUpdateElements:rL,excalidrawDeleteElements:oL,excalidrawConnectElements:sL,excalidrawSetAppState:iL,excalidrawResize:aL,excalidrawClearScene:lL,excalidrawFromMermaid:cL},Ug={name:"excalidraw",definitions:fb,operations:Ei,handlers:bc};function VM(){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 uL=S.lazy(()=>me(()=>import("./ExcalidrawModal-B2sXbVJB.js"),[],import.meta.url)),nd=he();function dL(){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(uL,{initialElements:[],initialAppState:{},initialFiles:{},isShown:e,onSave:s,onDelete:i,onClose:a,closeOnClickOutside:!1})}):null}const fL=S.lazy(()=>me(()=>import("./DeckComponent-Fp6Vw8vN.js"),[],import.meta.url));function gL(){return{deck:{title:"Untitled deck",template:"datalayer"},slides:[{type:"title",title:"A new slide",meta:"Double-click to edit its specification"}]}}function pL(n){const e=n.getAttribute("data-lexical-deck");if(!e)return null;try{return{node:rd(JSON.parse(e))}}catch{return null}}class Xo extends Jo{__spec;static getType(){return"deck"}static clone(e){return new Xo(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:pL,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??gL()}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(fL,{className:{base:r.base||"",focus:r.focus||""},format:this.__format,nodeKey:this.getKey(),spec:this.__spec})})}isTopLevel(){return!0}}function rd(n){return new Xo(n)}function YM(n){return n instanceof Xo}const od=he("INSERT_DECK_COMMAND");function hL(n){if(!n.hasNodes([Xo]))throw new Error("DeckExtension: DeckNode not registered on editor");return n.registerCommand(od,e=>(sr(rd(e)),!0),V)}const _L=pe({name:"@datalayer/jupyter-lexical/Deck",nodes:()=>[Xo],register:hL}),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 mL(n){const e=Math.max(0,Math.floor(n/1e3));return`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`}function bL(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 yL({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:mL(r-e.startedAt)}),x.jsx(ft,{variant:"danger",leadingVisual:Lw,onClick:()=>Vu(n),sx:{ml:"auto"},children:"Stop"})]})]})}function wL({className:n,format:e,nodeKey:t,recordingId:r,recorded:o}){const[s]=fe(),i=Hr(),a=S.useSyncExternalStore(DN,()=>PN(r)),l=JN(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=()=>{WN(r,{source:c,microphone:f},()=>g(!0))},_=()=>{HN(r),g(!1)},m=w=>{const C=document.createElement("a");C.href=w.url,C.download=UN(w),C.click()};let b;return a?.status==="recording"?b=x.jsx(yL,{recordingId:r,recording:a}):a?.status==="recorded"?b=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:bL,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:Nw,onClick:()=>m(a),children:"Download"}),i&&x.jsx(ft,{onClick:_,children:"Record again"})]})]}):l==="lost"?b=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?b=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]}),FN()?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})]}):b=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:b})})}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||jN(),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(wL,{className:{base:r.base||"",focus:r.focus||""},format:this.__format,nodeKey:this.getKey(),recordingId:this.__recordingId,recorded:this.__recorded})}isTopLevel(){return!0}}function xL(){return new Zn}function _b(n){return n instanceof Zn}const sd=he("INSERT_VIDEO_COMMAND");function CL(n){if(!n.hasNodes([Zn]))throw new Error("VideoExtension: VideoNode not registered on editor");return de(n.registerCommand(sd,()=>(sr(xL()),!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 SL=pe({name:"@datalayer/jupyter-lexical/Video",nodes:()=>[Zn],register:CL});function vL({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(vn,{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(vn,{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(vL,{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},kL=Object.freeze(Object.defineProperty({__proto__:null,EquationsPlugin:Kg,INSERT_EQUATION_COMMAND:id,InsertEquationDialog:ad,default:Kg},Symbol.toStringTag,{value:"Module"}));class ze 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 TL({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 IL=({kernel:n,initCode:e=""}={})=>{const[t]=fe(),[r,o]=Go(),[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,b]=h[0].split("x").map(w=>parseInt(w,10));f.push(new ze(`${m}x${b} 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},(b,w)=>w+1).map(b=>new ze(`${m}x${b} 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 ze("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 ze("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 ze("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 ze(`Heading ${g}`,{icon:x.jsx(ox,{size:16}),keywords:["heading","header",`h${g}`],onSelect:()=>t.update(()=>{const h=D();F(h)&&Un(h,()=>fn(`h${g}`))})})),new ze("Numbered List",{icon:x.jsx(Eh,{size:16}),keywords:["numbered list","ordered list","ol"],onSelect:()=>t.dispatchCommand(eu,void 0)}),new ze("Bulleted List",{icon:x.jsx(vh,{size:16}),keywords:["bulleted list","unordered list","ul"],onSelect:()=>t.dispatchCommand(Qc,void 0)}),new ze("Check List",{icon:x.jsx(Ow,{size:16}),keywords:["check list","todo list"],onSelect:()=>t.dispatchCommand(Zc,void 0)}),new ze("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 ze("Collapsible Container",{icon:x.jsx(zc,{size:16}),keywords:["collapsible","collapse","expand","toggle","accordion","container"],onSelect:()=>t.dispatchCommand(Gu,void 0)}),new ze("Excalidraw",{icon:x.jsx(Rw,{size:16}),keywords:["excalidraw","drawing","diagram","sketch","whiteboard","draw"],onSelect:()=>t.dispatchCommand(nd,void 0)}),new ze("Video",{icon:x.jsx(Wc,{size:16}),keywords:["video","record","recording","screen","camera","webcam"],onSelect:()=>t.dispatchCommand(sd,void 0)}),new ze("Loom Video",{icon:x.jsx(Ws,{size:16}),keywords:["loom","video","record","recording","screen"],onSelect:()=>t.dispatchCommand(ka,void 0)}),new ze("Deck Slide",{icon:x.jsx(hs,{size:16}),keywords:["deck","slide","slides","presentation","pitch"],onSelect:()=>t.dispatchCommand(od,void 0)}),new ze("Quote",{icon:x.jsx(Nh,{size:16}),keywords:["block quote"],onSelect:()=>t.update(()=>{const g=D();F(g)&&Un(g,()=>Ln())})}),new ze("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 ze("Divider",{icon:x.jsx(ji,{size:16}),keywords:["horizontal rule","divider","hr"],onSelect:()=>t.dispatchCommand(Kc,void 0)}),...qu.map(g=>new ze(`Embed ${g.contentName}`,{icon:g.icon,keywords:[...g.keywords,"embed"],onSelect:()=>t.dispatchCommand(Ju,g.type)})),new ze("Equation",{icon:x.jsx(Aw,{size:16}),keywords:["equation","latex","math"],onSelect:()=>o("Insert Equation",g=>x.jsx(ad,{activeEditor:t,onClose:g}))}),new ze("GIF",{icon:x.jsx(hs,{size:16}),keywords:["gif","animate","image","file"],onSelect:()=>{yu().then(g=>{g&&t.dispatchCommand(Ys,g)})}}),new ze("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 ze(`Align ${g}`,{icon:g==="left"?x.jsx(sx,{size:16}):g==="right"?x.jsx(ix,{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(TL,{index:m,isSelected:d===m,onClick:()=>{_.disabled||(h(m),g(_))},onMouseEnter:()=>{_.disabled||h(m)},option:_},_.key))})}),f.current):null})]})},yc=4,EL=2,NL="draggable-block-menu",Wg="application/x-lexical-drag-block",Hg=28,LL=1,OL=-1,Jg=0;let Ni=1/0;function RL(n){return n===0?1/0:Ni>=0&&Ni<n?Ni:Math.floor(n/2)}function AL(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=AL(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=RL(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:b,reason:{isOnTopSide:w,isOnBottomSide:C}}=m.contains(d);if(b){i=u,Ni=a;break}l===Jg&&(w?l=OL:C?l=LL:l=1/0),a+=l}}),i}function ML(n){return!!n.closest(`.${NL}`)}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 $L(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 DL(n,e){const{transform:t}=e.style;e.style.transform="translateZ(0)",n.setDragImage(e,0,0),setTimeout(()=>{e.style.transform=t})}function PL(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-EL+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 jL(n){n&&(n.style.opacity="0",n.style.transform="translate(-10000px, -10000px)")}function FL(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)||ML(m))return;const b=_l(e,n,_);a(b)}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&&$L(i,r.current,e)},[e,i]),S.useEffect(()=>{function g(_){if(!s.current)return!1;const[m]=uo(_);if(m)return!1;const{pageY:b,target:w}=_;if(!pl(w))return!1;const C=_l(e,n,_,!0),v=o.current;return C===null||v===null?!1:(PL(v,C,b/Wn(w),e),_.preventDefault(),!0)}function h(_){if(!s.current)return!1;const[m]=uo(_);if(m)return!1;const{target:b,dataTransfer:w,pageY:C}=_,v=w?.getData(Wg)||"",k=Q(v);if(!k||!pl(b))return!1;const I=_l(e,n,_,!0);if(!I)return!1;const E=Ae(I);if(!E)return!1;if(E===k)return!0;const N=I.getBoundingClientRect().top;return C/Wn(b)>=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;DL(h,i);let _="";n.update(()=>{const m=Ae(i);m&&(_=m.getKey())}),s.current=!0,h.setData(Wg,_)}function d(){s.current=!1,jL(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(Mw,{size:16}):null}),x.jsx("div",{className:`draggable-block-target-line ${u}`,ref:o})]}),e)}function XM({anchorElem:n=document.body}){const[e]=fe();return FL(e,n,e._editable)}const BL=()=>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 UL(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,b]=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")),b(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(Xe,"bold")},{key:"italic",type:"button",order:1,ariaLabel:"Format text as italics",title:"Italic",icon:Oh,isActive:u,onClick:()=>n.dispatchCommand(Xe,"italic")},{key:"underline",type:"button",order:2,ariaLabel:"Format text to underlined",title:"Underline",icon:BL,isActive:d,onClick:()=>n.dispatchCommand(Xe,"underline")},{key:"strikethrough",type:"button",order:3,ariaLabel:"Format text with a strikethrough",title:"Strikethrough",icon:Rh,isActive:h,onClick:()=>n.dispatchCommand(Xe,"strikethrough")},{key:"subscript",type:"button",order:4,ariaLabel:"Format Subscript",title:"Subscript",icon:void 0,label:"x₂",isActive:m,onClick:()=>n.dispatchCommand(Xe,"subscript")},{key:"superscript",type:"button",order:5,ariaLabel:"Format Superscript",title:"Superscript",icon:void 0,label:"x²",isActive:w,onClick:()=>n.dispatchCommand(Xe,"superscript")},{key:"code",type:"button",order:6,ariaLabel:"Insert code block",title:"Code",icon:br,isActive:v,onClick:()=>n.dispatchCommand(Xe,"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 ZM({anchorElem:n=document.body,setIsLinkEditMode:e,extraItems:t}){const[r]=fe();return UL(r,n,e,t)}function zL(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:zL}),ss={code:{triggerMode:"auto",contextBefore:-1,contextAfter:-1,language:"python"},prose:{triggerMode:"manual",contextBefore:-1,contextAfter:-1},debounceMs:200,manualTriggerKey:"Cmd+Shift+,"};function KL(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 QM(n){return n===-1||n>=0}function e$(n){return n.triggerMode==="auto"}function t$(n){return n.triggerMode==="manual"||n.triggerMode==="auto"}function n$(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($w,{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 r$(n){return n instanceof Fr}const WL=he(),HL=he();function JL(n){if(!n.hasNodes([Fr]))throw new Error("JupyterCellNode is not registered.");return de(n.registerCommand(WL,e=>{const t=Vg(e);return Tr([t]),!0},V),n.registerCommand(HL,e=>{const t=Vg({...e});return Tr([t]),!0},V))}const qL=pe({name:"@datalayer/jupyter-lexical/JupyterCell",nodes:()=>[Fr],register:JL}),VL=he("INSERT_LAYOUT_COMMAND");function YL(n){return n.trim().split(/\s+/).length}function o$(n){return Array.from({length:Math.max(1,n)},()=>"1fr").join(" ")}function GL(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(VL,t=>(n.update(()=>{const r=Ou(t);for(let o=0;o<YL(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:GL});function Yg(n,e,t,r,o){return n==="code"?ZL(e,t):QL(e,t,r,o)}function ZL(n,e){const t=n.getTextContent(),r=nO(n,e),o=t.substring(0,r),s=t.substring(r);return{before:o,after:s,fullText:t}}function QL(n,e,t,r){const s=se().getChildren(),i=eO(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 ZN=pe({name:"@datalayer/jupyter-lexical/CodeBlockHighlight",dependencies:[Vh],register:XN}),Gu=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 QN(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(Gu,()=>(n.update(()=>{const e=Z_(),t=ne();sr(Eu(!0).append(e.append(t),Nu().append(ne()))),t.select()}),!0),ee))}const e2=pe({name:"@datalayer/jupyter-lexical/Collapsible",nodes:()=>[Mr,Os,$r],register:QN}),t2=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 n2(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 r2({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 o2({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(r2,{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]),t2(()=>{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 b=S.useMemo(()=>({options:o,selectOptionAndCleanUp:h,selectedIndex:d,setHighlightedIndex:f}),[h,d,o]);return s!=null?s(t,b,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 s2(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:b}=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=`${b}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+b&&(d.style.top=`${_-v-b+(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 n2(n,l.current,c,u),a!=null&&a===l.current&&(Pg(a,t),i?.append(a)),l}const i2=`\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'"~=<>_:;`;function Hm(n,{minLength:e=1,maxLength:t=75,punctuation:r=i2,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),_=s2(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]),b=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(()=>b({getRect:()=>v.getBoundingClientRect(),match:E}));m()})});return()=>{w()}},[d,i,e,g,m,b,f]),S.useEffect(()=>d.registerEditableListener(w=>{w||m()}),[d,m]),g===null||d===null||_.current===null?null:x.jsx(o2,{close:m,resolution:g,editor:d,anchorElementRef:_,options:n,menuRenderFn:s,shouldSplitNodeWithQuery:!0,onSelectOption:t,commandPriority:l,preselectFirstItem:u})}const a2=n=>n.split(/[\s._-]+/).filter(Boolean).slice(0,2).map(e=>e[0].toUpperCase()).join("")||"?";function l2({author:n,size:e}){const t=Jc(n);return n.avatarUrl?x.jsx(ux,{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(_w,{size:Math.round(e*.65)}):a2(t)})}const jr=S.createContext({}),c2=[],u2=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:[]})})},u2);return()=>{o=!1,clearTimeout(s)}},[n,e]),t&&t.query===n?t.people:c2}class d2 extends Wm{person;constructor(e){super(e.uid),this.person=e}}function f2({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 d2(c)),[s]),a=Hm("@",{minLength:1}),l=S.useCallback((c,u,f)=>{e.update(()=>{const d=$e(`@${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 g2({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:rx,"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(vn,{"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 p2={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"}},h2={...p2,paragraph:"CommentEditorTheme__paragraph"},ys=he();function _2({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:h2,dependencies:[Sw,Sh,vw]}),m2=pe({name:"@datalayer/jupyter-lexical/CommentComposer/Focused",dependencies:[Vm,kw]});function b2({editorRef:n}){const[e]=fe();return Yu(()=>(n.current=e,()=>{n.current=null}),[e,n]),null}function y2({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:m2;return x.jsx(xw,{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(Cw,{onChange:r}),x.jsx(y2,{onEscape:t}),o!==void 0&&x.jsx(f2,{onMention:o}),s!==void 0&&x.jsx(b2,{editorRef:s})]})})}function Gm(n,e){return S.useCallback((t,r)=>{t.read(()=>{n(yw()),e(!ww(r.isComposing(),!0))})},[e,n])}const jg=256;function w2({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=$l(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)}},b=Gm(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:b,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 x2({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=Gm(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(Iw,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:Tw,"aria-label":"Send comment",variant:"invisible",size:"small",onClick:d,disabled:!s})]})}function Xm({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 C2(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]=Go(),{Avatar:i=l2}=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:["· ",C2(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(Xm,{commentOrThread:n,deleteCommentOrThread:e,thread:t,onClose:l}))}}),o]})]})}function S2({activeIDs:n,comments:e,deleteCommentOrThread:t,listRef:r,submitAddComment:o,markNodeMap:s,resolveThread:i}){const[a]=fe(),[l,c]=S.useState(0),[u,f]=Go(),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 b=document.activeElement;a.update(()=>{const w=Array.from(m)[0],C=Q(w);Ro(C)&&C.selectStart()},{onUpdate(){b!==null&&b.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(Xm,{commentOrThread:g,deleteCommentOrThread:t,onClose:m}))}}),u]}),x.jsx(g2,{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(x2,{submitAddComment:o,thread:g,placeholder:"Reply to comment..."})})]},h)}return x.jsx(Fg,{comment:g,deleteComment:t,rtf:d},h)})})}function v2({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(bw,{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(S2,{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 qM({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([]),[b,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(mw(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:[b&&x.jsx(jr.Provider,{value:M,children:x.jsx(w2,{editor:s,cancelAddComment:v,submitAddComment:N})}),e&&g!==null&&g!==void 0&&!b&&St.createPortal(x.jsx(_2,{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(v2,{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:Ke().describe("Left edge, in scene coordinates"),y:Ke().describe("Top edge, in scene coordinates"),width:Ke().optional().describe("Width in pixels (shapes only)"),height:Ke().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:Ke().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:Ke().optional().describe("Outline thickness, 1 | 2 | 4"),strokeStyle:wr(["solid","dashed","dotted"]).optional().describe("Outline style"),roughness:Ke().optional().describe("0 for architect (clean), 1 for artist, 2 for cartoonist"),opacity:Ke().optional().describe("0-100"),angle:Ke().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(Ke())).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:Ke().optional().describe("Rendered width in pixels. Omit to size to the content."),height:Ke().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:Ke().optional(),y:Ke().optional(),width:Ke().optional(),height:Ke().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:Ke().optional(),strokeStyle:wr(["solid","dashed","dotted"]).optional(),opacity:Ke().optional().describe("0-100"),angle:Ke().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:Ke().optional().describe("Grid spacing in pixels. 0 turns the grid off.")}),cb=Lt({blockId:On,width:Ke().optional().describe("Rendered width in pixels. Omit to go back to sizing by content."),height:Ke().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:Ke().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"],k2={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"]},T2={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"]},I2={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"]},E2={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"]},N2={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"]},L2={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"]},O2={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"]},R2={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"]},A2={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"]},M2={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"]},$2={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=[k2,$2,T2,I2,E2,N2,O2,L2,R2,A2,M2],hl=()=>({elements:[],appState:{},files:{}});function Xu(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 Xs=n=>n.elements.filter(e=>!e?.isDeleted);function D2(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 P2(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=D2(t);if(r.text===void 0){const o=e.get(r.id);o&&(r.text=o)}return r})}function Qu(n){const e=Xs(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??""}),Xu(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 hn=(n,e,t)=>({success:!0,blockId:n,elementCount:Xs(e).length,...t});let j2=0;const F2=()=>`dla-${Date.now().toString(36)}-${(j2+=1).toString(36)}`;function B2(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-917PkDRT.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=F2()),e.add(a),r.push(a),B2(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 U2(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?U2(c,String(e.id)):c),l}const z2=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 hn(s.blockId,o,{createdIds:r.ids,message:`Drawing inserted with ${r.elements.length} element(s)`})},K2=async n=>{const t=(await n.getBlocks("detailed")).filter(r=>r.block_type==="excalidraw").map(r=>{const o=Xu(r.metadata?.data);return{blockId:r.block_id,elementCount:Xs(o).length,description:Qu(o),width:r.metadata?.width,height:r.metadata?.height}});return{drawings:t,count:t.length}},W2=async(n,e)=>{const t=String(e.blockId),r=Rn(n.editor,t),o=Xs(r);return{blockId:t,elementCount:o.length,elements:e.detail==="full"?o:P2(o),appState:r.appState,description:Qu(r)}},H2=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,...b}=u;return b}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),hn(t,r,{createdIds:c.ids,message:`Added ${c.elements.length} element(s)`})},J2=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),hn(t,r,{message:`Updated ${o.length} element(s)`})},q2=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),hn(t,r,{message:`Removed ${i-r.elements.length} element(s)`})},V2=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),hn(t,r,{createdIds:[c],message:`Connected '${o}' to '${s}'`})},Y2=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),hn(t,r,{message:"Canvas updated"})},G2=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 hn(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=Xs(r).length;return r.elements=[],r.files={},await eo(n.editor,t,r),hn(t,r,{message:`Emptied the drawing (${o} element(s) removed)`})},Z2=async(n,e)=>{const{parseMermaidToExcalidraw:t}=await me(async()=>{const{parseMermaidToExcalidraw:c}=await import("./index-DtYYe0Cw.js").then(u=>u.an);return{parseMermaidToExcalidraw:c}},[],import.meta.url),{convertToExcalidrawElements:r}=await me(async()=>{const{convertToExcalidrawElements:c}=await import("./percentages-BXMCSKIN-917PkDRT.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),hn(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 hn(l.blockId,a,{createdIds:s.map(c=>String(c.id)),message:`Drawing inserted with ${s.length} element(s) from Mermaid`})},bc={excalidrawInsertNode:z2,excalidrawListDrawings:K2,excalidrawReadScene:W2,excalidrawAddElements:H2,excalidrawUpdateElements:J2,excalidrawDeleteElements:q2,excalidrawConnectElements:V2,excalidrawSetAppState:Y2,excalidrawResize:G2,excalidrawClearScene:X2,excalidrawFromMermaid:Z2};function tn(n,e){return{name:n,async execute(t,r){const o=Ew(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 Q2=tn("excalidrawInsertNode",tb),eL=tn("excalidrawListDrawings",nb),tL=tn("excalidrawReadScene",rb),nL=tn("excalidrawAddElements",ob),rL=tn("excalidrawUpdateElements",sb),oL=tn("excalidrawDeleteElements",ib),sL=tn("excalidrawConnectElements",ab),iL=tn("excalidrawSetAppState",lb),aL=tn("excalidrawResize",cb),lL=tn("excalidrawClearScene",ub),cL=tn("excalidrawFromMermaid",db),Ei={excalidrawInsertNode:Q2,excalidrawListDrawings:eL,excalidrawReadScene:tL,excalidrawAddElements:nL,excalidrawUpdateElements:rL,excalidrawDeleteElements:oL,excalidrawConnectElements:sL,excalidrawSetAppState:iL,excalidrawResize:aL,excalidrawClearScene:lL,excalidrawFromMermaid:cL},Ug={name:"excalidraw",definitions:fb,operations:Ei,handlers:bc};function VM(){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 uL=S.lazy(()=>me(()=>import("./ExcalidrawModal-C5Or1sZ5.js"),[],import.meta.url)),nd=he();function dL(){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(uL,{initialElements:[],initialAppState:{},initialFiles:{},isShown:e,onSave:s,onDelete:i,onClose:a,closeOnClickOutside:!1})}):null}const fL=S.lazy(()=>me(()=>import("./DeckComponent-BfOXdQhk.js"),[],import.meta.url));function gL(){return{deck:{title:"Untitled deck",template:"datalayer"},slides:[{type:"title",title:"A new slide",meta:"Double-click to edit its specification"}]}}function pL(n){const e=n.getAttribute("data-lexical-deck");if(!e)return null;try{return{node:rd(JSON.parse(e))}}catch{return null}}class Xo extends Jo{__spec;static getType(){return"deck"}static clone(e){return new Xo(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:pL,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??gL()}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(fL,{className:{base:r.base||"",focus:r.focus||""},format:this.__format,nodeKey:this.getKey(),spec:this.__spec})})}isTopLevel(){return!0}}function rd(n){return new Xo(n)}function YM(n){return n instanceof Xo}const od=he("INSERT_DECK_COMMAND");function hL(n){if(!n.hasNodes([Xo]))throw new Error("DeckExtension: DeckNode not registered on editor");return n.registerCommand(od,e=>(sr(rd(e)),!0),V)}const _L=pe({name:"@datalayer/jupyter-lexical/Deck",nodes:()=>[Xo],register:hL}),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 mL(n){const e=Math.max(0,Math.floor(n/1e3));return`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`}function bL(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 yL({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:mL(r-e.startedAt)}),x.jsx(ft,{variant:"danger",leadingVisual:Lw,onClick:()=>Vu(n),sx:{ml:"auto"},children:"Stop"})]})]})}function wL({className:n,format:e,nodeKey:t,recordingId:r,recorded:o}){const[s]=fe(),i=Hr(),a=S.useSyncExternalStore(DN,()=>PN(r)),l=JN(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=()=>{WN(r,{source:c,microphone:f},()=>g(!0))},_=()=>{HN(r),g(!1)},m=w=>{const C=document.createElement("a");C.href=w.url,C.download=UN(w),C.click()};let b;return a?.status==="recording"?b=x.jsx(yL,{recordingId:r,recording:a}):a?.status==="recorded"?b=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:bL,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:Nw,onClick:()=>m(a),children:"Download"}),i&&x.jsx(ft,{onClick:_,children:"Record again"})]})]}):l==="lost"?b=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?b=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]}),FN()?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})]}):b=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:b})})}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||jN(),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(wL,{className:{base:r.base||"",focus:r.focus||""},format:this.__format,nodeKey:this.getKey(),recordingId:this.__recordingId,recorded:this.__recorded})}isTopLevel(){return!0}}function xL(){return new Zn}function _b(n){return n instanceof Zn}const sd=he("INSERT_VIDEO_COMMAND");function CL(n){if(!n.hasNodes([Zn]))throw new Error("VideoExtension: VideoNode not registered on editor");return de(n.registerCommand(sd,()=>(sr(xL()),!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 SL=pe({name:"@datalayer/jupyter-lexical/Video",nodes:()=>[Zn],register:CL});function vL({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(vn,{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(vn,{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(vL,{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},kL=Object.freeze(Object.defineProperty({__proto__:null,EquationsPlugin:Kg,INSERT_EQUATION_COMMAND:id,InsertEquationDialog:ad,default:Kg},Symbol.toStringTag,{value:"Module"}));class ze 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 TL({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 IL=({kernel:n,initCode:e=""}={})=>{const[t]=fe(),[r,o]=Go(),[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,b]=h[0].split("x").map(w=>parseInt(w,10));f.push(new ze(`${m}x${b} 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},(b,w)=>w+1).map(b=>new ze(`${m}x${b} 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 ze("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 ze("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 ze("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 ze(`Heading ${g}`,{icon:x.jsx(ox,{size:16}),keywords:["heading","header",`h${g}`],onSelect:()=>t.update(()=>{const h=D();F(h)&&Un(h,()=>fn(`h${g}`))})})),new ze("Numbered List",{icon:x.jsx(Eh,{size:16}),keywords:["numbered list","ordered list","ol"],onSelect:()=>t.dispatchCommand(eu,void 0)}),new ze("Bulleted List",{icon:x.jsx(vh,{size:16}),keywords:["bulleted list","unordered list","ul"],onSelect:()=>t.dispatchCommand(Qc,void 0)}),new ze("Check List",{icon:x.jsx(Ow,{size:16}),keywords:["check list","todo list"],onSelect:()=>t.dispatchCommand(Zc,void 0)}),new ze("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 ze("Collapsible Container",{icon:x.jsx(zc,{size:16}),keywords:["collapsible","collapse","expand","toggle","accordion","container"],onSelect:()=>t.dispatchCommand(Gu,void 0)}),new ze("Excalidraw",{icon:x.jsx(Rw,{size:16}),keywords:["excalidraw","drawing","diagram","sketch","whiteboard","draw"],onSelect:()=>t.dispatchCommand(nd,void 0)}),new ze("Video",{icon:x.jsx(Wc,{size:16}),keywords:["video","record","recording","screen","camera","webcam"],onSelect:()=>t.dispatchCommand(sd,void 0)}),new ze("Loom Video",{icon:x.jsx(Ws,{size:16}),keywords:["loom","video","record","recording","screen"],onSelect:()=>t.dispatchCommand(ka,void 0)}),new ze("Deck Slide",{icon:x.jsx(hs,{size:16}),keywords:["deck","slide","slides","presentation","pitch"],onSelect:()=>t.dispatchCommand(od,void 0)}),new ze("Quote",{icon:x.jsx(Nh,{size:16}),keywords:["block quote"],onSelect:()=>t.update(()=>{const g=D();F(g)&&Un(g,()=>Ln())})}),new ze("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 ze("Divider",{icon:x.jsx(ji,{size:16}),keywords:["horizontal rule","divider","hr"],onSelect:()=>t.dispatchCommand(Kc,void 0)}),...qu.map(g=>new ze(`Embed ${g.contentName}`,{icon:g.icon,keywords:[...g.keywords,"embed"],onSelect:()=>t.dispatchCommand(Ju,g.type)})),new ze("Equation",{icon:x.jsx(Aw,{size:16}),keywords:["equation","latex","math"],onSelect:()=>o("Insert Equation",g=>x.jsx(ad,{activeEditor:t,onClose:g}))}),new ze("GIF",{icon:x.jsx(hs,{size:16}),keywords:["gif","animate","image","file"],onSelect:()=>{yu().then(g=>{g&&t.dispatchCommand(Ys,g)})}}),new ze("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 ze(`Align ${g}`,{icon:g==="left"?x.jsx(sx,{size:16}):g==="right"?x.jsx(ix,{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(TL,{index:m,isSelected:d===m,onClick:()=>{_.disabled||(h(m),g(_))},onMouseEnter:()=>{_.disabled||h(m)},option:_},_.key))})}),f.current):null})]})},yc=4,EL=2,NL="draggable-block-menu",Wg="application/x-lexical-drag-block",Hg=28,LL=1,OL=-1,Jg=0;let Ni=1/0;function RL(n){return n===0?1/0:Ni>=0&&Ni<n?Ni:Math.floor(n/2)}function AL(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=AL(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=RL(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:b,reason:{isOnTopSide:w,isOnBottomSide:C}}=m.contains(d);if(b){i=u,Ni=a;break}l===Jg&&(w?l=OL:C?l=LL:l=1/0),a+=l}}),i}function ML(n){return!!n.closest(`.${NL}`)}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 $L(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 DL(n,e){const{transform:t}=e.style;e.style.transform="translateZ(0)",n.setDragImage(e,0,0),setTimeout(()=>{e.style.transform=t})}function PL(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-EL+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 jL(n){n&&(n.style.opacity="0",n.style.transform="translate(-10000px, -10000px)")}function FL(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)||ML(m))return;const b=_l(e,n,_);a(b)}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&&$L(i,r.current,e)},[e,i]),S.useEffect(()=>{function g(_){if(!s.current)return!1;const[m]=uo(_);if(m)return!1;const{pageY:b,target:w}=_;if(!pl(w))return!1;const C=_l(e,n,_,!0),v=o.current;return C===null||v===null?!1:(PL(v,C,b/Wn(w),e),_.preventDefault(),!0)}function h(_){if(!s.current)return!1;const[m]=uo(_);if(m)return!1;const{target:b,dataTransfer:w,pageY:C}=_,v=w?.getData(Wg)||"",k=Q(v);if(!k||!pl(b))return!1;const I=_l(e,n,_,!0);if(!I)return!1;const E=Ae(I);if(!E)return!1;if(E===k)return!0;const N=I.getBoundingClientRect().top;return C/Wn(b)>=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;DL(h,i);let _="";n.update(()=>{const m=Ae(i);m&&(_=m.getKey())}),s.current=!0,h.setData(Wg,_)}function d(){s.current=!1,jL(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(Mw,{size:16}):null}),x.jsx("div",{className:`draggable-block-target-line ${u}`,ref:o})]}),e)}function XM({anchorElem:n=document.body}){const[e]=fe();return FL(e,n,e._editable)}const BL=()=>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 UL(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,b]=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")),b(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(Xe,"bold")},{key:"italic",type:"button",order:1,ariaLabel:"Format text as italics",title:"Italic",icon:Oh,isActive:u,onClick:()=>n.dispatchCommand(Xe,"italic")},{key:"underline",type:"button",order:2,ariaLabel:"Format text to underlined",title:"Underline",icon:BL,isActive:d,onClick:()=>n.dispatchCommand(Xe,"underline")},{key:"strikethrough",type:"button",order:3,ariaLabel:"Format text with a strikethrough",title:"Strikethrough",icon:Rh,isActive:h,onClick:()=>n.dispatchCommand(Xe,"strikethrough")},{key:"subscript",type:"button",order:4,ariaLabel:"Format Subscript",title:"Subscript",icon:void 0,label:"x₂",isActive:m,onClick:()=>n.dispatchCommand(Xe,"subscript")},{key:"superscript",type:"button",order:5,ariaLabel:"Format Superscript",title:"Superscript",icon:void 0,label:"x²",isActive:w,onClick:()=>n.dispatchCommand(Xe,"superscript")},{key:"code",type:"button",order:6,ariaLabel:"Insert code block",title:"Code",icon:br,isActive:v,onClick:()=>n.dispatchCommand(Xe,"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 ZM({anchorElem:n=document.body,setIsLinkEditMode:e,extraItems:t}){const[r]=fe();return UL(r,n,e,t)}function zL(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:zL}),ss={code:{triggerMode:"auto",contextBefore:-1,contextAfter:-1,language:"python"},prose:{triggerMode:"manual",contextBefore:-1,contextAfter:-1},debounceMs:200,manualTriggerKey:"Cmd+Shift+,"};function KL(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 QM(n){return n===-1||n>=0}function e$(n){return n.triggerMode==="auto"}function t$(n){return n.triggerMode==="manual"||n.triggerMode==="auto"}function n$(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($w,{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 r$(n){return n instanceof Fr}const WL=he(),HL=he();function JL(n){if(!n.hasNodes([Fr]))throw new Error("JupyterCellNode is not registered.");return de(n.registerCommand(WL,e=>{const t=Vg(e);return Tr([t]),!0},V),n.registerCommand(HL,e=>{const t=Vg({...e});return Tr([t]),!0},V))}const qL=pe({name:"@datalayer/jupyter-lexical/JupyterCell",nodes:()=>[Fr],register:JL}),VL=he("INSERT_LAYOUT_COMMAND");function YL(n){return n.trim().split(/\s+/).length}function o$(n){return Array.from({length:Math.max(1,n)},()=>"1fr").join(" ")}function GL(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(VL,t=>(n.update(()=>{const r=Ou(t);for(let o=0;o<YL(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:GL});function Yg(n,e,t,r,o){return n==="code"?ZL(e,t):QL(e,t,r,o)}function ZL(n,e){const t=n.getTextContent(),r=nO(n,e),o=t.substring(0,r),s=t.substring(r);return{before:o,after:s,fullText:t}}function QL(n,e,t,r){const s=se().getChildren(),i=eO(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=tO(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 eO(n){let e=n;for(;e;){if(ht(e)||e.getType()==="heading"||e.getType()==="listitem")return e;e=e.getParent()}return se()}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,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 rO(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 oO(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 sO({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:rO(d.kind)}),x.jsx("span",{style:{flex:1},children:oO(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 iO(n){const e=n.getChildren();for(const t of e)if(ds(t))return!0;return!1}function Gg(n){let e=n;for(;e;){if(st(e))return e;e=e.getParent()}return null}function aO(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 lO(n){const e=n.getLanguage();return!e||e==="python"||e==="py"?"python":e==="markdown"||e==="md"||e==="text"?"markdown":"unknown"}function cO(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 s$({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]),b=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=Gg(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=cO(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=lO(C);if(E==="unknown")return;const N=aO(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=Gg(k);if(!I||iO(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(sO,{items:s,onSelect:b,onClose:m,position:c,filterText:f}):null}const Xg=he("TRIGGER_INLINE_COMPLETION_COMMAND");function uO({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(()=>KL(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 b=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=b},[b]),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 pO{_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(b=>b.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 b=m.getChildren?.()||[];for(const w of b)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(()=>kL);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($e("__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-CqA-IwCx.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-ZawlUPsx.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.uq);return{$wrapNodeInElement:f}},[],import.meta.url),{$isRootOrShadowRoot:i}=await me(async()=>{const{$isRootOrShadowRoot:f}=await import("../datalayer-app-main.js").then(d=>d.up);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(b=>b.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 b=i(h[_]).getChildren();for(let w=0;w<Math.min(c.length,b.length);w++){const v=b[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($e(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-DsX9nIHt.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(b=>b.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 b=i(h[_]).getChildren();for(let w=0;w<Math.min(c.length,b.length);w++){const v=b[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($e(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-D1HhRyAi.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($e(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=$e(o.text);return o.format&&s.setFormat(o.format),s}):tp(t||"").map(s=>{const i=$e(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($e(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=$e(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(`