@fileverse-dev/ddoc 1.1.8 → 1.1.9
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.es.js +2 -2
- package/dist/index.umd.js +2 -2
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
@@ -319,7 +319,7 @@ img.ProseMirror-separator {
|
|
319
319
|
*
|
320
320
|
* This source code is licensed under the ISC license.
|
321
321
|
* See the LICENSE file in the root directory of this source tree.
|
322
|
-
*/const h0=Me("Youtube",[["path",{d:"M2.5 17a24.12 24.12 0 0 1 0-10 2 2 0 0 1 1.4-1.4 49.56 49.56 0 0 1 16.2 0A2 2 0 0 1 21.5 7a24.12 24.12 0 0 1 0 10 2 2 0 0 1-1.4 1.4 49.55 49.55 0 0 1-16.2 0A2 2 0 0 1 2.5 17",key:"1q2vi4"}],["path",{d:"m10 15 5-3-5-3z",key:"1jp15x"}]]),uT=({editor:n,isOpen:e,setIsOpen:t})=>{const r=[{name:"Text",icon:d0,command:()=>n.chain().focus().toggleNode("paragraph","paragraph").run(),isActive:()=>n.isActive("paragraph")&&!n.isActive("bulletList")&&!n.isActive("orderedList")},{name:"Heading 1",icon:o0,command:()=>n.chain().focus().toggleHeading({level:1}).run(),isActive:()=>n.isActive("heading",{level:1})},{name:"Heading 2",icon:l0,command:()=>n.chain().focus().toggleHeading({level:2}).run(),isActive:()=>n.isActive("heading",{level:2})},{name:"Heading 3",icon:a0,command:()=>n.chain().focus().toggleHeading({level:3}).run(),isActive:()=>n.isActive("heading",{level:3})},{name:"To-do List",icon:c0,command:()=>n.chain().focus().toggleTaskList().run(),isActive:()=>n.isActive("taskItem")},{name:"Bullet List",icon:sd,command:()=>n.chain().focus().toggleBulletList().run(),isActive:()=>n.isActive("bulletList")},{name:"Numbered List",icon:sd,command:()=>n.chain().focus().toggleOrderedList().run(),isActive:()=>n.isActive("orderedList")},{name:"Quote",icon:u0,command:()=>n.chain().focus().toggleNode("paragraph","paragraph").toggleBlockquote().run(),isActive:()=>n.isActive("blockquote")},{name:"Code",icon:i0,command:()=>n.chain().focus().toggleCode().run(),isActive:()=>n.isActive("code")}],i=r.filter(s=>s.isActive()).pop()??{name:"Multiple"};return D.jsxs("div",{className:"relative h-full",children:[D.jsxs("button",{className:"flex h-full items-center gap-1 p-2 text-sm font-medium text-stone-600 hover:bg-stone-100 active:bg-stone-200",onClick:()=>t(!e),children:[D.jsx("span",{children:i==null?void 0:i.name}),D.jsx(id,{className:"h-4 w-4"})]}),e&&D.jsx("section",{className:"fixed top-full z-[99999] mt-1 flex w-48 flex-col overflow-hidden rounded border border-stone-200 bg-white p-1 shadow-xl animate-in fade-in slide-in-from-top-1",children:r.map((s,o)=>D.jsxs("button",{onClick:()=>{s.command(),t(!1)},className:Fe("flex items-center justify-between rounded-sm px-2 py-1 text-sm text-stone-600 hover:bg-stone-100",{"text-blue-600":s.isActive()}),children:[D.jsxs("div",{className:"flex items-center space-x-2",children:[D.jsx("div",{className:"rounded-sm border border-stone-200 p-1",children:D.jsx(s.icon,{className:"h-3 w-3"})}),D.jsx("span",{children:s.name})]}),i.name===s.name&&D.jsx(Bl,{className:"h-4 w-4"})]},o))})]})},dT=({editor:n,isOpen:e,setIsOpen:t})=>{const r=[{name:"Default",color:"#000000"},{name:"Purple",color:"#9333EA"},{name:"Red",color:"#E00000"},{name:"Blue",color:"#2563EB"},{name:"Green",color:"#008A00"},{name:"Orange",color:"#FFA500"},{name:"Pink",color:"#BA4081"},{name:"Gray",color:"#A8A29E"}],i=r.find(({color:s})=>n.isActive("textStyle",{color:s}));return D.jsxs("div",{className:"",children:[D.jsxs("button",{className:"flex h-[100%] items-center gap-1 p-2 text-sm font-medium text-stone-600 hover:bg-stone-100 active:bg-stone-200",onClick:()=>t(!e),children:[D.jsx("span",{style:{color:(i==null?void 0:i.color)||"#000000"},children:"A"}),D.jsx(id,{className:"h-4 w-4 "})]}),e&&D.jsx("section",{className:"fixed top-full z-[99999] mt-1 flex w-48 flex-col overflow-hidden rounded border border-stone-200 bg-white p-1 shadow-xl animate-in fade-in slide-in-from-top-1",children:r.map(({name:s,color:o},l)=>D.jsxs("button",{onClick:()=>{n.chain().focus().setColor(o).run(),t(!1)},className:Fe("flex items-center justify-between rounded-sm px-2 py-1 text-sm text-stone-600 hover:bg-stone-100",{"text-blue-600":n.isActive("textStyle",{color:o})}),children:[D.jsxs("div",{className:"flex items-center space-x-2",children:[D.jsx("div",{className:"rounded-sm border border-stone-200 px-1 py-px font-medium",style:{color:o},children:"A"}),D.jsx("span",{children:s})]}),n.isActive("textStyle",{color:o})&&D.jsx(Bl,{className:"h-4 w-4"})]},l))})]})};var Te=(n=>(n[n.NONE=0]="NONE",n[n.HEADING=1]="HEADING",n[n.TEXT_COLOR=2]="TEXT_COLOR",n[n.HIGHLIGHT=3]="HIGHLIGHT",n[n.LINK=4]="LINK",n[n.FONT_FAMILY=5]="FONT_FAMILY",n[n.ALIGNMENT=6]="ALIGNMENT",n[n.LIST=7]="LIST",n))(Te||{});function fT(n){const[e,t]=O.useState(n),r=O.useRef(null),i=s=>{r&&r.current&&!r.current.contains(s.target)&&t(0)};return O.useEffect(()=>(document.addEventListener("click",i,!0),()=>{document.removeEventListener("click",i,!0)}),[]),{ref:r,toolVisibilty:e,setToolVisibility:t}}const hT="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cmask%20id='mask0_349_446'%20style='mask-type:alpha'%20maskUnits='userSpaceOnUse'%20x='0'%20y='0'%20width='24'%20height='24'%3e%3crect%20width='24'%20height='24'%20fill='%23D9D9D9'/%3e%3c/mask%3e%3cg%20mask='url(%23mask0_349_446)'%3e%3cpath%20d='M5.55%2019L2%2015.45L3.4%2014.05L5.525%2016.175L9.775%2011.925L11.175%2013.35L5.55%2019ZM5.55%2011L2%207.45005L3.4%206.05005L5.525%208.17505L9.775%203.92505L11.175%205.35005L5.55%2011ZM13%2017V15H22V17H13ZM13%209.00005V7.00005H22V9.00005H13Z'%20fill='%231C1B1F'/%3e%3c/g%3e%3c/svg%3e",pT="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cmask%20id='mask0_337_2594'%20style='mask-type:alpha'%20maskUnits='userSpaceOnUse'%20x='0'%20y='0'%20width='24'%20height='24'%3e%3crect%20width='24'%20height='24'%20fill='%23D9D9D9'/%3e%3c/mask%3e%3cg%20mask='url(%23mask0_337_2594)'%3e%3cpath%20d='M3.9751%2017L7.7251%207H9.5251L13.2751%2017H11.5501L10.6501%2014.45H6.6001L5.7001%2017H3.9751ZM7.1251%2013H10.1251L8.6751%208.85H8.5751L7.1251%2013ZM16.3501%2017.275C15.5334%2017.275%2014.8918%2017.0625%2014.4251%2016.6375C13.9584%2016.2125%2013.7251%2015.6333%2013.7251%2014.9C13.7251%2014.2%2013.9959%2013.6292%2014.5376%2013.1875C15.0793%2012.7458%2015.7751%2012.525%2016.6251%2012.525C17.0084%2012.525%2017.3626%2012.5542%2017.6876%2012.6125C18.0126%2012.6708%2018.2918%2012.7667%2018.5251%2012.9V12.55C18.5251%2012.1%2018.3709%2011.7417%2018.0626%2011.475C17.7543%2011.2083%2017.3334%2011.075%2016.8001%2011.075C16.4501%2011.075%2016.1209%2011.15%2015.8126%2011.3C15.5043%2011.45%2015.2418%2011.6667%2015.0251%2011.95L13.9501%2011.15C14.2668%2010.7%2014.6668%2010.3583%2015.1501%2010.125C15.6334%209.89167%2016.1918%209.775%2016.8251%209.775C17.8584%209.775%2018.6501%2010.0208%2019.2001%2010.5125C19.7501%2011.0042%2020.0251%2011.7167%2020.0251%2012.65V17.05H18.5501V16.2H18.4751C18.2584%2016.5333%2017.9668%2016.7958%2017.6001%2016.9875C17.2334%2017.1792%2016.8168%2017.275%2016.3501%2017.275ZM16.6001%2016.025C17.1334%2016.025%2017.5876%2015.8375%2017.9626%2015.4625C18.3376%2015.0875%2018.5251%2014.6333%2018.5251%2014.1C18.2918%2013.9667%2018.0251%2013.8667%2017.7251%2013.8C17.4251%2013.7333%2017.1501%2013.7%2016.9001%2013.7C16.3668%2013.7%2015.9584%2013.8042%2015.6751%2014.0125C15.3918%2014.2208%2015.2501%2014.5167%2015.2501%2014.9C15.2501%2015.2333%2015.3751%2015.5042%2015.6251%2015.7125C15.8751%2015.9208%2016.2001%2016.025%2016.6001%2016.025Z'%20fill='%231C1B1F'/%3e%3c/g%3e%3c/svg%3e",p0="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cmask%20id='mask0_224_2464'%20style='mask-type:alpha'%20maskUnits='userSpaceOnUse'%20x='0'%20y='0'%20width='24'%20height='24'%3e%3crect%20width='24'%20height='24'%20fill='%23D9D9D9'/%3e%3c/mask%3e%3cg%20mask='url(%23mask0_224_2464)'%3e%3cpath%20d='M3%2021V19H21V21H3ZM7%2017V15H17V17H7ZM3%2013V11H21V13H3ZM7%209V7H17V9H7ZM3%205V3H21V5H3Z'%20fill='%231C1B1F'/%3e%3c/g%3e%3c/svg%3e",od="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cmask%20id='mask0_337_2575'%20style='mask-type:alpha'%20maskUnits='userSpaceOnUse'%20x='0'%20y='0'%20width='24'%20height='24'%3e%3crect%20width='24'%20height='24'%20fill='%23D9D9D9'/%3e%3c/mask%3e%3cg%20mask='url(%23mask0_337_2575)'%3e%3cpath%20d='M3%2021V19H21V21H3ZM3%2017V15H15V17H3ZM3%2013V11H21V13H3ZM3%209V7H15V9H3ZM3%205V3H21V5H3Z'%20fill='%231C1B1F'/%3e%3c/g%3e%3c/svg%3e",m0="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cmask%20id='mask0_224_2470'%20style='mask-type:alpha'%20maskUnits='userSpaceOnUse'%20x='0'%20y='0'%20width='24'%20height='24'%3e%3crect%20width='24'%20height='24'%20fill='%23D9D9D9'/%3e%3c/mask%3e%3cg%20mask='url(%23mask0_224_2470)'%3e%3cpath%20d='M3%205V3H21V5H3ZM9%209V7H21V9H9ZM3%2013V11H21V13H3ZM9%2017V15H21V17H9ZM3%2021V19H21V21H3Z'%20fill='%231C1B1F'/%3e%3c/g%3e%3c/svg%3e",g0="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cmask%20id='mask0_337_2572'%20style='mask-type:alpha'%20maskUnits='userSpaceOnUse'%20x='0'%20y='0'%20width='24'%20height='24'%3e%3crect%20width='24'%20height='24'%20fill='%23D9D9D9'/%3e%3c/mask%3e%3cg%20mask='url(%23mask0_337_2572)'%3e%3cpath%20d='M9%2019V17H21V19H9ZM9%2013V11H21V13H9ZM9%207V5H21V7H9ZM5%2020C4.45%2020%203.97917%2019.8042%203.5875%2019.4125C3.19583%2019.0208%203%2018.55%203%2018C3%2017.45%203.19583%2016.9792%203.5875%2016.5875C3.97917%2016.1958%204.45%2016%205%2016C5.55%2016%206.02083%2016.1958%206.4125%2016.5875C6.80417%2016.9792%207%2017.45%207%2018C7%2018.55%206.80417%2019.0208%206.4125%2019.4125C6.02083%2019.8042%205.55%2020%205%2020ZM5%2014C4.45%2014%203.97917%2013.8042%203.5875%2013.4125C3.19583%2013.0208%203%2012.55%203%2012C3%2011.45%203.19583%2010.9792%203.5875%2010.5875C3.97917%2010.1958%204.45%2010%205%2010C5.55%2010%206.02083%2010.1958%206.4125%2010.5875C6.80417%2010.9792%207%2011.45%207%2012C7%2012.55%206.80417%2013.0208%206.4125%2013.4125C6.02083%2013.8042%205.55%2014%205%2014ZM5%208C4.45%208%203.97917%207.80417%203.5875%207.4125C3.19583%207.02083%203%206.55%203%206C3%205.45%203.19583%204.97917%203.5875%204.5875C3.97917%204.19583%204.45%204%205%204C5.55%204%206.02083%204.19583%206.4125%204.5875C6.80417%204.97917%207%205.45%207%206C7%206.55%206.80417%207.02083%206.4125%207.4125C6.02083%207.80417%205.55%208%205%208Z'%20fill='%231C1B1F'/%3e%3c/g%3e%3c/svg%3e",mT="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cmask%20id='mask0_349_458'%20style='mask-type:alpha'%20maskUnits='userSpaceOnUse'%20x='0'%20y='0'%20width='24'%20height='24'%3e%3crect%20width='24'%20height='24'%20fill='%23D9D9D9'/%3e%3c/mask%3e%3cg%20mask='url(%23mask0_349_458)'%3e%3cpath%20d='M3%2022V20.5H5.5V19.75H4V18.25H5.5V17.5H3V16H6C6.28333%2016%206.52083%2016.0958%206.7125%2016.2875C6.90417%2016.4792%207%2016.7167%207%2017V18C7%2018.2833%206.90417%2018.5208%206.7125%2018.7125C6.52083%2018.9042%206.28333%2019%206%2019C6.28333%2019%206.52083%2019.0958%206.7125%2019.2875C6.90417%2019.4792%207%2019.7167%207%2020V21C7%2021.2833%206.90417%2021.5208%206.7125%2021.7125C6.52083%2021.9042%206.28333%2022%206%2022H3ZM3%2015V12.25C3%2011.9667%203.09583%2011.7292%203.2875%2011.5375C3.47917%2011.3458%203.71667%2011.25%204%2011.25H5.5V10.5H3V9H6C6.28333%209%206.52083%209.09583%206.7125%209.2875C6.90417%209.47917%207%209.71667%207%2010V11.75C7%2012.0333%206.90417%2012.2708%206.7125%2012.4625C6.52083%2012.6542%206.28333%2012.75%206%2012.75H4.5V13.5H7V15H3ZM4.5%208V3.5H3V2H6V8H4.5ZM9%2019V17H21V19H9ZM9%2013V11H21V13H9ZM9%207V5H21V7H9Z'%20fill='%231C1B1F'/%3e%3c/g%3e%3c/svg%3e",gT="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cmask%20id='mask0_337_2560'%20style='mask-type:alpha'%20maskUnits='userSpaceOnUse'%20x='0'%20y='0'%20width='24'%20height='24'%3e%3crect%20width='24'%20height='24'%20fill='%23D9D9D9'/%3e%3c/mask%3e%3cg%20mask='url(%23mask0_337_2560)'%3e%3cpath%20d='M5%2019V17H19V19H5ZM6.9%2015L11%204H13L17.1%2015H15.2L14.25%2012.2H9.8L8.8%2015H6.9ZM10.35%2010.6H13.65L12.05%206.05H11.95L10.35%2010.6Z'%20fill='%231C1B1F'/%3e%3c/g%3e%3c/svg%3e",yT="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20height='24'%20viewBox='0%20-960%20960%20960'%20width='24'%3e%3cpath%20d='m228-240%2092-160q-66%200-113-47t-47-113q0-66%2047-113t113-47q66%200%20113%2047t47%20113q0%2023-5.5%2042.5T458-480L320-240h-92Zm360%200%2092-160q-66%200-113-47t-47-113q0-66%2047-113t113-47q66%200%20113%2047t47%20113q0%2023-5.5%2042.5T818-480L680-240h-92ZM320-500q25%200%2042.5-17.5T380-560q0-25-17.5-42.5T320-620q-25%200-42.5%2017.5T260-560q0%2025%2017.5%2042.5T320-500Zm360%200q25%200%2042.5-17.5T740-560q0-25-17.5-42.5T680-620q-25%200-42.5%2017.5T620-560q0%2025%2017.5%2042.5T680-500Zm0-60Zm-360%200Z'/%3e%3c/svg%3e",bT="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20height='24'%20viewBox='0%20-960%20960%20960'%20width='24'%3e%3cpath%20d='M200-280v-400h80v160h160v-160h80v400h-80v-160H280v160h-80Zm480%200v-320h-80v-80h160v400h-80Z'/%3e%3c/svg%3e",vT="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20height='24'%20viewBox='0%20-960%20960%20960'%20width='24'%3e%3cpath%20d='M120-280v-400h80v160h160v-160h80v400h-80v-160H200v160h-80Zm400%200v-160q0-33%2023.5-56.5T600-520h160v-80H520v-80h240q33%200%2056.5%2023.5T840-600v80q0%2033-23.5%2056.5T760-440H600v80h240v80H520Z'/%3e%3c/svg%3e",wT="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20height='24'%20viewBox='0%20-960%20960%20960'%20width='24'%3e%3cpath%20d='M120-280v-400h80v160h160v-160h80v400h-80v-160H200v160h-80Zm400%200v-80h240v-80H600v-80h160v-80H520v-80h240q33%200%2056.5%2023.5T840-600v240q0%2033-23.5%2056.5T760-280H520Z'/%3e%3c/svg%3e",xT="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20height='24'%20viewBox='0%20-960%20960%20960'%20width='24'%3e%3cpath%20d='M680-360q-17%200-28.5-11.5T640-400v-160q0-17%2011.5-28.5T680-600h120q17%200%2028.5%2011.5T840-560v40h-60v-20h-80v120h80v-20h60v40q0%2017-11.5%2028.5T800-360H680Zm-300%200v-240h160q17%200%2028.5%2011.5T580-560v40q0%2017-11.5%2028.5T540-480q17%200%2028.5%2011.5T580-440v40q0%2017-11.5%2028.5T540-360H380Zm60-150h80v-30h-80v30Zm0%2090h80v-30h-80v30Zm-320%2060v-200q0-17%2011.5-28.5T160-600h120q17%200%2028.5%2011.5T320-560v200h-60v-60h-80v60h-60Zm60-120h80v-60h-80v60Z'/%3e%3c/svg%3e",CT="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20height='24'%20viewBox='0%20-960%20960%20960'%20width='24'%3e%3cpath%20d='M544-400%20440-504%20240-304l104%20104%20200-200Zm-47-161%20104%20104%20199-199-104-104-199%20199Zm-84-28%20216%20216-229%20229q-24%2024-56%2024t-56-24l-2-2-26%2026H60l126-126-2-2q-24-24-24-56t24-56l229-229Zm0%200%20227-227q24-24%2056-24t56%2024l104%20104q24%2024%2024%2056t-24%2056L629-373%20413-589Z'/%3e%3c/svg%3e",kT="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%3e%3cpath%20fill='currentColor'%20d='M19%205v14H5V5h14m0-2H5c-1.1%200-2%20.9-2%202v14c0%201.1.9%202%202%202h14c1.1%200%202-.9%202-2V5c0-1.1-.9-2-2-2zm-4.86%208.86l-3%203.87L9%2013.14L6%2017h12l-3.86-5.14z'/%3e%3c/svg%3e",$l=new We("upload-image"),ST=()=>new je({key:$l,state:{init(){return He.empty},apply(n,e){e=e.map(n.mapping,n.doc);const t=n.getMeta(this);if(t&&t.add){const{id:r,pos:i,src:s}=t.add,o=document.createElement("div");o.setAttribute("class","img-placeholder");const l=document.createElement("img");l.setAttribute("class","rounded-lg border border-stone-200"),l.src=s,o.appendChild(l);const a=ut.widget(i+1,o,{id:r});e=e.add(n.doc,[a])}else t&&t.remove&&(e=e.remove(e.find(void 0,void 0,r=>r.id==t.remove.id)));return e}},props:{decorations(n){return this.getState(n)}}});function ET(n,e){const r=$l.getState(n).find(null,null,i=>i.id==e);return r.length?r[0].from:null}function y0(n,e,t){if(n.type.includes("image/")){if(n.size>1024*1024){console.log("failed");return}}else{console.log("file is not an image");return}const r={},i=e.state.tr;i.selection.empty||i.deleteSelection();const s=new FileReader;s.readAsDataURL(n),s.onload=()=>{i.setMeta($l,{add:{id:r,pos:t,src:s.result}}),e.dispatch(i)},TT(n).then(o=>{const{schema:l}=e.state,a=ET(e.state,r);if(a==null)return;const c=typeof o=="object"?s.result:o,u=l.nodes.resizableMedia.create({src:c,"media-type":"img"}),d=e.state.tr.replaceWith(a-2,a+u.nodeSize,u).setMeta($l,{remove:{id:r}});e.dispatch(d)})}const TT=n=>new Promise(e=>{const t=new FileReader;t.readAsDataURL(n),t.onload=()=>e(t.result)}),AT=async n=>{const e=new FileReader;if(e.readAsDataURL(n),n.size>1024*1024)throw e.abort(),console.log("should be less than 1 mb"),new Error("Image too large");return await new Promise(r=>{e.onload=()=>{r(e.result)}})},b0=({editor:n})=>{const{ref:e,toolVisibilty:t,setToolVisibility:r}=fT(Te.NONE);return{toolbar:[{icon:pT,title:"Font",onClick:()=>r(Te.FONT_FAMILY),isActive:t===Te.FONT_FAMILY},{icon:gT,title:"Text Color",onClick:()=>r(Te.TEXT_COLOR),isActive:t===Te.TEXT_COLOR},{icon:CT,title:"Highlight",onClick:()=>r(Te.HIGHLIGHT),isActive:t===Te.HIGHLIGHT},null,{icon:Yg,title:"Bold",onClick:()=>n==null?void 0:n.chain().focus().toggleBold().run(),isActive:n==null?void 0:n.isActive("bold")},{icon:Zg,title:"Italic",onClick:()=>n==null?void 0:n.chain().focus().toggleItalic().run(),isActive:n==null?void 0:n.isActive("italic")},{icon:Xg,title:"Underlined",onClick:()=>n==null?void 0:n.chain().focus().toggleUnderline().run(),isActive:n==null?void 0:n.isActive("underline")},{icon:e0,title:"Strikethrough",onClick:()=>n==null?void 0:n.chain().focus().toggleStrike().run(),isActive:n==null?void 0:n.isActive("strike")},null,{icon:g0,title:"List",onClick:()=>r(Te.LIST),isActive:t===Te.LIST},{icon:od,title:"Alignment",onClick:()=>r(Te.ALIGNMENT),isActive:t===Te.ALIGNMENT},{icon:yT,title:"Quote",onClick:()=>n==null?void 0:n.chain().focus().toggleBlockquote().run(),isActive:n==null?void 0:n.isActive("blockquote")},null,{icon:kT,title:"Upload Image",onClick:()=>{n==null||n.chain().focus().deleteRange(n.state.selection).run();const s=document.createElement("input");s.type="file",s.accept="image/*",s.onchange=async()=>{var o;if((o=s.files)!=null&&o.length){const l=s.files[0],a=n.view.state.selection.from;y0(l,n.view,a)}},s.click()},isActive:!1},{icon:t0,title:"Link",onClick:()=>r(Te.LINK),isActive:n==null?void 0:n.isActive("link")},{icon:Qg,title:"Code",onClick:()=>n==null?void 0:n.chain().focus().toggleCodeBlock().run(),isActive:n==null?void 0:n.isActive("codeBlock")}],toolRef:e,toolVisibilty:t,setToolVisibility:r}},MT=({editor:n,setVisibility:e,elementRef:t})=>{const r=[{color:"#00FF00",code:"bg-[#00FF00]"},{color:"#008080",code:"bg-[#008080]"},{color:"#FFC0CB",code:"bg-[#FFC0CB]"},{color:"#808000",code:"bg-[#808000]"},{color:"#800000",code:"bg-[#800000]"},{color:"#000080",code:"bg-[#000080]"},{color:"#7FFFD4",code:"bg-[#7FFFD4]"},{color:"#40E0D0",code:"bg-[#40E0D0]"},{color:"#C0C0C0",code:"bg-[#C0C0C0]"},{color:"#808080",code:"bg-[#808080]"},{color:"#000000",code:"bg-[#000000]"},{color:"#FFFFFF",code:"bg-[#FFFFFF]"},{color:"#CD5C5C",code:"bg-[#CD5C5C]"},{color:"#F08080",code:"bg-[#F08080]"},{color:"#FA8072",code:"bg-[#FA8072]"},{color:"#E9967A",code:"bg-[#E9967A]"},{color:"#FFA07A",code:"bg-[#FFA07A]"},{color:"#DC143C",code:"bg-[#DC143C]"},{color:"#FF6347",code:"bg-[#FF6347]"},{color:"#FF7F50",code:"bg-[#FF7F50]"},{color:"#FF4500",code:"bg-[#FF4500]"},{color:"#BDB76B",code:"bg-[#BDB76B]"},{color:"#FFD700",code:"bg-[#FFD700]"},{color:"#F0E68C",code:"bg-[#F0E68C]"},{color:"#FFE5B4",code:"bg-[#FFE5B4]"},{color:"#9ACD32",code:"bg-[#9ACD32]"},{color:"#556B2F",code:"bg-[#556B2F]"},{color:"#6B8E23",code:"bg-[#6B8E23]"},{color:"#7CFC00",code:"bg-[#7CFC00]"},{color:"#7FFF00",code:"bg-[#7FFF00]"},{color:"#ADFF2F",code:"bg-[#ADFF2F]"},{color:"#00BFFF",code:"bg-[#00BFFF]"},{color:"#1E90FF",code:"bg-[#1E90FF]"},{color:"#6495ED",code:"bg-[#6495ED]"},{color:"#4682B4",code:"bg-[#4682B4]"},{color:"#4169E1",code:"bg-[#4169E1]"},{color:"#8A2BE2",code:"bg-[#8A2BE2]"},{color:"#4B0082",code:"bg-[#4B0082]"},{color:"#6A5ACD",code:"bg-[#6A5ACD]"}];return D.jsxs("div",{ref:t,className:"z-50 h-auto absolute gap-2 top-[50px] flex flex-wrap left-[20%] max-h-[330px] w-[20.5rem] overflow-y-auto scroll-smooth rounded-md border border-stone-200 bg-white px-1 py-2 shadow-md transition-all",children:[D.jsx(r0,{className:"cursor-pointer",onClick:()=>{n.chain().focus().unsetHighlight().run(),e(Te.NONE)}}),r.map(i=>D.jsx("div",{onClick:()=>{n.chain().focus().toggleHighlight({color:i.color}).run(),e(Te.NONE)},className:`w-6 ${i.code} drop-shadow rounded-full flex items-center justify-center cursor-pointer ease-in duration-200 hover:scale-[1.05] h-6`,children:D.jsx(Bl,{size:14,className:`${n.isActive("highlight",{color:i.color})?"visible":"invisible"}`})},i.color))]})},OT=({elementRef:n,editor:e,setToolVisibility:t})=>{const r=[{title:"Trebuchet MS",command:i=>{i.chain().focus().setFontFamily("Trebuchet MS, sans-serif").run()}},{title:"Verdana",command:i=>{i.chain().focus().setFontFamily("Verdana, Geneva, sans-serif").run()}},{title:"Georgia",command:i=>{i.chain().focus().setFontFamily("Georgia, serif").run()}},{title:"Arial",command:i=>{i.chain().focus().setFontFamily("Arial, Helvetica, sans-serif").run()}},{title:"Comic Sans MS",command:i=>{i.chain().focus().setFontFamily("Comic Sans MS, Comic Sans").run()}},{title:"Impact",command:i=>{i.chain().focus().setFontFamily("Impact, Charcoal, sans-serif").run()}},{title:"Palatino",command:i=>{i.chain().focus().setFontFamily("Palatino Linotype, Book Antiqua, Palatino, serif").run()}},{title:"Lucida Grande",command:i=>{i.chain().focus().setFontFamily("Lucida Sans Unicode, Lucida Grande, sans-serif").run()}},{title:"Serif",command:i=>{i.chain().focus().setFontFamily("serif").run()}},{title:"Monospace",command:i=>{i.chain().focus().setFontFamily("monospace").run()}},{title:"Cursive",command:i=>{i.chain().focus().setFontFamily("cursive").run()}}];return D.jsx("div",{ref:n,className:Fe("z-50 h-auto absolute top-[50px] left-[20%] max-h-[330px] w-48 overflow-y-auto scroll-smooth rounded-md border border-stone-200 bg-white px-1 py-2 shadow-md transition-all"),children:r.map(i=>D.jsx("button",{onClick:()=>{i.command(e),t(Te.NONE)},style:{fontFamily:i.title},className:`flex w-full ${e.isActive("textStyle",{fontFamily:i.title})?"bg-red-500":""} items-center space-x-2 rounded-md px-2 py-1 text-left text-sm text-stone-900 hover:bg-stone-100`,children:D.jsx("p",{className:"font-medium",children:i.title})},i.title))})},_T=({elementRef:n,editor:e,setToolVisibility:t})=>D.jsxs("div",{ref:n,className:Fe("z-50 h-auto absolute gap-2 top-[50px] right-[25%] flex flex-wrap max-h-[330px] overflow-y-auto scroll-smooth rounded-md border border-stone-200 bg-white px-1 py-2 shadow-md transition-all"),children:[D.jsx("span",{onClick:()=>{e==null||e.chain().focus().setTextAlign("left").run(),t(Te.NONE)},className:` hover:bg-[#f2f2f2] ${e.isActive({textAlign:"left"})&&"bg-[#f2f2f2]"} rounded-lg w-8 h-8 p-1 flex justify-center items-center`,children:D.jsx("img",{src:od,alt:"align left"})}),D.jsx("span",{onClick:()=>{e==null||e.chain().focus().setTextAlign("center").run(),t(Te.NONE)},className:` hover:bg-[#f2f2f2] ${e.isActive({textAlign:"center"})&&"bg-[#f2f2f2]"} rounded-lg w-8 h-8 p-1 flex justify-center items-center`,children:D.jsx("img",{src:p0,alt:"align center"})}),D.jsx("span",{onClick:()=>{e==null||e.chain().focus().setTextAlign("right").run(),t(Te.NONE)},className:` hover:bg-[#f2f2f2] ${e.isActive({textAlign:"right"})&&"bg-[#f2f2f2]"} rounded-lg w-8 h-8 p-1 flex justify-center items-center`,children:D.jsx("img",{src:m0,alt:"align right"})})]}),NT=({elementRef:n,editor:e,setToolVisibility:t})=>D.jsxs("div",{ref:n,className:Fe("z-50 h-auto absolute gap-2 top-[50px] right-[30%] flex flex-wrap max-h-[330px] overflow-y-auto scroll-smooth rounded-md border border-stone-200 bg-white px-1 py-2 shadow-md transition-all"),children:[D.jsx("div",{className:"tooltip tooltip-open tooltip-bottom","data-tip":"unordered list",children:D.jsx("span",{onClick:()=>{e==null||e.chain().focus().toggleBulletList().run(),t(Te.NONE)},className:` hover:bg-[#f2f2f2] ${e.isActive("bulletList")?"bg-[#f2f2f2]":""} rounded-lg w-8 h-8 p-1 flex justify-center items-center`,children:D.jsx("img",{src:g0,alt:"bullet list"})})}),D.jsx("div",{className:"tooltip tooltip-open tooltip-bottom","data-tip":"ordered list",children:D.jsx("span",{onClick:()=>{e==null||e.chain().focus().toggleOrderedList().run(),t(Te.NONE)},className:` hover:bg-[#f2f2f2] ${e.isActive("orderedList")?"bg-[#f2f2f2]":""} rounded-lg w-8 h-8 p-1 flex justify-center items-center`,children:D.jsx("img",{src:mT,alt:"numbered list"})})}),D.jsx("div",{className:"tooltip tooltip-open tooltip-bottom","data-tip":"to-do list",children:D.jsx("span",{onClick:()=>{e==null||e.chain().focus().toggleTaskList().run(),t(Te.NONE)},className:` hover:bg-[#f2f2f2] ${e.isActive("taskList")?"bg-[#f2f2f2]":""} rounded-lg w-8 h-8 p-1 flex justify-center items-center`,children:D.jsx("img",{src:hT,alt:"checklist"})})})]}),v0=({elementRef:n,editor:e,setToolVisibility:t,bubbleMenu:r,setIsLinkPopupOpen:i})=>{const[s,o]=O.useState(e.getAttributes("link").href),l=()=>{if(s===null)return;if(s===""){e.chain().focus().extendMarkRange("link").unsetLink().run();return}let a=s;!s.startsWith("http://")&&!s.startsWith("https://")&&(a="https://"+s);try{a.match(/^((http|https):\/\/)?([w|W]{3}\.)+[a-zA-Z0-9\-\.]{3,}\.[a-zA-Z]{2,}(\.[a-zA-Z]{2,})?$/)&&e.chain().focus().extendMarkRange("link").setLink({href:a}).run()}catch{console.error("Invalid URL");return}e.chain().focus().extendMarkRange("link").setLink({href:a}).run(),t(Te.NONE),r&&i&&i(!1)};return D.jsxs("div",{ref:n,className:"z-50 h-auto absolute gap-2 top-[50px] items-center flex right-[10%] max-h-[330px] overflow-y-auto scroll-smooth rounded-md border border-stone-200 bg-white p-2 shadow-md transition-all",children:[D.jsx("input",{onChange:a=>o(a.target.value),className:"border-2 focus:border-black px-2 py-1.5 rounded w-full font-medium text-sm",placeholder:"Add link here",value:s}),D.jsx("div",{className:"h-full flex items-center",children:D.jsx("button",{onClick:()=>l(),className:"min-w-fit",children:"Apply"})})]})},DT=({editor:n,setVisibility:e,elementRef:t})=>{const r=[{color:"#00FF00",code:"bg-[#00FF00]"},{color:"#008080",code:"bg-[#008080]"},{color:"#FFC0CB",code:"bg-[#FFC0CB]"},{color:"#808000",code:"bg-[#808000]"},{color:"#800000",code:"bg-[#800000]"},{color:"#000080",code:"bg-[#000080]"},{color:"#7FFFD4",code:"bg-[#7FFFD4]"},{color:"#40E0D0",code:"bg-[#40E0D0]"},{color:"#C0C0C0",code:"bg-[#C0C0C0]"},{color:"#808080",code:"bg-[#808080]"},{color:"#000000",code:"bg-[#000000]"},{color:"#FFFFFF",code:"bg-[#FFFFFF]"},{color:"#CD5C5C",code:"bg-[#CD5C5C]"},{color:"#F08080",code:"bg-[#F08080]"},{color:"#FA8072",code:"bg-[#FA8072]"},{color:"#E9967A",code:"bg-[#E9967A]"},{color:"#FFA07A",code:"bg-[#FFA07A]"},{color:"#DC143C",code:"bg-[#DC143C]"},{color:"#FF6347",code:"bg-[#FF6347]"},{color:"#FF7F50",code:"bg-[#FF7F50]"},{color:"#FF4500",code:"bg-[#FF4500]"},{color:"#BDB76B",code:"bg-[#BDB76B]"},{color:"#FFD700",code:"bg-[#FFD700]"},{color:"#F0E68C",code:"bg-[#F0E68C]"},{color:"#FFE5B4",code:"bg-[#FFE5B4]"},{color:"#9ACD32",code:"bg-[#9ACD32]"},{color:"#556B2F",code:"bg-[#556B2F]"},{color:"#6B8E23",code:"bg-[#6B8E23]"},{color:"#7CFC00",code:"bg-[#7CFC00]"},{color:"#7FFF00",code:"bg-[#7FFF00]"},{color:"#ADFF2F",code:"bg-[#ADFF2F]"},{color:"#00BFFF",code:"bg-[#00BFFF]"},{color:"#1E90FF",code:"bg-[#1E90FF]"},{color:"#6495ED",code:"bg-[#6495ED]"},{color:"#4682B4",code:"bg-[#4682B4]"},{color:"#4169E1",code:"bg-[#4169E1]"},{color:"#8A2BE2",code:"bg-[#8A2BE2]"},{color:"#4B0082",code:"bg-[#4B0082]"},{color:"#6A5ACD",code:"bg-[#6A5ACD]"}];return D.jsxs("div",{ref:t,className:"z-50 h-auto absolute gap-2 top-[50px] flex flex-wrap left-[100px] max-h-[330px] w-[20.5rem] overflow-y-auto scroll-smooth rounded-md border border-stone-200 bg-white px-1 py-2 shadow-md transition-all",children:[D.jsx(r0,{className:"cursor-pointer",onClick:()=>{n.chain().focus().unsetColor().run(),e(Te.NONE)}}),r.map(i=>D.jsx("div",{onClick:()=>{n.chain().focus().setColor(i.color).run(),e(Te.NONE)},className:`w-6 ${i.code} drop-shadow rounded-full flex justify-center items-center cursor-pointer ease-in duration-200 hover:scale-[1.05] h-6`,children:D.jsx(Bl,{size:14,className:`${n.isActive("textStyle",{color:i.color})?"visible":"invisible"}`})},i.color))]})},RT=({editor:n,setVisibility:e,elementRef:t})=>{const r=[{title:"Text",description:"Normal",icon:xT,command:i=>i.chain().focus().toggleNode("paragraph","paragraph").run()},{title:"Heading 1",description:"Big",icon:bT,command:i=>{i.chain().focus().toggleHeading({level:1}).run()}},{title:"Heading 2",description:"Medium",icon:vT,command:i=>{i.chain().focus().toggleHeading({level:2}).run()}},{title:"Heading 3",description:"Small",icon:wT,command:i=>{i.chain().focus().toggleHeading({level:3}).run()}}];return D.jsx("section",{ref:t,className:Fe(" absolute top-[50px] z-50 mt-1 flex w-48 flex-col overflow-hidden rounded border border-stone-200 bg-white p-1 shadow-xl animate-in fade-in slide-in-from-top-1","left-0"),children:r.map(i=>D.jsxs("button",{onClick:()=>{i.command(n),e(Te.NONE)},className:"flex w-full items-center space-x-2 rounded-md px-2 py-1 text-left text-sm text-stone-900 hover:bg-stone-100",children:[D.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-md border border-stone-200 bg-white",children:D.jsx("img",{src:i.icon,alt:i.title})}),D.jsxs("div",{children:[D.jsx("p",{className:"font-medium",children:i.title}),D.jsxs("p",{className:"text-xs text-stone-500",children:[" ",i.description," "]})]})]},i.title))})},LT=n=>{const e=[{name:"bold",isActive:()=>n.editor.isActive("bold"),command:()=>n.editor.chain().focus().toggleBold().run(),icon:Yg},{name:"italic",isActive:()=>n.editor.isActive("italic"),command:()=>n.editor.chain().focus().toggleItalic().run(),icon:Zg},{name:"underline",isActive:()=>n.editor.isActive("underline"),command:()=>n.editor.chain().focus().toggleUnderline().run(),icon:Xg},{name:"strike",isActive:()=>n.editor.isActive("strike"),command:()=>n.editor.chain().focus().toggleStrike().run(),icon:e0},{name:"codeBlock",isActive:()=>n.editor.isActive("codeBlock"),command:()=>n.editor.chain().focus().toggleCodeBlock().run(),icon:Qg},{name:"link",isActive:()=>n.editor.isActive("link"),command:()=>a(!l),icon:t0}],t={...n,shouldShow:({state:d,editor:f})=>{const{selection:h}=d,{empty:p}=h;return!(f.isActive("image")||p||Qm(h))},tippyOptions:{moveTransition:"transform 0.15s ease-out",duration:200,animation:"shift-toward-subtle",onHidden:()=>{i(!1),o(!1),a(!1)}}},[r,i]=O.useState(!1),[s,o]=O.useState(!1),[l,a]=O.useState(!1),{toolRef:c,setToolVisibility:u}=b0({editor:n.editor});return D.jsxs(Ug,{...t,className:"flex gap-1 overflow-hidden rounded border border-stone-200 bg-white shadow-xl",children:[D.jsx(uT,{editor:n.editor,isOpen:r,setIsOpen:()=>{i(!r),o(!1)}}),e.map((d,f)=>D.jsx("button",{onClick:d.command,className:" py-2 text-stone-600 hover:bg-stone-100 active:bg-stone-200",children:D.jsx("img",{src:d.icon,className:Fe(" p-1 rounded-lg h-6 w-6",{"bg-yellow-300":d.isActive()})})},f)),D.jsx(dT,{editor:n.editor,isOpen:s,setIsOpen:()=>{o(!s),i(!1)}}),l&&D.jsx(v0,{setToolVisibility:u,editor:n.editor,elementRef:c,bubbleMenu:!0,setIsLinkPopupOpen:a})]})};function IT(){const n=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"];let e=[];for(let t=0;t<36;t++)t===8||t===13||t===18||t===23?e[t]="-":e[t]=n[Math.ceil(Math.random()*n.length-1)];return e.join("")}var PT=IT;const FT=Nc(PT),w0=Ve.create({name:"column",content:"dBlock+",isolating:!0,addAttributes(){return{position:{default:"",parseHTML:n=>n.getAttribute("data-position"),renderHTML:n=>({"data-position":n.position})}}},renderHTML({HTMLAttributes:n}){return["div",xe(n,{"data-type":"column"}),0]},parseHTML(){return[{tag:'div[data-type="column"]'}]}}),BT=(n,e)=>Array.from({length:n},(t,r)=>e(r)),jl=({type:n,content:e})=>e?{type:n,content:e}:{type:n},$T=({content:n})=>jl({type:"paragraph",content:n}),x0=({content:n})=>jl({type:"dBlock",content:n}),C0=({content:n})=>jl({type:"column",content:n}),k0=({content:n})=>jl({type:"columns",content:n}),S0=n=>{const e=[x0({content:[$T({})]})];return BT(n,()=>C0({content:e}))},E0=(n,e)=>{for(let t=n.depth;t>0;t--){const r=n.node(t),i=t>0?n.before(t):0,s=n.start(t);if(e({node:r,pos:i,start:s}))return{start:s,depth:t,node:r,pos:i}}throw Error("no ancestor found")};class Hl extends ue{constructor(t){const{$from:r,$to:i}=t;super(r,i);vr(this,"_$from");vr(this,"_$to");this._$from=r,this._$to=i}get $from(){return this._$from}get $to(){return this._$to}map(){return this}content(){return this.$from.doc.slice(this.from,this.to,!0)}eq(t){return t instanceof Hl&&t.anchor==this.anchor}toJSON(){return{type:"column",from:this.from,to:this.to}}expandSelection(t){var a;const r=({pos:c,node:u})=>u.type.name===w0.name?!0:t.resolve(c).depth<=0,{pos:i}=E0(this.$from,r);this._$from=t.resolve(i);const{pos:s,node:o}=E0(this.$to,r);this._$to=t.resolve(s+o.nodeSize),((a=this.getFirstNode())==null?void 0:a.type.name)===Vl.name&&(this._$from=t.resolve(this.$from.pos+2),this._$to=t.resolve(this.$to.pos+2));const l=this;l.$anchor=this._$from,l.$head=this._$to,l.ranges=[new Jc(this._$from,this._$to)]}static create(t,r,i){const s=t.resolve(r),o=t.resolve(i),l=new ce(s,o);return new Hl(l)}getFirstNode(){return this.content().content.firstChild}}var pi=(n=>(n.AlignLeft="align-left",n.AlignRight="align-right",n.AlignCenter="align-center",n))(pi||{});const Vl=Ve.create({name:"columns",group:"columns",content:"column{2,}",defining:!0,draggable:!0,isolating:!0,addAttributes(){return{layout:{default:"align-center"}}},addCommands(){return{unsetColumns:()=>({tr:n,dispatch:e})=>{try{if(!e)return;const t=n.selection.$from,i=Ru(t,({node:a})=>!this.options.nestedColumns&&a.type==this.type?!0:a.type==this.type);if(i===void 0)return;let s=[];i.node.descendants((a,c,u)=>{(u==null?void 0:u.type.name)===Vl.name&&s.push(a)}),s=s.reverse().filter(a=>a.content.size>0);const o=n.doc.resolve(i.pos),l=new se(o);return n=n.setSelection(l),s.forEach(a=>n=n.insert(i.pos,a)),n=n.deleteSelection(),e(n)}catch(t){console.error(t)}},setColumns:(n,e=!1)=>({tr:t,dispatch:r})=>{try{const{doc:i,selection:s}=t;if(!r){console.log("no dispatch");return}const o=new Hl(s);o.expandSelection(i);const{openStart:l,openEnd:a}=o.content();if(l!==a){console.warn("failed depth check");return}let c;if(e){const h=o.content().toJSON(),p=C0(h),g=S0(n-1);c=k0({content:[p,...g]})}else{const h=S0(n);c=k0({content:h})}const u=i.type.schema.nodeFromJSON(x0({content:[c]}));if(u===null)return;const d=o.$anchor.parent.type;if(!(h=>!(!h.contentMatch.matchType(this.type)||!this.options.nestedColumns&&h.name===Vl.name))(d)){console.warn("content not allowed");return}return t=t.setSelection(o),t=t.replaceSelectionWith(u,!1),r(t)}catch(i){console.error(i)}},setLayout:n=>({commands:e})=>e.updateAttributes("columns",{layout:n})}},renderHTML({HTMLAttributes:n}){return["div",{"data-type":"columns",class:`layout-${n.layout}`},0]},parseHTML(){return[{tag:'div[data-type="columns"]'}]}}),jT=(n,e)=>{const{view:t,state:{selection:{from:r}}}=n,i=document.querySelectorAll(".has-focus"),s=i.length,l=i[s-1];if(l&&l.getAttribute("data-type")&&l.getAttribute("data-type")===e||l&&l.classList&&l.classList.contains(e))return l;const a=t.domAtPos(r).node;let c=a;for(c.tagName||(c=a.parentElement);c&&!(c.getAttribute("data-type")&&c.getAttribute("data-type")===e)&&!c.classList.contains(e);)c=c.parentElement;return c},ld=O.forwardRef(({children:n,className:e,withShadow:t=!0,withBorder:r=!0,...i},s)=>{const o=Fe(e,"bg-white rounded-md",t?"shadow-md":"",r?"border border-neutral-200":"");return D.jsx("div",{className:o,...i,ref:s,children:n})});ld.displayName="Surface";const zl=O.forwardRef(({active:n,buttonSize:e="medium",children:t,disabled:r,variant:i="primary",className:s,activeClassname:o,...l},a)=>{const c=Fe("flex group items-center justify-center border border-transparent gap-2 text-sm font-semibold rounded-md disabled:opacity-50 whitespace-nowrap",i==="primary"&&Fe("text-white bg-black border-black dark:text-black dark:bg-white dark:border-white",!r&&!n&&"hover:bg-neutral-800 active:bg-neutral-900 dark:hover:bg-neutral-200 dark:active:bg-neutral-300",n&&Fe("bg-neutral-900 dark:bg-neutral-300",o)),i==="secondary"&&Fe("text-neutral-900 dark:text-white",!r&&!n&&"hover:bg-neutral-100 active:bg-neutral-200 dark:hover:bg-neutral-900 dark:active:bg-neutral-800",n&&"bg-neutral-200 dark:bg-neutral-800"),i==="tertiary"&&Fe("bg-neutral-50 text-neutral-900 dark:bg-neutral-900 dark:text-white dark:border-neutral-900",!r&&!n&&"hover:bg-neutral-100 active:bg-neutral-200 dark:hover:bg-neutral-800 dark:active:bg-neutral-700",n&&Fe("bg-neutral-200 dark:bg-neutral-800",o)),i==="ghost"&&Fe("bg-transparent border-transparent text-neutral-500",!r&&!n&&"hover:bg-black/5 hover:text-neutral-700 active:bg-black/10 active:text-neutral-800 ",n&&Fe("bg-black/10 text-neutral-800 ",o)),e==="medium"&&"py-2 px-3",e==="small"&&"py-1 px-2",e==="icon"&&"w-8 h-8",e==="iconSmall"&&"w-6 h-6",s);return D.jsx("button",{ref:a,disabled:r,className:c,...l,children:t})});zl.displayName="Button";const T0=({content:n,children:e})=>{const[t,r]=O.useState(!1);return D.jsxs("div",{className:"relative inline-block",onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),children:[e,t&&D.jsx("div",{className:"absolute z-10 p-2 mt-2 text-sm text-white bg-gray-800 rounded shadow-lg",children:n})]})},A0=O.forwardRef(({shouldShowContent:n=!0,children:e,isVertical:t=!1,className:r,...i},s)=>{const o=Fe("text-black inline-flex h-full leading-none gap-0.5",t?"flex-col p-2":"flex-row p-1 items-center",r);return n?n&&D.jsx(ld,{className:o,...i,ref:s,children:e}):null});A0.displayName="Toolbar";const M0=O.forwardRef(({horizontal:n,className:e,...t},r)=>{const i=Fe("bg-neutral-200",n?"w-full min-w-[1.5rem] h-[1px] my-1 first:mt-0 last:mt-0":"h-full min-h-[1.5rem] w-[1px] mx-1 first:ml-0 last:mr-0",e);return D.jsx("div",{className:i,ref:r,...t})});M0.displayName="Toolbar.Divider";const O0=O.forwardRef(({children:n,buttonSize:e="icon",variant:t="ghost",className:r,tooltip:i,activeClassname:s,...o},l)=>{const a=Fe("gap-1 min-w-[2rem] px-2 w-auto",r),c=D.jsx(zl,{activeClassname:s,className:a,variant:t,buttonSize:e,ref:l,...o,children:n});return i?D.jsx(T0,{content:i,children:c}):c});O0.displayName="ToolbarButton";const vo={Wrapper:A0,Divider:M0,Button:O0},HT=({editor:n,appendTo:e})=>{const t=O.useCallback(()=>{const l=jT(n,"columns");return(l==null?void 0:l.getBoundingClientRect())||new DOMRect(-1e3,-1e3,0,0)},[n]),r=O.useCallback(()=>n.isActive("columns"),[n]),i=O.useCallback(()=>{n.chain().focus().setLayout(pi.AlignLeft).run()},[n]),s=O.useCallback(()=>{n.chain().focus().setLayout(pi.AlignRight).run()},[n]),o=O.useCallback(()=>{n.chain().focus().setLayout(pi.AlignCenter).run()},[n]);return D.jsx(Ug,{editor:n,pluginKey:`columnsMenu-${FT()}`,shouldShow:r,updateDelay:0,tippyOptions:{offset:[0,8],popperOptions:{modifiers:[{name:"flip",enabled:!1}]},getReferenceClientRect:t,moveTransition:"transform 0.15s ease-out",duration:200,animation:"shift-toward-subtle",appendTo:()=>e==null?void 0:e.current,plugins:[OE],sticky:"popper"},children:D.jsxs(vo.Wrapper,{children:[D.jsx(vo.Button,{tooltip:"Align left",active:n.isActive("columns",{layout:pi.AlignLeft}),onClick:i,children:D.jsx(eT,{size:20})}),D.jsx(vo.Button,{tooltip:"Align center",active:n.isActive("columns",{layout:pi.AlignCenter}),onClick:o,children:D.jsx(s0,{size:20})}),D.jsx(vo.Button,{tooltip:"Align right",active:n.isActive("columns",{layout:pi.AlignRight}),onClick:s,children:D.jsx(tT,{size:20})})]})})},_0=O.createContext(null),Ul=()=>O.useContext(_0),VT=({children:n,isPreviewMode:e})=>D.jsx(_0.Provider,{value:e,children:n}),N0=({height:n,width:e})=>D.jsx("span",{className:"flex items-center justify-center ",children:D.jsx("span",{className:`${e?`w-${e}`:"w-8"} ${n?`h-${n}`:"h-8"} border-4 border-t-4 border-t-[#ccc] border-gray-500 rounded-full animate-spin`})}),zT=({editor:n})=>{const{toolRef:e,toolVisibilty:t,setToolVisibility:r,toolbar:i}=b0({editor:n});return D.jsxs("div",{className:"w-fit bg-transparent px-4 items-center rounded-lg h-16 flex gap-1 justify-center",children:[D.jsxs("button",{className:"hover:bg-[#f2f2f2] border gap-2 rounded-lg w-28 h-8 p-1 flex justify-center items-center",onClick:()=>r(Te.HEADING),children:[D.jsx("span",{className:"text-sm",children:n!=null&&n.isActive("heading",{level:1})?"Heading 1":n!=null&&n.isActive("heading",{level:2})?"Heading 2":n!=null&&n.isActive("heading",{level:3})?"Heading 3":"Text"}),D.jsx(id,{className:"h-4 w-4"})]}),i.map((s,o)=>s?D.jsx("div",{className:"tooltip tooltip-bottom","data-tip":s.title,children:D.jsx("span",{onClick:()=>s.onClick(),className:Fe("rounded-lg w-8 h-8 p-1 flex cursor-pointer justify-center items-center",s.isActive?"bg-yellow-300":"hover:bg-[#f2f2f2]"),children:typeof s.icon=="string"?D.jsx("img",{src:s.icon,className:"w-4"}):s.icon})},s.title):D.jsx("div",{className:" w-[1px] h-[50%] bg-[#777777]"},o)),t===Te.HEADING&&D.jsx(RT,{setVisibility:r,editor:n,elementRef:e}),t===Te.TEXT_COLOR&&D.jsx(DT,{setVisibility:r,editor:n,elementRef:e}),t===Te.HIGHLIGHT&&D.jsx(MT,{setVisibility:r,editor:n,elementRef:e}),t===Te.FONT_FAMILY&&D.jsx(OT,{setToolVisibility:r,editor:n,elementRef:e}),t===Te.ALIGNMENT&&D.jsx(_T,{setToolVisibility:r,editor:n,elementRef:e}),t===Te.LIST&&D.jsx(NT,{setToolVisibility:r,editor:n,elementRef:e}),t===Te.LINK&&D.jsx(v0,{setToolVisibility:r,editor:n,elementRef:e})]})},Lt=()=>new Map,ad=n=>{const e=Lt();return n.forEach((t,r)=>{e.set(r,t)}),e},zt=(n,e,t)=>{let r=n.get(e);return r===void 0&&n.set(e,r=t()),r},UT=(n,e)=>{const t=[];for(const[r,i]of n)t.push(e(i,r));return t},WT=(n,e)=>{for(const[t,r]of n)if(e(r,t))return!0;return!1},or=()=>new Set,cd=n=>n[n.length-1],qT=(n,e)=>{for(let t=0;t<e.length;t++)n.push(e[t])},lr=Array.from,KT=(n,e)=>{for(let t=0;t<n.length;t++)if(e(n[t],t,n))return!0;return!1},ud=Array.isArray;class dd{constructor(){this._observers=Lt()}on(e,t){return zt(this._observers,e,or).add(t),t}once(e,t){const r=(...i)=>{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){const r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return lr((this._observers.get(e)||Lt()).values()).forEach(r=>r(...t))}destroy(){this._observers=Lt()}}class D0{constructor(){this._observers=Lt()}on(e,t){zt(this._observers,e,or).add(t)}once(e,t){const r=(...i)=>{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){const r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return lr((this._observers.get(e)||Lt()).values()).forEach(r=>r(...t))}destroy(){this._observers=Lt()}}const wn=Math.floor,Wl=Math.abs,JT=Math.log10,Ir=(n,e)=>n<e?n:e,ar=(n,e)=>n>e?n:e,R0=n=>n!==0?n<0:1/n<0,Bn=Date.now,GT=1200,YT=2500,ql=3e4,fd=n=>{if(n.shouldConnect&&n.ws===null){const e=new WebSocket(n.url),t=n.binaryType;let r=null;t&&(e.binaryType=t),n.ws=e,n.connecting=!0,n.connected=!1,e.onmessage=o=>{n.lastMessageReceived=Bn();const l=o.data,a=typeof l=="string"?JSON.parse(l):l;a&&a.type==="pong"&&(clearTimeout(r),r=setTimeout(s,ql/2)),n.emit("message",[a,n])};const i=o=>{n.ws!==null&&(n.ws=null,n.connecting=!1,n.connected?(n.connected=!1,n.emit("disconnect",[{type:"disconnect",error:o},n])):n.unsuccessfulReconnects++,setTimeout(fd,Ir(JT(n.unsuccessfulReconnects+1)*GT,YT),n)),clearTimeout(r)},s=()=>{n.ws===e&&n.send({type:"ping"})};e.onclose=()=>i(null),e.onerror=o=>i(o),e.onopen=()=>{n.lastMessageReceived=Bn(),n.connecting=!1,n.connected=!0,n.unsuccessfulReconnects=0,n.emit("connect",[{type:"connect"},n]),r=setTimeout(s,ql/2)}}};class ZT extends D0{constructor(e,{binaryType:t}={}){super(),this.url=e,this.ws=null,this.binaryType=t||null,this.connected=!1,this.connecting=!1,this.unsuccessfulReconnects=0,this.lastMessageReceived=0,this.shouldConnect=!0,this._checkInterval=setInterval(()=>{this.connected&&ql<Bn()-this.lastMessageReceived&&this.ws.close()},ql/2),fd(this)}send(e){this.ws&&this.ws.send(JSON.stringify(e))}destroy(){clearInterval(this._checkInterval),this.disconnect(),super.destroy()}disconnect(){this.shouldConnect=!1,this.ws!==null&&this.ws.close()}connect(){this.shouldConnect=!0,!this.connected&&this.ws===null&&fd(this)}}const $n=n=>new Error(n),xn=()=>{throw $n("Method unimplemented")},cn=()=>{throw $n("Unexpected case")},L0=1,I0=2,hd=4,pd=8,wo=32,cr=64,Yt=128,Kl=31,md=63,mi=127,XT=2147483647,QT=crypto.getRandomValues.bind(crypto),P0=Math.random,F0=()=>QT(new Uint32Array(1))[0],eA=n=>n[wn(P0()*n.length)],tA="10000000-1000-4000-8000"+-1e11,B0=()=>tA.replace(/[018]/g,n=>(n^F0()&15>>n/4).toString(16)),$0=Number.MAX_SAFE_INTEGER,nA=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&wn(n)===n),rA=String.fromCharCode,iA=n=>n.toLowerCase(),sA=/^\s*/g,oA=n=>n.replace(sA,""),lA=/([A-Z])/g,j0=(n,e)=>oA(n.replace(lA,t=>`${e}${iA(t)}`)),aA=n=>{const e=unescape(encodeURIComponent(n)),t=e.length,r=new Uint8Array(t);for(let i=0;i<t;i++)r[i]=e.codePointAt(i);return r},xo=typeof TextEncoder<"u"?new TextEncoder:null,gd=xo?n=>xo.encode(n):aA;let Co=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Co&&Co.decode(new Uint8Array).length===1&&(Co=null);class ko{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const gt=()=>new ko,cA=n=>{let e=n.cpos;for(let t=0;t<n.bufs.length;t++)e+=n.bufs[t].length;return e},qe=n=>{const e=new Uint8Array(cA(n));let t=0;for(let r=0;r<n.bufs.length;r++){const i=n.bufs[r];e.set(i,t),t+=i.length}return e.set(new Uint8Array(n.cbuf.buffer,0,n.cpos),t),e},uA=(n,e)=>{const t=n.cbuf.length;t-n.cpos<e&&(n.bufs.push(new Uint8Array(n.cbuf.buffer,0,n.cpos)),n.cbuf=new Uint8Array(ar(t,e)*2),n.cpos=0)},yt=(n,e)=>{const t=n.cbuf.length;n.cpos===t&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(t*2),n.cpos=0),n.cbuf[n.cpos++]=e},So=yt,ae=(n,e)=>{for(;e>mi;)yt(n,Yt|mi&e),e=wn(e/128);yt(n,mi&e)},yd=(n,e)=>{const t=R0(e);for(t&&(e=-e),yt(n,(e>md?Yt:0)|(t?cr:0)|md&e),e=wn(e/64);e>0;)yt(n,(e>mi?Yt:0)|mi&e),e=wn(e/128)},bd=new Uint8Array(3e4),dA=bd.length/3,fA=(n,e)=>{if(e.length<dA){const t=xo.encodeInto(e,bd).written||0;ae(n,t);for(let r=0;r<t;r++)yt(n,bd[r])}else Xe(n,gd(e))},hA=(n,e)=>{const t=unescape(encodeURIComponent(e)),r=t.length;ae(n,r);for(let i=0;i<r;i++)yt(n,t.codePointAt(i))},jn=xo&&xo.encodeInto?fA:hA,Jl=(n,e)=>{const t=n.cbuf.length,r=n.cpos,i=Ir(t-r,e.length),s=e.length-i;n.cbuf.set(e.subarray(0,i),r),n.cpos+=i,s>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(ar(t*2,s)),n.cbuf.set(e.subarray(i)),n.cpos=s)},Xe=(n,e)=>{ae(n,e.byteLength),Jl(n,e)},vd=(n,e)=>{uA(n,e);const t=new DataView(n.cbuf.buffer,n.cpos,e);return n.cpos+=e,t},pA=(n,e)=>vd(n,4).setFloat32(0,e,!1),mA=(n,e)=>vd(n,8).setFloat64(0,e,!1),gA=(n,e)=>vd(n,8).setBigInt64(0,e,!1),H0=new DataView(new ArrayBuffer(4)),yA=n=>(H0.setFloat32(0,n),H0.getFloat32(0)===n),ts=(n,e)=>{switch(typeof e){case"string":yt(n,119),jn(n,e);break;case"number":nA(e)&&Wl(e)<=XT?(yt(n,125),yd(n,e)):yA(e)?(yt(n,124),pA(n,e)):(yt(n,123),mA(n,e));break;case"bigint":yt(n,122),gA(n,e);break;case"object":if(e===null)yt(n,126);else if(ud(e)){yt(n,117),ae(n,e.length);for(let t=0;t<e.length;t++)ts(n,e[t])}else if(e instanceof Uint8Array)yt(n,116),Xe(n,e);else{yt(n,118);const t=Object.keys(e);ae(n,t.length);for(let r=0;r<t.length;r++){const i=t[r];jn(n,i),ts(n,e[i])}}break;case"boolean":yt(n,e?120:121);break;default:yt(n,127)}};class V0 extends ko{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&ae(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const z0=n=>{n.count>0&&(yd(n.encoder,n.count===1?n.s:-n.s),n.count>1&&ae(n.encoder,n.count-2))};class Gl{constructor(){this.encoder=new ko,this.s=0,this.count=0}write(e){this.s===e?this.count++:(z0(this),this.count=1,this.s=e)}toUint8Array(){return z0(this),qe(this.encoder)}}const U0=n=>{if(n.count>0){const e=n.diff*2+(n.count===1?0:1);yd(n.encoder,e),n.count>1&&ae(n.encoder,n.count-2)}};class wd{constructor(){this.encoder=new ko,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(U0(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return U0(this),qe(this.encoder)}}class bA{constructor(){this.sarr=[],this.s="",this.lensE=new Gl}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new ko;return this.sarr.push(this.s),this.s="",jn(e,this.sarr.join("")),Jl(e,this.lensE.toUint8Array()),qe(e)}}const W0=$n("Unexpected end of array"),q0=$n("Integer out of Range");class Yl{constructor(e){this.arr=e,this.pos=0}}const Hn=n=>new Yl(n),vA=n=>n.pos!==n.arr.length,wA=(n,e)=>{const t=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,e);return n.pos+=e,t},bt=n=>wA(n,he(n)),gi=n=>n.arr[n.pos++],he=n=>{let e=0,t=1;const r=n.arr.length;for(;n.pos<r;){const i=n.arr[n.pos++];if(e=e+(i&mi)*t,t*=128,i<Yt)return e;if(e>$0)throw q0}throw W0},xd=n=>{let e=n.arr[n.pos++],t=e&md,r=64;const i=(e&cr)>0?-1:1;if(!(e&Yt))return i*t;const s=n.arr.length;for(;n.pos<s;){if(e=n.arr[n.pos++],t=t+(e&mi)*r,r*=128,e<Yt)return i*t;if(t>$0)throw q0}throw W0},ur=Co?n=>Co.decode(bt(n)):n=>{let e=he(n);if(e===0)return"";{let t=String.fromCodePoint(gi(n));if(--e<100)for(;e--;)t+=String.fromCodePoint(gi(n));else for(;e>0;){const r=e<1e4?e:1e4,i=n.arr.subarray(n.pos,n.pos+r);n.pos+=r,t+=String.fromCodePoint.apply(null,i),e-=r}return decodeURIComponent(escape(t))}},Cd=(n,e)=>{const t=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,e);return n.pos+=e,t},xA=[n=>{},n=>null,xd,n=>Cd(n,4).getFloat32(0,!1),n=>Cd(n,8).getFloat64(0,!1),n=>Cd(n,8).getBigInt64(0,!1),n=>!1,n=>!0,ur,n=>{const e=he(n),t={};for(let r=0;r<e;r++){const i=ur(n);t[i]=ns(n)}return t},n=>{const e=he(n),t=[];for(let r=0;r<e;r++)t.push(ns(n));return t},bt],ns=n=>xA[127-gi(n)](n);class K0 extends Yl{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),vA(this)?this.count=he(this)+1:this.count=-1),this.count--,this.s}}class Zl extends Yl{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=xd(this);const e=R0(this.s);this.count=1,e&&(this.s=-this.s,this.count=he(this)+2)}return this.count--,this.s}}class kd extends Yl{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const e=xd(this),t=e&1;this.diff=wn(e/2),this.count=1,t&&(this.count=he(this)+2)}return this.s+=this.diff,this.count--,this.s}}class CA{constructor(e){this.decoder=new Zl(e),this.str=ur(this.decoder),this.spos=0}read(){const e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}}const J0=n=>n===void 0?null:n;class kA{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}}let G0=new kA,Sd=!0;try{typeof localStorage<"u"&&localStorage&&(G0=localStorage,Sd=!1)}catch{}const Y0=G0,SA=n=>Sd||addEventListener("storage",n),EA=n=>Sd||removeEventListener("storage",n),TA=Object.assign,Ed=Object.keys,AA=(n,e)=>{for(const t in n)e(n[t],t)},Z0=n=>Ed(n).length,X0=n=>Ed(n).length,MA=n=>{for(const e in n)return!1;return!0},OA=(n,e)=>{for(const t in n)if(!e(n[t],t))return!1;return!0},Q0=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),_A=(n,e)=>n===e||X0(n)===X0(e)&&OA(n,(t,r)=>(t!==void 0||Q0(e,r))&&e[r]===t),Td=(n,e,t=0)=>{try{for(;t<n.length;t++)n[t](...e)}finally{t<n.length&&Td(n,e,t+1)}},NA=()=>{},DA=n=>n,RA=(n,e)=>n===e,Eo=(n,e)=>{if(n==null||e==null)return RA(n,e);if(n.constructor!==e.constructor)return!1;if(n===e)return!0;switch(n.constructor){case ArrayBuffer:n=new Uint8Array(n),e=new Uint8Array(e);case Uint8Array:{if(n.byteLength!==e.byteLength)return!1;for(let t=0;t<n.length;t++)if(n[t]!==e[t])return!1;break}case Set:{if(n.size!==e.size)return!1;for(const t of n)if(!e.has(t))return!1;break}case Map:{if(n.size!==e.size)return!1;for(const t of n.keys())if(!e.has(t)||!Eo(n.get(t),e.get(t)))return!1;break}case Object:if(Z0(n)!==Z0(e))return!1;for(const t in n)if(!Q0(n,t)||!Eo(n[t],e[t]))return!1;break;case Array:if(n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(!Eo(n[t],e[t]))return!1;break;default:return!1}return!0},LA=(n,e)=>e.includes(n),rs=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",Ad=typeof window<"u"&&typeof document<"u"&&!rs;let Vn;const IA=()=>{if(Vn===void 0)if(rs){Vn=Lt();const n=process.argv;let e=null;for(let t=0;t<n.length;t++){const r=n[t];r[0]==="-"?(e!==null&&Vn.set(e,""),e=r):e!==null&&(Vn.set(e,r),e=null)}e!==null&&Vn.set(e,"")}else typeof location=="object"?(Vn=Lt(),(location.search||"?").slice(1).split("&").forEach(n=>{if(n.length!==0){const[e,t]=n.split("=");Vn.set(`--${j0(e,"-")}`,t),Vn.set(`-${j0(e,"-")}`,t)}})):Vn=Lt();return Vn},Md=n=>IA().has(n),Xl=n=>J0(rs?process.env[n.toUpperCase().replaceAll("-","_")]:Y0.getItem(n));(n=>Md("--"+n)||Xl(n)!==null)("production");const ey=rs&&LA(process.env.FORCE_COLOR,["true","1","2"]),PA=!Md("--no-colors")&&(!rs||process.stdout.isTTY||ey)&&(!rs||Md("--color")||ey||Xl("COLORTERM")!==null||(Xl("TERM")||"").includes("color"));class FA{constructor(e,t){this.left=e,this.right=t}}const dr=(n,e)=>new FA(n,e),BA=typeof document<"u"?document:{};typeof DOMParser<"u"&&new DOMParser;const $A=n=>UT(n,(e,t)=>`${t}:${e};`).join(""),jA=JSON.stringify,HA=(n=>class{constructor(t){this._=t}destroy(){n(this._)}})(clearTimeout),Od=(n,e)=>new HA(setTimeout(e,n)),fr=Symbol,un=fr(),yi=fr(),ty=fr(),_d=fr(),ny=fr(),ry=fr(),iy=fr(),Ql=fr(),ea=fr(),VA=n=>{var r;n.length===1&&((r=n[0])==null?void 0:r.constructor)===Function&&(n=n[0]());const e=[];let t=0;for(;t<n.length;t++){const i=n[t];i===void 0||i.constructor===String||i.constructor===Number||i.constructor===Object&&e.push(JSON.stringify(i))}return e},sy=[ny,iy,Ql,ty];let Nd=0,oy=Bn();const zA=(n,e)=>{const t=sy[Nd],r=Xl("log"),i=r!==null&&(r==="*"||r==="true"||new RegExp(r,"gi").test(e));return Nd=(Nd+1)%sy.length,e+=": ",i?(...s)=>{var a;s.length===1&&((a=s[0])==null?void 0:a.constructor)===Function&&(s=s[0]());const o=Bn(),l=o-oy;oy=o,n(t,e,ea,...s.map(c=>{switch(c!=null&&c.constructor===Uint8Array&&(c=Array.from(c)),typeof c){case"string":case"symbol":return c;default:return jA(c)}}),t," +"+l+"ms")}:NA},UA={[un]:dr("font-weight","bold"),[yi]:dr("font-weight","normal"),[ty]:dr("color","blue"),[ny]:dr("color","green"),[_d]:dr("color","grey"),[ry]:dr("color","red"),[iy]:dr("color","purple"),[Ql]:dr("color","orange"),[ea]:dr("color","black")},ly=PA?n=>{var o;n.length===1&&((o=n[0])==null?void 0:o.constructor)===Function&&(n=n[0]());const e=[],t=[],r=Lt();let i=[],s=0;for(;s<n.length;s++){const l=n[s],a=UA[l];if(a!==void 0)r.set(a.left,a.right);else{if(l===void 0)break;if(l.constructor===String||l.constructor===Number){const c=$A(r);s>0||c.length>0?(e.push("%c"+l),t.push(c)):e.push(l)}else break}}for(s>0&&(i=t,i.unshift(e.join("")));s<n.length;s++){const l=n[s];l instanceof Symbol||i.push(l)}return i}:VA,ay=(...n)=>{console.log(...ly(n)),cy.forEach(e=>e.print(n))},WA=(...n)=>{console.warn(...ly(n)),n.unshift(Ql),cy.forEach(e=>e.print(n))},cy=or(),qA=n=>zA(ay,n),uy=n=>new Promise(n);Promise.all.bind(Promise);const KA=n=>Promise.reject(n),Dd=n=>Promise.resolve(n),dy=n=>new Uint8Array(n),JA=(n,e,t)=>new Uint8Array(n,e,t),GA=n=>new Uint8Array(n),YA=n=>{let e="";for(let t=0;t<n.byteLength;t++)e+=rA(n[t]);return btoa(e)},ZA=n=>Buffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),XA=n=>{const e=atob(n),t=dy(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t},QA=n=>{const e=Buffer.from(n,"base64");return JA(e.buffer,e.byteOffset,e.byteLength)},fy=Ad?YA:ZA,hy=Ad?XA:QA,eM=n=>{const e=dy(n.byteLength);return e.set(n),e},py=new Map;class tM{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:hy(t.newValue||"")}),SA(this._onChange)}postMessage(e){Y0.setItem(this.room,fy(GA(e)))}close(){EA(this._onChange)}}const nM=typeof BroadcastChannel>"u"?tM:BroadcastChannel,Rd=n=>zt(py,n,()=>{const e=or(),t=new nM(n);return t.onmessage=r=>e.forEach(i=>i(r.data,"broadcastchannel")),{bc:t,subs:e}}),rM=(n,e)=>(Rd(n).subs.add(e),e),iM=(n,e)=>{const t=Rd(n),r=t.subs.delete(e);return r&&t.subs.size===0&&(t.bc.close(),py.delete(n)),r},sM=(n,e,t=null)=>{const r=Rd(n);r.bc.postMessage(e),r.subs.forEach(i=>i(e,t))},my=()=>{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}},gy=n=>({[Symbol.iterator](){return this},next:n}),oM=(n,e)=>gy(()=>{let t;do t=n.next();while(!t.done&&!e(t.value));return t}),Ld=(n,e)=>gy(()=>{const{done:t,value:r}=n.next();return{done:t,value:t?void 0:e(r)}});class Id{constructor(e,t){this.clock=e,this.len=t}}class is{constructor(){this.clients=new Map}}const Pr=(n,e,t)=>e.clients.forEach((r,i)=>{const s=n.doc.store.clients.get(i);for(let o=0;o<r.length;o++){const l=r[o];Fy(n,s,l.clock,l.len,t)}}),lM=(n,e)=>{let t=0,r=n.length-1;for(;t<=r;){const i=wn((t+r)/2),s=n[i],o=s.clock;if(o<=e){if(e<o+s.len)return i;t=i+1}else r=i-1}return null},ss=(n,e)=>{const t=n.clients.get(e.client);return t!==void 0&&lM(t,e.clock)!==null},Pd=n=>{n.clients.forEach(e=>{e.sort((i,s)=>i.clock-s.clock);let t,r;for(t=1,r=1;t<e.length;t++){const i=e[r-1],s=e[t];i.clock+i.len>=s.clock?i.len=ar(i.len,s.clock+s.len-i.clock):(r<t&&(e[r]=s),r++)}e.length=r})},Fd=n=>{const e=new is;for(let t=0;t<n.length;t++)n[t].clients.forEach((r,i)=>{if(!e.clients.has(i)){const s=r.slice();for(let o=t+1;o<n.length;o++)qT(s,n[o].clients.get(i)||[]);e.clients.set(i,s)}});return Pd(e),e},To=(n,e,t,r)=>{zt(n.clients,e,()=>[]).push(new Id(t,r))},yy=()=>new is,by=n=>{const e=yy();return n.clients.forEach((t,r)=>{const i=[];for(let s=0;s<t.length;s++){const o=t[s];if(o.deleted){const l=o.id.clock;let a=o.length;if(s+1<t.length)for(let c=t[s+1];s+1<t.length&&c.deleted;c=t[++s+1])a+=c.length;i.push(new Id(l,a))}}i.length>0&&e.clients.set(r,i)}),e},ls=(n,e)=>{ae(n.restEncoder,e.clients.size),lr(e.clients.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{n.resetDsCurVal(),ae(n.restEncoder,t);const i=r.length;ae(n.restEncoder,i);for(let s=0;s<i;s++){const o=r[s];n.writeDsClock(o.clock),n.writeDsLen(o.len)}})},Bd=n=>{const e=new is,t=he(n.restDecoder);for(let r=0;r<t;r++){n.resetDsCurVal();const i=he(n.restDecoder),s=he(n.restDecoder);if(s>0){const o=zt(e.clients,i,()=>[]);for(let l=0;l<s;l++)o.push(new Id(n.readDsClock(),n.readDsLen()))}}return e},vy=(n,e,t)=>{const r=new is,i=he(n.restDecoder);for(let s=0;s<i;s++){n.resetDsCurVal();const o=he(n.restDecoder),l=he(n.restDecoder),a=t.clients.get(o)||[],c=rt(t,o);for(let u=0;u<l;u++){const d=n.readDsClock(),f=d+n.readDsLen();if(d<c){c<f&&To(r,o,c,f-c);let h=zn(a,d),p=a[h];for(!p.deleted&&p.id.clock<d&&(a.splice(h+1,0,ha(e,p,d-p.id.clock)),h++);h<a.length&&(p=a[h++],p.id.clock<f);)p.deleted||(f<p.id.clock+p.length&&a.splice(h,0,ha(e,p,f-p.id.clock)),p.delete(e))}else To(r,o,d,f-d)}}if(r.clients.size>0){const s=new bi;return ae(s.restEncoder,0),ls(s,r),s.toUint8Array()}return null},wy=F0;class as extends dd{constructor({guid:e=B0(),collectionid:t=null,gc:r=!0,gcFilter:i=()=>!0,meta:s=null,autoLoad:o=!1,shouldLoad:l=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=wy(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Ly,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=o,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.whenLoaded=uy(c=>{this.on("load",()=>{this.isLoaded=!0,c(this)})});const a=()=>uy(c=>{const u=d=>{(d===void 0||d===!0)&&(this.off("sync",u),c())};this.on("sync",u)});this.on("sync",c=>{c===!1&&this.isSynced&&(this.whenSynced=a()),this.isSynced=c===void 0||c===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=a()}load(){const e=this._item;e!==null&&!this.shouldLoad&&Be(e.parent.doc,t=>{t.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(lr(this.subdocs).map(e=>e.guid))}transact(e,t=null){return Be(this,e,t)}get(e,t=Et){const r=zt(this.share,e,()=>{const s=new t;return s._integrate(this,null),s}),i=r.constructor;if(t!==Et&&i!==t)if(i===Et){const s=new t;s._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=s}),s._start=r._start;for(let o=s._start;o!==null;o=o.right)o.parent=s;return s._length=r._length,this.share.set(e,s),s._integrate(this,null),s}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return r}getArray(e=""){return this.get(e,hs)}getText(e=""){return this.get(e,wi)}getMap(e=""){return this.get(e,ps)}getXmlElement(e=""){return this.get(e,It)}getXmlFragment(e=""){return this.get(e,xi)}toJSON(){const e={};return this.share.forEach((t,r)=>{e[r]=t.toJSON()}),e}destroy(){lr(this.subdocs).forEach(t=>t.destroy());const e=this._item;if(e!==null){this._item=null;const t=e.content;t.doc=new as({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,Be(e.parent.doc,r=>{const i=t.doc;e.deleted||r.subdocsAdded.add(i),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class xy{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return he(this.restDecoder)}readDsLen(){return he(this.restDecoder)}}class Cy extends xy{readLeftID(){return pe(he(this.restDecoder),he(this.restDecoder))}readRightID(){return pe(he(this.restDecoder),he(this.restDecoder))}readClient(){return he(this.restDecoder)}readInfo(){return gi(this.restDecoder)}readString(){return ur(this.restDecoder)}readParentInfo(){return he(this.restDecoder)===1}readTypeRef(){return he(this.restDecoder)}readLen(){return he(this.restDecoder)}readAny(){return ns(this.restDecoder)}readBuf(){return eM(bt(this.restDecoder))}readJSON(){return JSON.parse(ur(this.restDecoder))}readKey(){return ur(this.restDecoder)}}class aM{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=he(this.restDecoder),this.dsCurrVal}readDsLen(){const e=he(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class cs extends aM{constructor(e){super(e),this.keys=[],he(e),this.keyClockDecoder=new kd(bt(e)),this.clientDecoder=new Zl(bt(e)),this.leftClockDecoder=new kd(bt(e)),this.rightClockDecoder=new kd(bt(e)),this.infoDecoder=new K0(bt(e),gi),this.stringDecoder=new CA(bt(e)),this.parentInfoDecoder=new K0(bt(e),gi),this.typeRefDecoder=new Zl(bt(e)),this.lenDecoder=new Zl(bt(e))}readLeftID(){return new us(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new us(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return ns(this.restDecoder)}readBuf(){return bt(this.restDecoder)}readJSON(){return ns(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{const t=this.stringDecoder.read();return this.keys.push(t),t}}}class ky{constructor(){this.restEncoder=gt()}toUint8Array(){return qe(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){ae(this.restEncoder,e)}writeDsLen(e){ae(this.restEncoder,e)}}class Ao extends ky{writeLeftID(e){ae(this.restEncoder,e.client),ae(this.restEncoder,e.clock)}writeRightID(e){ae(this.restEncoder,e.client),ae(this.restEncoder,e.clock)}writeClient(e){ae(this.restEncoder,e)}writeInfo(e){So(this.restEncoder,e)}writeString(e){jn(this.restEncoder,e)}writeParentInfo(e){ae(this.restEncoder,e?1:0)}writeTypeRef(e){ae(this.restEncoder,e)}writeLen(e){ae(this.restEncoder,e)}writeAny(e){ts(this.restEncoder,e)}writeBuf(e){Xe(this.restEncoder,e)}writeJSON(e){jn(this.restEncoder,JSON.stringify(e))}writeKey(e){jn(this.restEncoder,e)}}class Sy{constructor(){this.restEncoder=gt(),this.dsCurrVal=0}toUint8Array(){return qe(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,ae(this.restEncoder,t)}writeDsLen(e){e===0&&cn(),ae(this.restEncoder,e-1),this.dsCurrVal+=e}}class bi extends Sy{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new wd,this.clientEncoder=new Gl,this.leftClockEncoder=new wd,this.rightClockEncoder=new wd,this.infoEncoder=new V0(So),this.stringEncoder=new bA,this.parentInfoEncoder=new V0(So),this.typeRefEncoder=new Gl,this.lenEncoder=new Gl}toUint8Array(){const e=gt();return ae(e,0),Xe(e,this.keyClockEncoder.toUint8Array()),Xe(e,this.clientEncoder.toUint8Array()),Xe(e,this.leftClockEncoder.toUint8Array()),Xe(e,this.rightClockEncoder.toUint8Array()),Xe(e,qe(this.infoEncoder)),Xe(e,this.stringEncoder.toUint8Array()),Xe(e,qe(this.parentInfoEncoder)),Xe(e,this.typeRefEncoder.toUint8Array()),Xe(e,this.lenEncoder.toUint8Array()),Jl(e,qe(this.restEncoder)),qe(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){ts(this.restEncoder,e)}writeBuf(e){Xe(this.restEncoder,e)}writeJSON(e){ts(this.restEncoder,e)}writeKey(e){const t=this.keyMap.get(e);t===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}}const cM=(n,e,t,r)=>{r=ar(r,e[0].id.clock);const i=zn(e,r);ae(n.restEncoder,e.length-i),n.writeClient(t),ae(n.restEncoder,r);const s=e[i];s.write(n,r-s.id.clock);for(let o=i+1;o<e.length;o++)e[o].write(n,0)},$d=(n,e,t)=>{const r=new Map;t.forEach((i,s)=>{rt(e,s)>i&&r.set(s,i)}),Do(e).forEach((i,s)=>{t.has(s)||r.set(s,0)}),ae(n.restEncoder,r.size),lr(r.entries()).sort((i,s)=>s[0]-i[0]).forEach(([i,s])=>{cM(n,e.clients.get(i),i,s)})},uM=(n,e)=>{const t=Lt(),r=he(n.restDecoder);for(let i=0;i<r;i++){const s=he(n.restDecoder),o=new Array(s),l=n.readClient();let a=he(n.restDecoder);t.set(l,{i:0,refs:o});for(let c=0;c<s;c++){const u=n.readInfo();switch(Kl&u){case 0:{const d=n.readLen();o[c]=new dn(pe(l,a),d),a+=d;break}case 10:{const d=he(n.restDecoder);o[c]=new fn(pe(l,a),d),a+=d;break}default:{const d=(u&(cr|Yt))===0,f=new ze(pe(l,a),null,(u&Yt)===Yt?n.readLeftID():null,null,(u&cr)===cr?n.readRightID():null,d?n.readParentInfo()?e.get(n.readString()):n.readLeftID():null,d&&(u&wo)===wo?n.readString():null,pb(n,u));o[c]=f,a+=f.length}}}}return t},dM=(n,e,t)=>{const r=[];let i=lr(t.keys()).sort((h,p)=>h-p);if(i.length===0)return null;const s=()=>{if(i.length===0)return null;let h=t.get(i[i.length-1]);for(;h.refs.length===h.i;)if(i.pop(),i.length>0)h=t.get(i[i.length-1]);else return null;return h};let o=s();if(o===null)return null;const l=new Ly,a=new Map,c=(h,p)=>{const g=a.get(h);(g==null||g>p)&&a.set(h,p)};let u=o.refs[o.i++];const d=new Map,f=()=>{for(const h of r){const p=h.id.client,g=t.get(p);g?(g.i--,l.clients.set(p,g.refs.slice(g.i)),t.delete(p),g.i=0,g.refs=[]):l.clients.set(p,[h]),i=i.filter(v=>v!==p)}r.length=0};for(;;){if(u.constructor!==fn){const p=zt(d,u.id.client,()=>rt(e,u.id.client))-u.id.clock;if(p<0)r.push(u),c(u.id.client,u.id.clock-1),f();else{const g=u.getMissing(n,e);if(g!==null){r.push(u);const v=t.get(g)||{refs:[],i:0};if(v.refs.length===v.i)c(g,rt(e,g)),f();else{u=v.refs[v.i++];continue}}else(p===0||p<u.length)&&(u.integrate(n,p),d.set(u.id.client,u.id.clock+u.length))}}if(r.length>0)u=r.pop();else if(o!==null&&o.i<o.refs.length)u=o.refs[o.i++];else{if(o=s(),o===null)break;u=o.refs[o.i++]}}if(l.clients.size>0){const h=new bi;return $d(h,l,new Map),ae(h.restEncoder,0),{missing:a,update:h.toUint8Array()}}return null},fM=(n,e)=>$d(n,e.doc.store,e.beforeState),hM=(n,e,t,r=new cs(n))=>Be(e,i=>{i.local=!1;let s=!1;const o=i.doc,l=o.store,a=uM(r,o),c=dM(i,l,a),u=l.pendingStructs;if(u){for(const[f,h]of u.missing)if(h<rt(l,f)){s=!0;break}if(c){for(const[f,h]of c.missing){const p=u.missing.get(f);(p==null||p>h)&&u.missing.set(f,h)}u.update=ra([u.update,c.update])}}else l.pendingStructs=c;const d=vy(r,i,l);if(l.pendingDs){const f=new cs(Hn(l.pendingDs));he(f.restDecoder);const h=vy(f,i,l);d&&h?l.pendingDs=ra([d,h]):l.pendingDs=d||h}else l.pendingDs=d;if(s){const f=l.pendingStructs.update;l.pendingStructs=null,Ey(i.doc,f)}},t,!1),Ey=(n,e,t,r=cs)=>{const i=Hn(e);hM(i,n,t,new r(i))},pM=(n,e,t)=>Ey(n,e,t,Cy),mM=(n,e,t=new Map)=>{$d(n,e.store,t),ls(n,by(e.store))},gM=(n,e=new Uint8Array([0]),t=new bi)=>{const r=Ty(e);mM(t,n,r);const i=[t.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(IM(n.store.pendingStructs.update,e)),i.length>1){if(t.constructor===Ao)return RM(i.map((s,o)=>o===0?s:FM(s)));if(t.constructor===bi)return ra(i)}return i[0]},yM=(n,e)=>gM(n,e,new Ao),bM=n=>{const e=new Map,t=he(n.restDecoder);for(let r=0;r<t;r++){const i=he(n.restDecoder),s=he(n.restDecoder);e.set(i,s)}return e},Ty=n=>bM(new xy(Hn(n))),Ay=(n,e)=>(ae(n.restEncoder,e.size),lr(e.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{ae(n.restEncoder,t),ae(n.restEncoder,r)}),n),vM=(n,e)=>Ay(n,Do(e.store)),wM=(n,e=new Sy)=>(n instanceof Map?Ay(e,n):vM(e,n),e.toUint8Array()),xM=n=>wM(n,new ky);class CM{constructor(){this.l=[]}}const My=()=>new CM,Oy=(n,e)=>n.l.push(e),_y=(n,e)=>{const t=n.l,r=t.length;n.l=t.filter(i=>e!==i),r===n.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Ny=(n,e,t)=>Td(n.l,[e,t]);class us{constructor(e,t){this.client=e,this.clock=t}}const ds=(n,e)=>n===e||n!==null&&e!==null&&n.client===e.client&&n.clock===e.clock,pe=(n,e)=>new us(n,e),Mo=n=>{for(const[e,t]of n.doc.share.entries())if(t===n)return e;throw cn()},Oo=(n,e)=>{for(;e!==null;){if(e.parent===n)return!0;e=e.parent._item}return!1};class _o{constructor(e,t,r,i=0){this.type=e,this.tname=t,this.item=r,this.assoc=i}}const No=n=>new _o(n.type==null?null:pe(n.type.client,n.type.clock),n.tname||null,n.item==null?null:pe(n.item.client,n.item.clock),n.assoc==null?0:n.assoc);class kM{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}}const SM=(n,e,t=0)=>new kM(n,e,t),ta=(n,e,t)=>{let r=null,i=null;return n._item===null?i=Mo(n):r=pe(n._item.id.client,n._item.id.clock),new _o(r,i,e,t)},jd=(n,e,t=0)=>{let r=n._start;if(t<0){if(e===0)return ta(n,null,t);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return ta(n,pe(r.id.client,r.id.clock+e),t);e-=r.length}if(r.right===null&&t<0)return ta(n,r.lastId,t);r=r.right}return ta(n,null,t)},EM=(n,e,t=!0)=>{const r=e.store,i=n.item,s=n.type,o=n.tname,l=n.assoc;let a=null,c=0;if(i!==null){if(rt(r,i.client)<=i.clock)return null;const u=t?ef(r,i):{item:fs(r,i),diff:0},d=u.item;if(!(d instanceof ze))return null;if(a=d.parent,a._item===null||!a._item.deleted){c=d.deleted||!d.countable?0:u.diff+(l>=0?0:1);let f=d.left;for(;f!==null;)!f.deleted&&f.countable&&(c+=f.length),f=f.left}}else{if(o!==null)a=e.get(o);else if(s!==null){if(rt(r,s.client)<=s.clock)return null;const{item:u}=t?ef(r,s):{item:fs(r,s)};if(u instanceof ze&&u.content instanceof kn)a=u.content.type;else return null}else throw cn();l>=0?c=a._length:c=0}return SM(a,c,n.assoc)},Dy=(n,e)=>n===e||n!==null&&e!==null&&n.tname===e.tname&&ds(n.item,e.item)&&ds(n.type,e.type)&&n.assoc===e.assoc;class Hd{constructor(e,t){this.ds=e,this.sv=t}}const Ry=(n,e)=>new Hd(n,e),TM=n=>Ry(by(n.store),Do(n.store)),vi=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&(e.sv.get(n.id.client)||0)>n.id.clock&&!ss(e.ds,n.id),Vd=(n,e)=>{const t=zt(n.meta,Vd,or),r=n.doc.store;t.has(e)||(e.sv.forEach((i,s)=>{i<rt(r,s)&&Ut(n,pe(s,i))}),Pr(n,e.ds,i=>{}),t.add(e))};class Ly{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Do=n=>{const e=new Map;return n.clients.forEach((t,r)=>{const i=t[t.length-1];e.set(r,i.id.clock+i.length)}),e},rt=(n,e)=>{const t=n.clients.get(e);if(t===void 0)return 0;const r=t[t.length-1];return r.id.clock+r.length},Iy=(n,e)=>{let t=n.clients.get(e.id.client);if(t===void 0)t=[],n.clients.set(e.id.client,t);else{const r=t[t.length-1];if(r.id.clock+r.length!==e.id.clock)throw cn()}t.push(e)},zn=(n,e)=>{let t=0,r=n.length-1,i=n[r],s=i.id.clock;if(s===e)return r;let o=wn(e/(s+i.length-1)*r);for(;t<=r;){if(i=n[o],s=i.id.clock,s<=e){if(e<s+i.length)return o;t=o+1}else r=o-1;o=wn((t+r)/2)}throw cn()},fs=(n,e)=>{const t=n.clients.get(e.client);return t[zn(t,e.clock)]},zd=(n,e,t)=>{const r=zn(e,t),i=e[r];return i.id.clock<t&&i instanceof ze?(e.splice(r+1,0,ha(n,i,t-i.id.clock)),r+1):r},Ut=(n,e)=>{const t=n.doc.store.clients.get(e.client);return t[zd(n,t,e.clock)]},Py=(n,e,t)=>{const r=e.clients.get(t.client),i=zn(r,t.clock),s=r[i];return t.clock!==s.id.clock+s.length-1&&s.constructor!==dn&&r.splice(i+1,0,ha(n,s,t.clock-s.id.clock+1)),s},AM=(n,e,t)=>{const r=n.clients.get(e.id.client);r[zn(r,e.id.clock)]=t},Fy=(n,e,t,r,i)=>{if(r===0)return;const s=t+r;let o=zd(n,e,t),l;do l=e[o++],s<l.id.clock+l.length&&zd(n,e,s),i(l);while(o<e.length&&e[o].id.clock<s)};class MM{constructor(e,t,r){this.doc=e,this.deleteSet=new is,this.beforeState=Do(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=r,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const By=(n,e)=>e.deleteSet.clients.size===0&&!WT(e.afterState,(t,r)=>e.beforeState.get(r)!==t)?!1:(Pd(e.deleteSet),fM(n,e),ls(n,e.deleteSet),!0),$y=(n,e,t)=>{const r=e._item;(r===null||r.id.clock<(n.beforeState.get(r.id.client)||0)&&!r.deleted)&&zt(n.changed,e,or).add(t)},na=(n,e)=>{let t=n[e],r=n[e-1],i=e;for(;i>0;t=r,r=n[--i-1]){if(r.deleted===t.deleted&&r.constructor===t.constructor&&r.mergeWith(t)){t instanceof ze&&t.parentSub!==null&&t.parent._map.get(t.parentSub)===t&&t.parent._map.set(t.parentSub,r);continue}break}const s=e-i;return s&&n.splice(e+1-s,s),s},OM=(n,e,t)=>{for(const[r,i]of n.clients.entries()){const s=e.clients.get(r);for(let o=i.length-1;o>=0;o--){const l=i[o],a=l.clock+l.len;for(let c=zn(s,l.clock),u=s[c];c<s.length&&u.id.clock<a;u=s[++c]){const d=s[c];if(l.clock+l.len<=d.id.clock)break;d instanceof ze&&d.deleted&&!d.keep&&t(d)&&d.gc(e,!1)}}}},_M=(n,e)=>{n.clients.forEach((t,r)=>{const i=e.clients.get(r);for(let s=t.length-1;s>=0;s--){const o=t[s],l=Ir(i.length-1,1+zn(i,o.clock+o.len-1));for(let a=l,c=i[a];a>0&&c.id.clock>=o.clock;c=i[a])a-=1+na(i,a)}})},jy=(n,e)=>{if(e<n.length){const t=n[e],r=t.doc,i=r.store,s=t.deleteSet,o=t._mergeStructs;try{Pd(s),t.afterState=Do(t.doc.store),r.emit("beforeObserverCalls",[t,r]);const l=[];t.changed.forEach((a,c)=>l.push(()=>{(c._item===null||!c._item.deleted)&&c._callObserver(t,a)})),l.push(()=>{t.changedParentTypes.forEach((a,c)=>{c._dEH.l.length>0&&(c._item===null||!c._item.deleted)&&(a=a.filter(u=>u.target._item===null||!u.target._item.deleted),a.forEach(u=>{u.currentTarget=c,u._path=null}),a.sort((u,d)=>u.path.length-d.path.length),Ny(c._dEH,a,t))})}),l.push(()=>r.emit("afterTransaction",[t,r])),Td(l,[]),t._needFormattingCleanup&&ZM(t)}finally{r.gc&&OM(s,i,r.gcFilter),_M(s,i),t.afterState.forEach((u,d)=>{const f=t.beforeState.get(d)||0;if(f!==u){const h=i.clients.get(d),p=ar(zn(h,f),1);for(let g=h.length-1;g>=p;)g-=1+na(h,g)}});for(let u=o.length-1;u>=0;u--){const{client:d,clock:f}=o[u].id,h=i.clients.get(d),p=zn(h,f);p+1<h.length&&na(h,p+1)>1||p>0&&na(h,p)}if(!t.local&&t.afterState.get(r.clientID)!==t.beforeState.get(r.clientID)&&(ay(Ql,un,"[yjs] ",yi,ry,"Changed the client-id because another client seems to be using it."),r.clientID=wy()),r.emit("afterTransactionCleanup",[t,r]),r._observers.has("update")){const u=new Ao;By(u,t)&&r.emit("update",[u.toUint8Array(),t.origin,r,t])}if(r._observers.has("updateV2")){const u=new bi;By(u,t)&&r.emit("updateV2",[u.toUint8Array(),t.origin,r,t])}const{subdocsAdded:l,subdocsLoaded:a,subdocsRemoved:c}=t;(l.size>0||c.size>0||a.size>0)&&(l.forEach(u=>{u.clientID=r.clientID,u.collectionid==null&&(u.collectionid=r.collectionid),r.subdocs.add(u)}),c.forEach(u=>r.subdocs.delete(u)),r.emit("subdocs",[{loaded:a,added:l,removed:c},r,t]),c.forEach(u=>u.destroy())),n.length<=e+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,n])):jy(n,e+1)}}},Be=(n,e,t=null,r=!0)=>{const i=n._transactionCleanups;let s=!1,o=null;n._transaction===null&&(s=!0,n._transaction=new MM(n,t,r),i.push(n._transaction),i.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{o=e(n._transaction)}finally{if(s){const l=n._transaction===i[0];n._transaction=null,l&&jy(i,0)}}return o};class NM{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}}const Hy=(n,e,t)=>{Pr(n,t.deletions,r=>{r instanceof ze&&e.scope.some(i=>Oo(i,r))&&tf(r,!1)})},Vy=(n,e,t)=>{let r=null;const i=n.doc,s=n.scope;if(Be(i,o=>{for(;e.length>0&&n.currStackItem===null;){const l=i.store,a=e.pop(),c=new Set,u=[];let d=!1;Pr(o,a.insertions,f=>{if(f instanceof ze){if(f.redone!==null){let{item:h,diff:p}=ef(l,f.id);p>0&&(h=Ut(o,pe(h.id.client,h.id.clock+p))),f=h}!f.deleted&&s.some(h=>Oo(h,f))&&u.push(f)}}),Pr(o,a.deletions,f=>{f instanceof ze&&s.some(h=>Oo(h,f))&&!ss(a.insertions,f.id)&&c.add(f)}),c.forEach(f=>{d=hb(o,f,c,a.insertions,n.ignoreRemoteMapChanges,n)!==null||d});for(let f=u.length-1;f>=0;f--){const h=u[f];n.deleteFilter(h)&&(h.delete(o),d=!0)}n.currStackItem=d?a:null}o.changed.forEach((l,a)=>{l.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),r=o},n),n.currStackItem!=null){const o=r.changedParentTypes;n.emit("stack-item-popped",[{stackItem:n.currStackItem,type:t,changedParentTypes:o,origin:n},n]),n.currStackItem=null}return n.currStackItem};class zy extends dd{constructor(e,{captureTimeout:t=500,captureTransaction:r=a=>!0,deleteFilter:i=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:l=ud(e)?e[0].doc:e.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(e),this.deleteFilter=i,s.add(this),this.trackedOrigins=s,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=t,this.afterTransactionHandler=a=>{if(!this.captureTransaction(a)||!this.scope.some(v=>a.changedParentTypes.has(v))||!this.trackedOrigins.has(a.origin)&&(!a.origin||!this.trackedOrigins.has(a.origin.constructor)))return;const c=this.undoing,u=this.redoing,d=c?this.redoStack:this.undoStack;c?this.stopCapturing():u||this.clear(!1,!0);const f=new is;a.afterState.forEach((v,w)=>{const S=a.beforeState.get(w)||0,x=v-S;x>0&&To(f,w,S,x)});const h=Bn();let p=!1;if(this.lastChange>0&&h-this.lastChange<this.captureTimeout&&d.length>0&&!c&&!u){const v=d[d.length-1];v.deletions=Fd([v.deletions,a.deleteSet]),v.insertions=Fd([v.insertions,f])}else d.push(new NM(a.deleteSet,f)),p=!0;!c&&!u&&(this.lastChange=h),Pr(a,a.deleteSet,v=>{v instanceof ze&&this.scope.some(w=>Oo(w,v))&&tf(v,!0)});const g=[{stackItem:d[d.length-1],origin:a.origin,type:c?"redo":"undo",changedParentTypes:a.changedParentTypes},this];p?this.emit("stack-item-added",g):this.emit("stack-item-updated",g)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(e){e=ud(e)?e:[e],e.forEach(t=>{this.scope.every(r=>r!==t)&&(t.doc!==this.doc&&WA("[yjs#509] Not same Y.Doc"),this.scope.push(t))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(r=>{e&&(this.undoStack.forEach(i=>Hy(r,this,i)),this.undoStack=[]),t&&(this.redoStack.forEach(i=>Hy(r,this,i)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=Vy(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Vy(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}}function*DM(n){const e=he(n.restDecoder);for(let t=0;t<e;t++){const r=he(n.restDecoder),i=n.readClient();let s=he(n.restDecoder);for(let o=0;o<r;o++){const l=n.readInfo();if(l===10){const a=he(n.restDecoder);yield new fn(pe(i,s),a),s+=a}else if(Kl&l){const a=(l&(cr|Yt))===0,c=new ze(pe(i,s),null,(l&Yt)===Yt?n.readLeftID():null,null,(l&cr)===cr?n.readRightID():null,a?n.readParentInfo()?n.readString():n.readLeftID():null,a&&(l&wo)===wo?n.readString():null,pb(n,l));yield c,s+=c.length}else{const a=n.readLen();yield new dn(pe(i,s),a),s+=a}}}}class Ud{constructor(e,t){this.gen=DM(e),this.curr=null,this.done=!1,this.filterSkips=t,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===fn);return this.curr}}class Wd{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}}const RM=n=>ra(n,Cy,Ao),LM=(n,e)=>{if(n.constructor===dn){const{client:t,clock:r}=n.id;return new dn(pe(t,r+e),n.length-e)}else if(n.constructor===fn){const{client:t,clock:r}=n.id;return new fn(pe(t,r+e),n.length-e)}else{const t=n,{client:r,clock:i}=t.id;return new ze(pe(r,i+e),null,pe(r,i+e-1),null,t.rightOrigin,t.parent,t.parentSub,t.content.splice(e))}},ra=(n,e=cs,t=bi)=>{if(n.length===1)return n[0];const r=n.map(u=>new e(Hn(u)));let i=r.map(u=>new Ud(u,!0)),s=null;const o=new t,l=new Wd(o);for(;i=i.filter(f=>f.curr!==null),i.sort((f,h)=>{if(f.curr.id.client===h.curr.id.client){const p=f.curr.id.clock-h.curr.id.clock;return p===0?f.curr.constructor===h.curr.constructor?0:f.curr.constructor===fn?1:-1:p}else return h.curr.id.client-f.curr.id.client}),i.length!==0;){const u=i[0],d=u.curr.id.client;if(s!==null){let f=u.curr,h=!1;for(;f!==null&&f.id.clock+f.length<=s.struct.id.clock+s.struct.length&&f.id.client>=s.struct.id.client;)f=u.next(),h=!0;if(f===null||f.id.client!==d||h&&f.id.clock>s.struct.id.clock+s.struct.length)continue;if(d!==s.struct.id.client)Fr(l,s.struct,s.offset),s={struct:f,offset:0},u.next();else if(s.struct.id.clock+s.struct.length<f.id.clock)if(s.struct.constructor===fn)s.struct.length=f.id.clock+f.length-s.struct.id.clock;else{Fr(l,s.struct,s.offset);const p=f.id.clock-s.struct.id.clock-s.struct.length;s={struct:new fn(pe(d,s.struct.id.clock+s.struct.length),p),offset:0}}else{const p=s.struct.id.clock+s.struct.length-f.id.clock;p>0&&(s.struct.constructor===fn?s.struct.length-=p:f=LM(f,p)),s.struct.mergeWith(f)||(Fr(l,s.struct,s.offset),s={struct:f,offset:0},u.next())}}else s={struct:u.curr,offset:0},u.next();for(let f=u.curr;f!==null&&f.id.client===d&&f.id.clock===s.struct.id.clock+s.struct.length&&f.constructor!==fn;f=u.next())Fr(l,s.struct,s.offset),s={struct:f,offset:0}}s!==null&&(Fr(l,s.struct,s.offset),s=null),qd(l);const a=r.map(u=>Bd(u)),c=Fd(a);return ls(o,c),o.toUint8Array()},IM=(n,e,t=cs,r=bi)=>{const i=Ty(e),s=new r,o=new Wd(s),l=new t(Hn(n)),a=new Ud(l,!1);for(;a.curr;){const u=a.curr,d=u.id.client,f=i.get(d)||0;if(a.curr.constructor===fn){a.next();continue}if(u.id.clock+u.length>f)for(Fr(o,u,ar(f-u.id.clock,0)),a.next();a.curr&&a.curr.id.client===d;)Fr(o,a.curr,0),a.next();else for(;a.curr&&a.curr.id.client===d&&a.curr.id.clock+a.curr.length<=f;)a.next()}qd(o);const c=Bd(l);return ls(s,c),s.toUint8Array()},Uy=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:qe(n.encoder.restEncoder)}),n.encoder.restEncoder=gt(),n.written=0)},Fr=(n,e,t)=>{n.written>0&&n.currClient!==e.id.client&&Uy(n),n.written===0&&(n.currClient=e.id.client,n.encoder.writeClient(e.id.client),ae(n.encoder.restEncoder,e.id.clock+t)),e.write(n.encoder,t),n.written++},qd=n=>{Uy(n);const e=n.encoder.restEncoder;ae(e,n.clientStructs.length);for(let t=0;t<n.clientStructs.length;t++){const r=n.clientStructs[t];ae(e,r.written),Jl(e,r.restEncoder)}},PM=(n,e,t,r)=>{const i=new t(Hn(n)),s=new Ud(i,!1),o=new r,l=new Wd(o);for(let c=s.curr;c!==null;c=s.next())Fr(l,e(c),0);qd(l);const a=Bd(i);return ls(o,a),o.toUint8Array()},FM=n=>PM(n,DA,cs,Ao),Wy="You must not compute changes after the event-handler fired.";class ia{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=BM(this.currentTarget,this.target))}deletes(e){return ss(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw $n(Wy);const e=new Map,t=this.target;this.transaction.changed.get(t).forEach(i=>{if(i!==null){const s=t._map.get(i);let o,l;if(this.adds(s)){let a=s.left;for(;a!==null&&this.adds(a);)a=a.left;if(this.deletes(s))if(a!==null&&this.deletes(a))o="delete",l=cd(a.content.getContent());else return;else a!==null&&this.deletes(a)?(o="update",l=cd(a.content.getContent())):(o="add",l=void 0)}else if(this.deletes(s))o="delete",l=cd(s.content.getContent());else return;e.set(i,{action:o,oldValue:l})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw $n(Wy);const t=this.target,r=or(),i=or(),s=[];if(e={added:r,deleted:i,delta:s,keys:this.keys},this.transaction.changed.get(t).has(null)){let l=null;const a=()=>{l&&s.push(l)};for(let c=t._start;c!==null;c=c.right)c.deleted?this.deletes(c)&&!this.adds(c)&&((l===null||l.delete===void 0)&&(a(),l={delete:0}),l.delete+=c.length,i.add(c)):this.adds(c)?((l===null||l.insert===void 0)&&(a(),l={insert:[]}),l.insert=l.insert.concat(c.content.getContent()),r.add(c)):((l===null||l.retain===void 0)&&(a(),l={retain:0}),l.retain+=c.length);l!==null&&l.retain===void 0&&a()}this._changes=e}return e}}const BM=(n,e)=>{const t=[];for(;e._item!==null&&e!==n;){if(e._item.parentSub!==null)t.unshift(e._item.parentSub);else{let r=0,i=e._item.parent._start;for(;i!==e._item&&i!==null;)i.deleted||r++,i=i.right;t.unshift(r)}e=e._item.parent}return t},qy=80;let Kd=0;class $M{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Kd++}}const jM=n=>{n.timestamp=Kd++},Ky=(n,e,t)=>{n.p.marker=!1,n.p=e,e.marker=!0,n.index=t,n.timestamp=Kd++},HM=(n,e,t)=>{if(n.length>=qy){const r=n.reduce((i,s)=>i.timestamp<s.timestamp?i:s);return Ky(r,e,t),r}else{const r=new $M(e,t);return n.push(r),r}},sa=(n,e)=>{if(n._start===null||e===0||n._searchMarker===null)return null;const t=n._searchMarker.length===0?null:n._searchMarker.reduce((s,o)=>Wl(e-s.index)<Wl(e-o.index)?s:o);let r=n._start,i=0;for(t!==null&&(r=t.p,i=t.index,jM(t));r.right!==null&&i<e;){if(!r.deleted&&r.countable){if(e<i+r.length)break;i+=r.length}r=r.right}for(;r.left!==null&&i>e;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return t!==null&&Wl(t.index-i)<r.parent.length/qy?(Ky(t,r,i),t):HM(n._searchMarker,r,i)},Ro=(n,e,t)=>{for(let r=n.length-1;r>=0;r--){const i=n[r];if(t>0){let s=i.p;for(s.marker=!1;s&&(s.deleted||!s.countable);)s=s.left,s&&!s.deleted&&s.countable&&(i.index-=s.length);if(s===null||s.marker===!0){n.splice(r,1);continue}i.p=s,s.marker=!0}(e<i.index||t>0&&e===i.index)&&(i.index=ar(e,i.index+t))}},oa=(n,e,t)=>{const r=n,i=e.changedParentTypes;for(;zt(i,n,()=>[]).push(t),n._item!==null;)n=n._item.parent;Ny(r._eH,t,e)};class Et{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=My(),this._dEH=My(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw xn()}clone(){throw xn()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){Oy(this._eH,e)}observeDeep(e){Oy(this._dEH,e)}unobserve(e){_y(this._eH,e)}unobserveDeep(e){_y(this._dEH,e)}toJSON(){}}const Jy=(n,e,t)=>{e<0&&(e=n._length+e),t<0&&(t=n._length+t);let r=t-e;const i=[];let s=n._start;for(;s!==null&&r>0;){if(s.countable&&!s.deleted){const o=s.content.getContent();if(o.length<=e)e-=o.length;else{for(let l=e;l<o.length&&r>0;l++)i.push(o[l]),r--;e=0}}s=s.right}return i},Gy=n=>{const e=[];let t=n._start;for(;t!==null;){if(t.countable&&!t.deleted){const r=t.content.getContent();for(let i=0;i<r.length;i++)e.push(r[i])}t=t.right}return e},Yy=(n,e)=>{const t=[];let r=n._start;for(;r!==null;){if(r.countable&&vi(r,e)){const i=r.content.getContent();for(let s=0;s<i.length;s++)t.push(i[s])}r=r.right}return t},Lo=(n,e)=>{let t=0,r=n._start;for(;r!==null;){if(r.countable&&!r.deleted){const i=r.content.getContent();for(let s=0;s<i.length;s++)e(i[s],t++,n)}r=r.right}},Zy=(n,e)=>{const t=[];return Lo(n,(r,i)=>{t.push(e(r,i,n))}),t},VM=n=>{let e=n._start,t=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(t===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};t=e.content.getContent(),r=0,e=e.right}const i=t[r++];return t.length<=r&&(t=null),{done:!1,value:i}}}},Xy=(n,e)=>{const t=sa(n,e);let r=n._start;for(t!==null&&(r=t.p,e-=t.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(e<r.length)return r.content.getContent()[e];e-=r.length}},la=(n,e,t,r)=>{let i=t;const s=n.doc,o=s.clientID,l=s.store,a=t===null?e._start:t.right;let c=[];const u=()=>{c.length>0&&(i=new ze(pe(o,rt(l,o)),i,i&&i.lastId,a,a&&a.id,e,null,new ki(c)),i.integrate(n,0),c=[])};r.forEach(d=>{if(d===null)c.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:c.push(d);break;default:switch(u(),d.constructor){case Uint8Array:case ArrayBuffer:i=new ze(pe(o,rt(l,o)),i,i&&i.lastId,a,a&&a.id,e,null,new Io(new Uint8Array(d))),i.integrate(n,0);break;case as:i=new ze(pe(o,rt(l,o)),i,i&&i.lastId,a,a&&a.id,e,null,new Fo(d)),i.integrate(n,0);break;default:if(d instanceof Et)i=new ze(pe(o,rt(l,o)),i,i&&i.lastId,a,a&&a.id,e,null,new kn(d)),i.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),u()},Qy=()=>$n("Length exceeded!"),eb=(n,e,t,r)=>{if(t>e._length)throw Qy();if(t===0)return e._searchMarker&&Ro(e._searchMarker,t,r.length),la(n,e,null,r);const i=t,s=sa(e,t);let o=e._start;for(s!==null&&(o=s.p,t-=s.index,t===0&&(o=o.prev,t+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(t<=o.length){t<o.length&&Ut(n,pe(o.id.client,o.id.clock+t));break}t-=o.length}return e._searchMarker&&Ro(e._searchMarker,i,r.length),la(n,e,o,r)},zM=(n,e,t)=>{let i=(e._searchMarker||[]).reduce((s,o)=>o.index>s.index?o:s,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return la(n,e,i,t)},tb=(n,e,t,r)=>{if(r===0)return;const i=t,s=r,o=sa(e,t);let l=e._start;for(o!==null&&(l=o.p,t-=o.index);l!==null&&t>0;l=l.right)!l.deleted&&l.countable&&(t<l.length&&Ut(n,pe(l.id.client,l.id.clock+t)),t-=l.length);for(;r>0&&l!==null;)l.deleted||(r<l.length&&Ut(n,pe(l.id.client,l.id.clock+r)),l.delete(n),r-=l.length),l=l.right;if(r>0)throw Qy();e._searchMarker&&Ro(e._searchMarker,i,-s+r)},aa=(n,e,t)=>{const r=e._map.get(t);r!==void 0&&r.delete(n)},Jd=(n,e,t,r)=>{const i=e._map.get(t)||null,s=n.doc,o=s.clientID;let l;if(r==null)l=new ki([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:l=new ki([r]);break;case Uint8Array:l=new Io(r);break;case as:l=new Fo(r);break;default:if(r instanceof Et)l=new kn(r);else throw new Error("Unexpected content type")}new ze(pe(o,rt(s.store,o)),i,i&&i.lastId,null,null,e,t,l).integrate(n,0)},Gd=(n,e)=>{const t=n._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},nb=n=>{const e={};return n._map.forEach((t,r)=>{t.deleted||(e[r]=t.content.getContent()[t.length-1])}),e},rb=(n,e)=>{const t=n._map.get(e);return t!==void 0&&!t.deleted},UM=(n,e)=>{const t={};return n._map.forEach((r,i)=>{let s=r;for(;s!==null&&(!e.sv.has(s.id.client)||s.id.clock>=(e.sv.get(s.id.client)||0));)s=s.left;s!==null&&vi(s,e)&&(t[i]=s.content.getContent()[s.length-1])}),t},ca=n=>oM(n.entries(),e=>!e[1].deleted);class WM extends ia{constructor(e,t){super(e,t),this._transaction=t}}class hs extends Et{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const t=new hs;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new hs}clone(){const e=new hs;return e.insert(0,this.toArray().map(t=>t instanceof Et?t.clone():t)),e}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}_callObserver(e,t){super._callObserver(e,t),oa(this,e,new WM(this,e))}insert(e,t){this.doc!==null?Be(this.doc,r=>{eb(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?Be(this.doc,t=>{zM(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?Be(this.doc,r=>{tb(r,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return Xy(this,e)}toArray(){return Gy(this)}slice(e=0,t=this.length){return Jy(this,e,t)}toJSON(){return this.map(e=>e instanceof Et?e.toJSON():e)}map(e){return Zy(this,e)}forEach(e){Lo(this,e)}[Symbol.iterator](){return VM(this)}_write(e){e.writeTypeRef(mO)}}const qM=n=>new hs;class KM extends ia{constructor(e,t,r){super(e,t),this.keysChanged=r}}class ps extends Et{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((r,i)=>{this.set(i,r)}),this._prelimContent=null}_copy(){return new ps}clone(){const e=new ps;return this.forEach((t,r)=>{e.set(r,t instanceof Et?t.clone():t)}),e}_callObserver(e,t){oa(this,e,new KM(this,e,t))}toJSON(){const e={};return this._map.forEach((t,r)=>{if(!t.deleted){const i=t.content.getContent()[t.length-1];e[r]=i instanceof Et?i.toJSON():i}}),e}get size(){return[...ca(this._map)].length}keys(){return Ld(ca(this._map),e=>e[0])}values(){return Ld(ca(this._map),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Ld(ca(this._map),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this._map.forEach((t,r)=>{t.deleted||e(t.content.getContent()[t.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?Be(this.doc,t=>{aa(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?Be(this.doc,r=>{Jd(r,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Gd(this,e)}has(e){return rb(this,e)}clear(){this.doc!==null?Be(this.doc,e=>{this.forEach(function(t,r,i){aa(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(gO)}}const JM=n=>new ps,Br=(n,e)=>n===e||typeof n=="object"&&typeof e=="object"&&n&&e&&_A(n,e);class Yd{constructor(e,t,r,i){this.left=e,this.right=t,this.index=r,this.currentAttributes=i}forward(){switch(this.right===null&&cn(),this.right.content.constructor){case lt:this.right.deleted||ms(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}}const ib=(n,e,t)=>{for(;e.right!==null&&t>0;){switch(e.right.content.constructor){case lt:e.right.deleted||ms(e.currentAttributes,e.right.content);break;default:e.right.deleted||(t<e.right.length&&Ut(n,pe(e.right.id.client,e.right.id.clock+t)),e.index+=e.right.length,t-=e.right.length);break}e.left=e.right,e.right=e.right.right}return e},ua=(n,e,t,r)=>{const i=new Map,s=r?sa(e,t):null;if(s){const o=new Yd(s.p.left,s.p,s.index,i);return ib(n,o,t-s.index)}else{const o=new Yd(null,e._start,0,i);return ib(n,o,t)}},sb=(n,e,t,r)=>{for(;t.right!==null&&(t.right.deleted===!0||t.right.content.constructor===lt&&Br(r.get(t.right.content.key),t.right.content.value));)t.right.deleted||r.delete(t.right.content.key),t.forward();const i=n.doc,s=i.clientID;r.forEach((o,l)=>{const a=t.left,c=t.right,u=new ze(pe(s,rt(i.store,s)),a,a&&a.lastId,c,c&&c.id,e,null,new lt(l,o));u.integrate(n,0),t.right=u,t.forward()})},ms=(n,e)=>{const{key:t,value:r}=e;r===null?n.delete(t):n.set(t,r)},ob=(n,e)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===lt&&Br(e[n.right.content.key]??null,n.right.content.value)))break;n.forward()}},lb=(n,e,t,r)=>{const i=n.doc,s=i.clientID,o=new Map;for(const l in r){const a=r[l],c=t.currentAttributes.get(l)??null;if(!Br(c,a)){o.set(l,c);const{left:u,right:d}=t;t.right=new ze(pe(s,rt(i.store,s)),u,u&&u.lastId,d,d&&d.id,e,null,new lt(l,a)),t.right.integrate(n,0),t.forward()}}return o},Zd=(n,e,t,r,i)=>{t.currentAttributes.forEach((f,h)=>{i[h]===void 0&&(i[h]=null)});const s=n.doc,o=s.clientID;ob(t,i);const l=lb(n,e,t,i),a=r.constructor===String?new Cn(r):r instanceof Et?new kn(r):new Ci(r);let{left:c,right:u,index:d}=t;e._searchMarker&&Ro(e._searchMarker,t.index,a.getLength()),u=new ze(pe(o,rt(s.store,o)),c,c&&c.lastId,u,u&&u.id,e,null,a),u.integrate(n,0),t.right=u,t.index=d,t.forward(),sb(n,e,t,l)},ab=(n,e,t,r,i)=>{const s=n.doc,o=s.clientID;ob(t,i);const l=lb(n,e,t,i);e:for(;t.right!==null&&(r>0||l.size>0&&(t.right.deleted||t.right.content.constructor===lt));){if(!t.right.deleted)switch(t.right.content.constructor){case lt:{const{key:a,value:c}=t.right.content,u=i[a];if(u!==void 0){if(Br(u,c))l.delete(a);else{if(r===0)break e;l.set(a,c)}t.right.delete(n)}else t.currentAttributes.set(a,c);break}default:r<t.right.length&&Ut(n,pe(t.right.id.client,t.right.id.clock+r)),r-=t.right.length;break}t.forward()}if(r>0){let a="";for(;r>0;r--)a+=`
|
322
|
+
*/const h0=Me("Youtube",[["path",{d:"M2.5 17a24.12 24.12 0 0 1 0-10 2 2 0 0 1 1.4-1.4 49.56 49.56 0 0 1 16.2 0A2 2 0 0 1 21.5 7a24.12 24.12 0 0 1 0 10 2 2 0 0 1-1.4 1.4 49.55 49.55 0 0 1-16.2 0A2 2 0 0 1 2.5 17",key:"1q2vi4"}],["path",{d:"m10 15 5-3-5-3z",key:"1jp15x"}]]),uT=({editor:n,isOpen:e,setIsOpen:t})=>{const r=[{name:"Text",icon:d0,command:()=>n.chain().focus().toggleNode("paragraph","paragraph").run(),isActive:()=>n.isActive("paragraph")&&!n.isActive("bulletList")&&!n.isActive("orderedList")},{name:"Heading 1",icon:o0,command:()=>n.chain().focus().toggleHeading({level:1}).run(),isActive:()=>n.isActive("heading",{level:1})},{name:"Heading 2",icon:l0,command:()=>n.chain().focus().toggleHeading({level:2}).run(),isActive:()=>n.isActive("heading",{level:2})},{name:"Heading 3",icon:a0,command:()=>n.chain().focus().toggleHeading({level:3}).run(),isActive:()=>n.isActive("heading",{level:3})},{name:"To-do List",icon:c0,command:()=>n.chain().focus().toggleTaskList().run(),isActive:()=>n.isActive("taskItem")},{name:"Bullet List",icon:sd,command:()=>n.chain().focus().toggleBulletList().run(),isActive:()=>n.isActive("bulletList")},{name:"Numbered List",icon:sd,command:()=>n.chain().focus().toggleOrderedList().run(),isActive:()=>n.isActive("orderedList")},{name:"Quote",icon:u0,command:()=>n.chain().focus().toggleNode("paragraph","paragraph").toggleBlockquote().run(),isActive:()=>n.isActive("blockquote")},{name:"Code",icon:i0,command:()=>n.chain().focus().toggleCode().run(),isActive:()=>n.isActive("code")}],i=r.filter(s=>s.isActive()).pop()??{name:"Multiple"};return D.jsxs("div",{className:"relative h-full",children:[D.jsxs("button",{className:"flex h-full items-center gap-1 p-2 text-sm font-medium text-stone-600 hover:bg-stone-100 active:bg-stone-200",onClick:()=>t(!e),children:[D.jsx("span",{children:i==null?void 0:i.name}),D.jsx(id,{className:"h-4 w-4"})]}),e&&D.jsx("section",{className:"fixed top-full z-[99999] mt-1 flex w-48 flex-col overflow-hidden rounded border border-stone-200 bg-white p-1 shadow-xl animate-in fade-in slide-in-from-top-1",children:r.map((s,o)=>D.jsxs("button",{onClick:()=>{s.command(),t(!1)},className:Fe("flex items-center justify-between rounded-sm px-2 py-1 text-sm text-stone-600 hover:bg-stone-100",{"text-blue-600":s.isActive()}),children:[D.jsxs("div",{className:"flex items-center space-x-2",children:[D.jsx("div",{className:"rounded-sm border border-stone-200 p-1",children:D.jsx(s.icon,{className:"h-3 w-3"})}),D.jsx("span",{children:s.name})]}),i.name===s.name&&D.jsx(Bl,{className:"h-4 w-4"})]},o))})]})},dT=({editor:n,isOpen:e,setIsOpen:t})=>{const r=[{name:"Default",color:"#000000"},{name:"Purple",color:"#9333EA"},{name:"Red",color:"#E00000"},{name:"Blue",color:"#2563EB"},{name:"Green",color:"#008A00"},{name:"Orange",color:"#FFA500"},{name:"Pink",color:"#BA4081"},{name:"Gray",color:"#A8A29E"}],i=r.find(({color:s})=>n.isActive("textStyle",{color:s}));return D.jsxs("div",{className:"",children:[D.jsxs("button",{className:"flex h-[100%] items-center gap-1 p-2 text-sm font-medium text-stone-600 hover:bg-stone-100 active:bg-stone-200",onClick:()=>t(!e),children:[D.jsx("span",{style:{color:(i==null?void 0:i.color)||"#000000"},children:"A"}),D.jsx(id,{className:"h-4 w-4 "})]}),e&&D.jsx("section",{className:"fixed top-full z-[99999] mt-1 flex w-48 flex-col overflow-hidden rounded border border-stone-200 bg-white p-1 shadow-xl animate-in fade-in slide-in-from-top-1",children:r.map(({name:s,color:o},l)=>D.jsxs("button",{onClick:()=>{n.chain().focus().setColor(o).run(),t(!1)},className:Fe("flex items-center justify-between rounded-sm px-2 py-1 text-sm text-stone-600 hover:bg-stone-100",{"text-blue-600":n.isActive("textStyle",{color:o})}),children:[D.jsxs("div",{className:"flex items-center space-x-2",children:[D.jsx("div",{className:"rounded-sm border border-stone-200 px-1 py-px font-medium",style:{color:o},children:"A"}),D.jsx("span",{children:s})]}),n.isActive("textStyle",{color:o})&&D.jsx(Bl,{className:"h-4 w-4"})]},l))})]})};var Te=(n=>(n[n.NONE=0]="NONE",n[n.HEADING=1]="HEADING",n[n.TEXT_COLOR=2]="TEXT_COLOR",n[n.HIGHLIGHT=3]="HIGHLIGHT",n[n.LINK=4]="LINK",n[n.FONT_FAMILY=5]="FONT_FAMILY",n[n.ALIGNMENT=6]="ALIGNMENT",n[n.LIST=7]="LIST",n))(Te||{});function fT(n){const[e,t]=O.useState(n),r=O.useRef(null),i=s=>{r&&r.current&&!r.current.contains(s.target)&&t(0)};return O.useEffect(()=>(document.addEventListener("click",i,!0),()=>{document.removeEventListener("click",i,!0)}),[]),{ref:r,toolVisibilty:e,setToolVisibility:t}}const hT="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cmask%20id='mask0_349_446'%20style='mask-type:alpha'%20maskUnits='userSpaceOnUse'%20x='0'%20y='0'%20width='24'%20height='24'%3e%3crect%20width='24'%20height='24'%20fill='%23D9D9D9'/%3e%3c/mask%3e%3cg%20mask='url(%23mask0_349_446)'%3e%3cpath%20d='M5.55%2019L2%2015.45L3.4%2014.05L5.525%2016.175L9.775%2011.925L11.175%2013.35L5.55%2019ZM5.55%2011L2%207.45005L3.4%206.05005L5.525%208.17505L9.775%203.92505L11.175%205.35005L5.55%2011ZM13%2017V15H22V17H13ZM13%209.00005V7.00005H22V9.00005H13Z'%20fill='%231C1B1F'/%3e%3c/g%3e%3c/svg%3e",pT="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cmask%20id='mask0_337_2594'%20style='mask-type:alpha'%20maskUnits='userSpaceOnUse'%20x='0'%20y='0'%20width='24'%20height='24'%3e%3crect%20width='24'%20height='24'%20fill='%23D9D9D9'/%3e%3c/mask%3e%3cg%20mask='url(%23mask0_337_2594)'%3e%3cpath%20d='M3.9751%2017L7.7251%207H9.5251L13.2751%2017H11.5501L10.6501%2014.45H6.6001L5.7001%2017H3.9751ZM7.1251%2013H10.1251L8.6751%208.85H8.5751L7.1251%2013ZM16.3501%2017.275C15.5334%2017.275%2014.8918%2017.0625%2014.4251%2016.6375C13.9584%2016.2125%2013.7251%2015.6333%2013.7251%2014.9C13.7251%2014.2%2013.9959%2013.6292%2014.5376%2013.1875C15.0793%2012.7458%2015.7751%2012.525%2016.6251%2012.525C17.0084%2012.525%2017.3626%2012.5542%2017.6876%2012.6125C18.0126%2012.6708%2018.2918%2012.7667%2018.5251%2012.9V12.55C18.5251%2012.1%2018.3709%2011.7417%2018.0626%2011.475C17.7543%2011.2083%2017.3334%2011.075%2016.8001%2011.075C16.4501%2011.075%2016.1209%2011.15%2015.8126%2011.3C15.5043%2011.45%2015.2418%2011.6667%2015.0251%2011.95L13.9501%2011.15C14.2668%2010.7%2014.6668%2010.3583%2015.1501%2010.125C15.6334%209.89167%2016.1918%209.775%2016.8251%209.775C17.8584%209.775%2018.6501%2010.0208%2019.2001%2010.5125C19.7501%2011.0042%2020.0251%2011.7167%2020.0251%2012.65V17.05H18.5501V16.2H18.4751C18.2584%2016.5333%2017.9668%2016.7958%2017.6001%2016.9875C17.2334%2017.1792%2016.8168%2017.275%2016.3501%2017.275ZM16.6001%2016.025C17.1334%2016.025%2017.5876%2015.8375%2017.9626%2015.4625C18.3376%2015.0875%2018.5251%2014.6333%2018.5251%2014.1C18.2918%2013.9667%2018.0251%2013.8667%2017.7251%2013.8C17.4251%2013.7333%2017.1501%2013.7%2016.9001%2013.7C16.3668%2013.7%2015.9584%2013.8042%2015.6751%2014.0125C15.3918%2014.2208%2015.2501%2014.5167%2015.2501%2014.9C15.2501%2015.2333%2015.3751%2015.5042%2015.6251%2015.7125C15.8751%2015.9208%2016.2001%2016.025%2016.6001%2016.025Z'%20fill='%231C1B1F'/%3e%3c/g%3e%3c/svg%3e",p0="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cmask%20id='mask0_224_2464'%20style='mask-type:alpha'%20maskUnits='userSpaceOnUse'%20x='0'%20y='0'%20width='24'%20height='24'%3e%3crect%20width='24'%20height='24'%20fill='%23D9D9D9'/%3e%3c/mask%3e%3cg%20mask='url(%23mask0_224_2464)'%3e%3cpath%20d='M3%2021V19H21V21H3ZM7%2017V15H17V17H7ZM3%2013V11H21V13H3ZM7%209V7H17V9H7ZM3%205V3H21V5H3Z'%20fill='%231C1B1F'/%3e%3c/g%3e%3c/svg%3e",od="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cmask%20id='mask0_337_2575'%20style='mask-type:alpha'%20maskUnits='userSpaceOnUse'%20x='0'%20y='0'%20width='24'%20height='24'%3e%3crect%20width='24'%20height='24'%20fill='%23D9D9D9'/%3e%3c/mask%3e%3cg%20mask='url(%23mask0_337_2575)'%3e%3cpath%20d='M3%2021V19H21V21H3ZM3%2017V15H15V17H3ZM3%2013V11H21V13H3ZM3%209V7H15V9H3ZM3%205V3H21V5H3Z'%20fill='%231C1B1F'/%3e%3c/g%3e%3c/svg%3e",m0="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cmask%20id='mask0_224_2470'%20style='mask-type:alpha'%20maskUnits='userSpaceOnUse'%20x='0'%20y='0'%20width='24'%20height='24'%3e%3crect%20width='24'%20height='24'%20fill='%23D9D9D9'/%3e%3c/mask%3e%3cg%20mask='url(%23mask0_224_2470)'%3e%3cpath%20d='M3%205V3H21V5H3ZM9%209V7H21V9H9ZM3%2013V11H21V13H3ZM9%2017V15H21V17H9ZM3%2021V19H21V21H3Z'%20fill='%231C1B1F'/%3e%3c/g%3e%3c/svg%3e",g0="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cmask%20id='mask0_337_2572'%20style='mask-type:alpha'%20maskUnits='userSpaceOnUse'%20x='0'%20y='0'%20width='24'%20height='24'%3e%3crect%20width='24'%20height='24'%20fill='%23D9D9D9'/%3e%3c/mask%3e%3cg%20mask='url(%23mask0_337_2572)'%3e%3cpath%20d='M9%2019V17H21V19H9ZM9%2013V11H21V13H9ZM9%207V5H21V7H9ZM5%2020C4.45%2020%203.97917%2019.8042%203.5875%2019.4125C3.19583%2019.0208%203%2018.55%203%2018C3%2017.45%203.19583%2016.9792%203.5875%2016.5875C3.97917%2016.1958%204.45%2016%205%2016C5.55%2016%206.02083%2016.1958%206.4125%2016.5875C6.80417%2016.9792%207%2017.45%207%2018C7%2018.55%206.80417%2019.0208%206.4125%2019.4125C6.02083%2019.8042%205.55%2020%205%2020ZM5%2014C4.45%2014%203.97917%2013.8042%203.5875%2013.4125C3.19583%2013.0208%203%2012.55%203%2012C3%2011.45%203.19583%2010.9792%203.5875%2010.5875C3.97917%2010.1958%204.45%2010%205%2010C5.55%2010%206.02083%2010.1958%206.4125%2010.5875C6.80417%2010.9792%207%2011.45%207%2012C7%2012.55%206.80417%2013.0208%206.4125%2013.4125C6.02083%2013.8042%205.55%2014%205%2014ZM5%208C4.45%208%203.97917%207.80417%203.5875%207.4125C3.19583%207.02083%203%206.55%203%206C3%205.45%203.19583%204.97917%203.5875%204.5875C3.97917%204.19583%204.45%204%205%204C5.55%204%206.02083%204.19583%206.4125%204.5875C6.80417%204.97917%207%205.45%207%206C7%206.55%206.80417%207.02083%206.4125%207.4125C6.02083%207.80417%205.55%208%205%208Z'%20fill='%231C1B1F'/%3e%3c/g%3e%3c/svg%3e",mT="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cmask%20id='mask0_349_458'%20style='mask-type:alpha'%20maskUnits='userSpaceOnUse'%20x='0'%20y='0'%20width='24'%20height='24'%3e%3crect%20width='24'%20height='24'%20fill='%23D9D9D9'/%3e%3c/mask%3e%3cg%20mask='url(%23mask0_349_458)'%3e%3cpath%20d='M3%2022V20.5H5.5V19.75H4V18.25H5.5V17.5H3V16H6C6.28333%2016%206.52083%2016.0958%206.7125%2016.2875C6.90417%2016.4792%207%2016.7167%207%2017V18C7%2018.2833%206.90417%2018.5208%206.7125%2018.7125C6.52083%2018.9042%206.28333%2019%206%2019C6.28333%2019%206.52083%2019.0958%206.7125%2019.2875C6.90417%2019.4792%207%2019.7167%207%2020V21C7%2021.2833%206.90417%2021.5208%206.7125%2021.7125C6.52083%2021.9042%206.28333%2022%206%2022H3ZM3%2015V12.25C3%2011.9667%203.09583%2011.7292%203.2875%2011.5375C3.47917%2011.3458%203.71667%2011.25%204%2011.25H5.5V10.5H3V9H6C6.28333%209%206.52083%209.09583%206.7125%209.2875C6.90417%209.47917%207%209.71667%207%2010V11.75C7%2012.0333%206.90417%2012.2708%206.7125%2012.4625C6.52083%2012.6542%206.28333%2012.75%206%2012.75H4.5V13.5H7V15H3ZM4.5%208V3.5H3V2H6V8H4.5ZM9%2019V17H21V19H9ZM9%2013V11H21V13H9ZM9%207V5H21V7H9Z'%20fill='%231C1B1F'/%3e%3c/g%3e%3c/svg%3e",gT="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cmask%20id='mask0_337_2560'%20style='mask-type:alpha'%20maskUnits='userSpaceOnUse'%20x='0'%20y='0'%20width='24'%20height='24'%3e%3crect%20width='24'%20height='24'%20fill='%23D9D9D9'/%3e%3c/mask%3e%3cg%20mask='url(%23mask0_337_2560)'%3e%3cpath%20d='M5%2019V17H19V19H5ZM6.9%2015L11%204H13L17.1%2015H15.2L14.25%2012.2H9.8L8.8%2015H6.9ZM10.35%2010.6H13.65L12.05%206.05H11.95L10.35%2010.6Z'%20fill='%231C1B1F'/%3e%3c/g%3e%3c/svg%3e",yT="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20height='24'%20viewBox='0%20-960%20960%20960'%20width='24'%3e%3cpath%20d='m228-240%2092-160q-66%200-113-47t-47-113q0-66%2047-113t113-47q66%200%20113%2047t47%20113q0%2023-5.5%2042.5T458-480L320-240h-92Zm360%200%2092-160q-66%200-113-47t-47-113q0-66%2047-113t113-47q66%200%20113%2047t47%20113q0%2023-5.5%2042.5T818-480L680-240h-92ZM320-500q25%200%2042.5-17.5T380-560q0-25-17.5-42.5T320-620q-25%200-42.5%2017.5T260-560q0%2025%2017.5%2042.5T320-500Zm360%200q25%200%2042.5-17.5T740-560q0-25-17.5-42.5T680-620q-25%200-42.5%2017.5T620-560q0%2025%2017.5%2042.5T680-500Zm0-60Zm-360%200Z'/%3e%3c/svg%3e",bT="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20height='24'%20viewBox='0%20-960%20960%20960'%20width='24'%3e%3cpath%20d='M200-280v-400h80v160h160v-160h80v400h-80v-160H280v160h-80Zm480%200v-320h-80v-80h160v400h-80Z'/%3e%3c/svg%3e",vT="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20height='24'%20viewBox='0%20-960%20960%20960'%20width='24'%3e%3cpath%20d='M120-280v-400h80v160h160v-160h80v400h-80v-160H200v160h-80Zm400%200v-160q0-33%2023.5-56.5T600-520h160v-80H520v-80h240q33%200%2056.5%2023.5T840-600v80q0%2033-23.5%2056.5T760-440H600v80h240v80H520Z'/%3e%3c/svg%3e",wT="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20height='24'%20viewBox='0%20-960%20960%20960'%20width='24'%3e%3cpath%20d='M120-280v-400h80v160h160v-160h80v400h-80v-160H200v160h-80Zm400%200v-80h240v-80H600v-80h160v-80H520v-80h240q33%200%2056.5%2023.5T840-600v240q0%2033-23.5%2056.5T760-280H520Z'/%3e%3c/svg%3e",xT="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20height='24'%20viewBox='0%20-960%20960%20960'%20width='24'%3e%3cpath%20d='M680-360q-17%200-28.5-11.5T640-400v-160q0-17%2011.5-28.5T680-600h120q17%200%2028.5%2011.5T840-560v40h-60v-20h-80v120h80v-20h60v40q0%2017-11.5%2028.5T800-360H680Zm-300%200v-240h160q17%200%2028.5%2011.5T580-560v40q0%2017-11.5%2028.5T540-480q17%200%2028.5%2011.5T580-440v40q0%2017-11.5%2028.5T540-360H380Zm60-150h80v-30h-80v30Zm0%2090h80v-30h-80v30Zm-320%2060v-200q0-17%2011.5-28.5T160-600h120q17%200%2028.5%2011.5T320-560v200h-60v-60h-80v60h-60Zm60-120h80v-60h-80v60Z'/%3e%3c/svg%3e",CT="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20height='24'%20viewBox='0%20-960%20960%20960'%20width='24'%3e%3cpath%20d='M544-400%20440-504%20240-304l104%20104%20200-200Zm-47-161%20104%20104%20199-199-104-104-199%20199Zm-84-28%20216%20216-229%20229q-24%2024-56%2024t-56-24l-2-2-26%2026H60l126-126-2-2q-24-24-24-56t24-56l229-229Zm0%200%20227-227q24-24%2056-24t56%2024l104%20104q24%2024%2024%2056t-24%2056L629-373%20413-589Z'/%3e%3c/svg%3e",kT="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%3e%3cpath%20fill='currentColor'%20d='M19%205v14H5V5h14m0-2H5c-1.1%200-2%20.9-2%202v14c0%201.1.9%202%202%202h14c1.1%200%202-.9%202-2V5c0-1.1-.9-2-2-2zm-4.86%208.86l-3%203.87L9%2013.14L6%2017h12l-3.86-5.14z'/%3e%3c/svg%3e",$l=new We("upload-image"),ST=()=>new je({key:$l,state:{init(){return He.empty},apply(n,e){e=e.map(n.mapping,n.doc);const t=n.getMeta(this);if(t&&t.add){const{id:r,pos:i,src:s}=t.add,o=document.createElement("div");o.setAttribute("class","img-placeholder");const l=document.createElement("img");l.setAttribute("class","rounded-lg border border-stone-200"),l.src=s,o.appendChild(l);const a=ut.widget(i+1,o,{id:r});e=e.add(n.doc,[a])}else t&&t.remove&&(e=e.remove(e.find(void 0,void 0,r=>r.id==t.remove.id)));return e}},props:{decorations(n){return this.getState(n)}}});function ET(n,e){const r=$l.getState(n).find(null,null,i=>i.id==e);return r.length?r[0].from:null}function y0(n,e,t){if(n.type.includes("image/")){if(n.size>1024*1024){console.log("failed");return}}else{console.log("file is not an image");return}const r={},i=e.state.tr;i.selection.empty||i.deleteSelection();const s=new FileReader;s.readAsDataURL(n),s.onload=()=>{i.setMeta($l,{add:{id:r,pos:t,src:s.result}}),e.dispatch(i)},TT(n).then(o=>{const{schema:l}=e.state,a=ET(e.state,r);if(a==null)return;const c=typeof o=="object"?s.result:o,u=l.nodes.resizableMedia.create({src:c,"media-type":"img"}),d=e.state.tr.replaceWith(a-2,a+u.nodeSize,u).setMeta($l,{remove:{id:r}});e.dispatch(d)})}const TT=n=>new Promise(e=>{const t=new FileReader;t.readAsDataURL(n),t.onload=()=>e(t.result)}),AT=async n=>{const e=new FileReader;if(e.readAsDataURL(n),n.size>1024*1024)throw e.abort(),console.log("should be less than 1 mb"),new Error("Image too large");return await new Promise(r=>{e.onload=()=>{r(e.result)}})},b0=({editor:n})=>{const{ref:e,toolVisibilty:t,setToolVisibility:r}=fT(Te.NONE);return{toolbar:[{icon:pT,title:"Font",onClick:()=>r(Te.FONT_FAMILY),isActive:t===Te.FONT_FAMILY},{icon:gT,title:"Text Color",onClick:()=>r(Te.TEXT_COLOR),isActive:t===Te.TEXT_COLOR},{icon:CT,title:"Highlight",onClick:()=>r(Te.HIGHLIGHT),isActive:t===Te.HIGHLIGHT},null,{icon:Yg,title:"Bold",onClick:()=>n==null?void 0:n.chain().focus().toggleBold().run(),isActive:n==null?void 0:n.isActive("bold")},{icon:Zg,title:"Italic",onClick:()=>n==null?void 0:n.chain().focus().toggleItalic().run(),isActive:n==null?void 0:n.isActive("italic")},{icon:Xg,title:"Underlined",onClick:()=>n==null?void 0:n.chain().focus().toggleUnderline().run(),isActive:n==null?void 0:n.isActive("underline")},{icon:e0,title:"Strikethrough",onClick:()=>n==null?void 0:n.chain().focus().toggleStrike().run(),isActive:n==null?void 0:n.isActive("strike")},null,{icon:g0,title:"List",onClick:()=>r(Te.LIST),isActive:t===Te.LIST},{icon:od,title:"Alignment",onClick:()=>r(Te.ALIGNMENT),isActive:t===Te.ALIGNMENT},{icon:yT,title:"Quote",onClick:()=>n==null?void 0:n.chain().focus().toggleBlockquote().run(),isActive:n==null?void 0:n.isActive("blockquote")},null,{icon:kT,title:"Upload Image",onClick:()=>{n==null||n.chain().focus().deleteRange(n.state.selection).run();const s=document.createElement("input");s.type="file",s.accept="image/*",s.onchange=async()=>{var o;if((o=s.files)!=null&&o.length){const l=s.files[0],a=n.view.state.selection.from;y0(l,n.view,a)}},s.click()},isActive:!1},{icon:t0,title:"Link",onClick:()=>r(Te.LINK),isActive:n==null?void 0:n.isActive("link")},{icon:Qg,title:"Code",onClick:()=>n==null?void 0:n.chain().focus().toggleCodeBlock().run(),isActive:n==null?void 0:n.isActive("codeBlock")}],toolRef:e,toolVisibilty:t,setToolVisibility:r}},MT=({editor:n,setVisibility:e,elementRef:t})=>{const r=[{color:"#00FF00",code:"bg-[#00FF00]"},{color:"#008080",code:"bg-[#008080]"},{color:"#FFC0CB",code:"bg-[#FFC0CB]"},{color:"#808000",code:"bg-[#808000]"},{color:"#800000",code:"bg-[#800000]"},{color:"#000080",code:"bg-[#000080]"},{color:"#7FFFD4",code:"bg-[#7FFFD4]"},{color:"#40E0D0",code:"bg-[#40E0D0]"},{color:"#C0C0C0",code:"bg-[#C0C0C0]"},{color:"#808080",code:"bg-[#808080]"},{color:"#000000",code:"bg-[#000000]"},{color:"#FFFFFF",code:"bg-[#FFFFFF]"},{color:"#CD5C5C",code:"bg-[#CD5C5C]"},{color:"#F08080",code:"bg-[#F08080]"},{color:"#FA8072",code:"bg-[#FA8072]"},{color:"#E9967A",code:"bg-[#E9967A]"},{color:"#FFA07A",code:"bg-[#FFA07A]"},{color:"#DC143C",code:"bg-[#DC143C]"},{color:"#FF6347",code:"bg-[#FF6347]"},{color:"#FF7F50",code:"bg-[#FF7F50]"},{color:"#FF4500",code:"bg-[#FF4500]"},{color:"#BDB76B",code:"bg-[#BDB76B]"},{color:"#FFD700",code:"bg-[#FFD700]"},{color:"#F0E68C",code:"bg-[#F0E68C]"},{color:"#FFE5B4",code:"bg-[#FFE5B4]"},{color:"#9ACD32",code:"bg-[#9ACD32]"},{color:"#556B2F",code:"bg-[#556B2F]"},{color:"#6B8E23",code:"bg-[#6B8E23]"},{color:"#7CFC00",code:"bg-[#7CFC00]"},{color:"#7FFF00",code:"bg-[#7FFF00]"},{color:"#ADFF2F",code:"bg-[#ADFF2F]"},{color:"#00BFFF",code:"bg-[#00BFFF]"},{color:"#1E90FF",code:"bg-[#1E90FF]"},{color:"#6495ED",code:"bg-[#6495ED]"},{color:"#4682B4",code:"bg-[#4682B4]"},{color:"#4169E1",code:"bg-[#4169E1]"},{color:"#8A2BE2",code:"bg-[#8A2BE2]"},{color:"#4B0082",code:"bg-[#4B0082]"},{color:"#6A5ACD",code:"bg-[#6A5ACD]"}];return D.jsxs("div",{ref:t,className:"z-50 h-auto absolute gap-2 top-[50px] flex flex-wrap left-[20%] max-h-[330px] w-[20.5rem] overflow-y-auto scroll-smooth rounded-md border border-stone-200 bg-white px-1 py-2 shadow-md transition-all",children:[D.jsx(r0,{className:"cursor-pointer",onClick:()=>{n.chain().focus().unsetHighlight().run(),e(Te.NONE)}}),r.map(i=>D.jsx("div",{onClick:()=>{n.chain().focus().toggleHighlight({color:i.color}).run(),e(Te.NONE)},className:`w-6 ${i.code} drop-shadow rounded-full flex items-center justify-center cursor-pointer ease-in duration-200 hover:scale-[1.05] h-6`,children:D.jsx(Bl,{size:14,className:`${n.isActive("highlight",{color:i.color})?"visible":"invisible"}`})},i.color))]})},OT=({elementRef:n,editor:e,setToolVisibility:t})=>{const r=[{title:"Trebuchet MS",command:i=>{i.chain().focus().setFontFamily("Trebuchet MS, sans-serif").run()}},{title:"Verdana",command:i=>{i.chain().focus().setFontFamily("Verdana, Geneva, sans-serif").run()}},{title:"Georgia",command:i=>{i.chain().focus().setFontFamily("Georgia, serif").run()}},{title:"Arial",command:i=>{i.chain().focus().setFontFamily("Arial, Helvetica, sans-serif").run()}},{title:"Comic Sans MS",command:i=>{i.chain().focus().setFontFamily("Comic Sans MS, Comic Sans").run()}},{title:"Impact",command:i=>{i.chain().focus().setFontFamily("Impact, Charcoal, sans-serif").run()}},{title:"Palatino",command:i=>{i.chain().focus().setFontFamily("Palatino Linotype, Book Antiqua, Palatino, serif").run()}},{title:"Lucida Grande",command:i=>{i.chain().focus().setFontFamily("Lucida Sans Unicode, Lucida Grande, sans-serif").run()}},{title:"Serif",command:i=>{i.chain().focus().setFontFamily("serif").run()}},{title:"Monospace",command:i=>{i.chain().focus().setFontFamily("monospace").run()}},{title:"Cursive",command:i=>{i.chain().focus().setFontFamily("cursive").run()}}];return D.jsx("div",{ref:n,className:Fe("z-50 h-auto absolute top-[50px] left-[20%] max-h-[330px] w-48 overflow-y-auto scroll-smooth rounded-md border border-stone-200 bg-white px-1 py-2 shadow-md transition-all"),children:r.map(i=>D.jsx("button",{onClick:()=>{i.command(e),t(Te.NONE)},style:{fontFamily:i.title},className:`flex w-full ${e.isActive("textStyle",{fontFamily:i.title})?"bg-red-500":""} items-center space-x-2 rounded-md px-2 py-1 text-left text-sm text-stone-900 hover:bg-stone-100`,children:D.jsx("p",{className:"font-medium",children:i.title})},i.title))})},_T=({elementRef:n,editor:e,setToolVisibility:t})=>D.jsxs("div",{ref:n,className:Fe("z-50 h-auto absolute gap-2 top-[50px] right-[25%] flex flex-wrap max-h-[330px] overflow-y-auto scroll-smooth rounded-md border border-stone-200 bg-white px-1 py-2 shadow-md transition-all"),children:[D.jsx("span",{onClick:()=>{e==null||e.chain().focus().setTextAlign("left").run(),t(Te.NONE)},className:` hover:bg-[#f2f2f2] ${e.isActive({textAlign:"left"})&&"bg-[#f2f2f2]"} rounded-lg w-8 h-8 p-1 flex justify-center items-center`,children:D.jsx("img",{src:od,alt:"align left"})}),D.jsx("span",{onClick:()=>{e==null||e.chain().focus().setTextAlign("center").run(),t(Te.NONE)},className:` hover:bg-[#f2f2f2] ${e.isActive({textAlign:"center"})&&"bg-[#f2f2f2]"} rounded-lg w-8 h-8 p-1 flex justify-center items-center`,children:D.jsx("img",{src:p0,alt:"align center"})}),D.jsx("span",{onClick:()=>{e==null||e.chain().focus().setTextAlign("right").run(),t(Te.NONE)},className:` hover:bg-[#f2f2f2] ${e.isActive({textAlign:"right"})&&"bg-[#f2f2f2]"} rounded-lg w-8 h-8 p-1 flex justify-center items-center`,children:D.jsx("img",{src:m0,alt:"align right"})})]}),NT=({elementRef:n,editor:e,setToolVisibility:t})=>D.jsxs("div",{ref:n,className:Fe("z-50 h-auto absolute gap-2 top-[50px] right-[30%] flex flex-wrap max-h-[330px] overflow-y-auto scroll-smooth rounded-md border border-stone-200 bg-white px-1 py-2 shadow-md transition-all"),children:[D.jsx("div",{className:"tooltip tooltip-open tooltip-bottom","data-tip":"unordered list",children:D.jsx("span",{onClick:()=>{e==null||e.chain().focus().toggleBulletList().run(),t(Te.NONE)},className:` hover:bg-[#f2f2f2] ${e.isActive("bulletList")?"bg-[#f2f2f2]":""} rounded-lg w-8 h-8 p-1 flex justify-center items-center`,children:D.jsx("img",{src:g0,alt:"bullet list"})})}),D.jsx("div",{className:"tooltip tooltip-open tooltip-bottom","data-tip":"ordered list",children:D.jsx("span",{onClick:()=>{e==null||e.chain().focus().toggleOrderedList().run(),t(Te.NONE)},className:` hover:bg-[#f2f2f2] ${e.isActive("orderedList")?"bg-[#f2f2f2]":""} rounded-lg w-8 h-8 p-1 flex justify-center items-center`,children:D.jsx("img",{src:mT,alt:"numbered list"})})}),D.jsx("div",{className:"tooltip tooltip-open tooltip-bottom","data-tip":"to-do list",children:D.jsx("span",{onClick:()=>{e==null||e.chain().focus().toggleTaskList().run(),t(Te.NONE)},className:` hover:bg-[#f2f2f2] ${e.isActive("taskList")?"bg-[#f2f2f2]":""} rounded-lg w-8 h-8 p-1 flex justify-center items-center`,children:D.jsx("img",{src:hT,alt:"checklist"})})})]}),v0=({elementRef:n,editor:e,setToolVisibility:t,bubbleMenu:r,setIsLinkPopupOpen:i})=>{const[s,o]=O.useState(e.getAttributes("link").href),l=()=>{if(s===null)return;if(s===""){e.chain().focus().extendMarkRange("link").unsetLink().run();return}let a=s;!s.startsWith("http://")&&!s.startsWith("https://")&&(a="https://"+s);try{a.match(/^((http|https):\/\/)?([w|W]{3}\.)+[a-zA-Z0-9\-\.]{3,}\.[a-zA-Z]{2,}(\.[a-zA-Z]{2,})?$/)&&e.chain().focus().extendMarkRange("link").setLink({href:a}).run()}catch{console.error("Invalid URL");return}e.chain().focus().extendMarkRange("link").setLink({href:a}).run(),t(Te.NONE),r&&i&&i(!1)};return D.jsxs("div",{ref:n,className:"z-50 h-auto absolute gap-2 top-[50px] items-center flex right-[10%] max-h-[330px] overflow-y-auto scroll-smooth rounded-md border border-stone-200 bg-white p-2 shadow-md transition-all",children:[D.jsx("input",{onChange:a=>o(a.target.value),className:"border-2 focus:border-black px-2 py-1.5 rounded w-full font-medium text-sm",placeholder:"Add link here",value:s}),D.jsx("div",{className:"h-full flex items-center",children:D.jsx("button",{onClick:()=>l(),className:"min-w-fit",children:"Apply"})})]})},DT=({editor:n,setVisibility:e,elementRef:t})=>{const r=[{color:"#00FF00",code:"bg-[#00FF00]"},{color:"#008080",code:"bg-[#008080]"},{color:"#FFC0CB",code:"bg-[#FFC0CB]"},{color:"#808000",code:"bg-[#808000]"},{color:"#800000",code:"bg-[#800000]"},{color:"#000080",code:"bg-[#000080]"},{color:"#7FFFD4",code:"bg-[#7FFFD4]"},{color:"#40E0D0",code:"bg-[#40E0D0]"},{color:"#C0C0C0",code:"bg-[#C0C0C0]"},{color:"#808080",code:"bg-[#808080]"},{color:"#000000",code:"bg-[#000000]"},{color:"#FFFFFF",code:"bg-[#FFFFFF]"},{color:"#CD5C5C",code:"bg-[#CD5C5C]"},{color:"#F08080",code:"bg-[#F08080]"},{color:"#FA8072",code:"bg-[#FA8072]"},{color:"#E9967A",code:"bg-[#E9967A]"},{color:"#FFA07A",code:"bg-[#FFA07A]"},{color:"#DC143C",code:"bg-[#DC143C]"},{color:"#FF6347",code:"bg-[#FF6347]"},{color:"#FF7F50",code:"bg-[#FF7F50]"},{color:"#FF4500",code:"bg-[#FF4500]"},{color:"#BDB76B",code:"bg-[#BDB76B]"},{color:"#FFD700",code:"bg-[#FFD700]"},{color:"#F0E68C",code:"bg-[#F0E68C]"},{color:"#FFE5B4",code:"bg-[#FFE5B4]"},{color:"#9ACD32",code:"bg-[#9ACD32]"},{color:"#556B2F",code:"bg-[#556B2F]"},{color:"#6B8E23",code:"bg-[#6B8E23]"},{color:"#7CFC00",code:"bg-[#7CFC00]"},{color:"#7FFF00",code:"bg-[#7FFF00]"},{color:"#ADFF2F",code:"bg-[#ADFF2F]"},{color:"#00BFFF",code:"bg-[#00BFFF]"},{color:"#1E90FF",code:"bg-[#1E90FF]"},{color:"#6495ED",code:"bg-[#6495ED]"},{color:"#4682B4",code:"bg-[#4682B4]"},{color:"#4169E1",code:"bg-[#4169E1]"},{color:"#8A2BE2",code:"bg-[#8A2BE2]"},{color:"#4B0082",code:"bg-[#4B0082]"},{color:"#6A5ACD",code:"bg-[#6A5ACD]"}];return D.jsxs("div",{ref:t,className:"z-50 h-auto absolute gap-2 top-[50px] flex flex-wrap left-[100px] max-h-[330px] w-[20.5rem] overflow-y-auto scroll-smooth rounded-md border border-stone-200 bg-white px-1 py-2 shadow-md transition-all",children:[D.jsx(r0,{className:"cursor-pointer",onClick:()=>{n.chain().focus().unsetColor().run(),e(Te.NONE)}}),r.map(i=>D.jsx("div",{onClick:()=>{n.chain().focus().setColor(i.color).run(),e(Te.NONE)},className:`w-6 ${i.code} drop-shadow rounded-full flex justify-center items-center cursor-pointer ease-in duration-200 hover:scale-[1.05] h-6`,children:D.jsx(Bl,{size:14,className:`${n.isActive("textStyle",{color:i.color})?"visible":"invisible"}`})},i.color))]})},RT=({editor:n,setVisibility:e,elementRef:t})=>{const r=[{title:"Text",description:"Normal",icon:xT,command:i=>i.chain().focus().toggleNode("paragraph","paragraph").run()},{title:"Heading 1",description:"Big",icon:bT,command:i=>{i.chain().focus().toggleHeading({level:1}).run()}},{title:"Heading 2",description:"Medium",icon:vT,command:i=>{i.chain().focus().toggleHeading({level:2}).run()}},{title:"Heading 3",description:"Small",icon:wT,command:i=>{i.chain().focus().toggleHeading({level:3}).run()}}];return D.jsx("section",{ref:t,className:Fe(" absolute top-[50px] z-50 mt-1 flex w-48 flex-col overflow-hidden rounded border border-stone-200 bg-white p-1 shadow-xl animate-in fade-in slide-in-from-top-1","left-0"),children:r.map(i=>D.jsxs("button",{onClick:()=>{i.command(n),e(Te.NONE)},className:"flex w-full items-center space-x-2 rounded-md px-2 py-1 text-left text-sm text-stone-900 hover:bg-stone-100",children:[D.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-md border border-stone-200 bg-white",children:D.jsx("img",{src:i.icon,alt:i.title})}),D.jsxs("div",{children:[D.jsx("p",{className:"font-medium",children:i.title}),D.jsxs("p",{className:"text-xs text-stone-500",children:[" ",i.description," "]})]})]},i.title))})},LT=n=>{const e=[{name:"bold",isActive:()=>n.editor.isActive("bold"),command:()=>n.editor.chain().focus().toggleBold().run(),icon:Yg},{name:"italic",isActive:()=>n.editor.isActive("italic"),command:()=>n.editor.chain().focus().toggleItalic().run(),icon:Zg},{name:"underline",isActive:()=>n.editor.isActive("underline"),command:()=>n.editor.chain().focus().toggleUnderline().run(),icon:Xg},{name:"strike",isActive:()=>n.editor.isActive("strike"),command:()=>n.editor.chain().focus().toggleStrike().run(),icon:e0},{name:"codeBlock",isActive:()=>n.editor.isActive("codeBlock"),command:()=>n.editor.chain().focus().toggleCodeBlock().run(),icon:Qg},{name:"link",isActive:()=>n.editor.isActive("link"),command:()=>a(!l),icon:t0}],t={...n,shouldShow:({state:d,editor:f})=>{const{selection:h}=d,{empty:p}=h;return!(f.isActive("image")||p||Qm(h))},tippyOptions:{moveTransition:"transform 0.15s ease-out",duration:200,animation:"shift-toward-subtle",onHidden:()=>{i(!1),o(!1),a(!1)}}},[r,i]=O.useState(!1),[s,o]=O.useState(!1),[l,a]=O.useState(!1),{toolRef:c,setToolVisibility:u}=b0({editor:n.editor});return D.jsxs(Ug,{...t,className:"flex gap-1 overflow-hidden rounded border border-stone-200 bg-white shadow-xl",children:[D.jsx(uT,{editor:n.editor,isOpen:r,setIsOpen:()=>{i(!r),o(!1)}}),e.map((d,f)=>D.jsx("button",{onClick:d.command,className:" py-2 text-stone-600 hover:bg-stone-100 active:bg-stone-200",children:D.jsx("img",{src:d.icon,className:Fe(" p-1 rounded-lg h-6 w-6",{"bg-yellow-300":d.isActive()})})},f)),D.jsx(dT,{editor:n.editor,isOpen:s,setIsOpen:()=>{o(!s),i(!1)}}),l&&D.jsx(v0,{setToolVisibility:u,editor:n.editor,elementRef:c,bubbleMenu:!0,setIsLinkPopupOpen:a})]})};function IT(){const n=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"];let e=[];for(let t=0;t<36;t++)t===8||t===13||t===18||t===23?e[t]="-":e[t]=n[Math.ceil(Math.random()*n.length-1)];return e.join("")}var PT=IT;const FT=Nc(PT),w0=Ve.create({name:"column",content:"dBlock+",isolating:!0,addAttributes(){return{position:{default:"",parseHTML:n=>n.getAttribute("data-position"),renderHTML:n=>({"data-position":n.position})}}},renderHTML({HTMLAttributes:n}){return["div",xe(n,{"data-type":"column"}),0]},parseHTML(){return[{tag:'div[data-type="column"]'}]}}),BT=(n,e)=>Array.from({length:n},(t,r)=>e(r)),jl=({type:n,content:e})=>e?{type:n,content:e}:{type:n},$T=({content:n})=>jl({type:"paragraph",content:n}),x0=({content:n})=>jl({type:"dBlock",content:n}),C0=({content:n})=>jl({type:"column",content:n}),k0=({content:n})=>jl({type:"columns",content:n}),S0=n=>{const e=[x0({content:[$T({})]})];return BT(n,()=>C0({content:e}))},E0=(n,e)=>{for(let t=n.depth;t>0;t--){const r=n.node(t),i=t>0?n.before(t):0,s=n.start(t);if(e({node:r,pos:i,start:s}))return{start:s,depth:t,node:r,pos:i}}throw Error("no ancestor found")};class Hl extends ue{constructor(t){const{$from:r,$to:i}=t;super(r,i);vr(this,"_$from");vr(this,"_$to");this._$from=r,this._$to=i}get $from(){return this._$from}get $to(){return this._$to}map(){return this}content(){return this.$from.doc.slice(this.from,this.to,!0)}eq(t){return t instanceof Hl&&t.anchor==this.anchor}toJSON(){return{type:"column",from:this.from,to:this.to}}expandSelection(t){var a;const r=({pos:c,node:u})=>u.type.name===w0.name?!0:t.resolve(c).depth<=0,{pos:i}=E0(this.$from,r);this._$from=t.resolve(i);const{pos:s,node:o}=E0(this.$to,r);this._$to=t.resolve(s+o.nodeSize),((a=this.getFirstNode())==null?void 0:a.type.name)===Vl.name&&(this._$from=t.resolve(this.$from.pos+2),this._$to=t.resolve(this.$to.pos+2));const l=this;l.$anchor=this._$from,l.$head=this._$to,l.ranges=[new Jc(this._$from,this._$to)]}static create(t,r,i){const s=t.resolve(r),o=t.resolve(i),l=new ce(s,o);return new Hl(l)}getFirstNode(){return this.content().content.firstChild}}var pi=(n=>(n.AlignLeft="align-left",n.AlignRight="align-right",n.AlignCenter="align-center",n))(pi||{});const Vl=Ve.create({name:"columns",group:"columns",content:"column{2,}",defining:!0,draggable:!0,isolating:!0,addAttributes(){return{layout:{default:"align-center"}}},addCommands(){return{unsetColumns:()=>({tr:n,dispatch:e})=>{try{if(!e)return;const t=n.selection.$from,i=Ru(t,({node:a})=>!this.options.nestedColumns&&a.type==this.type?!0:a.type==this.type);if(i===void 0)return;let s=[];i.node.descendants((a,c,u)=>{(u==null?void 0:u.type.name)===Vl.name&&s.push(a)}),s=s.reverse().filter(a=>a.content.size>0);const o=n.doc.resolve(i.pos),l=new se(o);return n=n.setSelection(l),s.forEach(a=>n=n.insert(i.pos,a)),n=n.deleteSelection(),e(n)}catch(t){console.error(t)}},setColumns:(n,e=!1)=>({tr:t,dispatch:r})=>{try{const{doc:i,selection:s}=t;if(!r){console.log("no dispatch");return}const o=new Hl(s);o.expandSelection(i);const{openStart:l,openEnd:a}=o.content();if(l!==a){console.warn("failed depth check");return}let c;if(e){const h=o.content().toJSON(),p=C0(h),g=S0(n-1);c=k0({content:[p,...g]})}else{const h=S0(n);c=k0({content:h})}const u=i.type.schema.nodeFromJSON(x0({content:[c]}));if(u===null)return;const d=o.$anchor.parent.type;if(!(h=>!(!h.contentMatch.matchType(this.type)||!this.options.nestedColumns&&h.name===Vl.name))(d)){console.warn("content not allowed");return}return t=t.setSelection(o),t=t.replaceSelectionWith(u,!1),r(t)}catch(i){console.error(i)}},setLayout:n=>({commands:e})=>e.updateAttributes("columns",{layout:n})}},renderHTML({HTMLAttributes:n}){return["div",{"data-type":"columns",class:`layout-${n.layout}`},0]},parseHTML(){return[{tag:'div[data-type="columns"]'}]}}),jT=(n,e)=>{const{view:t,state:{selection:{from:r}}}=n,i=document.querySelectorAll(".has-focus"),s=i.length,l=i[s-1];if(l&&l.getAttribute("data-type")&&l.getAttribute("data-type")===e||l&&l.classList&&l.classList.contains(e))return l;const a=t.domAtPos(r).node;let c=a;for(c.tagName||(c=a.parentElement);c&&!(c.getAttribute("data-type")&&c.getAttribute("data-type")===e)&&!c.classList.contains(e);)c=c.parentElement;return c},ld=O.forwardRef(({children:n,className:e,withShadow:t=!0,withBorder:r=!0,...i},s)=>{const o=Fe(e,"bg-white rounded-md",t?"shadow-md":"",r?"border border-neutral-200":"");return D.jsx("div",{className:o,...i,ref:s,children:n})});ld.displayName="Surface";const zl=O.forwardRef(({active:n,buttonSize:e="medium",children:t,disabled:r,variant:i="primary",className:s,activeClassname:o,...l},a)=>{const c=Fe("flex group items-center justify-center border border-transparent gap-2 text-sm font-semibold rounded disabled:opacity-50 whitespace-nowrap",i==="primary"&&Fe("text-white bg-black border-black dark:text-black dark:bg-white dark:border-white",!r&&!n&&"hover:bg-neutral-800 active:bg-neutral-900 dark:hover:bg-neutral-200 dark:active:bg-neutral-300",n&&Fe("bg-neutral-900 dark:bg-neutral-300",o)),i==="secondary"&&Fe("text-neutral-900 dark:text-white",!r&&!n&&"hover:bg-neutral-100 active:bg-neutral-200 dark:hover:bg-neutral-900 dark:active:bg-neutral-800",n&&"bg-neutral-200 dark:bg-neutral-800"),i==="tertiary"&&Fe("bg-neutral-50 text-neutral-900 dark:bg-neutral-900 dark:text-white dark:border-neutral-900",!r&&!n&&"hover:bg-neutral-100 active:bg-neutral-200 dark:hover:bg-neutral-800 dark:active:bg-neutral-700",n&&Fe("bg-neutral-200 dark:bg-neutral-800",o)),i==="ghost"&&Fe("bg-transparent border-transparent text-neutral-500",!r&&!n&&"hover:bg-black/5 hover:text-neutral-700 active:bg-black/10 active:text-neutral-800 ",n&&Fe("bg-black/10 text-neutral-800 ",o)),e==="medium"&&"py-2 px-3",e==="small"&&"py-1 px-2",e==="icon"&&"w-8 h-8",e==="iconSmall"&&"w-6 h-6",s);return D.jsx("button",{ref:a,disabled:r,className:c,...l,children:t})});zl.displayName="Button";const T0=({content:n,children:e})=>{const[t,r]=O.useState(!1);return D.jsxs("div",{className:"relative inline-block",onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),children:[e,t&&D.jsx("div",{className:"absolute z-10 p-2 mt-2 text-sm text-white bg-gray-800 rounded shadow-lg",children:n})]})},A0=O.forwardRef(({shouldShowContent:n=!0,children:e,isVertical:t=!1,className:r,...i},s)=>{const o=Fe("text-black inline-flex h-full leading-none gap-0.5",t?"flex-col p-2":"flex-row p-1 items-center",r);return n?n&&D.jsx(ld,{className:o,...i,ref:s,children:e}):null});A0.displayName="Toolbar";const M0=O.forwardRef(({horizontal:n,className:e,...t},r)=>{const i=Fe("bg-neutral-200",n?"w-full min-w-[1.5rem] h-[1px] my-1 first:mt-0 last:mt-0":"h-full min-h-[1.5rem] w-[1px] mx-1 first:ml-0 last:mr-0",e);return D.jsx("div",{className:i,ref:r,...t})});M0.displayName="Toolbar.Divider";const O0=O.forwardRef(({children:n,buttonSize:e="icon",variant:t="ghost",className:r,tooltip:i,activeClassname:s,...o},l)=>{const a=Fe("gap-1 min-w-[2rem] px-2 w-auto",r),c=D.jsx(zl,{activeClassname:s,className:a,variant:t,buttonSize:e,ref:l,...o,children:n});return i?D.jsx(T0,{content:i,children:c}):c});O0.displayName="ToolbarButton";const vo={Wrapper:A0,Divider:M0,Button:O0},HT=({editor:n,appendTo:e})=>{const t=O.useCallback(()=>{const l=jT(n,"columns");return(l==null?void 0:l.getBoundingClientRect())||new DOMRect(-1e3,-1e3,0,0)},[n]),r=O.useCallback(()=>n.isActive("columns"),[n]),i=O.useCallback(()=>{n.chain().focus().setLayout(pi.AlignLeft).run()},[n]),s=O.useCallback(()=>{n.chain().focus().setLayout(pi.AlignRight).run()},[n]),o=O.useCallback(()=>{n.chain().focus().setLayout(pi.AlignCenter).run()},[n]);return D.jsx(Ug,{editor:n,pluginKey:`columnsMenu-${FT()}`,shouldShow:r,updateDelay:0,tippyOptions:{offset:[0,8],popperOptions:{modifiers:[{name:"flip",enabled:!1}]},getReferenceClientRect:t,moveTransition:"transform 0.15s ease-out",duration:200,animation:"shift-toward-subtle",appendTo:()=>e==null?void 0:e.current,plugins:[OE],sticky:"popper"},children:D.jsxs(vo.Wrapper,{children:[D.jsx(vo.Button,{tooltip:"Align left",active:n.isActive("columns",{layout:pi.AlignLeft}),onClick:i,children:D.jsx(eT,{size:20})}),D.jsx(vo.Button,{tooltip:"Align center",active:n.isActive("columns",{layout:pi.AlignCenter}),onClick:o,children:D.jsx(s0,{size:20})}),D.jsx(vo.Button,{tooltip:"Align right",active:n.isActive("columns",{layout:pi.AlignRight}),onClick:s,children:D.jsx(tT,{size:20})})]})})},_0=O.createContext(null),Ul=()=>O.useContext(_0),VT=({children:n,isPreviewMode:e})=>D.jsx(_0.Provider,{value:e,children:n}),N0=({height:n,width:e})=>D.jsx("span",{className:"flex items-center justify-center ",children:D.jsx("span",{className:`${e?`w-${e}`:"w-8"} ${n?`h-${n}`:"h-8"} border-4 border-t-4 border-t-[#ccc] border-gray-500 rounded-full animate-spin`})}),zT=({editor:n})=>{const{toolRef:e,toolVisibilty:t,setToolVisibility:r,toolbar:i}=b0({editor:n});return D.jsxs("div",{className:"w-fit bg-transparent px-4 items-center rounded-lg h-16 flex gap-1 justify-center",children:[D.jsxs("button",{className:"hover:bg-[#f2f2f2] border gap-2 rounded-lg w-28 h-8 p-1 flex justify-center items-center",onClick:()=>r(Te.HEADING),children:[D.jsx("span",{className:"text-sm",children:n!=null&&n.isActive("heading",{level:1})?"Heading 1":n!=null&&n.isActive("heading",{level:2})?"Heading 2":n!=null&&n.isActive("heading",{level:3})?"Heading 3":"Text"}),D.jsx(id,{className:"h-4 w-4"})]}),i.map((s,o)=>s?D.jsx("div",{className:"tooltip tooltip-bottom","data-tip":s.title,children:D.jsx("span",{onClick:()=>s.onClick(),className:Fe("rounded-lg w-8 h-8 p-1 flex cursor-pointer justify-center items-center",s.isActive?"bg-yellow-300":"hover:bg-[#f2f2f2]"),children:typeof s.icon=="string"?D.jsx("img",{src:s.icon,className:"w-4"}):s.icon})},s.title):D.jsx("div",{className:" w-[1px] h-[50%] bg-[#777777]"},o)),t===Te.HEADING&&D.jsx(RT,{setVisibility:r,editor:n,elementRef:e}),t===Te.TEXT_COLOR&&D.jsx(DT,{setVisibility:r,editor:n,elementRef:e}),t===Te.HIGHLIGHT&&D.jsx(MT,{setVisibility:r,editor:n,elementRef:e}),t===Te.FONT_FAMILY&&D.jsx(OT,{setToolVisibility:r,editor:n,elementRef:e}),t===Te.ALIGNMENT&&D.jsx(_T,{setToolVisibility:r,editor:n,elementRef:e}),t===Te.LIST&&D.jsx(NT,{setToolVisibility:r,editor:n,elementRef:e}),t===Te.LINK&&D.jsx(v0,{setToolVisibility:r,editor:n,elementRef:e})]})},Lt=()=>new Map,ad=n=>{const e=Lt();return n.forEach((t,r)=>{e.set(r,t)}),e},zt=(n,e,t)=>{let r=n.get(e);return r===void 0&&n.set(e,r=t()),r},UT=(n,e)=>{const t=[];for(const[r,i]of n)t.push(e(i,r));return t},WT=(n,e)=>{for(const[t,r]of n)if(e(r,t))return!0;return!1},or=()=>new Set,cd=n=>n[n.length-1],qT=(n,e)=>{for(let t=0;t<e.length;t++)n.push(e[t])},lr=Array.from,KT=(n,e)=>{for(let t=0;t<n.length;t++)if(e(n[t],t,n))return!0;return!1},ud=Array.isArray;class dd{constructor(){this._observers=Lt()}on(e,t){return zt(this._observers,e,or).add(t),t}once(e,t){const r=(...i)=>{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){const r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return lr((this._observers.get(e)||Lt()).values()).forEach(r=>r(...t))}destroy(){this._observers=Lt()}}class D0{constructor(){this._observers=Lt()}on(e,t){zt(this._observers,e,or).add(t)}once(e,t){const r=(...i)=>{this.off(e,r),t(...i)};this.on(e,r)}off(e,t){const r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return lr((this._observers.get(e)||Lt()).values()).forEach(r=>r(...t))}destroy(){this._observers=Lt()}}const wn=Math.floor,Wl=Math.abs,JT=Math.log10,Ir=(n,e)=>n<e?n:e,ar=(n,e)=>n>e?n:e,R0=n=>n!==0?n<0:1/n<0,Bn=Date.now,GT=1200,YT=2500,ql=3e4,fd=n=>{if(n.shouldConnect&&n.ws===null){const e=new WebSocket(n.url),t=n.binaryType;let r=null;t&&(e.binaryType=t),n.ws=e,n.connecting=!0,n.connected=!1,e.onmessage=o=>{n.lastMessageReceived=Bn();const l=o.data,a=typeof l=="string"?JSON.parse(l):l;a&&a.type==="pong"&&(clearTimeout(r),r=setTimeout(s,ql/2)),n.emit("message",[a,n])};const i=o=>{n.ws!==null&&(n.ws=null,n.connecting=!1,n.connected?(n.connected=!1,n.emit("disconnect",[{type:"disconnect",error:o},n])):n.unsuccessfulReconnects++,setTimeout(fd,Ir(JT(n.unsuccessfulReconnects+1)*GT,YT),n)),clearTimeout(r)},s=()=>{n.ws===e&&n.send({type:"ping"})};e.onclose=()=>i(null),e.onerror=o=>i(o),e.onopen=()=>{n.lastMessageReceived=Bn(),n.connecting=!1,n.connected=!0,n.unsuccessfulReconnects=0,n.emit("connect",[{type:"connect"},n]),r=setTimeout(s,ql/2)}}};class ZT extends D0{constructor(e,{binaryType:t}={}){super(),this.url=e,this.ws=null,this.binaryType=t||null,this.connected=!1,this.connecting=!1,this.unsuccessfulReconnects=0,this.lastMessageReceived=0,this.shouldConnect=!0,this._checkInterval=setInterval(()=>{this.connected&&ql<Bn()-this.lastMessageReceived&&this.ws.close()},ql/2),fd(this)}send(e){this.ws&&this.ws.send(JSON.stringify(e))}destroy(){clearInterval(this._checkInterval),this.disconnect(),super.destroy()}disconnect(){this.shouldConnect=!1,this.ws!==null&&this.ws.close()}connect(){this.shouldConnect=!0,!this.connected&&this.ws===null&&fd(this)}}const $n=n=>new Error(n),xn=()=>{throw $n("Method unimplemented")},cn=()=>{throw $n("Unexpected case")},L0=1,I0=2,hd=4,pd=8,wo=32,cr=64,Yt=128,Kl=31,md=63,mi=127,XT=2147483647,QT=crypto.getRandomValues.bind(crypto),P0=Math.random,F0=()=>QT(new Uint32Array(1))[0],eA=n=>n[wn(P0()*n.length)],tA="10000000-1000-4000-8000"+-1e11,B0=()=>tA.replace(/[018]/g,n=>(n^F0()&15>>n/4).toString(16)),$0=Number.MAX_SAFE_INTEGER,nA=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&wn(n)===n),rA=String.fromCharCode,iA=n=>n.toLowerCase(),sA=/^\s*/g,oA=n=>n.replace(sA,""),lA=/([A-Z])/g,j0=(n,e)=>oA(n.replace(lA,t=>`${e}${iA(t)}`)),aA=n=>{const e=unescape(encodeURIComponent(n)),t=e.length,r=new Uint8Array(t);for(let i=0;i<t;i++)r[i]=e.codePointAt(i);return r},xo=typeof TextEncoder<"u"?new TextEncoder:null,gd=xo?n=>xo.encode(n):aA;let Co=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Co&&Co.decode(new Uint8Array).length===1&&(Co=null);class ko{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const gt=()=>new ko,cA=n=>{let e=n.cpos;for(let t=0;t<n.bufs.length;t++)e+=n.bufs[t].length;return e},qe=n=>{const e=new Uint8Array(cA(n));let t=0;for(let r=0;r<n.bufs.length;r++){const i=n.bufs[r];e.set(i,t),t+=i.length}return e.set(new Uint8Array(n.cbuf.buffer,0,n.cpos),t),e},uA=(n,e)=>{const t=n.cbuf.length;t-n.cpos<e&&(n.bufs.push(new Uint8Array(n.cbuf.buffer,0,n.cpos)),n.cbuf=new Uint8Array(ar(t,e)*2),n.cpos=0)},yt=(n,e)=>{const t=n.cbuf.length;n.cpos===t&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(t*2),n.cpos=0),n.cbuf[n.cpos++]=e},So=yt,ae=(n,e)=>{for(;e>mi;)yt(n,Yt|mi&e),e=wn(e/128);yt(n,mi&e)},yd=(n,e)=>{const t=R0(e);for(t&&(e=-e),yt(n,(e>md?Yt:0)|(t?cr:0)|md&e),e=wn(e/64);e>0;)yt(n,(e>mi?Yt:0)|mi&e),e=wn(e/128)},bd=new Uint8Array(3e4),dA=bd.length/3,fA=(n,e)=>{if(e.length<dA){const t=xo.encodeInto(e,bd).written||0;ae(n,t);for(let r=0;r<t;r++)yt(n,bd[r])}else Xe(n,gd(e))},hA=(n,e)=>{const t=unescape(encodeURIComponent(e)),r=t.length;ae(n,r);for(let i=0;i<r;i++)yt(n,t.codePointAt(i))},jn=xo&&xo.encodeInto?fA:hA,Jl=(n,e)=>{const t=n.cbuf.length,r=n.cpos,i=Ir(t-r,e.length),s=e.length-i;n.cbuf.set(e.subarray(0,i),r),n.cpos+=i,s>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(ar(t*2,s)),n.cbuf.set(e.subarray(i)),n.cpos=s)},Xe=(n,e)=>{ae(n,e.byteLength),Jl(n,e)},vd=(n,e)=>{uA(n,e);const t=new DataView(n.cbuf.buffer,n.cpos,e);return n.cpos+=e,t},pA=(n,e)=>vd(n,4).setFloat32(0,e,!1),mA=(n,e)=>vd(n,8).setFloat64(0,e,!1),gA=(n,e)=>vd(n,8).setBigInt64(0,e,!1),H0=new DataView(new ArrayBuffer(4)),yA=n=>(H0.setFloat32(0,n),H0.getFloat32(0)===n),ts=(n,e)=>{switch(typeof e){case"string":yt(n,119),jn(n,e);break;case"number":nA(e)&&Wl(e)<=XT?(yt(n,125),yd(n,e)):yA(e)?(yt(n,124),pA(n,e)):(yt(n,123),mA(n,e));break;case"bigint":yt(n,122),gA(n,e);break;case"object":if(e===null)yt(n,126);else if(ud(e)){yt(n,117),ae(n,e.length);for(let t=0;t<e.length;t++)ts(n,e[t])}else if(e instanceof Uint8Array)yt(n,116),Xe(n,e);else{yt(n,118);const t=Object.keys(e);ae(n,t.length);for(let r=0;r<t.length;r++){const i=t[r];jn(n,i),ts(n,e[i])}}break;case"boolean":yt(n,e?120:121);break;default:yt(n,127)}};class V0 extends ko{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&ae(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const z0=n=>{n.count>0&&(yd(n.encoder,n.count===1?n.s:-n.s),n.count>1&&ae(n.encoder,n.count-2))};class Gl{constructor(){this.encoder=new ko,this.s=0,this.count=0}write(e){this.s===e?this.count++:(z0(this),this.count=1,this.s=e)}toUint8Array(){return z0(this),qe(this.encoder)}}const U0=n=>{if(n.count>0){const e=n.diff*2+(n.count===1?0:1);yd(n.encoder,e),n.count>1&&ae(n.encoder,n.count-2)}};class wd{constructor(){this.encoder=new ko,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(U0(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return U0(this),qe(this.encoder)}}class bA{constructor(){this.sarr=[],this.s="",this.lensE=new Gl}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new ko;return this.sarr.push(this.s),this.s="",jn(e,this.sarr.join("")),Jl(e,this.lensE.toUint8Array()),qe(e)}}const W0=$n("Unexpected end of array"),q0=$n("Integer out of Range");class Yl{constructor(e){this.arr=e,this.pos=0}}const Hn=n=>new Yl(n),vA=n=>n.pos!==n.arr.length,wA=(n,e)=>{const t=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,e);return n.pos+=e,t},bt=n=>wA(n,he(n)),gi=n=>n.arr[n.pos++],he=n=>{let e=0,t=1;const r=n.arr.length;for(;n.pos<r;){const i=n.arr[n.pos++];if(e=e+(i&mi)*t,t*=128,i<Yt)return e;if(e>$0)throw q0}throw W0},xd=n=>{let e=n.arr[n.pos++],t=e&md,r=64;const i=(e&cr)>0?-1:1;if(!(e&Yt))return i*t;const s=n.arr.length;for(;n.pos<s;){if(e=n.arr[n.pos++],t=t+(e&mi)*r,r*=128,e<Yt)return i*t;if(t>$0)throw q0}throw W0},ur=Co?n=>Co.decode(bt(n)):n=>{let e=he(n);if(e===0)return"";{let t=String.fromCodePoint(gi(n));if(--e<100)for(;e--;)t+=String.fromCodePoint(gi(n));else for(;e>0;){const r=e<1e4?e:1e4,i=n.arr.subarray(n.pos,n.pos+r);n.pos+=r,t+=String.fromCodePoint.apply(null,i),e-=r}return decodeURIComponent(escape(t))}},Cd=(n,e)=>{const t=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,e);return n.pos+=e,t},xA=[n=>{},n=>null,xd,n=>Cd(n,4).getFloat32(0,!1),n=>Cd(n,8).getFloat64(0,!1),n=>Cd(n,8).getBigInt64(0,!1),n=>!1,n=>!0,ur,n=>{const e=he(n),t={};for(let r=0;r<e;r++){const i=ur(n);t[i]=ns(n)}return t},n=>{const e=he(n),t=[];for(let r=0;r<e;r++)t.push(ns(n));return t},bt],ns=n=>xA[127-gi(n)](n);class K0 extends Yl{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),vA(this)?this.count=he(this)+1:this.count=-1),this.count--,this.s}}class Zl extends Yl{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=xd(this);const e=R0(this.s);this.count=1,e&&(this.s=-this.s,this.count=he(this)+2)}return this.count--,this.s}}class kd extends Yl{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const e=xd(this),t=e&1;this.diff=wn(e/2),this.count=1,t&&(this.count=he(this)+2)}return this.s+=this.diff,this.count--,this.s}}class CA{constructor(e){this.decoder=new Zl(e),this.str=ur(this.decoder),this.spos=0}read(){const e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}}const J0=n=>n===void 0?null:n;class kA{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}}let G0=new kA,Sd=!0;try{typeof localStorage<"u"&&localStorage&&(G0=localStorage,Sd=!1)}catch{}const Y0=G0,SA=n=>Sd||addEventListener("storage",n),EA=n=>Sd||removeEventListener("storage",n),TA=Object.assign,Ed=Object.keys,AA=(n,e)=>{for(const t in n)e(n[t],t)},Z0=n=>Ed(n).length,X0=n=>Ed(n).length,MA=n=>{for(const e in n)return!1;return!0},OA=(n,e)=>{for(const t in n)if(!e(n[t],t))return!1;return!0},Q0=(n,e)=>Object.prototype.hasOwnProperty.call(n,e),_A=(n,e)=>n===e||X0(n)===X0(e)&&OA(n,(t,r)=>(t!==void 0||Q0(e,r))&&e[r]===t),Td=(n,e,t=0)=>{try{for(;t<n.length;t++)n[t](...e)}finally{t<n.length&&Td(n,e,t+1)}},NA=()=>{},DA=n=>n,RA=(n,e)=>n===e,Eo=(n,e)=>{if(n==null||e==null)return RA(n,e);if(n.constructor!==e.constructor)return!1;if(n===e)return!0;switch(n.constructor){case ArrayBuffer:n=new Uint8Array(n),e=new Uint8Array(e);case Uint8Array:{if(n.byteLength!==e.byteLength)return!1;for(let t=0;t<n.length;t++)if(n[t]!==e[t])return!1;break}case Set:{if(n.size!==e.size)return!1;for(const t of n)if(!e.has(t))return!1;break}case Map:{if(n.size!==e.size)return!1;for(const t of n.keys())if(!e.has(t)||!Eo(n.get(t),e.get(t)))return!1;break}case Object:if(Z0(n)!==Z0(e))return!1;for(const t in n)if(!Q0(n,t)||!Eo(n[t],e[t]))return!1;break;case Array:if(n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(!Eo(n[t],e[t]))return!1;break;default:return!1}return!0},LA=(n,e)=>e.includes(n),rs=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",Ad=typeof window<"u"&&typeof document<"u"&&!rs;let Vn;const IA=()=>{if(Vn===void 0)if(rs){Vn=Lt();const n=process.argv;let e=null;for(let t=0;t<n.length;t++){const r=n[t];r[0]==="-"?(e!==null&&Vn.set(e,""),e=r):e!==null&&(Vn.set(e,r),e=null)}e!==null&&Vn.set(e,"")}else typeof location=="object"?(Vn=Lt(),(location.search||"?").slice(1).split("&").forEach(n=>{if(n.length!==0){const[e,t]=n.split("=");Vn.set(`--${j0(e,"-")}`,t),Vn.set(`-${j0(e,"-")}`,t)}})):Vn=Lt();return Vn},Md=n=>IA().has(n),Xl=n=>J0(rs?process.env[n.toUpperCase().replaceAll("-","_")]:Y0.getItem(n));(n=>Md("--"+n)||Xl(n)!==null)("production");const ey=rs&&LA(process.env.FORCE_COLOR,["true","1","2"]),PA=!Md("--no-colors")&&(!rs||process.stdout.isTTY||ey)&&(!rs||Md("--color")||ey||Xl("COLORTERM")!==null||(Xl("TERM")||"").includes("color"));class FA{constructor(e,t){this.left=e,this.right=t}}const dr=(n,e)=>new FA(n,e),BA=typeof document<"u"?document:{};typeof DOMParser<"u"&&new DOMParser;const $A=n=>UT(n,(e,t)=>`${t}:${e};`).join(""),jA=JSON.stringify,HA=(n=>class{constructor(t){this._=t}destroy(){n(this._)}})(clearTimeout),Od=(n,e)=>new HA(setTimeout(e,n)),fr=Symbol,un=fr(),yi=fr(),ty=fr(),_d=fr(),ny=fr(),ry=fr(),iy=fr(),Ql=fr(),ea=fr(),VA=n=>{var r;n.length===1&&((r=n[0])==null?void 0:r.constructor)===Function&&(n=n[0]());const e=[];let t=0;for(;t<n.length;t++){const i=n[t];i===void 0||i.constructor===String||i.constructor===Number||i.constructor===Object&&e.push(JSON.stringify(i))}return e},sy=[ny,iy,Ql,ty];let Nd=0,oy=Bn();const zA=(n,e)=>{const t=sy[Nd],r=Xl("log"),i=r!==null&&(r==="*"||r==="true"||new RegExp(r,"gi").test(e));return Nd=(Nd+1)%sy.length,e+=": ",i?(...s)=>{var a;s.length===1&&((a=s[0])==null?void 0:a.constructor)===Function&&(s=s[0]());const o=Bn(),l=o-oy;oy=o,n(t,e,ea,...s.map(c=>{switch(c!=null&&c.constructor===Uint8Array&&(c=Array.from(c)),typeof c){case"string":case"symbol":return c;default:return jA(c)}}),t," +"+l+"ms")}:NA},UA={[un]:dr("font-weight","bold"),[yi]:dr("font-weight","normal"),[ty]:dr("color","blue"),[ny]:dr("color","green"),[_d]:dr("color","grey"),[ry]:dr("color","red"),[iy]:dr("color","purple"),[Ql]:dr("color","orange"),[ea]:dr("color","black")},ly=PA?n=>{var o;n.length===1&&((o=n[0])==null?void 0:o.constructor)===Function&&(n=n[0]());const e=[],t=[],r=Lt();let i=[],s=0;for(;s<n.length;s++){const l=n[s],a=UA[l];if(a!==void 0)r.set(a.left,a.right);else{if(l===void 0)break;if(l.constructor===String||l.constructor===Number){const c=$A(r);s>0||c.length>0?(e.push("%c"+l),t.push(c)):e.push(l)}else break}}for(s>0&&(i=t,i.unshift(e.join("")));s<n.length;s++){const l=n[s];l instanceof Symbol||i.push(l)}return i}:VA,ay=(...n)=>{console.log(...ly(n)),cy.forEach(e=>e.print(n))},WA=(...n)=>{console.warn(...ly(n)),n.unshift(Ql),cy.forEach(e=>e.print(n))},cy=or(),qA=n=>zA(ay,n),uy=n=>new Promise(n);Promise.all.bind(Promise);const KA=n=>Promise.reject(n),Dd=n=>Promise.resolve(n),dy=n=>new Uint8Array(n),JA=(n,e,t)=>new Uint8Array(n,e,t),GA=n=>new Uint8Array(n),YA=n=>{let e="";for(let t=0;t<n.byteLength;t++)e+=rA(n[t]);return btoa(e)},ZA=n=>Buffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),XA=n=>{const e=atob(n),t=dy(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t},QA=n=>{const e=Buffer.from(n,"base64");return JA(e.buffer,e.byteOffset,e.byteLength)},fy=Ad?YA:ZA,hy=Ad?XA:QA,eM=n=>{const e=dy(n.byteLength);return e.set(n),e},py=new Map;class tM{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:hy(t.newValue||"")}),SA(this._onChange)}postMessage(e){Y0.setItem(this.room,fy(GA(e)))}close(){EA(this._onChange)}}const nM=typeof BroadcastChannel>"u"?tM:BroadcastChannel,Rd=n=>zt(py,n,()=>{const e=or(),t=new nM(n);return t.onmessage=r=>e.forEach(i=>i(r.data,"broadcastchannel")),{bc:t,subs:e}}),rM=(n,e)=>(Rd(n).subs.add(e),e),iM=(n,e)=>{const t=Rd(n),r=t.subs.delete(e);return r&&t.subs.size===0&&(t.bc.close(),py.delete(n)),r},sM=(n,e,t=null)=>{const r=Rd(n);r.bc.postMessage(e),r.subs.forEach(i=>i(e,t))},my=()=>{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}},gy=n=>({[Symbol.iterator](){return this},next:n}),oM=(n,e)=>gy(()=>{let t;do t=n.next();while(!t.done&&!e(t.value));return t}),Ld=(n,e)=>gy(()=>{const{done:t,value:r}=n.next();return{done:t,value:t?void 0:e(r)}});class Id{constructor(e,t){this.clock=e,this.len=t}}class is{constructor(){this.clients=new Map}}const Pr=(n,e,t)=>e.clients.forEach((r,i)=>{const s=n.doc.store.clients.get(i);for(let o=0;o<r.length;o++){const l=r[o];Fy(n,s,l.clock,l.len,t)}}),lM=(n,e)=>{let t=0,r=n.length-1;for(;t<=r;){const i=wn((t+r)/2),s=n[i],o=s.clock;if(o<=e){if(e<o+s.len)return i;t=i+1}else r=i-1}return null},ss=(n,e)=>{const t=n.clients.get(e.client);return t!==void 0&&lM(t,e.clock)!==null},Pd=n=>{n.clients.forEach(e=>{e.sort((i,s)=>i.clock-s.clock);let t,r;for(t=1,r=1;t<e.length;t++){const i=e[r-1],s=e[t];i.clock+i.len>=s.clock?i.len=ar(i.len,s.clock+s.len-i.clock):(r<t&&(e[r]=s),r++)}e.length=r})},Fd=n=>{const e=new is;for(let t=0;t<n.length;t++)n[t].clients.forEach((r,i)=>{if(!e.clients.has(i)){const s=r.slice();for(let o=t+1;o<n.length;o++)qT(s,n[o].clients.get(i)||[]);e.clients.set(i,s)}});return Pd(e),e},To=(n,e,t,r)=>{zt(n.clients,e,()=>[]).push(new Id(t,r))},yy=()=>new is,by=n=>{const e=yy();return n.clients.forEach((t,r)=>{const i=[];for(let s=0;s<t.length;s++){const o=t[s];if(o.deleted){const l=o.id.clock;let a=o.length;if(s+1<t.length)for(let c=t[s+1];s+1<t.length&&c.deleted;c=t[++s+1])a+=c.length;i.push(new Id(l,a))}}i.length>0&&e.clients.set(r,i)}),e},ls=(n,e)=>{ae(n.restEncoder,e.clients.size),lr(e.clients.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{n.resetDsCurVal(),ae(n.restEncoder,t);const i=r.length;ae(n.restEncoder,i);for(let s=0;s<i;s++){const o=r[s];n.writeDsClock(o.clock),n.writeDsLen(o.len)}})},Bd=n=>{const e=new is,t=he(n.restDecoder);for(let r=0;r<t;r++){n.resetDsCurVal();const i=he(n.restDecoder),s=he(n.restDecoder);if(s>0){const o=zt(e.clients,i,()=>[]);for(let l=0;l<s;l++)o.push(new Id(n.readDsClock(),n.readDsLen()))}}return e},vy=(n,e,t)=>{const r=new is,i=he(n.restDecoder);for(let s=0;s<i;s++){n.resetDsCurVal();const o=he(n.restDecoder),l=he(n.restDecoder),a=t.clients.get(o)||[],c=rt(t,o);for(let u=0;u<l;u++){const d=n.readDsClock(),f=d+n.readDsLen();if(d<c){c<f&&To(r,o,c,f-c);let h=zn(a,d),p=a[h];for(!p.deleted&&p.id.clock<d&&(a.splice(h+1,0,ha(e,p,d-p.id.clock)),h++);h<a.length&&(p=a[h++],p.id.clock<f);)p.deleted||(f<p.id.clock+p.length&&a.splice(h,0,ha(e,p,f-p.id.clock)),p.delete(e))}else To(r,o,d,f-d)}}if(r.clients.size>0){const s=new bi;return ae(s.restEncoder,0),ls(s,r),s.toUint8Array()}return null},wy=F0;class as extends dd{constructor({guid:e=B0(),collectionid:t=null,gc:r=!0,gcFilter:i=()=>!0,meta:s=null,autoLoad:o=!1,shouldLoad:l=!0}={}){super(),this.gc=r,this.gcFilter=i,this.clientID=wy(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Ly,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=o,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.whenLoaded=uy(c=>{this.on("load",()=>{this.isLoaded=!0,c(this)})});const a=()=>uy(c=>{const u=d=>{(d===void 0||d===!0)&&(this.off("sync",u),c())};this.on("sync",u)});this.on("sync",c=>{c===!1&&this.isSynced&&(this.whenSynced=a()),this.isSynced=c===void 0||c===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=a()}load(){const e=this._item;e!==null&&!this.shouldLoad&&Be(e.parent.doc,t=>{t.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(lr(this.subdocs).map(e=>e.guid))}transact(e,t=null){return Be(this,e,t)}get(e,t=Et){const r=zt(this.share,e,()=>{const s=new t;return s._integrate(this,null),s}),i=r.constructor;if(t!==Et&&i!==t)if(i===Et){const s=new t;s._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=s}),s._start=r._start;for(let o=s._start;o!==null;o=o.right)o.parent=s;return s._length=r._length,this.share.set(e,s),s._integrate(this,null),s}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return r}getArray(e=""){return this.get(e,hs)}getText(e=""){return this.get(e,wi)}getMap(e=""){return this.get(e,ps)}getXmlElement(e=""){return this.get(e,It)}getXmlFragment(e=""){return this.get(e,xi)}toJSON(){const e={};return this.share.forEach((t,r)=>{e[r]=t.toJSON()}),e}destroy(){lr(this.subdocs).forEach(t=>t.destroy());const e=this._item;if(e!==null){this._item=null;const t=e.content;t.doc=new as({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,Be(e.parent.doc,r=>{const i=t.doc;e.deleted||r.subdocsAdded.add(i),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class xy{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return he(this.restDecoder)}readDsLen(){return he(this.restDecoder)}}class Cy extends xy{readLeftID(){return pe(he(this.restDecoder),he(this.restDecoder))}readRightID(){return pe(he(this.restDecoder),he(this.restDecoder))}readClient(){return he(this.restDecoder)}readInfo(){return gi(this.restDecoder)}readString(){return ur(this.restDecoder)}readParentInfo(){return he(this.restDecoder)===1}readTypeRef(){return he(this.restDecoder)}readLen(){return he(this.restDecoder)}readAny(){return ns(this.restDecoder)}readBuf(){return eM(bt(this.restDecoder))}readJSON(){return JSON.parse(ur(this.restDecoder))}readKey(){return ur(this.restDecoder)}}class aM{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=he(this.restDecoder),this.dsCurrVal}readDsLen(){const e=he(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class cs extends aM{constructor(e){super(e),this.keys=[],he(e),this.keyClockDecoder=new kd(bt(e)),this.clientDecoder=new Zl(bt(e)),this.leftClockDecoder=new kd(bt(e)),this.rightClockDecoder=new kd(bt(e)),this.infoDecoder=new K0(bt(e),gi),this.stringDecoder=new CA(bt(e)),this.parentInfoDecoder=new K0(bt(e),gi),this.typeRefDecoder=new Zl(bt(e)),this.lenDecoder=new Zl(bt(e))}readLeftID(){return new us(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new us(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return ns(this.restDecoder)}readBuf(){return bt(this.restDecoder)}readJSON(){return ns(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{const t=this.stringDecoder.read();return this.keys.push(t),t}}}class ky{constructor(){this.restEncoder=gt()}toUint8Array(){return qe(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){ae(this.restEncoder,e)}writeDsLen(e){ae(this.restEncoder,e)}}class Ao extends ky{writeLeftID(e){ae(this.restEncoder,e.client),ae(this.restEncoder,e.clock)}writeRightID(e){ae(this.restEncoder,e.client),ae(this.restEncoder,e.clock)}writeClient(e){ae(this.restEncoder,e)}writeInfo(e){So(this.restEncoder,e)}writeString(e){jn(this.restEncoder,e)}writeParentInfo(e){ae(this.restEncoder,e?1:0)}writeTypeRef(e){ae(this.restEncoder,e)}writeLen(e){ae(this.restEncoder,e)}writeAny(e){ts(this.restEncoder,e)}writeBuf(e){Xe(this.restEncoder,e)}writeJSON(e){jn(this.restEncoder,JSON.stringify(e))}writeKey(e){jn(this.restEncoder,e)}}class Sy{constructor(){this.restEncoder=gt(),this.dsCurrVal=0}toUint8Array(){return qe(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,ae(this.restEncoder,t)}writeDsLen(e){e===0&&cn(),ae(this.restEncoder,e-1),this.dsCurrVal+=e}}class bi extends Sy{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new wd,this.clientEncoder=new Gl,this.leftClockEncoder=new wd,this.rightClockEncoder=new wd,this.infoEncoder=new V0(So),this.stringEncoder=new bA,this.parentInfoEncoder=new V0(So),this.typeRefEncoder=new Gl,this.lenEncoder=new Gl}toUint8Array(){const e=gt();return ae(e,0),Xe(e,this.keyClockEncoder.toUint8Array()),Xe(e,this.clientEncoder.toUint8Array()),Xe(e,this.leftClockEncoder.toUint8Array()),Xe(e,this.rightClockEncoder.toUint8Array()),Xe(e,qe(this.infoEncoder)),Xe(e,this.stringEncoder.toUint8Array()),Xe(e,qe(this.parentInfoEncoder)),Xe(e,this.typeRefEncoder.toUint8Array()),Xe(e,this.lenEncoder.toUint8Array()),Jl(e,qe(this.restEncoder)),qe(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){ts(this.restEncoder,e)}writeBuf(e){Xe(this.restEncoder,e)}writeJSON(e){ts(this.restEncoder,e)}writeKey(e){const t=this.keyMap.get(e);t===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}}const cM=(n,e,t,r)=>{r=ar(r,e[0].id.clock);const i=zn(e,r);ae(n.restEncoder,e.length-i),n.writeClient(t),ae(n.restEncoder,r);const s=e[i];s.write(n,r-s.id.clock);for(let o=i+1;o<e.length;o++)e[o].write(n,0)},$d=(n,e,t)=>{const r=new Map;t.forEach((i,s)=>{rt(e,s)>i&&r.set(s,i)}),Do(e).forEach((i,s)=>{t.has(s)||r.set(s,0)}),ae(n.restEncoder,r.size),lr(r.entries()).sort((i,s)=>s[0]-i[0]).forEach(([i,s])=>{cM(n,e.clients.get(i),i,s)})},uM=(n,e)=>{const t=Lt(),r=he(n.restDecoder);for(let i=0;i<r;i++){const s=he(n.restDecoder),o=new Array(s),l=n.readClient();let a=he(n.restDecoder);t.set(l,{i:0,refs:o});for(let c=0;c<s;c++){const u=n.readInfo();switch(Kl&u){case 0:{const d=n.readLen();o[c]=new dn(pe(l,a),d),a+=d;break}case 10:{const d=he(n.restDecoder);o[c]=new fn(pe(l,a),d),a+=d;break}default:{const d=(u&(cr|Yt))===0,f=new ze(pe(l,a),null,(u&Yt)===Yt?n.readLeftID():null,null,(u&cr)===cr?n.readRightID():null,d?n.readParentInfo()?e.get(n.readString()):n.readLeftID():null,d&&(u&wo)===wo?n.readString():null,pb(n,u));o[c]=f,a+=f.length}}}}return t},dM=(n,e,t)=>{const r=[];let i=lr(t.keys()).sort((h,p)=>h-p);if(i.length===0)return null;const s=()=>{if(i.length===0)return null;let h=t.get(i[i.length-1]);for(;h.refs.length===h.i;)if(i.pop(),i.length>0)h=t.get(i[i.length-1]);else return null;return h};let o=s();if(o===null)return null;const l=new Ly,a=new Map,c=(h,p)=>{const g=a.get(h);(g==null||g>p)&&a.set(h,p)};let u=o.refs[o.i++];const d=new Map,f=()=>{for(const h of r){const p=h.id.client,g=t.get(p);g?(g.i--,l.clients.set(p,g.refs.slice(g.i)),t.delete(p),g.i=0,g.refs=[]):l.clients.set(p,[h]),i=i.filter(v=>v!==p)}r.length=0};for(;;){if(u.constructor!==fn){const p=zt(d,u.id.client,()=>rt(e,u.id.client))-u.id.clock;if(p<0)r.push(u),c(u.id.client,u.id.clock-1),f();else{const g=u.getMissing(n,e);if(g!==null){r.push(u);const v=t.get(g)||{refs:[],i:0};if(v.refs.length===v.i)c(g,rt(e,g)),f();else{u=v.refs[v.i++];continue}}else(p===0||p<u.length)&&(u.integrate(n,p),d.set(u.id.client,u.id.clock+u.length))}}if(r.length>0)u=r.pop();else if(o!==null&&o.i<o.refs.length)u=o.refs[o.i++];else{if(o=s(),o===null)break;u=o.refs[o.i++]}}if(l.clients.size>0){const h=new bi;return $d(h,l,new Map),ae(h.restEncoder,0),{missing:a,update:h.toUint8Array()}}return null},fM=(n,e)=>$d(n,e.doc.store,e.beforeState),hM=(n,e,t,r=new cs(n))=>Be(e,i=>{i.local=!1;let s=!1;const o=i.doc,l=o.store,a=uM(r,o),c=dM(i,l,a),u=l.pendingStructs;if(u){for(const[f,h]of u.missing)if(h<rt(l,f)){s=!0;break}if(c){for(const[f,h]of c.missing){const p=u.missing.get(f);(p==null||p>h)&&u.missing.set(f,h)}u.update=ra([u.update,c.update])}}else l.pendingStructs=c;const d=vy(r,i,l);if(l.pendingDs){const f=new cs(Hn(l.pendingDs));he(f.restDecoder);const h=vy(f,i,l);d&&h?l.pendingDs=ra([d,h]):l.pendingDs=d||h}else l.pendingDs=d;if(s){const f=l.pendingStructs.update;l.pendingStructs=null,Ey(i.doc,f)}},t,!1),Ey=(n,e,t,r=cs)=>{const i=Hn(e);hM(i,n,t,new r(i))},pM=(n,e,t)=>Ey(n,e,t,Cy),mM=(n,e,t=new Map)=>{$d(n,e.store,t),ls(n,by(e.store))},gM=(n,e=new Uint8Array([0]),t=new bi)=>{const r=Ty(e);mM(t,n,r);const i=[t.toUint8Array()];if(n.store.pendingDs&&i.push(n.store.pendingDs),n.store.pendingStructs&&i.push(IM(n.store.pendingStructs.update,e)),i.length>1){if(t.constructor===Ao)return RM(i.map((s,o)=>o===0?s:FM(s)));if(t.constructor===bi)return ra(i)}return i[0]},yM=(n,e)=>gM(n,e,new Ao),bM=n=>{const e=new Map,t=he(n.restDecoder);for(let r=0;r<t;r++){const i=he(n.restDecoder),s=he(n.restDecoder);e.set(i,s)}return e},Ty=n=>bM(new xy(Hn(n))),Ay=(n,e)=>(ae(n.restEncoder,e.size),lr(e.entries()).sort((t,r)=>r[0]-t[0]).forEach(([t,r])=>{ae(n.restEncoder,t),ae(n.restEncoder,r)}),n),vM=(n,e)=>Ay(n,Do(e.store)),wM=(n,e=new Sy)=>(n instanceof Map?Ay(e,n):vM(e,n),e.toUint8Array()),xM=n=>wM(n,new ky);class CM{constructor(){this.l=[]}}const My=()=>new CM,Oy=(n,e)=>n.l.push(e),_y=(n,e)=>{const t=n.l,r=t.length;n.l=t.filter(i=>e!==i),r===n.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Ny=(n,e,t)=>Td(n.l,[e,t]);class us{constructor(e,t){this.client=e,this.clock=t}}const ds=(n,e)=>n===e||n!==null&&e!==null&&n.client===e.client&&n.clock===e.clock,pe=(n,e)=>new us(n,e),Mo=n=>{for(const[e,t]of n.doc.share.entries())if(t===n)return e;throw cn()},Oo=(n,e)=>{for(;e!==null;){if(e.parent===n)return!0;e=e.parent._item}return!1};class _o{constructor(e,t,r,i=0){this.type=e,this.tname=t,this.item=r,this.assoc=i}}const No=n=>new _o(n.type==null?null:pe(n.type.client,n.type.clock),n.tname||null,n.item==null?null:pe(n.item.client,n.item.clock),n.assoc==null?0:n.assoc);class kM{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}}const SM=(n,e,t=0)=>new kM(n,e,t),ta=(n,e,t)=>{let r=null,i=null;return n._item===null?i=Mo(n):r=pe(n._item.id.client,n._item.id.clock),new _o(r,i,e,t)},jd=(n,e,t=0)=>{let r=n._start;if(t<0){if(e===0)return ta(n,null,t);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return ta(n,pe(r.id.client,r.id.clock+e),t);e-=r.length}if(r.right===null&&t<0)return ta(n,r.lastId,t);r=r.right}return ta(n,null,t)},EM=(n,e,t=!0)=>{const r=e.store,i=n.item,s=n.type,o=n.tname,l=n.assoc;let a=null,c=0;if(i!==null){if(rt(r,i.client)<=i.clock)return null;const u=t?ef(r,i):{item:fs(r,i),diff:0},d=u.item;if(!(d instanceof ze))return null;if(a=d.parent,a._item===null||!a._item.deleted){c=d.deleted||!d.countable?0:u.diff+(l>=0?0:1);let f=d.left;for(;f!==null;)!f.deleted&&f.countable&&(c+=f.length),f=f.left}}else{if(o!==null)a=e.get(o);else if(s!==null){if(rt(r,s.client)<=s.clock)return null;const{item:u}=t?ef(r,s):{item:fs(r,s)};if(u instanceof ze&&u.content instanceof kn)a=u.content.type;else return null}else throw cn();l>=0?c=a._length:c=0}return SM(a,c,n.assoc)},Dy=(n,e)=>n===e||n!==null&&e!==null&&n.tname===e.tname&&ds(n.item,e.item)&&ds(n.type,e.type)&&n.assoc===e.assoc;class Hd{constructor(e,t){this.ds=e,this.sv=t}}const Ry=(n,e)=>new Hd(n,e),TM=n=>Ry(by(n.store),Do(n.store)),vi=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&(e.sv.get(n.id.client)||0)>n.id.clock&&!ss(e.ds,n.id),Vd=(n,e)=>{const t=zt(n.meta,Vd,or),r=n.doc.store;t.has(e)||(e.sv.forEach((i,s)=>{i<rt(r,s)&&Ut(n,pe(s,i))}),Pr(n,e.ds,i=>{}),t.add(e))};class Ly{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Do=n=>{const e=new Map;return n.clients.forEach((t,r)=>{const i=t[t.length-1];e.set(r,i.id.clock+i.length)}),e},rt=(n,e)=>{const t=n.clients.get(e);if(t===void 0)return 0;const r=t[t.length-1];return r.id.clock+r.length},Iy=(n,e)=>{let t=n.clients.get(e.id.client);if(t===void 0)t=[],n.clients.set(e.id.client,t);else{const r=t[t.length-1];if(r.id.clock+r.length!==e.id.clock)throw cn()}t.push(e)},zn=(n,e)=>{let t=0,r=n.length-1,i=n[r],s=i.id.clock;if(s===e)return r;let o=wn(e/(s+i.length-1)*r);for(;t<=r;){if(i=n[o],s=i.id.clock,s<=e){if(e<s+i.length)return o;t=o+1}else r=o-1;o=wn((t+r)/2)}throw cn()},fs=(n,e)=>{const t=n.clients.get(e.client);return t[zn(t,e.clock)]},zd=(n,e,t)=>{const r=zn(e,t),i=e[r];return i.id.clock<t&&i instanceof ze?(e.splice(r+1,0,ha(n,i,t-i.id.clock)),r+1):r},Ut=(n,e)=>{const t=n.doc.store.clients.get(e.client);return t[zd(n,t,e.clock)]},Py=(n,e,t)=>{const r=e.clients.get(t.client),i=zn(r,t.clock),s=r[i];return t.clock!==s.id.clock+s.length-1&&s.constructor!==dn&&r.splice(i+1,0,ha(n,s,t.clock-s.id.clock+1)),s},AM=(n,e,t)=>{const r=n.clients.get(e.id.client);r[zn(r,e.id.clock)]=t},Fy=(n,e,t,r,i)=>{if(r===0)return;const s=t+r;let o=zd(n,e,t),l;do l=e[o++],s<l.id.clock+l.length&&zd(n,e,s),i(l);while(o<e.length&&e[o].id.clock<s)};class MM{constructor(e,t,r){this.doc=e,this.deleteSet=new is,this.beforeState=Do(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=r,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const By=(n,e)=>e.deleteSet.clients.size===0&&!WT(e.afterState,(t,r)=>e.beforeState.get(r)!==t)?!1:(Pd(e.deleteSet),fM(n,e),ls(n,e.deleteSet),!0),$y=(n,e,t)=>{const r=e._item;(r===null||r.id.clock<(n.beforeState.get(r.id.client)||0)&&!r.deleted)&&zt(n.changed,e,or).add(t)},na=(n,e)=>{let t=n[e],r=n[e-1],i=e;for(;i>0;t=r,r=n[--i-1]){if(r.deleted===t.deleted&&r.constructor===t.constructor&&r.mergeWith(t)){t instanceof ze&&t.parentSub!==null&&t.parent._map.get(t.parentSub)===t&&t.parent._map.set(t.parentSub,r);continue}break}const s=e-i;return s&&n.splice(e+1-s,s),s},OM=(n,e,t)=>{for(const[r,i]of n.clients.entries()){const s=e.clients.get(r);for(let o=i.length-1;o>=0;o--){const l=i[o],a=l.clock+l.len;for(let c=zn(s,l.clock),u=s[c];c<s.length&&u.id.clock<a;u=s[++c]){const d=s[c];if(l.clock+l.len<=d.id.clock)break;d instanceof ze&&d.deleted&&!d.keep&&t(d)&&d.gc(e,!1)}}}},_M=(n,e)=>{n.clients.forEach((t,r)=>{const i=e.clients.get(r);for(let s=t.length-1;s>=0;s--){const o=t[s],l=Ir(i.length-1,1+zn(i,o.clock+o.len-1));for(let a=l,c=i[a];a>0&&c.id.clock>=o.clock;c=i[a])a-=1+na(i,a)}})},jy=(n,e)=>{if(e<n.length){const t=n[e],r=t.doc,i=r.store,s=t.deleteSet,o=t._mergeStructs;try{Pd(s),t.afterState=Do(t.doc.store),r.emit("beforeObserverCalls",[t,r]);const l=[];t.changed.forEach((a,c)=>l.push(()=>{(c._item===null||!c._item.deleted)&&c._callObserver(t,a)})),l.push(()=>{t.changedParentTypes.forEach((a,c)=>{c._dEH.l.length>0&&(c._item===null||!c._item.deleted)&&(a=a.filter(u=>u.target._item===null||!u.target._item.deleted),a.forEach(u=>{u.currentTarget=c,u._path=null}),a.sort((u,d)=>u.path.length-d.path.length),Ny(c._dEH,a,t))})}),l.push(()=>r.emit("afterTransaction",[t,r])),Td(l,[]),t._needFormattingCleanup&&ZM(t)}finally{r.gc&&OM(s,i,r.gcFilter),_M(s,i),t.afterState.forEach((u,d)=>{const f=t.beforeState.get(d)||0;if(f!==u){const h=i.clients.get(d),p=ar(zn(h,f),1);for(let g=h.length-1;g>=p;)g-=1+na(h,g)}});for(let u=o.length-1;u>=0;u--){const{client:d,clock:f}=o[u].id,h=i.clients.get(d),p=zn(h,f);p+1<h.length&&na(h,p+1)>1||p>0&&na(h,p)}if(!t.local&&t.afterState.get(r.clientID)!==t.beforeState.get(r.clientID)&&(ay(Ql,un,"[yjs] ",yi,ry,"Changed the client-id because another client seems to be using it."),r.clientID=wy()),r.emit("afterTransactionCleanup",[t,r]),r._observers.has("update")){const u=new Ao;By(u,t)&&r.emit("update",[u.toUint8Array(),t.origin,r,t])}if(r._observers.has("updateV2")){const u=new bi;By(u,t)&&r.emit("updateV2",[u.toUint8Array(),t.origin,r,t])}const{subdocsAdded:l,subdocsLoaded:a,subdocsRemoved:c}=t;(l.size>0||c.size>0||a.size>0)&&(l.forEach(u=>{u.clientID=r.clientID,u.collectionid==null&&(u.collectionid=r.collectionid),r.subdocs.add(u)}),c.forEach(u=>r.subdocs.delete(u)),r.emit("subdocs",[{loaded:a,added:l,removed:c},r,t]),c.forEach(u=>u.destroy())),n.length<=e+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,n])):jy(n,e+1)}}},Be=(n,e,t=null,r=!0)=>{const i=n._transactionCleanups;let s=!1,o=null;n._transaction===null&&(s=!0,n._transaction=new MM(n,t,r),i.push(n._transaction),i.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{o=e(n._transaction)}finally{if(s){const l=n._transaction===i[0];n._transaction=null,l&&jy(i,0)}}return o};class NM{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}}const Hy=(n,e,t)=>{Pr(n,t.deletions,r=>{r instanceof ze&&e.scope.some(i=>Oo(i,r))&&tf(r,!1)})},Vy=(n,e,t)=>{let r=null;const i=n.doc,s=n.scope;if(Be(i,o=>{for(;e.length>0&&n.currStackItem===null;){const l=i.store,a=e.pop(),c=new Set,u=[];let d=!1;Pr(o,a.insertions,f=>{if(f instanceof ze){if(f.redone!==null){let{item:h,diff:p}=ef(l,f.id);p>0&&(h=Ut(o,pe(h.id.client,h.id.clock+p))),f=h}!f.deleted&&s.some(h=>Oo(h,f))&&u.push(f)}}),Pr(o,a.deletions,f=>{f instanceof ze&&s.some(h=>Oo(h,f))&&!ss(a.insertions,f.id)&&c.add(f)}),c.forEach(f=>{d=hb(o,f,c,a.insertions,n.ignoreRemoteMapChanges,n)!==null||d});for(let f=u.length-1;f>=0;f--){const h=u[f];n.deleteFilter(h)&&(h.delete(o),d=!0)}n.currStackItem=d?a:null}o.changed.forEach((l,a)=>{l.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),r=o},n),n.currStackItem!=null){const o=r.changedParentTypes;n.emit("stack-item-popped",[{stackItem:n.currStackItem,type:t,changedParentTypes:o,origin:n},n]),n.currStackItem=null}return n.currStackItem};class zy extends dd{constructor(e,{captureTimeout:t=500,captureTransaction:r=a=>!0,deleteFilter:i=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:l=ud(e)?e[0].doc:e.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(e),this.deleteFilter=i,s.add(this),this.trackedOrigins=s,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=t,this.afterTransactionHandler=a=>{if(!this.captureTransaction(a)||!this.scope.some(v=>a.changedParentTypes.has(v))||!this.trackedOrigins.has(a.origin)&&(!a.origin||!this.trackedOrigins.has(a.origin.constructor)))return;const c=this.undoing,u=this.redoing,d=c?this.redoStack:this.undoStack;c?this.stopCapturing():u||this.clear(!1,!0);const f=new is;a.afterState.forEach((v,w)=>{const S=a.beforeState.get(w)||0,x=v-S;x>0&&To(f,w,S,x)});const h=Bn();let p=!1;if(this.lastChange>0&&h-this.lastChange<this.captureTimeout&&d.length>0&&!c&&!u){const v=d[d.length-1];v.deletions=Fd([v.deletions,a.deleteSet]),v.insertions=Fd([v.insertions,f])}else d.push(new NM(a.deleteSet,f)),p=!0;!c&&!u&&(this.lastChange=h),Pr(a,a.deleteSet,v=>{v instanceof ze&&this.scope.some(w=>Oo(w,v))&&tf(v,!0)});const g=[{stackItem:d[d.length-1],origin:a.origin,type:c?"redo":"undo",changedParentTypes:a.changedParentTypes},this];p?this.emit("stack-item-added",g):this.emit("stack-item-updated",g)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(e){e=ud(e)?e:[e],e.forEach(t=>{this.scope.every(r=>r!==t)&&(t.doc!==this.doc&&WA("[yjs#509] Not same Y.Doc"),this.scope.push(t))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(r=>{e&&(this.undoStack.forEach(i=>Hy(r,this,i)),this.undoStack=[]),t&&(this.redoStack.forEach(i=>Hy(r,this,i)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=Vy(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Vy(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}}function*DM(n){const e=he(n.restDecoder);for(let t=0;t<e;t++){const r=he(n.restDecoder),i=n.readClient();let s=he(n.restDecoder);for(let o=0;o<r;o++){const l=n.readInfo();if(l===10){const a=he(n.restDecoder);yield new fn(pe(i,s),a),s+=a}else if(Kl&l){const a=(l&(cr|Yt))===0,c=new ze(pe(i,s),null,(l&Yt)===Yt?n.readLeftID():null,null,(l&cr)===cr?n.readRightID():null,a?n.readParentInfo()?n.readString():n.readLeftID():null,a&&(l&wo)===wo?n.readString():null,pb(n,l));yield c,s+=c.length}else{const a=n.readLen();yield new dn(pe(i,s),a),s+=a}}}}class Ud{constructor(e,t){this.gen=DM(e),this.curr=null,this.done=!1,this.filterSkips=t,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===fn);return this.curr}}class Wd{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}}const RM=n=>ra(n,Cy,Ao),LM=(n,e)=>{if(n.constructor===dn){const{client:t,clock:r}=n.id;return new dn(pe(t,r+e),n.length-e)}else if(n.constructor===fn){const{client:t,clock:r}=n.id;return new fn(pe(t,r+e),n.length-e)}else{const t=n,{client:r,clock:i}=t.id;return new ze(pe(r,i+e),null,pe(r,i+e-1),null,t.rightOrigin,t.parent,t.parentSub,t.content.splice(e))}},ra=(n,e=cs,t=bi)=>{if(n.length===1)return n[0];const r=n.map(u=>new e(Hn(u)));let i=r.map(u=>new Ud(u,!0)),s=null;const o=new t,l=new Wd(o);for(;i=i.filter(f=>f.curr!==null),i.sort((f,h)=>{if(f.curr.id.client===h.curr.id.client){const p=f.curr.id.clock-h.curr.id.clock;return p===0?f.curr.constructor===h.curr.constructor?0:f.curr.constructor===fn?1:-1:p}else return h.curr.id.client-f.curr.id.client}),i.length!==0;){const u=i[0],d=u.curr.id.client;if(s!==null){let f=u.curr,h=!1;for(;f!==null&&f.id.clock+f.length<=s.struct.id.clock+s.struct.length&&f.id.client>=s.struct.id.client;)f=u.next(),h=!0;if(f===null||f.id.client!==d||h&&f.id.clock>s.struct.id.clock+s.struct.length)continue;if(d!==s.struct.id.client)Fr(l,s.struct,s.offset),s={struct:f,offset:0},u.next();else if(s.struct.id.clock+s.struct.length<f.id.clock)if(s.struct.constructor===fn)s.struct.length=f.id.clock+f.length-s.struct.id.clock;else{Fr(l,s.struct,s.offset);const p=f.id.clock-s.struct.id.clock-s.struct.length;s={struct:new fn(pe(d,s.struct.id.clock+s.struct.length),p),offset:0}}else{const p=s.struct.id.clock+s.struct.length-f.id.clock;p>0&&(s.struct.constructor===fn?s.struct.length-=p:f=LM(f,p)),s.struct.mergeWith(f)||(Fr(l,s.struct,s.offset),s={struct:f,offset:0},u.next())}}else s={struct:u.curr,offset:0},u.next();for(let f=u.curr;f!==null&&f.id.client===d&&f.id.clock===s.struct.id.clock+s.struct.length&&f.constructor!==fn;f=u.next())Fr(l,s.struct,s.offset),s={struct:f,offset:0}}s!==null&&(Fr(l,s.struct,s.offset),s=null),qd(l);const a=r.map(u=>Bd(u)),c=Fd(a);return ls(o,c),o.toUint8Array()},IM=(n,e,t=cs,r=bi)=>{const i=Ty(e),s=new r,o=new Wd(s),l=new t(Hn(n)),a=new Ud(l,!1);for(;a.curr;){const u=a.curr,d=u.id.client,f=i.get(d)||0;if(a.curr.constructor===fn){a.next();continue}if(u.id.clock+u.length>f)for(Fr(o,u,ar(f-u.id.clock,0)),a.next();a.curr&&a.curr.id.client===d;)Fr(o,a.curr,0),a.next();else for(;a.curr&&a.curr.id.client===d&&a.curr.id.clock+a.curr.length<=f;)a.next()}qd(o);const c=Bd(l);return ls(s,c),s.toUint8Array()},Uy=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:qe(n.encoder.restEncoder)}),n.encoder.restEncoder=gt(),n.written=0)},Fr=(n,e,t)=>{n.written>0&&n.currClient!==e.id.client&&Uy(n),n.written===0&&(n.currClient=e.id.client,n.encoder.writeClient(e.id.client),ae(n.encoder.restEncoder,e.id.clock+t)),e.write(n.encoder,t),n.written++},qd=n=>{Uy(n);const e=n.encoder.restEncoder;ae(e,n.clientStructs.length);for(let t=0;t<n.clientStructs.length;t++){const r=n.clientStructs[t];ae(e,r.written),Jl(e,r.restEncoder)}},PM=(n,e,t,r)=>{const i=new t(Hn(n)),s=new Ud(i,!1),o=new r,l=new Wd(o);for(let c=s.curr;c!==null;c=s.next())Fr(l,e(c),0);qd(l);const a=Bd(i);return ls(o,a),o.toUint8Array()},FM=n=>PM(n,DA,cs,Ao),Wy="You must not compute changes after the event-handler fired.";class ia{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=BM(this.currentTarget,this.target))}deletes(e){return ss(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw $n(Wy);const e=new Map,t=this.target;this.transaction.changed.get(t).forEach(i=>{if(i!==null){const s=t._map.get(i);let o,l;if(this.adds(s)){let a=s.left;for(;a!==null&&this.adds(a);)a=a.left;if(this.deletes(s))if(a!==null&&this.deletes(a))o="delete",l=cd(a.content.getContent());else return;else a!==null&&this.deletes(a)?(o="update",l=cd(a.content.getContent())):(o="add",l=void 0)}else if(this.deletes(s))o="delete",l=cd(s.content.getContent());else return;e.set(i,{action:o,oldValue:l})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw $n(Wy);const t=this.target,r=or(),i=or(),s=[];if(e={added:r,deleted:i,delta:s,keys:this.keys},this.transaction.changed.get(t).has(null)){let l=null;const a=()=>{l&&s.push(l)};for(let c=t._start;c!==null;c=c.right)c.deleted?this.deletes(c)&&!this.adds(c)&&((l===null||l.delete===void 0)&&(a(),l={delete:0}),l.delete+=c.length,i.add(c)):this.adds(c)?((l===null||l.insert===void 0)&&(a(),l={insert:[]}),l.insert=l.insert.concat(c.content.getContent()),r.add(c)):((l===null||l.retain===void 0)&&(a(),l={retain:0}),l.retain+=c.length);l!==null&&l.retain===void 0&&a()}this._changes=e}return e}}const BM=(n,e)=>{const t=[];for(;e._item!==null&&e!==n;){if(e._item.parentSub!==null)t.unshift(e._item.parentSub);else{let r=0,i=e._item.parent._start;for(;i!==e._item&&i!==null;)i.deleted||r++,i=i.right;t.unshift(r)}e=e._item.parent}return t},qy=80;let Kd=0;class $M{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Kd++}}const jM=n=>{n.timestamp=Kd++},Ky=(n,e,t)=>{n.p.marker=!1,n.p=e,e.marker=!0,n.index=t,n.timestamp=Kd++},HM=(n,e,t)=>{if(n.length>=qy){const r=n.reduce((i,s)=>i.timestamp<s.timestamp?i:s);return Ky(r,e,t),r}else{const r=new $M(e,t);return n.push(r),r}},sa=(n,e)=>{if(n._start===null||e===0||n._searchMarker===null)return null;const t=n._searchMarker.length===0?null:n._searchMarker.reduce((s,o)=>Wl(e-s.index)<Wl(e-o.index)?s:o);let r=n._start,i=0;for(t!==null&&(r=t.p,i=t.index,jM(t));r.right!==null&&i<e;){if(!r.deleted&&r.countable){if(e<i+r.length)break;i+=r.length}r=r.right}for(;r.left!==null&&i>e;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return t!==null&&Wl(t.index-i)<r.parent.length/qy?(Ky(t,r,i),t):HM(n._searchMarker,r,i)},Ro=(n,e,t)=>{for(let r=n.length-1;r>=0;r--){const i=n[r];if(t>0){let s=i.p;for(s.marker=!1;s&&(s.deleted||!s.countable);)s=s.left,s&&!s.deleted&&s.countable&&(i.index-=s.length);if(s===null||s.marker===!0){n.splice(r,1);continue}i.p=s,s.marker=!0}(e<i.index||t>0&&e===i.index)&&(i.index=ar(e,i.index+t))}},oa=(n,e,t)=>{const r=n,i=e.changedParentTypes;for(;zt(i,n,()=>[]).push(t),n._item!==null;)n=n._item.parent;Ny(r._eH,t,e)};class Et{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=My(),this._dEH=My(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw xn()}clone(){throw xn()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){Oy(this._eH,e)}observeDeep(e){Oy(this._dEH,e)}unobserve(e){_y(this._eH,e)}unobserveDeep(e){_y(this._dEH,e)}toJSON(){}}const Jy=(n,e,t)=>{e<0&&(e=n._length+e),t<0&&(t=n._length+t);let r=t-e;const i=[];let s=n._start;for(;s!==null&&r>0;){if(s.countable&&!s.deleted){const o=s.content.getContent();if(o.length<=e)e-=o.length;else{for(let l=e;l<o.length&&r>0;l++)i.push(o[l]),r--;e=0}}s=s.right}return i},Gy=n=>{const e=[];let t=n._start;for(;t!==null;){if(t.countable&&!t.deleted){const r=t.content.getContent();for(let i=0;i<r.length;i++)e.push(r[i])}t=t.right}return e},Yy=(n,e)=>{const t=[];let r=n._start;for(;r!==null;){if(r.countable&&vi(r,e)){const i=r.content.getContent();for(let s=0;s<i.length;s++)t.push(i[s])}r=r.right}return t},Lo=(n,e)=>{let t=0,r=n._start;for(;r!==null;){if(r.countable&&!r.deleted){const i=r.content.getContent();for(let s=0;s<i.length;s++)e(i[s],t++,n)}r=r.right}},Zy=(n,e)=>{const t=[];return Lo(n,(r,i)=>{t.push(e(r,i,n))}),t},VM=n=>{let e=n._start,t=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(t===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};t=e.content.getContent(),r=0,e=e.right}const i=t[r++];return t.length<=r&&(t=null),{done:!1,value:i}}}},Xy=(n,e)=>{const t=sa(n,e);let r=n._start;for(t!==null&&(r=t.p,e-=t.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(e<r.length)return r.content.getContent()[e];e-=r.length}},la=(n,e,t,r)=>{let i=t;const s=n.doc,o=s.clientID,l=s.store,a=t===null?e._start:t.right;let c=[];const u=()=>{c.length>0&&(i=new ze(pe(o,rt(l,o)),i,i&&i.lastId,a,a&&a.id,e,null,new ki(c)),i.integrate(n,0),c=[])};r.forEach(d=>{if(d===null)c.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:c.push(d);break;default:switch(u(),d.constructor){case Uint8Array:case ArrayBuffer:i=new ze(pe(o,rt(l,o)),i,i&&i.lastId,a,a&&a.id,e,null,new Io(new Uint8Array(d))),i.integrate(n,0);break;case as:i=new ze(pe(o,rt(l,o)),i,i&&i.lastId,a,a&&a.id,e,null,new Fo(d)),i.integrate(n,0);break;default:if(d instanceof Et)i=new ze(pe(o,rt(l,o)),i,i&&i.lastId,a,a&&a.id,e,null,new kn(d)),i.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),u()},Qy=()=>$n("Length exceeded!"),eb=(n,e,t,r)=>{if(t>e._length)throw Qy();if(t===0)return e._searchMarker&&Ro(e._searchMarker,t,r.length),la(n,e,null,r);const i=t,s=sa(e,t);let o=e._start;for(s!==null&&(o=s.p,t-=s.index,t===0&&(o=o.prev,t+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(t<=o.length){t<o.length&&Ut(n,pe(o.id.client,o.id.clock+t));break}t-=o.length}return e._searchMarker&&Ro(e._searchMarker,i,r.length),la(n,e,o,r)},zM=(n,e,t)=>{let i=(e._searchMarker||[]).reduce((s,o)=>o.index>s.index?o:s,{index:0,p:e._start}).p;if(i)for(;i.right;)i=i.right;return la(n,e,i,t)},tb=(n,e,t,r)=>{if(r===0)return;const i=t,s=r,o=sa(e,t);let l=e._start;for(o!==null&&(l=o.p,t-=o.index);l!==null&&t>0;l=l.right)!l.deleted&&l.countable&&(t<l.length&&Ut(n,pe(l.id.client,l.id.clock+t)),t-=l.length);for(;r>0&&l!==null;)l.deleted||(r<l.length&&Ut(n,pe(l.id.client,l.id.clock+r)),l.delete(n),r-=l.length),l=l.right;if(r>0)throw Qy();e._searchMarker&&Ro(e._searchMarker,i,-s+r)},aa=(n,e,t)=>{const r=e._map.get(t);r!==void 0&&r.delete(n)},Jd=(n,e,t,r)=>{const i=e._map.get(t)||null,s=n.doc,o=s.clientID;let l;if(r==null)l=new ki([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:l=new ki([r]);break;case Uint8Array:l=new Io(r);break;case as:l=new Fo(r);break;default:if(r instanceof Et)l=new kn(r);else throw new Error("Unexpected content type")}new ze(pe(o,rt(s.store,o)),i,i&&i.lastId,null,null,e,t,l).integrate(n,0)},Gd=(n,e)=>{const t=n._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},nb=n=>{const e={};return n._map.forEach((t,r)=>{t.deleted||(e[r]=t.content.getContent()[t.length-1])}),e},rb=(n,e)=>{const t=n._map.get(e);return t!==void 0&&!t.deleted},UM=(n,e)=>{const t={};return n._map.forEach((r,i)=>{let s=r;for(;s!==null&&(!e.sv.has(s.id.client)||s.id.clock>=(e.sv.get(s.id.client)||0));)s=s.left;s!==null&&vi(s,e)&&(t[i]=s.content.getContent()[s.length-1])}),t},ca=n=>oM(n.entries(),e=>!e[1].deleted);class WM extends ia{constructor(e,t){super(e,t),this._transaction=t}}class hs extends Et{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const t=new hs;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new hs}clone(){const e=new hs;return e.insert(0,this.toArray().map(t=>t instanceof Et?t.clone():t)),e}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}_callObserver(e,t){super._callObserver(e,t),oa(this,e,new WM(this,e))}insert(e,t){this.doc!==null?Be(this.doc,r=>{eb(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?Be(this.doc,t=>{zM(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?Be(this.doc,r=>{tb(r,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return Xy(this,e)}toArray(){return Gy(this)}slice(e=0,t=this.length){return Jy(this,e,t)}toJSON(){return this.map(e=>e instanceof Et?e.toJSON():e)}map(e){return Zy(this,e)}forEach(e){Lo(this,e)}[Symbol.iterator](){return VM(this)}_write(e){e.writeTypeRef(mO)}}const qM=n=>new hs;class KM extends ia{constructor(e,t,r){super(e,t),this.keysChanged=r}}class ps extends Et{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((r,i)=>{this.set(i,r)}),this._prelimContent=null}_copy(){return new ps}clone(){const e=new ps;return this.forEach((t,r)=>{e.set(r,t instanceof Et?t.clone():t)}),e}_callObserver(e,t){oa(this,e,new KM(this,e,t))}toJSON(){const e={};return this._map.forEach((t,r)=>{if(!t.deleted){const i=t.content.getContent()[t.length-1];e[r]=i instanceof Et?i.toJSON():i}}),e}get size(){return[...ca(this._map)].length}keys(){return Ld(ca(this._map),e=>e[0])}values(){return Ld(ca(this._map),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Ld(ca(this._map),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this._map.forEach((t,r)=>{t.deleted||e(t.content.getContent()[t.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?Be(this.doc,t=>{aa(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?Be(this.doc,r=>{Jd(r,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Gd(this,e)}has(e){return rb(this,e)}clear(){this.doc!==null?Be(this.doc,e=>{this.forEach(function(t,r,i){aa(e,i,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(gO)}}const JM=n=>new ps,Br=(n,e)=>n===e||typeof n=="object"&&typeof e=="object"&&n&&e&&_A(n,e);class Yd{constructor(e,t,r,i){this.left=e,this.right=t,this.index=r,this.currentAttributes=i}forward(){switch(this.right===null&&cn(),this.right.content.constructor){case lt:this.right.deleted||ms(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}}const ib=(n,e,t)=>{for(;e.right!==null&&t>0;){switch(e.right.content.constructor){case lt:e.right.deleted||ms(e.currentAttributes,e.right.content);break;default:e.right.deleted||(t<e.right.length&&Ut(n,pe(e.right.id.client,e.right.id.clock+t)),e.index+=e.right.length,t-=e.right.length);break}e.left=e.right,e.right=e.right.right}return e},ua=(n,e,t,r)=>{const i=new Map,s=r?sa(e,t):null;if(s){const o=new Yd(s.p.left,s.p,s.index,i);return ib(n,o,t-s.index)}else{const o=new Yd(null,e._start,0,i);return ib(n,o,t)}},sb=(n,e,t,r)=>{for(;t.right!==null&&(t.right.deleted===!0||t.right.content.constructor===lt&&Br(r.get(t.right.content.key),t.right.content.value));)t.right.deleted||r.delete(t.right.content.key),t.forward();const i=n.doc,s=i.clientID;r.forEach((o,l)=>{const a=t.left,c=t.right,u=new ze(pe(s,rt(i.store,s)),a,a&&a.lastId,c,c&&c.id,e,null,new lt(l,o));u.integrate(n,0),t.right=u,t.forward()})},ms=(n,e)=>{const{key:t,value:r}=e;r===null?n.delete(t):n.set(t,r)},ob=(n,e)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===lt&&Br(e[n.right.content.key]??null,n.right.content.value)))break;n.forward()}},lb=(n,e,t,r)=>{const i=n.doc,s=i.clientID,o=new Map;for(const l in r){const a=r[l],c=t.currentAttributes.get(l)??null;if(!Br(c,a)){o.set(l,c);const{left:u,right:d}=t;t.right=new ze(pe(s,rt(i.store,s)),u,u&&u.lastId,d,d&&d.id,e,null,new lt(l,a)),t.right.integrate(n,0),t.forward()}}return o},Zd=(n,e,t,r,i)=>{t.currentAttributes.forEach((f,h)=>{i[h]===void 0&&(i[h]=null)});const s=n.doc,o=s.clientID;ob(t,i);const l=lb(n,e,t,i),a=r.constructor===String?new Cn(r):r instanceof Et?new kn(r):new Ci(r);let{left:c,right:u,index:d}=t;e._searchMarker&&Ro(e._searchMarker,t.index,a.getLength()),u=new ze(pe(o,rt(s.store,o)),c,c&&c.lastId,u,u&&u.id,e,null,a),u.integrate(n,0),t.right=u,t.index=d,t.forward(),sb(n,e,t,l)},ab=(n,e,t,r,i)=>{const s=n.doc,o=s.clientID;ob(t,i);const l=lb(n,e,t,i);e:for(;t.right!==null&&(r>0||l.size>0&&(t.right.deleted||t.right.content.constructor===lt));){if(!t.right.deleted)switch(t.right.content.constructor){case lt:{const{key:a,value:c}=t.right.content,u=i[a];if(u!==void 0){if(Br(u,c))l.delete(a);else{if(r===0)break e;l.set(a,c)}t.right.delete(n)}else t.currentAttributes.set(a,c);break}default:r<t.right.length&&Ut(n,pe(t.right.id.client,t.right.id.clock+r)),r-=t.right.length;break}t.forward()}if(r>0){let a="";for(;r>0;r--)a+=`
|
323
323
|
`;t.right=new ze(pe(o,rt(s.store,o)),t.left,t.left&&t.left.lastId,t.right,t.right&&t.right.id,e,null,new Cn(a)),t.right.integrate(n,0),t.forward()}sb(n,e,t,l)},cb=(n,e,t,r,i)=>{let s=e;const o=Lt();for(;s&&(!s.countable||s.deleted);){if(!s.deleted&&s.content.constructor===lt){const c=s.content;o.set(c.key,c)}s=s.right}let l=0,a=!1;for(;e!==s;){if(t===e&&(a=!0),!e.deleted){const c=e.content;switch(c.constructor){case lt:{const{key:u,value:d}=c,f=r.get(u)??null;(o.get(u)!==c||f===d)&&(e.delete(n),l++,!a&&(i.get(u)??null)===d&&f!==d&&(f===null?i.delete(u):i.set(u,f))),!a&&!e.deleted&&ms(i,c);break}}}e=e.right}return l},GM=(n,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;const t=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===lt){const r=e.content.key;t.has(r)?e.delete(n):t.add(r)}e=e.left}},YM=n=>{let e=0;return Be(n.doc,t=>{let r=n._start,i=n._start,s=Lt();const o=ad(s);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case lt:ms(o,i.content);break;default:e+=cb(t,r,i,s,o),s=ad(o),r=i;break}i=i.right}}),e},ZM=n=>{const e=new Set,t=n.doc;for(const[r,i]of n.afterState.entries()){const s=n.beforeState.get(r)||0;i!==s&&Fy(n,t.store.clients.get(r),s,i,o=>{!o.deleted&&o.content.constructor===lt&&o.constructor!==dn&&e.add(o.parent)})}Be(t,r=>{Pr(n,n.deleteSet,i=>{if(i instanceof dn||!i.parent._hasFormatting||e.has(i.parent))return;const s=i.parent;i.content.constructor===lt?e.add(s):GM(r,i)});for(const i of e)YM(i)})},ub=(n,e,t)=>{const r=t,i=ad(e.currentAttributes),s=e.right;for(;t>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case kn:case Ci:case Cn:t<e.right.length&&Ut(n,pe(e.right.id.client,e.right.id.clock+t)),t-=e.right.length,e.right.delete(n);break}e.forward()}s&&cb(n,s,e.right,i,e.currentAttributes);const o=(e.left||e.right).parent;return o._searchMarker&&Ro(o._searchMarker,e.index,-r+t),e};class XM extends ia{constructor(e,t,r){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,r.forEach(i=>{i===null?this.childListChanged=!0:this.keysChanged.add(i)})}get changes(){if(this._changes===null){const e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){const e=this.target.doc,t=[];Be(e,r=>{const i=new Map,s=new Map;let o=this.target._start,l=null;const a={};let c="",u=0,d=0;const f=()=>{if(l!==null){let h=null;switch(l){case"delete":d>0&&(h={delete:d}),d=0;break;case"insert":(typeof c=="object"||c.length>0)&&(h={insert:c},i.size>0&&(h.attributes={},i.forEach((p,g)=>{p!==null&&(h.attributes[g]=p)}))),c="";break;case"retain":u>0&&(h={retain:u},MA(a)||(h.attributes=TA({},a))),u=0;break}h&&t.push(h),l=null}};for(;o!==null;){switch(o.content.constructor){case kn:case Ci:this.adds(o)?this.deletes(o)||(f(),l="insert",c=o.content.getContent()[0],f()):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),d+=1):o.deleted||(l!=="retain"&&(f(),l="retain"),u+=1);break;case Cn:this.adds(o)?this.deletes(o)||(l!=="insert"&&(f(),l="insert"),c+=o.content.str):this.deletes(o)?(l!=="delete"&&(f(),l="delete"),d+=o.length):o.deleted||(l!=="retain"&&(f(),l="retain"),u+=o.length);break;case lt:{const{key:h,value:p}=o.content;if(this.adds(o)){if(!this.deletes(o)){const g=i.get(h)??null;Br(g,p)?p!==null&&o.delete(r):(l==="retain"&&f(),Br(p,s.get(h)??null)?delete a[h]:a[h]=p)}}else if(this.deletes(o)){s.set(h,p);const g=i.get(h)??null;Br(g,p)||(l==="retain"&&f(),a[h]=g)}else if(!o.deleted){s.set(h,p);const g=a[h];g!==void 0&&(Br(g,p)?g!==null&&o.delete(r):(l==="retain"&&f(),p===null?delete a[h]:a[h]=p))}o.deleted||(l==="insert"&&f(),ms(i,o.content));break}}o=o.right}for(f();t.length>0;){const h=t[t.length-1];if(h.retain!==void 0&&h.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}}class wi extends Et{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new wi}clone(){const e=new wi;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);const r=new XM(this,e,t);oa(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){let e="",t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Cn&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc!==null?Be(this.doc,r=>{const i=new Yd(null,this._start,0,new Map);for(let s=0;s<e.length;s++){const o=e[s];if(o.insert!==void 0){const l=!t&&typeof o.insert=="string"&&s===e.length-1&&i.right===null&&o.insert.slice(-1)===`
|
324
324
|
`?o.insert.slice(0,-1):o.insert;(typeof l!="string"||l.length>0)&&Zd(r,this,i,l,o.attributes||{})}else o.retain!==void 0?ab(r,this,i,o.retain,o.attributes||{}):o.delete!==void 0&&ub(r,i,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,r){const i=[],s=new Map,o=this.doc;let l="",a=this._start;function c(){if(l.length>0){const d={};let f=!1;s.forEach((p,g)=>{f=!0,d[g]=p});const h={insert:l};f&&(h.attributes=d),i.push(h),l=""}}const u=()=>{for(;a!==null;){if(vi(a,e)||t!==void 0&&vi(a,t))switch(a.content.constructor){case Cn:{const d=s.get("ychange");e!==void 0&&!vi(a,e)?(d===void 0||d.user!==a.id.client||d.type!=="removed")&&(c(),s.set("ychange",r?r("removed",a.id):{type:"removed"})):t!==void 0&&!vi(a,t)?(d===void 0||d.user!==a.id.client||d.type!=="added")&&(c(),s.set("ychange",r?r("added",a.id):{type:"added"})):d!==void 0&&(c(),s.delete("ychange")),l+=a.content.str;break}case kn:case Ci:{c();const d={insert:a.content.getContent()[0]};if(s.size>0){const f={};d.attributes=f,s.forEach((h,p)=>{f[p]=h})}i.push(d);break}case lt:vi(a,e)&&(c(),ms(s,a.content));break}a=a.right}c()};return e||t?Be(o,d=>{e&&Vd(d,e),t&&Vd(d,t),u()},"cleanup"):u(),i}insert(e,t,r){if(t.length<=0)return;const i=this.doc;i!==null?Be(i,s=>{const o=ua(s,this,e,!r);r||(r={},o.currentAttributes.forEach((l,a)=>{r[a]=l})),Zd(s,this,o,t,r)}):this._pending.push(()=>this.insert(e,t,r))}insertEmbed(e,t,r){const i=this.doc;i!==null?Be(i,s=>{const o=ua(s,this,e,!r);Zd(s,this,o,t,r||{})}):this._pending.push(()=>this.insertEmbed(e,t,r||{}))}delete(e,t){if(t===0)return;const r=this.doc;r!==null?Be(r,i=>{ub(i,ua(i,this,e,!0),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,r){if(t===0)return;const i=this.doc;i!==null?Be(i,s=>{const o=ua(s,this,e,!1);o.right!==null&&ab(s,this,o,t,r)}):this._pending.push(()=>this.format(e,t,r))}removeAttribute(e){this.doc!==null?Be(this.doc,t=>{aa(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?Be(this.doc,r=>{Jd(r,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Gd(this,e)}getAttributes(){return nb(this)}_write(e){e.writeTypeRef(yO)}}const QM=n=>new wi;class Xd{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===It||t.constructor===xi)&&t._start!==null)e=t._start;else for(;e!==null;)if(e.right!==null){e=e.right;break}else e.parent===this._root?e=null:e=e.parent._item;while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}}class xi extends Et{constructor(){super(),this._prelimContent=[]}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new xi}clone(){const e=new xi;return e.insert(0,this.toArray().map(t=>t instanceof Et?t.clone():t)),e}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new Xd(this,e)}querySelector(e){e=e.toUpperCase();const r=new Xd(this,i=>i.nodeName&&i.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),lr(new Xd(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){oa(this,e,new nO(this,t,e))}toString(){return Zy(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},r){const i=e.createDocumentFragment();return r!==void 0&&r._createAssociation(i,this),Lo(this,s=>{i.insertBefore(s.toDOM(e,t,r),null)}),i}insert(e,t){this.doc!==null?Be(this.doc,r=>{eb(r,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(this.doc!==null)Be(this.doc,r=>{const i=e&&e instanceof Et?e._item:e;la(r,this,i,t)});else{const r=this._prelimContent,i=e===null?0:r.findIndex(s=>s===e)+1;if(i===0&&e!==null)throw $n("Reference item not found");r.splice(i,0,...t)}}delete(e,t=1){this.doc!==null?Be(this.doc,r=>{tb(r,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return Gy(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return Xy(this,e)}slice(e=0,t=this.length){return Jy(this,e,t)}forEach(e){Lo(this,e)}_write(e){e.writeTypeRef(vO)}}const eO=n=>new xi;class It extends xi{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((r,i)=>{this.setAttribute(i,r)}),this._prelimAttrs=null}_copy(){return new It(this.nodeName)}clone(){const e=new It(this.nodeName),t=this.getAttributes();return AA(t,(r,i)=>{typeof r=="string"&&e.setAttribute(i,r)}),e.insert(0,this.toArray().map(r=>r instanceof Et?r.clone():r)),e}toString(){const e=this.getAttributes(),t=[],r=[];for(const l in e)r.push(l);r.sort();const i=r.length;for(let l=0;l<i;l++){const a=r[l];t.push(a+'="'+e[a]+'"')}const s=this.nodeName.toLocaleLowerCase(),o=t.length>0?" "+t.join(" "):"";return`<${s}${o}>${super.toString()}</${s}>`}removeAttribute(e){this.doc!==null?Be(this.doc,t=>{aa(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?Be(this.doc,r=>{Jd(r,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Gd(this,e)}hasAttribute(e){return rb(this,e)}getAttributes(e){return e?UM(this,e):nb(this)}toDOM(e=document,t={},r){const i=e.createElement(this.nodeName),s=this.getAttributes();for(const o in s){const l=s[o];typeof l=="string"&&i.setAttribute(o,l)}return Lo(this,o=>{i.appendChild(o.toDOM(e,t,r))}),r!==void 0&&r._createAssociation(i,this),i}_write(e){e.writeTypeRef(bO),e.writeKey(this.nodeName)}}const tO=n=>new It(n.readKey());class nO extends ia{constructor(e,t,r){super(e,r),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(i=>{i===null?this.childListChanged=!0:this.attributesChanged.add(i)})}}class da extends ps{constructor(e){super(),this.hookName=e}_copy(){return new da(this.hookName)}clone(){const e=new da(this.hookName);return this.forEach((t,r)=>{e.set(r,t)}),e}toDOM(e=document,t={},r){const i=t[this.hookName];let s;return i!==void 0?s=i.createDom(this):s=document.createElement(this.hookName),s.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(s,this),s}_write(e){e.writeTypeRef(wO),e.writeKey(this.hookName)}}const rO=n=>new da(n.readKey());class Zt extends wi{get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new Zt}clone(){const e=new Zt;return e.applyDelta(this.toDelta()),e}toDOM(e=document,t,r){const i=e.createTextNode(this.toString());return r!==void 0&&r._createAssociation(i,this),i}toString(){return this.toDelta().map(e=>{const t=[];for(const i in e.attributes){const s=[];for(const o in e.attributes[i])s.push({key:o,value:e.attributes[i][o]});s.sort((o,l)=>o.key<l.key?-1:1),t.push({nodeName:i,attrs:s})}t.sort((i,s)=>i.nodeName<s.nodeName?-1:1);let r="";for(let i=0;i<t.length;i++){const s=t[i];r+=`<${s.nodeName}`;for(let o=0;o<s.attrs.length;o++){const l=s.attrs[o];r+=` ${l.key}="${l.value}"`}r+=">"}r+=e.insert;for(let i=t.length-1;i>=0;i--)r+=`</${t[i].nodeName}>`;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(xO)}}const iO=n=>new Zt;class Qd{constructor(e,t){this.id=e,this.length=t}get deleted(){throw xn()}mergeWith(e){return!1}write(e,t,r){throw xn()}integrate(e,t){throw xn()}}const sO=0;class dn extends Qd{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),Iy(e.doc.store,this)}write(e,t){e.writeInfo(sO),e.writeLen(this.length-t)}getMissing(e,t){return null}}class Io{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Io(this.content)}splice(e){throw xn()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}}const oO=n=>new Io(n.readBuf());class Po{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Po(this.len)}splice(e){const t=new Po(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){To(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}}const lO=n=>new Po(n.readLen()),db=(n,e)=>new as({guid:n,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class Fo{constructor(e){e._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=e;const t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Fo(db(this.doc.guid,this.opts))}splice(e){throw xn()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}}const aO=n=>new Fo(db(n.readString(),n.readAny()));class Ci{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Ci(this.embed)}splice(e){throw xn()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}}const cO=n=>new Ci(n.readJSON());class lt{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new lt(this.key,this.value)}splice(e){throw xn()}mergeWith(e){return!1}integrate(e,t){const r=t.parent;r._searchMarker=null,r._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}const uO=n=>new lt(n.readKey(),n.readJSON());class fa{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new fa(this.arr)}splice(e){const t=new fa(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){const r=this.arr.length;e.writeLen(r-t);for(let i=t;i<r;i++){const s=this.arr[i];e.writeString(s===void 0?"undefined":JSON.stringify(s))}}getRef(){return 2}}const dO=n=>{const e=n.readLen(),t=[];for(let r=0;r<e;r++){const i=n.readString();i==="undefined"?t.push(void 0):t.push(JSON.parse(i))}return new fa(t)};class ki{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ki(this.arr)}splice(e){const t=new ki(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){const r=this.arr.length;e.writeLen(r-t);for(let i=t;i<r;i++){const s=this.arr[i];e.writeAny(s)}}getRef(){return 8}}const fO=n=>{const e=n.readLen(),t=[];for(let r=0;r<e;r++)t.push(n.readAny());return new ki(t)};class Cn{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new Cn(this.str)}splice(e){const t=new Cn(this.str.slice(e));this.str=this.str.slice(0,e);const r=this.str.charCodeAt(e-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,e-1)+"�",t.str="�"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}}const hO=n=>new Cn(n.readString()),pO=[qM,JM,QM,tO,eO,rO,iO],mO=0,gO=1,yO=2,bO=3,vO=4,wO=5,xO=6;class kn{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new kn(this.type._copy())}splice(e){throw xn()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(r=>{r.deleted?r.id.clock<(e.beforeState.get(r.id.client)||0)&&e._mergeStructs.push(r):r.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(e,!0),r=r.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}}const CO=n=>new kn(pO[n.readTypeRef()](n)),ef=(n,e)=>{let t=e,r=0,i;do r>0&&(t=pe(t.client,t.clock+r)),i=fs(n,t),r=t.clock-i.id.clock,t=i.redone;while(t!==null&&i instanceof ze);return{item:i,diff:r}},tf=(n,e)=>{for(;n!==null&&n.keep!==e;)n.keep=e,n=n.parent._item},ha=(n,e,t)=>{const{client:r,clock:i}=e.id,s=new ze(pe(r,i+t),e,pe(r,i+t-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t));return e.deleted&&s.markDeleted(),e.keep&&(s.keep=!0),e.redone!==null&&(s.redone=pe(e.redone.client,e.redone.clock+t)),e.right=s,s.right!==null&&(s.right.left=s),n._mergeStructs.push(s),s.parentSub!==null&&s.right===null&&s.parent._map.set(s.parentSub,s),e.length=t,s},fb=(n,e)=>KT(n,t=>ss(t.deletions,e)),hb=(n,e,t,r,i,s)=>{const o=n.doc,l=o.store,a=o.clientID,c=e.redone;if(c!==null)return Ut(n,c);let u=e.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!t.has(u)||hb(n,u,t,r,i,s)===null))return null;for(;u.redone!==null;)u=Ut(n,u.redone)}const h=u===null?e.parent:u.content.type;if(e.parentSub===null){for(d=e.left,f=e;d!==null;){let w=d;for(;w!==null&&w.parent._item!==u;)w=w.redone===null?null:Ut(n,w.redone);if(w!==null&&w.parent._item===u){d=w;break}d=d.left}for(;f!==null;){let w=f;for(;w!==null&&w.parent._item!==u;)w=w.redone===null?null:Ut(n,w.redone);if(w!==null&&w.parent._item===u){f=w;break}f=f.right}}else if(f=null,e.right&&!i){for(d=e;d!==null&&d.right!==null&&(d.right.redone||ss(r,d.right.id)||fb(s.undoStack,d.right.id)||fb(s.redoStack,d.right.id));)for(d=d.right;d.redone;)d=Ut(n,d.redone);if(d&&d.right!==null)return null}else d=h._map.get(e.parentSub)||null;const p=rt(l,a),g=pe(a,p),v=new ze(g,d,d&&d.lastId,f,f&&f.id,h,e.parentSub,e.content.copy());return e.redone=g,tf(v,!0),v.integrate(n,0),v};let ze=class Sh extends Qd{constructor(e,t,r,i,s,o,l,a){super(e,a.getLength()),this.origin=r,this.left=t,this.right=i,this.rightOrigin=s,this.parent=o,this.parentSub=l,this.redone=null,this.content=a,this.info=this.content.isCountable()?I0:0}set marker(e){(this.info&pd)>0!==e&&(this.info^=pd)}get marker(){return(this.info&pd)>0}get keep(){return(this.info&L0)>0}set keep(e){this.keep!==e&&(this.info^=L0)}get countable(){return(this.info&I0)>0}get deleted(){return(this.info&hd)>0}set deleted(e){this.deleted!==e&&(this.info^=hd)}markDeleted(){this.info|=hd}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=rt(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=rt(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===us&&this.id.client!==this.parent.client&&this.parent.clock>=rt(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Py(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Ut(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===dn||this.right&&this.right.constructor===dn)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===Sh&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===Sh&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===us){const r=fs(t,this.parent);r.constructor===dn?this.parent=null:this.parent=r.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Py(e,e.doc.store,pe(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,i;if(r!==null)i=r.right;else if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start;const s=new Set,o=new Set;for(;i!==null&&i!==this.right;){if(o.add(i),s.add(i),ds(this.origin,i.origin)){if(i.id.client<this.id.client)r=i,s.clear();else if(ds(this.rightOrigin,i.rightOrigin))break}else if(i.origin!==null&&o.has(fs(e.doc.store,i.origin)))s.has(fs(e.doc.store,i.origin))||(r=i,s.clear());else break;i=i.right}this.left=r}if(this.left!==null){const r=this.left.right;this.right=r,this.left.right=this}else{let r;if(this.parentSub!==null)for(r=this.parent._map.get(this.parentSub)||null;r!==null&&r.left!==null;)r=r.left;else r=this.parent._start,this.parent._start=this;this.right=r}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Iy(e.doc.store,this),this.content.integrate(e,this),$y(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new dn(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;e!==null&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;e!==null&&e.deleted;)e=e.left;return e}get lastId(){return this.length===1?this.id:pe(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&ds(e.origin,this.lastId)&&this.right===e&&ds(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&this.redone===null&&e.redone===null&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){const t=this.parent._searchMarker;return t&&t.forEach(r=>{r.p===e&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){const t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),To(e.deleteSet,this.id.client,this.id.clock,this.length),$y(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw cn();this.content.gc(e),t?AM(e,this,new dn(this.id,this.length)):this.content=new Po(this.length)}write(e,t){const r=t>0?pe(this.id.client,this.id.clock+t-1):this.origin,i=this.rightOrigin,s=this.parentSub,o=this.content.getRef()&Kl|(r===null?0:Yt)|(i===null?0:cr)|(s===null?0:wo);if(e.writeInfo(o),r!==null&&e.writeLeftID(r),i!==null&&e.writeRightID(i),r===null&&i===null){const l=this.parent;if(l._item!==void 0){const a=l._item;if(a===null){const c=Mo(l);e.writeParentInfo(!0),e.writeString(c)}else e.writeParentInfo(!1),e.writeLeftID(a.id)}else l.constructor===String?(e.writeParentInfo(!0),e.writeString(l)):l.constructor===us?(e.writeParentInfo(!1),e.writeLeftID(l)):cn();s!==null&&e.writeString(s)}this.content.write(e,t)}};const pb=(n,e)=>kO[e&Kl](n),kO=[()=>{cn()},lO,dO,oO,hO,cO,uO,CO,fO,aO,()=>{cn()}],SO=10;class fn extends Qd{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){cn()}write(e,t){e.writeInfo(SO),ae(e.restEncoder,this.length-t)}getMissing(e,t){return null}}const mb=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},gb="__ $YJS$ __";mb[gb]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),mb[gb]=!0;function pa(n){throw new Error('Could not dynamically require "'+n+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var yb={exports:{}};(function(n,e){(function(t){n.exports=t()})(function(){var t=Math.floor,r=Math.abs,i=Math.pow;return function(){function s(o,l,a){function c(f,h){if(!l[f]){if(!o[f]){var p=typeof pa=="function"&&pa;if(!h&&p)return p(f,!0);if(u)return u(f,!0);var g=new Error("Cannot find module '"+f+"'");throw g.code="MODULE_NOT_FOUND",g}var v=l[f]={exports:{}};o[f][0].call(v.exports,function(w){var S=o[f][1][w];return c(S||w)},v,v.exports,s,o,l,a)}return l[f].exports}for(var u=typeof pa=="function"&&pa,d=0;d<a.length;d++)c(a[d]);return c}return s}()({1:[function(s,o,l){function a(y){var k=y.length;if(0<k%4)throw new Error("Invalid string. Length must be a multiple of 4");var E=y.indexOf("=");E===-1&&(E=k);var T=E===k?0:4-E%4;return[E,T]}function c(y,k,E){return 3*(k+E)/4-E}function u(y){var k,E,T=a(y),N=T[0],_=T[1],A=new v(c(y,N,_)),R=0,P=0<_?N-4:N;for(E=0;E<P;E+=4)k=g[y.charCodeAt(E)]<<18|g[y.charCodeAt(E+1)]<<12|g[y.charCodeAt(E+2)]<<6|g[y.charCodeAt(E+3)],A[R++]=255&k>>16,A[R++]=255&k>>8,A[R++]=255&k;return _===2&&(k=g[y.charCodeAt(E)]<<2|g[y.charCodeAt(E+1)]>>4,A[R++]=255&k),_===1&&(k=g[y.charCodeAt(E)]<<10|g[y.charCodeAt(E+1)]<<4|g[y.charCodeAt(E+2)]>>2,A[R++]=255&k>>8,A[R++]=255&k),A}function d(y){return p[63&y>>18]+p[63&y>>12]+p[63&y>>6]+p[63&y]}function f(y,k,E){for(var T,N=[],_=k;_<E;_+=3)T=(16711680&y[_]<<16)+(65280&y[_+1]<<8)+(255&y[_+2]),N.push(d(T));return N.join("")}function h(y){for(var k,E=y.length,T=E%3,N=[],_=16383,A=0,R=E-T;A<R;A+=_)N.push(f(y,A,A+_>R?R:A+_));return T===1?(k=y[E-1],N.push(p[k>>2]+p[63&k<<4]+"==")):T===2&&(k=(y[E-2]<<8)+y[E-1],N.push(p[k>>10]+p[63&k>>4]+p[63&k<<2]+"=")),N.join("")}l.byteLength=function(y){var k=a(y),E=k[0],T=k[1];return 3*(E+T)/4-T},l.toByteArray=u,l.fromByteArray=h;for(var p=[],g=[],v=typeof Uint8Array>"u"?Array:Uint8Array,w="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",S=0,x=w.length;S<x;++S)p[S]=w[S],g[w.charCodeAt(S)]=S;g[45]=62,g[95]=63},{}],2:[function(){},{}],3:[function(s,o,l){(function(){(function(){var a=String.fromCharCode,c=Math.min;function u(m){if(2147483647<m)throw new RangeError('The value "'+m+'" is invalid for option "size"');var b=new Uint8Array(m);return b.__proto__=d.prototype,b}function d(m,b,C){if(typeof m=="number"){if(typeof b=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return g(m)}return f(m,b,C)}function f(m,b,C){if(typeof m=="string")return v(m,b);if(ArrayBuffer.isView(m))return w(m);if(m==null)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof m);if(B(m,ArrayBuffer)||m&&B(m.buffer,ArrayBuffer))return S(m,b,C);if(typeof m=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');var I=m.valueOf&&m.valueOf();if(I!=null&&I!==m)return d.from(I,b,C);var F=x(m);if(F)return F;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof m[Symbol.toPrimitive]=="function")return d.from(m[Symbol.toPrimitive]("string"),b,C);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof m)}function h(m){if(typeof m!="number")throw new TypeError('"size" argument must be of type number');if(0>m)throw new RangeError('The value "'+m+'" is invalid for option "size"')}function p(m,b,C){return h(m),0>=m||b===void 0?u(m):typeof C=="string"?u(m).fill(b,C):u(m).fill(b)}function g(m){return h(m),u(0>m?0:0|y(m))}function v(m,b){if((typeof b!="string"||b==="")&&(b="utf8"),!d.isEncoding(b))throw new TypeError("Unknown encoding: "+b);var C=0|k(m,b),I=u(C),F=I.write(m,b);return F!==C&&(I=I.slice(0,F)),I}function w(m){for(var b=0>m.length?0:0|y(m.length),C=u(b),I=0;I<b;I+=1)C[I]=255&m[I];return C}function S(m,b,C){if(0>b||m.byteLength<b)throw new RangeError('"offset" is outside of buffer bounds');if(m.byteLength<b+(C||0))throw new RangeError('"length" is outside of buffer bounds');var I;return I=b===void 0&&C===void 0?new Uint8Array(m):C===void 0?new Uint8Array(m,b):new Uint8Array(m,b,C),I.__proto__=d.prototype,I}function x(m){if(d.isBuffer(m)){var b=0|y(m.length),C=u(b);return C.length===0||m.copy(C,0,0,b),C}return m.length===void 0?m.type==="Buffer"&&Array.isArray(m.data)?w(m.data):void 0:typeof m.length!="number"||j(m.length)?u(0):w(m)}function y(m){if(m>=2147483647)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x7fffffff bytes");return 0|m}function k(m,b){if(d.isBuffer(m))return m.length;if(ArrayBuffer.isView(m)||B(m,ArrayBuffer))return m.byteLength;if(typeof m!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof m);var C=m.length,I=2<arguments.length&&arguments[2]===!0;if(!I&&C===0)return 0;for(var F=!1;;)switch(b){case"ascii":case"latin1":case"binary":return C;case"utf8":case"utf-8":return Ye(m).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*C;case"hex":return C>>>1;case"base64":return it(m).length;default:if(F)return I?-1:Ye(m).length;b=(""+b).toLowerCase(),F=!0}}function E(m,b,C){var I=!1;if((b===void 0||0>b)&&(b=0),b>this.length||((C===void 0||C>this.length)&&(C=this.length),0>=C)||(C>>>=0,b>>>=0,C<=b))return"";for(m||(m="utf8");;)switch(m){case"hex":return Re(this,b,C);case"utf8":case"utf-8":return G(this,b,C);case"ascii":return X(this,b,C);case"latin1":case"binary":return we(this,b,C);case"base64":return J(this,b,C);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Pe(this,b,C);default:if(I)throw new TypeError("Unknown encoding: "+m);m=(m+"").toLowerCase(),I=!0}}function T(m,b,C){var I=m[b];m[b]=m[C],m[C]=I}function N(m,b,C,I,F){if(m.length===0)return-1;if(typeof C=="string"?(I=C,C=0):2147483647<C?C=2147483647:-2147483648>C&&(C=-2147483648),C=+C,j(C)&&(C=F?0:m.length-1),0>C&&(C=m.length+C),C>=m.length){if(F)return-1;C=m.length-1}else if(0>C)if(F)C=0;else return-1;if(typeof b=="string"&&(b=d.from(b,I)),d.isBuffer(b))return b.length===0?-1:_(m,b,C,I,F);if(typeof b=="number")return b&=255,typeof Uint8Array.prototype.indexOf=="function"?F?Uint8Array.prototype.indexOf.call(m,b,C):Uint8Array.prototype.lastIndexOf.call(m,b,C):_(m,[b],C,I,F);throw new TypeError("val must be string, number or Buffer")}function _(m,b,C,I,F){function H(Qn,z){return ne===1?Qn[z]:Qn.readUInt16BE(z*ne)}var ne=1,de=m.length,Oe=b.length;if(I!==void 0&&(I=(I+"").toLowerCase(),I==="ucs2"||I==="ucs-2"||I==="utf16le"||I==="utf-16le")){if(2>m.length||2>b.length)return-1;ne=2,de/=2,Oe/=2,C/=2}var be;if(F){var me=-1;for(be=C;be<de;be++)if(H(m,be)!==H(b,me===-1?0:be-me))me!==-1&&(be-=be-me),me=-1;else if(me===-1&&(me=be),be-me+1===Oe)return me*ne}else for(C+Oe>de&&(C=de-Oe),be=C;0<=be;be--){for(var Ze=!0,An=0;An<Oe;An++)if(H(m,be+An)!==H(b,An)){Ze=!1;break}if(Ze)return be}return-1}function A(m,b,C,I){C=+C||0;var F=m.length-C;I?(I=+I,I>F&&(I=F)):I=F;var H=b.length;I>H/2&&(I=H/2);for(var ne,de=0;de<I;++de){if(ne=parseInt(b.substr(2*de,2),16),j(ne))return de;m[C+de]=ne}return de}function R(m,b,C,I){return at(Ye(b,m.length-C),m,C,I)}function P(m,b,C,I){return at(Ot(b),m,C,I)}function $(m,b,C,I){return P(m,b,C,I)}function V(m,b,C,I){return at(it(b),m,C,I)}function U(m,b,C,I){return at(xt(b,m.length-C),m,C,I)}function J(m,b,C){return b===0&&C===m.length?q.fromByteArray(m):q.fromByteArray(m.slice(b,C))}function G(m,b,C){C=c(m.length,C);for(var I=[],F=b;F<C;){var H=m[F],ne=null,de=239<H?4:223<H?3:191<H?2:1;if(F+de<=C){var Oe,be,me,Ze;de===1?128>H&&(ne=H):de===2?(Oe=m[F+1],(192&Oe)==128&&(Ze=(31&H)<<6|63&Oe,127<Ze&&(ne=Ze))):de===3?(Oe=m[F+1],be=m[F+2],(192&Oe)==128&&(192&be)==128&&(Ze=(15&H)<<12|(63&Oe)<<6|63&be,2047<Ze&&(55296>Ze||57343<Ze)&&(ne=Ze))):de===4&&(Oe=m[F+1],be=m[F+2],me=m[F+3],(192&Oe)==128&&(192&be)==128&&(192&me)==128&&(Ze=(15&H)<<18|(63&Oe)<<12|(63&be)<<6|63&me,65535<Ze&&1114112>Ze&&(ne=Ze)))}ne===null?(ne=65533,de=1):65535<ne&&(ne-=65536,I.push(55296|1023&ne>>>10),ne=56320|1023&ne),I.push(ne),F+=de}return ie(I)}function ie(m){var b=m.length;if(b<=4096)return a.apply(String,m);for(var C="",I=0;I<b;)C+=a.apply(String,m.slice(I,I+=4096));return C}function X(m,b,C){var I="";C=c(m.length,C);for(var F=b;F<C;++F)I+=a(127&m[F]);return I}function we(m,b,C){var I="";C=c(m.length,C);for(var F=b;F<C;++F)I+=a(m[F]);return I}function Re(m,b,C){var I=m.length;(!b||0>b)&&(b=0),(!C||0>C||C>I)&&(C=I);for(var F="",H=b;H<C;++H)F+=Ge(m[H]);return F}function Pe(m,b,C){for(var I=m.slice(b,C),F="",H=0;H<I.length;H+=2)F+=a(I[H]+256*I[H+1]);return F}function Ce(m,b,C){if(m%1!=0||0>m)throw new RangeError("offset is not uint");if(m+b>C)throw new RangeError("Trying to access beyond buffer length")}function ye(m,b,C,I,F,H){if(!d.isBuffer(m))throw new TypeError('"buffer" argument must be a Buffer instance');if(b>F||b<H)throw new RangeError('"value" argument is out of bounds');if(C+I>m.length)throw new RangeError("Index out of range")}function Ne(m,b,C,I){if(C+I>m.length)throw new RangeError("Index out of range");if(0>C)throw new RangeError("Index out of range")}function Le(m,b,C,I,F){return b=+b,C>>>=0,F||Ne(m,b,C,4),te.write(m,b,C,I,23,4),C+4}function tt(m,b,C,I,F){return b=+b,C>>>=0,F||Ne(m,b,C,8),te.write(m,b,C,I,52,8),C+8}function nt(m){if(m=m.split("=")[0],m=m.trim().replace(M,""),2>m.length)return"";for(;m.length%4!=0;)m+="=";return m}function Ge(m){return 16>m?"0"+m.toString(16):m.toString(16)}function Ye(m,b){b=b||1/0;for(var C,I=m.length,F=null,H=[],ne=0;ne<I;++ne){if(C=m.charCodeAt(ne),55295<C&&57344>C){if(!F){if(56319<C){-1<(b-=3)&&H.push(239,191,189);continue}else if(ne+1===I){-1<(b-=3)&&H.push(239,191,189);continue}F=C;continue}if(56320>C){-1<(b-=3)&&H.push(239,191,189),F=C;continue}C=(F-55296<<10|C-56320)+65536}else F&&-1<(b-=3)&&H.push(239,191,189);if(F=null,128>C){if(0>(b-=1))break;H.push(C)}else if(2048>C){if(0>(b-=2))break;H.push(192|C>>6,128|63&C)}else if(65536>C){if(0>(b-=3))break;H.push(224|C>>12,128|63&C>>6,128|63&C)}else if(1114112>C){if(0>(b-=4))break;H.push(240|C>>18,128|63&C>>12,128|63&C>>6,128|63&C)}else throw new Error("Invalid code point")}return H}function Ot(m){for(var b=[],C=0;C<m.length;++C)b.push(255&m.charCodeAt(C));return b}function xt(m,b){for(var C,I,F,H=[],ne=0;ne<m.length&&!(0>(b-=2));++ne)C=m.charCodeAt(ne),I=C>>8,F=C%256,H.push(F),H.push(I);return H}function it(m){return q.toByteArray(nt(m))}function at(m,b,C,I){for(var F=0;F<I&&!(F+C>=b.length||F>=m.length);++F)b[F+C]=m[F];return F}function B(m,b){return m instanceof b||m!=null&&m.constructor!=null&&m.constructor.name!=null&&m.constructor.name===b.name}function j(m){return m!==m}var q=s("base64-js"),te=s("ieee754");l.Buffer=d,l.SlowBuffer=function(m){return+m!=m&&(m=0),d.alloc(+m)},l.INSPECT_MAX_BYTES=50,l.kMaxLength=2147483647,d.TYPED_ARRAY_SUPPORT=function(){try{var m=new Uint8Array(1);return m.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},m.foo()===42}catch{return!1}}(),d.TYPED_ARRAY_SUPPORT||typeof console>"u"||typeof console.error!="function"||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(d.prototype,"parent",{enumerable:!0,get:function(){return d.isBuffer(this)?this.buffer:void 0}}),Object.defineProperty(d.prototype,"offset",{enumerable:!0,get:function(){return d.isBuffer(this)?this.byteOffset:void 0}}),typeof Symbol<"u"&&Symbol.species!=null&&d[Symbol.species]===d&&Object.defineProperty(d,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),d.poolSize=8192,d.from=function(m,b,C){return f(m,b,C)},d.prototype.__proto__=Uint8Array.prototype,d.__proto__=Uint8Array,d.alloc=function(m,b,C){return p(m,b,C)},d.allocUnsafe=function(m){return g(m)},d.allocUnsafeSlow=function(m){return g(m)},d.isBuffer=function(m){return m!=null&&m._isBuffer===!0&&m!==d.prototype},d.compare=function(m,b){if(B(m,Uint8Array)&&(m=d.from(m,m.offset,m.byteLength)),B(b,Uint8Array)&&(b=d.from(b,b.offset,b.byteLength)),!d.isBuffer(m)||!d.isBuffer(b))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(m===b)return 0;for(var C=m.length,I=b.length,F=0,H=c(C,I);F<H;++F)if(m[F]!==b[F]){C=m[F],I=b[F];break}return C<I?-1:I<C?1:0},d.isEncoding=function(m){switch((m+"").toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},d.concat=function(m,b){if(!Array.isArray(m))throw new TypeError('"list" argument must be an Array of Buffers');if(m.length===0)return d.alloc(0);var C;if(b===void 0)for(b=0,C=0;C<m.length;++C)b+=m[C].length;var I=d.allocUnsafe(b),F=0;for(C=0;C<m.length;++C){var H=m[C];if(B(H,Uint8Array)&&(H=d.from(H)),!d.isBuffer(H))throw new TypeError('"list" argument must be an Array of Buffers');H.copy(I,F),F+=H.length}return I},d.byteLength=k,d.prototype._isBuffer=!0,d.prototype.swap16=function(){var m=this.length;if(m%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var b=0;b<m;b+=2)T(this,b,b+1);return this},d.prototype.swap32=function(){var m=this.length;if(m%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var b=0;b<m;b+=4)T(this,b,b+3),T(this,b+1,b+2);return this},d.prototype.swap64=function(){var m=this.length;if(m%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var b=0;b<m;b+=8)T(this,b,b+7),T(this,b+1,b+6),T(this,b+2,b+5),T(this,b+3,b+4);return this},d.prototype.toString=function(){var m=this.length;return m===0?"":arguments.length===0?G(this,0,m):E.apply(this,arguments)},d.prototype.toLocaleString=d.prototype.toString,d.prototype.equals=function(m){if(!d.isBuffer(m))throw new TypeError("Argument must be a Buffer");return this===m||d.compare(this,m)===0},d.prototype.inspect=function(){var m="",b=l.INSPECT_MAX_BYTES;return m=this.toString("hex",0,b).replace(/(.{2})/g,"$1 ").trim(),this.length>b&&(m+=" ... "),"<Buffer "+m+">"},d.prototype.compare=function(m,b,C,I,F){if(B(m,Uint8Array)&&(m=d.from(m,m.offset,m.byteLength)),!d.isBuffer(m))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof m);if(b===void 0&&(b=0),C===void 0&&(C=m?m.length:0),I===void 0&&(I=0),F===void 0&&(F=this.length),0>b||C>m.length||0>I||F>this.length)throw new RangeError("out of range index");if(I>=F&&b>=C)return 0;if(I>=F)return-1;if(b>=C)return 1;if(b>>>=0,C>>>=0,I>>>=0,F>>>=0,this===m)return 0;for(var H=F-I,ne=C-b,de=c(H,ne),Oe=this.slice(I,F),be=m.slice(b,C),me=0;me<de;++me)if(Oe[me]!==be[me]){H=Oe[me],ne=be[me];break}return H<ne?-1:ne<H?1:0},d.prototype.includes=function(m,b,C){return this.indexOf(m,b,C)!==-1},d.prototype.indexOf=function(m,b,C){return N(this,m,b,C,!0)},d.prototype.lastIndexOf=function(m,b,C){return N(this,m,b,C,!1)},d.prototype.write=function(m,b,C,I){if(b===void 0)I="utf8",C=this.length,b=0;else if(C===void 0&&typeof b=="string")I=b,C=this.length,b=0;else if(isFinite(b))b>>>=0,isFinite(C)?(C>>>=0,I===void 0&&(I="utf8")):(I=C,C=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var F=this.length-b;if((C===void 0||C>F)&&(C=F),0<m.length&&(0>C||0>b)||b>this.length)throw new RangeError("Attempt to write outside buffer bounds");I||(I="utf8");for(var H=!1;;)switch(I){case"hex":return A(this,m,b,C);case"utf8":case"utf-8":return R(this,m,b,C);case"ascii":return P(this,m,b,C);case"latin1":case"binary":return $(this,m,b,C);case"base64":return V(this,m,b,C);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U(this,m,b,C);default:if(H)throw new TypeError("Unknown encoding: "+I);I=(""+I).toLowerCase(),H=!0}},d.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},d.prototype.slice=function(m,b){var C=this.length;m=~~m,b=b===void 0?C:~~b,0>m?(m+=C,0>m&&(m=0)):m>C&&(m=C),0>b?(b+=C,0>b&&(b=0)):b>C&&(b=C),b<m&&(b=m);var I=this.subarray(m,b);return I.__proto__=d.prototype,I},d.prototype.readUIntLE=function(m,b,C){m>>>=0,b>>>=0,C||Ce(m,b,this.length);for(var I=this[m],F=1,H=0;++H<b&&(F*=256);)I+=this[m+H]*F;return I},d.prototype.readUIntBE=function(m,b,C){m>>>=0,b>>>=0,C||Ce(m,b,this.length);for(var I=this[m+--b],F=1;0<b&&(F*=256);)I+=this[m+--b]*F;return I},d.prototype.readUInt8=function(m,b){return m>>>=0,b||Ce(m,1,this.length),this[m]},d.prototype.readUInt16LE=function(m,b){return m>>>=0,b||Ce(m,2,this.length),this[m]|this[m+1]<<8},d.prototype.readUInt16BE=function(m,b){return m>>>=0,b||Ce(m,2,this.length),this[m]<<8|this[m+1]},d.prototype.readUInt32LE=function(m,b){return m>>>=0,b||Ce(m,4,this.length),(this[m]|this[m+1]<<8|this[m+2]<<16)+16777216*this[m+3]},d.prototype.readUInt32BE=function(m,b){return m>>>=0,b||Ce(m,4,this.length),16777216*this[m]+(this[m+1]<<16|this[m+2]<<8|this[m+3])},d.prototype.readIntLE=function(m,b,C){m>>>=0,b>>>=0,C||Ce(m,b,this.length);for(var I=this[m],F=1,H=0;++H<b&&(F*=256);)I+=this[m+H]*F;return F*=128,I>=F&&(I-=i(2,8*b)),I},d.prototype.readIntBE=function(m,b,C){m>>>=0,b>>>=0,C||Ce(m,b,this.length);for(var I=b,F=1,H=this[m+--I];0<I&&(F*=256);)H+=this[m+--I]*F;return F*=128,H>=F&&(H-=i(2,8*b)),H},d.prototype.readInt8=function(m,b){return m>>>=0,b||Ce(m,1,this.length),128&this[m]?-1*(255-this[m]+1):this[m]},d.prototype.readInt16LE=function(m,b){m>>>=0,b||Ce(m,2,this.length);var C=this[m]|this[m+1]<<8;return 32768&C?4294901760|C:C},d.prototype.readInt16BE=function(m,b){m>>>=0,b||Ce(m,2,this.length);var C=this[m+1]|this[m]<<8;return 32768&C?4294901760|C:C},d.prototype.readInt32LE=function(m,b){return m>>>=0,b||Ce(m,4,this.length),this[m]|this[m+1]<<8|this[m+2]<<16|this[m+3]<<24},d.prototype.readInt32BE=function(m,b){return m>>>=0,b||Ce(m,4,this.length),this[m]<<24|this[m+1]<<16|this[m+2]<<8|this[m+3]},d.prototype.readFloatLE=function(m,b){return m>>>=0,b||Ce(m,4,this.length),te.read(this,m,!0,23,4)},d.prototype.readFloatBE=function(m,b){return m>>>=0,b||Ce(m,4,this.length),te.read(this,m,!1,23,4)},d.prototype.readDoubleLE=function(m,b){return m>>>=0,b||Ce(m,8,this.length),te.read(this,m,!0,52,8)},d.prototype.readDoubleBE=function(m,b){return m>>>=0,b||Ce(m,8,this.length),te.read(this,m,!1,52,8)},d.prototype.writeUIntLE=function(m,b,C,I){if(m=+m,b>>>=0,C>>>=0,!I){var F=i(2,8*C)-1;ye(this,m,b,C,F,0)}var H=1,ne=0;for(this[b]=255&m;++ne<C&&(H*=256);)this[b+ne]=255&m/H;return b+C},d.prototype.writeUIntBE=function(m,b,C,I){if(m=+m,b>>>=0,C>>>=0,!I){var F=i(2,8*C)-1;ye(this,m,b,C,F,0)}var H=C-1,ne=1;for(this[b+H]=255&m;0<=--H&&(ne*=256);)this[b+H]=255&m/ne;return b+C},d.prototype.writeUInt8=function(m,b,C){return m=+m,b>>>=0,C||ye(this,m,b,1,255,0),this[b]=255&m,b+1},d.prototype.writeUInt16LE=function(m,b,C){return m=+m,b>>>=0,C||ye(this,m,b,2,65535,0),this[b]=255&m,this[b+1]=m>>>8,b+2},d.prototype.writeUInt16BE=function(m,b,C){return m=+m,b>>>=0,C||ye(this,m,b,2,65535,0),this[b]=m>>>8,this[b+1]=255&m,b+2},d.prototype.writeUInt32LE=function(m,b,C){return m=+m,b>>>=0,C||ye(this,m,b,4,4294967295,0),this[b+3]=m>>>24,this[b+2]=m>>>16,this[b+1]=m>>>8,this[b]=255&m,b+4},d.prototype.writeUInt32BE=function(m,b,C){return m=+m,b>>>=0,C||ye(this,m,b,4,4294967295,0),this[b]=m>>>24,this[b+1]=m>>>16,this[b+2]=m>>>8,this[b+3]=255&m,b+4},d.prototype.writeIntLE=function(m,b,C,I){if(m=+m,b>>>=0,!I){var F=i(2,8*C-1);ye(this,m,b,C,F-1,-F)}var H=0,ne=1,de=0;for(this[b]=255&m;++H<C&&(ne*=256);)0>m&&de===0&&this[b+H-1]!==0&&(de=1),this[b+H]=255&(m/ne>>0)-de;return b+C},d.prototype.writeIntBE=function(m,b,C,I){if(m=+m,b>>>=0,!I){var F=i(2,8*C-1);ye(this,m,b,C,F-1,-F)}var H=C-1,ne=1,de=0;for(this[b+H]=255&m;0<=--H&&(ne*=256);)0>m&&de===0&&this[b+H+1]!==0&&(de=1),this[b+H]=255&(m/ne>>0)-de;return b+C},d.prototype.writeInt8=function(m,b,C){return m=+m,b>>>=0,C||ye(this,m,b,1,127,-128),0>m&&(m=255+m+1),this[b]=255&m,b+1},d.prototype.writeInt16LE=function(m,b,C){return m=+m,b>>>=0,C||ye(this,m,b,2,32767,-32768),this[b]=255&m,this[b+1]=m>>>8,b+2},d.prototype.writeInt16BE=function(m,b,C){return m=+m,b>>>=0,C||ye(this,m,b,2,32767,-32768),this[b]=m>>>8,this[b+1]=255&m,b+2},d.prototype.writeInt32LE=function(m,b,C){return m=+m,b>>>=0,C||ye(this,m,b,4,2147483647,-2147483648),this[b]=255&m,this[b+1]=m>>>8,this[b+2]=m>>>16,this[b+3]=m>>>24,b+4},d.prototype.writeInt32BE=function(m,b,C){return m=+m,b>>>=0,C||ye(this,m,b,4,2147483647,-2147483648),0>m&&(m=4294967295+m+1),this[b]=m>>>24,this[b+1]=m>>>16,this[b+2]=m>>>8,this[b+3]=255&m,b+4},d.prototype.writeFloatLE=function(m,b,C){return Le(this,m,b,!0,C)},d.prototype.writeFloatBE=function(m,b,C){return Le(this,m,b,!1,C)},d.prototype.writeDoubleLE=function(m,b,C){return tt(this,m,b,!0,C)},d.prototype.writeDoubleBE=function(m,b,C){return tt(this,m,b,!1,C)},d.prototype.copy=function(m,b,C,I){if(!d.isBuffer(m))throw new TypeError("argument should be a Buffer");if(C||(C=0),I||I===0||(I=this.length),b>=m.length&&(b=m.length),b||(b=0),0<I&&I<C&&(I=C),I===C||m.length===0||this.length===0)return 0;if(0>b)throw new RangeError("targetStart out of bounds");if(0>C||C>=this.length)throw new RangeError("Index out of range");if(0>I)throw new RangeError("sourceEnd out of bounds");I>this.length&&(I=this.length),m.length-b<I-C&&(I=m.length-b+C);var F=I-C;if(this===m&&typeof Uint8Array.prototype.copyWithin=="function")this.copyWithin(b,C,I);else if(this===m&&C<b&&b<I)for(var H=F-1;0<=H;--H)m[H+b]=this[H+C];else Uint8Array.prototype.set.call(m,this.subarray(C,I),b);return F},d.prototype.fill=function(m,b,C,I){if(typeof m=="string"){if(typeof b=="string"?(I=b,b=0,C=this.length):typeof C=="string"&&(I=C,C=this.length),I!==void 0&&typeof I!="string")throw new TypeError("encoding must be a string");if(typeof I=="string"&&!d.isEncoding(I))throw new TypeError("Unknown encoding: "+I);if(m.length===1){var F=m.charCodeAt(0);(I==="utf8"&&128>F||I==="latin1")&&(m=F)}}else typeof m=="number"&&(m&=255);if(0>b||this.length<b||this.length<C)throw new RangeError("Out of range index");if(C<=b)return this;b>>>=0,C=C===void 0?this.length:C>>>0,m||(m=0);var H;if(typeof m=="number")for(H=b;H<C;++H)this[H]=m;else{var ne=d.isBuffer(m)?m:d.from(m,I),de=ne.length;if(de===0)throw new TypeError('The value "'+m+'" is invalid for argument "value"');for(H=0;H<C-b;++H)this[H+b]=ne[H%de]}return this};var M=/[^+/0-9A-Za-z-_]/g}).call(this)}).call(this,s("buffer").Buffer)},{"base64-js":1,buffer:3,ieee754:9}],4:[function(s,o,l){(function(a){(function(){function c(){let d;try{d=l.storage.getItem("debug")}catch{}return!d&&typeof a<"u"&&"env"in a&&(d=a.env.DEBUG),d}l.formatArgs=function(d){if(d[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+d[0]+(this.useColors?"%c ":" ")+"+"+o.exports.humanize(this.diff),!this.useColors)return;const f="color: "+this.color;d.splice(1,0,f,"color: inherit");let h=0,p=0;d[0].replace(/%[a-zA-Z%]/g,g=>{g==="%%"||(h++,g==="%c"&&(p=h))}),d.splice(p,0,f)},l.save=function(d){try{d?l.storage.setItem("debug",d):l.storage.removeItem("debug")}catch{}},l.load=c,l.useColors=function(){return!!(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))||!(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&(typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&31<=parseInt(RegExp.$1,10)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},l.storage=function(){try{return localStorage}catch{}}(),l.destroy=(()=>{let d=!1;return()=>{d||(d=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),l.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],l.log=console.debug||console.log||(()=>{}),o.exports=s("./common")(l);const{formatters:u}=o.exports;u.j=function(d){try{return JSON.stringify(d)}catch(f){return"[UnexpectedJSONParseError]: "+f.message}}}).call(this)}).call(this,s("_process"))},{"./common":5,_process:12}],5:[function(s,o){o.exports=function(l){function a(d){function f(...g){if(!f.enabled)return;const v=f,w=+new Date,S=w-(h||w);v.diff=S,v.prev=h,v.curr=w,h=w,g[0]=a.coerce(g[0]),typeof g[0]!="string"&&g.unshift("%O");let x=0;g[0]=g[0].replace(/%([a-zA-Z%])/g,(k,E)=>{if(k==="%%")return"%";x++;const T=a.formatters[E];if(typeof T=="function"){const N=g[x];k=T.call(v,N),g.splice(x,1),x--}return k}),a.formatArgs.call(v,g),(v.log||a.log).apply(v,g)}let h,p=null;return f.namespace=d,f.useColors=a.useColors(),f.color=a.selectColor(d),f.extend=c,f.destroy=a.destroy,Object.defineProperty(f,"enabled",{enumerable:!0,configurable:!1,get:()=>p===null?a.enabled(d):p,set:g=>{p=g}}),typeof a.init=="function"&&a.init(f),f}function c(d,f){const h=a(this.namespace+(typeof f>"u"?":":f)+d);return h.log=this.log,h}function u(d){return d.toString().substring(2,d.toString().length-2).replace(/\.\*\?$/,"*")}return a.debug=a,a.default=a,a.coerce=function(d){return d instanceof Error?d.stack||d.message:d},a.disable=function(){const d=[...a.names.map(u),...a.skips.map(u).map(f=>"-"+f)].join(",");return a.enable(""),d},a.enable=function(d){a.save(d),a.names=[],a.skips=[];let f;const h=(typeof d=="string"?d:"").split(/[\s,]+/),p=h.length;for(f=0;f<p;f++)h[f]&&(d=h[f].replace(/\*/g,".*?"),d[0]==="-"?a.skips.push(new RegExp("^"+d.substr(1)+"$")):a.names.push(new RegExp("^"+d+"$")))},a.enabled=function(d){if(d[d.length-1]==="*")return!0;let f,h;for(f=0,h=a.skips.length;f<h;f++)if(a.skips[f].test(d))return!1;for(f=0,h=a.names.length;f<h;f++)if(a.names[f].test(d))return!0;return!1},a.humanize=s("ms"),a.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(l).forEach(d=>{a[d]=l[d]}),a.names=[],a.skips=[],a.formatters={},a.selectColor=function(d){let f=0;for(let h=0;h<d.length;h++)f=(f<<5)-f+d.charCodeAt(h),f|=0;return a.colors[r(f)%a.colors.length]},a.enable(a.load()),a}},{ms:11}],6:[function(s,o){function l(a,c){for(const u in c)Object.defineProperty(a,u,{value:c[u],enumerable:!0,configurable:!0});return a}o.exports=function(a,c,u){if(!a||typeof a=="string")throw new TypeError("Please pass an Error to err-code");u||(u={}),typeof c=="object"&&(u=c,c=""),c&&(u.code=c);try{return l(a,u)}catch{u.message=a.message,u.stack=a.stack;const f=function(){};return f.prototype=Object.create(Object.getPrototypeOf(a)),l(new f,u)}}},{}],7:[function(s,o){function l(A){console&&console.warn&&console.warn(A)}function a(){a.init.call(this)}function c(A){if(typeof A!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof A)}function u(A){return A._maxListeners===void 0?a.defaultMaxListeners:A._maxListeners}function d(A,R,P,$){var V,U,J;if(c(P),U=A._events,U===void 0?(U=A._events=Object.create(null),A._eventsCount=0):(U.newListener!==void 0&&(A.emit("newListener",R,P.listener?P.listener:P),U=A._events),J=U[R]),J===void 0)J=U[R]=P,++A._eventsCount;else if(typeof J=="function"?J=U[R]=$?[P,J]:[J,P]:$?J.unshift(P):J.push(P),V=u(A),0<V&&J.length>V&&!J.warned){J.warned=!0;var G=new Error("Possible EventEmitter memory leak detected. "+J.length+" "+(R+" listeners added. Use emitter.setMaxListeners() to increase limit"));G.name="MaxListenersExceededWarning",G.emitter=A,G.type=R,G.count=J.length,l(G)}return A}function f(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function h(A,R,P){var $={fired:!1,wrapFn:void 0,target:A,type:R,listener:P},V=f.bind($);return V.listener=P,$.wrapFn=V,V}function p(A,R,P){var $=A._events;if($===void 0)return[];var V=$[R];return V===void 0?[]:typeof V=="function"?P?[V.listener||V]:[V]:P?S(V):v(V,V.length)}function g(A){var R=this._events;if(R!==void 0){var P=R[A];if(typeof P=="function")return 1;if(P!==void 0)return P.length}return 0}function v(A,R){for(var P=Array(R),$=0;$<R;++$)P[$]=A[$];return P}function w(A,R){for(;R+1<A.length;R++)A[R]=A[R+1];A.pop()}function S(A){for(var R=Array(A.length),P=0;P<R.length;++P)R[P]=A[P].listener||A[P];return R}function x(A,R,P){typeof A.on=="function"&&y(A,"error",R,P)}function y(A,R,P,$){if(typeof A.on=="function")$.once?A.once(R,P):A.on(R,P);else if(typeof A.addEventListener=="function")A.addEventListener(R,function V(U){$.once&&A.removeEventListener(R,V),P(U)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof A)}var k,E=typeof Reflect=="object"?Reflect:null,T=E&&typeof E.apply=="function"?E.apply:function(A,R,P){return Function.prototype.apply.call(A,R,P)};k=E&&typeof E.ownKeys=="function"?E.ownKeys:Object.getOwnPropertySymbols?function(A){return Object.getOwnPropertyNames(A).concat(Object.getOwnPropertySymbols(A))}:function(A){return Object.getOwnPropertyNames(A)};var N=Number.isNaN||function(A){return A!==A};o.exports=a,o.exports.once=function(A,R){return new Promise(function(P,$){function V(J){A.removeListener(R,U),$(J)}function U(){typeof A.removeListener=="function"&&A.removeListener("error",V),P([].slice.call(arguments))}y(A,R,U,{once:!0}),R!=="error"&&x(A,V,{once:!0})})},a.EventEmitter=a,a.prototype._events=void 0,a.prototype._eventsCount=0,a.prototype._maxListeners=void 0;var _=10;Object.defineProperty(a,"defaultMaxListeners",{enumerable:!0,get:function(){return _},set:function(A){if(typeof A!="number"||0>A||N(A))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+A+".");_=A}}),a.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},a.prototype.setMaxListeners=function(A){if(typeof A!="number"||0>A||N(A))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+A+".");return this._maxListeners=A,this},a.prototype.getMaxListeners=function(){return u(this)},a.prototype.emit=function(A){for(var R=[],P=1;P<arguments.length;P++)R.push(arguments[P]);var $=A==="error",V=this._events;if(V!==void 0)$=$&&V.error===void 0;else if(!$)return!1;if($){var U;if(0<R.length&&(U=R[0]),U instanceof Error)throw U;var J=new Error("Unhandled error."+(U?" ("+U.message+")":""));throw J.context=U,J}var G=V[A];if(G===void 0)return!1;if(typeof G=="function")T(G,this,R);else for(var ie=G.length,X=v(G,ie),P=0;P<ie;++P)T(X[P],this,R);return!0},a.prototype.addListener=function(A,R){return d(this,A,R,!1)},a.prototype.on=a.prototype.addListener,a.prototype.prependListener=function(A,R){return d(this,A,R,!0)},a.prototype.once=function(A,R){return c(R),this.on(A,h(this,A,R)),this},a.prototype.prependOnceListener=function(A,R){return c(R),this.prependListener(A,h(this,A,R)),this},a.prototype.removeListener=function(A,R){var P,$,V,U,J;if(c(R),$=this._events,$===void 0)return this;if(P=$[A],P===void 0)return this;if(P===R||P.listener===R)--this._eventsCount==0?this._events=Object.create(null):(delete $[A],$.removeListener&&this.emit("removeListener",A,P.listener||R));else if(typeof P!="function"){for(V=-1,U=P.length-1;0<=U;U--)if(P[U]===R||P[U].listener===R){J=P[U].listener,V=U;break}if(0>V)return this;V===0?P.shift():w(P,V),P.length===1&&($[A]=P[0]),$.removeListener!==void 0&&this.emit("removeListener",A,J||R)}return this},a.prototype.off=a.prototype.removeListener,a.prototype.removeAllListeners=function(A){var R,P,$;if(P=this._events,P===void 0)return this;if(P.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):P[A]!==void 0&&(--this._eventsCount==0?this._events=Object.create(null):delete P[A]),this;if(arguments.length===0){var V,U=Object.keys(P);for($=0;$<U.length;++$)V=U[$],V!=="removeListener"&&this.removeAllListeners(V);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(R=P[A],typeof R=="function")this.removeListener(A,R);else if(R!==void 0)for($=R.length-1;0<=$;$--)this.removeListener(A,R[$]);return this},a.prototype.listeners=function(A){return p(this,A,!0)},a.prototype.rawListeners=function(A){return p(this,A,!1)},a.listenerCount=function(A,R){return typeof A.listenerCount=="function"?A.listenerCount(R):g.call(A,R)},a.prototype.listenerCount=g,a.prototype.eventNames=function(){return 0<this._eventsCount?k(this._events):[]}},{}],8:[function(s,o){o.exports=function(){if(typeof globalThis>"u")return null;var l={RTCPeerConnection:globalThis.RTCPeerConnection||globalThis.mozRTCPeerConnection||globalThis.webkitRTCPeerConnection,RTCSessionDescription:globalThis.RTCSessionDescription||globalThis.mozRTCSessionDescription||globalThis.webkitRTCSessionDescription,RTCIceCandidate:globalThis.RTCIceCandidate||globalThis.mozRTCIceCandidate||globalThis.webkitRTCIceCandidate};return l.RTCPeerConnection?l:null}},{}],9:[function(s,o,l){/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */l.read=function(a,c,u,d,f){var h,p,g=8*f-d-1,v=(1<<g)-1,w=v>>1,S=-7,x=u?f-1:0,y=u?-1:1,k=a[c+x];for(x+=y,h=k&(1<<-S)-1,k>>=-S,S+=g;0<S;h=256*h+a[c+x],x+=y,S-=8);for(p=h&(1<<-S)-1,h>>=-S,S+=d;0<S;p=256*p+a[c+x],x+=y,S-=8);if(h===0)h=1-w;else{if(h===v)return p?NaN:(k?-1:1)*(1/0);p+=i(2,d),h-=w}return(k?-1:1)*p*i(2,h-d)},l.write=function(a,c,u,d,f,h){var p,g,v,w=Math.LN2,S=Math.log,x=8*h-f-1,y=(1<<x)-1,k=y>>1,E=f===23?i(2,-24)-i(2,-77):0,T=d?0:h-1,N=d?1:-1,_=0>c||c===0&&0>1/c?1:0;for(c=r(c),isNaN(c)||c===1/0?(g=isNaN(c)?1:0,p=y):(p=t(S(c)/w),1>c*(v=i(2,-p))&&(p--,v*=2),c+=1<=p+k?E/v:E*i(2,1-k),2<=c*v&&(p++,v/=2),p+k>=y?(g=0,p=y):1<=p+k?(g=(c*v-1)*i(2,f),p+=k):(g=c*i(2,k-1)*i(2,f),p=0));8<=f;a[u+T]=255&g,T+=N,g/=256,f-=8);for(p=p<<f|g,x+=f;0<x;a[u+T]=255&p,T+=N,p/=256,x-=8);a[u+T-N]|=128*_}},{}],10:[function(s,o){o.exports=typeof Object.create=="function"?function(l,a){a&&(l.super_=a,l.prototype=Object.create(a.prototype,{constructor:{value:l,enumerable:!1,writable:!0,configurable:!0}}))}:function(l,a){if(a){l.super_=a;var c=function(){};c.prototype=a.prototype,l.prototype=new c,l.prototype.constructor=l}}},{}],11:[function(s,o){var l=Math.round;function a(f){if(f+="",!(100<f.length)){var h=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(f);if(h){var p=parseFloat(h[1]),g=(h[2]||"ms").toLowerCase();return g==="years"||g==="year"||g==="yrs"||g==="yr"||g==="y"?315576e5*p:g==="weeks"||g==="week"||g==="w"?6048e5*p:g==="days"||g==="day"||g==="d"?864e5*p:g==="hours"||g==="hour"||g==="hrs"||g==="hr"||g==="h"?36e5*p:g==="minutes"||g==="minute"||g==="mins"||g==="min"||g==="m"?6e4*p:g==="seconds"||g==="second"||g==="secs"||g==="sec"||g==="s"?1e3*p:g==="milliseconds"||g==="millisecond"||g==="msecs"||g==="msec"||g==="ms"?p:void 0}}}function c(f){var h=r(f);return 864e5<=h?l(f/864e5)+"d":36e5<=h?l(f/36e5)+"h":6e4<=h?l(f/6e4)+"m":1e3<=h?l(f/1e3)+"s":f+"ms"}function u(f){var h=r(f);return 864e5<=h?d(f,h,864e5,"day"):36e5<=h?d(f,h,36e5,"hour"):6e4<=h?d(f,h,6e4,"minute"):1e3<=h?d(f,h,1e3,"second"):f+" ms"}function d(f,h,p,g){return l(f/p)+" "+g+(h>=1.5*p?"s":"")}o.exports=function(f,h){h=h||{};var p=typeof f;if(p=="string"&&0<f.length)return a(f);if(p==="number"&&isFinite(f))return h.long?u(f):c(f);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(f))}},{}],12:[function(s,o){function l(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function c(E){if(g===setTimeout)return setTimeout(E,0);if((g===l||!g)&&setTimeout)return g=setTimeout,setTimeout(E,0);try{return g(E,0)}catch{try{return g.call(null,E,0)}catch{return g.call(this,E,0)}}}function u(E){if(v===clearTimeout)return clearTimeout(E);if((v===a||!v)&&clearTimeout)return v=clearTimeout,clearTimeout(E);try{return v(E)}catch{try{return v.call(null,E)}catch{return v.call(this,E)}}}function d(){y&&S&&(y=!1,S.length?x=S.concat(x):k=-1,x.length&&f())}function f(){if(!y){var E=c(d);y=!0;for(var T=x.length;T;){for(S=x,x=[];++k<T;)S&&S[k].run();k=-1,T=x.length}S=null,y=!1,u(E)}}function h(E,T){this.fun=E,this.array=T}function p(){}var g,v,w=o.exports={};(function(){try{g=typeof setTimeout=="function"?setTimeout:l}catch{g=l}try{v=typeof clearTimeout=="function"?clearTimeout:a}catch{v=a}})();var S,x=[],y=!1,k=-1;w.nextTick=function(E){var T=Array(arguments.length-1);if(1<arguments.length)for(var N=1;N<arguments.length;N++)T[N-1]=arguments[N];x.push(new h(E,T)),x.length!==1||y||c(f)},h.prototype.run=function(){this.fun.apply(null,this.array)},w.title="browser",w.browser=!0,w.env={},w.argv=[],w.version="",w.versions={},w.on=p,w.addListener=p,w.once=p,w.off=p,w.removeListener=p,w.removeAllListeners=p,w.emit=p,w.prependListener=p,w.prependOnceListener=p,w.listeners=function(){return[]},w.binding=function(){throw new Error("process.binding is not supported")},w.cwd=function(){return"/"},w.chdir=function(){throw new Error("process.chdir is not supported")},w.umask=function(){return 0}},{}],13:[function(s,o){(function(l){(function(){/*! queue-microtask. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */let a;o.exports=typeof queueMicrotask=="function"?queueMicrotask.bind(typeof window>"u"?l:window):c=>(a||(a=Promise.resolve())).then(c).catch(u=>setTimeout(()=>{throw u},0))}).call(this)}).call(this,typeof On>"u"?typeof self>"u"?typeof window>"u"?{}:window:self:On)},{}],14:[function(s,o){(function(l,a){(function(){var c=s("safe-buffer").Buffer,u=a.crypto||a.msCrypto;o.exports=u&&u.getRandomValues?function(d,f){if(d>4294967295)throw new RangeError("requested too many random bytes");var h=c.allocUnsafe(d);if(0<d)if(65536<d)for(var p=0;p<d;p+=65536)u.getRandomValues(h.slice(p,p+65536));else u.getRandomValues(h);return typeof f=="function"?l.nextTick(function(){f(null,h)}):h}:function(){throw new Error(`Secure random number generation is not supported by this browser.
|
325
325
|
Use Chrome, Firefox or Internet Explorer 11`)}}).call(this)}).call(this,s("_process"),typeof On>"u"?typeof self>"u"?typeof window>"u"?{}:window:self:On)},{_process:12,"safe-buffer":30}],15:[function(s,o){function l(p,g){p.prototype=Object.create(g.prototype),p.prototype.constructor=p,p.__proto__=g}function a(p,g,v){function w(x,y,k){return typeof g=="string"?g:g(x,y,k)}v||(v=Error);var S=function(x){function y(k,E,T){return x.call(this,w(k,E,T))||this}return l(y,x),y}(v);S.prototype.name=v.name,S.prototype.code=p,h[p]=S}function c(p,g){if(Array.isArray(p)){var v=p.length;return p=p.map(function(w){return w+""}),2<v?"one of ".concat(g," ").concat(p.slice(0,v-1).join(", "),", or ")+p[v-1]:v===2?"one of ".concat(g," ").concat(p[0]," or ").concat(p[1]):"of ".concat(g," ").concat(p[0])}return"of ".concat(g," ").concat(p+"")}function u(p,g,v){return p.substr(0,g.length)===g}function d(p,g,v){return(v===void 0||v>p.length)&&(v=p.length),p.substring(v-g.length,v)===g}function f(p,g,v){return typeof v!="number"&&(v=0),!(v+g.length>p.length)&&p.indexOf(g,v)!==-1}var h={};a("ERR_INVALID_OPT_VALUE",function(p,g){return'The value "'+g+'" is invalid for option "'+p+'"'},TypeError),a("ERR_INVALID_ARG_TYPE",function(p,g,v){var w;typeof g=="string"&&u(g,"not ")?(w="must not be",g=g.replace(/^not /,"")):w="must be";var S;if(d(p," argument"))S="The ".concat(p," ").concat(w," ").concat(c(g,"type"));else{var x=f(p,".")?"property":"argument";S='The "'.concat(p,'" ').concat(x," ").concat(w," ").concat(c(g,"type"))}return S+=". Received type ".concat(typeof v),S},TypeError),a("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),a("ERR_METHOD_NOT_IMPLEMENTED",function(p){return"The "+p+" method is not implemented"}),a("ERR_STREAM_PREMATURE_CLOSE","Premature close"),a("ERR_STREAM_DESTROYED",function(p){return"Cannot call "+p+" after a stream was destroyed"}),a("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),a("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),a("ERR_STREAM_WRITE_AFTER_END","write after end"),a("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),a("ERR_UNKNOWN_ENCODING",function(p){return"Unknown encoding: "+p},TypeError),a("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),o.exports.codes=h},{}],16:[function(s,o){(function(l){(function(){function a(w){return this instanceof a?(f.call(this,w),h.call(this,w),this.allowHalfOpen=!0,void(w&&(w.readable===!1&&(this.readable=!1),w.writable===!1&&(this.writable=!1),w.allowHalfOpen===!1&&(this.allowHalfOpen=!1,this.once("end",c))))):new a(w)}function c(){this._writableState.ended||l.nextTick(u,this)}function u(w){w.end()}var d=Object.keys||function(w){var S=[];for(var x in w)S.push(x);return S};o.exports=a;var f=s("./_stream_readable"),h=s("./_stream_writable");s("inherits")(a,f);for(var p,g=d(h.prototype),v=0;v<g.length;v++)p=g[v],a.prototype[p]||(a.prototype[p]=h.prototype[p]);Object.defineProperty(a.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(a.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(a.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(a.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState!==void 0&&this._writableState!==void 0&&this._readableState.destroyed&&this._writableState.destroyed},set:function(w){this._readableState===void 0||this._writableState===void 0||(this._readableState.destroyed=w,this._writableState.destroyed=w)}})}).call(this)}).call(this,s("_process"))},{"./_stream_readable":18,"./_stream_writable":20,_process:12,inherits:10}],17:[function(s,o){function l(c){return this instanceof l?void a.call(this,c):new l(c)}o.exports=l;var a=s("./_stream_transform");s("inherits")(l,a),l.prototype._transform=function(c,u,d){d(null,c)}},{"./_stream_transform":19,inherits:10}],18:[function(s,o){(function(l,a){(function(){function c(M){return Pe.from(M)}function u(M){return Pe.isBuffer(M)||M instanceof Ce}function d(M,m,b){return typeof M.prependListener=="function"?M.prependListener(m,b):void(M._events&&M._events[m]?Array.isArray(M._events[m])?M._events[m].unshift(b):M._events[m]=[b,M._events[m]]:M.on(m,b))}function f(M,m,b){ie=ie||s("./_stream_duplex"),M=M||{},typeof b!="boolean"&&(b=m instanceof ie),this.objectMode=!!M.objectMode,b&&(this.objectMode=this.objectMode||!!M.readableObjectMode),this.highWaterMark=Ot(this,M,"readableHighWaterMark",b),this.buffer=new nt,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=M.emitClose!==!1,this.autoDestroy=!!M.autoDestroy,this.destroyed=!1,this.defaultEncoding=M.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,M.encoding&&(!Ne&&(Ne=s("string_decoder/").StringDecoder),this.decoder=new Ne(M.encoding),this.encoding=M.encoding)}function h(M){if(ie=ie||s("./_stream_duplex"),!(this instanceof h))return new h(M);var m=this instanceof ie;this._readableState=new f(M,this,m),this.readable=!0,M&&(typeof M.read=="function"&&(this._read=M.read),typeof M.destroy=="function"&&(this._destroy=M.destroy)),Re.call(this)}function p(M,m,b,C,I){X("readableAddChunk",m);var F=M._readableState;if(m===null)F.reading=!1,x(M,F);else{var H;if(I||(H=v(F,m)),H)q(M,H);else if(!(F.objectMode||m&&0<m.length))C||(F.reading=!1,E(M,F));else if(typeof m=="string"||F.objectMode||Object.getPrototypeOf(m)===Pe.prototype||(m=c(m)),C)F.endEmitted?q(M,new j):g(M,F,m,!0);else if(F.ended)q(M,new at);else{if(F.destroyed)return!1;F.reading=!1,F.decoder&&!b?(m=F.decoder.write(m),F.objectMode||m.length!==0?g(M,F,m,!1):E(M,F)):g(M,F,m,!1)}}return!F.ended&&(F.length<F.highWaterMark||F.length===0)}function g(M,m,b,C){m.flowing&&m.length===0&&!m.sync?(m.awaitDrain=0,M.emit("data",b)):(m.length+=m.objectMode?1:b.length,C?m.buffer.unshift(b):m.buffer.push(b),m.needReadable&&y(M)),E(M,m)}function v(M,m){var b;return u(m)||typeof m=="string"||m===void 0||M.objectMode||(b=new it("chunk",["string","Buffer","Uint8Array"],m)),b}function w(M){return 1073741824<=M?M=1073741824:(M--,M|=M>>>1,M|=M>>>2,M|=M>>>4,M|=M>>>8,M|=M>>>16,M++),M}function S(M,m){return 0>=M||m.length===0&&m.ended?0:m.objectMode?1:M===M?(M>m.highWaterMark&&(m.highWaterMark=w(M)),M<=m.length?M:m.ended?m.length:(m.needReadable=!0,0)):m.flowing&&m.length?m.buffer.head.data.length:m.length}function x(M,m){if(X("onEofChunk"),!m.ended){if(m.decoder){var b=m.decoder.end();b&&b.length&&(m.buffer.push(b),m.length+=m.objectMode?1:b.length)}m.ended=!0,m.sync?y(M):(m.needReadable=!1,!m.emittedReadable&&(m.emittedReadable=!0,k(M)))}}function y(M){var m=M._readableState;X("emitReadable",m.needReadable,m.emittedReadable),m.needReadable=!1,m.emittedReadable||(X("emitReadable",m.flowing),m.emittedReadable=!0,l.nextTick(k,M))}function k(M){var m=M._readableState;X("emitReadable_",m.destroyed,m.length,m.ended),!m.destroyed&&(m.length||m.ended)&&(M.emit("readable"),m.emittedReadable=!1),m.needReadable=!m.flowing&&!m.ended&&m.length<=m.highWaterMark,$(M)}function E(M,m){m.readingMore||(m.readingMore=!0,l.nextTick(T,M,m))}function T(M,m){for(;!m.reading&&!m.ended&&(m.length<m.highWaterMark||m.flowing&&m.length===0);){var b=m.length;if(X("maybeReadMore read 0"),M.read(0),b===m.length)break}m.readingMore=!1}function N(M){return function(){var m=M._readableState;X("pipeOnDrain",m.awaitDrain),m.awaitDrain&&m.awaitDrain--,m.awaitDrain===0&&we(M,"data")&&(m.flowing=!0,$(M))}}function _(M){var m=M._readableState;m.readableListening=0<M.listenerCount("readable"),m.resumeScheduled&&!m.paused?m.flowing=!0:0<M.listenerCount("data")&&M.resume()}function A(M){X("readable nexttick read 0"),M.read(0)}function R(M,m){m.resumeScheduled||(m.resumeScheduled=!0,l.nextTick(P,M,m))}function P(M,m){X("resume",m.reading),m.reading||M.read(0),m.resumeScheduled=!1,M.emit("resume"),$(M),m.flowing&&!m.reading&&M.read(0)}function $(M){var m=M._readableState;for(X("flow",m.flowing);m.flowing&&M.read()!==null;);}function V(M,m){if(m.length===0)return null;var b;return m.objectMode?b=m.buffer.shift():!M||M>=m.length?(b=m.decoder?m.buffer.join(""):m.buffer.length===1?m.buffer.first():m.buffer.concat(m.length),m.buffer.clear()):b=m.buffer.consume(M,m.decoder),b}function U(M){var m=M._readableState;X("endReadable",m.endEmitted),m.endEmitted||(m.ended=!0,l.nextTick(J,m,M))}function J(M,m){if(X("endReadableNT",M.endEmitted,M.length),!M.endEmitted&&M.length===0&&(M.endEmitted=!0,m.readable=!1,m.emit("end"),M.autoDestroy)){var b=m._writableState;(!b||b.autoDestroy&&b.finished)&&m.destroy()}}function G(M,m){for(var b=0,C=M.length;b<C;b++)if(M[b]===m)return b;return-1}o.exports=h;var ie;h.ReadableState=f;var X;s("events").EventEmitter;var we=function(M,m){return M.listeners(m).length},Re=s("./internal/streams/stream"),Pe=s("buffer").Buffer,Ce=a.Uint8Array||function(){},ye=s("util");X=ye&&ye.debuglog?ye.debuglog("stream"):function(){};var Ne,Le,tt,nt=s("./internal/streams/buffer_list"),Ge=s("./internal/streams/destroy"),Ye=s("./internal/streams/state"),Ot=Ye.getHighWaterMark,xt=s("../errors").codes,it=xt.ERR_INVALID_ARG_TYPE,at=xt.ERR_STREAM_PUSH_AFTER_EOF,B=xt.ERR_METHOD_NOT_IMPLEMENTED,j=xt.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;s("inherits")(h,Re);var q=Ge.errorOrDestroy,te=["error","close","destroy","pause","resume"];Object.defineProperty(h.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState!==void 0&&this._readableState.destroyed},set:function(M){this._readableState&&(this._readableState.destroyed=M)}}),h.prototype.destroy=Ge.destroy,h.prototype._undestroy=Ge.undestroy,h.prototype._destroy=function(M,m){m(M)},h.prototype.push=function(M,m){var b,C=this._readableState;return C.objectMode?b=!0:typeof M=="string"&&(m=m||C.defaultEncoding,m!==C.encoding&&(M=Pe.from(M,m),m=""),b=!0),p(this,M,m,!1,b)},h.prototype.unshift=function(M){return p(this,M,null,!0,!1)},h.prototype.isPaused=function(){return this._readableState.flowing===!1},h.prototype.setEncoding=function(M){Ne||(Ne=s("string_decoder/").StringDecoder);var m=new Ne(M);this._readableState.decoder=m,this._readableState.encoding=this._readableState.decoder.encoding;for(var b=this._readableState.buffer.head,C="";b!==null;)C+=m.write(b.data),b=b.next;return this._readableState.buffer.clear(),C!==""&&this._readableState.buffer.push(C),this._readableState.length=C.length,this},h.prototype.read=function(M){X("read",M),M=parseInt(M,10);var m=this._readableState,b=M;if(M!==0&&(m.emittedReadable=!1),M===0&&m.needReadable&&((m.highWaterMark===0?0<m.length:m.length>=m.highWaterMark)||m.ended))return X("read: emitReadable",m.length,m.ended),m.length===0&&m.ended?U(this):y(this),null;if(M=S(M,m),M===0&&m.ended)return m.length===0&&U(this),null;var C=m.needReadable;X("need readable",C),(m.length===0||m.length-M<m.highWaterMark)&&(C=!0,X("length less than watermark",C)),m.ended||m.reading?(C=!1,X("reading or ended",C)):C&&(X("do read"),m.reading=!0,m.sync=!0,m.length===0&&(m.needReadable=!0),this._read(m.highWaterMark),m.sync=!1,!m.reading&&(M=S(b,m)));var I;return I=0<M?V(M,m):null,I===null?(m.needReadable=m.length<=m.highWaterMark,M=0):(m.length-=M,m.awaitDrain=0),m.length===0&&(!m.ended&&(m.needReadable=!0),b!==M&&m.ended&&U(this)),I!==null&&this.emit("data",I),I},h.prototype._read=function(){q(this,new B("_read()"))},h.prototype.pipe=function(M,m){function b(ee,oe){X("onunpipe"),ee===be&&oe&&oe.hasUnpiped===!1&&(oe.hasUnpiped=!0,I())}function C(){X("onend"),M.end()}function I(){X("cleanup"),M.removeListener("close",ne),M.removeListener("finish",de),M.removeListener("drain",Qn),M.removeListener("error",H),M.removeListener("unpipe",b),be.removeListener("end",C),be.removeListener("end",Oe),be.removeListener("data",F),z=!0,me.awaitDrain&&(!M._writableState||M._writableState.needDrain)&&Qn()}function F(ee){X("ondata");var oe=M.write(ee);X("dest.write",oe),oe===!1&&((me.pipesCount===1&&me.pipes===M||1<me.pipesCount&&G(me.pipes,M)!==-1)&&!z&&(X("false write response, pause",me.awaitDrain),me.awaitDrain++),be.pause())}function H(ee){X("onerror",ee),Oe(),M.removeListener("error",H),we(M,"error")===0&&q(M,ee)}function ne(){M.removeListener("finish",de),Oe()}function de(){X("onfinish"),M.removeListener("close",ne),Oe()}function Oe(){X("unpipe"),be.unpipe(M)}var be=this,me=this._readableState;switch(me.pipesCount){case 0:me.pipes=M;break;case 1:me.pipes=[me.pipes,M];break;default:me.pipes.push(M)}me.pipesCount+=1,X("pipe count=%d opts=%j",me.pipesCount,m);var Ze=(!m||m.end!==!1)&&M!==l.stdout&&M!==l.stderr,An=Ze?C:Oe;me.endEmitted?l.nextTick(An):be.once("end",An),M.on("unpipe",b);var Qn=N(be);M.on("drain",Qn);var z=!1;return be.on("data",F),d(M,"error",H),M.once("close",ne),M.once("finish",de),M.emit("pipe",be),me.flowing||(X("pipe resume"),be.resume()),M},h.prototype.unpipe=function(M){var m=this._readableState,b={hasUnpiped:!1};if(m.pipesCount===0)return this;if(m.pipesCount===1)return M&&M!==m.pipes?this:(M||(M=m.pipes),m.pipes=null,m.pipesCount=0,m.flowing=!1,M&&M.emit("unpipe",this,b),this);if(!M){var C=m.pipes,I=m.pipesCount;m.pipes=null,m.pipesCount=0,m.flowing=!1;for(var F=0;F<I;F++)C[F].emit("unpipe",this,{hasUnpiped:!1});return this}var H=G(m.pipes,M);return H===-1?this:(m.pipes.splice(H,1),m.pipesCount-=1,m.pipesCount===1&&(m.pipes=m.pipes[0]),M.emit("unpipe",this,b),this)},h.prototype.on=function(M,m){var b=Re.prototype.on.call(this,M,m),C=this._readableState;return M==="data"?(C.readableListening=0<this.listenerCount("readable"),C.flowing!==!1&&this.resume()):M=="readable"&&!C.endEmitted&&!C.readableListening&&(C.readableListening=C.needReadable=!0,C.flowing=!1,C.emittedReadable=!1,X("on readable",C.length,C.reading),C.length?y(this):!C.reading&&l.nextTick(A,this)),b},h.prototype.addListener=h.prototype.on,h.prototype.removeListener=function(M,m){var b=Re.prototype.removeListener.call(this,M,m);return M==="readable"&&l.nextTick(_,this),b},h.prototype.removeAllListeners=function(M){var m=Re.prototype.removeAllListeners.apply(this,arguments);return(M==="readable"||M===void 0)&&l.nextTick(_,this),m},h.prototype.resume=function(){var M=this._readableState;return M.flowing||(X("resume"),M.flowing=!M.readableListening,R(this,M)),M.paused=!1,this},h.prototype.pause=function(){return X("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(X("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},h.prototype.wrap=function(M){var m=this,b=this._readableState,C=!1;for(var I in M.on("end",function(){if(X("wrapped end"),b.decoder&&!b.ended){var H=b.decoder.end();H&&H.length&&m.push(H)}m.push(null)}),M.on("data",function(H){if(X("wrapped data"),b.decoder&&(H=b.decoder.write(H)),!(b.objectMode&&H==null)&&(b.objectMode||H&&H.length)){var ne=m.push(H);ne||(C=!0,M.pause())}}),M)this[I]===void 0&&typeof M[I]=="function"&&(this[I]=function(H){return function(){return M[H].apply(M,arguments)}}(I));for(var F=0;F<te.length;F++)M.on(te[F],this.emit.bind(this,te[F]));return this._read=function(H){X("wrapped _read",H),C&&(C=!1,M.resume())},this},typeof Symbol=="function"&&(h.prototype[Symbol.asyncIterator]=function(){return Le===void 0&&(Le=s("./internal/streams/async_iterator")),Le(this)}),Object.defineProperty(h.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(h.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(h.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(M){this._readableState&&(this._readableState.flowing=M)}}),h._fromList=V,Object.defineProperty(h.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}}),typeof Symbol=="function"&&(h.from=function(M,m){return tt===void 0&&(tt=s("./internal/streams/from")),tt(h,M,m)})}).call(this)}).call(this,s("_process"),typeof On>"u"?typeof self>"u"?typeof window>"u"?{}:window:self:On)},{"../errors":15,"./_stream_duplex":16,"./internal/streams/async_iterator":21,"./internal/streams/buffer_list":22,"./internal/streams/destroy":23,"./internal/streams/from":25,"./internal/streams/state":27,"./internal/streams/stream":28,_process:12,buffer:3,events:7,inherits:10,"string_decoder/":31,util:2}],19:[function(s,o){function l(w,S){var x=this._transformState;x.transforming=!1;var y=x.writecb;if(y===null)return this.emit("error",new h);x.writechunk=null,x.writecb=null,S!=null&&this.push(S),y(w);var k=this._readableState;k.reading=!1,(k.needReadable||k.length<k.highWaterMark)&&this._read(k.highWaterMark)}function a(w){return this instanceof a?(v.call(this,w),this._transformState={afterTransform:l.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,w&&(typeof w.transform=="function"&&(this._transform=w.transform),typeof w.flush=="function"&&(this._flush=w.flush)),void this.on("prefinish",c)):new a(w)}function c(){var w=this;typeof this._flush!="function"||this._readableState.destroyed?u(this,null,null):this._flush(function(S,x){u(w,S,x)})}function u(w,S,x){if(S)return w.emit("error",S);if(x!=null&&w.push(x),w._writableState.length)throw new g;if(w._transformState.transforming)throw new p;return w.push(null)}o.exports=a;var d=s("../errors").codes,f=d.ERR_METHOD_NOT_IMPLEMENTED,h=d.ERR_MULTIPLE_CALLBACK,p=d.ERR_TRANSFORM_ALREADY_TRANSFORMING,g=d.ERR_TRANSFORM_WITH_LENGTH_0,v=s("./_stream_duplex");s("inherits")(a,v),a.prototype.push=function(w,S){return this._transformState.needTransform=!1,v.prototype.push.call(this,w,S)},a.prototype._transform=function(w,S,x){x(new f("_transform()"))},a.prototype._write=function(w,S,x){var y=this._transformState;if(y.writecb=x,y.writechunk=w,y.writeencoding=S,!y.transforming){var k=this._readableState;(y.needTransform||k.needReadable||k.length<k.highWaterMark)&&this._read(k.highWaterMark)}},a.prototype._read=function(){var w=this._transformState;w.writechunk===null||w.transforming?w.needTransform=!0:(w.transforming=!0,this._transform(w.writechunk,w.writeencoding,w.afterTransform))},a.prototype._destroy=function(w,S){v.prototype._destroy.call(this,w,function(x){S(x)})}},{"../errors":15,"./_stream_duplex":16,inherits:10}],20:[function(s,o){(function(l,a){(function(){function c(B){var j=this;this.next=null,this.entry=null,this.finish=function(){U(j,B)}}function u(B){return X.from(B)}function d(B){return X.isBuffer(B)||B instanceof we}function f(){}function h(B,j,q){J=J||s("./_stream_duplex"),B=B||{},typeof q!="boolean"&&(q=j instanceof J),this.objectMode=!!B.objectMode,q&&(this.objectMode=this.objectMode||!!B.writableObjectMode),this.highWaterMark=Ce(this,B,"writableHighWaterMark",q),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var te=B.decodeStrings===!1;this.decodeStrings=!te,this.defaultEncoding=B.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(M){E(j,M)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=B.emitClose!==!1,this.autoDestroy=!!B.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new c(this)}function p(B){J=J||s("./_stream_duplex");var j=this instanceof J;return j||at.call(p,this)?(this._writableState=new h(B,this,j),this.writable=!0,B&&(typeof B.write=="function"&&(this._write=B.write),typeof B.writev=="function"&&(this._writev=B.writev),typeof B.destroy=="function"&&(this._destroy=B.destroy),typeof B.final=="function"&&(this._final=B.final)),void ie.call(this)):new p(B)}function g(B,j){var q=new Ot;it(B,q),l.nextTick(j,q)}function v(B,j,q,te){var M;return q===null?M=new Ye:typeof q!="string"&&!j.objectMode&&(M=new Ne("chunk",["string","Buffer"],q)),!M||(it(B,M),l.nextTick(te,M),!1)}function w(B,j,q){return B.objectMode||B.decodeStrings===!1||typeof j!="string"||(j=X.from(j,q)),j}function S(B,j,q,te,M,m){if(!q){var b=w(j,te,M);te!==b&&(q=!0,M="buffer",te=b)}var C=j.objectMode?1:te.length;j.length+=C;var I=j.length<j.highWaterMark;if(I||(j.needDrain=!0),j.writing||j.corked){var F=j.lastBufferedRequest;j.lastBufferedRequest={chunk:te,encoding:M,isBuf:q,callback:m,next:null},F?F.next=j.lastBufferedRequest:j.bufferedRequest=j.lastBufferedRequest,j.bufferedRequestCount+=1}else x(B,j,!1,C,te,M,m);return I}function x(B,j,q,te,M,m,b){j.writelen=te,j.writecb=b,j.writing=!0,j.sync=!0,j.destroyed?j.onwrite(new Ge("write")):q?B._writev(M,j.onwrite):B._write(M,m,j.onwrite),j.sync=!1}function y(B,j,q,te,M){--j.pendingcb,q?(l.nextTick(M,te),l.nextTick($,B,j),B._writableState.errorEmitted=!0,it(B,te)):(M(te),B._writableState.errorEmitted=!0,it(B,te),$(B,j))}function k(B){B.writing=!1,B.writecb=null,B.length-=B.writelen,B.writelen=0}function E(B,j){var q=B._writableState,te=q.sync,M=q.writecb;if(typeof M!="function")throw new tt;if(k(q),j)y(B,q,te,j,M);else{var m=A(q)||B.destroyed;m||q.corked||q.bufferProcessing||!q.bufferedRequest||_(B,q),te?l.nextTick(T,B,q,m,M):T(B,q,m,M)}}function T(B,j,q,te){q||N(B,j),j.pendingcb--,te(),$(B,j)}function N(B,j){j.length===0&&j.needDrain&&(j.needDrain=!1,B.emit("drain"))}function _(B,j){j.bufferProcessing=!0;var q=j.bufferedRequest;if(B._writev&&q&&q.next){var te=j.bufferedRequestCount,M=Array(te),m=j.corkedRequestsFree;m.entry=q;for(var b=0,C=!0;q;)M[b]=q,q.isBuf||(C=!1),q=q.next,b+=1;M.allBuffers=C,x(B,j,!0,j.length,M,"",m.finish),j.pendingcb++,j.lastBufferedRequest=null,m.next?(j.corkedRequestsFree=m.next,m.next=null):j.corkedRequestsFree=new c(j),j.bufferedRequestCount=0}else{for(;q;){var I=q.chunk,F=q.encoding,H=q.callback,ne=j.objectMode?1:I.length;if(x(B,j,!1,ne,I,F,H),q=q.next,j.bufferedRequestCount--,j.writing)break}q===null&&(j.lastBufferedRequest=null)}j.bufferedRequest=q,j.bufferProcessing=!1}function A(B){return B.ending&&B.length===0&&B.bufferedRequest===null&&!B.finished&&!B.writing}function R(B,j){B._final(function(q){j.pendingcb--,q&&it(B,q),j.prefinished=!0,B.emit("prefinish"),$(B,j)})}function P(B,j){j.prefinished||j.finalCalled||(typeof B._final!="function"||j.destroyed?(j.prefinished=!0,B.emit("prefinish")):(j.pendingcb++,j.finalCalled=!0,l.nextTick(R,B,j)))}function $(B,j){var q=A(j);if(q&&(P(B,j),j.pendingcb===0&&(j.finished=!0,B.emit("finish"),j.autoDestroy))){var te=B._readableState;(!te||te.autoDestroy&&te.endEmitted)&&B.destroy()}return q}function V(B,j,q){j.ending=!0,$(B,j),q&&(j.finished?l.nextTick(q):B.once("finish",q)),j.ended=!0,B.writable=!1}function U(B,j,q){var te=B.entry;for(B.entry=null;te;){var M=te.callback;j.pendingcb--,M(q),te=te.next}j.corkedRequestsFree.next=B}o.exports=p;var J;p.WritableState=h;var G={deprecate:s("util-deprecate")},ie=s("./internal/streams/stream"),X=s("buffer").Buffer,we=a.Uint8Array||function(){},Re=s("./internal/streams/destroy"),Pe=s("./internal/streams/state"),Ce=Pe.getHighWaterMark,ye=s("../errors").codes,Ne=ye.ERR_INVALID_ARG_TYPE,Le=ye.ERR_METHOD_NOT_IMPLEMENTED,tt=ye.ERR_MULTIPLE_CALLBACK,nt=ye.ERR_STREAM_CANNOT_PIPE,Ge=ye.ERR_STREAM_DESTROYED,Ye=ye.ERR_STREAM_NULL_VALUES,Ot=ye.ERR_STREAM_WRITE_AFTER_END,xt=ye.ERR_UNKNOWN_ENCODING,it=Re.errorOrDestroy;s("inherits")(p,ie),h.prototype.getBuffer=function(){for(var B=this.bufferedRequest,j=[];B;)j.push(B),B=B.next;return j},function(){try{Object.defineProperty(h.prototype,"buffer",{get:G.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}}();var at;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(at=Function.prototype[Symbol.hasInstance],Object.defineProperty(p,Symbol.hasInstance,{value:function(B){return!!at.call(this,B)||this===p&&B&&B._writableState instanceof h}})):at=function(B){return B instanceof this},p.prototype.pipe=function(){it(this,new nt)},p.prototype.write=function(B,j,q){var te=this._writableState,M=!1,m=!te.objectMode&&d(B);return m&&!X.isBuffer(B)&&(B=u(B)),typeof j=="function"&&(q=j,j=null),m?j="buffer":!j&&(j=te.defaultEncoding),typeof q!="function"&&(q=f),te.ending?g(this,q):(m||v(this,te,B,q))&&(te.pendingcb++,M=S(this,te,m,B,j,q)),M},p.prototype.cork=function(){this._writableState.corked++},p.prototype.uncork=function(){var B=this._writableState;B.corked&&(B.corked--,!B.writing&&!B.corked&&!B.bufferProcessing&&B.bufferedRequest&&_(this,B))},p.prototype.setDefaultEncoding=function(B){if(typeof B=="string"&&(B=B.toLowerCase()),!(-1<["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((B+"").toLowerCase())))throw new xt(B);return this._writableState.defaultEncoding=B,this},Object.defineProperty(p.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(p.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),p.prototype._write=function(B,j,q){q(new Le("_write()"))},p.prototype._writev=null,p.prototype.end=function(B,j,q){var te=this._writableState;return typeof B=="function"?(q=B,B=null,j=null):typeof j=="function"&&(q=j,j=null),B!=null&&this.write(B,j),te.corked&&(te.corked=1,this.uncork()),te.ending||V(this,te,q),this},Object.defineProperty(p.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(p.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState!==void 0&&this._writableState.destroyed},set:function(B){this._writableState&&(this._writableState.destroyed=B)}}),p.prototype.destroy=Re.destroy,p.prototype._undestroy=Re.undestroy,p.prototype._destroy=function(B,j){j(B)}}).call(this)}).call(this,s("_process"),typeof On>"u"?typeof self>"u"?typeof window>"u"?{}:window:self:On)},{"../errors":15,"./_stream_duplex":16,"./internal/streams/destroy":23,"./internal/streams/state":27,"./internal/streams/stream":28,_process:12,buffer:3,inherits:10,"util-deprecate":32}],21:[function(s,o){(function(l){(function(){function a(N,_,A){return _ in N?Object.defineProperty(N,_,{value:A,enumerable:!0,configurable:!0,writable:!0}):N[_]=A,N}function c(N,_){return{value:N,done:_}}function u(N){var _=N[g];if(_!==null){var A=N[k].read();A!==null&&(N[x]=null,N[g]=null,N[v]=null,_(c(A,!1)))}}function d(N){l.nextTick(u,N)}function f(N,_){return function(A,R){N.then(function(){return _[S]?void A(c(void 0,!0)):void _[y](A,R)},R)}}var h,p=s("./end-of-stream"),g=Symbol("lastResolve"),v=Symbol("lastReject"),w=Symbol("error"),S=Symbol("ended"),x=Symbol("lastPromise"),y=Symbol("handlePromise"),k=Symbol("stream"),E=Object.getPrototypeOf(function(){}),T=Object.setPrototypeOf((h={get stream(){return this[k]},next:function(){var N=this,_=this[w];if(_!==null)return Promise.reject(_);if(this[S])return Promise.resolve(c(void 0,!0));if(this[k].destroyed)return new Promise(function($,V){l.nextTick(function(){N[w]?V(N[w]):$(c(void 0,!0))})});var A,R=this[x];if(R)A=new Promise(f(R,this));else{var P=this[k].read();if(P!==null)return Promise.resolve(c(P,!1));A=new Promise(this[y])}return this[x]=A,A}},a(h,Symbol.asyncIterator,function(){return this}),a(h,"return",function(){var N=this;return new Promise(function(_,A){N[k].destroy(null,function(R){return R?void A(R):void _(c(void 0,!0))})})}),h),E);o.exports=function(N){var _,A=Object.create(T,(_={},a(_,k,{value:N,writable:!0}),a(_,g,{value:null,writable:!0}),a(_,v,{value:null,writable:!0}),a(_,w,{value:null,writable:!0}),a(_,S,{value:N._readableState.endEmitted,writable:!0}),a(_,y,{value:function(R,P){var $=A[k].read();$?(A[x]=null,A[g]=null,A[v]=null,R(c($,!1))):(A[g]=R,A[v]=P)},writable:!0}),_));return A[x]=null,p(N,function(R){if(R&&R.code!=="ERR_STREAM_PREMATURE_CLOSE"){var P=A[v];return P!==null&&(A[x]=null,A[g]=null,A[v]=null,P(R)),void(A[w]=R)}var $=A[g];$!==null&&(A[x]=null,A[g]=null,A[v]=null,$(c(void 0,!0))),A[S]=!0}),N.on("readable",d.bind(null,A)),A}}).call(this)}).call(this,s("_process"))},{"./end-of-stream":24,_process:12}],22:[function(s,o){function l(x,y){var k=Object.keys(x);if(Object.getOwnPropertySymbols){var E=Object.getOwnPropertySymbols(x);y&&(E=E.filter(function(T){return Object.getOwnPropertyDescriptor(x,T).enumerable})),k.push.apply(k,E)}return k}function a(x){for(var y,k=1;k<arguments.length;k++)y=arguments[k]==null?{}:arguments[k],k%2?l(Object(y),!0).forEach(function(E){c(x,E,y[E])}):Object.getOwnPropertyDescriptors?Object.defineProperties(x,Object.getOwnPropertyDescriptors(y)):l(Object(y)).forEach(function(E){Object.defineProperty(x,E,Object.getOwnPropertyDescriptor(y,E))});return x}function c(x,y,k){return y in x?Object.defineProperty(x,y,{value:k,enumerable:!0,configurable:!0,writable:!0}):x[y]=k,x}function u(x,y){if(!(x instanceof y))throw new TypeError("Cannot call a class as a function")}function d(x,y){for(var k,E=0;E<y.length;E++)k=y[E],k.enumerable=k.enumerable||!1,k.configurable=!0,"value"in k&&(k.writable=!0),Object.defineProperty(x,k.key,k)}function f(x,y,k){return y&&d(x.prototype,y),x}function h(x,y,k){g.prototype.copy.call(x,y,k)}var p=s("buffer"),g=p.Buffer,v=s("util"),w=v.inspect,S=w&&w.custom||"inspect";o.exports=function(){function x(){u(this,x),this.head=null,this.tail=null,this.length=0}return f(x,[{key:"push",value:function(y){var k={data:y,next:null};0<this.length?this.tail.next=k:this.head=k,this.tail=k,++this.length}},{key:"unshift",value:function(y){var k={data:y,next:this.head};this.length===0&&(this.tail=k),this.head=k,++this.length}},{key:"shift",value:function(){if(this.length!==0){var y=this.head.data;return this.head=this.length===1?this.tail=null:this.head.next,--this.length,y}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(y){if(this.length===0)return"";for(var k=this.head,E=""+k.data;k=k.next;)E+=y+k.data;return E}},{key:"concat",value:function(y){if(this.length===0)return g.alloc(0);for(var k=g.allocUnsafe(y>>>0),E=this.head,T=0;E;)h(E.data,k,T),T+=E.data.length,E=E.next;return k}},{key:"consume",value:function(y,k){var E;return y<this.head.data.length?(E=this.head.data.slice(0,y),this.head.data=this.head.data.slice(y)):y===this.head.data.length?E=this.shift():E=k?this._getString(y):this._getBuffer(y),E}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(y){var k=this.head,E=1,T=k.data;for(y-=T.length;k=k.next;){var N=k.data,_=y>N.length?N.length:y;if(T+=_===N.length?N:N.slice(0,y),y-=_,y===0){_===N.length?(++E,this.head=k.next?k.next:this.tail=null):(this.head=k,k.data=N.slice(_));break}++E}return this.length-=E,T}},{key:"_getBuffer",value:function(y){var k=g.allocUnsafe(y),E=this.head,T=1;for(E.data.copy(k),y-=E.data.length;E=E.next;){var N=E.data,_=y>N.length?N.length:y;if(N.copy(k,k.length-y,0,_),y-=_,y===0){_===N.length?(++T,this.head=E.next?E.next:this.tail=null):(this.head=E,E.data=N.slice(_));break}++T}return this.length-=T,k}},{key:S,value:function(y,k){return w(this,a({},k,{depth:0,customInspect:!1}))}}]),x}()},{buffer:3,util:2}],23:[function(s,o){(function(l){(function(){function a(d,f){u(d,f),c(d)}function c(d){d._writableState&&!d._writableState.emitClose||d._readableState&&!d._readableState.emitClose||d.emit("close")}function u(d,f){d.emit("error",f)}o.exports={destroy:function(d,f){var h=this,p=this._readableState&&this._readableState.destroyed,g=this._writableState&&this._writableState.destroyed;return p||g?(f?f(d):d&&(this._writableState?!this._writableState.errorEmitted&&(this._writableState.errorEmitted=!0,l.nextTick(u,this,d)):l.nextTick(u,this,d)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(d||null,function(v){!f&&v?h._writableState?h._writableState.errorEmitted?l.nextTick(c,h):(h._writableState.errorEmitted=!0,l.nextTick(a,h,v)):l.nextTick(a,h,v):f?(l.nextTick(c,h),f(v)):l.nextTick(c,h)}),this)},undestroy:function(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)},errorOrDestroy:function(d,f){var h=d._readableState,p=d._writableState;h&&h.autoDestroy||p&&p.autoDestroy?d.destroy(f):d.emit("error",f)}}}).call(this)}).call(this,s("_process"))},{_process:12}],24:[function(s,o){function l(f){var h=!1;return function(){if(!h){h=!0;for(var p=arguments.length,g=Array(p),v=0;v<p;v++)g[v]=arguments[v];f.apply(this,g)}}}function a(){}function c(f){return f.setHeader&&typeof f.abort=="function"}function u(f,h,p){if(typeof h=="function")return u(f,null,h);h||(h={}),p=l(p||a);var g=h.readable||h.readable!==!1&&f.readable,v=h.writable||h.writable!==!1&&f.writable,w=function(){f.writable||x()},S=f._writableState&&f._writableState.finished,x=function(){v=!1,S=!0,g||p.call(f)},y=f._readableState&&f._readableState.endEmitted,k=function(){g=!1,y=!0,v||p.call(f)},E=function(_){p.call(f,_)},T=function(){var _;return g&&!y?(f._readableState&&f._readableState.ended||(_=new d),p.call(f,_)):v&&!S?(f._writableState&&f._writableState.ended||(_=new d),p.call(f,_)):void 0},N=function(){f.req.on("finish",x)};return c(f)?(f.on("complete",x),f.on("abort",T),f.req?N():f.on("request",N)):v&&!f._writableState&&(f.on("end",w),f.on("close",w)),f.on("end",k),f.on("finish",x),h.error!==!1&&f.on("error",E),f.on("close",T),function(){f.removeListener("complete",x),f.removeListener("abort",T),f.removeListener("request",N),f.req&&f.req.removeListener("finish",x),f.removeListener("end",w),f.removeListener("close",w),f.removeListener("finish",x),f.removeListener("end",k),f.removeListener("error",E),f.removeListener("close",T)}}var d=s("../../../errors").codes.ERR_STREAM_PREMATURE_CLOSE;o.exports=u},{"../../../errors":15}],25:[function(s,o){o.exports=function(){throw new Error("Readable.from is not available in the browser")}},{}],26:[function(s,o){function l(S){var x=!1;return function(){x||(x=!0,S.apply(void 0,arguments))}}function a(S){if(S)throw S}function c(S){return S.setHeader&&typeof S.abort=="function"}function u(S,x,y,k){k=l(k);var E=!1;S.on("close",function(){E=!0}),p===void 0&&(p=s("./end-of-stream")),p(S,{readable:x,writable:y},function(N){return N?k(N):(E=!0,void k())});var T=!1;return function(N){if(!E)return T?void 0:(T=!0,c(S)?S.abort():typeof S.destroy=="function"?S.destroy():void k(N||new w("pipe")))}}function d(S){S()}function f(S,x){return S.pipe(x)}function h(S){return S.length&&typeof S[S.length-1]=="function"?S.pop():a}var p,g=s("../../../errors").codes,v=g.ERR_MISSING_ARGS,w=g.ERR_STREAM_DESTROYED;o.exports=function(){for(var S=arguments.length,x=Array(S),y=0;y<S;y++)x[y]=arguments[y];var k=h(x);if(Array.isArray(x[0])&&(x=x[0]),2>x.length)throw new v("streams");var E,T=x.map(function(N,_){var A=_<x.length-1;return u(N,A,0<_,function(R){E||(E=R),R&&T.forEach(d),A||(T.forEach(d),k(E))})});return x.reduce(f)}},{"../../../errors":15,"./end-of-stream":24}],27:[function(s,o){function l(c,u,d){return c.highWaterMark==null?u?c[d]:null:c.highWaterMark}var a=s("../../../errors").codes.ERR_INVALID_OPT_VALUE;o.exports={getHighWaterMark:function(c,u,d,f){var h=l(u,f,d);if(h!=null){if(!(isFinite(h)&&t(h)===h)||0>h){var p=f?d:"highWaterMark";throw new a(p,h)}return t(h)}return c.objectMode?16:16384}}},{"../../../errors":15}],28:[function(s,o){o.exports=s("events").EventEmitter},{events:7}],29:[function(s,o,l){l=o.exports=s("./lib/_stream_readable.js"),l.Stream=l,l.Readable=l,l.Writable=s("./lib/_stream_writable.js"),l.Duplex=s("./lib/_stream_duplex.js"),l.Transform=s("./lib/_stream_transform.js"),l.PassThrough=s("./lib/_stream_passthrough.js"),l.finished=s("./lib/internal/streams/end-of-stream.js"),l.pipeline=s("./lib/internal/streams/pipeline.js")},{"./lib/_stream_duplex.js":16,"./lib/_stream_passthrough.js":17,"./lib/_stream_readable.js":18,"./lib/_stream_transform.js":19,"./lib/_stream_writable.js":20,"./lib/internal/streams/end-of-stream.js":24,"./lib/internal/streams/pipeline.js":26}],30:[function(s,o,l){function a(f,h){for(var p in f)h[p]=f[p]}function c(f,h,p){return d(f,h,p)}/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */var u=s("buffer"),d=u.Buffer;d.from&&d.alloc&&d.allocUnsafe&&d.allocUnsafeSlow?o.exports=u:(a(u,l),l.Buffer=c),c.prototype=Object.create(d.prototype),a(d,c),c.from=function(f,h,p){if(typeof f=="number")throw new TypeError("Argument must not be a number");return d(f,h,p)},c.alloc=function(f,h,p){if(typeof f!="number")throw new TypeError("Argument must be a number");var g=d(f);return h===void 0?g.fill(0):typeof p=="string"?g.fill(h,p):g.fill(h),g},c.allocUnsafe=function(f){if(typeof f!="number")throw new TypeError("Argument must be a number");return d(f)},c.allocUnsafeSlow=function(f){if(typeof f!="number")throw new TypeError("Argument must be a number");return u.SlowBuffer(f)}},{buffer:3}],31:[function(s,o,l){function a(T){if(!T)return"utf8";for(var N;;)switch(T){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return T;default:if(N)return;T=(""+T).toLowerCase(),N=!0}}function c(T){var N=a(T);if(typeof N!="string"&&(k.isEncoding===E||!E(T)))throw new Error("Unknown encoding: "+T);return N||T}function u(T){this.encoding=c(T);var N;switch(this.encoding){case"utf16le":this.text=g,this.end=v,N=4;break;case"utf8":this.fillLast=p,N=4;break;case"base64":this.text=w,this.end=S,N=3;break;default:return this.write=x,void(this.end=y)}this.lastNeed=0,this.lastTotal=0,this.lastChar=k.allocUnsafe(N)}function d(T){return 127>=T?0:T>>5==6?2:T>>4==14?3:T>>3==30?4:T>>6==2?-1:-2}function f(T,N,_){var A=N.length-1;if(A<_)return 0;var R=d(N[A]);return 0<=R?(0<R&&(T.lastNeed=R-1),R):--A<_||R===-2?0:(R=d(N[A]),0<=R?(0<R&&(T.lastNeed=R-2),R):--A<_||R===-2?0:(R=d(N[A]),0<=R?(0<R&&(R===2?R=0:T.lastNeed=R-3),R):0))}function h(T,N){if((192&N[0])!=128)return T.lastNeed=0,"�";if(1<T.lastNeed&&1<N.length){if((192&N[1])!=128)return T.lastNeed=1,"�";if(2<T.lastNeed&&2<N.length&&(192&N[2])!=128)return T.lastNeed=2,"�"}}function p(T){var N=this.lastTotal-this.lastNeed,_=h(this,T);return _===void 0?this.lastNeed<=T.length?(T.copy(this.lastChar,N,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(T.copy(this.lastChar,N,0,T.length),void(this.lastNeed-=T.length)):_}function g(T,N){if((T.length-N)%2==0){var _=T.toString("utf16le",N);if(_){var A=_.charCodeAt(_.length-1);if(55296<=A&&56319>=A)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=T[T.length-2],this.lastChar[1]=T[T.length-1],_.slice(0,-1)}return _}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=T[T.length-1],T.toString("utf16le",N,T.length-1)}function v(T){var N=T&&T.length?this.write(T):"";if(this.lastNeed){var _=this.lastTotal-this.lastNeed;return N+this.lastChar.toString("utf16le",0,_)}return N}function w(T,N){var _=(T.length-N)%3;return _==0?T.toString("base64",N):(this.lastNeed=3-_,this.lastTotal=3,_==1?this.lastChar[0]=T[T.length-1]:(this.lastChar[0]=T[T.length-2],this.lastChar[1]=T[T.length-1]),T.toString("base64",N,T.length-_))}function S(T){var N=T&&T.length?this.write(T):"";return this.lastNeed?N+this.lastChar.toString("base64",0,3-this.lastNeed):N}function x(T){return T.toString(this.encoding)}function y(T){return T&&T.length?this.write(T):""}var k=s("safe-buffer").Buffer,E=k.isEncoding||function(T){switch(T=""+T,T&&T.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};l.StringDecoder=u,u.prototype.write=function(T){if(T.length===0)return"";var N,_;if(this.lastNeed){if(N=this.fillLast(T),N===void 0)return"";_=this.lastNeed,this.lastNeed=0}else _=0;return _<T.length?N?N+this.text(T,_):this.text(T,_):N||""},u.prototype.end=function(T){var N=T&&T.length?this.write(T):"";return this.lastNeed?N+"�":N},u.prototype.text=function(T,N){var _=f(this,T,N);if(!this.lastNeed)return T.toString("utf8",N);this.lastTotal=_;var A=T.length-(_-this.lastNeed);return T.copy(this.lastChar,0,A),T.toString("utf8",N,A)},u.prototype.fillLast=function(T){return this.lastNeed<=T.length?(T.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(T.copy(this.lastChar,this.lastTotal-this.lastNeed,0,T.length),void(this.lastNeed-=T.length))}},{"safe-buffer":30}],32:[function(s,o){(function(l){(function(){function a(c){try{if(!l.localStorage)return!1}catch{return!1}var u=l.localStorage[c];return u!=null&&(u+"").toLowerCase()==="true"}o.exports=function(c,u){function d(){if(!f){if(a("throwDeprecation"))throw new Error(u);a("traceDeprecation")?console.trace(u):console.warn(u),f=!0}return c.apply(this,arguments)}if(a("noDeprecation"))return c;var f=!1;return d}}).call(this)}).call(this,typeof On>"u"?typeof self>"u"?typeof window>"u"?{}:window:self:On)},{}],"/":[function(s,o){function l(S){return S.replace(/a=ice-options:trickle\s\n/g,"")}function a(S){console.warn(S)}/*! simple-peer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */const c=s("debug")("simple-peer"),u=s("get-browser-rtc"),d=s("randombytes"),f=s("readable-stream"),h=s("queue-microtask"),p=s("err-code"),{Buffer:g}=s("buffer"),v=65536;class w extends f.Duplex{constructor(x){if(x=Object.assign({allowHalfOpen:!1},x),super(x),this._id=d(4).toString("hex").slice(0,7),this._debug("new peer %o",x),this.channelName=x.initiator?x.channelName||d(20).toString("hex"):null,this.initiator=x.initiator||!1,this.channelConfig=x.channelConfig||w.channelConfig,this.channelNegotiated=this.channelConfig.negotiated,this.config=Object.assign({},w.config,x.config),this.offerOptions=x.offerOptions||{},this.answerOptions=x.answerOptions||{},this.sdpTransform=x.sdpTransform||(y=>y),this.streams=x.streams||(x.stream?[x.stream]:[]),this.trickle=x.trickle===void 0||x.trickle,this.allowHalfTrickle=x.allowHalfTrickle!==void 0&&x.allowHalfTrickle,this.iceCompleteTimeout=x.iceCompleteTimeout||5e3,this.destroyed=!1,this.destroying=!1,this._connected=!1,this.remoteAddress=void 0,this.remoteFamily=void 0,this.remotePort=void 0,this.localAddress=void 0,this.localFamily=void 0,this.localPort=void 0,this._wrtc=x.wrtc&&typeof x.wrtc=="object"?x.wrtc:u(),!this._wrtc)throw p(typeof window>"u"?new Error("No WebRTC support: Specify `opts.wrtc` option in this environment"):new Error("No WebRTC support: Not a supported browser"),"ERR_WEBRTC_SUPPORT");this._pcReady=!1,this._channelReady=!1,this._iceComplete=!1,this._iceCompleteTimer=null,this._channel=null,this._pendingCandidates=[],this._isNegotiating=!1,this._firstNegotiation=!0,this._batchedNegotiation=!1,this._queuedNegotiation=!1,this._sendersAwaitingStable=[],this._senderMap=new Map,this._closingInterval=null,this._remoteTracks=[],this._remoteStreams=[],this._chunk=null,this._cb=null,this._interval=null;try{this._pc=new this._wrtc.RTCPeerConnection(this.config)}catch(y){return void this.destroy(p(y,"ERR_PC_CONSTRUCTOR"))}this._isReactNativeWebrtc=typeof this._pc._peerConnectionId=="number",this._pc.oniceconnectionstatechange=()=>{this._onIceStateChange()},this._pc.onicegatheringstatechange=()=>{this._onIceStateChange()},this._pc.onconnectionstatechange=()=>{this._onConnectionStateChange()},this._pc.onsignalingstatechange=()=>{this._onSignalingStateChange()},this._pc.onicecandidate=y=>{this._onIceCandidate(y)},typeof this._pc.peerIdentity=="object"&&this._pc.peerIdentity.catch(y=>{this.destroy(p(y,"ERR_PC_PEER_IDENTITY"))}),this.initiator||this.channelNegotiated?this._setupData({channel:this._pc.createDataChannel(this.channelName,this.channelConfig)}):this._pc.ondatachannel=y=>{this._setupData(y)},this.streams&&this.streams.forEach(y=>{this.addStream(y)}),this._pc.ontrack=y=>{this._onTrack(y)},this._debug("initial negotiation"),this._needsNegotiation(),this._onFinishBound=()=>{this._onFinish()},this.once("finish",this._onFinishBound)}get bufferSize(){return this._channel&&this._channel.bufferedAmount||0}get connected(){return this._connected&&this._channel.readyState==="open"}address(){return{port:this.localPort,family:this.localFamily,address:this.localAddress}}signal(x){if(!this.destroying){if(this.destroyed)throw p(new Error("cannot signal after peer is destroyed"),"ERR_DESTROYED");if(typeof x=="string")try{x=JSON.parse(x)}catch{x={}}this._debug("signal()"),x.renegotiate&&this.initiator&&(this._debug("got request to renegotiate"),this._needsNegotiation()),x.transceiverRequest&&this.initiator&&(this._debug("got request for transceiver"),this.addTransceiver(x.transceiverRequest.kind,x.transceiverRequest.init)),x.candidate&&(this._pc.remoteDescription&&this._pc.remoteDescription.type?this._addIceCandidate(x.candidate):this._pendingCandidates.push(x.candidate)),x.sdp&&this._pc.setRemoteDescription(new this._wrtc.RTCSessionDescription(x)).then(()=>{this.destroyed||(this._pendingCandidates.forEach(y=>{this._addIceCandidate(y)}),this._pendingCandidates=[],this._pc.remoteDescription.type==="offer"&&this._createAnswer())}).catch(y=>{this.destroy(p(y,"ERR_SET_REMOTE_DESCRIPTION"))}),x.sdp||x.candidate||x.renegotiate||x.transceiverRequest||this.destroy(p(new Error("signal() called with invalid signal data"),"ERR_SIGNALING"))}}_addIceCandidate(x){const y=new this._wrtc.RTCIceCandidate(x);this._pc.addIceCandidate(y).catch(k=>{!y.address||y.address.endsWith(".local")?a("Ignoring unsupported ICE candidate."):this.destroy(p(k,"ERR_ADD_ICE_CANDIDATE"))})}send(x){if(!this.destroying){if(this.destroyed)throw p(new Error("cannot send after peer is destroyed"),"ERR_DESTROYED");this._channel.send(x)}}addTransceiver(x,y){if(!this.destroying){if(this.destroyed)throw p(new Error("cannot addTransceiver after peer is destroyed"),"ERR_DESTROYED");if(this._debug("addTransceiver()"),this.initiator)try{this._pc.addTransceiver(x,y),this._needsNegotiation()}catch(k){this.destroy(p(k,"ERR_ADD_TRANSCEIVER"))}else this.emit("signal",{type:"transceiverRequest",transceiverRequest:{kind:x,init:y}})}}addStream(x){if(!this.destroying){if(this.destroyed)throw p(new Error("cannot addStream after peer is destroyed"),"ERR_DESTROYED");this._debug("addStream()"),x.getTracks().forEach(y=>{this.addTrack(y,x)})}}addTrack(x,y){if(this.destroying)return;if(this.destroyed)throw p(new Error("cannot addTrack after peer is destroyed"),"ERR_DESTROYED");this._debug("addTrack()");const k=this._senderMap.get(x)||new Map;let E=k.get(y);if(!E)E=this._pc.addTrack(x,y),k.set(y,E),this._senderMap.set(x,k),this._needsNegotiation();else throw E.removed?p(new Error("Track has been removed. You should enable/disable tracks that you want to re-add."),"ERR_SENDER_REMOVED"):p(new Error("Track has already been added to that stream."),"ERR_SENDER_ALREADY_ADDED")}replaceTrack(x,y,k){if(this.destroying)return;if(this.destroyed)throw p(new Error("cannot replaceTrack after peer is destroyed"),"ERR_DESTROYED");this._debug("replaceTrack()");const E=this._senderMap.get(x),T=E?E.get(k):null;if(!T)throw p(new Error("Cannot replace track that was never added."),"ERR_TRACK_NOT_ADDED");y&&this._senderMap.set(y,E),T.replaceTrack==null?this.destroy(p(new Error("replaceTrack is not supported in this browser"),"ERR_UNSUPPORTED_REPLACETRACK")):T.replaceTrack(y)}removeTrack(x,y){if(this.destroying)return;if(this.destroyed)throw p(new Error("cannot removeTrack after peer is destroyed"),"ERR_DESTROYED");this._debug("removeSender()");const k=this._senderMap.get(x),E=k?k.get(y):null;if(!E)throw p(new Error("Cannot remove track that was never added."),"ERR_TRACK_NOT_ADDED");try{E.removed=!0,this._pc.removeTrack(E)}catch(T){T.name==="NS_ERROR_UNEXPECTED"?this._sendersAwaitingStable.push(E):this.destroy(p(T,"ERR_REMOVE_TRACK"))}this._needsNegotiation()}removeStream(x){if(!this.destroying){if(this.destroyed)throw p(new Error("cannot removeStream after peer is destroyed"),"ERR_DESTROYED");this._debug("removeSenders()"),x.getTracks().forEach(y=>{this.removeTrack(y,x)})}}_needsNegotiation(){this._debug("_needsNegotiation"),this._batchedNegotiation||(this._batchedNegotiation=!0,h(()=>{this._batchedNegotiation=!1,this.initiator||!this._firstNegotiation?(this._debug("starting batched negotiation"),this.negotiate()):this._debug("non-initiator initial negotiation request discarded"),this._firstNegotiation=!1}))}negotiate(){if(!this.destroying){if(this.destroyed)throw p(new Error("cannot negotiate after peer is destroyed"),"ERR_DESTROYED");this.initiator?this._isNegotiating?(this._queuedNegotiation=!0,this._debug("already negotiating, queueing")):(this._debug("start negotiation"),setTimeout(()=>{this._createOffer()},0)):this._isNegotiating?(this._queuedNegotiation=!0,this._debug("already negotiating, queueing")):(this._debug("requesting negotiation from initiator"),this.emit("signal",{type:"renegotiate",renegotiate:!0})),this._isNegotiating=!0}}destroy(x){this._destroy(x,()=>{})}_destroy(x,y){this.destroyed||this.destroying||(this.destroying=!0,this._debug("destroying (error: %s)",x&&(x.message||x)),h(()=>{if(this.destroyed=!0,this.destroying=!1,this._debug("destroy (error: %s)",x&&(x.message||x)),this.readable=this.writable=!1,this._readableState.ended||this.push(null),this._writableState.finished||this.end(),this._connected=!1,this._pcReady=!1,this._channelReady=!1,this._remoteTracks=null,this._remoteStreams=null,this._senderMap=null,clearInterval(this._closingInterval),this._closingInterval=null,clearInterval(this._interval),this._interval=null,this._chunk=null,this._cb=null,this._onFinishBound&&this.removeListener("finish",this._onFinishBound),this._onFinishBound=null,this._channel){try{this._channel.close()}catch{}this._channel.onmessage=null,this._channel.onopen=null,this._channel.onclose=null,this._channel.onerror=null}if(this._pc){try{this._pc.close()}catch{}this._pc.oniceconnectionstatechange=null,this._pc.onicegatheringstatechange=null,this._pc.onsignalingstatechange=null,this._pc.onicecandidate=null,this._pc.ontrack=null,this._pc.ondatachannel=null}this._pc=null,this._channel=null,x&&this.emit("error",x),this.emit("close"),y()}))}_setupData(x){if(!x.channel)return this.destroy(p(new Error("Data channel event is missing `channel` property"),"ERR_DATA_CHANNEL"));this._channel=x.channel,this._channel.binaryType="arraybuffer",typeof this._channel.bufferedAmountLowThreshold=="number"&&(this._channel.bufferedAmountLowThreshold=v),this.channelName=this._channel.label,this._channel.onmessage=k=>{this._onChannelMessage(k)},this._channel.onbufferedamountlow=()=>{this._onChannelBufferedAmountLow()},this._channel.onopen=()=>{this._onChannelOpen()},this._channel.onclose=()=>{this._onChannelClose()},this._channel.onerror=k=>{const E=k.error instanceof Error?k.error:new Error(`Datachannel error: ${k.message} ${k.filename}:${k.lineno}:${k.colno}`);this.destroy(p(E,"ERR_DATA_CHANNEL"))};let y=!1;this._closingInterval=setInterval(()=>{this._channel&&this._channel.readyState==="closing"?(y&&this._onChannelClose(),y=!0):y=!1},5e3)}_read(){}_write(x,y,k){if(this.destroyed)return k(p(new Error("cannot write after peer is destroyed"),"ERR_DATA_CHANNEL"));if(this._connected){try{this.send(x)}catch(E){return this.destroy(p(E,"ERR_DATA_CHANNEL"))}this._channel.bufferedAmount>v?(this._debug("start backpressure: bufferedAmount %d",this._channel.bufferedAmount),this._cb=k):k(null)}else this._debug("write before connect"),this._chunk=x,this._cb=k}_onFinish(){if(!this.destroyed){const x=()=>{setTimeout(()=>this.destroy(),1e3)};this._connected?x():this.once("connect",x)}}_startIceCompleteTimeout(){this.destroyed||this._iceCompleteTimer||(this._debug("started iceComplete timeout"),this._iceCompleteTimer=setTimeout(()=>{this._iceComplete||(this._iceComplete=!0,this._debug("iceComplete timeout completed"),this.emit("iceTimeout"),this.emit("_iceComplete"))},this.iceCompleteTimeout))}_createOffer(){this.destroyed||this._pc.createOffer(this.offerOptions).then(x=>{if(this.destroyed)return;this.trickle||this.allowHalfTrickle||(x.sdp=l(x.sdp)),x.sdp=this.sdpTransform(x.sdp);const y=()=>{if(!this.destroyed){const k=this._pc.localDescription||x;this._debug("signal"),this.emit("signal",{type:k.type,sdp:k.sdp})}};this._pc.setLocalDescription(x).then(()=>{this._debug("createOffer success"),this.destroyed||(this.trickle||this._iceComplete?y():this.once("_iceComplete",y))}).catch(k=>{this.destroy(p(k,"ERR_SET_LOCAL_DESCRIPTION"))})}).catch(x=>{this.destroy(p(x,"ERR_CREATE_OFFER"))})}_requestMissingTransceivers(){this._pc.getTransceivers&&this._pc.getTransceivers().forEach(x=>{x.mid||!x.sender.track||x.requested||(x.requested=!0,this.addTransceiver(x.sender.track.kind))})}_createAnswer(){this.destroyed||this._pc.createAnswer(this.answerOptions).then(x=>{if(this.destroyed)return;this.trickle||this.allowHalfTrickle||(x.sdp=l(x.sdp)),x.sdp=this.sdpTransform(x.sdp);const y=()=>{if(!this.destroyed){const k=this._pc.localDescription||x;this._debug("signal"),this.emit("signal",{type:k.type,sdp:k.sdp}),this.initiator||this._requestMissingTransceivers()}};this._pc.setLocalDescription(x).then(()=>{this.destroyed||(this.trickle||this._iceComplete?y():this.once("_iceComplete",y))}).catch(k=>{this.destroy(p(k,"ERR_SET_LOCAL_DESCRIPTION"))})}).catch(x=>{this.destroy(p(x,"ERR_CREATE_ANSWER"))})}_onConnectionStateChange(){this.destroyed||this._pc.connectionState==="failed"&&this.destroy(p(new Error("Connection failed."),"ERR_CONNECTION_FAILURE"))}_onIceStateChange(){if(this.destroyed)return;const x=this._pc.iceConnectionState,y=this._pc.iceGatheringState;this._debug("iceStateChange (connection: %s) (gathering: %s)",x,y),this.emit("iceStateChange",x,y),(x==="connected"||x==="completed")&&(this._pcReady=!0,this._maybeReady()),x==="failed"&&this.destroy(p(new Error("Ice connection failed."),"ERR_ICE_CONNECTION_FAILURE")),x==="closed"&&this.destroy(p(new Error("Ice connection closed."),"ERR_ICE_CONNECTION_CLOSED"))}getStats(x){const y=k=>(Object.prototype.toString.call(k.values)==="[object Array]"&&k.values.forEach(E=>{Object.assign(k,E)}),k);this._pc.getStats.length===0||this._isReactNativeWebrtc?this._pc.getStats().then(k=>{const E=[];k.forEach(T=>{E.push(y(T))}),x(null,E)},k=>x(k)):0<this._pc.getStats.length?this._pc.getStats(k=>{if(this.destroyed)return;const E=[];k.result().forEach(T=>{const N={};T.names().forEach(_=>{N[_]=T.stat(_)}),N.id=T.id,N.type=T.type,N.timestamp=T.timestamp,E.push(y(N))}),x(null,E)},k=>x(k)):x(null,[])}_maybeReady(){if(this._debug("maybeReady pc %s channel %s",this._pcReady,this._channelReady),this._connected||this._connecting||!this._pcReady||!this._channelReady)return;this._connecting=!0;const x=()=>{this.destroyed||this.getStats((y,k)=>{if(this.destroyed)return;y&&(k=[]);const E={},T={},N={};let _=!1;k.forEach(R=>{(R.type==="remotecandidate"||R.type==="remote-candidate")&&(E[R.id]=R),(R.type==="localcandidate"||R.type==="local-candidate")&&(T[R.id]=R),(R.type==="candidatepair"||R.type==="candidate-pair")&&(N[R.id]=R)});const A=R=>{_=!0;let P=T[R.localCandidateId];P&&(P.ip||P.address)?(this.localAddress=P.ip||P.address,this.localPort=+P.port):P&&P.ipAddress?(this.localAddress=P.ipAddress,this.localPort=+P.portNumber):typeof R.googLocalAddress=="string"&&(P=R.googLocalAddress.split(":"),this.localAddress=P[0],this.localPort=+P[1]),this.localAddress&&(this.localFamily=this.localAddress.includes(":")?"IPv6":"IPv4");let $=E[R.remoteCandidateId];$&&($.ip||$.address)?(this.remoteAddress=$.ip||$.address,this.remotePort=+$.port):$&&$.ipAddress?(this.remoteAddress=$.ipAddress,this.remotePort=+$.portNumber):typeof R.googRemoteAddress=="string"&&($=R.googRemoteAddress.split(":"),this.remoteAddress=$[0],this.remotePort=+$[1]),this.remoteAddress&&(this.remoteFamily=this.remoteAddress.includes(":")?"IPv6":"IPv4"),this._debug("connect local: %s:%s remote: %s:%s",this.localAddress,this.localPort,this.remoteAddress,this.remotePort)};if(k.forEach(R=>{R.type==="transport"&&R.selectedCandidatePairId&&A(N[R.selectedCandidatePairId]),(R.type==="googCandidatePair"&&R.googActiveConnection==="true"||(R.type==="candidatepair"||R.type==="candidate-pair")&&R.selected)&&A(R)}),!_&&(!Object.keys(N).length||Object.keys(T).length))return void setTimeout(x,100);if(this._connecting=!1,this._connected=!0,this._chunk){try{this.send(this._chunk)}catch(P){return this.destroy(p(P,"ERR_DATA_CHANNEL"))}this._chunk=null,this._debug('sent chunk from "write before connect"');const R=this._cb;this._cb=null,R(null)}typeof this._channel.bufferedAmountLowThreshold!="number"&&(this._interval=setInterval(()=>this._onInterval(),150),this._interval.unref&&this._interval.unref()),this._debug("connect"),this.emit("connect")})};x()}_onInterval(){this._cb&&this._channel&&!(this._channel.bufferedAmount>v)&&this._onChannelBufferedAmountLow()}_onSignalingStateChange(){this.destroyed||(this._pc.signalingState==="stable"&&(this._isNegotiating=!1,this._debug("flushing sender queue",this._sendersAwaitingStable),this._sendersAwaitingStable.forEach(x=>{this._pc.removeTrack(x),this._queuedNegotiation=!0}),this._sendersAwaitingStable=[],this._queuedNegotiation?(this._debug("flushing negotiation queue"),this._queuedNegotiation=!1,this._needsNegotiation()):(this._debug("negotiated"),this.emit("negotiated"))),this._debug("signalingStateChange %s",this._pc.signalingState),this.emit("signalingStateChange",this._pc.signalingState))}_onIceCandidate(x){this.destroyed||(x.candidate&&this.trickle?this.emit("signal",{type:"candidate",candidate:{candidate:x.candidate.candidate,sdpMLineIndex:x.candidate.sdpMLineIndex,sdpMid:x.candidate.sdpMid}}):!x.candidate&&!this._iceComplete&&(this._iceComplete=!0,this.emit("_iceComplete")),x.candidate&&this._startIceCompleteTimeout())}_onChannelMessage(x){if(this.destroyed)return;let y=x.data;y instanceof ArrayBuffer&&(y=g.from(y)),this.push(y)}_onChannelBufferedAmountLow(){if(!this.destroyed&&this._cb){this._debug("ending backpressure: bufferedAmount %d",this._channel.bufferedAmount);const x=this._cb;this._cb=null,x(null)}}_onChannelOpen(){this._connected||this.destroyed||(this._debug("on channel open"),this._channelReady=!0,this._maybeReady())}_onChannelClose(){this.destroyed||(this._debug("on channel close"),this.destroy())}_onTrack(x){this.destroyed||x.streams.forEach(y=>{this._debug("on track"),this.emit("track",x.track,y),this._remoteTracks.push({track:x.track,stream:y}),this._remoteStreams.some(k=>k.id===y.id)||(this._remoteStreams.push(y),h(()=>{this._debug("on stream"),this.emit("stream",y)}))})}_debug(){const x=[].slice.call(arguments);x[0]="["+this._id+"] "+x[0],c.apply(null,x)}}w.WEBRTC_SUPPORT=!!u(),w.config={iceServers:[{urls:["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478"]}],sdpSemantics:"unified-plan"},w.channelConfig={},o.exports=w},{buffer:3,debug:4,"err-code":6,"get-browser-rtc":8,"queue-microtask":13,randombytes:14,"readable-stream":29}]},{},[])("/")})})(yb);var EO=yb.exports;const TO=Nc(EO),nf=0,rf=1,bb=2,vb=(n,e)=>{ae(n,nf);const t=xM(e);Xe(n,t)},wb=(n,e,t)=>{ae(n,rf),Xe(n,yM(e,t))},AO=(n,e,t)=>wb(e,t,bt(n)),xb=(n,e,t)=>{try{pM(e,bt(n),t)}catch(r){console.error("Caught error while handling a Yjs update",r)}},MO=(n,e)=>{ae(n,bb),Xe(n,e)},OO=xb,_O=(n,e,t,r)=>{const i=he(n);switch(i){case nf:AO(n,e,t);break;case rf:xb(n,t,r);break;case bb:OO(n,t,r);break;default:throw new Error("Unknown message type")}return i},sf=3e4;class NO extends D0{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const t=Bn();this.getLocalState()!==null&&sf/2<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const r=[];this.meta.forEach((i,s)=>{s!==this.clientID&&sf<=t-i.lastUpdated&&this.states.has(s)&&r.push(s)}),r.length>0&&of(this,r,"timeout")},wn(sf/10)),e.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){const t=this.clientID,r=this.meta.get(t),i=r===void 0?0:r.clock+1,s=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:i,lastUpdated:Bn()});const o=[],l=[],a=[],c=[];e===null?c.push(t):s==null?e!=null&&o.push(t):(l.push(t),Eo(s,e)||a.push(t)),(o.length>0||a.length>0||c.length>0)&&this.emit("change",[{added:o,updated:a,removed:c},"local"]),this.emit("update",[{added:o,updated:l,removed:c},"local"])}setLocalStateField(e,t){const r=this.getLocalState();r!==null&&this.setLocalState({...r,[e]:t})}getStates(){return this.states}}const of=(n,e,t)=>{const r=[];for(let i=0;i<e.length;i++){const s=e[i];if(n.states.has(s)){if(n.states.delete(s),s===n.clientID){const o=n.meta.get(s);n.meta.set(s,{clock:o.clock+1,lastUpdated:Bn()})}r.push(s)}}r.length>0&&(n.emit("change",[{added:[],updated:[],removed:r},t]),n.emit("update",[{added:[],updated:[],removed:r},t]))},ma=(n,e,t=n.states)=>{const r=e.length,i=gt();ae(i,r);for(let s=0;s<r;s++){const o=e[s],l=t.get(o)||null,a=n.meta.get(o).clock;ae(i,o),ae(i,a),jn(i,JSON.stringify(l))}return qe(i)},DO=(n,e,t)=>{const r=Hn(e),i=Bn(),s=[],o=[],l=[],a=[],c=he(r);for(let u=0;u<c;u++){const d=he(r);let f=he(r);const h=JSON.parse(ur(r)),p=n.meta.get(d),g=n.states.get(d),v=p===void 0?0:p.clock;(v<f||v===f&&h===null&&n.states.has(d))&&(h===null?d===n.clientID&&n.getLocalState()!=null?f++:n.states.delete(d):n.states.set(d,h),n.meta.set(d,{clock:f,lastUpdated:i}),p===void 0&&h!==null?s.push(d):p!==void 0&&h===null?a.push(d):h!==null&&(Eo(h,g)||l.push(d),o.push(d)))}(s.length>0||l.length>0||a.length>0)&&n.emit("change",[{added:s,updated:l,removed:a},t]),(s.length>0||o.length>0||a.length>0)&&n.emit("update",[{added:s,updated:o,removed:a},t])},RO=(n,e)=>{const t=gd(n).buffer,r=gd(e).buffer;return crypto.subtle.importKey("raw",t,"PBKDF2",!1,["deriveKey"]).then(i=>crypto.subtle.deriveKey({name:"PBKDF2",salt:r,iterations:1e5,hash:"SHA-256"},i,{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]))},Cb=(n,e)=>{if(!e)return Dd(n);const t=crypto.getRandomValues(new Uint8Array(12));return crypto.subtle.encrypt({name:"AES-GCM",iv:t},e,n).then(r=>{const i=gt();return jn(i,"AES-GCM"),Xe(i,t),Xe(i,new Uint8Array(r)),qe(i)})},LO=(n,e)=>{const t=gt();return ts(t,n),Cb(qe(t),e)},kb=(n,e)=>{if(!e)return Dd(n);const t=Hn(n);ur(t)!=="AES-GCM"&&KA($n("Unknown encryption algorithm"));const i=bt(t),s=bt(t);return crypto.subtle.decrypt({name:"AES-GCM",iv:i},e,s).then(o=>new Uint8Array(o))},IO=(n,e)=>kb(n,e).then(t=>ns(Hn(new Uint8Array(t)))),Xt=qA("y-webrtc"),gs=0,Sb=3,Bo=1,lf=4,ga=new Map,Si=new Map,Eb=n=>{let e=!0;n.webrtcConns.forEach(t=>{t.synced||(e=!1)}),(!e&&n.synced||e&&!n.synced)&&(n.synced=e,n.provider.emit("synced",[{synced:e}]),Xt("synced ",un,n.name,yi," with all peers"))},Tb=(n,e,t)=>{const r=Hn(e),i=gt(),s=he(r);if(n===void 0)return null;const o=n.awareness,l=n.doc;let a=!1;switch(s){case gs:{ae(i,gs);const c=_O(r,i,l,n);c===rf&&!n.synced&&t(),c===nf&&(a=!0);break}case Sb:ae(i,Bo),Xe(i,ma(o,Array.from(o.getStates().keys()))),a=!0;break;case Bo:DO(o,bt(r),n);break;case lf:{const c=gi(r)===1,u=ur(r);if(u!==n.peerId&&(n.bcConns.has(u)&&!c||!n.bcConns.has(u)&&c)){const d=[],f=[];c?(n.bcConns.add(u),f.push(u)):(n.bcConns.delete(u),d.push(u)),n.provider.emit("peers",[{added:f,removed:d,webrtcPeers:Array.from(n.webrtcConns.keys()),bcPeers:Array.from(n.bcConns)}]),Ob(n)}break}default:return console.error("Unable to compute message"),i}return a?i:null},PO=(n,e)=>{const t=n.room;return Xt("received message from ",un,n.remotePeerId,_d," (",t.name,")",yi,ea),Tb(t,e,()=>{n.synced=!0,Xt("synced ",un,t.name,yi," with ",un,n.remotePeerId),Eb(t)})},af=(n,e)=>{Xt("send message to ",un,n.remotePeerId,yi,_d," (",n.room.name,")",ea);try{n.peer.send(qe(e))}catch{}},FO=(n,e)=>{Xt("broadcast message in ",un,n.name,yi),n.webrtcConns.forEach(t=>{try{t.peer.send(e)}catch{}})};class Ab{constructor(e,t,r,i){Xt("establishing connection to ",un,r),this.room=i,this.remotePeerId=r,this.glareToken=void 0,this.closed=!1,this.connected=!1,this.synced=!1,this.peer=new TO({initiator:t,...i.provider.peerOpts}),this.peer.on("signal",s=>{this.glareToken===void 0&&(this.glareToken=Date.now()+Math.random()),uf(e,i,{to:r,from:i.peerId,type:"signal",token:this.glareToken,signal:s})}),this.peer.on("connect",()=>{Xt("connected to ",un,r),this.connected=!0;const o=i.provider.doc,l=i.awareness,a=gt();ae(a,gs),vb(a,o),af(this,a);const c=l.getStates();if(c.size>0){const u=gt();ae(u,Bo),Xe(u,ma(l,Array.from(c.keys()))),af(this,u)}}),this.peer.on("close",()=>{this.connected=!1,this.closed=!0,i.webrtcConns.has(this.remotePeerId)&&(i.webrtcConns.delete(this.remotePeerId),i.provider.emit("peers",[{removed:[this.remotePeerId],added:[],webrtcPeers:Array.from(i.webrtcConns.keys()),bcPeers:Array.from(i.bcConns)}])),Eb(i),this.peer.destroy(),Xt("closed connection to ",un,r),cf(i)}),this.peer.on("error",s=>{Xt("Error in connection to ",un,r,": ",s),cf(i)}),this.peer.on("data",s=>{const o=PO(this,s);o!==null&&af(this,o)})}destroy(){this.peer.destroy()}}const $r=(n,e)=>Cb(e,n.key).then(t=>n.mux(()=>sM(n.name,t))),Mb=(n,e)=>{n.bcconnected&&$r(n,e),FO(n,e)},cf=n=>{ga.forEach(e=>{e.connected&&(e.send({type:"subscribe",topics:[n.name]}),n.webrtcConns.size<n.provider.maxConns&&uf(e,n,{type:"announce",from:n.peerId}))})},Ob=n=>{if(n.provider.filterBcConns){const e=gt();ae(e,lf),So(e,1),jn(e,n.peerId),$r(n,qe(e))}};class BO{constructor(e,t,r,i){this.peerId=B0(),this.doc=e,this.awareness=t.awareness,this.provider=t,this.synced=!1,this.name=r,this.key=i,this.webrtcConns=new Map,this.bcConns=new Set,this.mux=my(),this.bcconnected=!1,this._bcSubscriber=s=>kb(new Uint8Array(s),i).then(o=>this.mux(()=>{const l=Tb(this,o,()=>{});l&&$r(this,qe(l))})),this._docUpdateHandler=(s,o)=>{const l=gt();ae(l,gs),MO(l,s),Mb(this,qe(l))},this._awarenessUpdateHandler=({added:s,updated:o,removed:l},a)=>{const c=s.concat(o).concat(l),u=gt();ae(u,Bo),Xe(u,ma(this.awareness,c)),Mb(this,qe(u))},this._beforeUnloadHandler=()=>{of(this.awareness,[e.clientID],"window unload"),Si.forEach(s=>{s.disconnect()})},typeof window<"u"?window.addEventListener("beforeunload",this._beforeUnloadHandler):typeof process<"u"&&process.on("exit",this._beforeUnloadHandler)}connect(){this.doc.on("update",this._docUpdateHandler),this.awareness.on("update",this._awarenessUpdateHandler),cf(this);const e=this.name;rM(e,this._bcSubscriber),this.bcconnected=!0,Ob(this);const t=gt();ae(t,gs),vb(t,this.doc),$r(this,qe(t));const r=gt();ae(r,gs),wb(r,this.doc),$r(this,qe(r));const i=gt();ae(i,Sb),$r(this,qe(i));const s=gt();ae(s,Bo),Xe(s,ma(this.awareness,[this.doc.clientID])),$r(this,qe(s))}disconnect(){ga.forEach(t=>{t.connected&&t.send({type:"unsubscribe",topics:[this.name]})}),of(this.awareness,[this.doc.clientID],"disconnect");const e=gt();ae(e,lf),So(e,0),jn(e,this.peerId),$r(this,qe(e)),iM(this.name,this._bcSubscriber),this.bcconnected=!1,this.doc.off("update",this._docUpdateHandler),this.awareness.off("update",this._awarenessUpdateHandler),this.webrtcConns.forEach(t=>t.destroy())}destroy(){this.disconnect(),typeof window<"u"?window.removeEventListener("beforeunload",this._beforeUnloadHandler):typeof process<"u"&&process.off("exit",this._beforeUnloadHandler)}}const $O=(n,e,t,r)=>{if(Si.has(t))throw $n(`A Yjs Doc connected to room "${t}" already exists!`);const i=new BO(n,e,t,r);return Si.set(t,i),i},uf=(n,e,t)=>{e.key?LO(t,e.key).then(r=>{n.send({type:"publish",topic:e.name,data:fy(r)})}):n.send({type:"publish",topic:e.name,data:t})};class jO extends ZT{constructor(e){super(e),this.providers=new Set,this.on("connect",()=>{Xt(`connected (${e})`);const t=Array.from(Si.keys());this.send({type:"subscribe",topics:t}),Si.forEach(r=>uf(this,r,{type:"announce",from:r.peerId}))}),this.on("message",t=>{switch(t.type){case"publish":{const r=t.topic,i=Si.get(r);if(i==null||typeof r!="string")return;const s=o=>{const l=i.webrtcConns,a=i.peerId;if(o==null||o.from===a||o.to!==void 0&&o.to!==a||i.bcConns.has(o.from))return;const c=l.has(o.from)?()=>{}:()=>i.provider.emit("peers",[{removed:[],added:[o.from],webrtcPeers:Array.from(i.webrtcConns.keys()),bcPeers:Array.from(i.bcConns)}]);switch(o.type){case"announce":l.size<i.provider.maxConns&&(zt(l,o.from,()=>new Ab(this,!0,o.from,i)),c());break;case"signal":if(o.signal.type==="offer"){const u=l.get(o.from);if(u){const d=o.token,f=u.glareToken;if(f&&f>d){Xt("offer rejected: ",o.from);return}u.glareToken=void 0}}if(o.signal.type==="answer"){Xt("offer answered by: ",o.from);const u=l.get(o.from);u.glareToken=void 0}o.to===a&&(zt(l,o.from,()=>new Ab(this,!1,o.from,i)).peer.signal(o.signal),c());break}};i.key?typeof t.data=="string"&&IO(hy(t.data),i.key).then(s):s(t.data)}}}),this.on("disconnect",()=>Xt(`disconnect (${e})`))}}const df=n=>{n.emit("status",[{connected:n.connected}])};class HO extends dd{constructor(e,t,{signaling:r=["wss://y-webrtc-eu.fly.dev"],password:i=null,awareness:s=new NO(t),maxConns:o=20+wn(P0()*15),filterBcConns:l=!0,peerOpts:a={}}={}){super(),this.roomName=e,this.doc=t,this.filterBcConns=l,this.awareness=s,this.shouldConnect=!1,this.signalingUrls=r,this.signalingConns=[],this.maxConns=o,this.peerOpts=a,this.key=i?RO(i,e):Dd(null),this.room=null,this.key.then(c=>{this.room=$O(t,this,e,c),this.shouldConnect?this.room.connect():this.room.disconnect(),df(this)}),this.connect(),this.destroy=this.destroy.bind(this),t.on("destroy",this.destroy)}get connected(){return this.room!==null&&this.shouldConnect}connect(){this.shouldConnect=!0,this.signalingUrls.forEach(e=>{const t=zt(ga,e,()=>new jO(e));this.signalingConns.push(t),t.providers.add(this)}),this.room&&(this.room.connect(),df(this))}disconnect(){this.shouldConnect=!1,this.signalingConns.forEach(e=>{e.providers.delete(this),e.providers.size===0&&(e.destroy(),ga.delete(e.url))}),this.room&&(this.room.disconnect(),df(this))}destroy(){this.doc.off("destroy",this.destroy),this.key.then(()=>{this.room.destroy(),Si.delete(this.roomName)}),super.destroy()}}const VO={attributes:{class:"prose-lg prose-headings:font-display prose prose-p:my-2 prose-h1:my-2 prose-h2:my-2 prose-h3:my-2 prose-ul:my-2 prose-ol:my-2 max-w-none focus:outline-none w-full",spellcheck:"false",suppressContentEditableWarning:"true"},handleDOMEvents:{keydown:(n,e)=>{if(["ArrowUp","ArrowDown","Enter"].includes(e.key)&&document.querySelector("#slash-command"))return!0}}},zO=/[\uD800-\uDBFF]/,UO=/[\uDC00-\uDFFF]/,WO=(n,e)=>{let t=0,r=0;for(;t<n.length&&t<e.length&&n[t]===e[t];)t++;for(t>0&&zO.test(n[t-1])&&t--;r+t<n.length&&r+t<e.length&&n[n.length-r-1]===e[e.length-r-1];)r++;return r>0&&UO.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},Ke=new We("y-sync"),hr=new We("y-undo"),ya=new We("yjs-cursor"),ba=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&e.sv.get(n.id.client)>n.id.clock&&!ss(e.ds,n.id),qO=[{light:"#ecd44433",dark:"#ecd444"}],KO=(n,e,t)=>{if(!n.has(t)){if(n.size<e.length){const r=or();n.forEach(i=>r.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,eA(e))}return n.get(t)},JO=(n,{colors:e=qO,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{}}={})=>{let s=!1;const o=new je({props:{editable:l=>{const a=Ke.getState(l);return a.snapshot==null&&a.prevSnapshot==null}},key:Ke,state:{init:(l,a)=>({type:n,doc:n.doc,binding:null,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:e,colorMapping:t,permanentUserData:r}),apply:(l,a)=>{const c=l.getMeta(Ke);if(c!==void 0){a=Object.assign({},a);for(const u in c)a[u]=c[u]}return a.addToHistory=l.getMeta("addToHistory")!==!1,a.isChangeOrigin=c!==void 0&&!!c.isChangeOrigin,a.isUndoRedoOperation=c!==void 0&&!!c.isChangeOrigin&&!!c.isUndoRedoOperation,a.binding!==null&&c!==void 0&&(c.snapshot!=null||c.prevSnapshot!=null)&&Od(0,()=>{a.binding==null||a.binding.isDestroyed||(c.restore==null?a.binding._renderSnapshot(c.snapshot,c.prevSnapshot,a):(a.binding._renderSnapshot(c.snapshot,c.snapshot,a),delete a.restore,delete a.snapshot,delete a.prevSnapshot,a.binding.mux(()=>{a.binding._prosemirrorChanged(a.binding.prosemirrorView.state.doc)})))}),a}},view:l=>{const a=new YO(n,l);return a._forceRerender(),i(),{update:()=>{const c=o.getState(l.state);if(c.snapshot==null&&c.prevSnapshot==null&&(s||l.state.doc.content.findDiffStart(l.state.doc.type.createAndFill().content)!==null)){if(s=!0,c.addToHistory===!1&&!c.isChangeOrigin){const u=hr.getState(l.state),d=u&&u.undoManager;d&&d.stopCapturing()}a.mux(()=>{c.doc.transact(u=>{u.meta.set("addToHistory",c.addToHistory),a._prosemirrorChanged(l.state.doc)},Ke)})}},destroy:()=>{a.destroy()}}}});return o},GO=(n,e,t)=>{if(e!==null&&e.anchor!==null&&e.head!==null){const r=Ho(t.doc,t.type,e.anchor,t.mapping),i=Ho(t.doc,t.type,e.head,t.mapping);r!==null&&i!==null&&(n=n.setSelection(ce.create(n.doc,r,i)))}},ff=(n,e)=>({anchor:Ca(e.selection.anchor,n.type,n.mapping),head:Ca(e.selection.head,n.type,n.mapping)});class YO{constructor(e,t){this.type=e,this.prosemirrorView=t,this.mux=my(),this.isDestroyed=!1,this.mapping=new Map,this._observeFunction=this._typeChanged.bind(this),this.doc=e.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&(this.beforeTransactionSelection=ff(this,t.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),e.observeDeep(this._observeFunction),this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return this.prosemirrorView.hasFocus()?(Ad&&this._domSelectionInView===null&&(Od(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){const e=this.prosemirrorView._root.getSelection(),t=this.prosemirrorView._root.createRange();t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset),t.getClientRects().length===0&&t.startContainer&&t.collapsed&&t.selectNodeContents(t.startContainer);const i=t.getBoundingClientRect(),s=BA.documentElement;return i.bottom>=0&&i.right>=0&&i.left<=(window.innerWidth||s.clientWidth||0)&&i.top<=(window.innerHeight||s.clientHeight||0)}renderSnapshot(e,t){t||(t=Ry(yy(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(Ke,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping=new Map,this.mux(()=>{const e=this.type.toArray().map(r=>va(r,this.prosemirrorView.state.schema,this.mapping)).filter(r=>r!==null),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Y(W.from(e),0,0));t.setMeta(Ke,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(t)})}_forceRerender(){this.mapping=new Map,this.mux(()=>{const e=this.type.toArray().map(r=>va(r,this.prosemirrorView.state.schema,this.mapping)).filter(r=>r!==null),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Y(W.from(e),0,0));this.prosemirrorView.dispatch(t.setMeta(Ke,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,r){e||(e=TM(this.doc)),this.mapping=new Map,this.mux(()=>{this.doc.transact(i=>{const s=r.permanentUserData;s&&s.dss.forEach(c=>{Pr(i,c,u=>{})});const o=(c,u)=>{const d=c==="added"?s.getUserByClientId(u.client):s.getUserByDeletedId(u);return{user:d,type:c,color:KO(r.colorMapping,r.colors,d)}},l=Yy(this.type,new Hd(t.ds,e.sv)).map(c=>!c._item.deleted||ba(c._item,e)||ba(c._item,t)?va(c,this.prosemirrorView.state.schema,new Map,e,t,o):null).filter(c=>c!==null),a=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Y(W.from(l),0,0));this.prosemirrorView.dispatch(a.setMeta(Ke,{isChangeOrigin:!0}))},Ke)})}_typeChanged(e,t){const r=Ke.getState(this.prosemirrorView.state);if(e.length===0||r.snapshot!=null||r.prevSnapshot!=null){this.renderSnapshot(r.snapshot,r.prevSnapshot);return}this.mux(()=>{const i=(l,a)=>this.mapping.delete(a);Pr(t,t.deleteSet,l=>{if(l.constructor===ze){const a=l.content.type;a&&this.mapping.delete(a)}}),t.changed.forEach(i),t.changedParentTypes.forEach(i);const s=this.type.toArray().map(l=>_b(l,this.prosemirrorView.state.schema,this.mapping)).filter(l=>l!==null);let o=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Y(W.from(s),0,0));GO(o,this.beforeTransactionSelection,this),o=o.setMeta(Ke,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof zy}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)})}_prosemirrorChanged(e){this.doc.transact(()=>{mf(this.doc,this.type,e,this.mapping),this.beforeTransactionSelection=ff(this,this.prosemirrorView.state)},Ke)}destroy(){this.isDestroyed=!0,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions)}}const _b=(n,e,t,r,i,s)=>{const o=t.get(n);if(o===void 0){if(n instanceof It)return va(n,e,t,r,i,s);throw xn()}return o},va=(n,e,t,r,i,s)=>{const o=[],l=a=>{if(a.constructor===It){const c=_b(a,e,t,r,i,s);c!==null&&o.push(c)}else{const c=ZO(a,e,t,r,i,s);c!==null&&c.forEach(u=>{u!==null&&o.push(u)})}};r===void 0||i===void 0?n.toArray().forEach(l):Yy(n,new Hd(i.ds,r.sv)).forEach(l);try{const a=n.getAttributes(r);r!==void 0&&(ba(n._item,r)?ba(n._item,i)||(a.ychange=s?s("added",n._item.id):{type:"added"}):a.ychange=s?s("removed",n._item.id):{type:"removed"});const c=e.node(n.nodeName,a,o);return t.set(n,c),c}catch{return n.doc.transact(c=>{n._item.delete(c)},Ke),t.delete(n),null}},ZO=(n,e,t,r,i,s)=>{const o=[],l=n.toDelta(r,i,s);try{for(let a=0;a<l.length;a++){const c=l[a],u=[];for(const d in c.attributes)u.push(e.mark(d,c.attributes[d]));o.push(e.text(c.insert,u))}}catch{return n.doc.transact(c=>{n._item.delete(c)},Ke),null}return o},XO=(n,e)=>{const t=new Zt,r=n.map(i=>({insert:i.text,attributes:Lb(i.marks)}));return t.applyDelta(r),e.set(t,n),t},QO=(n,e)=>{const t=new It(n.type.name);for(const r in n.attrs){const i=n.attrs[r];i!==null&&r!=="ychange"&&t.setAttribute(r,i)}return t.insert(0,wa(n).map(r=>hf(r,e))),e.set(t,n),t},hf=(n,e)=>n instanceof Array?XO(n,e):QO(n,e),Nb=n=>typeof n=="object"&&n!==null,pf=(n,e)=>{const t=Object.keys(n).filter(i=>n[i]!==null);let r=t.length===Object.keys(e).filter(i=>e[i]!==null).length;for(let i=0;i<t.length&&r;i++){const s=t[i],o=n[s],l=e[s];r=s==="ychange"||o===l||Nb(o)&&Nb(l)&&pf(o,l)}return r},wa=n=>{const e=n.content.content,t=[];for(let r=0;r<e.length;r++){const i=e[r];if(i.isText){const s=[];for(let o=e[r];r<e.length&&o.isText;o=e[++r])s.push(o);r--,t.push(s)}else t.push(i)}return t},Db=(n,e)=>{const t=n.toDelta();return t.length===e.length&&t.every((r,i)=>r.insert===e[i].text&&Ed(r.attributes||{}).length===e[i].marks.length&&e[i].marks.every(s=>pf(r.attributes[s.type.name]||{},s.attrs)))},$o=(n,e)=>{if(n instanceof It&&!(e instanceof Array)&&gf(n,e)){const t=wa(e);return n._length===t.length&&pf(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>$o(r,t[i]))}return n instanceof Zt&&e instanceof Array&&Db(n,e)},xa=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),Rb=(n,e,t)=>{const r=n.toArray(),i=wa(e),s=i.length,o=r.length,l=Ir(o,s);let a=0,c=0,u=!1;for(;a<l;a++){const d=r[a],f=i[a];if(xa(t.get(d),f))u=!0;else if(!$o(d,f))break}for(;a+c<l;c++){const d=r[o-c-1],f=i[s-c-1];if(xa(t.get(d),f))u=!0;else if(!$o(d,f))break}return{equalityFactor:a+c,foundMappedChild:u}},e3=n=>{let e="",t=n._start;const r={};for(;t!==null;)t.deleted||(t.countable&&t.content instanceof Cn?e+=t.content.str:t.content instanceof lt&&(r[t.content.key]=null)),t=t.right;return{str:e,nAttrs:r}},t3=(n,e,t)=>{t.set(n,e);const{nAttrs:r,str:i}=e3(n),s=e.map(c=>({insert:c.text,attributes:Object.assign({},r,Lb(c.marks))})),{insert:o,remove:l,index:a}=WO(i,s.map(c=>c.insert).join(""));n.delete(a,l),n.insert(a,o),n.applyDelta(s.map(c=>({retain:c.insert.length,attributes:c.attributes})))},Lb=n=>{const e={};return n.forEach(t=>{t.type.name!=="ychange"&&(e[t.type.name]=t.attrs)}),e},mf=(n,e,t,r)=>{if(e instanceof It&&e.nodeName!==t.type.name)throw new Error("node name mismatch!");if(r.set(e,t),e instanceof It){const d=e.getAttributes(),f=t.attrs;for(const h in f)f[h]!==null?d[h]!==f[h]&&h!=="ychange"&&e.setAttribute(h,f[h]):e.removeAttribute(h);for(const h in d)f[h]===void 0&&e.removeAttribute(h)}const i=wa(t),s=i.length,o=e.toArray(),l=o.length,a=Ir(s,l);let c=0,u=0;for(;c<a;c++){const d=o[c],f=i[c];if(!xa(r.get(d),f))if($o(d,f))r.set(d,f);else break}for(;u+c+1<a;u++){const d=o[l-u-1],f=i[s-u-1];if(!xa(r.get(d),f))if($o(d,f))r.set(d,f);else break}n.transact(()=>{for(;l-c-u>0&&s-c-u>0;){const f=o[c],h=i[c],p=o[l-u-1],g=i[s-u-1];if(f instanceof Zt&&h instanceof Array)Db(f,h)||t3(f,h,r),c+=1;else{let v=f instanceof It&&gf(f,h),w=p instanceof It&&gf(p,g);if(v&&w){const S=Rb(f,h,r),x=Rb(p,g,r);S.foundMappedChild&&!x.foundMappedChild?w=!1:!S.foundMappedChild&&x.foundMappedChild||S.equalityFactor<x.equalityFactor?v=!1:w=!1}v?(mf(n,f,h,r),c+=1):w?(mf(n,p,g,r),u+=1):(r.delete(e.get(c)),e.delete(c,1),e.insert(c,[hf(h,r)]),c+=1)}}const d=l-c-u;if(l===1&&s===0&&o[0]instanceof Zt?(r.delete(o[0]),o[0].delete(0,o[0].length)):d>0&&(e.slice(c,c+d).forEach(f=>r.delete(f)),e.delete(c,d)),c+u<s){const f=[];for(let h=c;h<s-u;h++)f.push(hf(i[h],r));e.insert(c,f)}},Ke)},gf=(n,e)=>!(e instanceof Array)&&n.nodeName===e.type.name;let jo=null;const n3=()=>{const n=jo;jo=null,n.forEach((e,t)=>{const r=t.state.tr,i=Ke.getState(t.state);i&&i.binding&&!i.binding.isDestroyed&&(e.forEach((s,o)=>{r.setMeta(o,s)}),t.dispatch(r))})},r3=(n,e,t)=>{jo||(jo=new Map,Od(0,n3)),zt(jo,n,Lt).set(e,t)},Ca=(n,e,t)=>{if(n===0)return jd(e,0);let r=e._first===null?null:e._first.content.type;for(;r!==null&&e!==r;){if(r instanceof Zt){if(r._length>=n)return jd(r,n);if(n-=r._length,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{do r=r._item===null?null:r._item.parent,n--;while(r!==e&&r!==null&&r._item!==null&&r._item.next===null);r!==null&&r!==e&&(r=r._item===null?null:r._item.next.content.type)}}else{const i=(t.get(r)||{nodeSize:0}).nodeSize;if(r._first!==null&&n<i)r=r._first.content.type,n--;else{if(n===1&&r._length===0&&i>1)return new _o(r._item===null?null:r._item.id,r._item===null?Mo(r):null,null);if(n-=i,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{if(n===0)return r=r._item===null?r:r._item.parent,new _o(r._item===null?null:r._item.id,r._item===null?Mo(r):null,null);do r=r._item.parent,n--;while(r!==e&&r._item.next===null);r!==e&&(r=r._item.next.content.type)}}}if(r===null)throw cn();if(n===0&&r.constructor!==Zt&&r!==e)return i3(r._item.parent,r._item)}return jd(e,e._length)},i3=(n,e)=>{let t=null,r=null;return n._item===null?r=Mo(n):t=pe(n._item.id.client,n._item.id.clock),new _o(t,r,e.id)},Ho=(n,e,t,r)=>{const i=EM(t,n);if(i===null||i.type!==e&&!Oo(e,i.type._item))return null;let s=i.type,o=0;if(s.constructor===Zt)o=i.index;else if(s._item===null||!s._item.deleted){let l=s._first,a=0;for(;a<s._length&&a<i.index&&l!==null;){if(!l.deleted){const c=l.content.type;a++,c instanceof Zt?o+=c._length:o+=r.get(c).nodeSize}l=l.right}o+=1}for(;s!==e&&s._item!==null;){const l=s._item.parent;if(l._item===null||!l._item.deleted){o+=1;let a=l._first;for(;a!==null;){const c=a.content.type;if(c===s)break;a.deleted||(c instanceof Zt?o+=c._length:o+=r.get(c).nodeSize),a=a.right}}s=l}return o-1},s3=(n,e,t)=>n!==e,o3=n=>{const e=document.createElement("span");e.classList.add("ProseMirror-yjs-cursor"),e.setAttribute("style",`border-color: ${n.color}`);const t=document.createElement("div");t.setAttribute("style",`background-color: ${n.color}`),t.insertBefore(document.createTextNode(n.name),null);const r=document.createTextNode(""),i=document.createTextNode("");return e.insertBefore(r,null),e.insertBefore(t,null),e.insertBefore(i,null),e},Ib=n=>({style:`background-color: ${n.color}70`,class:"ProseMirror-yjs-selection"}),l3=/^#[0-9a-fA-F]{6}$/,Pb=(n,e,t,r,i)=>{const s=Ke.getState(n),o=s.doc,l=[];return s.snapshot!=null||s.prevSnapshot!=null||s.binding===null?He.create(n.doc,[]):(e.getStates().forEach((a,c)=>{if(t(o.clientID,c,a)&&a.cursor!=null){const u=a.user||{};u.color==null?u.color="#ffa500":l3.test(u.color)||console.warn("A user uses an unsupported color format",u),u.name==null&&(u.name=`User: ${c}`);let d=Ho(o,s.type,No(a.cursor.anchor),s.binding.mapping),f=Ho(o,s.type,No(a.cursor.head),s.binding.mapping);if(d!==null&&f!==null){const h=ar(n.doc.content.size-1,0);d=Ir(d,h),f=Ir(f,h),l.push(ut.widget(f,()=>r(u),{key:c+"",side:10}));const p=Ir(d,f),g=ar(d,f);l.push(ut.inline(p,g,i(u),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),He.create(n.doc,l))},a3=(n,{awarenessStateFilter:e=s3,cursorBuilder:t=o3,selectionBuilder:r=Ib,getSelection:i=o=>o.selection}={},s="cursor")=>new je({key:ya,state:{init(o,l){return Pb(l,n,e,t,r)},apply(o,l,a,c){const u=Ke.getState(c),d=o.getMeta(ya);return u&&u.isChangeOrigin||d&&d.awarenessUpdated?Pb(c,n,e,t,r):l.map(o.mapping,o.doc)}},props:{decorations:o=>ya.getState(o)},view:o=>{const l=()=>{o.docView&&r3(o,ya,{awarenessUpdated:!0})},a=()=>{const c=Ke.getState(o.state),u=n.getLocalState()||{};if(c.binding!=null)if(o.hasFocus()){const d=i(o.state),f=Ca(d.anchor,c.type,c.binding.mapping),h=Ca(d.head,c.type,c.binding.mapping);(u.cursor==null||!Dy(No(u.cursor.anchor),f)||!Dy(No(u.cursor.head),h))&&n.setLocalStateField(s,{anchor:f,head:h})}else u.cursor!=null&&Ho(c.doc,c.type,No(u.cursor.anchor),c.binding.mapping)!==null&&n.setLocalStateField(s,null)};return n.on("change",l),o.dom.addEventListener("focusin",a),o.dom.addEventListener("focusout",a),{update:a,destroy:()=>{o.dom.removeEventListener("focusin",a),o.dom.removeEventListener("focusout",a),n.off("change",l),n.setLocalStateField(s,null)}}}}),c3=n=>{const e=hr.getState(n).undoManager;if(e!=null)return e.undo(),!0},u3=n=>{const e=hr.getState(n).undoManager;if(e!=null)return e.redo(),!0},d3=new Set(["paragraph"]),f3=(n,e)=>!(n instanceof ze)||!(n.content instanceof kn)||!(n.content.type instanceof wi||n.content.type instanceof It&&e.has(n.content.type.nodeName))||n.content.type._length===0,h3=({protectedNodes:n=d3,trackedOrigins:e=[],undoManager:t=null}={})=>new je({key:hr,state:{init:(r,i)=>{const s=Ke.getState(i),o=t||new zy(s.type,{trackedOrigins:new Set([Ke].concat(e)),deleteFilter:l=>f3(l,n),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(r,i,s,o)=>{const l=Ke.getState(o).binding,a=i.undoManager,c=a.undoStack.length>0,u=a.redoStack.length>0;return l?{undoManager:a,prevSel:ff(l,s),hasUndoOps:c,hasRedoOps:u}:c!==i.hasUndoOps||u!==i.hasRedoOps?Object.assign({},i,{hasUndoOps:a.undoStack.length>0,hasRedoOps:a.redoStack.length>0}):i}},view:r=>{const i=Ke.getState(r.state),s=hr.getState(r.state).undoManager;return s.on("stack-item-added",({stackItem:o})=>{const l=i.binding;l&&o.meta.set(l,hr.getState(r.state).prevSel)}),s.on("stack-item-popped",({stackItem:o})=>{const l=i.binding;l&&(l.beforeTransactionSelection=o.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{s.destroy()}}}}),p3=Ue.create({name:"collaboration",priority:1e3,addOptions(){return{document:null,field:"default",fragment:null}},onCreate(){this.editor.extensionManager.extensions.find(n=>n.name==="history")&&console.warn('[tiptap warn]: "@tiptap/extension-collaboration" comes with its own history support and is not compatible with "@tiptap/extension-history".')},addCommands(){return{undo:()=>({tr:n,state:e,dispatch:t})=>(n.setMeta("preventDispatch",!0),hr.getState(e).undoManager.undoStack.length===0?!1:t?c3(e):!0),redo:()=>({tr:n,state:e,dispatch:t})=>(n.setMeta("preventDispatch",!0),hr.getState(e).undoManager.redoStack.length===0?!1:t?u3(e):!0)}},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo()}},addProseMirrorPlugins(){const n=this.options.fragment?this.options.fragment:this.options.document.getXmlFragment(this.options.field),e=h3(),t=e.spec.view;e.spec.view=l=>{const{undoManager:a}=hr.getState(l.state);a.restore&&(a.restore(),a.restore=()=>{});const c=t?t(l):void 0;return{destroy:()=>{const u=a.trackedOrigins.has(a),d=a._observers;a.restore=()=>{u&&a.trackedOrigins.add(a),a.doc.on("afterTransaction",a.afterTransactionHandler),a._observers=d},c!=null&&c.destroy&&c.destroy()}}};const r=this.options.ySyncOptions,i=this.options.onFirstRender,s={...r?{...r}:{},...i?{onFirstRender:i}:{}};return[JO(n,s),e]}}),Fb=n=>Array.from(n.entries()).map(([e,t])=>({clientId:e,...t.user})),Bb=()=>null,m3=Ue.create({name:"collaborationCursor",addOptions(){return{provider:null,user:{name:null,color:null},render:n=>{const e=document.createElement("span");e.classList.add("collaboration-cursor__caret"),e.setAttribute("style",`border-color: ${n.color}`);const t=document.createElement("div");return t.classList.add("collaboration-cursor__label"),t.setAttribute("style",`background-color: ${n.color}`),t.insertBefore(document.createTextNode(n.name),null),e.insertBefore(t,null),e},selectionRender:Ib,onUpdate:Bb}},onCreate(){this.options.onUpdate!==Bb&&console.warn('[tiptap warn]: DEPRECATED: The "onUpdate" option is deprecated. Please use `editor.storage.collaborationCursor.users` instead. Read more: https://tiptap.dev/api/extensions/collaboration-cursor')},addStorage(){return{users:[]}},addCommands(){return{updateUser:n=>()=>(this.options.user=n,this.options.provider.awareness.setLocalStateField("user",this.options.user),!0),user:n=>({editor:e})=>(console.warn('[tiptap warn]: DEPRECATED: The "user" command is deprecated. Please use "updateUser" instead. Read more: https://tiptap.dev/api/extensions/collaboration-cursor'),e.commands.updateUser(n))}},addProseMirrorPlugins(){return[a3((this.options.provider.awareness.setLocalStateField("user",this.options.user),this.storage.users=Fb(this.options.provider.awareness.states),this.options.provider.awareness.on("update",()=>{this.storage.users=Fb(this.options.provider.awareness.states)}),this.options.provider.awareness),{cursorBuilder:this.options.render,selectionBuilder:this.options.selectionRender})]}}),g3=/^\s*>\s$/,y3=Ve.create({name:"blockquote",addOptions(){return{HTMLAttributes:{}}},content:"block+",group:"block",defining:!0,parseHTML(){return[{tag:"blockquote"}]},renderHTML({HTMLAttributes:n}){return["blockquote",xe(this.options.HTMLAttributes,n),0]},addCommands(){return{setBlockquote:()=>({commands:n})=>n.wrapIn(this.name),toggleBlockquote:()=>({commands:n})=>n.toggleWrap(this.name),unsetBlockquote:()=>({commands:n})=>n.lift(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-b":()=>this.editor.commands.toggleBlockquote()}},addInputRules(){return[Ji({find:g3,type:this.type})]}}),b3=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,v3=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,w3=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,x3=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,C3=jt.create({name:"bold",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!=="normal"&&null},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}]},renderHTML({HTMLAttributes:n}){return["strong",xe(this.options.HTMLAttributes,n),0]},addCommands(){return{setBold:()=>({commands:n})=>n.setMark(this.name),toggleBold:()=>({commands:n})=>n.toggleMark(this.name),unsetBold:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[ai({find:b3,type:this.type}),ai({find:w3,type:this.type})]},addPasteRules(){return[Rr({find:v3,type:this.type}),Rr({find:x3,type:this.type})]}}),k3=Ve.create({name:"listItem",addOptions(){return{HTMLAttributes:{},bulletListTypeName:"bulletList",orderedListTypeName:"orderedList"}},content:"paragraph block*",defining:!0,parseHTML(){return[{tag:"li"}]},renderHTML({HTMLAttributes:n}){return["li",xe(this.options.HTMLAttributes,n),0]},addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}}),$b=jt.create({name:"textStyle",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"span",getAttrs:n=>n.hasAttribute("style")?{}:!1}]},renderHTML({HTMLAttributes:n}){return["span",xe(this.options.HTMLAttributes,n),0]},addCommands(){return{removeEmptyTextStyle:()=>({state:n,commands:e})=>{const t=oo(n,this.type);return Object.entries(t).some(([,i])=>!!i)?!0:e.unsetMark(this.name)}}}}),jb=/^\s*([-+*])\s$/,S3=Ve.create({name:"bulletList",addOptions(){return{itemTypeName:"listItem",HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:"block list",content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:"ul"}]},renderHTML({HTMLAttributes:n}){return["ul",xe(this.options.HTMLAttributes,n),0]},addCommands(){return{toggleBulletList:()=>({commands:n,chain:e})=>this.options.keepAttributes?e().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(k3.name,this.editor.getAttributes($b.name)).run():n.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let n=Ji({find:jb,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(n=Ji({find:jb,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes($b.name),editor:this.editor})),[n]}}),E3=/(?:^|\s)(`(?!\s+`)((?:[^`]+))`(?!\s+`))$/,T3=/(?:^|\s)(`(?!\s+`)((?:[^`]+))`(?!\s+`))/g,A3=jt.create({name:"code",addOptions(){return{HTMLAttributes:{}}},excludes:"_",code:!0,exitable:!0,parseHTML(){return[{tag:"code"}]},renderHTML({HTMLAttributes:n}){return["code",xe(this.options.HTMLAttributes,n),0]},addCommands(){return{setCode:()=>({commands:n})=>n.setMark(this.name),toggleCode:()=>({commands:n})=>n.toggleMark(this.name),unsetCode:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-e":()=>this.editor.commands.toggleCode()}},addInputRules(){return[ai({find:E3,type:this.type})]},addPasteRules(){return[Rr({find:T3,type:this.type})]}}),M3=/^```([a-z]+)?[\s\n]$/,O3=/^~~~([a-z]+)?[\s\n]$/,_3=Ve.create({name:"codeBlock",addOptions(){return{languageClassPrefix:"language-",exitOnTripleEnter:!0,exitOnArrowDown:!0,HTMLAttributes:{}}},content:"text*",marks:"",group:"block",code:!0,defining:!0,addAttributes(){return{language:{default:null,parseHTML:n=>{var e;const{languageClassPrefix:t}=this.options,s=[...((e=n.firstElementChild)===null||e===void 0?void 0:e.classList)||[]].filter(o=>o.startsWith(t)).map(o=>o.replace(t,""))[0];return s||null},rendered:!1}}},parseHTML(){return[{tag:"pre",preserveWhitespace:"full"}]},renderHTML({node:n,HTMLAttributes:e}){return["pre",xe(this.options.HTMLAttributes,e),["code",{class:n.attrs.language?this.options.languageClassPrefix+n.attrs.language:null},0]]},addCommands(){return{setCodeBlock:n=>({commands:e})=>e.setNode(this.name,n),toggleCodeBlock:n=>({commands:e})=>e.toggleNode(this.name,"paragraph",n)}},addKeyboardShortcuts(){return{"Mod-Alt-c":()=>this.editor.commands.toggleCodeBlock(),Backspace:()=>{const{empty:n,$anchor:e}=this.editor.state.selection,t=e.pos===1;return!n||e.parent.type.name!==this.name?!1:t||!e.parent.textContent.length?this.editor.commands.clearNodes():!1},Enter:({editor:n})=>{if(!this.options.exitOnTripleEnter)return!1;const{state:e}=n,{selection:t}=e,{$from:r,empty:i}=t;if(!i||r.parent.type!==this.type)return!1;const s=r.parentOffset===r.parent.nodeSize-2,o=r.parent.textContent.endsWith(`
|
@@ -371,4 +371,4 @@ Use Chrome, Firefox or Internet Explorer 11`)}}).call(this)}).call(this,s("_proc
|
|
371
371
|
.block-interactivity-`.concat(n,` {pointer-events: none;}
|
372
372
|
.allow-interactivity-`).concat(n,` {pointer-events: all;}
|
373
373
|
`)},BR=0,_s=[];function $R(n){var e=le.useRef([]),t=le.useRef([0,0]),r=le.useRef(),i=le.useState(BR++)[0],s=le.useState(function(){return ov()})[0],o=le.useRef(n);le.useEffect(function(){o.current=n},[n]),le.useEffect(function(){if(n.inert){document.body.classList.add("block-interactivity-".concat(i));var g=oR([n.lockRef.current],(n.shards||[]).map(hv),!0).filter(Boolean);return g.forEach(function(v){return v.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),g.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(i))})}}},[n.inert,n.lockRef.current,n.shards]);var l=le.useCallback(function(g,v){if("touches"in g&&g.touches.length===2)return!o.current.allowPinchZoom;var w=Cc(g),S=t.current,x="deltaX"in g?g.deltaX:S[0]-w[0],y="deltaY"in g?g.deltaY:S[1]-w[1],k,E=g.target,T=Math.abs(x)>Math.abs(y)?"h":"v";if("touches"in g&&T==="h"&&E.type==="range")return!1;var N=cv(T,E);if(!N)return!0;if(N?k=T:(k=T==="v"?"h":"v",N=cv(T,E)),!N)return!1;if(!r.current&&"changedTouches"in g&&(x||y)&&(r.current=k),!k)return!0;var _=r.current||k;return IR(_,v,g,_==="h"?x:y,!0)},[]),a=le.useCallback(function(g){var v=g;if(!(!_s.length||_s[_s.length-1]!==s)){var w="deltaY"in v?fv(v):Cc(v),S=e.current.filter(function(k){return k.name===v.type&&k.target===v.target&&PR(k.delta,w)})[0];if(S&&S.should){v.cancelable&&v.preventDefault();return}if(!S){var x=(o.current.shards||[]).map(hv).filter(Boolean).filter(function(k){return k.contains(v.target)}),y=x.length>0?l(v,x[0]):!o.current.noIsolation;y&&v.cancelable&&v.preventDefault()}}},[]),c=le.useCallback(function(g,v,w,S){var x={name:g,delta:v,target:w,should:S};e.current.push(x),setTimeout(function(){e.current=e.current.filter(function(y){return y!==x})},1)},[]),u=le.useCallback(function(g){t.current=Cc(g),r.current=void 0},[]),d=le.useCallback(function(g){c(g.type,fv(g),g.target,l(g,n.lockRef.current))},[]),f=le.useCallback(function(g){c(g.type,Cc(g),g.target,l(g,n.lockRef.current))},[]);le.useEffect(function(){return _s.push(s),n.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener("wheel",a,Os),document.addEventListener("touchmove",a,Os),document.addEventListener("touchstart",u,Os),function(){_s=_s.filter(function(g){return g!==s}),document.removeEventListener("wheel",a,Os),document.removeEventListener("touchmove",a,Os),document.removeEventListener("touchstart",u,Os)}},[]);var h=n.removeScrollBar,p=n.inert;return le.createElement(le.Fragment,null,p?le.createElement(s,{styles:FR(i)}):null,h?le.createElement(MR,{gapMode:"margin"}):null)}const jR=mR(sv,$R);var pv=le.forwardRef(function(n,e){return le.createElement(wc,Zn({},n,{ref:e,sideCar:jR}))});pv.classNames=wc.classNames;const mv="Popover",[gv,o4]=v1(mv,[G1]),oh=G1(),[HR,Ns]=gv(mv),VR=n=>{const{__scopePopover:e,children:t,open:r,defaultOpen:i,onOpenChange:s,modal:o=!1}=n,l=oh(e),a=O.useRef(null),[c,u]=O.useState(!1),[d=!1,f]=eR({prop:r,defaultProp:i,onChange:s});return O.createElement(GD,l,O.createElement(HR,{scope:e,contentId:FN(),triggerRef:a,open:d,onOpenChange:f,onOpenToggle:O.useCallback(()=>f(h=>!h),[f]),hasCustomAnchor:c,onCustomAnchorAdd:O.useCallback(()=>u(!0),[]),onCustomAnchorRemove:O.useCallback(()=>u(!1),[]),modal:o},t))},zR="PopoverTrigger",UR=O.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,i=Ns(zR,t),s=oh(t),o=Ai(e,i.triggerRef),l=O.createElement(Mi.button,dt({type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":bv(i.open)},r,{ref:o,onClick:Ur(n.onClick,i.onOpenToggle)}));return i.hasCustomAnchor?l:O.createElement(YD,dt({asChild:!0},s),l)}),WR="PopoverPortal",[l4,qR]=gv(WR,{forceMount:void 0}),Yo="PopoverContent",KR=O.forwardRef((n,e)=>{const t=qR(Yo,n.__scopePopover),{forceMount:r=t.forceMount,...i}=n,s=Ns(Yo,n.__scopePopover);return O.createElement(ev,{present:r||s.open},s.modal?O.createElement(JR,dt({},i,{ref:e})):O.createElement(GR,dt({},i,{ref:e})))}),JR=O.forwardRef((n,e)=>{const t=Ns(Yo,n.__scopePopover),r=O.useRef(null),i=Ai(e,r),s=O.useRef(!1);return O.useEffect(()=>{const o=r.current;if(o)return sR(o)},[]),O.createElement(pv,{as:$f,allowPinchZoom:!0},O.createElement(yv,dt({},n,{ref:i,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ur(n.onCloseAutoFocus,o=>{var l;o.preventDefault(),s.current||(l=t.triggerRef.current)===null||l===void 0||l.focus()}),onPointerDownOutside:Ur(n.onPointerDownOutside,o=>{const l=o.detail.originalEvent,a=l.button===0&&l.ctrlKey===!0,c=l.button===2||a;s.current=c},{checkForDefaultPrevented:!1}),onFocusOutside:Ur(n.onFocusOutside,o=>o.preventDefault(),{checkForDefaultPrevented:!1})})))}),GR=O.forwardRef((n,e)=>{const t=Ns(Yo,n.__scopePopover),r=O.useRef(!1),i=O.useRef(!1);return O.createElement(yv,dt({},n,{ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var o;if((o=n.onCloseAutoFocus)===null||o===void 0||o.call(n,s),!s.defaultPrevented){var l;r.current||(l=t.triggerRef.current)===null||l===void 0||l.focus(),s.preventDefault()}r.current=!1,i.current=!1},onInteractOutside:s=>{var o,l;(o=n.onInteractOutside)===null||o===void 0||o.call(n,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const a=s.target;((l=t.triggerRef.current)===null||l===void 0?void 0:l.contains(a))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}}))}),yv=O.forwardRef((n,e)=>{const{__scopePopover:t,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:o,onEscapeKeyDown:l,onPointerDownOutside:a,onFocusOutside:c,onInteractOutside:u,...d}=n,f=Ns(Yo,t),h=oh(t);return AN(),O.createElement(MN,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s},O.createElement(SN,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:u,onEscapeKeyDown:l,onPointerDownOutside:a,onFocusOutside:c,onDismiss:()=>f.onOpenChange(!1)},O.createElement(ZD,dt({"data-state":bv(f.open),role:"dialog",id:f.contentId},h,d,{ref:e,style:{...d.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}}))))}),YR="PopoverClose",ZR=O.forwardRef((n,e)=>{const{__scopePopover:t,...r}=n,i=Ns(YR,t);return O.createElement(Mi.button,dt({type:"button"},r,{ref:e,onClick:Ur(n.onClick,()=>i.onOpenChange(!1))}))});function bv(n){return n?"open":"closed"}const XR=VR,QR=UR,e5=KR,kc=ZR,Sc=({children:n,isActive:e,onClick:t,disabled:r,className:i})=>{const s=Fe("flex items-center gap-2 p-1.5 text-xs font-medium text-neutral-500 text-left w-full rounded-md border border-transparent transition-all",!e&&!r,"hover:border-neutral-200 hover:bg-neutral-100",e&&!r&&"bg-neutral-200 text-neutral-800",r&&"text-neutral-300 cursor-not-allowed",i);return D.jsx("button",{className:s,disabled:r,onClick:t,children:n})},t5=(n,e,t)=>{const r=O.useCallback(()=>{const l=n.chain();l.setNodeSelection(t).unsetAllMarks(),(e==null?void 0:e.type.name)!=="paragraph"&&l.setParagraph(),l.run()},[n,t,e==null?void 0:e.type.name]),i=O.useCallback(()=>{n.commands.setNodeSelection(t);const{$anchor:l}=n.state.selection,a=l.node(1)||n.state.selection.node;n.chain().setMeta("hideDragHandle",!0).insertContentAt(t+((e==null?void 0:e.nodeSize)||0),a.toJSON()).run()},[n,t,e==null?void 0:e.nodeSize]),s=O.useCallback(()=>{n.chain().setMeta("hideDragHandle",!0).setNodeSelection(t).run(),document.execCommand("copy"),alert("copied")},[n,t]),o=O.useCallback(()=>{n.chain().setMeta("hideDragHandle",!0).setNodeSelection(t).deleteSelection().run()},[n,t]);return{resetTextFormatting:r,duplicateNode:i,copyNodeToClipboard:s,deleteNode:o}},n5=({node:n,getPos:e,editor:t,deleteNode:r})=>{const[i,s]=O.useState(!1),o=t5(t,n,e()),l=Ul(),a=["https://twitter.com","https://x.com"],c=O.useMemo(()=>{const{content:_}=n.content;return _[0].type.name==="table"},[n.content]),u=O.useMemo(()=>{var A;const{content:_}=n.content;return(A=_[0].content.content[0])==null?void 0:A.text},[n.content]),d=O.useMemo(()=>{var A;const{content:_}=n.content;return(A=_[0].content.content[1])==null?void 0:A.text},[n.content]),f=O.useMemo(()=>{const{content:_}=n.content;return _[0].content.content.find(A=>{var R;return(R=A==null?void 0:A.text)==null?void 0:R.match(/\/status\/([0-9]*)/)})},[n.content]),h=()=>{if(!u)return;let _=u;if(u.includes("<iframe"))_=d;else switch(!0){case/youtu\.?be(?:\.com)?\/(?:.*v(?:\/|=)|(?:.*\/)?)([a-zA-Z0-9-_]+)/.test(u):{const V=u.match(/youtu\.?be(?:\.com)?\/(?:.*v(?:\/|=)|(?:.*\/)?)([a-zA-Z0-9-_]+)/);V&&V.length>0&&(_=`https://www.youtube.com/embed/${V[1]}`);break}case/vimeo\.com\/([a-zA-Z0-9-_]+)/.test(u):{const V=u.match(/vimeo\.com\/([a-zA-Z0-9-_]+)/);V&&V.length>0&&(_=`https://player.vimeo.com/video/${V[1]}`);break}default:return}const A=640,R=360,P=e(),$=P+n.nodeSize;_&&(t==null||t.chain().focus(P).deleteRange({from:P===0?P:P+1,to:$}).setIframe({src:_,width:A,height:R}).run())},p=_=>{const A=_.match(/\/status\/([0-9]*)/);return A&&A.length>0?A[1]:null},g=()=>{if(!u)return;let _=u;const A=a.some(V=>u.includes(V)),R=p(u);A&&R?_=R:f&&(_=p(f.text));const P=e(),$=P+n.nodeSize;_&&(t==null||t.chain().focus(P).deleteRange({from:P===2?P:P+1,to:$}).setTweetEmbed({tweetId:_}).run())},v=()=>{const _=e()+n.nodeSize;t.commands.insertContentAt(_,{type:"dBlock",content:[{type:"paragraph"}]})},w=()=>{const _=e();t.commands.insertContentAt(_,{type:"dBlock",content:[{type:"paragraph"}]})},S=()=>{r()},x=_=>{_.altKey?k():y()},y=()=>{v()},k=()=>{w()},E=_=>{_.altKey&&S()},N=y1(()=>{if(a.some(_=>u.includes(_))||f!=null&&f.text){g();return}else{h();return}},1e3);return O.useEffect(()=>{u&&N()},[u]),D.jsxs(bo,{as:"div",className:Fe("flex gap-2 group w-full relative justify-center items-start",l&&"pointer-events-none",c&&"2xl:ml-4 pointer-events-auto"),children:[D.jsxs("section",{className:"lg:flex gap-1 hidden","aria-label":"left-menu",contentEditable:!1,children:[D.jsx(T0,{content:D.jsxs("div",{className:"flex flex-col w-40",children:[D.jsx("div",{className:"text-xs",children:"Click to add below"}),D.jsx("div",{className:"text-xs",children:"Opt + Click to add above"})]}),children:D.jsx("div",{className:`d-block-button cursor-pointer ${!l&&"group-hover:opacity-100"}`,contentEditable:!1,onClick:x,children:D.jsx(rT,{size:18})})}),D.jsxs(XR,{open:i,onOpenChange:s,children:[D.jsx(QR,{asChild:!0,children:D.jsx("div",{className:`d-block-button cursor-pointer ${!l&&"group-hover:opacity-100"}`,contentEditable:!1,draggable:!0,"data-drag-handle":!0,onClick:E,children:D.jsx(YE,{size:18})})}),D.jsx(e5,{side:"bottom",align:"start",sideOffset:8,className:"z-10",children:D.jsxs(ld,{className:"p-2 flex flex-col min-w-[16rem]",children:[D.jsx(kc,{children:D.jsxs(Sc,{onClick:o.resetTextFormatting,children:[D.jsx(iT,{size:18}),"Clear formatting"]})}),D.jsx(kc,{children:D.jsxs(Sc,{onClick:o.copyNodeToClipboard,children:[D.jsx(qE,{size:18}),"Copy to clipboard"]})}),D.jsx(kc,{children:D.jsxs(Sc,{onClick:o.duplicateNode,children:[D.jsx(JE,{size:18}),"Duplicate"]})}),D.jsx(vo.Divider,{horizontal:!0}),D.jsx(kc,{children:D.jsxs(Sc,{onClick:o.deleteNode,className:"text-red-500 hover:bg-red-500 bg-opacity-10 hover:bg-opacity-20",children:[D.jsx(cT,{size:18}),"Delete"]})})]})})]})]}),D.jsx(Kg,{className:Fe("node-view-content w-full",{"is-table min-w-auto":c})})]})},r5=Ve.create({name:"dBlock",priority:1e3,group:"dBlock",content:"(block|columns)",draggable:!0,selectable:!1,inline:!1,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:'div[data-type="d-block"]'}]},renderHTML({HTMLAttributes:n}){return["div",xe(n,{"data-type":"d-block"}),0]},addCommands(){return{setDBlock:n=>({state:e,chain:t})=>{const{selection:{from:r}}=e,i=n!==void 0||n!==null?r:n;return t().insertContentAt(i,{type:this.name,content:[{type:"paragraph"}]}).focus(i+2).run()},mergeDBlocksIntoList:n=>({state:e,dispatch:t})=>{if(!t)throw new Error("Dispatch function is not provided.");const{from:r,to:i}=e.selection;let s=e.tr;const o=[];if(e.doc.nodesBetween(r,i,a=>{if(a.type.name===this.name){const c=e.schema.nodes.listItem.create(null,a.content);c&&o.push(c)}}),o.length===0)return!1;const l=e.schema.nodes[n].create(null,o);return l?(s=s.replaceRangeWith(r,i,l),t(s),!0):!1},splitListToDBlocks:n=>({state:e,dispatch:t})=>{if(!t)throw new Error("Dispatch function is not provided.");const{from:r,to:i}=e.selection;let s=e.tr;return e.doc.nodesBetween(r,i,(o,l)=>{if(o.type.name===n){const a=e.schema.nodes[this.name].create(null,o.content);s=s.insert(l,a)}}),t(s),!0}}},addNodeView(){return hi(n5)},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setDBlock(),Enter:({editor:n})=>{var c;const{selection:{$head:e,from:t,to:r},doc:i}=n.state,s=e.node(e.depth-1);if((s==null?void 0:s.type.name)!=="dBlock")return!1;let o=-1,l="";i.descendants((u,d)=>{if(o!==-1)return!1;if(u.type.name===this.name)return;const[f,h]=[d,d+u.nodeSize];return f<=t&&r<=h&&(o=h,l=u.type.name),!1});const a=(c=i.slice(t,o))==null?void 0:c.toJSON().content;try{return l==="codeBlock"?n.chain().insertContentAt({from:t,to:o},`
|
374
|
-
`).focus(o+1).run():["columns","heading"].includes(l)?n.chain().insertContent({type:"dBlock",content:[{type:"paragraph"}]}).focus().run():n.chain().insertContentAt({from:t,to:o},{type:this.name,content:a}).focus(t+4).run()}catch(u){return console.error(`Error inserting content into dBlock node: ${u}`),!1}}}}});let lh,ah;if(typeof WeakMap<"u"){let n=new WeakMap;lh=e=>n.get(e),ah=(e,t)=>(n.set(e,t),t)}else{let n=[],e=10,t=0;lh=r=>{for(let i=0;i<n.length;i+=2)if(n[i]==r)return n[i+1]},ah=(r,i)=>(t==e&&(t=0),n[t++]=r,n[t++]=i)}class Ds{constructor(e,t,r,i){this.left=e,this.top=t,this.right=r,this.bottom=i}}class et{constructor(e,t,r,i){this.width=e,this.height=t,this.map=r,this.problems=i}findCell(e){for(let t=0;t<this.map.length;t++){let r=this.map[t];if(r!=e)continue;let i=t%this.width,s=t/this.width|0,o=i+1,l=s+1;for(let a=1;o<this.width&&this.map[t+a]==r;a++)o++;for(let a=1;l<this.height&&this.map[t+this.width*a]==r;a++)l++;return new Ds(i,s,o,l)}throw new RangeError("No cell with offset "+e+" found")}colCount(e){for(let t=0;t<this.map.length;t++)if(this.map[t]==e)return t%this.width;throw new RangeError("No cell with offset "+e+" found")}nextCell(e,t,r){let{left:i,right:s,top:o,bottom:l}=this.findCell(e);return t=="horiz"?(r<0?i==0:s==this.width)?null:this.map[o*this.width+(r<0?i-1:s)]:(r<0?o==0:l==this.height)?null:this.map[i+this.width*(r<0?o-1:l)]}rectBetween(e,t){let{left:r,right:i,top:s,bottom:o}=this.findCell(e),{left:l,right:a,top:c,bottom:u}=this.findCell(t);return new Ds(Math.min(r,l),Math.min(s,c),Math.max(i,a),Math.max(o,u))}cellsInRect(e){let t=[],r={};for(let i=e.top;i<e.bottom;i++)for(let s=e.left;s<e.right;s++){let o=i*this.width+s,l=this.map[o];r[l]||(r[l]=!0,(s!=e.left||!s||this.map[o-1]!=l)&&(i!=e.top||!i||this.map[o-this.width]!=l)&&t.push(l))}return t}positionAt(e,t,r){for(let i=0,s=0;;i++){let o=s+r.child(i).nodeSize;if(i==e){let l=t+e*this.width,a=(e+1)*this.width;for(;l<a&&this.map[l]<s;)l++;return l==a?o-1:this.map[l]}s=o}}static get(e){return lh(e)||ah(e,i5(e))}}function i5(n){if(n.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+n.type.name);let e=s5(n),t=n.childCount,r=[],i=0,s=null,o=[];for(let c=0,u=e*t;c<u;c++)r[c]=0;for(let c=0,u=0;c<t;c++){let d=n.child(c);u++;for(let p=0;;p++){for(;i<r.length&&r[i]!=0;)i++;if(p==d.childCount)break;let g=d.child(p),{colspan:v,rowspan:w,colwidth:S}=g.attrs;for(let x=0;x<w;x++){if(x+c>=t){(s||(s=[])).push({type:"overlong_rowspan",pos:u,n:w-x});break}let y=i+x*e;for(let k=0;k<v;k++){r[y+k]==0?r[y+k]=u:(s||(s=[])).push({type:"collision",row:c,pos:u,n:v-k});let E=S&&S[k];if(E){let T=(y+k)%e*2,N=o[T];N==null||N!=E&&o[T+1]==1?(o[T]=E,o[T+1]=1):N==E&&o[T+1]++}}}i+=v,u+=g.nodeSize}let f=(c+1)*e,h=0;for(;i<f;)r[i++]==0&&h++;h&&(s||(s=[])).push({type:"missing",row:c,n:h}),u++}let l=new et(e,t,r,s),a=!1;for(let c=0;!a&&c<o.length;c+=2)o[c]!=null&&o[c+1]<t&&(a=!0);return a&&o5(l,o,n),l}function s5(n){let e=-1,t=!1;for(let r=0;r<n.childCount;r++){let i=n.child(r),s=0;if(t)for(let o=0;o<r;o++){let l=n.child(o);for(let a=0;a<l.childCount;a++){let c=l.child(a);o+c.attrs.rowspan>r&&(s+=c.attrs.colspan)}}for(let o=0;o<i.childCount;o++){let l=i.child(o);s+=l.attrs.colspan,l.attrs.rowspan>1&&(t=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function o5(n,e,t){n.problems||(n.problems=[]);for(let r=0,i={};r<n.map.length;r++){let s=n.map[r];if(i[s])continue;i[s]=!0;let o=t.nodeAt(s),l=null;for(let a=0;a<o.attrs.colspan;a++){let c=(r+a)%n.width,u=e[c*2];u!=null&&(!o.attrs.colwidth||o.attrs.colwidth[a]!=u)&&((l||(l=l5(o.attrs)))[a]=u)}l&&n.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:l})}}function l5(n){if(n.colwidth)return n.colwidth.slice();let e=[];for(let t=0;t<n.colspan;t++)e.push(0);return e}function Mt(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(let t in n.nodes){let r=n.nodes[t],i=r.spec.tableRole;i&&(e[i]=r)}}return e}const Gr=new We("selectingCells");function Rs(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function a5(n){for(let e=n.depth;e>0;e--){const t=n.node(e).type.spec.tableRole;if(t==="cell"||t==="header_cell")return n.node(e)}return null}function Tn(n){let e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function Ec(n){let e=n.selection;return e.$anchorCell?e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell:e.node&&e.node.type.spec.tableRole=="cell"?e.$anchor:Rs(e.$head)||c5(e.$head)}function c5(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function ch(n){return n.parent.type.spec.tableRole=="row"&&n.nodeAfter}function u5(n){return n.node(0).resolve(n.pos+n.nodeAfter.nodeSize)}function uh(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function vv(n,e,t){let r=n.start(-1),s=et.get(n.node(-1)).nextCell(n.pos-r,e,t);return s==null?null:n.node(0).resolve(r+s)}function wt(n,e,t){let r={};for(let i in n)r[i]=n[i];return r[e]=t,r}function _i(n,e,t=1){let r=wt(n,"colspan",n.colspan-t);return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,t),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function wv(n,e,t=1){let r=wt(n,"colspan",n.colspan+t);if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;i<t;i++)r.colwidth.splice(e,0,0)}return r}function d5(n,e,t){let r=Mt(e.type.schema).header_cell;for(let i=0;i<n.height;i++)if(e.nodeAt(n.map[t+i*n.width]).type!=r)return!1;return!0}class Se extends ue{constructor(e,t=e){let r=e.node(-1),i=et.get(r),s=e.start(-1),o=i.rectBetween(e.pos-s,t.pos-s),l=e.node(0),a=i.cellsInRect(o).filter(u=>u!=t.pos-s);a.unshift(t.pos-s);let c=a.map(u=>{let d=r.nodeAt(u),f=u+s+1;return new Jc(l.resolve(f),l.resolve(f+d.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=t}map(e,t){let r=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(ch(r)&&ch(i)&&uh(r,i)){let s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?Se.rowSelection(r,i):s&&this.isColSelection()?Se.colSelection(r,i):new Se(r,i)}return ce.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=et.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),s={},o=[];for(let a=i.top;a<i.bottom;a++){let c=[];for(let u=a*t.width+i.left,d=i.left;d<i.right;d++,u++){let f=t.map[u];if(!s[f]){s[f]=!0;let h=t.findCell(f),p=e.nodeAt(f),g=i.left-h.left,v=h.right-i.right;if(g>0||v>0){let w=p.attrs;g>0&&(w=_i(w,0,g)),v>0&&(w=_i(w,w.colspan-v,v)),h.left<i.left?p=p.type.createAndFill(w):p=p.type.create(w,p.content)}if(h.top<i.top||h.bottom>i.bottom){let w=wt(p.attrs,"rowspan",Math.min(h.bottom,i.bottom)-Math.max(h.top,i.top));h.top<i.top?p=p.type.createAndFill(w):p=p.type.create(w,p.content)}c.push(p)}}o.push(e.child(a).copy(W.from(c)))}const l=this.isColSelection()&&this.isRowSelection()?e:o;return new Y(W.from(l),1,1)}replace(e,t=Y.empty){let r=e.steps.length,i=this.ranges;for(let o=0;o<i.length;o++){let{$from:l,$to:a}=i[o],c=e.mapping.slice(r);e.replace(c.map(l.pos),c.map(a.pos),o?Y.empty:t)}let s=ue.findFrom(e.doc.resolve(e.mapping.slice(r).map(this.to)),-1);s&&e.setSelection(s)}replaceWith(e,t){this.replace(e,new Y(W.from(t),0,0))}forEachCell(e){let t=this.$anchorCell.node(-1),r=et.get(t),i=this.$anchorCell.start(-1),s=r.cellsInRect(r.rectBetween(this.$anchorCell.pos-i,this.$headCell.pos-i));for(let o=0;o<s.length;o++)e(t.nodeAt(s[o]),i+s[o])}isColSelection(){let e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);if(Math.min(e,t)>0)return!1;let r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){let r=et.get(e.node(-1)),i=e.start(-1),s=r.findCell(e.pos-i),o=r.findCell(t.pos-i),l=e.node(0);return s.top<=o.top?(s.top>0&&(e=l.resolve(i+r.map[s.left])),o.bottom<r.height&&(t=l.resolve(i+r.map[r.width*(r.height-1)+o.right-1]))):(o.top>0&&(t=l.resolve(i+r.map[o.left])),s.bottom<r.height&&(e=l.resolve(i+r.map[r.width*(r.height-1)+s.right-1]))),new Se(e,t)}isRowSelection(){let e=et.get(this.$anchorCell.node(-1)),t=this.$anchorCell.start(-1),r=e.colCount(this.$anchorCell.pos-t),i=e.colCount(this.$headCell.pos-t);if(Math.min(r,i)>0)return!1;let s=r+this.$anchorCell.nodeAfter.attrs.colspan,o=i+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,o)==e.width}eq(e){return e instanceof Se&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){let r=et.get(e.node(-1)),i=e.start(-1),s=r.findCell(e.pos-i),o=r.findCell(t.pos-i),l=e.node(0);return s.left<=o.left?(s.left>0&&(e=l.resolve(i+r.map[s.top*r.width])),o.right<r.width&&(t=l.resolve(i+r.map[r.width*(o.top+1)-1]))):(o.left>0&&(t=l.resolve(i+r.map[o.top*r.width])),s.right<r.width&&(e=l.resolve(i+r.map[r.width*(s.top+1)-1]))),new Se(e,t)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(e,t){return new Se(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){return new Se(e.resolve(t),e.resolve(r))}getBookmark(){return new dh(this.$anchorCell.pos,this.$headCell.pos)}}Se.prototype.visible=!1,ue.jsonID("cell",Se);class dh{constructor(e,t){this.anchor=e,this.head=t}map(e){return new dh(e.map(this.anchor),e.map(this.head))}resolve(e){let t=e.resolve(this.anchor),r=e.resolve(this.head);return t.parent.type.spec.tableRole=="row"&&r.parent.type.spec.tableRole=="row"&&t.index()<t.parent.childCount&&r.index()<r.parent.childCount&&uh(t,r)?new Se(t,r):ue.near(r,1)}}function f5(n){if(!(n.selection instanceof Se))return null;let e=[];return n.selection.forEachCell((t,r)=>{e.push(ut.node(r,r+t.nodeSize,{class:"selectedCell"}))}),He.create(n.doc,e)}function h5({$from:n,$to:e}){if(n.pos==e.pos||n.pos<n.pos-6)return!1;let t=n.pos,r=e.pos,i=n.depth;for(;i>=0&&!(n.after(i+1)<n.end(i));i--,t++);for(let s=e.depth;s>=0&&!(e.before(s+1)>e.start(s));s--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function p5({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){let s=n.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){t=s;break}}for(let i=e.depth;i>0;i--){let s=e.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){r=s;break}}return t!==r&&e.parentOffset===0}function m5(n,e,t){let r=(e||n).selection,i=(e||n).doc,s,o;if(r instanceof se&&(o=r.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=Se.create(i,r.from);else if(o=="row"){let l=i.resolve(r.from+1);s=Se.rowSelection(l,l)}else if(!t){let l=et.get(r.node),a=r.from+1,c=a+l.map[l.width*l.height-1];s=Se.create(i,a+1,c)}}else r instanceof ce&&h5(r)?s=ce.create(i,r.from):r instanceof ce&&p5(r)&&(s=ce.create(i,r.$from.start(),r.$from.end()));return s&&(e||(e=n.tr)).setSelection(s),e}function g5(n){if(!n.size)return null;let{content:e,openStart:t,openEnd:r}=n;for(;e.childCount==1&&(t>0&&r>0||e.firstChild.type.spec.tableRole=="table");)t--,r--,e=e.firstChild.content;let i=e.firstChild,s=i.type.spec.tableRole,o=i.type.schema,l=[];if(s=="row")for(let a=0;a<e.childCount;a++){let c=e.child(a).content,u=a?0:Math.max(0,t-1),d=a<e.childCount-1?0:Math.max(0,r-1);(u||d)&&(c=fh(Mt(o).row,new Y(c,u,d)).content),l.push(c)}else if(s=="cell"||s=="header_cell")l.push(t||r?fh(Mt(o).row,new Y(e,t,r)).content:e);else return null;return y5(o,l)}function y5(n,e){let t=[];for(let i=0;i<e.length;i++){let s=e[i];for(let o=s.childCount-1;o>=0;o--){let{rowspan:l,colspan:a}=s.child(o).attrs;for(let c=i;c<i+l;c++)t[c]=(t[c]||0)+a}}let r=0;for(let i=0;i<t.length;i++)r=Math.max(r,t[i]);for(let i=0;i<t.length;i++)if(i>=e.length&&e.push(W.empty),t[i]<r){let s=Mt(n).cell.createAndFill(),o=[];for(let l=t[i];l<r;l++)o.push(s);e[i]=e[i].append(W.from(o))}return{height:e.length,width:r,rows:e}}function fh(n,e){let t=n.createAndFill();return new qc(t).replace(0,t.content.size,e).doc}function b5({width:n,height:e,rows:t},r,i){if(n!=r){let s=[],o=[];for(let l=0;l<t.length;l++){let a=t[l],c=[];for(let u=s[l]||0,d=0;u<r;d++){let f=a.child(d%a.childCount);u+f.attrs.colspan>r&&(f=f.type.create(_i(f.attrs,f.attrs.colspan,u+f.attrs.colspan-r),f.content)),c.push(f),u+=f.attrs.colspan;for(let h=1;h<f.attrs.rowspan;h++)s[l+h]=(s[l+h]||0)+f.attrs.colspan}o.push(W.from(c))}t=o,n=r}if(e!=i){let s=[];for(let o=0,l=0;o<i;o++,l++){let a=[],c=t[l%e];for(let u=0;u<c.childCount;u++){let d=c.child(u);o+d.attrs.rowspan>i&&(d=d.type.create(wt(d.attrs,"rowspan",Math.max(1,i-d.attrs.rowspan)),d.content)),a.push(d)}s.push(W.from(a))}t=s,e=i}return{width:n,height:e,rows:t}}function v5(n,e,t,r,i,s,o){let l=n.doc.type.schema,a=Mt(l),c,u;if(i>e.width)for(let d=0,f=0;d<e.height;d++){let h=t.child(d);f+=h.nodeSize;let p=[],g;h.lastChild==null||h.lastChild.type==a.cell?g=c||(c=a.cell.createAndFill()):g=u||(u=a.header_cell.createAndFill());for(let v=e.width;v<i;v++)p.push(g);n.insert(n.mapping.slice(o).map(f-1+r),p)}if(s>e.height){let d=[];for(let p=0,g=(e.height-1)*e.width;p<Math.max(e.width,i);p++){let v=p>=e.width?!1:t.nodeAt(e.map[g+p]).type==a.header_cell;d.push(v?u||(u=a.header_cell.createAndFill()):c||(c=a.cell.createAndFill()))}let f=a.row.create(null,W.from(d)),h=[];for(let p=e.height;p<s;p++)h.push(f);n.insert(n.mapping.slice(o).map(r+t.nodeSize-2),h)}return!!(c||u)}function xv(n,e,t,r,i,s,o,l){if(o==0||o==e.height)return!1;let a=!1;for(let c=i;c<s;c++){let u=o*e.width+c,d=e.map[u];if(e.map[u-e.width]==d){a=!0;let f=t.nodeAt(d),{top:h,left:p}=e.findCell(d);n.setNodeMarkup(n.mapping.slice(l).map(d+r),null,wt(f.attrs,"rowspan",o-h)),n.insert(n.mapping.slice(l).map(e.positionAt(o,p,t)),f.type.createAndFill(wt(f.attrs,"rowspan",h+f.attrs.rowspan-o))),c+=f.attrs.colspan-1}}return a}function Cv(n,e,t,r,i,s,o,l){if(o==0||o==e.width)return!1;let a=!1;for(let c=i;c<s;c++){let u=c*e.width+o,d=e.map[u];if(e.map[u-1]==d){a=!0;let f=t.nodeAt(d),h=e.colCount(d),p=n.mapping.slice(l).map(d+r);n.setNodeMarkup(p,null,_i(f.attrs,o-h,f.attrs.colspan-(o-h))),n.insert(p+f.nodeSize,f.type.createAndFill(_i(f.attrs,0,o-h))),c+=f.attrs.rowspan-1}}return a}function kv(n,e,t,r,i){let s=t?n.doc.nodeAt(t-1):n.doc,o=et.get(s),{top:l,left:a}=r,c=a+i.width,u=l+i.height,d=n.tr,f=0;function h(){s=t?d.doc.nodeAt(t-1):d.doc,o=et.get(s),f=d.mapping.maps.length}v5(d,o,s,t,c,u,f)&&h(),xv(d,o,s,t,a,c,l,f)&&h(),xv(d,o,s,t,a,c,u,f)&&h(),Cv(d,o,s,t,l,u,a,f)&&h(),Cv(d,o,s,t,l,u,c,f)&&h();for(let p=l;p<u;p++){let g=o.positionAt(p,a,s),v=o.positionAt(p,c,s);d.replace(d.mapping.slice(f).map(g+t),d.mapping.slice(f).map(v+t),new Y(i.rows[p-l],0,0))}h(),d.setSelection(new Se(d.doc.resolve(t+o.positionAt(l,a,s)),d.doc.resolve(t+o.positionAt(u-1,c-1,s)))),e(d)}const w5=ku({ArrowLeft:Ac("horiz",-1),ArrowRight:Ac("horiz",1),ArrowUp:Ac("vert",-1),ArrowDown:Ac("vert",1),"Shift-ArrowLeft":Mc("horiz",-1),"Shift-ArrowRight":Mc("horiz",1),"Shift-ArrowUp":Mc("vert",-1),"Shift-ArrowDown":Mc("vert",1),Backspace:Oc,"Mod-Backspace":Oc,Delete:Oc,"Mod-Delete":Oc});function Tc(n,e,t){return t.eq(n.selection)?!1:(e&&e(n.tr.setSelection(t).scrollIntoView()),!0)}function Ac(n,e){return(t,r,i)=>{let s=t.selection;if(s instanceof Se)return Tc(t,r,ue.near(s.$headCell,e));if(n!="horiz"&&!s.empty)return!1;let o=Sv(i,n,e);if(o==null)return!1;if(n=="horiz")return Tc(t,r,ue.near(t.doc.resolve(s.head+e),e));{let l=t.doc.resolve(o),a=vv(l,n,e),c;return a?c=ue.near(a,1):e<0?c=ue.near(t.doc.resolve(l.before(-1)),-1):c=ue.near(t.doc.resolve(l.after(-1)),1),Tc(t,r,c)}}}function Mc(n,e){return(t,r,i)=>{let s=t.selection;if(!(s instanceof Se)){let l=Sv(i,n,e);if(l==null)return!1;s=new Se(t.doc.resolve(l))}let o=vv(s.$headCell,n,e);return o?Tc(t,r,new Se(s.$anchorCell,o)):!1}}function Oc(n,e){let t=n.selection;if(!(t instanceof Se))return!1;if(e){let r=n.tr,i=Mt(n.schema).cell.createAndFill().content;t.forEachCell((s,o)=>{s.content.eq(i)||r.replace(r.mapping.map(o+1),r.mapping.map(o+s.nodeSize-1),new Y(i,0,0))}),r.docChanged&&e(r)}return!0}function x5(n,e){let t=n.state.doc,r=Rs(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new Se(r))),!0):!1}function C5(n,e,t){if(!Tn(n.state))return!1;let r=g5(t),i=n.state.selection;if(i instanceof Se){r||(r={width:1,height:1,rows:[W.from(fh(Mt(n.state.schema).cell,t))]});let s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),l=et.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return r=b5(r,l.right-l.left,l.bottom-l.top),kv(n.state,n.dispatch,o,l,r),!0}else if(r){let s=Ec(n.state),o=s.start(-1);return kv(n.state,n.dispatch,o,et.get(s.node(-1)).findCell(s.pos-o),r),!0}else return!1}function k5(n,e){if(e.ctrlKey||e.metaKey)return;let t=Ev(n,e.target),r;if(e.shiftKey&&n.state.selection instanceof Se)i(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&t&&(r=Rs(n.state.selection.$anchor))!=null&&hh(n,e).pos!=r.pos)i(r,e),e.preventDefault();else if(!t)return;function i(l,a){let c=hh(n,a),u=Gr.getState(n.state)==null;if(!c||!uh(l,c))if(u)c=l;else return;let d=new Se(l,c);if(u||!n.state.selection.eq(d)){let f=n.state.tr.setSelection(d);u&&f.setMeta(Gr,l.pos),n.dispatch(f)}}function s(){n.root.removeEventListener("mouseup",s),n.root.removeEventListener("dragstart",s),n.root.removeEventListener("mousemove",o),Gr.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(Gr,-1))}function o(l){let a=Gr.getState(n.state),c;if(a!=null)c=n.state.doc.resolve(a);else if(Ev(n,l.target)!=t&&(c=hh(n,e),!c))return s();c&&i(c,l)}n.root.addEventListener("mouseup",s),n.root.addEventListener("dragstart",s),n.root.addEventListener("mousemove",o)}function Sv(n,e,t){if(!(n.state.selection instanceof ce))return null;let{$head:r}=n.state.selection;for(let i=r.depth-1;i>=0;i--){let s=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){let l=r.before(i),a=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(a)?l:null}}return null}function Ev(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e}function hh(n,e){let t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?Rs(n.state.doc.resolve(t.pos)):null}const S5=new We("fix-tables");function Tv(n,e,t,r){let i=n.childCount,s=e.childCount;e:for(let o=0,l=0;o<s;o++){let a=e.child(o);for(let c=l,u=Math.min(i,o+3);c<u;c++)if(n.child(c)==a){l=c+1,t+=a.nodeSize;continue e}r(a,t),l<i&&n.child(l).sameMarkup(a)?Tv(n.child(l),a,t+1,r):a.nodesBetween(0,a.content.size,r,t+1),t+=a.nodeSize}}function Av(n,e){let t,r=(i,s)=>{i.type.spec.tableRole=="table"&&(t=E5(n,i,s,t))};return e?e.doc!=n.doc&&Tv(e.doc,n.doc,0,r):n.doc.descendants(r),t}function E5(n,e,t,r){let i=et.get(e);if(!i.problems)return r;r||(r=n.tr);let s=[];for(let a=0;a<i.height;a++)s.push(0);for(let a=0;a<i.problems.length;a++){let c=i.problems[a];if(c.type=="collision"){let u=e.nodeAt(c.pos);for(let d=0;d<u.attrs.rowspan;d++)s[c.row+d]+=c.n;r.setNodeMarkup(r.mapping.map(t+1+c.pos),null,_i(u.attrs,u.attrs.colspan-c.n,c.n))}else if(c.type=="missing")s[c.row]+=c.n;else if(c.type=="overlong_rowspan"){let u=e.nodeAt(c.pos);r.setNodeMarkup(r.mapping.map(t+1+c.pos),null,wt(u.attrs,"rowspan",u.attrs.rowspan-c.n))}else if(c.type=="colwidth mismatch"){let u=e.nodeAt(c.pos);r.setNodeMarkup(r.mapping.map(t+1+c.pos),null,wt(u.attrs,"colwidth",c.colwidth))}}let o,l;for(let a=0;a<s.length;a++)s[a]&&(o==null&&(o=a),l=a);for(let a=0,c=t+1;a<i.height;a++){let u=e.child(a),d=c+u.nodeSize,f=s[a];if(f>0){let h="cell";u.firstChild&&(h=u.firstChild.type.spec.tableRole);let p=[];for(let v=0;v<f;v++)p.push(Mt(n.schema)[h].createAndFill());let g=(a==0||o==a-1)&&l==a?c+1:d-1;r.insert(r.mapping.map(g),p)}c=d}return r.setMeta(S5,{fixTables:!0})}function Xn(n){let e=n.selection,t=Ec(n),r=t.node(-1),i=t.start(-1),s=et.get(r),o;return e instanceof Se?o=s.rectBetween(e.$anchorCell.pos-i,e.$headCell.pos-i):o=s.findCell(t.pos-i),o.tableStart=i,o.map=s,o.table=r,o}function Mv(n,{map:e,tableStart:t,table:r},i){let s=i>0?-1:0;d5(e,r,i+s)&&(s=i==0||i==e.width?null:0);for(let o=0;o<e.height;o++){let l=o*e.width+i;if(i>0&&i<e.width&&e.map[l-1]==e.map[l]){let a=e.map[l],c=r.nodeAt(a);n.setNodeMarkup(n.mapping.map(t+a),null,wv(c.attrs,i-e.colCount(a))),o+=c.attrs.rowspan-1}else{let a=s==null?Mt(r.type.schema).cell:r.nodeAt(e.map[l+s]).type,c=e.positionAt(o,i,r);n.insert(n.mapping.map(t+c),a.createAndFill())}}return n}function T5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n);e(Mv(n.tr,t,t.left))}return!0}function A5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n);e(Mv(n.tr,t,t.right))}return!0}function M5(n,{map:e,table:t,tableStart:r},i){let s=n.mapping.maps.length;for(let o=0;o<e.height;){let l=o*e.width+i,a=e.map[l],c=t.nodeAt(a);if(i>0&&e.map[l-1]==a||i<e.width-1&&e.map[l+1]==a)n.setNodeMarkup(n.mapping.slice(s).map(r+a),null,_i(c.attrs,i-e.colCount(a)));else{let u=n.mapping.slice(s).map(r+a);n.delete(u,u+c.nodeSize)}o+=c.attrs.rowspan}}function O5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n),r=n.tr;if(t.left==0&&t.right==t.map.width)return!1;for(let i=t.right-1;M5(r,t,i),i!=t.left;i--)t.table=t.tableStart?r.doc.nodeAt(t.tableStart-1):r.doc,t.map=et.get(t.table);e(r)}return!0}function _5(n,e,t){let r=Mt(e.type.schema).header_cell;for(let i=0;i<n.width;i++)if(e.nodeAt(n.map[i+t*n.width]).type!=r)return!1;return!0}function Ov(n,{map:e,tableStart:t,table:r},i){let s=t;for(let a=0;a<i;a++)s+=r.child(a).nodeSize;let o=[],l=i>0?-1:0;_5(e,r,i+l)&&(l=i==0||i==e.height?null:0);for(let a=0,c=e.width*i;a<e.width;a++,c++)if(i>0&&i<e.height&&e.map[c]==e.map[c-e.width]){let u=e.map[c],d=r.nodeAt(u).attrs;n.setNodeMarkup(t+u,null,wt(d,"rowspan",d.rowspan+1)),a+=d.colspan-1}else{let u=l==null?Mt(r.type.schema).cell:r.nodeAt(e.map[c+l*e.width]).type;o.push(u.createAndFill())}return n.insert(s,Mt(r.type.schema).row.create(null,o)),n}function N5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n);e(Ov(n.tr,t,t.top))}return!0}function D5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n);e(Ov(n.tr,t,t.bottom))}return!0}function R5(n,{map:e,table:t,tableStart:r},i){let s=0;for(let a=0;a<i;a++)s+=t.child(a).nodeSize;let o=s+t.child(i).nodeSize,l=n.mapping.maps.length;n.delete(s+r,o+r);for(let a=0,c=i*e.width;a<e.width;a++,c++){let u=e.map[c];if(i>0&&u==e.map[c-e.width]){let d=t.nodeAt(u).attrs;n.setNodeMarkup(n.mapping.slice(l).map(u+r),null,wt(d,"rowspan",d.rowspan-1)),a+=d.colspan-1}else if(i<e.width&&u==e.map[c+e.width]){let d=t.nodeAt(u),f=d.type.create(wt(d.attrs,"rowspan",d.attrs.rowspan-1),d.content),h=e.positionAt(i+1,a,t);n.insert(n.mapping.slice(l).map(r+h),f),a+=d.attrs.colspan-1}}}function L5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n),r=n.tr;if(t.top==0&&t.bottom==t.map.height)return!1;for(let i=t.bottom-1;R5(r,t,i),i!=t.top;i--)t.table=t.tableStart?r.doc.nodeAt(t.tableStart-1):r.doc,t.map=et.get(t.table);e(r)}return!0}function _v(n){let e=n.content;return e.childCount==1&&e.firstChild.isTextblock&&e.firstChild.childCount==0}function I5({width:n,height:e,map:t},r){let i=r.top*n+r.left,s=i,o=(r.bottom-1)*n+r.left,l=i+(r.right-r.left-1);for(let a=r.top;a<r.bottom;a++){if(r.left>0&&t[s]==t[s-1]||r.right<n&&t[l]==t[l+1])return!0;s+=n,l+=n}for(let a=r.left;a<r.right;a++){if(r.top>0&&t[i]==t[i-n]||r.bottom<e&&t[o]==t[o+n])return!0;i++,o++}return!1}function Nv(n,e){let t=n.selection;if(!(t instanceof Se)||t.$anchorCell.pos==t.$headCell.pos)return!1;let r=Xn(n),{map:i}=r;if(I5(i,r))return!1;if(e){let s=n.tr,o={},l=W.empty,a,c;for(let u=r.top;u<r.bottom;u++)for(let d=r.left;d<r.right;d++){let f=i.map[u*i.width+d],h=r.table.nodeAt(f);if(!o[f])if(o[f]=!0,a==null)a=f,c=h;else{_v(h)||(l=l.append(h.content));let p=s.mapping.map(f+r.tableStart);s.delete(p,p+h.nodeSize)}}if(s.setNodeMarkup(a+r.tableStart,null,wt(wv(c.attrs,c.attrs.colspan,r.right-r.left-c.attrs.colspan),"rowspan",r.bottom-r.top)),l.size){let u=a+1+c.content.size,d=_v(c)?a+1:u;s.replaceWith(d+r.tableStart,u+r.tableStart,l)}s.setSelection(new Se(s.doc.resolve(a+r.tableStart))),e(s)}return!0}function Dv(n,e){const t=Mt(n.schema);return P5(({node:r})=>t[r.type.spec.tableRole])(n,e)}function P5(n){return(e,t)=>{let r=e.selection,i,s;if(r instanceof Se){if(r.$anchorCell.pos!=r.$headCell.pos)return!1;i=r.$anchorCell.nodeAfter,s=r.$anchorCell.pos}else{if(i=a5(r.$from),!i)return!1;s=Rs(r.$from).pos}if(i.attrs.colspan==1&&i.attrs.rowspan==1)return!1;if(t){let o=i.attrs,l=[],a=o.colwidth;o.rowspan>1&&(o=wt(o,"rowspan",1)),o.colspan>1&&(o=wt(o,"colspan",1));let c=Xn(e),u=e.tr;for(let f=0;f<c.right-c.left;f++)l.push(a?wt(o,"colwidth",a&&a[f]?[a[f]]:null):o);let d;for(let f=c.top;f<c.bottom;f++){let h=c.map.positionAt(f,c.left,c.table);f==c.top&&(h+=i.nodeSize);for(let p=c.left,g=0;p<c.right;p++,g++)p==c.left&&f==c.top||u.insert(d=u.mapping.map(h+c.tableStart,1),n({node:i,row:f,col:p}).createAndFill(l[g]))}u.setNodeMarkup(s,n({node:i,row:c.top,col:c.left}),l[0]),r instanceof Se&&u.setSelection(new Se(u.doc.resolve(r.$anchorCell.pos),d&&u.doc.resolve(d))),t(u)}return!0}}function F5(n,e){return function(t,r){if(!Tn(t))return!1;let i=Ec(t);if(i.nodeAfter.attrs[n]===e)return!1;if(r){let s=t.tr;t.selection instanceof Se?t.selection.forEachCell((o,l)=>{o.attrs[n]!==e&&s.setNodeMarkup(l,null,wt(o.attrs,n,e))}):s.setNodeMarkup(i.pos,null,wt(i.nodeAfter.attrs,n,e)),r(s)}return!0}}function B5(n){return function(e,t){if(!Tn(e))return!1;if(t){let r=Mt(e.schema),i=Xn(e),s=e.tr,o=i.map.cellsInRect(n=="column"?new Ds(i.left,0,i.right,i.map.height):n=="row"?new Ds(0,i.top,i.map.width,i.bottom):i),l=o.map(a=>i.table.nodeAt(a));for(let a=0;a<o.length;a++)l[a].type==r.header_cell&&s.setNodeMarkup(i.tableStart+o[a],r.cell,l[a].attrs);if(s.steps.length==0)for(let a=0;a<o.length;a++)s.setNodeMarkup(i.tableStart+o[a],r.header_cell,l[a].attrs);t(s)}return!0}}function Rv(n,e,t){const r=e.map.cellsInRect({left:0,top:0,right:n=="row"?e.map.width:1,bottom:n=="column"?e.map.height:1});for(let i=0;i<r.length;i++){const s=e.table.nodeAt(r[i]);if(s&&s.type!==t.header_cell)return!1}return!0}function Zo(n,e){return e=e||{useDeprecatedLogic:!1},e.useDeprecatedLogic?B5(n):function(t,r){if(!Tn(t))return!1;if(r){let i=Mt(t.schema),s=Xn(t),o=t.tr,l=Rv("row",s,i),a=Rv("column",s,i),u=(n==="column"?l:n==="row"?a:!1)?1:0,d=n=="column"?new Ds(0,u,1,s.map.height):n=="row"?new Ds(u,0,s.map.width,1):s,f=n=="column"?a?i.cell:i.header_cell:n=="row"?l?i.cell:i.header_cell:i.cell;s.map.cellsInRect(d).forEach(h=>{const p=h+s.tableStart,g=o.doc.nodeAt(p);g&&o.setNodeMarkup(p,f,g.attrs)}),r(o)}return!0}}Zo("row",{useDeprecatedLogic:!0}),Zo("column",{useDeprecatedLogic:!0});let $5=Zo("cell",{useDeprecatedLogic:!0});function j5(n,e){if(e<0){let t=n.nodeBefore;if(t)return n.pos-t.nodeSize;for(let r=n.index(-1)-1,i=n.before();r>=0;r--){let s=n.node(-1).child(r);if(s.childCount)return i-1-s.lastChild.nodeSize;i-=s.nodeSize}}else{if(n.index()<n.parent.childCount-1)return n.pos+n.nodeAfter.nodeSize;let t=n.node(-1);for(let r=n.indexAfter(-1),i=n.after();r<t.childCount;r++){let s=t.child(r);if(s.childCount)return i+1;i+=s.nodeSize}}}function Lv(n){return function(e,t){if(!Tn(e))return!1;let r=j5(Ec(e),n);if(r!=null){if(t){let i=e.doc.resolve(r);t(e.tr.setSelection(ce.between(i,u5(i))).scrollIntoView())}return!0}}}function H5(n,e){let t=n.selection.$anchor;for(let r=t.depth;r>0;r--)if(t.node(r).type.spec.tableRole=="table")return e&&e(n.tr.delete(t.before(r),t.after(r)).scrollIntoView()),!0;return!1}let V5=class{constructor(e,t){this.node=e,this.cellMinWidth=t,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.colgroup=this.table.appendChild(document.createElement("colgroup")),ph(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type!=this.node.type?!1:(this.node=e,ph(e,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(e){return e.type=="attributes"&&(e.target==this.table||this.colgroup.contains(e.target))}};function ph(n,e,t,r,i,s){let o=0,l=!0,a=e.firstChild,c=n.firstChild;for(let u=0,d=0;u<c.childCount;u++){let{colspan:f,colwidth:h}=c.child(u).attrs;for(let p=0;p<f;p++,d++){let g=i==d?s:h&&h[p],v=g?g+"px":"";o+=g||r,g||(l=!1),a?(a.style.width!=v&&(a.style.width=v),a=a.nextSibling):e.appendChild(document.createElement("col")).style.width=v}}for(;a;){let u=a.nextSibling;a.parentNode.removeChild(a),a=u}l?(t.style.width=o+"px",t.style.minWidth=""):(t.style.width="",t.style.minWidth=o+"px")}const mn=new We("tableColumnResizing");function z5({handleWidth:n=5,cellMinWidth:e=25,View:t=V5,lastColumnResizable:r=!0}={}){return new je({key:mn,state:{init(s,o){return this.spec.props.nodeViews[Mt(o.schema).table.name]=(l,a)=>new t(l,e,a),new Xo(-1,!1)},apply(s,o){return o.apply(s)}},props:{attributes(s){return mn.getState(s).activeHandle>-1?{class:"resize-cursor"}:null},handleDOMEvents:{mousemove(s,o){U5(s,o,n,e,r)},mouseleave(s){W5(s)},mousedown(s,o){q5(s,o,e)}},decorations(s){let o=mn.getState(s);if(o.activeHandle>-1)return X5(s,o.activeHandle)},nodeViews:{}}})}class Xo{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){let t=this,r=e.getMeta(mn);if(r&&r.setHandle!=null)return new Xo(r.setHandle,null);if(r&&r.setDragging!==void 0)return new Xo(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);ch(e.doc.resolve(i))||(i=null),t=new Xo(i,t.dragging)}return t}}function U5(n,e,t,r,i){let s=mn.getState(n.state);if(!s.dragging){let o=J5(e.target),l=-1;if(o){let{left:a,right:c}=o.getBoundingClientRect();e.clientX-a<=t?l=Iv(n,e,"left"):c-e.clientX<=t&&(l=Iv(n,e,"right"))}if(l!=s.activeHandle){if(!i&&l!==-1){let a=n.state.doc.resolve(l),c=a.node(-1),u=et.get(c),d=a.start(-1);if(u.colCount(a.pos-d)+a.nodeAfter.attrs.colspan-1==u.width-1)return}Fv(n,l)}}}function W5(n){let e=mn.getState(n.state);e.activeHandle>-1&&!e.dragging&&Fv(n,-1)}function q5(n,e,t){let r=mn.getState(n.state);if(r.activeHandle==-1||r.dragging)return!1;let i=n.state.doc.nodeAt(r.activeHandle),s=K5(n,r.activeHandle,i.attrs);n.dispatch(n.state.tr.setMeta(mn,{setDragging:{startX:e.clientX,startWidth:s}}));function o(a){window.removeEventListener("mouseup",o),window.removeEventListener("mousemove",l);let c=mn.getState(n.state);c.dragging&&(G5(n,c.activeHandle,Pv(c.dragging,a,t)),n.dispatch(n.state.tr.setMeta(mn,{setDragging:null})))}function l(a){if(!a.which)return o(a);let c=mn.getState(n.state),u=Pv(c.dragging,a,t);Y5(n,c.activeHandle,u,t)}return window.addEventListener("mouseup",o),window.addEventListener("mousemove",l),e.preventDefault(),!0}function K5(n,e,{colspan:t,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let s=n.domAtPos(e),l=s.node.childNodes[s.offset].offsetWidth,a=t;if(r)for(let c=0;c<t;c++)r[c]&&(l-=r[c],a--);return l/a}function J5(n){for(;n&&n.nodeName!="TD"&&n.nodeName!="TH";)n=n.classList.contains("ProseMirror")?null:n.parentNode;return n}function Iv(n,e,t){let r=n.posAtCoords({left:e.clientX,top:e.clientY});if(!r)return-1;let{pos:i}=r,s=Rs(n.state.doc.resolve(i));if(!s)return-1;if(t=="right")return s.pos;let o=et.get(s.node(-1)),l=s.start(-1),a=o.map.indexOf(s.pos-l);return a%o.width==0?-1:l+o.map[a-1]}function Pv(n,e,t){let r=e.clientX-n.startX;return Math.max(t,n.startWidth+r)}function Fv(n,e){n.dispatch(n.state.tr.setMeta(mn,{setHandle:e}))}function G5(n,e,t){let r=n.state.doc.resolve(e),i=r.node(-1),s=et.get(i),o=r.start(-1),l=s.colCount(r.pos-o)+r.nodeAfter.attrs.colspan-1,a=n.state.tr;for(let c=0;c<s.height;c++){let u=c*s.width+l;if(c&&s.map[u]==s.map[u-s.width])continue;let d=s.map[u],{attrs:f}=i.nodeAt(d),h=f.colspan==1?0:l-s.colCount(d);if(f.colwidth&&f.colwidth[h]==t)continue;let p=f.colwidth?f.colwidth.slice():Z5(f.colspan);p[h]=t,a.setNodeMarkup(o+d,null,wt(f,"colwidth",p))}a.docChanged&&n.dispatch(a)}function Y5(n,e,t,r){let i=n.state.doc.resolve(e),s=i.node(-1),o=i.start(-1),l=et.get(s).colCount(i.pos-o)+i.nodeAfter.attrs.colspan-1,a=n.domAtPos(i.start(-1)).node;for(;a.nodeName!="TABLE";)a=a.parentNode;ph(s,a.firstChild,a,r,l,t)}function Z5(n){let e=[];for(let t=0;t<n;t++)e.push(0);return e}function X5(n,e){let t=[],r=n.doc.resolve(e),i=r.node(-1),s=et.get(i),o=r.start(-1),l=s.colCount(r.pos-o)+r.nodeAfter.attrs.colspan;for(let a=0;a<s.height;a++){let c=l+a*s.width-1;if((l==s.width||s.map[c]!=s.map[c+1])&&(a==0||s.map[c-1]!=s.map[c-1-s.width])){let u=s.map[c],d=o+u+i.nodeAt(u).nodeSize-1,f=document.createElement("div");f.className="column-resize-handle",t.push(ut.widget(d,f))}}return He.create(n.doc,t)}function Q5({allowTableNodeSelection:n=!1}={}){return new je({key:Gr,state:{init(){return null},apply(e,t){let r=e.getMeta(Gr);if(r!=null)return r==-1?null:r;if(t==null||!e.docChanged)return t;let{deleted:i,pos:s}=e.mapping.mapResult(t);return i?null:s}},props:{decorations:f5,handleDOMEvents:{mousedown:k5},createSelectionBetween(e){if(Gr.getState(e.state)!=null)return e.state.selection},handleTripleClick:x5,handleKeyDown:w5,handlePaste:C5},appendTransaction(e,t,r){return m5(r,Av(r,t),n)}})}function Bv(n,e,t,r,i,s){var u;let o=0,l=!0,a=e.firstChild;const c=n.firstChild;if(c)for(let d=0,f=0;d<c.childCount;d+=1){const{colspan:h,colwidth:p}=c.child(d).attrs;for(let g=0;g<h;g+=1,f+=1){const v=i===f?s:p&&p[g],w=v?`${v}px`:"";o+=v||r,v||(l=!1),a?(a.style.width!==w&&(a.style.width=w),a=a.nextSibling):e.appendChild(document.createElement("col")).style.width=w}}for(;a;){const d=a.nextSibling;(u=a==null?void 0:a.parentNode)==null||u.removeChild(a),a=d}l?(t.style.width=`${o}px`,t.style.minWidth=""):(t.style.width="",t.style.minWidth=`${o}px`)}class eL{constructor(e,t){vr(this,"node");vr(this,"cellMinWidth");vr(this,"dom");vr(this,"table");vr(this,"colgroup");vr(this,"contentDOM");this.node=e,this.cellMinWidth=t,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Bv(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type!==this.node.type?!1:(this.node=e,Bv(e,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(e){return e.type==="attributes"&&(e.target===this.table||this.colgroup.contains(e.target))}}function $v(n,e){return n.createAndFill()}function tL(n){if(n.cached.tableNodeTypes)return n.cached.tableNodeTypes;const e={};return Object.keys(n.nodes).forEach(t=>{const r=n.nodes[t];r.spec.tableRole&&(e[r.spec.tableRole]=r)}),n.cached.tableNodeTypes=e,e}function nL(n,e,t,r,i){const s=tL(n),o=[],l=[];for(let c=0;c<t;c+=1){const u=$v(s.cell);if(u&&l.push(u),r){const d=$v(s.header_cell);d&&o.push(d)}}const a=[];for(let c=0;c<e;c+=1)a.push(s.row.createChecked(null,r&&c===0?o:l));return s.table.createChecked(null,a)}function rL(n){return n instanceof Se}const _c=({editor:n})=>{const{selection:e}=n.state;if(!rL(e))return!1;let t=0;const r=Ru(e.ranges[0].$from,s=>s.type.name==="table");return r==null||r.node.descendants(s=>{if(s.type.name==="table")return!1;["tableCell","tableHeader"].includes(s.type.name)&&(t+=1)}),t===e.ranges.length?(n.commands.deleteTable(),!0):!1},iL=Ve.create({name:"table",addOptions(){return{HTMLAttributes:{},resizable:!1,handleWidth:5,cellMinWidth:25,View:eL,lastColumnResizable:!0,allowTableNodeSelection:!1}},content:"tableRow+",tableRole:"table",isolating:!0,group:"block",parseHTML(){return[{tag:"table"}]},renderHTML({node:n,HTMLAttributes:e}){let t=0,r=!0;try{n.content.firstChild.content.forEach(s=>{if(s.attrs.colwidth)s.attrs.colwidth.forEach(o=>{o?t+=o:(r=!1,t+=this.options.cellMinWidth)});else{r=!1;const o=s.attrs.colspan?s.attrs.colspan:1;t+=this.options.cellMinWidth*o}})}catch{r=!1}return r&&t>0?e.style=`width: ${t}px;`:t&&t>0?e.style=`min-width: ${t}px`:e.style=null,["div",{class:"table-wrapper"},["table",xe(this.options.HTMLAttributes,e),["tbody",0]]]},addCommands(){return{insertTable:({rows:n=3,cols:e=3,withHeaderRow:t=!0}={})=>({tr:r,dispatch:i,editor:s})=>{const{selection:o}=r,l=nL(s.schema,n,e,t);if(i){const a=r.selection.anchor+1;r.replaceRangeWith(o.from-1,o.to,l).scrollIntoView().setSelection(ce.near(r.doc.resolve(a)))}return!0},addColumnBefore:()=>({state:n,dispatch:e})=>T5(n,e),addColumnAfter:()=>({state:n,dispatch:e})=>A5(n,e),deleteColumn:()=>({state:n,dispatch:e})=>O5(n,e),addRowBefore:()=>({state:n,dispatch:e})=>N5(n,e),addRowAfter:()=>({state:n,dispatch:e})=>D5(n,e),deleteRow:()=>({state:n,dispatch:e})=>L5(n,e),deleteTable:()=>({state:n,dispatch:e})=>H5(n,e),mergeCells:()=>({state:n,dispatch:e})=>Nv(n,e),splitCell:()=>({state:n,dispatch:e})=>Dv(n,e),toggleHeaderColumn:()=>({state:n,dispatch:e})=>Zo("column")(n,e),toggleHeaderRow:()=>({state:n,dispatch:e})=>Zo("row")(n,e),toggleHeaderCell:()=>({state:n,dispatch:e})=>$5(n,e),mergeOrSplit:()=>({state:n,dispatch:e})=>Nv(n,e)?!0:Dv(n,e),setCellAttribute:(n,e)=>({state:t,dispatch:r})=>F5(n,e)(t,r),goToNextCell:()=>({state:n,dispatch:e})=>Lv(1)(n,e),goToPreviousCell:()=>({state:n,dispatch:e})=>Lv(-1)(n,e),fixTables:()=>({state:n,dispatch:e})=>(e&&Av(n),!0),setCellSelection:n=>({tr:e,dispatch:t})=>{if(t){const r=Se.create(e.doc,n.anchorCell,n.headCell);e.setSelection(r)}return!0}}},addKeyboardShortcuts(){return{Tab:()=>this.editor.commands.goToNextCell()?!0:this.editor.can().addRowAfter()?this.editor.chain().addRowAfter().goToNextCell().run():!1,"Shift-Tab":()=>this.editor.commands.goToPreviousCell(),Backspace:_c,"Mod-Backspace":_c,Delete:_c,"Mod-Delete":_c}},addProseMirrorPlugins(){return[...this.options.resizable&&this.editor.isEditable?[z5({handleWidth:this.options.handleWidth,cellMinWidth:this.options.cellMinWidth,View:this.options.View,lastColumnResizable:this.options.lastColumnResizable})]:[],Q5({allowTableNodeSelection:this.options.allowTableNodeSelection})]},extendNodeSchema(n){const e={name:n.name,options:n.options,storage:n.storage};return{tableRole:ge(re(n,"tableRole",e))}}});function jv(n,e){if(n==null)return{};var t={},r=Object.keys(n),i,s;for(s=0;s<r.length;s++)i=r[s],!(e.indexOf(i)>=0)&&(t[i]=n[i]);return t}var Hv=typeof window<"u"&&typeof document<"u";function mh(n,e){n&&(typeof n=="function"&&n(e),{}.hasOwnProperty.call(n,"current")&&(n.current=e))}function Vv(){return Hv&&document.createElement("div")}function sL(n){var e={"data-placement":n.placement};return n.referenceHidden&&(e["data-reference-hidden"]=""),n.escaped&&(e["data-escaped"]=""),e}function zv(n,e){if(n===e)return!0;if(typeof n=="object"&&n!=null&&typeof e=="object"&&e!=null){if(Object.keys(n).length!==Object.keys(e).length)return!1;for(var t in n)if(e.hasOwnProperty(t)){if(!zv(n[t],e[t]))return!1}else return!1;return!0}else return!1}function oL(n){var e=[];return n.forEach(function(t){e.find(function(r){return zv(t,r)})||e.push(t)}),e}function lL(n,e){var t,r;return Object.assign({},e,{popperOptions:Object.assign({},n.popperOptions,e.popperOptions,{modifiers:oL([].concat(((t=n.popperOptions)==null?void 0:t.modifiers)||[],((r=e.popperOptions)==null?void 0:r.modifiers)||[]))})})}var gh=Hv?O.useLayoutEffect:O.useEffect;function aL(n){var e=O.useRef();return e.current||(e.current=typeof n=="function"?n():n),e.current}function Uv(n,e,t){t.split(/\s+/).forEach(function(r){r&&n.classList[e](r)})}var cL={name:"className",defaultValue:"",fn:function(e){var t=e.popper.firstElementChild,r=function(){var l;return!!((l=e.props.render)!=null&&l.$$tippy)};function i(){if(e.props.className&&!r()){process.env.NODE_ENV!=="production"&&console.warn(["@tippyjs/react: Cannot use `className` prop in conjunction with","`render` prop. Place the className on the element you are","rendering."].join(" "));return}Uv(t,"add",e.props.className)}function s(){r()&&Uv(t,"remove",e.props.className)}return{onCreate:i,onBeforeUpdate:s,onAfterUpdate:i}}};function uL(n){function e(t){var r=t.children,i=t.content,s=t.visible,o=t.singleton,l=t.render,a=t.reference,c=t.disabled,u=c===void 0?!1:c,d=t.ignoreAttributes,f=d===void 0?!0:d;t.__source,t.__self;var h=jv(t,["children","content","visible","singleton","render","reference","disabled","ignoreAttributes","__source","__self"]),p=s!==void 0,g=o!==void 0,v=O.useState(!1),w=v[0],S=v[1],x=O.useState({}),y=x[0],k=x[1],E=O.useState(),T=E[0],N=E[1],_=aL(function(){return{container:Vv(),renders:1}}),A=Object.assign({ignoreAttributes:f},h,{content:_.container});p&&(process.env.NODE_ENV!=="production"&&["trigger","hideOnClick","showOnCreate"].forEach(function(V){A[V]!==void 0&&console.warn(["@tippyjs/react: Cannot specify `"+V+"` prop in","controlled mode (`visible` prop)"].join(" "))}),A.trigger="manual",A.hideOnClick=!1),g&&(u=!0);var R=A,P=A.plugins||[];l&&(R=Object.assign({},A,{plugins:g&&o.data!=null?[].concat(P,[{fn:function(){return{onTrigger:function(J,G){var ie=o.data.children.find(function(X){var we=X.instance;return we.reference===G.currentTarget});J.state.$$activeSingletonInstance=ie.instance,N(ie.content)}}}}]):P,render:function(){return{popper:_.container}}}));var $=[a].concat(r?[r.type]:[]);return gh(function(){var V=a;a&&a.hasOwnProperty("current")&&(V=a.current);var U=n(V||_.ref||Vv(),Object.assign({},R,{plugins:[cL].concat(A.plugins||[])}));return _.instance=U,u&&U.disable(),s&&U.show(),g&&o.hook({instance:U,content:i,props:R,setSingletonContent:N}),S(!0),function(){U.destroy(),o==null||o.cleanup(U)}},$),gh(function(){var V;if(_.renders===1){_.renders++;return}var U=_.instance;U.setProps(lL(U.props,R)),(V=U.popperInstance)==null||V.forceUpdate(),u?U.disable():U.enable(),p&&(s?U.show():U.hide()),g&&o.hook({instance:U,content:i,props:R,setSingletonContent:N})}),gh(function(){var V;if(l){var U=_.instance;U.setProps({popperOptions:Object.assign({},U.props.popperOptions,{modifiers:[].concat((((V=U.props.popperOptions)==null?void 0:V.modifiers)||[]).filter(function(J){var G=J.name;return G!=="$$tippyReact"}),[{name:"$$tippyReact",enabled:!0,phase:"beforeWrite",requires:["computeStyles"],fn:function(G){var ie,X=G.state,we=(ie=X.modifiersData)==null?void 0:ie.hide;(y.placement!==X.placement||y.referenceHidden!==(we==null?void 0:we.isReferenceHidden)||y.escaped!==(we==null?void 0:we.hasPopperEscaped))&&k({placement:X.placement,referenceHidden:we==null?void 0:we.isReferenceHidden,escaped:we==null?void 0:we.hasPopperEscaped}),X.attributes.popper={}}}])})})}},[y.placement,y.referenceHidden,y.escaped].concat($)),O.createElement(O.Fragment,null,r?O.cloneElement(r,{ref:function(U){_.ref=U,mh(r.ref,U)}}):null,w&&nn.createPortal(l?l(sL(y),T,_.instance):i,_.container))}return e}var dL=function(n,e){return O.forwardRef(function(r,i){var s=r.children,o=jv(r,["children"]);return O.createElement(n,Object.assign({},e,o),s?O.cloneElement(s,{ref:function(a){mh(i,a),mh(s.ref,a)}}):null)})},fL=dL(uL(fi));const hL=[{name:"Add row above",action:n=>n.chain().focus().addRowBefore().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M22 14a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v7h2v-2h4v2h2v-2h4v2h2v-2h4v2h2v-7M4 14h4v3H4v-3m6 0h4v3h-4v-3m10 0v3h-4v-3h4m-9-4h2V7h3V5h-3V2h-2v3H8v2h3v3Z"})})},{name:"Add row below",action:n=>n.chain().focus().addRowAfter().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M22 10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V3h2v2h4V3h2v2h4V3h2v2h4V3h2v7M4 10h4V7H4v3m6 0h4V7h-4v3m10 0V7h-4v3h4m-9 4h2v3h3v2h-3v3h-2v-3H8v-2h3v-3Z"})})},{name:"Add left column",action:n=>n.chain().focus().addColumnBefore().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M13 2a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h9V2h-9m7 8v4h-7v-4h7m0 6v4h-7v-4h7m0-12v4h-7V4h7M9 11H6V8H4v3H1v2h3v3h2v-3h3v-2Z"})})},{name:"Add right column",action:n=>n.chain().focus().addColumnAfter().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M11 2a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H2V2h9m-7 8v4h7v-4H4m0 6v4h7v-4H4M4 4v4h7V4H4m11 7h3V8h2v3h3v2h-3v3h-2v-3h-3v-2Z"})})},{name:"Remove row",action:n=>n.chain().focus().deleteRow().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M9.41 13L12 15.59L14.59 13L16 14.41L13.41 17L16 19.59L14.59 21L12 18.41L9.41 21L8 19.59L10.59 17L8 14.41L9.41 13M22 9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v3M4 9h4V6H4v3m6 0h4V6h-4v3m6 0h4V6h-4v3Z"})})},{name:"Remove column",action:n=>n.chain().focus().deleteColumn().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M4 2h7a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2m0 8v4h7v-4H4m0 6v4h7v-4H4M4 4v4h7V4H4m13.59 8L15 9.41L16.41 8L19 10.59L21.59 8L23 9.41L20.41 12L23 14.59L21.59 16L19 13.41L16.41 16L15 14.59L17.59 12Z"})})},{name:"Toggle header row",action:n=>n.chain().focus().toggleHeaderRow().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M22 14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-4a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v4M4 14h4v-4H4v4m6 0h4v-4h-4v4m6 0h4v-4h-4v4Z"})})},{name:"Toggle header column",action:n=>n.chain().focus().toggleHeaderColumn().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M8 2h8a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2m0 8v4h8v-4H8m0 6v4h8v-4H8M8 4v4h8V4H8Z"})})},{name:"Toggle header cell",action:n=>n.chain().focus().toggleHeaderCell().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M21 19a1 1 0 0 1-1 1h-1v-2h2v1m-6 1v-2h2v2h-2m-4 0v-2h2v2h-2m-4 0v-2h2v2H7m-3 0a1 1 0 0 1-1-1v-1h2v2H4M19 4H5a2 2 0 0 0-2 2v2h18V6c0-1.11-.89-2-2-2M5 14H3v2h2v-2m0-4H3v2h2v-2m16 0h-2v2h2v-2m0 4h-2v2h2v-2m-10 2v-2h2v2h-2m0-4v-2h2v2h-2"})})},{name:"Remove table",action:n=>n.chain().focus().deleteTable().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M12.35 20H10v-3h2.09c.12-.72.37-1.39.72-2H10v-3h4v1.54c.58-.54 1.25-.93 2-1.19V12h4v.35c.75.26 1.42.65 2 1.19V5c0-1.1-.9-2-2-2H4c-1.1 0-2 .9-2 2v15c0 1.1.9 2 2 2h9.54c-.54-.58-.93-1.25-1.19-2M16 7h4v3h-4V7m-6 0h4v3h-4V7M8 20H4v-3h4v3m0-5H4v-3h4v3m0-5H4V7h4v3m6.46 5.88l1.42-1.42L18 16.59l2.12-2.13l1.42 1.42L19.41 18l2.13 2.12l-1.42 1.42L18 19.41l-2.12 2.13l-1.42-1.42L16.59 18l-2.13-2.12"})})}],Wv=({node:n,getPos:e,selected:t,editor:r})=>{const[i,s]=O.useState(!1),o=Ul(),l=O.useRef(null),a=()=>{const{from:u,to:d}=r.state.selection,f=e(),h=f+n.nodeSize;s(f<=u&&d<=h)};O.useEffect(()=>(r.on("selectionUpdate",a),setTimeout(a,100),()=>{r.off("selectionUpdate",a)}));const c=()=>{var f,h;let u=(f=l.current)==null?void 0:f.clientTop;u&&(u+=5);let d=(h=l.current)==null?void 0:h.clientLeft;return d&&(d+=5),{top:`${u}px`,left:`${d}px`}};return D.jsxs(bo,{className:"group",children:[D.jsx(Kg,{as:"span"}),(i||t)&&D.jsx(fL,{appendTo:document.body,trigger:"click",interactive:!0,animation:"shift-toward-subtle",placement:"right-start",content:D.jsx("article",{className:"dropdown",contentEditable:!1,children:D.jsx("ul",{tabIndex:0,className:"dropdown-content fixed menu menu-compact p-2 shadow bg-base-100 rounded-box w-56",style:c(),children:hL.map(u=>D.jsx("li",{children:D.jsxs("button",{type:"button",className:"button",onClick:()=>u.action(r),children:[D.jsx("span",{children:u.icon}),D.jsx("span",{children:u.name})]})},u.name))})}),children:D.jsx("label",{tabIndex:0,className:Fe("trigger-button",{hidden:o}),contentEditable:!1,children:D.jsx(GE,{fontSize:"small"})})})]})},pL=Ve.create({name:"tableCell",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:n=>{const e=n.getAttribute("colwidth");return e?[parseInt(e,10)]:null}}}},tableRole:"cell",isolating:!0,parseHTML(){return[{tag:"td"}]},renderHTML({HTMLAttributes:n}){return["td",xe(this.options.HTMLAttributes,n),0]},addNodeView(){return hi(Wv,{as:"td",className:"relative"})}}),mL=Ve.create({name:"tableHeader",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:n=>{const e=n.getAttribute("colwidth");return e?[parseInt(e,10)]:null}}}},tableRole:"header_cell",isolating:!0,parseHTML(){return[{tag:"th"}]},renderHTML({HTMLAttributes:n}){return["th",xe(this.options.HTMLAttributes,n),0]},addNodeView(){return hi(Wv,{as:"th",className:"relative"})}}),qv=n=>(n.stopPropagation(),n.preventDefault(),n),gL=function(n){const e=n.scrollHeight>n.clientHeight,r=window.getComputedStyle(n).overflowY.indexOf("hidden")!==-1;return e&&!r},Kv=function(n){return!n||n===document.body?document.body:gL(n)?n:Kv(n.parentNode)},yh=(n,e,t)=>{const r=document.createElement(n);if(!r)throw new Error(`Element with name ${n} can't be created.`);return e&&Object.entries(e).forEach(([i,s])=>r.setAttribute(i,s)),t&&Object.entries(t).forEach(([i,s])=>r.addEventListener(i,s)),r},yL=Ve.create({name:"tableRow",addOptions(){return{HTMLAttributes:{}}},content:"(tableCell | tableHeader)*",tableRole:"row",parseHTML(){return[{tag:"tr"}]},renderHTML({HTMLAttributes:n}){return["tr",xe(this.options.HTMLAttributes,n),0]},addNodeView(){return({editor:n,HTMLAttributes:e,getPos:t})=>{const r=()=>t(),i=Kv(n.options.element);let s=!1;const o={deleteRow:()=>{this.editor.chain().deleteNode("tableRow").focus().run()},selectRow:()=>{const w=r(),S=n.state.doc.resolve(w),x=new se(S);n.view.dispatch(n.state.tr.setSelection(x))}},l=()=>{s=!0},a=()=>{s=!1},c=yh("section",{class:"absolute hidden flex items-center w-2 bg-gray-200 z-50 cursor-pointer border-1 border-indigo-600 rounded-l opacity-25 hover:opacity-100",contenteditable:"false"},{click:w=>{w&&qv(w),o.selectRow()},mouseenter:()=>{l()},mouseover:()=>{l()},mouseleave:()=>{a(),f()}}),u=yh("button",{class:"text-sm px-1 absolute -translate-x-[125%] hover:active:-translate-x-[125%] mr-2"},{click:w=>{w&&qv(w),o.deleteRow()}}),d=()=>{g(),c.classList.remove("hidden")},f=()=>{setTimeout(()=>{s||c.classList.add("hidden")},100)},h=yh("tr",{...e},{mouseenter:d,mouseover:d,mouseleave:f});c.append(u),document.body.append(c);let p="";const g=()=>{setTimeout(()=>{const w=h.getBoundingClientRect(),S=JSON.stringify(w);p!==S&&(c.style.top=`${w.top+document.documentElement.scrollTop}px`,c.style.left=`${w.x+document.documentElement.scrollLeft-8}px`,c.style.height=`${w.height+1}px`,p=S)})};return setTimeout(()=>{g()},100),n.on("selectionUpdate",g),n.on("update",g),i==null||i.addEventListener("scroll",g),document.addEventListener("scroll",g),{dom:h,contentDOM:h,destroy:()=>{c.remove(),n.off("selectionUpdate",g),n.off("update",g),i==null||i.removeEventListener("scroll",g),document.removeEventListener("scroll",g)}}}}}),bL=[iL.configure({resizable:!0}),pL,mL,yL],vL=Hb.extend({content:"(dBlock|columns)+"});function Jv({types:n,node:e}){return e!=null&&e.type?Array.isArray(n)&&n.includes(e.type)||e.type===n:!1}const wL=Ue.create({name:"trailingNode",addOptions(){return{node:"paragraph",notAfter:["paragraph"]}},addProseMirrorPlugins(){const n=new We(this.name),e=Object.entries(this.editor.schema.nodes).map(([,t])=>t).filter(t=>this.options.notAfter.includes(t.name));return[new je({key:n,appendTransaction:(t,r,i)=>{const{doc:s,tr:o,schema:l}=i,a=n.getState(i),c=s.content.size,u=l.nodes[this.options.node];if(a)return o.insert(c,u.create())},state:{init:(t,r)=>{const i=r.tr.doc.lastChild;return!Jv({node:i,types:e})},apply:(t,r)=>{var s,o,l;if(!t.docChanged)return r;const i=(l=(o=(s=t.doc.lastChild)==null?void 0:s.content)==null?void 0:o.content)==null?void 0:l[0];return!Jv({node:i,types:e})}}})]}}),xL=({node:n,editor:e,getPos:t})=>{const[r,i]=O.useState(""),s=Ul(),o=["https://twitter.com","https://x.com"],l=()=>{switch(n.attrs.data){case"twitter":return D.jsx(f0,{});case"iframe":return D.jsx(h0,{});default:return D.jsx(aT,{})}},a=()=>{switch(n.attrs.data){case"twitter":return"Embed a Twitter tweet";case"iframe":return"Embed a video";default:return"Embed an URL"}},c=()=>{if(!r){alert("Please enter a url");return}let p=r;if(r.includes("<iframe")){const x=r.match(/src="([^"]*)"/);x&&x.length>0&&(p=x[1])}else switch(!0){case/youtu\.?be(?:\.com)?\/(?:.*v(?:\/|=)|(?:.*\/)?)([a-zA-Z0-9-_]+)/.test(r):{const x=r.match(/youtu\.?be(?:\.com)?\/(?:.*v(?:\/|=)|(?:.*\/)?)([a-zA-Z0-9-_]+)/);x&&x.length>0&&(p=`https://www.youtube.com/embed/${x[1]}`);break}case/vimeo\.com\/([a-zA-Z0-9-_]+)/.test(r):{const x=r.match(/vimeo\.com\/([a-zA-Z0-9-_]+)/);x&&x.length>0&&(p=`https://player.vimeo.com/video/${x[1]}`);break}default:{alert("Please enter a valid url");return}}const g=640,v=360,w=t(),S=w+n.nodeSize;p&&(e==null||e.chain().focus(w).deleteRange({from:w,to:S}).setIframe({src:p,width:g,height:v}).run())},u=()=>{if(!r){alert("Please enter a url");return}let p=r;const g=o.some(y=>r.includes(y)),v=r.match(/\/status\/([0-9]*)/),w=v&&v.length>0;if(g&&w)p=v[1];else{alert("invalid url");return}const S=t(),x=S+n.nodeSize;p&&(e==null||e.chain().focus(S).deleteRange({from:S,to:x}).setTweetEmbed({tweetId:p}).run())},f=y1(()=>{switch(n.attrs.data){case"twitter":u();break;default:c();break}},500);O.useEffect(()=>{r&&f()},[r]),O.useEffect(()=>{e==null||e.chain().focus()},[]);const h=O.useRef(null);return O.useEffect(()=>{var p;(p=h.current)==null||p.focus()},[]),D.jsx(bo,{as:"div",className:"flex gap-2 group w-full relative justify-center items-start",children:!s&&D.jsxs("div",{className:"relative w-full",children:[D.jsx("div",{className:"absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none",children:l()}),D.jsx("input",{ref:h,value:r,placeholder:a(),onChange:p=>i(p.target.value),onClick:p=>p.stopPropagation(),className:"bg-stone-200 p-3 pl-10 rounded-xl w-full hover:bg-stone-300 cursor-pointer transition-all ease-in-out"})]})})},CL=Ve.create({name:"actionButton",group:"block",content:"block*",atom:!0,draggable:!0,addOptions(){return{HTMLAttributes:{class:"rounded-lg bg-stone-500"}}},addAttributes(){return{data:{default:null}}},addNodeView(){return hi(xL)},parseHTML(){return[{tag:"div[data-action-node]"}]},renderHTML({HTMLAttributes:n}){return console.log("action"),["div",xe(n,{"data-action-node":""}),0]},addCommands(){return{setActionButton:n=>({commands:e})=>e.insertContent({type:this.name,attrs:{data:n},content:[]})}}}),kL=[h_,d_.configure({strike:{HTMLAttributes:{class:"select-text pointer-events-auto"}},bold:{HTMLAttributes:{class:"select-text pointer-events-auto"}},italic:{HTMLAttributes:{class:"select-text pointer-events-auto"}},heading:{HTMLAttributes:{class:"select-text pointer-events-auto"}},paragraph:{HTMLAttributes:{class:"select-text pointer-events-auto"}},bulletList:{HTMLAttributes:{class:"flex flex-col items-start list-disc list-outside space-y-4 ml-6"}},orderedList:{HTMLAttributes:{class:"flex flex-col items-start list-decimal list-outside space-y-4 ml-6"}},listItem:{HTMLAttributes:{class:"leading-normal"}},blockquote:{HTMLAttributes:{class:"rounded-lg bg-stone-100 p-5 font-serif italic text-stone-800"}},codeBlock:{HTMLAttributes:{class:"rounded-lg bg-transparent border border-[#DDE2E4] p-5 font-mono font-medium text-stone-800"}},code:{HTMLAttributes:{class:"rounded-md bg-stone-200 p-1.5 font-mono font-medium text-black text-sm",spellcheck:"false"}},history:!1,gapcursor:!1,dropcursor:!1,document:!1,horizontalRule:!1}),p_.configure({types:["heading","paragraph"]}),tN,F_.configure({HTMLAttributes:{class:"text-blue-500 font-bold transition-colors cursor-pointer select-text pointer-events-auto"},openOnClick:!0}),B_.configure({placeholder:()=>"",includeChildren:!0,showOnlyCurrent:!0}),H_.configure({multicolor:!0}),eN,W_.configure({HTMLAttributes:{class:"select-text pointer-events-auto"}}),f_,iN,V_.configure({HTMLAttributes:{class:"not-prose space-y-4 ml-2"}}),U_.configure({HTMLAttributes:{class:"flex items-start"},nested:!0}),Vb.configure({width:3,color:"#d1d5db"}),zb,r5,wL,vL,...bL,hN.configure({uploadFn:AT}),rN,sN,cN,CL.extend({addInputRules(){return[Gv(/^(?:twt|###|___\s|\*\*\*\s)$/,"twitter",this.type),Gv(/^(?:ytb|@@@|___\s|\*\*\*\s)$/,"iframe",this.type)]}}),nN],Gv=(n,e,t)=>new io({find:n,handler:({state:r,range:i,commands:s})=>{const o={data:e},{tr:l}=r,a=i.from,c=i.to;l.insert(a-1,t.create(o)).delete(l.mapping.map(a),l.mapping.map(c)),s.focus(c-1)}}),Yv=["#30bced","#6eeb83","#fa69d1","#ecd444","#ee6352","#db3041","#0ad7f2","#1bff39"],SL=({isPreviewMode:n,data:e,enableCollaboration:t,collaborationId:r})=>{const[i,s]=O.useState({plugin:{title:"Untitled"}}),[o]=O.useState(new as),l=O.useRef(null),a=[...kL,p3.configure({document:o})];O.useEffect(()=>{if(r&&t){const f=new HO(r||"default-room",o,{signaling:["wss://fileverse-signaling-server-0529292ff51c.herokuapp.com/"]});return l.current=f,()=>{f.destroy(),o.destroy()}}},[r,o]),O.useEffect(()=>{t&&r&&(a.some(h=>h.name==="collaborationCursor")||a.push(m3.configure({provider:l.current,user:{color:Yv[Math.floor(Math.random()*Yv.length)]}})))},[l.current]);const c=FE({extensions:a,editorProps:VO,autofocus:"start"}),u=O.useRef(null),d=f=>{var h;(h=u.current)!=null&&h.contains(f.target)||c==null||c.chain().focus().run()};return O.useEffect(()=>{c==null||c.chain().focus()},[]),O.useEffect(()=>{c==null||c.setEditable(!n)},[n]),O.useEffect(()=>{e&&c&&(c==null||c.commands.setContent(e.editorJSONData),s(e.metaData))},[e,c]),{editor:c,pluginMetaData:i,setPluginMetaData:s,focusEditor:d,ref:u}},EL=({isPreviewMode:n=!1,onPublish:e,data:t,togglePreviewMode:r,enableCollaboration:i,collaborationId:s,onAutoSave:o})=>{const{editor:l,pluginMetaData:a,focusEditor:c,setPluginMetaData:u,ref:d}=SL({isPreviewMode:n,data:t,enableCollaboration:i,collaborationId:s,onPublish:e,togglePreviewMode:r});return O.useEffect(()=>{if(l&&o){const f=setInterval(()=>{o({metaData:a,editorJSONData:l.getJSON()})},1e4);return()=>clearInterval(f)}},[l,o,a]),l?D.jsx("div",{"data-cy":"single-webpage",className:"bg-[#f9fbfd]",children:D.jsx("div",{className:"h-full flex flex-col overflow-scroll no-scrollbar",children:D.jsxs("div",{className:"w-full h-screen",children:[D.jsx("div",{className:"h-fit relative bg-[#ffffff]",children:D.jsxs("div",{className:"flex items-center justify-center pl-4 pr-4 border-b-1 border gap-2 h-16",children:[D.jsx("div",{className:"grow",children:D.jsx(iw,{isPreviewMode:n,metaData:a,setMetaData:u})}),!n&&D.jsx("div",{className:"grow relative",children:D.jsx(zT,{editor:l})}),D.jsx("div",{children:D.jsxs(zl,{onClick:()=>r(n),children:[n?D.jsx(nT,{size:14}):D.jsx(sT,{size:14})," ",n?"Edit":"Preview"]})}),e&&D.jsx("div",{children:D.jsxs(zl,{onClick:()=>e({metaData:a,editorJSONData:l.getJSON()}),children:[D.jsx(oT,{size:14})," Share"]})})]})}),D.jsx("main",{className:"h-screen lg:h-full w-full rounded-[8px] flex flex-col justify-start items-center gap-2",children:D.jsx("div",{onClick:c,className:"w-full flex justify-center relative",children:D.jsx("div",{className:"p-12 sm:p-[96px] mt-4 min-h-[900px] shadow-inner bg-white overflow-scroll no-scrollbar rounded-md w-full sm:w-[70%] max-w-[856px]",children:D.jsxs("div",{ref:d,className:"w-full pt-4 h-full",children:[!n&&D.jsxs("div",{children:[D.jsx(LT,{editor:l}),D.jsx(HT,{editor:l,appendTo:d})]}),D.jsx(VT,{isPreviewMode:n,children:D.jsx(IE,{editor:l})})]})})})})]})})}):D.jsxs("div",{className:"w-screen h-screen flex flex-col gap-4 justify-center items-center",children:[D.jsx(N0,{}),D.jsx("p",{children:"Loading Editor..."})]})};Bt.DdocEditor=EL,Object.defineProperty(Bt,Symbol.toStringTag,{value:"Module"})});
|
374
|
+
`).focus(o+1).run():["columns","heading"].includes(l)?n.chain().insertContent({type:"dBlock",content:[{type:"paragraph"}]}).focus().run():n.chain().insertContentAt({from:t,to:o},{type:this.name,content:a}).focus(t+4).run()}catch(u){return console.error(`Error inserting content into dBlock node: ${u}`),!1}}}}});let lh,ah;if(typeof WeakMap<"u"){let n=new WeakMap;lh=e=>n.get(e),ah=(e,t)=>(n.set(e,t),t)}else{let n=[],e=10,t=0;lh=r=>{for(let i=0;i<n.length;i+=2)if(n[i]==r)return n[i+1]},ah=(r,i)=>(t==e&&(t=0),n[t++]=r,n[t++]=i)}class Ds{constructor(e,t,r,i){this.left=e,this.top=t,this.right=r,this.bottom=i}}class et{constructor(e,t,r,i){this.width=e,this.height=t,this.map=r,this.problems=i}findCell(e){for(let t=0;t<this.map.length;t++){let r=this.map[t];if(r!=e)continue;let i=t%this.width,s=t/this.width|0,o=i+1,l=s+1;for(let a=1;o<this.width&&this.map[t+a]==r;a++)o++;for(let a=1;l<this.height&&this.map[t+this.width*a]==r;a++)l++;return new Ds(i,s,o,l)}throw new RangeError("No cell with offset "+e+" found")}colCount(e){for(let t=0;t<this.map.length;t++)if(this.map[t]==e)return t%this.width;throw new RangeError("No cell with offset "+e+" found")}nextCell(e,t,r){let{left:i,right:s,top:o,bottom:l}=this.findCell(e);return t=="horiz"?(r<0?i==0:s==this.width)?null:this.map[o*this.width+(r<0?i-1:s)]:(r<0?o==0:l==this.height)?null:this.map[i+this.width*(r<0?o-1:l)]}rectBetween(e,t){let{left:r,right:i,top:s,bottom:o}=this.findCell(e),{left:l,right:a,top:c,bottom:u}=this.findCell(t);return new Ds(Math.min(r,l),Math.min(s,c),Math.max(i,a),Math.max(o,u))}cellsInRect(e){let t=[],r={};for(let i=e.top;i<e.bottom;i++)for(let s=e.left;s<e.right;s++){let o=i*this.width+s,l=this.map[o];r[l]||(r[l]=!0,(s!=e.left||!s||this.map[o-1]!=l)&&(i!=e.top||!i||this.map[o-this.width]!=l)&&t.push(l))}return t}positionAt(e,t,r){for(let i=0,s=0;;i++){let o=s+r.child(i).nodeSize;if(i==e){let l=t+e*this.width,a=(e+1)*this.width;for(;l<a&&this.map[l]<s;)l++;return l==a?o-1:this.map[l]}s=o}}static get(e){return lh(e)||ah(e,i5(e))}}function i5(n){if(n.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+n.type.name);let e=s5(n),t=n.childCount,r=[],i=0,s=null,o=[];for(let c=0,u=e*t;c<u;c++)r[c]=0;for(let c=0,u=0;c<t;c++){let d=n.child(c);u++;for(let p=0;;p++){for(;i<r.length&&r[i]!=0;)i++;if(p==d.childCount)break;let g=d.child(p),{colspan:v,rowspan:w,colwidth:S}=g.attrs;for(let x=0;x<w;x++){if(x+c>=t){(s||(s=[])).push({type:"overlong_rowspan",pos:u,n:w-x});break}let y=i+x*e;for(let k=0;k<v;k++){r[y+k]==0?r[y+k]=u:(s||(s=[])).push({type:"collision",row:c,pos:u,n:v-k});let E=S&&S[k];if(E){let T=(y+k)%e*2,N=o[T];N==null||N!=E&&o[T+1]==1?(o[T]=E,o[T+1]=1):N==E&&o[T+1]++}}}i+=v,u+=g.nodeSize}let f=(c+1)*e,h=0;for(;i<f;)r[i++]==0&&h++;h&&(s||(s=[])).push({type:"missing",row:c,n:h}),u++}let l=new et(e,t,r,s),a=!1;for(let c=0;!a&&c<o.length;c+=2)o[c]!=null&&o[c+1]<t&&(a=!0);return a&&o5(l,o,n),l}function s5(n){let e=-1,t=!1;for(let r=0;r<n.childCount;r++){let i=n.child(r),s=0;if(t)for(let o=0;o<r;o++){let l=n.child(o);for(let a=0;a<l.childCount;a++){let c=l.child(a);o+c.attrs.rowspan>r&&(s+=c.attrs.colspan)}}for(let o=0;o<i.childCount;o++){let l=i.child(o);s+=l.attrs.colspan,l.attrs.rowspan>1&&(t=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function o5(n,e,t){n.problems||(n.problems=[]);for(let r=0,i={};r<n.map.length;r++){let s=n.map[r];if(i[s])continue;i[s]=!0;let o=t.nodeAt(s),l=null;for(let a=0;a<o.attrs.colspan;a++){let c=(r+a)%n.width,u=e[c*2];u!=null&&(!o.attrs.colwidth||o.attrs.colwidth[a]!=u)&&((l||(l=l5(o.attrs)))[a]=u)}l&&n.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:l})}}function l5(n){if(n.colwidth)return n.colwidth.slice();let e=[];for(let t=0;t<n.colspan;t++)e.push(0);return e}function Mt(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(let t in n.nodes){let r=n.nodes[t],i=r.spec.tableRole;i&&(e[i]=r)}}return e}const Gr=new We("selectingCells");function Rs(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function a5(n){for(let e=n.depth;e>0;e--){const t=n.node(e).type.spec.tableRole;if(t==="cell"||t==="header_cell")return n.node(e)}return null}function Tn(n){let e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function Ec(n){let e=n.selection;return e.$anchorCell?e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell:e.node&&e.node.type.spec.tableRole=="cell"?e.$anchor:Rs(e.$head)||c5(e.$head)}function c5(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){let r=e.type.spec.tableRole;if(r=="cell"||r=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function ch(n){return n.parent.type.spec.tableRole=="row"&&n.nodeAfter}function u5(n){return n.node(0).resolve(n.pos+n.nodeAfter.nodeSize)}function uh(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function vv(n,e,t){let r=n.start(-1),s=et.get(n.node(-1)).nextCell(n.pos-r,e,t);return s==null?null:n.node(0).resolve(r+s)}function wt(n,e,t){let r={};for(let i in n)r[i]=n[i];return r[e]=t,r}function _i(n,e,t=1){let r=wt(n,"colspan",n.colspan-t);return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(e,t),r.colwidth.some(i=>i>0)||(r.colwidth=null)),r}function wv(n,e,t=1){let r=wt(n,"colspan",n.colspan+t);if(r.colwidth){r.colwidth=r.colwidth.slice();for(let i=0;i<t;i++)r.colwidth.splice(e,0,0)}return r}function d5(n,e,t){let r=Mt(e.type.schema).header_cell;for(let i=0;i<n.height;i++)if(e.nodeAt(n.map[t+i*n.width]).type!=r)return!1;return!0}class Se extends ue{constructor(e,t=e){let r=e.node(-1),i=et.get(r),s=e.start(-1),o=i.rectBetween(e.pos-s,t.pos-s),l=e.node(0),a=i.cellsInRect(o).filter(u=>u!=t.pos-s);a.unshift(t.pos-s);let c=a.map(u=>{let d=r.nodeAt(u),f=u+s+1;return new Jc(l.resolve(f),l.resolve(f+d.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=t}map(e,t){let r=e.resolve(t.map(this.$anchorCell.pos)),i=e.resolve(t.map(this.$headCell.pos));if(ch(r)&&ch(i)&&uh(r,i)){let s=this.$anchorCell.node(-1)!=r.node(-1);return s&&this.isRowSelection()?Se.rowSelection(r,i):s&&this.isColSelection()?Se.colSelection(r,i):new Se(r,i)}return ce.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=et.get(e),r=this.$anchorCell.start(-1),i=t.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r),s={},o=[];for(let a=i.top;a<i.bottom;a++){let c=[];for(let u=a*t.width+i.left,d=i.left;d<i.right;d++,u++){let f=t.map[u];if(!s[f]){s[f]=!0;let h=t.findCell(f),p=e.nodeAt(f),g=i.left-h.left,v=h.right-i.right;if(g>0||v>0){let w=p.attrs;g>0&&(w=_i(w,0,g)),v>0&&(w=_i(w,w.colspan-v,v)),h.left<i.left?p=p.type.createAndFill(w):p=p.type.create(w,p.content)}if(h.top<i.top||h.bottom>i.bottom){let w=wt(p.attrs,"rowspan",Math.min(h.bottom,i.bottom)-Math.max(h.top,i.top));h.top<i.top?p=p.type.createAndFill(w):p=p.type.create(w,p.content)}c.push(p)}}o.push(e.child(a).copy(W.from(c)))}const l=this.isColSelection()&&this.isRowSelection()?e:o;return new Y(W.from(l),1,1)}replace(e,t=Y.empty){let r=e.steps.length,i=this.ranges;for(let o=0;o<i.length;o++){let{$from:l,$to:a}=i[o],c=e.mapping.slice(r);e.replace(c.map(l.pos),c.map(a.pos),o?Y.empty:t)}let s=ue.findFrom(e.doc.resolve(e.mapping.slice(r).map(this.to)),-1);s&&e.setSelection(s)}replaceWith(e,t){this.replace(e,new Y(W.from(t),0,0))}forEachCell(e){let t=this.$anchorCell.node(-1),r=et.get(t),i=this.$anchorCell.start(-1),s=r.cellsInRect(r.rectBetween(this.$anchorCell.pos-i,this.$headCell.pos-i));for(let o=0;o<s.length;o++)e(t.nodeAt(s[o]),i+s[o])}isColSelection(){let e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);if(Math.min(e,t)>0)return!1;let r=e+this.$anchorCell.nodeAfter.attrs.rowspan,i=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(r,i)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){let r=et.get(e.node(-1)),i=e.start(-1),s=r.findCell(e.pos-i),o=r.findCell(t.pos-i),l=e.node(0);return s.top<=o.top?(s.top>0&&(e=l.resolve(i+r.map[s.left])),o.bottom<r.height&&(t=l.resolve(i+r.map[r.width*(r.height-1)+o.right-1]))):(o.top>0&&(t=l.resolve(i+r.map[o.left])),s.bottom<r.height&&(e=l.resolve(i+r.map[r.width*(r.height-1)+s.right-1]))),new Se(e,t)}isRowSelection(){let e=et.get(this.$anchorCell.node(-1)),t=this.$anchorCell.start(-1),r=e.colCount(this.$anchorCell.pos-t),i=e.colCount(this.$headCell.pos-t);if(Math.min(r,i)>0)return!1;let s=r+this.$anchorCell.nodeAfter.attrs.colspan,o=i+this.$headCell.nodeAfter.attrs.colspan;return Math.max(s,o)==e.width}eq(e){return e instanceof Se&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){let r=et.get(e.node(-1)),i=e.start(-1),s=r.findCell(e.pos-i),o=r.findCell(t.pos-i),l=e.node(0);return s.left<=o.left?(s.left>0&&(e=l.resolve(i+r.map[s.top*r.width])),o.right<r.width&&(t=l.resolve(i+r.map[r.width*(o.top+1)-1]))):(o.left>0&&(t=l.resolve(i+r.map[o.top*r.width])),s.right<r.width&&(e=l.resolve(i+r.map[r.width*(s.top+1)-1]))),new Se(e,t)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(e,t){return new Se(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){return new Se(e.resolve(t),e.resolve(r))}getBookmark(){return new dh(this.$anchorCell.pos,this.$headCell.pos)}}Se.prototype.visible=!1,ue.jsonID("cell",Se);class dh{constructor(e,t){this.anchor=e,this.head=t}map(e){return new dh(e.map(this.anchor),e.map(this.head))}resolve(e){let t=e.resolve(this.anchor),r=e.resolve(this.head);return t.parent.type.spec.tableRole=="row"&&r.parent.type.spec.tableRole=="row"&&t.index()<t.parent.childCount&&r.index()<r.parent.childCount&&uh(t,r)?new Se(t,r):ue.near(r,1)}}function f5(n){if(!(n.selection instanceof Se))return null;let e=[];return n.selection.forEachCell((t,r)=>{e.push(ut.node(r,r+t.nodeSize,{class:"selectedCell"}))}),He.create(n.doc,e)}function h5({$from:n,$to:e}){if(n.pos==e.pos||n.pos<n.pos-6)return!1;let t=n.pos,r=e.pos,i=n.depth;for(;i>=0&&!(n.after(i+1)<n.end(i));i--,t++);for(let s=e.depth;s>=0&&!(e.before(s+1)>e.start(s));s--,r--);return t==r&&/row|table/.test(n.node(i).type.spec.tableRole)}function p5({$from:n,$to:e}){let t,r;for(let i=n.depth;i>0;i--){let s=n.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){t=s;break}}for(let i=e.depth;i>0;i--){let s=e.node(i);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){r=s;break}}return t!==r&&e.parentOffset===0}function m5(n,e,t){let r=(e||n).selection,i=(e||n).doc,s,o;if(r instanceof se&&(o=r.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=Se.create(i,r.from);else if(o=="row"){let l=i.resolve(r.from+1);s=Se.rowSelection(l,l)}else if(!t){let l=et.get(r.node),a=r.from+1,c=a+l.map[l.width*l.height-1];s=Se.create(i,a+1,c)}}else r instanceof ce&&h5(r)?s=ce.create(i,r.from):r instanceof ce&&p5(r)&&(s=ce.create(i,r.$from.start(),r.$from.end()));return s&&(e||(e=n.tr)).setSelection(s),e}function g5(n){if(!n.size)return null;let{content:e,openStart:t,openEnd:r}=n;for(;e.childCount==1&&(t>0&&r>0||e.firstChild.type.spec.tableRole=="table");)t--,r--,e=e.firstChild.content;let i=e.firstChild,s=i.type.spec.tableRole,o=i.type.schema,l=[];if(s=="row")for(let a=0;a<e.childCount;a++){let c=e.child(a).content,u=a?0:Math.max(0,t-1),d=a<e.childCount-1?0:Math.max(0,r-1);(u||d)&&(c=fh(Mt(o).row,new Y(c,u,d)).content),l.push(c)}else if(s=="cell"||s=="header_cell")l.push(t||r?fh(Mt(o).row,new Y(e,t,r)).content:e);else return null;return y5(o,l)}function y5(n,e){let t=[];for(let i=0;i<e.length;i++){let s=e[i];for(let o=s.childCount-1;o>=0;o--){let{rowspan:l,colspan:a}=s.child(o).attrs;for(let c=i;c<i+l;c++)t[c]=(t[c]||0)+a}}let r=0;for(let i=0;i<t.length;i++)r=Math.max(r,t[i]);for(let i=0;i<t.length;i++)if(i>=e.length&&e.push(W.empty),t[i]<r){let s=Mt(n).cell.createAndFill(),o=[];for(let l=t[i];l<r;l++)o.push(s);e[i]=e[i].append(W.from(o))}return{height:e.length,width:r,rows:e}}function fh(n,e){let t=n.createAndFill();return new qc(t).replace(0,t.content.size,e).doc}function b5({width:n,height:e,rows:t},r,i){if(n!=r){let s=[],o=[];for(let l=0;l<t.length;l++){let a=t[l],c=[];for(let u=s[l]||0,d=0;u<r;d++){let f=a.child(d%a.childCount);u+f.attrs.colspan>r&&(f=f.type.create(_i(f.attrs,f.attrs.colspan,u+f.attrs.colspan-r),f.content)),c.push(f),u+=f.attrs.colspan;for(let h=1;h<f.attrs.rowspan;h++)s[l+h]=(s[l+h]||0)+f.attrs.colspan}o.push(W.from(c))}t=o,n=r}if(e!=i){let s=[];for(let o=0,l=0;o<i;o++,l++){let a=[],c=t[l%e];for(let u=0;u<c.childCount;u++){let d=c.child(u);o+d.attrs.rowspan>i&&(d=d.type.create(wt(d.attrs,"rowspan",Math.max(1,i-d.attrs.rowspan)),d.content)),a.push(d)}s.push(W.from(a))}t=s,e=i}return{width:n,height:e,rows:t}}function v5(n,e,t,r,i,s,o){let l=n.doc.type.schema,a=Mt(l),c,u;if(i>e.width)for(let d=0,f=0;d<e.height;d++){let h=t.child(d);f+=h.nodeSize;let p=[],g;h.lastChild==null||h.lastChild.type==a.cell?g=c||(c=a.cell.createAndFill()):g=u||(u=a.header_cell.createAndFill());for(let v=e.width;v<i;v++)p.push(g);n.insert(n.mapping.slice(o).map(f-1+r),p)}if(s>e.height){let d=[];for(let p=0,g=(e.height-1)*e.width;p<Math.max(e.width,i);p++){let v=p>=e.width?!1:t.nodeAt(e.map[g+p]).type==a.header_cell;d.push(v?u||(u=a.header_cell.createAndFill()):c||(c=a.cell.createAndFill()))}let f=a.row.create(null,W.from(d)),h=[];for(let p=e.height;p<s;p++)h.push(f);n.insert(n.mapping.slice(o).map(r+t.nodeSize-2),h)}return!!(c||u)}function xv(n,e,t,r,i,s,o,l){if(o==0||o==e.height)return!1;let a=!1;for(let c=i;c<s;c++){let u=o*e.width+c,d=e.map[u];if(e.map[u-e.width]==d){a=!0;let f=t.nodeAt(d),{top:h,left:p}=e.findCell(d);n.setNodeMarkup(n.mapping.slice(l).map(d+r),null,wt(f.attrs,"rowspan",o-h)),n.insert(n.mapping.slice(l).map(e.positionAt(o,p,t)),f.type.createAndFill(wt(f.attrs,"rowspan",h+f.attrs.rowspan-o))),c+=f.attrs.colspan-1}}return a}function Cv(n,e,t,r,i,s,o,l){if(o==0||o==e.width)return!1;let a=!1;for(let c=i;c<s;c++){let u=c*e.width+o,d=e.map[u];if(e.map[u-1]==d){a=!0;let f=t.nodeAt(d),h=e.colCount(d),p=n.mapping.slice(l).map(d+r);n.setNodeMarkup(p,null,_i(f.attrs,o-h,f.attrs.colspan-(o-h))),n.insert(p+f.nodeSize,f.type.createAndFill(_i(f.attrs,0,o-h))),c+=f.attrs.rowspan-1}}return a}function kv(n,e,t,r,i){let s=t?n.doc.nodeAt(t-1):n.doc,o=et.get(s),{top:l,left:a}=r,c=a+i.width,u=l+i.height,d=n.tr,f=0;function h(){s=t?d.doc.nodeAt(t-1):d.doc,o=et.get(s),f=d.mapping.maps.length}v5(d,o,s,t,c,u,f)&&h(),xv(d,o,s,t,a,c,l,f)&&h(),xv(d,o,s,t,a,c,u,f)&&h(),Cv(d,o,s,t,l,u,a,f)&&h(),Cv(d,o,s,t,l,u,c,f)&&h();for(let p=l;p<u;p++){let g=o.positionAt(p,a,s),v=o.positionAt(p,c,s);d.replace(d.mapping.slice(f).map(g+t),d.mapping.slice(f).map(v+t),new Y(i.rows[p-l],0,0))}h(),d.setSelection(new Se(d.doc.resolve(t+o.positionAt(l,a,s)),d.doc.resolve(t+o.positionAt(u-1,c-1,s)))),e(d)}const w5=ku({ArrowLeft:Ac("horiz",-1),ArrowRight:Ac("horiz",1),ArrowUp:Ac("vert",-1),ArrowDown:Ac("vert",1),"Shift-ArrowLeft":Mc("horiz",-1),"Shift-ArrowRight":Mc("horiz",1),"Shift-ArrowUp":Mc("vert",-1),"Shift-ArrowDown":Mc("vert",1),Backspace:Oc,"Mod-Backspace":Oc,Delete:Oc,"Mod-Delete":Oc});function Tc(n,e,t){return t.eq(n.selection)?!1:(e&&e(n.tr.setSelection(t).scrollIntoView()),!0)}function Ac(n,e){return(t,r,i)=>{let s=t.selection;if(s instanceof Se)return Tc(t,r,ue.near(s.$headCell,e));if(n!="horiz"&&!s.empty)return!1;let o=Sv(i,n,e);if(o==null)return!1;if(n=="horiz")return Tc(t,r,ue.near(t.doc.resolve(s.head+e),e));{let l=t.doc.resolve(o),a=vv(l,n,e),c;return a?c=ue.near(a,1):e<0?c=ue.near(t.doc.resolve(l.before(-1)),-1):c=ue.near(t.doc.resolve(l.after(-1)),1),Tc(t,r,c)}}}function Mc(n,e){return(t,r,i)=>{let s=t.selection;if(!(s instanceof Se)){let l=Sv(i,n,e);if(l==null)return!1;s=new Se(t.doc.resolve(l))}let o=vv(s.$headCell,n,e);return o?Tc(t,r,new Se(s.$anchorCell,o)):!1}}function Oc(n,e){let t=n.selection;if(!(t instanceof Se))return!1;if(e){let r=n.tr,i=Mt(n.schema).cell.createAndFill().content;t.forEachCell((s,o)=>{s.content.eq(i)||r.replace(r.mapping.map(o+1),r.mapping.map(o+s.nodeSize-1),new Y(i,0,0))}),r.docChanged&&e(r)}return!0}function x5(n,e){let t=n.state.doc,r=Rs(t.resolve(e));return r?(n.dispatch(n.state.tr.setSelection(new Se(r))),!0):!1}function C5(n,e,t){if(!Tn(n.state))return!1;let r=g5(t),i=n.state.selection;if(i instanceof Se){r||(r={width:1,height:1,rows:[W.from(fh(Mt(n.state.schema).cell,t))]});let s=i.$anchorCell.node(-1),o=i.$anchorCell.start(-1),l=et.get(s).rectBetween(i.$anchorCell.pos-o,i.$headCell.pos-o);return r=b5(r,l.right-l.left,l.bottom-l.top),kv(n.state,n.dispatch,o,l,r),!0}else if(r){let s=Ec(n.state),o=s.start(-1);return kv(n.state,n.dispatch,o,et.get(s.node(-1)).findCell(s.pos-o),r),!0}else return!1}function k5(n,e){if(e.ctrlKey||e.metaKey)return;let t=Ev(n,e.target),r;if(e.shiftKey&&n.state.selection instanceof Se)i(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&t&&(r=Rs(n.state.selection.$anchor))!=null&&hh(n,e).pos!=r.pos)i(r,e),e.preventDefault();else if(!t)return;function i(l,a){let c=hh(n,a),u=Gr.getState(n.state)==null;if(!c||!uh(l,c))if(u)c=l;else return;let d=new Se(l,c);if(u||!n.state.selection.eq(d)){let f=n.state.tr.setSelection(d);u&&f.setMeta(Gr,l.pos),n.dispatch(f)}}function s(){n.root.removeEventListener("mouseup",s),n.root.removeEventListener("dragstart",s),n.root.removeEventListener("mousemove",o),Gr.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(Gr,-1))}function o(l){let a=Gr.getState(n.state),c;if(a!=null)c=n.state.doc.resolve(a);else if(Ev(n,l.target)!=t&&(c=hh(n,e),!c))return s();c&&i(c,l)}n.root.addEventListener("mouseup",s),n.root.addEventListener("dragstart",s),n.root.addEventListener("mousemove",o)}function Sv(n,e,t){if(!(n.state.selection instanceof ce))return null;let{$head:r}=n.state.selection;for(let i=r.depth-1;i>=0;i--){let s=r.node(i);if((t<0?r.index(i):r.indexAfter(i))!=(t<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){let l=r.before(i),a=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(a)?l:null}}return null}function Ev(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e}function hh(n,e){let t=n.posAtCoords({left:e.clientX,top:e.clientY});return t&&t?Rs(n.state.doc.resolve(t.pos)):null}const S5=new We("fix-tables");function Tv(n,e,t,r){let i=n.childCount,s=e.childCount;e:for(let o=0,l=0;o<s;o++){let a=e.child(o);for(let c=l,u=Math.min(i,o+3);c<u;c++)if(n.child(c)==a){l=c+1,t+=a.nodeSize;continue e}r(a,t),l<i&&n.child(l).sameMarkup(a)?Tv(n.child(l),a,t+1,r):a.nodesBetween(0,a.content.size,r,t+1),t+=a.nodeSize}}function Av(n,e){let t,r=(i,s)=>{i.type.spec.tableRole=="table"&&(t=E5(n,i,s,t))};return e?e.doc!=n.doc&&Tv(e.doc,n.doc,0,r):n.doc.descendants(r),t}function E5(n,e,t,r){let i=et.get(e);if(!i.problems)return r;r||(r=n.tr);let s=[];for(let a=0;a<i.height;a++)s.push(0);for(let a=0;a<i.problems.length;a++){let c=i.problems[a];if(c.type=="collision"){let u=e.nodeAt(c.pos);for(let d=0;d<u.attrs.rowspan;d++)s[c.row+d]+=c.n;r.setNodeMarkup(r.mapping.map(t+1+c.pos),null,_i(u.attrs,u.attrs.colspan-c.n,c.n))}else if(c.type=="missing")s[c.row]+=c.n;else if(c.type=="overlong_rowspan"){let u=e.nodeAt(c.pos);r.setNodeMarkup(r.mapping.map(t+1+c.pos),null,wt(u.attrs,"rowspan",u.attrs.rowspan-c.n))}else if(c.type=="colwidth mismatch"){let u=e.nodeAt(c.pos);r.setNodeMarkup(r.mapping.map(t+1+c.pos),null,wt(u.attrs,"colwidth",c.colwidth))}}let o,l;for(let a=0;a<s.length;a++)s[a]&&(o==null&&(o=a),l=a);for(let a=0,c=t+1;a<i.height;a++){let u=e.child(a),d=c+u.nodeSize,f=s[a];if(f>0){let h="cell";u.firstChild&&(h=u.firstChild.type.spec.tableRole);let p=[];for(let v=0;v<f;v++)p.push(Mt(n.schema)[h].createAndFill());let g=(a==0||o==a-1)&&l==a?c+1:d-1;r.insert(r.mapping.map(g),p)}c=d}return r.setMeta(S5,{fixTables:!0})}function Xn(n){let e=n.selection,t=Ec(n),r=t.node(-1),i=t.start(-1),s=et.get(r),o;return e instanceof Se?o=s.rectBetween(e.$anchorCell.pos-i,e.$headCell.pos-i):o=s.findCell(t.pos-i),o.tableStart=i,o.map=s,o.table=r,o}function Mv(n,{map:e,tableStart:t,table:r},i){let s=i>0?-1:0;d5(e,r,i+s)&&(s=i==0||i==e.width?null:0);for(let o=0;o<e.height;o++){let l=o*e.width+i;if(i>0&&i<e.width&&e.map[l-1]==e.map[l]){let a=e.map[l],c=r.nodeAt(a);n.setNodeMarkup(n.mapping.map(t+a),null,wv(c.attrs,i-e.colCount(a))),o+=c.attrs.rowspan-1}else{let a=s==null?Mt(r.type.schema).cell:r.nodeAt(e.map[l+s]).type,c=e.positionAt(o,i,r);n.insert(n.mapping.map(t+c),a.createAndFill())}}return n}function T5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n);e(Mv(n.tr,t,t.left))}return!0}function A5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n);e(Mv(n.tr,t,t.right))}return!0}function M5(n,{map:e,table:t,tableStart:r},i){let s=n.mapping.maps.length;for(let o=0;o<e.height;){let l=o*e.width+i,a=e.map[l],c=t.nodeAt(a);if(i>0&&e.map[l-1]==a||i<e.width-1&&e.map[l+1]==a)n.setNodeMarkup(n.mapping.slice(s).map(r+a),null,_i(c.attrs,i-e.colCount(a)));else{let u=n.mapping.slice(s).map(r+a);n.delete(u,u+c.nodeSize)}o+=c.attrs.rowspan}}function O5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n),r=n.tr;if(t.left==0&&t.right==t.map.width)return!1;for(let i=t.right-1;M5(r,t,i),i!=t.left;i--)t.table=t.tableStart?r.doc.nodeAt(t.tableStart-1):r.doc,t.map=et.get(t.table);e(r)}return!0}function _5(n,e,t){let r=Mt(e.type.schema).header_cell;for(let i=0;i<n.width;i++)if(e.nodeAt(n.map[i+t*n.width]).type!=r)return!1;return!0}function Ov(n,{map:e,tableStart:t,table:r},i){let s=t;for(let a=0;a<i;a++)s+=r.child(a).nodeSize;let o=[],l=i>0?-1:0;_5(e,r,i+l)&&(l=i==0||i==e.height?null:0);for(let a=0,c=e.width*i;a<e.width;a++,c++)if(i>0&&i<e.height&&e.map[c]==e.map[c-e.width]){let u=e.map[c],d=r.nodeAt(u).attrs;n.setNodeMarkup(t+u,null,wt(d,"rowspan",d.rowspan+1)),a+=d.colspan-1}else{let u=l==null?Mt(r.type.schema).cell:r.nodeAt(e.map[c+l*e.width]).type;o.push(u.createAndFill())}return n.insert(s,Mt(r.type.schema).row.create(null,o)),n}function N5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n);e(Ov(n.tr,t,t.top))}return!0}function D5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n);e(Ov(n.tr,t,t.bottom))}return!0}function R5(n,{map:e,table:t,tableStart:r},i){let s=0;for(let a=0;a<i;a++)s+=t.child(a).nodeSize;let o=s+t.child(i).nodeSize,l=n.mapping.maps.length;n.delete(s+r,o+r);for(let a=0,c=i*e.width;a<e.width;a++,c++){let u=e.map[c];if(i>0&&u==e.map[c-e.width]){let d=t.nodeAt(u).attrs;n.setNodeMarkup(n.mapping.slice(l).map(u+r),null,wt(d,"rowspan",d.rowspan-1)),a+=d.colspan-1}else if(i<e.width&&u==e.map[c+e.width]){let d=t.nodeAt(u),f=d.type.create(wt(d.attrs,"rowspan",d.attrs.rowspan-1),d.content),h=e.positionAt(i+1,a,t);n.insert(n.mapping.slice(l).map(r+h),f),a+=d.attrs.colspan-1}}}function L5(n,e){if(!Tn(n))return!1;if(e){let t=Xn(n),r=n.tr;if(t.top==0&&t.bottom==t.map.height)return!1;for(let i=t.bottom-1;R5(r,t,i),i!=t.top;i--)t.table=t.tableStart?r.doc.nodeAt(t.tableStart-1):r.doc,t.map=et.get(t.table);e(r)}return!0}function _v(n){let e=n.content;return e.childCount==1&&e.firstChild.isTextblock&&e.firstChild.childCount==0}function I5({width:n,height:e,map:t},r){let i=r.top*n+r.left,s=i,o=(r.bottom-1)*n+r.left,l=i+(r.right-r.left-1);for(let a=r.top;a<r.bottom;a++){if(r.left>0&&t[s]==t[s-1]||r.right<n&&t[l]==t[l+1])return!0;s+=n,l+=n}for(let a=r.left;a<r.right;a++){if(r.top>0&&t[i]==t[i-n]||r.bottom<e&&t[o]==t[o+n])return!0;i++,o++}return!1}function Nv(n,e){let t=n.selection;if(!(t instanceof Se)||t.$anchorCell.pos==t.$headCell.pos)return!1;let r=Xn(n),{map:i}=r;if(I5(i,r))return!1;if(e){let s=n.tr,o={},l=W.empty,a,c;for(let u=r.top;u<r.bottom;u++)for(let d=r.left;d<r.right;d++){let f=i.map[u*i.width+d],h=r.table.nodeAt(f);if(!o[f])if(o[f]=!0,a==null)a=f,c=h;else{_v(h)||(l=l.append(h.content));let p=s.mapping.map(f+r.tableStart);s.delete(p,p+h.nodeSize)}}if(s.setNodeMarkup(a+r.tableStart,null,wt(wv(c.attrs,c.attrs.colspan,r.right-r.left-c.attrs.colspan),"rowspan",r.bottom-r.top)),l.size){let u=a+1+c.content.size,d=_v(c)?a+1:u;s.replaceWith(d+r.tableStart,u+r.tableStart,l)}s.setSelection(new Se(s.doc.resolve(a+r.tableStart))),e(s)}return!0}function Dv(n,e){const t=Mt(n.schema);return P5(({node:r})=>t[r.type.spec.tableRole])(n,e)}function P5(n){return(e,t)=>{let r=e.selection,i,s;if(r instanceof Se){if(r.$anchorCell.pos!=r.$headCell.pos)return!1;i=r.$anchorCell.nodeAfter,s=r.$anchorCell.pos}else{if(i=a5(r.$from),!i)return!1;s=Rs(r.$from).pos}if(i.attrs.colspan==1&&i.attrs.rowspan==1)return!1;if(t){let o=i.attrs,l=[],a=o.colwidth;o.rowspan>1&&(o=wt(o,"rowspan",1)),o.colspan>1&&(o=wt(o,"colspan",1));let c=Xn(e),u=e.tr;for(let f=0;f<c.right-c.left;f++)l.push(a?wt(o,"colwidth",a&&a[f]?[a[f]]:null):o);let d;for(let f=c.top;f<c.bottom;f++){let h=c.map.positionAt(f,c.left,c.table);f==c.top&&(h+=i.nodeSize);for(let p=c.left,g=0;p<c.right;p++,g++)p==c.left&&f==c.top||u.insert(d=u.mapping.map(h+c.tableStart,1),n({node:i,row:f,col:p}).createAndFill(l[g]))}u.setNodeMarkup(s,n({node:i,row:c.top,col:c.left}),l[0]),r instanceof Se&&u.setSelection(new Se(u.doc.resolve(r.$anchorCell.pos),d&&u.doc.resolve(d))),t(u)}return!0}}function F5(n,e){return function(t,r){if(!Tn(t))return!1;let i=Ec(t);if(i.nodeAfter.attrs[n]===e)return!1;if(r){let s=t.tr;t.selection instanceof Se?t.selection.forEachCell((o,l)=>{o.attrs[n]!==e&&s.setNodeMarkup(l,null,wt(o.attrs,n,e))}):s.setNodeMarkup(i.pos,null,wt(i.nodeAfter.attrs,n,e)),r(s)}return!0}}function B5(n){return function(e,t){if(!Tn(e))return!1;if(t){let r=Mt(e.schema),i=Xn(e),s=e.tr,o=i.map.cellsInRect(n=="column"?new Ds(i.left,0,i.right,i.map.height):n=="row"?new Ds(0,i.top,i.map.width,i.bottom):i),l=o.map(a=>i.table.nodeAt(a));for(let a=0;a<o.length;a++)l[a].type==r.header_cell&&s.setNodeMarkup(i.tableStart+o[a],r.cell,l[a].attrs);if(s.steps.length==0)for(let a=0;a<o.length;a++)s.setNodeMarkup(i.tableStart+o[a],r.header_cell,l[a].attrs);t(s)}return!0}}function Rv(n,e,t){const r=e.map.cellsInRect({left:0,top:0,right:n=="row"?e.map.width:1,bottom:n=="column"?e.map.height:1});for(let i=0;i<r.length;i++){const s=e.table.nodeAt(r[i]);if(s&&s.type!==t.header_cell)return!1}return!0}function Zo(n,e){return e=e||{useDeprecatedLogic:!1},e.useDeprecatedLogic?B5(n):function(t,r){if(!Tn(t))return!1;if(r){let i=Mt(t.schema),s=Xn(t),o=t.tr,l=Rv("row",s,i),a=Rv("column",s,i),u=(n==="column"?l:n==="row"?a:!1)?1:0,d=n=="column"?new Ds(0,u,1,s.map.height):n=="row"?new Ds(u,0,s.map.width,1):s,f=n=="column"?a?i.cell:i.header_cell:n=="row"?l?i.cell:i.header_cell:i.cell;s.map.cellsInRect(d).forEach(h=>{const p=h+s.tableStart,g=o.doc.nodeAt(p);g&&o.setNodeMarkup(p,f,g.attrs)}),r(o)}return!0}}Zo("row",{useDeprecatedLogic:!0}),Zo("column",{useDeprecatedLogic:!0});let $5=Zo("cell",{useDeprecatedLogic:!0});function j5(n,e){if(e<0){let t=n.nodeBefore;if(t)return n.pos-t.nodeSize;for(let r=n.index(-1)-1,i=n.before();r>=0;r--){let s=n.node(-1).child(r);if(s.childCount)return i-1-s.lastChild.nodeSize;i-=s.nodeSize}}else{if(n.index()<n.parent.childCount-1)return n.pos+n.nodeAfter.nodeSize;let t=n.node(-1);for(let r=n.indexAfter(-1),i=n.after();r<t.childCount;r++){let s=t.child(r);if(s.childCount)return i+1;i+=s.nodeSize}}}function Lv(n){return function(e,t){if(!Tn(e))return!1;let r=j5(Ec(e),n);if(r!=null){if(t){let i=e.doc.resolve(r);t(e.tr.setSelection(ce.between(i,u5(i))).scrollIntoView())}return!0}}}function H5(n,e){let t=n.selection.$anchor;for(let r=t.depth;r>0;r--)if(t.node(r).type.spec.tableRole=="table")return e&&e(n.tr.delete(t.before(r),t.after(r)).scrollIntoView()),!0;return!1}let V5=class{constructor(e,t){this.node=e,this.cellMinWidth=t,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.colgroup=this.table.appendChild(document.createElement("colgroup")),ph(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type!=this.node.type?!1:(this.node=e,ph(e,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(e){return e.type=="attributes"&&(e.target==this.table||this.colgroup.contains(e.target))}};function ph(n,e,t,r,i,s){let o=0,l=!0,a=e.firstChild,c=n.firstChild;for(let u=0,d=0;u<c.childCount;u++){let{colspan:f,colwidth:h}=c.child(u).attrs;for(let p=0;p<f;p++,d++){let g=i==d?s:h&&h[p],v=g?g+"px":"";o+=g||r,g||(l=!1),a?(a.style.width!=v&&(a.style.width=v),a=a.nextSibling):e.appendChild(document.createElement("col")).style.width=v}}for(;a;){let u=a.nextSibling;a.parentNode.removeChild(a),a=u}l?(t.style.width=o+"px",t.style.minWidth=""):(t.style.width="",t.style.minWidth=o+"px")}const mn=new We("tableColumnResizing");function z5({handleWidth:n=5,cellMinWidth:e=25,View:t=V5,lastColumnResizable:r=!0}={}){return new je({key:mn,state:{init(s,o){return this.spec.props.nodeViews[Mt(o.schema).table.name]=(l,a)=>new t(l,e,a),new Xo(-1,!1)},apply(s,o){return o.apply(s)}},props:{attributes(s){return mn.getState(s).activeHandle>-1?{class:"resize-cursor"}:null},handleDOMEvents:{mousemove(s,o){U5(s,o,n,e,r)},mouseleave(s){W5(s)},mousedown(s,o){q5(s,o,e)}},decorations(s){let o=mn.getState(s);if(o.activeHandle>-1)return X5(s,o.activeHandle)},nodeViews:{}}})}class Xo{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){let t=this,r=e.getMeta(mn);if(r&&r.setHandle!=null)return new Xo(r.setHandle,null);if(r&&r.setDragging!==void 0)return new Xo(t.activeHandle,r.setDragging);if(t.activeHandle>-1&&e.docChanged){let i=e.mapping.map(t.activeHandle,-1);ch(e.doc.resolve(i))||(i=null),t=new Xo(i,t.dragging)}return t}}function U5(n,e,t,r,i){let s=mn.getState(n.state);if(!s.dragging){let o=J5(e.target),l=-1;if(o){let{left:a,right:c}=o.getBoundingClientRect();e.clientX-a<=t?l=Iv(n,e,"left"):c-e.clientX<=t&&(l=Iv(n,e,"right"))}if(l!=s.activeHandle){if(!i&&l!==-1){let a=n.state.doc.resolve(l),c=a.node(-1),u=et.get(c),d=a.start(-1);if(u.colCount(a.pos-d)+a.nodeAfter.attrs.colspan-1==u.width-1)return}Fv(n,l)}}}function W5(n){let e=mn.getState(n.state);e.activeHandle>-1&&!e.dragging&&Fv(n,-1)}function q5(n,e,t){let r=mn.getState(n.state);if(r.activeHandle==-1||r.dragging)return!1;let i=n.state.doc.nodeAt(r.activeHandle),s=K5(n,r.activeHandle,i.attrs);n.dispatch(n.state.tr.setMeta(mn,{setDragging:{startX:e.clientX,startWidth:s}}));function o(a){window.removeEventListener("mouseup",o),window.removeEventListener("mousemove",l);let c=mn.getState(n.state);c.dragging&&(G5(n,c.activeHandle,Pv(c.dragging,a,t)),n.dispatch(n.state.tr.setMeta(mn,{setDragging:null})))}function l(a){if(!a.which)return o(a);let c=mn.getState(n.state),u=Pv(c.dragging,a,t);Y5(n,c.activeHandle,u,t)}return window.addEventListener("mouseup",o),window.addEventListener("mousemove",l),e.preventDefault(),!0}function K5(n,e,{colspan:t,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let s=n.domAtPos(e),l=s.node.childNodes[s.offset].offsetWidth,a=t;if(r)for(let c=0;c<t;c++)r[c]&&(l-=r[c],a--);return l/a}function J5(n){for(;n&&n.nodeName!="TD"&&n.nodeName!="TH";)n=n.classList.contains("ProseMirror")?null:n.parentNode;return n}function Iv(n,e,t){let r=n.posAtCoords({left:e.clientX,top:e.clientY});if(!r)return-1;let{pos:i}=r,s=Rs(n.state.doc.resolve(i));if(!s)return-1;if(t=="right")return s.pos;let o=et.get(s.node(-1)),l=s.start(-1),a=o.map.indexOf(s.pos-l);return a%o.width==0?-1:l+o.map[a-1]}function Pv(n,e,t){let r=e.clientX-n.startX;return Math.max(t,n.startWidth+r)}function Fv(n,e){n.dispatch(n.state.tr.setMeta(mn,{setHandle:e}))}function G5(n,e,t){let r=n.state.doc.resolve(e),i=r.node(-1),s=et.get(i),o=r.start(-1),l=s.colCount(r.pos-o)+r.nodeAfter.attrs.colspan-1,a=n.state.tr;for(let c=0;c<s.height;c++){let u=c*s.width+l;if(c&&s.map[u]==s.map[u-s.width])continue;let d=s.map[u],{attrs:f}=i.nodeAt(d),h=f.colspan==1?0:l-s.colCount(d);if(f.colwidth&&f.colwidth[h]==t)continue;let p=f.colwidth?f.colwidth.slice():Z5(f.colspan);p[h]=t,a.setNodeMarkup(o+d,null,wt(f,"colwidth",p))}a.docChanged&&n.dispatch(a)}function Y5(n,e,t,r){let i=n.state.doc.resolve(e),s=i.node(-1),o=i.start(-1),l=et.get(s).colCount(i.pos-o)+i.nodeAfter.attrs.colspan-1,a=n.domAtPos(i.start(-1)).node;for(;a.nodeName!="TABLE";)a=a.parentNode;ph(s,a.firstChild,a,r,l,t)}function Z5(n){let e=[];for(let t=0;t<n;t++)e.push(0);return e}function X5(n,e){let t=[],r=n.doc.resolve(e),i=r.node(-1),s=et.get(i),o=r.start(-1),l=s.colCount(r.pos-o)+r.nodeAfter.attrs.colspan;for(let a=0;a<s.height;a++){let c=l+a*s.width-1;if((l==s.width||s.map[c]!=s.map[c+1])&&(a==0||s.map[c-1]!=s.map[c-1-s.width])){let u=s.map[c],d=o+u+i.nodeAt(u).nodeSize-1,f=document.createElement("div");f.className="column-resize-handle",t.push(ut.widget(d,f))}}return He.create(n.doc,t)}function Q5({allowTableNodeSelection:n=!1}={}){return new je({key:Gr,state:{init(){return null},apply(e,t){let r=e.getMeta(Gr);if(r!=null)return r==-1?null:r;if(t==null||!e.docChanged)return t;let{deleted:i,pos:s}=e.mapping.mapResult(t);return i?null:s}},props:{decorations:f5,handleDOMEvents:{mousedown:k5},createSelectionBetween(e){if(Gr.getState(e.state)!=null)return e.state.selection},handleTripleClick:x5,handleKeyDown:w5,handlePaste:C5},appendTransaction(e,t,r){return m5(r,Av(r,t),n)}})}function Bv(n,e,t,r,i,s){var u;let o=0,l=!0,a=e.firstChild;const c=n.firstChild;if(c)for(let d=0,f=0;d<c.childCount;d+=1){const{colspan:h,colwidth:p}=c.child(d).attrs;for(let g=0;g<h;g+=1,f+=1){const v=i===f?s:p&&p[g],w=v?`${v}px`:"";o+=v||r,v||(l=!1),a?(a.style.width!==w&&(a.style.width=w),a=a.nextSibling):e.appendChild(document.createElement("col")).style.width=w}}for(;a;){const d=a.nextSibling;(u=a==null?void 0:a.parentNode)==null||u.removeChild(a),a=d}l?(t.style.width=`${o}px`,t.style.minWidth=""):(t.style.width="",t.style.minWidth=`${o}px`)}class eL{constructor(e,t){vr(this,"node");vr(this,"cellMinWidth");vr(this,"dom");vr(this,"table");vr(this,"colgroup");vr(this,"contentDOM");this.node=e,this.cellMinWidth=t,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Bv(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type!==this.node.type?!1:(this.node=e,Bv(e,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(e){return e.type==="attributes"&&(e.target===this.table||this.colgroup.contains(e.target))}}function $v(n,e){return n.createAndFill()}function tL(n){if(n.cached.tableNodeTypes)return n.cached.tableNodeTypes;const e={};return Object.keys(n.nodes).forEach(t=>{const r=n.nodes[t];r.spec.tableRole&&(e[r.spec.tableRole]=r)}),n.cached.tableNodeTypes=e,e}function nL(n,e,t,r,i){const s=tL(n),o=[],l=[];for(let c=0;c<t;c+=1){const u=$v(s.cell);if(u&&l.push(u),r){const d=$v(s.header_cell);d&&o.push(d)}}const a=[];for(let c=0;c<e;c+=1)a.push(s.row.createChecked(null,r&&c===0?o:l));return s.table.createChecked(null,a)}function rL(n){return n instanceof Se}const _c=({editor:n})=>{const{selection:e}=n.state;if(!rL(e))return!1;let t=0;const r=Ru(e.ranges[0].$from,s=>s.type.name==="table");return r==null||r.node.descendants(s=>{if(s.type.name==="table")return!1;["tableCell","tableHeader"].includes(s.type.name)&&(t+=1)}),t===e.ranges.length?(n.commands.deleteTable(),!0):!1},iL=Ve.create({name:"table",addOptions(){return{HTMLAttributes:{},resizable:!1,handleWidth:5,cellMinWidth:25,View:eL,lastColumnResizable:!0,allowTableNodeSelection:!1}},content:"tableRow+",tableRole:"table",isolating:!0,group:"block",parseHTML(){return[{tag:"table"}]},renderHTML({node:n,HTMLAttributes:e}){let t=0,r=!0;try{n.content.firstChild.content.forEach(s=>{if(s.attrs.colwidth)s.attrs.colwidth.forEach(o=>{o?t+=o:(r=!1,t+=this.options.cellMinWidth)});else{r=!1;const o=s.attrs.colspan?s.attrs.colspan:1;t+=this.options.cellMinWidth*o}})}catch{r=!1}return r&&t>0?e.style=`width: ${t}px;`:t&&t>0?e.style=`min-width: ${t}px`:e.style=null,["div",{class:"table-wrapper"},["table",xe(this.options.HTMLAttributes,e),["tbody",0]]]},addCommands(){return{insertTable:({rows:n=3,cols:e=3,withHeaderRow:t=!0}={})=>({tr:r,dispatch:i,editor:s})=>{const{selection:o}=r,l=nL(s.schema,n,e,t);if(i){const a=r.selection.anchor+1;r.replaceRangeWith(o.from-1,o.to,l).scrollIntoView().setSelection(ce.near(r.doc.resolve(a)))}return!0},addColumnBefore:()=>({state:n,dispatch:e})=>T5(n,e),addColumnAfter:()=>({state:n,dispatch:e})=>A5(n,e),deleteColumn:()=>({state:n,dispatch:e})=>O5(n,e),addRowBefore:()=>({state:n,dispatch:e})=>N5(n,e),addRowAfter:()=>({state:n,dispatch:e})=>D5(n,e),deleteRow:()=>({state:n,dispatch:e})=>L5(n,e),deleteTable:()=>({state:n,dispatch:e})=>H5(n,e),mergeCells:()=>({state:n,dispatch:e})=>Nv(n,e),splitCell:()=>({state:n,dispatch:e})=>Dv(n,e),toggleHeaderColumn:()=>({state:n,dispatch:e})=>Zo("column")(n,e),toggleHeaderRow:()=>({state:n,dispatch:e})=>Zo("row")(n,e),toggleHeaderCell:()=>({state:n,dispatch:e})=>$5(n,e),mergeOrSplit:()=>({state:n,dispatch:e})=>Nv(n,e)?!0:Dv(n,e),setCellAttribute:(n,e)=>({state:t,dispatch:r})=>F5(n,e)(t,r),goToNextCell:()=>({state:n,dispatch:e})=>Lv(1)(n,e),goToPreviousCell:()=>({state:n,dispatch:e})=>Lv(-1)(n,e),fixTables:()=>({state:n,dispatch:e})=>(e&&Av(n),!0),setCellSelection:n=>({tr:e,dispatch:t})=>{if(t){const r=Se.create(e.doc,n.anchorCell,n.headCell);e.setSelection(r)}return!0}}},addKeyboardShortcuts(){return{Tab:()=>this.editor.commands.goToNextCell()?!0:this.editor.can().addRowAfter()?this.editor.chain().addRowAfter().goToNextCell().run():!1,"Shift-Tab":()=>this.editor.commands.goToPreviousCell(),Backspace:_c,"Mod-Backspace":_c,Delete:_c,"Mod-Delete":_c}},addProseMirrorPlugins(){return[...this.options.resizable&&this.editor.isEditable?[z5({handleWidth:this.options.handleWidth,cellMinWidth:this.options.cellMinWidth,View:this.options.View,lastColumnResizable:this.options.lastColumnResizable})]:[],Q5({allowTableNodeSelection:this.options.allowTableNodeSelection})]},extendNodeSchema(n){const e={name:n.name,options:n.options,storage:n.storage};return{tableRole:ge(re(n,"tableRole",e))}}});function jv(n,e){if(n==null)return{};var t={},r=Object.keys(n),i,s;for(s=0;s<r.length;s++)i=r[s],!(e.indexOf(i)>=0)&&(t[i]=n[i]);return t}var Hv=typeof window<"u"&&typeof document<"u";function mh(n,e){n&&(typeof n=="function"&&n(e),{}.hasOwnProperty.call(n,"current")&&(n.current=e))}function Vv(){return Hv&&document.createElement("div")}function sL(n){var e={"data-placement":n.placement};return n.referenceHidden&&(e["data-reference-hidden"]=""),n.escaped&&(e["data-escaped"]=""),e}function zv(n,e){if(n===e)return!0;if(typeof n=="object"&&n!=null&&typeof e=="object"&&e!=null){if(Object.keys(n).length!==Object.keys(e).length)return!1;for(var t in n)if(e.hasOwnProperty(t)){if(!zv(n[t],e[t]))return!1}else return!1;return!0}else return!1}function oL(n){var e=[];return n.forEach(function(t){e.find(function(r){return zv(t,r)})||e.push(t)}),e}function lL(n,e){var t,r;return Object.assign({},e,{popperOptions:Object.assign({},n.popperOptions,e.popperOptions,{modifiers:oL([].concat(((t=n.popperOptions)==null?void 0:t.modifiers)||[],((r=e.popperOptions)==null?void 0:r.modifiers)||[]))})})}var gh=Hv?O.useLayoutEffect:O.useEffect;function aL(n){var e=O.useRef();return e.current||(e.current=typeof n=="function"?n():n),e.current}function Uv(n,e,t){t.split(/\s+/).forEach(function(r){r&&n.classList[e](r)})}var cL={name:"className",defaultValue:"",fn:function(e){var t=e.popper.firstElementChild,r=function(){var l;return!!((l=e.props.render)!=null&&l.$$tippy)};function i(){if(e.props.className&&!r()){process.env.NODE_ENV!=="production"&&console.warn(["@tippyjs/react: Cannot use `className` prop in conjunction with","`render` prop. Place the className on the element you are","rendering."].join(" "));return}Uv(t,"add",e.props.className)}function s(){r()&&Uv(t,"remove",e.props.className)}return{onCreate:i,onBeforeUpdate:s,onAfterUpdate:i}}};function uL(n){function e(t){var r=t.children,i=t.content,s=t.visible,o=t.singleton,l=t.render,a=t.reference,c=t.disabled,u=c===void 0?!1:c,d=t.ignoreAttributes,f=d===void 0?!0:d;t.__source,t.__self;var h=jv(t,["children","content","visible","singleton","render","reference","disabled","ignoreAttributes","__source","__self"]),p=s!==void 0,g=o!==void 0,v=O.useState(!1),w=v[0],S=v[1],x=O.useState({}),y=x[0],k=x[1],E=O.useState(),T=E[0],N=E[1],_=aL(function(){return{container:Vv(),renders:1}}),A=Object.assign({ignoreAttributes:f},h,{content:_.container});p&&(process.env.NODE_ENV!=="production"&&["trigger","hideOnClick","showOnCreate"].forEach(function(V){A[V]!==void 0&&console.warn(["@tippyjs/react: Cannot specify `"+V+"` prop in","controlled mode (`visible` prop)"].join(" "))}),A.trigger="manual",A.hideOnClick=!1),g&&(u=!0);var R=A,P=A.plugins||[];l&&(R=Object.assign({},A,{plugins:g&&o.data!=null?[].concat(P,[{fn:function(){return{onTrigger:function(J,G){var ie=o.data.children.find(function(X){var we=X.instance;return we.reference===G.currentTarget});J.state.$$activeSingletonInstance=ie.instance,N(ie.content)}}}}]):P,render:function(){return{popper:_.container}}}));var $=[a].concat(r?[r.type]:[]);return gh(function(){var V=a;a&&a.hasOwnProperty("current")&&(V=a.current);var U=n(V||_.ref||Vv(),Object.assign({},R,{plugins:[cL].concat(A.plugins||[])}));return _.instance=U,u&&U.disable(),s&&U.show(),g&&o.hook({instance:U,content:i,props:R,setSingletonContent:N}),S(!0),function(){U.destroy(),o==null||o.cleanup(U)}},$),gh(function(){var V;if(_.renders===1){_.renders++;return}var U=_.instance;U.setProps(lL(U.props,R)),(V=U.popperInstance)==null||V.forceUpdate(),u?U.disable():U.enable(),p&&(s?U.show():U.hide()),g&&o.hook({instance:U,content:i,props:R,setSingletonContent:N})}),gh(function(){var V;if(l){var U=_.instance;U.setProps({popperOptions:Object.assign({},U.props.popperOptions,{modifiers:[].concat((((V=U.props.popperOptions)==null?void 0:V.modifiers)||[]).filter(function(J){var G=J.name;return G!=="$$tippyReact"}),[{name:"$$tippyReact",enabled:!0,phase:"beforeWrite",requires:["computeStyles"],fn:function(G){var ie,X=G.state,we=(ie=X.modifiersData)==null?void 0:ie.hide;(y.placement!==X.placement||y.referenceHidden!==(we==null?void 0:we.isReferenceHidden)||y.escaped!==(we==null?void 0:we.hasPopperEscaped))&&k({placement:X.placement,referenceHidden:we==null?void 0:we.isReferenceHidden,escaped:we==null?void 0:we.hasPopperEscaped}),X.attributes.popper={}}}])})})}},[y.placement,y.referenceHidden,y.escaped].concat($)),O.createElement(O.Fragment,null,r?O.cloneElement(r,{ref:function(U){_.ref=U,mh(r.ref,U)}}):null,w&&nn.createPortal(l?l(sL(y),T,_.instance):i,_.container))}return e}var dL=function(n,e){return O.forwardRef(function(r,i){var s=r.children,o=jv(r,["children"]);return O.createElement(n,Object.assign({},e,o),s?O.cloneElement(s,{ref:function(a){mh(i,a),mh(s.ref,a)}}):null)})},fL=dL(uL(fi));const hL=[{name:"Add row above",action:n=>n.chain().focus().addRowBefore().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M22 14a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v7h2v-2h4v2h2v-2h4v2h2v-2h4v2h2v-7M4 14h4v3H4v-3m6 0h4v3h-4v-3m10 0v3h-4v-3h4m-9-4h2V7h3V5h-3V2h-2v3H8v2h3v3Z"})})},{name:"Add row below",action:n=>n.chain().focus().addRowAfter().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M22 10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V3h2v2h4V3h2v2h4V3h2v2h4V3h2v7M4 10h4V7H4v3m6 0h4V7h-4v3m10 0V7h-4v3h4m-9 4h2v3h3v2h-3v3h-2v-3H8v-2h3v-3Z"})})},{name:"Add left column",action:n=>n.chain().focus().addColumnBefore().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M13 2a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h9V2h-9m7 8v4h-7v-4h7m0 6v4h-7v-4h7m0-12v4h-7V4h7M9 11H6V8H4v3H1v2h3v3h2v-3h3v-2Z"})})},{name:"Add right column",action:n=>n.chain().focus().addColumnAfter().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M11 2a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H2V2h9m-7 8v4h7v-4H4m0 6v4h7v-4H4M4 4v4h7V4H4m11 7h3V8h2v3h3v2h-3v3h-2v-3h-3v-2Z"})})},{name:"Remove row",action:n=>n.chain().focus().deleteRow().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M9.41 13L12 15.59L14.59 13L16 14.41L13.41 17L16 19.59L14.59 21L12 18.41L9.41 21L8 19.59L10.59 17L8 14.41L9.41 13M22 9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v3M4 9h4V6H4v3m6 0h4V6h-4v3m6 0h4V6h-4v3Z"})})},{name:"Remove column",action:n=>n.chain().focus().deleteColumn().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M4 2h7a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2m0 8v4h7v-4H4m0 6v4h7v-4H4M4 4v4h7V4H4m13.59 8L15 9.41L16.41 8L19 10.59L21.59 8L23 9.41L20.41 12L23 14.59L21.59 16L19 13.41L16.41 16L15 14.59L17.59 12Z"})})},{name:"Toggle header row",action:n=>n.chain().focus().toggleHeaderRow().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M22 14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-4a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v4M4 14h4v-4H4v4m6 0h4v-4h-4v4m6 0h4v-4h-4v4Z"})})},{name:"Toggle header column",action:n=>n.chain().focus().toggleHeaderColumn().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M8 2h8a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2m0 8v4h8v-4H8m0 6v4h8v-4H8M8 4v4h8V4H8Z"})})},{name:"Toggle header cell",action:n=>n.chain().focus().toggleHeaderCell().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M21 19a1 1 0 0 1-1 1h-1v-2h2v1m-6 1v-2h2v2h-2m-4 0v-2h2v2h-2m-4 0v-2h2v2H7m-3 0a1 1 0 0 1-1-1v-1h2v2H4M19 4H5a2 2 0 0 0-2 2v2h18V6c0-1.11-.89-2-2-2M5 14H3v2h2v-2m0-4H3v2h2v-2m16 0h-2v2h2v-2m0 4h-2v2h2v-2m-10 2v-2h2v2h-2m0-4v-2h2v2h-2"})})},{name:"Remove table",action:n=>n.chain().focus().deleteTable().run(),icon:D.jsx("svg",{viewBox:"0 0 24 24",children:D.jsx("path",{fill:"currentColor",d:"M12.35 20H10v-3h2.09c.12-.72.37-1.39.72-2H10v-3h4v1.54c.58-.54 1.25-.93 2-1.19V12h4v.35c.75.26 1.42.65 2 1.19V5c0-1.1-.9-2-2-2H4c-1.1 0-2 .9-2 2v15c0 1.1.9 2 2 2h9.54c-.54-.58-.93-1.25-1.19-2M16 7h4v3h-4V7m-6 0h4v3h-4V7M8 20H4v-3h4v3m0-5H4v-3h4v3m0-5H4V7h4v3m6.46 5.88l1.42-1.42L18 16.59l2.12-2.13l1.42 1.42L19.41 18l2.13 2.12l-1.42 1.42L18 19.41l-2.12 2.13l-1.42-1.42L16.59 18l-2.13-2.12"})})}],Wv=({node:n,getPos:e,selected:t,editor:r})=>{const[i,s]=O.useState(!1),o=Ul(),l=O.useRef(null),a=()=>{const{from:u,to:d}=r.state.selection,f=e(),h=f+n.nodeSize;s(f<=u&&d<=h)};O.useEffect(()=>(r.on("selectionUpdate",a),setTimeout(a,100),()=>{r.off("selectionUpdate",a)}));const c=()=>{var f,h;let u=(f=l.current)==null?void 0:f.clientTop;u&&(u+=5);let d=(h=l.current)==null?void 0:h.clientLeft;return d&&(d+=5),{top:`${u}px`,left:`${d}px`}};return D.jsxs(bo,{className:"group",children:[D.jsx(Kg,{as:"span"}),(i||t)&&D.jsx(fL,{appendTo:document.body,trigger:"click",interactive:!0,animation:"shift-toward-subtle",placement:"right-start",content:D.jsx("article",{className:"dropdown",contentEditable:!1,children:D.jsx("ul",{tabIndex:0,className:"dropdown-content fixed menu menu-compact p-2 shadow bg-base-100 rounded-box w-56",style:c(),children:hL.map(u=>D.jsx("li",{children:D.jsxs("button",{type:"button",className:"button",onClick:()=>u.action(r),children:[D.jsx("span",{children:u.icon}),D.jsx("span",{children:u.name})]})},u.name))})}),children:D.jsx("label",{tabIndex:0,className:Fe("trigger-button",{hidden:o}),contentEditable:!1,children:D.jsx(GE,{fontSize:"small"})})})]})},pL=Ve.create({name:"tableCell",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:n=>{const e=n.getAttribute("colwidth");return e?[parseInt(e,10)]:null}}}},tableRole:"cell",isolating:!0,parseHTML(){return[{tag:"td"}]},renderHTML({HTMLAttributes:n}){return["td",xe(this.options.HTMLAttributes,n),0]},addNodeView(){return hi(Wv,{as:"td",className:"relative"})}}),mL=Ve.create({name:"tableHeader",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:n=>{const e=n.getAttribute("colwidth");return e?[parseInt(e,10)]:null}}}},tableRole:"header_cell",isolating:!0,parseHTML(){return[{tag:"th"}]},renderHTML({HTMLAttributes:n}){return["th",xe(this.options.HTMLAttributes,n),0]},addNodeView(){return hi(Wv,{as:"th",className:"relative"})}}),qv=n=>(n.stopPropagation(),n.preventDefault(),n),gL=function(n){const e=n.scrollHeight>n.clientHeight,r=window.getComputedStyle(n).overflowY.indexOf("hidden")!==-1;return e&&!r},Kv=function(n){return!n||n===document.body?document.body:gL(n)?n:Kv(n.parentNode)},yh=(n,e,t)=>{const r=document.createElement(n);if(!r)throw new Error(`Element with name ${n} can't be created.`);return e&&Object.entries(e).forEach(([i,s])=>r.setAttribute(i,s)),t&&Object.entries(t).forEach(([i,s])=>r.addEventListener(i,s)),r},yL=Ve.create({name:"tableRow",addOptions(){return{HTMLAttributes:{}}},content:"(tableCell | tableHeader)*",tableRole:"row",parseHTML(){return[{tag:"tr"}]},renderHTML({HTMLAttributes:n}){return["tr",xe(this.options.HTMLAttributes,n),0]},addNodeView(){return({editor:n,HTMLAttributes:e,getPos:t})=>{const r=()=>t(),i=Kv(n.options.element);let s=!1;const o={deleteRow:()=>{this.editor.chain().deleteNode("tableRow").focus().run()},selectRow:()=>{const w=r(),S=n.state.doc.resolve(w),x=new se(S);n.view.dispatch(n.state.tr.setSelection(x))}},l=()=>{s=!0},a=()=>{s=!1},c=yh("section",{class:"absolute hidden flex items-center w-2 bg-gray-200 z-50 cursor-pointer border-1 border-indigo-600 rounded-l opacity-25 hover:opacity-100",contenteditable:"false"},{click:w=>{w&&qv(w),o.selectRow()},mouseenter:()=>{l()},mouseover:()=>{l()},mouseleave:()=>{a(),f()}}),u=yh("button",{class:"text-sm px-1 absolute -translate-x-[125%] hover:active:-translate-x-[125%] mr-2"},{click:w=>{w&&qv(w),o.deleteRow()}}),d=()=>{g(),c.classList.remove("hidden")},f=()=>{setTimeout(()=>{s||c.classList.add("hidden")},100)},h=yh("tr",{...e},{mouseenter:d,mouseover:d,mouseleave:f});c.append(u),document.body.append(c);let p="";const g=()=>{setTimeout(()=>{const w=h.getBoundingClientRect(),S=JSON.stringify(w);p!==S&&(c.style.top=`${w.top+document.documentElement.scrollTop}px`,c.style.left=`${w.x+document.documentElement.scrollLeft-8}px`,c.style.height=`${w.height+1}px`,p=S)})};return setTimeout(()=>{g()},100),n.on("selectionUpdate",g),n.on("update",g),i==null||i.addEventListener("scroll",g),document.addEventListener("scroll",g),{dom:h,contentDOM:h,destroy:()=>{c.remove(),n.off("selectionUpdate",g),n.off("update",g),i==null||i.removeEventListener("scroll",g),document.removeEventListener("scroll",g)}}}}}),bL=[iL.configure({resizable:!0}),pL,mL,yL],vL=Hb.extend({content:"(dBlock|columns)+"});function Jv({types:n,node:e}){return e!=null&&e.type?Array.isArray(n)&&n.includes(e.type)||e.type===n:!1}const wL=Ue.create({name:"trailingNode",addOptions(){return{node:"paragraph",notAfter:["paragraph"]}},addProseMirrorPlugins(){const n=new We(this.name),e=Object.entries(this.editor.schema.nodes).map(([,t])=>t).filter(t=>this.options.notAfter.includes(t.name));return[new je({key:n,appendTransaction:(t,r,i)=>{const{doc:s,tr:o,schema:l}=i,a=n.getState(i),c=s.content.size,u=l.nodes[this.options.node];if(a)return o.insert(c,u.create())},state:{init:(t,r)=>{const i=r.tr.doc.lastChild;return!Jv({node:i,types:e})},apply:(t,r)=>{var s,o,l;if(!t.docChanged)return r;const i=(l=(o=(s=t.doc.lastChild)==null?void 0:s.content)==null?void 0:o.content)==null?void 0:l[0];return!Jv({node:i,types:e})}}})]}}),xL=({node:n,editor:e,getPos:t})=>{const[r,i]=O.useState(""),s=Ul(),o=["https://twitter.com","https://x.com"],l=()=>{switch(n.attrs.data){case"twitter":return D.jsx(f0,{});case"iframe":return D.jsx(h0,{});default:return D.jsx(aT,{})}},a=()=>{switch(n.attrs.data){case"twitter":return"Embed a Twitter tweet";case"iframe":return"Embed a video";default:return"Embed an URL"}},c=()=>{if(!r){alert("Please enter a url");return}let p=r;if(r.includes("<iframe")){const x=r.match(/src="([^"]*)"/);x&&x.length>0&&(p=x[1])}else switch(!0){case/youtu\.?be(?:\.com)?\/(?:.*v(?:\/|=)|(?:.*\/)?)([a-zA-Z0-9-_]+)/.test(r):{const x=r.match(/youtu\.?be(?:\.com)?\/(?:.*v(?:\/|=)|(?:.*\/)?)([a-zA-Z0-9-_]+)/);x&&x.length>0&&(p=`https://www.youtube.com/embed/${x[1]}`);break}case/vimeo\.com\/([a-zA-Z0-9-_]+)/.test(r):{const x=r.match(/vimeo\.com\/([a-zA-Z0-9-_]+)/);x&&x.length>0&&(p=`https://player.vimeo.com/video/${x[1]}`);break}default:{alert("Please enter a valid url");return}}const g=640,v=360,w=t(),S=w+n.nodeSize;p&&(e==null||e.chain().focus(w).deleteRange({from:w,to:S}).setIframe({src:p,width:g,height:v}).run())},u=()=>{if(!r){alert("Please enter a url");return}let p=r;const g=o.some(y=>r.includes(y)),v=r.match(/\/status\/([0-9]*)/),w=v&&v.length>0;if(g&&w)p=v[1];else{alert("invalid url");return}const S=t(),x=S+n.nodeSize;p&&(e==null||e.chain().focus(S).deleteRange({from:S,to:x}).setTweetEmbed({tweetId:p}).run())},f=y1(()=>{switch(n.attrs.data){case"twitter":u();break;default:c();break}},500);O.useEffect(()=>{r&&f()},[r]),O.useEffect(()=>{e==null||e.chain().focus()},[]);const h=O.useRef(null);return O.useEffect(()=>{var p;(p=h.current)==null||p.focus()},[]),D.jsx(bo,{as:"div",className:"flex gap-2 group w-full relative justify-center items-start",children:!s&&D.jsxs("div",{className:"relative w-full",children:[D.jsx("div",{className:"absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none",children:l()}),D.jsx("input",{ref:h,value:r,placeholder:a(),onChange:p=>i(p.target.value),onClick:p=>p.stopPropagation(),className:"bg-stone-200 p-3 pl-10 rounded-xl w-full hover:bg-stone-300 cursor-pointer transition-all ease-in-out"})]})})},CL=Ve.create({name:"actionButton",group:"block",content:"block*",atom:!0,draggable:!0,addOptions(){return{HTMLAttributes:{class:"rounded-lg bg-stone-500"}}},addAttributes(){return{data:{default:null}}},addNodeView(){return hi(xL)},parseHTML(){return[{tag:"div[data-action-node]"}]},renderHTML({HTMLAttributes:n}){return console.log("action"),["div",xe(n,{"data-action-node":""}),0]},addCommands(){return{setActionButton:n=>({commands:e})=>e.insertContent({type:this.name,attrs:{data:n},content:[]})}}}),kL=[h_,d_.configure({strike:{HTMLAttributes:{class:"select-text pointer-events-auto"}},bold:{HTMLAttributes:{class:"select-text pointer-events-auto"}},italic:{HTMLAttributes:{class:"select-text pointer-events-auto"}},heading:{HTMLAttributes:{class:"select-text pointer-events-auto"}},paragraph:{HTMLAttributes:{class:"select-text pointer-events-auto"}},bulletList:{HTMLAttributes:{class:"flex flex-col items-start list-disc list-outside space-y-4 ml-6"}},orderedList:{HTMLAttributes:{class:"flex flex-col items-start list-decimal list-outside space-y-4 ml-6"}},listItem:{HTMLAttributes:{class:"leading-normal"}},blockquote:{HTMLAttributes:{class:"rounded-lg bg-stone-100 p-5 font-serif italic text-stone-800"}},codeBlock:{HTMLAttributes:{class:"rounded-lg bg-transparent border border-[#DDE2E4] p-5 font-mono font-medium text-stone-800"}},code:{HTMLAttributes:{class:"rounded-md bg-stone-200 p-1.5 font-mono font-medium text-black text-sm",spellcheck:"false"}},history:!1,gapcursor:!1,dropcursor:!1,document:!1,horizontalRule:!1}),p_.configure({types:["heading","paragraph"]}),tN,F_.configure({HTMLAttributes:{class:"text-blue-500 font-bold transition-colors cursor-pointer select-text pointer-events-auto"},openOnClick:!0}),B_.configure({placeholder:()=>"",includeChildren:!0,showOnlyCurrent:!0}),H_.configure({multicolor:!0}),eN,W_.configure({HTMLAttributes:{class:"select-text pointer-events-auto"}}),f_,iN,V_.configure({HTMLAttributes:{class:"not-prose space-y-4 ml-2"}}),U_.configure({HTMLAttributes:{class:"flex items-start"},nested:!0}),Vb.configure({width:3,color:"#d1d5db"}),zb,r5,wL,vL,...bL,hN.configure({uploadFn:AT}),rN,sN,cN,CL.extend({addInputRules(){return[Gv(/^(?:twt|###|___\s|\*\*\*\s)$/,"twitter",this.type),Gv(/^(?:ytb|@@@|___\s|\*\*\*\s)$/,"iframe",this.type)]}}),nN],Gv=(n,e,t)=>new io({find:n,handler:({state:r,range:i,commands:s})=>{const o={data:e},{tr:l}=r,a=i.from,c=i.to;l.insert(a-1,t.create(o)).delete(l.mapping.map(a),l.mapping.map(c)),s.focus(c-1)}}),Yv=["#30bced","#6eeb83","#fa69d1","#ecd444","#ee6352","#db3041","#0ad7f2","#1bff39"],SL=({isPreviewMode:n,data:e,enableCollaboration:t,collaborationId:r})=>{const[i,s]=O.useState({plugin:{title:"Untitled"}}),[o]=O.useState(new as),l=O.useRef(null),a=[...kL,p3.configure({document:o})];O.useEffect(()=>{if(r&&t){const f=new HO(r||"default-room",o,{signaling:["wss://fileverse-signaling-server-0529292ff51c.herokuapp.com/"]});return l.current=f,()=>{f.destroy(),o.destroy()}}},[r,o]),O.useEffect(()=>{t&&r&&(a.some(h=>h.name==="collaborationCursor")||a.push(m3.configure({provider:l.current,user:{color:Yv[Math.floor(Math.random()*Yv.length)]}})))},[l.current]);const c=FE({extensions:a,editorProps:VO,autofocus:"start"}),u=O.useRef(null),d=f=>{var h;(h=u.current)!=null&&h.contains(f.target)||c==null||c.chain().focus().run()};return O.useEffect(()=>{c==null||c.chain().focus()},[]),O.useEffect(()=>{c==null||c.setEditable(!n)},[n]),O.useEffect(()=>{e&&c&&(c==null||c.commands.setContent(e.editorJSONData),s(e.metaData))},[e,c]),{editor:c,pluginMetaData:i,setPluginMetaData:s,focusEditor:d,ref:u}},EL=({isPreviewMode:n=!1,onPublish:e,data:t,togglePreviewMode:r,enableCollaboration:i,collaborationId:s,onAutoSave:o})=>{const{editor:l,pluginMetaData:a,focusEditor:c,setPluginMetaData:u,ref:d}=SL({isPreviewMode:n,data:t,enableCollaboration:i,collaborationId:s,onPublish:e,togglePreviewMode:r});return O.useEffect(()=>{if(l&&o){const f=setInterval(()=>{o({metaData:a,editorJSONData:l.getJSON()})},1e4);return()=>clearInterval(f)}},[l,o,a]),l?D.jsx("div",{"data-cy":"single-webpage",className:"bg-[#f9fbfd]",children:D.jsx("div",{className:"h-full flex flex-col overflow-scroll no-scrollbar",children:D.jsxs("div",{className:"w-full h-screen",children:[D.jsx("div",{className:"h-fit relative bg-[#ffffff]",children:D.jsxs("div",{className:"flex items-center justify-center pl-4 pr-4 border-b-1 border gap-2 h-16",children:[D.jsx("div",{className:"grow",children:D.jsx(iw,{isPreviewMode:n,metaData:a,setMetaData:u})}),!n&&D.jsx("div",{className:"grow relative",children:D.jsx(zT,{editor:l})}),D.jsx("div",{children:D.jsxs(zl,{variant:"secondary",onClick:()=>r(n),children:[n?D.jsx(nT,{size:14}):D.jsx(sT,{size:14})," ",n?"Edit":"Preview"]})}),e&&D.jsx("div",{children:D.jsxs(zl,{onClick:()=>e({metaData:a,editorJSONData:l.getJSON()}),children:[D.jsx(oT,{size:14})," Share"]})})]})}),D.jsx("main",{className:"h-screen lg:h-full w-full rounded-[8px] flex flex-col justify-start items-center gap-2",children:D.jsx("div",{onClick:c,className:"w-full flex justify-center relative",children:D.jsx("div",{className:"p-12 sm:p-[96px] mt-4 min-h-[900px] shadow-inner bg-white overflow-scroll no-scrollbar rounded-md w-full sm:w-[70%] max-w-[856px]",children:D.jsxs("div",{ref:d,className:"w-full pt-4 h-full",children:[!n&&D.jsxs("div",{children:[D.jsx(LT,{editor:l}),D.jsx(HT,{editor:l,appendTo:d})]}),D.jsx(VT,{isPreviewMode:n,children:D.jsx(IE,{editor:l})})]})})})})]})})}):D.jsxs("div",{className:"w-screen h-screen flex flex-col gap-4 justify-center items-center",children:[D.jsx(N0,{}),D.jsx("p",{children:"Loading Editor..."})]})};Bt.DdocEditor=EL,Object.defineProperty(Bt,Symbol.toStringTag,{value:"Module"})});
|