@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.
- package/dist/post-builder.cjs +1 -1
- package/dist/post-builder.js +10 -3
- package/dist/post-builder.umd.cjs +1 -1
- package/package.json +1 -1
|
@@ -583,4 +583,4 @@ Defaulting to \`null\`.`}var kq=MA,Tq=NA;function DA({className:t,value:e,...n})
|
|
|
583
583
|
* @author Kent C. Dodds <me@kentcdodds.com> (https://kentcdodds.com)
|
|
584
584
|
*/const dn={CASE_SENSITIVE_EQUAL:7,EQUAL:6,STARTS_WITH:5,WORD_STARTS_WITH:4,CONTAINS:3,ACRONYM:2,MATCHES:1,NO_MATCH:0},_Y=(t,e)=>String(t.rankedValue).localeCompare(String(e.rankedValue));function _y(t,e,n={}){const{keys:r,threshold:o=dn.MATCHES,baseSort:s=_Y,sorter:i=c=>c.sort((u,d)=>LY(u,d,s))}=n,a=t.reduce(l,[]);return i(a).map(({item:c})=>c);function l(c,u,d){const f=RY(u,r,e,n),{rank:h,keyThreshold:p=o}=f;return h>=p&&c.push({...f,item:u,index:d}),c}}_y.rankings=dn;function RY(t,e,n,r){if(!e){const s=t;return{rankedValue:s,rank:dO(s,n,r),keyIndex:-1,keyThreshold:r.threshold}}return BY(t,e).reduce(({rank:s,rankedValue:i,keyIndex:a,keyThreshold:l},{itemValue:c,attributes:u},d)=>{let f=dO(c,n,r),h=i;const{minRanking:p,maxRanking:m,threshold:y}=u;return f<p&&f>=dn.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:dn.NO_MATCH,keyIndex:-1,keyThreshold:r.threshold})}function*IY(t,e){let n=-1;for(;(n=t.indexOf(e,n+1))>-1;)yield n;return-1}function dO(t,e,n){if(t=fO(t,n),e=fO(e,n),e.length>t.length)return dn.NO_MATCH;if(t===e)return dn.CASE_SENSITIVE_EQUAL;t=t.toLowerCase(),e=e.toLowerCase();const r=IY(t,e),o=r.next(),s=o.value;if(t.length===e.length&&s===0)return dn.EQUAL;if(s===0)return dn.STARTS_WITH;let i=o;for(;!i.done;){if(i.value>0&&t[i.value-1]===" ")return dn.WORD_STARTS_WITH;i=r.next()}return s>0?dn.CONTAINS:e.length===1?dn.NO_MATCH:DY(t).includes(e)?dn.ACRONYM:PY(t,e)}function DY(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 PY(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 dn.MATCHES+u*c}const i=o(e[0],t,0);if(i<0)return dn.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 dn.NO_MATCH}const a=r-i;return s(a)}function LY(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 fO(t,{keepDiacritics:e}){return t=`${t}`,e||(t=NY(t)),t}function jY(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 $Y(e,t);n=null}return n==null?[]:Array.isArray(n)?n:[String(n)]}function $Y(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 BY(t,e){const n=[];for(let r=0,o=e.length;r<o;r++){const s=e[r],i=FY(s),a=jY(t,s);for(let l=0,c=a.length;l<c;l++)n.push({itemValue:a[l],attributes:i})}return n}const hO={maxRanking:1/0,minRanking:-1/0};function FY(t){return typeof t=="string"?hO:{...hO,...t}}const pO=M.forwardRef((t,e)=>{const[n,r]=M.useState(0),o=M.useRef([]),s=M.useMemo(()=>t.query?_y(t.items,t.query,{keys:["label","email"],threshold:_y.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"})]})]})})]})});pO.displayName="MentionList";const HY=()=>typeof window<"u"&&window.ReactNativeWebView!==void 0,UY=(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:nh.User,from:gc.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:nh.Group,from:gc.Post,isCrossExposureEnable:c?.group?.allow_cross_exposure})):(console.warn("DEBUG HASHTAG SERVICE::","No active group selected or provided"),[])}});function mO(t,e){return{char:t,items:async()=>await e(),render:()=>{let n,r;return{onStart:o=>{n=new Zp(pO,{props:{...o,char:t},editor:o.editor}),o.clientRect&&(r=Bl("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 zY=(t,e,n)=>{const r=UY(t,e,n);return AY.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=HY(),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:[mO("@",r.fetchMentions),mO("#",r.fetchHashtags)]})};function VY({className:t,...e}){return g.jsx("div",{"data-slot":"skeleton",className:re("bg-accent animate-pulse rounded-md",t),...e})}const WY=({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(xe,{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(Qa,{})]})}),g.jsx(xe,{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(Pm,{})})]}),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(Qa,{className:"h-3 w-3 flex-shrink-0 opacity-50"})]})]})]})})]})},GY=({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(xe,{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(Qa,{})]})}),g.jsx(xe,{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(Pm,{})})]}),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(Qa,{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})]})]})})]})},qY=({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(Vo,{children:g.jsx(VY,{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(Vo,{contentEditable:!1,"data-drag-handle":!0,children:i===yc.Compact?g.jsx(WY,{...t.attrs,selected:n,domain:a,onClickDelete:e}):g.jsx(GY,{...t.attrs,selected:n,domain:a,onClickDelete:e})}):null},gO=Mt.create({name:"linkPreview",group:"block",atom:!0,addOptions(){return{variant:yc.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 za(qY)},addCommands(){return{setLinkPreview:t=>({commands:e})=>e.insertContent({type:this.name,attrs:t}),updateLinkPreviewByUid:$A(this.name),deleteLinkPreviewByUid:jA(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}}}}),Ry=Je.create({name:"customEnterHardBreak",addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.setHardBreak()}}}),KY=({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(Vo,{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(iS,{})})]}):g.jsx(Vo,{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(Vn,{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(Za,{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===be.Image&&g.jsx(_m,{className:"w-8 h-8 text-muted-foreground/50 mx-auto"}),o.attrs.type===be.Video&&g.jsx(jm,{className:"w-8 h-8 text-muted-foreground/50 mx-auto"}),o.attrs.type===be.Audio&&g.jsx(Wu,{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(DA,{value:a,className:"h-1"})})]}):g.jsxs(g.Fragment,{children:[o.attrs.type===be.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===be.Video&&g.jsx("video",{src:o.attrs.src,className:"size-20 object-cover rounded-lg border border-border"}),o.attrs.type===be.Audio&&g.jsx("div",{className:"size-20 flex items-center justify-center bg-accent rounded-lg border border-border",children:g.jsx(Wu,{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(iS,{})})]})})},YY=new ze("mediaMode"),JY=()=>{let t=!1;return new He({key:YY,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}}})},XY=Mt.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 za(KY)},addProseMirrorPlugins(){return this.options.mediaMode?[JY()]:[]}}),QY={class:"bg-muted text-foreground border border-border font-mono leading-snug rounded px-0.5 py-px after:content-none before:content-none"},ZY={class:"bg-muted text-foreground border border-border font-mono leading-snug rounded"},Iy=t=>GG.extend({content:t}),eJ=Iy("paragraph poll"),tJ=Iy("paragraph media? mediaGroup?"),nJ=Iy("paragraph linkPreview?"),rJ=({includeLink:t=!1,includeDocument:e=!0})=>({...e?{}:{document:!1},...t?{}:{link:!1},code:{HTMLAttributes:QY},codeBlock:{HTMLAttributes:ZY}}),rf=t=>iq.configure({placeholder:t,showOnlyWhenEditable:!0}),of=(t,e,n)=>zY(t,e,n),oJ=({editorType:t,api:e,store:n,user:r})=>{const s={[ht.Text]:sJ,[ht.Media]:aJ,[ht.Link]:lJ,[ht.Poll]:iJ}[t];return s?s({api:e,store:n,user:r}):[]},sJ=({api:t,store:e,user:n})=>{const{core:r,mfs:o,fileStore:s}=t;return[uq.configure(rJ({includeLink:!1})),rf(`What's on your mind, ${n?.name?n?.name:""}`),pq,gq,fq.configure({types:["heading","paragraph","media"],alignments:[Ze.LEFT,Ze.CENTER,Ze.RIGHT],defaultAlignment:Ze.LEFT}),BA,zA,LK,eM.configure({openOnClick:!1,linkOnPaste:!1,api:r}),gO,of(r,o,e),wM.configure({api:s}),bM.configure({api:r})]},iJ=({api:t,store:e})=>{const{core:n,mfs:r}=t;return[eJ,Yg,Jg,Wg,wg,rf("Ask a Question"),Ry,zA,of(n,r,e)]},aJ=({api:t,store:e,user:n})=>{const{core:r,mfs:o,fileStore:s}=t;return[tJ,Yg,Jg,Wg,wg,rf(`What's on your mind, ${n?.name?n?.name:""}`),Ry,BA.configure({attrs:{mediaMode:!0}}),XY.configure({mediaMode:!0}),of(r,o,e),wM.configure({api:s})]},lJ=({api:t,store:e,user:n})=>{const{core:r,mfs:o}=t;return[nJ,Yg,Jg,wg,rf(`What's on your mind, ${n?.name?n?.name:""}`),Ry,eM.configure({openOnClick:!1,linkOnPaste:!1,api:r,linkMode:!0}),gO.configure({variant:yc.Extended,selectable:!1,draggable:!1}),bM.configure({api:r,autoEmbed:!1,autoLinkSelection:!1}),of(r,o,e)]},cJ=()=>({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")}}),uJ=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()}}),dJ=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()},fJ=({editorType:t,groupId:e,postId:n,user:r})=>{const[,o]=M.useState(0),s=ga(),i=M.useMemo(()=>RG({groupId:e,postId:n}),[e,n]),{getTabContent:a}=em();M.useEffect(()=>{o(u=>u+1)},[]);const l=MF({extensions:oJ({editorType:t,api:s,store:i,user:r}),content:"",editorProps:cJ(),onCreate:({editor:u})=>{i.getState().setEditor(u),t===ht.Poll&&dJ(u)},immediatelyRender:!1},[t]);M.useEffect(()=>{const u=a(t);u&&l?.isEditable&&l.commands.setContent(u)},[l,t,a]);const c=uJ(l);return{editor:l,actions:c,store:i}},gr=()=>new Map,Dy=t=>{const e=gr();return t.forEach((n,r)=>{e.set(r,n)}),e},bo=(t,e,n)=>{let r=t.get(e);return r===void 0&&t.set(e,r=n()),r},hJ=(t,e)=>{const n=[];for(const[r,o]of t)n.push(e(o,r));return n},pJ=(t,e)=>{for(const[n,r]of t)if(e(r,n))return!0;return!1},qs=()=>new Set,Py=t=>t[t.length-1],mJ=(t,e)=>{for(let n=0;n<e.length;n++)t.push(e[n])},Ks=Array.from,gJ=(t,e)=>{for(let n=0;n<t.length;n++)if(e(t[n],n,t))return!0;return!1},Ly=Array.isArray;class yO{constructor(){this._observers=gr()}on(e,n){return bo(this._observers,e,qs).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 Ks((this._observers.get(e)||gr()).values()).forEach(r=>r(...n))}destroy(){this._observers=gr()}}const xo=Math.floor,sf=Math.abs,Ki=(t,e)=>t<e?t:e,is=(t,e)=>t>e?t:e,vO=t=>t!==0?t<0:1/t<0,bO=1,xO=2,jy=4,$y=8,Hl=32,wo=64,fn=128,yJ=1<<29,af=31,By=63,Ys=127,vJ=2147483647,wO=Number.MAX_SAFE_INTEGER,bJ=Number.isInteger||(t=>typeof t=="number"&&isFinite(t)&&xo(t)===t),xJ=String.fromCharCode,wJ=t=>t.toLowerCase(),EJ=/^\s*/g,SJ=t=>t.replace(EJ,""),kJ=/([A-Z])/g,EO=(t,e)=>SJ(t.replace(kJ,n=>`${e}${wJ(n)}`)),TJ=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},Ul=typeof TextEncoder<"u"?new TextEncoder:null,CJ=Ul?t=>Ul.encode(t):TJ;let zl=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});zl&&zl.decode(new Uint8Array).length===1&&(zl=null);class Vl{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Wl=()=>new Vl,AJ=t=>{const e=Wl();return t(e),yr(e)},MJ=t=>{let e=t.cpos;for(let n=0;n<t.bufs.length;n++)e+=t.bufs[n].length;return e},yr=t=>{const e=new Uint8Array(MJ(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},OJ=(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(is(n,e)*2),t.cpos=0)},jt=(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},Fy=jt,Fe=(t,e)=>{for(;e>Ys;)jt(t,fn|Ys&e),e=xo(e/128);jt(t,Ys&e)},Hy=(t,e)=>{const n=vO(e);for(n&&(e=-e),jt(t,(e>By?fn:0)|(n?wo:0)|By&e),e=xo(e/64);e>0;)jt(t,(e>Ys?fn:0)|Ys&e),e=xo(e/128)},Uy=new Uint8Array(3e4),NJ=Uy.length/3,_J=(t,e)=>{if(e.length<NJ){const n=Ul.encodeInto(e,Uy).written||0;Fe(t,n);for(let r=0;r<n;r++)jt(t,Uy[r])}else jn(t,CJ(e))},RJ=(t,e)=>{const n=unescape(encodeURIComponent(e)),r=n.length;Fe(t,r);for(let o=0;o<r;o++)jt(t,n.codePointAt(o))},Yi=Ul&&Ul.encodeInto?_J:RJ,lf=(t,e)=>{const n=t.cbuf.length,r=t.cpos,o=Ki(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(is(n*2,s)),t.cbuf.set(e.subarray(o)),t.cpos=s)},jn=(t,e)=>{Fe(t,e.byteLength),lf(t,e)},zy=(t,e)=>{OJ(t,e);const n=new DataView(t.cbuf.buffer,t.cpos,e);return t.cpos+=e,n},IJ=(t,e)=>zy(t,4).setFloat32(0,e,!1),DJ=(t,e)=>zy(t,8).setFloat64(0,e,!1),PJ=(t,e)=>zy(t,8).setBigInt64(0,e,!1),SO=new DataView(new ArrayBuffer(4)),LJ=t=>(SO.setFloat32(0,t),SO.getFloat32(0)===t),Ji=(t,e)=>{switch(typeof e){case"string":jt(t,119),Yi(t,e);break;case"number":bJ(e)&&sf(e)<=vJ?(jt(t,125),Hy(t,e)):LJ(e)?(jt(t,124),IJ(t,e)):(jt(t,123),DJ(t,e));break;case"bigint":jt(t,122),PJ(t,e);break;case"object":if(e===null)jt(t,126);else if(Ly(e)){jt(t,117),Fe(t,e.length);for(let n=0;n<e.length;n++)Ji(t,e[n])}else if(e instanceof Uint8Array)jt(t,116),jn(t,e);else{jt(t,118);const n=Object.keys(e);Fe(t,n.length);for(let r=0;r<n.length;r++){const o=n[r];Yi(t,o),Ji(t,e[o])}}break;case"boolean":jt(t,e?120:121);break;default:jt(t,127)}};class kO extends Vl{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&Fe(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const TO=t=>{t.count>0&&(Hy(t.encoder,t.count===1?t.s:-t.s),t.count>1&&Fe(t.encoder,t.count-2))};class cf{constructor(){this.encoder=new Vl,this.s=0,this.count=0}write(e){this.s===e?this.count++:(TO(this),this.count=1,this.s=e)}toUint8Array(){return TO(this),yr(this.encoder)}}const CO=t=>{if(t.count>0){const e=t.diff*2+(t.count===1?0:1);Hy(t.encoder,e),t.count>1&&Fe(t.encoder,t.count-2)}};class Vy{constructor(){this.encoder=new Vl,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(CO(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return CO(this),yr(this.encoder)}}class jJ{constructor(){this.sarr=[],this.s="",this.lensE=new cf}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 Vl;return this.sarr.push(this.s),this.s="",Yi(e,this.sarr.join("")),lf(e,this.lensE.toUint8Array()),yr(e)}}const as=t=>new Error(t),vr=()=>{throw as("Method unimplemented")},kn=()=>{throw as("Unexpected case")},AO=as("Unexpected end of array"),MO=as("Integer out of Range");class uf{constructor(e){this.arr=e,this.pos=0}}const Wy=t=>new uf(t),$J=t=>t.pos!==t.arr.length,BJ=(t,e)=>{const n=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,n},Zn=t=>BJ(t,st(t)),Gl=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&Ys)*n,n*=128,o<fn)return e;if(e>wO)throw MO}throw AO},Gy=t=>{let e=t.arr[t.pos++],n=e&By,r=64;const o=(e&wo)>0?-1:1;if((e&fn)===0)return o*n;const s=t.arr.length;for(;t.pos<s;){if(e=t.arr[t.pos++],n=n+(e&Ys)*r,r*=128,e<fn)return o*n;if(n>wO)throw MO}throw AO},qy=zl?t=>zl.decode(Zn(t)):t=>{let e=st(t);if(e===0)return"";{let n=String.fromCodePoint(Gl(t));if(--e<100)for(;e--;)n+=String.fromCodePoint(Gl(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))}},Ky=(t,e)=>{const n=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,e);return t.pos+=e,n},FJ=[t=>{},t=>null,Gy,t=>Ky(t,4).getFloat32(0,!1),t=>Ky(t,8).getFloat64(0,!1),t=>Ky(t,8).getBigInt64(0,!1),t=>!1,t=>!0,qy,t=>{const e=st(t),n={};for(let r=0;r<e;r++){const o=qy(t);n[o]=df(t)}return n},t=>{const e=st(t),n=[];for(let r=0;r<e;r++)n.push(df(t));return n},Zn],df=t=>FJ[127-Gl(t)](t);class OO extends uf{constructor(e,n){super(e),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),$J(this)?this.count=st(this)+1:this.count=-1),this.count--,this.s}}class ff extends uf{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=Gy(this);const e=vO(this.s);this.count=1,e&&(this.s=-this.s,this.count=st(this)+2)}return this.count--,this.s}}class Yy extends uf{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const e=Gy(this),n=e&1;this.diff=xo(e/2),this.count=1,n&&(this.count=st(this)+2)}return this.s+=this.diff,this.count--,this.s}}class HJ{constructor(e){this.decoder=new ff(e),this.str=qy(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 UJ=crypto.getRandomValues.bind(crypto),zJ=Math.random,NO=()=>UJ(new Uint32Array(1))[0],VJ=t=>t[xo(zJ()*t.length)],WJ="10000000-1000-4000-8000"+-1e11,GJ=()=>WJ.replace(/[018]/g,t=>(t^NO()&15>>t/4).toString(16)),qJ=Date.now,_O=t=>new Promise(t);Promise.all.bind(Promise);const RO=t=>t===void 0?null:t;class KJ{constructor(){this.map=new Map}setItem(e,n){this.map.set(e,n)}getItem(e){return this.map.get(e)}}let IO=new KJ,YJ=!0;try{typeof localStorage<"u"&&localStorage&&(IO=localStorage,YJ=!1)}catch{}const JJ=IO,XJ=Object.assign,DO=Object.keys,QJ=(t,e)=>{for(const n in t)e(t[n],n)},PO=t=>DO(t).length,ZJ=t=>{for(const e in t)return!1;return!0},LO=(t,e)=>{for(const n in t)if(!e(t[n],n))return!1;return!0},eX=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),tX=(t,e)=>t===e||PO(t)===PO(e)&&LO(t,(n,r)=>(n!==void 0||eX(e,r))&&e[r]===n),nX=Object.freeze,jO=t=>{for(const e in t){const n=t[e];(typeof n=="object"||typeof n=="function")&&jO(t[e])}return nX(t)},Jy=(t,e,n=0)=>{try{for(;n<t.length;n++)t[n](...e)}finally{n<t.length&&Jy(t,e,n+1)}},rX=(t,e)=>e.includes(t),Xi=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",$O=typeof window<"u"&&typeof document<"u"&&!Xi;let zr;const oX=()=>{if(zr===void 0)if(Xi){zr=gr();const t=process.argv;let e=null;for(let n=0;n<t.length;n++){const r=t[n];r[0]==="-"?(e!==null&&zr.set(e,""),e=r):e!==null&&(zr.set(e,r),e=null)}e!==null&&zr.set(e,"")}else typeof location=="object"?(zr=gr(),(location.search||"?").slice(1).split("&").forEach(t=>{if(t.length!==0){const[e,n]=t.split("=");zr.set(`--${EO(e,"-")}`,n),zr.set(`-${EO(e,"-")}`,n)}})):zr=gr();return zr},Xy=t=>oX().has(t),hf=t=>RO(Xi?process.env[t.toUpperCase().replaceAll("-","_")]:JJ.getItem(t)),BO=t=>Xy("--"+t)||hf(t)!==null;BO("production");const sX=Xi&&rX(process.env.FORCE_COLOR,["true","1","2"])||!Xy("--no-colors")&&!BO("no-color")&&(!Xi||process.stdout.isTTY)&&(!Xi||Xy("--color")||hf("COLORTERM")!==null||(hf("TERM")||"").includes("color")),iX=$O?t=>{let e="";for(let n=0;n<t.byteLength;n++)e+=xJ(t[n]);return btoa(e)}:t=>Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("base64"),aX=t=>AJ(e=>Ji(e,t));class lX{constructor(e,n){this.left=e,this.right=n}}const Eo=(t,e)=>new lX(t,e),cX=typeof document<"u"?document:{};typeof DOMParser<"u"&&new DOMParser;const uX=t=>hJ(t,(e,n)=>`${n}:${e};`).join(""),dX=(t=>class{constructor(n){this._=n}destroy(){t(this._)}})(clearTimeout),FO=(t,e)=>new dX(setTimeout(e,t)),So=Symbol,HO=So(),UO=So(),fX=So(),hX=So(),pX=So(),zO=So(),mX=So(),Qy=So(),gX=So(),yX=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},vX={[HO]:Eo("font-weight","bold"),[UO]:Eo("font-weight","normal"),[fX]:Eo("color","blue"),[pX]:Eo("color","green"),[hX]:Eo("color","grey"),[zO]:Eo("color","red"),[mX]:Eo("color","purple"),[Qy]:Eo("color","orange"),[gX]:Eo("color","black")},VO=sX?t=>{t.length===1&&t[0]?.constructor===Function&&(t=t[0]());const e=[],n=[],r=gr();let o=[],s=0;for(;s<t.length;s++){const i=t[s],a=vX[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=uX(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}:yX,bX=(...t)=>{console.log(...VO(t)),GO.forEach(e=>e.print(t))},WO=(...t)=>{console.warn(...VO(t)),t.unshift(Qy),GO.forEach(e=>e.print(t))},GO=qs(),qO=t=>({[Symbol.iterator](){return this},next:t}),xX=(t,e)=>qO(()=>{let n;do n=t.next();while(!n.done&&!e(n.value));return n}),Zy=(t,e)=>qO(()=>{const{done:n,value:r}=t.next();return{done:n,value:n?void 0:e(r)}});class ev{constructor(e,n){this.clock=e,this.len=n}}class Qi{constructor(){this.clients=new Map}}const ls=(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])iN(t,s,c.clock,c.len,n)}}),wX=(t,e)=>{let n=0,r=t.length-1;for(;n<=r;){const o=xo((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},Zi=(t,e)=>{const n=t.clients.get(e.client);return n!==void 0&&wX(n,e.clock)!==null},tv=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=is(o.len,s.clock+s.len-o.clock):(r<n&&(e[r]=s),r++)}e.length=r})},nv=t=>{const e=new Qi;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++)mJ(s,t[i].clients.get(o)||[]);e.clients.set(o,s)}});return tv(e),e},ql=(t,e,n,r)=>{bo(t.clients,e,()=>[]).push(new ev(n,r))},KO=()=>new Qi,EX=t=>{const e=KO();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 ev(a,l))}}o.length>0&&e.clients.set(r,o)}),e},rv=(t,e)=>{Fe(t.restEncoder,e.clients.size),Ks(e.clients.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{t.resetDsCurVal(),Fe(t.restEncoder,n);const o=r.length;Fe(t.restEncoder,o);for(let s=0;s<o;s++){const i=r[s];t.writeDsClock(i.clock),t.writeDsLen(i.len)}})},SX=t=>{const e=new Qi,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=bo(e.clients,o,()=>[]);for(let a=0;a<s;a++)i.push(new ev(t.readDsClock(),t.readDsLen()))}}return e},YO=(t,e,n)=>{const r=new Qi,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=bt(n,i);for(let u=0;u<a;u++){const d=t.readDsClock(),f=d+t.readDsLen();if(d<c){c<f&&ql(r,i,c,f-c);let h=br(l,d),p=l[h];for(!p.deleted&&p.id.clock<d&&(l.splice(h+1,0,Nf(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,Nf(e,p,f-p.id.clock)),p.delete(e))}else ql(r,i,d,f-d)}}if(r.clients.size>0){const s=new mf;return Fe(s.restEncoder,0),rv(s,r),s.toUint8Array()}return null},JO=NO;class Js extends yO{constructor({guid:e=GJ(),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=JO(),this.guid=e,this.collectionid=n,this.share=new Map,this.store=new rN,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=_O(c=>{this.on("load",()=>{this.isLoaded=!0,c(this)})});const l=()=>_O(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&&Xe(e.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Ks(this.subdocs).map(e=>e.guid))}transact(e,n=null){return Xe(this,e,n)}get(e,n=$t){const r=bo(this.share,e,()=>{const s=new n;return s._integrate(this,null),s}),o=r.constructor;if(n!==$t&&o!==n)if(o===$t){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,na)}getText(e=""){return this.get(e,us)}getMap(e=""){return this.get(e,ra)}getXmlElement(e=""){return this.get(e,en)}getXmlFragment(e=""){return this.get(e,Qs)}toJSON(){const e={};return this.share.forEach((n,r)=>{e[r]=n.toJSON()}),e}destroy(){this.isDestroyed=!0,Ks(this.subdocs).forEach(n=>n.destroy());const e=this._item;if(e!==null){this._item=null;const n=e.content;n.doc=new Js({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=e,Xe(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 kX{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 pf extends kX{constructor(e){super(e),this.keys=[],st(e),this.keyClockDecoder=new Yy(Zn(e)),this.clientDecoder=new ff(Zn(e)),this.leftClockDecoder=new Yy(Zn(e)),this.rightClockDecoder=new Yy(Zn(e)),this.infoDecoder=new OO(Zn(e),Gl),this.stringDecoder=new HJ(Zn(e)),this.parentInfoDecoder=new OO(Zn(e),Gl),this.typeRefDecoder=new ff(Zn(e)),this.lenDecoder=new ff(Zn(e))}readLeftID(){return new ea(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new ea(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 df(this.restDecoder)}readBuf(){return Zn(this.restDecoder)}readJSON(){return df(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 TX{constructor(){this.restEncoder=Wl()}toUint8Array(){return yr(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){Fe(this.restEncoder,e)}writeDsLen(e){Fe(this.restEncoder,e)}}class CX extends TX{writeLeftID(e){Fe(this.restEncoder,e.client),Fe(this.restEncoder,e.clock)}writeRightID(e){Fe(this.restEncoder,e.client),Fe(this.restEncoder,e.clock)}writeClient(e){Fe(this.restEncoder,e)}writeInfo(e){Fy(this.restEncoder,e)}writeString(e){Yi(this.restEncoder,e)}writeParentInfo(e){Fe(this.restEncoder,e?1:0)}writeTypeRef(e){Fe(this.restEncoder,e)}writeLen(e){Fe(this.restEncoder,e)}writeAny(e){Ji(this.restEncoder,e)}writeBuf(e){jn(this.restEncoder,e)}writeJSON(e){Yi(this.restEncoder,JSON.stringify(e))}writeKey(e){Yi(this.restEncoder,e)}}class AX{constructor(){this.restEncoder=Wl(),this.dsCurrVal=0}toUint8Array(){return yr(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const n=e-this.dsCurrVal;this.dsCurrVal=e,Fe(this.restEncoder,n)}writeDsLen(e){e===0&&kn(),Fe(this.restEncoder,e-1),this.dsCurrVal+=e}}class mf extends AX{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Vy,this.clientEncoder=new cf,this.leftClockEncoder=new Vy,this.rightClockEncoder=new Vy,this.infoEncoder=new kO(Fy),this.stringEncoder=new jJ,this.parentInfoEncoder=new kO(Fy),this.typeRefEncoder=new cf,this.lenEncoder=new cf}toUint8Array(){const e=Wl();return Fe(e,0),jn(e,this.keyClockEncoder.toUint8Array()),jn(e,this.clientEncoder.toUint8Array()),jn(e,this.leftClockEncoder.toUint8Array()),jn(e,this.rightClockEncoder.toUint8Array()),jn(e,yr(this.infoEncoder)),jn(e,this.stringEncoder.toUint8Array()),jn(e,yr(this.parentInfoEncoder)),jn(e,this.typeRefEncoder.toUint8Array()),jn(e,this.lenEncoder.toUint8Array()),lf(e,yr(this.restEncoder)),yr(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){Ji(this.restEncoder,e)}writeBuf(e){jn(this.restEncoder,e)}writeJSON(e){Ji(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 MX=(t,e,n,r)=>{r=is(r,e[0].id.clock);const o=br(e,r);Fe(t.restEncoder,e.length-o),t.writeClient(n),Fe(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)},XO=(t,e,n)=>{const r=new Map;n.forEach((o,s)=>{bt(e,s)>o&&r.set(s,o)}),bf(e).forEach((o,s)=>{n.has(s)||r.set(s,0)}),Fe(t.restEncoder,r.size),Ks(r.entries()).sort((o,s)=>s[0]-o[0]).forEach(([o,s])=>{MX(t,e.clients.get(o),o,s)})},OX=(t,e)=>{const n=gr(),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(af&u){case 0:{const d=t.readLen();i[c]=new er(Ie(a,l),d),l+=d;break}case 10:{const d=st(t.restDecoder);i[c]=new Er(Ie(a,l),d),l+=d;break}default:{const d=(u&(wo|fn))===0,f=new nt(Ie(a,l),null,(u&fn)===fn?t.readLeftID():null,null,(u&wo)===wo?t.readRightID():null,d?t.readParentInfo()?e.get(t.readString()):t.readLeftID():null,d&&(u&Hl)===Hl?t.readString():null,$N(t,u));i[c]=f,l+=f.length}}}}return n},NX=(t,e,n)=>{const r=[];let o=Ks(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 rN,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!==Er){const p=bo(d,u.id.client,()=>bt(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,bt(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 mf;return XO(h,a,new Map),Fe(h.restEncoder,0),{missing:l,update:h.toUint8Array()}}return null},_X=(t,e)=>XO(t,e.doc.store,e.beforeState),RX=(t,e,n,r=new pf(t))=>Xe(e,o=>{o.local=!1;let s=!1;const i=o.doc,a=i.store,l=OX(r,i),c=NX(o,a,l),u=a.pendingStructs;if(u){for(const[f,h]of u.missing)if(h<bt(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=hN([u.update,c.update])}}else a.pendingStructs=c;const d=YO(r,o,a);if(a.pendingDs){const f=new pf(Wy(a.pendingDs));st(f.restDecoder);const h=YO(f,o,a);d&&h?a.pendingDs=hN([d,h]):a.pendingDs=d||h}else a.pendingDs=d;if(s){const f=a.pendingStructs.update;a.pendingStructs=null,ov(o.doc,f)}},n,!1),ov=(t,e,n,r=pf)=>{const o=Wy(e);RX(o,t,n,new r(o))};class IX{constructor(){this.l=[]}}const QO=()=>new IX,ZO=(t,e)=>t.l.push(e),eN=(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.")},tN=(t,e,n)=>Jy(t.l,[e,n]);class ea{constructor(e,n){this.client=e,this.clock=n}}const gf=(t,e)=>t===e||t!==null&&e!==null&&t.client===e.client&&t.clock===e.clock,Ie=(t,e)=>new ea(t,e),Kl=t=>{for(const[e,n]of t.doc.share.entries())if(n===t)return e;throw kn()},Yl=(t,e)=>{for(;e!==null;){if(e.parent===t)return!0;e=e.parent._item}return!1};class yf{constructor(e,n,r,o=0){this.type=e,this.tname=n,this.item=r,this.assoc=o}}class DX{constructor(e,n,r=0){this.type=e,this.index=n,this.assoc=r}}const PX=(t,e,n=0)=>new DX(t,e,n),vf=(t,e,n)=>{let r=null,o=null;return t._item===null?o=Kl(t):r=Ie(t._item.id.client,t._item.id.clock),new yf(r,o,e,n)},sv=(t,e,n=0)=>{let r=t._start;if(n<0){if(e===0)return vf(t,null,n);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return vf(t,Ie(r.id.client,r.id.clock+e),n);e-=r.length}if(r.right===null&&n<0)return vf(t,r.lastId,n);r=r.right}return vf(t,null,n)},LX=(t,e)=>{const n=ta(t,e),r=e.clock-n.id.clock;return{item:n,diff:r}},jX=(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(bt(r,o.client)<=o.clock)return null;const u=n?yv(r,o):LX(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(bt(r,s.client)<=s.clock)return null;const{item:u}=n?yv(r,s):{item:ta(r,s)};if(u instanceof nt&&u.content instanceof wr)l=u.content.type;else return null}else throw kn();a>=0?c=l._length:c=0}return PX(l,c,t.assoc)};class iv{constructor(e,n){this.ds=e,this.sv=n}}const nN=(t,e)=>new iv(t,e),av=t=>nN(EX(t.store),bf(t.store)),Xs=(t,e)=>e===void 0?!t.deleted:e.sv.has(t.id.client)&&(e.sv.get(t.id.client)||0)>t.id.clock&&!Zi(e.ds,t.id),lv=(t,e)=>{const n=bo(t.meta,lv,qs),r=t.doc.store;n.has(e)||(e.sv.forEach((o,s)=>{o<bt(r,s)&&Tn(t,Ie(s,o))}),ls(t,e.ds,o=>{}),n.add(e))};class rN{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const bf=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},bt=(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},oN=(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 kn()}n.push(e)},br=(t,e)=>{let n=0,r=t.length-1,o=t[r],s=o.id.clock;if(s===e)return r;let i=xo(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=xo((n+r)/2)}throw kn()},ta=(t,e)=>{const n=t.clients.get(e.client);return n[br(n,e.clock)]},cv=(t,e,n)=>{const r=br(e,n),o=e[r];return o.id.clock<n&&o instanceof nt?(e.splice(r+1,0,Nf(t,o,n-o.id.clock)),r+1):r},Tn=(t,e)=>{const n=t.doc.store.clients.get(e.client);return n[cv(t,n,e.clock)]},sN=(t,e,n)=>{const r=e.clients.get(n.client),o=br(r,n.clock),s=r[o];return n.clock!==s.id.clock+s.length-1&&s.constructor!==er&&r.splice(o+1,0,Nf(t,s,n.clock-s.id.clock+1)),s},$X=(t,e,n)=>{const r=t.clients.get(e.id.client);r[br(r,e.id.clock)]=n},iN=(t,e,n,r,o)=>{if(r===0)return;const s=n+r;let i=cv(t,e,n),a;do a=e[i++],s<a.id.clock+a.length&&cv(t,e,s),o(a);while(i<e.length&&e[i].id.clock<s)};class BX{constructor(e,n,r){this.doc=e,this.deleteSet=new Qi,this.beforeState=bf(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 aN=(t,e)=>e.deleteSet.clients.size===0&&!pJ(e.afterState,(n,r)=>e.beforeState.get(r)!==n)?!1:(tv(e.deleteSet),_X(t,e),rv(t,e.deleteSet),!0),lN=(t,e,n)=>{const r=e._item;(r===null||r.id.clock<(t.beforeState.get(r.id.client)||0)&&!r.deleted)&&bo(t.changed,e,qs).add(n)},xf=(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},FX=(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=br(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)}}}},HX=(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=Ki(o.length-1,1+br(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+xf(o,l)}})},cN=(t,e)=>{if(e<t.length){const n=t[e],r=n.doc,o=r.store,s=n.deleteSet,i=n._mergeStructs;try{tv(s),n.afterState=bf(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),tN(c._dEH,l,n))})}),a.push(()=>r.emit("afterTransaction",[n,r])),Jy(a,[]),n._needFormattingCleanup&&aQ(n)}finally{r.gc&&FX(s,o,r.gcFilter),HX(s,o),n.afterState.forEach((u,d)=>{const f=n.beforeState.get(d)||0;if(f!==u){const h=o.clients.get(d),p=is(br(h,f),1);for(let m=h.length-1;m>=p;)m-=1+xf(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=br(h,f);p+1<h.length&&xf(h,p+1)>1||p>0&&xf(h,p)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(bX(Qy,HO,"[yjs] ",UO,zO,"Changed the client-id because another client seems to be using it."),r.clientID=JO()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){const u=new CX;aN(u,n)&&r.emit("update",[u.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){const u=new mf;aN(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])):cN(t,e+1)}}},Xe=(t,e,n=null,r=!0)=>{const o=t._transactionCleanups;let s=!1,i=null;t._transaction===null&&(s=!0,t._transaction=new BX(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&&cN(o,0)}}return i};class UX{constructor(e,n){this.insertions=n,this.deletions=e,this.meta=new Map}}const uN=(t,e,n)=>{ls(t,n.deletions,r=>{r instanceof nt&&e.scope.some(o=>o===t.doc||Yl(o,r))&&vv(r,!1)})},dN=(t,e,n)=>{let r=null;const o=t.doc,s=t.scope;Xe(o,a=>{for(;e.length>0&&t.currStackItem===null;){const l=o.store,c=e.pop(),u=new Set,d=[];let f=!1;ls(a,c.insertions,h=>{if(h instanceof nt){if(h.redone!==null){let{item:p,diff:m}=yv(l,h.id);m>0&&(p=Tn(a,Ie(p.id.client,p.id.clock+m))),h=p}!h.deleted&&s.some(p=>p===a.doc||Yl(p,h))&&d.push(h)}}),ls(a,c.deletions,h=>{h instanceof nt&&s.some(p=>p===a.doc||Yl(p,h))&&!Zi(c.insertions,h.id)&&u.add(h)}),u.forEach(h=>{f=jN(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 fN extends yO{constructor(e,{captureTimeout:n=500,captureTransaction:r=l=>!0,deleteFilter:o=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:i=!1,doc:a=Ly(e)?e[0].doc:e instanceof Js?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 Qi;l.afterState.forEach((y,v)=>{const w=l.beforeState.get(v)||0,E=y-w;E>0&&ql(f,v,w,E)});const h=qJ();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=nv([y.deletions,l.deleteSet]),y.insertions=nv([y.insertions,f])}else d.push(new UX(l.deleteSet,f)),p=!0;!c&&!u&&(this.lastChange=h),ls(l,l.deleteSet,y=>{y instanceof nt&&this.scope.some(v=>v===l.doc||Yl(v,y))&&vv(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=Ly(e)?e:[e],e.forEach(r=>{n.has(r)||(n.add(r),(r instanceof $t?r.doc!==this.doc:r!==this.doc)&&WO("[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=>uN(r,this,o)),this.undoStack=[]),n&&(this.redoStack.forEach(o=>uN(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=dN(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=dN(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*zX(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 Er(Ie(o,s),l),s+=l}else if((af&a)!==0){const l=(a&(wo|fn))===0,c=new nt(Ie(o,s),null,(a&fn)===fn?t.readLeftID():null,null,(a&wo)===wo?t.readRightID():null,l?t.readParentInfo()?t.readString():t.readLeftID():null,l&&(a&Hl)===Hl?t.readString():null,$N(t,a));yield c,s+=c.length}else{const l=t.readLen();yield new er(Ie(o,s),l),s+=l}}}}class VX{constructor(e,n){this.gen=zX(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===Er);return this.curr}}class WX{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}}const GX=(t,e)=>{if(t.constructor===er){const{client:n,clock:r}=t.id;return new er(Ie(n,r+e),t.length-e)}else if(t.constructor===Er){const{client:n,clock:r}=t.id;return new Er(Ie(n,r+e),t.length-e)}else{const n=t,{client:r,clock:o}=n.id;return new nt(Ie(r,o+e),null,Ie(r,o+e-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(e))}},hN=(t,e=pf,n=mf)=>{if(t.length===1)return t[0];const r=t.map(u=>new e(Wy(u)));let o=r.map(u=>new VX(u,!0)),s=null;const i=new n,a=new WX(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===Er?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)Jl(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===Er)s.struct.length=f.id.clock+f.length-s.struct.id.clock;else{Jl(a,s.struct,s.offset);const p=f.id.clock-s.struct.id.clock-s.struct.length;s={struct:new Er(Ie(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===Er?s.struct.length-=p:f=GX(f,p)),s.struct.mergeWith(f)||(Jl(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!==Er;f=u.next())Jl(a,s.struct,s.offset),s={struct:f,offset:0}}s!==null&&(Jl(a,s.struct,s.offset),s=null),qX(a);const l=r.map(u=>SX(u)),c=nv(l);return rv(i,c),i.toUint8Array()},pN=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:yr(t.encoder.restEncoder)}),t.encoder.restEncoder=Wl(),t.written=0)},Jl=(t,e,n)=>{t.written>0&&t.currClient!==e.id.client&&pN(t),t.written===0&&(t.currClient=e.id.client,t.encoder.writeClient(e.id.client),Fe(t.encoder.restEncoder,e.id.clock+n)),e.write(t.encoder,n),t.written++},qX=t=>{pN(t);const e=t.encoder.restEncoder;Fe(e,t.clientStructs.length);for(let n=0;n<t.clientStructs.length;n++){const r=t.clientStructs[n];Fe(e,r.written),lf(e,r.restEncoder)}},mN="You must not compute changes after the event-handler fired.";class wf{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=KX(this.currentTarget,this.target))}deletes(e){return Zi(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw as(mN);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=Py(l.content.getContent());else return;else l!==null&&this.deletes(l)?(i="update",a=Py(l.content.getContent())):(i="add",a=void 0)}else if(this.deletes(s))i="delete",a=Py(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 as(mN);const n=this.target,r=qs(),o=qs(),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 KX=(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=()=>{WO("Invalid access: Add Yjs type to a document before reading data.")},gN=80;let uv=0;class YX{constructor(e,n){e.marker=!0,this.p=e,this.index=n,this.timestamp=uv++}}const JX=t=>{t.timestamp=uv++},yN=(t,e,n)=>{t.p.marker=!1,t.p=e,e.marker=!0,t.index=n,t.timestamp=uv++},XX=(t,e,n)=>{if(t.length>=gN){const r=t.reduce((o,s)=>o.timestamp<s.timestamp?o:s);return yN(r,e,n),r}else{const r=new YX(e,n);return t.push(r),r}},Ef=(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)=>sf(e-s.index)<sf(e-i.index)?s:i);let r=t._start,o=0;for(n!==null&&(r=n.p,o=n.index,JX(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&&sf(n.index-o)<r.parent.length/gN?(yN(n,r,o),n):XX(t._searchMarker,r,o)},Xl=(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=is(e,o.index+n))}},Sf=(t,e,n)=>{const r=t,o=e.changedParentTypes;for(;bo(o,t,()=>[]).push(n),t._item!==null;)t=t._item.parent;tN(r._eH,n,e)};class $t{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=QO(),this._dEH=QO(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,n){this.doc=e,this._item=n}_copy(){throw vr()}clone(){throw vr()}_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){ZO(this._eH,e)}observeDeep(e){ZO(this._dEH,e)}unobserve(e){eN(this._eH,e)}unobserveDeep(e){eN(this._dEH,e)}toJSON(){}}const vN=(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},bN=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},xN=(t,e)=>{const n=[];let r=t._start;for(;r!==null;){if(r.countable&&Xs(r,e)){const o=r.content.getContent();for(let s=0;s<o.length;s++)n.push(o[s])}r=r.right}return n},Ql=(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}},wN=(t,e)=>{const n=[];return Ql(t,(r,o)=>{n.push(e(r,o,t))}),n},QX=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}}}},EN=(t,e)=>{t.doc??Zt();const n=Ef(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}},kf=(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(Ie(i,bt(a,i)),o,o&&o.lastId,l,l&&l.id,e,null,new ei(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(Ie(i,bt(a,i)),o,o&&o.lastId,l,l&&l.id,e,null,new Zl(new Uint8Array(d))),o.integrate(t,0);break;case Js:o=new nt(Ie(i,bt(a,i)),o,o&&o.lastId,l,l&&l.id,e,null,new tc(d)),o.integrate(t,0);break;default:if(d instanceof $t)o=new nt(Ie(i,bt(a,i)),o,o&&o.lastId,l,l&&l.id,e,null,new wr(d)),o.integrate(t,0);else throw new Error("Unexpected content type in insert operation")}}}),u()},SN=()=>as("Length exceeded!"),kN=(t,e,n,r)=>{if(n>e._length)throw SN();if(n===0)return e._searchMarker&&Xl(e._searchMarker,n,r.length),kf(t,e,null,r);const o=n,s=Ef(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&&Tn(t,Ie(i.id.client,i.id.clock+n));break}n-=i.length}return e._searchMarker&&Xl(e._searchMarker,o,r.length),kf(t,e,i,r)},ZX=(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 kf(t,e,o,n)},TN=(t,e,n,r)=>{if(r===0)return;const o=n,s=r,i=Ef(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&&Tn(t,Ie(a.id.client,a.id.clock+n)),n-=a.length);for(;r>0&&a!==null;)a.deleted||(r<a.length&&Tn(t,Ie(a.id.client,a.id.clock+r)),a.delete(t),r-=a.length),a=a.right;if(r>0)throw SN();e._searchMarker&&Xl(e._searchMarker,o,-s+r)},Tf=(t,e,n)=>{const r=e._map.get(n);r!==void 0&&r.delete(t)},dv=(t,e,n,r)=>{const o=e._map.get(n)||null,s=t.doc,i=s.clientID;let a;if(r==null)a=new ei([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:a=new ei([r]);break;case Uint8Array:a=new Zl(r);break;case Js:a=new tc(r);break;default:if(r instanceof $t)a=new wr(r);else throw new Error("Unexpected content type")}new nt(Ie(i,bt(s.store,i)),o,o&&o.lastId,null,null,e,n,a).integrate(t,0)},fv=(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},CN=t=>{const e={};return t.doc??Zt(),t._map.forEach((n,r)=>{n.deleted||(e[r]=n.content.getContent()[n.length-1])}),e},AN=(t,e)=>{t.doc??Zt();const n=t._map.get(e);return n!==void 0&&!n.deleted},eQ=(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&&Xs(s,e)&&(n[o]=s.content.getContent()[s.length-1])}),n},Cf=t=>(t.doc??Zt(),xX(t._map.entries(),e=>!e[1].deleted));class tQ extends wf{}class na extends $t{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const n=new na;return n.push(e),n}_integrate(e,n){super._integrate(e,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new na}clone(){const e=new na;return e.insert(0,this.toArray().map(n=>n instanceof $t?n.clone():n)),e}get length(){return this.doc??Zt(),this._length}_callObserver(e,n){super._callObserver(e,n),Sf(this,e,new tQ(this,e))}insert(e,n){this.doc!==null?Xe(this.doc,r=>{kN(r,this,e,n)}):this._prelimContent.splice(e,0,...n)}push(e){this.doc!==null?Xe(this.doc,n=>{ZX(n,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,n=1){this.doc!==null?Xe(this.doc,r=>{TN(r,this,e,n)}):this._prelimContent.splice(e,n)}get(e){return EN(this,e)}toArray(){return bN(this)}slice(e=0,n=this.length){return vN(this,e,n)}toJSON(){return this.map(e=>e instanceof $t?e.toJSON():e)}map(e){return wN(this,e)}forEach(e){Ql(this,e)}[Symbol.iterator](){return QX(this)}_write(e){e.writeTypeRef(CQ)}}const nQ=t=>new na;class rQ extends wf{constructor(e,n,r){super(e,n),this.keysChanged=r}}class ra extends $t{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 ra}clone(){const e=new ra;return this.forEach((n,r)=>{e.set(r,n instanceof $t?n.clone():n)}),e}_callObserver(e,n){Sf(this,e,new rQ(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 $t?o.toJSON():o}}),e}get size(){return[...Cf(this)].length}keys(){return Zy(Cf(this),e=>e[0])}values(){return Zy(Cf(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Zy(Cf(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?Xe(this.doc,n=>{Tf(n,this,e)}):this._prelimContent.delete(e)}set(e,n){return this.doc!==null?Xe(this.doc,r=>{dv(r,this,e,n)}):this._prelimContent.set(e,n),n}get(e){return fv(this,e)}has(e){return AN(this,e)}clear(){this.doc!==null?Xe(this.doc,e=>{this.forEach(function(n,r,o){Tf(e,o,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(AQ)}}const oQ=t=>new ra,cs=(t,e)=>t===e||typeof t=="object"&&typeof e=="object"&&t&&e&&tX(t,e);class hv{constructor(e,n,r,o){this.left=e,this.right=n,this.index=r,this.currentAttributes=o}forward(){switch(this.right===null&&kn(),this.right.content.constructor){case kt:this.right.deleted||oa(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 MN=(t,e,n)=>{for(;e.right!==null&&n>0;){switch(e.right.content.constructor){case kt:e.right.deleted||oa(e.currentAttributes,e.right.content);break;default:e.right.deleted||(n<e.right.length&&Tn(t,Ie(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},Af=(t,e,n,r)=>{const o=new Map,s=r?Ef(e,n):null;if(s){const i=new hv(s.p.left,s.p,s.index,o);return MN(t,i,n-s.index)}else{const i=new hv(null,e._start,0,o);return MN(t,i,n)}},ON=(t,e,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===kt&&cs(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(Ie(s,bt(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()})},oa=(t,e)=>{const{key:n,value:r}=e;r===null?t.delete(n):t.set(n,r)},NN=(t,e)=>{for(;t.right!==null;){if(!(t.right.deleted||t.right.content.constructor===kt&&cs(e[t.right.content.key]??null,t.right.content.value)))break;t.forward()}},_N=(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(!cs(c,l)){i.set(a,c);const{left:u,right:d}=n;n.right=new nt(Ie(s,bt(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},pv=(t,e,n,r,o)=>{n.currentAttributes.forEach((f,h)=>{o[h]===void 0&&(o[h]=null)});const s=t.doc,i=s.clientID;NN(n,o);const a=_N(t,e,n,o),l=r.constructor===String?new xr(r):r instanceof $t?new wr(r):new Zs(r);let{left:c,right:u,index:d}=n;e._searchMarker&&Xl(e._searchMarker,n.index,l.getLength()),u=new nt(Ie(i,bt(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(),ON(t,e,n,a)},RN=(t,e,n,r,o)=>{const s=t.doc,i=s.clientID;NN(n,o);const a=_N(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(cs(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&&Tn(t,Ie(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(Ie(i,bt(s.store,i)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,e,null,new xr(l)),n.right.integrate(t,0),n.forward()}ON(t,e,n,a)},IN=(t,e,n,r,o)=>{let s=e;const i=gr();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&&oa(o,c);break}}}e=e.right}return a},sQ=(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}},iQ=t=>{let e=0;return Xe(t.doc,n=>{let r=t._start,o=t._start,s=gr();const i=Dy(s);for(;o;){if(o.deleted===!1)switch(o.content.constructor){case kt:oa(i,o.content);break;default:e+=IN(n,r,o,s,i),s=Dy(i),r=o;break}o=o.right}}),e},aQ=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&&iN(t,n.store.clients.get(r),s,o,i=>{!i.deleted&&i.content.constructor===kt&&i.constructor!==er&&e.add(i.parent)})}Xe(n,r=>{ls(t,t.deleteSet,o=>{if(o instanceof er||!o.parent._hasFormatting||e.has(o.parent))return;const s=o.parent;o.content.constructor===kt?e.add(s):sQ(r,o)});for(const o of e)iQ(o)})},DN=(t,e,n)=>{const r=n,o=Dy(e.currentAttributes),s=e.right;for(;n>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case wr:case Zs:case xr:n<e.right.length&&Tn(t,Ie(e.right.id.client,e.right.id.clock+n)),n-=e.right.length,e.right.delete(t);break}e.forward()}s&&IN(t,s,e.right,o,e.currentAttributes);const i=(e.left||e.right).parent;return i._searchMarker&&Xl(i._searchMarker,e.index,-r+n),e};class lQ extends wf{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=[];Xe(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},ZJ(l)||(h.attributes=XJ({},l))),u=0;break}h&&n.push(h),a=null}};for(;i!==null;){switch(i.content.constructor){case wr:case Zs: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 xr: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;cs(m,p)?p!==null&&i.delete(r):(a==="retain"&&f(),cs(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;cs(m,p)||(a==="retain"&&f(),l[h]=m)}else if(!i.deleted){s.set(h,p);const m=l[h];m!==void 0&&(cs(m,p)?m!==null&&i.delete(r):(a==="retain"&&f(),p===null?delete l[h]:l[h]=p))}i.deleted||(a==="insert"&&f(),oa(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 us extends $t{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 us}clone(){const e=new us;return e.applyDelta(this.toDelta()),e}_callObserver(e,n){super._callObserver(e,n);const r=new lQ(this,e,n);Sf(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===xr&&(e+=n.content.str),n=n.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:n=!0}={}){this.doc!==null?Xe(this.doc,r=>{const o=new hv(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)&&pv(r,this,o,a,i.attributes||{})}else i.retain!==void 0?RN(r,this,o,i.retain,i.attributes||{}):i.delete!==void 0&&DN(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(Xs(l,e)||n!==void 0&&Xs(l,n))switch(l.content.constructor){case xr:{const d=s.get("ychange");e!==void 0&&!Xs(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&&!Xs(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 wr:case Zs:{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:Xs(l,e)&&(c(),oa(s,l.content));break}l=l.right}c()};return e||n?Xe(i,d=>{e&&lv(d,e),n&&lv(d,n),u()},"cleanup"):u(),o}insert(e,n,r){if(n.length<=0)return;const o=this.doc;o!==null?Xe(o,s=>{const i=Af(s,this,e,!r);r||(r={},i.currentAttributes.forEach((a,l)=>{r[l]=a})),pv(s,this,i,n,r)}):this._pending.push(()=>this.insert(e,n,r))}insertEmbed(e,n,r){const o=this.doc;o!==null?Xe(o,s=>{const i=Af(s,this,e,!r);pv(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?Xe(r,o=>{DN(o,Af(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?Xe(o,s=>{const i=Af(s,this,e,!1);i.right!==null&&RN(s,this,i,n,r)}):this._pending.push(()=>this.format(e,n,r))}removeAttribute(e){this.doc!==null?Xe(this.doc,n=>{Tf(n,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,n){this.doc!==null?Xe(this.doc,r=>{dv(r,this,e,n)}):this._pending.push(()=>this.setAttribute(e,n))}getAttribute(e){return fv(this,e)}getAttributes(){return CN(this)}_write(e){e.writeTypeRef(MQ)}}const cQ=t=>new us;class mv{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===en||n.constructor===Qs)&&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 Qs extends $t{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 Qs}clone(){const e=new Qs;return e.insert(0,this.toArray().map(n=>n instanceof $t?n.clone():n)),e}get length(){return this.doc??Zt(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new mv(this,e)}querySelector(e){e=e.toUpperCase();const r=new mv(this,o=>o.nodeName&&o.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),Ks(new mv(this,n=>n.nodeName&&n.nodeName.toUpperCase()===e))}_callObserver(e,n){Sf(this,e,new fQ(this,n,e))}toString(){return wN(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),Ql(this,s=>{o.insertBefore(s.toDOM(e,n,r),null)}),o}insert(e,n){this.doc!==null?Xe(this.doc,r=>{kN(r,this,e,n)}):this._prelimContent.splice(e,0,...n)}insertAfter(e,n){if(this.doc!==null)Xe(this.doc,r=>{const o=e&&e instanceof $t?e._item:e;kf(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 as("Reference item not found");r.splice(o,0,...n)}}delete(e,n=1){this.doc!==null?Xe(this.doc,r=>{TN(r,this,e,n)}):this._prelimContent.splice(e,n)}toArray(){return bN(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return EN(this,e)}slice(e=0,n=this.length){return vN(this,e,n)}forEach(e){Ql(this,e)}_write(e){e.writeTypeRef(NQ)}}const uQ=t=>new Qs;class en extends Qs{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 en(this.nodeName)}clone(){const e=new en(this.nodeName),n=this.getAttributes();return QJ(n,(r,o)=>{typeof r=="string"&&e.setAttribute(o,r)}),e.insert(0,this.toArray().map(r=>r instanceof $t?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?Xe(this.doc,n=>{Tf(n,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,n){this.doc!==null?Xe(this.doc,r=>{dv(r,this,e,n)}):this._prelimAttrs.set(e,n)}getAttribute(e){return fv(this,e)}hasAttribute(e){return AN(this,e)}getAttributes(e){return e?eQ(this,e):CN(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 Ql(this,i=>{o.appendChild(i.toDOM(e,n,r))}),r!==void 0&&r._createAssociation(o,this),o}_write(e){e.writeTypeRef(OQ),e.writeKey(this.nodeName)}}const dQ=t=>new en(t.readKey());class fQ extends wf{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 Mf extends ra{constructor(e){super(),this.hookName=e}_copy(){return new Mf(this.hookName)}clone(){const e=new Mf(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(_Q),e.writeKey(this.hookName)}}const hQ=t=>new Mf(t.readKey());class Cn extends us{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 Cn}clone(){const e=new Cn;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(RQ)}}const pQ=t=>new Cn;class gv{constructor(e,n){this.id=e,this.length=n}get deleted(){throw vr()}mergeWith(e){return!1}write(e,n,r){throw vr()}integrate(e,n){throw vr()}}const mQ=0;class er extends gv{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),oN(e.doc.store,this)}write(e,n){e.writeInfo(mQ),e.writeLen(this.length-n)}getMissing(e,n){return null}}class Zl{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Zl(this.content)}splice(e){throw vr()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeBuf(this.content)}getRef(){return 3}}const gQ=t=>new Zl(t.readBuf());class ec{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new ec(this.len)}splice(e){const n=new ec(this.len-e);return this.len=e,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,n){ql(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 yQ=t=>new ec(t.readLen()),PN=(t,e)=>new Js({guid:t,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class tc{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 tc(PN(this.doc.guid,this.opts))}splice(e){throw vr()}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 vQ=t=>new tc(PN(t.readString(),t.readAny()));class Zs{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Zs(this.embed)}splice(e){throw vr()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeJSON(this.embed)}getRef(){return 5}}const bQ=t=>new Zs(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 vr()}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 xQ=t=>new kt(t.readKey(),t.readJSON());class Of{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Of(this.arr)}splice(e){const n=new Of(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 wQ=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 Of(n)},EQ=hf("node_env")==="development";class ei{constructor(e){this.arr=e,EQ&&jO(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ei(this.arr)}splice(e){const n=new ei(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 SQ=t=>{const e=t.readLen(),n=[];for(let r=0;r<e;r++)n.push(t.readAny());return new ei(n)};class xr{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new xr(this.str)}splice(e){const n=new xr(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 kQ=t=>new xr(t.readString()),TQ=[nQ,oQ,cQ,dQ,uQ,hQ,pQ],CQ=0,AQ=1,MQ=2,OQ=3,NQ=4,_Q=5,RQ=6;class wr{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new wr(this.type._copy())}splice(e){throw vr()}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 IQ=t=>new wr(TQ[t.readTypeRef()](t)),yv=(t,e)=>{let n=e,r=0,o;do r>0&&(n=Ie(n.client,n.clock+r)),o=ta(t,n),r=n.clock-o.id.clock,n=o.redone;while(n!==null&&o instanceof nt);return{item:o,diff:r}},vv=(t,e)=>{for(;t!==null&&t.keep!==e;)t.keep=e,t=t.parent._item},Nf=(t,e,n)=>{const{client:r,clock:o}=e.id,s=new nt(Ie(r,o+n),e,Ie(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=Ie(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},LN=(t,e)=>gJ(t,n=>Zi(n.deletions,e)),jN=(t,e,n,r,o,s)=>{const i=t.doc,a=i.store,l=i.clientID,c=e.redone;if(c!==null)return Tn(t,c);let u=e.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||jN(t,u,n,r,o,s)===null))return null;for(;u.redone!==null;)u=Tn(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:Tn(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:Tn(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||Zi(r,d.right.id)||LN(s.undoStack,d.right.id)||LN(s.redoStack,d.right.id));)for(d=d.right;d.redone;)d=Tn(t,d.redone);if(d&&d.right!==null)return null}else d=h._map.get(e.parentSub)||null;const p=bt(a,l),m=Ie(l,p),y=new nt(m,d,d&&d.lastId,f,f&&f.id,h,e.parentSub,e.content.copy());return e.redone=m,vv(y,!0),y.integrate(t,0),y};let nt=class Fv extends gv{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()?xO:0}set marker(e){(this.info&$y)>0!==e&&(this.info^=$y)}get marker(){return(this.info&$y)>0}get keep(){return(this.info&bO)>0}set keep(e){this.keep!==e&&(this.info^=bO)}get countable(){return(this.info&xO)>0}get deleted(){return(this.info&jy)>0}set deleted(e){this.deleted!==e&&(this.info^=jy)}markDeleted(){this.info|=jy}getMissing(e,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=bt(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=bt(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ea&&this.id.client!==this.parent.client&&this.parent.clock>=bt(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=sN(e,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Tn(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===er||this.right&&this.right.constructor===er)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===Fv?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===Fv&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===ea){const r=ta(n,this.parent);r.constructor===er?this.parent=null:this.parent=r.content.type}return null}integrate(e,n){if(n>0&&(this.id.clock+=n,this.left=sN(e,e.doc.store,Ie(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),gf(this.origin,o.origin)){if(o.id.client<this.id.client)r=o,s.clear();else if(gf(this.rightOrigin,o.rightOrigin))break}else if(o.origin!==null&&i.has(ta(e.doc.store,o.origin)))s.has(ta(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),oN(e.doc.store,this),this.content.integrate(e,this),lN(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new er(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:Ie(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&gf(e.origin,this.lastId)&&this.right===e&&gf(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(),ql(e.deleteSet,this.id.client,this.id.clock,this.length),lN(e,n,this.parentSub),this.content.delete(e)}}gc(e,n){if(!this.deleted)throw kn();this.content.gc(e),n?$X(e,this,new er(this.id,this.length)):this.content=new ec(this.length)}write(e,n){const r=n>0?Ie(this.id.client,this.id.clock+n-1):this.origin,o=this.rightOrigin,s=this.parentSub,i=this.content.getRef()&af|(r===null?0:fn)|(o===null?0:wo)|(s===null?0:Hl);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=Kl(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===ea?(e.writeParentInfo(!1),e.writeLeftID(a)):kn();s!==null&&e.writeString(s)}this.content.write(e,n)}};const $N=(t,e)=>DQ[e&af](t),DQ=[()=>{kn()},yQ,wQ,gQ,kQ,bQ,xQ,IQ,SQ,vQ,()=>{kn()}],PQ=10;class Er extends gv{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,n){kn()}write(e,n){e.writeInfo(PQ),Fe(e.restEncoder,this.length-n)}getMissing(e,n){return null}}const BN=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},FN="__ $YJS$ __";BN[FN]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),BN[FN]=!0;const LQ=()=>{let t=!0;return(e,n)=>{if(t){t=!1;try{e()}finally{t=!0}}else n!==void 0&&n()}},jQ=/[\uD800-\uDBFF]/,$Q=/[\uDC00-\uDFFF]/,BQ=(t,e)=>{let n=0,r=0;for(;n<t.length&&n<e.length&&t[n]===e[n];)n++;for(n>0&&jQ.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&&$Q.test(t[t.length-r])&&r--,{index:n,remove:t.length-n-r,insert:e.slice(n,e.length-r)}},Vr=(t,e)=>t>>>e|t<<32-e,FQ=t=>Vr(t,2)^Vr(t,13)^Vr(t,22),HQ=t=>Vr(t,6)^Vr(t,11)^Vr(t,25),UQ=t=>Vr(t,7)^Vr(t,18)^t>>>3,zQ=t=>Vr(t,17)^Vr(t,19)^t>>>10,VQ=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]),WQ=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class GQ{constructor(){const e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(WQ),this._W=new Uint32Array(e,64,64)}_updateHash(){const e=this._H,n=this._W;for(let d=16;d<64;d++)n[d]=zQ(n[d-2])+n[d-7]+UQ(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+HQ(a)+(a&l^~a&c)+VQ[d]+n[d]>>>0,h=FQ(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]|=fn<<(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)]|=fn<<(3-n%4)*8),this._W[14]=e.byteLength/yJ,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 qQ=t=>new GQ().digest(t),gt=new ze("y-sync"),ko=new ze("y-undo");new ze("yjs-cursor");const KQ=t=>{for(let n=6;n<t.length;n++)t[n%6]=t[n%6]^t[n];return t.slice(0,6)},YQ=t=>iX(KQ(qQ(aX(t)))),_f=(t,e)=>e===void 0?!t.deleted:e.sv.has(t.id.client)&&e.sv.get(t.id.client)>t.id.clock&&!Zi(e.ds,t.id),JQ=[{light:"#ecd44433",dark:"#ecd444"}],XQ=(t,e,n)=>{if(!t.has(n)){if(t.size<e.length){const r=qs();t.forEach(o=>r.add(o)),e=e.filter(o=>!r.has(o))}t.set(n,VJ(e))}return t.get(n)},QQ=(t,{colors:e=JQ,colorMapping:n=new Map,permanentUserData:r=null,onFirstRender:o=()=>{},mapping:s}={})=>{let i=!1;const a=new eZ(t,s),l=new He({props:{editable:c=>{const u=gt.getState(c);return u.snapshot==null&&u.prevSnapshot==null}},key:gt,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(gt);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)&&FO(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=ko.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)},gt)})}},destroy:()=>{a.destroy()}})});return l},ZQ=(t,e,n)=>{if(e!==null&&e.anchor!==null&&e.head!==null)if(e.type==="all")t.setSelection(new vn(t.doc));else if(e.type==="node"){const r=Pf(n.doc,n.type,e.anchor,n.mapping);t.setSelection(ue.create(t.doc,r))}else{const r=Pf(n.doc,n.type,e.anchor,n.mapping),o=Pf(n.doc,n.type,e.head,n.mapping);r!==null&&o!==null&&t.setSelection(pe.between(t.doc.resolve(r),t.doc.resolve(o)))}},bv=(t,e)=>({type:e.selection.jsonID,anchor:Tv(e.selection.anchor,t.type,t.mapping),head:Tv(e.selection.head,t.type,t.mapping)});class eZ{constructor(e,n=new Map){this.type=e,this.prosemirrorView=null,this.mux=LQ(),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=bv(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()?($O&&this._domSelectionInView===null&&(FO(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=cX.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=nN(KO(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(gt,{snapshot:e,prevSnapshot:n}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{const e=this.type.toArray().map(r=>Rf(r,this.prosemirrorView.state.schema,this)).filter(r=>r!==null),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Q(F.from(e),0,0));n.setMeta(gt,{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=>Rf(o,this.prosemirrorView.state.schema,this)).filter(o=>o!==null),r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Q(F.from(n),0,0));if(e){const o=Ki(is(e.anchor,0),r.doc.content.size),s=Ki(is(e.head,0),r.doc.content.size);r.setSelection(pe.create(r.doc,o,s))}this.prosemirrorView.dispatch(r.setMeta(gt,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,n,r){let o=this.doc,s=this.type;if(e||(e=av(this.doc)),e instanceof Uint8Array||n instanceof Uint8Array)if((!(e instanceof Uint8Array)||!(n instanceof Uint8Array))&&kn(),o=new Js({gc:!1}),ov(o,n),n=av(o),ov(o,e),e=av(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=br(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=>{ls(i,d,f=>{})});const l=(d,f)=>{const h=d==="added"?a.getUserByClientId(f.client):a.getUserByDeletedId(f);return{user:h,type:d,color:XQ(r.colorMapping,r.colors,h)}},c=xN(s,new iv(n.ds,e.sv)).map(d=>!d._item.deleted||_f(d._item,e)||_f(d._item,n)?Rf(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 Q(F.from(c),0,0));this.prosemirrorView.dispatch(u.setMeta(gt,{isChangeOrigin:!0}))},gt)})}_typeChanged(e,n){if(this.prosemirrorView==null)return;const r=gt.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);ls(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=>HN(a,this.prosemirrorView.state.schema,this)).filter(a=>a!==null);let i=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Q(F.from(s),0,0));ZQ(i,this.beforeTransactionSelection,this),i=i.setMeta(gt,{isChangeOrigin:!0,isUndoRedoOperation:n.origin instanceof fN}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&i.scrollIntoView(),this.prosemirrorView.dispatch(i)})}_prosemirrorChanged(e){this.doc.transact(()=>{Sv(this.doc,this.type,e,this),this.beforeTransactionSelection=bv(this,this.prosemirrorView.state)},gt)}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 HN=(t,e,n,r,o,s)=>{const i=n.mapping.get(t);if(i===void 0){if(t instanceof en)return Rf(t,e,n,r,o,s);throw vr()}return i},Rf=(t,e,n,r,o,s)=>{const i=[],a=l=>{if(l instanceof en){const c=HN(l,e,n,r,o,s);c!==null&&i.push(c)}else{const c=l._item.right?.content?.type;c instanceof us&&!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=tZ(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):xN(t,new iv(o.ds,r.sv)).forEach(a);try{const l=t.getAttributes(r);r!==void 0&&(_f(t._item,r)?_f(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)},gt),n.mapping.delete(t),null}},tZ=(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,aZ(c.attributes,e)))}}catch{return t.doc.transact(c=>{t._item.delete(c)},gt),null}return i},nZ=(t,e)=>{const n=new Cn,r=t.map(o=>({insert:o.text,attributes:WN(o.marks,e)}));return n.applyDelta(r),e.mapping.set(n,t),n},rZ=(t,e)=>{const n=new en(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,If(t).map(r=>xv(r,e))),e.mapping.set(n,t),n},xv=(t,e)=>t instanceof Array?nZ(t,e):rZ(t,e),UN=t=>typeof t=="object"&&t!==null,wv=(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||UN(i)&&UN(a)&&wv(i,a)}return r},If=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},zN=(t,e)=>{const n=t.toDelta();return n.length===e.length&&n.every((r,o)=>r.insert===e[o].text&&DO(r.attributes||{}).length===e[o].marks.length&&LO(r.attributes,(s,i)=>{const a=Ev(i),l=e[o].marks;return wv(s,l.find(c=>c.type.name===a)?.attrs)}))},nc=(t,e)=>{if(t instanceof en&&!(e instanceof Array)&&kv(t,e)){const n=If(e);return t._length===n.length&&wv(t.getAttributes(),e.attrs)&&t.toArray().every((r,o)=>nc(r,n[o]))}return t instanceof Cn&&e instanceof Array&&zN(t,e)},Df=(t,e)=>t===e||t instanceof Array&&e instanceof Array&&t.length===e.length&&t.every((n,r)=>e[r]===n),VN=(t,e,n)=>{const r=t.toArray(),o=If(e),s=o.length,i=r.length,a=Ki(i,s);let l=0,c=0,u=!1;for(;l<a;l++){const d=r[l],f=o[l];if(Df(n.mapping.get(d),f))u=!0;else if(!nc(d,f))break}for(;l+c<a;c++){const d=r[i-c-1],f=o[s-c-1];if(Df(n.mapping.get(d),f))u=!0;else if(!nc(d,f))break}return{equalityFactor:l+c,foundMappedChild:u}},oZ=t=>{let e="",n=t._start;const r={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof xr?e+=n.content.str:n.content instanceof kt&&(r[n.content.key]=null)),n=n.right;return{str:e,nAttrs:r}},sZ=(t,e,n)=>{n.mapping.set(t,e);const{nAttrs:r,str:o}=oZ(t),s=e.map(c=>({insert:c.text,attributes:Object.assign({},r,WN(c.marks,n))})),{insert:i,remove:a,index:l}=BQ(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})))},iZ=/(.*)(--[a-zA-Z0-9+/=]{8})$/,Ev=t=>iZ.exec(t)?.[1]??t,aZ=(t,e)=>{const n=[];for(const r in t)n.push(e.mark(Ev(r),t[r]));return n},WN=(t,e)=>{const n={};return t.forEach(r=>{if(r.type.name!=="ychange"){const o=bo(e.isOMark,r.type,()=>!r.type.excludes(r.type));n[o?`${r.type.name}--${YQ(r.toJSON())}`:r.type.name]=r.attrs}}),n},Sv=(t,e,n,r)=>{if(e instanceof en&&e.nodeName!==n.type.name)throw new Error("node name mismatch!");if(r.mapping.set(e,n),e instanceof en){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=If(n),s=o.length,i=e.toArray(),a=i.length,l=Ki(s,a);let c=0,u=0;for(;c<l;c++){const d=i[c],f=o[c];if(!Df(r.mapping.get(d),f))if(nc(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(!Df(r.mapping.get(d),f))if(nc(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 Cn&&h instanceof Array)zN(f,h)||sZ(f,h,r),c+=1;else{let y=f instanceof en&&kv(f,h),v=p instanceof en&&kv(p,m);if(y&&v){const w=VN(f,h,r),E=VN(p,m,r);w.foundMappedChild&&!E.foundMappedChild?v=!1:!w.foundMappedChild&&E.foundMappedChild||w.equalityFactor<E.equalityFactor?y=!1:v=!1}y?(Sv(t,f,h,r),c+=1):v?(Sv(t,p,m,r),u+=1):(r.mapping.delete(e.get(c)),e.delete(c,1),e.insert(c,[xv(h,r)]),c+=1)}}const d=a-c-u;if(a===1&&s===0&&i[0]instanceof Cn?(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(xv(o[h],r));e.insert(c,f)}},gt)},kv=(t,e)=>!(e instanceof Array)&&t.nodeName===e.type.name,Tv=(t,e,n)=>{if(t===0)return sv(e,0,-1);let r=e._first===null?null:e._first.content.type;for(;r!==null&&e!==r;){if(r instanceof Cn){if(r._length>=t)return sv(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 yf(r._item===null?null:r._item.id,r._item===null?Kl(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 yf(r._item===null?null:r._item.id,r._item===null?Kl(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 kn();if(t===0&&r.constructor!==Cn&&r!==e)return lZ(r._item.parent,r._item)}return sv(e,e._length,-1)},lZ=(t,e)=>{let n=null,r=null;return t._item===null?r=Kl(t):n=Ie(t._item.id.client,t._item.id.clock),new yf(n,r,e.id)},Pf=(t,e,n,r)=>{const o=jX(n,t);if(o===null||o.type!==e&&!Yl(e,o.type._item))return null;let s=o.type,i=0;if(s.constructor===Cn)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 Cn?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 Cn?i+=c._length:i+=r.get(c).nodeSize),l=l.right}}s=a}return i-1};function cZ(t){const e=t.toArray(),n=r=>{let o;if(r instanceof Cn)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:Ev(l)};return Object.keys(c)&&(d.attrs=c),d})),a});else if(r instanceof en){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 kn();return o};return{type:"doc",content:e.map(n)}}const uZ=t=>{const e=ko.getState(t).undoManager;if(e!=null)return e.undo(),!0},dZ=t=>{const e=ko.getState(t).undoManager;if(e!=null)return e.redo(),!0},fZ=new Set(["paragraph"]),hZ=(t,e)=>!(t instanceof nt)||!(t.content instanceof wr)||!(t.content.type instanceof us||t.content.type instanceof en&&e.has(t.content.type.nodeName))||t.content.type._length===0,pZ=({protectedNodes:t=fZ,trackedOrigins:e=[],undoManager:n=null}={})=>new He({key:ko,state:{init:(r,o)=>{const s=gt.getState(o),i=n||new fN(s.type,{trackedOrigins:new Set([gt].concat(e)),deleteFilter:a=>hZ(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=gt.getState(i).binding,l=o.undoManager,c=l.undoStack.length>0,u=l.redoStack.length>0;return a?{undoManager:l,prevSel:bv(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=gt.getState(r.state),s=ko.getState(r.state).undoManager;return s.on("stack-item-added",({stackItem:i})=>{const a=o.binding;a&&i.meta.set(a,ko.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()}}}});Je.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),ko.getState(e).undoManager.undoStack.length===0?!1:n?uZ(e):!0),redo:()=>({tr:t,state:e,dispatch:n})=>(t.setMeta("preventDispatch",!0),ko.getState(e).undoManager.redoStack.length===0?!1:n?dZ(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=pZ(this.options.yUndoOptions),r=n.spec.view;n.spec.view=i=>{const{undoManager:a}=ko.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=QQ(e,o);return this.editor.options.enableContentCheck&&((t=e.doc)==null||t.on("beforeTransaction",()=>{try{const i=cZ(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 He({key:new ze("filterInvalidContent"),filterTransaction:()=>{var i;return this.storage.isDisabled!==!1&&((i=e.doc)==null||i.destroy()),!0}})].filter(Boolean)}});function mZ(t){return!!t.getMeta(gt)}function GN(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(Vt.node(o,o+s.nodeSize,{class:"ProseMirror-selectednoderange"}))}),et.create(n,e)}function Lf(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 wa(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 Px(o.resolve(c),o.resolve(u));r.push(d)}),r}var gZ=class q_{constructor(e,n){this.anchor=e,this.head=n}map(e){return new q_(e.map(this.anchor),e.map(this.head))}resolve(e){const n=e.resolve(this.anchor),r=e.resolve(this.head);return new ds(n,r)}},ds=class ps extends Me{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=Lf(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 ps&&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 ps(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 ps(s,i,this.depth)}const n=this.ranges[0],r=e.resolve(Math.max(0,n.$from.pos-1));return new ps(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 ps(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 ps(this.$anchor,r,this.depth)}static fromJSON(e,n){return new ps(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 gZ(this.anchor,this.head)}};ds.prototype.visible=!1;function jf(t){return t instanceof ds}Je.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(!jf(s)){const u=ds.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(!jf(s)){const u=ds.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=ds.create(o,0,o.content.size,e);return s.setSelection(i),n.dispatch(s),!0}}},onSelectionUpdate(){const{selection:t}=this.editor.state;jf(t)&&this.editor.view.dom.classList.add("ProseMirror-noderangeselection")},addProseMirrorPlugins(){let t=!1,e=!1;return[new He({key:new ze("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=ds.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=jf(r);if(t=!1,!e)return o?(t=!0,GN(r.ranges)):null;const{$from:s,$to:i}=r;if(!o&&s.sameParent(i))return null;const a=Lf(s,i,this.options.depth);return a.length?(t=!0,GN(a)):null}}})]}});function yZ(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 vZ(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=yZ(o)}),e}var qN=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 $f(t,e){return window.getComputedStyle(t)[e]}function bZ(t=0,e=0,n=0){return Math.min(Math.max(t,e),n)}function xZ(t,e,n){const r=parseInt($f(t.dom,"paddingLeft"),10),o=parseInt($f(t.dom,"paddingRight"),10),s=parseInt($f(t.dom,"borderLeftWidth"),10),i=parseInt($f(t.dom,"borderLeftWidth"),10),a=t.dom.getBoundingClientRect();return{left:bZ(e,a.left+r+s,a.right-o-i),top:n}}function KN(t){var e;(e=t.parentNode)==null||e.removeChild(t)}function wZ(t,e){const{doc:n}=e.view.state,r=qN({editor:e,x:t.clientX,y:t.clientY,direction:"right"});if(!r.resultNode||r.pos===null)return[];const o=t.clientX,s=xZ(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 Lf(c,u,0)}function EZ(t,e){const{view:n}=e;if(!t.dataTransfer)return;const{empty:r,$from:o,$to:s}=n.state.selection,i=wZ(t,e),a=Lf(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=ds.create(n.state.doc,f,h),m=p.content();c.forEach(y=>{const v=n.nodeDOM(y.$from.pos),w=vZ(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",()=>KN(d),{once:!0})}var YN=(t,e)=>{const n=t.resolve(e),{depth:r}=n;return r===0?e:n.pos-n.parentOffset-1},JN=(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},Cv=(t,e)=>{const n=gt.getState(t);return n?Tv(e,n.type,n.binding.mapping):null},SZ=(t,e)=>{const n=gt.getState(t);return n?Pf(n.doc,n.type,e,n.binding.mapping)||0:-1},XN=(t,e)=>{let n=e;for(;n?.parentNode&&n.parentNode!==t.dom;)n=n.parentNode;return n},QN=new ze("dragHandle"),ZN=({pluginKey:t=QN,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()};LS(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),EZ(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 He({key:typeof t=="string"?new ze(t):t,state:{init(){return{locked:!1}},apply(x,T,S,k){const C=x.getMeta("lockDragHandle"),_=x.getMeta("hideDragHandle");if(C!==void 0&&(c=C),_)return m(),c=!1,u=null,d=-1,s?.({editor:n,node:null,pos:-1}),T;if(x.docChanged&&d!==-1&&e)if(mZ(x)){const N=SZ(k,f);N!==d&&(d=N)}else{const N=x.mapping.map(d);N!==d&&(d=N,f=Cv(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=XN(x,C),C===x.dom||C?.nodeType!==1)return;const _=x.posAtDOM(C,0),N=JN(n.state.doc,_),L=YN(n.state.doc,_);u=N,d=L,f=Cv(x.state,d),s?.({editor:n,node:u,pos:d}),v(C)},destroy(){h&&(cancelAnimationFrame(h),h=null,p=null),e&&KN(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=qN({x:S,y:k,direction:"right",editor:n});if(!C.resultElement)return;let _=C.resultElement;if(_=XN(x,_),_===x.dom||_?.nodeType!==1)return;const N=x.posAtDOM(_,0),L=JN(n.state.doc,N);if(L!==u){const $=YN(n.state.doc,N);u=L,d=$,f=Cv(x.state,d),s?.({editor:n,node:u,pos:d}),v(_),y()}})),!1}}}})}},Av={placement:"left-start",strategy:"absolute"};Je.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[ZN({computePositionConfig:{...Av,...this.options.computePositionConfig},getReferencedVirtualElement:this.options.getReferencedVirtualElement,element:t,editor:this.editor,onNodeChange:this.options.onNodeChange}).plugin]}});var kZ=t=>{const{className:e="drag-handle",children:n,editor:r,pluginKey:o=QN,onNodeChange:s,onElementDragStart:i,onElementDragEnd:a,computePositionConfig:l=Av}=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=ZN({editor:r,element:c,pluginKey:o,computePositionConfig:{...Av,...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})},TZ=kZ;const e_=({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(jF,{editorTab:n,onSwitchEditorTab:r}),g.jsx(NG,{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(TZ,{editor:t,className:re(" pr-2",n!==ht.Text&&"hidden size-0 overflow-hidden pointer-events-none"),children:g.jsx(Vn,{variant:"ghost",className:"bg-white cursor-grab py-0.5 px-0 border size-auto",children:g.jsx(Zz,{className:"text-muted-foreground"})})}),g.jsx(SF,{className:"grow overflow-y-auto","data-theme":"select-post-builder",editor:t})]})})]}),CZ=({open:t,onOpenChange:e,...n})=>g.jsx($m,{open:t,onOpenChange:e,children:g.jsx(Bm,{className:"bg-transparent border-0 p-0 lg:max-w-4xl",showCloseButton:!1,children:g.jsx(e_,{...n,className:"bg-white max-h-dvh h-full"})})});function t_(t,[e,n]){return Math.min(n,Math.max(e,t))}var AZ=[" ","Enter","ArrowUp","ArrowDown"],MZ=[" ","Enter"],ti="Select",[Bf,Ff,OZ]=ph(ti),[sa]=Nn(ti,[OZ,qo]),Hf=qo(),[NZ,fs]=sa(ti),[_Z,RZ]=sa(ti),n_=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=Cc(c),[k,C]=Xr({prop:r,defaultProp:o??!1,onChange:s,caller:ti}),[_,N]=Xr({prop:i,defaultProp:a,onChange:l,caller:ti}),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(Ou,{...m,children:g.jsxs(NZ,{required:h,scope:e,trigger:y,onTriggerChange:v,valueNode:w,onValueNodeChange:E,valueNodeHasChildren:x,onValueNodeHasChildrenChange:T,contentId:Bn(),value:_,onValueChange:N,open:k,onOpenChange:C,dir:S,triggerPointerDownPosRef:L,disabled:f,children:[g.jsx(Bf.Provider,{scope:e,children:g.jsx(_Z,{scope:t.__scopeSelect,onNativeOptionAdd:b.useCallback(P=>{U(H=>new Set(H).add(P))},[]),onNativeOptionRemove:b.useCallback(P=>{U(H=>{const R=new Set(H);return R.delete(P),R})},[]),children:n})}),$?g.jsxs(k_,{"aria-hidden":!0,required:h,tabIndex:-1,name:u,autoComplete:d,value:_,onChange:P=>N(P.target.value),disabled:f,form:p,children:[_===void 0?g.jsx("option",{value:""}):null,Array.from(B)]},j):null]})})};n_.displayName=ti;var r_="SelectTrigger",o_=b.forwardRef((t,e)=>{const{__scopeSelect:n,disabled:r=!1,...o}=t,s=Hf(n),i=fs(r_,n),a=i.disabled||r,l=$e(e,i.onTriggerChange),c=Ff(n),u=b.useRef("touch"),[d,f,h]=C_(m=>{const y=c().filter(E=>!E.disabled),v=y.find(E=>E.value===i.value),w=A_(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(qa,{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":T_(i.value)?"":void 0,...o,ref:l,onClick:te(o.onClick,m=>{m.currentTarget.focus(),u.current!=="mouse"&&p(m)}),onPointerDown:te(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:te(o.onKeyDown,m=>{const y=d.current!=="";!(m.ctrlKey||m.altKey||m.metaKey)&&m.key.length===1&&f(m.key),!(y&&m.key===" ")&&AZ.includes(m.key)&&(p(),m.preventDefault())})})})});o_.displayName=r_;var s_="SelectValue",i_=b.forwardRef((t,e)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=t,l=fs(s_,n),{onValueNodeHasChildrenChange:c}=l,u=s!==void 0,d=$e(e,l.onValueNodeChange);return Ct(()=>{c(u)},[c,u]),g.jsx(ge.span,{...a,ref:d,style:{pointerEvents:"none"},children:T_(l.value)?g.jsx(g.Fragment,{children:i}):s})});i_.displayName=s_;var IZ="SelectIcon",a_=b.forwardRef((t,e)=>{const{__scopeSelect:n,children:r,...o}=t;return g.jsx(ge.span,{"aria-hidden":!0,...o,ref:e,children:r||"▼"})});a_.displayName=IZ;var DZ="SelectPortal",l_=t=>g.jsx(Oi,{asChild:!0,...t});l_.displayName=DZ;var ni="SelectContent",c_=b.forwardRef((t,e)=>{const n=fs(ni,t.__scopeSelect),[r,o]=b.useState();if(Ct(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?sc.createPortal(g.jsx(u_,{scope:t.__scopeSelect,children:g.jsx(Bf.Slot,{scope:t.__scopeSelect,children:g.jsx("div",{children:t.children})})}),s):null}return g.jsx(d_,{...t,ref:e})});c_.displayName=ni;var Sr=10,[u_,hs]=sa(ni),PZ="SelectContentImpl",LZ=Oo("SelectContent.RemoveScroll"),d_=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(ni,n),[E,x]=b.useState(null),[T,S]=b.useState(null),k=$e(e,z=>x(z)),[C,_]=b.useState(null),[N,L]=b.useState(null),$=Ff(n),[B,U]=b.useState(!1),j=b.useRef(!1);b.useEffect(()=>{if(E)return Uu(E)},[E]),Du();const P=b.useCallback(z=>{const[ee,...Oe]=$().map(Se=>Se.ref.current),[he]=Oe.slice(-1),we=document.activeElement;for(const Se of z)if(Se===we||(Se?.scrollIntoView({block:"nearest"}),Se===ee&&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:R,triggerPointerDownPosRef:V}=w;b.useEffect(()=>{if(E){let z={x:0,y:0};const ee=he=>{z={x:Math.abs(Math.round(he.pageX)-(V.current?.x??0)),y:Math.abs(Math.round(he.pageY)-(V.current?.y??0))}},Oe=he=>{z.x<=10&&z.y<=10?he.preventDefault():E.contains(he.target)||R(!1),document.removeEventListener("pointermove",ee),V.current=null};return V.current!==null&&(document.addEventListener("pointermove",ee),document.addEventListener("pointerup",Oe,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",ee),document.removeEventListener("pointerup",Oe,{capture:!0})}}},[E,R,V]),b.useEffect(()=>{const z=()=>R(!1);return window.addEventListener("blur",z),window.addEventListener("resize",z),()=>{window.removeEventListener("blur",z),window.removeEventListener("resize",z)}},[R]);const[ie,ne]=C_(z=>{const ee=$().filter(we=>!we.disabled),Oe=ee.find(we=>we.ref.current===document.activeElement),he=A_(ee,z,Oe);he&&setTimeout(()=>he.ref.current.focus())}),ye=b.useCallback((z,ee,Oe)=>{const he=!j.current&&!Oe;(w.value!==void 0&&w.value===ee||he)&&(_(z),he&&(j.current=!0))},[w.value]),G=b.useCallback(()=>E?.focus(),[E]),Z=b.useCallback((z,ee,Oe)=>{const he=!j.current&&!Oe;(w.value!==void 0&&w.value===ee||he)&&L(z)},[w.value]),J=r==="popper"?Mv:f_,me=J===Mv?{side:a,sideOffset:l,align:c,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:h,sticky:p,hideWhenDetached:m,avoidCollisions:y}:{};return g.jsx(u_,{scope:n,content:E,viewport:T,onViewportChange:S,itemRefCallback:ye,selectedItem:C,onItemLeave:G,itemTextRefCallback:Z,focusSelectedItem:H,selectedItemText:N,position:r,isPositioned:B,searchRef:ie,children:g.jsx(Xa,{as:LZ,allowPinchZoom:!0,children:g.jsx(Ja,{asChild:!0,trapped:w.open,onMountAutoFocus:z=>{z.preventDefault()},onUnmountAutoFocus:te(o,z=>{w.trigger?.focus({preventScroll:!0}),z.preventDefault()}),children:g.jsx(ki,{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:te(v.onKeyDown,z=>{const ee=z.ctrlKey||z.altKey||z.metaKey;if(z.key==="Tab"&&z.preventDefault(),!ee&&z.key.length===1&&ne(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()}})})})})})})});d_.displayName=PZ;var jZ="SelectItemAlignedPosition",f_=b.forwardRef((t,e)=>{const{__scopeSelect:n,onPlaced:r,...o}=t,s=fs(ni,n),i=hs(ni,n),[a,l]=b.useState(null),[c,u]=b.useState(null),d=$e(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(),_=s.valueNode.getBoundingClientRect(),N=v.getBoundingClientRect();if(s.dir!=="rtl"){const we=N.left-C.left,Se=_.left-we,Ve=k.left-Se,ut=k.width+Ve,dt=Math.max(ut,C.width),Ot=window.innerWidth-Sr,yt=t_(Se,[Sr,Math.max(Sr,Ot-dt)]);a.style.minWidth=ut+"px",a.style.left=yt+"px"}else{const we=C.right-N.right,Se=window.innerWidth-_.right-we,Ve=window.innerWidth-k.right-Se,ut=k.width+Ve,dt=Math.max(ut,C.width),Ot=window.innerWidth-Sr,yt=t_(Se,[Sr,Math.max(Sr,Ot-dt)]);a.style.minWidth=ut+"px",a.style.right=yt+"px"}const L=f(),$=window.innerHeight-Sr*2,B=m.scrollHeight,U=window.getComputedStyle(c),j=parseInt(U.borderTopWidth,10),P=parseInt(U.paddingTop,10),H=parseInt(U.borderBottomWidth,10),R=parseInt(U.paddingBottom,10),V=j+P+B+R+H,ie=Math.min(y.offsetHeight*5,V),ne=window.getComputedStyle(m),ye=parseInt(ne.paddingTop,10),G=parseInt(ne.paddingBottom,10),Z=k.top+k.height/2-Sr,J=$-Z,me=y.offsetHeight/2,z=y.offsetTop+me,ee=j+P+z,Oe=V-ee;if(ee<=Z){const we=L.length>0&&y===L[L.length-1].ref.current;a.style.bottom="0px";const Se=c.clientHeight-m.offsetTop-m.offsetHeight,Ve=Math.max(J,me+(we?G:0)+Se+H),ut=ee+Ve;a.style.height=ut+"px"}else{const we=L.length>0&&y===L[0].ref.current;a.style.top="0px";const Ve=Math.max(Z,j+m.offsetTop+(we?ye:0)+me)+Oe;a.style.height=Ve+"px",m.scrollTop=ee-Z+m.offsetTop}a.style.margin=`${Sr}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]);Ct(()=>E(),[E]);const[x,T]=b.useState();Ct(()=>{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(BZ,{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}})})})});f_.displayName=jZ;var $Z="SelectPopperPosition",Mv=b.forwardRef((t,e)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=Sr,...s}=t,i=Hf(n);return g.jsx(Nu,{...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)"}})});Mv.displayName=$Z;var[BZ,Ov]=sa(ni,{}),Nv="SelectViewport",h_=b.forwardRef((t,e)=>{const{__scopeSelect:n,nonce:r,...o}=t,s=hs(Nv,n),i=Ov(Nv,n),a=$e(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:te(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-Sr*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})})})]})});h_.displayName=Nv;var p_="SelectGroup",[FZ,HZ]=sa(p_),UZ=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,o=Bn();return g.jsx(FZ,{scope:n,id:o,children:g.jsx(ge.div,{role:"group","aria-labelledby":o,...r,ref:e})})});UZ.displayName=p_;var m_="SelectLabel",zZ=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,o=HZ(m_,n);return g.jsx(ge.div,{id:o.id,...r,ref:e})});zZ.displayName=m_;var Uf="SelectItem",[VZ,g_]=sa(Uf),y_=b.forwardRef((t,e)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=t,a=fs(Uf,n),l=hs(Uf,n),c=a.value===r,[u,d]=b.useState(s??""),[f,h]=b.useState(!1),p=$e(e,w=>l.itemRefCallback?.(w,r,o)),m=Bn(),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(VZ,{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:te(i.onFocus,()=>h(!0)),onBlur:te(i.onBlur,()=>h(!1)),onClick:te(i.onClick,()=>{y.current!=="mouse"&&v()}),onPointerUp:te(i.onPointerUp,()=>{y.current==="mouse"&&v()}),onPointerDown:te(i.onPointerDown,w=>{y.current=w.pointerType}),onPointerMove:te(i.onPointerMove,w=>{y.current=w.pointerType,o?l.onItemLeave?.():y.current==="mouse"&&w.currentTarget.focus({preventScroll:!0})}),onPointerLeave:te(i.onPointerLeave,w=>{w.currentTarget===document.activeElement&&l.onItemLeave?.()}),onKeyDown:te(i.onKeyDown,w=>{l.searchRef?.current!==""&&w.key===" "||(MZ.includes(w.key)&&v(),w.key===" "&&w.preventDefault())})})})})});y_.displayName=Uf;var rc="SelectItemText",v_=b.forwardRef((t,e)=>{const{__scopeSelect:n,className:r,style:o,...s}=t,i=fs(rc,n),a=hs(rc,n),l=g_(rc,n),c=RZ(rc,n),[u,d]=b.useState(null),f=$e(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 Ct(()=>(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?sc.createPortal(s.children,i.valueNode):null]})});v_.displayName=rc;var b_="SelectItemIndicator",x_=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t;return g_(b_,n).isSelected?g.jsx(ge.span,{"aria-hidden":!0,...r,ref:e}):null});x_.displayName=b_;var _v="SelectScrollUpButton",w_=b.forwardRef((t,e)=>{const n=hs(_v,t.__scopeSelect),r=Ov(_v,t.__scopeSelect),[o,s]=b.useState(!1),i=$e(e,r.onScrollButtonChange);return Ct(()=>{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(S_,{...t,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});w_.displayName=_v;var Rv="SelectScrollDownButton",E_=b.forwardRef((t,e)=>{const n=hs(Rv,t.__scopeSelect),r=Ov(Rv,t.__scopeSelect),[o,s]=b.useState(!1),i=$e(e,r.onScrollButtonChange);return Ct(()=>{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(S_,{...t,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});E_.displayName=Rv;var S_=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]),Ct(()=>{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:te(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:te(o.onPointerMove,()=>{s.onItemLeave?.(),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:te(o.onPointerLeave,()=>{l()})})}),WZ="SelectSeparator",GZ=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t;return g.jsx(ge.div,{"aria-hidden":!0,...r,ref:e})});GZ.displayName=WZ;var Iv="SelectArrow",qZ=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,o=Hf(n),s=fs(Iv,n),i=hs(Iv,n);return s.open&&i.position==="popper"?g.jsx(_u,{...o,...r,ref:e}):null});qZ.displayName=Iv;var KZ="SelectBubbleInput",k_=b.forwardRef(({__scopeSelect:t,value:e,...n},r)=>{const o=b.useRef(null),s=$e(r,o),i=AC(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:{...JS,...n.style},ref:s,defaultValue:e})});k_.displayName=KZ;function T_(t){return t===""||t===void 0}function C_(t){const e=ir(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 A_(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=YZ(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 YZ(t,e){return t.map((n,r)=>t[(e+r)%t.length])}var JZ=n_,XZ=o_,QZ=i_,ZZ=a_,eee=l_,tee=c_,nee=h_,ree=y_,oee=v_,see=x_,iee=w_,aee=E_;function lee({...t}){return g.jsx(JZ,{"data-slot":"select",...t})}function cee({...t}){return g.jsx(QZ,{"data-slot":"select-value",...t})}function uee({className:t,size:e="default",children:n,...r}){return g.jsxs(XZ,{"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(ZZ,{asChild:!0,children:g.jsx(Yk,{className:"size-4 opacity-50"})})]})}function dee({className:t,children:e,position:n="popper",align:r="center",...o}){return g.jsx(eee,{children:g.jsx("div",{id:"select-wrapper","data-theme":"select-post-builder",children:g.jsxs(tee,{"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(hee,{}),g.jsx(nee,{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(pee,{})]})})})}function fee({className:t,children:e,...n}){return g.jsxs(ree,{"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(see,{children:g.jsx(Kk,{className:"size-4"})})}),g.jsx(oee,{children:e})]})}function hee({className:t,...e}){return g.jsx(iee,{"data-slot":"select-scroll-up-button",className:re("flex cursor-default items-center justify-center py-1",t),...e,children:g.jsx(Jz,{className:"size-4"})})}function pee({className:t,...e}){return g.jsx(aee,{"data-slot":"select-scroll-down-button",className:re("flex cursor-default items-center justify-center py-1",t),...e,children:g.jsx(Yk,{className:"size-4"})})}function mee(){return Ph.useSyncExternalStore(gee,()=>!0,()=>!1)}function gee(){return()=>{}}var Dv="Avatar",[yee]=Nn(Dv),[vee,M_]=yee(Dv),O_=b.forwardRef((t,e)=>{const{__scopeAvatar:n,...r}=t,[o,s]=b.useState("idle");return g.jsx(vee,{scope:n,imageLoadingStatus:o,onImageLoadingStatusChange:s,children:g.jsx(ge.span,{...r,ref:e})})});O_.displayName=Dv;var N_="AvatarImage",__=b.forwardRef((t,e)=>{const{__scopeAvatar:n,src:r,onLoadingStatusChange:o=()=>{},...s}=t,i=M_(N_,n),a=bee(r,s),l=ir(c=>{o(c),i.onImageLoadingStatusChange(c)});return Ct(()=>{a!=="idle"&&l(a)},[a,l]),a==="loaded"?g.jsx(ge.img,{...s,ref:e,src:r}):null});__.displayName=N_;var R_="AvatarFallback",I_=b.forwardRef((t,e)=>{const{__scopeAvatar:n,delayMs:r,...o}=t,s=M_(R_,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});I_.displayName=R_;function D_(t,e){return t?e?(t.src!==e&&(t.src=e),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function bee(t,{referrerPolicy:e,crossOrigin:n}){const r=mee(),o=b.useRef(null),s=r?(o.current||(o.current=new window.Image),o.current):null,[i,a]=b.useState(()=>D_(s,t));return Ct(()=>{a(D_(s,t))},[s,t]),Ct(()=>{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 xee=O_,wee=__,Eee=I_;function P_({className:t,...e}){return g.jsx(xee,{"data-slot":"avatar",className:re("relative flex size-8 shrink-0 overflow-hidden rounded-full",t),...e})}function L_({className:t,...e}){return g.jsx(wee,{"data-slot":"avatar-image",className:re("aspect-square size-full",t),...e})}function j_({className:t,...e}){return g.jsx(Eee,{"data-slot":"avatar-fallback",className:re("bg-muted flex size-full items-center justify-center rounded-full",t),...e})}const See=({user:t,store:e})=>{const{core:n}=ga(),[r,o]=M.useState([]),[s,i]=M.useState(!1),a=Jr(),[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(P_,{children:[g.jsx(L_,{src:t?.avatar??t?.avatarPlaceholder}),g.jsx(j_,{className:"bg-primary-send text-background",children:t?.name?.charAt(0)})]}),g.jsxs(lee,{value:f,onValueChange:p,disabled:h||s,children:[g.jsx(uee,{size:"sm",id:`group-selector-${f}-${a}`,className:"bg-background","aria-label":"Select group",children:g.jsx(cee,{className:"text-sm",placeholder:s?"Loading groups...":"Select a group…"})}),g.jsx(dee,{align:"start",children:r.map(m=>g.jsxs(fee,{value:m.group_id,children:[g.jsxs(P_,{className:"size-6",children:[g.jsx(L_,{src:m.group.avatar}),g.jsx(j_,{children:m?.group?.name?.charAt(0)})]}),g.jsx("span",{className:"text-sm",children:m.group?.name??m.group_id})]},m.group_id))})]})]})};var kee=(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{}},Tee=b.createContext(void 0),Cee={setTheme:t=>{},themes:[]},Aee=()=>{var t;return(t=b.useContext(Tee))!=null?t:Cee};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:`(${kee.toString()})(${u})`}})});const Mee=({...t})=>{const{theme:e="system"}=Aee();return g.jsx(cD,{theme:e,className:"toaster group",style:{"--normal-bg":"var(--popover)","--normal-text":"var(--popover-foreground)","--normal-border":"var(--border)"},...t})},zf=t=>({html:t?.getHTML(),json:t?.getJSON(),text:t?.getText()}),Vf=()=>({postId:Jr(),timestamp:new Date().getTime(),specialType:Mb.POST}),Pv=t=>({mentionData:dl(t,"mention")?.map(r=>J6(e8(r.attrs,U6),["mentionSuggestionChar","label"]))?.filter(r=>Object.keys(r).length>0)}),Oee=t=>({items:dl(t,"media").map(r=>r.attrs?.payload)}),Nee=t=>({items:dl(t,"poll")[0].attrs?.choices}),_ee=({editor:t,sendCrossMention:e})=>{const{html:n,json:r}=zf(t),o=Vf(),s=PC(r,"text")?.text?.trim()??"",i=new Array(PC(r,"media")?.attrs?.payload).filter(Boolean),a=n;return{...o,type:pa.NEW_POST_MESSAGE,body:s,items:i,htmlBody:a,sendCrossMention:e,mentionData:[]}},Ree=({editor:t,sendCrossMention:e})=>{const{json:n,text:r}=zf(t),o=Vf(),s=r,{mentionData:i}=Pv(n),{items:a}=Oee(n);return{...o,type:pa.NEW_POST_MEDIA,body:s,items:a,mentionData:i,sendCrossMention:e}},Iee=({editor:t,sendCrossMention:e})=>{const{json:n,text:r}=zf(t),o=Vf(),s=r,{mentionData:i}=Pv(n);return{...o,type:pa.NEW_POST_MESSAGE,body:s,items:[],mentionData:i,sendCrossMention:e}},Dee=({editor:t,sendCrossMention:e})=>{const{json:n,text:r}=zf(t),o=Vf(),s=r,{mentionData:i}=Pv(n),{items:a}=Nee(n);return{...o,type:pa.NEW_POST_POLL,body:s,items:a,mentionData:i,sendCrossMention:e}},Pee=(t,e)=>{switch(t){case ht.Text:return _ee(e);case ht.Media:return Ree(e);case ht.Link:return Iee(e);case ht.Poll:return Dee(e);default:return null}},Lee=({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(ht.Text),{editor:h,actions:p,store:m}=fJ({editorType:d,groupId:t,postId:e,user:n}),{clearContent:y}=em(),v=M.useMemo(()=>({editor:h}),[h]),w=E=>{if(!h)return;const x=h?.getHTML(),T=h?.getJSON(),S=h?.getText(),k=Pee(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(Qp.Provider,{value:v,children:[r&&g.jsx(See,{user:n,store:m}),o?g.jsx(CZ,{open:c,onOpenChange:u,editor:h,actions:p,editorTab:d,onSwitchEditor:f,isSubmitting:i,onSubmit:w}):g.jsx(e_,{editor:h,actions:p,editorTab:d,onSwitchEditor:f,isSubmitting:i,onSubmit:w})]})}),g.jsx(Mee,{position:"top-center"})]}):null};vt.PostBuilderEditor=Lee,vt.PostBuilderProvider=SD,Object.defineProperty(vt,Symbol.toStringTag,{value:"Module"})}));
|
|
586
|
+
`?i.insert.slice(0,-1):i.insert;(typeof a!="string"||a.length>0)&&pv(r,this,o,a,i.attributes||{})}else i.retain!==void 0?RN(r,this,o,i.retain,i.attributes||{}):i.delete!==void 0&&DN(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(Xs(l,e)||n!==void 0&&Xs(l,n))switch(l.content.constructor){case xr:{const d=s.get("ychange");e!==void 0&&!Xs(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&&!Xs(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 wr:case Zs:{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:Xs(l,e)&&(c(),oa(s,l.content));break}l=l.right}c()};return e||n?Xe(i,d=>{e&&lv(d,e),n&&lv(d,n),u()},"cleanup"):u(),o}insert(e,n,r){if(n.length<=0)return;const o=this.doc;o!==null?Xe(o,s=>{const i=Af(s,this,e,!r);r||(r={},i.currentAttributes.forEach((a,l)=>{r[l]=a})),pv(s,this,i,n,r)}):this._pending.push(()=>this.insert(e,n,r))}insertEmbed(e,n,r){const o=this.doc;o!==null?Xe(o,s=>{const i=Af(s,this,e,!r);pv(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?Xe(r,o=>{DN(o,Af(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?Xe(o,s=>{const i=Af(s,this,e,!1);i.right!==null&&RN(s,this,i,n,r)}):this._pending.push(()=>this.format(e,n,r))}removeAttribute(e){this.doc!==null?Xe(this.doc,n=>{Tf(n,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,n){this.doc!==null?Xe(this.doc,r=>{dv(r,this,e,n)}):this._pending.push(()=>this.setAttribute(e,n))}getAttribute(e){return fv(this,e)}getAttributes(){return CN(this)}_write(e){e.writeTypeRef(MQ)}}const cQ=t=>new us;class mv{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===en||n.constructor===Qs)&&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 Qs extends $t{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 Qs}clone(){const e=new Qs;return e.insert(0,this.toArray().map(n=>n instanceof $t?n.clone():n)),e}get length(){return this.doc??Zt(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new mv(this,e)}querySelector(e){e=e.toUpperCase();const r=new mv(this,o=>o.nodeName&&o.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),Ks(new mv(this,n=>n.nodeName&&n.nodeName.toUpperCase()===e))}_callObserver(e,n){Sf(this,e,new fQ(this,n,e))}toString(){return wN(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),Ql(this,s=>{o.insertBefore(s.toDOM(e,n,r),null)}),o}insert(e,n){this.doc!==null?Xe(this.doc,r=>{kN(r,this,e,n)}):this._prelimContent.splice(e,0,...n)}insertAfter(e,n){if(this.doc!==null)Xe(this.doc,r=>{const o=e&&e instanceof $t?e._item:e;kf(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 as("Reference item not found");r.splice(o,0,...n)}}delete(e,n=1){this.doc!==null?Xe(this.doc,r=>{TN(r,this,e,n)}):this._prelimContent.splice(e,n)}toArray(){return bN(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return EN(this,e)}slice(e=0,n=this.length){return vN(this,e,n)}forEach(e){Ql(this,e)}_write(e){e.writeTypeRef(NQ)}}const uQ=t=>new Qs;class en extends Qs{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 en(this.nodeName)}clone(){const e=new en(this.nodeName),n=this.getAttributes();return QJ(n,(r,o)=>{typeof r=="string"&&e.setAttribute(o,r)}),e.insert(0,this.toArray().map(r=>r instanceof $t?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?Xe(this.doc,n=>{Tf(n,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,n){this.doc!==null?Xe(this.doc,r=>{dv(r,this,e,n)}):this._prelimAttrs.set(e,n)}getAttribute(e){return fv(this,e)}hasAttribute(e){return AN(this,e)}getAttributes(e){return e?eQ(this,e):CN(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 Ql(this,i=>{o.appendChild(i.toDOM(e,n,r))}),r!==void 0&&r._createAssociation(o,this),o}_write(e){e.writeTypeRef(OQ),e.writeKey(this.nodeName)}}const dQ=t=>new en(t.readKey());class fQ extends wf{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 Mf extends ra{constructor(e){super(),this.hookName=e}_copy(){return new Mf(this.hookName)}clone(){const e=new Mf(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(_Q),e.writeKey(this.hookName)}}const hQ=t=>new Mf(t.readKey());class Cn extends us{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 Cn}clone(){const e=new Cn;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(RQ)}}const pQ=t=>new Cn;class gv{constructor(e,n){this.id=e,this.length=n}get deleted(){throw vr()}mergeWith(e){return!1}write(e,n,r){throw vr()}integrate(e,n){throw vr()}}const mQ=0;class er extends gv{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),oN(e.doc.store,this)}write(e,n){e.writeInfo(mQ),e.writeLen(this.length-n)}getMissing(e,n){return null}}class Zl{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Zl(this.content)}splice(e){throw vr()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeBuf(this.content)}getRef(){return 3}}const gQ=t=>new Zl(t.readBuf());class ec{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new ec(this.len)}splice(e){const n=new ec(this.len-e);return this.len=e,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,n){ql(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 yQ=t=>new ec(t.readLen()),PN=(t,e)=>new Js({guid:t,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class tc{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 tc(PN(this.doc.guid,this.opts))}splice(e){throw vr()}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 vQ=t=>new tc(PN(t.readString(),t.readAny()));class Zs{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Zs(this.embed)}splice(e){throw vr()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeJSON(this.embed)}getRef(){return 5}}const bQ=t=>new Zs(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 vr()}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 xQ=t=>new kt(t.readKey(),t.readJSON());class Of{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Of(this.arr)}splice(e){const n=new Of(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 wQ=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 Of(n)},EQ=hf("node_env")==="development";class ei{constructor(e){this.arr=e,EQ&&jO(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ei(this.arr)}splice(e){const n=new ei(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 SQ=t=>{const e=t.readLen(),n=[];for(let r=0;r<e;r++)n.push(t.readAny());return new ei(n)};class xr{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new xr(this.str)}splice(e){const n=new xr(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 kQ=t=>new xr(t.readString()),TQ=[nQ,oQ,cQ,dQ,uQ,hQ,pQ],CQ=0,AQ=1,MQ=2,OQ=3,NQ=4,_Q=5,RQ=6;class wr{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new wr(this.type._copy())}splice(e){throw vr()}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 IQ=t=>new wr(TQ[t.readTypeRef()](t)),yv=(t,e)=>{let n=e,r=0,o;do r>0&&(n=Ie(n.client,n.clock+r)),o=ta(t,n),r=n.clock-o.id.clock,n=o.redone;while(n!==null&&o instanceof nt);return{item:o,diff:r}},vv=(t,e)=>{for(;t!==null&&t.keep!==e;)t.keep=e,t=t.parent._item},Nf=(t,e,n)=>{const{client:r,clock:o}=e.id,s=new nt(Ie(r,o+n),e,Ie(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=Ie(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},LN=(t,e)=>gJ(t,n=>Zi(n.deletions,e)),jN=(t,e,n,r,o,s)=>{const i=t.doc,a=i.store,l=i.clientID,c=e.redone;if(c!==null)return Tn(t,c);let u=e.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||jN(t,u,n,r,o,s)===null))return null;for(;u.redone!==null;)u=Tn(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:Tn(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:Tn(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||Zi(r,d.right.id)||LN(s.undoStack,d.right.id)||LN(s.redoStack,d.right.id));)for(d=d.right;d.redone;)d=Tn(t,d.redone);if(d&&d.right!==null)return null}else d=h._map.get(e.parentSub)||null;const p=bt(a,l),m=Ie(l,p),y=new nt(m,d,d&&d.lastId,f,f&&f.id,h,e.parentSub,e.content.copy());return e.redone=m,vv(y,!0),y.integrate(t,0),y};let nt=class Fv extends gv{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()?xO:0}set marker(e){(this.info&$y)>0!==e&&(this.info^=$y)}get marker(){return(this.info&$y)>0}get keep(){return(this.info&bO)>0}set keep(e){this.keep!==e&&(this.info^=bO)}get countable(){return(this.info&xO)>0}get deleted(){return(this.info&jy)>0}set deleted(e){this.deleted!==e&&(this.info^=jy)}markDeleted(){this.info|=jy}getMissing(e,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=bt(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=bt(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ea&&this.id.client!==this.parent.client&&this.parent.clock>=bt(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=sN(e,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Tn(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===er||this.right&&this.right.constructor===er)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===Fv?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===Fv&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===ea){const r=ta(n,this.parent);r.constructor===er?this.parent=null:this.parent=r.content.type}return null}integrate(e,n){if(n>0&&(this.id.clock+=n,this.left=sN(e,e.doc.store,Ie(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),gf(this.origin,o.origin)){if(o.id.client<this.id.client)r=o,s.clear();else if(gf(this.rightOrigin,o.rightOrigin))break}else if(o.origin!==null&&i.has(ta(e.doc.store,o.origin)))s.has(ta(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),oN(e.doc.store,this),this.content.integrate(e,this),lN(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new er(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:Ie(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&gf(e.origin,this.lastId)&&this.right===e&&gf(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(),ql(e.deleteSet,this.id.client,this.id.clock,this.length),lN(e,n,this.parentSub),this.content.delete(e)}}gc(e,n){if(!this.deleted)throw kn();this.content.gc(e),n?$X(e,this,new er(this.id,this.length)):this.content=new ec(this.length)}write(e,n){const r=n>0?Ie(this.id.client,this.id.clock+n-1):this.origin,o=this.rightOrigin,s=this.parentSub,i=this.content.getRef()&af|(r===null?0:fn)|(o===null?0:wo)|(s===null?0:Hl);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=Kl(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===ea?(e.writeParentInfo(!1),e.writeLeftID(a)):kn();s!==null&&e.writeString(s)}this.content.write(e,n)}};const $N=(t,e)=>DQ[e&af](t),DQ=[()=>{kn()},yQ,wQ,gQ,kQ,bQ,xQ,IQ,SQ,vQ,()=>{kn()}],PQ=10;class Er extends gv{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,n){kn()}write(e,n){e.writeInfo(PQ),Fe(e.restEncoder,this.length-n)}getMissing(e,n){return null}}const BN=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},FN="__ $YJS$ __";BN[FN]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),BN[FN]=!0;const LQ=()=>{let t=!0;return(e,n)=>{if(t){t=!1;try{e()}finally{t=!0}}else n!==void 0&&n()}},jQ=/[\uD800-\uDBFF]/,$Q=/[\uDC00-\uDFFF]/,BQ=(t,e)=>{let n=0,r=0;for(;n<t.length&&n<e.length&&t[n]===e[n];)n++;for(n>0&&jQ.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&&$Q.test(t[t.length-r])&&r--,{index:n,remove:t.length-n-r,insert:e.slice(n,e.length-r)}},Vr=(t,e)=>t>>>e|t<<32-e,FQ=t=>Vr(t,2)^Vr(t,13)^Vr(t,22),HQ=t=>Vr(t,6)^Vr(t,11)^Vr(t,25),UQ=t=>Vr(t,7)^Vr(t,18)^t>>>3,zQ=t=>Vr(t,17)^Vr(t,19)^t>>>10,VQ=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]),WQ=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class GQ{constructor(){const e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(WQ),this._W=new Uint32Array(e,64,64)}_updateHash(){const e=this._H,n=this._W;for(let d=16;d<64;d++)n[d]=zQ(n[d-2])+n[d-7]+UQ(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+HQ(a)+(a&l^~a&c)+VQ[d]+n[d]>>>0,h=FQ(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]|=fn<<(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)]|=fn<<(3-n%4)*8),this._W[14]=e.byteLength/yJ,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 qQ=t=>new GQ().digest(t),gt=new ze("y-sync"),ko=new ze("y-undo");new ze("yjs-cursor");const KQ=t=>{for(let n=6;n<t.length;n++)t[n%6]=t[n%6]^t[n];return t.slice(0,6)},YQ=t=>iX(KQ(qQ(aX(t)))),_f=(t,e)=>e===void 0?!t.deleted:e.sv.has(t.id.client)&&e.sv.get(t.id.client)>t.id.clock&&!Zi(e.ds,t.id),JQ=[{light:"#ecd44433",dark:"#ecd444"}],XQ=(t,e,n)=>{if(!t.has(n)){if(t.size<e.length){const r=qs();t.forEach(o=>r.add(o)),e=e.filter(o=>!r.has(o))}t.set(n,VJ(e))}return t.get(n)},QQ=(t,{colors:e=JQ,colorMapping:n=new Map,permanentUserData:r=null,onFirstRender:o=()=>{},mapping:s}={})=>{let i=!1;const a=new eZ(t,s),l=new He({props:{editable:c=>{const u=gt.getState(c);return u.snapshot==null&&u.prevSnapshot==null}},key:gt,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(gt);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)&&FO(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=ko.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)},gt)})}},destroy:()=>{a.destroy()}})});return l},ZQ=(t,e,n)=>{if(e!==null&&e.anchor!==null&&e.head!==null)if(e.type==="all")t.setSelection(new vn(t.doc));else if(e.type==="node"){const r=Pf(n.doc,n.type,e.anchor,n.mapping);t.setSelection(ue.create(t.doc,r))}else{const r=Pf(n.doc,n.type,e.anchor,n.mapping),o=Pf(n.doc,n.type,e.head,n.mapping);r!==null&&o!==null&&t.setSelection(pe.between(t.doc.resolve(r),t.doc.resolve(o)))}},bv=(t,e)=>({type:e.selection.jsonID,anchor:Tv(e.selection.anchor,t.type,t.mapping),head:Tv(e.selection.head,t.type,t.mapping)});class eZ{constructor(e,n=new Map){this.type=e,this.prosemirrorView=null,this.mux=LQ(),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=bv(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()?($O&&this._domSelectionInView===null&&(FO(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=cX.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=nN(KO(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(gt,{snapshot:e,prevSnapshot:n}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{const e=this.type.toArray().map(r=>Rf(r,this.prosemirrorView.state.schema,this)).filter(r=>r!==null),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Q(F.from(e),0,0));n.setMeta(gt,{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=>Rf(o,this.prosemirrorView.state.schema,this)).filter(o=>o!==null),r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Q(F.from(n),0,0));if(e){const o=Ki(is(e.anchor,0),r.doc.content.size),s=Ki(is(e.head,0),r.doc.content.size);r.setSelection(pe.create(r.doc,o,s))}this.prosemirrorView.dispatch(r.setMeta(gt,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,n,r){let o=this.doc,s=this.type;if(e||(e=av(this.doc)),e instanceof Uint8Array||n instanceof Uint8Array)if((!(e instanceof Uint8Array)||!(n instanceof Uint8Array))&&kn(),o=new Js({gc:!1}),ov(o,n),n=av(o),ov(o,e),e=av(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=br(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=>{ls(i,d,f=>{})});const l=(d,f)=>{const h=d==="added"?a.getUserByClientId(f.client):a.getUserByDeletedId(f);return{user:h,type:d,color:XQ(r.colorMapping,r.colors,h)}},c=xN(s,new iv(n.ds,e.sv)).map(d=>!d._item.deleted||_f(d._item,e)||_f(d._item,n)?Rf(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 Q(F.from(c),0,0));this.prosemirrorView.dispatch(u.setMeta(gt,{isChangeOrigin:!0}))},gt)})}_typeChanged(e,n){if(this.prosemirrorView==null)return;const r=gt.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);ls(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=>HN(a,this.prosemirrorView.state.schema,this)).filter(a=>a!==null);let i=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Q(F.from(s),0,0));ZQ(i,this.beforeTransactionSelection,this),i=i.setMeta(gt,{isChangeOrigin:!0,isUndoRedoOperation:n.origin instanceof fN}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&i.scrollIntoView(),this.prosemirrorView.dispatch(i)})}_prosemirrorChanged(e){this.doc.transact(()=>{Sv(this.doc,this.type,e,this),this.beforeTransactionSelection=bv(this,this.prosemirrorView.state)},gt)}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 HN=(t,e,n,r,o,s)=>{const i=n.mapping.get(t);if(i===void 0){if(t instanceof en)return Rf(t,e,n,r,o,s);throw vr()}return i},Rf=(t,e,n,r,o,s)=>{const i=[],a=l=>{if(l instanceof en){const c=HN(l,e,n,r,o,s);c!==null&&i.push(c)}else{const c=l._item.right?.content?.type;c instanceof us&&!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=tZ(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):xN(t,new iv(o.ds,r.sv)).forEach(a);try{const l=t.getAttributes(r);r!==void 0&&(_f(t._item,r)?_f(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)},gt),n.mapping.delete(t),null}},tZ=(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,aZ(c.attributes,e)))}}catch{return t.doc.transact(c=>{t._item.delete(c)},gt),null}return i},nZ=(t,e)=>{const n=new Cn,r=t.map(o=>({insert:o.text,attributes:WN(o.marks,e)}));return n.applyDelta(r),e.mapping.set(n,t),n},rZ=(t,e)=>{const n=new en(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,If(t).map(r=>xv(r,e))),e.mapping.set(n,t),n},xv=(t,e)=>t instanceof Array?nZ(t,e):rZ(t,e),UN=t=>typeof t=="object"&&t!==null,wv=(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||UN(i)&&UN(a)&&wv(i,a)}return r},If=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},zN=(t,e)=>{const n=t.toDelta();return n.length===e.length&&n.every((r,o)=>r.insert===e[o].text&&DO(r.attributes||{}).length===e[o].marks.length&&LO(r.attributes,(s,i)=>{const a=Ev(i),l=e[o].marks;return wv(s,l.find(c=>c.type.name===a)?.attrs)}))},nc=(t,e)=>{if(t instanceof en&&!(e instanceof Array)&&kv(t,e)){const n=If(e);return t._length===n.length&&wv(t.getAttributes(),e.attrs)&&t.toArray().every((r,o)=>nc(r,n[o]))}return t instanceof Cn&&e instanceof Array&&zN(t,e)},Df=(t,e)=>t===e||t instanceof Array&&e instanceof Array&&t.length===e.length&&t.every((n,r)=>e[r]===n),VN=(t,e,n)=>{const r=t.toArray(),o=If(e),s=o.length,i=r.length,a=Ki(i,s);let l=0,c=0,u=!1;for(;l<a;l++){const d=r[l],f=o[l];if(Df(n.mapping.get(d),f))u=!0;else if(!nc(d,f))break}for(;l+c<a;c++){const d=r[i-c-1],f=o[s-c-1];if(Df(n.mapping.get(d),f))u=!0;else if(!nc(d,f))break}return{equalityFactor:l+c,foundMappedChild:u}},oZ=t=>{let e="",n=t._start;const r={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof xr?e+=n.content.str:n.content instanceof kt&&(r[n.content.key]=null)),n=n.right;return{str:e,nAttrs:r}},sZ=(t,e,n)=>{n.mapping.set(t,e);const{nAttrs:r,str:o}=oZ(t),s=e.map(c=>({insert:c.text,attributes:Object.assign({},r,WN(c.marks,n))})),{insert:i,remove:a,index:l}=BQ(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})))},iZ=/(.*)(--[a-zA-Z0-9+/=]{8})$/,Ev=t=>iZ.exec(t)?.[1]??t,aZ=(t,e)=>{const n=[];for(const r in t)n.push(e.mark(Ev(r),t[r]));return n},WN=(t,e)=>{const n={};return t.forEach(r=>{if(r.type.name!=="ychange"){const o=bo(e.isOMark,r.type,()=>!r.type.excludes(r.type));n[o?`${r.type.name}--${YQ(r.toJSON())}`:r.type.name]=r.attrs}}),n},Sv=(t,e,n,r)=>{if(e instanceof en&&e.nodeName!==n.type.name)throw new Error("node name mismatch!");if(r.mapping.set(e,n),e instanceof en){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=If(n),s=o.length,i=e.toArray(),a=i.length,l=Ki(s,a);let c=0,u=0;for(;c<l;c++){const d=i[c],f=o[c];if(!Df(r.mapping.get(d),f))if(nc(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(!Df(r.mapping.get(d),f))if(nc(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 Cn&&h instanceof Array)zN(f,h)||sZ(f,h,r),c+=1;else{let y=f instanceof en&&kv(f,h),v=p instanceof en&&kv(p,m);if(y&&v){const w=VN(f,h,r),E=VN(p,m,r);w.foundMappedChild&&!E.foundMappedChild?v=!1:!w.foundMappedChild&&E.foundMappedChild||w.equalityFactor<E.equalityFactor?y=!1:v=!1}y?(Sv(t,f,h,r),c+=1):v?(Sv(t,p,m,r),u+=1):(r.mapping.delete(e.get(c)),e.delete(c,1),e.insert(c,[xv(h,r)]),c+=1)}}const d=a-c-u;if(a===1&&s===0&&i[0]instanceof Cn?(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(xv(o[h],r));e.insert(c,f)}},gt)},kv=(t,e)=>!(e instanceof Array)&&t.nodeName===e.type.name,Tv=(t,e,n)=>{if(t===0)return sv(e,0,-1);let r=e._first===null?null:e._first.content.type;for(;r!==null&&e!==r;){if(r instanceof Cn){if(r._length>=t)return sv(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 yf(r._item===null?null:r._item.id,r._item===null?Kl(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 yf(r._item===null?null:r._item.id,r._item===null?Kl(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 kn();if(t===0&&r.constructor!==Cn&&r!==e)return lZ(r._item.parent,r._item)}return sv(e,e._length,-1)},lZ=(t,e)=>{let n=null,r=null;return t._item===null?r=Kl(t):n=Ie(t._item.id.client,t._item.id.clock),new yf(n,r,e.id)},Pf=(t,e,n,r)=>{const o=jX(n,t);if(o===null||o.type!==e&&!Yl(e,o.type._item))return null;let s=o.type,i=0;if(s.constructor===Cn)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 Cn?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 Cn?i+=c._length:i+=r.get(c).nodeSize),l=l.right}}s=a}return i-1};function cZ(t){const e=t.toArray(),n=r=>{let o;if(r instanceof Cn)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:Ev(l)};return Object.keys(c)&&(d.attrs=c),d})),a});else if(r instanceof en){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 kn();return o};return{type:"doc",content:e.map(n)}}const uZ=t=>{const e=ko.getState(t).undoManager;if(e!=null)return e.undo(),!0},dZ=t=>{const e=ko.getState(t).undoManager;if(e!=null)return e.redo(),!0},fZ=new Set(["paragraph"]),hZ=(t,e)=>!(t instanceof nt)||!(t.content instanceof wr)||!(t.content.type instanceof us||t.content.type instanceof en&&e.has(t.content.type.nodeName))||t.content.type._length===0,pZ=({protectedNodes:t=fZ,trackedOrigins:e=[],undoManager:n=null}={})=>new He({key:ko,state:{init:(r,o)=>{const s=gt.getState(o),i=n||new fN(s.type,{trackedOrigins:new Set([gt].concat(e)),deleteFilter:a=>hZ(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=gt.getState(i).binding,l=o.undoManager,c=l.undoStack.length>0,u=l.redoStack.length>0;return a?{undoManager:l,prevSel:bv(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=gt.getState(r.state),s=ko.getState(r.state).undoManager;return s.on("stack-item-added",({stackItem:i})=>{const a=o.binding;a&&i.meta.set(a,ko.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()}}}});Je.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),ko.getState(e).undoManager.undoStack.length===0?!1:n?uZ(e):!0),redo:()=>({tr:t,state:e,dispatch:n})=>(t.setMeta("preventDispatch",!0),ko.getState(e).undoManager.redoStack.length===0?!1:n?dZ(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=pZ(this.options.yUndoOptions),r=n.spec.view;n.spec.view=i=>{const{undoManager:a}=ko.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=QQ(e,o);return this.editor.options.enableContentCheck&&((t=e.doc)==null||t.on("beforeTransaction",()=>{try{const i=cZ(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 He({key:new ze("filterInvalidContent"),filterTransaction:()=>{var i;return this.storage.isDisabled!==!1&&((i=e.doc)==null||i.destroy()),!0}})].filter(Boolean)}});function mZ(t){return!!t.getMeta(gt)}function GN(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(Vt.node(o,o+s.nodeSize,{class:"ProseMirror-selectednoderange"}))}),et.create(n,e)}function Lf(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 wa(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 Px(o.resolve(c),o.resolve(u));r.push(d)}),r}var gZ=class q_{constructor(e,n){this.anchor=e,this.head=n}map(e){return new q_(e.map(this.anchor),e.map(this.head))}resolve(e){const n=e.resolve(this.anchor),r=e.resolve(this.head);return new ds(n,r)}},ds=class ps extends Me{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=Lf(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 ps&&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 ps(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 ps(s,i,this.depth)}const n=this.ranges[0],r=e.resolve(Math.max(0,n.$from.pos-1));return new ps(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 ps(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 ps(this.$anchor,r,this.depth)}static fromJSON(e,n){return new ps(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 gZ(this.anchor,this.head)}};ds.prototype.visible=!1;function jf(t){return t instanceof ds}Je.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(!jf(s)){const u=ds.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(!jf(s)){const u=ds.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=ds.create(o,0,o.content.size,e);return s.setSelection(i),n.dispatch(s),!0}}},onSelectionUpdate(){const{selection:t}=this.editor.state;jf(t)&&this.editor.view.dom.classList.add("ProseMirror-noderangeselection")},addProseMirrorPlugins(){let t=!1,e=!1;return[new He({key:new ze("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=ds.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=jf(r);if(t=!1,!e)return o?(t=!0,GN(r.ranges)):null;const{$from:s,$to:i}=r;if(!o&&s.sameParent(i))return null;const a=Lf(s,i,this.options.depth);return a.length?(t=!0,GN(a)):null}}})]}});function yZ(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 vZ(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=yZ(o)}),e}var qN=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 $f(t,e){return window.getComputedStyle(t)[e]}function bZ(t=0,e=0,n=0){return Math.min(Math.max(t,e),n)}function xZ(t,e,n){const r=parseInt($f(t.dom,"paddingLeft"),10),o=parseInt($f(t.dom,"paddingRight"),10),s=parseInt($f(t.dom,"borderLeftWidth"),10),i=parseInt($f(t.dom,"borderLeftWidth"),10),a=t.dom.getBoundingClientRect();return{left:bZ(e,a.left+r+s,a.right-o-i),top:n}}function KN(t){var e;(e=t.parentNode)==null||e.removeChild(t)}function wZ(t,e){const{doc:n}=e.view.state,r=qN({editor:e,x:t.clientX,y:t.clientY,direction:"right"});if(!r.resultNode||r.pos===null)return[];const o=t.clientX,s=xZ(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 Lf(c,u,0)}function EZ(t,e){const{view:n}=e;if(!t.dataTransfer)return;const{empty:r,$from:o,$to:s}=n.state.selection,i=wZ(t,e),a=Lf(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=ds.create(n.state.doc,f,h),m=p.content();c.forEach(y=>{const v=n.nodeDOM(y.$from.pos),w=vZ(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",()=>KN(d),{once:!0})}var YN=(t,e)=>{const n=t.resolve(e),{depth:r}=n;return r===0?e:n.pos-n.parentOffset-1},JN=(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},Cv=(t,e)=>{const n=gt.getState(t);return n?Tv(e,n.type,n.binding.mapping):null},SZ=(t,e)=>{const n=gt.getState(t);return n?Pf(n.doc,n.type,e,n.binding.mapping)||0:-1},XN=(t,e)=>{let n=e;for(;n?.parentNode&&n.parentNode!==t.dom;)n=n.parentNode;return n},QN=new ze("dragHandle"),ZN=({pluginKey:t=QN,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()};LS(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),EZ(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 He({key:typeof t=="string"?new ze(t):t,state:{init(){return{locked:!1}},apply(x,T,S,k){const C=x.getMeta("lockDragHandle"),_=x.getMeta("hideDragHandle");if(C!==void 0&&(c=C),_)return m(),c=!1,u=null,d=-1,s?.({editor:n,node:null,pos:-1}),T;if(x.docChanged&&d!==-1&&e)if(mZ(x)){const N=SZ(k,f);N!==d&&(d=N)}else{const N=x.mapping.map(d);N!==d&&(d=N,f=Cv(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=XN(x,C),C===x.dom||C?.nodeType!==1)return;const _=x.posAtDOM(C,0),N=JN(n.state.doc,_),L=YN(n.state.doc,_);u=N,d=L,f=Cv(x.state,d),s?.({editor:n,node:u,pos:d}),v(C)},destroy(){h&&(cancelAnimationFrame(h),h=null,p=null),e&&KN(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=qN({x:S,y:k,direction:"right",editor:n});if(!C.resultElement)return;let _=C.resultElement;if(_=XN(x,_),_===x.dom||_?.nodeType!==1)return;const N=x.posAtDOM(_,0),L=JN(n.state.doc,N);if(L!==u){const $=YN(n.state.doc,N);u=L,d=$,f=Cv(x.state,d),s?.({editor:n,node:u,pos:d}),v(_),y()}})),!1}}}})}},Av={placement:"left-start",strategy:"absolute"};Je.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[ZN({computePositionConfig:{...Av,...this.options.computePositionConfig},getReferencedVirtualElement:this.options.getReferencedVirtualElement,element:t,editor:this.editor,onNodeChange:this.options.onNodeChange}).plugin]}});var kZ=t=>{const{className:e="drag-handle",children:n,editor:r,pluginKey:o=QN,onNodeChange:s,onElementDragStart:i,onElementDragEnd:a,computePositionConfig:l=Av}=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=ZN({editor:r,element:c,pluginKey:o,computePositionConfig:{...Av,...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})},TZ=kZ;const e_=({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(jF,{editorTab:n,onSwitchEditorTab:r}),g.jsx(NG,{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(TZ,{editor:t,className:re(" pr-2",n!==ht.Text&&"hidden size-0 overflow-hidden pointer-events-none"),children:g.jsx(Vn,{variant:"ghost",className:"bg-white cursor-grab py-0.5 px-0 border size-auto",children:g.jsx(Zz,{className:"text-muted-foreground"})})}),g.jsx(SF,{className:"grow overflow-y-auto","data-theme":"select-post-builder",editor:t})]})})]}),CZ=({open:t,onOpenChange:e,...n})=>g.jsx($m,{open:t,onOpenChange:e,children:g.jsx(Bm,{className:"bg-transparent border-0 p-0 lg:max-w-4xl -translate-1/2",showCloseButton:!1,children:g.jsx(e_,{...n,className:"bg-white max-h-dvh h-full"})})});function t_(t,[e,n]){return Math.min(n,Math.max(e,t))}var AZ=[" ","Enter","ArrowUp","ArrowDown"],MZ=[" ","Enter"],ti="Select",[Bf,Ff,OZ]=ph(ti),[sa]=Nn(ti,[OZ,qo]),Hf=qo(),[NZ,fs]=sa(ti),[_Z,RZ]=sa(ti),n_=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=Cc(c),[k,C]=Xr({prop:r,defaultProp:o??!1,onChange:s,caller:ti}),[_,N]=Xr({prop:i,defaultProp:a,onChange:l,caller:ti}),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(Ou,{...m,children:g.jsxs(NZ,{required:h,scope:e,trigger:y,onTriggerChange:v,valueNode:w,onValueNodeChange:E,valueNodeHasChildren:x,onValueNodeHasChildrenChange:T,contentId:Bn(),value:_,onValueChange:N,open:k,onOpenChange:C,dir:S,triggerPointerDownPosRef:L,disabled:f,children:[g.jsx(Bf.Provider,{scope:e,children:g.jsx(_Z,{scope:t.__scopeSelect,onNativeOptionAdd:b.useCallback(P=>{U(H=>new Set(H).add(P))},[]),onNativeOptionRemove:b.useCallback(P=>{U(H=>{const R=new Set(H);return R.delete(P),R})},[]),children:n})}),$?g.jsxs(k_,{"aria-hidden":!0,required:h,tabIndex:-1,name:u,autoComplete:d,value:_,onChange:P=>N(P.target.value),disabled:f,form:p,children:[_===void 0?g.jsx("option",{value:""}):null,Array.from(B)]},j):null]})})};n_.displayName=ti;var r_="SelectTrigger",o_=b.forwardRef((t,e)=>{const{__scopeSelect:n,disabled:r=!1,...o}=t,s=Hf(n),i=fs(r_,n),a=i.disabled||r,l=$e(e,i.onTriggerChange),c=Ff(n),u=b.useRef("touch"),[d,f,h]=C_(m=>{const y=c().filter(E=>!E.disabled),v=y.find(E=>E.value===i.value),w=A_(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(qa,{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":T_(i.value)?"":void 0,...o,ref:l,onClick:te(o.onClick,m=>{m.currentTarget.focus(),u.current!=="mouse"&&p(m)}),onPointerDown:te(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:te(o.onKeyDown,m=>{const y=d.current!=="";!(m.ctrlKey||m.altKey||m.metaKey)&&m.key.length===1&&f(m.key),!(y&&m.key===" ")&&AZ.includes(m.key)&&(p(),m.preventDefault())})})})});o_.displayName=r_;var s_="SelectValue",i_=b.forwardRef((t,e)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=t,l=fs(s_,n),{onValueNodeHasChildrenChange:c}=l,u=s!==void 0,d=$e(e,l.onValueNodeChange);return Ct(()=>{c(u)},[c,u]),g.jsx(ge.span,{...a,ref:d,style:{pointerEvents:"none"},children:T_(l.value)?g.jsx(g.Fragment,{children:i}):s})});i_.displayName=s_;var IZ="SelectIcon",a_=b.forwardRef((t,e)=>{const{__scopeSelect:n,children:r,...o}=t;return g.jsx(ge.span,{"aria-hidden":!0,...o,ref:e,children:r||"▼"})});a_.displayName=IZ;var DZ="SelectPortal",l_=t=>g.jsx(Oi,{asChild:!0,...t});l_.displayName=DZ;var ni="SelectContent",c_=b.forwardRef((t,e)=>{const n=fs(ni,t.__scopeSelect),[r,o]=b.useState();if(Ct(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?sc.createPortal(g.jsx(u_,{scope:t.__scopeSelect,children:g.jsx(Bf.Slot,{scope:t.__scopeSelect,children:g.jsx("div",{children:t.children})})}),s):null}return g.jsx(d_,{...t,ref:e})});c_.displayName=ni;var Sr=10,[u_,hs]=sa(ni),PZ="SelectContentImpl",LZ=Oo("SelectContent.RemoveScroll"),d_=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(ni,n),[E,x]=b.useState(null),[T,S]=b.useState(null),k=$e(e,z=>x(z)),[C,_]=b.useState(null),[N,L]=b.useState(null),$=Ff(n),[B,U]=b.useState(!1),j=b.useRef(!1);b.useEffect(()=>{if(E)return Uu(E)},[E]),Du();const P=b.useCallback(z=>{const[ee,...Oe]=$().map(Se=>Se.ref.current),[he]=Oe.slice(-1),we=document.activeElement;for(const Se of z)if(Se===we||(Se?.scrollIntoView({block:"nearest"}),Se===ee&&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:R,triggerPointerDownPosRef:V}=w;b.useEffect(()=>{if(E){let z={x:0,y:0};const ee=he=>{z={x:Math.abs(Math.round(he.pageX)-(V.current?.x??0)),y:Math.abs(Math.round(he.pageY)-(V.current?.y??0))}},Oe=he=>{z.x<=10&&z.y<=10?he.preventDefault():E.contains(he.target)||R(!1),document.removeEventListener("pointermove",ee),V.current=null};return V.current!==null&&(document.addEventListener("pointermove",ee),document.addEventListener("pointerup",Oe,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",ee),document.removeEventListener("pointerup",Oe,{capture:!0})}}},[E,R,V]),b.useEffect(()=>{const z=()=>R(!1);return window.addEventListener("blur",z),window.addEventListener("resize",z),()=>{window.removeEventListener("blur",z),window.removeEventListener("resize",z)}},[R]);const[ie,ne]=C_(z=>{const ee=$().filter(we=>!we.disabled),Oe=ee.find(we=>we.ref.current===document.activeElement),he=A_(ee,z,Oe);he&&setTimeout(()=>he.ref.current.focus())}),ye=b.useCallback((z,ee,Oe)=>{const he=!j.current&&!Oe;(w.value!==void 0&&w.value===ee||he)&&(_(z),he&&(j.current=!0))},[w.value]),G=b.useCallback(()=>E?.focus(),[E]),Z=b.useCallback((z,ee,Oe)=>{const he=!j.current&&!Oe;(w.value!==void 0&&w.value===ee||he)&&L(z)},[w.value]),J=r==="popper"?Mv:f_,me=J===Mv?{side:a,sideOffset:l,align:c,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:h,sticky:p,hideWhenDetached:m,avoidCollisions:y}:{};return g.jsx(u_,{scope:n,content:E,viewport:T,onViewportChange:S,itemRefCallback:ye,selectedItem:C,onItemLeave:G,itemTextRefCallback:Z,focusSelectedItem:H,selectedItemText:N,position:r,isPositioned:B,searchRef:ie,children:g.jsx(Xa,{as:LZ,allowPinchZoom:!0,children:g.jsx(Ja,{asChild:!0,trapped:w.open,onMountAutoFocus:z=>{z.preventDefault()},onUnmountAutoFocus:te(o,z=>{w.trigger?.focus({preventScroll:!0}),z.preventDefault()}),children:g.jsx(ki,{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:te(v.onKeyDown,z=>{const ee=z.ctrlKey||z.altKey||z.metaKey;if(z.key==="Tab"&&z.preventDefault(),!ee&&z.key.length===1&&ne(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()}})})})})})})});d_.displayName=PZ;var jZ="SelectItemAlignedPosition",f_=b.forwardRef((t,e)=>{const{__scopeSelect:n,onPlaced:r,...o}=t,s=fs(ni,n),i=hs(ni,n),[a,l]=b.useState(null),[c,u]=b.useState(null),d=$e(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(),_=s.valueNode.getBoundingClientRect(),N=v.getBoundingClientRect();if(s.dir!=="rtl"){const we=N.left-C.left,Se=_.left-we,Ve=k.left-Se,ut=k.width+Ve,dt=Math.max(ut,C.width),Ot=window.innerWidth-Sr,yt=t_(Se,[Sr,Math.max(Sr,Ot-dt)]);a.style.minWidth=ut+"px",a.style.left=yt+"px"}else{const we=C.right-N.right,Se=window.innerWidth-_.right-we,Ve=window.innerWidth-k.right-Se,ut=k.width+Ve,dt=Math.max(ut,C.width),Ot=window.innerWidth-Sr,yt=t_(Se,[Sr,Math.max(Sr,Ot-dt)]);a.style.minWidth=ut+"px",a.style.right=yt+"px"}const L=f(),$=window.innerHeight-Sr*2,B=m.scrollHeight,U=window.getComputedStyle(c),j=parseInt(U.borderTopWidth,10),P=parseInt(U.paddingTop,10),H=parseInt(U.borderBottomWidth,10),R=parseInt(U.paddingBottom,10),V=j+P+B+R+H,ie=Math.min(y.offsetHeight*5,V),ne=window.getComputedStyle(m),ye=parseInt(ne.paddingTop,10),G=parseInt(ne.paddingBottom,10),Z=k.top+k.height/2-Sr,J=$-Z,me=y.offsetHeight/2,z=y.offsetTop+me,ee=j+P+z,Oe=V-ee;if(ee<=Z){const we=L.length>0&&y===L[L.length-1].ref.current;a.style.bottom="0px";const Se=c.clientHeight-m.offsetTop-m.offsetHeight,Ve=Math.max(J,me+(we?G:0)+Se+H),ut=ee+Ve;a.style.height=ut+"px"}else{const we=L.length>0&&y===L[0].ref.current;a.style.top="0px";const Ve=Math.max(Z,j+m.offsetTop+(we?ye:0)+me)+Oe;a.style.height=Ve+"px",m.scrollTop=ee-Z+m.offsetTop}a.style.margin=`${Sr}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]);Ct(()=>E(),[E]);const[x,T]=b.useState();Ct(()=>{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(BZ,{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}})})})});f_.displayName=jZ;var $Z="SelectPopperPosition",Mv=b.forwardRef((t,e)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=Sr,...s}=t,i=Hf(n);return g.jsx(Nu,{...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)"}})});Mv.displayName=$Z;var[BZ,Ov]=sa(ni,{}),Nv="SelectViewport",h_=b.forwardRef((t,e)=>{const{__scopeSelect:n,nonce:r,...o}=t,s=hs(Nv,n),i=Ov(Nv,n),a=$e(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:te(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-Sr*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})})})]})});h_.displayName=Nv;var p_="SelectGroup",[FZ,HZ]=sa(p_),UZ=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,o=Bn();return g.jsx(FZ,{scope:n,id:o,children:g.jsx(ge.div,{role:"group","aria-labelledby":o,...r,ref:e})})});UZ.displayName=p_;var m_="SelectLabel",zZ=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,o=HZ(m_,n);return g.jsx(ge.div,{id:o.id,...r,ref:e})});zZ.displayName=m_;var Uf="SelectItem",[VZ,g_]=sa(Uf),y_=b.forwardRef((t,e)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=t,a=fs(Uf,n),l=hs(Uf,n),c=a.value===r,[u,d]=b.useState(s??""),[f,h]=b.useState(!1),p=$e(e,w=>l.itemRefCallback?.(w,r,o)),m=Bn(),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(VZ,{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:te(i.onFocus,()=>h(!0)),onBlur:te(i.onBlur,()=>h(!1)),onClick:te(i.onClick,()=>{y.current!=="mouse"&&v()}),onPointerUp:te(i.onPointerUp,()=>{y.current==="mouse"&&v()}),onPointerDown:te(i.onPointerDown,w=>{y.current=w.pointerType}),onPointerMove:te(i.onPointerMove,w=>{y.current=w.pointerType,o?l.onItemLeave?.():y.current==="mouse"&&w.currentTarget.focus({preventScroll:!0})}),onPointerLeave:te(i.onPointerLeave,w=>{w.currentTarget===document.activeElement&&l.onItemLeave?.()}),onKeyDown:te(i.onKeyDown,w=>{l.searchRef?.current!==""&&w.key===" "||(MZ.includes(w.key)&&v(),w.key===" "&&w.preventDefault())})})})})});y_.displayName=Uf;var rc="SelectItemText",v_=b.forwardRef((t,e)=>{const{__scopeSelect:n,className:r,style:o,...s}=t,i=fs(rc,n),a=hs(rc,n),l=g_(rc,n),c=RZ(rc,n),[u,d]=b.useState(null),f=$e(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 Ct(()=>(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?sc.createPortal(s.children,i.valueNode):null]})});v_.displayName=rc;var b_="SelectItemIndicator",x_=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t;return g_(b_,n).isSelected?g.jsx(ge.span,{"aria-hidden":!0,...r,ref:e}):null});x_.displayName=b_;var _v="SelectScrollUpButton",w_=b.forwardRef((t,e)=>{const n=hs(_v,t.__scopeSelect),r=Ov(_v,t.__scopeSelect),[o,s]=b.useState(!1),i=$e(e,r.onScrollButtonChange);return Ct(()=>{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(S_,{...t,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});w_.displayName=_v;var Rv="SelectScrollDownButton",E_=b.forwardRef((t,e)=>{const n=hs(Rv,t.__scopeSelect),r=Ov(Rv,t.__scopeSelect),[o,s]=b.useState(!1),i=$e(e,r.onScrollButtonChange);return Ct(()=>{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(S_,{...t,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});E_.displayName=Rv;var S_=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]),Ct(()=>{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:te(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:te(o.onPointerMove,()=>{s.onItemLeave?.(),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:te(o.onPointerLeave,()=>{l()})})}),WZ="SelectSeparator",GZ=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t;return g.jsx(ge.div,{"aria-hidden":!0,...r,ref:e})});GZ.displayName=WZ;var Iv="SelectArrow",qZ=b.forwardRef((t,e)=>{const{__scopeSelect:n,...r}=t,o=Hf(n),s=fs(Iv,n),i=hs(Iv,n);return s.open&&i.position==="popper"?g.jsx(_u,{...o,...r,ref:e}):null});qZ.displayName=Iv;var KZ="SelectBubbleInput",k_=b.forwardRef(({__scopeSelect:t,value:e,...n},r)=>{const o=b.useRef(null),s=$e(r,o),i=AC(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:{...JS,...n.style},ref:s,defaultValue:e})});k_.displayName=KZ;function T_(t){return t===""||t===void 0}function C_(t){const e=ir(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 A_(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=YZ(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 YZ(t,e){return t.map((n,r)=>t[(e+r)%t.length])}var JZ=n_,XZ=o_,QZ=i_,ZZ=a_,eee=l_,tee=c_,nee=h_,ree=y_,oee=v_,see=x_,iee=w_,aee=E_;function lee({...t}){return g.jsx(JZ,{"data-slot":"select",...t})}function cee({...t}){return g.jsx(QZ,{"data-slot":"select-value",...t})}function uee({className:t,size:e="default",children:n,...r}){return g.jsxs(XZ,{"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(ZZ,{asChild:!0,children:g.jsx(Yk,{className:"size-4 opacity-50"})})]})}function dee({className:t,children:e,position:n="popper",align:r="center",...o}){return g.jsx(eee,{children:g.jsx("div",{id:"select-wrapper","data-theme":"select-post-builder",children:g.jsxs(tee,{"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(hee,{}),g.jsx(nee,{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(pee,{})]})})})}function fee({className:t,children:e,...n}){return g.jsxs(ree,{"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(see,{children:g.jsx(Kk,{className:"size-4"})})}),g.jsx(oee,{children:e})]})}function hee({className:t,...e}){return g.jsx(iee,{"data-slot":"select-scroll-up-button",className:re("flex cursor-default items-center justify-center py-1",t),...e,children:g.jsx(Jz,{className:"size-4"})})}function pee({className:t,...e}){return g.jsx(aee,{"data-slot":"select-scroll-down-button",className:re("flex cursor-default items-center justify-center py-1",t),...e,children:g.jsx(Yk,{className:"size-4"})})}function mee(){return Ph.useSyncExternalStore(gee,()=>!0,()=>!1)}function gee(){return()=>{}}var Dv="Avatar",[yee]=Nn(Dv),[vee,M_]=yee(Dv),O_=b.forwardRef((t,e)=>{const{__scopeAvatar:n,...r}=t,[o,s]=b.useState("idle");return g.jsx(vee,{scope:n,imageLoadingStatus:o,onImageLoadingStatusChange:s,children:g.jsx(ge.span,{...r,ref:e})})});O_.displayName=Dv;var N_="AvatarImage",__=b.forwardRef((t,e)=>{const{__scopeAvatar:n,src:r,onLoadingStatusChange:o=()=>{},...s}=t,i=M_(N_,n),a=bee(r,s),l=ir(c=>{o(c),i.onImageLoadingStatusChange(c)});return Ct(()=>{a!=="idle"&&l(a)},[a,l]),a==="loaded"?g.jsx(ge.img,{...s,ref:e,src:r}):null});__.displayName=N_;var R_="AvatarFallback",I_=b.forwardRef((t,e)=>{const{__scopeAvatar:n,delayMs:r,...o}=t,s=M_(R_,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});I_.displayName=R_;function D_(t,e){return t?e?(t.src!==e&&(t.src=e),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function bee(t,{referrerPolicy:e,crossOrigin:n}){const r=mee(),o=b.useRef(null),s=r?(o.current||(o.current=new window.Image),o.current):null,[i,a]=b.useState(()=>D_(s,t));return Ct(()=>{a(D_(s,t))},[s,t]),Ct(()=>{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 xee=O_,wee=__,Eee=I_;function P_({className:t,...e}){return g.jsx(xee,{"data-slot":"avatar",className:re("relative flex size-8 shrink-0 overflow-hidden rounded-full",t),...e})}function L_({className:t,...e}){return g.jsx(wee,{"data-slot":"avatar-image",className:re("aspect-square size-full",t),...e})}function j_({className:t,...e}){return g.jsx(Eee,{"data-slot":"avatar-fallback",className:re("bg-muted flex size-full items-center justify-center rounded-full",t),...e})}const See=({user:t,store:e})=>{const{core:n}=ga(),[r,o]=M.useState([]),[s,i]=M.useState(!1),a=Jr(),[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(P_,{children:[g.jsx(L_,{src:t?.avatar??t?.avatarPlaceholder}),g.jsx(j_,{className:"bg-primary-send text-background",children:t?.name?.charAt(0)?.toUpperCase()})]}),g.jsxs(lee,{value:f,onValueChange:p,disabled:h||s,children:[g.jsx(uee,{size:"sm",id:`group-selector-${f}-${a}`,className:"bg-background","aria-label":"Select group",children:g.jsx(cee,{className:"text-sm",placeholder:s?"Loading groups...":"Select a group…"})}),g.jsx(dee,{align:"start",children:r.map(m=>g.jsxs(fee,{value:m.group_id,children:[g.jsxs(P_,{className:"size-6",children:[g.jsx(L_,{src:m.group.avatar}),g.jsx(j_,{children:m?.group?.name?.charAt(0)})]}),g.jsx("span",{className:"text-sm",children:m.group?.name??m.group_id})]},m.group_id))})]})]})};var kee=(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{}},Tee=b.createContext(void 0),Cee={setTheme:t=>{},themes:[]},Aee=()=>{var t;return(t=b.useContext(Tee))!=null?t:Cee};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:`(${kee.toString()})(${u})`}})});const Mee=({...t})=>{const{theme:e="system"}=Aee();return g.jsx(cD,{theme:e,className:"toaster group",style:{"--normal-bg":"var(--popover)","--normal-text":"var(--popover-foreground)","--normal-border":"var(--border)"},...t})},zf=t=>({html:t?.getHTML(),json:t?.getJSON(),text:t?.getText()}),Vf=()=>({postId:Jr(),timestamp:new Date().getTime(),specialType:Mb.POST}),Pv=t=>({mentionData:dl(t,"mention")?.map(r=>J6(e8(r.attrs,U6),["mentionSuggestionChar","label"]))?.filter(r=>Object.keys(r).length>0)}),Oee=t=>({items:dl(t,"media").map(r=>r.attrs?.payload)}),Nee=t=>({items:dl(t,"poll")[0].attrs?.choices}),_ee=({editor:t,sendCrossMention:e})=>{const{html:n,json:r}=zf(t),o=Vf(),s=PC(r,"text")?.text?.trim()??"",i=new Array(PC(r,"media")?.attrs?.payload).filter(Boolean),a=n;return{...o,type:pa.NEW_POST_MESSAGE,body:s,items:i,htmlBody:a,sendCrossMention:e,mentionData:[]}},Ree=({editor:t,sendCrossMention:e})=>{const{json:n,text:r}=zf(t),o=Vf(),s=r,{mentionData:i}=Pv(n),{items:a}=Oee(n);return{...o,type:pa.NEW_POST_MEDIA,body:s,items:a,mentionData:i,sendCrossMention:e}},Iee=({editor:t,sendCrossMention:e})=>{const{json:n,text:r}=zf(t),o=Vf(),s=r,{mentionData:i}=Pv(n);return{...o,type:pa.NEW_POST_MESSAGE,body:s,items:[],mentionData:i,sendCrossMention:e}},Dee=({editor:t,sendCrossMention:e})=>{const{json:n,text:r}=zf(t),o=Vf(),s=r,{mentionData:i}=Pv(n),{items:a}=Nee(n);return{...o,type:pa.NEW_POST_POLL,body:s,items:a,mentionData:i,sendCrossMention:e}},Pee=(t,e)=>{switch(t){case ht.Text:return _ee(e);case ht.Media:return Ree(e);case ht.Link:return Iee(e);case ht.Poll:return Dee(e);default:return null}},Lee=({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(ht.Text),{editor:h,actions:p,store:m}=fJ({editorType:d,groupId:t,postId:e,user:n}),{clearContent:y}=em(),v=M.useMemo(()=>({editor:h}),[h]),w=E=>{if(!h)return;const x=h?.getHTML(),T=h?.getJSON(),S=h?.getText(),k=Pee(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(Qp.Provider,{value:v,children:[!r&&g.jsx(See,{user:n,store:m}),o?g.jsx(CZ,{open:c,onOpenChange:u,editor:h,actions:p,editorTab:d,onSwitchEditor:f,isSubmitting:i,onSubmit:w}):g.jsx(e_,{editor:h,actions:p,editorTab:d,onSwitchEditor:f,isSubmitting:i,onSubmit:w})]})}),g.jsx(Mee,{position:"top-center"})]}):null};vt.PostBuilderEditor=Lee,vt.PostBuilderProvider=SD,Object.defineProperty(vt,Symbol.toStringTag,{value:"Module"})}));
|