@select-org/select-post-builder 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -583,4 +583,4 @@ Defaulting to \`null\`.`}var wK=sO,EK=aO;function cO({className:t,value:e,...n})
583
583
  * @author Kent C. Dodds <me@kentcdodds.com> (https://kentcdodds.com)
584
584
  */const sn={CASE_SENSITIVE_EQUAL:7,EQUAL:6,STARTS_WITH:5,WORD_STARTS_WITH:4,CONTAINS:3,ACRONYM:2,MATCHES:1,NO_MATCH:0},MJ=(t,e)=>String(t.rankedValue).localeCompare(String(e.rankedValue));function jm(t,e,n={}){const{keys:r,threshold:o=sn.MATCHES,baseSort:s=MJ,sorter:i=c=>c.sort((u,d)=>DJ(u,d,s))}=n,a=t.reduce(l,[]);return i(a).map(({item:c})=>c);function l(c,u,d){const f=OJ(u,r,e,n),{rank:h,keyThreshold:p=o}=f;return h>=p&&c.push({...f,item:u,index:d}),c}}jm.rankings=sn;function OJ(t,e,n,r){if(!e){const s=t;return{rankedValue:s,rank:hE(s,n,r),keyIndex:-1,keyThreshold:r.threshold}}return LJ(t,e).reduce(({rank:s,rankedValue:i,keyIndex:a,keyThreshold:l},{itemValue:c,attributes:u},d)=>{let f=hE(c,n,r),h=i;const{minRanking:p,maxRanking:m,threshold:y}=u;return f<p&&f>=sn.MATCHES?f=p:f>m&&(f=m),f>s&&(s=f,a=d,l=y,h=c),{rankedValue:h,rank:s,keyIndex:a,keyThreshold:l}},{rankedValue:t,rank:sn.NO_MATCH,keyIndex:-1,keyThreshold:r.threshold})}function*RJ(t,e){let n=-1;for(;(n=t.indexOf(e,n+1))>-1;)yield n;return-1}function hE(t,e,n){if(t=pE(t,n),e=pE(e,n),e.length>t.length)return sn.NO_MATCH;if(t===e)return sn.CASE_SENSITIVE_EQUAL;t=t.toLowerCase(),e=e.toLowerCase();const r=RJ(t,e),o=r.next(),s=o.value;if(t.length===e.length&&s===0)return sn.EQUAL;if(s===0)return sn.STARTS_WITH;let i=o;for(;!i.done;){if(i.value>0&&t[i.value-1]===" ")return sn.WORD_STARTS_WITH;i=r.next()}return s>0?sn.CONTAINS:e.length===1?sn.NO_MATCH:NJ(t).includes(e)?sn.ACRONYM:_J(t,e)}function NJ(t){let e="",n=" ";for(let r=0;r<t.length;r++){const o=t.charAt(r);(n===" "||n==="-")&&!(o===" "||o==="-")&&(e+=o),n=o}return e}function _J(t,e){let n=0,r=0;function o(l,c,u){for(let d=u,f=c.length;d<f;d++)if(c[d]===l)return n+=1,d+1;return-1}function s(l){const c=1/l,u=n/e.length;return sn.MATCHES+u*c}const i=o(e[0],t,0);if(i<0)return sn.NO_MATCH;r=i;for(let l=1,c=e.length;l<c;l++){const u=e[l];if(r=o(u,t,r),!(r>-1))return sn.NO_MATCH}const a=r-i;return s(a)}function DJ(t,e,n){const{rank:s,keyIndex:i}=t,{rank:a,keyIndex:l}=e;return s===a?i===l?n(t,e):i<l?-1:1:s>a?-1:1}function pE(t,{keepDiacritics:e}){return t=`${t}`,e||(t=AJ(t)),t}function IJ(t,e){typeof e=="object"&&(e=e.key);let n;if(typeof e=="function")n=e(t);else if(t==null)n=null;else if(Object.hasOwnProperty.call(t,e))n=t[e];else{if(e.includes("."))return PJ(e,t);n=null}return n==null?[]:Array.isArray(n)?n:[String(n)]}function PJ(t,e){const n=t.split(".");let r=[e];for(let o=0,s=n.length;o<s;o++){const i=n[o];let a=[];for(let l=0,c=r.length;l<c;l++){const u=r[l];if(u!=null)if(Object.hasOwnProperty.call(u,i)){const d=u[i];d!=null&&a.push(d)}else i==="*"&&(a=a.concat(u))}r=a}return Array.isArray(r[0])?[].concat(...r):r}function LJ(t,e){const n=[];for(let r=0,o=e.length;r<o;r++){const s=e[r],i=jJ(s),a=IJ(t,s);for(let l=0,c=a.length;l<c;l++)n.push({itemValue:a[l],attributes:i})}return n}const mE={maxRanking:1/0,minRanking:-1/0};function jJ(t){return typeof t=="string"?mE:{...mE,...t}}const iR=M.forwardRef((t,e)=>{const[n,r]=M.useState(0),o=M.useRef([]),s=M.useMemo(()=>t.query?jm(t.items,t.query,{keys:["label","email"],threshold:jm.rankings.CONTAINS}):t.items,[t.items,t.query]),i=d=>{const f=s[d];f&&t.command({...f,id:f?.id,label:f?.label})},a=()=>{r(d=>(d+s.length-1)%s.length)},l=()=>{r(d=>(d+1)%s.length)},c=()=>{i(n)};M.useEffect(()=>{r(0)},[s]),M.useEffect(()=>{const d=o.current[n];d&&d.scrollIntoView({block:"nearest",behavior:"instant"})},[n]),M.useImperativeHandle(e,()=>({onKeyDown:d=>d.key==="ArrowUp"?(a(),!0):d.key==="ArrowDown"?(l(),!0):d.key==="Enter"&&s.length>0?(c(),!0):!1}));const u=t.char==="@";return g.jsxs("div",{className:"w-80 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 shadow-lg overflow-hidden",children:[g.jsx("div",{className:"px-3 py-2 border-b border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/50",children:g.jsxs("div",{className:"flex items-center gap-2",children:[g.jsx("svg",{className:"h-4 w-4 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:g.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),g.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-300",children:t.query?g.jsxs(g.Fragment,{children:["Searching for: ",g.jsx("span",{className:"font-medium",children:t.query})]}):`Search ${u?"users":"hashtags"}...`})]})}),g.jsxs("div",{className:"px-3 py-1.5 text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider bg-gray-50 dark:bg-gray-900/50",children:[u?"Users":"Hashtags"," (",s.length,")"]}),g.jsx("ul",{className:"max-h-64 overflow-y-auto",children:s.length===0?g.jsx("div",{className:"p-4 text-center text-sm text-gray-500 dark:text-gray-400",children:t.query?`No ${u?"users":"hashtags"} found for "${t.query}"`:`No ${u?"users":"hashtags"} found`}):g.jsx("div",{className:"p-1",children:s.map((d,f)=>g.jsx("li",{ref:h=>{o.current[f]=h},onClick:()=>i(f),className:`flex items-center gap-3 px-3 py-2.5 cursor-pointer rounded-md transition-colors ${n===f?"bg-blue-50 dark:bg-blue-900/20":"hover:bg-gray-50 dark:hover:bg-gray-700/50"}`,children:u?g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"h-9 w-9 flex-shrink-0 rounded-full bg-gradient-to-br from-blue-400 to-blue-600 flex items-center justify-center",children:d.avatar?g.jsx("img",{src:d.avatar,alt:d.label,className:"h-9 w-9 rounded-full object-cover"}):g.jsx("span",{className:"text-white font-medium text-sm",children:d.label?.charAt(0).toUpperCase()})}),g.jsxs("div",{className:"flex flex-col min-w-0 flex-1",children:[g.jsx("span",{className:"font-medium text-sm text-gray-900 dark:text-gray-100 truncate",children:d.label}),d.email&&g.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:d.email})]})]}):g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-md bg-gradient-to-br from-purple-400 to-purple-600",children:g.jsx("svg",{className:"h-5 w-5 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:g.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 20l4-16m2 16l4-16M6 9h14M4 15h14"})})}),g.jsxs("div",{className:"flex flex-col min-w-0 flex-1",children:[g.jsxs("span",{className:"font-medium text-sm text-gray-900 dark:text-gray-100 truncate",children:["#",d.label]}),d.count!==void 0&&g.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:[d.count.toLocaleString()," posts"]})]})]})},d.id))})}),g.jsx("div",{className:"px-3 py-2 border-t border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/50",children:g.jsxs("div",{className:"flex items-center gap-3 text-xs text-gray-500 dark:text-gray-400",children:[g.jsxs("div",{className:"flex items-center gap-1",children:[g.jsx("kbd",{className:"px-1.5 py-0.5 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded text-xs",children:"↑↓"}),g.jsx("span",{children:"Navigate"})]}),g.jsxs("div",{className:"flex items-center gap-1",children:[g.jsx("kbd",{className:"px-1.5 py-0.5 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded text-xs",children:"↵"}),g.jsx("span",{children:"Select"})]}),g.jsxs("div",{className:"flex items-center gap-1",children:[g.jsx("kbd",{className:"px-1.5 py-0.5 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded text-xs",children:"Esc"}),g.jsx("span",{children:"Close"})]})]})})]})});iR.displayName="MentionList";const $J=()=>typeof window<"u"&&window.ReactNativeWebView!==void 0,BJ=(t,e,n)=>({fetchMentions:async()=>{const s=n.getState().getMentionParams();if(!s)return console.error("DEBUG MENTION SERVICE::","No group id or post id has been provided"),[];const{groupId:i,postId:a}=s;return console.log({groupId:i,postId:a}),(a?await e.getRecommendationPost(i,a,0,999):await e.getRecommendationGroup(i,0,999)).entries?.filter(c=>!!c?.user_data)?.map(c=>({id:c?.user_data?.id,label:c?.user_data?.name,avatar:c?.user_data?.avatar,inThisThread:1,name:c?.user_data?.name,selectId:c.user_data?.username,type:Ep.User,from:lu.Post}))},fetchHashtags:async()=>{const{selectedGroupId:s,groupId:i}=n.getState(),a=s??i;return a?(await t.fetchGroupConversations(999,0)).entries.filter(c=>c?.group_id!==a).map(c=>({id:c?.group_id,label:c?.group?.name,avatar:c?.group?.avatar,inThisThread:1,name:c?.group?.name,selectId:c?.group?.select_id,type:Ep.Group,from:lu.Post,isCrossExposureEnable:c?.group?.allow_cross_exposure})):(console.warn("DEBUG HASHTAG SERVICE::","No active group selected or provided"),[])}});function gE(t,e){return{char:t,items:async()=>await e(),render:()=>{let n,r;return{onStart:o=>{n=new ny(iR,{props:{...o,char:t},editor:o.editor}),o.clientRect&&(r=Zl("body",{getReferenceClientRect:o.clientRect,appendTo:()=>document.body,theme:"select-post-builder",content:n.element,showOnCreate:!0,interactive:!0,trigger:"manual",placement:"bottom-start"}))},onUpdate(o){n.updateProps({...o,char:t}),o.clientRect&&r[0].setProps({getReferenceClientRect:o.clientRect})},onKeyDown(o){return o.event.key==="Escape"?(r[0].hide(),!0):n?.ref?.onKeyDown(o.event)??!1},onExit(){r[0].destroy(),n.destroy()}}}}}const FJ=(t,e,n)=>{const r=BJ(t,e,n);return kJ.configure({HTMLAttributes:{class:"inline-block px-1.5 py-0.5 rounded font-medium no-underline cursor-pointer transition-all duration-200"},renderText({node:o,suggestion:s}){return`${s?.char??"@"}${o.attrs.label??o.attrs.id}`},renderHTML({node:o,suggestion:s,isFocused:i}){const a=s?.char??"@",l=o.attrs.label??o.attrs.id,c=o.attrs.id,u=$J(),f={"data-type":"mention","data-id":c,"data-label":l,"data-mention-suggestion-char":a,class:a==="@"?"inline-block px-1.5 py-0.5 rounded font-medium cursor-pointer transition-all duration-200 bg-blue-100 text-blue-700 hover:bg-blue-200 dark:bg-blue-900/30 dark:text-blue-300 dark:hover:bg-blue-900/50":"inline-block px-1.5 py-0.5 rounded font-medium cursor-pointer transition-all duration-200 bg-purple-100 text-purple-700 hover:bg-purple-200 dark:bg-purple-900/30 dark:text-purple-300 dark:hover:bg-purple-900/50"};if(u){const p=a==="@"?`window.ReactNativeWebView.postMessage(JSON.stringify({type: 'mention', userId: '${c}'}))`:`window.ReactNativeWebView.postMessage(JSON.stringify({type: 'hashtag', groupId: '${c}'}))`;return["span",{...f,onclick:p},`${a}${l}`]}const h=a==="@"?`/user/${c}`:`/hashtag/${c}`;return["a",{...f,...i?{}:{href:h,target:"_blank"},"data-mention-link":"true"},`${a}${l}`]},suggestions:[gE("@",r.fetchMentions),gE("#",r.fetchHashtags)]})};function HJ({className:t,...e}){return g.jsx("div",{"data-slot":"skeleton",className:re("bg-accent animate-pulse rounded-md",t),...e})}const UJ=({selected:t,href:e,title:n,description:r,image:o,domain:s,onClickDelete:i})=>{const a=b.useMemo(()=>{try{return s||new URL(e).hostname}catch{return"unknown"}},[e,s]),l=c=>{c.preventDefault(),c.stopPropagation(),i()};return g.jsxs("div",{className:re("not-prose relative w-full group my-4",t?"ring-2 ring-blue-500 ring-offset-2 rounded-lg":""),children:[g.jsxs("div",{className:"flex items-center gap-2 absolute z-50 right-2 top-1",children:[g.jsx(be,{asChild:!0,tooltip:"Visit Link",children:g.jsxs("span",{className:"relative",children:[g.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"absolute inset-0"}),g.jsx(sl,{})]})}),g.jsx(be,{tooltip:"Remove Link Preview",onClick:l,"aria-label":"Delete link preview",type:"button",size:"icon",className:"cursor-pointer size-6 shadow-none bg-transparent group-hover:bg-destructive/5 hover:bg-destructive/10 text-destructive hover:text-destructive",children:g.jsx(by,{})})]}),g.jsx("div",{className:"relative z-0 w-full",children:g.jsxs("div",{className:"group flex items-center gap-3 rounded-lg border bg-accent/30 p-3 transition-all hover:border-foreground/20 hover:shadow-sm",children:[g.jsx("div",{className:"relative h-16 w-16 flex-shrink-0 overflow-hidden rounded-md bg-muted",children:g.jsx("img",{src:o,alt:n,className:"size-16 object-cover transition-transform group-hover:scale-105"})}),g.jsxs("div",{className:"min-w-0 flex-1",children:[g.jsx("h3",{className:"truncate text-sm font-semibold leading-tight text-foreground",children:n}),g.jsx("p",{className:"line-clamp-1 text-xs text-muted-foreground",children:r}),g.jsxs("div",{className:"mt-1 flex items-center gap-1 text-xs text-muted-foreground",children:[g.jsx("span",{className:"truncate",children:a}),g.jsx(sl,{className:"h-3 w-3 flex-shrink-0 opacity-50"})]})]})]})})]})},zJ=({selected:t,href:e,title:n,description:r,image:o,domain:s,onClickDelete:i})=>{const a=b.useMemo(()=>{try{return s||new URL(e).hostname}catch{return"unknown"}},[e,s]),l=c=>{c.preventDefault(),c.stopPropagation(),i()};return g.jsxs("div",{className:re("not-prose relative w-full group mt-4",t?"ring-2 ring-blue-500 ring-offset-2 rounded-lg":""),children:[g.jsxs("div",{className:"flex items-center gap-2 absolute z-50 right-3 top-3",children:[g.jsx(be,{asChild:!0,tooltip:"Visit Link",className:"cursor-pointer backdrop-blur-2xl size-6 shadow-none group-hover:bg-accent/70 group-hover:text-accent-foreground text-primary-send",children:g.jsxs("span",{className:"relative",children:[g.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"absolute inset-0"}),g.jsx(sl,{})]})}),g.jsx(be,{tooltip:"Remove Link Preview",onClick:l,"aria-label":"Delete link preview",type:"button",size:"icon",className:"cursor-pointer backdrop-blur-2xl size-6 shadow-none bg-transparent group-hover:bg-red-50/70 hover:bg-red-50 text-destructive hover:text-destructive",children:g.jsx(by,{})})]}),g.jsx("div",{className:"relative z-0 w-full",children:g.jsxs("div",{className:"group overflow-hidden flex flex-col rounded-lg border bg-accent/30 transition-all hover:border-foreground/20 hover:shadow-sm",children:[g.jsx("div",{className:"relative h-80 w-full flex-shrink-0 overflow-hidden bg-muted border-b",children:g.jsx("img",{src:o,alt:n,className:"size-full object-cover transition-transform group-hover:scale-105"})}),g.jsxs("div",{className:"min-w-0 flex-1 p-3",children:[g.jsxs("div",{className:"mt-1 flex items-center gap-1 text-xs text-muted-foreground",children:[g.jsx("span",{className:"truncate",children:a}),g.jsx(sl,{className:"h-3 w-3 flex-shrink-0 opacity-50"})]}),g.jsx("h3",{className:"mt-1 mb-2 truncate text-lg font-semibold leading-tight text-foreground",children:n}),g.jsx("p",{className:"line-clamp-2 text-sm text-muted-foreground",children:r})]})]})})]})},VJ=({node:t,deleteNode:e,selected:n})=>{const{loading:r,href:o,domain:s,variant:i}=t.attrs,a=b.useMemo(()=>{try{return s||new URL(o).hostname}catch{return"unknown"}},[o,s]);return r?g.jsx(Qo,{children:g.jsx(HJ,{className:"w-full h-24 flex items-center justify-center rounded-lg",children:g.jsx("span",{className:"text-sm text-muted-foreground",children:"Fetching Link Metadata..."})})}):o?g.jsx(Qo,{contentEditable:!1,"data-drag-handle":!0,children:i===Id.Compact?g.jsx(UJ,{...t.attrs,selected:n,domain:a,onClickDelete:e}):g.jsx(zJ,{...t.attrs,selected:n,domain:a,onClickDelete:e})}):null},aR=_t.create({name:"linkPreview",group:"block",atom:!0,addOptions(){return{variant:Id.Compact,selectable:!0,draggable:!0}},draggable(){return this?.options?.draggable??!0},selectable(){return this?.options?.selectable??!0},addAttributes(){return{variant:{default:this.options.variant},uid:{default:null},href:{default:null},title:{default:null},description:{default:null},image:{default:null},domain:{default:null},loading:{default:!1}}},parseHTML(){return[{tag:"div[data-link-preview]",getAttrs:t=>{if(typeof t=="string")return!1;const e=t,n=e.querySelector("a");return{href:e.getAttribute("data-href")||n?.getAttribute("href")||"",uid:e.getAttribute("data-uid")||null,title:e.getAttribute("data-title")||null,description:e.getAttribute("data-description")||null,image:e.getAttribute("data-image")||null,domain:e.getAttribute("data-domain")||null}}}]},renderHTML({node:t}){const{href:e,uid:n,title:r,description:o,image:s,domain:i}=t.attrs;if(console.log("INSIDE RENDER HTML::",{href:e,image:s}),!e)return["div",{}];const a=[["a",{href:e,target:"_blank",rel:"noopener noreferrer",class:"absolute inset-0 z-30","aria-label":r||e}],["div",{class:"relative z-20 flex items-center gap-3 w-full"},...s?[["div",{class:"relative h-16 w-16 flex-shrink-0 overflow-hidden rounded-md bg-muted"},["img",{src:s,alt:r||"",class:"h-full w-full object-cover transition-transform group-hover:scale-105"}]]]:[],["div",{class:"min-w-0 flex-1"},...r?[["h3",{class:"truncate text-sm font-semibold leading-tight text-foreground"},r]]:[],...o?[["p",{class:"line-clamp-1 text-xs text-muted-foreground"},o]]:[],...i?[["div",{class:"mt-1 flex items-center gap-1 text-xs text-muted-foreground"},["span",{class:"truncate"},i]]]:[]]]];return["div",{"data-link-preview":"","data-href":e,"data-uid":n||"","data-title":r||"","data-description":o||"","data-image":s||"","data-domain":i||"",class:"not-prose my-4 relative group flex items-center gap-3 rounded-lg border bg-card p-3 transition-all hover:border-foreground/20 hover:shadow-sm"},...a]},addNodeView(){return Bl(VJ)},addCommands(){return{setLinkPreview:t=>({commands:e})=>e.insertContent({type:this.name,attrs:t}),updateLinkPreviewByUid:fO(this.name),deleteLinkPreviewByUid:dO(this.name),updateLinkPreview:t=>({commands:e})=>e.updateAttributes(this.name,t)}},addKeyboardShortcuts(){return{"Mod-Shift-k":()=>this.editor.commands.setLinkPreview({href:"",title:null,description:null,image:null,domain:null}),Backspace:()=>{const{selection:t}=this.editor.state,{$anchor:e}=t;return e.parent.type.name===this.name&&e.parentOffset===0?this.editor.commands.deleteNode(this.name):!1}}}}),yv=Qe.create({name:"customEnterHardBreak",addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.setHardBreak()}}}),WJ=({node:t,editor:e})=>{const n=o=>{e.commands.deleteMediaByUid(o)},r=t?.content?.content||[];return console.log("MediaGroupView render:",{contentSize:t?.content?.size,mediaCount:r?.length,nodes:r?.map(o=>({type:o?.type?.name,uid:o?.attrs?.uid}))}),r.length===0?g.jsxs(Qo,{className:"media-group-wrapper",children:[g.jsx("div",{className:"flex flex-wrap gap-2 p-8 bg-muted/30 rounded-lg border border-dashed border-border mt-4",children:g.jsx("p",{className:"text-sm text-muted-foreground w-full text-center",children:"No media added yet"})}),g.jsx("div",{className:"hidden",children:g.jsx($0,{})})]}):g.jsx(Qo,{className:"not-prose media-group-wrapper select-none leading-none mt-12",contentEditable:!1,children:g.jsxs("div",{className:"flex flex-wrap gap-2 leading-none mt-auto",children:[r.map((o,s)=>{const i=o?.attrs?.uploading,a=o?.attrs?.progress||0;return g.jsxs("div",{className:"relative group leading-none",children:[g.jsx(Zn,{size:"icon",onClick:()=>n(o.attrs.uid),className:"absolute size-6 top-1 right-1 z-10 p-1.5 bg-red-50 hover:bg-red-100 text-destructive rounded-full shadow-lg transition-all opacity-100 group-hover:scale-110",title:"Delete media",children:g.jsx(Wl,{className:"w-3.5 h-3.5"})}),i?g.jsxs("div",{className:"size-20 bg-muted rounded-lg border border-border flex items-center justify-center relative overflow-hidden",children:[g.jsxs("div",{className:"text-center space-y-2",children:[o.attrs.type===xe.Image&&g.jsx(vy,{className:"w-8 h-8 text-muted-foreground/50 mx-auto"}),o.attrs.type===xe.Video&&g.jsx(xy,{className:"w-8 h-8 text-muted-foreground/50 mx-auto"}),o.attrs.type===xe.Audio&&g.jsx(Ru,{className:"w-8 h-8 text-muted-foreground/50 mx-auto"}),g.jsxs("p",{className:"text-xs text-muted-foreground",children:[Math.round(a),"%"]})]}),g.jsx("div",{className:"absolute bottom-0 left-0 right-0 p-2",children:g.jsx(cO,{value:a,className:"h-1"})})]}):g.jsxs(g.Fragment,{children:[o.attrs.type===xe.Image&&g.jsx("img",{src:o.attrs.src,alt:o.attrs.caption||"",className:"size-20 object-cover rounded-lg border border-border"}),o.attrs.type===xe.Video&&g.jsx("video",{src:o.attrs.src,className:"size-20 object-cover rounded-lg border border-border"}),o.attrs.type===xe.Audio&&g.jsx("div",{className:"size-20 flex items-center justify-center bg-accent rounded-lg border border-border",children:g.jsx(Ru,{className:"w-8 h-8 text-muted-foreground"})})]}),o.attrs.caption&&!i&&g.jsx("p",{className:"text-xs text-muted-foreground text-center mt-1 truncate w-32",children:o.attrs.caption})]},o?.attrs?.uid||s)}),g.jsx("div",{className:"hidden",children:g.jsx($0,{})})]})})},GJ=new We("mediaMode"),qJ=()=>{let t=!1;return new Ue({key:GJ,appendTransaction(e,n,r){if(t||!e.some(s=>s.docChanged)||e.some(s=>s.getMeta("mediaMode-plugin"))||e.some(s=>s.getMeta("addToHistory")===!1))return null;try{t=!0;const s=r.tr;let i=!1;const a=[];if(r.doc.forEach((u,d)=>{u.type.name==="media"&&a.push({node:u,pos:d,size:u.nodeSize})}),a.length===0)return r.doc.forEach((u,d)=>{u.type.name==="mediaGroup"&&u.content.size===0&&(s.delete(d,d+u.nodeSize),i=!0)}),i&&(s.setMeta("addToHistory",!1),s.setMeta("mediaMode-plugin",!0)),i?s:null;let l=null,c=null;if(r.doc.forEach((u,d)=>{u.type.name==="mediaGroup"&&(l=d,c=u)}),l!==null&&c){const u=c.content.size;[...a].sort((v,w)=>w.pos-v.pos).forEach(({pos:v,size:w})=>{s.delete(v,v+w)});const h=a.filter(v=>v.pos<l).reduce((v,w)=>v+w.size,0),m=l-h+1+u;let y=0;a.forEach(({node:v})=>{s.insert(m+y,v),y+=v.nodeSize}),i=!0}else{if(!r.schema.nodes.mediaGroup)return null;const u=a.map(h=>h.node);if(u.some(h=>!h||h.type.name!=="media"))return console.warn("Invalid media nodes detected, skipping group creation"),null;const d=r.schema.nodes.mediaGroup.create({},u);[...a].sort((h,p)=>p.pos-h.pos).forEach(({pos:h,size:p})=>{s.delete(h,h+p)}),s.insert(s.doc.content.size,d),i=!0}if(i){const u=s.doc.content.size;if(u>=0&&u<=s.doc.content.size)try{const d=s.doc.resolve(u);s.setSelection(pe.near(d))}catch(d){console.warn("Could not set selection:",d)}s.setMeta("addToHistory",!1),s.setMeta("mediaMode-plugin",!0)}return i?s:null}catch(s){return console.error("MediaMode plugin error:",s),null}finally{t=!1}}})},KJ=_t.create({name:"mediaGroup",group:"block",content:"media*",atom:!1,selectable:!1,draggable:!1,addOptions(){return{mediaMode:!1}},parseHTML(){return[{tag:"div[data-media-group]"}]},renderHTML({HTMLAttributes:t}){return["div",Be(t,{"data-media-group":""}),0]},addNodeView(){return Bl(WJ)},addProseMirrorPlugins(){return this.options.mediaMode?[qJ()]:[]}}),YJ={class:"bg-muted text-foreground border border-border font-mono leading-snug rounded px-0.5 py-px after:content-none before:content-none"},JJ={class:"bg-muted text-foreground border border-border font-mono leading-snug rounded"},vv=t=>z9.extend({content:t}),XJ=vv("paragraph poll"),QJ=vv("paragraph media? mediaGroup?"),ZJ=vv("paragraph linkPreview?"),eX=({includeLink:t=!1,includeDocument:e=!0})=>({...e?{}:{document:!1},...t?{}:{link:!1},code:{HTMLAttributes:YJ},codeBlock:{HTMLAttributes:JJ}}),Af=t=>rK.configure({placeholder:t,showOnlyWhenEditable:!0}),Mf=(t,e,n)=>FJ(t,e,n),tX=({editorType:t,api:e,store:n,user:r})=>{const s={[gt.Text]:nX,[gt.Media]:oX,[gt.Link]:sX,[gt.Poll]:rX}[t];return s?s({api:e,store:n,user:r}):[]},nX=({api:t,store:e,user:n})=>{const{core:r,mfs:o,fileStore:s}=t;return[aK.configure(eX({includeLink:!1})),Af(`What's on your mind, ${n?.name?n?.name:""}`),dK,hK,cK.configure({types:["heading","paragraph","media"],alignments:[tt.LEFT,tt.CENTER,tt.RIGHT],defaultAlignment:tt.LEFT}),hO,gO,D7,AO.configure({openOnClick:!1,linkOnPaste:!1,api:r}),aR,Mf(r,o,e),jO.configure({api:s}),PO.configure({api:r})]},rX=({api:t,store:e})=>{const{core:n,mfs:r}=t;return[XJ,nv,rv,ev,Vy,Af("Ask a Question"),yv,gO,Mf(n,r,e)]},oX=({api:t,store:e,user:n})=>{const{core:r,mfs:o,fileStore:s}=t;return[QJ,nv,rv,ev,Vy,Af(`What's on your mind, ${n?.name?n?.name:""}`),yv,hO.configure({attrs:{mediaMode:!0}}),KJ.configure({mediaMode:!0}),Mf(r,o,e),jO.configure({api:s})]},sX=({api:t,store:e,user:n})=>{const{core:r,mfs:o}=t;return[ZJ,nv,rv,Vy,Af(`What's on your mind, ${n?.name?n?.name:""}`),yv,AO.configure({openOnClick:!1,linkOnPaste:!1,api:r,linkMode:!0}),aR.configure({variant:Id.Extended,selectable:!1,draggable:!1}),PO.configure({api:r,autoEmbed:!1,autoLinkSelection:!1}),Mf(r,o,e)]},iX=()=>({attributes:{class:re("max-w-full prose prose-sm sm:prose-base px-4 py-2 prose-img:my-3 prose-figcaption:text-xs prose-code:text-sm prose-codeblock:text-sm prose-a:text-blue-500 focus:outline-none")}}),aX=t=>({undo:()=>t?.chain().focus().undo().run(),redo:()=>t?.chain().focus().redo().run(),toggleHeading:e=>t?.chain().focus().toggleHeading({level:e}).run(),setParagraph:()=>t?.chain().focus().setParagraph().run(),toggleBold:()=>t?.chain().focus().toggleBold().run(),toggleItalic:()=>t?.chain().focus().toggleItalic().run(),toggleStrikethrough:()=>t?.chain().focus().toggleStrike().run(),toggleUnderline:()=>t?.chain().focus().toggleUnderline().run(),insertLink:e=>t?.chain().focus().setLink({href:e}).run(),toggleBulletList:()=>t?.chain().focus().toggleBulletList().run(),toggleOrderedList:()=>t?.chain().focus().toggleOrderedList().run(),toggleCode:()=>t?.chain().focus().toggleCode().run(),toggleCodeBlock:()=>t?.chain().focus().toggleCodeBlock().run(),toggleTextAlign:e=>t?.chain().focus().setTextAlign(e).run(),insertPoll:()=>t?.chain().focus().insertContent({type:"poll"}).run(),insertMedia:(e,n)=>{t?.chain()?.focus()?.insertContent([{type:"media",attrs:{src:e,type:n}},{type:"paragraph"}])?.run()}}),lX=t=>{t.chain().focus().insertContent({type:"paragraph"}).insertContent({type:"poll"}).command(({tr:e})=>{const{doc:n}=e;let r=-1;if(n.descendants((o,s)=>{if(o.type.name==="paragraph"&&r===-1)return r=s,!1}),r>=0){const o=n.nodeAt(r);if(o){const s=r+o.nodeSize-1,i=e.doc.resolve(s);e.setSelection(pe.near(i))}}return!0}).run()},cX=({editorType:t,groupId:e,postId:n,user:r})=>{const[,o]=M.useState(0),s=Dl(),i=M.useMemo(()=>O9({groupId:e,postId:n}),[e,n]),{getTabContent:a}=ry();M.useEffect(()=>{o(u=>u+1)},[]);const l=jF({extensions:tX({editorType:t,api:s,store:i,user:r}),content:"",editorProps:iX(),onCreate:({editor:u})=>{i.getState().setEditor(u),t===gt.Poll&&lX(u)},immediatelyRender:!1},[t]);M.useEffect(()=>{const u=a(t);u&&l?.isEditable&&l.commands.setContent(u)},[l,t,a]);const c=aX(l);return{editor:l,actions:c,store:i}},fr=()=>new Map,$m=t=>{const e=fr();return t.forEach((n,r)=>{e.set(r,n)}),e},ko=(t,e,n)=>{let r=t.get(e);return r===void 0&&t.set(e,r=n()),r},uX=(t,e)=>{const n=[];for(const[r,o]of t)n.push(e(o,r));return n},dX=(t,e)=>{for(const[n,r]of t)if(e(r,n))return!0;return!1},Us=()=>new Set,ip=t=>t[t.length-1],fX=(t,e)=>{for(let n=0;n<e.length;n++)t.push(e[n])},zs=Array.from,hX=(t,e)=>{for(let n=0;n<t.length;n++)if(e(t[n],n,t))return!0;return!1},Bm=Array.isArray;class lR{constructor(){this._observers=fr()}on(e,n){return ko(this._observers,e,Us).add(n),n}once(e,n){const r=(...o)=>{this.off(e,r),n(...o)};this.on(e,r)}off(e,n){const r=this._observers.get(e);r!==void 0&&(r.delete(n),r.size===0&&this._observers.delete(e))}emit(e,n){return zs((this._observers.get(e)||fr()).values()).forEach(r=>r(...n))}destroy(){this._observers=fr()}}const bo=Math.floor,tu=Math.abs,Ui=(t,e)=>t<e?t:e,ns=(t,e)=>t>e?t:e,cR=t=>t!==0?t<0:1/t<0,yE=1,vE=2,ap=4,lp=8,yl=32,co=64,an=128,pX=1<<29,Of=31,Fm=63,Ns=127,mX=2147483647,uR=Number.MAX_SAFE_INTEGER,gX=Number.isInteger||(t=>typeof t=="number"&&isFinite(t)&&bo(t)===t),yX=String.fromCharCode,vX=t=>t.toLowerCase(),bX=/^\s*/g,xX=t=>t.replace(bX,""),wX=/([A-Z])/g,bE=(t,e)=>xX(t.replace(wX,n=>`${e}${vX(n)}`)),EX=t=>{const e=unescape(encodeURIComponent(t)),n=e.length,r=new Uint8Array(n);for(let o=0;o<n;o++)r[o]=e.codePointAt(o);return r},vl=typeof TextEncoder<"u"?new TextEncoder:null,SX=t=>vl.encode(t),kX=vl?SX:EX;let Va=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Va&&Va.decode(new Uint8Array).length===1&&(Va=null);class ec{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const tc=()=>new ec,TX=t=>{const e=tc();return t(e),dr(e)},CX=t=>{let e=t.cpos;for(let n=0;n<t.bufs.length;n++)e+=t.bufs[n].length;return e},dr=t=>{const e=new Uint8Array(CX(t));let n=0;for(let r=0;r<t.bufs.length;r++){const o=t.bufs[r];e.set(o,n),n+=o.length}return e.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),n),e},AX=(t,e)=>{const n=t.cbuf.length;n-t.cpos<e&&(t.bufs.push(new Uint8Array(t.cbuf.buffer,0,t.cpos)),t.cbuf=new Uint8Array(ns(n,e)*2),t.cpos=0)},Pt=(t,e)=>{const n=t.cbuf.length;t.cpos===n&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(n*2),t.cpos=0),t.cbuf[t.cpos++]=e},Hm=Pt,$e=(t,e)=>{for(;e>Ns;)Pt(t,an|Ns&e),e=bo(e/128);Pt(t,Ns&e)},bv=(t,e)=>{const n=cR(e);for(n&&(e=-e),Pt(t,(e>Fm?an:0)|(n?co:0)|Fm&e),e=bo(e/64);e>0;)Pt(t,(e>Ns?an:0)|Ns&e),e=bo(e/128)},Um=new Uint8Array(3e4),MX=Um.length/3,OX=(t,e)=>{if(e.length<MX){const n=vl.encodeInto(e,Um).written||0;$e(t,n);for(let r=0;r<n;r++)Pt(t,Um[r])}else Rn(t,kX(e))},RX=(t,e)=>{const n=unescape(encodeURIComponent(e)),r=n.length;$e(t,r);for(let o=0;o<r;o++)Pt(t,n.codePointAt(o))},Si=vl&&vl.encodeInto?OX:RX,Rf=(t,e)=>{const n=t.cbuf.length,r=t.cpos,o=Ui(n-r,e.length),s=e.length-o;t.cbuf.set(e.subarray(0,o),r),t.cpos+=o,s>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(ns(n*2,s)),t.cbuf.set(e.subarray(o)),t.cpos=s)},Rn=(t,e)=>{$e(t,e.byteLength),Rf(t,e)},xv=(t,e)=>{AX(t,e);const n=new DataView(t.cbuf.buffer,t.cpos,e);return t.cpos+=e,n},NX=(t,e)=>xv(t,4).setFloat32(0,e,!1),_X=(t,e)=>xv(t,8).setFloat64(0,e,!1),DX=(t,e)=>xv(t,8).setBigInt64(0,e,!1),xE=new DataView(new ArrayBuffer(4)),IX=t=>(xE.setFloat32(0,t),xE.getFloat32(0)===t),zi=(t,e)=>{switch(typeof e){case"string":Pt(t,119),Si(t,e);break;case"number":gX(e)&&tu(e)<=mX?(Pt(t,125),bv(t,e)):IX(e)?(Pt(t,124),NX(t,e)):(Pt(t,123),_X(t,e));break;case"bigint":Pt(t,122),DX(t,e);break;case"object":if(e===null)Pt(t,126);else if(Bm(e)){Pt(t,117),$e(t,e.length);for(let n=0;n<e.length;n++)zi(t,e[n])}else if(e instanceof Uint8Array)Pt(t,116),Rn(t,e);else{Pt(t,118);const n=Object.keys(e);$e(t,n.length);for(let r=0;r<n.length;r++){const o=n[r];Si(t,o),zi(t,e[o])}}break;case"boolean":Pt(t,e?120:121);break;default:Pt(t,127)}};class wE extends ec{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&$e(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const EE=t=>{t.count>0&&(bv(t.encoder,t.count===1?t.s:-t.s),t.count>1&&$e(t.encoder,t.count-2))};class nu{constructor(){this.encoder=new ec,this.s=0,this.count=0}write(e){this.s===e?this.count++:(EE(this),this.count=1,this.s=e)}toUint8Array(){return EE(this),dr(this.encoder)}}const SE=t=>{if(t.count>0){const e=t.diff*2+(t.count===1?0:1);bv(t.encoder,e),t.count>1&&$e(t.encoder,t.count-2)}};class cp{constructor(){this.encoder=new ec,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(SE(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return SE(this),dr(this.encoder)}}class PX{constructor(){this.sarr=[],this.s="",this.lensE=new nu}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 ec;return this.sarr.push(this.s),this.s="",Si(e,this.sarr.join("")),Rf(e,this.lensE.toUint8Array()),dr(e)}}const rs=t=>new Error(t),hr=()=>{throw rs("Method unimplemented")},Mn=()=>{throw rs("Unexpected case")},dR=rs("Unexpected end of array"),fR=rs("Integer out of Range");class Nf{constructor(e){this.arr=e,this.pos=0}}const wv=t=>new Nf(t),LX=t=>t.pos!==t.arr.length,jX=(t,e)=>{const n=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,n},Vn=t=>jX(t,st(t)),bl=t=>t.arr[t.pos++],st=t=>{let e=0,n=1;const r=t.arr.length;for(;t.pos<r;){const o=t.arr[t.pos++];if(e=e+(o&Ns)*n,n*=128,o<an)return e;if(e>uR)throw fR}throw dR},Ev=t=>{let e=t.arr[t.pos++],n=e&Fm,r=64;const o=(e&co)>0?-1:1;if((e&an)===0)return o*n;const s=t.arr.length;for(;t.pos<s;){if(e=t.arr[t.pos++],n=n+(e&Ns)*r,r*=128,e<an)return o*n;if(n>uR)throw fR}throw dR},$X=t=>{let e=st(t);if(e===0)return"";{let n=String.fromCodePoint(bl(t));if(--e<100)for(;e--;)n+=String.fromCodePoint(bl(t));else for(;e>0;){const r=e<1e4?e:1e4,o=t.arr.subarray(t.pos,t.pos+r);t.pos+=r,n+=String.fromCodePoint.apply(null,o),e-=r}return decodeURIComponent(escape(n))}},BX=t=>Va.decode(Vn(t)),zm=Va?BX:$X,Sv=(t,e)=>{const n=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,e);return t.pos+=e,n},FX=t=>Sv(t,4).getFloat32(0,!1),HX=t=>Sv(t,8).getFloat64(0,!1),UX=t=>Sv(t,8).getBigInt64(0,!1),zX=[t=>{},t=>null,Ev,FX,HX,UX,t=>!1,t=>!0,zm,t=>{const e=st(t),n={};for(let r=0;r<e;r++){const o=zm(t);n[o]=gd(t)}return n},t=>{const e=st(t),n=[];for(let r=0;r<e;r++)n.push(gd(t));return n},Vn],gd=t=>zX[127-bl(t)](t);class kE extends Nf{constructor(e,n){super(e),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),LX(this)?this.count=st(this)+1:this.count=-1),this.count--,this.s}}class ru extends Nf{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=Ev(this);const e=cR(this.s);this.count=1,e&&(this.s=-this.s,this.count=st(this)+2)}return this.count--,this.s}}class up extends Nf{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const e=Ev(this),n=e&1;this.diff=bo(e/2),this.count=1,n&&(this.count=st(this)+2)}return this.s+=this.diff,this.count--,this.s}}class VX{constructor(e){this.decoder=new ru(e),this.str=zm(this.decoder),this.spos=0}read(){const e=this.spos+this.decoder.read(),n=this.str.slice(this.spos,e);return this.spos=e,n}}const WX=crypto.getRandomValues.bind(crypto),GX=Math.random,hR=()=>WX(new Uint32Array(1))[0],qX=t=>t[bo(GX()*t.length)],KX="10000000-1000-4000-8000"+-1e11,YX=()=>KX.replace(/[018]/g,t=>(t^hR()&15>>t/4).toString(16)),JX=Date.now,TE=t=>new Promise(t);Promise.all.bind(Promise);const CE=t=>t===void 0?null:t;class XX{constructor(){this.map=new Map}setItem(e,n){this.map.set(e,n)}getItem(e){return this.map.get(e)}}let pR=new XX,QX=!0;try{typeof localStorage<"u"&&localStorage&&(pR=localStorage,QX=!1)}catch{}const ZX=pR,eQ=Object.assign,mR=Object.keys,tQ=(t,e)=>{for(const n in t)e(t[n],n)},AE=t=>mR(t).length,nQ=t=>{for(const e in t)return!1;return!0},gR=(t,e)=>{for(const n in t)if(!e(t[n],n))return!1;return!0},rQ=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),oQ=(t,e)=>t===e||AE(t)===AE(e)&&gR(t,(n,r)=>(n!==void 0||rQ(e,r))&&e[r]===n),sQ=Object.freeze,yR=t=>{for(const e in t){const n=t[e];(typeof n=="object"||typeof n=="function")&&yR(t[e])}return sQ(t)},kv=(t,e,n=0)=>{try{for(;n<t.length;n++)t[n](...e)}finally{n<t.length&&kv(t,e,n+1)}},iQ=(t,e)=>e.includes(t),Vi=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",vR=typeof window<"u"&&typeof document<"u"&&!Vi;let Rr;const aQ=()=>{if(Rr===void 0)if(Vi){Rr=fr();const t=process.argv;let e=null;for(let n=0;n<t.length;n++){const r=t[n];r[0]==="-"?(e!==null&&Rr.set(e,""),e=r):e!==null&&(Rr.set(e,r),e=null)}e!==null&&Rr.set(e,"")}else typeof location=="object"?(Rr=fr(),(location.search||"?").slice(1).split("&").forEach(t=>{if(t.length!==0){const[e,n]=t.split("=");Rr.set(`--${bE(e,"-")}`,n),Rr.set(`-${bE(e,"-")}`,n)}})):Rr=fr();return Rr},Vm=t=>aQ().has(t),yd=t=>CE(Vi?process.env[t.toUpperCase().replaceAll("-","_")]:ZX.getItem(t)),bR=t=>Vm("--"+t)||yd(t)!==null;bR("production");const lQ=Vi&&iQ(process.env.FORCE_COLOR,["true","1","2"]),cQ=lQ||!Vm("--no-colors")&&!bR("no-color")&&(!Vi||process.stdout.isTTY)&&(!Vi||Vm("--color")||yd("COLORTERM")!==null||(yd("TERM")||"").includes("color")),uQ=t=>{let e="";for(let n=0;n<t.byteLength;n++)e+=yX(t[n]);return btoa(e)},dQ=t=>Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("base64"),fQ=vR?uQ:dQ,hQ=t=>TX(e=>zi(e,t));class pQ{constructor(e,n){this.left=e,this.right=n}}const Zr=(t,e)=>new pQ(t,e),mQ=typeof document<"u"?document:{};typeof DOMParser<"u"&&new DOMParser;const gQ=t=>uX(t,(e,n)=>`${n}:${e};`).join(""),yQ=t=>class{constructor(n){this._=n}destroy(){t(this._)}},vQ=yQ(clearTimeout),xR=(t,e)=>new vQ(setTimeout(e,t)),To=Symbol,wR=To(),ER=To(),bQ=To(),xQ=To(),wQ=To(),SR=To(),EQ=To(),Tv=To(),SQ=To(),kQ=t=>{t.length===1&&t[0]?.constructor===Function&&(t=t[0]());const e=[],n=[];let r=0;for(;r<t.length;r++){const o=t[r];if(o===void 0)break;if(o.constructor===String||o.constructor===Number)e.push(o);else if(o.constructor===Object)break}for(r>0&&n.push(e.join(""));r<t.length;r++){const o=t[r];o instanceof Symbol||n.push(o)}return n},TQ={[wR]:Zr("font-weight","bold"),[ER]:Zr("font-weight","normal"),[bQ]:Zr("color","blue"),[wQ]:Zr("color","green"),[xQ]:Zr("color","grey"),[SR]:Zr("color","red"),[EQ]:Zr("color","purple"),[Tv]:Zr("color","orange"),[SQ]:Zr("color","black")},CQ=t=>{t.length===1&&t[0]?.constructor===Function&&(t=t[0]());const e=[],n=[],r=fr();let o=[],s=0;for(;s<t.length;s++){const i=t[s],a=TQ[i];if(a!==void 0)r.set(a.left,a.right);else{if(i===void 0)break;if(i.constructor===String||i.constructor===Number){const l=gQ(r);s>0||l.length>0?(e.push("%c"+i),n.push(l)):e.push(i)}else break}}for(s>0&&(o=n,o.unshift(e.join("")));s<t.length;s++){const i=t[s];i instanceof Symbol||o.push(i)}return o},kR=cQ?CQ:kQ,AQ=(...t)=>{console.log(...kR(t)),CR.forEach(e=>e.print(t))},TR=(...t)=>{console.warn(...kR(t)),t.unshift(Tv),CR.forEach(e=>e.print(t))},CR=Us(),AR=t=>({[Symbol.iterator](){return this},next:t}),MQ=(t,e)=>AR(()=>{let n;do n=t.next();while(!n.done&&!e(n.value));return n}),dp=(t,e)=>AR(()=>{const{done:n,value:r}=t.next();return{done:n,value:n?void 0:e(r)}});class Cv{constructor(e,n){this.clock=e,this.len=n}}class ra{constructor(){this.clients=new Map}}const ss=(t,e,n)=>e.clients.forEach((r,o)=>{const s=t.doc.store.clients.get(o);if(s!=null){const i=s[s.length-1],a=i.id.clock+i.length;for(let l=0,c=r[l];l<r.length&&c.clock<a;c=r[++l])PR(t,s,c.clock,c.len,n)}}),OQ=(t,e)=>{let n=0,r=t.length-1;for(;n<=r;){const o=bo((n+r)/2),s=t[o],i=s.clock;if(i<=e){if(e<i+s.len)return o;n=o+1}else r=o-1}return null},oa=(t,e)=>{const n=t.clients.get(e.client);return n!==void 0&&OQ(n,e.clock)!==null},Av=t=>{t.clients.forEach(e=>{e.sort((o,s)=>o.clock-s.clock);let n,r;for(n=1,r=1;n<e.length;n++){const o=e[r-1],s=e[n];o.clock+o.len>=s.clock?o.len=ns(o.len,s.clock+s.len-o.clock):(r<n&&(e[r]=s),r++)}e.length=r})},Wm=t=>{const e=new ra;for(let n=0;n<t.length;n++)t[n].clients.forEach((r,o)=>{if(!e.clients.has(o)){const s=r.slice();for(let i=n+1;i<t.length;i++)fX(s,t[i].clients.get(o)||[]);e.clients.set(o,s)}});return Av(e),e},xl=(t,e,n,r)=>{ko(t.clients,e,()=>[]).push(new Cv(n,r))},MR=()=>new ra,RQ=t=>{const e=MR();return t.clients.forEach((n,r)=>{const o=[];for(let s=0;s<n.length;s++){const i=n[s];if(i.deleted){const a=i.id.clock;let l=i.length;if(s+1<n.length)for(let c=n[s+1];s+1<n.length&&c.deleted;c=n[++s+1])l+=c.length;o.push(new Cv(a,l))}}o.length>0&&e.clients.set(r,o)}),e},Mv=(t,e)=>{$e(t.restEncoder,e.clients.size),zs(e.clients.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{t.resetDsCurVal(),$e(t.restEncoder,n);const o=r.length;$e(t.restEncoder,o);for(let s=0;s<o;s++){const i=r[s];t.writeDsClock(i.clock),t.writeDsLen(i.len)}})},NQ=t=>{const e=new ra,n=st(t.restDecoder);for(let r=0;r<n;r++){t.resetDsCurVal();const o=st(t.restDecoder),s=st(t.restDecoder);if(s>0){const i=ko(e.clients,o,()=>[]);for(let a=0;a<s;a++)i.push(new Cv(t.readDsClock(),t.readDsLen()))}}return e},ME=(t,e,n)=>{const r=new ra,o=st(t.restDecoder);for(let s=0;s<o;s++){t.resetDsCurVal();const i=st(t.restDecoder),a=st(t.restDecoder),l=n.clients.get(i)||[],c=xt(n,i);for(let u=0;u<a;u++){const d=t.readDsClock(),f=d+t.readDsLen();if(d<c){c<f&&xl(r,i,c,f-c);let h=vr(l,d),p=l[h];for(!p.deleted&&p.id.clock<d&&(l.splice(h+1,0,kd(e,p,d-p.id.clock)),h++);h<l.length&&(p=l[h++],p.id.clock<f);)p.deleted||(f<p.id.clock+p.length&&l.splice(h,0,kd(e,p,f-p.id.clock)),p.delete(e))}else xl(r,i,d,f-d)}}if(r.clients.size>0){const s=new _f;return $e(s.restEncoder,0),Mv(s,r),s.toUint8Array()}return null},OR=hR;class ei extends lR{constructor({guid:e=YX(),collectionid:n=null,gc:r=!0,gcFilter:o=()=>!0,meta:s=null,autoLoad:i=!1,shouldLoad:a=!0}={}){super(),this.gc=r,this.gcFilter=o,this.clientID=OR(),this.guid=e,this.collectionid=n,this.share=new Map,this.store=new DR,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=a,this.autoLoad=i,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=TE(c=>{this.on("load",()=>{this.isLoaded=!0,c(this)})});const l=()=>TE(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=l()),this.isSynced=c===void 0||c===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){const e=this._item;e!==null&&!this.shouldLoad&&Je(e.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(zs(this.subdocs).map(e=>e.guid))}transact(e,n=null){return Je(this,e,n)}get(e,n=Bt){const r=ko(this.share,e,()=>{const s=new n;return s._integrate(this,null),s}),o=r.constructor;if(n!==Bt&&o!==n)if(o===Bt){const s=new n;s._map=r._map,r._map.forEach(i=>{for(;i!==null;i=i.left)i.parent=s}),s._start=r._start;for(let i=s._start;i!==null;i=i.right)i.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,Ci)}getText(e=""){return this.get(e,is)}getMap(e=""){return this.get(e,Wi)}getXmlElement(e=""){return this.get(e,Qt)}getXmlFragment(e=""){return this.get(e,Vs)}toJSON(){const e={};return this.share.forEach((n,r)=>{e[r]=n.toJSON()}),e}destroy(){this.isDestroyed=!0,zs(this.subdocs).forEach(n=>n.destroy());const e=this._item;if(e!==null){this._item=null;const n=e.content;n.doc=new ei({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=e,Je(e.parent.doc,r=>{const o=n.doc;e.deleted||r.subdocsAdded.add(o),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class _Q{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=st(this.restDecoder),this.dsCurrVal}readDsLen(){const e=st(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class vd extends _Q{constructor(e){super(e),this.keys=[],st(e),this.keyClockDecoder=new up(Vn(e)),this.clientDecoder=new ru(Vn(e)),this.leftClockDecoder=new up(Vn(e)),this.rightClockDecoder=new up(Vn(e)),this.infoDecoder=new kE(Vn(e),bl),this.stringDecoder=new VX(Vn(e)),this.parentInfoDecoder=new kE(Vn(e),bl),this.typeRefDecoder=new ru(Vn(e)),this.lenDecoder=new ru(Vn(e))}readLeftID(){return new ki(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new ki(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 gd(this.restDecoder)}readBuf(){return Vn(this.restDecoder)}readJSON(){return gd(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{const n=this.stringDecoder.read();return this.keys.push(n),n}}}class DQ{constructor(){this.restEncoder=tc()}toUint8Array(){return dr(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){$e(this.restEncoder,e)}writeDsLen(e){$e(this.restEncoder,e)}}class IQ extends DQ{writeLeftID(e){$e(this.restEncoder,e.client),$e(this.restEncoder,e.clock)}writeRightID(e){$e(this.restEncoder,e.client),$e(this.restEncoder,e.clock)}writeClient(e){$e(this.restEncoder,e)}writeInfo(e){Hm(this.restEncoder,e)}writeString(e){Si(this.restEncoder,e)}writeParentInfo(e){$e(this.restEncoder,e?1:0)}writeTypeRef(e){$e(this.restEncoder,e)}writeLen(e){$e(this.restEncoder,e)}writeAny(e){zi(this.restEncoder,e)}writeBuf(e){Rn(this.restEncoder,e)}writeJSON(e){Si(this.restEncoder,JSON.stringify(e))}writeKey(e){Si(this.restEncoder,e)}}class PQ{constructor(){this.restEncoder=tc(),this.dsCurrVal=0}toUint8Array(){return dr(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const n=e-this.dsCurrVal;this.dsCurrVal=e,$e(this.restEncoder,n)}writeDsLen(e){e===0&&Mn(),$e(this.restEncoder,e-1),this.dsCurrVal+=e}}class _f extends PQ{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new cp,this.clientEncoder=new nu,this.leftClockEncoder=new cp,this.rightClockEncoder=new cp,this.infoEncoder=new wE(Hm),this.stringEncoder=new PX,this.parentInfoEncoder=new wE(Hm),this.typeRefEncoder=new nu,this.lenEncoder=new nu}toUint8Array(){const e=tc();return $e(e,0),Rn(e,this.keyClockEncoder.toUint8Array()),Rn(e,this.clientEncoder.toUint8Array()),Rn(e,this.leftClockEncoder.toUint8Array()),Rn(e,this.rightClockEncoder.toUint8Array()),Rn(e,dr(this.infoEncoder)),Rn(e,this.stringEncoder.toUint8Array()),Rn(e,dr(this.parentInfoEncoder)),Rn(e,this.typeRefEncoder.toUint8Array()),Rn(e,this.lenEncoder.toUint8Array()),Rf(e,dr(this.restEncoder)),dr(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){zi(this.restEncoder,e)}writeBuf(e){Rn(this.restEncoder,e)}writeJSON(e){zi(this.restEncoder,e)}writeKey(e){const n=this.keyMap.get(e);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(n)}}const LQ=(t,e,n,r)=>{r=ns(r,e[0].id.clock);const o=vr(e,r);$e(t.restEncoder,e.length-o),t.writeClient(n),$e(t.restEncoder,r);const s=e[o];s.write(t,r-s.id.clock);for(let i=o+1;i<e.length;i++)e[i].write(t,0)},RR=(t,e,n)=>{const r=new Map;n.forEach((o,s)=>{xt(e,s)>o&&r.set(s,o)}),Df(e).forEach((o,s)=>{n.has(s)||r.set(s,0)}),$e(t.restEncoder,r.size),zs(r.entries()).sort((o,s)=>s[0]-o[0]).forEach(([o,s])=>{LQ(t,e.clients.get(o),o,s)})},jQ=(t,e)=>{const n=fr(),r=st(t.restDecoder);for(let o=0;o<r;o++){const s=st(t.restDecoder),i=new Array(s),a=t.readClient();let l=st(t.restDecoder);n.set(a,{i:0,refs:i});for(let c=0;c<s;c++){const u=t.readInfo();switch(Of&u){case 0:{const d=t.readLen();i[c]=new qn(De(a,l),d),l+=d;break}case 10:{const d=st(t.restDecoder);i[c]=new cr(De(a,l),d),l+=d;break}default:{const d=(u&(co|an))===0,f=new nt(De(a,l),null,(u&an)===an?t.readLeftID():null,null,(u&co)===co?t.readRightID():null,d?t.readParentInfo()?e.get(t.readString()):t.readLeftID():null,d&&(u&yl)===yl?t.readString():null,rN(t,u));i[c]=f,l+=f.length}}}}return n},$Q=(t,e,n)=>{const r=[];let o=zs(n.keys()).sort((h,p)=>h-p);if(o.length===0)return null;const s=()=>{if(o.length===0)return null;let h=n.get(o[o.length-1]);for(;h.refs.length===h.i;)if(o.pop(),o.length>0)h=n.get(o[o.length-1]);else return null;return h};let i=s();if(i===null)return null;const a=new DR,l=new Map,c=(h,p)=>{const m=l.get(h);(m==null||m>p)&&l.set(h,p)};let u=i.refs[i.i++];const d=new Map,f=()=>{for(const h of r){const p=h.id.client,m=n.get(p);m?(m.i--,a.clients.set(p,m.refs.slice(m.i)),n.delete(p),m.i=0,m.refs=[]):a.clients.set(p,[h]),o=o.filter(y=>y!==p)}r.length=0};for(;;){if(u.constructor!==cr){const p=ko(d,u.id.client,()=>xt(e,u.id.client))-u.id.clock;if(p<0)r.push(u),c(u.id.client,u.id.clock-1),f();else{const m=u.getMissing(t,e);if(m!==null){r.push(u);const y=n.get(m)||{refs:[],i:0};if(y.refs.length===y.i)c(m,xt(e,m)),f();else{u=y.refs[y.i++];continue}}else(p===0||p<u.length)&&(u.integrate(t,p),d.set(u.id.client,u.id.clock+u.length))}}if(r.length>0)u=r.pop();else if(i!==null&&i.i<i.refs.length)u=i.refs[i.i++];else{if(i=s(),i===null)break;u=i.refs[i.i++]}}if(a.clients.size>0){const h=new _f;return RR(h,a,new Map),$e(h.restEncoder,0),{missing:l,update:h.toUint8Array()}}return null},BQ=(t,e)=>RR(t,e.doc.store,e.beforeState),FQ=(t,e,n,r=new vd(t))=>Je(e,o=>{o.local=!1;let s=!1;const i=o.doc,a=i.store,l=jQ(r,i),c=$Q(o,a,l),u=a.pendingStructs;if(u){for(const[f,h]of u.missing)if(h<xt(a,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=jE([u.update,c.update])}}else a.pendingStructs=c;const d=ME(r,o,a);if(a.pendingDs){const f=new vd(wv(a.pendingDs));st(f.restDecoder);const h=ME(f,o,a);d&&h?a.pendingDs=jE([d,h]):a.pendingDs=d||h}else a.pendingDs=d;if(s){const f=a.pendingStructs.update;a.pendingStructs=null,Gm(o.doc,f)}},n,!1),Gm=(t,e,n,r=vd)=>{const o=wv(e);FQ(o,t,n,new r(o))};class HQ{constructor(){this.l=[]}}const OE=()=>new HQ,RE=(t,e)=>t.l.push(e),NE=(t,e)=>{const n=t.l,r=n.length;t.l=n.filter(o=>e!==o),r===t.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},NR=(t,e,n)=>kv(t.l,[e,n]);class ki{constructor(e,n){this.client=e,this.clock=n}}const Pc=(t,e)=>t===e||t!==null&&e!==null&&t.client===e.client&&t.clock===e.clock,De=(t,e)=>new ki(t,e),wl=t=>{for(const[e,n]of t.doc.share.entries())if(n===t)return e;throw Mn()},El=(t,e)=>{for(;e!==null;){if(e.parent===t)return!0;e=e.parent._item}return!1};class bd{constructor(e,n,r,o=0){this.type=e,this.tname=n,this.item=r,this.assoc=o}}class UQ{constructor(e,n,r=0){this.type=e,this.index=n,this.assoc=r}}const zQ=(t,e,n=0)=>new UQ(t,e,n),Lc=(t,e,n)=>{let r=null,o=null;return t._item===null?o=wl(t):r=De(t._item.id.client,t._item.id.clock),new bd(r,o,e,n)},fp=(t,e,n=0)=>{let r=t._start;if(n<0){if(e===0)return Lc(t,null,n);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return Lc(t,De(r.id.client,r.id.clock+e),n);e-=r.length}if(r.right===null&&n<0)return Lc(t,r.lastId,n);r=r.right}return Lc(t,null,n)},VQ=(t,e)=>{const n=Ti(t,e),r=e.clock-n.id.clock;return{item:n,diff:r}},WQ=(t,e,n=!0)=>{const r=e.store,o=t.item,s=t.type,i=t.tname,a=t.assoc;let l=null,c=0;if(o!==null){if(xt(r,o.client)<=o.clock)return null;const u=n?Jm(r,o):VQ(r,o),d=u.item;if(!(d instanceof nt))return null;if(l=d.parent,l._item===null||!l._item.deleted){c=d.deleted||!d.countable?0:u.diff+(a>=0?0:1);let f=d.left;for(;f!==null;)!f.deleted&&f.countable&&(c+=f.length),f=f.left}}else{if(i!==null)l=e.get(i);else if(s!==null){if(xt(r,s.client)<=s.clock)return null;const{item:u}=n?Jm(r,s):{item:Ti(r,s)};if(u instanceof nt&&u.content instanceof Sr)l=u.content.type;else return null}else throw Mn();a>=0?c=l._length:c=0}return zQ(l,c,t.assoc)};class Ov{constructor(e,n){this.ds=e,this.sv=n}}const _R=(t,e)=>new Ov(t,e),hp=t=>_R(RQ(t.store),Df(t.store)),vs=(t,e)=>e===void 0?!t.deleted:e.sv.has(t.id.client)&&(e.sv.get(t.id.client)||0)>t.id.clock&&!oa(e.ds,t.id),qm=(t,e)=>{const n=ko(t.meta,qm,Us),r=t.doc.store;n.has(e)||(e.sv.forEach((o,s)=>{o<xt(r,s)&&xn(t,De(s,o))}),ss(t,e.ds,o=>{}),n.add(e))};class DR{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Df=t=>{const e=new Map;return t.clients.forEach((n,r)=>{const o=n[n.length-1];e.set(r,o.id.clock+o.length)}),e},xt=(t,e)=>{const n=t.clients.get(e);if(n===void 0)return 0;const r=n[n.length-1];return r.id.clock+r.length},IR=(t,e)=>{let n=t.clients.get(e.id.client);if(n===void 0)n=[],t.clients.set(e.id.client,n);else{const r=n[n.length-1];if(r.id.clock+r.length!==e.id.clock)throw Mn()}n.push(e)},vr=(t,e)=>{let n=0,r=t.length-1,o=t[r],s=o.id.clock;if(s===e)return r;let i=bo(e/(s+o.length-1)*r);for(;n<=r;){if(o=t[i],s=o.id.clock,s<=e){if(e<s+o.length)return i;n=i+1}else r=i-1;i=bo((n+r)/2)}throw Mn()},GQ=(t,e)=>{const n=t.clients.get(e.client);return n[vr(n,e.clock)]},Ti=GQ,Km=(t,e,n)=>{const r=vr(e,n),o=e[r];return o.id.clock<n&&o instanceof nt?(e.splice(r+1,0,kd(t,o,n-o.id.clock)),r+1):r},xn=(t,e)=>{const n=t.doc.store.clients.get(e.client);return n[Km(t,n,e.clock)]},_E=(t,e,n)=>{const r=e.clients.get(n.client),o=vr(r,n.clock),s=r[o];return n.clock!==s.id.clock+s.length-1&&s.constructor!==qn&&r.splice(o+1,0,kd(t,s,n.clock-s.id.clock+1)),s},qQ=(t,e,n)=>{const r=t.clients.get(e.id.client);r[vr(r,e.id.clock)]=n},PR=(t,e,n,r,o)=>{if(r===0)return;const s=n+r;let i=Km(t,e,n),a;do a=e[i++],s<a.id.clock+a.length&&Km(t,e,s),o(a);while(i<e.length&&e[i].id.clock<s)};class KQ{constructor(e,n,r){this.doc=e,this.deleteSet=new ra,this.beforeState=Df(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=r,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const DE=(t,e)=>e.deleteSet.clients.size===0&&!dX(e.afterState,(n,r)=>e.beforeState.get(r)!==n)?!1:(Av(e.deleteSet),BQ(t,e),Mv(t,e.deleteSet),!0),IE=(t,e,n)=>{const r=e._item;(r===null||r.id.clock<(t.beforeState.get(r.id.client)||0)&&!r.deleted)&&ko(t.changed,e,Us).add(n)},ou=(t,e)=>{let n=t[e],r=t[e-1],o=e;for(;o>0;n=r,r=t[--o-1]){if(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n)){n instanceof nt&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}const s=e-o;return s&&t.splice(e+1-s,s),s},YQ=(t,e,n)=>{for(const[r,o]of t.clients.entries()){const s=e.clients.get(r);for(let i=o.length-1;i>=0;i--){const a=o[i],l=a.clock+a.len;for(let c=vr(s,a.clock),u=s[c];c<s.length&&u.id.clock<l;u=s[++c]){const d=s[c];if(a.clock+a.len<=d.id.clock)break;d instanceof nt&&d.deleted&&!d.keep&&n(d)&&d.gc(e,!1)}}}},JQ=(t,e)=>{t.clients.forEach((n,r)=>{const o=e.clients.get(r);for(let s=n.length-1;s>=0;s--){const i=n[s],a=Ui(o.length-1,1+vr(o,i.clock+i.len-1));for(let l=a,c=o[l];l>0&&c.id.clock>=i.clock;c=o[l])l-=1+ou(o,l)}})},LR=(t,e)=>{if(e<t.length){const n=t[e],r=n.doc,o=r.store,s=n.deleteSet,i=n._mergeStructs;try{Av(s),n.afterState=Df(n.doc.store),r.emit("beforeObserverCalls",[n,r]);const a=[];n.changed.forEach((l,c)=>a.push(()=>{(c._item===null||!c._item.deleted)&&c._callObserver(n,l)})),a.push(()=>{n.changedParentTypes.forEach((l,c)=>{c._dEH.l.length>0&&(c._item===null||!c._item.deleted)&&(l=l.filter(u=>u.target._item===null||!u.target._item.deleted),l.forEach(u=>{u.currentTarget=c,u._path=null}),l.sort((u,d)=>u.path.length-d.path.length),NR(c._dEH,l,n))})}),a.push(()=>r.emit("afterTransaction",[n,r])),kv(a,[]),n._needFormattingCleanup&&gZ(n)}finally{r.gc&&YQ(s,o,r.gcFilter),JQ(s,o),n.afterState.forEach((u,d)=>{const f=n.beforeState.get(d)||0;if(f!==u){const h=o.clients.get(d),p=ns(vr(h,f),1);for(let m=h.length-1;m>=p;)m-=1+ou(h,m)}});for(let u=i.length-1;u>=0;u--){const{client:d,clock:f}=i[u].id,h=o.clients.get(d),p=vr(h,f);p+1<h.length&&ou(h,p+1)>1||p>0&&ou(h,p)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(AQ(Tv,wR,"[yjs] ",ER,SR,"Changed the client-id because another client seems to be using it."),r.clientID=OR()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){const u=new IQ;DE(u,n)&&r.emit("update",[u.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){const u=new _f;DE(u,n)&&r.emit("updateV2",[u.toUint8Array(),n.origin,r,n])}const{subdocsAdded:a,subdocsLoaded:l,subdocsRemoved:c}=n;(a.size>0||c.size>0||l.size>0)&&(a.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:l,added:a,removed:c},r,n]),c.forEach(u=>u.destroy())),t.length<=e+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,t])):LR(t,e+1)}}},Je=(t,e,n=null,r=!0)=>{const o=t._transactionCleanups;let s=!1,i=null;t._transaction===null&&(s=!0,t._transaction=new KQ(t,n,r),o.push(t._transaction),o.length===1&&t.emit("beforeAllTransactions",[t]),t.emit("beforeTransaction",[t._transaction,t]));try{i=e(t._transaction)}finally{if(s){const a=t._transaction===o[0];t._transaction=null,a&&LR(o,0)}}return i};class XQ{constructor(e,n){this.insertions=n,this.deletions=e,this.meta=new Map}}const PE=(t,e,n)=>{ss(t,n.deletions,r=>{r instanceof nt&&e.scope.some(o=>o===t.doc||El(o,r))&&Iv(r,!1)})},LE=(t,e,n)=>{let r=null;const o=t.doc,s=t.scope;Je(o,a=>{for(;e.length>0&&t.currStackItem===null;){const l=o.store,c=e.pop(),u=new Set,d=[];let f=!1;ss(a,c.insertions,h=>{if(h instanceof nt){if(h.redone!==null){let{item:p,diff:m}=Jm(l,h.id);m>0&&(p=xn(a,De(p.id.client,p.id.clock+m))),h=p}!h.deleted&&s.some(p=>p===a.doc||El(p,h))&&d.push(h)}}),ss(a,c.deletions,h=>{h instanceof nt&&s.some(p=>p===a.doc||El(p,h))&&!oa(c.insertions,h.id)&&u.add(h)}),u.forEach(h=>{f=nN(a,h,u,c.insertions,t.ignoreRemoteMapChanges,t)!==null||f});for(let h=d.length-1;h>=0;h--){const p=d[h];t.deleteFilter(p)&&(p.delete(a),f=!0)}t.currStackItem=f?c:null}a.changed.forEach((l,c)=>{l.has(null)&&c._searchMarker&&(c._searchMarker.length=0)}),r=a},t);const i=t.currStackItem;if(i!=null){const a=r.changedParentTypes;t.emit("stack-item-popped",[{stackItem:i,type:n,changedParentTypes:a,origin:t},t]),t.currStackItem=null}return i};class jR extends lR{constructor(e,{captureTimeout:n=500,captureTransaction:r=l=>!0,deleteFilter:o=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:i=!1,doc:a=Bm(e)?e[0].doc:e instanceof ei?e:e.doc}={}){super(),this.scope=[],this.doc=a,this.addToScope(e),this.deleteFilter=o,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=i,this.captureTimeout=n,this.afterTransactionHandler=l=>{if(!this.captureTransaction(l)||!this.scope.some(y=>l.changedParentTypes.has(y)||y===this.doc)||!this.trackedOrigins.has(l.origin)&&(!l.origin||!this.trackedOrigins.has(l.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 ra;l.afterState.forEach((y,v)=>{const w=l.beforeState.get(v)||0,E=y-w;E>0&&xl(f,v,w,E)});const h=JX();let p=!1;if(this.lastChange>0&&h-this.lastChange<this.captureTimeout&&d.length>0&&!c&&!u){const y=d[d.length-1];y.deletions=Wm([y.deletions,l.deleteSet]),y.insertions=Wm([y.insertions,f])}else d.push(new XQ(l.deleteSet,f)),p=!0;!c&&!u&&(this.lastChange=h),ss(l,l.deleteSet,y=>{y instanceof nt&&this.scope.some(v=>v===l.doc||El(v,y))&&Iv(y,!0)});const m=[{stackItem:d[d.length-1],origin:l.origin,type:c?"redo":"undo",changedParentTypes:l.changedParentTypes},this];p?this.emit("stack-item-added",m):this.emit("stack-item-updated",m)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(e){const n=new Set(this.scope);e=Bm(e)?e:[e],e.forEach(r=>{n.has(r)||(n.add(r),(r instanceof Bt?r.doc!==this.doc:r!==this.doc)&&TR("[yjs#509] Not same Y.Doc"),this.scope.push(r))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,n=!0){(e&&this.canUndo()||n&&this.canRedo())&&this.doc.transact(r=>{e&&(this.undoStack.forEach(o=>PE(r,this,o)),this.undoStack=[]),n&&(this.redoStack.forEach(o=>PE(r,this,o)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=LE(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=LE(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*QQ(t){const e=st(t.restDecoder);for(let n=0;n<e;n++){const r=st(t.restDecoder),o=t.readClient();let s=st(t.restDecoder);for(let i=0;i<r;i++){const a=t.readInfo();if(a===10){const l=st(t.restDecoder);yield new cr(De(o,s),l),s+=l}else if((Of&a)!==0){const l=(a&(co|an))===0,c=new nt(De(o,s),null,(a&an)===an?t.readLeftID():null,null,(a&co)===co?t.readRightID():null,l?t.readParentInfo()?t.readString():t.readLeftID():null,l&&(a&yl)===yl?t.readString():null,rN(t,a));yield c,s+=c.length}else{const l=t.readLen();yield new qn(De(o,s),l),s+=l}}}}class ZQ{constructor(e,n){this.gen=QQ(e),this.curr=null,this.done=!1,this.filterSkips=n,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===cr);return this.curr}}class eZ{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}}const tZ=(t,e)=>{if(t.constructor===qn){const{client:n,clock:r}=t.id;return new qn(De(n,r+e),t.length-e)}else if(t.constructor===cr){const{client:n,clock:r}=t.id;return new cr(De(n,r+e),t.length-e)}else{const n=t,{client:r,clock:o}=n.id;return new nt(De(r,o+e),null,De(r,o+e-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(e))}},jE=(t,e=vd,n=_f)=>{if(t.length===1)return t[0];const r=t.map(u=>new e(wv(u)));let o=r.map(u=>new ZQ(u,!0)),s=null;const i=new n,a=new eZ(i);for(;o=o.filter(f=>f.curr!==null),o.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===cr?1:-1:p}else return h.curr.id.client-f.curr.id.client}),o.length!==0;){const u=o[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)xa(a,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===cr)s.struct.length=f.id.clock+f.length-s.struct.id.clock;else{xa(a,s.struct,s.offset);const p=f.id.clock-s.struct.id.clock-s.struct.length;s={struct:new cr(De(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===cr?s.struct.length-=p:f=tZ(f,p)),s.struct.mergeWith(f)||(xa(a,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!==cr;f=u.next())xa(a,s.struct,s.offset),s={struct:f,offset:0}}s!==null&&(xa(a,s.struct,s.offset),s=null),nZ(a);const l=r.map(u=>NQ(u)),c=Wm(l);return Mv(i,c),i.toUint8Array()},$R=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:dr(t.encoder.restEncoder)}),t.encoder.restEncoder=tc(),t.written=0)},xa=(t,e,n)=>{t.written>0&&t.currClient!==e.id.client&&$R(t),t.written===0&&(t.currClient=e.id.client,t.encoder.writeClient(e.id.client),$e(t.encoder.restEncoder,e.id.clock+n)),e.write(t.encoder,n),t.written++},nZ=t=>{$R(t);const e=t.encoder.restEncoder;$e(e,t.clientStructs.length);for(let n=0;n<t.clientStructs.length;n++){const r=t.clientStructs[n];$e(e,r.written),Rf(e,r.restEncoder)}},$E="You must not compute changes after the event-handler fired.";class If{constructor(e,n){this.target=e,this.currentTarget=e,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=rZ(this.currentTarget,this.target))}deletes(e){return oa(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw rs($E);const e=new Map,n=this.target;this.transaction.changed.get(n).forEach(o=>{if(o!==null){const s=n._map.get(o);let i,a;if(this.adds(s)){let l=s.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(s))if(l!==null&&this.deletes(l))i="delete",a=ip(l.content.getContent());else return;else l!==null&&this.deletes(l)?(i="update",a=ip(l.content.getContent())):(i="add",a=void 0)}else if(this.deletes(s))i="delete",a=ip(s.content.getContent());else return;e.set(o,{action:i,oldValue:a})}}),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 rs($E);const n=this.target,r=Us(),o=Us(),s=[];if(e={added:r,deleted:o,delta:s,keys:this.keys},this.transaction.changed.get(n).has(null)){let a=null;const l=()=>{a&&s.push(a)};for(let c=n._start;c!==null;c=c.right)c.deleted?this.deletes(c)&&!this.adds(c)&&((a===null||a.delete===void 0)&&(l(),a={delete:0}),a.delete+=c.length,o.add(c)):this.adds(c)?((a===null||a.insert===void 0)&&(l(),a={insert:[]}),a.insert=a.insert.concat(c.content.getContent()),r.add(c)):((a===null||a.retain===void 0)&&(l(),a={retain:0}),a.retain+=c.length);a!==null&&a.retain===void 0&&l()}this._changes=e}return e}}const rZ=(t,e)=>{const n=[];for(;e._item!==null&&e!==t;){if(e._item.parentSub!==null)n.unshift(e._item.parentSub);else{let r=0,o=e._item.parent._start;for(;o!==e._item&&o!==null;)!o.deleted&&o.countable&&(r+=o.length),o=o.right;n.unshift(r)}e=e._item.parent}return n},Zt=()=>{TR("Invalid access: Add Yjs type to a document before reading data.")},BR=80;let Rv=0;class oZ{constructor(e,n){e.marker=!0,this.p=e,this.index=n,this.timestamp=Rv++}}const sZ=t=>{t.timestamp=Rv++},FR=(t,e,n)=>{t.p.marker=!1,t.p=e,e.marker=!0,t.index=n,t.timestamp=Rv++},iZ=(t,e,n)=>{if(t.length>=BR){const r=t.reduce((o,s)=>o.timestamp<s.timestamp?o:s);return FR(r,e,n),r}else{const r=new oZ(e,n);return t.push(r),r}},Pf=(t,e)=>{if(t._start===null||e===0||t._searchMarker===null)return null;const n=t._searchMarker.length===0?null:t._searchMarker.reduce((s,i)=>tu(e-s.index)<tu(e-i.index)?s:i);let r=t._start,o=0;for(n!==null&&(r=n.p,o=n.index,sZ(n));r.right!==null&&o<e;){if(!r.deleted&&r.countable){if(e<o+r.length)break;o+=r.length}r=r.right}for(;r.left!==null&&o>e;)r=r.left,!r.deleted&&r.countable&&(o-=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&&(o-=r.length);return n!==null&&tu(n.index-o)<r.parent.length/BR?(FR(n,r,o),n):iZ(t._searchMarker,r,o)},Sl=(t,e,n)=>{for(let r=t.length-1;r>=0;r--){const o=t[r];if(n>0){let s=o.p;for(s.marker=!1;s&&(s.deleted||!s.countable);)s=s.left,s&&!s.deleted&&s.countable&&(o.index-=s.length);if(s===null||s.marker===!0){t.splice(r,1);continue}o.p=s,s.marker=!0}(e<o.index||n>0&&e===o.index)&&(o.index=ns(e,o.index+n))}},Lf=(t,e,n)=>{const r=t,o=e.changedParentTypes;for(;ko(o,t,()=>[]).push(n),t._item!==null;)t=t._item.parent;NR(r._eH,n,e)};class Bt{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=OE(),this._dEH=OE(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,n){this.doc=e,this._item=n}_copy(){throw hr()}clone(){throw hr()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,n){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){RE(this._eH,e)}observeDeep(e){RE(this._dEH,e)}unobserve(e){NE(this._eH,e)}unobserveDeep(e){NE(this._dEH,e)}toJSON(){}}const HR=(t,e,n)=>{t.doc??Zt(),e<0&&(e=t._length+e),n<0&&(n=t._length+n);let r=n-e;const o=[];let s=t._start;for(;s!==null&&r>0;){if(s.countable&&!s.deleted){const i=s.content.getContent();if(i.length<=e)e-=i.length;else{for(let a=e;a<i.length&&r>0;a++)o.push(i[a]),r--;e=0}}s=s.right}return o},UR=t=>{t.doc??Zt();const e=[];let n=t._start;for(;n!==null;){if(n.countable&&!n.deleted){const r=n.content.getContent();for(let o=0;o<r.length;o++)e.push(r[o])}n=n.right}return e},zR=(t,e)=>{const n=[];let r=t._start;for(;r!==null;){if(r.countable&&vs(r,e)){const o=r.content.getContent();for(let s=0;s<o.length;s++)n.push(o[s])}r=r.right}return n},kl=(t,e)=>{let n=0,r=t._start;for(t.doc??Zt();r!==null;){if(r.countable&&!r.deleted){const o=r.content.getContent();for(let s=0;s<o.length;s++)e(o[s],n++,t)}r=r.right}},VR=(t,e)=>{const n=[];return kl(t,(r,o)=>{n.push(e(r,o,t))}),n},aZ=t=>{let e=t._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};n=e.content.getContent(),r=0,e=e.right}const o=n[r++];return n.length<=r&&(n=null),{done:!1,value:o}}}},WR=(t,e)=>{t.doc??Zt();const n=Pf(t,e);let r=t._start;for(n!==null&&(r=n.p,e-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(e<r.length)return r.content.getContent()[e];e-=r.length}},xd=(t,e,n,r)=>{let o=n;const s=t.doc,i=s.clientID,a=s.store,l=n===null?e._start:n.right;let c=[];const u=()=>{c.length>0&&(o=new nt(De(i,xt(a,i)),o,o&&o.lastId,l,l&&l.id,e,null,new Ws(c)),o.integrate(t,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:o=new nt(De(i,xt(a,i)),o,o&&o.lastId,l,l&&l.id,e,null,new nc(new Uint8Array(d))),o.integrate(t,0);break;case ei:o=new nt(De(i,xt(a,i)),o,o&&o.lastId,l,l&&l.id,e,null,new rc(d)),o.integrate(t,0);break;default:if(d instanceof Bt)o=new nt(De(i,xt(a,i)),o,o&&o.lastId,l,l&&l.id,e,null,new Sr(d)),o.integrate(t,0);else throw new Error("Unexpected content type in insert operation")}}}),u()},GR=()=>rs("Length exceeded!"),qR=(t,e,n,r)=>{if(n>e._length)throw GR();if(n===0)return e._searchMarker&&Sl(e._searchMarker,n,r.length),xd(t,e,null,r);const o=n,s=Pf(e,n);let i=e._start;for(s!==null&&(i=s.p,n-=s.index,n===0&&(i=i.prev,n+=i&&i.countable&&!i.deleted?i.length:0));i!==null;i=i.right)if(!i.deleted&&i.countable){if(n<=i.length){n<i.length&&xn(t,De(i.id.client,i.id.clock+n));break}n-=i.length}return e._searchMarker&&Sl(e._searchMarker,o,r.length),xd(t,e,i,r)},lZ=(t,e,n)=>{let o=(e._searchMarker||[]).reduce((s,i)=>i.index>s.index?i:s,{index:0,p:e._start}).p;if(o)for(;o.right;)o=o.right;return xd(t,e,o,n)},KR=(t,e,n,r)=>{if(r===0)return;const o=n,s=r,i=Pf(e,n);let a=e._start;for(i!==null&&(a=i.p,n-=i.index);a!==null&&n>0;a=a.right)!a.deleted&&a.countable&&(n<a.length&&xn(t,De(a.id.client,a.id.clock+n)),n-=a.length);for(;r>0&&a!==null;)a.deleted||(r<a.length&&xn(t,De(a.id.client,a.id.clock+r)),a.delete(t),r-=a.length),a=a.right;if(r>0)throw GR();e._searchMarker&&Sl(e._searchMarker,o,-s+r)},wd=(t,e,n)=>{const r=e._map.get(n);r!==void 0&&r.delete(t)},Nv=(t,e,n,r)=>{const o=e._map.get(n)||null,s=t.doc,i=s.clientID;let a;if(r==null)a=new Ws([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:a=new Ws([r]);break;case Uint8Array:a=new nc(r);break;case ei:a=new rc(r);break;default:if(r instanceof Bt)a=new Sr(r);else throw new Error("Unexpected content type")}new nt(De(i,xt(s.store,i)),o,o&&o.lastId,null,null,e,n,a).integrate(t,0)},_v=(t,e)=>{t.doc??Zt();const n=t._map.get(e);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},YR=t=>{const e={};return t.doc??Zt(),t._map.forEach((n,r)=>{n.deleted||(e[r]=n.content.getContent()[n.length-1])}),e},JR=(t,e)=>{t.doc??Zt();const n=t._map.get(e);return n!==void 0&&!n.deleted},cZ=(t,e)=>{const n={};return t._map.forEach((r,o)=>{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&&vs(s,e)&&(n[o]=s.content.getContent()[s.length-1])}),n},jc=t=>(t.doc??Zt(),MQ(t._map.entries(),e=>!e[1].deleted));class uZ extends If{}class Ci extends Bt{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const n=new Ci;return n.push(e),n}_integrate(e,n){super._integrate(e,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Ci}clone(){const e=new Ci;return e.insert(0,this.toArray().map(n=>n instanceof Bt?n.clone():n)),e}get length(){return this.doc??Zt(),this._length}_callObserver(e,n){super._callObserver(e,n),Lf(this,e,new uZ(this,e))}insert(e,n){this.doc!==null?Je(this.doc,r=>{qR(r,this,e,n)}):this._prelimContent.splice(e,0,...n)}push(e){this.doc!==null?Je(this.doc,n=>{lZ(n,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,n=1){this.doc!==null?Je(this.doc,r=>{KR(r,this,e,n)}):this._prelimContent.splice(e,n)}get(e){return WR(this,e)}toArray(){return UR(this)}slice(e=0,n=this.length){return HR(this,e,n)}toJSON(){return this.map(e=>e instanceof Bt?e.toJSON():e)}map(e){return VR(this,e)}forEach(e){kl(this,e)}[Symbol.iterator](){return aZ(this)}_write(e){e.writeTypeRef(PZ)}}const dZ=t=>new Ci;class fZ extends If{constructor(e,n,r){super(e,n),this.keysChanged=r}}class Wi extends Bt{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,n){super._integrate(e,n),this._prelimContent.forEach((r,o)=>{this.set(o,r)}),this._prelimContent=null}_copy(){return new Wi}clone(){const e=new Wi;return this.forEach((n,r)=>{e.set(r,n instanceof Bt?n.clone():n)}),e}_callObserver(e,n){Lf(this,e,new fZ(this,e,n))}toJSON(){this.doc??Zt();const e={};return this._map.forEach((n,r)=>{if(!n.deleted){const o=n.content.getContent()[n.length-1];e[r]=o instanceof Bt?o.toJSON():o}}),e}get size(){return[...jc(this)].length}keys(){return dp(jc(this),e=>e[0])}values(){return dp(jc(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return dp(jc(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??Zt(),this._map.forEach((n,r)=>{n.deleted||e(n.content.getContent()[n.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?Je(this.doc,n=>{wd(n,this,e)}):this._prelimContent.delete(e)}set(e,n){return this.doc!==null?Je(this.doc,r=>{Nv(r,this,e,n)}):this._prelimContent.set(e,n),n}get(e){return _v(this,e)}has(e){return JR(this,e)}clear(){this.doc!==null?Je(this.doc,e=>{this.forEach(function(n,r,o){wd(e,o,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(LZ)}}const hZ=t=>new Wi,zo=(t,e)=>t===e||typeof t=="object"&&typeof e=="object"&&t&&e&&oQ(t,e);class Ym{constructor(e,n,r,o){this.left=e,this.right=n,this.index=r,this.currentAttributes=o}forward(){switch(this.right===null&&Mn(),this.right.content.constructor){case kt:this.right.deleted||sa(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 BE=(t,e,n)=>{for(;e.right!==null&&n>0;){switch(e.right.content.constructor){case kt:e.right.deleted||sa(e.currentAttributes,e.right.content);break;default:e.right.deleted||(n<e.right.length&&xn(t,De(e.right.id.client,e.right.id.clock+n)),e.index+=e.right.length,n-=e.right.length);break}e.left=e.right,e.right=e.right.right}return e},$c=(t,e,n,r)=>{const o=new Map,s=r?Pf(e,n):null;if(s){const i=new Ym(s.p.left,s.p,s.index,o);return BE(t,i,n-s.index)}else{const i=new Ym(null,e._start,0,o);return BE(t,i,n)}},XR=(t,e,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===kt&&zo(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();const o=t.doc,s=o.clientID;r.forEach((i,a)=>{const l=n.left,c=n.right,u=new nt(De(s,xt(o.store,s)),l,l&&l.lastId,c,c&&c.id,e,null,new kt(a,i));u.integrate(t,0),n.right=u,n.forward()})},sa=(t,e)=>{const{key:n,value:r}=e;r===null?t.delete(n):t.set(n,r)},QR=(t,e)=>{for(;t.right!==null;){if(!(t.right.deleted||t.right.content.constructor===kt&&zo(e[t.right.content.key]??null,t.right.content.value)))break;t.forward()}},ZR=(t,e,n,r)=>{const o=t.doc,s=o.clientID,i=new Map;for(const a in r){const l=r[a],c=n.currentAttributes.get(a)??null;if(!zo(c,l)){i.set(a,c);const{left:u,right:d}=n;n.right=new nt(De(s,xt(o.store,s)),u,u&&u.lastId,d,d&&d.id,e,null,new kt(a,l)),n.right.integrate(t,0),n.forward()}}return i},pp=(t,e,n,r,o)=>{n.currentAttributes.forEach((f,h)=>{o[h]===void 0&&(o[h]=null)});const s=t.doc,i=s.clientID;QR(n,o);const a=ZR(t,e,n,o),l=r.constructor===String?new br(r):r instanceof Bt?new Sr(r):new ti(r);let{left:c,right:u,index:d}=n;e._searchMarker&&Sl(e._searchMarker,n.index,l.getLength()),u=new nt(De(i,xt(s.store,i)),c,c&&c.lastId,u,u&&u.id,e,null,l),u.integrate(t,0),n.right=u,n.index=d,n.forward(),XR(t,e,n,a)},FE=(t,e,n,r,o)=>{const s=t.doc,i=s.clientID;QR(n,o);const a=ZR(t,e,n,o);e:for(;n.right!==null&&(r>0||a.size>0&&(n.right.deleted||n.right.content.constructor===kt));){if(!n.right.deleted)switch(n.right.content.constructor){case kt:{const{key:l,value:c}=n.right.content,u=o[l];if(u!==void 0){if(zo(u,c))a.delete(l);else{if(r===0)break e;a.set(l,c)}n.right.delete(t)}else n.currentAttributes.set(l,c);break}default:r<n.right.length&&xn(t,De(n.right.id.client,n.right.id.clock+r)),r-=n.right.length;break}n.forward()}if(r>0){let l="";for(;r>0;r--)l+=`
585
585
  `;n.right=new nt(De(i,xt(s.store,i)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,e,null,new br(l)),n.right.integrate(t,0),n.forward()}XR(t,e,n,a)},eN=(t,e,n,r,o)=>{let s=e;const i=fr();for(;s&&(!s.countable||s.deleted);){if(!s.deleted&&s.content.constructor===kt){const c=s.content;i.set(c.key,c)}s=s.right}let a=0,l=!1;for(;e!==s;){if(n===e&&(l=!0),!e.deleted){const c=e.content;switch(c.constructor){case kt:{const{key:u,value:d}=c,f=r.get(u)??null;(i.get(u)!==c||f===d)&&(e.delete(t),a++,!l&&(o.get(u)??null)===d&&f!==d&&(f===null?o.delete(u):o.set(u,f))),!l&&!e.deleted&&sa(o,c);break}}}e=e.right}return a},pZ=(t,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;const n=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===kt){const r=e.content.key;n.has(r)?e.delete(t):n.add(r)}e=e.left}},mZ=t=>{let e=0;return Je(t.doc,n=>{let r=t._start,o=t._start,s=fr();const i=$m(s);for(;o;){if(o.deleted===!1)switch(o.content.constructor){case kt:sa(i,o.content);break;default:e+=eN(n,r,o,s,i),s=$m(i),r=o;break}o=o.right}}),e},gZ=t=>{const e=new Set,n=t.doc;for(const[r,o]of t.afterState.entries()){const s=t.beforeState.get(r)||0;o!==s&&PR(t,n.store.clients.get(r),s,o,i=>{!i.deleted&&i.content.constructor===kt&&i.constructor!==qn&&e.add(i.parent)})}Je(n,r=>{ss(t,t.deleteSet,o=>{if(o instanceof qn||!o.parent._hasFormatting||e.has(o.parent))return;const s=o.parent;o.content.constructor===kt?e.add(s):pZ(r,o)});for(const o of e)mZ(o)})},HE=(t,e,n)=>{const r=n,o=$m(e.currentAttributes),s=e.right;for(;n>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case Sr:case ti:case br:n<e.right.length&&xn(t,De(e.right.id.client,e.right.id.clock+n)),n-=e.right.length,e.right.delete(t);break}e.forward()}s&&eN(t,s,e.right,o,e.currentAttributes);const i=(e.left||e.right).parent;return i._searchMarker&&Sl(i._searchMarker,e.index,-r+n),e};class yZ extends If{constructor(e,n,r){super(e,n),this.childListChanged=!1,this.keysChanged=new Set,r.forEach(o=>{o===null?this.childListChanged=!0:this.keysChanged.add(o)})}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,n=[];Je(e,r=>{const o=new Map,s=new Map;let i=this.target._start,a=null;const l={};let c="",u=0,d=0;const f=()=>{if(a!==null){let h=null;switch(a){case"delete":d>0&&(h={delete:d}),d=0;break;case"insert":(typeof c=="object"||c.length>0)&&(h={insert:c},o.size>0&&(h.attributes={},o.forEach((p,m)=>{p!==null&&(h.attributes[m]=p)}))),c="";break;case"retain":u>0&&(h={retain:u},nQ(l)||(h.attributes=eQ({},l))),u=0;break}h&&n.push(h),a=null}};for(;i!==null;){switch(i.content.constructor){case Sr:case ti:this.adds(i)?this.deletes(i)||(f(),a="insert",c=i.content.getContent()[0],f()):this.deletes(i)?(a!=="delete"&&(f(),a="delete"),d+=1):i.deleted||(a!=="retain"&&(f(),a="retain"),u+=1);break;case br:this.adds(i)?this.deletes(i)||(a!=="insert"&&(f(),a="insert"),c+=i.content.str):this.deletes(i)?(a!=="delete"&&(f(),a="delete"),d+=i.length):i.deleted||(a!=="retain"&&(f(),a="retain"),u+=i.length);break;case kt:{const{key:h,value:p}=i.content;if(this.adds(i)){if(!this.deletes(i)){const m=o.get(h)??null;zo(m,p)?p!==null&&i.delete(r):(a==="retain"&&f(),zo(p,s.get(h)??null)?delete l[h]:l[h]=p)}}else if(this.deletes(i)){s.set(h,p);const m=o.get(h)??null;zo(m,p)||(a==="retain"&&f(),l[h]=m)}else if(!i.deleted){s.set(h,p);const m=l[h];m!==void 0&&(zo(m,p)?m!==null&&i.delete(r):(a==="retain"&&f(),p===null?delete l[h]:l[h]=p))}i.deleted||(a==="insert"&&f(),sa(o,i.content));break}}i=i.right}for(f();n.length>0;){const h=n[n.length-1];if(h.retain!==void 0&&h.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class is extends Bt{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??Zt(),this._length}_integrate(e,n){super._integrate(e,n);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new is}clone(){const e=new is;return e.applyDelta(this.toDelta()),e}_callObserver(e,n){super._callObserver(e,n);const r=new yZ(this,e,n);Lf(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??Zt();let e="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===br&&(e+=n.content.str),n=n.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:n=!0}={}){this.doc!==null?Je(this.doc,r=>{const o=new Ym(null,this._start,0,new Map);for(let s=0;s<e.length;s++){const i=e[s];if(i.insert!==void 0){const a=!n&&typeof i.insert=="string"&&s===e.length-1&&o.right===null&&i.insert.slice(-1)===`
586
- `?i.insert.slice(0,-1):i.insert;(typeof a!="string"||a.length>0)&&pp(r,this,o,a,i.attributes||{})}else i.retain!==void 0?FE(r,this,o,i.retain,i.attributes||{}):i.delete!==void 0&&HE(r,o,i.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,n,r){this.doc??Zt();const o=[],s=new Map,i=this.doc;let a="",l=this._start;function c(){if(a.length>0){const d={};let f=!1;s.forEach((p,m)=>{f=!0,d[m]=p});const h={insert:a};f&&(h.attributes=d),o.push(h),a=""}}const u=()=>{for(;l!==null;){if(vs(l,e)||n!==void 0&&vs(l,n))switch(l.content.constructor){case br:{const d=s.get("ychange");e!==void 0&&!vs(l,e)?(d===void 0||d.user!==l.id.client||d.type!=="removed")&&(c(),s.set("ychange",r?r("removed",l.id):{type:"removed"})):n!==void 0&&!vs(l,n)?(d===void 0||d.user!==l.id.client||d.type!=="added")&&(c(),s.set("ychange",r?r("added",l.id):{type:"added"})):d!==void 0&&(c(),s.delete("ychange")),a+=l.content.str;break}case Sr:case ti:{c();const d={insert:l.content.getContent()[0]};if(s.size>0){const f={};d.attributes=f,s.forEach((h,p)=>{f[p]=h})}o.push(d);break}case kt:vs(l,e)&&(c(),sa(s,l.content));break}l=l.right}c()};return e||n?Je(i,d=>{e&&qm(d,e),n&&qm(d,n),u()},"cleanup"):u(),o}insert(e,n,r){if(n.length<=0)return;const o=this.doc;o!==null?Je(o,s=>{const i=$c(s,this,e,!r);r||(r={},i.currentAttributes.forEach((a,l)=>{r[l]=a})),pp(s,this,i,n,r)}):this._pending.push(()=>this.insert(e,n,r))}insertEmbed(e,n,r){const o=this.doc;o!==null?Je(o,s=>{const i=$c(s,this,e,!r);pp(s,this,i,n,r||{})}):this._pending.push(()=>this.insertEmbed(e,n,r||{}))}delete(e,n){if(n===0)return;const r=this.doc;r!==null?Je(r,o=>{HE(o,$c(o,this,e,!0),n)}):this._pending.push(()=>this.delete(e,n))}format(e,n,r){if(n===0)return;const o=this.doc;o!==null?Je(o,s=>{const i=$c(s,this,e,!1);i.right!==null&&FE(s,this,i,n,r)}):this._pending.push(()=>this.format(e,n,r))}removeAttribute(e){this.doc!==null?Je(this.doc,n=>{wd(n,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,n){this.doc!==null?Je(this.doc,r=>{Nv(r,this,e,n)}):this._pending.push(()=>this.setAttribute(e,n))}getAttribute(e){return _v(this,e)}getAttributes(){return YR(this)}_write(e){e.writeTypeRef(jZ)}}const vZ=t=>new is;class mp{constructor(e,n=()=>!0){this._filter=n,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??Zt()}[Symbol.iterator](){return this}next(){let e=this._currentNode,n=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(n)))do if(n=e.content.type,!e.deleted&&(n.constructor===Qt||n.constructor===Vs)&&n._start!==null)e=n._start;else for(;e!==null;){const r=e.next;if(r!==null){e=r;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 Vs extends Bt{constructor(){super(),this._prelimContent=[]}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,n){super._integrate(e,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Vs}clone(){const e=new Vs;return e.insert(0,this.toArray().map(n=>n instanceof Bt?n.clone():n)),e}get length(){return this.doc??Zt(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new mp(this,e)}querySelector(e){e=e.toUpperCase();const r=new mp(this,o=>o.nodeName&&o.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),zs(new mp(this,n=>n.nodeName&&n.nodeName.toUpperCase()===e))}_callObserver(e,n){Lf(this,e,new wZ(this,n,e))}toString(){return VR(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,n={},r){const o=e.createDocumentFragment();return r!==void 0&&r._createAssociation(o,this),kl(this,s=>{o.insertBefore(s.toDOM(e,n,r),null)}),o}insert(e,n){this.doc!==null?Je(this.doc,r=>{qR(r,this,e,n)}):this._prelimContent.splice(e,0,...n)}insertAfter(e,n){if(this.doc!==null)Je(this.doc,r=>{const o=e&&e instanceof Bt?e._item:e;xd(r,this,o,n)});else{const r=this._prelimContent,o=e===null?0:r.findIndex(s=>s===e)+1;if(o===0&&e!==null)throw rs("Reference item not found");r.splice(o,0,...n)}}delete(e,n=1){this.doc!==null?Je(this.doc,r=>{KR(r,this,e,n)}):this._prelimContent.splice(e,n)}toArray(){return UR(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return WR(this,e)}slice(e=0,n=this.length){return HR(this,e,n)}forEach(e){kl(this,e)}_write(e){e.writeTypeRef(BZ)}}const bZ=t=>new Vs;class Qt extends Vs{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,n){super._integrate(e,n),this._prelimAttrs.forEach((r,o)=>{this.setAttribute(o,r)}),this._prelimAttrs=null}_copy(){return new Qt(this.nodeName)}clone(){const e=new Qt(this.nodeName),n=this.getAttributes();return tQ(n,(r,o)=>{typeof r=="string"&&e.setAttribute(o,r)}),e.insert(0,this.toArray().map(r=>r instanceof Bt?r.clone():r)),e}toString(){const e=this.getAttributes(),n=[],r=[];for(const a in e)r.push(a);r.sort();const o=r.length;for(let a=0;a<o;a++){const l=r[a];n.push(l+'="'+e[l]+'"')}const s=this.nodeName.toLocaleLowerCase(),i=n.length>0?" "+n.join(" "):"";return`<${s}${i}>${super.toString()}</${s}>`}removeAttribute(e){this.doc!==null?Je(this.doc,n=>{wd(n,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,n){this.doc!==null?Je(this.doc,r=>{Nv(r,this,e,n)}):this._prelimAttrs.set(e,n)}getAttribute(e){return _v(this,e)}hasAttribute(e){return JR(this,e)}getAttributes(e){return e?cZ(this,e):YR(this)}toDOM(e=document,n={},r){const o=e.createElement(this.nodeName),s=this.getAttributes();for(const i in s){const a=s[i];typeof a=="string"&&o.setAttribute(i,a)}return kl(this,i=>{o.appendChild(i.toDOM(e,n,r))}),r!==void 0&&r._createAssociation(o,this),o}_write(e){e.writeTypeRef($Z),e.writeKey(this.nodeName)}}const xZ=t=>new Qt(t.readKey());class wZ extends If{constructor(e,n,r){super(e,r),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(o=>{o===null?this.childListChanged=!0:this.attributesChanged.add(o)})}}class Ed extends Wi{constructor(e){super(),this.hookName=e}_copy(){return new Ed(this.hookName)}clone(){const e=new Ed(this.hookName);return this.forEach((n,r)=>{e.set(r,n)}),e}toDOM(e=document,n={},r){const o=n[this.hookName];let s;return o!==void 0?s=o.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(FZ),e.writeKey(this.hookName)}}const EZ=t=>new Ed(t.readKey());class An extends is{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 An}clone(){const e=new An;return e.applyDelta(this.toDelta()),e}toDOM(e=document,n,r){const o=e.createTextNode(this.toString());return r!==void 0&&r._createAssociation(o,this),o}toString(){return this.toDelta().map(e=>{const n=[];for(const o in e.attributes){const s=[];for(const i in e.attributes[o])s.push({key:i,value:e.attributes[o][i]});s.sort((i,a)=>i.key<a.key?-1:1),n.push({nodeName:o,attrs:s})}n.sort((o,s)=>o.nodeName<s.nodeName?-1:1);let r="";for(let o=0;o<n.length;o++){const s=n[o];r+=`<${s.nodeName}`;for(let i=0;i<s.attrs.length;i++){const a=s.attrs[i];r+=` ${a.key}="${a.value}"`}r+=">"}r+=e.insert;for(let o=n.length-1;o>=0;o--)r+=`</${n[o].nodeName}>`;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(HZ)}}const SZ=t=>new An;class Dv{constructor(e,n){this.id=e,this.length=n}get deleted(){throw hr()}mergeWith(e){return!1}write(e,n,r){throw hr()}integrate(e,n){throw hr()}}const kZ=0;class qn extends Dv{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,n){n>0&&(this.id.clock+=n,this.length-=n),IR(e.doc.store,this)}write(e,n){e.writeInfo(kZ),e.writeLen(this.length-n)}getMissing(e,n){return null}}class nc{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new nc(this.content)}splice(e){throw hr()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeBuf(this.content)}getRef(){return 3}}const TZ=t=>new nc(t.readBuf());class Tl{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Tl(this.len)}splice(e){const n=new Tl(this.len-e);return this.len=e,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,n){xl(e.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(e){}gc(e){}write(e,n){e.writeLen(this.len-n)}getRef(){return 1}}const CZ=t=>new Tl(t.readLen()),tN=(t,e)=>new ei({guid:t,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class rc{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 n={};this.opts=n,e.gc||(n.gc=!1),e.autoLoad&&(n.autoLoad=!0),e.meta!==null&&(n.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new rc(tN(this.doc.guid,this.opts))}splice(e){throw hr()}mergeWith(e){return!1}integrate(e,n){this.doc._item=n,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,n){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}}const AZ=t=>new rc(tN(t.readString(),t.readAny()));class ti{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new ti(this.embed)}splice(e){throw hr()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeJSON(this.embed)}getRef(){return 5}}const MZ=t=>new ti(t.readJSON());class kt{constructor(e,n){this.key=e,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new kt(this.key,this.value)}splice(e){throw hr()}mergeWith(e){return!1}integrate(e,n){const r=n.parent;r._searchMarker=null,r._hasFormatting=!0}delete(e){}gc(e){}write(e,n){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}const OZ=t=>new kt(t.readKey(),t.readJSON());class Sd{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Sd(this.arr)}splice(e){const n=new Sd(this.arr.slice(e));return this.arr=this.arr.slice(0,e),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,n){}delete(e){}gc(e){}write(e,n){const r=this.arr.length;e.writeLen(r-n);for(let o=n;o<r;o++){const s=this.arr[o];e.writeString(s===void 0?"undefined":JSON.stringify(s))}}getRef(){return 2}}const RZ=t=>{const e=t.readLen(),n=[];for(let r=0;r<e;r++){const o=t.readString();o==="undefined"?n.push(void 0):n.push(JSON.parse(o))}return new Sd(n)},NZ=yd("node_env")==="development";class Ws{constructor(e){this.arr=e,NZ&&yR(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Ws(this.arr)}splice(e){const n=new Ws(this.arr.slice(e));return this.arr=this.arr.slice(0,e),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,n){}delete(e){}gc(e){}write(e,n){const r=this.arr.length;e.writeLen(r-n);for(let o=n;o<r;o++){const s=this.arr[o];e.writeAny(s)}}getRef(){return 8}}const _Z=t=>{const e=t.readLen(),n=[];for(let r=0;r<e;r++)n.push(t.readAny());return new Ws(n)};class br{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new br(this.str)}splice(e){const n=new br(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)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}}const DZ=t=>new br(t.readString()),IZ=[dZ,hZ,vZ,xZ,bZ,EZ,SZ],PZ=0,LZ=1,jZ=2,$Z=3,BZ=4,FZ=5,HZ=6;class Sr{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new Sr(this.type._copy())}splice(e){throw hr()}mergeWith(e){return!1}integrate(e,n){this.type._integrate(e.doc,n)}delete(e){let n=this.type._start;for(;n!==null;)n.deleted?n.id.clock<(e.beforeState.get(n.id.client)||0)&&e._mergeStructs.push(n):n.delete(e),n=n.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 n=this.type._start;for(;n!==null;)n.gc(e,!0),n=n.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,n){this.type._write(e)}getRef(){return 7}}const UZ=t=>new Sr(IZ[t.readTypeRef()](t)),Jm=(t,e)=>{let n=e,r=0,o;do r>0&&(n=De(n.client,n.clock+r)),o=Ti(t,n),r=n.clock-o.id.clock,n=o.redone;while(n!==null&&o instanceof nt);return{item:o,diff:r}},Iv=(t,e)=>{for(;t!==null&&t.keep!==e;)t.keep=e,t=t.parent._item},kd=(t,e,n)=>{const{client:r,clock:o}=e.id,s=new nt(De(r,o+n),e,De(r,o+n-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(n));return e.deleted&&s.markDeleted(),e.keep&&(s.keep=!0),e.redone!==null&&(s.redone=De(e.redone.client,e.redone.clock+n)),e.right=s,s.right!==null&&(s.right.left=s),t._mergeStructs.push(s),s.parentSub!==null&&s.right===null&&s.parent._map.set(s.parentSub,s),e.length=n,s},UE=(t,e)=>hX(t,n=>oa(n.deletions,e)),nN=(t,e,n,r,o,s)=>{const i=t.doc,a=i.store,l=i.clientID,c=e.redone;if(c!==null)return xn(t,c);let u=e.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||nN(t,u,n,r,o,s)===null))return null;for(;u.redone!==null;)u=xn(t,u.redone)}const h=u===null?e.parent:u.content.type;if(e.parentSub===null){for(d=e.left,f=e;d!==null;){let v=d;for(;v!==null&&v.parent._item!==u;)v=v.redone===null?null:xn(t,v.redone);if(v!==null&&v.parent._item===u){d=v;break}d=d.left}for(;f!==null;){let v=f;for(;v!==null&&v.parent._item!==u;)v=v.redone===null?null:xn(t,v.redone);if(v!==null&&v.parent._item===u){f=v;break}f=f.right}}else if(f=null,e.right&&!o){for(d=e;d!==null&&d.right!==null&&(d.right.redone||oa(r,d.right.id)||UE(s.undoStack,d.right.id)||UE(s.redoStack,d.right.id));)for(d=d.right;d.redone;)d=xn(t,d.redone);if(d&&d.right!==null)return null}else d=h._map.get(e.parentSub)||null;const p=xt(a,l),m=De(l,p),y=new nt(m,d,d&&d.lastId,f,f&&f.id,h,e.parentSub,e.content.copy());return e.redone=m,Iv(y,!0),y.integrate(t,0),y};let nt=class Xm extends Dv{constructor(e,n,r,o,s,i,a,l){super(e,l.getLength()),this.origin=r,this.left=n,this.right=o,this.rightOrigin=s,this.parent=i,this.parentSub=a,this.redone=null,this.content=l,this.info=this.content.isCountable()?vE:0}set marker(e){(this.info&lp)>0!==e&&(this.info^=lp)}get marker(){return(this.info&lp)>0}get keep(){return(this.info&yE)>0}set keep(e){this.keep!==e&&(this.info^=yE)}get countable(){return(this.info&vE)>0}get deleted(){return(this.info&ap)>0}set deleted(e){this.deleted!==e&&(this.info^=ap)}markDeleted(){this.info|=ap}getMissing(e,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=xt(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=xt(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ki&&this.id.client!==this.parent.client&&this.parent.clock>=xt(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=_E(e,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=xn(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===qn||this.right&&this.right.constructor===qn)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===Xm?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===Xm&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===ki){const r=Ti(n,this.parent);r.constructor===qn?this.parent=null:this.parent=r.content.type}return null}integrate(e,n){if(n>0&&(this.id.clock+=n,this.left=_E(e,e.doc.store,De(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,o;if(r!==null)o=r.right;else if(this.parentSub!==null)for(o=this.parent._map.get(this.parentSub)||null;o!==null&&o.left!==null;)o=o.left;else o=this.parent._start;const s=new Set,i=new Set;for(;o!==null&&o!==this.right;){if(i.add(o),s.add(o),Pc(this.origin,o.origin)){if(o.id.client<this.id.client)r=o,s.clear();else if(Pc(this.rightOrigin,o.rightOrigin))break}else if(o.origin!==null&&i.has(Ti(e.doc.store,o.origin)))s.has(Ti(e.doc.store,o.origin))||(r=o,s.clear());else break;o=o.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),IR(e.doc.store,this),this.content.integrate(e,this),IE(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new qn(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:De(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&Pc(e.origin,this.lastId)&&this.right===e&&Pc(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 n=this.parent._searchMarker;return n&&n.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 n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),xl(e.deleteSet,this.id.client,this.id.clock,this.length),IE(e,n,this.parentSub),this.content.delete(e)}}gc(e,n){if(!this.deleted)throw Mn();this.content.gc(e),n?qQ(e,this,new qn(this.id,this.length)):this.content=new Tl(this.length)}write(e,n){const r=n>0?De(this.id.client,this.id.clock+n-1):this.origin,o=this.rightOrigin,s=this.parentSub,i=this.content.getRef()&Of|(r===null?0:an)|(o===null?0:co)|(s===null?0:yl);if(e.writeInfo(i),r!==null&&e.writeLeftID(r),o!==null&&e.writeRightID(o),r===null&&o===null){const a=this.parent;if(a._item!==void 0){const l=a._item;if(l===null){const c=wl(a);e.writeParentInfo(!0),e.writeString(c)}else e.writeParentInfo(!1),e.writeLeftID(l.id)}else a.constructor===String?(e.writeParentInfo(!0),e.writeString(a)):a.constructor===ki?(e.writeParentInfo(!1),e.writeLeftID(a)):Mn();s!==null&&e.writeString(s)}this.content.write(e,n)}};const rN=(t,e)=>zZ[e&Of](t),zZ=[()=>{Mn()},CZ,RZ,TZ,DZ,MZ,OZ,UZ,_Z,AZ,()=>{Mn()}],VZ=10;class cr extends Dv{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,n){Mn()}write(e,n){e.writeInfo(VZ),$e(e.restEncoder,this.length-n)}getMissing(e,n){return null}}const oN=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},sN="__ $YJS$ __";oN[sN]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");oN[sN]=!0;const WZ=()=>{let t=!0;return(e,n)=>{if(t){t=!1;try{e()}finally{t=!0}}else n!==void 0&&n()}},GZ=/[\uD800-\uDBFF]/,qZ=/[\uDC00-\uDFFF]/,KZ=(t,e)=>{let n=0,r=0;for(;n<t.length&&n<e.length&&t[n]===e[n];)n++;for(n>0&&GZ.test(t[n-1])&&n--;r+n<t.length&&r+n<e.length&&t[t.length-r-1]===e[e.length-r-1];)r++;return r>0&&qZ.test(t[t.length-r])&&r--,{index:n,remove:t.length-n-r,insert:e.slice(n,e.length-r)}},YZ=KZ,Fr=(t,e)=>t>>>e|t<<32-e,JZ=t=>Fr(t,2)^Fr(t,13)^Fr(t,22),XZ=t=>Fr(t,6)^Fr(t,11)^Fr(t,25),QZ=t=>Fr(t,7)^Fr(t,18)^t>>>3,ZZ=t=>Fr(t,17)^Fr(t,19)^t>>>10,eee=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),tee=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class nee{constructor(){const e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(tee),this._W=new Uint32Array(e,64,64)}_updateHash(){const e=this._H,n=this._W;for(let d=16;d<64;d++)n[d]=ZZ(n[d-2])+n[d-7]+QZ(n[d-15])+n[d-16];let r=e[0],o=e[1],s=e[2],i=e[3],a=e[4],l=e[5],c=e[6],u=e[7];for(let d=0,f,h;d<64;d++)f=u+XZ(a)+(a&l^~a&c)+eee[d]+n[d]>>>0,h=JZ(r)+(r&o^r&s^o&s)>>>0,u=c,c=l,l=a,a=i+f>>>0,i=s,s=o,o=r,r=f+h>>>0;e[0]+=r,e[1]+=o,e[2]+=s,e[3]+=i,e[4]+=a,e[5]+=l,e[6]+=c,e[7]+=u}digest(e){let n=0;for(;n+56<=e.length;){let i=0;for(;i<16&&n+3<e.length;i++)this._W[i]=e[n++]<<24|e[n++]<<16|e[n++]<<8|e[n++];if(n%64!==0){for(this._W.fill(0,i,16);n<e.length;)this._W[i]|=e[n]<<(3-n%4)*8,n++;this._W[i]|=an<<(3-n%4)*8}this._updateHash()}const r=n%64!==0;this._W.fill(0,0,16);let o=0;for(;n<e.length;o++)for(let i=3;i>=0&&n<e.length;i--)this._W[o]|=e[n++]<<i*8;r||(this._W[o-(n%4===0?0:1)]|=an<<(3-n%4)*8),this._W[14]=e.byteLength/pX,this._W[15]=e.byteLength*8,this._updateHash();const s=new Uint8Array(32);for(let i=0;i<this._H.length;i++)for(let a=0;a<4;a++)s[i*4+a]=this._H[i]>>>(3-a)*8;return s}}const ree=t=>new nee().digest(t),pt=new We("y-sync"),uo=new We("y-undo");new We("yjs-cursor");const oee=t=>{for(let n=6;n<t.length;n++)t[n%6]=t[n%6]^t[n];return t.slice(0,6)},see=t=>fQ(oee(ree(hQ(t)))),Td=(t,e)=>e===void 0?!t.deleted:e.sv.has(t.id.client)&&e.sv.get(t.id.client)>t.id.clock&&!oa(e.ds,t.id),iee=[{light:"#ecd44433",dark:"#ecd444"}],aee=(t,e,n)=>{if(!t.has(n)){if(t.size<e.length){const r=Us();t.forEach(o=>r.add(o)),e=e.filter(o=>!r.has(o))}t.set(n,qX(e))}return t.get(n)},lee=(t,{colors:e=iee,colorMapping:n=new Map,permanentUserData:r=null,onFirstRender:o=()=>{},mapping:s}={})=>{let i=!1;const a=new uee(t,s),l=new Ue({props:{editable:c=>{const u=pt.getState(c);return u.snapshot==null&&u.prevSnapshot==null}},key:pt,state:{init:(c,u)=>({type:t,doc:t.doc,binding:a,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:e,colorMapping:n,permanentUserData:r}),apply:(c,u)=>{const d=c.getMeta(pt);if(d!==void 0){u=Object.assign({},u);for(const f in d)u[f]=d[f]}return u.addToHistory=c.getMeta("addToHistory")!==!1,u.isChangeOrigin=d!==void 0&&!!d.isChangeOrigin,u.isUndoRedoOperation=d!==void 0&&!!d.isChangeOrigin&&!!d.isUndoRedoOperation,a.prosemirrorView!==null&&d!==void 0&&(d.snapshot!=null||d.prevSnapshot!=null)&&xR(0,()=>{a.prosemirrorView!=null&&(d.restore==null?a._renderSnapshot(d.snapshot,d.prevSnapshot,u):(a._renderSnapshot(d.snapshot,d.snapshot,u),delete u.restore,delete u.snapshot,delete u.prevSnapshot,a.mux(()=>{a._prosemirrorChanged(a.prosemirrorView.state.doc)})))}),u}},view:c=>(a.initView(c),s==null&&a._forceRerender(),o(),{update:()=>{const u=l.getState(c.state);if(u.snapshot==null&&u.prevSnapshot==null&&(i||c.state.doc.content.findDiffStart(c.state.doc.type.createAndFill().content)!==null)){if(i=!0,u.addToHistory===!1&&!u.isChangeOrigin){const d=uo.getState(c.state),f=d&&d.undoManager;f&&f.stopCapturing()}a.mux(()=>{u.doc.transact(d=>{d.meta.set("addToHistory",u.addToHistory),a._prosemirrorChanged(c.state.doc)},pt)})}},destroy:()=>{a.destroy()}})});return l},cee=(t,e,n)=>{if(e!==null&&e.anchor!==null&&e.head!==null)if(e.type==="all")t.setSelection(new Sn(t.doc));else if(e.type==="node"){const r=iu(n.doc,n.type,e.anchor,n.mapping);t.setSelection(ue.create(t.doc,r))}else{const r=iu(n.doc,n.type,e.anchor,n.mapping),o=iu(n.doc,n.type,e.head,n.mapping);r!==null&&o!==null&&t.setSelection(pe.between(t.doc.resolve(r),t.doc.resolve(o)))}},Qm=(t,e)=>({type:e.selection.jsonID,anchor:ng(e.selection.anchor,t.type,t.mapping),head:ng(e.selection.head,t.type,t.mapping)});class uee{constructor(e,n=new Map){this.type=e,this.prosemirrorView=null,this.mux=WZ(),this.mapping=n,this.isOMark=new Map,this._observeFunction=this._typeChanged.bind(this),this.doc=e.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=Qm(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return this.prosemirrorView.hasFocus()?(vR&&this._domSelectionInView===null&&(xR(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){const e=this.prosemirrorView._root.getSelection();if(e==null||e.anchorNode==null)return!1;const n=this.prosemirrorView._root.createRange();n.setStart(e.anchorNode,e.anchorOffset),n.setEnd(e.focusNode,e.focusOffset),n.getClientRects().length===0&&n.startContainer&&n.collapsed&&n.selectNodeContents(n.startContainer);const o=n.getBoundingClientRect(),s=mQ.documentElement;return o.bottom>=0&&o.right>=0&&o.left<=(window.innerWidth||s.clientWidth||0)&&o.top<=(window.innerHeight||s.clientHeight||0)}renderSnapshot(e,n){n||(n=_R(MR(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(pt,{snapshot:e,prevSnapshot:n}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{const e=this.type.toArray().map(r=>su(r,this.prosemirrorView.state.schema,this)).filter(r=>r!==null),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new ee(F.from(e),0,0));n.setMeta(pt,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(n)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{const e=this.beforeTransactionSelection!==null?null:this.prosemirrorView.state.selection,n=this.type.toArray().map(o=>su(o,this.prosemirrorView.state.schema,this)).filter(o=>o!==null),r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new ee(F.from(n),0,0));if(e){const o=Ui(ns(e.anchor,0),r.doc.content.size),s=Ui(ns(e.head,0),r.doc.content.size);r.setSelection(pe.create(r.doc,o,s))}this.prosemirrorView.dispatch(r.setMeta(pt,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,n,r){let o=this.doc,s=this.type;if(e||(e=hp(this.doc)),e instanceof Uint8Array||n instanceof Uint8Array)if((!(e instanceof Uint8Array)||!(n instanceof Uint8Array))&&Mn(),o=new ei({gc:!1}),Gm(o,n),n=hp(o),Gm(o,e),e=hp(o),s._item===null){const i=Array.from(this.doc.share.keys()).find(a=>this.doc.share.get(a)===this.type);s=o.getXmlFragment(i)}else{const i=o.store.clients.get(s._item.id.client)??[],a=vr(i,s._item.id.clock);s=i[a].content.type}this.mapping.clear(),this.mux(()=>{o.transact(i=>{const a=r.permanentUserData;a&&a.dss.forEach(d=>{ss(i,d,f=>{})});const l=(d,f)=>{const h=d==="added"?a.getUserByClientId(f.client):a.getUserByDeletedId(f);return{user:h,type:d,color:aee(r.colorMapping,r.colors,h)}},c=zR(s,new Ov(n.ds,e.sv)).map(d=>!d._item.deleted||Td(d._item,e)||Td(d._item,n)?su(d,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},e,n,l):null).filter(d=>d!==null),u=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new ee(F.from(c),0,0));this.prosemirrorView.dispatch(u.setMeta(pt,{isChangeOrigin:!0}))},pt)})}_typeChanged(e,n){if(this.prosemirrorView==null)return;const r=pt.getState(this.prosemirrorView.state);if(e.length===0||r.snapshot!=null||r.prevSnapshot!=null){this.renderSnapshot(r.snapshot,r.prevSnapshot);return}this.mux(()=>{const o=(a,l)=>this.mapping.delete(l);ss(n,n.deleteSet,a=>{if(a.constructor===nt){const l=a.content.type;l&&this.mapping.delete(l)}}),n.changed.forEach(o),n.changedParentTypes.forEach(o);const s=this.type.toArray().map(a=>iN(a,this.prosemirrorView.state.schema,this)).filter(a=>a!==null);let i=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new ee(F.from(s),0,0));cee(i,this.beforeTransactionSelection,this),i=i.setMeta(pt,{isChangeOrigin:!0,isUndoRedoOperation:n.origin instanceof jR}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&i.scrollIntoView(),this.prosemirrorView.dispatch(i)})}_prosemirrorChanged(e){this.doc.transact(()=>{eg(this.doc,this.type,e,this),this.beforeTransactionSelection=Qm(this,this.prosemirrorView.state)},pt)}initView(e){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=e,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}}const iN=(t,e,n,r,o,s)=>{const i=n.mapping.get(t);if(i===void 0){if(t instanceof Qt)return su(t,e,n,r,o,s);throw hr()}return i},su=(t,e,n,r,o,s)=>{const i=[],a=l=>{if(l instanceof Qt){const c=iN(l,e,n,r,o,s);c!==null&&i.push(c)}else{const c=l._item.right?.content?.type;c instanceof is&&!c._item.deleted&&c._item.id.client===c.doc.clientID&&(l.applyDelta([{retain:l.length},...c.toDelta()]),c.doc.transact(d=>{c._item.delete(d)}));const u=dee(l,e,n,r,o,s);u!==null&&u.forEach(d=>{d!==null&&i.push(d)})}};r===void 0||o===void 0?t.toArray().forEach(a):zR(t,new Ov(o.ds,r.sv)).forEach(a);try{const l=t.getAttributes(r);r!==void 0&&(Td(t._item,r)?Td(t._item,o)||(l.ychange=s?s("added",t._item.id):{type:"added"}):l.ychange=s?s("removed",t._item.id):{type:"removed"});const c=e.node(t.nodeName,l,i);return n.mapping.set(t,c),c}catch{return t.doc.transact(c=>{t._item.delete(c)},pt),n.mapping.delete(t),null}},dee=(t,e,n,r,o,s)=>{const i=[],a=t.toDelta(r,o,s);try{for(let l=0;l<a.length;l++){const c=a[l];i.push(e.text(c.insert,yee(c.attributes,e)))}}catch{return t.doc.transact(c=>{t._item.delete(c)},pt),null}return i},fee=(t,e)=>{const n=new An,r=t.map(o=>({insert:o.text,attributes:lN(o.marks,e)}));return n.applyDelta(r),e.mapping.set(n,t),n},hee=(t,e)=>{const n=new Qt(t.type.name);for(const r in t.attrs){const o=t.attrs[r];o!==null&&r!=="ychange"&&n.setAttribute(r,o)}return n.insert(0,jf(t).map(r=>Zm(r,e))),e.mapping.set(n,t),n},Zm=(t,e)=>t instanceof Array?fee(t,e):hee(t,e),zE=t=>typeof t=="object"&&t!==null,Pv=(t,e)=>{const n=Object.keys(t).filter(o=>t[o]!==null);let r=n.length===Object.keys(e).filter(o=>e[o]!==null).length;for(let o=0;o<n.length&&r;o++){const s=n[o],i=t[s],a=e[s];r=s==="ychange"||i===a||zE(i)&&zE(a)&&Pv(i,a)}return r},jf=t=>{const e=t.content.content,n=[];for(let r=0;r<e.length;r++){const o=e[r];if(o.isText){const s=[];for(let i=e[r];r<e.length&&i.isText;i=e[++r])s.push(i);r--,n.push(s)}else n.push(o)}return n},aN=(t,e)=>{const n=t.toDelta();return n.length===e.length&&n.every((r,o)=>r.insert===e[o].text&&mR(r.attributes||{}).length===e[o].marks.length&&gR(r.attributes,(s,i)=>{const a=Lv(i),l=e[o].marks;return Pv(s,l.find(c=>c.type.name===a)?.attrs)}))},Cl=(t,e)=>{if(t instanceof Qt&&!(e instanceof Array)&&tg(t,e)){const n=jf(e);return t._length===n.length&&Pv(t.getAttributes(),e.attrs)&&t.toArray().every((r,o)=>Cl(r,n[o]))}return t instanceof An&&e instanceof Array&&aN(t,e)},Cd=(t,e)=>t===e||t instanceof Array&&e instanceof Array&&t.length===e.length&&t.every((n,r)=>e[r]===n),VE=(t,e,n)=>{const r=t.toArray(),o=jf(e),s=o.length,i=r.length,a=Ui(i,s);let l=0,c=0,u=!1;for(;l<a;l++){const d=r[l],f=o[l];if(Cd(n.mapping.get(d),f))u=!0;else if(!Cl(d,f))break}for(;l+c<a;c++){const d=r[i-c-1],f=o[s-c-1];if(Cd(n.mapping.get(d),f))u=!0;else if(!Cl(d,f))break}return{equalityFactor:l+c,foundMappedChild:u}},pee=t=>{let e="",n=t._start;const r={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof br?e+=n.content.str:n.content instanceof kt&&(r[n.content.key]=null)),n=n.right;return{str:e,nAttrs:r}},mee=(t,e,n)=>{n.mapping.set(t,e);const{nAttrs:r,str:o}=pee(t),s=e.map(c=>({insert:c.text,attributes:Object.assign({},r,lN(c.marks,n))})),{insert:i,remove:a,index:l}=YZ(o,s.map(c=>c.insert).join(""));t.delete(l,a),t.insert(l,i),t.applyDelta(s.map(c=>({retain:c.insert.length,attributes:c.attributes})))},gee=/(.*)(--[a-zA-Z0-9+/=]{8})$/,Lv=t=>gee.exec(t)?.[1]??t,yee=(t,e)=>{const n=[];for(const r in t)n.push(e.mark(Lv(r),t[r]));return n},lN=(t,e)=>{const n={};return t.forEach(r=>{if(r.type.name!=="ychange"){const o=ko(e.isOMark,r.type,()=>!r.type.excludes(r.type));n[o?`${r.type.name}--${see(r.toJSON())}`:r.type.name]=r.attrs}}),n},eg=(t,e,n,r)=>{if(e instanceof Qt&&e.nodeName!==n.type.name)throw new Error("node name mismatch!");if(r.mapping.set(e,n),e instanceof Qt){const d=e.getAttributes(),f=n.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 o=jf(n),s=o.length,i=e.toArray(),a=i.length,l=Ui(s,a);let c=0,u=0;for(;c<l;c++){const d=i[c],f=o[c];if(!Cd(r.mapping.get(d),f))if(Cl(d,f))r.mapping.set(d,f);else break}for(;u+c+1<l;u++){const d=i[a-u-1],f=o[s-u-1];if(!Cd(r.mapping.get(d),f))if(Cl(d,f))r.mapping.set(d,f);else break}t.transact(()=>{for(;a-c-u>0&&s-c-u>0;){const f=i[c],h=o[c],p=i[a-u-1],m=o[s-u-1];if(f instanceof An&&h instanceof Array)aN(f,h)||mee(f,h,r),c+=1;else{let y=f instanceof Qt&&tg(f,h),v=p instanceof Qt&&tg(p,m);if(y&&v){const w=VE(f,h,r),E=VE(p,m,r);w.foundMappedChild&&!E.foundMappedChild?v=!1:!w.foundMappedChild&&E.foundMappedChild||w.equalityFactor<E.equalityFactor?y=!1:v=!1}y?(eg(t,f,h,r),c+=1):v?(eg(t,p,m,r),u+=1):(r.mapping.delete(e.get(c)),e.delete(c,1),e.insert(c,[Zm(h,r)]),c+=1)}}const d=a-c-u;if(a===1&&s===0&&i[0]instanceof An?(r.mapping.delete(i[0]),i[0].delete(0,i[0].length)):d>0&&(e.slice(c,c+d).forEach(f=>r.mapping.delete(f)),e.delete(c,d)),c+u<s){const f=[];for(let h=c;h<s-u;h++)f.push(Zm(o[h],r));e.insert(c,f)}},pt)},tg=(t,e)=>!(e instanceof Array)&&t.nodeName===e.type.name,ng=(t,e,n)=>{if(t===0)return fp(e,0,-1);let r=e._first===null?null:e._first.content.type;for(;r!==null&&e!==r;){if(r instanceof An){if(r._length>=t)return fp(r,t,-1);if(t-=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,t--;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 o=(n.get(r)||{nodeSize:0}).nodeSize;if(r._first!==null&&t<o)r=r._first.content.type,t--;else{if(t===1&&r._length===0&&o>1)return new bd(r._item===null?null:r._item.id,r._item===null?wl(r):null,null);if(t-=o,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{if(t===0)return r=r._item===null?r:r._item.parent,new bd(r._item===null?null:r._item.id,r._item===null?wl(r):null,null);do r=r._item.parent,t--;while(r!==e&&r._item.next===null);r!==e&&(r=r._item.next.content.type)}}}if(r===null)throw Mn();if(t===0&&r.constructor!==An&&r!==e)return vee(r._item.parent,r._item)}return fp(e,e._length,-1)},vee=(t,e)=>{let n=null,r=null;return t._item===null?r=wl(t):n=De(t._item.id.client,t._item.id.clock),new bd(n,r,e.id)},iu=(t,e,n,r)=>{const o=WQ(n,t);if(o===null||o.type!==e&&!El(e,o.type._item))return null;let s=o.type,i=0;if(s.constructor===An)i=o.index;else if(s._item===null||!s._item.deleted){let a=s._first,l=0;for(;l<s._length&&l<o.index&&a!==null;){if(!a.deleted){const c=a.content.type;l++,c instanceof An?i+=c._length:i+=r.get(c).nodeSize}a=a.right}i+=1}for(;s!==e&&s._item!==null;){const a=s._item.parent;if(a._item===null||!a._item.deleted){i+=1;let l=a._first;for(;l!==null;){const c=l.content.type;if(c===s)break;l.deleted||(c instanceof An?i+=c._length:i+=r.get(c).nodeSize),l=l.right}}s=a}return i-1};function bee(t){const e=t.toArray(),n=r=>{let o;if(r instanceof An)o=r.toDelta().map(i=>{const a={type:"text",text:i.insert};return i.attributes&&(a.marks=Object.keys(i.attributes).map(l=>{const c=i.attributes[l],d={type:Lv(l)};return Object.keys(c)&&(d.attrs=c),d})),a});else if(r instanceof Qt){o={type:r.nodeName};const s=r.getAttributes();Object.keys(s).length&&(o.attrs=s);const i=r.toArray();i.length&&(o.content=i.map(n).flat())}else Mn();return o};return{type:"doc",content:e.map(n)}}const xee=t=>{const e=uo.getState(t).undoManager;if(e!=null)return e.undo(),!0},wee=t=>{const e=uo.getState(t).undoManager;if(e!=null)return e.redo(),!0},Eee=new Set(["paragraph"]),See=(t,e)=>!(t instanceof nt)||!(t.content instanceof Sr)||!(t.content.type instanceof is||t.content.type instanceof Qt&&e.has(t.content.type.nodeName))||t.content.type._length===0,kee=({protectedNodes:t=Eee,trackedOrigins:e=[],undoManager:n=null}={})=>new Ue({key:uo,state:{init:(r,o)=>{const s=pt.getState(o),i=n||new jR(s.type,{trackedOrigins:new Set([pt].concat(e)),deleteFilter:a=>See(a,t),captureTransaction:a=>a.meta.get("addToHistory")!==!1});return{undoManager:i,prevSel:null,hasUndoOps:i.undoStack.length>0,hasRedoOps:i.redoStack.length>0}},apply:(r,o,s,i)=>{const a=pt.getState(i).binding,l=o.undoManager,c=l.undoStack.length>0,u=l.redoStack.length>0;return a?{undoManager:l,prevSel:Qm(a,s),hasUndoOps:c,hasRedoOps:u}:c!==o.hasUndoOps||u!==o.hasRedoOps?Object.assign({},o,{hasUndoOps:l.undoStack.length>0,hasRedoOps:l.redoStack.length>0}):o}},view:r=>{const o=pt.getState(r.state),s=uo.getState(r.state).undoManager;return s.on("stack-item-added",({stackItem:i})=>{const a=o.binding;a&&i.meta.set(a,uo.getState(r.state).prevSel)}),s.on("stack-item-popped",({stackItem:i})=>{const a=o.binding;a&&(a.beforeTransactionSelection=i.meta.get(a)||a.beforeTransactionSelection)}),{destroy:()=>{s.destroy()}}}});Qe.create({name:"collaboration",priority:1e3,addOptions(){return{document:null,field:"default",fragment:null,provider:null}},addStorage(){return{isDisabled:!1}},onCreate(){this.editor.extensionManager.extensions.find(t=>t.name==="undoRedo")&&console.warn('[tiptap warn]: "@tiptap/extension-collaboration" comes with its own history support and is not compatible with "@tiptap/extension-undo-redo".')},addCommands(){return{undo:()=>({tr:t,state:e,dispatch:n})=>(t.setMeta("preventDispatch",!0),uo.getState(e).undoManager.undoStack.length===0?!1:n?xee(e):!0),redo:()=>({tr:t,state:e,dispatch:n})=>(t.setMeta("preventDispatch",!0),uo.getState(e).undoManager.redoStack.length===0?!1:n?wee(e):!0)}},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo()}},addProseMirrorPlugins(){var t;const e=this.options.fragment?this.options.fragment:this.options.document.getXmlFragment(this.options.field),n=kee(this.options.yUndoOptions),r=n.spec.view;n.spec.view=i=>{const{undoManager:a}=uo.getState(i.state);a.restore&&(a.restore(),a.restore=()=>{});const l=r?r(i):void 0;return{destroy:()=>{const c=a.trackedOrigins.has(a),u=a._observers;a.restore=()=>{c&&a.trackedOrigins.add(a),a.doc.on("afterTransaction",a.afterTransactionHandler),a._observers=u},l?.destroy&&l.destroy()}}};const o={...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender},s=lee(e,o);return this.editor.options.enableContentCheck&&((t=e.doc)==null||t.on("beforeTransaction",()=>{try{const i=bee(e);if(i.content.length===0)return;this.editor.schema.nodeFromJSON(i).check()}catch(i){return this.editor.emit("contentError",{error:i,editor:this.editor,disableCollaboration:()=>{var a;(a=e.doc)==null||a.destroy(),this.storage.isDisabled=!0}}),!1}})),[s,n,this.editor.options.enableContentCheck&&new Ue({key:new We("filterInvalidContent"),filterTransaction:()=>{var i;return this.storage.isDisabled!==!1&&((i=e.doc)==null||i.destroy()),!0}})].filter(Boolean)}});function Tee(t){return!!t.getMeta(pt)}function WE(t){if(!t.length)return et.empty;const e=[],n=t[0].$from.node(0);return t.forEach(r=>{const o=r.$from.pos,s=r.$from.nodeAfter;s&&e.push(Gt.node(o,o+s.nodeSize,{class:"ProseMirror-selectednoderange"}))}),et.create(n,e)}function $f(t,e,n){const r=[],o=t.node(0);typeof n=="number"&&n>=0||(t.sameParent(e)?n=Math.max(0,t.sharedDepth(e.pos)-1):n=t.sharedDepth(e.pos));const s=new Ga(t,e,n),i=s.depth===0?0:o.resolve(s.start).posAtIndex(0);return s.parent.forEach((a,l)=>{const c=i+l,u=c+a.nodeSize;if(c<s.start||c>=s.end)return;const d=new Qk(o.resolve(c),o.resolve(u));r.push(d)}),r}var Cee=class cN{constructor(e,n){this.anchor=e,this.head=n}map(e){return new cN(e.map(this.anchor),e.map(this.head))}resolve(e){const n=e.resolve(this.anchor),r=e.resolve(this.head);return new Vo(n,r)}},Vo=class _o extends Oe{constructor(e,n,r,o=1){const{doc:s}=e,i=e===n,a=e.pos===s.content.size&&n.pos===s.content.size,l=i&&!a?s.resolve(n.pos+(o>0?1:-1)):n,c=i&&a?s.resolve(e.pos-(o>0?1:-1)):e,u=$f(c.min(l),c.max(l),r),d=l.pos>=e.pos?u[0].$from:u[u.length-1].$to,f=l.pos>=e.pos?u[u.length-1].$to:u[0].$from;super(d,f,u),this.depth=r}get $to(){return this.ranges[this.ranges.length-1].$to}eq(e){return e instanceof _o&&e.$from.pos===this.$from.pos&&e.$to.pos===this.$to.pos}map(e,n){const r=e.resolve(n.map(this.anchor)),o=e.resolve(n.map(this.head));return new _o(r,o)}toJSON(){return{type:"nodeRange",anchor:this.anchor,head:this.head}}get isForwards(){return this.head>=this.anchor}get isBackwards(){return!this.isForwards}extendBackwards(){const{doc:e}=this.$from;if(this.isForwards&&this.ranges.length>1){const o=this.ranges.slice(0,-1),s=o[0].$from,i=o[o.length-1].$to;return new _o(s,i,this.depth)}const n=this.ranges[0],r=e.resolve(Math.max(0,n.$from.pos-1));return new _o(this.$anchor,r,this.depth)}extendForwards(){const{doc:e}=this.$from;if(this.isBackwards&&this.ranges.length>1){const o=this.ranges.slice(1),s=o[0].$from,i=o[o.length-1].$to;return new _o(i,s,this.depth)}const n=this.ranges[this.ranges.length-1],r=e.resolve(Math.min(e.content.size,n.$to.pos+1));return new _o(this.$anchor,r,this.depth)}static fromJSON(e,n){return new _o(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r,o,s=1){return new this(e.resolve(n),e.resolve(r),o,s)}getBookmark(){return new Cee(this.anchor,this.head)}};Vo.prototype.visible=!1;function Bc(t){return t instanceof Vo}Qe.create({name:"nodeRange",addOptions(){return{depth:void 0,key:"Mod"}},addKeyboardShortcuts(){return{"Shift-ArrowUp":({editor:t})=>{const{depth:e}=this.options,{view:n,state:r}=t,{doc:o,selection:s,tr:i}=r,{anchor:a,head:l}=s;if(!Bc(s)){const u=Vo.create(o,a,l,e,-1);return i.setSelection(u),n.dispatch(i),!0}const c=s.extendBackwards();return i.setSelection(c),n.dispatch(i),!0},"Shift-ArrowDown":({editor:t})=>{const{depth:e}=this.options,{view:n,state:r}=t,{doc:o,selection:s,tr:i}=r,{anchor:a,head:l}=s;if(!Bc(s)){const u=Vo.create(o,a,l,e);return i.setSelection(u),n.dispatch(i),!0}const c=s.extendForwards();return i.setSelection(c),n.dispatch(i),!0},"Mod-a":({editor:t})=>{const{depth:e}=this.options,{view:n,state:r}=t,{doc:o,tr:s}=r,i=Vo.create(o,0,o.content.size,e);return s.setSelection(i),n.dispatch(s),!0}}},onSelectionUpdate(){const{selection:t}=this.editor.state;Bc(t)&&this.editor.view.dom.classList.add("ProseMirror-noderangeselection")},addProseMirrorPlugins(){let t=!1,e=!1;return[new Ue({key:new We("nodeRange"),props:{attributes:()=>t?{class:"ProseMirror-noderangeselection"}:{class:""},handleDOMEvents:{mousedown:(n,r)=>{const{key:o}=this.options,s=/Mac/.test(navigator.platform),i=!!r.shiftKey,a=!!r.ctrlKey,l=!!r.altKey,c=!!r.metaKey,u=s?c:a;return(o==null||o==="Shift"&&i||o==="Control"&&a||o==="Alt"&&l||o==="Meta"&&c||o==="Mod"&&u)&&(e=!0),e&&document.addEventListener("mouseup",()=>{e=!1;const{state:d}=n,{doc:f,selection:h,tr:p}=d,{$anchor:m,$head:y}=h;if(m.sameParent(y))return;const v=Vo.create(f,m.pos,y.pos,this.options.depth);p.setSelection(v),n.dispatch(p)},{once:!0}),!1}},decorations:n=>{const{selection:r}=n,o=Bc(r);if(t=!1,!e)return o?(t=!0,WE(r.ranges)):null;const{$from:s,$to:i}=r;if(!o&&s.sameParent(i))return null;const a=$f(s,i,this.options.depth);return a.length?(t=!0,WE(a)):null}}})]}});function Aee(t){let e="";const n=getComputedStyle(t);for(let r=0;r<n.length;r+=1)e+=`${n[r]}:${n.getPropertyValue(n[r])};`;return e}function Mee(t){const e=t.cloneNode(!0),n=[t,...Array.from(t.getElementsByTagName("*"))],r=[e,...Array.from(e.getElementsByTagName("*"))];return n.forEach((o,s)=>{r[s].style.cssText=Aee(o)}),e}var uN=t=>{const{x:e,y:n,direction:r="right",editor:o,bandHeight:s=5}=t,i={top:n-s,bottom:n+s,left:r==="right"?e:0,right:r==="right"?window.innerWidth-e:e},l=[...o.view.dom.querySelectorAll("*")].filter(h=>o.view.posAtDOM(h,0)>=0).filter(h=>{const p=h.getBoundingClientRect();return!(p.bottom<i.top||p.top>i.bottom||p.right<i.left||p.left>i.right)});if(!l||l.length===0)return{resultElement:null,resultNode:null,pos:null};const c=l[0],u=o.view.posAtDOM(c,0);if(u===-1)return{resultElement:c,resultNode:null,pos:null};const d=o.state.doc.resolve(u);if(d.nodeAfter){const h=o.view.nodeDOM(d.pos);if(h&&h===c)return{resultElement:c,resultNode:d.nodeAfter,pos:u}}const f=o.state.doc.nodeAt(u-1);return{resultElement:c,resultNode:f,pos:u}};function Fc(t,e){return window.getComputedStyle(t)[e]}function Oee(t=0,e=0,n=0){return Math.min(Math.max(t,e),n)}function Ree(t,e,n){const r=parseInt(Fc(t.dom,"paddingLeft"),10),o=parseInt(Fc(t.dom,"paddingRight"),10),s=parseInt(Fc(t.dom,"borderLeftWidth"),10),i=parseInt(Fc(t.dom,"borderLeftWidth"),10),a=t.dom.getBoundingClientRect();return{left:Oee(e,a.left+r+s,a.right-o-i),top:n}}function dN(t){var e;(e=t.parentNode)==null||e.removeChild(t)}function Nee(t,e){const{doc:n}=e.view.state,r=uN({editor:e,x:t.clientX,y:t.clientY,direction:"right"});if(!r.resultNode||r.pos===null)return[];const o=t.clientX,s=Ree(e.view,o,t.clientY),i=e.view.posAtCoords(s);if(!i)return[];const{pos:a}=i;if(!n.resolve(a).parent)return[];const c=n.resolve(r.pos),u=n.resolve(r.pos+1);return $f(c,u,0)}function _ee(t,e){const{view:n}=e;if(!t.dataTransfer)return;const{empty:r,$from:o,$to:s}=n.state.selection,i=Nee(t,e),a=$f(o,s,0),l=a.some(y=>i.find(v=>v.$from===y.$from&&v.$to===y.$to)),c=r||!l?i:a;if(!c.length)return;const{tr:u}=n.state,d=document.createElement("div"),f=c[0].$from.pos,h=c[c.length-1].$to.pos,p=Vo.create(n.state.doc,f,h),m=p.content();c.forEach(y=>{const v=n.nodeDOM(y.$from.pos),w=Mee(v);d.append(w)}),d.style.position="absolute",d.style.top="-10000px",document.body.append(d),t.dataTransfer.clearData(),t.dataTransfer.setDragImage(d,0,0),n.dragging={slice:m,move:!0},u.setSelection(p),n.dispatch(u),document.addEventListener("drop",()=>dN(d),{once:!0})}var GE=(t,e)=>{const n=t.resolve(e),{depth:r}=n;return r===0?e:n.pos-n.parentOffset-1},qE=(t,e)=>{const n=t.nodeAt(e),r=t.resolve(e);let{depth:o}=r,s=n;for(;o>0;){const i=r.node(o);o-=1,o===0&&(s=i)}return s},gp=(t,e)=>{const n=pt.getState(t);return n?ng(e,n.type,n.binding.mapping):null},Dee=(t,e)=>{const n=pt.getState(t);return n?iu(n.doc,n.type,e,n.binding.mapping)||0:-1},KE=(t,e)=>{let n=e;for(;n?.parentNode&&n.parentNode!==t.dom;)n=n.parentNode;return n},fN=new We("dragHandle"),hN=({pluginKey:t=fN,element:e,editor:n,computePositionConfig:r,getReferencedVirtualElement:o,onNodeChange:s,onElementDragStart:i,onElementDragEnd:a})=>{const l=document.createElement("div");let c=!1,u=null,d=-1,f,h=null,p=null;function m(){e&&(e.style.visibility="hidden",e.style.pointerEvents="none")}function y(){if(e){if(!n.isEditable){m();return}e.style.visibility="",e.style.pointerEvents="auto"}}function v(x){const T=o?.()||{getBoundingClientRect:()=>x.getBoundingClientRect()};UT(T,e,r).then(S=>{Object.assign(e.style,{position:S.strategy,left:`${S.x}px`,top:`${S.y}px`})})}function w(x){i?.(x),_ee(x,n),setTimeout(()=>{e&&(e.style.pointerEvents="none")},0)}function E(x){a?.(x),m(),e&&(e.style.pointerEvents="auto")}return e.addEventListener("dragstart",w),e.addEventListener("dragend",E),l.appendChild(e),{unbind(){e.removeEventListener("dragstart",w),e.removeEventListener("dragend",E),h&&(cancelAnimationFrame(h),h=null,p=null)},plugin:new Ue({key:typeof t=="string"?new We(t):t,state:{init(){return{locked:!1}},apply(x,T,S,k){const C=x.getMeta("lockDragHandle"),N=x.getMeta("hideDragHandle");if(C!==void 0&&(c=C),N)return m(),c=!1,u=null,d=-1,s?.({editor:n,node:null,pos:-1}),T;if(x.docChanged&&d!==-1&&e)if(Tee(x)){const R=Dee(k,f);R!==d&&(d=R)}else{const R=x.mapping.map(d);R!==d&&(d=R,f=gp(k,d))}return T}},view:x=>{var T;return e.draggable=!0,e.style.pointerEvents="auto",(T=n.view.dom.parentElement)==null||T.appendChild(l),l.style.pointerEvents="none",l.style.position="absolute",l.style.top="0",l.style.left="0",{update(S,k){if(!e)return;if(!n.isEditable){m();return}if(c?e.draggable=!1:e.draggable=!0,x.state.doc.eq(k.doc)||d===-1)return;let C=x.nodeDOM(d);if(C=KE(x,C),C===x.dom||C?.nodeType!==1)return;const N=x.posAtDOM(C,0),R=qE(n.state.doc,N),L=GE(n.state.doc,N);u=R,d=L,f=gp(x.state,d),s?.({editor:n,node:u,pos:d}),v(C)},destroy(){h&&(cancelAnimationFrame(h),h=null,p=null),e&&dN(l)}}},props:{handleDOMEvents:{keydown(x){return!e||c||x.hasFocus()&&(m(),u=null,d=-1,s?.({editor:n,node:null,pos:-1})),!1},mouseleave(x,T){return c||T.target&&!l.contains(T.relatedTarget)&&(m(),u=null,d=-1,s?.({editor:n,node:null,pos:-1})),!1},mousemove(x,T){return!e||c||(p={x:T.clientX,y:T.clientY},h)||(h=requestAnimationFrame(()=>{if(h=null,!p)return;const{x:S,y:k}=p;p=null;const C=uN({x:S,y:k,direction:"right",editor:n});if(!C.resultElement)return;let N=C.resultElement;if(N=KE(x,N),N===x.dom||N?.nodeType!==1)return;const R=x.posAtDOM(N,0),L=qE(n.state.doc,R);if(L!==u){const $=GE(n.state.doc,R);u=L,d=$,f=gp(x.state,d),s?.({editor:n,node:u,pos:d}),v(N),y()}})),!1}}}})}},rg={placement:"left-start",strategy:"absolute"};Qe.create({name:"dragHandle",addOptions(){return{render(){const t=document.createElement("div");return t.classList.add("drag-handle"),t},computePositionConfig:{},locked:!1,onNodeChange:()=>null}},addCommands(){return{lockDragHandle:()=>({editor:t})=>(this.options.locked=!0,t.commands.setMeta("lockDragHandle",this.options.locked)),unlockDragHandle:()=>({editor:t})=>(this.options.locked=!1,t.commands.setMeta("lockDragHandle",this.options.locked)),toggleDragHandle:()=>({editor:t})=>(this.options.locked=!this.options.locked,t.commands.setMeta("lockDragHandle",this.options.locked))}},addProseMirrorPlugins(){const t=this.options.render();return[hN({computePositionConfig:{...rg,...this.options.computePositionConfig},getReferencedVirtualElement:this.options.getReferencedVirtualElement,element:t,editor:this.editor,onNodeChange:this.options.onNodeChange}).plugin]}});var Iee=t=>{const{className:e="drag-handle",children:n,editor:r,pluginKey:o=fN,onNodeChange:s,onElementDragStart:i,onElementDragEnd:a,computePositionConfig:l=rg}=t,[c,u]=M.useState(null),d=M.useRef(null);return M.useEffect(()=>{let f=null;return c?r.isDestroyed?()=>{d.current=null}:(d.current||(f=hN({editor:r,element:c,pluginKey:o,computePositionConfig:{...rg,...l},onElementDragStart:i,onElementDragEnd:a,onNodeChange:s}),d.current=f.plugin,r.registerPlugin(d.current)),()=>{r.unregisterPlugin(o),d.current=null,f&&(f.unbind(),f=null)}):()=>{d.current=null}},[c,r,s,o,l,i,a]),g.jsx("div",{className:e,style:{visibility:"hidden",position:"absolute"},ref:u,children:n})},Pee=Iee;const pN=({editor:t,actions:e,editorTab:n,onSwitchEditor:r,isSubmitting:o,onSubmit:s,className:i})=>g.jsxs("div",{className:re("post-builder-editor bg-background border rounded-md overflow-hidden min-h-60 max-h-[calc(100dvh-7rem)] flex flex-col overflow-y-auto transition-all duration-300 ease-in-out",i),children:[g.jsx(GF,{editorTab:n,onSwitchEditorTab:r}),g.jsx(A9,{editor:t,actions:e,isSubmitting:o,onSubmit:s,editorType:n,children:g.jsxs("div",{className:"flex flex-col grow overflow-y-auto",children:[g.jsx(Pee,{editor:t,className:re(" pr-2",n!==gt.Text&&"hidden size-0 overflow-hidden pointer-events-none"),children:g.jsx(Zn,{variant:"ghost",className:"bg-white cursor-grab py-0.5 px-0 border size-auto",children:g.jsx(xV,{className:"text-muted-foreground"})})}),g.jsx(_F,{className:"grow overflow-y-auto","data-theme":"select-post-builder",editor:t})]})})]}),Lee=({open:t,onOpenChange:e,...n})=>g.jsx(wy,{open:t,onOpenChange:e,children:g.jsx(Ey,{className:"bg-transparent border-0 p-0 lg:max-w-4xl",showCloseButton:!1,children:g.jsx(pN,{...n,className:"bg-white max-h-dvh h-full"})})});function YE(t,[e,n]){return Math.min(n,Math.max(e,t))}var jee=[" ","Enter","ArrowUp","ArrowDown"],$ee=[" ","Enter"],Gs="Select",[Bf,Ff,Bee]=yg(Gs),[ia]=Ln(Gs,[Bee,cs]),Hf=cs(),[Fee,fs]=ia(Gs),[Hee,Uee]=ia(Gs),mN=t=>{const{__scopeSelect:e,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:u,autoComplete:d,disabled:f,required:h,form:p}=t,m=Hf(e),[y,v]=b.useState(null),[w,E]=b.useState(null),[x,T]=b.useState(!1),S=jd(c),[k,C]=po({prop:r,defaultProp:o??!1,onChange:s,caller:Gs}),[N,R]=po({prop:i,defaultProp:a,onChange:l,caller:Gs}),L=b.useRef(null),$=y?p||!!y.closest("form"):!0,[B,U]=b.useState(new Set),j=Array.from(B).map(P=>P.props.value).join(";");return g.jsx(sf,{...m,children:g.jsxs(Fee,{required:h,scope:e,trigger:y,onTriggerChange:v,valueNode:w,onValueNodeChange:E,valueNodeHasChildren:x,onValueNodeHasChildrenChange:T,contentId:Kn(),value:N,onValueChange:R,open:k,onOpenChange:C,dir:S,triggerPointerDownPosRef:L,disabled:f,children:[g.jsx(Bf.Provider,{scope:e,children:g.jsx(Hee,{scope:t.__scopeSelect,onNativeOptionAdd:b.useCallback(P=>{U(H=>new Set(H).add(P))},[]),onNativeOptionRemove:b.useCallback(P=>{U(H=>{const _=new Set(H);return _.delete(P),_})},[]),children:n})}),$?g.jsxs(jN,{"aria-hidden":!0,required:h,tabIndex:-1,name:u,autoComplete:d,value:N,onChange:P=>R(P.target.value),disabled:f,form:p,children:[N===void 0?g.jsx("option",{value:""}):null,Array.from(B)]},j):null]})})};mN.displayName=Gs;var gN="SelectTrigger",yN=b.forwardRef((t,e)=>{const{__scopeSelect:n,disabled:r=!1,...o}=t,s=Hf(n),i=fs(gN,n),a=i.disabled||r,l=Fe(e,i.onTriggerChange),c=Ff(n),u=b.useRef("touch"),[d,f,h]=BN(m=>{const y=c().filter(E=>!E.disabled),v=y.find(E=>E.value===i.value),w=FN(y,m,v);w!==void 0&&i.onValueChange(w.value)}),p=m=>{a||(i.onOpenChange(!0),h()),m&&(i.triggerPointerDownPosRef.current={x:Math.round(m.pageX),y:Math.round(m.pageY)})};return g.jsx(Hl,{asChild:!0,...s,children:g.jsx(ge.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":$N(i.value)?"":void 0,...o,ref:l,onClick:ne(o.onClick,m=>{m.currentTarget.focus(),u.current!=="mouse"&&p(m)}),onPointerDown:ne(o.onPointerDown,m=>{u.current=m.pointerType;const y=m.target;y.hasPointerCapture(m.pointerId)&&y.releasePointerCapture(m.pointerId),m.button===0&&m.ctrlKey===!1&&m.pointerType==="mouse"&&(p(m),m.preventDefault())}),onKeyDown:ne(o.onKeyDown,m=>{const y=d.current!=="";!(m.ctrlKey||m.altKey||m.metaKey)&&m.key.length===1&&f(m.key),!(y&&m.key===" ")&&jee.includes(m.key)&&(p(),m.preventDefault())})})})});yN.displayName=gN;var vN="SelectValue",bN=b.forwardRef((t,e)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=t,l=fs(vN,n),{onValueNodeHasChildrenChange:c}=l,u=s!==void 0,d=Fe(e,l.onValueNodeChange);return Nt(()=>{c(u)},[c,u]),g.jsx(ge.span,{...a,ref:d,style:{pointerEvents:"none"},children:$N(l.value)?g.jsx(g.Fragment,{children:i}):s})});bN.displayName=vN;var zee="SelectIcon",xN=b.forwardRef((t,e)=>{const{__scopeSelect:n,children:r,...o}=t;return g.jsx(ge.span,{"aria-hidden":!0,...o,ref:e,children:r||"▼"})});xN.displayName=zee;var Vee="SelectPortal",wN=t=>g.jsx(ea,{asChild:!0,...t});wN.displayName=Vee;var qs="SelectContent",EN=b.forwardRef((t,e)=>{const n=fs(qs,t.__scopeSelect),[r,o]=b.useState();if(Nt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Md.createPortal(g.jsx(SN,{scope:t.__scopeSelect,children:g.jsx(Bf.Slot,{scope:t.__scopeSelect,children:g.jsx("div",{children:t.children})})}),s):null}return g.jsx(kN,{...t,ref:e})});EN.displayName=qs;var ir=10,[SN,hs]=ia(qs),Wee="SelectContentImpl",Gee=Yo("SelectContent.RemoveScroll"),kN=b.forwardRef((t,e)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:h,sticky:p,hideWhenDetached:m,avoidCollisions:y,...v}=t,w=fs(qs,n),[E,x]=b.useState(null),[T,S]=b.useState(null),k=Fe(e,z=>x(z)),[C,N]=b.useState(null),[R,L]=b.useState(null),$=Ff(n),[B,U]=b.useState(!1),j=b.useRef(!1);b.useEffect(()=>{if(E)return hf(E)},[E]),df();const P=b.useCallback(z=>{const[Z,...Me]=$().map(Se=>Se.ref.current),[he]=Me.slice(-1),we=document.activeElement;for(const Se of z)if(Se===we||(Se?.scrollIntoView({block:"nearest"}),Se===Z&&T&&(T.scrollTop=0),Se===he&&T&&(T.scrollTop=T.scrollHeight),Se?.focus(),document.activeElement!==we))return},[$,T]),H=b.useCallback(()=>P([C,E]),[P,C,E]);b.useEffect(()=>{B&&H()},[B,H]);const{onOpenChange:_,triggerPointerDownPosRef:V}=w;b.useEffect(()=>{if(E){let z={x:0,y:0};const Z=he=>{z={x:Math.abs(Math.round(he.pageX)-(V.current?.x??0)),y:Math.abs(Math.round(he.pageY)-(V.current?.y??0))}},Me=he=>{z.x<=10&&z.y<=10?he.preventDefault():E.contains(he.target)||_(!1),document.removeEventListener("pointermove",Z),V.current=null};return V.current!==null&&(document.addEventListener("pointermove",Z),document.addEventListener("pointerup",Me,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",Z),document.removeEventListener("pointerup",Me,{capture:!0})}}},[E,_,V]),b.useEffect(()=>{const z=()=>_(!1);return window.addEventListener("blur",z),window.addEventListener("resize",z),()=>{window.removeEventListener("blur",z),window.removeEventListener("resize",z)}},[_]);const[ie,te]=BN(z=>{const Z=$().filter(we=>!we.disabled),Me=Z.find(we=>we.ref.current===document.activeElement),he=FN(Z,z,Me);he&&setTimeout(()=>he.ref.current.focus())}),ye=b.useCallback((z,Z,Me)=>{const he=!j.current&&!Me;(w.value!==void 0&&w.value===Z||he)&&(N(z),he&&(j.current=!0))},[w.value]),G=b.useCallback(()=>E?.focus(),[E]),Q=b.useCallback((z,Z,Me)=>{const he=!j.current&&!Me;(w.value!==void 0&&w.value===Z||he)&&L(z)},[w.value]),J=r==="popper"?og:TN,me=J===og?{side:a,sideOffset:l,align:c,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:h,sticky:p,hideWhenDetached:m,avoidCollisions:y}:{};return g.jsx(SN,{scope:n,content:E,viewport:T,onViewportChange:S,itemRefCallback:ye,selectedItem:C,onItemLeave:G,itemTextRefCallback:Q,focusSelectedItem:H,selectedItemText:R,position:r,isPositioned:B,searchRef:ie,children:g.jsx(Vl,{as:Gee,allowPinchZoom:!0,children:g.jsx(zl,{asChild:!0,trapped:w.open,onMountAutoFocus:z=>{z.preventDefault()},onUnmountAutoFocus:ne(o,z=>{w.trigger?.focus({preventScroll:!0}),z.preventDefault()}),children:g.jsx(Xi,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:z=>z.preventDefault(),onDismiss:()=>w.onOpenChange(!1),children:g.jsx(J,{role:"listbox",id:w.contentId,"data-state":w.open?"open":"closed",dir:w.dir,onContextMenu:z=>z.preventDefault(),...v,...me,onPlaced:()=>U(!0),ref:k,style:{display:"flex",flexDirection:"column",outline:"none",...v.style},onKeyDown:ne(v.onKeyDown,z=>{const Z=z.ctrlKey||z.altKey||z.metaKey;if(z.key==="Tab"&&z.preventDefault(),!Z&&z.key.length===1&&te(z.key),["ArrowUp","ArrowDown","Home","End"].includes(z.key)){let he=$().filter(we=>!we.disabled).map(we=>we.ref.current);if(["ArrowUp","End"].includes(z.key)&&(he=he.slice().reverse()),["ArrowUp","ArrowDown"].includes(z.key)){const we=z.target,Se=he.indexOf(we);he=he.slice(Se+1)}setTimeout(()=>P(he)),z.preventDefault()}})})})})})})});kN.displayName=Wee;var qee="SelectItemAlignedPosition",TN=b.forwardRef((t,e)=>{const{__scopeSelect:n,onPlaced:r,...o}=t,s=fs(qs,n),i=hs(qs,n),[a,l]=b.useState(null),[c,u]=b.useState(null),d=Fe(e,k=>u(k)),f=Ff(n),h=b.useRef(!1),p=b.useRef(!0),{viewport:m,selectedItem:y,selectedItemText:v,focusSelectedItem:w}=i,E=b.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&m&&y&&v){const k=s.trigger.getBoundingClientRect(),C=c.getBoundingClientRect(),N=s.valueNode.getBoundingClientRect(),R=v.getBoundingClientRect();if(s.dir!=="rtl"){const we=R.left-C.left,Se=N.left-we,ze=k.left-Se,ut=k.width+ze,dt=Math.max(ut,C.width),Tt=window.innerWidth-ir,ft=YE(Se,[ir,Math.max(ir,Tt-dt)]);a.style.minWidth=ut+"px",a.style.left=ft+"px"}else{const we=C.right-R.right,Se=window.innerWidth-N.right-we,ze=window.innerWidth-k.right-Se,ut=k.width+ze,dt=Math.max(ut,C.width),Tt=window.innerWidth-ir,ft=YE(Se,[ir,Math.max(ir,Tt-dt)]);a.style.minWidth=ut+"px",a.style.right=ft+"px"}const L=f(),$=window.innerHeight-ir*2,B=m.scrollHeight,U=window.getComputedStyle(c),j=parseInt(U.borderTopWidth,10),P=parseInt(U.paddingTop,10),H=parseInt(U.borderBottomWidth,10),_=parseInt(U.paddingBottom,10),V=j+P+B+_+H,ie=Math.min(y.offsetHeight*5,V),te=window.getComputedStyle(m),ye=parseInt(te.paddingTop,10),G=parseInt(te.paddingBottom,10),Q=k.top+k.height/2-ir,J=$-Q,me=y.offsetHeight/2,z=y.offsetTop+me,Z=j+P+z,Me=V-Z;if(Z<=Q){const we=L.length>0&&y===L[L.length-1].ref.current;a.style.bottom="0px";const Se=c.clientHeight-m.offsetTop-m.offsetHeight,ze=Math.max(J,me+(we?G:0)+Se+H),ut=Z+ze;a.style.height=ut+"px"}else{const we=L.length>0&&y===L[0].ref.current;a.style.top="0px";const ze=Math.max(Q,j+m.offsetTop+(we?ye:0)+me)+Me;a.style.height=ze+"px",m.scrollTop=Z-Q+m.offsetTop}a.style.margin=`${ir}px 0`,a.style.minHeight=ie+"px",a.style.maxHeight=$+"px",r?.(),requestAnimationFrame(()=>h.current=!0)}},[f,s.trigger,s.valueNode,a,c,m,y,v,s.dir,r]);Nt(()=>E(),[E]);const[x,T]=b.useState();Nt(()=>{c&&T(window.getComputedStyle(c).zIndex)},[c]);const S=b.useCallback(k=>{k&&p.current===!0&&(E(),w?.(),p.current=!1)},[E,w]);return g.jsx(Yee,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:h,onScrollButtonChange:S,children:g.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:x},children:g.jsx(ge.div,{...o,ref:d,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});TN.displayName=qee;var Kee="SelectPopperPosition",og=b.forwardRef((t,e)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=ir,...s}=t,i=Hf(n);return g.jsx(af,{...i,...s,ref:e,align:r,collisionPadding:o,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});og.displayName=Kee;var[Yee,jv]=ia(qs,{}),sg="SelectViewport",CN=b.forwardRef((t,e)=>{const{__scopeSelect:n,nonce:r,...o}=t,s=hs(sg,n),i=jv(sg,n),a=Fe(e,s.onViewportChange),l=b.useRef(0);return g.jsxs(g.Fragment,{children:[g.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),g.jsx(Bf.Slot,{scope:n,children:g.jsx(ge.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ne(o.onScroll,c=>{const u=c.currentTarget,{contentWrapper:d,shouldExpandOnScrollRef:f}=i;if(f?.current&&d){const h=Math.abs(l.current-u.scrollTop);if(h>0){const p=window.innerHeight-ir*2,m=parseFloat(d.style.minHeight),y=parseFloat(d.style.height),v=Math.max(m,y);if(v<p){const w=v+h,E=Math.min(p,w),x=w-E;d.style.height=E+"px",d.style.bottom==="0px"&&(u.scrollTop=x>0?x:0,d.style.justifyContent="flex-end")}}}l.current=u.scrollTop})})})]})});CN.displayName=sg;var AN="SelectGroup",[Jee,Xee]=ia(AN),Qee=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,o=Kn();return g.jsx(Jee,{scope:n,id:o,children:g.jsx(ge.div,{role:"group","aria-labelledby":o,...r,ref:e})})});Qee.displayName=AN;var MN="SelectLabel",Zee=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,o=Xee(MN,n);return g.jsx(ge.div,{id:o.id,...r,ref:e})});Zee.displayName=MN;var Ad="SelectItem",[ete,ON]=ia(Ad),RN=b.forwardRef((t,e)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=t,a=fs(Ad,n),l=hs(Ad,n),c=a.value===r,[u,d]=b.useState(s??""),[f,h]=b.useState(!1),p=Fe(e,w=>l.itemRefCallback?.(w,r,o)),m=Kn(),y=b.useRef("touch"),v=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return g.jsx(ete,{scope:n,value:r,disabled:o,textId:m,isSelected:c,onItemTextChange:b.useCallback(w=>{d(E=>E||(w?.textContent??"").trim())},[]),children:g.jsx(Bf.ItemSlot,{scope:n,value:r,disabled:o,textValue:u,children:g.jsx(ge.div,{role:"option","aria-labelledby":m,"data-highlighted":f?"":void 0,"aria-selected":c&&f,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:p,onFocus:ne(i.onFocus,()=>h(!0)),onBlur:ne(i.onBlur,()=>h(!1)),onClick:ne(i.onClick,()=>{y.current!=="mouse"&&v()}),onPointerUp:ne(i.onPointerUp,()=>{y.current==="mouse"&&v()}),onPointerDown:ne(i.onPointerDown,w=>{y.current=w.pointerType}),onPointerMove:ne(i.onPointerMove,w=>{y.current=w.pointerType,o?l.onItemLeave?.():y.current==="mouse"&&w.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ne(i.onPointerLeave,w=>{w.currentTarget===document.activeElement&&l.onItemLeave?.()}),onKeyDown:ne(i.onKeyDown,w=>{l.searchRef?.current!==""&&w.key===" "||($ee.includes(w.key)&&v(),w.key===" "&&w.preventDefault())})})})})});RN.displayName=Ad;var Ca="SelectItemText",NN=b.forwardRef((t,e)=>{const{__scopeSelect:n,className:r,style:o,...s}=t,i=fs(Ca,n),a=hs(Ca,n),l=ON(Ca,n),c=Uee(Ca,n),[u,d]=b.useState(null),f=Fe(e,v=>d(v),l.onItemTextChange,v=>a.itemTextRefCallback?.(v,l.value,l.disabled)),h=u?.textContent,p=b.useMemo(()=>g.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:m,onNativeOptionRemove:y}=c;return Nt(()=>(m(p),()=>y(p)),[m,y,p]),g.jsxs(g.Fragment,{children:[g.jsx(ge.span,{id:l.textId,...s,ref:f}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Md.createPortal(s.children,i.valueNode):null]})});NN.displayName=Ca;var _N="SelectItemIndicator",DN=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t;return ON(_N,n).isSelected?g.jsx(ge.span,{"aria-hidden":!0,...r,ref:e}):null});DN.displayName=_N;var ig="SelectScrollUpButton",IN=b.forwardRef((t,e)=>{const n=hs(ig,t.__scopeSelect),r=jv(ig,t.__scopeSelect),[o,s]=b.useState(!1),i=Fe(e,r.onScrollButtonChange);return Nt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?g.jsx(LN,{...t,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});IN.displayName=ig;var ag="SelectScrollDownButton",PN=b.forwardRef((t,e)=>{const n=hs(ag,t.__scopeSelect),r=jv(ag,t.__scopeSelect),[o,s]=b.useState(!1),i=Fe(e,r.onScrollButtonChange);return Nt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,u=Math.ceil(l.scrollTop)<c;s(u)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?g.jsx(LN,{...t,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});PN.displayName=ag;var LN=b.forwardRef((t,e)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=t,s=hs("SelectScrollButton",n),i=b.useRef(null),a=Ff(n),l=b.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return b.useEffect(()=>()=>l(),[l]),Nt(()=>{a().find(u=>u.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:"nearest"})},[a]),g.jsx(ge.div,{"aria-hidden":!0,...o,ref:e,style:{flexShrink:0,...o.style},onPointerDown:ne(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ne(o.onPointerMove,()=>{s.onItemLeave?.(),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ne(o.onPointerLeave,()=>{l()})})}),tte="SelectSeparator",nte=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t;return g.jsx(ge.div,{"aria-hidden":!0,...r,ref:e})});nte.displayName=tte;var lg="SelectArrow",rte=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,o=Hf(n),s=fs(lg,n),i=hs(lg,n);return s.open&&i.position==="popper"?g.jsx(lf,{...o,...r,ref:e}):null});rte.displayName=lg;var ote="SelectBubbleInput",jN=b.forwardRef(({__scopeSelect:t,value:e,...n},r)=>{const o=b.useRef(null),s=Fe(r,o),i=EM(e);return b.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,u=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==e&&u){const d=new Event("change",{bubbles:!0});u.call(a,e),a.dispatchEvent(d)}},[i,e]),g.jsx(ge.select,{...n,style:{...tC,...n.style},ref:s,defaultValue:e})});jN.displayName=ote;function $N(t){return t===""||t===void 0}function BN(t){const e=pr(t),n=b.useRef(""),r=b.useRef(0),o=b.useCallback(i=>{const a=n.current+i;e(a),(function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))})(a)},[e]),s=b.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return b.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function FN(t,e,n){const o=e.length>1&&Array.from(e).every(c=>c===e[0])?e[0]:e,s=n?t.indexOf(n):-1;let i=ste(t,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function ste(t,e){return t.map((n,r)=>t[(e+r)%t.length])}var ite=mN,ate=yN,lte=bN,cte=xN,ute=wN,dte=EN,fte=CN,hte=RN,pte=NN,mte=DN,gte=IN,yte=PN;function vte({...t}){return g.jsx(ite,{"data-slot":"select",...t})}function bte({...t}){return g.jsx(lte,{"data-slot":"select-value",...t})}function xte({className:t,size:e="default",children:n,...r}){return g.jsxs(ate,{"data-slot":"select-trigger","data-size":e,className:re("border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",t),...r,children:[n,g.jsx(cte,{asChild:!0,children:g.jsx(zC,{className:"size-4 opacity-50"})})]})}function wte({className:t,children:e,position:n="popper",align:r="center",...o}){return g.jsx(ute,{children:g.jsx("div",{id:"select-wrapper","data-theme":"select-post-builder",children:g.jsxs(dte,{"data-slot":"select-content",className:re("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",t),position:n,align:r,...o,children:[g.jsx(Ste,{}),g.jsx(fte,{className:re("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:e}),g.jsx(kte,{})]})})})}function Ete({className:t,children:e,...n}){return g.jsxs(hte,{"data-slot":"select-item",className:re("focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",t),...n,children:[g.jsx("span",{className:"absolute right-2 flex size-3.5 items-center justify-center",children:g.jsx(mte,{children:g.jsx(UC,{className:"size-4"})})}),g.jsx(pte,{children:e})]})}function Ste({className:t,...e}){return g.jsx(gte,{"data-slot":"select-scroll-up-button",className:re("flex cursor-default items-center justify-center py-1",t),...e,children:g.jsx(uV,{className:"size-4"})})}function kte({className:t,...e}){return g.jsx(yte,{"data-slot":"select-scroll-down-button",className:re("flex cursor-default items-center justify-center py-1",t),...e,children:g.jsx(zC,{className:"size-4"})})}function Tte(){return kg.useSyncExternalStore(Cte,()=>!0,()=>!1)}function Cte(){return()=>{}}var $v="Avatar",[Ate]=Ln($v),[Mte,HN]=Ate($v),UN=b.forwardRef((t,e)=>{const{__scopeAvatar:n,...r}=t,[o,s]=b.useState("idle");return g.jsx(Mte,{scope:n,imageLoadingStatus:o,onImageLoadingStatusChange:s,children:g.jsx(ge.span,{...r,ref:e})})});UN.displayName=$v;var zN="AvatarImage",VN=b.forwardRef((t,e)=>{const{__scopeAvatar:n,src:r,onLoadingStatusChange:o=()=>{},...s}=t,i=HN(zN,n),a=Ote(r,s),l=pr(c=>{o(c),i.onImageLoadingStatusChange(c)});return Nt(()=>{a!=="idle"&&l(a)},[a,l]),a==="loaded"?g.jsx(ge.img,{...s,ref:e,src:r}):null});VN.displayName=zN;var WN="AvatarFallback",GN=b.forwardRef((t,e)=>{const{__scopeAvatar:n,delayMs:r,...o}=t,s=HN(WN,n),[i,a]=b.useState(r===void 0);return b.useEffect(()=>{if(r!==void 0){const l=window.setTimeout(()=>a(!0),r);return()=>window.clearTimeout(l)}},[r]),i&&s.imageLoadingStatus!=="loaded"?g.jsx(ge.span,{...o,ref:e}):null});GN.displayName=WN;function JE(t,e){return t?e?(t.src!==e&&(t.src=e),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function Ote(t,{referrerPolicy:e,crossOrigin:n}){const r=Tte(),o=b.useRef(null),s=r?(o.current||(o.current=new window.Image),o.current):null,[i,a]=b.useState(()=>JE(s,t));return Nt(()=>{a(JE(s,t))},[s,t]),Nt(()=>{const l=d=>()=>{a(d)};if(!s)return;const c=l("loaded"),u=l("error");return s.addEventListener("load",c),s.addEventListener("error",u),e&&(s.referrerPolicy=e),typeof n=="string"&&(s.crossOrigin=n),()=>{s.removeEventListener("load",c),s.removeEventListener("error",u)}},[s,n,e]),i}var Rte=UN,Nte=VN,_te=GN;function XE({className:t,...e}){return g.jsx(Rte,{"data-slot":"avatar",className:re("relative flex size-8 shrink-0 overflow-hidden rounded-full",t),...e})}function QE({className:t,...e}){return g.jsx(Nte,{"data-slot":"avatar-image",className:re("aspect-square size-full",t),...e})}function ZE({className:t,...e}){return g.jsx(_te,{"data-slot":"avatar-fallback",className:re("bg-muted flex size-full items-center justify-center rounded-full",t),...e})}const Dte=({user:t,store:e})=>{const{core:n}=Dl(),[r,o]=M.useState([]),[s,i]=M.useState(!1),a=ho(),[l,c]=M.useState(e.getState());M.useEffect(()=>e.subscribe(()=>{c(e.getState())}),[e]);const{groupId:u,selectedGroupId:d}=l,f=d??u??"",h=!!u;M.useEffect(()=>{let m=!1;return(async()=>{i(!0);try{const v=await n.fetchGroupConversations(999,0);m||o(v.entries??[])}catch(v){m||console.error("Failed to fetch groups:",v)}finally{m||i(!1)}})(),()=>{m=!0}},[n]);const p=m=>{e.getState().selectGroup(m)};return g.jsxs("div",{className:"not-prose flex items-center gap-3",children:[t?.id&&g.jsxs(XE,{children:[g.jsx(QE,{src:t?.avatar??t?.avatarPlaceholder}),g.jsx(ZE,{className:"bg-primary-send text-background",children:t?.name?.charAt(0)})]}),g.jsxs(vte,{value:f,onValueChange:p,disabled:h||s,children:[g.jsx(xte,{size:"sm",id:`group-selector-${f}-${a}`,className:"bg-background","aria-label":"Select group",children:g.jsx(bte,{className:"text-sm",placeholder:s?"Loading groups...":"Select a group…"})}),g.jsx(wte,{align:"start",children:r.map(m=>g.jsxs(Ete,{value:m.group_id,children:[g.jsxs(XE,{className:"size-6",children:[g.jsx(QE,{src:m.group.avatar}),g.jsx(ZE,{children:m?.group?.name?.charAt(0)})]}),g.jsx("span",{className:"text-sm",children:m.group?.name??m.group_id})]},m.group_id))})]})]})};var Ite=(t,e,n,r,o,s,i,a)=>{let l=document.documentElement,c=["light","dark"];function u(h){(Array.isArray(t)?t:[t]).forEach(p=>{let m=p==="class",y=m&&s?o.map(v=>s[v]||v):o;m?(l.classList.remove(...y),l.classList.add(s&&s[h]?s[h]:h)):l.setAttribute(p,h)}),d(h)}function d(h){a&&c.includes(h)&&(l.style.colorScheme=h)}function f(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}if(r)u(r);else try{let h=localStorage.getItem(e)||n,p=i&&h==="system"?f():h;u(p)}catch{}},Pte=b.createContext(void 0),Lte={setTheme:t=>{},themes:[]},jte=()=>{var t;return(t=b.useContext(Pte))!=null?t:Lte};b.memo(({forcedTheme:t,storageKey:e,attribute:n,enableSystem:r,enableColorScheme:o,defaultTheme:s,value:i,themes:a,nonce:l,scriptProps:c})=>{let u=JSON.stringify([n,e,s,t,a,i,r,o]).slice(1,-1);return b.createElement("script",{...c,suppressHydrationWarning:!0,nonce:typeof window>"u"?l:"",dangerouslySetInnerHTML:{__html:`(${Ite.toString()})(${u})`}})});const $te=({...t})=>{const{theme:e="system"}=jte();return g.jsx(mI,{theme:e,className:"toaster group",style:{"--normal-bg":"var(--popover)","--normal-text":"var(--popover-foreground)","--normal-border":"var(--border)"},...t})},Uf=t=>({html:t?.getHTML(),json:t?.getJSON(),text:t?.getText()}),zf=()=>({postId:ho(),timestamp:new Date().getTime(),specialType:TS.POST}),Bv=t=>({mentionData:Kl(t,"mention")?.map(r=>q8(X8(r.attrs,B8),["mentionSuggestionChar","label"]))?.filter(r=>Object.keys(r).length>0)}),Bte=t=>({items:Kl(t,"media").map(r=>r.attrs?.payload)}),Fte=t=>({items:Kl(t,"poll")[0].attrs?.choices}),Hte=({editor:t,sendCrossMention:e})=>{const{html:n,json:r}=Uf(t),o=zf(),s=pw(r,"text")?.text?.trim()??"",i=new Array(pw(r,"media")?.attrs?.payload).filter(Boolean),a=n;return{...o,type:_l.NEW_POST_MESSAGE,body:s,items:i,htmlBody:a,sendCrossMention:e,mentionData:[]}},Ute=({editor:t,sendCrossMention:e})=>{const{json:n,text:r}=Uf(t),o=zf(),s=r,{mentionData:i}=Bv(n),{items:a}=Bte(n);return{...o,type:_l.NEW_POST_MEDIA,body:s,items:a,mentionData:i,sendCrossMention:e}},zte=({editor:t,sendCrossMention:e})=>{const{json:n,text:r}=Uf(t),o=zf(),s=r,{mentionData:i}=Bv(n);return{...o,type:_l.NEW_POST_MESSAGE,body:s,items:[],mentionData:i,sendCrossMention:e}},Vte=({editor:t,sendCrossMention:e})=>{const{json:n,text:r}=Uf(t),o=zf(),s=r,{mentionData:i}=Bv(n),{items:a}=Fte(n);return{...o,type:_l.NEW_POST_POLL,body:s,items:a,mentionData:i,sendCrossMention:e}},Wte=(t,e)=>{switch(t){case gt.Text:return Hte(e);case gt.Media:return Ute(e);case gt.Link:return zte(e);case gt.Poll:return Vte(e);default:return null}},Gte=({groupId:t,postId:e,user:n,hideGroupSelector:r=!1,showModal:o=!1,clearOnSuccess:s=!0,isSubmitting:i,onCreatePost:a})=>{const l=M.useRef(null),[c,u]=M.useState(()=>o),[d,f]=M.useState(gt.Text),{editor:h,actions:p,store:m}=cX({editorType:d,groupId:t,postId:e,user:n}),{clearContent:y}=ry(),v=M.useMemo(()=>({editor:h}),[h]),w=E=>{if(!h)return;const x=h?.getHTML(),T=h?.getJSON(),S=h?.getText(),k=Wte(d,{editor:h,sendCrossMention:E});k&&(a?.({payload:k,html:x,json:T,text:S}),s&&(y(),h?.chain()?.focus()?.clearContent()?.run()))};return M.useEffect(()=>{h&&h?.chain()?.focus()?.run()},[h]),M.useEffect(()=>u(o),[o]),h?g.jsxs("div",{className:"max-w-full w-full","data-theme":"select-post-builder",children:[g.jsx("div",{ref:l,className:"flex-1 space-y-3 max-w-full",children:g.jsxs(ty.Provider,{value:v,children:[r&&g.jsx(Dte,{user:n,store:m}),o?g.jsx(Lee,{open:c,onOpenChange:u,editor:h,actions:p,editorTab:d,onSwitchEditor:f,isSubmitting:i,onSubmit:w}):g.jsx(pN,{editor:h,actions:p,editorTab:d,onSwitchEditor:f,isSubmitting:i,onSubmit:w})]})}),g.jsx($te,{position:"top-center"})]}):null};exports.PostBuilderEditor=Gte;exports.PostBuilderProvider=RI;
586
+ `?i.insert.slice(0,-1):i.insert;(typeof a!="string"||a.length>0)&&pp(r,this,o,a,i.attributes||{})}else i.retain!==void 0?FE(r,this,o,i.retain,i.attributes||{}):i.delete!==void 0&&HE(r,o,i.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,n,r){this.doc??Zt();const o=[],s=new Map,i=this.doc;let a="",l=this._start;function c(){if(a.length>0){const d={};let f=!1;s.forEach((p,m)=>{f=!0,d[m]=p});const h={insert:a};f&&(h.attributes=d),o.push(h),a=""}}const u=()=>{for(;l!==null;){if(vs(l,e)||n!==void 0&&vs(l,n))switch(l.content.constructor){case br:{const d=s.get("ychange");e!==void 0&&!vs(l,e)?(d===void 0||d.user!==l.id.client||d.type!=="removed")&&(c(),s.set("ychange",r?r("removed",l.id):{type:"removed"})):n!==void 0&&!vs(l,n)?(d===void 0||d.user!==l.id.client||d.type!=="added")&&(c(),s.set("ychange",r?r("added",l.id):{type:"added"})):d!==void 0&&(c(),s.delete("ychange")),a+=l.content.str;break}case Sr:case ti:{c();const d={insert:l.content.getContent()[0]};if(s.size>0){const f={};d.attributes=f,s.forEach((h,p)=>{f[p]=h})}o.push(d);break}case kt:vs(l,e)&&(c(),sa(s,l.content));break}l=l.right}c()};return e||n?Je(i,d=>{e&&qm(d,e),n&&qm(d,n),u()},"cleanup"):u(),o}insert(e,n,r){if(n.length<=0)return;const o=this.doc;o!==null?Je(o,s=>{const i=$c(s,this,e,!r);r||(r={},i.currentAttributes.forEach((a,l)=>{r[l]=a})),pp(s,this,i,n,r)}):this._pending.push(()=>this.insert(e,n,r))}insertEmbed(e,n,r){const o=this.doc;o!==null?Je(o,s=>{const i=$c(s,this,e,!r);pp(s,this,i,n,r||{})}):this._pending.push(()=>this.insertEmbed(e,n,r||{}))}delete(e,n){if(n===0)return;const r=this.doc;r!==null?Je(r,o=>{HE(o,$c(o,this,e,!0),n)}):this._pending.push(()=>this.delete(e,n))}format(e,n,r){if(n===0)return;const o=this.doc;o!==null?Je(o,s=>{const i=$c(s,this,e,!1);i.right!==null&&FE(s,this,i,n,r)}):this._pending.push(()=>this.format(e,n,r))}removeAttribute(e){this.doc!==null?Je(this.doc,n=>{wd(n,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,n){this.doc!==null?Je(this.doc,r=>{Nv(r,this,e,n)}):this._pending.push(()=>this.setAttribute(e,n))}getAttribute(e){return _v(this,e)}getAttributes(){return YR(this)}_write(e){e.writeTypeRef(jZ)}}const vZ=t=>new is;class mp{constructor(e,n=()=>!0){this._filter=n,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??Zt()}[Symbol.iterator](){return this}next(){let e=this._currentNode,n=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(n)))do if(n=e.content.type,!e.deleted&&(n.constructor===Qt||n.constructor===Vs)&&n._start!==null)e=n._start;else for(;e!==null;){const r=e.next;if(r!==null){e=r;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 Vs extends Bt{constructor(){super(),this._prelimContent=[]}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,n){super._integrate(e,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Vs}clone(){const e=new Vs;return e.insert(0,this.toArray().map(n=>n instanceof Bt?n.clone():n)),e}get length(){return this.doc??Zt(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new mp(this,e)}querySelector(e){e=e.toUpperCase();const r=new mp(this,o=>o.nodeName&&o.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),zs(new mp(this,n=>n.nodeName&&n.nodeName.toUpperCase()===e))}_callObserver(e,n){Lf(this,e,new wZ(this,n,e))}toString(){return VR(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,n={},r){const o=e.createDocumentFragment();return r!==void 0&&r._createAssociation(o,this),kl(this,s=>{o.insertBefore(s.toDOM(e,n,r),null)}),o}insert(e,n){this.doc!==null?Je(this.doc,r=>{qR(r,this,e,n)}):this._prelimContent.splice(e,0,...n)}insertAfter(e,n){if(this.doc!==null)Je(this.doc,r=>{const o=e&&e instanceof Bt?e._item:e;xd(r,this,o,n)});else{const r=this._prelimContent,o=e===null?0:r.findIndex(s=>s===e)+1;if(o===0&&e!==null)throw rs("Reference item not found");r.splice(o,0,...n)}}delete(e,n=1){this.doc!==null?Je(this.doc,r=>{KR(r,this,e,n)}):this._prelimContent.splice(e,n)}toArray(){return UR(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return WR(this,e)}slice(e=0,n=this.length){return HR(this,e,n)}forEach(e){kl(this,e)}_write(e){e.writeTypeRef(BZ)}}const bZ=t=>new Vs;class Qt extends Vs{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,n){super._integrate(e,n),this._prelimAttrs.forEach((r,o)=>{this.setAttribute(o,r)}),this._prelimAttrs=null}_copy(){return new Qt(this.nodeName)}clone(){const e=new Qt(this.nodeName),n=this.getAttributes();return tQ(n,(r,o)=>{typeof r=="string"&&e.setAttribute(o,r)}),e.insert(0,this.toArray().map(r=>r instanceof Bt?r.clone():r)),e}toString(){const e=this.getAttributes(),n=[],r=[];for(const a in e)r.push(a);r.sort();const o=r.length;for(let a=0;a<o;a++){const l=r[a];n.push(l+'="'+e[l]+'"')}const s=this.nodeName.toLocaleLowerCase(),i=n.length>0?" "+n.join(" "):"";return`<${s}${i}>${super.toString()}</${s}>`}removeAttribute(e){this.doc!==null?Je(this.doc,n=>{wd(n,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,n){this.doc!==null?Je(this.doc,r=>{Nv(r,this,e,n)}):this._prelimAttrs.set(e,n)}getAttribute(e){return _v(this,e)}hasAttribute(e){return JR(this,e)}getAttributes(e){return e?cZ(this,e):YR(this)}toDOM(e=document,n={},r){const o=e.createElement(this.nodeName),s=this.getAttributes();for(const i in s){const a=s[i];typeof a=="string"&&o.setAttribute(i,a)}return kl(this,i=>{o.appendChild(i.toDOM(e,n,r))}),r!==void 0&&r._createAssociation(o,this),o}_write(e){e.writeTypeRef($Z),e.writeKey(this.nodeName)}}const xZ=t=>new Qt(t.readKey());class wZ extends If{constructor(e,n,r){super(e,r),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(o=>{o===null?this.childListChanged=!0:this.attributesChanged.add(o)})}}class Ed extends Wi{constructor(e){super(),this.hookName=e}_copy(){return new Ed(this.hookName)}clone(){const e=new Ed(this.hookName);return this.forEach((n,r)=>{e.set(r,n)}),e}toDOM(e=document,n={},r){const o=n[this.hookName];let s;return o!==void 0?s=o.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(FZ),e.writeKey(this.hookName)}}const EZ=t=>new Ed(t.readKey());class An extends is{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 An}clone(){const e=new An;return e.applyDelta(this.toDelta()),e}toDOM(e=document,n,r){const o=e.createTextNode(this.toString());return r!==void 0&&r._createAssociation(o,this),o}toString(){return this.toDelta().map(e=>{const n=[];for(const o in e.attributes){const s=[];for(const i in e.attributes[o])s.push({key:i,value:e.attributes[o][i]});s.sort((i,a)=>i.key<a.key?-1:1),n.push({nodeName:o,attrs:s})}n.sort((o,s)=>o.nodeName<s.nodeName?-1:1);let r="";for(let o=0;o<n.length;o++){const s=n[o];r+=`<${s.nodeName}`;for(let i=0;i<s.attrs.length;i++){const a=s.attrs[i];r+=` ${a.key}="${a.value}"`}r+=">"}r+=e.insert;for(let o=n.length-1;o>=0;o--)r+=`</${n[o].nodeName}>`;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(HZ)}}const SZ=t=>new An;class Dv{constructor(e,n){this.id=e,this.length=n}get deleted(){throw hr()}mergeWith(e){return!1}write(e,n,r){throw hr()}integrate(e,n){throw hr()}}const kZ=0;class qn extends Dv{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,n){n>0&&(this.id.clock+=n,this.length-=n),IR(e.doc.store,this)}write(e,n){e.writeInfo(kZ),e.writeLen(this.length-n)}getMissing(e,n){return null}}class nc{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new nc(this.content)}splice(e){throw hr()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeBuf(this.content)}getRef(){return 3}}const TZ=t=>new nc(t.readBuf());class Tl{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Tl(this.len)}splice(e){const n=new Tl(this.len-e);return this.len=e,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,n){xl(e.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(e){}gc(e){}write(e,n){e.writeLen(this.len-n)}getRef(){return 1}}const CZ=t=>new Tl(t.readLen()),tN=(t,e)=>new ei({guid:t,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class rc{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 n={};this.opts=n,e.gc||(n.gc=!1),e.autoLoad&&(n.autoLoad=!0),e.meta!==null&&(n.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new rc(tN(this.doc.guid,this.opts))}splice(e){throw hr()}mergeWith(e){return!1}integrate(e,n){this.doc._item=n,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,n){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}}const AZ=t=>new rc(tN(t.readString(),t.readAny()));class ti{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new ti(this.embed)}splice(e){throw hr()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeJSON(this.embed)}getRef(){return 5}}const MZ=t=>new ti(t.readJSON());class kt{constructor(e,n){this.key=e,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new kt(this.key,this.value)}splice(e){throw hr()}mergeWith(e){return!1}integrate(e,n){const r=n.parent;r._searchMarker=null,r._hasFormatting=!0}delete(e){}gc(e){}write(e,n){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}const OZ=t=>new kt(t.readKey(),t.readJSON());class Sd{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Sd(this.arr)}splice(e){const n=new Sd(this.arr.slice(e));return this.arr=this.arr.slice(0,e),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,n){}delete(e){}gc(e){}write(e,n){const r=this.arr.length;e.writeLen(r-n);for(let o=n;o<r;o++){const s=this.arr[o];e.writeString(s===void 0?"undefined":JSON.stringify(s))}}getRef(){return 2}}const RZ=t=>{const e=t.readLen(),n=[];for(let r=0;r<e;r++){const o=t.readString();o==="undefined"?n.push(void 0):n.push(JSON.parse(o))}return new Sd(n)},NZ=yd("node_env")==="development";class Ws{constructor(e){this.arr=e,NZ&&yR(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Ws(this.arr)}splice(e){const n=new Ws(this.arr.slice(e));return this.arr=this.arr.slice(0,e),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,n){}delete(e){}gc(e){}write(e,n){const r=this.arr.length;e.writeLen(r-n);for(let o=n;o<r;o++){const s=this.arr[o];e.writeAny(s)}}getRef(){return 8}}const _Z=t=>{const e=t.readLen(),n=[];for(let r=0;r<e;r++)n.push(t.readAny());return new Ws(n)};class br{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new br(this.str)}splice(e){const n=new br(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)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}}const DZ=t=>new br(t.readString()),IZ=[dZ,hZ,vZ,xZ,bZ,EZ,SZ],PZ=0,LZ=1,jZ=2,$Z=3,BZ=4,FZ=5,HZ=6;class Sr{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new Sr(this.type._copy())}splice(e){throw hr()}mergeWith(e){return!1}integrate(e,n){this.type._integrate(e.doc,n)}delete(e){let n=this.type._start;for(;n!==null;)n.deleted?n.id.clock<(e.beforeState.get(n.id.client)||0)&&e._mergeStructs.push(n):n.delete(e),n=n.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 n=this.type._start;for(;n!==null;)n.gc(e,!0),n=n.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,n){this.type._write(e)}getRef(){return 7}}const UZ=t=>new Sr(IZ[t.readTypeRef()](t)),Jm=(t,e)=>{let n=e,r=0,o;do r>0&&(n=De(n.client,n.clock+r)),o=Ti(t,n),r=n.clock-o.id.clock,n=o.redone;while(n!==null&&o instanceof nt);return{item:o,diff:r}},Iv=(t,e)=>{for(;t!==null&&t.keep!==e;)t.keep=e,t=t.parent._item},kd=(t,e,n)=>{const{client:r,clock:o}=e.id,s=new nt(De(r,o+n),e,De(r,o+n-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(n));return e.deleted&&s.markDeleted(),e.keep&&(s.keep=!0),e.redone!==null&&(s.redone=De(e.redone.client,e.redone.clock+n)),e.right=s,s.right!==null&&(s.right.left=s),t._mergeStructs.push(s),s.parentSub!==null&&s.right===null&&s.parent._map.set(s.parentSub,s),e.length=n,s},UE=(t,e)=>hX(t,n=>oa(n.deletions,e)),nN=(t,e,n,r,o,s)=>{const i=t.doc,a=i.store,l=i.clientID,c=e.redone;if(c!==null)return xn(t,c);let u=e.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||nN(t,u,n,r,o,s)===null))return null;for(;u.redone!==null;)u=xn(t,u.redone)}const h=u===null?e.parent:u.content.type;if(e.parentSub===null){for(d=e.left,f=e;d!==null;){let v=d;for(;v!==null&&v.parent._item!==u;)v=v.redone===null?null:xn(t,v.redone);if(v!==null&&v.parent._item===u){d=v;break}d=d.left}for(;f!==null;){let v=f;for(;v!==null&&v.parent._item!==u;)v=v.redone===null?null:xn(t,v.redone);if(v!==null&&v.parent._item===u){f=v;break}f=f.right}}else if(f=null,e.right&&!o){for(d=e;d!==null&&d.right!==null&&(d.right.redone||oa(r,d.right.id)||UE(s.undoStack,d.right.id)||UE(s.redoStack,d.right.id));)for(d=d.right;d.redone;)d=xn(t,d.redone);if(d&&d.right!==null)return null}else d=h._map.get(e.parentSub)||null;const p=xt(a,l),m=De(l,p),y=new nt(m,d,d&&d.lastId,f,f&&f.id,h,e.parentSub,e.content.copy());return e.redone=m,Iv(y,!0),y.integrate(t,0),y};let nt=class Xm extends Dv{constructor(e,n,r,o,s,i,a,l){super(e,l.getLength()),this.origin=r,this.left=n,this.right=o,this.rightOrigin=s,this.parent=i,this.parentSub=a,this.redone=null,this.content=l,this.info=this.content.isCountable()?vE:0}set marker(e){(this.info&lp)>0!==e&&(this.info^=lp)}get marker(){return(this.info&lp)>0}get keep(){return(this.info&yE)>0}set keep(e){this.keep!==e&&(this.info^=yE)}get countable(){return(this.info&vE)>0}get deleted(){return(this.info&ap)>0}set deleted(e){this.deleted!==e&&(this.info^=ap)}markDeleted(){this.info|=ap}getMissing(e,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=xt(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=xt(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ki&&this.id.client!==this.parent.client&&this.parent.clock>=xt(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=_E(e,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=xn(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===qn||this.right&&this.right.constructor===qn)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===Xm?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===Xm&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===ki){const r=Ti(n,this.parent);r.constructor===qn?this.parent=null:this.parent=r.content.type}return null}integrate(e,n){if(n>0&&(this.id.clock+=n,this.left=_E(e,e.doc.store,De(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,o;if(r!==null)o=r.right;else if(this.parentSub!==null)for(o=this.parent._map.get(this.parentSub)||null;o!==null&&o.left!==null;)o=o.left;else o=this.parent._start;const s=new Set,i=new Set;for(;o!==null&&o!==this.right;){if(i.add(o),s.add(o),Pc(this.origin,o.origin)){if(o.id.client<this.id.client)r=o,s.clear();else if(Pc(this.rightOrigin,o.rightOrigin))break}else if(o.origin!==null&&i.has(Ti(e.doc.store,o.origin)))s.has(Ti(e.doc.store,o.origin))||(r=o,s.clear());else break;o=o.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),IR(e.doc.store,this),this.content.integrate(e,this),IE(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new qn(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:De(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&Pc(e.origin,this.lastId)&&this.right===e&&Pc(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 n=this.parent._searchMarker;return n&&n.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 n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),xl(e.deleteSet,this.id.client,this.id.clock,this.length),IE(e,n,this.parentSub),this.content.delete(e)}}gc(e,n){if(!this.deleted)throw Mn();this.content.gc(e),n?qQ(e,this,new qn(this.id,this.length)):this.content=new Tl(this.length)}write(e,n){const r=n>0?De(this.id.client,this.id.clock+n-1):this.origin,o=this.rightOrigin,s=this.parentSub,i=this.content.getRef()&Of|(r===null?0:an)|(o===null?0:co)|(s===null?0:yl);if(e.writeInfo(i),r!==null&&e.writeLeftID(r),o!==null&&e.writeRightID(o),r===null&&o===null){const a=this.parent;if(a._item!==void 0){const l=a._item;if(l===null){const c=wl(a);e.writeParentInfo(!0),e.writeString(c)}else e.writeParentInfo(!1),e.writeLeftID(l.id)}else a.constructor===String?(e.writeParentInfo(!0),e.writeString(a)):a.constructor===ki?(e.writeParentInfo(!1),e.writeLeftID(a)):Mn();s!==null&&e.writeString(s)}this.content.write(e,n)}};const rN=(t,e)=>zZ[e&Of](t),zZ=[()=>{Mn()},CZ,RZ,TZ,DZ,MZ,OZ,UZ,_Z,AZ,()=>{Mn()}],VZ=10;class cr extends Dv{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,n){Mn()}write(e,n){e.writeInfo(VZ),$e(e.restEncoder,this.length-n)}getMissing(e,n){return null}}const oN=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},sN="__ $YJS$ __";oN[sN]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");oN[sN]=!0;const WZ=()=>{let t=!0;return(e,n)=>{if(t){t=!1;try{e()}finally{t=!0}}else n!==void 0&&n()}},GZ=/[\uD800-\uDBFF]/,qZ=/[\uDC00-\uDFFF]/,KZ=(t,e)=>{let n=0,r=0;for(;n<t.length&&n<e.length&&t[n]===e[n];)n++;for(n>0&&GZ.test(t[n-1])&&n--;r+n<t.length&&r+n<e.length&&t[t.length-r-1]===e[e.length-r-1];)r++;return r>0&&qZ.test(t[t.length-r])&&r--,{index:n,remove:t.length-n-r,insert:e.slice(n,e.length-r)}},YZ=KZ,Fr=(t,e)=>t>>>e|t<<32-e,JZ=t=>Fr(t,2)^Fr(t,13)^Fr(t,22),XZ=t=>Fr(t,6)^Fr(t,11)^Fr(t,25),QZ=t=>Fr(t,7)^Fr(t,18)^t>>>3,ZZ=t=>Fr(t,17)^Fr(t,19)^t>>>10,eee=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),tee=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class nee{constructor(){const e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(tee),this._W=new Uint32Array(e,64,64)}_updateHash(){const e=this._H,n=this._W;for(let d=16;d<64;d++)n[d]=ZZ(n[d-2])+n[d-7]+QZ(n[d-15])+n[d-16];let r=e[0],o=e[1],s=e[2],i=e[3],a=e[4],l=e[5],c=e[6],u=e[7];for(let d=0,f,h;d<64;d++)f=u+XZ(a)+(a&l^~a&c)+eee[d]+n[d]>>>0,h=JZ(r)+(r&o^r&s^o&s)>>>0,u=c,c=l,l=a,a=i+f>>>0,i=s,s=o,o=r,r=f+h>>>0;e[0]+=r,e[1]+=o,e[2]+=s,e[3]+=i,e[4]+=a,e[5]+=l,e[6]+=c,e[7]+=u}digest(e){let n=0;for(;n+56<=e.length;){let i=0;for(;i<16&&n+3<e.length;i++)this._W[i]=e[n++]<<24|e[n++]<<16|e[n++]<<8|e[n++];if(n%64!==0){for(this._W.fill(0,i,16);n<e.length;)this._W[i]|=e[n]<<(3-n%4)*8,n++;this._W[i]|=an<<(3-n%4)*8}this._updateHash()}const r=n%64!==0;this._W.fill(0,0,16);let o=0;for(;n<e.length;o++)for(let i=3;i>=0&&n<e.length;i--)this._W[o]|=e[n++]<<i*8;r||(this._W[o-(n%4===0?0:1)]|=an<<(3-n%4)*8),this._W[14]=e.byteLength/pX,this._W[15]=e.byteLength*8,this._updateHash();const s=new Uint8Array(32);for(let i=0;i<this._H.length;i++)for(let a=0;a<4;a++)s[i*4+a]=this._H[i]>>>(3-a)*8;return s}}const ree=t=>new nee().digest(t),pt=new We("y-sync"),uo=new We("y-undo");new We("yjs-cursor");const oee=t=>{for(let n=6;n<t.length;n++)t[n%6]=t[n%6]^t[n];return t.slice(0,6)},see=t=>fQ(oee(ree(hQ(t)))),Td=(t,e)=>e===void 0?!t.deleted:e.sv.has(t.id.client)&&e.sv.get(t.id.client)>t.id.clock&&!oa(e.ds,t.id),iee=[{light:"#ecd44433",dark:"#ecd444"}],aee=(t,e,n)=>{if(!t.has(n)){if(t.size<e.length){const r=Us();t.forEach(o=>r.add(o)),e=e.filter(o=>!r.has(o))}t.set(n,qX(e))}return t.get(n)},lee=(t,{colors:e=iee,colorMapping:n=new Map,permanentUserData:r=null,onFirstRender:o=()=>{},mapping:s}={})=>{let i=!1;const a=new uee(t,s),l=new Ue({props:{editable:c=>{const u=pt.getState(c);return u.snapshot==null&&u.prevSnapshot==null}},key:pt,state:{init:(c,u)=>({type:t,doc:t.doc,binding:a,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:e,colorMapping:n,permanentUserData:r}),apply:(c,u)=>{const d=c.getMeta(pt);if(d!==void 0){u=Object.assign({},u);for(const f in d)u[f]=d[f]}return u.addToHistory=c.getMeta("addToHistory")!==!1,u.isChangeOrigin=d!==void 0&&!!d.isChangeOrigin,u.isUndoRedoOperation=d!==void 0&&!!d.isChangeOrigin&&!!d.isUndoRedoOperation,a.prosemirrorView!==null&&d!==void 0&&(d.snapshot!=null||d.prevSnapshot!=null)&&xR(0,()=>{a.prosemirrorView!=null&&(d.restore==null?a._renderSnapshot(d.snapshot,d.prevSnapshot,u):(a._renderSnapshot(d.snapshot,d.snapshot,u),delete u.restore,delete u.snapshot,delete u.prevSnapshot,a.mux(()=>{a._prosemirrorChanged(a.prosemirrorView.state.doc)})))}),u}},view:c=>(a.initView(c),s==null&&a._forceRerender(),o(),{update:()=>{const u=l.getState(c.state);if(u.snapshot==null&&u.prevSnapshot==null&&(i||c.state.doc.content.findDiffStart(c.state.doc.type.createAndFill().content)!==null)){if(i=!0,u.addToHistory===!1&&!u.isChangeOrigin){const d=uo.getState(c.state),f=d&&d.undoManager;f&&f.stopCapturing()}a.mux(()=>{u.doc.transact(d=>{d.meta.set("addToHistory",u.addToHistory),a._prosemirrorChanged(c.state.doc)},pt)})}},destroy:()=>{a.destroy()}})});return l},cee=(t,e,n)=>{if(e!==null&&e.anchor!==null&&e.head!==null)if(e.type==="all")t.setSelection(new Sn(t.doc));else if(e.type==="node"){const r=iu(n.doc,n.type,e.anchor,n.mapping);t.setSelection(ue.create(t.doc,r))}else{const r=iu(n.doc,n.type,e.anchor,n.mapping),o=iu(n.doc,n.type,e.head,n.mapping);r!==null&&o!==null&&t.setSelection(pe.between(t.doc.resolve(r),t.doc.resolve(o)))}},Qm=(t,e)=>({type:e.selection.jsonID,anchor:ng(e.selection.anchor,t.type,t.mapping),head:ng(e.selection.head,t.type,t.mapping)});class uee{constructor(e,n=new Map){this.type=e,this.prosemirrorView=null,this.mux=WZ(),this.mapping=n,this.isOMark=new Map,this._observeFunction=this._typeChanged.bind(this),this.doc=e.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=Qm(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return this.prosemirrorView.hasFocus()?(vR&&this._domSelectionInView===null&&(xR(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){const e=this.prosemirrorView._root.getSelection();if(e==null||e.anchorNode==null)return!1;const n=this.prosemirrorView._root.createRange();n.setStart(e.anchorNode,e.anchorOffset),n.setEnd(e.focusNode,e.focusOffset),n.getClientRects().length===0&&n.startContainer&&n.collapsed&&n.selectNodeContents(n.startContainer);const o=n.getBoundingClientRect(),s=mQ.documentElement;return o.bottom>=0&&o.right>=0&&o.left<=(window.innerWidth||s.clientWidth||0)&&o.top<=(window.innerHeight||s.clientHeight||0)}renderSnapshot(e,n){n||(n=_R(MR(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(pt,{snapshot:e,prevSnapshot:n}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{const e=this.type.toArray().map(r=>su(r,this.prosemirrorView.state.schema,this)).filter(r=>r!==null),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new ee(F.from(e),0,0));n.setMeta(pt,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(n)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{const e=this.beforeTransactionSelection!==null?null:this.prosemirrorView.state.selection,n=this.type.toArray().map(o=>su(o,this.prosemirrorView.state.schema,this)).filter(o=>o!==null),r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new ee(F.from(n),0,0));if(e){const o=Ui(ns(e.anchor,0),r.doc.content.size),s=Ui(ns(e.head,0),r.doc.content.size);r.setSelection(pe.create(r.doc,o,s))}this.prosemirrorView.dispatch(r.setMeta(pt,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,n,r){let o=this.doc,s=this.type;if(e||(e=hp(this.doc)),e instanceof Uint8Array||n instanceof Uint8Array)if((!(e instanceof Uint8Array)||!(n instanceof Uint8Array))&&Mn(),o=new ei({gc:!1}),Gm(o,n),n=hp(o),Gm(o,e),e=hp(o),s._item===null){const i=Array.from(this.doc.share.keys()).find(a=>this.doc.share.get(a)===this.type);s=o.getXmlFragment(i)}else{const i=o.store.clients.get(s._item.id.client)??[],a=vr(i,s._item.id.clock);s=i[a].content.type}this.mapping.clear(),this.mux(()=>{o.transact(i=>{const a=r.permanentUserData;a&&a.dss.forEach(d=>{ss(i,d,f=>{})});const l=(d,f)=>{const h=d==="added"?a.getUserByClientId(f.client):a.getUserByDeletedId(f);return{user:h,type:d,color:aee(r.colorMapping,r.colors,h)}},c=zR(s,new Ov(n.ds,e.sv)).map(d=>!d._item.deleted||Td(d._item,e)||Td(d._item,n)?su(d,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},e,n,l):null).filter(d=>d!==null),u=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new ee(F.from(c),0,0));this.prosemirrorView.dispatch(u.setMeta(pt,{isChangeOrigin:!0}))},pt)})}_typeChanged(e,n){if(this.prosemirrorView==null)return;const r=pt.getState(this.prosemirrorView.state);if(e.length===0||r.snapshot!=null||r.prevSnapshot!=null){this.renderSnapshot(r.snapshot,r.prevSnapshot);return}this.mux(()=>{const o=(a,l)=>this.mapping.delete(l);ss(n,n.deleteSet,a=>{if(a.constructor===nt){const l=a.content.type;l&&this.mapping.delete(l)}}),n.changed.forEach(o),n.changedParentTypes.forEach(o);const s=this.type.toArray().map(a=>iN(a,this.prosemirrorView.state.schema,this)).filter(a=>a!==null);let i=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new ee(F.from(s),0,0));cee(i,this.beforeTransactionSelection,this),i=i.setMeta(pt,{isChangeOrigin:!0,isUndoRedoOperation:n.origin instanceof jR}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&i.scrollIntoView(),this.prosemirrorView.dispatch(i)})}_prosemirrorChanged(e){this.doc.transact(()=>{eg(this.doc,this.type,e,this),this.beforeTransactionSelection=Qm(this,this.prosemirrorView.state)},pt)}initView(e){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=e,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}}const iN=(t,e,n,r,o,s)=>{const i=n.mapping.get(t);if(i===void 0){if(t instanceof Qt)return su(t,e,n,r,o,s);throw hr()}return i},su=(t,e,n,r,o,s)=>{const i=[],a=l=>{if(l instanceof Qt){const c=iN(l,e,n,r,o,s);c!==null&&i.push(c)}else{const c=l._item.right?.content?.type;c instanceof is&&!c._item.deleted&&c._item.id.client===c.doc.clientID&&(l.applyDelta([{retain:l.length},...c.toDelta()]),c.doc.transact(d=>{c._item.delete(d)}));const u=dee(l,e,n,r,o,s);u!==null&&u.forEach(d=>{d!==null&&i.push(d)})}};r===void 0||o===void 0?t.toArray().forEach(a):zR(t,new Ov(o.ds,r.sv)).forEach(a);try{const l=t.getAttributes(r);r!==void 0&&(Td(t._item,r)?Td(t._item,o)||(l.ychange=s?s("added",t._item.id):{type:"added"}):l.ychange=s?s("removed",t._item.id):{type:"removed"});const c=e.node(t.nodeName,l,i);return n.mapping.set(t,c),c}catch{return t.doc.transact(c=>{t._item.delete(c)},pt),n.mapping.delete(t),null}},dee=(t,e,n,r,o,s)=>{const i=[],a=t.toDelta(r,o,s);try{for(let l=0;l<a.length;l++){const c=a[l];i.push(e.text(c.insert,yee(c.attributes,e)))}}catch{return t.doc.transact(c=>{t._item.delete(c)},pt),null}return i},fee=(t,e)=>{const n=new An,r=t.map(o=>({insert:o.text,attributes:lN(o.marks,e)}));return n.applyDelta(r),e.mapping.set(n,t),n},hee=(t,e)=>{const n=new Qt(t.type.name);for(const r in t.attrs){const o=t.attrs[r];o!==null&&r!=="ychange"&&n.setAttribute(r,o)}return n.insert(0,jf(t).map(r=>Zm(r,e))),e.mapping.set(n,t),n},Zm=(t,e)=>t instanceof Array?fee(t,e):hee(t,e),zE=t=>typeof t=="object"&&t!==null,Pv=(t,e)=>{const n=Object.keys(t).filter(o=>t[o]!==null);let r=n.length===Object.keys(e).filter(o=>e[o]!==null).length;for(let o=0;o<n.length&&r;o++){const s=n[o],i=t[s],a=e[s];r=s==="ychange"||i===a||zE(i)&&zE(a)&&Pv(i,a)}return r},jf=t=>{const e=t.content.content,n=[];for(let r=0;r<e.length;r++){const o=e[r];if(o.isText){const s=[];for(let i=e[r];r<e.length&&i.isText;i=e[++r])s.push(i);r--,n.push(s)}else n.push(o)}return n},aN=(t,e)=>{const n=t.toDelta();return n.length===e.length&&n.every((r,o)=>r.insert===e[o].text&&mR(r.attributes||{}).length===e[o].marks.length&&gR(r.attributes,(s,i)=>{const a=Lv(i),l=e[o].marks;return Pv(s,l.find(c=>c.type.name===a)?.attrs)}))},Cl=(t,e)=>{if(t instanceof Qt&&!(e instanceof Array)&&tg(t,e)){const n=jf(e);return t._length===n.length&&Pv(t.getAttributes(),e.attrs)&&t.toArray().every((r,o)=>Cl(r,n[o]))}return t instanceof An&&e instanceof Array&&aN(t,e)},Cd=(t,e)=>t===e||t instanceof Array&&e instanceof Array&&t.length===e.length&&t.every((n,r)=>e[r]===n),VE=(t,e,n)=>{const r=t.toArray(),o=jf(e),s=o.length,i=r.length,a=Ui(i,s);let l=0,c=0,u=!1;for(;l<a;l++){const d=r[l],f=o[l];if(Cd(n.mapping.get(d),f))u=!0;else if(!Cl(d,f))break}for(;l+c<a;c++){const d=r[i-c-1],f=o[s-c-1];if(Cd(n.mapping.get(d),f))u=!0;else if(!Cl(d,f))break}return{equalityFactor:l+c,foundMappedChild:u}},pee=t=>{let e="",n=t._start;const r={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof br?e+=n.content.str:n.content instanceof kt&&(r[n.content.key]=null)),n=n.right;return{str:e,nAttrs:r}},mee=(t,e,n)=>{n.mapping.set(t,e);const{nAttrs:r,str:o}=pee(t),s=e.map(c=>({insert:c.text,attributes:Object.assign({},r,lN(c.marks,n))})),{insert:i,remove:a,index:l}=YZ(o,s.map(c=>c.insert).join(""));t.delete(l,a),t.insert(l,i),t.applyDelta(s.map(c=>({retain:c.insert.length,attributes:c.attributes})))},gee=/(.*)(--[a-zA-Z0-9+/=]{8})$/,Lv=t=>gee.exec(t)?.[1]??t,yee=(t,e)=>{const n=[];for(const r in t)n.push(e.mark(Lv(r),t[r]));return n},lN=(t,e)=>{const n={};return t.forEach(r=>{if(r.type.name!=="ychange"){const o=ko(e.isOMark,r.type,()=>!r.type.excludes(r.type));n[o?`${r.type.name}--${see(r.toJSON())}`:r.type.name]=r.attrs}}),n},eg=(t,e,n,r)=>{if(e instanceof Qt&&e.nodeName!==n.type.name)throw new Error("node name mismatch!");if(r.mapping.set(e,n),e instanceof Qt){const d=e.getAttributes(),f=n.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 o=jf(n),s=o.length,i=e.toArray(),a=i.length,l=Ui(s,a);let c=0,u=0;for(;c<l;c++){const d=i[c],f=o[c];if(!Cd(r.mapping.get(d),f))if(Cl(d,f))r.mapping.set(d,f);else break}for(;u+c+1<l;u++){const d=i[a-u-1],f=o[s-u-1];if(!Cd(r.mapping.get(d),f))if(Cl(d,f))r.mapping.set(d,f);else break}t.transact(()=>{for(;a-c-u>0&&s-c-u>0;){const f=i[c],h=o[c],p=i[a-u-1],m=o[s-u-1];if(f instanceof An&&h instanceof Array)aN(f,h)||mee(f,h,r),c+=1;else{let y=f instanceof Qt&&tg(f,h),v=p instanceof Qt&&tg(p,m);if(y&&v){const w=VE(f,h,r),E=VE(p,m,r);w.foundMappedChild&&!E.foundMappedChild?v=!1:!w.foundMappedChild&&E.foundMappedChild||w.equalityFactor<E.equalityFactor?y=!1:v=!1}y?(eg(t,f,h,r),c+=1):v?(eg(t,p,m,r),u+=1):(r.mapping.delete(e.get(c)),e.delete(c,1),e.insert(c,[Zm(h,r)]),c+=1)}}const d=a-c-u;if(a===1&&s===0&&i[0]instanceof An?(r.mapping.delete(i[0]),i[0].delete(0,i[0].length)):d>0&&(e.slice(c,c+d).forEach(f=>r.mapping.delete(f)),e.delete(c,d)),c+u<s){const f=[];for(let h=c;h<s-u;h++)f.push(Zm(o[h],r));e.insert(c,f)}},pt)},tg=(t,e)=>!(e instanceof Array)&&t.nodeName===e.type.name,ng=(t,e,n)=>{if(t===0)return fp(e,0,-1);let r=e._first===null?null:e._first.content.type;for(;r!==null&&e!==r;){if(r instanceof An){if(r._length>=t)return fp(r,t,-1);if(t-=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,t--;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 o=(n.get(r)||{nodeSize:0}).nodeSize;if(r._first!==null&&t<o)r=r._first.content.type,t--;else{if(t===1&&r._length===0&&o>1)return new bd(r._item===null?null:r._item.id,r._item===null?wl(r):null,null);if(t-=o,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{if(t===0)return r=r._item===null?r:r._item.parent,new bd(r._item===null?null:r._item.id,r._item===null?wl(r):null,null);do r=r._item.parent,t--;while(r!==e&&r._item.next===null);r!==e&&(r=r._item.next.content.type)}}}if(r===null)throw Mn();if(t===0&&r.constructor!==An&&r!==e)return vee(r._item.parent,r._item)}return fp(e,e._length,-1)},vee=(t,e)=>{let n=null,r=null;return t._item===null?r=wl(t):n=De(t._item.id.client,t._item.id.clock),new bd(n,r,e.id)},iu=(t,e,n,r)=>{const o=WQ(n,t);if(o===null||o.type!==e&&!El(e,o.type._item))return null;let s=o.type,i=0;if(s.constructor===An)i=o.index;else if(s._item===null||!s._item.deleted){let a=s._first,l=0;for(;l<s._length&&l<o.index&&a!==null;){if(!a.deleted){const c=a.content.type;l++,c instanceof An?i+=c._length:i+=r.get(c).nodeSize}a=a.right}i+=1}for(;s!==e&&s._item!==null;){const a=s._item.parent;if(a._item===null||!a._item.deleted){i+=1;let l=a._first;for(;l!==null;){const c=l.content.type;if(c===s)break;l.deleted||(c instanceof An?i+=c._length:i+=r.get(c).nodeSize),l=l.right}}s=a}return i-1};function bee(t){const e=t.toArray(),n=r=>{let o;if(r instanceof An)o=r.toDelta().map(i=>{const a={type:"text",text:i.insert};return i.attributes&&(a.marks=Object.keys(i.attributes).map(l=>{const c=i.attributes[l],d={type:Lv(l)};return Object.keys(c)&&(d.attrs=c),d})),a});else if(r instanceof Qt){o={type:r.nodeName};const s=r.getAttributes();Object.keys(s).length&&(o.attrs=s);const i=r.toArray();i.length&&(o.content=i.map(n).flat())}else Mn();return o};return{type:"doc",content:e.map(n)}}const xee=t=>{const e=uo.getState(t).undoManager;if(e!=null)return e.undo(),!0},wee=t=>{const e=uo.getState(t).undoManager;if(e!=null)return e.redo(),!0},Eee=new Set(["paragraph"]),See=(t,e)=>!(t instanceof nt)||!(t.content instanceof Sr)||!(t.content.type instanceof is||t.content.type instanceof Qt&&e.has(t.content.type.nodeName))||t.content.type._length===0,kee=({protectedNodes:t=Eee,trackedOrigins:e=[],undoManager:n=null}={})=>new Ue({key:uo,state:{init:(r,o)=>{const s=pt.getState(o),i=n||new jR(s.type,{trackedOrigins:new Set([pt].concat(e)),deleteFilter:a=>See(a,t),captureTransaction:a=>a.meta.get("addToHistory")!==!1});return{undoManager:i,prevSel:null,hasUndoOps:i.undoStack.length>0,hasRedoOps:i.redoStack.length>0}},apply:(r,o,s,i)=>{const a=pt.getState(i).binding,l=o.undoManager,c=l.undoStack.length>0,u=l.redoStack.length>0;return a?{undoManager:l,prevSel:Qm(a,s),hasUndoOps:c,hasRedoOps:u}:c!==o.hasUndoOps||u!==o.hasRedoOps?Object.assign({},o,{hasUndoOps:l.undoStack.length>0,hasRedoOps:l.redoStack.length>0}):o}},view:r=>{const o=pt.getState(r.state),s=uo.getState(r.state).undoManager;return s.on("stack-item-added",({stackItem:i})=>{const a=o.binding;a&&i.meta.set(a,uo.getState(r.state).prevSel)}),s.on("stack-item-popped",({stackItem:i})=>{const a=o.binding;a&&(a.beforeTransactionSelection=i.meta.get(a)||a.beforeTransactionSelection)}),{destroy:()=>{s.destroy()}}}});Qe.create({name:"collaboration",priority:1e3,addOptions(){return{document:null,field:"default",fragment:null,provider:null}},addStorage(){return{isDisabled:!1}},onCreate(){this.editor.extensionManager.extensions.find(t=>t.name==="undoRedo")&&console.warn('[tiptap warn]: "@tiptap/extension-collaboration" comes with its own history support and is not compatible with "@tiptap/extension-undo-redo".')},addCommands(){return{undo:()=>({tr:t,state:e,dispatch:n})=>(t.setMeta("preventDispatch",!0),uo.getState(e).undoManager.undoStack.length===0?!1:n?xee(e):!0),redo:()=>({tr:t,state:e,dispatch:n})=>(t.setMeta("preventDispatch",!0),uo.getState(e).undoManager.redoStack.length===0?!1:n?wee(e):!0)}},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo()}},addProseMirrorPlugins(){var t;const e=this.options.fragment?this.options.fragment:this.options.document.getXmlFragment(this.options.field),n=kee(this.options.yUndoOptions),r=n.spec.view;n.spec.view=i=>{const{undoManager:a}=uo.getState(i.state);a.restore&&(a.restore(),a.restore=()=>{});const l=r?r(i):void 0;return{destroy:()=>{const c=a.trackedOrigins.has(a),u=a._observers;a.restore=()=>{c&&a.trackedOrigins.add(a),a.doc.on("afterTransaction",a.afterTransactionHandler),a._observers=u},l?.destroy&&l.destroy()}}};const o={...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender},s=lee(e,o);return this.editor.options.enableContentCheck&&((t=e.doc)==null||t.on("beforeTransaction",()=>{try{const i=bee(e);if(i.content.length===0)return;this.editor.schema.nodeFromJSON(i).check()}catch(i){return this.editor.emit("contentError",{error:i,editor:this.editor,disableCollaboration:()=>{var a;(a=e.doc)==null||a.destroy(),this.storage.isDisabled=!0}}),!1}})),[s,n,this.editor.options.enableContentCheck&&new Ue({key:new We("filterInvalidContent"),filterTransaction:()=>{var i;return this.storage.isDisabled!==!1&&((i=e.doc)==null||i.destroy()),!0}})].filter(Boolean)}});function Tee(t){return!!t.getMeta(pt)}function WE(t){if(!t.length)return et.empty;const e=[],n=t[0].$from.node(0);return t.forEach(r=>{const o=r.$from.pos,s=r.$from.nodeAfter;s&&e.push(Gt.node(o,o+s.nodeSize,{class:"ProseMirror-selectednoderange"}))}),et.create(n,e)}function $f(t,e,n){const r=[],o=t.node(0);typeof n=="number"&&n>=0||(t.sameParent(e)?n=Math.max(0,t.sharedDepth(e.pos)-1):n=t.sharedDepth(e.pos));const s=new Ga(t,e,n),i=s.depth===0?0:o.resolve(s.start).posAtIndex(0);return s.parent.forEach((a,l)=>{const c=i+l,u=c+a.nodeSize;if(c<s.start||c>=s.end)return;const d=new Qk(o.resolve(c),o.resolve(u));r.push(d)}),r}var Cee=class cN{constructor(e,n){this.anchor=e,this.head=n}map(e){return new cN(e.map(this.anchor),e.map(this.head))}resolve(e){const n=e.resolve(this.anchor),r=e.resolve(this.head);return new Vo(n,r)}},Vo=class _o extends Oe{constructor(e,n,r,o=1){const{doc:s}=e,i=e===n,a=e.pos===s.content.size&&n.pos===s.content.size,l=i&&!a?s.resolve(n.pos+(o>0?1:-1)):n,c=i&&a?s.resolve(e.pos-(o>0?1:-1)):e,u=$f(c.min(l),c.max(l),r),d=l.pos>=e.pos?u[0].$from:u[u.length-1].$to,f=l.pos>=e.pos?u[u.length-1].$to:u[0].$from;super(d,f,u),this.depth=r}get $to(){return this.ranges[this.ranges.length-1].$to}eq(e){return e instanceof _o&&e.$from.pos===this.$from.pos&&e.$to.pos===this.$to.pos}map(e,n){const r=e.resolve(n.map(this.anchor)),o=e.resolve(n.map(this.head));return new _o(r,o)}toJSON(){return{type:"nodeRange",anchor:this.anchor,head:this.head}}get isForwards(){return this.head>=this.anchor}get isBackwards(){return!this.isForwards}extendBackwards(){const{doc:e}=this.$from;if(this.isForwards&&this.ranges.length>1){const o=this.ranges.slice(0,-1),s=o[0].$from,i=o[o.length-1].$to;return new _o(s,i,this.depth)}const n=this.ranges[0],r=e.resolve(Math.max(0,n.$from.pos-1));return new _o(this.$anchor,r,this.depth)}extendForwards(){const{doc:e}=this.$from;if(this.isBackwards&&this.ranges.length>1){const o=this.ranges.slice(1),s=o[0].$from,i=o[o.length-1].$to;return new _o(i,s,this.depth)}const n=this.ranges[this.ranges.length-1],r=e.resolve(Math.min(e.content.size,n.$to.pos+1));return new _o(this.$anchor,r,this.depth)}static fromJSON(e,n){return new _o(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r,o,s=1){return new this(e.resolve(n),e.resolve(r),o,s)}getBookmark(){return new Cee(this.anchor,this.head)}};Vo.prototype.visible=!1;function Bc(t){return t instanceof Vo}Qe.create({name:"nodeRange",addOptions(){return{depth:void 0,key:"Mod"}},addKeyboardShortcuts(){return{"Shift-ArrowUp":({editor:t})=>{const{depth:e}=this.options,{view:n,state:r}=t,{doc:o,selection:s,tr:i}=r,{anchor:a,head:l}=s;if(!Bc(s)){const u=Vo.create(o,a,l,e,-1);return i.setSelection(u),n.dispatch(i),!0}const c=s.extendBackwards();return i.setSelection(c),n.dispatch(i),!0},"Shift-ArrowDown":({editor:t})=>{const{depth:e}=this.options,{view:n,state:r}=t,{doc:o,selection:s,tr:i}=r,{anchor:a,head:l}=s;if(!Bc(s)){const u=Vo.create(o,a,l,e);return i.setSelection(u),n.dispatch(i),!0}const c=s.extendForwards();return i.setSelection(c),n.dispatch(i),!0},"Mod-a":({editor:t})=>{const{depth:e}=this.options,{view:n,state:r}=t,{doc:o,tr:s}=r,i=Vo.create(o,0,o.content.size,e);return s.setSelection(i),n.dispatch(s),!0}}},onSelectionUpdate(){const{selection:t}=this.editor.state;Bc(t)&&this.editor.view.dom.classList.add("ProseMirror-noderangeselection")},addProseMirrorPlugins(){let t=!1,e=!1;return[new Ue({key:new We("nodeRange"),props:{attributes:()=>t?{class:"ProseMirror-noderangeselection"}:{class:""},handleDOMEvents:{mousedown:(n,r)=>{const{key:o}=this.options,s=/Mac/.test(navigator.platform),i=!!r.shiftKey,a=!!r.ctrlKey,l=!!r.altKey,c=!!r.metaKey,u=s?c:a;return(o==null||o==="Shift"&&i||o==="Control"&&a||o==="Alt"&&l||o==="Meta"&&c||o==="Mod"&&u)&&(e=!0),e&&document.addEventListener("mouseup",()=>{e=!1;const{state:d}=n,{doc:f,selection:h,tr:p}=d,{$anchor:m,$head:y}=h;if(m.sameParent(y))return;const v=Vo.create(f,m.pos,y.pos,this.options.depth);p.setSelection(v),n.dispatch(p)},{once:!0}),!1}},decorations:n=>{const{selection:r}=n,o=Bc(r);if(t=!1,!e)return o?(t=!0,WE(r.ranges)):null;const{$from:s,$to:i}=r;if(!o&&s.sameParent(i))return null;const a=$f(s,i,this.options.depth);return a.length?(t=!0,WE(a)):null}}})]}});function Aee(t){let e="";const n=getComputedStyle(t);for(let r=0;r<n.length;r+=1)e+=`${n[r]}:${n.getPropertyValue(n[r])};`;return e}function Mee(t){const e=t.cloneNode(!0),n=[t,...Array.from(t.getElementsByTagName("*"))],r=[e,...Array.from(e.getElementsByTagName("*"))];return n.forEach((o,s)=>{r[s].style.cssText=Aee(o)}),e}var uN=t=>{const{x:e,y:n,direction:r="right",editor:o,bandHeight:s=5}=t,i={top:n-s,bottom:n+s,left:r==="right"?e:0,right:r==="right"?window.innerWidth-e:e},l=[...o.view.dom.querySelectorAll("*")].filter(h=>o.view.posAtDOM(h,0)>=0).filter(h=>{const p=h.getBoundingClientRect();return!(p.bottom<i.top||p.top>i.bottom||p.right<i.left||p.left>i.right)});if(!l||l.length===0)return{resultElement:null,resultNode:null,pos:null};const c=l[0],u=o.view.posAtDOM(c,0);if(u===-1)return{resultElement:c,resultNode:null,pos:null};const d=o.state.doc.resolve(u);if(d.nodeAfter){const h=o.view.nodeDOM(d.pos);if(h&&h===c)return{resultElement:c,resultNode:d.nodeAfter,pos:u}}const f=o.state.doc.nodeAt(u-1);return{resultElement:c,resultNode:f,pos:u}};function Fc(t,e){return window.getComputedStyle(t)[e]}function Oee(t=0,e=0,n=0){return Math.min(Math.max(t,e),n)}function Ree(t,e,n){const r=parseInt(Fc(t.dom,"paddingLeft"),10),o=parseInt(Fc(t.dom,"paddingRight"),10),s=parseInt(Fc(t.dom,"borderLeftWidth"),10),i=parseInt(Fc(t.dom,"borderLeftWidth"),10),a=t.dom.getBoundingClientRect();return{left:Oee(e,a.left+r+s,a.right-o-i),top:n}}function dN(t){var e;(e=t.parentNode)==null||e.removeChild(t)}function Nee(t,e){const{doc:n}=e.view.state,r=uN({editor:e,x:t.clientX,y:t.clientY,direction:"right"});if(!r.resultNode||r.pos===null)return[];const o=t.clientX,s=Ree(e.view,o,t.clientY),i=e.view.posAtCoords(s);if(!i)return[];const{pos:a}=i;if(!n.resolve(a).parent)return[];const c=n.resolve(r.pos),u=n.resolve(r.pos+1);return $f(c,u,0)}function _ee(t,e){const{view:n}=e;if(!t.dataTransfer)return;const{empty:r,$from:o,$to:s}=n.state.selection,i=Nee(t,e),a=$f(o,s,0),l=a.some(y=>i.find(v=>v.$from===y.$from&&v.$to===y.$to)),c=r||!l?i:a;if(!c.length)return;const{tr:u}=n.state,d=document.createElement("div"),f=c[0].$from.pos,h=c[c.length-1].$to.pos,p=Vo.create(n.state.doc,f,h),m=p.content();c.forEach(y=>{const v=n.nodeDOM(y.$from.pos),w=Mee(v);d.append(w)}),d.style.position="absolute",d.style.top="-10000px",document.body.append(d),t.dataTransfer.clearData(),t.dataTransfer.setDragImage(d,0,0),n.dragging={slice:m,move:!0},u.setSelection(p),n.dispatch(u),document.addEventListener("drop",()=>dN(d),{once:!0})}var GE=(t,e)=>{const n=t.resolve(e),{depth:r}=n;return r===0?e:n.pos-n.parentOffset-1},qE=(t,e)=>{const n=t.nodeAt(e),r=t.resolve(e);let{depth:o}=r,s=n;for(;o>0;){const i=r.node(o);o-=1,o===0&&(s=i)}return s},gp=(t,e)=>{const n=pt.getState(t);return n?ng(e,n.type,n.binding.mapping):null},Dee=(t,e)=>{const n=pt.getState(t);return n?iu(n.doc,n.type,e,n.binding.mapping)||0:-1},KE=(t,e)=>{let n=e;for(;n?.parentNode&&n.parentNode!==t.dom;)n=n.parentNode;return n},fN=new We("dragHandle"),hN=({pluginKey:t=fN,element:e,editor:n,computePositionConfig:r,getReferencedVirtualElement:o,onNodeChange:s,onElementDragStart:i,onElementDragEnd:a})=>{const l=document.createElement("div");let c=!1,u=null,d=-1,f,h=null,p=null;function m(){e&&(e.style.visibility="hidden",e.style.pointerEvents="none")}function y(){if(e){if(!n.isEditable){m();return}e.style.visibility="",e.style.pointerEvents="auto"}}function v(x){const T=o?.()||{getBoundingClientRect:()=>x.getBoundingClientRect()};UT(T,e,r).then(S=>{Object.assign(e.style,{position:S.strategy,left:`${S.x}px`,top:`${S.y}px`})})}function w(x){i?.(x),_ee(x,n),setTimeout(()=>{e&&(e.style.pointerEvents="none")},0)}function E(x){a?.(x),m(),e&&(e.style.pointerEvents="auto")}return e.addEventListener("dragstart",w),e.addEventListener("dragend",E),l.appendChild(e),{unbind(){e.removeEventListener("dragstart",w),e.removeEventListener("dragend",E),h&&(cancelAnimationFrame(h),h=null,p=null)},plugin:new Ue({key:typeof t=="string"?new We(t):t,state:{init(){return{locked:!1}},apply(x,T,S,k){const C=x.getMeta("lockDragHandle"),N=x.getMeta("hideDragHandle");if(C!==void 0&&(c=C),N)return m(),c=!1,u=null,d=-1,s?.({editor:n,node:null,pos:-1}),T;if(x.docChanged&&d!==-1&&e)if(Tee(x)){const R=Dee(k,f);R!==d&&(d=R)}else{const R=x.mapping.map(d);R!==d&&(d=R,f=gp(k,d))}return T}},view:x=>{var T;return e.draggable=!0,e.style.pointerEvents="auto",(T=n.view.dom.parentElement)==null||T.appendChild(l),l.style.pointerEvents="none",l.style.position="absolute",l.style.top="0",l.style.left="0",{update(S,k){if(!e)return;if(!n.isEditable){m();return}if(c?e.draggable=!1:e.draggable=!0,x.state.doc.eq(k.doc)||d===-1)return;let C=x.nodeDOM(d);if(C=KE(x,C),C===x.dom||C?.nodeType!==1)return;const N=x.posAtDOM(C,0),R=qE(n.state.doc,N),L=GE(n.state.doc,N);u=R,d=L,f=gp(x.state,d),s?.({editor:n,node:u,pos:d}),v(C)},destroy(){h&&(cancelAnimationFrame(h),h=null,p=null),e&&dN(l)}}},props:{handleDOMEvents:{keydown(x){return!e||c||x.hasFocus()&&(m(),u=null,d=-1,s?.({editor:n,node:null,pos:-1})),!1},mouseleave(x,T){return c||T.target&&!l.contains(T.relatedTarget)&&(m(),u=null,d=-1,s?.({editor:n,node:null,pos:-1})),!1},mousemove(x,T){return!e||c||(p={x:T.clientX,y:T.clientY},h)||(h=requestAnimationFrame(()=>{if(h=null,!p)return;const{x:S,y:k}=p;p=null;const C=uN({x:S,y:k,direction:"right",editor:n});if(!C.resultElement)return;let N=C.resultElement;if(N=KE(x,N),N===x.dom||N?.nodeType!==1)return;const R=x.posAtDOM(N,0),L=qE(n.state.doc,R);if(L!==u){const $=GE(n.state.doc,R);u=L,d=$,f=gp(x.state,d),s?.({editor:n,node:u,pos:d}),v(N),y()}})),!1}}}})}},rg={placement:"left-start",strategy:"absolute"};Qe.create({name:"dragHandle",addOptions(){return{render(){const t=document.createElement("div");return t.classList.add("drag-handle"),t},computePositionConfig:{},locked:!1,onNodeChange:()=>null}},addCommands(){return{lockDragHandle:()=>({editor:t})=>(this.options.locked=!0,t.commands.setMeta("lockDragHandle",this.options.locked)),unlockDragHandle:()=>({editor:t})=>(this.options.locked=!1,t.commands.setMeta("lockDragHandle",this.options.locked)),toggleDragHandle:()=>({editor:t})=>(this.options.locked=!this.options.locked,t.commands.setMeta("lockDragHandle",this.options.locked))}},addProseMirrorPlugins(){const t=this.options.render();return[hN({computePositionConfig:{...rg,...this.options.computePositionConfig},getReferencedVirtualElement:this.options.getReferencedVirtualElement,element:t,editor:this.editor,onNodeChange:this.options.onNodeChange}).plugin]}});var Iee=t=>{const{className:e="drag-handle",children:n,editor:r,pluginKey:o=fN,onNodeChange:s,onElementDragStart:i,onElementDragEnd:a,computePositionConfig:l=rg}=t,[c,u]=M.useState(null),d=M.useRef(null);return M.useEffect(()=>{let f=null;return c?r.isDestroyed?()=>{d.current=null}:(d.current||(f=hN({editor:r,element:c,pluginKey:o,computePositionConfig:{...rg,...l},onElementDragStart:i,onElementDragEnd:a,onNodeChange:s}),d.current=f.plugin,r.registerPlugin(d.current)),()=>{r.unregisterPlugin(o),d.current=null,f&&(f.unbind(),f=null)}):()=>{d.current=null}},[c,r,s,o,l,i,a]),g.jsx("div",{className:e,style:{visibility:"hidden",position:"absolute"},ref:u,children:n})},Pee=Iee;const pN=({editor:t,actions:e,editorTab:n,onSwitchEditor:r,isSubmitting:o,onSubmit:s,className:i})=>g.jsxs("div",{className:re("post-builder-editor bg-background border rounded-md overflow-hidden min-h-60 max-h-[calc(100dvh-7rem)] flex flex-col overflow-y-auto transition-all duration-300 ease-in-out",i),children:[g.jsx(GF,{editorTab:n,onSwitchEditorTab:r}),g.jsx(A9,{editor:t,actions:e,isSubmitting:o,onSubmit:s,editorType:n,children:g.jsxs("div",{className:"flex flex-col grow overflow-y-auto",children:[g.jsx(Pee,{editor:t,className:re(" pr-2",n!==gt.Text&&"hidden size-0 overflow-hidden pointer-events-none"),children:g.jsx(Zn,{variant:"ghost",className:"bg-white cursor-grab py-0.5 px-0 border size-auto",children:g.jsx(xV,{className:"text-muted-foreground"})})}),g.jsx(_F,{className:"grow overflow-y-auto","data-theme":"select-post-builder",editor:t})]})})]}),Lee=({open:t,onOpenChange:e,...n})=>g.jsx(wy,{open:t,onOpenChange:e,children:g.jsx(Ey,{className:"bg-transparent border-0 p-0 lg:max-w-4xl -translate-1/2",showCloseButton:!1,children:g.jsx(pN,{...n,className:"bg-white max-h-dvh h-full"})})});function YE(t,[e,n]){return Math.min(n,Math.max(e,t))}var jee=[" ","Enter","ArrowUp","ArrowDown"],$ee=[" ","Enter"],Gs="Select",[Bf,Ff,Bee]=yg(Gs),[ia]=Ln(Gs,[Bee,cs]),Hf=cs(),[Fee,fs]=ia(Gs),[Hee,Uee]=ia(Gs),mN=t=>{const{__scopeSelect:e,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:u,autoComplete:d,disabled:f,required:h,form:p}=t,m=Hf(e),[y,v]=b.useState(null),[w,E]=b.useState(null),[x,T]=b.useState(!1),S=jd(c),[k,C]=po({prop:r,defaultProp:o??!1,onChange:s,caller:Gs}),[N,R]=po({prop:i,defaultProp:a,onChange:l,caller:Gs}),L=b.useRef(null),$=y?p||!!y.closest("form"):!0,[B,U]=b.useState(new Set),j=Array.from(B).map(P=>P.props.value).join(";");return g.jsx(sf,{...m,children:g.jsxs(Fee,{required:h,scope:e,trigger:y,onTriggerChange:v,valueNode:w,onValueNodeChange:E,valueNodeHasChildren:x,onValueNodeHasChildrenChange:T,contentId:Kn(),value:N,onValueChange:R,open:k,onOpenChange:C,dir:S,triggerPointerDownPosRef:L,disabled:f,children:[g.jsx(Bf.Provider,{scope:e,children:g.jsx(Hee,{scope:t.__scopeSelect,onNativeOptionAdd:b.useCallback(P=>{U(H=>new Set(H).add(P))},[]),onNativeOptionRemove:b.useCallback(P=>{U(H=>{const _=new Set(H);return _.delete(P),_})},[]),children:n})}),$?g.jsxs(jN,{"aria-hidden":!0,required:h,tabIndex:-1,name:u,autoComplete:d,value:N,onChange:P=>R(P.target.value),disabled:f,form:p,children:[N===void 0?g.jsx("option",{value:""}):null,Array.from(B)]},j):null]})})};mN.displayName=Gs;var gN="SelectTrigger",yN=b.forwardRef((t,e)=>{const{__scopeSelect:n,disabled:r=!1,...o}=t,s=Hf(n),i=fs(gN,n),a=i.disabled||r,l=Fe(e,i.onTriggerChange),c=Ff(n),u=b.useRef("touch"),[d,f,h]=BN(m=>{const y=c().filter(E=>!E.disabled),v=y.find(E=>E.value===i.value),w=FN(y,m,v);w!==void 0&&i.onValueChange(w.value)}),p=m=>{a||(i.onOpenChange(!0),h()),m&&(i.triggerPointerDownPosRef.current={x:Math.round(m.pageX),y:Math.round(m.pageY)})};return g.jsx(Hl,{asChild:!0,...s,children:g.jsx(ge.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":$N(i.value)?"":void 0,...o,ref:l,onClick:ne(o.onClick,m=>{m.currentTarget.focus(),u.current!=="mouse"&&p(m)}),onPointerDown:ne(o.onPointerDown,m=>{u.current=m.pointerType;const y=m.target;y.hasPointerCapture(m.pointerId)&&y.releasePointerCapture(m.pointerId),m.button===0&&m.ctrlKey===!1&&m.pointerType==="mouse"&&(p(m),m.preventDefault())}),onKeyDown:ne(o.onKeyDown,m=>{const y=d.current!=="";!(m.ctrlKey||m.altKey||m.metaKey)&&m.key.length===1&&f(m.key),!(y&&m.key===" ")&&jee.includes(m.key)&&(p(),m.preventDefault())})})})});yN.displayName=gN;var vN="SelectValue",bN=b.forwardRef((t,e)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=t,l=fs(vN,n),{onValueNodeHasChildrenChange:c}=l,u=s!==void 0,d=Fe(e,l.onValueNodeChange);return Nt(()=>{c(u)},[c,u]),g.jsx(ge.span,{...a,ref:d,style:{pointerEvents:"none"},children:$N(l.value)?g.jsx(g.Fragment,{children:i}):s})});bN.displayName=vN;var zee="SelectIcon",xN=b.forwardRef((t,e)=>{const{__scopeSelect:n,children:r,...o}=t;return g.jsx(ge.span,{"aria-hidden":!0,...o,ref:e,children:r||"▼"})});xN.displayName=zee;var Vee="SelectPortal",wN=t=>g.jsx(ea,{asChild:!0,...t});wN.displayName=Vee;var qs="SelectContent",EN=b.forwardRef((t,e)=>{const n=fs(qs,t.__scopeSelect),[r,o]=b.useState();if(Nt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Md.createPortal(g.jsx(SN,{scope:t.__scopeSelect,children:g.jsx(Bf.Slot,{scope:t.__scopeSelect,children:g.jsx("div",{children:t.children})})}),s):null}return g.jsx(kN,{...t,ref:e})});EN.displayName=qs;var ir=10,[SN,hs]=ia(qs),Wee="SelectContentImpl",Gee=Yo("SelectContent.RemoveScroll"),kN=b.forwardRef((t,e)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:h,sticky:p,hideWhenDetached:m,avoidCollisions:y,...v}=t,w=fs(qs,n),[E,x]=b.useState(null),[T,S]=b.useState(null),k=Fe(e,z=>x(z)),[C,N]=b.useState(null),[R,L]=b.useState(null),$=Ff(n),[B,U]=b.useState(!1),j=b.useRef(!1);b.useEffect(()=>{if(E)return hf(E)},[E]),df();const P=b.useCallback(z=>{const[Z,...Me]=$().map(Se=>Se.ref.current),[he]=Me.slice(-1),we=document.activeElement;for(const Se of z)if(Se===we||(Se?.scrollIntoView({block:"nearest"}),Se===Z&&T&&(T.scrollTop=0),Se===he&&T&&(T.scrollTop=T.scrollHeight),Se?.focus(),document.activeElement!==we))return},[$,T]),H=b.useCallback(()=>P([C,E]),[P,C,E]);b.useEffect(()=>{B&&H()},[B,H]);const{onOpenChange:_,triggerPointerDownPosRef:V}=w;b.useEffect(()=>{if(E){let z={x:0,y:0};const Z=he=>{z={x:Math.abs(Math.round(he.pageX)-(V.current?.x??0)),y:Math.abs(Math.round(he.pageY)-(V.current?.y??0))}},Me=he=>{z.x<=10&&z.y<=10?he.preventDefault():E.contains(he.target)||_(!1),document.removeEventListener("pointermove",Z),V.current=null};return V.current!==null&&(document.addEventListener("pointermove",Z),document.addEventListener("pointerup",Me,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",Z),document.removeEventListener("pointerup",Me,{capture:!0})}}},[E,_,V]),b.useEffect(()=>{const z=()=>_(!1);return window.addEventListener("blur",z),window.addEventListener("resize",z),()=>{window.removeEventListener("blur",z),window.removeEventListener("resize",z)}},[_]);const[ie,te]=BN(z=>{const Z=$().filter(we=>!we.disabled),Me=Z.find(we=>we.ref.current===document.activeElement),he=FN(Z,z,Me);he&&setTimeout(()=>he.ref.current.focus())}),ye=b.useCallback((z,Z,Me)=>{const he=!j.current&&!Me;(w.value!==void 0&&w.value===Z||he)&&(N(z),he&&(j.current=!0))},[w.value]),G=b.useCallback(()=>E?.focus(),[E]),Q=b.useCallback((z,Z,Me)=>{const he=!j.current&&!Me;(w.value!==void 0&&w.value===Z||he)&&L(z)},[w.value]),J=r==="popper"?og:TN,me=J===og?{side:a,sideOffset:l,align:c,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:h,sticky:p,hideWhenDetached:m,avoidCollisions:y}:{};return g.jsx(SN,{scope:n,content:E,viewport:T,onViewportChange:S,itemRefCallback:ye,selectedItem:C,onItemLeave:G,itemTextRefCallback:Q,focusSelectedItem:H,selectedItemText:R,position:r,isPositioned:B,searchRef:ie,children:g.jsx(Vl,{as:Gee,allowPinchZoom:!0,children:g.jsx(zl,{asChild:!0,trapped:w.open,onMountAutoFocus:z=>{z.preventDefault()},onUnmountAutoFocus:ne(o,z=>{w.trigger?.focus({preventScroll:!0}),z.preventDefault()}),children:g.jsx(Xi,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:z=>z.preventDefault(),onDismiss:()=>w.onOpenChange(!1),children:g.jsx(J,{role:"listbox",id:w.contentId,"data-state":w.open?"open":"closed",dir:w.dir,onContextMenu:z=>z.preventDefault(),...v,...me,onPlaced:()=>U(!0),ref:k,style:{display:"flex",flexDirection:"column",outline:"none",...v.style},onKeyDown:ne(v.onKeyDown,z=>{const Z=z.ctrlKey||z.altKey||z.metaKey;if(z.key==="Tab"&&z.preventDefault(),!Z&&z.key.length===1&&te(z.key),["ArrowUp","ArrowDown","Home","End"].includes(z.key)){let he=$().filter(we=>!we.disabled).map(we=>we.ref.current);if(["ArrowUp","End"].includes(z.key)&&(he=he.slice().reverse()),["ArrowUp","ArrowDown"].includes(z.key)){const we=z.target,Se=he.indexOf(we);he=he.slice(Se+1)}setTimeout(()=>P(he)),z.preventDefault()}})})})})})})});kN.displayName=Wee;var qee="SelectItemAlignedPosition",TN=b.forwardRef((t,e)=>{const{__scopeSelect:n,onPlaced:r,...o}=t,s=fs(qs,n),i=hs(qs,n),[a,l]=b.useState(null),[c,u]=b.useState(null),d=Fe(e,k=>u(k)),f=Ff(n),h=b.useRef(!1),p=b.useRef(!0),{viewport:m,selectedItem:y,selectedItemText:v,focusSelectedItem:w}=i,E=b.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&m&&y&&v){const k=s.trigger.getBoundingClientRect(),C=c.getBoundingClientRect(),N=s.valueNode.getBoundingClientRect(),R=v.getBoundingClientRect();if(s.dir!=="rtl"){const we=R.left-C.left,Se=N.left-we,ze=k.left-Se,ut=k.width+ze,dt=Math.max(ut,C.width),Tt=window.innerWidth-ir,ft=YE(Se,[ir,Math.max(ir,Tt-dt)]);a.style.minWidth=ut+"px",a.style.left=ft+"px"}else{const we=C.right-R.right,Se=window.innerWidth-N.right-we,ze=window.innerWidth-k.right-Se,ut=k.width+ze,dt=Math.max(ut,C.width),Tt=window.innerWidth-ir,ft=YE(Se,[ir,Math.max(ir,Tt-dt)]);a.style.minWidth=ut+"px",a.style.right=ft+"px"}const L=f(),$=window.innerHeight-ir*2,B=m.scrollHeight,U=window.getComputedStyle(c),j=parseInt(U.borderTopWidth,10),P=parseInt(U.paddingTop,10),H=parseInt(U.borderBottomWidth,10),_=parseInt(U.paddingBottom,10),V=j+P+B+_+H,ie=Math.min(y.offsetHeight*5,V),te=window.getComputedStyle(m),ye=parseInt(te.paddingTop,10),G=parseInt(te.paddingBottom,10),Q=k.top+k.height/2-ir,J=$-Q,me=y.offsetHeight/2,z=y.offsetTop+me,Z=j+P+z,Me=V-Z;if(Z<=Q){const we=L.length>0&&y===L[L.length-1].ref.current;a.style.bottom="0px";const Se=c.clientHeight-m.offsetTop-m.offsetHeight,ze=Math.max(J,me+(we?G:0)+Se+H),ut=Z+ze;a.style.height=ut+"px"}else{const we=L.length>0&&y===L[0].ref.current;a.style.top="0px";const ze=Math.max(Q,j+m.offsetTop+(we?ye:0)+me)+Me;a.style.height=ze+"px",m.scrollTop=Z-Q+m.offsetTop}a.style.margin=`${ir}px 0`,a.style.minHeight=ie+"px",a.style.maxHeight=$+"px",r?.(),requestAnimationFrame(()=>h.current=!0)}},[f,s.trigger,s.valueNode,a,c,m,y,v,s.dir,r]);Nt(()=>E(),[E]);const[x,T]=b.useState();Nt(()=>{c&&T(window.getComputedStyle(c).zIndex)},[c]);const S=b.useCallback(k=>{k&&p.current===!0&&(E(),w?.(),p.current=!1)},[E,w]);return g.jsx(Yee,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:h,onScrollButtonChange:S,children:g.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:x},children:g.jsx(ge.div,{...o,ref:d,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});TN.displayName=qee;var Kee="SelectPopperPosition",og=b.forwardRef((t,e)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=ir,...s}=t,i=Hf(n);return g.jsx(af,{...i,...s,ref:e,align:r,collisionPadding:o,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});og.displayName=Kee;var[Yee,jv]=ia(qs,{}),sg="SelectViewport",CN=b.forwardRef((t,e)=>{const{__scopeSelect:n,nonce:r,...o}=t,s=hs(sg,n),i=jv(sg,n),a=Fe(e,s.onViewportChange),l=b.useRef(0);return g.jsxs(g.Fragment,{children:[g.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),g.jsx(Bf.Slot,{scope:n,children:g.jsx(ge.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ne(o.onScroll,c=>{const u=c.currentTarget,{contentWrapper:d,shouldExpandOnScrollRef:f}=i;if(f?.current&&d){const h=Math.abs(l.current-u.scrollTop);if(h>0){const p=window.innerHeight-ir*2,m=parseFloat(d.style.minHeight),y=parseFloat(d.style.height),v=Math.max(m,y);if(v<p){const w=v+h,E=Math.min(p,w),x=w-E;d.style.height=E+"px",d.style.bottom==="0px"&&(u.scrollTop=x>0?x:0,d.style.justifyContent="flex-end")}}}l.current=u.scrollTop})})})]})});CN.displayName=sg;var AN="SelectGroup",[Jee,Xee]=ia(AN),Qee=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,o=Kn();return g.jsx(Jee,{scope:n,id:o,children:g.jsx(ge.div,{role:"group","aria-labelledby":o,...r,ref:e})})});Qee.displayName=AN;var MN="SelectLabel",Zee=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,o=Xee(MN,n);return g.jsx(ge.div,{id:o.id,...r,ref:e})});Zee.displayName=MN;var Ad="SelectItem",[ete,ON]=ia(Ad),RN=b.forwardRef((t,e)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=t,a=fs(Ad,n),l=hs(Ad,n),c=a.value===r,[u,d]=b.useState(s??""),[f,h]=b.useState(!1),p=Fe(e,w=>l.itemRefCallback?.(w,r,o)),m=Kn(),y=b.useRef("touch"),v=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return g.jsx(ete,{scope:n,value:r,disabled:o,textId:m,isSelected:c,onItemTextChange:b.useCallback(w=>{d(E=>E||(w?.textContent??"").trim())},[]),children:g.jsx(Bf.ItemSlot,{scope:n,value:r,disabled:o,textValue:u,children:g.jsx(ge.div,{role:"option","aria-labelledby":m,"data-highlighted":f?"":void 0,"aria-selected":c&&f,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:p,onFocus:ne(i.onFocus,()=>h(!0)),onBlur:ne(i.onBlur,()=>h(!1)),onClick:ne(i.onClick,()=>{y.current!=="mouse"&&v()}),onPointerUp:ne(i.onPointerUp,()=>{y.current==="mouse"&&v()}),onPointerDown:ne(i.onPointerDown,w=>{y.current=w.pointerType}),onPointerMove:ne(i.onPointerMove,w=>{y.current=w.pointerType,o?l.onItemLeave?.():y.current==="mouse"&&w.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ne(i.onPointerLeave,w=>{w.currentTarget===document.activeElement&&l.onItemLeave?.()}),onKeyDown:ne(i.onKeyDown,w=>{l.searchRef?.current!==""&&w.key===" "||($ee.includes(w.key)&&v(),w.key===" "&&w.preventDefault())})})})})});RN.displayName=Ad;var Ca="SelectItemText",NN=b.forwardRef((t,e)=>{const{__scopeSelect:n,className:r,style:o,...s}=t,i=fs(Ca,n),a=hs(Ca,n),l=ON(Ca,n),c=Uee(Ca,n),[u,d]=b.useState(null),f=Fe(e,v=>d(v),l.onItemTextChange,v=>a.itemTextRefCallback?.(v,l.value,l.disabled)),h=u?.textContent,p=b.useMemo(()=>g.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:m,onNativeOptionRemove:y}=c;return Nt(()=>(m(p),()=>y(p)),[m,y,p]),g.jsxs(g.Fragment,{children:[g.jsx(ge.span,{id:l.textId,...s,ref:f}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Md.createPortal(s.children,i.valueNode):null]})});NN.displayName=Ca;var _N="SelectItemIndicator",DN=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t;return ON(_N,n).isSelected?g.jsx(ge.span,{"aria-hidden":!0,...r,ref:e}):null});DN.displayName=_N;var ig="SelectScrollUpButton",IN=b.forwardRef((t,e)=>{const n=hs(ig,t.__scopeSelect),r=jv(ig,t.__scopeSelect),[o,s]=b.useState(!1),i=Fe(e,r.onScrollButtonChange);return Nt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?g.jsx(LN,{...t,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});IN.displayName=ig;var ag="SelectScrollDownButton",PN=b.forwardRef((t,e)=>{const n=hs(ag,t.__scopeSelect),r=jv(ag,t.__scopeSelect),[o,s]=b.useState(!1),i=Fe(e,r.onScrollButtonChange);return Nt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,u=Math.ceil(l.scrollTop)<c;s(u)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?g.jsx(LN,{...t,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});PN.displayName=ag;var LN=b.forwardRef((t,e)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=t,s=hs("SelectScrollButton",n),i=b.useRef(null),a=Ff(n),l=b.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return b.useEffect(()=>()=>l(),[l]),Nt(()=>{a().find(u=>u.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:"nearest"})},[a]),g.jsx(ge.div,{"aria-hidden":!0,...o,ref:e,style:{flexShrink:0,...o.style},onPointerDown:ne(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ne(o.onPointerMove,()=>{s.onItemLeave?.(),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ne(o.onPointerLeave,()=>{l()})})}),tte="SelectSeparator",nte=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t;return g.jsx(ge.div,{"aria-hidden":!0,...r,ref:e})});nte.displayName=tte;var lg="SelectArrow",rte=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,o=Hf(n),s=fs(lg,n),i=hs(lg,n);return s.open&&i.position==="popper"?g.jsx(lf,{...o,...r,ref:e}):null});rte.displayName=lg;var ote="SelectBubbleInput",jN=b.forwardRef(({__scopeSelect:t,value:e,...n},r)=>{const o=b.useRef(null),s=Fe(r,o),i=EM(e);return b.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,u=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==e&&u){const d=new Event("change",{bubbles:!0});u.call(a,e),a.dispatchEvent(d)}},[i,e]),g.jsx(ge.select,{...n,style:{...tC,...n.style},ref:s,defaultValue:e})});jN.displayName=ote;function $N(t){return t===""||t===void 0}function BN(t){const e=pr(t),n=b.useRef(""),r=b.useRef(0),o=b.useCallback(i=>{const a=n.current+i;e(a),(function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))})(a)},[e]),s=b.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return b.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function FN(t,e,n){const o=e.length>1&&Array.from(e).every(c=>c===e[0])?e[0]:e,s=n?t.indexOf(n):-1;let i=ste(t,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function ste(t,e){return t.map((n,r)=>t[(e+r)%t.length])}var ite=mN,ate=yN,lte=bN,cte=xN,ute=wN,dte=EN,fte=CN,hte=RN,pte=NN,mte=DN,gte=IN,yte=PN;function vte({...t}){return g.jsx(ite,{"data-slot":"select",...t})}function bte({...t}){return g.jsx(lte,{"data-slot":"select-value",...t})}function xte({className:t,size:e="default",children:n,...r}){return g.jsxs(ate,{"data-slot":"select-trigger","data-size":e,className:re("border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",t),...r,children:[n,g.jsx(cte,{asChild:!0,children:g.jsx(zC,{className:"size-4 opacity-50"})})]})}function wte({className:t,children:e,position:n="popper",align:r="center",...o}){return g.jsx(ute,{children:g.jsx("div",{id:"select-wrapper","data-theme":"select-post-builder",children:g.jsxs(dte,{"data-slot":"select-content",className:re("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",t),position:n,align:r,...o,children:[g.jsx(Ste,{}),g.jsx(fte,{className:re("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:e}),g.jsx(kte,{})]})})})}function Ete({className:t,children:e,...n}){return g.jsxs(hte,{"data-slot":"select-item",className:re("focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",t),...n,children:[g.jsx("span",{className:"absolute right-2 flex size-3.5 items-center justify-center",children:g.jsx(mte,{children:g.jsx(UC,{className:"size-4"})})}),g.jsx(pte,{children:e})]})}function Ste({className:t,...e}){return g.jsx(gte,{"data-slot":"select-scroll-up-button",className:re("flex cursor-default items-center justify-center py-1",t),...e,children:g.jsx(uV,{className:"size-4"})})}function kte({className:t,...e}){return g.jsx(yte,{"data-slot":"select-scroll-down-button",className:re("flex cursor-default items-center justify-center py-1",t),...e,children:g.jsx(zC,{className:"size-4"})})}function Tte(){return kg.useSyncExternalStore(Cte,()=>!0,()=>!1)}function Cte(){return()=>{}}var $v="Avatar",[Ate]=Ln($v),[Mte,HN]=Ate($v),UN=b.forwardRef((t,e)=>{const{__scopeAvatar:n,...r}=t,[o,s]=b.useState("idle");return g.jsx(Mte,{scope:n,imageLoadingStatus:o,onImageLoadingStatusChange:s,children:g.jsx(ge.span,{...r,ref:e})})});UN.displayName=$v;var zN="AvatarImage",VN=b.forwardRef((t,e)=>{const{__scopeAvatar:n,src:r,onLoadingStatusChange:o=()=>{},...s}=t,i=HN(zN,n),a=Ote(r,s),l=pr(c=>{o(c),i.onImageLoadingStatusChange(c)});return Nt(()=>{a!=="idle"&&l(a)},[a,l]),a==="loaded"?g.jsx(ge.img,{...s,ref:e,src:r}):null});VN.displayName=zN;var WN="AvatarFallback",GN=b.forwardRef((t,e)=>{const{__scopeAvatar:n,delayMs:r,...o}=t,s=HN(WN,n),[i,a]=b.useState(r===void 0);return b.useEffect(()=>{if(r!==void 0){const l=window.setTimeout(()=>a(!0),r);return()=>window.clearTimeout(l)}},[r]),i&&s.imageLoadingStatus!=="loaded"?g.jsx(ge.span,{...o,ref:e}):null});GN.displayName=WN;function JE(t,e){return t?e?(t.src!==e&&(t.src=e),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function Ote(t,{referrerPolicy:e,crossOrigin:n}){const r=Tte(),o=b.useRef(null),s=r?(o.current||(o.current=new window.Image),o.current):null,[i,a]=b.useState(()=>JE(s,t));return Nt(()=>{a(JE(s,t))},[s,t]),Nt(()=>{const l=d=>()=>{a(d)};if(!s)return;const c=l("loaded"),u=l("error");return s.addEventListener("load",c),s.addEventListener("error",u),e&&(s.referrerPolicy=e),typeof n=="string"&&(s.crossOrigin=n),()=>{s.removeEventListener("load",c),s.removeEventListener("error",u)}},[s,n,e]),i}var Rte=UN,Nte=VN,_te=GN;function XE({className:t,...e}){return g.jsx(Rte,{"data-slot":"avatar",className:re("relative flex size-8 shrink-0 overflow-hidden rounded-full",t),...e})}function QE({className:t,...e}){return g.jsx(Nte,{"data-slot":"avatar-image",className:re("aspect-square size-full",t),...e})}function ZE({className:t,...e}){return g.jsx(_te,{"data-slot":"avatar-fallback",className:re("bg-muted flex size-full items-center justify-center rounded-full",t),...e})}const Dte=({user:t,store:e})=>{const{core:n}=Dl(),[r,o]=M.useState([]),[s,i]=M.useState(!1),a=ho(),[l,c]=M.useState(e.getState());M.useEffect(()=>e.subscribe(()=>{c(e.getState())}),[e]);const{groupId:u,selectedGroupId:d}=l,f=d??u??"",h=!!u;M.useEffect(()=>{let m=!1;return(async()=>{i(!0);try{const v=await n.fetchGroupConversations(999,0);m||o(v.entries??[])}catch(v){m||console.error("Failed to fetch groups:",v)}finally{m||i(!1)}})(),()=>{m=!0}},[n]);const p=m=>{e.getState().selectGroup(m)};return g.jsxs("div",{className:"not-prose flex items-center gap-3",children:[t?.id&&g.jsxs(XE,{children:[g.jsx(QE,{src:t?.avatar??t?.avatarPlaceholder}),g.jsx(ZE,{className:"bg-primary-send text-background",children:t?.name?.charAt(0)?.toUpperCase()})]}),g.jsxs(vte,{value:f,onValueChange:p,disabled:h||s,children:[g.jsx(xte,{size:"sm",id:`group-selector-${f}-${a}`,className:"bg-background","aria-label":"Select group",children:g.jsx(bte,{className:"text-sm",placeholder:s?"Loading groups...":"Select a group…"})}),g.jsx(wte,{align:"start",children:r.map(m=>g.jsxs(Ete,{value:m.group_id,children:[g.jsxs(XE,{className:"size-6",children:[g.jsx(QE,{src:m.group.avatar}),g.jsx(ZE,{children:m?.group?.name?.charAt(0)})]}),g.jsx("span",{className:"text-sm",children:m.group?.name??m.group_id})]},m.group_id))})]})]})};var Ite=(t,e,n,r,o,s,i,a)=>{let l=document.documentElement,c=["light","dark"];function u(h){(Array.isArray(t)?t:[t]).forEach(p=>{let m=p==="class",y=m&&s?o.map(v=>s[v]||v):o;m?(l.classList.remove(...y),l.classList.add(s&&s[h]?s[h]:h)):l.setAttribute(p,h)}),d(h)}function d(h){a&&c.includes(h)&&(l.style.colorScheme=h)}function f(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}if(r)u(r);else try{let h=localStorage.getItem(e)||n,p=i&&h==="system"?f():h;u(p)}catch{}},Pte=b.createContext(void 0),Lte={setTheme:t=>{},themes:[]},jte=()=>{var t;return(t=b.useContext(Pte))!=null?t:Lte};b.memo(({forcedTheme:t,storageKey:e,attribute:n,enableSystem:r,enableColorScheme:o,defaultTheme:s,value:i,themes:a,nonce:l,scriptProps:c})=>{let u=JSON.stringify([n,e,s,t,a,i,r,o]).slice(1,-1);return b.createElement("script",{...c,suppressHydrationWarning:!0,nonce:typeof window>"u"?l:"",dangerouslySetInnerHTML:{__html:`(${Ite.toString()})(${u})`}})});const $te=({...t})=>{const{theme:e="system"}=jte();return g.jsx(mI,{theme:e,className:"toaster group",style:{"--normal-bg":"var(--popover)","--normal-text":"var(--popover-foreground)","--normal-border":"var(--border)"},...t})},Uf=t=>({html:t?.getHTML(),json:t?.getJSON(),text:t?.getText()}),zf=()=>({postId:ho(),timestamp:new Date().getTime(),specialType:TS.POST}),Bv=t=>({mentionData:Kl(t,"mention")?.map(r=>q8(X8(r.attrs,B8),["mentionSuggestionChar","label"]))?.filter(r=>Object.keys(r).length>0)}),Bte=t=>({items:Kl(t,"media").map(r=>r.attrs?.payload)}),Fte=t=>({items:Kl(t,"poll")[0].attrs?.choices}),Hte=({editor:t,sendCrossMention:e})=>{const{html:n,json:r}=Uf(t),o=zf(),s=pw(r,"text")?.text?.trim()??"",i=new Array(pw(r,"media")?.attrs?.payload).filter(Boolean),a=n;return{...o,type:_l.NEW_POST_MESSAGE,body:s,items:i,htmlBody:a,sendCrossMention:e,mentionData:[]}},Ute=({editor:t,sendCrossMention:e})=>{const{json:n,text:r}=Uf(t),o=zf(),s=r,{mentionData:i}=Bv(n),{items:a}=Bte(n);return{...o,type:_l.NEW_POST_MEDIA,body:s,items:a,mentionData:i,sendCrossMention:e}},zte=({editor:t,sendCrossMention:e})=>{const{json:n,text:r}=Uf(t),o=zf(),s=r,{mentionData:i}=Bv(n);return{...o,type:_l.NEW_POST_MESSAGE,body:s,items:[],mentionData:i,sendCrossMention:e}},Vte=({editor:t,sendCrossMention:e})=>{const{json:n,text:r}=Uf(t),o=zf(),s=r,{mentionData:i}=Bv(n),{items:a}=Fte(n);return{...o,type:_l.NEW_POST_POLL,body:s,items:a,mentionData:i,sendCrossMention:e}},Wte=(t,e)=>{switch(t){case gt.Text:return Hte(e);case gt.Media:return Ute(e);case gt.Link:return zte(e);case gt.Poll:return Vte(e);default:return null}},Gte=({groupId:t,postId:e,user:n,hideGroupSelector:r=!1,showModal:o=!1,clearOnSuccess:s=!0,isSubmitting:i,onCreatePost:a})=>{const l=M.useRef(null),[c,u]=M.useState(()=>o),[d,f]=M.useState(gt.Text),{editor:h,actions:p,store:m}=cX({editorType:d,groupId:t,postId:e,user:n}),{clearContent:y}=ry(),v=M.useMemo(()=>({editor:h}),[h]),w=E=>{if(!h)return;const x=h?.getHTML(),T=h?.getJSON(),S=h?.getText(),k=Wte(d,{editor:h,sendCrossMention:E});k&&(a?.({payload:k,html:x,json:T,text:S}),s&&(y(),h?.chain()?.focus()?.clearContent()?.run()))};return M.useEffect(()=>{h&&h?.chain()?.focus()?.run()},[h]),M.useEffect(()=>u(o),[o]),h?g.jsxs("div",{className:"max-w-full w-full","data-theme":"select-post-builder",children:[g.jsx("div",{ref:l,className:"flex-1 space-y-3 max-w-full",children:g.jsxs(ty.Provider,{value:v,children:[!r&&g.jsx(Dte,{user:n,store:m}),o?g.jsx(Lee,{open:c,onOpenChange:u,editor:h,actions:p,editorTab:d,onSwitchEditor:f,isSubmitting:i,onSubmit:w}):g.jsx(pN,{editor:h,actions:p,editorTab:d,onSwitchEditor:f,isSubmitting:i,onSubmit:w})]})}),g.jsx($te,{position:"top-center"})]}):null};exports.PostBuilderEditor=Gte;exports.PostBuilderProvider=RI;