noteloom 0.3.0 → 0.3.1

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/noteloom.cjs CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";var tu=Object.defineProperty;var nu=(t,e,n)=>e in t?tu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var _s=(t,e,n)=>nu(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react"),l=require("react/jsx-runtime"),Ve=require("react-dom"),Z={INSERT_BLOCK:"insertBlock",REMOVE_BLOCK:"removeBlock",MOVE_BLOCK:"moveBlock",CHANGE_BLOCK_TYPE:"changeBlockType",UPDATE_BLOCK_PROPS:"updateBlockProps",UPDATE_RUN:"updateRun",SET_BLOCK_CONTENT_IDS:"setBlockContentIds",REPLACE_RUN_SPAN:"replaceRunSpan",SET_BLOCK_RUNS:"setBlockRuns",EDIT_RUN_CHARS:"editRunChars",ADD_FIELD_TYPE:"addFieldType",UPDATE_FIELD_TYPE:"updateFieldType",REMOVE_FIELD_TYPE:"removeFieldType",ADD_COMMENT_THREAD:"addCommentThread",REMOVE_COMMENT_THREAD:"removeCommentThread",ADD_COMMENT_REPLY:"addCommentReply",REMOVE_COMMENT_REPLY:"removeCommentReply",RESOLVE_COMMENT:"resolveComment"};function me(t,e,n,r){return{type:Z.INSERT_BLOCK,block:t,parentId:e,index:n,subtree:r}}function ee(t){return{type:Z.REMOVE_BLOCK,id:t}}function ct(t,e,n){return{type:Z.MOVE_BLOCK,id:t,toParentId:e,toIndex:n}}function J(t,e){return{type:Z.UPDATE_BLOCK_PROPS,id:t,patch:e}}function fo(t,e,n){return{type:Z.CHANGE_BLOCK_TYPE,id:t,blockType:e,props:n}}function ue(t,e){return{type:Z.UPDATE_RUN,id:t,patch:e}}function Zr(t,e,n,r){return{type:Z.EDIT_RUN_CHARS,id:t,tombstoneIds:e,restoreIds:n,previousValue:r}}function nn(t,e){return{type:Z.SET_BLOCK_CONTENT_IDS,blockId:t,contentIds:e}}function _t(t,e,n){return{type:Z.REPLACE_RUN_SPAN,blockId:t,oldRunIds:e,newRuns:n}}function Me(t,e){return{type:Z.SET_BLOCK_RUNS,blockId:t,runs:e}}function ho(t){return{type:Z.ADD_FIELD_TYPE,fieldType:t}}function mo(t,e){return{type:Z.UPDATE_FIELD_TYPE,id:t,patch:e}}function bo(t){return{type:Z.REMOVE_FIELD_TYPE,id:t}}function Cn(t){return{type:Z.ADD_COMMENT_THREAD,thread:t}}function go(t){return{type:Z.REMOVE_COMMENT_THREAD,commentId:t}}function xo(t,e){return{type:Z.ADD_COMMENT_REPLY,commentId:t,message:e}}function ga(t,e){return{type:Z.REMOVE_COMMENT_REPLY,commentId:t,messageId:e}}function yo(t,e){return{type:Z.RESOLVE_COMMENT,commentId:t,resolved:e}}const ru=Object.freeze(Object.defineProperty({__proto__:null,OP:Z,addCommentReply:xo,addCommentThread:Cn,addFieldType:ho,changeBlockType:fo,editRunChars:Zr,insertBlock:me,moveBlock:ct,removeBlock:ee,removeCommentReply:ga,removeCommentThread:go,removeFieldType:bo,replaceRunSpan:_t,resolveComment:yo,setBlockContentIds:nn,setBlockRuns:Me,updateBlockProps:J,updateFieldType:mo,updateRun:ue},Symbol.toStringTag,{value:"Module"}));class Sn{constructor(e){this.peerId=e,this.wallTime=0,this.counter=0}tick(){const e=Date.now();return e>this.wallTime?(this.wallTime=e,this.counter=0):this.counter+=1,{wallTime:this.wallTime,counter:this.counter,peerId:this.peerId}}receive(e){const n=Date.now(),r=Math.max(n,this.wallTime,e.wallTime);return r===this.wallTime&&r===e.wallTime?this.counter=Math.max(this.counter,e.counter)+1:r===this.wallTime?this.counter+=1:r===e.wallTime?this.counter=e.counter+1:this.counter=0,this.wallTime=r,{wallTime:this.wallTime,counter:this.counter,peerId:this.peerId}}static compare(e,n){return e.wallTime!==n.wallTime?e.wallTime-n.wallTime:e.counter!==n.counter?e.counter-n.counter:e.peerId===n.peerId?0:e.peerId<n.peerId?-1:1}}function xa(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`peer-${Date.now()}-${Math.random().toString(36).slice(2)}`}class Qt{constructor(){this.slots=new Map}static fromArray(e,{peerId:n="legacy"}={}){const r=new Qt;let o=null;for(const s of e)r.slots.set(s,{id:s,originId:o,peerId:n,clock:{wallTime:0,counter:0,peerId:n},deleted:!1}),o=s;return r}has(e){return this.slots.has(e)}getSlot(e){return this.slots.get(e)}isDeleted(e){const n=this.slots.get(e);return!n||n.deleted}insert(e,n,r,o){this.slots.has(e)||this.slots.set(e,{id:e,originId:n,peerId:o,clock:r,deleted:!1})}delete(e,n){const r=this.slots.get(e);r&&(r.deleted=!0,n&&(r.deletedClock=n))}restore(e){const n=this.slots.get(e);n&&(n.deleted=!1)}move(e,n,r,o){if(n===e)return;const s=this.slots.get(e);if(!s)return;const a=s.originId;for(const i of this.slots.values())i.originId===e&&(i.originId=a);s.originId=n,s.peerId=o,s.clock=r,s.deleted=!1}merge(e){for(const n of e){const r=this.slots.get(n.id);r?n.deleted&&!r.deleted&&(r.deleted=!0):this.slots.set(n.id,{...n})}}toSlotArray(){return Array.from(this.slots.values())}tombstoneCount(){let e=0;for(const n of this.slots.values())n.deleted&&(e+=1);return e}pruneTombstones(e){let n=0;for(const[r,o]of this.slots){if(!o.deleted)continue;const s=o.deletedClock??o.clock;if(!(Sn.compare(s,e)>=0)){for(const a of this.slots.values())a.originId===r&&(a.originId=o.originId);this.slots.delete(r),n+=1}}return n}toArray(){const e=new Map;for(const o of this.slots.values()){const s=e.get(o.originId);s?s.push(o):e.set(o.originId,[o])}for(const o of e.values())o.sort((s,a)=>Sn.compare(a.clock,s.clock));const n=[],r=[...e.get(null)??[]].reverse();for(;r.length>0;){const o=r.pop();o.deleted||n.push(o.id);const s=e.get(o.id);if(s)for(let a=s.length-1;a>=0;a-=1)r.push(s[a])}return n}}class en{constructor(){this.clocks=new Map}static compositeKey(e,n){return`${e}:${n}`}get(e,n){return this.clocks.get(en.compositeKey(e,n))??null}recordLocal(e,n,r){this.clocks.set(en.compositeKey(e,n),r)}shouldApplyRemote(e,n,r){const o=this.get(e,n);return o?Sn.compare(r,o)>0:!0}recordRemote(e,n,r){this.clocks.set(en.compositeKey(e,n),r)}}function ou(t,e){const n=Array.from(t??""),r=Array.from(e??"");let o=0;const s=Math.min(n.length,r.length);for(;o<s&&n[o]===r[o];)o+=1;let a=n.length,i=r.length;for(;a>o&&i>o&&n[a-1]===r[i-1];)a-=1,i-=1;return{start:o,oldEnd:a,newEnd:i,oldChars:n,newChars:r}}function E(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`id-${Date.now()}-${Math.random().toString(36).slice(2)}`}const $r="$fieldTypes",Xe="$comments";class ur{constructor(e){this.blocks=new Map(((e==null?void 0:e.blocks)??[]).map(n=>[n.id,n])),this.runs=new Map(((e==null?void 0:e.runs)??[]).map(n=>[n.id,n])),this.rootId=(e==null?void 0:e.rootId)??null,this.fieldTypes=new Map(((e==null?void 0:e.fieldTypes)??[]).map(n=>[n.id,n])),this._fieldTypesSnapshot=null,this.comments=new Map(((e==null?void 0:e.comments)??[]).map(n=>[n.id,n])),this._commentsSnapshot=null,this._listeners=new Map,this._globalListeners=new Set,this._peerId=xa(),this._clock=new Sn(this._peerId),this._fieldClocks=new en,this._orders=new Map,this._runOrders=new Map,this._runChars=new Map,this._runValueSnapshots=new Map}_getOrder(e){let n=this._orders.get(e);if(!n){const r=this.blocks.get(e);n=Qt.fromArray((r==null?void 0:r.contentIds)??[],{peerId:"legacy"}),this._orders.set(e,n)}return n}_getRunOrder(e){let n=this._runOrders.get(e);if(!n){const r=this.runs.get(e),o=new Map;n=new Qt;let s=null,a=0;for(const i of Array.from((r==null?void 0:r.value)??"")){const u=`${e}:legacyChar:${a}`;o.set(u,i),n.insert(u,s,{wallTime:0,counter:0,peerId:"legacy"},"legacy"),s=u,a+=1}this._runOrders.set(e,n),this._runChars.set(e,o)}return n}_materializeRunValue(e){let n=this._runValueSnapshots.get(e);if(n===void 0){const r=this._getRunOrder(e),o=this._runChars.get(e);n=r.toArray().map(s=>o.get(s)).join(""),this._runValueSnapshots.set(e,n)}return n}_editRunText(e,n){const r=this._materializeRunValue(e),{start:o,oldEnd:s,newEnd:a,newChars:i}=ou(r,n),u=this._getRunOrder(e),c=this._runChars.get(e),f=u.toArray(),d=this._clock.tick(),h=[];for(let x=o;x<s;x+=1){const y=f[x];u.delete(y,d),h.push({id:y,clock:d})}const m=[];let g=o>0?f[o-1]:null;for(let x=o;x<a;x+=1){const y=E(),k=i[x];c.set(y,k),u.insert(y,g,d,this._peerId),m.push({id:y,char:k,afterId:g,clock:d}),g=y}return this._runValueSnapshots.delete(e),{oldValue:r,insertedChars:m,deletedCharIds:h,clock:d}}_replayRunTextEdit(e,n){const r=this._getRunOrder(e),o=this._runChars.get(e);for(const s of n.insertedChars)r.has(s.id)?r.restore(s.id):(o.set(s.id,s.char),r.insert(s.id,s.afterId,s.clock,this._peerId));for(const s of n.deletedCharIds)r.delete(s.id,s.clock);this._runValueSnapshots.delete(e)}getBlock(e){return this.blocks.get(e)}getRun(e){return this.runs.get(e)}getFieldTypes(){return this._fieldTypesSnapshot||(this._fieldTypesSnapshot=[...this.fieldTypes.values()]),this._fieldTypesSnapshot}getFieldType(e){return this.fieldTypes.get(e)}getComments(){return this._commentsSnapshot||(this._commentsSnapshot=[...this.comments.values()]),this._commentsSnapshot}getComment(e){return this.comments.get(e)}getAllRunIds(){return[...this.runs.keys()]}getRootId(){return this.rootId}subscribe(e,n){let r=this._listeners.get(e);return r||(r=new Set,this._listeners.set(e,r)),r.add(n),()=>{r.delete(n),r.size===0&&this._listeners.delete(e)}}subscribeAll(e){return this._globalListeners.add(e),()=>this._globalListeners.delete(e)}_notify(e){for(const n of e){const r=this._listeners.get(n);if(r)for(const o of[...r])o()}if(this._globalListeners.size>0)for(const n of[...this._globalListeners])n()}_captureSubtree(e){const n=[],r=[],o=s=>{var i;if(this.runs.has(s)){r.push(this.runs.get(s));return}const a=this.blocks.get(s);if(a){n.push(a);for(const u of a.contentIds)o(u);for(const u of((i=a.props)==null?void 0:i.titleRunIds)??[])o(u)}};return o(e),{blocks:n,runs:r}}_deleteSubtree(e){const n=r=>{var s;if(this.runs.has(r)){this.runs.delete(r);return}const o=this.blocks.get(r);if(o){for(const a of o.contentIds)n(a);for(const a of((s=o.props)==null?void 0:s.titleRunIds)??[])n(a);this.blocks.delete(r)}};n(e)}applyOperation(e){var n;switch(e.type){case Z.UPDATE_RUN:{const r=this.runs.get(e.id),o=Object.keys(e.patch);if(o.length===1&&o[0]==="value"){let i=e._charEdit;if(i)this._replayRunTextEdit(e.id,i);else{const{oldValue:c,insertedChars:f,deletedCharIds:d,clock:h}=this._editRunText(e.id,e.patch.value);i={oldValue:c,insertedChars:f,deletedCharIds:d,clock:h},e._charEdit=i}const u=this._materializeRunValue(e.id);return this.runs.set(e.id,{...r,value:u}),this._lastEnvelope={kind:"runTextEdit",runId:e.id,insertedChars:i.insertedChars,deletedCharIds:i.deletedCharIds,clock:i.clock},this._notify([e.id]),Zr(e.id,i.insertedChars.map(c=>c.id),i.deletedCharIds.map(c=>c.id),i.oldValue)}const s={},a={};for(const i of o)s[i]=r[i],a[i]=this._clock.tick(),this._fieldClocks.recordLocal(e.id,i,a[i]);return this.runs.set(e.id,{...r,...e.patch}),this._lastEnvelope={kind:"fieldWrite",target:"run",id:e.id,patch:e.patch,clocks:a},this._notify([e.id]),ue(e.id,s)}case Z.EDIT_RUN_CHARS:{const r=this._getRunOrder(e.id),o=this._clock.tick();for(const i of e.tombstoneIds)r.delete(i,o);for(const i of e.restoreIds)r.restore(i);this._runValueSnapshots.delete(e.id);const s=this.runs.get(e.id),a=this._materializeRunValue(e.id);return this.runs.set(e.id,{...s,value:a}),this._lastEnvelope={kind:"runCharEdit",runId:e.id,tombstoneIds:e.tombstoneIds,restoreIds:e.restoreIds,clock:o},this._notify([e.id]),Zr(e.id,e.restoreIds,e.tombstoneIds)}case Z.UPDATE_BLOCK_PROPS:{const r=this.blocks.get(e.id),o={},s={};for(const a of Object.keys(e.patch))o[a]=r.props[a],s[a]=this._clock.tick(),this._fieldClocks.recordLocal(e.id,`props.${a}`,s[a]);return this.blocks.set(e.id,{...r,props:{...r.props,...e.patch}}),this._lastEnvelope={kind:"fieldWrite",target:"blockProps",id:e.id,patch:e.patch,clocks:s},this._notify([e.id]),J(e.id,o)}case Z.CHANGE_BLOCK_TYPE:{const r=this.blocks.get(e.id),o=r.type,s=r.props,a=this._clock.tick();return this._fieldClocks.recordLocal(e.id,"type",a),this.blocks.set(e.id,{...r,type:e.blockType,props:e.props}),this._lastEnvelope={kind:"fieldWrite",target:"blockType",id:e.id,blockType:e.blockType,props:e.props,clock:a},this._notify([e.id]),fo(e.id,o,s)}case Z.INSERT_BLOCK:{if(e.subtree){for(const s of e.subtree.blocks)this.blocks.set(s.id,s);for(const s of e.subtree.runs)this.runs.set(s.id,s)}else this.blocks.set(e.block.id,e.block);const r=this.blocks.get(e.parentId),o=this._getOrder(e.parentId);if(o.has(e.block.id))o.restore(e.block.id);else{const s=o.toArray(),a=e.index??s.length,i=a>0?s[a-1]:null;o.insert(e.block.id,i,this._clock.tick(),this._peerId)}return this.blocks.set(e.parentId,{...r,contentIds:o.toArray()}),this._lastEnvelope={kind:"insertSlot",parentId:e.parentId,blockId:e.block.id,slot:o.getSlot(e.block.id),subtree:e.subtree??{blocks:[e.block],runs:[]}},this._notify([e.block.id,e.parentId]),ee(e.block.id)}case Z.REMOVE_BLOCK:{const r=this.blocks.get(e.id),o=r.parentId,s=this.blocks.get(o),a=this._getOrder(o),i=a.toArray().indexOf(e.id),u=this._captureSubtree(e.id);this._deleteSubtree(e.id);const c=this._clock.tick();return a.delete(e.id,c),this.blocks.set(o,{...s,contentIds:a.toArray()}),this._lastEnvelope={kind:"deleteSlot",parentId:o,blockId:e.id,clock:c},this._notify([o]),{type:Z.INSERT_BLOCK,block:r,parentId:o,index:i,subtree:u}}case Z.MOVE_BLOCK:{const o=this.blocks.get(e.id).parentId,s=this._getOrder(o),a=s.toArray().indexOf(e.id);s.delete(e.id,this._clock.tick()),this.blocks.set(o,{...this.blocks.get(o),contentIds:s.toArray()});const i=this._getOrder(e.toParentId),u=i.toArray(),c=e.toIndex??u.length,f=c>0?u[c-1]:null,d=this._clock.tick();i.has(e.id)?i.move(e.id,f,d,this._peerId):i.insert(e.id,f,d,this._peerId),this.blocks.set(e.toParentId,{...this.blocks.get(e.toParentId),contentIds:i.toArray()}),this.blocks.set(e.id,{...this.blocks.get(e.id),parentId:e.toParentId}),this._lastEnvelope={kind:"moveSlot",fromParentId:o,toParentId:e.toParentId,blockId:e.id,slot:i.getSlot(e.id)};const h=new Set([e.id,o,e.toParentId]);return this._notify(h),ct(e.id,o,a)}case Z.SET_BLOCK_CONTENT_IDS:{const r=this.blocks.get(e.blockId),o=r.contentIds;return this.blocks.set(e.blockId,{...r,contentIds:e.contentIds}),this._orders.set(e.blockId,Qt.fromArray(e.contentIds,{peerId:"legacy"})),this._lastEnvelope=null,this._notify([e.blockId]),nn(e.blockId,o)}case Z.REPLACE_RUN_SPAN:{const r=this.blocks.get(e.blockId),o=r.contentIds.indexOf(e.oldRunIds[0])!==-1,s=o?r.contentIds:((n=r.props)==null?void 0:n.titleRunIds)??[],a=s.indexOf(e.oldRunIds[0]),i=e.oldRunIds.map(c=>this.runs.get(c));for(const c of e.oldRunIds)this.runs.delete(c);for(const c of e.newRuns)this.runs.set(c.id,c);const u=[...s];return u.splice(a,e.oldRunIds.length,...e.newRuns.map(c=>c.id)),o?this.blocks.set(e.blockId,{...r,contentIds:u}):this.blocks.set(e.blockId,{...r,props:{...r.props,titleRunIds:u}}),this._lastEnvelope=null,this._notify([e.blockId,...e.oldRunIds,...e.newRuns.map(c=>c.id)]),_t(e.blockId,e.newRuns.map(c=>c.id),i)}case Z.SET_BLOCK_RUNS:{const r=this.blocks.get(e.blockId),o=r.props&&"titleRunIds"in r.props,s=o?r.props.titleRunIds:r.contentIds,a=s.map(u=>this.runs.get(u)).filter(Boolean);for(const u of s)this.runs.delete(u);for(const u of e.runs)this.runs.set(u.id,u);const i=e.runs.map(u=>u.id);return o?this.blocks.set(e.blockId,{...r,props:{...r.props,titleRunIds:i}}):this.blocks.set(e.blockId,{...r,contentIds:i}),this._lastEnvelope=null,this._notify([e.blockId,...s,...i]),Me(e.blockId,a)}case Z.ADD_FIELD_TYPE:return this.fieldTypes.set(e.fieldType.id,e.fieldType),this._fieldTypesSnapshot=null,this._notify([$r]),bo(e.fieldType.id);case Z.UPDATE_FIELD_TYPE:{const r=this.fieldTypes.get(e.id),o={};for(const s of Object.keys(e.patch))o[s]=r[s];return this.fieldTypes.set(e.id,{...r,...e.patch}),this._fieldTypesSnapshot=null,this._notify([$r]),mo(e.id,o)}case Z.REMOVE_FIELD_TYPE:{const r=this.fieldTypes.get(e.id);return this.fieldTypes.delete(e.id),this._fieldTypesSnapshot=null,this._notify([$r]),ho(r)}case Z.ADD_COMMENT_THREAD:return this.comments.set(e.thread.id,e.thread),this._commentsSnapshot=null,this._lastEnvelope={kind:"commentWrite",op:"addThread",thread:e.thread},this._notify([Xe]),go(e.thread.id);case Z.REMOVE_COMMENT_THREAD:{const r=this.comments.get(e.commentId);return this.comments.delete(e.commentId),this._commentsSnapshot=null,this._lastEnvelope={kind:"commentWrite",op:"removeThread",commentId:e.commentId},this._notify([Xe]),Cn(r)}case Z.ADD_COMMENT_REPLY:{const r=this.comments.get(e.commentId);return this.comments.set(e.commentId,{...r,messages:[...r.messages,e.message]}),this._commentsSnapshot=null,this._lastEnvelope={kind:"commentWrite",op:"addReply",commentId:e.commentId,message:e.message},this._notify([Xe]),ga(e.commentId,e.message.id)}case Z.REMOVE_COMMENT_REPLY:{const r=this.comments.get(e.commentId),o=r.messages.find(s=>s.id===e.messageId);return this.comments.set(e.commentId,{...r,messages:r.messages.filter(s=>s.id!==e.messageId)}),this._commentsSnapshot=null,this._lastEnvelope={kind:"commentWrite",op:"removeReply",commentId:e.commentId,messageId:e.messageId},this._notify([Xe]),xo(e.commentId,o)}case Z.RESOLVE_COMMENT:{const r=this.comments.get(e.commentId),o=r.resolved;return this.comments.set(e.commentId,{...r,resolved:e.resolved}),this._commentsSnapshot=null,this._lastEnvelope={kind:"commentWrite",op:"resolve",commentId:e.commentId,resolved:e.resolved},this._notify([Xe]),yo(e.commentId,o)}default:throw new Error(`Unknown operation type: ${e.type}`)}}applyOperations(e){return e.map(n=>this.applyOperation(n))}getLastEnvelope(){return this._lastEnvelope}applyRemoteOperation(e){var n,r;if(e)switch(e.kind){case"insertSlot":{for(const a of e.subtree.blocks)this.blocks.has(a.id)||this.blocks.set(a.id,a);for(const a of e.subtree.runs)this.runs.has(a.id)||this.runs.set(a.id,a);const o=this._getOrder(e.parentId);o.merge([e.slot]);const s=this.blocks.get(e.parentId);this.blocks.set(e.parentId,{...s,contentIds:o.toArray()}),this._clock.receive(e.slot.clock),this._notify([e.blockId,e.parentId]);return}case"deleteSlot":{const o=this._getOrder(e.parentId);this.blocks.has(e.blockId)&&this._deleteSubtree(e.blockId),o.delete(e.blockId,e.clock),e.clock&&this._clock.receive(e.clock);const s=this.blocks.get(e.parentId);this.blocks.set(e.parentId,{...s,contentIds:o.toArray()}),this._notify([e.parentId]);return}case"moveSlot":{const o=this._getOrder(e.fromParentId);o.delete(e.blockId,(n=e.slot)==null?void 0:n.clock),this.blocks.set(e.fromParentId,{...this.blocks.get(e.fromParentId),contentIds:o.toArray()});const s=this._getOrder(e.toParentId),a=s.has(e.blockId);s.merge([e.slot]),a&&s.move(e.blockId,e.slot.originId,e.slot.clock,e.slot.peerId),this.blocks.set(e.toParentId,{...this.blocks.get(e.toParentId),contentIds:s.toArray()}),this.blocks.has(e.blockId)&&this.blocks.set(e.blockId,{...this.blocks.get(e.blockId),parentId:e.toParentId}),this._clock.receive(e.slot.clock),this._notify([e.blockId,e.fromParentId,e.toParentId]);return}case"fieldWrite":{if(e.target==="run"){const o=this.runs.get(e.id);if(o){const s={};for(const a of Object.keys(e.patch)){const i=e.clocks[a];this._fieldClocks.shouldApplyRemote(e.id,a,i)&&(s[a]=e.patch[a],this._fieldClocks.recordRemote(e.id,a,i))}Object.keys(s).length>0&&(this.runs.set(e.id,{...o,...s}),this._notify([e.id]))}}else if(e.target==="blockProps"){const o=this.blocks.get(e.id);if(o){const s={};for(const a of Object.keys(e.patch)){const i=e.clocks[a];this._fieldClocks.shouldApplyRemote(e.id,`props.${a}`,i)&&(s[a]=e.patch[a],this._fieldClocks.recordRemote(e.id,`props.${a}`,i))}Object.keys(s).length>0&&(this.blocks.set(e.id,{...o,props:{...o.props,...s}}),this._notify([e.id]))}}else if(e.target==="blockType"){const o=this.blocks.get(e.id);o&&this._fieldClocks.shouldApplyRemote(e.id,"type",e.clock)&&(this._fieldClocks.recordRemote(e.id,"type",e.clock),this.blocks.set(e.id,{...o,type:e.blockType,props:e.props}),this._notify([e.id]))}for(const o of Object.values(e.clocks??{}))this._clock.receive(o);e.clock&&this._clock.receive(e.clock);return}case"runTextEdit":{const o=this._getRunOrder(e.runId),s=this._runChars.get(e.runId);for(const i of e.insertedChars)o.has(i.id)||s.set(i.id,i.char),o.insert(i.id,i.afterId,i.clock,(r=i.clock)==null?void 0:r.peerId);for(const i of e.deletedCharIds)o.delete(i.id,i.clock);this._runValueSnapshots.delete(e.runId);const a=this.runs.get(e.runId);a&&(this.runs.set(e.runId,{...a,value:this._materializeRunValue(e.runId)}),this._notify([e.runId])),this._clock.receive(e.clock);return}case"runCharEdit":{const o=this._getRunOrder(e.runId);for(const a of e.tombstoneIds)o.delete(a,e.clock);for(const a of e.restoreIds)o.restore(a);this._runValueSnapshots.delete(e.runId);const s=this.runs.get(e.runId);s&&(this.runs.set(e.runId,{...s,value:this._materializeRunValue(e.runId)}),this._notify([e.runId])),this._clock.receive(e.clock);return}case"commentWrite":{if(e.op==="addThread")this.comments.has(e.thread.id)||(this.comments.set(e.thread.id,e.thread),this._commentsSnapshot=null,this._notify([Xe]));else if(e.op==="removeThread")this.comments.delete(e.commentId)&&(this._commentsSnapshot=null,this._notify([Xe]));else if(e.op==="addReply"){const o=this.comments.get(e.commentId);o&&!o.messages.some(s=>s.id===e.message.id)&&(this.comments.set(e.commentId,{...o,messages:[...o.messages,e.message]}),this._commentsSnapshot=null,this._notify([Xe]))}else if(e.op==="removeReply"){const o=this.comments.get(e.commentId);o&&o.messages.some(s=>s.id===e.messageId)&&(this.comments.set(e.commentId,{...o,messages:o.messages.filter(s=>s.id!==e.messageId)}),this._commentsSnapshot=null,this._notify([Xe]))}else if(e.op==="resolve"){const o=this.comments.get(e.commentId);o&&(this.comments.set(e.commentId,{...o,resolved:e.resolved}),this._commentsSnapshot=null,this._notify([Xe]))}return}default:throw new Error(`Unknown remote envelope kind: ${e.kind}`)}}getTombstoneCount(){let e=0;for(const n of this._orders.values())e+=n.tombstoneCount();for(const n of this._runOrders.values())e+=n.tombstoneCount();return e}pruneTombstones({maxAgeMs:e=24*60*60*1e3,now:n=Date.now()}={}){const r={wallTime:n-e,counter:0,peerId:""};let o=0;for(const s of this._orders.values())o+=s.pruneTombstones(r);for(const s of this._runOrders.values())o+=s.pruneTombstones(r);return o}toJSON(){return{blocks:[...this.blocks.values()],runs:[...this.runs.values()],rootId:this.rootId,fieldTypes:[...this.fieldTypes.values()],comments:[...this.comments.values()]}}static fromJSON(e){return new ur(e)}}const su=500;function au(t,e){const n=t??"",r=e??"";let o=0;const s=Math.min(n.length,r.length);for(;o<s&&n[o]===r[o];)o+=1;let a=n.length,i=r.length;for(;a>o&&i>o&&n[a-1]===r[i-1];)a-=1,i-=1;return{beforeOffset:a,afterOffset:i}}function ya(t){var e;if((t==null?void 0:t.type)==="updateRun"&&typeof((e=t.patch)==null?void 0:e.value)=="string")return t.patch.value;if((t==null?void 0:t.type)==="editRunChars"&&typeof t.previousValue=="string")return t.previousValue}function Os(t){var i;if(!t.ops.length||!t.inverses.length)return null;const e=t.ops[0],n=t.ops[t.ops.length-1];if(e.type!=="updateRun"||n.type!=="updateRun"||e.id!==n.id||typeof((i=n.patch)==null?void 0:i.value)!="string")return null;const r=t.inverses[t.inverses.length-1],o=ya(r);if(o===void 0)return null;const{beforeOffset:s,afterOffset:a}=au(o,n.patch.value);return{runId:e.id,beforeOffset:s,afterOffset:a}}function Ms(t){const e=[],n=r=>{var o;r&&((o=r.block)!=null&&o.id&&e.push(r.block.id),r.blockId&&e.push(r.blockId),r.id&&e.push(r.id),r.parentId&&e.push(r.parentId),r.toParentId&&e.push(r.toParentId))};for(const r of t.ops)n(r);for(const r of t.inverses)n(r);return[...new Set(e)]}class ka{constructor(e,{idleMs:n=su,trackChanges:r=!1,maxChangeLogSize:o=500}={}){this.store=e,this.idleMs=n,this.undoStack=[],this.redoStack=[],this.currentBatch=null,this.idleTimer=null,this.historyLog=[],this._listeners=new Set,this._undoRedoSnapshot={canUndo:!1,canRedo:!1},this._pendingSelection=null,this._pendingAffectedBlockIds=[],this.trackChanges=r,this.maxChangeLogSize=o,this.changeLog=[]}_recordChange(e,n,r){var a;if(!this.trackChanges)return;const o=e.patch!==void 0&&(n==null?void 0:n.patch)!==void 0,s=o?void 0:ya(n);this.changeLog.push({opType:e.type,id:e.id??e.blockId??((a=e.block)==null?void 0:a.id),before:o?n.patch:s!==void 0?{value:s}:void 0,after:o||s!==void 0?e.patch:void 0,actorId:r.actorId??null,timestamp:r.timestamp??Date.now()}),this.changeLog.length>this.maxChangeLogSize&&this.changeLog.shift()}getChangeLog(){return[...this.changeLog]}getPendingSelection(){return this._pendingSelection}getPendingAffectedBlockIds(){return this._pendingAffectedBlockIds}getUndoRedoSnapshot(){const e=this.canUndo(),n=this.canRedo();return(this._undoRedoSnapshot.canUndo!==e||this._undoRedoSnapshot.canRedo!==n)&&(this._undoRedoSnapshot={canUndo:e,canRedo:n}),this._undoRedoSnapshot}getBlock(e){return this.store.getBlock(e)}getRun(e){return this.store.getRun(e)}getRootId(){return this.store.getRootId()}getFieldTypes(){return this.store.getFieldTypes()}getFieldType(e){return this.store.getFieldType(e)}getComments(){return this.store.getComments()}getComment(e){return this.store.getComment(e)}getAllRunIds(){return this.store.getAllRunIds()}subscribe(e,n){return this.store.subscribe(e,n)}subscribeAll(e){return this.store.subscribeAll(e)}getTombstoneCount(){return this.store.getTombstoneCount()}pruneTombstones(e){return this.store.pruneTombstones(e)}toJSON(){return this.store.toJSON()}applyOperation(e,n={}){return this.perform(e,n)}applyOperations(e,n={}){return e.map(r=>this.perform(r,n))}performBatch(e,n={}){var a;const r=n.actorId??null,o=n.timestamp??Date.now();this._commitCurrentBatch();const s=[];for(const i of e){const u=this.store.applyOperation(i);s.unshift(u),this.historyLog.push({opType:i.type,id:i.id??i.blockId??((a=i.block)==null?void 0:a.id),actorId:r,timestamp:o}),this._recordChange(i,u,{actorId:r,timestamp:o})}this.redoStack=[],this.undoStack.push({ops:[...e],inverses:s,batchKey:null,actorId:r,timestamp:o,lastTimestamp:o,boundaryHit:!0}),this._notify()}perform(e,n={}){const r=n.actorId??null,o=n.timestamp??Date.now(),s=this.store.applyOperation(e);return this._record(e,s,{actorId:r,timestamp:o}),s}_batchKeyFor(e){return e.type==="updateRun"?`run:${e.id}`:null}_isWordBoundary(e){var r;if(e.type!=="updateRun")return!1;const n=(r=e.patch)==null?void 0:r.value;return typeof n!="string"||n.length===0?!1:/\s/.test(n[n.length-1])}_record(e,n,r){var i;this.redoStack=[];const o=this._batchKeyFor(e),s=this.currentBatch&&r.timestamp-this.currentBatch.lastTimestamp<=this.idleMs;this.currentBatch&&o!==null&&this.currentBatch.batchKey===o&&s&&!this.currentBatch.boundaryHit?(this.currentBatch.ops.push(e),this.currentBatch.inverses.unshift(n),this.currentBatch.lastTimestamp=r.timestamp,this._isWordBoundary(e)&&(this.currentBatch.boundaryHit=!0)):(this._commitCurrentBatch(),this.currentBatch={ops:[e],inverses:[n],batchKey:o,actorId:r.actorId,timestamp:r.timestamp,lastTimestamp:r.timestamp,boundaryHit:this._isWordBoundary(e)}),this._resetIdleTimer(),this.historyLog.push({opType:e.type,id:e.id??((i=e.block)==null?void 0:i.id),actorId:r.actorId,timestamp:r.timestamp}),this._recordChange(e,n,r),this._notify()}_resetIdleTimer(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this._commitCurrentBatch(),this._notify()},this.idleMs)}_commitCurrentBatch(){this.currentBatch&&(this.undoStack.push(this.currentBatch),this.currentBatch=null,this.idleTimer&&(clearTimeout(this.idleTimer),this.idleTimer=null))}flush(){this._commitCurrentBatch(),this._notify()}undo(){this._commitCurrentBatch();const e=this.undoStack.pop();if(!e)return!1;for(const r of e.inverses)this.store.applyOperation(r);this.redoStack.push(e);const n=Os(e);return this._pendingSelection=n?{runId:n.runId,offset:n.beforeOffset}:null,this._pendingAffectedBlockIds=Ms(e),this._notify(),!0}redo(){const e=this.redoStack.pop();if(!e)return!1;for(const r of e.ops)this.store.applyOperation(r);this.undoStack.push(e);const n=Os(e);return this._pendingSelection=n?{runId:n.runId,offset:n.afterOffset}:null,this._pendingAffectedBlockIds=Ms(e),this._notify(),!0}canUndo(){return this.undoStack.length>0||this.currentBatch!==null}canRedo(){return this.redoStack.length>0}getHistoryLog(){return[...this.historyLog]}subscribeToHistory(e){return this._listeners.add(e),()=>this._listeners.delete(e)}_notify(){for(const e of this._listeners)e()}}const lu=60*60*1e3,iu=24*60*60*1e3;function cu({store:t,intervalMs:e=lu,maxAgeMs:n=iu,onPrune:r,onError:o}){const s=setInterval(()=>{try{const a=t.pruneTombstones({maxAgeMs:n});a>0&&(r==null||r(a))}catch(a){o==null||o(a)}},e);return{stop(){clearInterval(s)}}}const Ge={HELLO:"hello",OP:"op",SYNC_REQUEST:"syncRequest",SYNC_RESPONSE:"syncResponse",PRESENCE:"presence"};function Jt(t){return JSON.stringify(t)}function va(t){const e=JSON.parse(t);if(!e||typeof e.type!="string")throw new Error("Invalid sync message: missing type");return e}function uu(t){return{type:Ge.HELLO,peerId:t}}function du(t){return{type:Ge.OP,envelope:t}}function pu(){return{type:Ge.SYNC_REQUEST}}function fu(t){return{type:Ge.SYNC_RESPONSE,doc:t}}function Ls(t,e){return{type:Ge.PRESENCE,peerId:t,data:e}}const hu="noteloom-sync",mu={iceServers:[{urls:"stun:stun.l.google.com:19302"}]},Fn=16e3,bu=1e6,gu=256e3;function xu(){return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}class wa{constructor({signaling:e,remotePeerId:n,initiator:r,rtcConfig:o=mu}){this.remotePeerId=n,this._signaling=e,this._pc=new RTCPeerConnection(o),this._channel=null,this._openListeners=new Set,this._closeListeners=new Set,this._messageListeners=new Set,this._chunkBuffers=new Map,this._sendQueue=[],this._pumping=!1,this._pc.onicecandidate=s=>{s.candidate&&this._signaling.send(n,{kind:"ice",candidate:s.candidate.toJSON()})},r?(this._wireChannel(this._pc.createDataChannel(hu)),this._pc.createOffer().then(s=>this._pc.setLocalDescription(s).then(()=>s)).then(s=>this._signaling.send(n,{kind:"offer",sdp:s}))):this._pc.ondatachannel=s=>this._wireChannel(s.channel),this._unsubscribeSignaling=e.onMessage((s,a)=>{s===n&&this._handleSignal(a)})}async _handleSignal(e){if(e.kind==="offer"){await this._pc.setRemoteDescription(e.sdp);const n=await this._pc.createAnswer();await this._pc.setLocalDescription(n),this._signaling.send(this.remotePeerId,{kind:"answer",sdp:n})}else if(e.kind==="answer")await this._pc.setRemoteDescription(e.sdp);else if(e.kind==="ice")try{await this._pc.addIceCandidate(e.candidate)}catch{}}_wireChannel(e){this._channel=e,e.bufferedAmountLowThreshold=gu,e.onopen=()=>{for(const n of this._openListeners)n()},e.onclose=()=>{for(const n of this._closeListeners)n()},e.onmessage=n=>this._handleRawMessage(n.data)}_handleRawMessage(e){if(typeof e!="string"||e.length===0)return;const n=e[0];if(n==="S"){for(const m of this._messageListeners)m(e.slice(1));return}if(n!=="C")return;const r=e.slice(1),o=r.indexOf(":"),s=r.indexOf(":",o+1),a=r.indexOf(":",s+1);if(o===-1||s===-1||a===-1)return;const i=r.slice(0,o),u=Number(r.slice(o+1,s)),c=Number(r.slice(s+1,a)),f=r.slice(a+1);let d=this._chunkBuffers.get(i);if(d||(d={total:c,received:new Map},this._chunkBuffers.set(i,d)),d.received.set(u,f),d.received.size<d.total)return;this._chunkBuffers.delete(i);let h="";for(let m=0;m<d.total;m+=1)h+=d.received.get(m);for(const m of this._messageListeners)m(h)}send(e){var n;if(((n=this._channel)==null?void 0:n.readyState)==="open"){if(e.length<=Fn)this._sendQueue.push(`S${e}`);else{const r=xu(),o=Math.ceil(e.length/Fn);for(let s=0;s<o;s+=1){const a=e.slice(s*Fn,(s+1)*Fn);this._sendQueue.push(`C${r}:${s}:${o}:${a}`)}}this._pumpSendQueue()}}async _pumpSendQueue(){if(!this._pumping){this._pumping=!0;try{for(;this._sendQueue.length>0;){if(!this._channel||this._channel.readyState!=="open"){this._sendQueue.length=0;break}if(this._channel.bufferedAmount>bu){await this._waitForBufferedAmountLow();continue}const e=this._sendQueue.shift();try{this._channel.send(e)}catch(n){console.warn("[noteloom] failed to send a sync message to peer",this.remotePeerId,n),this._sendQueue.length=0;break}}}finally{this._pumping=!1}}}_waitForBufferedAmountLow(){return new Promise(e=>{if(!this._channel){e();return}const n=()=>{this._channel.removeEventListener("bufferedamountlow",n),e()};this._channel.addEventListener("bufferedamountlow",n)})}onOpen(e){return this._openListeners.add(e),()=>this._openListeners.delete(e)}onClose(e){return this._closeListeners.add(e),()=>this._closeListeners.delete(e)}onMessage(e){return this._messageListeners.add(e),()=>this._messageListeners.delete(e)}close(){var e,n;this._chunkBuffers.clear(),this._sendQueue.length=0,(e=this._unsubscribeSignaling)==null||e.call(this),(n=this._channel)==null||n.close(),this._pc.close()}}const yu=100;class ku{constructor({history:e,signaling:n,presenceThrottleMs:r=yu}){this._history=e,this._store=e.store,this._signaling=n,this._peers=new Map,this._unsubscribeLocal=this._attachLocalBroadcast(),this._localPresence=null,this._remotePresence=new Map,this._presenceListeners=new Set,this._presenceThrottleMs=r,this._presenceThrottleTimer=null,this._presenceDirty=!1}_attachLocalBroadcast(){const e=this._store.applyOperation.bind(this._store);this._pendingEnvelopes=[],this._store.applyOperation=r=>{const o=e(r),s=this._store.getLastEnvelope();return s&&this._pendingEnvelopes.push(s),o};const n={};for(const r of["perform","performBatch","undo","redo"]){const o=this._history[r].bind(this._history);n[r]=o,this._history[r]=(...s)=>{const a=o(...s);return this._flushPendingEnvelopes(),a}}return()=>{for(const r of Object.keys(n))this._history[r]=n[r];this._store.applyOperation=e}}_flushPendingEnvelopes(){const e=this._pendingEnvelopes;this._pendingEnvelopes=[];for(const n of e)this._broadcast(du(n))}_broadcast(e){const n=Jt(e);for(const r of this._peers.values())r.send(n)}connect(e,{initiator:n}){var o;(o=this._peers.get(e))==null||o.close();const r=new wa({signaling:this._signaling,remotePeerId:e,initiator:n});return r.onOpen(()=>{r.send(Jt(uu(this._signaling.localPeerId))),r.send(Jt(pu())),this._localPresence!==null&&r.send(Jt(Ls(this._signaling.localPeerId,this._localPresence)))}),r.onMessage(s=>this._handleMessage(r,s)),r.onClose(()=>{this._peers.delete(e),this._remotePresence.delete(e)&&this._notifyPresenceListeners()}),this._peers.set(e,r),r}setLocalPresence(e){this._localPresence=e,this._presenceDirty=!0,!this._presenceThrottleTimer&&(this._flushLocalPresence(),this._presenceThrottleTimer=setTimeout(()=>{this._presenceThrottleTimer=null,this._presenceDirty&&this._flushLocalPresence()},this._presenceThrottleMs))}_flushLocalPresence(){this._presenceDirty=!1,this._broadcast(Ls(this._signaling.localPeerId,this._localPresence))}getPresence(){return new Map(this._remotePresence)}onPresenceChange(e){return this._presenceListeners.add(e),()=>this._presenceListeners.delete(e)}_notifyPresenceListeners(){const e=this.getPresence();for(const n of this._presenceListeners)n(e)}_handleMessage(e,n){let r;try{r=va(n)}catch{return}r.type===Ge.OP?(this._store.applyRemoteOperation(r.envelope),this._history.flush()):r.type===Ge.SYNC_REQUEST?e.send(Jt(fu(this._store.toJSON()))):r.type===Ge.SYNC_RESPONSE?this._adoptSnapshotIfEmpty(r.doc):r.type===Ge.PRESENCE&&(this._remotePresence.set(r.peerId,r.data),this._notifyPresenceListeners())}_adoptSnapshotIfEmpty(e){const n=this._store.getRootId();n&&this._store.getBlock(n)||(this._store.blocks=new Map((e.blocks??[]).map(r=>[r.id,r])),this._store.runs=new Map((e.runs??[]).map(r=>[r.id,r])),this._store.rootId=e.rootId??null,this._store._orders=new Map,this._store._notify([...this._store.blocks.keys(),...this._store.runs.keys()]))}disconnect(e){var n;(n=this._peers.get(e))==null||n.close(),this._peers.delete(e)}destroy(){this._unsubscribeLocal(),this._presenceThrottleTimer&&clearTimeout(this._presenceThrottleTimer);for(const e of this._peers.values())e.close();this._peers.clear(),this._remotePresence.clear(),this._presenceListeners.clear()}}function vu({url:t,roomId:e,peerId:n,WebSocketImpl:r=WebSocket}){const o=new Set,s=new Set,a=new Set,i=[],u=`${t}${t.includes("?")?"&":"?"}room=${encodeURIComponent(e)}&peerId=${encodeURIComponent(n)}`,c=new r(u);c.addEventListener("open",()=>{for(const{toPeerId:d,payload:h}of i)f(d,h);i.length=0}),c.addEventListener("message",d=>{let h;try{h=JSON.parse(d.data)}catch{return}if(h.type==="roster")for(const m of h.peerIds??[])for(const g of s)g(m);else if(h.type==="peer-joined")for(const m of s)m(h.peerId);else if(h.type==="peer-left")for(const m of a)m(h.peerId);else if(h.type==="signal")for(const m of o)m(h.fromPeerId,h.payload)});function f(d,h){if(c.readyState!==r.OPEN){i.push({toPeerId:d,payload:h});return}c.send(JSON.stringify({type:"signal",toPeerId:d,payload:h}))}return{localPeerId:n,send(d,h){f(d,h)},onMessage(d){return o.add(d),()=>o.delete(d)},onPeerDiscovered(d){return s.add(d),()=>s.delete(d)},onPeerLeft(d){return a.add(d),()=>a.delete(d)},close(){i.length=0,c.close()}}}const wu="noteloom-documents",Ze="documents",Qe="templates",et="versions",Iu=3;let Un=null;function De(){return Un||(Un=new Promise((t,e)=>{const n=indexedDB.open(wu,Iu);n.onupgradeneeded=()=>{n.result.objectStoreNames.contains(Ze)||n.result.createObjectStore(Ze),n.result.objectStoreNames.contains(Qe)||n.result.createObjectStore(Qe,{keyPath:"id"}),n.result.objectStoreNames.contains(et)||n.result.createObjectStore(et,{keyPath:"id"})},n.onsuccess=()=>t(n.result),n.onerror=()=>e(n.error)}),Un)}async function Ia(t,e){const n=await De();return new Promise((r,o)=>{const s=n.transaction(Ze,"readwrite");s.objectStore(Ze).put(e,t),s.oncomplete=()=>r(),s.onerror=()=>o(s.error)})}async function Ca(t){const e=await De();return new Promise((n,r)=>{const s=e.transaction(Ze,"readonly").objectStore(Ze).get(t);s.onsuccess=()=>n(s.result??null),s.onerror=()=>r(s.error)})}async function Cu(t){const e=await De();return new Promise((n,r)=>{const o=e.transaction(Ze,"readwrite");o.objectStore(Ze).delete(t),o.oncomplete=()=>n(),o.onerror=()=>r(o.error)})}async function Su(){const t=await De();return new Promise((e,n)=>{const o=t.transaction(Ze,"readonly").objectStore(Ze).getAllKeys();o.onsuccess=()=>e(o.result),o.onerror=()=>n(o.error)})}async function Ru(t){const e=await De();return new Promise((n,r)=>{const o=e.transaction(Qe,"readwrite");o.objectStore(Qe).put(t),o.oncomplete=()=>n(),o.onerror=()=>r(o.error)})}async function Tu(t){const e=await De();return new Promise((n,r)=>{const s=e.transaction(Qe,"readonly").objectStore(Qe).get(t);s.onsuccess=()=>n(s.result??null),s.onerror=()=>r(s.error)})}async function ju(t){const e=await De();return new Promise((n,r)=>{const o=e.transaction(Qe,"readwrite");o.objectStore(Qe).delete(t),o.oncomplete=()=>n(),o.onerror=()=>r(o.error)})}async function Qr(){const t=await De();return new Promise((e,n)=>{const o=t.transaction(Qe,"readonly").objectStore(Qe).getAll();o.onsuccess=()=>e(o.result),o.onerror=()=>n(o.error)})}async function Sa(t){const e=await De();return new Promise((n,r)=>{const o=e.transaction(et,"readwrite");o.objectStore(et).put(t),o.oncomplete=()=>n(),o.onerror=()=>r(o.error)})}async function Eu(t){const e=await De();return new Promise((n,r)=>{const s=e.transaction(et,"readonly").objectStore(et).get(t);s.onsuccess=()=>n(s.result??null),s.onerror=()=>r(s.error)})}async function Ra(t){const e=await De();return new Promise((n,r)=>{const o=e.transaction(et,"readwrite");o.objectStore(et).delete(t),o.oncomplete=()=>n(),o.onerror=()=>r(o.error)})}async function rr(t){const e=await De();return new Promise((n,r)=>{const s=e.transaction(et,"readonly").objectStore(et).getAll();s.onsuccess=()=>{const a=s.result.filter(i=>i.docId===t);a.sort((i,u)=>u.timestamp-i.timestamp),n(a)},s.onerror=()=>r(s.error)})}const Bu=500;function Ta({store:t,docId:e,debounceMs:n=Bu,onError:r}){let o=null;function s(){Ia(e,t.toJSON()).catch(c=>r==null?void 0:r(c))}function a(){o&&(clearTimeout(o),o=null,s())}const i=t.subscribeAll(()=>{o&&clearTimeout(o),o=setTimeout(()=>{o=null,s()},n)});function u(){o&&clearTimeout(o),o=null,i()}return{stop:u,flush:a}}function En(t,e,n,r){const o={store:t,registry:e,inlineRegistry:r};return{html:_u(t,e,n,o),text:n.map(s=>{const a=t.getBlock(s);return e.get(a.type).toPlainText(a,o)}).join(`
2
- `),json:JSON.stringify({version:1,blocks:n.map(s=>Bn(t,s))})}}function _u(t,e,n,r){let o="",s=0;for(;s<n.length;){const a=t.getBlock(n[s]);if(a.type==="listItem"){const i=!!a.props.ordered;let u="",c=s;for(;c<n.length;){const d=t.getBlock(n[c]);if(d.type!=="listItem"||!!d.props.ordered!==i)break;u+=e.get("listItem").toHTML(d,r),c+=1}const f=i?"ol":"ul";o+=`<${f}>${u}</${f}>`,s=c}else if(a.type==="blockquote"){let i="",u=s;for(;u<n.length;){const c=t.getBlock(n[u]);if(c.type!=="blockquote")break;i+=e.get("blockquote").toHTML(c,r),u+=1}o+=`<blockquote>${i}</blockquote>`,s=u}else o+=e.get(a.type).toHTML(a,r),s+=1}return o}function Bn(t,e){const n=[],r=[],o=s=>{var u;const a=t.getRun(s);if(a){r.push(a);return}const i=t.getBlock(s);if(i){n.push(i);for(const c of i.contentIds)o(c);for(const c of((u=i.props)==null?void 0:u.titleRunIds)??[])o(c)}};return o(e),{rootId:e,blocks:n,runs:r}}function dr({rootId:t,blocks:e,runs:n}){const r=new Map;for(const u of e)r.set(u.id,E());for(const u of n)r.set(u.id,E());const o=u=>r.get(u)??u,s=e.map(u=>{var c;return{...u,id:o(u.id),parentId:u.parentId?o(u.parentId):u.parentId,contentIds:u.contentIds.map(o),props:{...u.props,...(c=u.props)!=null&&c.titleRunIds?{titleRunIds:u.props.titleRunIds.map(o)}:{}}}}),a=n.map(u=>({...u,id:o(u.id)})),i=o(t);return{block:s.find(u=>u.id===i),runs:a,subtreeBlocks:s.filter(u=>u.id!==i)}}function Ou(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Mu(t,e){return{roots:e.map(n=>Bn(t,n))}}function ja(t,e,{parentId:n,index:r}){const o=[];let s=r;for(const a of e.roots){const{block:i,runs:u,subtreeBlocks:c}=dr(a);i.parentId=n,o.push(me(i,n,s,{blocks:[i,...c],runs:u})),s+=1}Ou(t,o)}function Lu(t,e){const n=t.store??t;n.blocks=new Map((e.blocks??[]).map(r=>[r.id,r])),n.runs=new Map((e.runs??[]).map(r=>[r.id,r])),n.rootId=e.rootId??null,n.fieldTypes=new Map((e.fieldTypes??[]).map(r=>[r.id,r])),n._fieldTypesSnapshot=null,n.comments=new Map((e.comments??[]).map(r=>[r.id,r])),n._commentsSnapshot=null,n._orders=new Map,n._notify([...n.blocks.keys(),...n.runs.keys(),"$fieldTypes","$comments"])}function Nu(t,e){for(const n of e)t.register(`__blockTemplate:${n.id}`,{component:()=>null,isLeaf:!0,slashCommand:{label:n.label,icon:n.icon,keywords:n.keywords??[n.label],run(r,{blockId:o,runId:s,sliceStart:a,sliceEnd:i}){const u=r.getRun(s),c=(u==null?void 0:u.value)??"";r.applyOperation(ue(s,{value:c.slice(0,a)+c.slice(i)}));const f=r.getBlock(o),h=r.getBlock(f.parentId).contentIds.indexOf(o)+1;ja(r,n,{parentId:f.parentId,index:h})}}})}function Au({scope:t}={}){const[e,n]=p.useState([]),[r,o]=p.useState(!1),s=p.useCallback(()=>(o(!1),Qr().then(a=>{n(t?a.filter(i=>i.scope===t):a),o(!0)})),[t]);return p.useEffect(()=>{let a=!1;return o(!1),Qr().then(i=>{a||(n(t?i.filter(u=>u.scope===t):i),o(!0))}),()=>{a=!0}},[t]),{templates:e,isLoaded:r,refresh:s}}function Du({templates:t,onSelect:e,emptyLabel:n="No templates yet."}){return t.length===0?l.jsx("p",{className:"be-template-picker-empty",children:n}):l.jsx("ul",{className:"be-template-picker",role:"list",children:t.map(r=>l.jsxs("li",{className:"be-template-card",children:[l.jsxs("div",{className:"be-template-card-body",children:[l.jsx("span",{className:"be-template-card-name",children:r.name}),r.description&&l.jsx("span",{className:"be-template-card-description",children:r.description})]}),l.jsx("button",{type:"button",className:"be-template-card-select",onClick:()=>e(r),children:"Use"})]},r.id))})}function ko(t,{pretty:e=!0}={}){const n=t.getRootId(),{blocks:r,runs:o}=Bn(t,n);return JSON.stringify({version:1,rootId:n,blocks:r,runs:o},null,e?2:0)}function Ea(t,e,n){const r=t.getBlock(t.getRootId());return r?En(t,e,r.contentIds,n).html:""}function Ba(t,e,n){const r=t.getBlock(t.getRootId());return r?En(t,e,r.contentIds,n).text:""}const Pu=5*60*1e3,$u=50;function zu({store:t,docId:e,intervalMs:n=Pu,label:r,maxVersions:o=$u,onSnapshot:s,onError:a}){const i=setInterval(async()=>{try{const u=JSON.parse(ko(t)),c={id:crypto.randomUUID(),docId:e,timestamp:Date.now(),label:r,doc:u};await Sa(c),s==null||s(c);const f=await rr(e);if(f.length>o){const d=f.slice(o);await Promise.all(d.map(h=>Ra(h.id)))}}catch(u){a==null||a(u)}},n);return{stop(){clearInterval(i)}}}function Hu(t){const[e,n]=p.useState([]),[r,o]=p.useState(!1),s=p.useCallback(()=>t?(o(!1),rr(t).then(a=>{n(a),o(!0)})):Promise.resolve(),[t]);return p.useEffect(()=>{if(!t){n([]),o(!0);return}let a=!1;return o(!1),rr(t).then(i=>{a||(n(i),o(!0))}),()=>{a=!0}},[t]),{versions:e,isLoaded:r,refresh:s}}function Fu(t,e){var r;const n=t.getBlock(e);return((r=n.props)==null?void 0:r.titleRunIds)??n.contentIds}function _a(t,e){const n=(t==null?void 0:t.commentIds)??[];return n.includes(e)?t??{}:{...t,commentIds:[...n,e]}}function Uu(t,e){const n=(t==null?void 0:t.commentIds)??[];if(!n.includes(e))return t??{};const r={...t},o=n.filter(s=>s!==e);return o.length>0?r.commentIds=o:delete r.commentIds,r}function Vu(t,e,n,r,o){const s=_a(e.marks,o);if(n===0&&r===e.value.length)return{type:"updateRun",id:e.id,patch:{marks:s}};const a=e.value.slice(0,n),i=e.value.slice(n,r),u=e.value.slice(r),c=[];return a&&c.push({id:E(),type:"text",value:a,marks:{...e.marks}}),c.push({id:E(),type:"text",value:i,marks:s}),u&&c.push({id:E(),type:"text",value:u,marks:{...e.marks}}),_t(t,[e.id],c)}function vo(t,{blockId:e,startRunId:n,startOffset:r,endRunId:o,endOffset:s},a){const i=Fu(t,e),u=i.indexOf(n),c=i.indexOf(o);if(u===-1||c===-1)return null;const[f,d]=u<=c?[u,c]:[c,u],h=u<=c?r:s,m=u<=c?s:r,g=i.slice(f,d+1),x=g.map(k=>t.getRun(k));if(f===d){const k=x[0];if(k.type!=="text")return null;const w=Math.max(0,Math.min(h,m)),v=Math.min(k.value.length,Math.max(h,m));return w===v?null:Vu(e,k,w,v,a)}const y=[];return x.forEach((k,w)=>{if(k.type!=="text"){y.push(k);return}const v=w===0,j=w===x.length-1,I=v?h:0,C=j?m:k.value.length,T=k.value.slice(0,I),M=k.value.slice(I,C),B=k.value.slice(C);T&&y.push({id:E(),type:"text",value:T,marks:{...k.marks}}),y.push({id:E(),type:"text",value:M,marks:_a(k.marks,a)}),B&&y.push({id:E(),type:"text",value:B,marks:{...k.marks}})}),_t(e,g,y)}function wo(t,e){var r,o;const n=[];for(const s of t.getAllRunIds()){const a=t.getRun(s);(o=(r=a==null?void 0:a.marks)==null?void 0:r.commentIds)!=null&&o.includes(e)&&n.push({type:"updateRun",id:s,patch:{marks:Uu(a.marks,e)}})}return n}function Oa(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Yu(t,e,{authorId:n,text:r}){const o=E(),s=vo(t,e,o),a={id:o,blockId:e.blockId,anchorRunIds:[e.startRunId,e.endRunId],resolved:!1,messages:[{id:E(),authorId:n,text:r,createdAt:Date.now()}]},i=s?[s,Cn(a)]:[Cn(a)];return Oa(t,i),o}function Ma(t,e,{authorId:n,text:r}){const o={id:E(),authorId:n,text:r,createdAt:Date.now()};return t.applyOperation(xo(e,o)),o.id}function La(t,e,n=!0){t.applyOperation(yo(e,n))}function Na(t,e){const n=wo(t,e);Oa(t,[...n,go(e)])}const Ku=`/*\r
1
+ "use strict";var dd=Object.defineProperty;var ud=(t,e,n)=>e in t?dd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var Ms=(t,e,n)=>ud(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react"),l=require("react/jsx-runtime"),De=require("react-dom"),Z={INSERT_BLOCK:"insertBlock",REMOVE_BLOCK:"removeBlock",MOVE_BLOCK:"moveBlock",CHANGE_BLOCK_TYPE:"changeBlockType",UPDATE_BLOCK_PROPS:"updateBlockProps",UPDATE_RUN:"updateRun",SET_BLOCK_CONTENT_IDS:"setBlockContentIds",REPLACE_RUN_SPAN:"replaceRunSpan",SET_BLOCK_RUNS:"setBlockRuns",EDIT_RUN_CHARS:"editRunChars",ADD_FIELD_TYPE:"addFieldType",UPDATE_FIELD_TYPE:"updateFieldType",REMOVE_FIELD_TYPE:"removeFieldType",ADD_COMMENT_THREAD:"addCommentThread",REMOVE_COMMENT_THREAD:"removeCommentThread",ADD_COMMENT_REPLY:"addCommentReply",REMOVE_COMMENT_REPLY:"removeCommentReply",RESOLVE_COMMENT:"resolveComment"};function me(t,e,n,r){return{type:Z.INSERT_BLOCK,block:t,parentId:e,index:n,subtree:r}}function ee(t){return{type:Z.REMOVE_BLOCK,id:t}}function ct(t,e,n){return{type:Z.MOVE_BLOCK,id:t,toParentId:e,toIndex:n}}function J(t,e){return{type:Z.UPDATE_BLOCK_PROPS,id:t,patch:e}}function mo(t,e,n){return{type:Z.CHANGE_BLOCK_TYPE,id:t,blockType:e,props:n}}function de(t,e){return{type:Z.UPDATE_RUN,id:t,patch:e}}function eo(t,e,n,r){return{type:Z.EDIT_RUN_CHARS,id:t,tombstoneIds:e,restoreIds:n,previousValue:r}}function nn(t,e){return{type:Z.SET_BLOCK_CONTENT_IDS,blockId:t,contentIds:e}}function Nt(t,e,n){return{type:Z.REPLACE_RUN_SPAN,blockId:t,oldRunIds:e,newRuns:n}}function Me(t,e){return{type:Z.SET_BLOCK_RUNS,blockId:t,runs:e}}function bo(t){return{type:Z.ADD_FIELD_TYPE,fieldType:t}}function go(t,e){return{type:Z.UPDATE_FIELD_TYPE,id:t,patch:e}}function xo(t){return{type:Z.REMOVE_FIELD_TYPE,id:t}}function Cn(t){return{type:Z.ADD_COMMENT_THREAD,thread:t}}function yo(t){return{type:Z.REMOVE_COMMENT_THREAD,commentId:t}}function ko(t,e){return{type:Z.ADD_COMMENT_REPLY,commentId:t,message:e}}function wa(t,e){return{type:Z.REMOVE_COMMENT_REPLY,commentId:t,messageId:e}}function vo(t,e){return{type:Z.RESOLVE_COMMENT,commentId:t,resolved:e}}const pd=Object.freeze(Object.defineProperty({__proto__:null,OP:Z,addCommentReply:ko,addCommentThread:Cn,addFieldType:bo,changeBlockType:mo,editRunChars:eo,insertBlock:me,moveBlock:ct,removeBlock:ee,removeCommentReply:wa,removeCommentThread:yo,removeFieldType:xo,replaceRunSpan:Nt,resolveComment:vo,setBlockContentIds:nn,setBlockRuns:Me,updateBlockProps:J,updateFieldType:go,updateRun:de},Symbol.toStringTag,{value:"Module"}));class Sn{constructor(e){this.peerId=e,this.wallTime=0,this.counter=0}tick(){const e=Date.now();return e>this.wallTime?(this.wallTime=e,this.counter=0):this.counter+=1,{wallTime:this.wallTime,counter:this.counter,peerId:this.peerId}}receive(e){const n=Date.now(),r=Math.max(n,this.wallTime,e.wallTime);return r===this.wallTime&&r===e.wallTime?this.counter=Math.max(this.counter,e.counter)+1:r===this.wallTime?this.counter+=1:r===e.wallTime?this.counter=e.counter+1:this.counter=0,this.wallTime=r,{wallTime:this.wallTime,counter:this.counter,peerId:this.peerId}}static compare(e,n){return e.wallTime!==n.wallTime?e.wallTime-n.wallTime:e.counter!==n.counter?e.counter-n.counter:e.peerId===n.peerId?0:e.peerId<n.peerId?-1:1}}function Ia(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`peer-${Date.now()}-${Math.random().toString(36).slice(2)}`}class Qt{constructor(){this.slots=new Map}static fromArray(e,{peerId:n="legacy"}={}){const r=new Qt;let o=null;for(const s of e)r.slots.set(s,{id:s,originId:o,peerId:n,clock:{wallTime:0,counter:0,peerId:n},deleted:!1}),o=s;return r}has(e){return this.slots.has(e)}getSlot(e){return this.slots.get(e)}isDeleted(e){const n=this.slots.get(e);return!n||n.deleted}insert(e,n,r,o){this.slots.has(e)||this.slots.set(e,{id:e,originId:n,peerId:o,clock:r,deleted:!1})}delete(e,n){const r=this.slots.get(e);r&&(r.deleted=!0,n&&(r.deletedClock=n))}restore(e){const n=this.slots.get(e);n&&(n.deleted=!1)}move(e,n,r,o){if(n===e)return;const s=this.slots.get(e);if(!s)return;const a=s.originId;for(const i of this.slots.values())i.originId===e&&(i.originId=a);s.originId=n,s.peerId=o,s.clock=r,s.deleted=!1}merge(e){for(const n of e){const r=this.slots.get(n.id);r?n.deleted&&!r.deleted&&(r.deleted=!0):this.slots.set(n.id,{...n})}}toSlotArray(){return Array.from(this.slots.values())}tombstoneCount(){let e=0;for(const n of this.slots.values())n.deleted&&(e+=1);return e}pruneTombstones(e){let n=0;for(const[r,o]of this.slots){if(!o.deleted)continue;const s=o.deletedClock??o.clock;if(!(Sn.compare(s,e)>=0)){for(const a of this.slots.values())a.originId===r&&(a.originId=o.originId);this.slots.delete(r),n+=1}}return n}toArray(){const e=new Map;for(const o of this.slots.values()){const s=e.get(o.originId);s?s.push(o):e.set(o.originId,[o])}for(const o of e.values())o.sort((s,a)=>Sn.compare(a.clock,s.clock));const n=[],r=[...e.get(null)??[]].reverse();for(;r.length>0;){const o=r.pop();o.deleted||n.push(o.id);const s=e.get(o.id);if(s)for(let a=s.length-1;a>=0;a-=1)r.push(s[a])}return n}}class en{constructor(){this.clocks=new Map}static compositeKey(e,n){return`${e}:${n}`}get(e,n){return this.clocks.get(en.compositeKey(e,n))??null}recordLocal(e,n,r){this.clocks.set(en.compositeKey(e,n),r)}shouldApplyRemote(e,n,r){const o=this.get(e,n);return o?Sn.compare(r,o)>0:!0}recordRemote(e,n,r){this.clocks.set(en.compositeKey(e,n),r)}}function fd(t,e){const n=Array.from(t??""),r=Array.from(e??"");let o=0;const s=Math.min(n.length,r.length);for(;o<s&&n[o]===r[o];)o+=1;let a=n.length,i=r.length;for(;a>o&&i>o&&n[a-1]===r[i-1];)a-=1,i-=1;return{start:o,oldEnd:a,newEnd:i,oldChars:n,newChars:r}}function _(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`id-${Date.now()}-${Math.random().toString(36).slice(2)}`}const Hr="$fieldTypes",Xe="$comments";class Bn{constructor(e){this.blocks=new Map(((e==null?void 0:e.blocks)??[]).map(n=>[n.id,n])),this.runs=new Map(((e==null?void 0:e.runs)??[]).map(n=>[n.id,n])),this.rootId=(e==null?void 0:e.rootId)??null,this.fieldTypes=new Map(((e==null?void 0:e.fieldTypes)??[]).map(n=>[n.id,n])),this._fieldTypesSnapshot=null,this.comments=new Map(((e==null?void 0:e.comments)??[]).map(n=>[n.id,n])),this._commentsSnapshot=null,this._listeners=new Map,this._globalListeners=new Set,this._peerId=Ia(),this._clock=new Sn(this._peerId),this._fieldClocks=new en,this._orders=new Map,this._runOrders=new Map,this._runChars=new Map,this._runValueSnapshots=new Map}_getOrder(e){let n=this._orders.get(e);if(!n){const r=this.blocks.get(e);n=Qt.fromArray((r==null?void 0:r.contentIds)??[],{peerId:"legacy"}),this._orders.set(e,n)}return n}_getRunOrder(e){let n=this._runOrders.get(e);if(!n){const r=this.runs.get(e),o=new Map;n=new Qt;let s=null,a=0;for(const i of Array.from((r==null?void 0:r.value)??"")){const d=`${e}:legacyChar:${a}`;o.set(d,i),n.insert(d,s,{wallTime:0,counter:0,peerId:"legacy"},"legacy"),s=d,a+=1}this._runOrders.set(e,n),this._runChars.set(e,o)}return n}_materializeRunValue(e){let n=this._runValueSnapshots.get(e);if(n===void 0){const r=this._getRunOrder(e),o=this._runChars.get(e);n=r.toArray().map(s=>o.get(s)).join(""),this._runValueSnapshots.set(e,n)}return n}_editRunText(e,n){const r=this._materializeRunValue(e),{start:o,oldEnd:s,newEnd:a,newChars:i}=fd(r,n),d=this._getRunOrder(e),c=this._runChars.get(e),f=d.toArray(),u=this._clock.tick(),h=[];for(let x=o;x<s;x+=1){const y=f[x];d.delete(y,u),h.push({id:y,clock:u})}const m=[];let g=o>0?f[o-1]:null;for(let x=o;x<a;x+=1){const y=_(),k=i[x];c.set(y,k),d.insert(y,g,u,this._peerId),m.push({id:y,char:k,afterId:g,clock:u}),g=y}return this._runValueSnapshots.delete(e),{oldValue:r,insertedChars:m,deletedCharIds:h,clock:u}}_replayRunTextEdit(e,n){const r=this._getRunOrder(e),o=this._runChars.get(e);for(const s of n.insertedChars)r.has(s.id)?r.restore(s.id):(o.set(s.id,s.char),r.insert(s.id,s.afterId,s.clock,this._peerId));for(const s of n.deletedCharIds)r.delete(s.id,s.clock);this._runValueSnapshots.delete(e)}getBlock(e){return this.blocks.get(e)}getRun(e){return this.runs.get(e)}getFieldTypes(){return this._fieldTypesSnapshot||(this._fieldTypesSnapshot=[...this.fieldTypes.values()]),this._fieldTypesSnapshot}getFieldType(e){return this.fieldTypes.get(e)}getComments(){return this._commentsSnapshot||(this._commentsSnapshot=[...this.comments.values()]),this._commentsSnapshot}getComment(e){return this.comments.get(e)}getAllRunIds(){return[...this.runs.keys()]}getRootId(){return this.rootId}subscribe(e,n){let r=this._listeners.get(e);return r||(r=new Set,this._listeners.set(e,r)),r.add(n),()=>{r.delete(n),r.size===0&&this._listeners.delete(e)}}subscribeAll(e){return this._globalListeners.add(e),()=>this._globalListeners.delete(e)}_notify(e){for(const n of e){const r=this._listeners.get(n);if(r)for(const o of[...r])o()}if(this._globalListeners.size>0)for(const n of[...this._globalListeners])n()}_captureSubtree(e){const n=[],r=[],o=s=>{var i;if(this.runs.has(s)){r.push(this.runs.get(s));return}const a=this.blocks.get(s);if(a){n.push(a);for(const d of a.contentIds)o(d);for(const d of((i=a.props)==null?void 0:i.titleRunIds)??[])o(d)}};return o(e),{blocks:n,runs:r}}_deleteSubtree(e){const n=r=>{var s;if(this.runs.has(r)){this.runs.delete(r);return}const o=this.blocks.get(r);if(o){for(const a of o.contentIds)n(a);for(const a of((s=o.props)==null?void 0:s.titleRunIds)??[])n(a);this.blocks.delete(r)}};n(e)}applyOperation(e){var n;switch(e.type){case Z.UPDATE_RUN:{const r=this.runs.get(e.id),o=Object.keys(e.patch);if(o.length===1&&o[0]==="value"){let i=e._charEdit;if(i)this._replayRunTextEdit(e.id,i);else{const{oldValue:c,insertedChars:f,deletedCharIds:u,clock:h}=this._editRunText(e.id,e.patch.value);i={oldValue:c,insertedChars:f,deletedCharIds:u,clock:h},e._charEdit=i}const d=this._materializeRunValue(e.id);return this.runs.set(e.id,{...r,value:d}),this._lastEnvelope={kind:"runTextEdit",runId:e.id,insertedChars:i.insertedChars,deletedCharIds:i.deletedCharIds,clock:i.clock},this._notify([e.id]),eo(e.id,i.insertedChars.map(c=>c.id),i.deletedCharIds.map(c=>c.id),i.oldValue)}const s={},a={};for(const i of o)s[i]=r[i],a[i]=this._clock.tick(),this._fieldClocks.recordLocal(e.id,i,a[i]);return this.runs.set(e.id,{...r,...e.patch}),this._lastEnvelope={kind:"fieldWrite",target:"run",id:e.id,patch:e.patch,clocks:a},this._notify([e.id]),de(e.id,s)}case Z.EDIT_RUN_CHARS:{const r=this._getRunOrder(e.id),o=this._clock.tick();for(const i of e.tombstoneIds)r.delete(i,o);for(const i of e.restoreIds)r.restore(i);this._runValueSnapshots.delete(e.id);const s=this.runs.get(e.id),a=this._materializeRunValue(e.id);return this.runs.set(e.id,{...s,value:a}),this._lastEnvelope={kind:"runCharEdit",runId:e.id,tombstoneIds:e.tombstoneIds,restoreIds:e.restoreIds,clock:o},this._notify([e.id]),eo(e.id,e.restoreIds,e.tombstoneIds)}case Z.UPDATE_BLOCK_PROPS:{const r=this.blocks.get(e.id),o={},s={};for(const a of Object.keys(e.patch))o[a]=r.props[a],s[a]=this._clock.tick(),this._fieldClocks.recordLocal(e.id,`props.${a}`,s[a]);return this.blocks.set(e.id,{...r,props:{...r.props,...e.patch}}),this._lastEnvelope={kind:"fieldWrite",target:"blockProps",id:e.id,patch:e.patch,clocks:s},this._notify([e.id]),J(e.id,o)}case Z.CHANGE_BLOCK_TYPE:{const r=this.blocks.get(e.id),o=r.type,s=r.props,a=this._clock.tick();return this._fieldClocks.recordLocal(e.id,"type",a),this.blocks.set(e.id,{...r,type:e.blockType,props:e.props}),this._lastEnvelope={kind:"fieldWrite",target:"blockType",id:e.id,blockType:e.blockType,props:e.props,clock:a},this._notify([e.id]),mo(e.id,o,s)}case Z.INSERT_BLOCK:{if(e.subtree){for(const s of e.subtree.blocks)this.blocks.set(s.id,s);for(const s of e.subtree.runs)this.runs.set(s.id,s)}else this.blocks.set(e.block.id,e.block);const r=this.blocks.get(e.parentId),o=this._getOrder(e.parentId);if(o.has(e.block.id))o.restore(e.block.id);else{const s=o.toArray(),a=e.index??s.length,i=a>0?s[a-1]:null;o.insert(e.block.id,i,this._clock.tick(),this._peerId)}return this.blocks.set(e.parentId,{...r,contentIds:o.toArray()}),this._lastEnvelope={kind:"insertSlot",parentId:e.parentId,blockId:e.block.id,slot:o.getSlot(e.block.id),subtree:e.subtree??{blocks:[e.block],runs:[]}},this._notify([e.block.id,e.parentId]),ee(e.block.id)}case Z.REMOVE_BLOCK:{const r=this.blocks.get(e.id),o=r.parentId,s=this.blocks.get(o),a=this._getOrder(o),i=a.toArray().indexOf(e.id),d=this._captureSubtree(e.id);this._deleteSubtree(e.id);const c=this._clock.tick();return a.delete(e.id,c),this.blocks.set(o,{...s,contentIds:a.toArray()}),this._lastEnvelope={kind:"deleteSlot",parentId:o,blockId:e.id,clock:c},this._notify([o]),{type:Z.INSERT_BLOCK,block:r,parentId:o,index:i,subtree:d}}case Z.MOVE_BLOCK:{const o=this.blocks.get(e.id).parentId,s=this._getOrder(o),a=s.toArray().indexOf(e.id);s.delete(e.id,this._clock.tick()),this.blocks.set(o,{...this.blocks.get(o),contentIds:s.toArray()});const i=this._getOrder(e.toParentId),d=i.toArray(),c=e.toIndex??d.length,f=c>0?d[c-1]:null,u=this._clock.tick();i.has(e.id)?i.move(e.id,f,u,this._peerId):i.insert(e.id,f,u,this._peerId),this.blocks.set(e.toParentId,{...this.blocks.get(e.toParentId),contentIds:i.toArray()}),this.blocks.set(e.id,{...this.blocks.get(e.id),parentId:e.toParentId}),this._lastEnvelope={kind:"moveSlot",fromParentId:o,toParentId:e.toParentId,blockId:e.id,slot:i.getSlot(e.id)};const h=new Set([e.id,o,e.toParentId]);return this._notify(h),ct(e.id,o,a)}case Z.SET_BLOCK_CONTENT_IDS:{const r=this.blocks.get(e.blockId),o=r.contentIds;return this.blocks.set(e.blockId,{...r,contentIds:e.contentIds}),this._orders.set(e.blockId,Qt.fromArray(e.contentIds,{peerId:"legacy"})),this._lastEnvelope=null,this._notify([e.blockId]),nn(e.blockId,o)}case Z.REPLACE_RUN_SPAN:{const r=this.blocks.get(e.blockId),o=r.contentIds.indexOf(e.oldRunIds[0])!==-1,s=o?r.contentIds:((n=r.props)==null?void 0:n.titleRunIds)??[],a=s.indexOf(e.oldRunIds[0]),i=e.oldRunIds.map(c=>this.runs.get(c));for(const c of e.oldRunIds)this.runs.delete(c);for(const c of e.newRuns)this.runs.set(c.id,c);const d=[...s];return d.splice(a,e.oldRunIds.length,...e.newRuns.map(c=>c.id)),o?this.blocks.set(e.blockId,{...r,contentIds:d}):this.blocks.set(e.blockId,{...r,props:{...r.props,titleRunIds:d}}),this._lastEnvelope=null,this._notify([e.blockId,...e.oldRunIds,...e.newRuns.map(c=>c.id)]),Nt(e.blockId,e.newRuns.map(c=>c.id),i)}case Z.SET_BLOCK_RUNS:{const r=this.blocks.get(e.blockId),o=r.props&&"titleRunIds"in r.props,s=o?r.props.titleRunIds:r.contentIds,a=s.map(d=>this.runs.get(d)).filter(Boolean);for(const d of s)this.runs.delete(d);for(const d of e.runs)this.runs.set(d.id,d);const i=e.runs.map(d=>d.id);return o?this.blocks.set(e.blockId,{...r,props:{...r.props,titleRunIds:i}}):this.blocks.set(e.blockId,{...r,contentIds:i}),this._lastEnvelope=null,this._notify([e.blockId,...s,...i]),Me(e.blockId,a)}case Z.ADD_FIELD_TYPE:return this.fieldTypes.set(e.fieldType.id,e.fieldType),this._fieldTypesSnapshot=null,this._notify([Hr]),xo(e.fieldType.id);case Z.UPDATE_FIELD_TYPE:{const r=this.fieldTypes.get(e.id),o={};for(const s of Object.keys(e.patch))o[s]=r[s];return this.fieldTypes.set(e.id,{...r,...e.patch}),this._fieldTypesSnapshot=null,this._notify([Hr]),go(e.id,o)}case Z.REMOVE_FIELD_TYPE:{const r=this.fieldTypes.get(e.id);return this.fieldTypes.delete(e.id),this._fieldTypesSnapshot=null,this._notify([Hr]),bo(r)}case Z.ADD_COMMENT_THREAD:return this.comments.set(e.thread.id,e.thread),this._commentsSnapshot=null,this._lastEnvelope={kind:"commentWrite",op:"addThread",thread:e.thread},this._notify([Xe]),yo(e.thread.id);case Z.REMOVE_COMMENT_THREAD:{const r=this.comments.get(e.commentId);return this.comments.delete(e.commentId),this._commentsSnapshot=null,this._lastEnvelope={kind:"commentWrite",op:"removeThread",commentId:e.commentId},this._notify([Xe]),Cn(r)}case Z.ADD_COMMENT_REPLY:{const r=this.comments.get(e.commentId);return this.comments.set(e.commentId,{...r,messages:[...r.messages,e.message]}),this._commentsSnapshot=null,this._lastEnvelope={kind:"commentWrite",op:"addReply",commentId:e.commentId,message:e.message},this._notify([Xe]),wa(e.commentId,e.message.id)}case Z.REMOVE_COMMENT_REPLY:{const r=this.comments.get(e.commentId),o=r.messages.find(s=>s.id===e.messageId);return this.comments.set(e.commentId,{...r,messages:r.messages.filter(s=>s.id!==e.messageId)}),this._commentsSnapshot=null,this._lastEnvelope={kind:"commentWrite",op:"removeReply",commentId:e.commentId,messageId:e.messageId},this._notify([Xe]),ko(e.commentId,o)}case Z.RESOLVE_COMMENT:{const r=this.comments.get(e.commentId),o=r.resolved;return this.comments.set(e.commentId,{...r,resolved:e.resolved}),this._commentsSnapshot=null,this._lastEnvelope={kind:"commentWrite",op:"resolve",commentId:e.commentId,resolved:e.resolved},this._notify([Xe]),vo(e.commentId,o)}default:throw new Error(`Unknown operation type: ${e.type}`)}}applyOperations(e){return e.map(n=>this.applyOperation(n))}getLastEnvelope(){return this._lastEnvelope}applyRemoteOperation(e){var n,r;if(e)switch(e.kind){case"insertSlot":{for(const a of e.subtree.blocks)this.blocks.has(a.id)||this.blocks.set(a.id,a);for(const a of e.subtree.runs)this.runs.has(a.id)||this.runs.set(a.id,a);const o=this._getOrder(e.parentId);o.merge([e.slot]);const s=this.blocks.get(e.parentId);this.blocks.set(e.parentId,{...s,contentIds:o.toArray()}),this._clock.receive(e.slot.clock),this._notify([e.blockId,e.parentId]);return}case"deleteSlot":{const o=this._getOrder(e.parentId);this.blocks.has(e.blockId)&&this._deleteSubtree(e.blockId),o.delete(e.blockId,e.clock),e.clock&&this._clock.receive(e.clock);const s=this.blocks.get(e.parentId);this.blocks.set(e.parentId,{...s,contentIds:o.toArray()}),this._notify([e.parentId]);return}case"moveSlot":{const o=this._getOrder(e.fromParentId);o.delete(e.blockId,(n=e.slot)==null?void 0:n.clock),this.blocks.set(e.fromParentId,{...this.blocks.get(e.fromParentId),contentIds:o.toArray()});const s=this._getOrder(e.toParentId),a=s.has(e.blockId);s.merge([e.slot]),a&&s.move(e.blockId,e.slot.originId,e.slot.clock,e.slot.peerId),this.blocks.set(e.toParentId,{...this.blocks.get(e.toParentId),contentIds:s.toArray()}),this.blocks.has(e.blockId)&&this.blocks.set(e.blockId,{...this.blocks.get(e.blockId),parentId:e.toParentId}),this._clock.receive(e.slot.clock),this._notify([e.blockId,e.fromParentId,e.toParentId]);return}case"fieldWrite":{if(e.target==="run"){const o=this.runs.get(e.id);if(o){const s={};for(const a of Object.keys(e.patch)){const i=e.clocks[a];this._fieldClocks.shouldApplyRemote(e.id,a,i)&&(s[a]=e.patch[a],this._fieldClocks.recordRemote(e.id,a,i))}Object.keys(s).length>0&&(this.runs.set(e.id,{...o,...s}),this._notify([e.id]))}}else if(e.target==="blockProps"){const o=this.blocks.get(e.id);if(o){const s={};for(const a of Object.keys(e.patch)){const i=e.clocks[a];this._fieldClocks.shouldApplyRemote(e.id,`props.${a}`,i)&&(s[a]=e.patch[a],this._fieldClocks.recordRemote(e.id,`props.${a}`,i))}Object.keys(s).length>0&&(this.blocks.set(e.id,{...o,props:{...o.props,...s}}),this._notify([e.id]))}}else if(e.target==="blockType"){const o=this.blocks.get(e.id);o&&this._fieldClocks.shouldApplyRemote(e.id,"type",e.clock)&&(this._fieldClocks.recordRemote(e.id,"type",e.clock),this.blocks.set(e.id,{...o,type:e.blockType,props:e.props}),this._notify([e.id]))}for(const o of Object.values(e.clocks??{}))this._clock.receive(o);e.clock&&this._clock.receive(e.clock);return}case"runTextEdit":{const o=this._getRunOrder(e.runId),s=this._runChars.get(e.runId);for(const i of e.insertedChars)o.has(i.id)||s.set(i.id,i.char),o.insert(i.id,i.afterId,i.clock,(r=i.clock)==null?void 0:r.peerId);for(const i of e.deletedCharIds)o.delete(i.id,i.clock);this._runValueSnapshots.delete(e.runId);const a=this.runs.get(e.runId);a&&(this.runs.set(e.runId,{...a,value:this._materializeRunValue(e.runId)}),this._notify([e.runId])),this._clock.receive(e.clock);return}case"runCharEdit":{const o=this._getRunOrder(e.runId);for(const a of e.tombstoneIds)o.delete(a,e.clock);for(const a of e.restoreIds)o.restore(a);this._runValueSnapshots.delete(e.runId);const s=this.runs.get(e.runId);s&&(this.runs.set(e.runId,{...s,value:this._materializeRunValue(e.runId)}),this._notify([e.runId])),this._clock.receive(e.clock);return}case"commentWrite":{if(e.op==="addThread")this.comments.has(e.thread.id)||(this.comments.set(e.thread.id,e.thread),this._commentsSnapshot=null,this._notify([Xe]));else if(e.op==="removeThread")this.comments.delete(e.commentId)&&(this._commentsSnapshot=null,this._notify([Xe]));else if(e.op==="addReply"){const o=this.comments.get(e.commentId);o&&!o.messages.some(s=>s.id===e.message.id)&&(this.comments.set(e.commentId,{...o,messages:[...o.messages,e.message]}),this._commentsSnapshot=null,this._notify([Xe]))}else if(e.op==="removeReply"){const o=this.comments.get(e.commentId);o&&o.messages.some(s=>s.id===e.messageId)&&(this.comments.set(e.commentId,{...o,messages:o.messages.filter(s=>s.id!==e.messageId)}),this._commentsSnapshot=null,this._notify([Xe]))}else if(e.op==="resolve"){const o=this.comments.get(e.commentId);o&&(this.comments.set(e.commentId,{...o,resolved:e.resolved}),this._commentsSnapshot=null,this._notify([Xe]))}return}default:throw new Error(`Unknown remote envelope kind: ${e.kind}`)}}getTombstoneCount(){let e=0;for(const n of this._orders.values())e+=n.tombstoneCount();for(const n of this._runOrders.values())e+=n.tombstoneCount();return e}pruneTombstones({maxAgeMs:e=24*60*60*1e3,now:n=Date.now()}={}){const r={wallTime:n-e,counter:0,peerId:""};let o=0;for(const s of this._orders.values())o+=s.pruneTombstones(r);for(const s of this._runOrders.values())o+=s.pruneTombstones(r);return o}toJSON(){return{blocks:[...this.blocks.values()],runs:[...this.runs.values()],rootId:this.rootId,fieldTypes:[...this.fieldTypes.values()],comments:[...this.comments.values()]}}static fromJSON(e){return new Bn(e)}}const hd=500;function md(t,e){const n=t??"",r=e??"";let o=0;const s=Math.min(n.length,r.length);for(;o<s&&n[o]===r[o];)o+=1;let a=n.length,i=r.length;for(;a>o&&i>o&&n[a-1]===r[i-1];)a-=1,i-=1;return{beforeOffset:a,afterOffset:i}}function Ca(t){var e;if((t==null?void 0:t.type)==="updateRun"&&typeof((e=t.patch)==null?void 0:e.value)=="string")return t.patch.value;if((t==null?void 0:t.type)==="editRunChars"&&typeof t.previousValue=="string")return t.previousValue}function Os(t){var i;if(!t.ops.length||!t.inverses.length)return null;const e=t.ops[0],n=t.ops[t.ops.length-1];if(e.type!=="updateRun"||n.type!=="updateRun"||e.id!==n.id||typeof((i=n.patch)==null?void 0:i.value)!="string")return null;const r=t.inverses[t.inverses.length-1],o=Ca(r);if(o===void 0)return null;const{beforeOffset:s,afterOffset:a}=md(o,n.patch.value);return{runId:e.id,beforeOffset:s,afterOffset:a}}function Ls(t){const e=[],n=r=>{var o;r&&((o=r.block)!=null&&o.id&&e.push(r.block.id),r.blockId&&e.push(r.blockId),r.id&&e.push(r.id),r.parentId&&e.push(r.parentId),r.toParentId&&e.push(r.toParentId))};for(const r of t.ops)n(r);for(const r of t.inverses)n(r);return[...new Set(e)]}class Sa{constructor(e,{idleMs:n=hd,trackChanges:r=!1,maxChangeLogSize:o=500,defaultActorId:s=null}={}){this.store=e,this.idleMs=n,this.defaultActorId=s,this.undoStack=[],this.redoStack=[],this.currentBatch=null,this.idleTimer=null,this.historyLog=[],this._listeners=new Set,this._undoRedoSnapshot={canUndo:!1,canRedo:!1},this._pendingSelection=null,this._pendingAffectedBlockIds=[],this.trackChanges=r,this.maxChangeLogSize=o,this.changeLog=[]}_recordChange(e,n,r){var a;if(!this.trackChanges)return;const o=e.patch!==void 0&&(n==null?void 0:n.patch)!==void 0,s=o?void 0:Ca(n);this.changeLog.push({opType:e.type,id:e.id??e.blockId??((a=e.block)==null?void 0:a.id),before:o?n.patch:s!==void 0?{value:s}:void 0,after:o||s!==void 0?e.patch:void 0,actorId:r.actorId??null,timestamp:r.timestamp??Date.now()}),this.changeLog.length>this.maxChangeLogSize&&this.changeLog.shift()}getChangeLog(){return[...this.changeLog]}getPendingSelection(){return this._pendingSelection}getPendingAffectedBlockIds(){return this._pendingAffectedBlockIds}getUndoRedoSnapshot(){const e=this.canUndo(),n=this.canRedo();return(this._undoRedoSnapshot.canUndo!==e||this._undoRedoSnapshot.canRedo!==n)&&(this._undoRedoSnapshot={canUndo:e,canRedo:n}),this._undoRedoSnapshot}getBlock(e){return this.store.getBlock(e)}getRun(e){return this.store.getRun(e)}getRootId(){return this.store.getRootId()}getFieldTypes(){return this.store.getFieldTypes()}getFieldType(e){return this.store.getFieldType(e)}getComments(){return this.store.getComments()}getComment(e){return this.store.getComment(e)}getAllRunIds(){return this.store.getAllRunIds()}subscribe(e,n){return this.store.subscribe(e,n)}subscribeAll(e){return this.store.subscribeAll(e)}getTombstoneCount(){return this.store.getTombstoneCount()}pruneTombstones(e){return this.store.pruneTombstones(e)}toJSON(){return this.store.toJSON()}applyOperation(e,n={}){return this.perform(e,n)}applyOperations(e,n={}){return e.map(r=>this.perform(r,n))}setDefaultActorId(e){this.defaultActorId=e}performBatch(e,n={}){var a;const r=n.actorId??this.defaultActorId,o=n.timestamp??Date.now();this._commitCurrentBatch();const s=[];for(const i of e){const d=this.store.applyOperation(i);s.unshift(d),this.historyLog.push({opType:i.type,id:i.id??i.blockId??((a=i.block)==null?void 0:a.id),actorId:r,timestamp:o}),this._recordChange(i,d,{actorId:r,timestamp:o})}this.redoStack=[],this.undoStack.push({ops:[...e],inverses:s,batchKey:null,actorId:r,timestamp:o,lastTimestamp:o,boundaryHit:!0}),this._notify()}perform(e,n={}){const r=n.actorId??this.defaultActorId,o=n.timestamp??Date.now(),s=this.store.applyOperation(e);return this._record(e,s,{actorId:r,timestamp:o}),s}_batchKeyFor(e){return e.type==="updateRun"?`run:${e.id}`:null}_isWordBoundary(e){var r;if(e.type!=="updateRun")return!1;const n=(r=e.patch)==null?void 0:r.value;return typeof n!="string"||n.length===0?!1:/\s/.test(n[n.length-1])}_record(e,n,r){var i;this.redoStack=[];const o=this._batchKeyFor(e),s=this.currentBatch&&r.timestamp-this.currentBatch.lastTimestamp<=this.idleMs;this.currentBatch&&o!==null&&this.currentBatch.batchKey===o&&s&&!this.currentBatch.boundaryHit?(this.currentBatch.ops.push(e),this.currentBatch.inverses.unshift(n),this.currentBatch.lastTimestamp=r.timestamp,this._isWordBoundary(e)&&(this.currentBatch.boundaryHit=!0)):(this._commitCurrentBatch(),this.currentBatch={ops:[e],inverses:[n],batchKey:o,actorId:r.actorId,timestamp:r.timestamp,lastTimestamp:r.timestamp,boundaryHit:this._isWordBoundary(e)}),this._resetIdleTimer(),this.historyLog.push({opType:e.type,id:e.id??((i=e.block)==null?void 0:i.id),actorId:r.actorId,timestamp:r.timestamp}),this._recordChange(e,n,r),this._notify()}_resetIdleTimer(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this._commitCurrentBatch(),this._notify()},this.idleMs)}_commitCurrentBatch(){this.currentBatch&&(this.undoStack.push(this.currentBatch),this.currentBatch=null,this.idleTimer&&(clearTimeout(this.idleTimer),this.idleTimer=null))}flush(){this._commitCurrentBatch(),this._notify()}undo(){this._commitCurrentBatch();const e=this.undoStack.pop();if(!e)return!1;for(const r of e.inverses)this.store.applyOperation(r);this.redoStack.push(e);const n=Os(e);return this._pendingSelection=n?{runId:n.runId,offset:n.beforeOffset}:null,this._pendingAffectedBlockIds=Ls(e),this._notify(),!0}redo(){const e=this.redoStack.pop();if(!e)return!1;for(const r of e.ops)this.store.applyOperation(r);this.undoStack.push(e);const n=Os(e);return this._pendingSelection=n?{runId:n.runId,offset:n.afterOffset}:null,this._pendingAffectedBlockIds=Ls(e),this._notify(),!0}canUndo(){return this.undoStack.length>0||this.currentBatch!==null}canRedo(){return this.redoStack.length>0}getHistoryLog(){return[...this.historyLog]}subscribeToHistory(e){return this._listeners.add(e),()=>this._listeners.delete(e)}_notify(){for(const e of this._listeners)e()}}const bd=60*60*1e3,gd=24*60*60*1e3;function xd({store:t,intervalMs:e=bd,maxAgeMs:n=gd,onPrune:r,onError:o}){const s=setInterval(()=>{try{const a=t.pruneTombstones({maxAgeMs:n});a>0&&(r==null||r(a))}catch(a){o==null||o(a)}},e);return{stop(){clearInterval(s)}}}const Je={HELLO:"hello",OP:"op",SYNC_REQUEST:"syncRequest",SYNC_RESPONSE:"syncResponse",PRESENCE:"presence"};function Jt(t){return JSON.stringify(t)}function ja(t){const e=JSON.parse(t);if(!e||typeof e.type!="string")throw new Error("Invalid sync message: missing type");return e}function yd(t){return{type:Je.HELLO,peerId:t}}function kd(t){return{type:Je.OP,envelope:t}}function vd(){return{type:Je.SYNC_REQUEST}}function wd(t){return{type:Je.SYNC_RESPONSE,doc:t}}function As(t,e){return{type:Je.PRESENCE,peerId:t,data:e}}const Id="noteloom-sync",Cd={iceServers:[{urls:"stun:stun.l.google.com:19302"}]},Vn=16e3,Sd=1e6,jd=256e3;function Rd(){return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}class Ra{constructor({signaling:e,remotePeerId:n,initiator:r,rtcConfig:o=Cd}){this.remotePeerId=n,this._signaling=e,this._pc=new RTCPeerConnection(o),this._channel=null,this._openListeners=new Set,this._closeListeners=new Set,this._messageListeners=new Set,this._chunkBuffers=new Map,this._sendQueue=[],this._pumping=!1,this._pc.onicecandidate=s=>{s.candidate&&this._signaling.send(n,{kind:"ice",candidate:s.candidate.toJSON()})},r?(this._wireChannel(this._pc.createDataChannel(Id)),this._pc.createOffer().then(s=>this._pc.setLocalDescription(s).then(()=>s)).then(s=>this._signaling.send(n,{kind:"offer",sdp:s}))):this._pc.ondatachannel=s=>this._wireChannel(s.channel),this._unsubscribeSignaling=e.onMessage((s,a)=>{s===n&&this._handleSignal(a)})}async _handleSignal(e){if(e.kind==="offer"){await this._pc.setRemoteDescription(e.sdp);const n=await this._pc.createAnswer();await this._pc.setLocalDescription(n),this._signaling.send(this.remotePeerId,{kind:"answer",sdp:n})}else if(e.kind==="answer")await this._pc.setRemoteDescription(e.sdp);else if(e.kind==="ice")try{await this._pc.addIceCandidate(e.candidate)}catch{}}_wireChannel(e){this._channel=e,e.bufferedAmountLowThreshold=jd,e.onopen=()=>{for(const n of this._openListeners)n()},e.onclose=()=>{for(const n of this._closeListeners)n()},e.onmessage=n=>this._handleRawMessage(n.data)}_handleRawMessage(e){if(typeof e!="string"||e.length===0)return;const n=e[0];if(n==="S"){for(const m of this._messageListeners)m(e.slice(1));return}if(n!=="C")return;const r=e.slice(1),o=r.indexOf(":"),s=r.indexOf(":",o+1),a=r.indexOf(":",s+1);if(o===-1||s===-1||a===-1)return;const i=r.slice(0,o),d=Number(r.slice(o+1,s)),c=Number(r.slice(s+1,a)),f=r.slice(a+1);let u=this._chunkBuffers.get(i);if(u||(u={total:c,received:new Map},this._chunkBuffers.set(i,u)),u.received.set(d,f),u.received.size<u.total)return;this._chunkBuffers.delete(i);let h="";for(let m=0;m<u.total;m+=1)h+=u.received.get(m);for(const m of this._messageListeners)m(h)}send(e){var n;if(((n=this._channel)==null?void 0:n.readyState)==="open"){if(e.length<=Vn)this._sendQueue.push(`S${e}`);else{const r=Rd(),o=Math.ceil(e.length/Vn);for(let s=0;s<o;s+=1){const a=e.slice(s*Vn,(s+1)*Vn);this._sendQueue.push(`C${r}:${s}:${o}:${a}`)}}this._pumpSendQueue()}}async _pumpSendQueue(){if(!this._pumping){this._pumping=!0;try{for(;this._sendQueue.length>0;){if(!this._channel||this._channel.readyState!=="open"){this._sendQueue.length=0;break}if(this._channel.bufferedAmount>Sd){await this._waitForBufferedAmountLow();continue}const e=this._sendQueue.shift();try{this._channel.send(e)}catch(n){console.warn("[noteloom] failed to send a sync message to peer",this.remotePeerId,n),this._sendQueue.length=0;break}}}finally{this._pumping=!1}}}_waitForBufferedAmountLow(){return new Promise(e=>{if(!this._channel){e();return}const n=()=>{this._channel.removeEventListener("bufferedamountlow",n),e()};this._channel.addEventListener("bufferedamountlow",n)})}onOpen(e){return this._openListeners.add(e),()=>this._openListeners.delete(e)}onClose(e){return this._closeListeners.add(e),()=>this._closeListeners.delete(e)}onMessage(e){return this._messageListeners.add(e),()=>this._messageListeners.delete(e)}close(){var e,n;this._chunkBuffers.clear(),this._sendQueue.length=0,(e=this._unsubscribeSignaling)==null||e.call(this),(n=this._channel)==null||n.close(),this._pc.close()}}const Td=100;class Ed{constructor({history:e,signaling:n,presenceThrottleMs:r=Td}){this._history=e,this._store=e.store,this._signaling=n,this._peers=new Map,this._unsubscribeLocal=this._attachLocalBroadcast(),this._localPresence=null,this._remotePresence=new Map,this._presenceListeners=new Set,this._presenceThrottleMs=r,this._presenceThrottleTimer=null,this._presenceDirty=!1}_attachLocalBroadcast(){const e=this._store.applyOperation.bind(this._store);this._pendingEnvelopes=[],this._store.applyOperation=r=>{const o=e(r),s=this._store.getLastEnvelope();return s&&this._pendingEnvelopes.push(s),o};const n={};for(const r of["perform","performBatch","undo","redo"]){const o=this._history[r].bind(this._history);n[r]=o,this._history[r]=(...s)=>{const a=o(...s);return this._flushPendingEnvelopes(),a}}return()=>{for(const r of Object.keys(n))this._history[r]=n[r];this._store.applyOperation=e}}_flushPendingEnvelopes(){const e=this._pendingEnvelopes;this._pendingEnvelopes=[];for(const n of e)this._broadcast(kd(n))}_broadcast(e){const n=Jt(e);for(const r of this._peers.values())r.send(n)}connect(e,{initiator:n}){var o;(o=this._peers.get(e))==null||o.close();const r=new Ra({signaling:this._signaling,remotePeerId:e,initiator:n});return r.onOpen(()=>{r.send(Jt(yd(this._signaling.localPeerId))),r.send(Jt(vd())),this._localPresence!==null&&r.send(Jt(As(this._signaling.localPeerId,this._localPresence)))}),r.onMessage(s=>this._handleMessage(r,s)),r.onClose(()=>{this._peers.delete(e),this._remotePresence.delete(e)&&this._notifyPresenceListeners()}),this._peers.set(e,r),r}setLocalPresence(e){this._localPresence=e,this._presenceDirty=!0,!this._presenceThrottleTimer&&(this._flushLocalPresence(),this._presenceThrottleTimer=setTimeout(()=>{this._presenceThrottleTimer=null,this._presenceDirty&&this._flushLocalPresence()},this._presenceThrottleMs))}_flushLocalPresence(){this._presenceDirty=!1,this._broadcast(As(this._signaling.localPeerId,this._localPresence))}getPresence(){return new Map(this._remotePresence)}onPresenceChange(e){return this._presenceListeners.add(e),()=>this._presenceListeners.delete(e)}_notifyPresenceListeners(){const e=this.getPresence();for(const n of this._presenceListeners)n(e)}_handleMessage(e,n){let r;try{r=ja(n)}catch{return}r.type===Je.OP?(this._store.applyRemoteOperation(r.envelope),this._history.flush()):r.type===Je.SYNC_REQUEST?e.send(Jt(wd(this._store.toJSON()))):r.type===Je.SYNC_RESPONSE?this._adoptSnapshotIfEmpty(r.doc):r.type===Je.PRESENCE&&(this._remotePresence.set(r.peerId,r.data),this._notifyPresenceListeners())}_adoptSnapshotIfEmpty(e){const n=this._store.getRootId();n&&this._store.getBlock(n)||(this._store.blocks=new Map((e.blocks??[]).map(r=>[r.id,r])),this._store.runs=new Map((e.runs??[]).map(r=>[r.id,r])),this._store.rootId=e.rootId??null,this._store._orders=new Map,this._store._notify([...this._store.blocks.keys(),...this._store.runs.keys()]))}disconnect(e){var n;(n=this._peers.get(e))==null||n.close(),this._peers.delete(e)}destroy(){this._unsubscribeLocal(),this._presenceThrottleTimer&&clearTimeout(this._presenceThrottleTimer);for(const e of this._peers.values())e.close();this._peers.clear(),this._remotePresence.clear(),this._presenceListeners.clear()}}function Bd({url:t,roomId:e,peerId:n,WebSocketImpl:r=WebSocket}){const o=new Set,s=new Set,a=new Set,i=[],d=`${t}${t.includes("?")?"&":"?"}room=${encodeURIComponent(e)}&peerId=${encodeURIComponent(n)}`,c=new r(d);c.addEventListener("open",()=>{for(const{toPeerId:u,payload:h}of i)f(u,h);i.length=0}),c.addEventListener("message",u=>{let h;try{h=JSON.parse(u.data)}catch{return}if(h.type==="roster")for(const m of h.peerIds??[])for(const g of s)g(m);else if(h.type==="peer-joined")for(const m of s)m(h.peerId);else if(h.type==="peer-left")for(const m of a)m(h.peerId);else if(h.type==="signal")for(const m of o)m(h.fromPeerId,h.payload)});function f(u,h){if(c.readyState!==r.OPEN){i.push({toPeerId:u,payload:h});return}c.send(JSON.stringify({type:"signal",toPeerId:u,payload:h}))}return{localPeerId:n,send(u,h){f(u,h)},onMessage(u){return o.add(u),()=>o.delete(u)},onPeerDiscovered(u){return s.add(u),()=>s.delete(u)},onPeerLeft(u){return a.add(u),()=>a.delete(u)},close(){i.length=0,c.close()}}}const _d="noteloom-documents",Qe="documents",et="templates",tt="versions",Nd=3;let Yn=null;function Pe(){return Yn||(Yn=new Promise((t,e)=>{const n=indexedDB.open(_d,Nd);n.onupgradeneeded=()=>{n.result.objectStoreNames.contains(Qe)||n.result.createObjectStore(Qe),n.result.objectStoreNames.contains(et)||n.result.createObjectStore(et,{keyPath:"id"}),n.result.objectStoreNames.contains(tt)||n.result.createObjectStore(tt,{keyPath:"id"})},n.onsuccess=()=>t(n.result),n.onerror=()=>e(n.error)}),Yn)}async function Ta(t,e){const n=await Pe();return new Promise((r,o)=>{const s=n.transaction(Qe,"readwrite");s.objectStore(Qe).put(e,t),s.oncomplete=()=>r(),s.onerror=()=>o(s.error)})}async function Ea(t){const e=await Pe();return new Promise((n,r)=>{const s=e.transaction(Qe,"readonly").objectStore(Qe).get(t);s.onsuccess=()=>n(s.result??null),s.onerror=()=>r(s.error)})}async function Md(t){const e=await Pe();return new Promise((n,r)=>{const o=e.transaction(Qe,"readwrite");o.objectStore(Qe).delete(t),o.oncomplete=()=>n(),o.onerror=()=>r(o.error)})}async function Od(){const t=await Pe();return new Promise((e,n)=>{const o=t.transaction(Qe,"readonly").objectStore(Qe).getAllKeys();o.onsuccess=()=>e(o.result),o.onerror=()=>n(o.error)})}async function Ld(t){const e=await Pe();return new Promise((n,r)=>{const o=e.transaction(et,"readwrite");o.objectStore(et).put(t),o.oncomplete=()=>n(),o.onerror=()=>r(o.error)})}async function Ad(t){const e=await Pe();return new Promise((n,r)=>{const s=e.transaction(et,"readonly").objectStore(et).get(t);s.onsuccess=()=>n(s.result??null),s.onerror=()=>r(s.error)})}async function Dd(t){const e=await Pe();return new Promise((n,r)=>{const o=e.transaction(et,"readwrite");o.objectStore(et).delete(t),o.oncomplete=()=>n(),o.onerror=()=>r(o.error)})}async function to(){const t=await Pe();return new Promise((e,n)=>{const o=t.transaction(et,"readonly").objectStore(et).getAll();o.onsuccess=()=>e(o.result),o.onerror=()=>n(o.error)})}async function Ba(t){const e=await Pe();return new Promise((n,r)=>{const o=e.transaction(tt,"readwrite");o.objectStore(tt).put(t),o.oncomplete=()=>n(),o.onerror=()=>r(o.error)})}async function Pd(t){const e=await Pe();return new Promise((n,r)=>{const s=e.transaction(tt,"readonly").objectStore(tt).get(t);s.onsuccess=()=>n(s.result??null),s.onerror=()=>r(s.error)})}async function _a(t){const e=await Pe();return new Promise((n,r)=>{const o=e.transaction(tt,"readwrite");o.objectStore(tt).delete(t),o.oncomplete=()=>n(),o.onerror=()=>r(o.error)})}async function ar(t){const e=await Pe();return new Promise((n,r)=>{const s=e.transaction(tt,"readonly").objectStore(tt).getAll();s.onsuccess=()=>{const a=s.result.filter(i=>i.docId===t);a.sort((i,d)=>d.timestamp-i.timestamp),n(a)},s.onerror=()=>r(s.error)})}const $d=500;function Na({store:t,docId:e,debounceMs:n=$d,onError:r}){let o=null;function s(){Ta(e,t.toJSON()).catch(c=>r==null?void 0:r(c))}function a(){o&&(clearTimeout(o),o=null,s())}const i=t.subscribeAll(()=>{o&&clearTimeout(o),o=setTimeout(()=>{o=null,s()},n)});function d(){o&&clearTimeout(o),o=null,i()}return{stop:d,flush:a}}function _n(t,e,n,r){const o={store:t,registry:e,inlineRegistry:r};return{html:zd(t,e,n,o),text:n.map(s=>{const a=t.getBlock(s);return e.get(a.type).toPlainText(a,o)}).join(`
2
+ `),json:JSON.stringify({version:1,blocks:n.map(s=>Nn(t,s))})}}function zd(t,e,n,r){let o="",s=0;for(;s<n.length;){const a=t.getBlock(n[s]);if(a.type==="listItem"){const i=!!a.props.ordered;let d="",c=s;for(;c<n.length;){const u=t.getBlock(n[c]);if(u.type!=="listItem"||!!u.props.ordered!==i)break;d+=e.get("listItem").toHTML(u,r),c+=1}const f=i?"ol":"ul";o+=`<${f}>${d}</${f}>`,s=c}else if(a.type==="blockquote"){let i="",d=s;for(;d<n.length;){const c=t.getBlock(n[d]);if(c.type!=="blockquote")break;i+=e.get("blockquote").toHTML(c,r),d+=1}o+=`<blockquote>${i}</blockquote>`,s=d}else o+=e.get(a.type).toHTML(a,r),s+=1}return o}function Nn(t,e){const n=[],r=[],o=s=>{var d;const a=t.getRun(s);if(a){r.push(a);return}const i=t.getBlock(s);if(i){n.push(i);for(const c of i.contentIds)o(c);for(const c of((d=i.props)==null?void 0:d.titleRunIds)??[])o(c)}};return o(e),{rootId:e,blocks:n,runs:r}}function fr({rootId:t,blocks:e,runs:n}){const r=new Map;for(const d of e)r.set(d.id,_());for(const d of n)r.set(d.id,_());const o=d=>r.get(d)??d,s=e.map(d=>{var c;return{...d,id:o(d.id),parentId:d.parentId?o(d.parentId):d.parentId,contentIds:d.contentIds.map(o),props:{...d.props,...(c=d.props)!=null&&c.titleRunIds?{titleRunIds:d.props.titleRunIds.map(o)}:{}}}}),a=n.map(d=>({...d,id:o(d.id)})),i=o(t);return{block:s.find(d=>d.id===i),runs:a,subtreeBlocks:s.filter(d=>d.id!==i)}}function Hd(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Fd(t,e){return{roots:e.map(n=>Nn(t,n))}}function Ma(t,e,{parentId:n,index:r}){const o=[];let s=r;for(const a of e.roots){const{block:i,runs:d,subtreeBlocks:c}=fr(a);i.parentId=n,o.push(me(i,n,s,{blocks:[i,...c],runs:d})),s+=1}Hd(t,o)}function Oa(t,e){const n=t.store??t;n.blocks=new Map((e.blocks??[]).map(r=>[r.id,r])),n.runs=new Map((e.runs??[]).map(r=>[r.id,r])),n.rootId=e.rootId??null,n.fieldTypes=new Map((e.fieldTypes??[]).map(r=>[r.id,r])),n._fieldTypesSnapshot=null,n.comments=new Map((e.comments??[]).map(r=>[r.id,r])),n._commentsSnapshot=null,n._orders=new Map,n._notify([...n.blocks.keys(),...n.runs.keys(),"$fieldTypes","$comments"])}function Ud(t,e){for(const n of e)t.register(`__blockTemplate:${n.id}`,{component:()=>null,isLeaf:!0,slashCommand:{label:n.label,icon:n.icon,keywords:n.keywords??[n.label],run(r,{blockId:o,runId:s,sliceStart:a,sliceEnd:i}){const d=r.getRun(s),c=(d==null?void 0:d.value)??"";r.applyOperation(de(s,{value:c.slice(0,a)+c.slice(i)}));const f=r.getBlock(o),h=r.getBlock(f.parentId).contentIds.indexOf(o)+1;Ma(r,n,{parentId:f.parentId,index:h})}}})}function Vd({scope:t}={}){const[e,n]=p.useState([]),[r,o]=p.useState(!1),s=p.useCallback(()=>(o(!1),to().then(a=>{n(t?a.filter(i=>i.scope===t):a),o(!0)})),[t]);return p.useEffect(()=>{let a=!1;return o(!1),to().then(i=>{a||(n(t?i.filter(d=>d.scope===t):i),o(!0))}),()=>{a=!0}},[t]),{templates:e,isLoaded:r,refresh:s}}function Yd({templates:t,onSelect:e,emptyLabel:n="No templates yet."}){return t.length===0?l.jsx("p",{className:"be-template-picker-empty",children:n}):l.jsx("ul",{className:"be-template-picker",role:"list",children:t.map(r=>l.jsxs("li",{className:"be-template-card",children:[l.jsxs("div",{className:"be-template-card-body",children:[l.jsx("span",{className:"be-template-card-name",children:r.name}),r.description&&l.jsx("span",{className:"be-template-card-description",children:r.description})]}),l.jsx("button",{type:"button",className:"be-template-card-select",onClick:()=>e(r),children:"Use"})]},r.id))})}function wo(t,{pretty:e=!0}={}){const n=t.getRootId(),{blocks:r,runs:o}=Nn(t,n);return JSON.stringify({version:1,rootId:n,blocks:r,runs:o},null,e?2:0)}function Io(t,e,n){const r=t.getBlock(t.getRootId());return r?_n(t,e,r.contentIds,n).html:""}function La(t,e,n){const r=t.getBlock(t.getRootId());return r?_n(t,e,r.contentIds,n).text:""}const Kd=5*60*1e3,Wd=200;function Aa({store:t,docId:e,idleMs:n=Kd,maxVersions:r=Wd,onSnapshot:o,onError:s}){let a=null,i=t.getHistoryLog().length,d=!1;function c(){a&&(clearTimeout(a),a=null)}async function f(){if(c(),!d)return;d=!1;const h=t.getHistoryLog(),m=h.slice(i);if(i=h.length,m.length===0)return;const g=new Set(m.map(k=>k.id).filter(Boolean)),x=[...new Set(m.map(k=>k.actorId).filter(Boolean))],y=m[m.length-1].actorId??null;try{const k=JSON.parse(wo(t)),v={id:crypto.randomUUID(),docId:e,timestamp:Date.now(),authorId:y,authorIds:x,summary:`${g.size} block${g.size===1?"":"s"} changed`,doc:k};await Ba(v),o==null||o(v);const w=await ar(e);if(w.length>r){const B=w.slice(r);await Promise.all(B.map(I=>_a(I.id)))}}catch(k){s==null||s(k)}}const u=t.subscribeToHistory(()=>{d=!0,c(),a=setTimeout(f,n)});return{stop(){c(),u()},flush:f}}function qd(t,e){const n=Ds(t),r=Ds(e),o=n.length,s=r.length,a=Array.from({length:o+1},()=>new Uint32Array(s+1));for(let u=o-1;u>=0;u-=1)for(let h=s-1;h>=0;h-=1)a[u][h]=n[u]===r[h]?a[u+1][h+1]+1:Math.max(a[u+1][h],a[u][h+1]);const i=[],d=(u,h)=>{const m=i[i.length-1];m&&m.type===u?m.text+=h:i.push({type:u,text:h})};let c=0,f=0;for(;c<o&&f<s;)n[c]===r[f]?(d("equal",n[c]),c+=1,f+=1):a[c+1][f]>=a[c][f+1]?(d("removed",n[c]),c+=1):(d("added",r[f]),f+=1);for(;c<o;)d("removed",n[c]),c+=1;for(;f<s;)d("added",r[f]),f+=1;return i}function Ds(t){return(t??"").match(/\s+|[^\s]+/g)??[]}const Xd={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function Kn(t){return t.replace(/[&<>"']/g,e=>Xd[e])}function Ps(t){const e=new Map(t.blocks.map(a=>[a.id,a])),n=new Map(t.runs.map(a=>[a.id,a])),r=[],o=a=>a.map(i=>{var d;return((d=n.get(i))==null?void 0:d.value)??""}).join(""),s=a=>{var c;const i=e.get(a);if(!i)return;const d=(c=i.props)==null?void 0:c.titleRunIds;Array.isArray(d)&&d.length>0?r.push({id:a,text:o(d)}):i.contentIds.length>0&&i.contentIds.every(f=>n.has(f))&&r.push({id:a,text:o(i.contentIds)});for(const f of i.contentIds)n.has(f)||s(f)};return s(t.rootId),r}const $s={rootId:"root",blocks:[{id:"root",type:"page",parentId:null,contentIds:[],props:{}}],runs:[]};function Da(t,e){const n=Ps(t??$s),r=Ps(e??$s),o=new Map(n.map(i=>[i.id,i])),s=new Set(r.map(i=>i.id)),a=[];for(const i of r){const d=o.get(i.id);if(!d){const u=Kn(i.text)||"&nbsp;";a.push(`<p class="be-version-diff-block"><span class="be-version-diff-added">${u}</span></p>`);continue}if(d.text===i.text){a.push(`<p class="be-version-diff-block">${Kn(i.text)||"&nbsp;"}</p>`);continue}const f=qd(d.text,i.text).map(u=>{const h=Kn(u.text);return u.type==="added"?`<span class="be-version-diff-added">${h}</span>`:u.type==="removed"?`<span class="be-version-diff-removed">${h}</span>`:h}).join("");a.push(`<p class="be-version-diff-block">${f}</p>`)}for(const i of n)if(!s.has(i.id)){const d=Kn(i.text)||"&nbsp;";a.push(`<p class="be-version-diff-block"><span class="be-version-diff-removed">${d}</span></p>`)}return a.length===0?'<p class="be-version-diff-empty">No text changes.</p>':a.join("")}function Pa(t){const[e,n]=p.useState([]),[r,o]=p.useState(!1),s=p.useCallback(()=>t?(o(!1),ar(t).then(a=>{n(a),o(!0)})):Promise.resolve(),[t]);return p.useEffect(()=>{if(!t){n([]),o(!0);return}let a=!1;return o(!1),ar(t).then(i=>{a||(n(i),o(!0))}),()=>{a=!0}},[t]),{versions:e,isLoaded:r,refresh:s}}const Gd=`/*\r
3
3
  * noteloom's default theme — minimal, clean, modern SaaS-adjacent.\r
4
4
  *\r
5
5
  * Ships as plain CSS custom properties on :root (not scoped to a wrapper\r
@@ -2768,6 +2768,288 @@ tr.be-table-row:hover .be-table-delete-row {\r
2768
2768
  }\r
2769
2769
  }\r
2770
2770
  \r
2771
+ /* --- version history: trigger button + drawer (VersionHistory) --- */\r
2772
+ \r
2773
+ .be-version-history-trigger {\r
2774
+ display: inline-flex;\r
2775
+ align-items: center;\r
2776
+ gap: 6px;\r
2777
+ border: 1px solid var(--noteloom-border);\r
2778
+ background: var(--noteloom-bg);\r
2779
+ color: var(--noteloom-text);\r
2780
+ border-radius: var(--noteloom-radius-md);\r
2781
+ padding: 5px 10px;\r
2782
+ font-size: 0.85rem;\r
2783
+ cursor: pointer;\r
2784
+ }\r
2785
+ \r
2786
+ .be-version-history-trigger:hover {\r
2787
+ background: var(--noteloom-bg-hover);\r
2788
+ }\r
2789
+ \r
2790
+ .be-version-history-backdrop {\r
2791
+ position: fixed;\r
2792
+ inset: 0;\r
2793
+ background: rgba(15, 23, 42, 0.25);\r
2794
+ z-index: 1400;\r
2795
+ }\r
2796
+ \r
2797
+ .be-version-history-drawer {\r
2798
+ position: fixed;\r
2799
+ top: 0;\r
2800
+ right: 0;\r
2801
+ bottom: 0;\r
2802
+ width: 360px;\r
2803
+ max-width: 100vw;\r
2804
+ background: var(--noteloom-bg);\r
2805
+ box-shadow: var(--noteloom-shadow);\r
2806
+ z-index: 1401;\r
2807
+ display: flex;\r
2808
+ flex-direction: column;\r
2809
+ }\r
2810
+ \r
2811
+ .be-version-history-header {\r
2812
+ display: flex;\r
2813
+ align-items: center;\r
2814
+ justify-content: space-between;\r
2815
+ padding: 14px 16px;\r
2816
+ border-bottom: 1px solid var(--noteloom-border);\r
2817
+ font-weight: 700;\r
2818
+ font-size: 0.95rem;\r
2819
+ }\r
2820
+ \r
2821
+ .be-version-history-close {\r
2822
+ border: none;\r
2823
+ background: transparent;\r
2824
+ color: var(--noteloom-text-muted);\r
2825
+ width: 24px;\r
2826
+ height: 24px;\r
2827
+ display: flex;\r
2828
+ align-items: center;\r
2829
+ justify-content: center;\r
2830
+ border-radius: var(--noteloom-radius-sm);\r
2831
+ cursor: pointer;\r
2832
+ }\r
2833
+ \r
2834
+ .be-version-history-close:hover {\r
2835
+ background: var(--noteloom-bg-hover);\r
2836
+ color: var(--noteloom-text);\r
2837
+ }\r
2838
+ \r
2839
+ .be-version-history-list {\r
2840
+ flex: 1;\r
2841
+ overflow-y: auto;\r
2842
+ padding: 8px 0;\r
2843
+ }\r
2844
+ \r
2845
+ .be-version-history-empty {\r
2846
+ color: var(--noteloom-text-muted);\r
2847
+ font-size: 0.85rem;\r
2848
+ padding: 16px;\r
2849
+ margin: 0;\r
2850
+ }\r
2851
+ \r
2852
+ .be-version-history-group-label {\r
2853
+ font-weight: 600;\r
2854
+ font-size: 0.78rem;\r
2855
+ color: var(--noteloom-text-muted);\r
2856
+ padding: 10px 16px 4px;\r
2857
+ }\r
2858
+ \r
2859
+ .be-version-history-item {\r
2860
+ display: flex;\r
2861
+ align-items: center;\r
2862
+ gap: 10px;\r
2863
+ width: 100%;\r
2864
+ border: none;\r
2865
+ background: transparent;\r
2866
+ padding: 8px 16px;\r
2867
+ text-align: left;\r
2868
+ cursor: pointer;\r
2869
+ }\r
2870
+ \r
2871
+ .be-version-history-item:hover {\r
2872
+ background: var(--noteloom-bg-hover);\r
2873
+ }\r
2874
+ \r
2875
+ .be-version-history-item-body {\r
2876
+ min-width: 0;\r
2877
+ }\r
2878
+ \r
2879
+ .be-version-history-item-author {\r
2880
+ font-weight: 600;\r
2881
+ font-size: 0.85rem;\r
2882
+ }\r
2883
+ \r
2884
+ .be-version-history-item-meta {\r
2885
+ font-size: 0.78rem;\r
2886
+ color: var(--noteloom-text-muted);\r
2887
+ overflow: hidden;\r
2888
+ text-overflow: ellipsis;\r
2889
+ white-space: nowrap;\r
2890
+ }\r
2891
+ \r
2892
+ .be-version-history-preview {\r
2893
+ flex: 1;\r
2894
+ display: flex;\r
2895
+ flex-direction: column;\r
2896
+ min-height: 0;\r
2897
+ }\r
2898
+ \r
2899
+ .be-version-history-preview-meta {\r
2900
+ display: flex;\r
2901
+ align-items: center;\r
2902
+ gap: 10px;\r
2903
+ padding: 12px 16px;\r
2904
+ border-bottom: 1px solid var(--noteloom-border);\r
2905
+ }\r
2906
+ \r
2907
+ .be-version-history-preview-author {\r
2908
+ font-weight: 600;\r
2909
+ font-size: 0.85rem;\r
2910
+ }\r
2911
+ \r
2912
+ .be-version-history-preview-time {\r
2913
+ font-size: 0.78rem;\r
2914
+ color: var(--noteloom-text-muted);\r
2915
+ }\r
2916
+ \r
2917
+ .be-version-history-view-toggle {\r
2918
+ display: flex;\r
2919
+ gap: 4px;\r
2920
+ padding: 8px 16px 0;\r
2921
+ }\r
2922
+ \r
2923
+ .be-version-history-view-toggle button {\r
2924
+ border: none;\r
2925
+ background: transparent;\r
2926
+ color: var(--noteloom-text-muted);\r
2927
+ font-size: 0.78rem;\r
2928
+ font-weight: 600;\r
2929
+ padding: 5px 10px;\r
2930
+ border-radius: var(--noteloom-radius-md);\r
2931
+ cursor: pointer;\r
2932
+ }\r
2933
+ \r
2934
+ .be-version-history-view-toggle button.is-active {\r
2935
+ background: var(--noteloom-bg-subtle);\r
2936
+ color: var(--noteloom-text);\r
2937
+ }\r
2938
+ \r
2939
+ .be-version-history-diff-legend {\r
2940
+ display: flex;\r
2941
+ align-items: center;\r
2942
+ gap: 10px;\r
2943
+ padding: 10px 16px 0;\r
2944
+ font-size: 0.75rem;\r
2945
+ }\r
2946
+ \r
2947
+ .be-version-history-diff-legend-note {\r
2948
+ color: var(--noteloom-text-muted);\r
2949
+ }\r
2950
+ \r
2951
+ .be-version-history-preview-body {\r
2952
+ flex: 1;\r
2953
+ overflow-y: auto;\r
2954
+ padding: 16px;\r
2955
+ font-size: 0.9rem;\r
2956
+ line-height: 1.6;\r
2957
+ }\r
2958
+ \r
2959
+ .be-version-history-diff-body :is(p.be-version-diff-block) {\r
2960
+ margin: 0 0 0.6em;\r
2961
+ }\r
2962
+ \r
2963
+ /* Google Docs-style change highlighting: additions get a green underline/background,\r
2964
+ removals a struck-through red one -- self-evident at a glance, no legend required\r
2965
+ to understand the individual spans (the legend row above just labels the colors). */\r
2966
+ .be-version-diff-added {\r
2967
+ background: rgba(34, 197, 94, 0.18);\r
2968
+ color: var(--noteloom-text);\r
2969
+ text-decoration: underline;\r
2970
+ text-decoration-color: rgba(34, 197, 94, 0.6);\r
2971
+ border-radius: 2px;\r
2972
+ padding: 0 1px;\r
2973
+ }\r
2974
+ \r
2975
+ .be-version-diff-removed {\r
2976
+ background: rgba(239, 68, 68, 0.14);\r
2977
+ color: var(--noteloom-text-muted);\r
2978
+ text-decoration: line-through;\r
2979
+ text-decoration-color: rgba(239, 68, 68, 0.6);\r
2980
+ border-radius: 2px;\r
2981
+ padding: 0 1px;\r
2982
+ }\r
2983
+ \r
2984
+ .be-version-history-diff-legend .be-version-diff-added,\r
2985
+ .be-version-history-diff-legend .be-version-diff-removed {\r
2986
+ padding: 2px 6px;\r
2987
+ text-decoration: none;\r
2988
+ font-weight: 600;\r
2989
+ }\r
2990
+ \r
2991
+ /* exportDocumentHTML emits plain semantic HTML (<p>/<h1-3>/<ul>/<blockquote>/...),\r
2992
+ not this package's own be-* block classes, so the preview needs its own\r
2993
+ basic typography rather than inheriting the live editor's block styling. */\r
2994
+ .be-version-history-preview-body :is(h1, h2, h3) {\r
2995
+ margin: 0.6em 0 0.3em;\r
2996
+ }\r
2997
+ \r
2998
+ .be-version-history-preview-body p {\r
2999
+ margin: 0 0 0.6em;\r
3000
+ }\r
3001
+ \r
3002
+ .be-version-history-preview-body :is(ul, ol) {\r
3003
+ margin: 0 0 0.6em;\r
3004
+ padding-left: 1.4em;\r
3005
+ }\r
3006
+ \r
3007
+ .be-version-history-preview-body blockquote {\r
3008
+ margin: 0 0 0.6em;\r
3009
+ padding-left: 0.8em;\r
3010
+ border-left: 3px solid var(--noteloom-border);\r
3011
+ color: var(--noteloom-text-muted);\r
3012
+ }\r
3013
+ \r
3014
+ .be-version-history-preview-body pre {\r
3015
+ background: var(--noteloom-bg-subtle);\r
3016
+ border-radius: var(--noteloom-radius-sm);\r
3017
+ padding: 10px;\r
3018
+ overflow-x: auto;\r
3019
+ }\r
3020
+ \r
3021
+ .be-version-history-preview-actions {\r
3022
+ display: flex;\r
3023
+ justify-content: space-between;\r
3024
+ align-items: center;\r
3025
+ gap: 8px;\r
3026
+ padding: 12px 16px;\r
3027
+ border-top: 1px solid var(--noteloom-border);\r
3028
+ }\r
3029
+ \r
3030
+ .be-version-history-preview-actions button {\r
3031
+ border-radius: var(--noteloom-radius-md);\r
3032
+ padding: 6px 12px;\r
3033
+ font-size: 0.82rem;\r
3034
+ font-weight: 600;\r
3035
+ cursor: pointer;\r
3036
+ }\r
3037
+ \r
3038
+ .be-version-history-preview-actions button:first-child {\r
3039
+ border: 1px solid var(--noteloom-border);\r
3040
+ background: var(--noteloom-bg);\r
3041
+ color: var(--noteloom-text);\r
3042
+ }\r
3043
+ \r
3044
+ .be-version-history-restore {\r
3045
+ display: flex;\r
3046
+ align-items: center;\r
3047
+ gap: 6px;\r
3048
+ border: none;\r
3049
+ background: var(--noteloom-accent);\r
3050
+ color: #fff;\r
3051
+ }\r
3052
+ \r
2771
3053
  /* --- voice typing: caret-anchored listening/processing indicator --- */\r
2772
3054
  \r
2773
3055
  .be-voice-indicator {\r
@@ -2917,11 +3199,11 @@ tr.be-table-row:hover .be-table-delete-row {\r
2917
3199
  break-inside: avoid;\r
2918
3200
  }\r
2919
3201
  }\r
2920
- `,Ns="noteloom-default-styles";function Aa(){if(typeof document>"u"||document.getElementById(Ns))return;const t=document.createElement("style");t.id=Ns,t.textContent=Ku,document.head.appendChild(t)}const Da=p.createContext(null);function Pa({store:t,registry:e,inlineRegistry:n=null,history:r=null,className:o,style:s,theme:a="default",getBlockClassName:i,commentAuthorId:u,children:c}){p.useEffect(()=>{a!=="none"&&Aa()},[a]);const[f,d]=p.useState(!1),[h,m]=p.useState(null),[g,x]=p.useState([]),[y,k]=p.useState(!1),[w,v]=p.useState(null),j=p.useCallback(()=>v("new"),[]),I=p.useCallback(N=>v(N),[]),C=p.useCallback(()=>v(null),[]),T=p.useRef(null),M=p.useCallback(()=>T.current,[]),B=p.useCallback(N=>{var V,K;const $=T.current;$!==N&&($&&((V=document.querySelector(`[data-block-id="${$}"]`))==null||V.classList.remove("be-block-selected")),T.current=N,N&&((K=document.querySelector(`[data-block-id="${N}"]`))==null||K.classList.add("be-block-selected")))},[]),L=p.useMemo(()=>({store:t,registry:e,inlineRegistry:n,history:r,isWholeDocumentSelected:f,setIsWholeDocumentSelected:d,selectedBlockRange:g,setSelectedBlockRange:x,getSelectedBlockId:M,setSelectedBlockId:B,isPreviewMode:y,setIsPreviewMode:k,fieldTypeEditorTarget:w,openCreateFieldType:j,openEditFieldType:I,closeFieldTypeEditor:C,getBlockClassName:i,commentAuthorId:u,hoveredCommentId:h,setHoveredCommentId:m}),[t,e,n,r,f,g,M,B,y,w,j,I,C,i,u,h]),S=o||s?l.jsx("div",{className:o?`be-root ${o}`:"be-root",style:s,children:c}):c;return l.jsx(Da.Provider,{value:L,children:S})}function Pe(){const t=p.useContext(Da);if(!t)throw new Error("Editor hooks must be used within an <EditorProvider>");return t}function G(){return Pe().store}function vt(){return Pe().registry}function tt(){return Pe().inlineRegistry}function Io(){const{isWholeDocumentSelected:t,setIsWholeDocumentSelected:e}=Pe();return[t,e]}function _n(){const{selectedBlockRange:t,setSelectedBlockRange:e}=Pe();return[t,e]}function ut(){const{getSelectedBlockId:t,setSelectedBlockId:e}=Pe();return{getSelectedBlockId:t,setSelectedBlockId:e}}function Co(){const{isPreviewMode:t,setIsPreviewMode:e}=Pe();return[t,e]}function Ie(t,e){const{getBlockClassName:n}=Pe(),r=e&&n?n(e):void 0;return r?`${t} ${r}`:t}function $a(){return Pe().commentAuthorId}function pr(){const{hoveredCommentId:t,setHoveredCommentId:e}=Pe();return[t,e]}function So(){const{fieldTypeEditorTarget:t,openCreateFieldType:e,openEditFieldType:n,closeFieldTypeEditor:r}=Pe();return{target:t,openCreate:e,openEdit:n,close:r}}const Wu="$comments";function za(){const t=G(),e=p.useCallback(r=>t.subscribe(Wu,r),[t]),n=p.useCallback(()=>t.getComments(),[t]);return p.useSyncExternalStore(e,n)}const As=["#e03131","#e8590c","#2f9e44","#1971c2","#9c36b5"];function Xu(t){let e=0;const n=String(t??"");for(let r=0;r<n.length;r+=1)e=e*31+n.charCodeAt(r)|0;return As[Math.abs(e)%As.length]}function qu(t){const e=String(t??"").trim();if(!e)return"?";const n=e.split(/\s+/).filter(Boolean);return n.length>=2?(n[0][0]+n[1][0]).toUpperCase():e.slice(0,2).toUpperCase()}const eo=60*1e3,to=60*eo,zr=24*to;function Gu(t,e=Date.now()){const n=e-t;if(n<eo)return"just now";if(n<to){const r=Math.floor(n/eo);return`${r} min${r===1?"":"s"} ago`}if(n<zr){const r=Math.floor(n/to);return`${r} hour${r===1?"":"s"} ago`}if(n<7*zr){const r=Math.floor(n/zr);return`${r} day${r===1?"":"s"} ago`}return new Date(t).toLocaleDateString()}function Ro({authorId:t,size:e=26}){return l.jsx("span",{className:"be-comment-avatar",style:{width:e,height:e,fontSize:Math.max(10,e*.4),background:Xu(t)},"aria-hidden":"true",children:qu(t)})}function Y({children:t,size:e=16,strokeWidth:n=2,...r}){return l.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:n,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",...r,children:t})}function jt(t){return l.jsx(Y,{...t,children:l.jsx("polyline",{points:"9 18 15 12 9 6"})})}function fr(t){return l.jsx(Y,{...t,children:l.jsx("polyline",{points:"6 9 12 15 18 9"})})}function Ot(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),l.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Ju(t){return l.jsxs(Y,{...t,fill:"currentColor",stroke:"none",children:[l.jsx("circle",{cx:"5",cy:"12",r:"1.6"}),l.jsx("circle",{cx:"12",cy:"12",r:"1.6"}),l.jsx("circle",{cx:"19",cy:"12",r:"1.6"})]})}function Ha(t){return l.jsx(Y,{...t,children:l.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}function To(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),l.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function Fa(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"}),l.jsx("path",{d:"M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"})]})}function Ua(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"19",y1:"4",x2:"10",y2:"4"}),l.jsx("line",{x1:"14",y1:"20",x2:"5",y2:"20"}),l.jsx("line",{x1:"15",y1:"4",x2:"9",y2:"20"})]})}function Va(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M6 3v7a6 6 0 0 0 12 0V3"}),l.jsx("line",{x1:"4",y1:"21",x2:"20",y2:"21"})]})}function Ya(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M12 20h9"}),l.jsx("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]})}function Zu(t){return l.jsx(Y,{...t,children:l.jsx("path",{d:"M3 17c2-4 4-4 6 0s4 4 6 0 4-4 6 0"})})}function Ka(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),l.jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]})}function Wa(t){return l.jsx(Y,{...t,children:l.jsx("path",{d:"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"})})}function Qu(t){return l.jsx(Y,{...t,children:l.jsx("polyline",{points:"20 6 9 17 4 12"})})}function ed(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),l.jsx("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})}function td(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M16 4H9a3 3 0 0 0-2.83 4"}),l.jsx("path",{d:"M14 12a4 4 0 0 1 0 8H6"}),l.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})]})}function Xa(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"21",y1:"6",x2:"3",y2:"6"}),l.jsx("line",{x1:"17",y1:"10",x2:"3",y2:"10"}),l.jsx("line",{x1:"21",y1:"14",x2:"3",y2:"14"}),l.jsx("line",{x1:"17",y1:"18",x2:"3",y2:"18"})]})}function nd(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"21",y1:"6",x2:"3",y2:"6"}),l.jsx("line",{x1:"18",y1:"10",x2:"6",y2:"10"}),l.jsx("line",{x1:"21",y1:"14",x2:"3",y2:"14"}),l.jsx("line",{x1:"18",y1:"18",x2:"6",y2:"18"})]})}function qa(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"21",y1:"6",x2:"3",y2:"6"}),l.jsx("line",{x1:"21",y1:"10",x2:"7",y2:"10"}),l.jsx("line",{x1:"21",y1:"14",x2:"3",y2:"14"}),l.jsx("line",{x1:"21",y1:"18",x2:"7",y2:"18"})]})}function rd(t){return l.jsx(Y,{...t,children:[5,12,19].flatMap(e=>[9,15].map(n=>l.jsx("circle",{cx:n,cy:e,r:"1.3",fill:"currentColor",stroke:"none"},`${n}-${e}`)))})}function On(t){return l.jsxs(Y,{...t,children:[l.jsx("polyline",{points:"3 6 5 6 21 6"}),l.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}),l.jsx("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),l.jsx("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}function jo(t){return l.jsxs(Y,{...t,children:[l.jsx("rect",{x:"9",y:"9",width:"12",height:"12",rx:"2"}),l.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}function hr(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),l.jsx("polyline",{points:"5 12 12 5 19 12"})]})}function mr(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),l.jsx("polyline",{points:"19 12 12 19 5 12"})]})}function Ga(t){return l.jsx(Y,{...t,children:l.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"1"})})}function od(t){return l.jsx(Y,{...t,children:l.jsx("circle",{cx:"12",cy:"12",r:"8"})})}function sd(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"6",y1:"18",x2:"18",y2:"6"}),l.jsx("polyline",{points:"9 6 18 6 18 15"})]})}function ad(t){return l.jsx(Y,{...t,children:l.jsx("polygon",{points:"12 3 21 12 12 21 3 12"})})}function ld(t){return l.jsx(Y,{...t,children:l.jsx("polygon",{points:"12 4 20 20 4 20"})})}function id(t){return l.jsx(Y,{...t,children:l.jsx("polygon",{points:"12 3 14.7 9.4 21.5 9.9 16.3 14.4 17.9 21 12 17.4 6.1 21 7.7 14.4 2.5 9.9 9.3 9.4"})})}function cd(t){return l.jsx(Y,{...t,children:l.jsx("path",{d:"M5 3l14 8-6 2-2 6-6-16z"})})}function Ja(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M19 20H9l-6-6a1.5 1.5 0 0 1 0-2l9-9a1.5 1.5 0 0 1 2 0l7 7a1.5 1.5 0 0 1 0 2l-7 7"}),l.jsx("path",{d:"M6.5 12.5 13 19"})]})}function ud(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M12 3v12"}),l.jsx("path",{d:"M7 10l5 5 5-5"}),l.jsx("path",{d:"M4 19h16"})]})}function dd(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M6 15V9a6 6 0 0 1 12 0v6"}),l.jsx("path",{d:"M6 15a3 3 0 0 0 6 0v-4"}),l.jsx("path",{d:"M18 15a3 3 0 0 1-6 0v-4"}),l.jsx("line",{x1:"3",y1:"9",x2:"6",y2:"9"}),l.jsx("line",{x1:"3",y1:"15",x2:"6",y2:"15"}),l.jsx("line",{x1:"18",y1:"9",x2:"21",y2:"9"}),l.jsx("line",{x1:"18",y1:"15",x2:"21",y2:"15"})]})}function pd(t){return l.jsxs(Y,{...t,children:[l.jsx("circle",{cx:"6",cy:"6",r:"3"}),l.jsx("circle",{cx:"6",cy:"18",r:"3"}),l.jsx("line",{x1:"20",y1:"4",x2:"8.12",y2:"15.88"}),l.jsx("line",{x1:"14.47",y1:"14.48",x2:"20",y2:"20"}),l.jsx("line",{x1:"8.12",y1:"8.12",x2:"12",y2:"12"})]})}function Eo(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"17",y1:"6",x2:"3",y2:"6"}),l.jsx("line",{x1:"21",y1:"12",x2:"3",y2:"12"}),l.jsx("line",{x1:"15",y1:"18",x2:"3",y2:"18"})]})}function Bo({level:t=1,size:e=16,...n}){return l.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",...n,children:l.jsxs("text",{x:"2",y:"18",fontSize:"14",fontWeight:"700",fill:"currentColor",fontFamily:"inherit",children:["H",t]})})}function Za(t){return l.jsx(Bo,{level:1,...t})}function Qa(t){return l.jsx(Bo,{level:2,...t})}function el(t){return l.jsx(Bo,{level:3,...t})}function tl(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M7 7a3 3 0 0 0-3 3v3a2 2 0 0 0 2 2h2a1 1 0 0 0 1-1v-4a1 1 0 0 0-1-1H6a3 3 0 0 1 3-3z"}),l.jsx("path",{d:"M17 7a3 3 0 0 0-3 3v3a2 2 0 0 0 2 2h2a1 1 0 0 0 1-1v-4a1 1 0 0 0-1-1h-2a3 3 0 0 1 3-3z"})]})}function _o(t){return l.jsxs(Y,{...t,children:[l.jsx("polyline",{points:"9 8 4 12 9 16"}),l.jsx("polyline",{points:"15 8 20 12 15 16"})]})}function fd(t){return l.jsx(Y,{...t,children:l.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})})}function nl(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M4 5h16a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H9l-4 4v-4H4a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1z"}),l.jsx("line",{x1:"7",y1:"9",x2:"17",y2:"9"}),l.jsx("line",{x1:"7",y1:"12.5",x2:"13",y2:"12.5"})]})}function hd(t){return l.jsxs(Y,{...t,children:[l.jsx("rect",{x:"3",y:"8",width:"18",height:"8",rx:"3"}),l.jsx("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]})}function md(t){return l.jsxs(Y,{...t,children:[l.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"1"}),l.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"}),l.jsx("line",{x1:"3",y1:"16",x2:"21",y2:"16"}),l.jsx("line",{x1:"9",y1:"4",x2:"9",y2:"20"}),l.jsx("line",{x1:"15",y1:"4",x2:"15",y2:"20"})]})}function bd(t){return l.jsxs(Y,{...t,children:[l.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"1"}),l.jsx("line",{x1:"9",y1:"4",x2:"9",y2:"20"}),l.jsx("line",{x1:"15",y1:"4",x2:"15",y2:"20"})]})}function rl(t){return l.jsxs(Y,{...t,children:[l.jsx("circle",{cx:"4.5",cy:"6",r:"1.2",fill:"currentColor",stroke:"none"}),l.jsx("circle",{cx:"4.5",cy:"12",r:"1.2",fill:"currentColor",stroke:"none"}),l.jsx("circle",{cx:"4.5",cy:"18",r:"1.2",fill:"currentColor",stroke:"none"}),l.jsx("line",{x1:"9",y1:"6",x2:"21",y2:"6"}),l.jsx("line",{x1:"9",y1:"12",x2:"21",y2:"12"}),l.jsx("line",{x1:"9",y1:"18",x2:"21",y2:"18"})]})}function ol(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"10",y1:"6",x2:"21",y2:"6"}),l.jsx("line",{x1:"10",y1:"12",x2:"21",y2:"12"}),l.jsx("line",{x1:"10",y1:"18",x2:"21",y2:"18"}),l.jsx("text",{x:"2",y:"8.5",fontSize:"7",fontWeight:"700",fill:"currentColor",stroke:"none",children:"1"}),l.jsx("text",{x:"2",y:"14.5",fontSize:"7",fontWeight:"700",fill:"currentColor",stroke:"none",children:"2"}),l.jsx("text",{x:"2",y:"20.5",fontSize:"7",fontWeight:"700",fill:"currentColor",stroke:"none",children:"3"})]})}function Oo(t){return l.jsxs(Y,{...t,children:[l.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"3"}),l.jsx("polyline",{points:"8 12 11 15 16 9"})]})}function gd(t){return l.jsxs(Y,{...t,children:[l.jsx("rect",{x:"3",y:"5",width:"18",height:"16",rx:"2"}),l.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"}),l.jsx("line",{x1:"8",y1:"3",x2:"8",y2:"7"}),l.jsx("line",{x1:"16",y1:"3",x2:"16",y2:"7"})]})}function sl(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M12 3h7a2 2 0 0 1 2 2v7a2 2 0 0 1-.59 1.41l-8 8a2 2 0 0 1-2.82 0l-7-7a2 2 0 0 1 0-2.82l8-8A2 2 0 0 1 12 3z"}),l.jsx("circle",{cx:"15.5",cy:"8.5",r:"1.2",fill:"currentColor",stroke:"none"})]})}function xd(t){return l.jsxs(Y,{...t,children:[l.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),l.jsx("circle",{cx:"9",cy:"10",r:"1.5",fill:"currentColor",stroke:"none"}),l.jsx("path",{d:"M4 17l5-5 4 4 4-5 4 6"})]})}function yd(t){return l.jsxs(Y,{...t,children:[l.jsx("rect",{x:"3",y:"5",width:"14",height:"14",rx:"2"}),l.jsx("path",{d:"M17 10l4-2.5v9L17 14"})]})}function Mo(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7z"}),l.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function Lo(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M17.94 17.94A10.94 10.94 0 0 1 12 19c-6.5 0-10-7-10-7a18.5 18.5 0 0 1 5.06-5.94M9.9 4.24A10.94 10.94 0 0 1 12 4c6.5 0 10 7 10 7a18.5 18.5 0 0 1-2.16 3.19"}),l.jsx("path",{d:"M14.12 14.12a3 3 0 1 1-4.24-4.24"}),l.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function kd(t){return l.jsxs(Y,{...t,children:[l.jsx("line",{x1:"4",y1:"10",x2:"4",y2:"14"}),l.jsx("line",{x1:"8",y1:"7",x2:"8",y2:"17"}),l.jsx("line",{x1:"12",y1:"4",x2:"12",y2:"20"}),l.jsx("line",{x1:"16",y1:"7",x2:"16",y2:"17"}),l.jsx("line",{x1:"20",y1:"10",x2:"20",y2:"14"})]})}function vd(t){return l.jsxs(Y,{...t,children:[l.jsx("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),l.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),l.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),l.jsx("line",{x1:"8",y1:"23",x2:"16",y2:"23"})]})}function No({authorId:t,placeholder:e="Add a comment…",autoFocus:n=!1,onSubmit:r,onCancel:o}){const[s,a]=p.useState(""),i=p.useRef(null),u=s.trim();function c(){const h=i.current;h&&(h.style.height="auto",h.style.height=`${h.scrollHeight}px`)}function f(h){a(h.target.value),c()}function d(h){h.preventDefault(),u&&(r(u),a(""),i.current&&(i.current.style.height=""))}return l.jsxs("form",{className:"be-comment-composer",onSubmit:d,children:[l.jsxs("div",{className:"be-comment-composer-input-row",children:[l.jsx(Ro,{authorId:t,size:26}),l.jsx("textarea",{ref:i,className:"be-comment-composer-textarea",value:s,onChange:f,placeholder:e,rows:2,autoFocus:n,onKeyDown:h=>{h.key==="Enter"&&(h.metaKey||h.ctrlKey)?d(h):h.key==="Escape"&&o&&o()}})]}),l.jsxs("div",{className:"be-comment-composer-actions",children:[o&&l.jsx("button",{type:"button",className:"be-comment-composer-cancel",onClick:o,children:"Cancel"}),l.jsxs("button",{type:"submit",className:"be-comment-composer-submit",disabled:!u,children:[l.jsx(ed,{size:13}),"Send"]})]})]})}function Ds({message:t,size:e=26}){return l.jsxs("div",{className:"be-comment-message",children:[l.jsx(Ro,{authorId:t.authorId,size:e}),l.jsxs("div",{className:"be-comment-message-body",children:[l.jsxs("div",{className:"be-comment-message-header",children:[l.jsx("span",{className:"be-comment-message-author",children:t.authorId}),l.jsx("span",{className:"be-comment-message-time",children:Gu(t.createdAt)})]}),l.jsx("p",{className:"be-comment-message-text",children:t.text})]})]})}function Ao({store:t,thread:e,authorId:n,onJumpToText:r}){const[o,s]=p.useState(!1),[a,i]=pr(),[u,...c]=e.messages;function f(d){Ma(t,e.id,{authorId:n,text:d}),s(!1)}return l.jsxs("div",{className:`be-comment-thread${e.resolved?" be-comment-thread-resolved":""}${a===e.id?" be-comment-thread-hovered":""}`,onMouseEnter:()=>i(e.id),onMouseLeave:()=>i(null),children:[l.jsx("div",{onClick:r?()=>r(e.id):void 0,style:r?{cursor:"pointer"}:void 0,children:l.jsx(Ds,{message:u})}),c.length>0&&l.jsx("div",{className:"be-comment-thread-replies",children:c.map(d=>l.jsx(Ds,{message:d,size:22},d.id))}),o?l.jsx(No,{authorId:n,placeholder:"Reply…",autoFocus:!0,onSubmit:f,onCancel:()=>s(!1)}):l.jsxs("div",{className:"be-comment-thread-actions",children:[n&&l.jsxs("button",{type:"button",onClick:()=>s(!0),children:[l.jsx(Wa,{size:13}),"Reply"]}),l.jsxs("button",{type:"button",onClick:()=>La(t,e.id,!e.resolved),children:[l.jsx(Qu,{size:13}),e.resolved?"Reopen":"Resolve"]}),l.jsx("button",{type:"button",className:"be-comment-thread-delete",onClick:()=>Na(t,e.id),"aria-label":"Delete comment",title:"Delete comment",children:l.jsx(On,{size:13})})]})]})}function al(t,e){var n,r,o;for(const s of e.anchorRunIds??[]){const a=document.querySelector(`[data-run-id="${s}"]`);if(a)return a}for(const s of t.getAllRunIds())if((o=(r=(n=t.getRun(s))==null?void 0:n.marks)==null?void 0:r.commentIds)!=null&&o.includes(e.id)){const a=document.querySelector(`[data-run-id="${s}"]`);if(a)return a}return null}function wd(t,e,n){const r=t.getComment(e);if(!r)return;const o=al(t,r);o&&(o.scrollIntoView({behavior:"smooth",block:"center"}),n(e),setTimeout(()=>n(s=>s===e?null:s),1500))}function ll({authorId:t}){const e=G(),n=za(),[,r]=pr(),o=p.useRef(null),[s,a]=p.useState({}),i=[...n].sort((c,f)=>Number(c.resolved)-Number(f.resolved));p.useLayoutEffect(()=>{function c(){const f=o.current;if(!f)return;const d=f.getBoundingClientRect().top,h={};let m=-1/0;for(const g of i){const x=al(e,g),y=x?x.getBoundingClientRect().top-d:Number.isFinite(m)?m+90:0,k=Math.max(m,y);h[g.id]=k,m=k+90}a(h)}return c(),window.addEventListener("scroll",c,!0),window.addEventListener("resize",c),()=>{window.removeEventListener("scroll",c,!0),window.removeEventListener("resize",c)}},[n,e]);const u=Object.values(s).reduce((c,f)=>Math.max(c,f+120),0);return i.length===0?null:l.jsx("div",{className:"be-comments-panel",contentEditable:!1,children:l.jsx("div",{ref:o,className:"be-comments-panel-list",style:{height:u},children:i.map(c=>l.jsx("div",{className:"be-comments-panel-item",style:{top:s[c.id]??0},children:l.jsx(Ao,{store:e,thread:c,authorId:t,onJumpToText:f=>wd(e,f,r)})},c.id))})})}class il{constructor(){this._types=new Map}register(e,n){this._types.set(e,n)}get(e){return this._types.get(e)}isLeaf(e){var n;return!!((n=this._types.get(e))!=null&&n.isLeaf)}listSlashCommands(){const e=[];for(const n of this._types.values())n.slashCommand&&e.push(n.slashCommand),n.slashCommands&&e.push(...n.slashCommands);return e}listHtmlMatchers(){return[...this._types.values()].filter(e=>e.fromHTML)}}function cl(){return new il}class ul{constructor(){this._types=new Map}register(e,n){this._types.set(e,n)}unregister(e){this._types.delete(e)}get(e){return this._types.get(e)}listHtmlMatchers(){return[...this._types.values()].filter(e=>e.fromHTML)}listSlashCommands(){const e=[];for(const n of this._types.values())n.slashCommand&&e.push(n.slashCommand),n.slashCommands&&e.push(...n.slashCommands);return e}listAtCommands(){const e=[];for(const n of this._types.values())n.atCommand&&e.push(n.atCommand),n.atCommands&&e.push(...n.atCommands);return e}}function dl(){return new ul}function be(t){const e=G(),n=p.useCallback(o=>e.subscribe(t,o),[e,t]),r=p.useCallback(()=>e.getBlock(t),[e,t]);return p.useSyncExternalStore(n,r)}function wt(t){const e=G(),n=p.useCallback(o=>e.subscribe(t,o),[e,t]),r=p.useCallback(()=>e.getRun(t),[e,t]);return p.useSyncExternalStore(n,r)}const pl="​",Id=/​/g;function at(t){return(t??"").replace(Id,"")}function Ps(t){return at(t.textContent)}function Cd(t,e){var i;const n=new Map(e.map(u=>[u.id,u])),r=new Set,o=[];let s=!0;for(const u of t.childNodes){const c=u.nodeType===1?(i=u.dataset)==null?void 0:i.runId:void 0;if(c&&n.has(c)){r.add(c);const d=n.get(c);if(d.type!=="text"){o.push(d);continue}const h=Ps(u);o.push(h===d.value?d:{...d,value:h});continue}s=!1;const f=Ps(u);f&&o.push({id:E(),type:"text",value:f,marks:{}})}if(e.some(u=>!r.has(u.id))&&(s=!1),o.length!==e.length&&(s=!1),s){for(let u=0;u<o.length;u+=1)if(o[u].id!==e[u].id){s=!1;break}}const a=!s||o.some((u,c)=>u!==e[c]);return{runs:o,changed:a,onlyValueChanges:s}}function fl(t){return t?t.type!=="text"?!1:(t.value??"")==="":!0}function Le(t,e){return!e||e.length===0?!0:e.every(n=>fl(t.getRun(n)))}function Mn(t,e){var o,s;if(!e)return!1;const n=e.contentIds.length>0,r=(((s=(o=e.props)==null?void 0:o.titleRunIds)==null?void 0:s.length)??0)>0;return!n&&!r}function hl(t,e){const n=document.querySelector(`[data-run-id="${t}"]`);if(!n)return;n.focus();const r=n.firstChild,o=document.createRange();if(r&&r.nodeType===3){const a=Math.max(0,Math.min(e,r.length));o.setStart(r,a),o.setEnd(r,a)}else o.selectNodeContents(n),o.collapse(e<=0);const s=window.getSelection();s==null||s.removeAllRanges(),s==null||s.addRange(o)}function ml(t,e){requestAnimationFrame(()=>{const n=document.querySelector(`[data-run-id="${t}"]`);if(!n)return;n.focus();const r=document.createRange();r.selectNodeContents(n),r.collapse(e);const o=window.getSelection();o==null||o.removeAllRanges(),o==null||o.addRange(r)})}function ye(t){ml(t,!1)}function br(t){ml(t,!0)}function Je(t,e){requestAnimationFrame(()=>hl(t,e))}function $s(t,e){hl(t,e)}const Sd='button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';function dt({isOpen:t,onClose:e,title:n,size:r="default",variant:o="dialog",children:s}){const a=p.useRef(null),i=p.useRef(null);if(p.useEffect(()=>{if(!t)return;const c=f=>{f.key==="Escape"&&e()};return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[t,e]),p.useEffect(()=>{var c,f,d;if(t){i.current=document.activeElement;const h=a.current;(c=(h==null?void 0:h.querySelector(Sd))??h)==null||c.focus();return}(d=(f=i.current)==null?void 0:f.focus)==null||d.call(f),i.current=null},[t]),!t)return null;const u=o==="sheet";return l.jsx("div",{className:`be-modal-overlay${u?" be-modal-overlay-sheet":""}`,onMouseDown:c=>{c.target===c.currentTarget&&e()},children:l.jsxs("div",{ref:a,className:`be-modal${r==="large"?" be-modal-large":""}${u?" be-modal-sheet":""}`,role:"dialog","aria-modal":"true","aria-label":n,tabIndex:-1,children:[n&&l.jsx("div",{className:"be-modal-title",children:n}),s]})})}function bl({isOpen:t,initialHref:e,initialTarget:n,hasExistingLink:r,onSave:o,onRemove:s,onClose:a}){const[i,u]=p.useState(""),[c,f]=p.useState("_self");p.useEffect(()=>{t&&(u(e),f(n))},[t]);const d=i.trim(),h=p.useCallback(m=>{m.preventDefault(),d&&o(d,c)},[d,c,o]);return l.jsx(dt,{isOpen:t,onClose:a,title:r?"Edit link":"Add link",children:l.jsxs("form",{onSubmit:h,children:[l.jsxs("label",{className:"be-modal-field",children:[l.jsx("span",{children:"URL"}),l.jsx("input",{type:"text",value:i,onChange:m=>u(m.target.value),placeholder:"https://example.com",autoFocus:!0})]}),l.jsxs("label",{className:"be-modal-field",children:[l.jsx("span",{children:"Open in"}),l.jsxs("select",{value:c,onChange:m=>f(m.target.value),children:[l.jsx("option",{value:"_self",children:"Same tab"}),l.jsx("option",{value:"_blank",children:"New tab"})]})]}),l.jsxs("div",{className:"be-modal-actions",children:[r&&l.jsx("button",{type:"button",className:"be-modal-delete",onClick:s,children:"Remove link"}),l.jsx("button",{type:"button",className:"be-modal-cancel",onClick:a,children:"Cancel"}),l.jsx("button",{type:"submit",className:"be-modal-save",disabled:!d,children:"Save"})]})]})})}const tn=8;function gr(t,e){const n=Math.max(tn,window.innerWidth-e-tn);return Math.min(Math.max(t,tn),n)}function Rd(t,e){const n=Math.max(tn,window.innerHeight-e-tn);return Math.min(Math.max(t,tn),n)}function Ln(t,e,n,r){const[o,s]=p.useState(null);return p.useLayoutEffect(()=>{if(n==null||r==null){s(null);return}s({top:n,left:r})},[n,r]),p.useLayoutEffect(()=>{if(!e||!t.current||!o)return;const a=t.current.getBoundingClientRect(),i=gr(o.left,a.width),u=Rd(o.top,a.height);(i!==o.left||u!==o.top)&&s({top:u,left:i})},[e,t,o]),o}function Td({containerRef:t,store:e}){var w;const[n,r]=p.useState(null),[o,s]=p.useState(!1),a=p.useRef(null),i=p.useRef(null),u=p.useCallback(()=>{a.current&&(clearTimeout(a.current),a.current=null)},[]),c=p.useCallback(()=>{u(),a.current=setTimeout(()=>{r(v=>o?v:null)},250)},[u,o]);p.useEffect(()=>{const v=t.current;if(!v)return;const j=C=>{var L,S,N;const T=(S=(L=C.target).closest)==null?void 0:S.call(L,"[data-run-id]");if(!T||!v.contains(T))return;const M=T.dataset.runId,B=e.getRun(M);(N=B==null?void 0:B.marks)!=null&&N.link&&(u(),r($=>($==null?void 0:$.runId)===M?$:{runId:M,rect:T.getBoundingClientRect()}))},I=()=>c();return v.addEventListener("mouseover",j),v.addEventListener("mouseout",I),()=>{v.removeEventListener("mouseover",j),v.removeEventListener("mouseout",I)}},[t,e,u,c]),p.useEffect(()=>()=>u(),[u]);const f=p.useCallback(()=>s(!0),[]),d=p.useCallback(()=>{s(!1),r(null)},[]),h=p.useCallback((v,j)=>{if(!n)return;const I=e.getRun(n.runId);I&&(e.applyOperation(ue(n.runId,{marks:{...I.marks,link:{href:v,target:j}}})),d())},[n,e,d]),m=p.useCallback(()=>{if(!n)return;const v=e.getRun(n.runId);if(!v)return;const j={...v.marks};delete j.link,e.applyOperation(ue(n.runId,{marks:j})),d()},[n,e,d]),g=n&&e.getRun(n.runId),x=(w=g==null?void 0:g.marks)==null?void 0:w.link,y=!!(n&&x&&!o),k=Ln(i,y,n?n.rect.bottom+6:null,n?n.rect.left:null);return l.jsxs(l.Fragment,{children:[y&&k?Ve.createPortal(l.jsxs("div",{ref:i,className:"be-link-hover-card",contentEditable:!1,style:{position:"fixed",top:k.top,left:k.left},onMouseEnter:u,onMouseLeave:c,children:[l.jsx("a",{className:"be-link-hover-card-url",href:x.href,target:x.target==="_blank"?"_blank":"_self",rel:"noopener noreferrer",children:x.href}),l.jsx("button",{type:"button",className:"be-link-hover-card-btn",onClick:f,"aria-label":"Edit link",title:"Edit link",children:l.jsx(Ya,{size:13})}),l.jsx("button",{type:"button",className:"be-link-hover-card-btn",onClick:m,"aria-label":"Remove link",title:"Remove link",children:l.jsx(Ot,{size:13})})]}),document.body):null,l.jsx(bl,{isOpen:o,initialHref:(x==null?void 0:x.href)??"",initialTarget:(x==null?void 0:x.target)??"_self",hasExistingLink:!!x,onSave:h,onRemove:m,onClose:d})]})}function gl({title:t,onClose:e}){return l.jsxs("div",{className:"be-comment-popover-header",children:[l.jsx("span",{className:"be-comment-popover-title",children:t}),l.jsx("button",{type:"button",className:"be-comment-popover-close",onClick:e,"aria-label":"Close",children:l.jsx(Ot,{size:14})})]})}function jd({containerRef:t,store:e,authorId:n}){const[r,o]=p.useState(null),[s,a]=p.useState(!1),i=p.useRef(null),u=p.useRef(null),[,c]=pr(),f=p.useCallback(()=>{i.current&&(clearTimeout(i.current),i.current=null)},[]),d=p.useCallback(()=>{f(),i.current=setTimeout(()=>{o(y=>s?y:null)},250)},[f,s]);p.useEffect(()=>{const y=t.current;if(!y)return;const k=I=>{var M,B,L;const C=(M=I==null?void 0:I.closest)==null?void 0:M.call(I,"[data-run-id]");if(!C||!y.contains(C))return null;const T=(L=(B=e.getRun(C.dataset.runId))==null?void 0:B.marks)==null?void 0:L.commentIds;return T!=null&&T.length?{runEl:C,commentIds:T}:null},w=I=>{const C=k(I.target);C&&(f(),o(T=>T&&T.runEl===C.runEl?T:{rect:C.runEl.getBoundingClientRect(),commentIds:C.commentIds,runEl:C.runEl}))},v=()=>d(),j=I=>{const C=k(I.target);if(!C){a(!1),o(null);return}f(),a(!0),o({rect:C.runEl.getBoundingClientRect(),commentIds:C.commentIds,runEl:C.runEl})};return y.addEventListener("mouseover",w),y.addEventListener("mouseout",v),y.addEventListener("click",j),()=>{y.removeEventListener("mouseover",w),y.removeEventListener("mouseout",v),y.removeEventListener("click",j)}},[t,e,f,d]),p.useEffect(()=>{if(!r)return;const y=w=>{var v,j;(v=u.current)!=null&&v.contains(w.target)||(j=t.current)!=null&&j.contains(w.target)||(a(!1),o(null))},k=w=>{w.key==="Escape"&&(a(!1),o(null))};return document.addEventListener("mousedown",y),document.addEventListener("keydown",k),()=>{document.removeEventListener("mousedown",y),document.removeEventListener("keydown",k)}},[r,t]),p.useEffect(()=>()=>f(),[f]),p.useEffect(()=>{var y;c(((y=r==null?void 0:r.commentIds)==null?void 0:y[0])??null)},[r,c]);const h=p.useCallback(()=>{a(!1),o(null)},[]),m=!!r,g=Ln(u,m,r?r.rect.bottom+6:null,r?r.rect.left:null);if(!m||!g)return null;const x=r.commentIds.map(y=>e.getComment(y)).filter(Boolean);return x.length===0?null:Ve.createPortal(l.jsxs("div",{ref:u,className:"be-comment-popover",contentEditable:!1,style:{position:"fixed",top:g.top,left:g.left},onMouseEnter:f,onMouseLeave:d,children:[l.jsx(gl,{title:`Comments (${x.length})`,onClose:h}),x.map(y=>l.jsx(Ao,{store:e,thread:y,authorId:n},y.id))]}),document.body)}function zs(t,e){const n=t==null?void 0:t.parentElement;if(!n||!n.hasAttribute("data-placeholder"))return;e.length===0||e.every(fl)?n.setAttribute("data-empty",""):n.removeAttribute("data-empty")}function Ed(t={}){return{fontWeight:t.bold?"bold":void 0,fontStyle:t.italic?"italic":void 0,textDecoration:[(t.underline||t.link)&&"underline",t.strike&&"line-through"].filter(Boolean).join(" ")||void 0,verticalAlign:t.subscript?"sub":t.superscript?"super":void 0,fontSize:t.subscript||t.superscript?"smaller":void 0,color:t.color||(t.link?"var(--noteloom-accent)":void 0),backgroundColor:t.highlight||void 0,cursor:t.link?"pointer":void 0}}function Bd(t,e){const n=t.childNodes.length===1?t.firstChild:null;n&&n.nodeType===3?n.nodeValue!==e&&(n.nodeValue=e):t.textContent=e}function _d({id:t,host:e,onValueSynced:n}){const r=wt(t),[o]=pr();return p.useLayoutEffect(()=>{var f,d,h,m,g;if(!e||!r)return;const s=r.value??"";(at(e.textContent)!==s||s===""&&e.textContent==="")&&Bd(e,s===""?pl:s);const u=Ed(r.marks);e.style.fontWeight=u.fontWeight??"",e.style.fontStyle=u.fontStyle??"",e.style.textDecoration=u.textDecoration??"",e.style.verticalAlign=u.verticalAlign??"",e.style.fontSize=u.fontSize??"",e.style.color=u.color??"",e.style.backgroundColor=u.backgroundColor??"",e.style.cursor=u.cursor??"",e.classList.toggle("be-comment-highlight",(((d=(f=r.marks)==null?void 0:f.commentIds)==null?void 0:d.length)??0)>0),e.classList.toggle("be-comment-highlight-active",!!o&&!!((m=(h=r.marks)==null?void 0:h.commentIds)!=null&&m.includes(o)));const c=(g=r.marks)==null?void 0:g.link;e.title=c!=null&&c.href?`${c.href} — Ctrl+Click to open`:"",e.onclick=c!=null&&c.href?x=>{!x.ctrlKey&&!x.metaKey||(x.preventDefault(),window.open(c.href,c.target==="_blank"?"_blank":"_self","noopener,noreferrer"))}:null,n==null||n()},[e,r,n,o]),null}function Hs(t,e,n,r){var d,h,m;const o=(d=window.getSelection)==null?void 0:d.call(window);if(!o||!o.isCollapsed||o.rangeCount===0)return null;const{anchorNode:s,anchorOffset:a}=o;if(!s||!t.contains(s))return null;const i=g=>{const x=e.indexOf(g);if(x===-1)return null;const y=r?e[x-1]:e[x+1];if(!y)return null;const k=n(y);return k&&k.type!=="text"?y:null};if(s===t){const g=r?a-1:a,x=t.childNodes[g],y=(x==null?void 0:x.nodeType)===1?(h=x.dataset)==null?void 0:h.runId:void 0;if(!y||e.indexOf(y)===-1)return null;const k=n(y);return k&&k.type!=="text"?y:null}const u=s.nodeType===1?s:s.parentElement,c=(m=u==null?void 0:u.closest)==null?void 0:m.call(u,"[data-run-id]");return!c||!t.contains(c)||!(r?a===0:a===(s.textContent??"").length)?null:i(c.getAttribute("data-run-id"))}function Fs(t,e,n){var u,c;const r=(u=window.getSelection)==null?void 0:u.call(window);if(!r||r.isCollapsed||r.rangeCount===0)return null;const o=r.getRangeAt(0);if(o.startContainer!==o.endContainer||!t.contains(o.startContainer)||o.endOffset!==o.startOffset+1)return null;const s=o.startContainer.childNodes[o.startOffset],a=(s==null?void 0:s.nodeType)===1?(c=s.dataset)==null?void 0:c.runId:void 0;if(!a||e.indexOf(a)===-1)return null;const i=n(a);return i&&i.type!=="text"?a:null}function Us(t,e,n){var i;if(e===t)return{childIndex:n,charOffset:null};const r=e.nodeType===1?e:e.parentElement,o=(i=r==null?void 0:r.closest)==null?void 0:i.call(r,"[data-run-id]");if(!o||!t.contains(o))return null;const s=Array.prototype.indexOf.call(t.childNodes,o),a=e===o?n===0?0:(o.textContent??"").length:n;return{childIndex:s,charOffset:a}}function Od(t,e,n,r){const o=Us(t,r.startContainer,r.startOffset),s=Us(t,r.endContainer,r.endOffset);if(!o||!s)return null;const a=Array.from(t.childNodes).filter(f=>{var d;return f.nodeType===1&&((d=f.dataset)==null?void 0:d.runId)&&e.indexOf(f.dataset.runId)!==-1});let i=!1;const u=[];let c=null;return a.forEach((f,d)=>{const h=f.dataset.runId,m=n(h);if(!m)return;const g=d<o.childIndex,x=s.charOffset===null?d>=s.childIndex:d>s.childIndex;if(g||x){u.push(m);return}const y=o.charOffset!==null&&d===o.childIndex,k=s.charOffset!==null&&d===s.childIndex;if(m.type!=="text"){i=!0,c===null&&(c=u.length);return}const w=m.value??"";if(y&&k){const v=w.slice(0,o.charOffset)+w.slice(s.charOffset);v&&u.push({...m,value:v}),c=u.length}else if(y){const v=w.slice(0,o.charOffset);v&&u.push({...m,value:v}),c===null&&(c=u.length)}else if(k){const v=w.slice(s.charOffset);v&&u.push({id:E(),type:"text",value:v,marks:m.marks})}}),i?{nextRuns:u,insertionIndex:c??u.length}:null}function Md(t){var s;const e=(s=window.getSelection)==null?void 0:s.call(window);if(!e||!e.isCollapsed)return!1;const n=t.firstChild;if(!n)return!0;if(e.anchorNode===t)return e.anchorOffset===0;let r=n;for(;r&&r.firstChild;)r=r.firstChild;if(e.anchorNode!==r&&e.anchorNode!==n)return!1;const o=r.nodeType===3&&r.textContent===pl?1:0;return e.anchorOffset<=o}function Ld(t){var s;const e=(s=window.getSelection)==null?void 0:s.call(window);if(!e||!e.isCollapsed)return!1;const n=t.lastChild;if(!n)return!0;if(e.anchorNode===t)return e.anchorOffset>=t.childNodes.length;let r=n;for(;r&&r.lastChild;)r=r.lastChild;if(e.anchorNode!==r&&e.anchorNode!==n)return!1;const o=r.nodeType===3?(r.textContent??"").length:0;return e.anchorOffset>=o}function Vs(t,e,n){const r=t.getBlock(e),o=t.getBlock(r==null?void 0:r.parentId);if(!o)return null;const s=o.contentIds.indexOf(e),a=n==="backward"?s-1:s+1;if(a<0||a>=o.contentIds.length)return null;const i=o.contentIds[a];return Mn(t,t.getBlock(i))?i:null}function Nd({id:t,blockId:e,host:n,inlineRegistry:r,onValueSynced:o}){const s=wt(t);if(!s)return null;if(s.type==="text")return l.jsx(_d,{id:t,host:n,onValueSynced:o});const a=r==null?void 0:r.get(s.type);if(!a)return process.env.NODE_ENV!=="production"&&console.warn(`[block-editor] No inline type registered for "${s.type}" (run: ${t})`),null;const i=a.component;return l.jsx(i,{id:t,blockId:e})}function Ad(t,e,n){let r=t.get(n);if(!r){r=document.createElement("span"),r.dataset.runId=n;const o=e.getRun(n);o&&o.type!=="text"&&r.setAttribute("contenteditable","false"),t.set(n,r)}return r}function pt({blockId:t,runIds:e,dir:n="auto",onEnter:r,onBackspaceAtStart:o,onDeleteAtEnd:s,onArrowUp:a,onArrowDown:i,onTab:u,onShiftTab:c,onAutoformat:f}){const d=G(),h=tt(),m=$a(),{getSelectedBlockId:g,setSelectedBlockId:x}=ut(),y=p.useRef(null),k=p.useRef(!1),w=p.useRef(new Map);p.useLayoutEffect(()=>{const S=y.current;if(!S)return;const N=new Set(e);for(const[V,K]of w.current)N.has(V)||(K.remove(),w.current.delete(V));let $=null;for(const V of e){const K=w.current.get(V);if(!K)continue;const Q=$?$.nextSibling:S.firstChild;Q!==K&&S.insertBefore(K,Q),$=K}},[e]);const v=p.useCallback(()=>{if(k.current)return;const S=y.current;if(!S)return;const N=e.map(Q=>d.getRun(Q)).filter(Boolean),{runs:$,changed:V,onlyValueChanges:K}=Cd(S,N);if(V){if(K){if($.forEach((Q,D)=>{Q!==N[D]&&d.applyOperation(ue(Q.id,{value:Q.value}))}),f!=null&&f($))return}else d.applyOperation(Me(t,$.length?$:[{id:E(),type:"text",value:"",marks:{}}]));zs(S,$)}},[d,t,e,f]),j=p.useCallback(()=>{zs(y.current,e.map(S=>d.getRun(S)).filter(Boolean))},[d,e]),I=p.useCallback(()=>{k.current=!0},[]),C=p.useCallback(()=>{k.current=!1,v()},[v]),T=p.useCallback(S=>{const $=e.map(V=>d.getRun(V)).filter(Boolean).filter(V=>V.id!==S);d.applyOperation(Me(t,$.length?$:[{id:E(),type:"text",value:"",marks:{}}]))},[d,t,e]),M=p.useCallback(S=>{g()===S?(d.applyOperation(ee(S)),x(null)):x(S)},[d,g,x]),B=p.useCallback(S=>{var ce,ke,he,U;if(k.current)return;if(S.target instanceof Node){const ae=S.target.nodeType===1?S.target:S.target.parentElement;if((ce=ae==null?void 0:ae.closest)!=null&&ce.call(ae,'[contenteditable="false"]'))return}const N=S.inputType??"",$=N.startsWith("delete"),V=N==="insertText"||N==="insertReplacementText";if(!$&&!V)return;const K=y.current;if(!K)return;const Q=(ke=S.getTargetRanges)==null?void 0:ke.call(S),D=(he=window.getSelection)==null?void 0:he.call(window),F=(Q==null?void 0:Q[0])??(D!=null&&D.rangeCount?D.getRangeAt(0):null);if(!F||!K.contains(F.startContainer)||!K.contains(F.endContainer))return;const re=Od(K,e,ae=>d.getRun(ae),F);if(!re)return;S.preventDefault();let{nextRuns:H,insertionIndex:ne}=re,se=null,oe=!1;if(V&&S.data){const ae={id:E(),type:"text",value:S.data,marks:{}};H=[...H.slice(0,ne),ae,...H.slice(ne)],se=ae.id,oe=!1}else ne>0?(se=(U=H[ne-1])==null?void 0:U.id,oe=!1):H.length>0&&(se=H[0].id,oe=!0);const ge=H.length?H:[{id:E(),type:"text",value:"",marks:{}}];d.applyOperation(Me(t,ge));const Te=se??ge[0].id;oe?br(Te):ye(Te)},[d,t,e]);p.useEffect(()=>{const S=y.current;if(S)return S.addEventListener("beforeinput",B),()=>S.removeEventListener("beforeinput",B)},[B]);const L=p.useCallback(S=>{if(!k.current){if(S.key==="Enter"&&r){S.preventDefault(),r(S);return}if(S.key==="Backspace"){const N=y.current,$=N&&Fs(N,e,d.getRun.bind(d));if($){S.preventDefault(),T($);return}const V=N&&Hs(N,e,d.getRun.bind(d),!0);if(V){S.preventDefault(),T(V);return}if(N&&Md(N)){if(!Le(d,e)){const Q=Vs(d,t,"backward");if(Q){S.preventDefault(),M(Q);return}}S.preventDefault(),o&&o(S)}return}if(S.key==="Delete"){const N=y.current,$=N&&Fs(N,e,d.getRun.bind(d));if($){S.preventDefault(),T($);return}const V=N&&Hs(N,e,d.getRun.bind(d),!1);if(V){S.preventDefault(),T(V);return}if(N&&Ld(N)){const K=Vs(d,t,"forward");if(K){S.preventDefault(),M(K);return}s&&s(S)}return}if(S.key==="ArrowUp"&&a){S.preventDefault(),a(S);return}if(S.key==="ArrowDown"&&i){S.preventDefault(),i(S);return}S.key==="Tab"&&(S.shiftKey&&c?(S.preventDefault(),c(S)):!S.shiftKey&&u&&(S.preventDefault(),u(S)))}},[r,o,s,a,i,u,c,T,M,e,t,d]);return l.jsxs(l.Fragment,{children:[l.jsx("span",{ref:y,className:"be-editable",dir:n,contentEditable:!0,suppressContentEditableWarning:!0,onInput:v,onCompositionStart:I,onCompositionEnd:C,onKeyDown:L,children:e.map(S=>{const N=Ad(w.current,d,S);return Ve.createPortal(l.jsx(Nd,{id:S,blockId:t,host:N,inlineRegistry:h,onValueSynced:j},S),N)})}),l.jsx(Td,{containerRef:y,store:d}),l.jsx(jd,{containerRef:y,store:d,authorId:m})]})}function Dd(t,e,n){const r=t.getBlock(e),o=r&&t.getBlock(r.parentId);if(!o)return null;const s=o.contentIds.indexOf(e),a=n==="up"?s-1:s+1;return a<0||a>=o.contentIds.length?null:o.contentIds[a]}function xl(t,e,n){let r=e;for(;;){const o=Dd(t,r,n);if(!o)return null;const s=n==="up"?xr(t,o):Do(t,o);if(s)return s;r=o}}function _e(t,e,n){const r=xl(t,e,n);r&&ye(r)}function Do(t,e){var s;const n=t.getBlock(e);if(!n)return null;const r=((s=n.props)==null?void 0:s.titleRunIds)??n.contentIds;if(!r||r.length===0)return null;const o=r[0];return t.getRun(o)?o:Do(t,o)}function Re(t,e){const n=Do(t,e);n&&ye(n)}function xr(t,e){var s;const n=t.getBlock(e);if(!n)return null;const r=((s=n.props)==null?void 0:s.titleRunIds)??n.contentIds;if(!r||r.length===0)return null;const o=r[r.length-1];return t.getRun(o)?o:xr(t,o)}function Ys(t,e){const n=xr(t,e);n&&ye(n)}function Pd(){var i,u;const t=(i=window.getSelection)==null?void 0:i.call(window);if(!t||t.rangeCount===0)return null;const e=t.getRangeAt(0);if(e.collapsed||e.startContainer!==e.endContainer)return null;const n=e.startContainer,r=n.nodeType===1?n:n.parentElement,o=(u=r==null?void 0:r.closest)==null?void 0:u.call(r,"[data-run-id]");if(!o)return null;const s=o.closest("[data-block-id]");if(!s)return null;const a=n.textContent??"";return{runId:o.getAttribute("data-run-id"),blockId:s.getAttribute("data-block-id"),startOffset:at(a.slice(0,e.startOffset)).length,endOffset:at(a.slice(0,e.endOffset)).length}}function $d(t,e){var i,u;if((t==null?void 0:t.nodeType)!==1||((i=t.getAttribute)==null?void 0:i.call(t,"contenteditable"))!=="true")return null;const n=t.childNodes;if(n.length===0)return null;const r=e>=n.length,o=n[r?n.length-1:Math.max(0,e)],s=(o==null?void 0:o.nodeType)===1?(u=o.dataset)==null?void 0:u.runId:void 0;if(!s)return null;const a=o.closest("[data-block-id]");return a?{runId:s,blockId:a.getAttribute("data-block-id"),offset:r?at(o.textContent??"").length:0}:null}function Rn(t,e){var i;const n=$d(t,e);if(n)return n;let r=(t==null?void 0:t.nodeType)===1?t:t==null?void 0:t.parentElement;const o=(i=r==null?void 0:r.closest)==null?void 0:i.call(r,"[data-run-id]");if(!o)return null;const s=o.closest("[data-block-id]");if(!s)return null;let a=at((t.textContent??"").slice(0,e)).length;if(t===o){a=0;for(let u=0;u<e&&u<o.childNodes.length;u+=1)a+=at(o.childNodes[u].textContent??"").length}return{runId:o.getAttribute("data-run-id"),blockId:s.getAttribute("data-block-id"),offset:a}}function lt(){var e;const t=(e=window.getSelection)==null?void 0:e.call(window);return!t||t.rangeCount===0||!t.isCollapsed?null:Rn(t.anchorNode,t.anchorOffset)}function ln(){var r;const t=(r=window.getSelection)==null?void 0:r.call(window);if(!t||t.rangeCount===0||t.isCollapsed)return null;const e=Rn(t.anchorNode,t.anchorOffset),n=Rn(t.focusNode,t.focusOffset);return!e||!n||e.blockId!==n.blockId?null:{blockId:e.blockId,startRunId:e.runId,startOffset:e.offset,endRunId:n.runId,endOffset:n.offset}}function rn(t){var d;const e=(d=window.getSelection)==null?void 0:d.call(window);if(!e||e.rangeCount===0||e.isCollapsed)return null;const n=Rn(e.anchorNode,e.anchorOffset),r=Rn(e.focusNode,e.focusOffset);if(!n||!r||n.blockId===r.blockId)return null;const o=t.getBlock(n.blockId),s=o&&t.getBlock(o.parentId);if(!s)return null;const a=s.contentIds,i=a.indexOf(n.blockId),u=a.indexOf(r.blockId);if(i===-1||u===-1)return null;const[c,f]=i<=u?[i,u]:[u,i];return{blockIds:a.slice(c,f+1),startBlockId:n.blockId,startRunId:n.runId,startOffset:n.offset,endBlockId:r.blockId,endRunId:r.runId,endOffset:r.offset}}function yr(t,e,n){const o=t.getBlock(e).parentId,a=t.getBlock(o).contentIds.indexOf(e)+1,{block:i,runs:u=[],subtreeBlocks:c=[]}=n(o);return t.applyOperation(me(i,o,a,{blocks:[i,...c],runs:u})),i.id}function nt(t,e,n){const r=yr(t,e,n);return Re(t,r),r}function zd(t,e,n){const{block:r,runs:o=[],subtreeBlocks:s=[]}=n(e);return t.applyOperation(me(r,e,0,{blocks:[r,...s],runs:o})),Re(t,r.id),r.id}function yl(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Hd(t,e,n){const r=t.findIndex(c=>c.id===e);if(r===-1)return null;const o=t[r],s=t.slice(0,r),a=t.slice(r+1);if(o.type==="text"){const c=o.value??"",f=c.slice(0,n),d=c.slice(n);f&&d?(s.push({...o,value:f}),a.unshift({...o,id:E(),value:d})):d?a.unshift(o):s.push(o)}else n>0?s.push(o):a.unshift(o);const i=s.length?s:[{id:E(),type:"text",value:"",marks:{}}],u=a.length?a:[{id:E(),type:"text",value:"",marks:{}}];return{leftRuns:i,rightRuns:u}}function cn(t,e,n,r){const o=t.getBlock(e),s=t.getBlock(o.parentId),a=s.contentIds.indexOf(e)+1;return vl(t,e,n,r,{insertParentId:s.id,insertIndex:a,fallback:()=>nt(t,e,r)})}function kl(t,e,n,r){return vl(t,e,n,r,{insertParentId:e,insertIndex:0,fallback:()=>zd(t,e,r)})}function vl(t,e,n,r,{insertParentId:o,insertIndex:s,fallback:a}){const i=lt();if(!i||i.blockId!==e)return a();const u=n.map(y=>t.getRun(y)).filter(Boolean),c=Hd(u,i.runId,i.offset);if(!c)return a();const{leftRuns:f,rightRuns:d}=c,{block:h,runs:m=d,subtreeBlocks:g=[]}=r(o,d),x=f.length?f:[{id:E(),type:"text",value:"",marks:{}}];return yl(t,[Me(e,x),me(h,o,s,{blocks:[h,...g],runs:m})]),Re(t,h.id),h.id}function Fd(t){var e;return((e=t==null?void 0:t.props)==null?void 0:e.titleRunIds)??(t==null?void 0:t.contentIds)??[]}function Ud(t){var e,n;return!!((e=t==null?void 0:t.props)!=null&&e.titleRunIds)&&(((n=t.contentIds)==null?void 0:n.length)??0)>0}function Vd(t,e,n){const o=t.getBlock(e).parentId,a=t.getBlock(o).contentIds.indexOf(e),{block:i,runs:u=[],subtreeBlocks:c=[]}=n(o);return yl(t,[ee(e),me(i,o,a,{blocks:[i,...c],runs:u})]),Re(t,i.id),i.id}function Be(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o},s){const a=t.getRun(n),i=(a==null?void 0:a.value)??"",u=i.slice(0,r)+i.slice(o),c=t.getBlock(e),f=Fd(c);return f.length===1&&f[0]===n&&u===""&&!Ud(c)?Vd(t,e,s):(t.applyOperation(ue(n,{value:u})),nt(t,e,s))}function te(t,e={}){return function(r,o){const s=E(),a=o!=null&&o.length?o:[{id:E(),type:"text",value:"",marks:{}}];return{block:{id:s,type:t,parentId:r,contentIds:a.map(i=>i.id),props:e},runs:a}}}function un(t){const e=t.getRootId(),n=t.getBlock(e);if(!n||n.contentIds.length>0)return null;const{block:r,runs:o}=te("paragraph")(e);return t.applyOperation(me(r,e,0,{blocks:[r],runs:o})),r.id}const Yd=new Set(["callout"]),Ks=new Set(["paragraph","heading","blockquote"]);function wl(t,e){return t===e||Ks.has(t)&&Ks.has(e)}function Nn(t,e){const n=t.getBlock(e);if(!n)return null;const r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=n.contentIds.length===0||n.contentIds.length===1&&Kd(t,n.contentIds[0]);if(o<=0){if(!s)return null;if(r.contentIds.length>1)return Zt(t,[ee(e)]),t.getBlock(r.id).contentIds[0];if(Yd.has(r.type))return Wd(t,r);if(n.type==="paragraph")return null;const{block:c,runs:f}=te("paragraph")(r.id);return Zt(t,[me(c,r.id,o,{blocks:[c],runs:f}),ee(e)]),c.id}const a=r.contentIds[o-1],i=t.getBlock(a);if(s)return Zt(t,[ee(e)]),a;if(Mn(t,i))return Zt(t,[ee(a)]),e;if(!i||!wl(i.type,n.type))return null;const u=[...i.contentIds,...n.contentIds];return Zt(t,[nn(a,u),nn(e,[]),ee(e)]),a}function Kd(t,e){const n=t.getRun(e);return!n||(n.value??"")===""}function Wd(t,e){const n=t.getBlock(e.parentId);if(!n)return null;const r=n.contentIds.indexOf(e.id),o=r>0?n.contentIds[r-1]:null,s=r!==-1&&r<n.contentIds.length-1?n.contentIds[r+1]:null;Zt(t,[ee(e.id)]);const a=un(t);return o??s??a}function Zt(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function dn(t,e,n,r){if(!e||e===n)return;const o=xr(t,e);if(o){ye(o);return}r(e),requestAnimationFrame(()=>{var s;(s=document.querySelector(`[data-block-id="${e}"]`))==null||s.focus()})}function it(t,e){var r,o;if(!e)return"auto";if((r=e.props)!=null&&r.dir)return e.props.dir;const n=t.getBlock(t.getRootId());return((o=n==null?void 0:n.props)==null?void 0:o.dir)??"auto"}function Po(t,e,n,r,o,s){const a=t.getBlock(e),u=t.getBlock(a.parentId).contentIds.indexOf(e),c="titleRunIds"in r,f="titleRunIds"in(a.props??{}),d=s?!s.isLeaf(a.type)&&a.contentIds.length>0:!1,h=s?!s.isLeaf(n):!1,m=[];if(d&&!h&&a.contentIds.forEach((g,x)=>m.push(ct(g,a.parentId,u+1+x))),m.push(fo(e,n,r)),c)m.push(J(e,{titleRunIds:o})),!f&&!d&&m.push(nn(e,[]));else{const g=d&&h?a.contentIds:[];m.push(nn(e,[...g,...o]))}return{newBlockId:e,ops:m}}function Xd(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}const qd=[{re:/^(#{1,3})[  ]$/,type:"heading",props:t=>({level:t[1].length})},{re:/^[-*][  ]$/,type:"listItem",props:()=>({ordered:!1,titleRunIds:[]})},{re:/^\d+\.[  ]$/,type:"listItem",props:()=>({ordered:!0,titleRunIds:[]})},{re:/^\[\][  ]$/,type:"listItem",props:()=>({ordered:!1,checked:!1,titleRunIds:[]})},{re:/^>[  ]$/,type:"blockquote",props:()=>({})},{re:/^```$/,type:"code",props:()=>({language:"plaintext"})}];function Gd(t,e,n){if(n.length!==1||n[0].type!=="text")return!1;const r=n[0].value??"";for(const o of qd){const s=o.re.exec(r);if(!s)continue;const a=r.slice(s[0].length),{ops:i}=Po(t,e,o.type,o.props(s),[n[0].id]);return Xd(t,[ue(n[0].id,{value:a}),...i]),br(n[0].id),!0}return!1}const Jd=new Set(["callout","toggleHeading"]);function Zd({id:t}){const e=G(),n=be(t),{setSelectedBlockId:r}=ut(),o=p.useCallback(()=>{const h=e.getBlock(n==null?void 0:n.parentId),m=Le(e,(n==null?void 0:n.contentIds)??[]),g=!!h&&h.contentIds[h.contentIds.length-1]===t;if(m&&g&&Jd.has(h==null?void 0:h.type)){nt(e,h.id,te("paragraph"));return}cn(e,t,(n==null?void 0:n.contentIds)??[],te("paragraph"))},[e,t,n]),s=p.useCallback(()=>{var y,k;const h=e.getBlock(n==null?void 0:n.parentId),m=Le(e,(n==null?void 0:n.contentIds)??[]),g=((y=h==null?void 0:h.contentIds)==null?void 0:y.length)===1&&h.contentIds[0]===t;if(m&&g&&(h==null?void 0:h.type)==="toggleHeading"){const w=((k=h.props)==null?void 0:k.titleRunIds)??[],v=w[w.length-1];v&&ye(v);return}const x=Nn(e,t);dn(e,x,t,r)},[e,t,n,r]),a=p.useCallback(()=>_e(e,t,"up"),[e,t]),i=p.useCallback(()=>_e(e,t,"down"),[e,t]),u=p.useCallback(h=>Gd(e,t,h),[e,t]),c=Ie("be-paragraph",n);if(!n)return null;const f=Le(e,n.contentIds),d=it(e,n);return l.jsx("div",{className:c,"data-block-id":t,"data-empty":f?"":void 0,"data-placeholder":"Type '/' for commands",dir:d,children:l.jsx(pt,{blockId:t,runIds:n.contentIds,dir:d,onEnter:o,onBackspaceAtStart:s,onArrowUp:a,onArrowDown:i,onAutoformat:u})})}function Et(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Ee(t){return Et(t).replace(/"/g,"&quot;")}function ft(t,e){var o,s;if(!t)return"";if(t.type!=="text"){const a=(o=e==null?void 0:e.inlineRegistry)==null?void 0:o.get(t.type);return a?a.toHTML(t,e):Et(t.value??"")}const n=t.marks??{};let r=Et(t.value??"");if(n.code&&(r=`<code>${r}</code>`),n.bold&&(r=`<strong>${r}</strong>`),n.italic&&(r=`<em>${r}</em>`),n.underline&&(r=`<u>${r}</u>`),n.strike&&(r=`<s>${r}</s>`),n.subscript&&(r=`<sub>${r}</sub>`),n.superscript&&(r=`<sup>${r}</sup>`),n.color&&(r=`<span style="color:${Ee(n.color)}">${r}</span>`),n.highlight&&(r=`<span style="background-color:${Ee(n.highlight)}">${r}</span>`),(s=n.link)!=null&&s.href){const a=n.link.target==="_blank"?' target="_blank" rel="noopener noreferrer"':"";r=`<a href="${Ee(n.link.href)}"${a}>${r}</a>`}return r}function Hr(t,e){return(t??[]).map(n=>ft(n,e)).join("")}function It(t,e){var n;if(!t)return"";if(t.type!=="text"){const r=(n=e==null?void 0:e.inlineRegistry)==null?void 0:n.get(t.type);return r?r.toPlainText(t,e):t.value??""}return t.value??""}const Qd={STRONG:"bold",B:"bold",EM:"italic",I:"italic",U:"underline",S:"strike",STRIKE:"strike",DEL:"strike",CODE:"code",SUB:"subscript",SUP:"superscript"};function Ye(t,e,n={}){const r=[],o=(s,a)=>{var c,f;if(s.nodeType===3){const d=s.textContent;d&&r.push({id:E(),type:"text",value:d,marks:{...a}});return}if(s.nodeType!==1)return;if(e!=null&&e.inlineRegistry)for(const d of e.inlineRegistry.listHtmlMatchers()){const h=d.fromHTML(s,e);if(h){r.push(h);return}}let i=a;const u=Qd[s.tagName];u&&(i={...i,[u]:!0}),s.tagName==="A"&&s.getAttribute("href")&&(i={...i,link:{href:s.getAttribute("href"),target:s.getAttribute("target")==="_blank"?"_blank":"_self"}}),(c=s.style)!=null&&c.color&&(i={...i,color:s.style.color}),(f=s.style)!=null&&f.backgroundColor&&(i={...i,highlight:s.style.backgroundColor});for(const d of s.childNodes)o(d,i)};return o(t,n),r.length?r:[{id:E(),type:"text",value:"",marks:{}}]}function ep(t,e){return`<p>${t.contentIds.map(r=>e.store.getRun(r)).map(r=>ft(r,e)).join("")}</p>`}function tp(t,e){return t.contentIds.map(n=>It(e.store.getRun(n),e)).join("")}function np(t,e){if(t.tagName!=="P")return null;const n=Ye(t,e);return{block:{id:E(),type:"paragraph",parentId:null,contentIds:n.map(o=>o.id),props:{}},runs:n}}const Il={component:Zd,isLeaf:!0,defaultProps:{},toHTML:ep,toPlainText:tp,fromHTML:np,slashCommand:{label:"Text",icon:Eo,keywords:["paragraph","text","p"],run:(t,e)=>Be(t,e,te("paragraph"))}};function rp({id:t}){var m;const e=G(),n=be(t),{setSelectedBlockId:r}=ut(),o=p.useCallback(()=>{cn(e,t,(n==null?void 0:n.contentIds)??[],te("paragraph"))},[e,t,n]),s=p.useCallback(()=>{const g=Nn(e,t);dn(e,g,t,r)},[e,t,r]),a=p.useCallback(()=>_e(e,t,"up"),[e,t]),i=p.useCallback(()=>_e(e,t,"down"),[e,t]),u=((m=n==null?void 0:n.props)==null?void 0:m.level)??3,c=Ie(`be-heading be-heading-${u}`,n);if(!n)return null;const f=`h${u}`,d=Le(e,n.contentIds),h=it(e,n);return l.jsx(f,{className:c,"data-block-id":t,"data-empty":d?"":void 0,"data-placeholder":`Heading ${u}`,dir:h,children:l.jsx(pt,{blockId:t,runIds:n.contentIds,dir:h,onEnter:o,onBackspaceAtStart:s,onArrowUp:a,onArrowDown:i})})}const Fr={1:Za,2:Qa,3:el},op={H1:1,H2:2,H3:3};function sp(t,e){var o;const n=((o=t.props)==null?void 0:o.level)??3,r=t.contentIds.map(s=>e.store.getRun(s));return`<h${n}>${r.map(s=>ft(s,e)).join("")}</h${n}>`}function ap(t,e){return t.contentIds.map(n=>It(e.store.getRun(n),e)).join("")}function lp(t,e){const n=op[t.tagName];if(!n)return null;const r=Ye(t,e);return{block:{id:E(),type:"heading",parentId:null,contentIds:r.map(s=>s.id),props:{level:n}},runs:r}}const Cl={component:rp,isLeaf:!0,defaultProps:{level:3},toHTML:sp,toPlainText:ap,fromHTML:lp,slashCommands:[{label:"Heading 1",icon:Fr[1],keywords:["heading","h1","title"],run:(t,e)=>Be(t,e,te("heading",{level:1}))},{label:"Heading 2",icon:Fr[2],keywords:["heading","h2","subtitle"],run:(t,e)=>Be(t,e,te("heading",{level:2}))},{label:"Heading 3",icon:Fr[3],keywords:["heading","h3","title"],run:(t,e)=>Be(t,e,te("heading",{level:3}))}]},ip=[];function $o(t){const e=G(),n=p.useCallback(o=>e.subscribe(t,o),[e,t]),r=p.useCallback(()=>{const o=e.getBlock(t);return o?o.contentIds:ip},[e,t]);return p.useSyncExternalStore(n,r)}class Sl extends p.Component{constructor(){super(...arguments);_s(this,"state",{hasError:!1,nonce:0})}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(n,r){var o,s;process.env.NODE_ENV!=="production"&&console.error("[block-editor] a block failed to render; recovering by remounting it:",n,r),(s=(o=this.props).onError)==null||s.call(o,n,r),queueMicrotask(()=>this.setState(a=>({hasError:!1,nonce:a.nonce+1})))}render(){return this.state.hasError?null:l.jsx(p.Fragment,{children:this.props.children},this.state.nonce)}}const zo=p.memo(function({id:e}){const n=be(e),r=vt();if(!n)return null;const o=r.get(n.type);if(!o)return process.env.NODE_ENV!=="production"&&console.warn(`[block-editor] No block type registered for "${n.type}" (id: ${e})`),null;const s=o.component;return l.jsx(Sl,{children:l.jsx(s,{id:e})})});function Ue(t,e,n){p.useEffect(()=>{if(!e)return;const r=Array.isArray(t)?t:[t],o=a=>{r.some(u=>u.current&&u.current.contains(a.target))||n()},s=a=>{a.key==="Escape"&&n()};return document.addEventListener("mousedown",o),document.addEventListener("keydown",s),()=>{document.removeEventListener("mousedown",o),document.removeEventListener("keydown",s)}},[e,n,t])}function kr(t,e,n,r){const o=p.useRef(!1),s=p.useRef(!1);p.useEffect(()=>{var f,d;if(!e){s.current=!1,o.current&&(o.current=!1,(d=(f=r==null?void 0:r.current)==null?void 0:f.focus)==null||d.call(f));return}o.current=!0;const a=t.current;if(!a)return;const i=()=>Array.from(a.querySelectorAll('[role="menuitem"]')),u=h=>{var x;const m=i();if(m.length===0)return;const g=(h%m.length+m.length)%m.length;(x=m[g])==null||x.focus()};s.current||(s.current=!0,u(0));const c=h=>{if(h.key==="Escape"){h.preventDefault(),n();return}const m=i(),g=m.indexOf(document.activeElement);g!==-1&&(h.key==="ArrowDown"?(h.preventDefault(),u(g+1)):h.key==="ArrowUp"?(h.preventDefault(),u(g-1)):h.key==="Home"?(h.preventDefault(),u(0)):h.key==="End"&&(h.preventDefault(),u(m.length-1)))};return a.addEventListener("keydown",c),()=>a.removeEventListener("keydown",c)})}const Ws="be-live-region";function cp(){if(typeof document>"u")return null;let t=document.getElementById(Ws);return t||(t=document.createElement("div"),t.id=Ws,t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),Object.assign(t.style,{position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:"0",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:"0"}),document.body.appendChild(t),t)}function xe(t){const e=cp();e&&(e.textContent="",setTimeout(()=>{e.textContent=t},0))}const pn="💡",Rl="gray";function up({icon:t=pn,color:e=Rl}={}){return function(r){const o=E(),{block:s,runs:a}=te("paragraph")(o);return{block:{id:o,type:"callout",parentId:r,contentIds:[s.id],props:{icon:t,color:e}},runs:a,subtreeBlocks:[s]}}}const Tl=[{type:"paragraph",props:{},label:"Text",icon:Eo},{type:"heading",props:{level:1},label:"Heading 1",icon:Za},{type:"heading",props:{level:2},label:"Heading 2",icon:Qa},{type:"heading",props:{level:3},label:"Heading 3",icon:el},{type:"listItem",props:{ordered:!1,titleRunIds:[]},label:"Bulleted list",icon:rl},{type:"listItem",props:{ordered:!0,titleRunIds:[]},label:"Numbered list",icon:ol},{type:"listItem",props:{ordered:!1,checked:!1,titleRunIds:[]},label:"To-do list",icon:Oo},{type:"listItem",props:{ordered:!1,collapsed:!1,titleRunIds:[]},label:"Toggle list",icon:jt},{type:"toggleHeading",props:{level:2,collapsed:!1,titleRunIds:[]},label:"Toggle heading",icon:jt},{type:"blockquote",props:{},label:"Quote",icon:tl},{type:"callout",props:{icon:pn},label:"Callout",icon:nl},{type:"code",props:{language:"plaintext"},label:"Code",icon:_o}],dp=new Set(Tl.map(t=>t.type));function Ho(t){return dp.has(t)}function pp(t,e){return t!=null&&t.props&&"titleRunIds"in t.props?t.props.titleRunIds:e&&!e.isLeaf(t==null?void 0:t.type)?[]:(t==null?void 0:t.contentIds)??[]}function jl(t,e,n,r){const o=t.getBlock(n),s=pp(o,e),a=[];if(r.type==="code")for(const f of s){const d=t.getRun(f);d!=null&&d.marks&&Object.keys(d.marks).length>0&&a.push(ue(f,{marks:{}}))}const i={...r.props},{ops:u,newBlockId:c}=Po(t,n,r.type,i,s,e);return{ops:[...a,...u],newBlockId:c}}function El({onSelect:t,onClose:e,containerRef:n,menuClassName:r="be-block-gutter-menu",itemClassName:o="be-block-gutter-menu-item"}){const[s,a]=p.useState(!1),[i,u]=p.useState(null),c=p.useRef(null),f=p.useRef(null),d=p.useCallback(w=>{f.current=w,n&&(n.current=w)},[n]),h=p.useCallback(()=>{a(!1),e==null||e()},[e]);Ue([c,f],s,h),kr(f,s,h,c);const m=Ln(f,s,i==null?void 0:i.top,i?i.right+4:null),g=p.useCallback(()=>{var w;u(((w=c.current)==null?void 0:w.getBoundingClientRect())??null),a(!0)},[]),x=p.useCallback(w=>{t(w),h()},[t,h]),y=p.useCallback(w=>{w.key==="ArrowRight"&&!s&&(w.preventDefault(),g())},[s,g]),k=p.useCallback(w=>{w.key==="ArrowLeft"&&(w.preventDefault(),h())},[h]);return l.jsxs(l.Fragment,{children:[l.jsxs("button",{ref:c,type:"button",role:"menuitem",className:o,"aria-haspopup":"menu","aria-expanded":s,onClick:()=>s?h():g(),onKeyDown:y,children:[l.jsx(jt,{size:15})," Turn into"]}),s&&m&&Ve.createPortal(l.jsx("div",{ref:d,role:"menu","aria-label":"Turn into",className:r,style:{position:"fixed",top:m.top,left:m.left},onKeyDown:k,children:Tl.map((w,v)=>{const j=w.icon;return l.jsxs("button",{type:"button",role:"menuitem",className:o,onClick:()=>x(w),children:[l.jsx(j,{size:15})," ",w.label]},`${w.type}-${v}`)})}),document.body)]})}function Fo(t,e){const n=t.getBlock(e);if(!n)return null;const r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=Bn(t,e),{block:a,runs:i,subtreeBlocks:u}=dr(s);return t.applyOperation(me(a,r.id,o+1,{blocks:[a,...u],runs:i})),Re(t,a.id),a.id}function Uo(t,e){const n=t.getBlock(e),r=n&&t.getBlock(n.parentId);if(!r)return!1;const o=r.contentIds.indexOf(e);return o<=0?!1:(t.applyOperation(ct(e,r.id,o-1)),!0)}function Vo(t,e){const n=t.getBlock(e),r=n&&t.getBlock(n.parentId);if(!r)return!1;const o=r.contentIds.indexOf(e);return o===-1||o>=r.contentIds.length-1?!1:(t.applyOperation(ct(e,r.id,o+1)),!0)}function vr(t,e){const n=t.getBlock(e);if(!n)return null;const r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=o>0?r.contentIds[o-1]:null,a=o!==-1&&o<r.contentIds.length-1?r.contentIds[o+1]:null;t.applyOperation(ee(e));const i=un(t),u=s??a??i;return u&&Re(t,u),u??null}function fp(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Bl({id:t}){var S;const e=G(),n=vt(),r=be(t),[o,s]=p.useState(!1),[a,i]=p.useState(null),u=p.useRef(null),c=p.useRef(null),f=p.useRef(null),d=p.useMemo(()=>[u,c,f],[]),[h]=_n(),m=h.includes(t),g=p.useCallback(()=>s(!1),[]);Ue(d,o,g),kr(c,o,g,u);const x=p.useCallback(()=>{var N;i(((N=u.current)==null?void 0:N.getBoundingClientRect())??null),s(!0)},[]),y=Ln(c,o,(a==null?void 0:a.bottom)!=null?a.bottom+4:null,a==null?void 0:a.left),k=p.useCallback(()=>{nt(e,t,te("paragraph"))},[e,t]),w=p.useCallback(()=>{Fo(e,t),xe("Block duplicated"),g()},[e,t,g]),v=p.useCallback(()=>{Uo(e,t)&&xe("Block moved up"),g()},[e,t,g]),j=p.useCallback(()=>{Vo(e,t)&&xe("Block moved down"),g()},[e,t,g]),I=p.useCallback(()=>{vr(e,t),xe("Block deleted"),g()},[e,t,g]),C=!!((S=r==null?void 0:r.props)!=null&&S.hidden),T=p.useCallback(()=>{e.applyOperation(J(t,{hidden:!C})),xe(C?"Block shown in preview":"Block hidden in preview"),g()},[e,t,C,g]),M=it(e,r)==="rtl",B=p.useCallback(()=>{e.applyOperation(J(t,{dir:M?"ltr":"rtl"})),xe(M?"Block set to left-to-right":"Block set to right-to-left"),g()},[e,t,M,g]),L=p.useCallback(N=>{const{ops:$}=jl(e,n,t,N);fp(e,$),xe(`Turned into ${N.label}`),g()},[e,n,t,g]);return r?l.jsxs("div",{className:`be-block-row${C?" be-block-row-hidden":""}${m?" be-block-row-range-selected":""}`,"data-block-row-id":t,dir:it(e,r),children:[l.jsxs("div",{className:`be-block-gutter${o?" be-block-gutter-active":""}`,contentEditable:!1,children:[l.jsx("button",{type:"button",className:"be-block-gutter-btn",onClick:k,"aria-label":"Add block below",children:l.jsx(To,{size:16})}),l.jsx("button",{ref:u,type:"button",className:"be-block-gutter-btn","aria-label":"More options","aria-haspopup":"menu","aria-expanded":o,onClick:()=>o?g():x(),children:l.jsx(rd,{size:16})})]}),l.jsx("div",{className:"be-block-row-content",children:l.jsx(zo,{id:t})}),o&&y&&Ve.createPortal(l.jsxs("div",{ref:c,role:"menu","aria-label":"Block options",className:"be-block-gutter-menu",style:{position:"fixed",top:y.top,left:y.left},children:[l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:w,children:[l.jsx(jo,{size:15})," Duplicate"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:v,children:[l.jsx(hr,{size:15})," Move up"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:j,children:[l.jsx(mr,{size:15})," Move down"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:T,children:[C?l.jsx(Mo,{size:15}):l.jsx(Lo,{size:15}),C?"Show in preview":"Hide in preview"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:B,children:[M?l.jsx(Xa,{size:15}):l.jsx(qa,{size:15}),M?"Switch to left-to-right":"Switch to right-to-left"]}),Ho(r.type)&&l.jsx(El,{onSelect:L,onClose:()=>{},containerRef:f}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item be-block-gutter-menu-item-danger",onClick:I,children:[l.jsx(On,{size:15})," Delete"]})]}),document.body)]}):null}function ht({parentId:t,isTopLevel:e=!1}){const n=$o(t),r=G(),[o]=Co(),s=o?n.filter(a=>{var i,u;return!((u=(i=r.getBlock(a))==null?void 0:i.props)!=null&&u.hidden)}):n;return e&&!o?s.map(a=>l.jsx(Bl,{id:a},a)):s.map(a=>l.jsx(zo,{id:a},a))}const hp=97,mp=[[1e3,"m"],[900,"cm"],[500,"d"],[400,"cd"],[100,"c"],[90,"xc"],[50,"l"],[40,"xl"],[10,"x"],[9,"ix"],[5,"v"],[4,"iv"],[1,"i"]];function bp(t){let e="";for(;t>0;)t-=1,e=String.fromCharCode(hp+t%26)+e,t=Math.floor(t/26);return e}function gp(t){let e="",n=t;for(const[r,o]of mp)for(;n>=r;)e+=o,n-=r;return e}function xp(t){var e,n;return(t==null?void 0:t.type)==="listItem"&&((e=t.props)==null?void 0:e.checked)===void 0&&((n=t.props)==null?void 0:n.collapsed)===void 0}function Xs(t,e){let n=0,r=e;for(;r;){const o=t.getBlock(r.parentId);if(!o||o.type!=="listItem")break;n+=1,r=o}return n}function yp(t,e,n){const r=n.indexOf(e.id);let o=1;for(let s=r-1;s>=0;s-=1){const a=t.getBlock(n[s]);if(!xp(a)||!a.props.ordered)break;o+=1}return o}function kp(t,e){const n=(t%3+3)%3;return n===0?`${e}.`:n===1?`${bp(e)}.`:`${gp(e)}.`}const vp=["•","◦","▪"];function wp(t){const e=(t%3+3)%3;return vp[e]}function vn({ordered:t=!1,checked:e,collapsed:n}={}){return function(o,s){const a=E(),i=s!=null&&s.length?s:[{id:E(),type:"text",value:"",marks:{}}],u={ordered:t,titleRunIds:i.map(h=>h.id)};e!==void 0&&(u.checked=e);let c=[],f=[],d=i;if(n!==void 0){u.collapsed=n;const{block:h,runs:m}=te("paragraph")(a);c=[h.id],f=[h],d=[...i,...m]}return{block:{id:a,type:"listItem",parentId:o,contentIds:c,props:u},runs:d,subtreeBlocks:f}}}function Ip(t,e){const n=t.getBlock(e),r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=o>0?r.contentIds[o-1]:null,a=s?t.getBlock(s):null;if(!a||a.type!=="listItem"){_e(t,e,"down");return}t.applyOperation(ct(e,s,a.contentIds.length)),Re(t,e)}function no(t,e){const n=t.getBlock(e),r=t.getBlock(n.parentId);if(!r||r.type!=="listItem")return;const o=r.parentId,a=t.getBlock(o).contentIds.indexOf(r.id);t.applyOperation(ct(e,o,a+1)),Re(t,e)}function mn(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function _l(t,e){var n;return e.length===0||e.length===1&&(((n=t.getRun(e[0]))==null?void 0:n.value)??"")===""}function Cp(t,e){const n=e.contentIds??[];if(n.length===0)return!0;if(n.length>1)return!1;const r=t.getBlock(n[0]);return!!r&&r.type==="paragraph"&&Le(t,r.contentIds)}function Sp(t,e){const n=t.getBlock(e);if(!n)return null;const r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=n.props.titleRunIds??[],i=_l(t,s)&&Cp(t,n);if(o>0){const f=r.contentIds[o-1],d=t.getBlock(f);if(i)return mn(t,[ee(e)]),{focusBlockId:f,needsRefocus:!0};if(Mn(t,d))return mn(t,[ee(f)]),{focusBlockId:e,needsRefocus:!1};if((d==null?void 0:d.type)==="listItem"&&n.contentIds.length===0){const h=[...d.props.titleRunIds??[],...s];return mn(t,[J(f,{titleRunIds:h}),J(e,{titleRunIds:[]}),ee(e)]),{focusBlockId:f,needsRefocus:!0}}return null}if(r.type==="listItem")return no(t,e),{focusBlockId:e,needsRefocus:!0};if(!i)return null;if(r.contentIds.length>1)return mn(t,[ee(e)]),{focusBlockId:t.getBlock(r.id).contentIds[0],needsRefocus:!0};const{block:u,runs:c}=te("paragraph")(r.id);return mn(t,[me(u,r.id,o,{blocks:[u],runs:c}),ee(e)]),{focusBlockId:u.id,needsRefocus:!0}}function Rp(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Tp(t,e){const r=t.getBlock(e).parentId,s=t.getBlock(r).contentIds.indexOf(e),{block:a,runs:i}=te("paragraph")(r);return Rp(t,[me(a,r,s,{blocks:[a],runs:i}),J(e,{titleRunIds:[]}),ee(e)]),Re(t,a.id),a.id}function jp(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Ep({id:t}){var T,M;const e=G(),n=be(t),{setSelectedBlockId:r}=ut(),o=$o(n==null?void 0:n.parentId),s=p.useCallback(()=>{var Q,D,F,re,H;const B=((Q=n==null?void 0:n.props)==null?void 0:Q.titleRunIds)??[],L=e.getBlock(n==null?void 0:n.parentId),S=_l(e,B);if(S&&(L==null?void 0:L.type)==="listItem"){no(e,t);return}const N=(((D=n==null?void 0:n.contentIds)==null?void 0:D.length)??0)>0;if(S&&(L==null?void 0:L.type)!=="listItem"&&!N){Tp(e,t);return}const $=((F=n==null?void 0:n.props)==null?void 0:F.checked)!==void 0,V=((re=n==null?void 0:n.props)==null?void 0:re.collapsed)!==void 0,K=vn({ordered:(H=n==null?void 0:n.props)==null?void 0:H.ordered,checked:$?!1:void 0,collapsed:V?!1:void 0});N&&!V?kl(e,t,B,K):cn(e,t,B,K)},[e,t,n]),a=p.useCallback(()=>Ip(e,t),[e,t]),i=p.useCallback(()=>no(e,t),[e,t]),u=p.useCallback(()=>{const B=Sp(e,t);!B||!B.needsRefocus||dn(e,B.focusBlockId,t,r)},[e,t,r]),c=p.useCallback(()=>_e(e,t,"up"),[e,t]),f=p.useCallback(()=>_e(e,t,"down"),[e,t]),d=p.useCallback(()=>{var B;e.applyOperation(J(t,{checked:!((B=n==null?void 0:n.props)!=null&&B.checked)}))},[e,t,(T=n==null?void 0:n.props)==null?void 0:T.checked]),h=p.useCallback(()=>{var L,S;if(!((((L=n==null?void 0:n.contentIds)==null?void 0:L.length)??0)>0)){const{block:N,runs:$}=te("paragraph")(t);jp(e,[me(N,t,0,{blocks:[N],runs:$}),J(t,{collapsed:!1})]),ye(N.contentIds[0]);return}e.applyOperation(J(t,{collapsed:!((S=n==null?void 0:n.props)!=null&&S.collapsed)}))},[e,t,n==null?void 0:n.contentIds,(M=n==null?void 0:n.props)==null?void 0:M.collapsed]),m=Ie("be-list-item",n);if(!n)return null;const{ordered:g,checked:x,collapsed:y,titleRunIds:k=[]}=n.props,w=x!==void 0,v=!w&&y!==void 0,j=n.contentIds.length>0,I=k.map(B=>e.getRun(B)).filter(B=>(B==null?void 0:B.type)==="text").map(B=>B.value).join("").trim(),C=it(e,n);return l.jsxs("div",{className:m,"data-block-id":t,dir:C,children:[l.jsxs("div",{className:"be-list-item-row",children:[w?l.jsx("input",{type:"checkbox",className:"be-list-checkbox",checked:!!x,onChange:d,"aria-label":I||"To-do item"}):v?l.jsx("button",{type:"button",className:"be-list-toggle-marker",onClick:h,"aria-expanded":!y,"aria-label":j?y?"Expand toggle":"Collapse toggle":"Add content to toggle",children:y?l.jsx(jt,{}):l.jsx(fr,{})}):l.jsx("span",{className:"be-list-marker","aria-hidden":"true",children:g?kp(Xs(e,n),yp(e,n,o)):wp(Xs(e,n))}),l.jsx("div",{className:"be-list-item-title","data-empty":Le(e,k)?"":void 0,"data-placeholder":w?"To-do":v?"Toggle":"List item",style:x?{textDecoration:"line-through",opacity:.6}:void 0,children:l.jsx(pt,{blockId:t,runIds:k,dir:C,onEnter:s,onTab:a,onShiftTab:i,onBackspaceAtStart:u,onArrowUp:c,onArrowDown:f})})]}),(!v||!y)&&l.jsx("div",{className:"be-list-item-children",children:l.jsx(ht,{parentId:t})})]})}function Bp(t,e){const{titleRunIds:n=[],ordered:r}=t.props,o=n.map(i=>ft(e.store.getRun(i),e)).join(""),s=t.contentIds.map(i=>e.registry.get(e.store.getBlock(i).type).toHTML(e.store.getBlock(i),e)).join(""),a=s?`<${r?"ol":"ul"}>${s}</${r?"ol":"ul"}>`:"";return`<li>${o}${a}</li>`}function _p(t,e){const{titleRunIds:n=[]}=t.props;return n.map(r=>It(e.store.getRun(r),e)).join("")}function Ol(t,e){const n=[],r=[];for(const d of t.childNodes)d.nodeType===1&&(d.tagName==="UL"||d.tagName==="OL")?r.push(d):n.push(d);const o=t.ownerDocument.createElement("span");for(const d of n)o.appendChild(d.cloneNode(!0));const s=Ye(o,e),a=E(),i=[...s],u=[],c=[];for(const d of r){const h=d.tagName==="OL";for(const m of d.children){if(m.tagName!=="LI")continue;const g=Ol(m,e);g.block.parentId=a,g.block.props.ordered=h,u.push(g.block,...g.childBlocks),i.push(...g.runs),c.push(g.block.id)}}return{block:{id:a,type:"listItem",parentId:null,contentIds:c,props:{ordered:!1,titleRunIds:s.map(d=>d.id)}},runs:i,childBlocks:u}}function Op(t,e){if(t.tagName!=="LI")return null;const{block:n,runs:r,childBlocks:o}=Ol(t,e);return{block:n,runs:r,subtreeBlocks:o}}const Ml={component:Ep,isLeaf:!1,defaultProps:{ordered:!1,titleRunIds:[]},toHTML:Bp,toPlainText:_p,fromHTML:Op,slashCommands:[{label:"Bulleted list",icon:rl,keywords:["list","bullet","ul"],run:(t,e)=>Be(t,e,vn({ordered:!1}))},{label:"Numbered list",icon:ol,keywords:["list","number","ordered","ol"],run:(t,e)=>Be(t,e,vn({ordered:!0}))},{label:"To-do list",icon:Oo,keywords:["todo","checkbox","task","checklist"],run:(t,e)=>Be(t,e,vn({ordered:!1,checked:!1}))},{label:"Toggle list",icon:jt,keywords:["toggle","collapse","expand","dropdown","accordion"],run:(t,e)=>Be(t,e,vn({ordered:!1,collapsed:!1}))}]},Ll=["text","date","checkbox","select"],wr="text",Ir=160,or=80;function Mp(t){return`Column ${t+1}`}function Yo(t){return Array.from({length:t},(e,n)=>({id:E(),label:Mp(n),type:wr,width:Ir}))}function $e(t,e){var r;const n=(r=t.props)==null?void 0:r.columns;return!Array.isArray(n)||n.length!==e?Yo(e):n.map(o=>{const s=o.type??wr,a=o.width??Ir;return s===o.type&&a===o.width?o:{...o,type:s,width:a}})}function Nl(t){switch(t){case"date":return{id:E(),type:"date",value:"",marks:{},data:{isoDate:""}};case"checkbox":return{id:E(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:""}};case"select":return{id:E(),type:"tableSelect",value:"",marks:{},data:{selectedValue:"",selectedLabel:""}};default:return{id:E(),type:"text",value:"",marks:{}}}}function Cr(t,e){const n=Nl(e==null?void 0:e.type);return{block:{id:E(),type:"tableCell",parentId:t,contentIds:[n.id],props:{}},run:n}}function Al(t,e,n){if(t.type===e)return t;let r;if(t.type==="text")r=t.value??"";else{const o=n==null?void 0:n.get(t.type);r=o!=null&&o.toPlainText?o.toPlainText(t):""}if(e==="date"){const o=r?new Date(r):null,s=o&&!Number.isNaN(o.getTime())?o.toISOString().slice(0,10):"";return{id:E(),type:"date",value:"",marks:{},data:{isoDate:s}}}return e==="checkbox"?{id:E(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:r}}:{id:E(),type:"text",value:r,marks:{}}}function Bt(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Dl(t,e){const r=t.getBlock(e.parentId).contentIds.indexOf(e.id);Bt(t,[ee(e.id)]);const o=un(t);if(o)return Re(t,o),null;const s=t.getBlock(e.parentId),a=s.contentIds[r]??s.contentIds[r-1];return a&&Re(t,a),null}function Ko(t,e){const n=t.getBlock(e),r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=$e(r,n.contentIds.length),a=E(),i=[],u=[],c=[];for(const d of s){const h=Cr(a,d);i.push(h.block),u.push(h.run),c.push(h.block.id)}const f={id:a,type:"tableRow",parentId:r.id,contentIds:c,props:{}};return t.applyOperation(me(f,r.id,o+1,{blocks:[f,...i],runs:u})),Re(t,a),a}function Pl(t,e){const n=t.getBlock(e),r=t.getBlock(n.parentId);if(r.contentIds.length<=1)return Dl(t,r);const o=r.contentIds.indexOf(e);Bt(t,[ee(e)]);const s=t.getBlock(r.id),a=Math.min(o,s.contentIds.length-1),i=s.contentIds[a];return i&&Re(t,i),i??null}function sr(t,e,n){const r=t.getBlock(e),o=$e(r,r.contentIds[0]?t.getBlock(r.contentIds[0]).contentIds.length:0),s={id:E(),label:"New Column",type:wr,width:Ir},a=[];let i=null;for(const c of r.contentIds){const f=Cr(c,s);i===null&&(i=f.block.id),a.push(me(f.block,c,n+1,{blocks:[f.block],runs:[f.run]}))}const u=[...o];return u.splice(n+1,0,s),a.push(J(e,{columns:u})),Bt(t,a),i&&Re(t,i),i}function $l(t,e,n){const r=t.getBlock(e),o=t.getBlock(r.contentIds[0]);if(!o||o.contentIds.length<=1)return Dl(t,r);const s=$e(r,o.contentIds.length),a=r.contentIds.map(d=>{const h=t.getBlock(d);return ee(h.contentIds[n])}),i=s.filter((d,h)=>h!==n);a.push(J(e,{columns:i})),Bt(t,a);const u=t.getBlock(r.contentIds[0]),c=Math.min(n,u.contentIds.length-1),f=u.contentIds[c];return f&&Re(t,f),f??null}function zl(t,e,n,r){const o=t.getBlock(e),s=t.getBlock(o.contentIds[0]),a=$e(o,s?s.contentIds.length:0);if(!a[n])return;const i=[...a];i[n]={...a[n],width:Math.max(or,Math.round(r))},t.applyOperation(J(e,{columns:i}))}function Hl(t,e,n,r){const o=t.getBlock(e),s=t.getBlock(o.contentIds[0]),i=[...$e(o,s?s.contentIds.length:0)];i[n]&&(i[n]={...i[n],label:r},t.applyOperation(J(e,{columns:i})))}function Wo(t,e,n){return e.contentIds.map(r=>{const s=t.getBlock(r).contentIds[n],a=t.getBlock(s);return{cellId:s,run:t.getRun(a.contentIds[0])}})}function qs(t,e){if(!t)return"";if(t.type==="text")return t.value??"";const n=e==null?void 0:e.get(t.type);return n!=null&&n.toPlainText?n.toPlainText(t):""}function Lp(t,e,n,r){const o=Wo(t,e,n),s=[],a=new Map;for(const{run:u}of o){const c=qs(u,r).trim();if(!c||a.has(c))continue;const f={value:E(),label:c};a.set(c,f),s.push(f)}const i=o.map(({cellId:u,run:c})=>{const f=qs(c,r).trim(),d=a.get(f);return{cellId:u,run:{id:E(),type:"tableSelect",value:"",marks:{},data:{selectedValue:(d==null?void 0:d.value)??"",selectedLabel:(d==null?void 0:d.label)??""}}}});return{options:s,newRuns:i}}function Fl(t,e,n,r,o){const s=t.getBlock(e),a=t.getBlock(s.contentIds[0]),i=$e(s,a?a.contentIds.length:0),u=i[n];if(!u||u.type===r)return;const c=[...i];if(r==="select"){const{options:d,newRuns:h}=Lp(t,s,n,o);c[n]={...u,type:r,options:d};const m=[J(e,{columns:c})];for(const{cellId:g,run:x}of h)m.push(Me(g,[x]));Bt(t,m);return}c[n]={...u,type:r};const f=[J(e,{columns:c})];for(const{cellId:d,run:h}of Wo(t,s,n)){if(!h)continue;const m=Al(h,r,o);f.push(Me(d,[m]))}Bt(t,f)}function Zn(t,e,n,r){var d,h;const o=t.getBlock(e),s=t.getBlock(o.contentIds[0]),a=$e(o,s?s.contentIds.length:0),i=a[n];if(!i)return;const u=[...a];u[n]={...i,options:r};const c=[J(e,{columns:u})],f=new Map(r.map(m=>[m.value,m]));for(const{run:m}of Wo(t,o,n)){if(!m||m.type!=="tableSelect")continue;const g=((d=m.data)==null?void 0:d.selectedValue)??"",x=f.get(g),y=x?g:"",k=x?x.label:"";(y!==g||k!==(((h=m.data)==null?void 0:h.selectedLabel)??""))&&c.push(ue(m.id,{data:{selectedValue:y,selectedLabel:k}}))}Bt(t,c)}function Ul(t,e,n){const[r,o]=p.useState(null);return p.useLayoutEffect(()=>{o(n??null)},[n]),p.useLayoutEffect(()=>{if(!e||!t.current||r==null)return;const s=t.current.getBoundingClientRect(),a=gr(r,s.width);a!==r&&o(a)},[e,t,r]),r}function Vl(t,e,n){const[r,o]=p.useState(null);return p.useLayoutEffect(()=>{o(n??null)},[n]),p.useLayoutEffect(()=>{if(!e||!t.current||r==null)return;const s=t.current.getBoundingClientRect(),a=s.width/2,u=gr(r-a,s.width)+a;u!==r&&o(u)},[e,t,r]),r}function Np(t,e,n){const[r,o]=p.useState(null);return p.useLayoutEffect(()=>{o(n??null)},[n]),p.useLayoutEffect(()=>{if(!e||!t.current||r==null)return;const s=t.current.getBoundingClientRect(),i=gr(r-s.width,s.width)+s.width;i!==r&&o(i)},[e,t,r]),r}function Gs(){if(typeof window>"u"||!window.visualViewport)return 0;const t=window.visualViewport,e=window.innerHeight-(t.height+t.offsetTop);return e>0?Math.round(e):0}function Sr(){const[t,e]=p.useState(Gs);return p.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const n=window.visualViewport,r=()=>e(Gs());return r(),n.addEventListener("resize",r),n.addEventListener("scroll",r),()=>{n.removeEventListener("resize",r),n.removeEventListener("scroll",r)}},[]),t}const Ap=280;function Dp(t,e){return e?t.label.toLowerCase().includes(e.toLowerCase()):!0}function Mt({value:t,options:e,onChange:n,placeholder:r="Select…",ariaLabel:o,className:s="",variant:a="default",selectedLabel:i,selectedColor:u,onManageOptions:c,manageOptionsLabel:f="Manage options…",mention:d=!1}){var ke,he;const[h,m]=p.useState(!1),[g,x]=p.useState(""),[y,k]=p.useState(0),[w,v]=p.useState(null),j=Sr(),[I,C]=p.useState([]),[T,M]=p.useState(!1),[B,L]=p.useState(!1),S=p.useRef(null),N=p.useRef(null),$=p.useRef(null),V=p.useRef(null),K=p.useRef(null),Q=p.useMemo(()=>[S,$],[]),D=a==="tag",F=typeof e=="function",re=F?void 0:e.find(U=>U.value===t),H=t?re??(i?{label:i,color:u}:void 0):void 0,ne=p.useMemo(()=>F?I:e.filter(U=>Dp(U,g)),[F,I,e,g]);p.useEffect(()=>{if(!F||!h)return;let U=!1;M(!0),L(!1);const ae=setTimeout(()=>{Promise.resolve(e(g)).then(Ke=>{U||(C(Ke??[]),M(!1))}).catch(()=>{U||(C([]),M(!1),L(!0))})},250);return()=>{U=!0,clearTimeout(ae)}},[F,h,e,g]);const se=p.useCallback(()=>m(!1),[]);Ue(Q,h,se);const oe=Ul($,h,w==null?void 0:w.left),ge=p.useCallback(()=>{var U;v(((U=N.current)==null?void 0:U.getBoundingClientRect())??null),x(""),k(0),m(!0)},[]);p.useEffect(()=>{var U;h&&((U=V.current)==null||U.focus())},[h]),p.useEffect(()=>{var U,ae;(ae=(U=K.current)==null?void 0:U.scrollIntoView)==null||ae.call(U,{block:"nearest"})},[y]);const Te=p.useCallback(U=>{var ae;n(U.value,U),se(),(ae=N.current)==null||ae.focus()},[n,se]),ce=p.useCallback(U=>{var ae;U.key==="ArrowDown"?(U.preventDefault(),k(Ke=>Math.min(Ke+1,Math.max(ne.length-1,0)))):U.key==="ArrowUp"?(U.preventDefault(),k(Ke=>Math.max(Ke-1,0))):U.key==="Enter"?(U.preventDefault(),ne[y]&&Te(ne[y])):U.key==="Escape"&&(U.preventDefault(),se(),(ae=N.current)==null||ae.focus())},[ne,y,Te,se]);return l.jsxs("span",{className:`be-select ${s}`.trim(),ref:S,children:[l.jsx("button",{type:"button",ref:N,className:`be-select-trigger${D?" be-select-trigger-tag":""}${d?" be-select-trigger-mention":""}`,"aria-haspopup":"listbox","aria-expanded":h,"aria-label":o,onClick:()=>h?se():ge(),children:D?H?l.jsx("span",{className:`be-select-tag${d?" be-select-tag-mention":""}`,style:d?void 0:{background:(ke=H.color)==null?void 0:ke.bg,color:(he=H.color)==null?void 0:he.text},children:d?`@${H.label}`:H.label}):l.jsx("span",{className:"be-select-value be-select-value-placeholder",children:r}):l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"be-select-value",children:H?H.label:r}),l.jsx(fr,{size:14,className:"be-select-chevron"})]})}),h&&w&&oe!=null&&Ve.createPortal(l.jsxs("div",{ref:$,className:"be-select-popover",style:{position:"fixed",left:oe,minWidth:w.width,...w.bottom+Ap>window.innerHeight-j?{bottom:window.innerHeight-w.top+4}:{top:w.bottom+4}},children:[l.jsx("input",{ref:V,type:"text",className:"be-select-search",value:g,onChange:U=>{x(U.target.value),k(0)},onKeyDown:ce,placeholder:"Search…","aria-label":o?`Search ${o}`:"Search options"}),l.jsxs("div",{className:"be-select-options",role:"listbox",children:[F&&T&&l.jsx("div",{className:"be-select-empty",children:"Loading…"}),F&&!T&&B&&l.jsx("div",{className:"be-select-empty be-select-error",children:"Couldn't load options"}),!T&&!B&&ne.length===0&&l.jsx("div",{className:"be-select-empty",children:"No results"}),!T&&!B&&ne.map((U,ae)=>{var Ke,An;return l.jsx("div",{ref:ae===y?K:void 0,role:"option","aria-selected":U.value===t,className:`be-select-option${ae===y?" be-select-option-active":""}${U.value===t?" be-select-option-selected":""}`,onMouseDown:jr=>{jr.preventDefault(),Te(U)},onMouseEnter:()=>k(ae),children:D?l.jsx("span",{className:"be-select-tag",style:{background:(Ke=U.color)==null?void 0:Ke.bg,color:(An=U.color)==null?void 0:An.text},children:U.label}):U.label},U.value)})]}),c&&l.jsx("button",{type:"button",className:"be-select-manage-options",onMouseDown:U=>{U.preventDefault(),se(),c()},children:f})]}),document.body)]})}const Vn=[{bg:"#e9e9e7",text:"#32302c"},{bg:"#eee0da",text:"#64473a"},{bg:"#fadec9",text:"#8a4b23"},{bg:"#fdecc8",text:"#8a6116"},{bg:"#dbeddb",text:"#256029"},{bg:"#d3e5ef",text:"#1a5f8a"},{bg:"#e8deee",text:"#5b3a8a"},{bg:"#f5e0e9",text:"#8a3a5f"},{bg:"#ffe2dd",text:"#a13a2f"}];function Tn(t){return Vn[(t%Vn.length+Vn.length)%Vn.length]}const Pp={text:"Text",date:"Date",checkbox:"Checkbox",select:"Select"},$p=Ll.map(t=>({value:t,label:Pp[t]})),zp=800;function Hp({tableId:t,colIndex:e,options:n}){const r=G(),[o,s]=p.useState(""),a=p.useCallback((c,f)=>{Zn(r,t,e,n.map(d=>d.value===c?{...d,label:f}:d))},[r,t,e,n]),i=p.useCallback(c=>Zn(r,t,e,n.filter(f=>f.value!==c)),[r,t,e,n]),u=p.useCallback(()=>{const c=o.trim();s(""),c&&Zn(r,t,e,[...n,{value:E(),label:c,color:Tn(n.length)}])},[r,t,e,n,o]);return l.jsxs("div",{className:"be-table-header-menu-options",children:[l.jsx("div",{className:"be-table-header-menu-options-label",children:"Options"}),n.map((c,f)=>l.jsxs("div",{className:"be-table-header-menu-option-row",children:[l.jsx("span",{className:"be-table-header-menu-option-swatch",style:{background:(c.color??Tn(f)).bg},"aria-hidden":"true"}),l.jsx("input",{className:"be-table-header-menu-option-input",value:c.label,onChange:d=>a(c.value,d.target.value),"aria-label":`Rename option ${c.label}`}),l.jsx("button",{type:"button",className:"be-table-header-menu-option-remove",onClick:()=>i(c.value),"aria-label":`Remove option ${c.label}`,children:l.jsx(Ot,{size:14})})]},c.value)),l.jsxs("div",{className:"be-table-header-menu-option-row",children:[l.jsx("input",{className:"be-table-header-menu-option-input",value:o,onChange:c=>s(c.target.value),placeholder:"New option…",onKeyDown:c=>{c.key==="Enter"&&(c.preventDefault(),u())}}),l.jsx("button",{type:"button",className:"be-table-header-menu-option-add",onClick:u,"aria-label":"Add option",children:"+"})]})]})}function Fp({tableId:t,column:e,colIndex:n,colCount:r}){const o=G(),s=tt(),[a,i]=p.useState(!1),[u,c]=p.useState(null),[f,d]=p.useState(null),h=p.useRef(null),m=p.useRef(null),g=p.useRef(null),x=p.useMemo(()=>[h,m],[]),y=p.useCallback(()=>i(!1),[]);Ue(x,a,y),kr(m,a,y,h);const k=Np(m,a,u==null?void 0:u.right),w=p.useCallback(()=>{var B;c(((B=g.current)==null?void 0:B.getBoundingClientRect())??null),i(!0)},[]),v=p.useCallback(B=>Hl(o,t,n,B.target.value),[o,t,n]),j=p.useCallback(()=>{sr(o,t,n-1),y()},[o,t,n,y]),I=p.useCallback(()=>{sr(o,t,n),y()},[o,t,n,y]),C=p.useCallback(()=>{$l(o,t,n),y()},[o,t,n,y]),T=p.useCallback(B=>Fl(o,t,n,B,s),[o,t,n,s]),M=p.useCallback(B=>{var D;B.preventDefault();const L=(D=g.current)==null?void 0:D.closest("table"),S=L==null?void 0:L.querySelector(`col[data-col-index="${n}"]`);if(!S)return;const N=g.current.getBoundingClientRect().width,$=B.clientX,V=F=>Math.max(or,Math.round(N+(F.clientX-$))),K=F=>{const re=V(F);S.style.width=`${re}px`,d(re)},Q=F=>{document.removeEventListener("mousemove",K),document.removeEventListener("mouseup",Q),zl(o,t,n,V(F)),d(null)};document.addEventListener("mousemove",K),document.addEventListener("mouseup",Q)},[o,t,n]);return l.jsxs("th",{ref:g,scope:"col",className:"be-table-header-cell",contentEditable:!1,children:[l.jsx("input",{className:"be-table-header-label",value:e.label,onChange:v,"aria-label":`Column ${n+1} name`}),l.jsx("button",{ref:h,type:"button",className:"be-table-header-menu-trigger","aria-label":`Column ${n+1} options`,"aria-haspopup":"menu","aria-expanded":a,onClick:()=>a?y():w(),children:"⋮"}),l.jsx("div",{className:"be-table-col-resize-handle",onMouseDown:M,role:"slider","aria-label":`Resize column ${n+1}`,"aria-valuemin":or,"aria-valuemax":zp,"aria-valuenow":f??e.width}),a&&u&&k!=null&&Ve.createPortal(l.jsxs("div",{ref:m,role:"menu","aria-label":`Column ${n+1} options`,className:"be-table-header-menu",style:{position:"fixed",top:u.bottom+4,left:k,transform:"translateX(-100%)"},children:[l.jsxs("div",{className:"be-table-header-menu-type",children:[l.jsx("span",{id:`be-table-col-type-${e.id}`,children:"Type"}),l.jsx(Mt,{value:e.type,options:$p,onChange:T,ariaLabel:"Column type",className:""})]}),e.type==="select"&&l.jsx(Hp,{tableId:t,colIndex:n,options:e.options??[]}),l.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item",onClick:j,children:"Insert column left"}),l.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item",onClick:I,children:"Insert column right"}),l.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item be-table-header-menu-item-danger",onClick:C,disabled:r<=1,children:"Delete column"})]}),document.body)]})}function Yl({tableId:t,columns:e}){return l.jsx("thead",{children:l.jsxs("tr",{className:"be-table-header-row",children:[e.map((n,r)=>l.jsx(Fp,{tableId:t,column:n,colIndex:r,colCount:e.length},n.id)),l.jsx("th",{className:"be-table-header-spacer","aria-hidden":"true"})]})})}function Up({id:t}){var i;const e=G(),n=be(t),r=p.useCallback(()=>{var c;const u=(c=n==null?void 0:n.contentIds)==null?void 0:c[n.contentIds.length-1];u&&Ko(e,u)},[e,n]),o=Ie("be-table-wrapper",n);if(!n)return null;const s=e.getBlock(n.contentIds[0]),a=$e(n,((i=s==null?void 0:s.contentIds)==null?void 0:i.length)??0);return l.jsx("div",{className:"be-table-scroll",children:l.jsxs("div",{className:o,"data-block-id":t,children:[l.jsxs("table",{className:"be-table",children:[l.jsxs("colgroup",{children:[a.map((u,c)=>l.jsx("col",{"data-col-index":c,style:{width:u.width}},u.id)),l.jsx("col",{className:"be-table-header-spacer-col"})]}),l.jsx(Yl,{tableId:t,columns:a}),l.jsx("tbody",{children:l.jsx(ht,{parentId:t})})]}),l.jsxs("button",{type:"button",className:"be-table-add-row",contentEditable:!1,onClick:r,children:[l.jsx(To,{size:14})," Add row"]})]})})}function Vp({id:t}){const e=G(),n=be(t),r=Ie("be-table-row",n),o=p.useCallback(()=>Pl(e,t),[e,t]);return l.jsxs("tr",{className:r,"data-block-id":t,children:[l.jsx(ht,{parentId:t}),l.jsx("td",{className:"be-table-row-actions",contentEditable:!1,children:l.jsx("button",{type:"button",className:"be-table-delete-row",onClick:o,"aria-label":"Delete row",title:"Delete row",children:l.jsx(Ot,{size:14})})})]})}function Kl(t,e){const n=t.getBlock(e),r=t.getBlock(n.parentId),o=t.getBlock(r.parentId);return{table:o,row:r,rowIndex:o.contentIds.indexOf(r.id),colIndex:r.contentIds.indexOf(e)}}function Yp(t,e,n){const{table:r,row:o,rowIndex:s,colIndex:a}=Kl(t,e);if(n==="left"||n==="right"){const f=n==="right"?1:-1,d=a+f;if(d>=0&&d<o.contentIds.length)return o.contentIds[d];const h=s+f;if(h<0||h>=r.contentIds.length)return null;const m=t.getBlock(r.contentIds[h]),g=n==="right"?0:m.contentIds.length-1;return m.contentIds[g]}const u=s+(n==="down"?1:-1);if(u<0||u>=r.contentIds.length)return null;const c=t.getBlock(r.contentIds[u]);return c.contentIds[a]??c.contentIds[c.contentIds.length-1]??null}function Kp(t,e){const n=xl(t,e,"down");if(n){ye(n);return}nt(t,e,te("paragraph"))}function bn(t,e,n){var o;const r=Yp(t,e,n);if(r){const s=t.getBlock(r),a=(o=s==null?void 0:s.contentIds)==null?void 0:o[0];a&&ye(a);return}if(n==="right"){const{table:s}=Kl(t,e);Kp(t,s.id)}}function Wp({id:t}){const e=G(),n=be(t),r=p.useCallback(()=>bn(e,t,"right"),[e,t]),o=p.useCallback(()=>bn(e,t,"left"),[e,t]),s=p.useCallback(()=>bn(e,t,"up"),[e,t]),a=p.useCallback(()=>bn(e,t,"down"),[e,t]),i=p.useCallback(()=>bn(e,t,"down"),[e,t]),u=Ie("be-table-cell",n);if(!n)return null;const c=it(e,n);return l.jsx("td",{className:u,"data-block-id":t,dir:c,children:l.jsx(pt,{blockId:t,runIds:n.contentIds,dir:c,onTab:r,onShiftTab:o,onArrowUp:s,onArrowDown:a,onEnter:i})})}function Xp(t,e){const n=E(),r=[],o=[],s=[];for(const a of e){const i=Cr(n,a);r.push(i.block),o.push(i.run),s.push(i.block.id)}return{block:{id:n,type:"tableRow",parentId:t,contentIds:s,props:{}},blocks:r,runs:o}}function qp({rows:t=2,cols:e=2}={}){return function(r){const o=E(),s=Yo(e),a=[],i=[],u=[];for(let f=0;f<t;f+=1){const d=Xp(o,s);a.push(d.block,...d.blocks),i.push(...d.runs),u.push(d.block.id)}return{block:{id:o,type:"table",parentId:r,contentIds:u,props:{columns:s}},runs:i,subtreeBlocks:a}}}function Gp(t,e){return`<td>${t.contentIds.map(r=>e.store.getRun(r)).map(r=>ft(r,e)).join("")}</td>`}function Jp(t,e){return t.contentIds.map(n=>It(e.store.getRun(n),e)).join("")}function Zp(t,e){if(t.tagName!=="TD"&&t.tagName!=="TH")return null;const n=Ye(t,e);return{block:{id:E(),type:"tableCell",parentId:null,contentIds:n.map(o=>o.id),props:{}},runs:n}}function Qp(t,e){return`<tr>${t.contentIds.map(r=>{const o=e.store.getBlock(r);return e.registry.get(o.type).toHTML(o,e)}).join("")}</tr>`}function ef(t,e){return t.contentIds.map(n=>{const r=e.store.getBlock(n);return e.registry.get(r.type).toPlainText(r,e)}).join(" ")}function tf(t,e){if(t.tagName!=="TR")return null;const n=[...t.children].filter(u=>u.tagName==="TD"||u.tagName==="TH"),r=E(),o=[],s=[],a=[];for(const u of n){const c=e.registry.get("tableCell").fromHTML(u,e);c&&(c.block.parentId=r,o.push(c.block),s.push(...c.runs),a.push(c.block.id))}return{block:{id:r,type:"tableRow",parentId:null,contentIds:a,props:{}},runs:s,subtreeBlocks:o}}function nf(t,e){var a;const n=t.contentIds[0]&&e.store.getBlock(t.contentIds[0]),r=$e(t,((a=n==null?void 0:n.contentIds)==null?void 0:a.length)??0),o=r.length?`<thead><tr>${r.map(i=>`<th>${Et(i.label??"")}</th>`).join("")}</tr></thead>`:"",s=t.contentIds.map(i=>{const u=e.store.getBlock(i);return e.registry.get(u.type).toHTML(u,e)}).join("");return`<table>${o}<tbody>${s}</tbody></table>`}function rf(t,e){return t.contentIds.map(n=>{const r=e.store.getBlock(n);return e.registry.get(r.type).toPlainText(r,e)}).join(`
2921
- `)}function of(t,e){if(t.tagName!=="TABLE")return null;const n=t.querySelector("thead tr"),r=t.querySelector("tbody")?[...t.querySelectorAll("tbody tr")]:[...t.querySelectorAll("tr")].filter(f=>f!==n),o=E(),s=[],a=[],i=[];for(const f of r){const d=e.registry.get("tableRow").fromHTML(f,e);if(d){d.block.parentId=o;for(const h of d.subtreeBlocks)h.parentId=d.block.id;s.push(d.block,...d.subtreeBlocks),a.push(...d.runs),i.push(d.block.id)}}const u={};if(n){const f=[...n.children].filter(d=>d.tagName==="TH"||d.tagName==="TD");u.columns=f.map(d=>({id:E(),label:d.textContent??""}))}return{block:{id:o,type:"table",parentId:null,contentIds:i,props:u},runs:a,subtreeBlocks:s}}const Wl={component:Wp,isLeaf:!0,defaultProps:{},toHTML:Gp,toPlainText:Jp,fromHTML:Zp},Xl={component:Vp,isLeaf:!1,defaultProps:{},toHTML:Qp,toPlainText:ef,fromHTML:tf},ql={component:Up,isLeaf:!1,defaultProps:{},toHTML:nf,toPlainText:rf,fromHTML:of,slashCommand:{label:"Table",icon:md,keywords:["table","grid"],run:(t,e)=>Be(t,e,qp({rows:2,cols:2}))}};function sf({id:t}){const e=be(t),n=Ie("be-layout",e);return l.jsx("div",{className:n,"data-block-id":t,style:{display:"flex",gap:"1em"},children:l.jsx(ht,{parentId:t})})}function af({id:t}){const e=be(t),n=Ie("be-layout-column",e);return l.jsx("div",{className:n,"data-block-id":t,children:l.jsx(ht,{parentId:t})})}function lf({columns:t=2}={}){return function(n){const r=E(),o=[],s=[],a=[];for(let u=0;u<t;u+=1){const c=E(),{block:f,runs:d}=te("paragraph")(c),h={id:c,type:"layoutColumn",parentId:r,contentIds:[f.id],props:{}};o.push(h,f),s.push(...d),a.push(c)}return{block:{id:r,type:"layout",parentId:n,contentIds:a,props:{}},runs:s,subtreeBlocks:o}}}function Gl(t,e){return(n,r)=>`${t}${n.contentIds.map(o=>{const s=r.store.getBlock(o);return r.registry.get(s.type).toHTML(s,r)}).join("")}${e}`}function Jl(t,e){return t.contentIds.map(n=>{const r=e.store.getBlock(n);return e.registry.get(r.type).toPlainText(r,e)}).join(`
2922
- `)}const Zl={component:af,isLeaf:!1,defaultProps:{},toHTML:Gl("<div>","</div>"),toPlainText:Jl},Ql={component:sf,isLeaf:!1,defaultProps:{},toHTML:Gl('<div style="display:flex;gap:1em">',"</div>"),toPlainText:Jl,slashCommands:[2,3,4,5].map(t=>({label:`${t} columns`,icon:bd,keywords:["layout","columns","column",String(t)],run:(e,n)=>Be(e,n,lf({columns:t}))}))};function cf({id:t}){const e=be(t),n=Ie("be-divider",e);return l.jsx("hr",{className:n,"data-block-id":t,contentEditable:!1,tabIndex:-1})}function uf(){return function(e){return{block:{id:E(),type:"divider",parentId:e,contentIds:[],props:{}},runs:[]}}}function df(){return"<hr />"}function pf(){return"---"}function ff(t){return t.tagName!=="HR"?null:{block:{id:E(),type:"divider",parentId:null,contentIds:[],props:{}},runs:[]}}const ei={component:cf,isLeaf:!0,defaultProps:{},toHTML:df,toPlainText:pf,fromHTML:ff,slashCommand:{label:"Divider",icon:fd,keywords:["divider","hr","separator","line"],run:(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o})=>{const s=t.getRun(n),a=(s==null?void 0:s.value)??"";t.applyOperation(ue(n,{value:a.slice(0,r)+a.slice(o)}));const i=yr(t,e,uf());return nt(t,i,te("paragraph")),i}}},ti=[{value:"gray",label:"Gray"},{value:"blue",label:"Blue"},{value:"green",label:"Green"},{value:"yellow",label:"Yellow"},{value:"orange",label:"Orange"},{value:"red",label:"Red"},{value:"purple",label:"Purple"},{value:"pink",label:"Pink"}];function hf({id:t}){var k,w;const e=G(),n=be(t),[r,o]=p.useState(!1),[s,a]=p.useState(!1),i=p.useRef(null),u=p.useRef(null),c=p.useMemo(()=>[i,u],[]),f=p.useCallback(()=>a(!1),[]);Ue(c,s,f);const d=((k=n==null?void 0:n.props)==null?void 0:k.icon)??pn,h=((w=n==null?void 0:n.props)==null?void 0:w.color)??Rl,m=p.useCallback(v=>{const j=v.target.value.trim();j&&e.applyOperation(J(t,{icon:j})),o(!1)},[e,t]),g=p.useCallback(v=>{v.key==="Enter"&&v.currentTarget.blur(),v.key==="Escape"&&o(!1)},[]),x=p.useCallback(v=>{e.applyOperation(J(t,{color:v})),a(!1)},[e,t]),y=Ie("be-callout",n);return n?l.jsxs("div",{className:y,"data-block-id":t,"data-color":h,children:[l.jsx("div",{className:"be-callout-icon-wrap",children:r?l.jsx("input",{type:"text",className:"be-callout-icon-input",defaultValue:d,autoFocus:!0,onBlur:m,onKeyDown:g,"aria-label":"Callout icon (paste or type an emoji)"}):l.jsx("button",{type:"button",className:"be-callout-icon",onClick:()=>o(!0),"aria-label":"Change callout icon",title:"Change icon",children:d})}),l.jsx("div",{className:"be-callout-content",children:l.jsx(ht,{parentId:t})}),l.jsxs("div",{className:"be-callout-color-wrap",contentEditable:!1,children:[l.jsx("button",{ref:i,type:"button",className:"be-callout-color-trigger","aria-label":"Callout color","aria-haspopup":"true","aria-expanded":s,title:"Callout color",onClick:()=>a(v=>!v),children:l.jsx("span",{className:`be-callout-color-dot be-callout-color-dot-${h}`})}),s&&l.jsx("div",{ref:u,className:"be-callout-color-picker",role:"menu","aria-label":"Callout color",children:ti.map(v=>l.jsx("button",{type:"button",role:"menuitem",className:`be-callout-color-option be-callout-color-option-${v.value}${v.value===h?" be-callout-color-option-active":""}`,title:v.label,"aria-label":v.label,onClick:()=>x(v.value)},v.value))})]})]}):null}function mf(t,e){return t.contentIds.map(n=>{const r=e.store.getBlock(n);return e.registry.get(r.type).toHTML(r,e)}).join("")}function bf(t,e){var r;const n=((r=t.props)==null?void 0:r.icon)??pn;return`<div class="callout" data-icon="${n}"><div class="callout-icon">${n}</div><div class="callout-content">${mf(t,e)}</div></div>`}function gf(t,e){var o;const n=((o=t.props)==null?void 0:o.icon)??pn,r=t.contentIds.map(s=>{const a=e.store.getBlock(s);return e.registry.get(a.type).toPlainText(a,e)}).join(`
2923
- `);return`${n} ${r}`}const ni={component:hf,isLeaf:!1,defaultProps:{icon:pn},toHTML:bf,toPlainText:gf,slashCommand:{label:"Callout",icon:nl,keywords:["callout","aside","note","info","tip","warning"],run:(t,e)=>Be(t,e,up())}};function xf({id:t}){const e=G(),n=be(t),{setSelectedBlockId:r}=ut(),o=p.useCallback(()=>{cn(e,t,(n==null?void 0:n.contentIds)??[],te("paragraph"))},[e,t,n]),s=p.useCallback(()=>{const d=Nn(e,t);dn(e,d,t,r)},[e,t,r]),a=p.useCallback(()=>_e(e,t,"up"),[e,t]),i=p.useCallback(()=>_e(e,t,"down"),[e,t]),u=Ie("be-blockquote",n);if(!n)return null;const c=Le(e,n.contentIds),f=it(e,n);return l.jsx("blockquote",{className:u,"data-block-id":t,"data-empty":c?"":void 0,"data-placeholder":"Empty quote",dir:f,children:l.jsx(pt,{blockId:t,runIds:n.contentIds,dir:f,onEnter:o,onBackspaceAtStart:s,onArrowUp:a,onArrowDown:i})})}function yf(t,e){return`<p>${t.contentIds.map(r=>e.store.getRun(r)).map(r=>ft(r,e)).join("")}</p>`}function kf(t,e){return t.contentIds.map(n=>It(e.store.getRun(n),e)).join("")}function vf(t,e){if(t.tagName!=="BLOCKQUOTE")return null;const n=Ye(t,e);return{block:{id:E(),type:"blockquote",parentId:null,contentIds:n.map(o=>o.id),props:{}},runs:n}}const ri={component:xf,isLeaf:!0,defaultProps:{},toHTML:yf,toPlainText:kf,fromHTML:vf,slashCommand:{label:"Quote",icon:tl,keywords:["quote","blockquote","citation"],run:(t,e)=>Be(t,e,te("blockquote"))}},oi=["plaintext","javascript","python","html","css","json","bash","sql"],wf=oi.map(t=>({value:t,label:t}));function Js(t,e,n){const r=lt();if(!r||r.blockId!==e)return;const o=t.getRun(r.runId);if(!o||o.type!=="text")return;const s=o.value??"",a=s.slice(0,r.offset)+n+s.slice(r.offset);t.applyOperation(ue(o.id,{value:a})),Je(o.id,r.offset+n.length)}function If({id:t}){var m;const e=G(),n=be(t),r=p.useCallback(()=>Js(e,t,`
2924
- `),[e,t]),o=p.useCallback(()=>Js(e,t," "),[e,t]),s=p.useCallback(()=>{var k;const g=Nn(e,t);if(!g||g===t)return;const x=e.getBlock(g),y=(k=x==null?void 0:x.contentIds)==null?void 0:k[x.contentIds.length-1];y&&ye(y)},[e,t]),a=p.useCallback(()=>_e(e,t,"up"),[e,t]),i=p.useCallback(()=>_e(e,t,"down"),[e,t]),u=p.useCallback(g=>e.applyOperation(J(t,{language:g})),[e,t]),c=p.useCallback(()=>vr(e,t),[e,t]),f=Ie("be-code-block",n);if(!n)return null;const d=((m=n.props)==null?void 0:m.language)??"plaintext",h=Le(e,n.contentIds);return l.jsxs("div",{className:f,"data-block-id":t,children:[l.jsxs("div",{className:"be-code-block-header",contentEditable:!1,children:[l.jsx(Mt,{className:"be-code-block-language",value:d,options:wf,onChange:u,ariaLabel:"Code language"}),l.jsx("button",{type:"button",className:"be-code-block-delete",onClick:c,"aria-label":"Delete code block",title:"Delete code block",children:l.jsx(On,{size:14})})]}),l.jsx("pre",{className:"be-code-block-pre",dir:"ltr",children:l.jsx("code",{"data-empty":h?"":void 0,"data-placeholder":"Empty code block",children:l.jsx(pt,{blockId:t,runIds:n.contentIds,dir:"ltr",onEnter:r,onTab:o,onBackspaceAtStart:s,onArrowUp:a,onArrowDown:i})})})]})}function Cf(t,e){var s;const n=t.contentIds.map(a=>e.store.getRun(a)),r=(s=t.props)==null?void 0:s.language;return`<pre><code${r&&r!=="plaintext"?` data-language="${Et(r)}"`:""}>${n.map(a=>ft(a,e)).join("")}</code></pre>`}function Sf(t,e){return t.contentIds.map(n=>It(e.store.getRun(n),e)).join("")}function Rf(t,e){var a;if(t.tagName!=="PRE")return null;const n=t.querySelector("code")??t,r=(a=n.getAttribute)==null?void 0:a.call(n,"data-language"),o=E();return{block:{id:E(),type:"code",parentId:null,contentIds:[o],props:r?{language:r}:{}},runs:[{id:o,type:"text",value:n.textContent??"",marks:{}}]}}const si={component:If,isLeaf:!0,defaultProps:{language:"plaintext"},toHTML:Cf,toPlainText:Sf,fromHTML:Rf,slashCommand:{label:"Code",icon:_o,keywords:["code","codeblock","snippet","pre"],run:(t,e)=>Be(t,e,te("code"))}};function Tf(t,e){var n;return e.length===0||e.length===1&&(((n=t.getRun(e[0]))==null?void 0:n.value)??"")===""}function jf(t,e){const n=e.contentIds??[];if(n.length===0)return!0;if(n.length>1)return!1;const r=t.getBlock(n[0]);return!!r&&r.type==="paragraph"&&Le(t,r.contentIds)}function Yn(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Ef(t,e){const n=t.getBlock(e);if(!n)return null;const r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=n.props.titleRunIds??[],a=Tf(t,s)&&jf(t,n);if(o<=0){if(!a)return null;if(r.contentIds.length>1)return Yn(t,[ee(e)]),{focusBlockId:t.getBlock(r.id).contentIds[0],needsRefocus:!0};const{block:c,runs:f}=te("paragraph")(r.id);return Yn(t,[me(c,r.id,o,{blocks:[c],runs:f}),ee(e)]),{focusBlockId:c.id,needsRefocus:!0}}const i=r.contentIds[o-1],u=t.getBlock(i);return a?(Yn(t,[ee(e)]),{focusBlockId:i,needsRefocus:!0}):Mn(t,u)?(Yn(t,[ee(i)]),{focusBlockId:e,needsRefocus:!1}):null}function Bf(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function _f({id:t}){var y;const e=G(),n=be(t),{setSelectedBlockId:r}=ut(),o=p.useCallback(()=>{var j,I;const k=((j=n==null?void 0:n.props)==null?void 0:j.titleRunIds)??[],w=(((I=n==null?void 0:n.contentIds)==null?void 0:I.length)??0)>0,v=te("paragraph");w?kl(e,t,k,v):cn(e,t,k,v)},[e,t,n]),s=p.useCallback(()=>{const k=Ef(e,t);!k||!k.needsRefocus||dn(e,k.focusBlockId,t,r)},[e,t,r]),a=p.useCallback(()=>_e(e,t,"up"),[e,t]),i=p.useCallback(()=>_e(e,t,"down"),[e,t]),u=p.useCallback(()=>{var w,v;if(!((((w=n==null?void 0:n.contentIds)==null?void 0:w.length)??0)>0)){const{block:j,runs:I}=te("paragraph")(t);Bf(e,[me(j,t,0,{blocks:[j],runs:I}),J(t,{collapsed:!1})]),ye(j.contentIds[0]);return}e.applyOperation(J(t,{collapsed:!((v=n==null?void 0:n.props)!=null&&v.collapsed)}))},[e,t,n==null?void 0:n.contentIds,(y=n==null?void 0:n.props)==null?void 0:y.collapsed]),c=Ie("be-toggle-heading",n);if(!n)return null;const{level:f=2,collapsed:d,titleRunIds:h=[]}=n.props,m=n.contentIds.length>0,g=`h${f}`,x=it(e,n);return l.jsxs("div",{className:c,"data-block-id":t,dir:x,children:[l.jsxs("div",{className:"be-toggle-heading-row",children:[l.jsx("button",{type:"button",className:"be-toggle-heading-marker",onClick:u,"aria-expanded":!d,"aria-label":m?d?"Expand section":"Collapse section":"Add content to section",children:d?l.jsx(jt,{}):l.jsx(fr,{})}),l.jsx(g,{className:`be-heading be-heading-${f} be-toggle-heading-title`,"data-empty":Le(e,h)?"":void 0,"data-placeholder":`Toggle heading ${f}`,children:l.jsx(pt,{blockId:t,runIds:h,dir:x,onEnter:o,onBackspaceAtStart:s,onArrowUp:a,onArrowDown:i})})]}),!d&&l.jsx("div",{className:"be-toggle-heading-children",children:l.jsx(ht,{parentId:t})})]})}function Of({level:t=2,collapsed:e=!1}={}){return function(r,o){const s=E(),a=o!=null&&o.length?o:[{id:E(),type:"text",value:"",marks:{}}],{block:i,runs:u}=te("paragraph")(s);return{block:{id:s,type:"toggleHeading",parentId:r,contentIds:[i.id],props:{level:t,collapsed:e,titleRunIds:a.map(c=>c.id)}},runs:[...a,...u],subtreeBlocks:[i]}}}function Mf(t,e){const{titleRunIds:n=[],level:r=2,collapsed:o}=t.props,s=n.map(i=>ft(e.store.getRun(i),e)).join(""),a=t.contentIds.map(i=>{const u=e.store.getBlock(i);return e.registry.get(u.type).toHTML(u,e)}).join("");return`<details${o?"":" open"}><summary><h${r}>${s}</h${r}></summary>${a}</details>`}function Lf(t,e){const{titleRunIds:n=[]}=t.props,r=n.map(s=>It(e.store.getRun(s),e)).join(""),o=t.contentIds.map(s=>{const a=e.store.getBlock(s);return e.registry.get(a.type).toPlainText(a,e)}).join(`
3202
+ `,zs="noteloom-default-styles";function $a(){if(typeof document>"u"||document.getElementById(zs))return;const t=document.createElement("style");t.id=zs,t.textContent=Gd,document.head.appendChild(t)}const za=p.createContext(null);function Ha({store:t,registry:e,inlineRegistry:n=null,history:r=null,className:o,style:s,theme:a="default",getBlockClassName:i,commentAuthorId:d,children:c}){p.useEffect(()=>{a!=="none"&&$a()},[a]);const[f,u]=p.useState(!1),[h,m]=p.useState(null),[g,x]=p.useState([]),[y,k]=p.useState(!1),[v,w]=p.useState(null),B=p.useCallback(()=>w("new"),[]),I=p.useCallback(L=>w(L),[]),C=p.useCallback(()=>w(null),[]),R=p.useRef(null),E=p.useCallback(()=>R.current,[]),T=p.useCallback(L=>{var Y,K;const $=R.current;$!==L&&($&&((Y=document.querySelector(`[data-block-id="${$}"]`))==null||Y.classList.remove("be-block-selected")),R.current=L,L&&((K=document.querySelector(`[data-block-id="${L}"]`))==null||K.classList.add("be-block-selected")))},[]),O=p.useMemo(()=>({store:t,registry:e,inlineRegistry:n,history:r,isWholeDocumentSelected:f,setIsWholeDocumentSelected:u,selectedBlockRange:g,setSelectedBlockRange:x,getSelectedBlockId:E,setSelectedBlockId:T,isPreviewMode:y,setIsPreviewMode:k,fieldTypeEditorTarget:v,openCreateFieldType:B,openEditFieldType:I,closeFieldTypeEditor:C,getBlockClassName:i,commentAuthorId:d,hoveredCommentId:h,setHoveredCommentId:m}),[t,e,n,r,f,g,E,T,y,v,B,I,C,i,d,h]),S=o||s?l.jsx("div",{className:o?`be-root ${o}`:"be-root",style:s,children:c}):c;return l.jsx(za.Provider,{value:O,children:S})}function $e(){const t=p.useContext(za);if(!t)throw new Error("Editor hooks must be used within an <EditorProvider>");return t}function G(){return $e().store}function dt(){return $e().registry}function Ke(){return $e().inlineRegistry}function Co(){const{isWholeDocumentSelected:t,setIsWholeDocumentSelected:e}=$e();return[t,e]}function Mn(){const{selectedBlockRange:t,setSelectedBlockRange:e}=$e();return[t,e]}function ut(){const{getSelectedBlockId:t,setSelectedBlockId:e}=$e();return{getSelectedBlockId:t,setSelectedBlockId:e}}function So(){const{isPreviewMode:t,setIsPreviewMode:e}=$e();return[t,e]}function Ie(t,e){const{getBlockClassName:n}=$e(),r=e&&n?n(e):void 0;return r?`${t} ${r}`:t}function Fa(){return $e().commentAuthorId}function hr(){const{hoveredCommentId:t,setHoveredCommentId:e}=$e();return[t,e]}function jo(){const{fieldTypeEditorTarget:t,openCreateFieldType:e,openEditFieldType:n,closeFieldTypeEditor:r}=$e();return{target:t,openCreate:e,openEdit:n,close:r}}const Hs=["#e03131","#e8590c","#2f9e44","#1971c2","#9c36b5"];function Jd(t){let e=0;const n=String(t??"");for(let r=0;r<n.length;r+=1)e=e*31+n.charCodeAt(r)|0;return Hs[Math.abs(e)%Hs.length]}function Zd(t){const e=String(t??"").trim();if(!e)return"?";const n=e.split(/\s+/).filter(Boolean);return n.length>=2?(n[0][0]+n[1][0]).toUpperCase():e.slice(0,2).toUpperCase()}const no=60*1e3,ro=60*no,Fr=24*ro;function Ua(t,e=Date.now()){const n=e-t;if(n<no)return"just now";if(n<ro){const r=Math.floor(n/no);return`${r} min${r===1?"":"s"} ago`}if(n<Fr){const r=Math.floor(n/ro);return`${r} hour${r===1?"":"s"} ago`}if(n<7*Fr){const r=Math.floor(n/Fr);return`${r} day${r===1?"":"s"} ago`}return new Date(t).toLocaleDateString()}function jn({authorId:t,size:e=26}){return l.jsx("span",{className:"be-comment-avatar",style:{width:e,height:e,fontSize:Math.max(10,e*.4),background:Jd(t)},"aria-hidden":"true",children:Zd(t)})}function V({children:t,size:e=16,strokeWidth:n=2,...r}){return l.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:n,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",...r,children:t})}function Et(t){return l.jsx(V,{...t,children:l.jsx("polyline",{points:"9 18 15 12 9 6"})})}function mr(t){return l.jsx(V,{...t,children:l.jsx("polyline",{points:"6 9 12 15 18 9"})})}function wt(t){return l.jsxs(V,{...t,children:[l.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),l.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Qd(t){return l.jsxs(V,{...t,fill:"currentColor",stroke:"none",children:[l.jsx("circle",{cx:"5",cy:"12",r:"1.6"}),l.jsx("circle",{cx:"12",cy:"12",r:"1.6"}),l.jsx("circle",{cx:"19",cy:"12",r:"1.6"})]})}function Va(t){return l.jsx(V,{...t,children:l.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}function Ro(t){return l.jsxs(V,{...t,children:[l.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),l.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function Ya(t){return l.jsxs(V,{...t,children:[l.jsx("path",{d:"M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"}),l.jsx("path",{d:"M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"})]})}function Ka(t){return l.jsxs(V,{...t,children:[l.jsx("line",{x1:"19",y1:"4",x2:"10",y2:"4"}),l.jsx("line",{x1:"14",y1:"20",x2:"5",y2:"20"}),l.jsx("line",{x1:"15",y1:"4",x2:"9",y2:"20"})]})}function Wa(t){return l.jsxs(V,{...t,children:[l.jsx("path",{d:"M6 3v7a6 6 0 0 0 12 0V3"}),l.jsx("line",{x1:"4",y1:"21",x2:"20",y2:"21"})]})}function qa(t){return l.jsxs(V,{...t,children:[l.jsx("path",{d:"M12 20h9"}),l.jsx("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]})}function eu(t){return l.jsx(V,{...t,children:l.jsx("path",{d:"M3 17c2-4 4-4 6 0s4 4 6 0 4-4 6 0"})})}function Xa(t){return l.jsxs(V,{...t,children:[l.jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),l.jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]})}function Ga(t){return l.jsx(V,{...t,children:l.jsx("path",{d:"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"})})}function tu(t){return l.jsxs(V,{...t,children:[l.jsx("path",{d:"M3 12a9 9 0 1 0 3-6.7"}),l.jsx("polyline",{points:"3 5 3 10 8 10"}),l.jsx("polyline",{points:"12 7 12 12 16 14"})]})}function nu(t){return l.jsxs(V,{...t,children:[l.jsx("path",{d:"M3 12a9 9 0 1 0 2.6-6.3"}),l.jsx("polyline",{points:"3 4 3 9 8 9"})]})}function ru(t){return l.jsx(V,{...t,children:l.jsx("polyline",{points:"20 6 9 17 4 12"})})}function ou(t){return l.jsxs(V,{...t,children:[l.jsx("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),l.jsx("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})}function su(t){return l.jsxs(V,{...t,children:[l.jsx("path",{d:"M16 4H9a3 3 0 0 0-2.83 4"}),l.jsx("path",{d:"M14 12a4 4 0 0 1 0 8H6"}),l.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})]})}function Ja(t){return l.jsxs(V,{...t,children:[l.jsx("line",{x1:"21",y1:"6",x2:"3",y2:"6"}),l.jsx("line",{x1:"17",y1:"10",x2:"3",y2:"10"}),l.jsx("line",{x1:"21",y1:"14",x2:"3",y2:"14"}),l.jsx("line",{x1:"17",y1:"18",x2:"3",y2:"18"})]})}function au(t){return l.jsxs(V,{...t,children:[l.jsx("line",{x1:"21",y1:"6",x2:"3",y2:"6"}),l.jsx("line",{x1:"18",y1:"10",x2:"6",y2:"10"}),l.jsx("line",{x1:"21",y1:"14",x2:"3",y2:"14"}),l.jsx("line",{x1:"18",y1:"18",x2:"6",y2:"18"})]})}function Za(t){return l.jsxs(V,{...t,children:[l.jsx("line",{x1:"21",y1:"6",x2:"3",y2:"6"}),l.jsx("line",{x1:"21",y1:"10",x2:"7",y2:"10"}),l.jsx("line",{x1:"21",y1:"14",x2:"3",y2:"14"}),l.jsx("line",{x1:"21",y1:"18",x2:"7",y2:"18"})]})}function lu(t){return l.jsx(V,{...t,children:[5,12,19].flatMap(e=>[9,15].map(n=>l.jsx("circle",{cx:n,cy:e,r:"1.3",fill:"currentColor",stroke:"none"},`${n}-${e}`)))})}function On(t){return l.jsxs(V,{...t,children:[l.jsx("polyline",{points:"3 6 5 6 21 6"}),l.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}),l.jsx("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),l.jsx("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}function To(t){return l.jsxs(V,{...t,children:[l.jsx("rect",{x:"9",y:"9",width:"12",height:"12",rx:"2"}),l.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}function br(t){return l.jsxs(V,{...t,children:[l.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),l.jsx("polyline",{points:"5 12 12 5 19 12"})]})}function gr(t){return l.jsxs(V,{...t,children:[l.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),l.jsx("polyline",{points:"19 12 12 19 5 12"})]})}function Qa(t){return l.jsx(V,{...t,children:l.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"1"})})}function iu(t){return l.jsx(V,{...t,children:l.jsx("circle",{cx:"12",cy:"12",r:"8"})})}function cu(t){return l.jsxs(V,{...t,children:[l.jsx("line",{x1:"6",y1:"18",x2:"18",y2:"6"}),l.jsx("polyline",{points:"9 6 18 6 18 15"})]})}function du(t){return l.jsx(V,{...t,children:l.jsx("polygon",{points:"12 3 21 12 12 21 3 12"})})}function uu(t){return l.jsx(V,{...t,children:l.jsx("polygon",{points:"12 4 20 20 4 20"})})}function pu(t){return l.jsx(V,{...t,children:l.jsx("polygon",{points:"12 3 14.7 9.4 21.5 9.9 16.3 14.4 17.9 21 12 17.4 6.1 21 7.7 14.4 2.5 9.9 9.3 9.4"})})}function fu(t){return l.jsx(V,{...t,children:l.jsx("path",{d:"M5 3l14 8-6 2-2 6-6-16z"})})}function el(t){return l.jsxs(V,{...t,children:[l.jsx("path",{d:"M19 20H9l-6-6a1.5 1.5 0 0 1 0-2l9-9a1.5 1.5 0 0 1 2 0l7 7a1.5 1.5 0 0 1 0 2l-7 7"}),l.jsx("path",{d:"M6.5 12.5 13 19"})]})}function hu(t){return l.jsxs(V,{...t,children:[l.jsx("path",{d:"M12 3v12"}),l.jsx("path",{d:"M7 10l5 5 5-5"}),l.jsx("path",{d:"M4 19h16"})]})}function mu(t){return l.jsxs(V,{...t,children:[l.jsx("path",{d:"M6 15V9a6 6 0 0 1 12 0v6"}),l.jsx("path",{d:"M6 15a3 3 0 0 0 6 0v-4"}),l.jsx("path",{d:"M18 15a3 3 0 0 1-6 0v-4"}),l.jsx("line",{x1:"3",y1:"9",x2:"6",y2:"9"}),l.jsx("line",{x1:"3",y1:"15",x2:"6",y2:"15"}),l.jsx("line",{x1:"18",y1:"9",x2:"21",y2:"9"}),l.jsx("line",{x1:"18",y1:"15",x2:"21",y2:"15"})]})}function bu(t){return l.jsxs(V,{...t,children:[l.jsx("circle",{cx:"6",cy:"6",r:"3"}),l.jsx("circle",{cx:"6",cy:"18",r:"3"}),l.jsx("line",{x1:"20",y1:"4",x2:"8.12",y2:"15.88"}),l.jsx("line",{x1:"14.47",y1:"14.48",x2:"20",y2:"20"}),l.jsx("line",{x1:"8.12",y1:"8.12",x2:"12",y2:"12"})]})}function Eo(t){return l.jsxs(V,{...t,children:[l.jsx("line",{x1:"17",y1:"6",x2:"3",y2:"6"}),l.jsx("line",{x1:"21",y1:"12",x2:"3",y2:"12"}),l.jsx("line",{x1:"15",y1:"18",x2:"3",y2:"18"})]})}function Bo({level:t=1,size:e=16,...n}){return l.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",...n,children:l.jsxs("text",{x:"2",y:"18",fontSize:"14",fontWeight:"700",fill:"currentColor",fontFamily:"inherit",children:["H",t]})})}function tl(t){return l.jsx(Bo,{level:1,...t})}function nl(t){return l.jsx(Bo,{level:2,...t})}function rl(t){return l.jsx(Bo,{level:3,...t})}function ol(t){return l.jsxs(V,{...t,children:[l.jsx("path",{d:"M7 7a3 3 0 0 0-3 3v3a2 2 0 0 0 2 2h2a1 1 0 0 0 1-1v-4a1 1 0 0 0-1-1H6a3 3 0 0 1 3-3z"}),l.jsx("path",{d:"M17 7a3 3 0 0 0-3 3v3a2 2 0 0 0 2 2h2a1 1 0 0 0 1-1v-4a1 1 0 0 0-1-1h-2a3 3 0 0 1 3-3z"})]})}function _o(t){return l.jsxs(V,{...t,children:[l.jsx("polyline",{points:"9 8 4 12 9 16"}),l.jsx("polyline",{points:"15 8 20 12 15 16"})]})}function gu(t){return l.jsx(V,{...t,children:l.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})})}function sl(t){return l.jsxs(V,{...t,children:[l.jsx("path",{d:"M4 5h16a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H9l-4 4v-4H4a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1z"}),l.jsx("line",{x1:"7",y1:"9",x2:"17",y2:"9"}),l.jsx("line",{x1:"7",y1:"12.5",x2:"13",y2:"12.5"})]})}function xu(t){return l.jsxs(V,{...t,children:[l.jsx("rect",{x:"3",y:"8",width:"18",height:"8",rx:"3"}),l.jsx("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]})}function yu(t){return l.jsxs(V,{...t,children:[l.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"1"}),l.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"}),l.jsx("line",{x1:"3",y1:"16",x2:"21",y2:"16"}),l.jsx("line",{x1:"9",y1:"4",x2:"9",y2:"20"}),l.jsx("line",{x1:"15",y1:"4",x2:"15",y2:"20"})]})}function ku(t){return l.jsxs(V,{...t,children:[l.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"1"}),l.jsx("line",{x1:"9",y1:"4",x2:"9",y2:"20"}),l.jsx("line",{x1:"15",y1:"4",x2:"15",y2:"20"})]})}function al(t){return l.jsxs(V,{...t,children:[l.jsx("circle",{cx:"4.5",cy:"6",r:"1.2",fill:"currentColor",stroke:"none"}),l.jsx("circle",{cx:"4.5",cy:"12",r:"1.2",fill:"currentColor",stroke:"none"}),l.jsx("circle",{cx:"4.5",cy:"18",r:"1.2",fill:"currentColor",stroke:"none"}),l.jsx("line",{x1:"9",y1:"6",x2:"21",y2:"6"}),l.jsx("line",{x1:"9",y1:"12",x2:"21",y2:"12"}),l.jsx("line",{x1:"9",y1:"18",x2:"21",y2:"18"})]})}function ll(t){return l.jsxs(V,{...t,children:[l.jsx("line",{x1:"10",y1:"6",x2:"21",y2:"6"}),l.jsx("line",{x1:"10",y1:"12",x2:"21",y2:"12"}),l.jsx("line",{x1:"10",y1:"18",x2:"21",y2:"18"}),l.jsx("text",{x:"2",y:"8.5",fontSize:"7",fontWeight:"700",fill:"currentColor",stroke:"none",children:"1"}),l.jsx("text",{x:"2",y:"14.5",fontSize:"7",fontWeight:"700",fill:"currentColor",stroke:"none",children:"2"}),l.jsx("text",{x:"2",y:"20.5",fontSize:"7",fontWeight:"700",fill:"currentColor",stroke:"none",children:"3"})]})}function No(t){return l.jsxs(V,{...t,children:[l.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"3"}),l.jsx("polyline",{points:"8 12 11 15 16 9"})]})}function vu(t){return l.jsxs(V,{...t,children:[l.jsx("rect",{x:"3",y:"5",width:"18",height:"16",rx:"2"}),l.jsx("line",{x1:"3",y1:"10",x2:"21",y2:"10"}),l.jsx("line",{x1:"8",y1:"3",x2:"8",y2:"7"}),l.jsx("line",{x1:"16",y1:"3",x2:"16",y2:"7"})]})}function il(t){return l.jsxs(V,{...t,children:[l.jsx("path",{d:"M12 3h7a2 2 0 0 1 2 2v7a2 2 0 0 1-.59 1.41l-8 8a2 2 0 0 1-2.82 0l-7-7a2 2 0 0 1 0-2.82l8-8A2 2 0 0 1 12 3z"}),l.jsx("circle",{cx:"15.5",cy:"8.5",r:"1.2",fill:"currentColor",stroke:"none"})]})}function wu(t){return l.jsxs(V,{...t,children:[l.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),l.jsx("circle",{cx:"9",cy:"10",r:"1.5",fill:"currentColor",stroke:"none"}),l.jsx("path",{d:"M4 17l5-5 4 4 4-5 4 6"})]})}function Iu(t){return l.jsxs(V,{...t,children:[l.jsx("rect",{x:"3",y:"5",width:"14",height:"14",rx:"2"}),l.jsx("path",{d:"M17 10l4-2.5v9L17 14"})]})}function Mo(t){return l.jsxs(V,{...t,children:[l.jsx("path",{d:"M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7z"}),l.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function Oo(t){return l.jsxs(V,{...t,children:[l.jsx("path",{d:"M17.94 17.94A10.94 10.94 0 0 1 12 19c-6.5 0-10-7-10-7a18.5 18.5 0 0 1 5.06-5.94M9.9 4.24A10.94 10.94 0 0 1 12 4c6.5 0 10 7 10 7a18.5 18.5 0 0 1-2.16 3.19"}),l.jsx("path",{d:"M14.12 14.12a3 3 0 1 1-4.24-4.24"}),l.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function Cu(t){return l.jsxs(V,{...t,children:[l.jsx("line",{x1:"4",y1:"10",x2:"4",y2:"14"}),l.jsx("line",{x1:"8",y1:"7",x2:"8",y2:"17"}),l.jsx("line",{x1:"12",y1:"4",x2:"12",y2:"20"}),l.jsx("line",{x1:"16",y1:"7",x2:"16",y2:"17"}),l.jsx("line",{x1:"20",y1:"10",x2:"20",y2:"14"})]})}function Su(t){return l.jsxs(V,{...t,children:[l.jsx("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),l.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),l.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),l.jsx("line",{x1:"8",y1:"23",x2:"16",y2:"23"})]})}function ju(t){const e=new Date(t),n=new Date,r=s=>new Date(s.getFullYear(),s.getMonth(),s.getDate()).getTime(),o=Math.round((r(n)-r(e))/(24*60*60*1e3));return o===0?"Today":o===1?"Yesterday":e.toLocaleDateString(void 0,{month:"long",day:"numeric",year:e.getFullYear()!==n.getFullYear()?"numeric":void 0})}function Ru({docId:t,idleMs:e,maxVersions:n}){const r=G(),o=dt(),s=Ke(),{versions:a,isLoaded:i,refresh:d}=Pa(t),[c,f]=p.useState(!1),[u,h]=p.useState(null),[m,g]=p.useState("changes"),x=p.useRef(null);p.useEffect(()=>{if(typeof r.getHistoryLog!="function")return;const E=Aa({store:r,docId:t,idleMs:e,maxVersions:n,onSnapshot:d});return()=>E.stop()},[r,t]);function y(){f(!1),h(null),g("changes")}p.useEffect(()=>{if(!c)return;const E=T=>{T.key==="Escape"&&y()};return document.addEventListener("keydown",E),()=>document.removeEventListener("keydown",E)},[c]);const k=a.findIndex(E=>E.id===u),v=k>=0?a[k]:null,w=k>=0?a[k+1]??null:null,B=p.useMemo(()=>{if(!v)return"";const E=new Bn(v.doc);return Io(E,o,s)},[v,o,s]),I=p.useMemo(()=>v?Da((w==null?void 0:w.doc)??null,v.doc):"",[v,w]);function C(){v&&window.confirm("Restore this version? This replaces the current document.")&&(Oa(r,v.doc),y())}const R=[];for(const E of a){const T=ju(E.timestamp);let O=R[R.length-1];(!O||O.label!==T)&&(O={label:T,versions:[]},R.push(O)),O.versions.push(E)}return l.jsxs(l.Fragment,{children:[l.jsxs("button",{type:"button",className:"be-version-history-trigger",onClick:()=>f(!0),title:"Version history",children:[l.jsx(tu,{size:15}),"Version history"]}),c&&De.createPortal(l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"be-version-history-backdrop",onClick:y}),l.jsxs("div",{ref:x,className:"be-version-history-drawer",role:"dialog","aria-label":"Version history",children:[l.jsxs("div",{className:"be-version-history-header",children:[l.jsx("span",{children:v?"Preview":"Version history"}),l.jsx("button",{type:"button",className:"be-version-history-close",onClick:y,"aria-label":"Close",children:l.jsx(wt,{size:14})})]}),v?l.jsxs("div",{className:"be-version-history-preview",children:[l.jsxs("div",{className:"be-version-history-preview-meta",children:[l.jsx(jn,{authorId:v.authorId,size:24}),l.jsxs("div",{children:[l.jsx("div",{className:"be-version-history-preview-author",children:v.authorId??"Unknown"}),l.jsxs("div",{className:"be-version-history-preview-time",children:[new Date(v.timestamp).toLocaleString()," · ",v.summary]})]})]}),l.jsxs("div",{className:"be-version-history-view-toggle",role:"tablist","aria-label":"View mode",children:[l.jsx("button",{type:"button",role:"tab","aria-selected":m==="changes",className:m==="changes"?"is-active":"",onClick:()=>g("changes"),children:"Changes"}),l.jsx("button",{type:"button",role:"tab","aria-selected":m==="preview",className:m==="preview"?"is-active":"",onClick:()=>g("preview"),children:"Preview"})]}),m==="changes"&&l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"be-version-history-diff-legend",children:[l.jsx("span",{className:"be-version-diff-added",children:"Added"}),l.jsx("span",{className:"be-version-diff-removed",children:"Removed"}),!w&&l.jsx("span",{className:"be-version-history-diff-legend-note",children:"First saved version — everything shown is new."})]}),l.jsx("div",{className:"be-version-history-preview-body be-version-history-diff-body",dangerouslySetInnerHTML:{__html:I}})]}),m==="preview"&&l.jsx("div",{className:"be-version-history-preview-body",dangerouslySetInnerHTML:{__html:B}}),l.jsxs("div",{className:"be-version-history-preview-actions",children:[l.jsx("button",{type:"button",onClick:()=>{h(null),g("changes")},children:"Back"}),l.jsxs("button",{type:"button",className:"be-version-history-restore",onClick:C,children:[l.jsx(nu,{size:13}),"Restore this version"]})]})]}):l.jsxs("div",{className:"be-version-history-list",children:[!i&&l.jsx("p",{className:"be-version-history-empty",children:"Loading…"}),i&&a.length===0&&l.jsx("p",{className:"be-version-history-empty",children:"No versions yet — one is saved automatically after you make some edits and pause."}),R.map(E=>l.jsxs("div",{className:"be-version-history-group",children:[l.jsx("div",{className:"be-version-history-group-label",children:E.label}),E.versions.map(T=>l.jsxs("button",{type:"button",className:"be-version-history-item",onClick:()=>h(T.id),children:[l.jsx(jn,{authorId:T.authorId,size:24}),l.jsxs("div",{className:"be-version-history-item-body",children:[l.jsx("div",{className:"be-version-history-item-author",children:T.authorId??"Unknown"}),l.jsxs("div",{className:"be-version-history-item-meta",children:[Ua(T.timestamp)," · ",T.summary]})]})]},T.id))]},E.label))]})]})]}),document.body)]})}function Tu(t,e){var r;const n=t.getBlock(e);return((r=n.props)==null?void 0:r.titleRunIds)??n.contentIds}function cl(t,e){const n=(t==null?void 0:t.commentIds)??[];return n.includes(e)?t??{}:{...t,commentIds:[...n,e]}}function Eu(t,e){const n=(t==null?void 0:t.commentIds)??[];if(!n.includes(e))return t??{};const r={...t},o=n.filter(s=>s!==e);return o.length>0?r.commentIds=o:delete r.commentIds,r}function Bu(t,e,n,r,o){const s=cl(e.marks,o);if(n===0&&r===e.value.length)return{type:"updateRun",id:e.id,patch:{marks:s}};const a=e.value.slice(0,n),i=e.value.slice(n,r),d=e.value.slice(r),c=[];return a&&c.push({id:_(),type:"text",value:a,marks:{...e.marks}}),c.push({id:_(),type:"text",value:i,marks:s}),d&&c.push({id:_(),type:"text",value:d,marks:{...e.marks}}),Nt(t,[e.id],c)}function Lo(t,{blockId:e,startRunId:n,startOffset:r,endRunId:o,endOffset:s},a){const i=Tu(t,e),d=i.indexOf(n),c=i.indexOf(o);if(d===-1||c===-1)return null;const[f,u]=d<=c?[d,c]:[c,d],h=d<=c?r:s,m=d<=c?s:r,g=i.slice(f,u+1),x=g.map(k=>t.getRun(k));if(f===u){const k=x[0];if(k.type!=="text")return null;const v=Math.max(0,Math.min(h,m)),w=Math.min(k.value.length,Math.max(h,m));return v===w?null:Bu(e,k,v,w,a)}const y=[];return x.forEach((k,v)=>{if(k.type!=="text"){y.push(k);return}const w=v===0,B=v===x.length-1,I=w?h:0,C=B?m:k.value.length,R=k.value.slice(0,I),E=k.value.slice(I,C),T=k.value.slice(C);R&&y.push({id:_(),type:"text",value:R,marks:{...k.marks}}),y.push({id:_(),type:"text",value:E,marks:cl(k.marks,a)}),T&&y.push({id:_(),type:"text",value:T,marks:{...k.marks}})}),Nt(e,g,y)}function Ao(t,e){var r,o;const n=[];for(const s of t.getAllRunIds()){const a=t.getRun(s);(o=(r=a==null?void 0:a.marks)==null?void 0:r.commentIds)!=null&&o.includes(e)&&n.push({type:"updateRun",id:s,patch:{marks:Eu(a.marks,e)}})}return n}function dl(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function _u(t,e,{authorId:n,text:r}){const o=_(),s=Lo(t,e,o),a={id:o,blockId:e.blockId,anchorRunIds:[e.startRunId,e.endRunId],resolved:!1,messages:[{id:_(),authorId:n,text:r,createdAt:Date.now()}]},i=s?[s,Cn(a)]:[Cn(a)];return dl(t,i),o}function ul(t,e,{authorId:n,text:r}){const o={id:_(),authorId:n,text:r,createdAt:Date.now()};return t.applyOperation(ko(e,o)),o.id}function pl(t,e,n=!0){t.applyOperation(vo(e,n))}function fl(t,e){const n=Ao(t,e);dl(t,[...n,yo(e)])}const Nu="$comments";function hl(){const t=G(),e=p.useCallback(r=>t.subscribe(Nu,r),[t]),n=p.useCallback(()=>t.getComments(),[t]);return p.useSyncExternalStore(e,n)}function Do({authorId:t,placeholder:e="Add a comment…",autoFocus:n=!1,onSubmit:r,onCancel:o}){const[s,a]=p.useState(""),i=p.useRef(null),d=s.trim();function c(){const h=i.current;h&&(h.style.height="auto",h.style.height=`${h.scrollHeight}px`)}function f(h){a(h.target.value),c()}function u(h){h.preventDefault(),d&&(r(d),a(""),i.current&&(i.current.style.height=""))}return l.jsxs("form",{className:"be-comment-composer",onSubmit:u,children:[l.jsxs("div",{className:"be-comment-composer-input-row",children:[l.jsx(jn,{authorId:t,size:26}),l.jsx("textarea",{ref:i,className:"be-comment-composer-textarea",value:s,onChange:f,placeholder:e,rows:2,autoFocus:n,onKeyDown:h=>{h.key==="Enter"&&(h.metaKey||h.ctrlKey)?u(h):h.key==="Escape"&&o&&o()}})]}),l.jsxs("div",{className:"be-comment-composer-actions",children:[o&&l.jsx("button",{type:"button",className:"be-comment-composer-cancel",onClick:o,children:"Cancel"}),l.jsxs("button",{type:"submit",className:"be-comment-composer-submit",disabled:!d,children:[l.jsx(ou,{size:13}),"Send"]})]})]})}function Fs({message:t,size:e=26}){return l.jsxs("div",{className:"be-comment-message",children:[l.jsx(jn,{authorId:t.authorId,size:e}),l.jsxs("div",{className:"be-comment-message-body",children:[l.jsxs("div",{className:"be-comment-message-header",children:[l.jsx("span",{className:"be-comment-message-author",children:t.authorId}),l.jsx("span",{className:"be-comment-message-time",children:Ua(t.createdAt)})]}),l.jsx("p",{className:"be-comment-message-text",children:t.text})]})]})}function Po({store:t,thread:e,authorId:n,onJumpToText:r}){const[o,s]=p.useState(!1),[a,i]=hr(),[d,...c]=e.messages;function f(u){ul(t,e.id,{authorId:n,text:u}),s(!1)}return l.jsxs("div",{className:`be-comment-thread${e.resolved?" be-comment-thread-resolved":""}${a===e.id?" be-comment-thread-hovered":""}`,onMouseEnter:()=>i(e.id),onMouseLeave:()=>i(null),children:[l.jsx("div",{onClick:r?()=>r(e.id):void 0,style:r?{cursor:"pointer"}:void 0,children:l.jsx(Fs,{message:d})}),c.length>0&&l.jsx("div",{className:"be-comment-thread-replies",children:c.map(u=>l.jsx(Fs,{message:u,size:22},u.id))}),o?l.jsx(Do,{authorId:n,placeholder:"Reply…",autoFocus:!0,onSubmit:f,onCancel:()=>s(!1)}):l.jsxs("div",{className:"be-comment-thread-actions",children:[n&&l.jsxs("button",{type:"button",onClick:()=>s(!0),children:[l.jsx(Ga,{size:13}),"Reply"]}),l.jsxs("button",{type:"button",onClick:()=>pl(t,e.id,!e.resolved),children:[l.jsx(ru,{size:13}),e.resolved?"Reopen":"Resolve"]}),l.jsx("button",{type:"button",className:"be-comment-thread-delete",onClick:()=>fl(t,e.id),"aria-label":"Delete comment",title:"Delete comment",children:l.jsx(On,{size:13})})]})]})}function ml(t,e){var n,r,o;for(const s of e.anchorRunIds??[]){const a=document.querySelector(`[data-run-id="${s}"]`);if(a)return a}for(const s of t.getAllRunIds())if((o=(r=(n=t.getRun(s))==null?void 0:n.marks)==null?void 0:r.commentIds)!=null&&o.includes(e.id)){const a=document.querySelector(`[data-run-id="${s}"]`);if(a)return a}return null}function Mu(t,e,n){const r=t.getComment(e);if(!r)return;const o=ml(t,r);o&&(o.scrollIntoView({behavior:"smooth",block:"center"}),n(e),setTimeout(()=>n(s=>s===e?null:s),1500))}function bl({authorId:t}){const e=G(),n=hl(),[,r]=hr(),o=p.useRef(null),[s,a]=p.useState({}),i=[...n].sort((c,f)=>Number(c.resolved)-Number(f.resolved));p.useLayoutEffect(()=>{function c(){const f=o.current;if(!f)return;const u=f.getBoundingClientRect().top,h={};let m=-1/0;for(const g of i){const x=ml(e,g),y=x?x.getBoundingClientRect().top-u:Number.isFinite(m)?m+90:0,k=Math.max(m,y);h[g.id]=k,m=k+90}a(h)}return c(),window.addEventListener("scroll",c,!0),window.addEventListener("resize",c),()=>{window.removeEventListener("scroll",c,!0),window.removeEventListener("resize",c)}},[n,e]);const d=Object.values(s).reduce((c,f)=>Math.max(c,f+120),0);return i.length===0?null:l.jsx("div",{className:"be-comments-panel",contentEditable:!1,children:l.jsx("div",{ref:o,className:"be-comments-panel-list",style:{height:d},children:i.map(c=>l.jsx("div",{className:"be-comments-panel-item",style:{top:s[c.id]??0},children:l.jsx(Po,{store:e,thread:c,authorId:t,onJumpToText:f=>Mu(e,f,r)})},c.id))})})}class gl{constructor(){this._types=new Map}register(e,n){this._types.set(e,n)}get(e){return this._types.get(e)}isLeaf(e){var n;return!!((n=this._types.get(e))!=null&&n.isLeaf)}listSlashCommands(){const e=[];for(const n of this._types.values())n.slashCommand&&e.push(n.slashCommand),n.slashCommands&&e.push(...n.slashCommands);return e}listHtmlMatchers(){return[...this._types.values()].filter(e=>e.fromHTML)}}function xl(){return new gl}class yl{constructor(){this._types=new Map}register(e,n){this._types.set(e,n)}unregister(e){this._types.delete(e)}get(e){return this._types.get(e)}listHtmlMatchers(){return[...this._types.values()].filter(e=>e.fromHTML)}listSlashCommands(){const e=[];for(const n of this._types.values())n.slashCommand&&e.push(n.slashCommand),n.slashCommands&&e.push(...n.slashCommands);return e}listAtCommands(){const e=[];for(const n of this._types.values())n.atCommand&&e.push(n.atCommand),n.atCommands&&e.push(...n.atCommands);return e}}function kl(){return new yl}function be(t){const e=G(),n=p.useCallback(o=>e.subscribe(t,o),[e,t]),r=p.useCallback(()=>e.getBlock(t),[e,t]);return p.useSyncExternalStore(n,r)}function It(t){const e=G(),n=p.useCallback(o=>e.subscribe(t,o),[e,t]),r=p.useCallback(()=>e.getRun(t),[e,t]);return p.useSyncExternalStore(n,r)}const vl="​",Ou=/​/g;function at(t){return(t??"").replace(Ou,"")}function Us(t){return at(t.textContent)}function Lu(t,e){var i;const n=new Map(e.map(d=>[d.id,d])),r=new Set,o=[];let s=!0;for(const d of t.childNodes){const c=d.nodeType===1?(i=d.dataset)==null?void 0:i.runId:void 0;if(c&&n.has(c)){r.add(c);const u=n.get(c);if(u.type!=="text"){o.push(u);continue}const h=Us(d);o.push(h===u.value?u:{...u,value:h});continue}s=!1;const f=Us(d);f&&o.push({id:_(),type:"text",value:f,marks:{}})}if(e.some(d=>!r.has(d.id))&&(s=!1),o.length!==e.length&&(s=!1),s){for(let d=0;d<o.length;d+=1)if(o[d].id!==e[d].id){s=!1;break}}const a=!s||o.some((d,c)=>d!==e[c]);return{runs:o,changed:a,onlyValueChanges:s}}function wl(t){return t?t.type!=="text"?!1:(t.value??"")==="":!0}function Oe(t,e){return!e||e.length===0?!0:e.every(n=>wl(t.getRun(n)))}function Ln(t,e){var o,s;if(!e)return!1;const n=e.contentIds.length>0,r=(((s=(o=e.props)==null?void 0:o.titleRunIds)==null?void 0:s.length)??0)>0;return!n&&!r}function Il(t,e){const n=document.querySelector(`[data-run-id="${t}"]`);if(!n)return;n.focus();const r=n.firstChild,o=document.createRange();if(r&&r.nodeType===3){const a=Math.max(0,Math.min(e,r.length));o.setStart(r,a),o.setEnd(r,a)}else o.selectNodeContents(n),o.collapse(e<=0);const s=window.getSelection();s==null||s.removeAllRanges(),s==null||s.addRange(o)}function Cl(t,e){requestAnimationFrame(()=>{const n=document.querySelector(`[data-run-id="${t}"]`);if(!n)return;n.focus();const r=document.createRange();r.selectNodeContents(n),r.collapse(e);const o=window.getSelection();o==null||o.removeAllRanges(),o==null||o.addRange(r)})}function ye(t){Cl(t,!1)}function xr(t){Cl(t,!0)}function Ze(t,e){requestAnimationFrame(()=>Il(t,e))}function Vs(t,e){Il(t,e)}const Au='button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';function pt({isOpen:t,onClose:e,title:n,size:r="default",variant:o="dialog",children:s}){const a=p.useRef(null),i=p.useRef(null);if(p.useEffect(()=>{if(!t)return;const c=f=>{f.key==="Escape"&&e()};return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[t,e]),p.useEffect(()=>{var c,f,u;if(t){i.current=document.activeElement;const h=a.current;(c=(h==null?void 0:h.querySelector(Au))??h)==null||c.focus();return}(u=(f=i.current)==null?void 0:f.focus)==null||u.call(f),i.current=null},[t]),!t)return null;const d=o==="sheet";return l.jsx("div",{className:`be-modal-overlay${d?" be-modal-overlay-sheet":""}`,onMouseDown:c=>{c.target===c.currentTarget&&e()},children:l.jsxs("div",{ref:a,className:`be-modal${r==="large"?" be-modal-large":""}${d?" be-modal-sheet":""}`,role:"dialog","aria-modal":"true","aria-label":n,tabIndex:-1,children:[n&&l.jsx("div",{className:"be-modal-title",children:n}),s]})})}function Sl({isOpen:t,initialHref:e,initialTarget:n,hasExistingLink:r,onSave:o,onRemove:s,onClose:a}){const[i,d]=p.useState(""),[c,f]=p.useState("_self");p.useEffect(()=>{t&&(d(e),f(n))},[t]);const u=i.trim(),h=p.useCallback(m=>{m.preventDefault(),u&&o(u,c)},[u,c,o]);return l.jsx(pt,{isOpen:t,onClose:a,title:r?"Edit link":"Add link",children:l.jsxs("form",{onSubmit:h,children:[l.jsxs("label",{className:"be-modal-field",children:[l.jsx("span",{children:"URL"}),l.jsx("input",{type:"text",value:i,onChange:m=>d(m.target.value),placeholder:"https://example.com",autoFocus:!0})]}),l.jsxs("label",{className:"be-modal-field",children:[l.jsx("span",{children:"Open in"}),l.jsxs("select",{value:c,onChange:m=>f(m.target.value),children:[l.jsx("option",{value:"_self",children:"Same tab"}),l.jsx("option",{value:"_blank",children:"New tab"})]})]}),l.jsxs("div",{className:"be-modal-actions",children:[r&&l.jsx("button",{type:"button",className:"be-modal-delete",onClick:s,children:"Remove link"}),l.jsx("button",{type:"button",className:"be-modal-cancel",onClick:a,children:"Cancel"}),l.jsx("button",{type:"submit",className:"be-modal-save",disabled:!u,children:"Save"})]})]})})}const tn=8;function yr(t,e){const n=Math.max(tn,window.innerWidth-e-tn);return Math.min(Math.max(t,tn),n)}function Du(t,e){const n=Math.max(tn,window.innerHeight-e-tn);return Math.min(Math.max(t,tn),n)}function An(t,e,n,r){const[o,s]=p.useState(null);return p.useLayoutEffect(()=>{if(n==null||r==null){s(null);return}s({top:n,left:r})},[n,r]),p.useLayoutEffect(()=>{if(!e||!t.current||!o)return;const a=t.current.getBoundingClientRect(),i=yr(o.left,a.width),d=Du(o.top,a.height);(i!==o.left||d!==o.top)&&s({top:d,left:i})},[e,t,o]),o}function Pu({containerRef:t,store:e}){var v;const[n,r]=p.useState(null),[o,s]=p.useState(!1),a=p.useRef(null),i=p.useRef(null),d=p.useCallback(()=>{a.current&&(clearTimeout(a.current),a.current=null)},[]),c=p.useCallback(()=>{d(),a.current=setTimeout(()=>{r(w=>o?w:null)},250)},[d,o]);p.useEffect(()=>{const w=t.current;if(!w)return;const B=C=>{var O,S,L;const R=(S=(O=C.target).closest)==null?void 0:S.call(O,"[data-run-id]");if(!R||!w.contains(R))return;const E=R.dataset.runId,T=e.getRun(E);(L=T==null?void 0:T.marks)!=null&&L.link&&(d(),r($=>($==null?void 0:$.runId)===E?$:{runId:E,rect:R.getBoundingClientRect()}))},I=()=>c();return w.addEventListener("mouseover",B),w.addEventListener("mouseout",I),()=>{w.removeEventListener("mouseover",B),w.removeEventListener("mouseout",I)}},[t,e,d,c]),p.useEffect(()=>()=>d(),[d]);const f=p.useCallback(()=>s(!0),[]),u=p.useCallback(()=>{s(!1),r(null)},[]),h=p.useCallback((w,B)=>{if(!n)return;const I=e.getRun(n.runId);I&&(e.applyOperation(de(n.runId,{marks:{...I.marks,link:{href:w,target:B}}})),u())},[n,e,u]),m=p.useCallback(()=>{if(!n)return;const w=e.getRun(n.runId);if(!w)return;const B={...w.marks};delete B.link,e.applyOperation(de(n.runId,{marks:B})),u()},[n,e,u]),g=n&&e.getRun(n.runId),x=(v=g==null?void 0:g.marks)==null?void 0:v.link,y=!!(n&&x&&!o),k=An(i,y,n?n.rect.bottom+6:null,n?n.rect.left:null);return l.jsxs(l.Fragment,{children:[y&&k?De.createPortal(l.jsxs("div",{ref:i,className:"be-link-hover-card",contentEditable:!1,style:{position:"fixed",top:k.top,left:k.left},onMouseEnter:d,onMouseLeave:c,children:[l.jsx("a",{className:"be-link-hover-card-url",href:x.href,target:x.target==="_blank"?"_blank":"_self",rel:"noopener noreferrer",children:x.href}),l.jsx("button",{type:"button",className:"be-link-hover-card-btn",onClick:f,"aria-label":"Edit link",title:"Edit link",children:l.jsx(qa,{size:13})}),l.jsx("button",{type:"button",className:"be-link-hover-card-btn",onClick:m,"aria-label":"Remove link",title:"Remove link",children:l.jsx(wt,{size:13})})]}),document.body):null,l.jsx(Sl,{isOpen:o,initialHref:(x==null?void 0:x.href)??"",initialTarget:(x==null?void 0:x.target)??"_self",hasExistingLink:!!x,onSave:h,onRemove:m,onClose:u})]})}function jl({title:t,onClose:e}){return l.jsxs("div",{className:"be-comment-popover-header",children:[l.jsx("span",{className:"be-comment-popover-title",children:t}),l.jsx("button",{type:"button",className:"be-comment-popover-close",onClick:e,"aria-label":"Close",children:l.jsx(wt,{size:14})})]})}function $u({containerRef:t,store:e,authorId:n}){const[r,o]=p.useState(null),[s,a]=p.useState(!1),i=p.useRef(null),d=p.useRef(null),[,c]=hr(),f=p.useCallback(()=>{i.current&&(clearTimeout(i.current),i.current=null)},[]),u=p.useCallback(()=>{f(),i.current=setTimeout(()=>{o(y=>s?y:null)},250)},[f,s]);p.useEffect(()=>{const y=t.current;if(!y)return;const k=I=>{var E,T,O;const C=(E=I==null?void 0:I.closest)==null?void 0:E.call(I,"[data-run-id]");if(!C||!y.contains(C))return null;const R=(O=(T=e.getRun(C.dataset.runId))==null?void 0:T.marks)==null?void 0:O.commentIds;return R!=null&&R.length?{runEl:C,commentIds:R}:null},v=I=>{const C=k(I.target);C&&(f(),o(R=>R&&R.runEl===C.runEl?R:{rect:C.runEl.getBoundingClientRect(),commentIds:C.commentIds,runEl:C.runEl}))},w=()=>u(),B=I=>{const C=k(I.target);if(!C){a(!1),o(null);return}f(),a(!0),o({rect:C.runEl.getBoundingClientRect(),commentIds:C.commentIds,runEl:C.runEl})};return y.addEventListener("mouseover",v),y.addEventListener("mouseout",w),y.addEventListener("click",B),()=>{y.removeEventListener("mouseover",v),y.removeEventListener("mouseout",w),y.removeEventListener("click",B)}},[t,e,f,u]),p.useEffect(()=>{if(!r)return;const y=v=>{var w,B;(w=d.current)!=null&&w.contains(v.target)||(B=t.current)!=null&&B.contains(v.target)||(a(!1),o(null))},k=v=>{v.key==="Escape"&&(a(!1),o(null))};return document.addEventListener("mousedown",y),document.addEventListener("keydown",k),()=>{document.removeEventListener("mousedown",y),document.removeEventListener("keydown",k)}},[r,t]),p.useEffect(()=>()=>f(),[f]),p.useEffect(()=>{var y;c(((y=r==null?void 0:r.commentIds)==null?void 0:y[0])??null)},[r,c]);const h=p.useCallback(()=>{a(!1),o(null)},[]),m=!!r,g=An(d,m,r?r.rect.bottom+6:null,r?r.rect.left:null);if(!m||!g)return null;const x=r.commentIds.map(y=>e.getComment(y)).filter(Boolean);return x.length===0?null:De.createPortal(l.jsxs("div",{ref:d,className:"be-comment-popover",contentEditable:!1,style:{position:"fixed",top:g.top,left:g.left},onMouseEnter:f,onMouseLeave:u,children:[l.jsx(jl,{title:`Comments (${x.length})`,onClose:h}),x.map(y=>l.jsx(Po,{store:e,thread:y,authorId:n},y.id))]}),document.body)}function Ys(t,e){const n=t==null?void 0:t.parentElement;if(!n||!n.hasAttribute("data-placeholder"))return;e.length===0||e.every(wl)?n.setAttribute("data-empty",""):n.removeAttribute("data-empty")}function zu(t={}){return{fontWeight:t.bold?"bold":void 0,fontStyle:t.italic?"italic":void 0,textDecoration:[(t.underline||t.link)&&"underline",t.strike&&"line-through"].filter(Boolean).join(" ")||void 0,verticalAlign:t.subscript?"sub":t.superscript?"super":void 0,fontSize:t.subscript||t.superscript?"smaller":void 0,color:t.color||(t.link?"var(--noteloom-accent)":void 0),backgroundColor:t.highlight||void 0,cursor:t.link?"pointer":void 0}}function Hu(t,e){const n=t.childNodes.length===1?t.firstChild:null;n&&n.nodeType===3?n.nodeValue!==e&&(n.nodeValue=e):t.textContent=e}function Fu({id:t,host:e,onValueSynced:n}){const r=It(t),[o]=hr();return p.useLayoutEffect(()=>{var f,u,h,m,g;if(!e||!r)return;const s=r.value??"";(at(e.textContent)!==s||s===""&&e.textContent==="")&&Hu(e,s===""?vl:s);const d=zu(r.marks);e.style.fontWeight=d.fontWeight??"",e.style.fontStyle=d.fontStyle??"",e.style.textDecoration=d.textDecoration??"",e.style.verticalAlign=d.verticalAlign??"",e.style.fontSize=d.fontSize??"",e.style.color=d.color??"",e.style.backgroundColor=d.backgroundColor??"",e.style.cursor=d.cursor??"",e.classList.toggle("be-comment-highlight",(((u=(f=r.marks)==null?void 0:f.commentIds)==null?void 0:u.length)??0)>0),e.classList.toggle("be-comment-highlight-active",!!o&&!!((m=(h=r.marks)==null?void 0:h.commentIds)!=null&&m.includes(o)));const c=(g=r.marks)==null?void 0:g.link;e.title=c!=null&&c.href?`${c.href} — Ctrl+Click to open`:"",e.onclick=c!=null&&c.href?x=>{!x.ctrlKey&&!x.metaKey||(x.preventDefault(),window.open(c.href,c.target==="_blank"?"_blank":"_self","noopener,noreferrer"))}:null,n==null||n()},[e,r,n,o]),null}function Ks(t,e,n,r){var u,h,m;const o=(u=window.getSelection)==null?void 0:u.call(window);if(!o||!o.isCollapsed||o.rangeCount===0)return null;const{anchorNode:s,anchorOffset:a}=o;if(!s||!t.contains(s))return null;const i=g=>{const x=e.indexOf(g);if(x===-1)return null;const y=r?e[x-1]:e[x+1];if(!y)return null;const k=n(y);return k&&k.type!=="text"?y:null};if(s===t){const g=r?a-1:a,x=t.childNodes[g],y=(x==null?void 0:x.nodeType)===1?(h=x.dataset)==null?void 0:h.runId:void 0;if(!y||e.indexOf(y)===-1)return null;const k=n(y);return k&&k.type!=="text"?y:null}const d=s.nodeType===1?s:s.parentElement,c=(m=d==null?void 0:d.closest)==null?void 0:m.call(d,"[data-run-id]");return!c||!t.contains(c)||!(r?a===0:a===(s.textContent??"").length)?null:i(c.getAttribute("data-run-id"))}function Ws(t,e,n){var d,c;const r=(d=window.getSelection)==null?void 0:d.call(window);if(!r||r.isCollapsed||r.rangeCount===0)return null;const o=r.getRangeAt(0);if(o.startContainer!==o.endContainer||!t.contains(o.startContainer)||o.endOffset!==o.startOffset+1)return null;const s=o.startContainer.childNodes[o.startOffset],a=(s==null?void 0:s.nodeType)===1?(c=s.dataset)==null?void 0:c.runId:void 0;if(!a||e.indexOf(a)===-1)return null;const i=n(a);return i&&i.type!=="text"?a:null}function qs(t,e,n){var i;if(e===t)return{childIndex:n,charOffset:null};const r=e.nodeType===1?e:e.parentElement,o=(i=r==null?void 0:r.closest)==null?void 0:i.call(r,"[data-run-id]");if(!o||!t.contains(o))return null;const s=Array.prototype.indexOf.call(t.childNodes,o),a=e===o?n===0?0:(o.textContent??"").length:n;return{childIndex:s,charOffset:a}}function Uu(t,e,n,r){const o=qs(t,r.startContainer,r.startOffset),s=qs(t,r.endContainer,r.endOffset);if(!o||!s)return null;const a=Array.from(t.childNodes).filter(f=>{var u;return f.nodeType===1&&((u=f.dataset)==null?void 0:u.runId)&&e.indexOf(f.dataset.runId)!==-1});let i=!1;const d=[];let c=null;return a.forEach((f,u)=>{const h=f.dataset.runId,m=n(h);if(!m)return;const g=u<o.childIndex,x=s.charOffset===null?u>=s.childIndex:u>s.childIndex;if(g||x){d.push(m);return}const y=o.charOffset!==null&&u===o.childIndex,k=s.charOffset!==null&&u===s.childIndex;if(m.type!=="text"){i=!0,c===null&&(c=d.length);return}const v=m.value??"";if(y&&k){const w=v.slice(0,o.charOffset)+v.slice(s.charOffset);w&&d.push({...m,value:w}),c=d.length}else if(y){const w=v.slice(0,o.charOffset);w&&d.push({...m,value:w}),c===null&&(c=d.length)}else if(k){const w=v.slice(s.charOffset);w&&d.push({id:_(),type:"text",value:w,marks:m.marks})}}),i?{nextRuns:d,insertionIndex:c??d.length}:null}function Vu(t){var s;const e=(s=window.getSelection)==null?void 0:s.call(window);if(!e||!e.isCollapsed)return!1;const n=t.firstChild;if(!n)return!0;if(e.anchorNode===t)return e.anchorOffset===0;let r=n;for(;r&&r.firstChild;)r=r.firstChild;if(e.anchorNode!==r&&e.anchorNode!==n)return!1;const o=r.nodeType===3&&r.textContent===vl?1:0;return e.anchorOffset<=o}function Yu(t){var s;const e=(s=window.getSelection)==null?void 0:s.call(window);if(!e||!e.isCollapsed)return!1;const n=t.lastChild;if(!n)return!0;if(e.anchorNode===t)return e.anchorOffset>=t.childNodes.length;let r=n;for(;r&&r.lastChild;)r=r.lastChild;if(e.anchorNode!==r&&e.anchorNode!==n)return!1;const o=r.nodeType===3?(r.textContent??"").length:0;return e.anchorOffset>=o}function Xs(t,e,n){const r=t.getBlock(e),o=t.getBlock(r==null?void 0:r.parentId);if(!o)return null;const s=o.contentIds.indexOf(e),a=n==="backward"?s-1:s+1;if(a<0||a>=o.contentIds.length)return null;const i=o.contentIds[a];return Ln(t,t.getBlock(i))?i:null}function Ku({id:t,blockId:e,host:n,inlineRegistry:r,onValueSynced:o}){const s=It(t);if(!s)return null;if(s.type==="text")return l.jsx(Fu,{id:t,host:n,onValueSynced:o});const a=r==null?void 0:r.get(s.type);if(!a)return process.env.NODE_ENV!=="production"&&console.warn(`[block-editor] No inline type registered for "${s.type}" (run: ${t})`),null;const i=a.component;return l.jsx(i,{id:t,blockId:e})}function Wu(t,e,n){let r=t.get(n);if(!r){r=document.createElement("span"),r.dataset.runId=n;const o=e.getRun(n);o&&o.type!=="text"&&r.setAttribute("contenteditable","false"),t.set(n,r)}return r}function ft({blockId:t,runIds:e,dir:n="auto",onEnter:r,onBackspaceAtStart:o,onDeleteAtEnd:s,onArrowUp:a,onArrowDown:i,onTab:d,onShiftTab:c,onAutoformat:f}){const u=G(),h=Ke(),m=Fa(),{getSelectedBlockId:g,setSelectedBlockId:x}=ut(),y=p.useRef(null),k=p.useRef(!1),v=p.useRef(new Map);p.useLayoutEffect(()=>{const S=y.current;if(!S)return;const L=new Set(e);for(const[Y,K]of v.current)L.has(Y)||(K.remove(),v.current.delete(Y));let $=null;for(const Y of e){const K=v.current.get(Y);if(!K)continue;const Q=$?$.nextSibling:S.firstChild;Q!==K&&S.insertBefore(K,Q),$=K}},[e]);const w=p.useCallback(()=>{if(k.current)return;const S=y.current;if(!S)return;const L=e.map(Q=>u.getRun(Q)).filter(Boolean),{runs:$,changed:Y,onlyValueChanges:K}=Lu(S,L);if(Y){if(K){if($.forEach((Q,D)=>{Q!==L[D]&&u.applyOperation(de(Q.id,{value:Q.value}))}),f!=null&&f($))return}else u.applyOperation(Me(t,$.length?$:[{id:_(),type:"text",value:"",marks:{}}]));Ys(S,$)}},[u,t,e,f]),B=p.useCallback(()=>{Ys(y.current,e.map(S=>u.getRun(S)).filter(Boolean))},[u,e]),I=p.useCallback(()=>{k.current=!0},[]),C=p.useCallback(()=>{k.current=!1,w()},[w]),R=p.useCallback(S=>{const $=e.map(Y=>u.getRun(Y)).filter(Boolean).filter(Y=>Y.id!==S);u.applyOperation(Me(t,$.length?$:[{id:_(),type:"text",value:"",marks:{}}]))},[u,t,e]),E=p.useCallback(S=>{g()===S?(u.applyOperation(ee(S)),x(null)):x(S)},[u,g,x]),T=p.useCallback(S=>{var ce,ke,he,U;if(k.current)return;if(S.target instanceof Node){const ae=S.target.nodeType===1?S.target:S.target.parentElement;if((ce=ae==null?void 0:ae.closest)!=null&&ce.call(ae,'[contenteditable="false"]'))return}const L=S.inputType??"",$=L.startsWith("delete"),Y=L==="insertText"||L==="insertReplacementText";if(!$&&!Y)return;const K=y.current;if(!K)return;const Q=(ke=S.getTargetRanges)==null?void 0:ke.call(S),D=(he=window.getSelection)==null?void 0:he.call(window),F=(Q==null?void 0:Q[0])??(D!=null&&D.rangeCount?D.getRangeAt(0):null);if(!F||!K.contains(F.startContainer)||!K.contains(F.endContainer))return;const re=Uu(K,e,ae=>u.getRun(ae),F);if(!re)return;S.preventDefault();let{nextRuns:H,insertionIndex:ne}=re,se=null,oe=!1;if(Y&&S.data){const ae={id:_(),type:"text",value:S.data,marks:{}};H=[...H.slice(0,ne),ae,...H.slice(ne)],se=ae.id,oe=!1}else ne>0?(se=(U=H[ne-1])==null?void 0:U.id,oe=!1):H.length>0&&(se=H[0].id,oe=!0);const ge=H.length?H:[{id:_(),type:"text",value:"",marks:{}}];u.applyOperation(Me(t,ge));const Re=se??ge[0].id;oe?xr(Re):ye(Re)},[u,t,e]);p.useEffect(()=>{const S=y.current;if(S)return S.addEventListener("beforeinput",T),()=>S.removeEventListener("beforeinput",T)},[T]);const O=p.useCallback(S=>{if(!k.current){if(S.key==="Enter"&&r){S.preventDefault(),r(S);return}if(S.key==="Backspace"){const L=y.current,$=L&&Ws(L,e,u.getRun.bind(u));if($){S.preventDefault(),R($);return}const Y=L&&Ks(L,e,u.getRun.bind(u),!0);if(Y){S.preventDefault(),R(Y);return}if(L&&Vu(L)){if(!Oe(u,e)){const Q=Xs(u,t,"backward");if(Q){S.preventDefault(),E(Q);return}}S.preventDefault(),o&&o(S)}return}if(S.key==="Delete"){const L=y.current,$=L&&Ws(L,e,u.getRun.bind(u));if($){S.preventDefault(),R($);return}const Y=L&&Ks(L,e,u.getRun.bind(u),!1);if(Y){S.preventDefault(),R(Y);return}if(L&&Yu(L)){const K=Xs(u,t,"forward");if(K){S.preventDefault(),E(K);return}s&&s(S)}return}if(S.key==="ArrowUp"&&a){S.preventDefault(),a(S);return}if(S.key==="ArrowDown"&&i){S.preventDefault(),i(S);return}S.key==="Tab"&&(S.shiftKey&&c?(S.preventDefault(),c(S)):!S.shiftKey&&d&&(S.preventDefault(),d(S)))}},[r,o,s,a,i,d,c,R,E,e,t,u]);return l.jsxs(l.Fragment,{children:[l.jsx("span",{ref:y,className:"be-editable",dir:n,contentEditable:!0,suppressContentEditableWarning:!0,onInput:w,onCompositionStart:I,onCompositionEnd:C,onKeyDown:O,children:e.map(S=>{const L=Wu(v.current,u,S);return De.createPortal(l.jsx(Ku,{id:S,blockId:t,host:L,inlineRegistry:h,onValueSynced:B},S),L)})}),l.jsx(Pu,{containerRef:y,store:u}),l.jsx($u,{containerRef:y,store:u,authorId:m})]})}function qu(t,e,n){const r=t.getBlock(e),o=r&&t.getBlock(r.parentId);if(!o)return null;const s=o.contentIds.indexOf(e),a=n==="up"?s-1:s+1;return a<0||a>=o.contentIds.length?null:o.contentIds[a]}function Rl(t,e,n){let r=e;for(;;){const o=qu(t,r,n);if(!o)return null;const s=n==="up"?kr(t,o):$o(t,o);if(s)return s;r=o}}function _e(t,e,n){const r=Rl(t,e,n);r&&ye(r)}function $o(t,e){var s;const n=t.getBlock(e);if(!n)return null;const r=((s=n.props)==null?void 0:s.titleRunIds)??n.contentIds;if(!r||r.length===0)return null;const o=r[0];return t.getRun(o)?o:$o(t,o)}function je(t,e){const n=$o(t,e);n&&ye(n)}function kr(t,e){var s;const n=t.getBlock(e);if(!n)return null;const r=((s=n.props)==null?void 0:s.titleRunIds)??n.contentIds;if(!r||r.length===0)return null;const o=r[r.length-1];return t.getRun(o)?o:kr(t,o)}function Gs(t,e){const n=kr(t,e);n&&ye(n)}function Xu(){var i,d;const t=(i=window.getSelection)==null?void 0:i.call(window);if(!t||t.rangeCount===0)return null;const e=t.getRangeAt(0);if(e.collapsed||e.startContainer!==e.endContainer)return null;const n=e.startContainer,r=n.nodeType===1?n:n.parentElement,o=(d=r==null?void 0:r.closest)==null?void 0:d.call(r,"[data-run-id]");if(!o)return null;const s=o.closest("[data-block-id]");if(!s)return null;const a=n.textContent??"";return{runId:o.getAttribute("data-run-id"),blockId:s.getAttribute("data-block-id"),startOffset:at(a.slice(0,e.startOffset)).length,endOffset:at(a.slice(0,e.endOffset)).length}}function Gu(t,e){var i,d;if((t==null?void 0:t.nodeType)!==1||((i=t.getAttribute)==null?void 0:i.call(t,"contenteditable"))!=="true")return null;const n=t.childNodes;if(n.length===0)return null;const r=e>=n.length,o=n[r?n.length-1:Math.max(0,e)],s=(o==null?void 0:o.nodeType)===1?(d=o.dataset)==null?void 0:d.runId:void 0;if(!s)return null;const a=o.closest("[data-block-id]");return a?{runId:s,blockId:a.getAttribute("data-block-id"),offset:r?at(o.textContent??"").length:0}:null}function Rn(t,e){var i;const n=Gu(t,e);if(n)return n;let r=(t==null?void 0:t.nodeType)===1?t:t==null?void 0:t.parentElement;const o=(i=r==null?void 0:r.closest)==null?void 0:i.call(r,"[data-run-id]");if(!o)return null;const s=o.closest("[data-block-id]");if(!s)return null;let a=at((t.textContent??"").slice(0,e)).length;if(t===o){a=0;for(let d=0;d<e&&d<o.childNodes.length;d+=1)a+=at(o.childNodes[d].textContent??"").length}return{runId:o.getAttribute("data-run-id"),blockId:s.getAttribute("data-block-id"),offset:a}}function lt(){var e;const t=(e=window.getSelection)==null?void 0:e.call(window);return!t||t.rangeCount===0||!t.isCollapsed?null:Rn(t.anchorNode,t.anchorOffset)}function ln(){var r;const t=(r=window.getSelection)==null?void 0:r.call(window);if(!t||t.rangeCount===0||t.isCollapsed)return null;const e=Rn(t.anchorNode,t.anchorOffset),n=Rn(t.focusNode,t.focusOffset);return!e||!n||e.blockId!==n.blockId?null:{blockId:e.blockId,startRunId:e.runId,startOffset:e.offset,endRunId:n.runId,endOffset:n.offset}}function rn(t){var u;const e=(u=window.getSelection)==null?void 0:u.call(window);if(!e||e.rangeCount===0||e.isCollapsed)return null;const n=Rn(e.anchorNode,e.anchorOffset),r=Rn(e.focusNode,e.focusOffset);if(!n||!r||n.blockId===r.blockId)return null;const o=t.getBlock(n.blockId),s=o&&t.getBlock(o.parentId);if(!s)return null;const a=s.contentIds,i=a.indexOf(n.blockId),d=a.indexOf(r.blockId);if(i===-1||d===-1)return null;const[c,f]=i<=d?[i,d]:[d,i];return{blockIds:a.slice(c,f+1),startBlockId:n.blockId,startRunId:n.runId,startOffset:n.offset,endBlockId:r.blockId,endRunId:r.runId,endOffset:r.offset}}function vr(t,e,n){const o=t.getBlock(e).parentId,a=t.getBlock(o).contentIds.indexOf(e)+1,{block:i,runs:d=[],subtreeBlocks:c=[]}=n(o);return t.applyOperation(me(i,o,a,{blocks:[i,...c],runs:d})),i.id}function nt(t,e,n){const r=vr(t,e,n);return je(t,r),r}function Ju(t,e,n){const{block:r,runs:o=[],subtreeBlocks:s=[]}=n(e);return t.applyOperation(me(r,e,0,{blocks:[r,...s],runs:o})),je(t,r.id),r.id}function Tl(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Zu(t,e,n){const r=t.findIndex(c=>c.id===e);if(r===-1)return null;const o=t[r],s=t.slice(0,r),a=t.slice(r+1);if(o.type==="text"){const c=o.value??"",f=c.slice(0,n),u=c.slice(n);f&&u?(s.push({...o,value:f}),a.unshift({...o,id:_(),value:u})):u?a.unshift(o):s.push(o)}else n>0?s.push(o):a.unshift(o);const i=s.length?s:[{id:_(),type:"text",value:"",marks:{}}],d=a.length?a:[{id:_(),type:"text",value:"",marks:{}}];return{leftRuns:i,rightRuns:d}}function cn(t,e,n,r){const o=t.getBlock(e),s=t.getBlock(o.parentId),a=s.contentIds.indexOf(e)+1;return Bl(t,e,n,r,{insertParentId:s.id,insertIndex:a,fallback:()=>nt(t,e,r)})}function El(t,e,n,r){return Bl(t,e,n,r,{insertParentId:e,insertIndex:0,fallback:()=>Ju(t,e,r)})}function Bl(t,e,n,r,{insertParentId:o,insertIndex:s,fallback:a}){const i=lt();if(!i||i.blockId!==e)return a();const d=n.map(y=>t.getRun(y)).filter(Boolean),c=Zu(d,i.runId,i.offset);if(!c)return a();const{leftRuns:f,rightRuns:u}=c,{block:h,runs:m=u,subtreeBlocks:g=[]}=r(o,u),x=f.length?f:[{id:_(),type:"text",value:"",marks:{}}];return Tl(t,[Me(e,x),me(h,o,s,{blocks:[h,...g],runs:m})]),je(t,h.id),h.id}function Qu(t){var e;return((e=t==null?void 0:t.props)==null?void 0:e.titleRunIds)??(t==null?void 0:t.contentIds)??[]}function ep(t){var e,n;return!!((e=t==null?void 0:t.props)!=null&&e.titleRunIds)&&(((n=t.contentIds)==null?void 0:n.length)??0)>0}function tp(t,e,n){const o=t.getBlock(e).parentId,a=t.getBlock(o).contentIds.indexOf(e),{block:i,runs:d=[],subtreeBlocks:c=[]}=n(o);return Tl(t,[ee(e),me(i,o,a,{blocks:[i,...c],runs:d})]),je(t,i.id),i.id}function Be(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o},s){const a=t.getRun(n),i=(a==null?void 0:a.value)??"",d=i.slice(0,r)+i.slice(o),c=t.getBlock(e),f=Qu(c);return f.length===1&&f[0]===n&&d===""&&!ep(c)?tp(t,e,s):(t.applyOperation(de(n,{value:d})),nt(t,e,s))}function te(t,e={}){return function(r,o){const s=_(),a=o!=null&&o.length?o:[{id:_(),type:"text",value:"",marks:{}}];return{block:{id:s,type:t,parentId:r,contentIds:a.map(i=>i.id),props:e},runs:a}}}function dn(t){const e=t.getRootId(),n=t.getBlock(e);if(!n||n.contentIds.length>0)return null;const{block:r,runs:o}=te("paragraph")(e);return t.applyOperation(me(r,e,0,{blocks:[r],runs:o})),r.id}const np=new Set(["callout"]),Js=new Set(["paragraph","heading","blockquote"]);function _l(t,e){return t===e||Js.has(t)&&Js.has(e)}function Dn(t,e){const n=t.getBlock(e);if(!n)return null;const r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=n.contentIds.length===0||n.contentIds.length===1&&rp(t,n.contentIds[0]);if(o<=0){if(!s)return null;if(r.contentIds.length>1)return Zt(t,[ee(e)]),t.getBlock(r.id).contentIds[0];if(np.has(r.type))return op(t,r);if(n.type==="paragraph")return null;const{block:c,runs:f}=te("paragraph")(r.id);return Zt(t,[me(c,r.id,o,{blocks:[c],runs:f}),ee(e)]),c.id}const a=r.contentIds[o-1],i=t.getBlock(a);if(s)return Zt(t,[ee(e)]),a;if(Ln(t,i))return Zt(t,[ee(a)]),e;if(!i||!_l(i.type,n.type))return null;const d=[...i.contentIds,...n.contentIds];return Zt(t,[nn(a,d),nn(e,[]),ee(e)]),a}function rp(t,e){const n=t.getRun(e);return!n||(n.value??"")===""}function op(t,e){const n=t.getBlock(e.parentId);if(!n)return null;const r=n.contentIds.indexOf(e.id),o=r>0?n.contentIds[r-1]:null,s=r!==-1&&r<n.contentIds.length-1?n.contentIds[r+1]:null;Zt(t,[ee(e.id)]);const a=dn(t);return o??s??a}function Zt(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function un(t,e,n,r){if(!e||e===n)return;const o=kr(t,e);if(o){ye(o);return}r(e),requestAnimationFrame(()=>{var s;(s=document.querySelector(`[data-block-id="${e}"]`))==null||s.focus()})}function it(t,e){var r,o;if(!e)return"auto";if((r=e.props)!=null&&r.dir)return e.props.dir;const n=t.getBlock(t.getRootId());return((o=n==null?void 0:n.props)==null?void 0:o.dir)??"auto"}function zo(t,e,n,r,o,s){const a=t.getBlock(e),d=t.getBlock(a.parentId).contentIds.indexOf(e),c="titleRunIds"in r,f="titleRunIds"in(a.props??{}),u=s?!s.isLeaf(a.type)&&a.contentIds.length>0:!1,h=s?!s.isLeaf(n):!1,m=[];if(u&&!h&&a.contentIds.forEach((g,x)=>m.push(ct(g,a.parentId,d+1+x))),m.push(mo(e,n,r)),c)m.push(J(e,{titleRunIds:o})),!f&&!u&&m.push(nn(e,[]));else{const g=u&&h?a.contentIds:[];m.push(nn(e,[...g,...o]))}return{newBlockId:e,ops:m}}function sp(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}const ap=[{re:/^(#{1,3})[  ]$/,type:"heading",props:t=>({level:t[1].length})},{re:/^[-*][  ]$/,type:"listItem",props:()=>({ordered:!1,titleRunIds:[]})},{re:/^\d+\.[  ]$/,type:"listItem",props:()=>({ordered:!0,titleRunIds:[]})},{re:/^\[\][  ]$/,type:"listItem",props:()=>({ordered:!1,checked:!1,titleRunIds:[]})},{re:/^>[  ]$/,type:"blockquote",props:()=>({})},{re:/^```$/,type:"code",props:()=>({language:"plaintext"})}];function lp(t,e,n){if(n.length!==1||n[0].type!=="text")return!1;const r=n[0].value??"";for(const o of ap){const s=o.re.exec(r);if(!s)continue;const a=r.slice(s[0].length),{ops:i}=zo(t,e,o.type,o.props(s),[n[0].id]);return sp(t,[de(n[0].id,{value:a}),...i]),xr(n[0].id),!0}return!1}const ip=new Set(["callout","toggleHeading"]);function cp({id:t}){const e=G(),n=be(t),{setSelectedBlockId:r}=ut(),o=p.useCallback(()=>{const h=e.getBlock(n==null?void 0:n.parentId),m=Oe(e,(n==null?void 0:n.contentIds)??[]),g=!!h&&h.contentIds[h.contentIds.length-1]===t;if(m&&g&&ip.has(h==null?void 0:h.type)){nt(e,h.id,te("paragraph"));return}cn(e,t,(n==null?void 0:n.contentIds)??[],te("paragraph"))},[e,t,n]),s=p.useCallback(()=>{var y,k;const h=e.getBlock(n==null?void 0:n.parentId),m=Oe(e,(n==null?void 0:n.contentIds)??[]),g=((y=h==null?void 0:h.contentIds)==null?void 0:y.length)===1&&h.contentIds[0]===t;if(m&&g&&(h==null?void 0:h.type)==="toggleHeading"){const v=((k=h.props)==null?void 0:k.titleRunIds)??[],w=v[v.length-1];w&&ye(w);return}const x=Dn(e,t);un(e,x,t,r)},[e,t,n,r]),a=p.useCallback(()=>_e(e,t,"up"),[e,t]),i=p.useCallback(()=>_e(e,t,"down"),[e,t]),d=p.useCallback(h=>lp(e,t,h),[e,t]),c=Ie("be-paragraph",n);if(!n)return null;const f=Oe(e,n.contentIds),u=it(e,n);return l.jsx("div",{className:c,"data-block-id":t,"data-empty":f?"":void 0,"data-placeholder":"Type '/' for commands",dir:u,children:l.jsx(ft,{blockId:t,runIds:n.contentIds,dir:u,onEnter:o,onBackspaceAtStart:s,onArrowUp:a,onArrowDown:i,onAutoformat:d})})}function Bt(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Ee(t){return Bt(t).replace(/"/g,"&quot;")}function ht(t,e){var o,s;if(!t)return"";if(t.type!=="text"){const a=(o=e==null?void 0:e.inlineRegistry)==null?void 0:o.get(t.type);return a?a.toHTML(t,e):Bt(t.value??"")}const n=t.marks??{};let r=Bt(t.value??"");if(n.code&&(r=`<code>${r}</code>`),n.bold&&(r=`<strong>${r}</strong>`),n.italic&&(r=`<em>${r}</em>`),n.underline&&(r=`<u>${r}</u>`),n.strike&&(r=`<s>${r}</s>`),n.subscript&&(r=`<sub>${r}</sub>`),n.superscript&&(r=`<sup>${r}</sup>`),n.color&&(r=`<span style="color:${Ee(n.color)}">${r}</span>`),n.highlight&&(r=`<span style="background-color:${Ee(n.highlight)}">${r}</span>`),(s=n.link)!=null&&s.href){const a=n.link.target==="_blank"?' target="_blank" rel="noopener noreferrer"':"";r=`<a href="${Ee(n.link.href)}"${a}>${r}</a>`}return r}function Ur(t,e){return(t??[]).map(n=>ht(n,e)).join("")}function Ct(t,e){var n;if(!t)return"";if(t.type!=="text"){const r=(n=e==null?void 0:e.inlineRegistry)==null?void 0:n.get(t.type);return r?r.toPlainText(t,e):t.value??""}return t.value??""}const dp={STRONG:"bold",B:"bold",EM:"italic",I:"italic",U:"underline",S:"strike",STRIKE:"strike",DEL:"strike",CODE:"code",SUB:"subscript",SUP:"superscript"};function Ye(t,e,n={}){const r=[],o=(s,a)=>{var c,f;if(s.nodeType===3){const u=s.textContent;u&&r.push({id:_(),type:"text",value:u,marks:{...a}});return}if(s.nodeType!==1)return;if(e!=null&&e.inlineRegistry)for(const u of e.inlineRegistry.listHtmlMatchers()){const h=u.fromHTML(s,e);if(h){r.push(h);return}}let i=a;const d=dp[s.tagName];d&&(i={...i,[d]:!0}),s.tagName==="A"&&s.getAttribute("href")&&(i={...i,link:{href:s.getAttribute("href"),target:s.getAttribute("target")==="_blank"?"_blank":"_self"}}),(c=s.style)!=null&&c.color&&(i={...i,color:s.style.color}),(f=s.style)!=null&&f.backgroundColor&&(i={...i,highlight:s.style.backgroundColor});for(const u of s.childNodes)o(u,i)};return o(t,n),r.length?r:[{id:_(),type:"text",value:"",marks:{}}]}function up(t,e){return`<p>${t.contentIds.map(r=>e.store.getRun(r)).map(r=>ht(r,e)).join("")}</p>`}function pp(t,e){return t.contentIds.map(n=>Ct(e.store.getRun(n),e)).join("")}function fp(t,e){if(t.tagName!=="P")return null;const n=Ye(t,e);return{block:{id:_(),type:"paragraph",parentId:null,contentIds:n.map(o=>o.id),props:{}},runs:n}}const Nl={component:cp,isLeaf:!0,defaultProps:{},toHTML:up,toPlainText:pp,fromHTML:fp,slashCommand:{label:"Text",icon:Eo,keywords:["paragraph","text","p"],run:(t,e)=>Be(t,e,te("paragraph"))}};function hp({id:t}){var m;const e=G(),n=be(t),{setSelectedBlockId:r}=ut(),o=p.useCallback(()=>{cn(e,t,(n==null?void 0:n.contentIds)??[],te("paragraph"))},[e,t,n]),s=p.useCallback(()=>{const g=Dn(e,t);un(e,g,t,r)},[e,t,r]),a=p.useCallback(()=>_e(e,t,"up"),[e,t]),i=p.useCallback(()=>_e(e,t,"down"),[e,t]),d=((m=n==null?void 0:n.props)==null?void 0:m.level)??3,c=Ie(`be-heading be-heading-${d}`,n);if(!n)return null;const f=`h${d}`,u=Oe(e,n.contentIds),h=it(e,n);return l.jsx(f,{className:c,"data-block-id":t,"data-empty":u?"":void 0,"data-placeholder":`Heading ${d}`,dir:h,children:l.jsx(ft,{blockId:t,runIds:n.contentIds,dir:h,onEnter:o,onBackspaceAtStart:s,onArrowUp:a,onArrowDown:i})})}const Vr={1:tl,2:nl,3:rl},mp={H1:1,H2:2,H3:3};function bp(t,e){var o;const n=((o=t.props)==null?void 0:o.level)??3,r=t.contentIds.map(s=>e.store.getRun(s));return`<h${n}>${r.map(s=>ht(s,e)).join("")}</h${n}>`}function gp(t,e){return t.contentIds.map(n=>Ct(e.store.getRun(n),e)).join("")}function xp(t,e){const n=mp[t.tagName];if(!n)return null;const r=Ye(t,e);return{block:{id:_(),type:"heading",parentId:null,contentIds:r.map(s=>s.id),props:{level:n}},runs:r}}const Ml={component:hp,isLeaf:!0,defaultProps:{level:3},toHTML:bp,toPlainText:gp,fromHTML:xp,slashCommands:[{label:"Heading 1",icon:Vr[1],keywords:["heading","h1","title"],run:(t,e)=>Be(t,e,te("heading",{level:1}))},{label:"Heading 2",icon:Vr[2],keywords:["heading","h2","subtitle"],run:(t,e)=>Be(t,e,te("heading",{level:2}))},{label:"Heading 3",icon:Vr[3],keywords:["heading","h3","title"],run:(t,e)=>Be(t,e,te("heading",{level:3}))}]},yp=[];function Ho(t){const e=G(),n=p.useCallback(o=>e.subscribe(t,o),[e,t]),r=p.useCallback(()=>{const o=e.getBlock(t);return o?o.contentIds:yp},[e,t]);return p.useSyncExternalStore(n,r)}class Ol extends p.Component{constructor(){super(...arguments);Ms(this,"state",{hasError:!1,nonce:0})}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(n,r){var o,s;process.env.NODE_ENV!=="production"&&console.error("[block-editor] a block failed to render; recovering by remounting it:",n,r),(s=(o=this.props).onError)==null||s.call(o,n,r),queueMicrotask(()=>this.setState(a=>({hasError:!1,nonce:a.nonce+1})))}render(){return this.state.hasError?null:l.jsx(p.Fragment,{children:this.props.children},this.state.nonce)}}const Fo=p.memo(function({id:e}){const n=be(e),r=dt();if(!n)return null;const o=r.get(n.type);if(!o)return process.env.NODE_ENV!=="production"&&console.warn(`[block-editor] No block type registered for "${n.type}" (id: ${e})`),null;const s=o.component;return l.jsx(Ol,{children:l.jsx(s,{id:e})})});function Ve(t,e,n){p.useEffect(()=>{if(!e)return;const r=Array.isArray(t)?t:[t],o=a=>{r.some(d=>d.current&&d.current.contains(a.target))||n()},s=a=>{a.key==="Escape"&&n()};return document.addEventListener("mousedown",o),document.addEventListener("keydown",s),()=>{document.removeEventListener("mousedown",o),document.removeEventListener("keydown",s)}},[e,n,t])}function wr(t,e,n,r){const o=p.useRef(!1),s=p.useRef(!1);p.useEffect(()=>{var f,u;if(!e){s.current=!1,o.current&&(o.current=!1,(u=(f=r==null?void 0:r.current)==null?void 0:f.focus)==null||u.call(f));return}o.current=!0;const a=t.current;if(!a)return;const i=()=>Array.from(a.querySelectorAll('[role="menuitem"]')),d=h=>{var x;const m=i();if(m.length===0)return;const g=(h%m.length+m.length)%m.length;(x=m[g])==null||x.focus()};s.current||(s.current=!0,d(0));const c=h=>{if(h.key==="Escape"){h.preventDefault(),n();return}const m=i(),g=m.indexOf(document.activeElement);g!==-1&&(h.key==="ArrowDown"?(h.preventDefault(),d(g+1)):h.key==="ArrowUp"?(h.preventDefault(),d(g-1)):h.key==="Home"?(h.preventDefault(),d(0)):h.key==="End"&&(h.preventDefault(),d(m.length-1)))};return a.addEventListener("keydown",c),()=>a.removeEventListener("keydown",c)})}const Zs="be-live-region";function kp(){if(typeof document>"u")return null;let t=document.getElementById(Zs);return t||(t=document.createElement("div"),t.id=Zs,t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),Object.assign(t.style,{position:"absolute",width:"1px",height:"1px",margin:"-1px",padding:"0",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:"0"}),document.body.appendChild(t),t)}function xe(t){const e=kp();e&&(e.textContent="",setTimeout(()=>{e.textContent=t},0))}const pn="💡",Ll="gray";function vp({icon:t=pn,color:e=Ll}={}){return function(r){const o=_(),{block:s,runs:a}=te("paragraph")(o);return{block:{id:o,type:"callout",parentId:r,contentIds:[s.id],props:{icon:t,color:e}},runs:a,subtreeBlocks:[s]}}}const Al=[{type:"paragraph",props:{},label:"Text",icon:Eo},{type:"heading",props:{level:1},label:"Heading 1",icon:tl},{type:"heading",props:{level:2},label:"Heading 2",icon:nl},{type:"heading",props:{level:3},label:"Heading 3",icon:rl},{type:"listItem",props:{ordered:!1,titleRunIds:[]},label:"Bulleted list",icon:al},{type:"listItem",props:{ordered:!0,titleRunIds:[]},label:"Numbered list",icon:ll},{type:"listItem",props:{ordered:!1,checked:!1,titleRunIds:[]},label:"To-do list",icon:No},{type:"listItem",props:{ordered:!1,collapsed:!1,titleRunIds:[]},label:"Toggle list",icon:Et},{type:"toggleHeading",props:{level:2,collapsed:!1,titleRunIds:[]},label:"Toggle heading",icon:Et},{type:"blockquote",props:{},label:"Quote",icon:ol},{type:"callout",props:{icon:pn},label:"Callout",icon:sl},{type:"code",props:{language:"plaintext"},label:"Code",icon:_o}],wp=new Set(Al.map(t=>t.type));function Uo(t){return wp.has(t)}function Ip(t,e){return t!=null&&t.props&&"titleRunIds"in t.props?t.props.titleRunIds:e&&!e.isLeaf(t==null?void 0:t.type)?[]:(t==null?void 0:t.contentIds)??[]}function Dl(t,e,n,r){const o=t.getBlock(n),s=Ip(o,e),a=[];if(r.type==="code")for(const f of s){const u=t.getRun(f);u!=null&&u.marks&&Object.keys(u.marks).length>0&&a.push(de(f,{marks:{}}))}const i={...r.props},{ops:d,newBlockId:c}=zo(t,n,r.type,i,s,e);return{ops:[...a,...d],newBlockId:c}}function Pl({onSelect:t,onClose:e,containerRef:n,menuClassName:r="be-block-gutter-menu",itemClassName:o="be-block-gutter-menu-item"}){const[s,a]=p.useState(!1),[i,d]=p.useState(null),c=p.useRef(null),f=p.useRef(null),u=p.useCallback(v=>{f.current=v,n&&(n.current=v)},[n]),h=p.useCallback(()=>{a(!1),e==null||e()},[e]);Ve([c,f],s,h),wr(f,s,h,c);const m=An(f,s,i==null?void 0:i.top,i?i.right+4:null),g=p.useCallback(()=>{var v;d(((v=c.current)==null?void 0:v.getBoundingClientRect())??null),a(!0)},[]),x=p.useCallback(v=>{t(v),h()},[t,h]),y=p.useCallback(v=>{v.key==="ArrowRight"&&!s&&(v.preventDefault(),g())},[s,g]),k=p.useCallback(v=>{v.key==="ArrowLeft"&&(v.preventDefault(),h())},[h]);return l.jsxs(l.Fragment,{children:[l.jsxs("button",{ref:c,type:"button",role:"menuitem",className:o,"aria-haspopup":"menu","aria-expanded":s,onClick:()=>s?h():g(),onKeyDown:y,children:[l.jsx(Et,{size:15})," Turn into"]}),s&&m&&De.createPortal(l.jsx("div",{ref:u,role:"menu","aria-label":"Turn into",className:r,style:{position:"fixed",top:m.top,left:m.left},onKeyDown:k,children:Al.map((v,w)=>{const B=v.icon;return l.jsxs("button",{type:"button",role:"menuitem",className:o,onClick:()=>x(v),children:[l.jsx(B,{size:15})," ",v.label]},`${v.type}-${w}`)})}),document.body)]})}function Vo(t,e){const n=t.getBlock(e);if(!n)return null;const r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=Nn(t,e),{block:a,runs:i,subtreeBlocks:d}=fr(s);return t.applyOperation(me(a,r.id,o+1,{blocks:[a,...d],runs:i})),je(t,a.id),a.id}function Yo(t,e){const n=t.getBlock(e),r=n&&t.getBlock(n.parentId);if(!r)return!1;const o=r.contentIds.indexOf(e);return o<=0?!1:(t.applyOperation(ct(e,r.id,o-1)),!0)}function Ko(t,e){const n=t.getBlock(e),r=n&&t.getBlock(n.parentId);if(!r)return!1;const o=r.contentIds.indexOf(e);return o===-1||o>=r.contentIds.length-1?!1:(t.applyOperation(ct(e,r.id,o+1)),!0)}function Ir(t,e){const n=t.getBlock(e);if(!n)return null;const r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=o>0?r.contentIds[o-1]:null,a=o!==-1&&o<r.contentIds.length-1?r.contentIds[o+1]:null;t.applyOperation(ee(e));const i=dn(t),d=s??a??i;return d&&je(t,d),d??null}function Cp(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function $l({id:t}){var S;const e=G(),n=dt(),r=be(t),[o,s]=p.useState(!1),[a,i]=p.useState(null),d=p.useRef(null),c=p.useRef(null),f=p.useRef(null),u=p.useMemo(()=>[d,c,f],[]),[h]=Mn(),m=h.includes(t),g=p.useCallback(()=>s(!1),[]);Ve(u,o,g),wr(c,o,g,d);const x=p.useCallback(()=>{var L;i(((L=d.current)==null?void 0:L.getBoundingClientRect())??null),s(!0)},[]),y=An(c,o,(a==null?void 0:a.bottom)!=null?a.bottom+4:null,a==null?void 0:a.left),k=p.useCallback(()=>{nt(e,t,te("paragraph"))},[e,t]),v=p.useCallback(()=>{Vo(e,t),xe("Block duplicated"),g()},[e,t,g]),w=p.useCallback(()=>{Yo(e,t)&&xe("Block moved up"),g()},[e,t,g]),B=p.useCallback(()=>{Ko(e,t)&&xe("Block moved down"),g()},[e,t,g]),I=p.useCallback(()=>{Ir(e,t),xe("Block deleted"),g()},[e,t,g]),C=!!((S=r==null?void 0:r.props)!=null&&S.hidden),R=p.useCallback(()=>{e.applyOperation(J(t,{hidden:!C})),xe(C?"Block shown in preview":"Block hidden in preview"),g()},[e,t,C,g]),E=it(e,r)==="rtl",T=p.useCallback(()=>{e.applyOperation(J(t,{dir:E?"ltr":"rtl"})),xe(E?"Block set to left-to-right":"Block set to right-to-left"),g()},[e,t,E,g]),O=p.useCallback(L=>{const{ops:$}=Dl(e,n,t,L);Cp(e,$),xe(`Turned into ${L.label}`),g()},[e,n,t,g]);return r?l.jsxs("div",{className:`be-block-row${C?" be-block-row-hidden":""}${m?" be-block-row-range-selected":""}`,"data-block-row-id":t,dir:it(e,r),children:[l.jsxs("div",{className:`be-block-gutter${o?" be-block-gutter-active":""}`,contentEditable:!1,children:[l.jsx("button",{type:"button",className:"be-block-gutter-btn",onClick:k,"aria-label":"Add block below",children:l.jsx(Ro,{size:16})}),l.jsx("button",{ref:d,type:"button",className:"be-block-gutter-btn","aria-label":"More options","aria-haspopup":"menu","aria-expanded":o,onClick:()=>o?g():x(),children:l.jsx(lu,{size:16})})]}),l.jsx("div",{className:"be-block-row-content",children:l.jsx(Fo,{id:t})}),o&&y&&De.createPortal(l.jsxs("div",{ref:c,role:"menu","aria-label":"Block options",className:"be-block-gutter-menu",style:{position:"fixed",top:y.top,left:y.left},children:[l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:v,children:[l.jsx(To,{size:15})," Duplicate"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:w,children:[l.jsx(br,{size:15})," Move up"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:B,children:[l.jsx(gr,{size:15})," Move down"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:R,children:[C?l.jsx(Mo,{size:15}):l.jsx(Oo,{size:15}),C?"Show in preview":"Hide in preview"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item",onClick:T,children:[E?l.jsx(Ja,{size:15}):l.jsx(Za,{size:15}),E?"Switch to left-to-right":"Switch to right-to-left"]}),Uo(r.type)&&l.jsx(Pl,{onSelect:O,onClose:()=>{},containerRef:f}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-gutter-menu-item be-block-gutter-menu-item-danger",onClick:I,children:[l.jsx(On,{size:15})," Delete"]})]}),document.body)]}):null}function mt({parentId:t,isTopLevel:e=!1}){const n=Ho(t),r=G(),[o]=So(),s=o?n.filter(a=>{var i,d;return!((d=(i=r.getBlock(a))==null?void 0:i.props)!=null&&d.hidden)}):n;return e&&!o?s.map(a=>l.jsx($l,{id:a},a)):s.map(a=>l.jsx(Fo,{id:a},a))}const Sp=97,jp=[[1e3,"m"],[900,"cm"],[500,"d"],[400,"cd"],[100,"c"],[90,"xc"],[50,"l"],[40,"xl"],[10,"x"],[9,"ix"],[5,"v"],[4,"iv"],[1,"i"]];function Rp(t){let e="";for(;t>0;)t-=1,e=String.fromCharCode(Sp+t%26)+e,t=Math.floor(t/26);return e}function Tp(t){let e="",n=t;for(const[r,o]of jp)for(;n>=r;)e+=o,n-=r;return e}function Ep(t){var e,n;return(t==null?void 0:t.type)==="listItem"&&((e=t.props)==null?void 0:e.checked)===void 0&&((n=t.props)==null?void 0:n.collapsed)===void 0}function Qs(t,e){let n=0,r=e;for(;r;){const o=t.getBlock(r.parentId);if(!o||o.type!=="listItem")break;n+=1,r=o}return n}function Bp(t,e,n){const r=n.indexOf(e.id);let o=1;for(let s=r-1;s>=0;s-=1){const a=t.getBlock(n[s]);if(!Ep(a)||!a.props.ordered)break;o+=1}return o}function _p(t,e){const n=(t%3+3)%3;return n===0?`${e}.`:n===1?`${Rp(e)}.`:`${Tp(e)}.`}const Np=["•","◦","▪"];function Mp(t){const e=(t%3+3)%3;return Np[e]}function vn({ordered:t=!1,checked:e,collapsed:n}={}){return function(o,s){const a=_(),i=s!=null&&s.length?s:[{id:_(),type:"text",value:"",marks:{}}],d={ordered:t,titleRunIds:i.map(h=>h.id)};e!==void 0&&(d.checked=e);let c=[],f=[],u=i;if(n!==void 0){d.collapsed=n;const{block:h,runs:m}=te("paragraph")(a);c=[h.id],f=[h],u=[...i,...m]}return{block:{id:a,type:"listItem",parentId:o,contentIds:c,props:d},runs:u,subtreeBlocks:f}}}function Op(t,e){const n=t.getBlock(e),r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=o>0?r.contentIds[o-1]:null,a=s?t.getBlock(s):null;if(!a||a.type!=="listItem"){_e(t,e,"down");return}t.applyOperation(ct(e,s,a.contentIds.length)),je(t,e)}function oo(t,e){const n=t.getBlock(e),r=t.getBlock(n.parentId);if(!r||r.type!=="listItem")return;const o=r.parentId,a=t.getBlock(o).contentIds.indexOf(r.id);t.applyOperation(ct(e,o,a+1)),je(t,e)}function mn(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function zl(t,e){var n;return e.length===0||e.length===1&&(((n=t.getRun(e[0]))==null?void 0:n.value)??"")===""}function Lp(t,e){const n=e.contentIds??[];if(n.length===0)return!0;if(n.length>1)return!1;const r=t.getBlock(n[0]);return!!r&&r.type==="paragraph"&&Oe(t,r.contentIds)}function Ap(t,e){const n=t.getBlock(e);if(!n)return null;const r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=n.props.titleRunIds??[],i=zl(t,s)&&Lp(t,n);if(o>0){const f=r.contentIds[o-1],u=t.getBlock(f);if(i)return mn(t,[ee(e)]),{focusBlockId:f,needsRefocus:!0};if(Ln(t,u))return mn(t,[ee(f)]),{focusBlockId:e,needsRefocus:!1};if((u==null?void 0:u.type)==="listItem"&&n.contentIds.length===0){const h=[...u.props.titleRunIds??[],...s];return mn(t,[J(f,{titleRunIds:h}),J(e,{titleRunIds:[]}),ee(e)]),{focusBlockId:f,needsRefocus:!0}}return null}if(r.type==="listItem")return oo(t,e),{focusBlockId:e,needsRefocus:!0};if(!i)return null;if(r.contentIds.length>1)return mn(t,[ee(e)]),{focusBlockId:t.getBlock(r.id).contentIds[0],needsRefocus:!0};const{block:d,runs:c}=te("paragraph")(r.id);return mn(t,[me(d,r.id,o,{blocks:[d],runs:c}),ee(e)]),{focusBlockId:d.id,needsRefocus:!0}}function Dp(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Pp(t,e){const r=t.getBlock(e).parentId,s=t.getBlock(r).contentIds.indexOf(e),{block:a,runs:i}=te("paragraph")(r);return Dp(t,[me(a,r,s,{blocks:[a],runs:i}),J(e,{titleRunIds:[]}),ee(e)]),je(t,a.id),a.id}function $p(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function zp({id:t}){var R,E;const e=G(),n=be(t),{setSelectedBlockId:r}=ut(),o=Ho(n==null?void 0:n.parentId),s=p.useCallback(()=>{var Q,D,F,re,H;const T=((Q=n==null?void 0:n.props)==null?void 0:Q.titleRunIds)??[],O=e.getBlock(n==null?void 0:n.parentId),S=zl(e,T);if(S&&(O==null?void 0:O.type)==="listItem"){oo(e,t);return}const L=(((D=n==null?void 0:n.contentIds)==null?void 0:D.length)??0)>0;if(S&&(O==null?void 0:O.type)!=="listItem"&&!L){Pp(e,t);return}const $=((F=n==null?void 0:n.props)==null?void 0:F.checked)!==void 0,Y=((re=n==null?void 0:n.props)==null?void 0:re.collapsed)!==void 0,K=vn({ordered:(H=n==null?void 0:n.props)==null?void 0:H.ordered,checked:$?!1:void 0,collapsed:Y?!1:void 0});L&&!Y?El(e,t,T,K):cn(e,t,T,K)},[e,t,n]),a=p.useCallback(()=>Op(e,t),[e,t]),i=p.useCallback(()=>oo(e,t),[e,t]),d=p.useCallback(()=>{const T=Ap(e,t);!T||!T.needsRefocus||un(e,T.focusBlockId,t,r)},[e,t,r]),c=p.useCallback(()=>_e(e,t,"up"),[e,t]),f=p.useCallback(()=>_e(e,t,"down"),[e,t]),u=p.useCallback(()=>{var T;e.applyOperation(J(t,{checked:!((T=n==null?void 0:n.props)!=null&&T.checked)}))},[e,t,(R=n==null?void 0:n.props)==null?void 0:R.checked]),h=p.useCallback(()=>{var O,S;if(!((((O=n==null?void 0:n.contentIds)==null?void 0:O.length)??0)>0)){const{block:L,runs:$}=te("paragraph")(t);$p(e,[me(L,t,0,{blocks:[L],runs:$}),J(t,{collapsed:!1})]),ye(L.contentIds[0]);return}e.applyOperation(J(t,{collapsed:!((S=n==null?void 0:n.props)!=null&&S.collapsed)}))},[e,t,n==null?void 0:n.contentIds,(E=n==null?void 0:n.props)==null?void 0:E.collapsed]),m=Ie("be-list-item",n);if(!n)return null;const{ordered:g,checked:x,collapsed:y,titleRunIds:k=[]}=n.props,v=x!==void 0,w=!v&&y!==void 0,B=n.contentIds.length>0,I=k.map(T=>e.getRun(T)).filter(T=>(T==null?void 0:T.type)==="text").map(T=>T.value).join("").trim(),C=it(e,n);return l.jsxs("div",{className:m,"data-block-id":t,dir:C,children:[l.jsxs("div",{className:"be-list-item-row",children:[v?l.jsx("input",{type:"checkbox",className:"be-list-checkbox",checked:!!x,onChange:u,"aria-label":I||"To-do item"}):w?l.jsx("button",{type:"button",className:"be-list-toggle-marker",onClick:h,"aria-expanded":!y,"aria-label":B?y?"Expand toggle":"Collapse toggle":"Add content to toggle",children:y?l.jsx(Et,{}):l.jsx(mr,{})}):l.jsx("span",{className:"be-list-marker","aria-hidden":"true",children:g?_p(Qs(e,n),Bp(e,n,o)):Mp(Qs(e,n))}),l.jsx("div",{className:"be-list-item-title","data-empty":Oe(e,k)?"":void 0,"data-placeholder":v?"To-do":w?"Toggle":"List item",style:x?{textDecoration:"line-through",opacity:.6}:void 0,children:l.jsx(ft,{blockId:t,runIds:k,dir:C,onEnter:s,onTab:a,onShiftTab:i,onBackspaceAtStart:d,onArrowUp:c,onArrowDown:f})})]}),(!w||!y)&&l.jsx("div",{className:"be-list-item-children",children:l.jsx(mt,{parentId:t})})]})}function Hp(t,e){const{titleRunIds:n=[],ordered:r}=t.props,o=n.map(i=>ht(e.store.getRun(i),e)).join(""),s=t.contentIds.map(i=>e.registry.get(e.store.getBlock(i).type).toHTML(e.store.getBlock(i),e)).join(""),a=s?`<${r?"ol":"ul"}>${s}</${r?"ol":"ul"}>`:"";return`<li>${o}${a}</li>`}function Fp(t,e){const{titleRunIds:n=[]}=t.props;return n.map(r=>Ct(e.store.getRun(r),e)).join("")}function Hl(t,e){const n=[],r=[];for(const u of t.childNodes)u.nodeType===1&&(u.tagName==="UL"||u.tagName==="OL")?r.push(u):n.push(u);const o=t.ownerDocument.createElement("span");for(const u of n)o.appendChild(u.cloneNode(!0));const s=Ye(o,e),a=_(),i=[...s],d=[],c=[];for(const u of r){const h=u.tagName==="OL";for(const m of u.children){if(m.tagName!=="LI")continue;const g=Hl(m,e);g.block.parentId=a,g.block.props.ordered=h,d.push(g.block,...g.childBlocks),i.push(...g.runs),c.push(g.block.id)}}return{block:{id:a,type:"listItem",parentId:null,contentIds:c,props:{ordered:!1,titleRunIds:s.map(u=>u.id)}},runs:i,childBlocks:d}}function Up(t,e){if(t.tagName!=="LI")return null;const{block:n,runs:r,childBlocks:o}=Hl(t,e);return{block:n,runs:r,subtreeBlocks:o}}const Fl={component:zp,isLeaf:!1,defaultProps:{ordered:!1,titleRunIds:[]},toHTML:Hp,toPlainText:Fp,fromHTML:Up,slashCommands:[{label:"Bulleted list",icon:al,keywords:["list","bullet","ul"],run:(t,e)=>Be(t,e,vn({ordered:!1}))},{label:"Numbered list",icon:ll,keywords:["list","number","ordered","ol"],run:(t,e)=>Be(t,e,vn({ordered:!0}))},{label:"To-do list",icon:No,keywords:["todo","checkbox","task","checklist"],run:(t,e)=>Be(t,e,vn({ordered:!1,checked:!1}))},{label:"Toggle list",icon:Et,keywords:["toggle","collapse","expand","dropdown","accordion"],run:(t,e)=>Be(t,e,vn({ordered:!1,collapsed:!1}))}]},Ul=["text","date","checkbox","select"],Cr="text",Sr=160,lr=80;function Vp(t){return`Column ${t+1}`}function Wo(t){return Array.from({length:t},(e,n)=>({id:_(),label:Vp(n),type:Cr,width:Sr}))}function ze(t,e){var r;const n=(r=t.props)==null?void 0:r.columns;return!Array.isArray(n)||n.length!==e?Wo(e):n.map(o=>{const s=o.type??Cr,a=o.width??Sr;return s===o.type&&a===o.width?o:{...o,type:s,width:a}})}function Vl(t){switch(t){case"date":return{id:_(),type:"date",value:"",marks:{},data:{isoDate:""}};case"checkbox":return{id:_(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:""}};case"select":return{id:_(),type:"tableSelect",value:"",marks:{},data:{selectedValue:"",selectedLabel:""}};default:return{id:_(),type:"text",value:"",marks:{}}}}function jr(t,e){const n=Vl(e==null?void 0:e.type);return{block:{id:_(),type:"tableCell",parentId:t,contentIds:[n.id],props:{}},run:n}}function Yl(t,e,n){if(t.type===e)return t;let r;if(t.type==="text")r=t.value??"";else{const o=n==null?void 0:n.get(t.type);r=o!=null&&o.toPlainText?o.toPlainText(t):""}if(e==="date"){const o=r?new Date(r):null,s=o&&!Number.isNaN(o.getTime())?o.toISOString().slice(0,10):"";return{id:_(),type:"date",value:"",marks:{},data:{isoDate:s}}}return e==="checkbox"?{id:_(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:r}}:{id:_(),type:"text",value:r,marks:{}}}function _t(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Kl(t,e){const r=t.getBlock(e.parentId).contentIds.indexOf(e.id);_t(t,[ee(e.id)]);const o=dn(t);if(o)return je(t,o),null;const s=t.getBlock(e.parentId),a=s.contentIds[r]??s.contentIds[r-1];return a&&je(t,a),null}function qo(t,e){const n=t.getBlock(e),r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=ze(r,n.contentIds.length),a=_(),i=[],d=[],c=[];for(const u of s){const h=jr(a,u);i.push(h.block),d.push(h.run),c.push(h.block.id)}const f={id:a,type:"tableRow",parentId:r.id,contentIds:c,props:{}};return t.applyOperation(me(f,r.id,o+1,{blocks:[f,...i],runs:d})),je(t,a),a}function Wl(t,e){const n=t.getBlock(e),r=t.getBlock(n.parentId);if(r.contentIds.length<=1)return Kl(t,r);const o=r.contentIds.indexOf(e);_t(t,[ee(e)]);const s=t.getBlock(r.id),a=Math.min(o,s.contentIds.length-1),i=s.contentIds[a];return i&&je(t,i),i??null}function ir(t,e,n){const r=t.getBlock(e),o=ze(r,r.contentIds[0]?t.getBlock(r.contentIds[0]).contentIds.length:0),s={id:_(),label:"New Column",type:Cr,width:Sr},a=[];let i=null;for(const c of r.contentIds){const f=jr(c,s);i===null&&(i=f.block.id),a.push(me(f.block,c,n+1,{blocks:[f.block],runs:[f.run]}))}const d=[...o];return d.splice(n+1,0,s),a.push(J(e,{columns:d})),_t(t,a),i&&je(t,i),i}function ql(t,e,n){const r=t.getBlock(e),o=t.getBlock(r.contentIds[0]);if(!o||o.contentIds.length<=1)return Kl(t,r);const s=ze(r,o.contentIds.length),a=r.contentIds.map(u=>{const h=t.getBlock(u);return ee(h.contentIds[n])}),i=s.filter((u,h)=>h!==n);a.push(J(e,{columns:i})),_t(t,a);const d=t.getBlock(r.contentIds[0]),c=Math.min(n,d.contentIds.length-1),f=d.contentIds[c];return f&&je(t,f),f??null}function Xl(t,e,n,r){const o=t.getBlock(e),s=t.getBlock(o.contentIds[0]),a=ze(o,s?s.contentIds.length:0);if(!a[n])return;const i=[...a];i[n]={...a[n],width:Math.max(lr,Math.round(r))},t.applyOperation(J(e,{columns:i}))}function Gl(t,e,n,r){const o=t.getBlock(e),s=t.getBlock(o.contentIds[0]),i=[...ze(o,s?s.contentIds.length:0)];i[n]&&(i[n]={...i[n],label:r},t.applyOperation(J(e,{columns:i})))}function Xo(t,e,n){return e.contentIds.map(r=>{const s=t.getBlock(r).contentIds[n],a=t.getBlock(s);return{cellId:s,run:t.getRun(a.contentIds[0])}})}function ea(t,e){if(!t)return"";if(t.type==="text")return t.value??"";const n=e==null?void 0:e.get(t.type);return n!=null&&n.toPlainText?n.toPlainText(t):""}function Yp(t,e,n,r){const o=Xo(t,e,n),s=[],a=new Map;for(const{run:d}of o){const c=ea(d,r).trim();if(!c||a.has(c))continue;const f={value:_(),label:c};a.set(c,f),s.push(f)}const i=o.map(({cellId:d,run:c})=>{const f=ea(c,r).trim(),u=a.get(f);return{cellId:d,run:{id:_(),type:"tableSelect",value:"",marks:{},data:{selectedValue:(u==null?void 0:u.value)??"",selectedLabel:(u==null?void 0:u.label)??""}}}});return{options:s,newRuns:i}}function Jl(t,e,n,r,o){const s=t.getBlock(e),a=t.getBlock(s.contentIds[0]),i=ze(s,a?a.contentIds.length:0),d=i[n];if(!d||d.type===r)return;const c=[...i];if(r==="select"){const{options:u,newRuns:h}=Yp(t,s,n,o);c[n]={...d,type:r,options:u};const m=[J(e,{columns:c})];for(const{cellId:g,run:x}of h)m.push(Me(g,[x]));_t(t,m);return}c[n]={...d,type:r};const f=[J(e,{columns:c})];for(const{cellId:u,run:h}of Xo(t,s,n)){if(!h)continue;const m=Yl(h,r,o);f.push(Me(u,[m]))}_t(t,f)}function tr(t,e,n,r){var u,h;const o=t.getBlock(e),s=t.getBlock(o.contentIds[0]),a=ze(o,s?s.contentIds.length:0),i=a[n];if(!i)return;const d=[...a];d[n]={...i,options:r};const c=[J(e,{columns:d})],f=new Map(r.map(m=>[m.value,m]));for(const{run:m}of Xo(t,o,n)){if(!m||m.type!=="tableSelect")continue;const g=((u=m.data)==null?void 0:u.selectedValue)??"",x=f.get(g),y=x?g:"",k=x?x.label:"";(y!==g||k!==(((h=m.data)==null?void 0:h.selectedLabel)??""))&&c.push(de(m.id,{data:{selectedValue:y,selectedLabel:k}}))}_t(t,c)}function Zl(t,e,n){const[r,o]=p.useState(null);return p.useLayoutEffect(()=>{o(n??null)},[n]),p.useLayoutEffect(()=>{if(!e||!t.current||r==null)return;const s=t.current.getBoundingClientRect(),a=yr(r,s.width);a!==r&&o(a)},[e,t,r]),r}function Ql(t,e,n){const[r,o]=p.useState(null);return p.useLayoutEffect(()=>{o(n??null)},[n]),p.useLayoutEffect(()=>{if(!e||!t.current||r==null)return;const s=t.current.getBoundingClientRect(),a=s.width/2,d=yr(r-a,s.width)+a;d!==r&&o(d)},[e,t,r]),r}function Kp(t,e,n){const[r,o]=p.useState(null);return p.useLayoutEffect(()=>{o(n??null)},[n]),p.useLayoutEffect(()=>{if(!e||!t.current||r==null)return;const s=t.current.getBoundingClientRect(),i=yr(r-s.width,s.width)+s.width;i!==r&&o(i)},[e,t,r]),r}function ta(){if(typeof window>"u"||!window.visualViewport)return 0;const t=window.visualViewport,e=window.innerHeight-(t.height+t.offsetTop);return e>0?Math.round(e):0}function Rr(){const[t,e]=p.useState(ta);return p.useEffect(()=>{if(typeof window>"u"||!window.visualViewport)return;const n=window.visualViewport,r=()=>e(ta());return r(),n.addEventListener("resize",r),n.addEventListener("scroll",r),()=>{n.removeEventListener("resize",r),n.removeEventListener("scroll",r)}},[]),t}const Wp=280;function qp(t,e){return e?t.label.toLowerCase().includes(e.toLowerCase()):!0}function Mt({value:t,options:e,onChange:n,placeholder:r="Select…",ariaLabel:o,className:s="",variant:a="default",selectedLabel:i,selectedColor:d,onManageOptions:c,manageOptionsLabel:f="Manage options…",mention:u=!1}){var ke,he;const[h,m]=p.useState(!1),[g,x]=p.useState(""),[y,k]=p.useState(0),[v,w]=p.useState(null),B=Rr(),[I,C]=p.useState([]),[R,E]=p.useState(!1),[T,O]=p.useState(!1),S=p.useRef(null),L=p.useRef(null),$=p.useRef(null),Y=p.useRef(null),K=p.useRef(null),Q=p.useMemo(()=>[S,$],[]),D=a==="tag",F=typeof e=="function",re=F?void 0:e.find(U=>U.value===t),H=t?re??(i?{label:i,color:d}:void 0):void 0,ne=p.useMemo(()=>F?I:e.filter(U=>qp(U,g)),[F,I,e,g]);p.useEffect(()=>{if(!F||!h)return;let U=!1;E(!0),O(!1);const ae=setTimeout(()=>{Promise.resolve(e(g)).then(We=>{U||(C(We??[]),E(!1))}).catch(()=>{U||(C([]),E(!1),O(!0))})},250);return()=>{U=!0,clearTimeout(ae)}},[F,h,e,g]);const se=p.useCallback(()=>m(!1),[]);Ve(Q,h,se);const oe=Zl($,h,v==null?void 0:v.left),ge=p.useCallback(()=>{var U;w(((U=L.current)==null?void 0:U.getBoundingClientRect())??null),x(""),k(0),m(!0)},[]);p.useEffect(()=>{var U;h&&((U=Y.current)==null||U.focus())},[h]),p.useEffect(()=>{var U,ae;(ae=(U=K.current)==null?void 0:U.scrollIntoView)==null||ae.call(U,{block:"nearest"})},[y]);const Re=p.useCallback(U=>{var ae;n(U.value,U),se(),(ae=L.current)==null||ae.focus()},[n,se]),ce=p.useCallback(U=>{var ae;U.key==="ArrowDown"?(U.preventDefault(),k(We=>Math.min(We+1,Math.max(ne.length-1,0)))):U.key==="ArrowUp"?(U.preventDefault(),k(We=>Math.max(We-1,0))):U.key==="Enter"?(U.preventDefault(),ne[y]&&Re(ne[y])):U.key==="Escape"&&(U.preventDefault(),se(),(ae=L.current)==null||ae.focus())},[ne,y,Re,se]);return l.jsxs("span",{className:`be-select ${s}`.trim(),ref:S,children:[l.jsx("button",{type:"button",ref:L,className:`be-select-trigger${D?" be-select-trigger-tag":""}${u?" be-select-trigger-mention":""}`,"aria-haspopup":"listbox","aria-expanded":h,"aria-label":o,onClick:()=>h?se():ge(),children:D?H?l.jsx("span",{className:`be-select-tag${u?" be-select-tag-mention":""}`,style:u?void 0:{background:(ke=H.color)==null?void 0:ke.bg,color:(he=H.color)==null?void 0:he.text},children:u?`@${H.label}`:H.label}):l.jsx("span",{className:"be-select-value be-select-value-placeholder",children:r}):l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"be-select-value",children:H?H.label:r}),l.jsx(mr,{size:14,className:"be-select-chevron"})]})}),h&&v&&oe!=null&&De.createPortal(l.jsxs("div",{ref:$,className:"be-select-popover",style:{position:"fixed",left:oe,minWidth:v.width,...v.bottom+Wp>window.innerHeight-B?{bottom:window.innerHeight-v.top+4}:{top:v.bottom+4}},children:[l.jsx("input",{ref:Y,type:"text",className:"be-select-search",value:g,onChange:U=>{x(U.target.value),k(0)},onKeyDown:ce,placeholder:"Search…","aria-label":o?`Search ${o}`:"Search options"}),l.jsxs("div",{className:"be-select-options",role:"listbox",children:[F&&R&&l.jsx("div",{className:"be-select-empty",children:"Loading…"}),F&&!R&&T&&l.jsx("div",{className:"be-select-empty be-select-error",children:"Couldn't load options"}),!R&&!T&&ne.length===0&&l.jsx("div",{className:"be-select-empty",children:"No results"}),!R&&!T&&ne.map((U,ae)=>{var We,Pn;return l.jsx("div",{ref:ae===y?K:void 0,role:"option","aria-selected":U.value===t,className:`be-select-option${ae===y?" be-select-option-active":""}${U.value===t?" be-select-option-selected":""}`,onMouseDown:Br=>{Br.preventDefault(),Re(U)},onMouseEnter:()=>k(ae),children:D?l.jsx("span",{className:"be-select-tag",style:{background:(We=U.color)==null?void 0:We.bg,color:(Pn=U.color)==null?void 0:Pn.text},children:U.label}):U.label},U.value)})]}),c&&l.jsx("button",{type:"button",className:"be-select-manage-options",onMouseDown:U=>{U.preventDefault(),se(),c()},children:f})]}),document.body)]})}const Wn=[{bg:"#e9e9e7",text:"#32302c"},{bg:"#eee0da",text:"#64473a"},{bg:"#fadec9",text:"#8a4b23"},{bg:"#fdecc8",text:"#8a6116"},{bg:"#dbeddb",text:"#256029"},{bg:"#d3e5ef",text:"#1a5f8a"},{bg:"#e8deee",text:"#5b3a8a"},{bg:"#f5e0e9",text:"#8a3a5f"},{bg:"#ffe2dd",text:"#a13a2f"}];function Tn(t){return Wn[(t%Wn.length+Wn.length)%Wn.length]}const Xp={text:"Text",date:"Date",checkbox:"Checkbox",select:"Select"},Gp=Ul.map(t=>({value:t,label:Xp[t]})),Jp=800;function Zp({tableId:t,colIndex:e,options:n}){const r=G(),[o,s]=p.useState(""),a=p.useCallback((c,f)=>{tr(r,t,e,n.map(u=>u.value===c?{...u,label:f}:u))},[r,t,e,n]),i=p.useCallback(c=>tr(r,t,e,n.filter(f=>f.value!==c)),[r,t,e,n]),d=p.useCallback(()=>{const c=o.trim();s(""),c&&tr(r,t,e,[...n,{value:_(),label:c,color:Tn(n.length)}])},[r,t,e,n,o]);return l.jsxs("div",{className:"be-table-header-menu-options",children:[l.jsx("div",{className:"be-table-header-menu-options-label",children:"Options"}),n.map((c,f)=>l.jsxs("div",{className:"be-table-header-menu-option-row",children:[l.jsx("span",{className:"be-table-header-menu-option-swatch",style:{background:(c.color??Tn(f)).bg},"aria-hidden":"true"}),l.jsx("input",{className:"be-table-header-menu-option-input",value:c.label,onChange:u=>a(c.value,u.target.value),"aria-label":`Rename option ${c.label}`}),l.jsx("button",{type:"button",className:"be-table-header-menu-option-remove",onClick:()=>i(c.value),"aria-label":`Remove option ${c.label}`,children:l.jsx(wt,{size:14})})]},c.value)),l.jsxs("div",{className:"be-table-header-menu-option-row",children:[l.jsx("input",{className:"be-table-header-menu-option-input",value:o,onChange:c=>s(c.target.value),placeholder:"New option…",onKeyDown:c=>{c.key==="Enter"&&(c.preventDefault(),d())}}),l.jsx("button",{type:"button",className:"be-table-header-menu-option-add",onClick:d,"aria-label":"Add option",children:"+"})]})]})}function Qp({tableId:t,column:e,colIndex:n,colCount:r}){const o=G(),s=Ke(),[a,i]=p.useState(!1),[d,c]=p.useState(null),[f,u]=p.useState(null),h=p.useRef(null),m=p.useRef(null),g=p.useRef(null),x=p.useMemo(()=>[h,m],[]),y=p.useCallback(()=>i(!1),[]);Ve(x,a,y),wr(m,a,y,h);const k=Kp(m,a,d==null?void 0:d.right),v=p.useCallback(()=>{var T;c(((T=g.current)==null?void 0:T.getBoundingClientRect())??null),i(!0)},[]),w=p.useCallback(T=>Gl(o,t,n,T.target.value),[o,t,n]),B=p.useCallback(()=>{ir(o,t,n-1),y()},[o,t,n,y]),I=p.useCallback(()=>{ir(o,t,n),y()},[o,t,n,y]),C=p.useCallback(()=>{ql(o,t,n),y()},[o,t,n,y]),R=p.useCallback(T=>Jl(o,t,n,T,s),[o,t,n,s]),E=p.useCallback(T=>{var D;T.preventDefault();const O=(D=g.current)==null?void 0:D.closest("table"),S=O==null?void 0:O.querySelector(`col[data-col-index="${n}"]`);if(!S)return;const L=g.current.getBoundingClientRect().width,$=T.clientX,Y=F=>Math.max(lr,Math.round(L+(F.clientX-$))),K=F=>{const re=Y(F);S.style.width=`${re}px`,u(re)},Q=F=>{document.removeEventListener("mousemove",K),document.removeEventListener("mouseup",Q),Xl(o,t,n,Y(F)),u(null)};document.addEventListener("mousemove",K),document.addEventListener("mouseup",Q)},[o,t,n]);return l.jsxs("th",{ref:g,scope:"col",className:"be-table-header-cell",contentEditable:!1,children:[l.jsx("input",{className:"be-table-header-label",value:e.label,onChange:w,"aria-label":`Column ${n+1} name`}),l.jsx("button",{ref:h,type:"button",className:"be-table-header-menu-trigger","aria-label":`Column ${n+1} options`,"aria-haspopup":"menu","aria-expanded":a,onClick:()=>a?y():v(),children:"⋮"}),l.jsx("div",{className:"be-table-col-resize-handle",onMouseDown:E,role:"slider","aria-label":`Resize column ${n+1}`,"aria-valuemin":lr,"aria-valuemax":Jp,"aria-valuenow":f??e.width}),a&&d&&k!=null&&De.createPortal(l.jsxs("div",{ref:m,role:"menu","aria-label":`Column ${n+1} options`,className:"be-table-header-menu",style:{position:"fixed",top:d.bottom+4,left:k,transform:"translateX(-100%)"},children:[l.jsxs("div",{className:"be-table-header-menu-type",children:[l.jsx("span",{id:`be-table-col-type-${e.id}`,children:"Type"}),l.jsx(Mt,{value:e.type,options:Gp,onChange:R,ariaLabel:"Column type",className:""})]}),e.type==="select"&&l.jsx(Zp,{tableId:t,colIndex:n,options:e.options??[]}),l.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item",onClick:B,children:"Insert column left"}),l.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item",onClick:I,children:"Insert column right"}),l.jsx("button",{type:"button",role:"menuitem",className:"be-table-header-menu-item be-table-header-menu-item-danger",onClick:C,disabled:r<=1,children:"Delete column"})]}),document.body)]})}function ei({tableId:t,columns:e}){return l.jsx("thead",{children:l.jsxs("tr",{className:"be-table-header-row",children:[e.map((n,r)=>l.jsx(Qp,{tableId:t,column:n,colIndex:r,colCount:e.length},n.id)),l.jsx("th",{className:"be-table-header-spacer","aria-hidden":"true"})]})})}function ef({id:t}){var i;const e=G(),n=be(t),r=p.useCallback(()=>{var c;const d=(c=n==null?void 0:n.contentIds)==null?void 0:c[n.contentIds.length-1];d&&qo(e,d)},[e,n]),o=Ie("be-table-wrapper",n);if(!n)return null;const s=e.getBlock(n.contentIds[0]),a=ze(n,((i=s==null?void 0:s.contentIds)==null?void 0:i.length)??0);return l.jsx("div",{className:"be-table-scroll",children:l.jsxs("div",{className:o,"data-block-id":t,children:[l.jsxs("table",{className:"be-table",children:[l.jsxs("colgroup",{children:[a.map((d,c)=>l.jsx("col",{"data-col-index":c,style:{width:d.width}},d.id)),l.jsx("col",{className:"be-table-header-spacer-col"})]}),l.jsx(ei,{tableId:t,columns:a}),l.jsx("tbody",{children:l.jsx(mt,{parentId:t})})]}),l.jsxs("button",{type:"button",className:"be-table-add-row",contentEditable:!1,onClick:r,children:[l.jsx(Ro,{size:14})," Add row"]})]})})}function tf({id:t}){const e=G(),n=be(t),r=Ie("be-table-row",n),o=p.useCallback(()=>Wl(e,t),[e,t]);return l.jsxs("tr",{className:r,"data-block-id":t,children:[l.jsx(mt,{parentId:t}),l.jsx("td",{className:"be-table-row-actions",contentEditable:!1,children:l.jsx("button",{type:"button",className:"be-table-delete-row",onClick:o,"aria-label":"Delete row",title:"Delete row",children:l.jsx(wt,{size:14})})})]})}function ti(t,e){const n=t.getBlock(e),r=t.getBlock(n.parentId),o=t.getBlock(r.parentId);return{table:o,row:r,rowIndex:o.contentIds.indexOf(r.id),colIndex:r.contentIds.indexOf(e)}}function nf(t,e,n){const{table:r,row:o,rowIndex:s,colIndex:a}=ti(t,e);if(n==="left"||n==="right"){const f=n==="right"?1:-1,u=a+f;if(u>=0&&u<o.contentIds.length)return o.contentIds[u];const h=s+f;if(h<0||h>=r.contentIds.length)return null;const m=t.getBlock(r.contentIds[h]),g=n==="right"?0:m.contentIds.length-1;return m.contentIds[g]}const d=s+(n==="down"?1:-1);if(d<0||d>=r.contentIds.length)return null;const c=t.getBlock(r.contentIds[d]);return c.contentIds[a]??c.contentIds[c.contentIds.length-1]??null}function rf(t,e){const n=Rl(t,e,"down");if(n){ye(n);return}nt(t,e,te("paragraph"))}function bn(t,e,n){var o;const r=nf(t,e,n);if(r){const s=t.getBlock(r),a=(o=s==null?void 0:s.contentIds)==null?void 0:o[0];a&&ye(a);return}if(n==="right"){const{table:s}=ti(t,e);rf(t,s.id)}}function of({id:t}){const e=G(),n=be(t),r=p.useCallback(()=>bn(e,t,"right"),[e,t]),o=p.useCallback(()=>bn(e,t,"left"),[e,t]),s=p.useCallback(()=>bn(e,t,"up"),[e,t]),a=p.useCallback(()=>bn(e,t,"down"),[e,t]),i=p.useCallback(()=>bn(e,t,"down"),[e,t]),d=Ie("be-table-cell",n);if(!n)return null;const c=it(e,n);return l.jsx("td",{className:d,"data-block-id":t,dir:c,children:l.jsx(ft,{blockId:t,runIds:n.contentIds,dir:c,onTab:r,onShiftTab:o,onArrowUp:s,onArrowDown:a,onEnter:i})})}function sf(t,e){const n=_(),r=[],o=[],s=[];for(const a of e){const i=jr(n,a);r.push(i.block),o.push(i.run),s.push(i.block.id)}return{block:{id:n,type:"tableRow",parentId:t,contentIds:s,props:{}},blocks:r,runs:o}}function af({rows:t=2,cols:e=2}={}){return function(r){const o=_(),s=Wo(e),a=[],i=[],d=[];for(let f=0;f<t;f+=1){const u=sf(o,s);a.push(u.block,...u.blocks),i.push(...u.runs),d.push(u.block.id)}return{block:{id:o,type:"table",parentId:r,contentIds:d,props:{columns:s}},runs:i,subtreeBlocks:a}}}function lf(t,e){return`<td>${t.contentIds.map(r=>e.store.getRun(r)).map(r=>ht(r,e)).join("")}</td>`}function cf(t,e){return t.contentIds.map(n=>Ct(e.store.getRun(n),e)).join("")}function df(t,e){if(t.tagName!=="TD"&&t.tagName!=="TH")return null;const n=Ye(t,e);return{block:{id:_(),type:"tableCell",parentId:null,contentIds:n.map(o=>o.id),props:{}},runs:n}}function uf(t,e){return`<tr>${t.contentIds.map(r=>{const o=e.store.getBlock(r);return e.registry.get(o.type).toHTML(o,e)}).join("")}</tr>`}function pf(t,e){return t.contentIds.map(n=>{const r=e.store.getBlock(n);return e.registry.get(r.type).toPlainText(r,e)}).join(" ")}function ff(t,e){if(t.tagName!=="TR")return null;const n=[...t.children].filter(d=>d.tagName==="TD"||d.tagName==="TH"),r=_(),o=[],s=[],a=[];for(const d of n){const c=e.registry.get("tableCell").fromHTML(d,e);c&&(c.block.parentId=r,o.push(c.block),s.push(...c.runs),a.push(c.block.id))}return{block:{id:r,type:"tableRow",parentId:null,contentIds:a,props:{}},runs:s,subtreeBlocks:o}}function hf(t,e){var a;const n=t.contentIds[0]&&e.store.getBlock(t.contentIds[0]),r=ze(t,((a=n==null?void 0:n.contentIds)==null?void 0:a.length)??0),o=r.length?`<thead><tr>${r.map(i=>`<th>${Bt(i.label??"")}</th>`).join("")}</tr></thead>`:"",s=t.contentIds.map(i=>{const d=e.store.getBlock(i);return e.registry.get(d.type).toHTML(d,e)}).join("");return`<table>${o}<tbody>${s}</tbody></table>`}function mf(t,e){return t.contentIds.map(n=>{const r=e.store.getBlock(n);return e.registry.get(r.type).toPlainText(r,e)}).join(`
3203
+ `)}function bf(t,e){if(t.tagName!=="TABLE")return null;const n=t.querySelector("thead tr"),r=t.querySelector("tbody")?[...t.querySelectorAll("tbody tr")]:[...t.querySelectorAll("tr")].filter(f=>f!==n),o=_(),s=[],a=[],i=[];for(const f of r){const u=e.registry.get("tableRow").fromHTML(f,e);if(u){u.block.parentId=o;for(const h of u.subtreeBlocks)h.parentId=u.block.id;s.push(u.block,...u.subtreeBlocks),a.push(...u.runs),i.push(u.block.id)}}const d={};if(n){const f=[...n.children].filter(u=>u.tagName==="TH"||u.tagName==="TD");d.columns=f.map(u=>({id:_(),label:u.textContent??""}))}return{block:{id:o,type:"table",parentId:null,contentIds:i,props:d},runs:a,subtreeBlocks:s}}const ni={component:of,isLeaf:!0,defaultProps:{},toHTML:lf,toPlainText:cf,fromHTML:df},ri={component:tf,isLeaf:!1,defaultProps:{},toHTML:uf,toPlainText:pf,fromHTML:ff},oi={component:ef,isLeaf:!1,defaultProps:{},toHTML:hf,toPlainText:mf,fromHTML:bf,slashCommand:{label:"Table",icon:yu,keywords:["table","grid"],run:(t,e)=>Be(t,e,af({rows:2,cols:2}))}};function gf({id:t}){const e=be(t),n=Ie("be-layout",e);return l.jsx("div",{className:n,"data-block-id":t,style:{display:"flex",gap:"1em"},children:l.jsx(mt,{parentId:t})})}function xf({id:t}){const e=be(t),n=Ie("be-layout-column",e);return l.jsx("div",{className:n,"data-block-id":t,children:l.jsx(mt,{parentId:t})})}function yf({columns:t=2}={}){return function(n){const r=_(),o=[],s=[],a=[];for(let d=0;d<t;d+=1){const c=_(),{block:f,runs:u}=te("paragraph")(c),h={id:c,type:"layoutColumn",parentId:r,contentIds:[f.id],props:{}};o.push(h,f),s.push(...u),a.push(c)}return{block:{id:r,type:"layout",parentId:n,contentIds:a,props:{}},runs:s,subtreeBlocks:o}}}function si(t,e){return(n,r)=>`${t}${n.contentIds.map(o=>{const s=r.store.getBlock(o);return r.registry.get(s.type).toHTML(s,r)}).join("")}${e}`}function ai(t,e){return t.contentIds.map(n=>{const r=e.store.getBlock(n);return e.registry.get(r.type).toPlainText(r,e)}).join(`
3204
+ `)}const li={component:xf,isLeaf:!1,defaultProps:{},toHTML:si("<div>","</div>"),toPlainText:ai},ii={component:gf,isLeaf:!1,defaultProps:{},toHTML:si('<div style="display:flex;gap:1em">',"</div>"),toPlainText:ai,slashCommands:[2,3,4,5].map(t=>({label:`${t} columns`,icon:ku,keywords:["layout","columns","column",String(t)],run:(e,n)=>Be(e,n,yf({columns:t}))}))};function kf({id:t}){const e=be(t),n=Ie("be-divider",e);return l.jsx("hr",{className:n,"data-block-id":t,contentEditable:!1,tabIndex:-1})}function vf(){return function(e){return{block:{id:_(),type:"divider",parentId:e,contentIds:[],props:{}},runs:[]}}}function wf(){return"<hr />"}function If(){return"---"}function Cf(t){return t.tagName!=="HR"?null:{block:{id:_(),type:"divider",parentId:null,contentIds:[],props:{}},runs:[]}}const ci={component:kf,isLeaf:!0,defaultProps:{},toHTML:wf,toPlainText:If,fromHTML:Cf,slashCommand:{label:"Divider",icon:gu,keywords:["divider","hr","separator","line"],run:(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o})=>{const s=t.getRun(n),a=(s==null?void 0:s.value)??"";t.applyOperation(de(n,{value:a.slice(0,r)+a.slice(o)}));const i=vr(t,e,vf());return nt(t,i,te("paragraph")),i}}},di=[{value:"gray",label:"Gray"},{value:"blue",label:"Blue"},{value:"green",label:"Green"},{value:"yellow",label:"Yellow"},{value:"orange",label:"Orange"},{value:"red",label:"Red"},{value:"purple",label:"Purple"},{value:"pink",label:"Pink"}];function Sf({id:t}){var k,v;const e=G(),n=be(t),[r,o]=p.useState(!1),[s,a]=p.useState(!1),i=p.useRef(null),d=p.useRef(null),c=p.useMemo(()=>[i,d],[]),f=p.useCallback(()=>a(!1),[]);Ve(c,s,f);const u=((k=n==null?void 0:n.props)==null?void 0:k.icon)??pn,h=((v=n==null?void 0:n.props)==null?void 0:v.color)??Ll,m=p.useCallback(w=>{const B=w.target.value.trim();B&&e.applyOperation(J(t,{icon:B})),o(!1)},[e,t]),g=p.useCallback(w=>{w.key==="Enter"&&w.currentTarget.blur(),w.key==="Escape"&&o(!1)},[]),x=p.useCallback(w=>{e.applyOperation(J(t,{color:w})),a(!1)},[e,t]),y=Ie("be-callout",n);return n?l.jsxs("div",{className:y,"data-block-id":t,"data-color":h,children:[l.jsx("div",{className:"be-callout-icon-wrap",children:r?l.jsx("input",{type:"text",className:"be-callout-icon-input",defaultValue:u,autoFocus:!0,onBlur:m,onKeyDown:g,"aria-label":"Callout icon (paste or type an emoji)"}):l.jsx("button",{type:"button",className:"be-callout-icon",onClick:()=>o(!0),"aria-label":"Change callout icon",title:"Change icon",children:u})}),l.jsx("div",{className:"be-callout-content",children:l.jsx(mt,{parentId:t})}),l.jsxs("div",{className:"be-callout-color-wrap",contentEditable:!1,children:[l.jsx("button",{ref:i,type:"button",className:"be-callout-color-trigger","aria-label":"Callout color","aria-haspopup":"true","aria-expanded":s,title:"Callout color",onClick:()=>a(w=>!w),children:l.jsx("span",{className:`be-callout-color-dot be-callout-color-dot-${h}`})}),s&&l.jsx("div",{ref:d,className:"be-callout-color-picker",role:"menu","aria-label":"Callout color",children:di.map(w=>l.jsx("button",{type:"button",role:"menuitem",className:`be-callout-color-option be-callout-color-option-${w.value}${w.value===h?" be-callout-color-option-active":""}`,title:w.label,"aria-label":w.label,onClick:()=>x(w.value)},w.value))})]})]}):null}function jf(t,e){return t.contentIds.map(n=>{const r=e.store.getBlock(n);return e.registry.get(r.type).toHTML(r,e)}).join("")}function Rf(t,e){var r;const n=((r=t.props)==null?void 0:r.icon)??pn;return`<div class="callout" data-icon="${n}"><div class="callout-icon">${n}</div><div class="callout-content">${jf(t,e)}</div></div>`}function Tf(t,e){var o;const n=((o=t.props)==null?void 0:o.icon)??pn,r=t.contentIds.map(s=>{const a=e.store.getBlock(s);return e.registry.get(a.type).toPlainText(a,e)}).join(`
3205
+ `);return`${n} ${r}`}const ui={component:Sf,isLeaf:!1,defaultProps:{icon:pn},toHTML:Rf,toPlainText:Tf,slashCommand:{label:"Callout",icon:sl,keywords:["callout","aside","note","info","tip","warning"],run:(t,e)=>Be(t,e,vp())}};function Ef({id:t}){const e=G(),n=be(t),{setSelectedBlockId:r}=ut(),o=p.useCallback(()=>{cn(e,t,(n==null?void 0:n.contentIds)??[],te("paragraph"))},[e,t,n]),s=p.useCallback(()=>{const u=Dn(e,t);un(e,u,t,r)},[e,t,r]),a=p.useCallback(()=>_e(e,t,"up"),[e,t]),i=p.useCallback(()=>_e(e,t,"down"),[e,t]),d=Ie("be-blockquote",n);if(!n)return null;const c=Oe(e,n.contentIds),f=it(e,n);return l.jsx("blockquote",{className:d,"data-block-id":t,"data-empty":c?"":void 0,"data-placeholder":"Empty quote",dir:f,children:l.jsx(ft,{blockId:t,runIds:n.contentIds,dir:f,onEnter:o,onBackspaceAtStart:s,onArrowUp:a,onArrowDown:i})})}function Bf(t,e){return`<p>${t.contentIds.map(r=>e.store.getRun(r)).map(r=>ht(r,e)).join("")}</p>`}function _f(t,e){return t.contentIds.map(n=>Ct(e.store.getRun(n),e)).join("")}function Nf(t,e){if(t.tagName!=="BLOCKQUOTE")return null;const n=Ye(t,e);return{block:{id:_(),type:"blockquote",parentId:null,contentIds:n.map(o=>o.id),props:{}},runs:n}}const pi={component:Ef,isLeaf:!0,defaultProps:{},toHTML:Bf,toPlainText:_f,fromHTML:Nf,slashCommand:{label:"Quote",icon:ol,keywords:["quote","blockquote","citation"],run:(t,e)=>Be(t,e,te("blockquote"))}},fi=["plaintext","javascript","python","html","css","json","bash","sql"],Mf=fi.map(t=>({value:t,label:t}));function na(t,e,n){const r=lt();if(!r||r.blockId!==e)return;const o=t.getRun(r.runId);if(!o||o.type!=="text")return;const s=o.value??"",a=s.slice(0,r.offset)+n+s.slice(r.offset);t.applyOperation(de(o.id,{value:a})),Ze(o.id,r.offset+n.length)}function Of({id:t}){var m;const e=G(),n=be(t),r=p.useCallback(()=>na(e,t,`
3206
+ `),[e,t]),o=p.useCallback(()=>na(e,t," "),[e,t]),s=p.useCallback(()=>{var k;const g=Dn(e,t);if(!g||g===t)return;const x=e.getBlock(g),y=(k=x==null?void 0:x.contentIds)==null?void 0:k[x.contentIds.length-1];y&&ye(y)},[e,t]),a=p.useCallback(()=>_e(e,t,"up"),[e,t]),i=p.useCallback(()=>_e(e,t,"down"),[e,t]),d=p.useCallback(g=>e.applyOperation(J(t,{language:g})),[e,t]),c=p.useCallback(()=>Ir(e,t),[e,t]),f=Ie("be-code-block",n);if(!n)return null;const u=((m=n.props)==null?void 0:m.language)??"plaintext",h=Oe(e,n.contentIds);return l.jsxs("div",{className:f,"data-block-id":t,children:[l.jsxs("div",{className:"be-code-block-header",contentEditable:!1,children:[l.jsx(Mt,{className:"be-code-block-language",value:u,options:Mf,onChange:d,ariaLabel:"Code language"}),l.jsx("button",{type:"button",className:"be-code-block-delete",onClick:c,"aria-label":"Delete code block",title:"Delete code block",children:l.jsx(On,{size:14})})]}),l.jsx("pre",{className:"be-code-block-pre",dir:"ltr",children:l.jsx("code",{"data-empty":h?"":void 0,"data-placeholder":"Empty code block",children:l.jsx(ft,{blockId:t,runIds:n.contentIds,dir:"ltr",onEnter:r,onTab:o,onBackspaceAtStart:s,onArrowUp:a,onArrowDown:i})})})]})}function Lf(t,e){var s;const n=t.contentIds.map(a=>e.store.getRun(a)),r=(s=t.props)==null?void 0:s.language;return`<pre><code${r&&r!=="plaintext"?` data-language="${Bt(r)}"`:""}>${n.map(a=>ht(a,e)).join("")}</code></pre>`}function Af(t,e){return t.contentIds.map(n=>Ct(e.store.getRun(n),e)).join("")}function Df(t,e){var a;if(t.tagName!=="PRE")return null;const n=t.querySelector("code")??t,r=(a=n.getAttribute)==null?void 0:a.call(n,"data-language"),o=_();return{block:{id:_(),type:"code",parentId:null,contentIds:[o],props:r?{language:r}:{}},runs:[{id:o,type:"text",value:n.textContent??"",marks:{}}]}}const hi={component:Of,isLeaf:!0,defaultProps:{language:"plaintext"},toHTML:Lf,toPlainText:Af,fromHTML:Df,slashCommand:{label:"Code",icon:_o,keywords:["code","codeblock","snippet","pre"],run:(t,e)=>Be(t,e,te("code"))}};function Pf(t,e){var n;return e.length===0||e.length===1&&(((n=t.getRun(e[0]))==null?void 0:n.value)??"")===""}function $f(t,e){const n=e.contentIds??[];if(n.length===0)return!0;if(n.length>1)return!1;const r=t.getBlock(n[0]);return!!r&&r.type==="paragraph"&&Oe(t,r.contentIds)}function qn(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function zf(t,e){const n=t.getBlock(e);if(!n)return null;const r=t.getBlock(n.parentId),o=r.contentIds.indexOf(e),s=n.props.titleRunIds??[],a=Pf(t,s)&&$f(t,n);if(o<=0){if(!a)return null;if(r.contentIds.length>1)return qn(t,[ee(e)]),{focusBlockId:t.getBlock(r.id).contentIds[0],needsRefocus:!0};const{block:c,runs:f}=te("paragraph")(r.id);return qn(t,[me(c,r.id,o,{blocks:[c],runs:f}),ee(e)]),{focusBlockId:c.id,needsRefocus:!0}}const i=r.contentIds[o-1],d=t.getBlock(i);return a?(qn(t,[ee(e)]),{focusBlockId:i,needsRefocus:!0}):Ln(t,d)?(qn(t,[ee(i)]),{focusBlockId:e,needsRefocus:!1}):null}function Hf(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Ff({id:t}){var y;const e=G(),n=be(t),{setSelectedBlockId:r}=ut(),o=p.useCallback(()=>{var B,I;const k=((B=n==null?void 0:n.props)==null?void 0:B.titleRunIds)??[],v=(((I=n==null?void 0:n.contentIds)==null?void 0:I.length)??0)>0,w=te("paragraph");v?El(e,t,k,w):cn(e,t,k,w)},[e,t,n]),s=p.useCallback(()=>{const k=zf(e,t);!k||!k.needsRefocus||un(e,k.focusBlockId,t,r)},[e,t,r]),a=p.useCallback(()=>_e(e,t,"up"),[e,t]),i=p.useCallback(()=>_e(e,t,"down"),[e,t]),d=p.useCallback(()=>{var v,w;if(!((((v=n==null?void 0:n.contentIds)==null?void 0:v.length)??0)>0)){const{block:B,runs:I}=te("paragraph")(t);Hf(e,[me(B,t,0,{blocks:[B],runs:I}),J(t,{collapsed:!1})]),ye(B.contentIds[0]);return}e.applyOperation(J(t,{collapsed:!((w=n==null?void 0:n.props)!=null&&w.collapsed)}))},[e,t,n==null?void 0:n.contentIds,(y=n==null?void 0:n.props)==null?void 0:y.collapsed]),c=Ie("be-toggle-heading",n);if(!n)return null;const{level:f=2,collapsed:u,titleRunIds:h=[]}=n.props,m=n.contentIds.length>0,g=`h${f}`,x=it(e,n);return l.jsxs("div",{className:c,"data-block-id":t,dir:x,children:[l.jsxs("div",{className:"be-toggle-heading-row",children:[l.jsx("button",{type:"button",className:"be-toggle-heading-marker",onClick:d,"aria-expanded":!u,"aria-label":m?u?"Expand section":"Collapse section":"Add content to section",children:u?l.jsx(Et,{}):l.jsx(mr,{})}),l.jsx(g,{className:`be-heading be-heading-${f} be-toggle-heading-title`,"data-empty":Oe(e,h)?"":void 0,"data-placeholder":`Toggle heading ${f}`,children:l.jsx(ft,{blockId:t,runIds:h,dir:x,onEnter:o,onBackspaceAtStart:s,onArrowUp:a,onArrowDown:i})})]}),!u&&l.jsx("div",{className:"be-toggle-heading-children",children:l.jsx(mt,{parentId:t})})]})}function Uf({level:t=2,collapsed:e=!1}={}){return function(r,o){const s=_(),a=o!=null&&o.length?o:[{id:_(),type:"text",value:"",marks:{}}],{block:i,runs:d}=te("paragraph")(s);return{block:{id:s,type:"toggleHeading",parentId:r,contentIds:[i.id],props:{level:t,collapsed:e,titleRunIds:a.map(c=>c.id)}},runs:[...a,...d],subtreeBlocks:[i]}}}function Vf(t,e){const{titleRunIds:n=[],level:r=2,collapsed:o}=t.props,s=n.map(i=>ht(e.store.getRun(i),e)).join(""),a=t.contentIds.map(i=>{const d=e.store.getBlock(i);return e.registry.get(d.type).toHTML(d,e)}).join("");return`<details${o?"":" open"}><summary><h${r}>${s}</h${r}></summary>${a}</details>`}function Yf(t,e){const{titleRunIds:n=[]}=t.props,r=n.map(s=>Ct(e.store.getRun(s),e)).join(""),o=t.contentIds.map(s=>{const a=e.store.getBlock(s);return e.registry.get(a.type).toPlainText(a,e)}).join(`
2925
3207
  `);return o?`${r}
2926
- ${o}`:r}function Nf(t,e){if(t.tagName!=="DETAILS")return null;const n=[...t.children].find(d=>d.tagName==="SUMMARY"),r=n==null?void 0:n.querySelector("h1,h2,h3,h4,h5,h6"),o=r?Math.min(6,Math.max(1,Number(r.tagName[1]))):2,s=r?Ye(r,e):[{id:E(),type:"text",value:"",marks:{}}],a=E(),i=[],u=[],c=[];for(const d of t.children){if(d===n||d.tagName!=="P")continue;const h=Ye(d,e),m={id:E(),type:"paragraph",parentId:a,contentIds:h.map(g=>g.id),props:{}};i.push(m),u.push(...h),c.push(m.id)}if(c.length===0){const{block:d,runs:h}=te("paragraph")(a);i.push(d),u.push(...h),c.push(d.id)}return{block:{id:a,type:"toggleHeading",parentId:null,contentIds:c,props:{level:o,collapsed:!t.hasAttribute("open"),titleRunIds:s.map(d=>d.id)}},runs:[...s,...u],subtreeBlocks:i}}const ai={component:_f,isLeaf:!1,defaultProps:{level:2,collapsed:!1,titleRunIds:[]},toHTML:Mf,toPlainText:Lf,fromHTML:Nf,slashCommands:[1,2,3].map(t=>({label:`Toggle heading ${t}`,icon:jt,keywords:["toggle","heading","collapse","section"],run:(e,n)=>Be(e,n,Of({level:t}))}))},Ur=[{label:"Blue",value:"#2b6fd6"},{label:"Green",value:"#2f9e44"},{label:"Red",value:"#e03131"},{label:"Purple",value:"#9c36b5"},{label:"Gray",value:"#495057"},{label:"Black",value:"#1a1a1a"}];function Af(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Df({isOpen:t,onClose:e,store:n,blockId:r}){const[o,s]=p.useState(""),[a,i]=p.useState(""),[u,c]=p.useState(Ur[0].value),[f,d]=p.useState([{key:"",value:""}]);p.useEffect(()=>{var w,v,j;if(!t)return;const x=n.getBlock(r);if(!x)return;const y=x.contentIds.map(I=>{var C;return((C=n.getRun(I))==null?void 0:C.value)??""}).join(""),k=((w=x.props)==null?void 0:w.customAttrs)??[];s(y),i(((v=x.props)==null?void 0:v.href)??""),c(((j=x.props)==null?void 0:j.color)??Ur[0].value),d([...k,{key:"",value:""}])},[t,r,n]);const h=p.useCallback((x,y)=>{d(k=>{const w=k.map((j,I)=>I===x?{...j,...y}:j),v=w[w.length-1];return(v.key.trim()||v.value.trim())&&w.push({key:"",value:""}),w})},[]),m=p.useCallback(x=>{d(y=>y.filter((k,w)=>w!==x))},[]),g=p.useCallback(()=>{const x={id:E(),type:"text",value:o,marks:{}},y=f.filter(k=>k.key.trim());Af(n,[Me(r,[x]),J(r,{href:a.trim(),color:u,customAttrs:y})]),e()},[n,r,o,a,u,f,e]);return l.jsxs(dt,{isOpen:t,onClose:e,title:"Edit button",children:[l.jsxs("label",{className:"be-modal-field",children:[l.jsx("span",{children:"Label"}),l.jsx("input",{type:"text",value:o,onChange:x=>s(x.target.value),placeholder:"Button"})]}),l.jsxs("label",{className:"be-modal-field",children:[l.jsx("span",{children:"Link URL"}),l.jsx("input",{type:"url",value:a,onChange:x=>i(x.target.value),placeholder:"https://example.com"})]}),l.jsxs("div",{className:"be-modal-field",children:[l.jsx("span",{children:"Color"}),l.jsx("div",{className:"be-modal-color-row",children:Ur.map(x=>l.jsx("button",{type:"button",className:`be-modal-color-swatch${u===x.value?" be-modal-color-swatch-active":""}`,style:{backgroundColor:x.value},title:x.label,"aria-label":x.label,onClick:()=>c(x.value)},x.value))})]}),l.jsxs("div",{className:"be-modal-field",children:[l.jsx("span",{children:"Custom attributes"}),f.map((x,y)=>l.jsxs("div",{className:"be-modal-attr-row",children:[l.jsx("input",{type:"text",placeholder:"name",value:x.key,onChange:k=>h(y,{key:k.target.value})}),l.jsx("input",{type:"text",placeholder:"value",value:x.value,onChange:k=>h(y,{value:k.target.value})}),(x.key||x.value)&&l.jsx("button",{type:"button",className:"be-modal-attr-remove",onClick:()=>m(y),"aria-label":"Remove attribute",children:l.jsx(Ot,{size:14})})]},y))]}),l.jsxs("div",{className:"be-modal-actions",children:[l.jsx("button",{type:"button",className:"be-modal-cancel",onClick:e,children:"Cancel"}),l.jsx("button",{type:"button",className:"be-modal-save",onClick:g,children:"Save"})]})]})}const Pf="#2b6fd6";function $f({id:t}){var w,v,j,I;const e=G(),n=be(t),{setSelectedBlockId:r}=ut(),[o,s]=p.useState(!1),a=p.useCallback(()=>{cn(e,t,(n==null?void 0:n.contentIds)??[],te("paragraph"))},[e,t,n]),i=p.useCallback(()=>{const C=Nn(e,t);dn(e,C,t,r)},[e,t,r]),u=p.useCallback(()=>_e(e,t,"up"),[e,t]),c=p.useCallback(()=>_e(e,t,"down"),[e,t]),f=p.useCallback(()=>{var T;const C=(T=n==null?void 0:n.props)==null?void 0:T.href;C&&window.open(C,"_blank","noopener,noreferrer")},[(w=n==null?void 0:n.props)==null?void 0:w.href]),d=Ie("be-button-block",n);if(!n)return null;const h=((v=n.props)==null?void 0:v.href)??"",m=((j=n.props)==null?void 0:j.color)??Pf,g=((I=n.props)==null?void 0:I.customAttrs)??[],x=Le(e,n.contentIds),y={};for(const{key:C,value:T}of g)C.trim()&&(y[`data-${C.trim()}`]=T);const k=it(e,n);return l.jsxs("div",{className:d,"data-block-id":t,dir:k,children:[l.jsxs("div",{className:"be-button-block-pill",style:{backgroundColor:m},...y,children:[l.jsx("span",{className:"be-button-block-label","data-empty":x?"":void 0,"data-placeholder":"Button",children:l.jsx(pt,{blockId:t,runIds:n.contentIds,dir:k,onEnter:a,onBackspaceAtStart:i,onArrowUp:u,onArrowDown:c})}),l.jsx("button",{type:"button",className:"be-button-block-open",onClick:f,disabled:!h,title:h||"No link set","aria-label":"Open link",children:"↗"}),l.jsx("button",{type:"button",className:"be-button-block-settings",onClick:()=>s(!0),"aria-label":"Edit button",title:"Edit label, link, color…",children:"⚙"})]}),l.jsx(Df,{isOpen:o,onClose:()=>s(!1),store:e,blockId:t})]})}function zf({href:t="",label:e="Button",color:n="",customAttrs:r=[]}={}){return function(s,a){const i=E(),u=a!=null&&a.length?a:[{id:E(),type:"text",value:e,marks:{}}];return{block:{id:i,type:"button",parentId:s,contentIds:u.map(c=>c.id),props:{href:t,color:n,customAttrs:r}},runs:u}}}const li="be-button-block-link";function Hf(t,e){var u,c,f;const n=t.contentIds.map(d=>e.store.getRun(d)),r=((u=t.props)==null?void 0:u.href)??"",o=(c=t.props)==null?void 0:c.color,s=o?` style="background-color:${Ee(o)}"`:"",i=(((f=t.props)==null?void 0:f.customAttrs)??[]).filter(d=>{var h;return(h=d.key)==null?void 0:h.trim()}).map(d=>` data-${Ee(d.key.trim())}="${Ee(d.value??"")}"`).join("");return`<a class="${li}" href="${Ee(r)}"${s}${i}>${n.map(d=>ft(d,e)).join("")}</a>`}function Ff(t,e){return t.contentIds.map(n=>It(e.store.getRun(n),e)).join("")}function Uf(t,e){var s;if(t.tagName!=="A"||!t.classList.contains(li))return null;const n=Ye(t,e),r=[];for(const a of t.attributes)a.name.startsWith("data-")&&r.push({key:a.name.slice(5),value:a.value});return{block:{id:E(),type:"button",parentId:null,contentIds:n.map(a=>a.id),props:{href:t.getAttribute("href")??"",color:((s=t.style)==null?void 0:s.backgroundColor)||void 0,customAttrs:r}},runs:n}}const ii={component:$f,isLeaf:!0,defaultProps:{href:"",color:"",customAttrs:[]},toHTML:Hf,toPlainText:Ff,fromHTML:Uf,slashCommand:{label:"Button",icon:hd,keywords:["button","link","cta","action"],run:(t,e)=>Be(t,e,zf())}};function Zs(t){return new Promise((e,n)=>{const r=new FileReader;r.onload=()=>e(r.result),r.onerror=()=>n(r.error),r.readAsDataURL(t)})}const Kn={image:"image",video:"video",audio:"audio",file:"file"},Vf={image:"image/*",video:"video/*",audio:"audio/*",file:"*/*"},ci=20,ui=100,Yf=[{value:"left",Icon:Xa,label:"Align left"},{value:"center",Icon:nd,label:"Align center"},{value:"right",Icon:qa,label:"Align right"}];function Kf(t){return Math.min(ui,Math.max(ci,Math.round(t)))}function Wf({kind:t,src:e,name:n,alt:r}){return t==="image"?l.jsx("img",{className:"be-embed-image",src:e,alt:r||""}):t==="video"?l.jsx("video",{className:"be-embed-video",src:e,controls:!0}):t==="audio"?l.jsx("audio",{className:"be-embed-audio",src:e,controls:!0}):l.jsxs("a",{className:"be-embed-file-link",href:e,download:n||void 0,target:"_blank",rel:"noopener noreferrer",children:[l.jsx(Ha,{size:14})," ",n||e]})}function Xf({id:t}){var re;const e=G(),n=be(t),[r,o]=p.useState(""),[s,a]=p.useState(!1),[i,u]=p.useState(null),[c,f]=p.useState(!1),[d,h]=p.useState(""),m=p.useRef(null),g=p.useRef(null),x=p.useCallback(H=>e.applyOperation(J(t,H)),[e,t]),y=p.useCallback(()=>{var H;h(((H=n==null?void 0:n.props)==null?void 0:H.alt)??""),f(!0)},[(re=n==null?void 0:n.props)==null?void 0:re.alt]),k=p.useCallback(()=>f(!1),[]),w=p.useCallback(H=>{H.preventDefault(),x({alt:d.trim()}),f(!1)},[d,x]),v=p.useCallback(async H=>{var oe;const ne=(oe=H.target.files)==null?void 0:oe[0];if(!ne)return;const se=await Zs(ne);x({src:se,name:ne.name,mimeType:ne.type})},[x]),j=p.useCallback(async H=>{var oe;H.preventDefault(),a(!1);const ne=(oe=H.dataTransfer.files)==null?void 0:oe[0];if(!ne)return;const se=await Zs(ne);x({src:se,name:ne.name,mimeType:ne.type})},[x]),I=p.useCallback(H=>{H.preventDefault(),a(!0)},[]),C=p.useCallback(()=>a(!1),[]),T=p.useCallback(()=>{const H=r.trim();H&&(x({src:H,name:H}),o(""))},[r,x]),M=p.useCallback(()=>x({src:"",name:"",mimeType:""}),[x]),B=p.useCallback(H=>{H.preventDefault();const ne=m.current,se=g.current;if(!ne||!se)return;const oe=ne.getBoundingClientRect().width,ge=se.getBoundingClientRect().width,Te=H.clientX,ce=U=>Kf((ge+(U.clientX-Te))/oe*100),ke=U=>u(ce(U)),he=U=>{document.removeEventListener("mousemove",ke),document.removeEventListener("mouseup",he),x({width:ce(U)}),u(null)};document.addEventListener("mousemove",ke),document.addEventListener("mouseup",he)},[x]),L=Ie("be-embed",n);if(!n)return null;const{kind:S="file",src:N,name:$,alt:V="",align:K="left",width:Q=100}=n.props,D=S==="image"||S==="video",F=i??Q;return l.jsxs("div",{className:L,"data-block-id":t,"data-kind":S,contentEditable:!1,tabIndex:-1,children:[N?l.jsx("div",{ref:m,className:`be-embed-preview be-embed-align-${K}`,children:l.jsxs("div",{ref:g,className:"be-embed-frame",style:D?{width:`${F}%`}:void 0,children:[l.jsxs("div",{className:"be-embed-toolbar",contentEditable:!1,children:[Yf.map(({value:H,Icon:ne,label:se})=>l.jsx("button",{type:"button",className:`be-embed-toolbar-btn${K===H?" be-embed-toolbar-btn-active":""}`,title:se,"aria-label":se,"aria-pressed":K===H,onClick:()=>x({align:H}),children:l.jsx(ne,{size:14})},H)),S==="image"&&l.jsx("button",{type:"button",className:"be-embed-toolbar-btn be-embed-alt-text-btn",onClick:y,children:"Alt text"}),l.jsx("button",{type:"button",className:"be-embed-remove",onClick:M,"aria-label":`Remove ${Kn[S]}`,children:"Remove"})]}),l.jsx(Wf,{kind:S,src:N,name:$,alt:V}),D&&l.jsx("div",{className:"be-embed-resize-handle",onMouseDown:B,role:"slider","aria-label":`Resize ${Kn[S]}`,"aria-valuemin":ci,"aria-valuemax":ui,"aria-valuenow":F})]})}):l.jsxs("div",{className:`be-embed-dropzone${s?" be-embed-dropzone-active":""}`,onDrop:j,onDragOver:I,onDragLeave:C,children:[l.jsxs("label",{className:"be-embed-upload-btn",children:["Upload ",Kn[S],l.jsx("input",{type:"file",accept:Vf[S],onChange:v,hidden:!0})]}),l.jsx("span",{className:"be-embed-dropzone-hint",children:"or drop a file, or paste a URL below"}),l.jsxs("div",{className:"be-embed-url-row",children:[l.jsx("input",{type:"text",className:"be-embed-url-input",placeholder:`https://... ${Kn[S]} URL`,value:r,onChange:H=>o(H.target.value),onKeyDown:H=>H.key==="Enter"&&T()}),l.jsx("button",{type:"button",className:"be-embed-url-commit",onClick:T,children:"Embed"})]})]}),l.jsx(dt,{isOpen:c,onClose:k,title:"Alt text",children:l.jsxs("form",{onSubmit:w,children:[l.jsxs("label",{className:"be-modal-field",children:[l.jsx("span",{children:"Describe this image for screen readers"}),l.jsx("input",{type:"text",value:d,onChange:H=>h(H.target.value),placeholder:"e.g. A hand-drawn diagram of the release process",autoFocus:!0})]}),l.jsxs("div",{className:"be-modal-actions",children:[l.jsx("button",{type:"button",className:"be-modal-cancel",onClick:k,children:"Cancel"}),l.jsx("button",{type:"submit",className:"be-modal-save",children:"Save"})]})]})})]})}function qf({kind:t="file",src:e="",name:n="",alt:r="",mimeType:o="",align:s="left",width:a=100}={}){return function(u){return{block:{id:E(),type:"embed",parentId:u,contentIds:[],props:{kind:t,src:e,name:n,alt:r,mimeType:o,align:s,width:a}},runs:[]}}}const Gf={image:xd,video:yd,audio:kd,file:Ha},di="be-embed-file-link";function Jf(t,e,n){if(t!=="image"&&t!=="video")return"";const r=[];return n!==100&&r.push(`width:${n}%`),e==="center"?r.push("display:block","margin-left:auto","margin-right:auto"):e==="right"&&r.push("display:block","margin-left:auto"),r.length?` style="${r.join(";")}"`:""}function Qs(t){var o,s,a,i;const e=(o=t.style)==null?void 0:o.width,n=e&&e.endsWith("%")?parseInt(e,10):100;let r="left";return((s=t.style)==null?void 0:s.marginLeft)==="auto"&&((a=t.style)==null?void 0:a.marginRight)==="auto"?r="center":((i=t.style)==null?void 0:i.marginLeft)==="auto"&&(r="right"),{align:r,width:Number.isFinite(n)?n:100}}function Zf(t){const{kind:e,src:n,name:r,alt:o="",align:s="left",width:a=100}=t.props;if(!n)return"<p></p>";const i=Jf(e,s,a);return e==="image"?`<img src="${Ee(n)}" alt="${Ee(o)}"${i}>`:e==="video"?`<video src="${Ee(n)}" controls${i}></video>`:e==="audio"?`<audio src="${Ee(n)}" controls></audio>`:`<a class="${di}" href="${Ee(n)}">${Et(r||n)}</a>`}function Qf(t){const{kind:e,src:n,name:r}=t.props;return n?`[${e}: ${r||n}]`:""}function eh(t){return t.tagName==="IMG"?Wn("image",t.getAttribute("src")??"","",{...Qs(t),alt:t.getAttribute("alt")??""}):t.tagName==="VIDEO"?Wn("video",t.getAttribute("src")??"","",Qs(t)):t.tagName==="AUDIO"?Wn("audio",t.getAttribute("src")??"",""):t.tagName==="A"&&t.classList.contains(di)?Wn("file",t.getAttribute("href")??"",t.textContent??""):null}function Wn(t,e,n,{align:r="left",width:o=100,alt:s=""}={}){return{block:{id:E(),type:"embed",parentId:null,contentIds:[],props:{kind:t,src:e,name:n,alt:s,align:r,width:o}},runs:[]}}function th(t){return(e,{blockId:n,runId:r,sliceStart:o,sliceEnd:s})=>{const a=e.getRun(r),i=(a==null?void 0:a.value)??"";e.applyOperation(ue(r,{value:i.slice(0,o)+i.slice(s)}));const u=yr(e,n,qf({kind:t}));return nt(e,u,te("paragraph")),u}}const pi={component:Xf,isLeaf:!0,defaultProps:{kind:"file",src:"",name:"",alt:"",mimeType:"",align:"left",width:100},toHTML:Zf,toPlainText:Qf,fromHTML:eh,slashCommands:["image","video","audio","file"].map(t=>({label:t.charAt(0).toUpperCase()+t.slice(1),icon:Gf[t],keywords:["embed","upload","insert",t],run:th(t)}))},fi=8,hi=.5,nh=.5,rh=4,Vr=.15,oh=8;function mi(t,e){return Math.hypot(t[0]-e[0],t[1]-e[1])}function Qn(t,e,n){return Math.min(n,Math.max(e,t))}function Xn(t){return Math.round(t*100)/100}const bi=.5;function sh(t){return t.some(([,,e])=>e!==void 0&&e!==bi)}function ah(t,{size:e=fi,thinning:n=hi}={}){const r=e/2,o=t.length;if(!sh(t))return new Array(o).fill(r);const a=new Array(o);let i=0;for(let c=0;c<o;c+=1){if(c>0){const g=mi(t[c],t[c-1]);i=i*.8+g*.2}const f=Qn(i/oh,0,1),d=t[c][2]??bi,h=.4+.6*Qn(d,0,1),m=Qn(r*h*(1-n*f),r*Vr,r);a[c]=m}const u=Math.min(rh,Math.floor(o/2));for(let c=0;c<u;c+=1){const f=(c+1)/(u+1),d=Vr+(1-Vr)*f;a[c]*=d,a[o-1-c]*=d}return a}function lh(t,e){const n=t.length;if(n<3||e<=0)return t;const r=new Array(n);r[0]=t[0],r[n-1]=t[n-1];for(let o=1;o<n-1;o+=1){const s=(t[o-1][0]+t[o+1][0])/2,a=(t[o-1][1]+t[o+1][1])/2,i=t[o][0]+(s-t[o][0])*e,u=t[o][1]+(a-t[o][1])*e;r[o]=[i,u,t[o][2]]}return r}function ih(t,e){const n=t.length,r=new Array(n),o=new Array(n);for(let s=0;s<n;s+=1){const a=t[Math.max(0,s-1)],i=t[Math.min(n-1,s+1)];let u=i[0]-a[0],c=i[1]-a[1];const f=Math.hypot(u,c)||1;u/=f,c/=f;const d=-c,h=u,m=e[s];r[s]=[t[s][0]+d*m,t[s][1]+h*m],o[s]=[t[s][0]-d*m,t[s][1]-h*m]}return{left:r,right:o}}function gi(t){if(t.length===0)return"";let e=`M${Xn(t[0][0])},${Xn(t[0][1])}`;for(let n=1;n<t.length;n+=1)e+=` L${Xn(t[n][0])},${Xn(t[n][1])}`;return e}function ch([t,e],n){const o=[];for(let s=0;s<12;s+=1){const a=s/12*Math.PI*2;o.push([t+Math.cos(a)*n,e+Math.sin(a)*n])}return`${gi(o)} Z`}function ar(t,e={}){const{size:n=fi,thinning:r=hi,smoothing:o=nh}=e;if(!t||t.length===0)return"";const s=[t[0]];for(let d=1;d<t.length;d+=1)mi(t[d],s[s.length-1])>.1&&s.push(t[d]);if(s.length===1){const d=s[0][2]??.5,h=n/2*(.4+.6*Qn(d,0,1));return ch(s[0],h)}const a=ah(s,{size:n,thinning:r}),i=lh(s,o),{left:u,right:c}=ih(i,a),f=[...u,...c.slice().reverse()];return`${gi(f)} Z`}function er(t){if(!t||t.length===0)return{minX:0,minY:0,maxX:0,maxY:0};let e=1/0,n=1/0,r=-1/0,o=-1/0;for(const[s,a]of t)s<e&&(e=s),a<n&&(n=a),s>r&&(r=s),a>o&&(o=a);return{minX:e,minY:n,maxX:r,maxY:o}}function Xo(t,e){const n=t.getBoundingClientRect(),r=n.width||1,o=n.height||1,s=Math.min(r/e,o/e),a=(r-e*s)/2,i=(o-e*s)/2;return{rect:n,scale:s,offsetX:a,offsetY:i}}function qe(t,e,n={x:0,y:0,size:1e3}){const{rect:r,scale:o,offsetX:s,offsetY:a}=Xo(e,n.size),i=n.x+(t.clientX-r.left-s)/o,u=n.y+(t.clientY-r.top-a)/o;return[i,u]}function Yr(t,e){return Xo(t,e).scale}function uh(t,e,n,r){const[o,s]=qe(t,e,n),{rect:a,scale:i,offsetX:u,offsetY:c}=Xo(e,r),f=o-(t.clientX-a.left-u)/i,d=s-(t.clientY-a.top-c)/i;return{x:f,y:d}}function ea(t,e){const n=t.x+t.size/2,r=t.y+t.size/2;return{x:n-e/2,y:r-e/2}}function gn(t,e,n=0){return t.minX-n<=e.maxX&&t.maxX+n>=e.minX&&t.minY-n<=e.maxY&&t.maxY+n>=e.minY}function wn(t,e,n,r){const o=Math.min(t,n),s=Math.min(e,r),a=Math.abs(n-t),i=Math.abs(r-e);return{x:o,y:s,width:a,height:i}}function xi(t,e,n,r,o){const s=o*Math.PI/180,a=Math.cos(s),i=Math.sin(s),u=t-n,c=e-r;return[n+u*a-c*i,r+u*i+c*a]}function yi(t,e,n){return t>=n.x&&t<=n.x+n.width&&e>=n.y&&e<=n.y+n.height}function dh(t,e,n){const r=n.width/2,o=n.height/2;if(r===0||o===0)return!1;const s=n.x+r,a=n.y+o,i=(t-s)/r,u=(e-a)/o;return i*i+u*u<=1}function ph(t,e,n,r,o,s){const a=o-n,i=s-r,u=a*a+i*i;if(u===0)return Math.hypot(t-n,e-r);let c=((t-n)*a+(e-r)*i)/u;c=Math.min(1,Math.max(0,c));const f=n+c*a,d=r+c*i;return Math.hypot(t-f,e-d)}function ki(t,e,n,r,o,s,a){return ph(t,e,n,r,o,s)<=a}function vi(t){const{x:e,y:n,width:r,height:o}=t;return[[e+r/2,n],[e+r,n+o/2],[e+r/2,n+o],[e,n+o/2]]}function wi(t){const{x:e,y:n,width:r,height:o}=t;return[[e+r/2,n],[e+r,n+o],[e,n+o]]}function Ii(t,e=5){const{x:n,y:r,width:o,height:s}=t,a=n+o/2,i=r+s/2,u=o/2,c=s/2,f=.4,d=[],h=Math.PI/e;let m=-Math.PI/2;for(let g=0;g<e*2;g+=1){const x=g%2===0,y=x?u:u*f,k=x?c:c*f;d.push([a+Math.cos(m)*y,i+Math.sin(m)*k]),m+=h}return d}function fh(t,e,n){let r=!1;for(let o=0,s=n.length-1;o<n.length;s=o,o+=1){const[a,i]=n[o],[u,c]=n[s];i>e!=c>e&&t<(u-a)*(e-i)/(c-i)+a&&(r=!r)}return r}function Ci(t,e,n,r,o=24){const s=n-t,a=r-e,i=Math.hypot(s,a),[u,c]=i===0?[1,0]:[s/i,a/i],f=n-u*o,d=r-c*o,h=-c,m=u,g=o/2;return[[n,r],[f+h*g,d+m*g],[f-h*g,d-m*g]]}function hh({compute:t,onCommit:e}){const[n,r]=p.useState(null),o=p.useCallback((s,a)=>{s.preventDefault();const i=c=>r(t(c,a)),u=c=>{document.removeEventListener("mousemove",i),document.removeEventListener("mouseup",u),e(t(c,a)),r(null)};document.addEventListener("mousemove",i),document.addEventListener("mouseup",u)},[t,e]);return{dragValue:n,startDrag:o}}const qo=480,Go=320;function mh({strokes:t=[],shapes:e=[],width:n=qo,height:r=Go}={}){return function(s){return{block:{id:E(),type:"canvas",parentId:s,contentIds:[],props:{strokes:t,shapes:e,width:n,height:r}},runs:[]}}}const bh={diamond:vi,triangle:wi,star:Ii};function gh(t){const e=t.strokeWidth??8,n=Ee(t.color);if(t.type==="arrow"){const i=Math.max(16,e*3),c=Ci(t.x1,t.y1,t.x2,t.y2,i).map(([f,d])=>`${f},${d}`).join(" ");return`<line x1="${t.x1}" y1="${t.y1}" x2="${t.x2}" y2="${t.y2}" stroke="${n}" stroke-width="${e}"></line><polygon points="${c}" fill="${n}"></polygon>`}const r=t.fillColor?Ee(t.fillColor):"none";let o;if(t.type==="rectangle")o=`<rect x="${t.x}" y="${t.y}" width="${t.width}" height="${t.height}" fill="${r}" stroke="${n}" stroke-width="${e}"></rect>`;else if(t.type==="ellipse"){const i=t.x+t.width/2,u=t.y+t.height/2;o=`<ellipse cx="${i}" cy="${u}" rx="${t.width/2}" ry="${t.height/2}" fill="${r}" stroke="${n}" stroke-width="${e}"></ellipse>`}else if(t.type==="text"){const i=t.fontSize??28,u=Et(t.text??"");o=`<foreignObject x="${t.x}" y="${t.y}" width="${t.width}" height="${t.height}"><div xmlns="http://www.w3.org/1999/xhtml" style="width:100%;height:100%;overflow:hidden;color:${n};font-size:${i}px;line-height:1.3;white-space:pre-wrap;word-break:break-word;">${u}</div></foreignObject>`}else{const i=bh[t.type];if(!i)return"";const u={x:t.x,y:t.y,width:t.width,height:t.height};o=`<polygon points="${i(u).map(([f,d])=>`${f},${d}`).join(" ")}" fill="${r}" stroke="${n}" stroke-width="${e}"></polygon>`}if(!t.rotation)return o;const s=t.x+t.width/2,a=t.y+t.height/2;return`<g transform="rotate(${t.rotation} ${s} ${a})">${o}</g>`}function Si(t){const{strokes:e=[],shapes:n=[],width:r,height:o}=t.props,s=e.map(i=>`<path fill="${Ee(i.color)}" d="${ar(i.points,{size:i.size})}"></path>`).join(""),a=n.map(gh).join("");return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 1000" width="${r}" height="${o}">${s}${a}</svg>`}const Tt=1e3,ta="#1a1a1a",Ri=8,na=["#1a1a1a","#e03131","#2f9e44","#1971c2","#f08c00"],xh=2,yh=40,kh=24,vh=6,ra=160,wh=120,Kr=.5,Wr=4,qn=1.1,oa=4,Gn=24,Ih=1,Ch=10,sa={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},Sh=220,Rh=60,ro=28,Th=12,jh=96,oo=10,aa=15,la=oo*5;function Ae(t){return Math.round(t/oo)*oo}function Eh(t){return Math.round(t/aa)*aa}function Bh(){const t=p.useRef(new WeakMap);return e=>{const n=t.current;let r=n.get(e);return r===void 0&&(r=ar(e.points,{size:e.size}),n.set(e,r)),r}}function _h(t,e,n){return{minX:t-n,minY:e-n,maxX:t+n,maxY:e+n}}function ia(t){let e=0,n=0;for(const o of t.values())e+=o.x,n+=o.y;const r=t.size||1;return{x:e/r,y:n/r}}function Oh(t,e,n,r){const o=t.points;if(o.length===1){const[s,a]=o[0];return Math.hypot(e-s,n-a)<=r}for(let s=0;s<o.length-1;s+=1){const[a,i]=o[s],[u,c]=o[s+1];if(ki(e,n,a,i,u,c,r))return!0}return!1}const Xr=new Set(["rectangle","ellipse","arrow","diamond","triangle","star"]),Ti={diamond:vi,triangle:wi,star:Ii},ca=[{type:"rectangle",label:"Rectangle",Icon:Ga},{type:"ellipse",label:"Ellipse",Icon:od},{type:"arrow",label:"Arrow",Icon:sd},{type:"diamond",label:"Diamond",Icon:ad},{type:"triangle",label:"Triangle",Icon:ld},{type:"star",label:"Star",Icon:id}],ua=[{mode:"object",label:"Object Eraser",Icon:Ja},{mode:"precise",label:"Precise Eraser",Icon:Ot}];function qr(t,e,n,r){return t.type==="arrow"?{type:"arrow",x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,color:e,strokeWidth:n}:{type:t.type,...wn(t.x1,t.y1,t.x2,t.y2),color:e,strokeWidth:n,fillColor:r}}const Mh=16;function ji(t,e,n){for(let r=n.length-1;r>=0;r-=1){const o=n[r];if(o.type==="arrow"){if(ki(t,e,o.x1,o.y1,o.x2,o.y2,Mh))return o.id;continue}const s={x:o.x,y:o.y,width:o.width,height:o.height};let[a,i]=[t,e];if(o.rotation){const{cx:f,cy:d}=Rr(o);[a,i]=xi(t,e,f,d,-o.rotation)}const u=Ti[o.type];let c;if(u?c=fh(a,i,u(s)):c=o.type==="ellipse"?dh(a,i,s):yi(a,i,s),c)return o.id}return null}function xn(t,e,n){return t.type==="arrow"?{...t,x1:t.x1+e,y1:t.y1+n,x2:t.x2+e,y2:t.y2+n}:{...t,x:t.x+e,y:t.y+n}}function jn(t){return t.type==="arrow"?{x:Math.min(t.x1,t.x2),y:Math.min(t.y1,t.y2),width:Math.abs(t.x2-t.x1),height:Math.abs(t.y2-t.y1)}:{x:t.x,y:t.y,width:t.width,height:t.height}}function Rr(t){const e=jn(t);return{cx:e.x+e.width/2,cy:e.y+e.height/2}}function yn(t,e,n){return{...t,points:t.points.map(([r,o,s])=>[r+e,o+n,s])}}function Lh(t,e){const n=[];let r=[];for(let o=0;o<t.length;o+=1)e.has(o)?(r.length>0&&n.push(r),r=[]):r.push(t[o]);return r.length>0&&n.push(r),n}function Ei(t){const e=er(t.points);return{x:e.minX,y:e.minY,width:e.maxX-e.minX,height:e.maxY-e.minY}}function Nh(t,e){return t==="stroke"?Ei(e):jn(e)}function da(t,e){var a,i;const n=((a=t==null?void 0:t.props)==null?void 0:a.strokes)??[],r=((i=t==null?void 0:t.props)==null?void 0:i.shapes)??[],o=n.find(u=>u.id===e);if(o)return{kind:"stroke",item:o};const s=r.find(u=>u.id===e);return s?{kind:"shape",item:s}:null}function Ah(t,e,n,r){const o=ji(t,e,r);if(o)return{kind:"shape",id:o};for(let s=n.length-1;s>=0;s-=1){const a=n[s];if(yi(t,e,Ei(a)))return{kind:"stroke",id:a.id}}return null}const Jn=24,kn=14;function so(t){return{nw:[t.x,t.y],ne:[t.x+t.width,t.y],sw:[t.x,t.y+t.height],se:[t.x+t.width,t.y+t.height]}}const Dh={nw:"se",ne:"sw",sw:"ne",se:"nw"},Ph=32;function Bi(t){const e=jn(t),n=e.x+e.width/2,r=e.y-Ph;if(!t.rotation)return[n,r];const{cx:o,cy:s}=Rr(t);return xi(n,r,o,s,t.rotation)}function $h(t,e,n){if(!n)return null;if(n.type==="arrow")return Math.hypot(t-n.x1,e-n.y1)<=Jn?"start":Math.hypot(t-n.x2,e-n.y2)<=Jn?"end":null;const[r,o]=Bi(n);if(Math.hypot(t-r,e-o)<=Jn)return"rotate";if(n.rotation)return null;for(const[s,[a,i]]of Object.entries(so(n)))if(Math.hypot(t-a,e-i)<=Jn)return s;return null}function Gr(t,e){return e.mode==="arrow-endpoint"?e.endpoint==="start"?{...t,x1:e.x,y1:e.y}:{...t,x2:e.x,y2:e.y}:e.mode==="rotate"?{...t,rotation:e.rotation}:{...t,...wn(e.fixedX,e.fixedY,e.x,e.y)}}function pa({shape:t,opacity:e=1}){const n=t.strokeWidth??Ri;let r;if(t.type==="rectangle")r=l.jsx("rect",{x:t.x,y:t.y,width:t.width,height:t.height,fill:t.fillColor??"none",stroke:t.color,strokeWidth:n,opacity:e});else if(t.type==="ellipse")r=l.jsx("ellipse",{cx:t.x+t.width/2,cy:t.y+t.height/2,rx:t.width/2,ry:t.height/2,fill:t.fillColor??"none",stroke:t.color,strokeWidth:n,opacity:e});else if(t.type==="arrow"){const a=Math.max(16,n*3),i=Ci(t.x1,t.y1,t.x2,t.y2,a);return l.jsxs("g",{opacity:e,children:[l.jsx("line",{x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,stroke:t.color,strokeWidth:n}),l.jsx("polygon",{points:i.map(([u,c])=>`${u},${c}`).join(" "),fill:t.color})]})}else if(t.type==="text")r=l.jsx("foreignObject",{x:t.x,y:t.y,width:t.width,height:t.height,opacity:e,children:l.jsx("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{width:"100%",height:"100%",overflow:"hidden",color:t.color,fontSize:t.fontSize??ro,lineHeight:1.3,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"inherit"},children:t.text})});else{const a=Ti[t.type];if(!a)return null;const i={x:t.x,y:t.y,width:t.width,height:t.height},u=a(i).map(([c,f])=>`${c},${f}`).join(" ");r=l.jsx("polygon",{points:u,fill:t.fillColor??"none",stroke:t.color,strokeWidth:n,opacity:e})}if(!t.rotation)return r;const{cx:o,cy:s}=Rr(t);return l.jsx("g",{transform:`rotate(${t.rotation} ${o} ${s})`,children:r})}function zh({id:t}){const e=G(),n=be(t),r=Ie("be-canvas",n),o=Bh(),[s,a]=p.useState("pen"),[i,u]=p.useState("object"),[c,f]=p.useState(ta),[d,h]=p.useState(Ri),[m,g]=p.useState(null),[x,y]=p.useState(!0),[k,w]=p.useState(ro),[v,j]=p.useState("rectangle"),[I,C]=p.useState(!1),[T,M]=p.useState(!1),[B,L]=p.useState(!1),[S,N]=p.useState(!1),[$,V]=p.useState(!1),[K,Q]=p.useState(!1),D=p.useRef(null),F=p.useRef(null),re=p.useRef(null),H=p.useRef(null),ne=p.useRef(null),se=p.useRef(null),oe=p.useRef(null),ge=p.useRef(null),Te=p.useRef(null),ce=p.useRef(null),ke=p.useRef(null),he=p.useRef(null),U=p.useMemo(()=>[D,F],[]),ae=p.useMemo(()=>[re,H],[]),Ke=p.useMemo(()=>[ne,se],[]),An=p.useMemo(()=>[oe,ge],[]),jr=p.useMemo(()=>[Te,ce],[]),_c=p.useMemo(()=>[ke,he],[]),is=p.useCallback(()=>C(!1),[]),Er=p.useCallback(()=>M(!1),[]),Oc=p.useCallback(()=>L(!1),[]),cs=p.useCallback(()=>N(!1),[]),Mc=p.useCallback(()=>V(!1),[]),us=p.useCallback(()=>Q(!1),[]);Ue(U,I,is),Ue(ae,T,Er),Ue(Ke,B,Oc),Ue(An,S,cs),Ue(jr,$,Mc),Ue(_c,K,us);const We=p.useRef(null),fn=p.useRef([]),Lt=p.useRef(!1),Nt=p.useRef(null),[ds,ps]=p.useState(null),mt=p.useRef(new Set),Ct=p.useRef(new Set),At=p.useRef(new Map),Dt=p.useRef(!1),Pt=p.useRef(null),[Lc,fs]=p.useState(()=>new Set),[Nc,hs]=p.useState(()=>new Set),ze=p.useRef(null),[ms,Br]=p.useState(null),[le,rt]=p.useState(()=>new Set),bt=p.useRef(null),[we,bs]=p.useState(null),gt=p.useRef(null),[hn,gs]=p.useState(null),_r=p.useRef([]),[pe,$t]=p.useState(null),He=p.useRef(null),[xt,Or]=p.useState(null),[de,St]=p.useState({x:0,y:0,zoom:1}),Oe=Tt/de.zoom,Rt=p.useRef(null),Fe=p.useRef(new Map),yt=p.useRef(null),{dragValue:zt,startDrag:xs}=hh({compute:(b,R)=>({width:Math.max(ra,Math.round(R.startWidth+(b.clientX-R.startX))),height:Math.max(wh,Math.round(R.startHeight+(b.clientY-R.startY)))}),onCommit:b=>e.applyOperation(J(t,b))}),ys=p.useCallback(b=>{Nt.current==null&&(Nt.current=requestAnimationFrame(()=>{Nt.current=null,ps(ar(fn.current,{size:b}))}))},[]),Ht=p.useCallback(()=>{Lt.current=!1,Nt.current!=null&&(cancelAnimationFrame(Nt.current),Nt.current=null),fn.current=[],ps(null)},[]),ks=p.useCallback(()=>{var O;const b=fn.current;if(b.length===0)return;const R={id:E(),points:b,color:c,size:d},_=((O=n==null?void 0:n.props)==null?void 0:O.strokes)??[];e.applyOperation(J(t,{strokes:[..._,R]}))},[e,t,n,c,d]),vs=p.useCallback(()=>{Pt.current==null&&(Pt.current=requestAnimationFrame(()=>{Pt.current=null,fs(new Set(mt.current)),hs(new Set(Ct.current))}))},[]),Dn=p.useCallback((b,R)=>{var q,W;const _=i==="precise"?vh:kh,O=_h(b,R,_),P=((q=n==null?void 0:n.props)==null?void 0:q.strokes)??[];for(const z of P){if(i==="precise"){const ot=er(z.points);if(!gn(ot,O,z.size/2))continue;let Ce=At.current.get(z.id);z.points.forEach(([je,Se],fe)=>{Ce!=null&&Ce.has(fe)||Math.hypot(je-b,Se-R)>_||(Ce||(Ce=new Set,At.current.set(z.id,Ce)),Ce.add(fe))}),Ce!=null&&Ce.size&&mt.current.add(z.id);continue}if(mt.current.has(z.id))continue;const X=z.size/2,ie=er(z.points);gn(ie,O,X)&&Oh(z,b,R,_+X)&&mt.current.add(z.id)}const A=((W=n==null?void 0:n.props)==null?void 0:W.shapes)??[];for(const z of A){if(Ct.current.has(z.id))continue;const X=jn(z),ie={minX:X.x,minY:X.y,maxX:X.x+X.width,maxY:X.y+X.height};gn(ie,O)&&Ct.current.add(z.id)}vs()},[n,i,vs]),Ft=p.useCallback(()=>{Dt.current=!1,Pt.current!=null&&(cancelAnimationFrame(Pt.current),Pt.current=null),mt.current=new Set,Ct.current=new Set,At.current=new Map,fs(new Set),hs(new Set)},[]),ws=p.useCallback(()=>{var A,q;const b=i!=="precise"&&mt.current.size>0,R=i==="precise"&&At.current.size>0;if(!b&&!R&&Ct.current.size===0)return;const _=((A=n==null?void 0:n.props)==null?void 0:A.strokes)??[],O=((q=n==null?void 0:n.props)==null?void 0:q.shapes)??[];let P;if(b)P=_.filter(W=>!mt.current.has(W.id));else if(R){P=[];for(const W of _){const z=At.current.get(W.id);if(!z||z.size===0){P.push(W);continue}Lh(W.points,z).forEach((X,ie)=>{P.push({...W,id:ie===0?W.id:E(),points:X})})}}else P=_;e.applyOperation(J(t,{strokes:P,shapes:O.filter(W=>!Ct.current.has(W.id))}))},[e,t,n,i]),Ut=p.useCallback(()=>{ze.current=null,Br(null)},[]),Is=p.useCallback(()=>{var O;const b=ze.current;if(!b)return;if(b.type==="arrow"){if(b.x1===b.x2&&b.y1===b.y2)return}else{const P=wn(b.x1,b.y1,b.x2,b.y2);if(P.width===0||P.height===0)return}const R={id:E(),...qr(b,c,d,m)},_=((O=n==null?void 0:n.props)==null?void 0:O.shapes)??[];e.applyOperation(J(t,{shapes:[..._,R]}))},[e,t,n,c,d,m]),Vt=p.useCallback(()=>{bt.current=null,bs(null)},[]),Cs=p.useCallback(()=>{var q,W;const b=bt.current;if(!b||b.dx===0&&b.dy===0)return;const R=new Set(b.ids),_=((q=n==null?void 0:n.props)==null?void 0:q.strokes)??[],O=((W=n==null?void 0:n.props)==null?void 0:W.shapes)??[],P=_.map(z=>R.has(z.id)?yn(z,b.dx,b.dy):z),A=O.map(z=>R.has(z.id)?xn(z,b.dx,b.dy):z);e.applyOperation(J(t,{strokes:P,shapes:A}))},[e,t,n]),Yt=p.useCallback(()=>{gt.current=null,gs(null)},[]),Ss=p.useCallback(()=>{var q,W;const b=gt.current;if(!b)return;const R=wn(b.startX,b.startY,b.x,b.y);if(R.width<oa&&R.height<oa){rt(new Set);return}const _={minX:R.x,minY:R.y,maxX:R.x+R.width,maxY:R.y+R.height},O=((q=n==null?void 0:n.props)==null?void 0:q.strokes)??[],P=((W=n==null?void 0:n.props)==null?void 0:W.shapes)??[],A=[];for(const z of O)gn(er(z.points),_)&&A.push(z.id);for(const z of P){const X=jn(z),ie={minX:X.x,minY:X.y,maxX:X.x+X.width,maxY:X.y+X.height};gn(ie,_)&&A.push(z.id)}rt(new Set(A))},[n]),Mr=p.useCallback(()=>{le.size!==0&&(_r.current=[...le].map(b=>da(n,b)).filter(Boolean))},[n,le]),Lr=p.useCallback(()=>{var q,W;const b=_r.current;if(b.length===0)return;const R=((q=n==null?void 0:n.props)==null?void 0:q.strokes)??[],_=((W=n==null?void 0:n.props)==null?void 0:W.shapes)??[],O=[],P=[],A=[];for(const{kind:z,item:X}of b){const ie=E();A.push(ie),z==="stroke"?O.push({...yn(X,Gn,Gn),id:ie}):P.push({...xn(X,Gn,Gn),id:ie})}e.applyOperation(J(t,{strokes:[...R,...O],shapes:[..._,...P]})),rt(new Set(A)),a("select")},[e,t,n]),Kt=p.useCallback(b=>{var P,A;if(le.size===0)return;const R=q=>{const W=q.filter(X=>le.has(X.id));if(W.length===0)return q;const z=q.filter(X=>!le.has(X.id));return b?[...z,...W]:[...W,...z]},_=((P=n==null?void 0:n.props)==null?void 0:P.strokes)??[],O=((A=n==null?void 0:n.props)==null?void 0:A.shapes)??[];e.applyOperation(J(t,{strokes:R(_),shapes:R(O)}))},[e,t,n,le]),Ac=p.useCallback(()=>Kt(!0),[Kt]),Dc=p.useCallback(()=>Kt(!1),[Kt]),Nr=p.useCallback((b,R)=>{$t({id:null,x:b,y:R,width:Sh,height:Rh,text:"",color:c,fontSize:k})},[c,k]),Pn=p.useCallback(b=>{$t({id:b.id,x:b.x,y:b.y,width:b.width,height:b.height,text:b.text,color:b.color,fontSize:b.fontSize??ro})},[]),Pc=p.useCallback(()=>{$t(null)},[]),$c=p.useCallback(()=>{var q,W,z;const b=pe;if(!b)return;$t(null);const R=((q=n==null?void 0:n.props)==null?void 0:q.shapes)??[],_=b.text;if(!_.trim()){b.id&&(e.applyOperation(J(t,{shapes:R.filter(X=>X.id!==b.id)})),rt(new Set)),(W=We.current)==null||W.focus();return}const O=b.id??E(),P={id:O,type:"text",x:b.x,y:b.y,width:b.width,height:b.height,text:_,color:b.color,fontSize:b.fontSize},A=b.id?R.map(X=>X.id===b.id?P:X):[...R,P];e.applyOperation(J(t,{shapes:A})),rt(new Set([O])),a("select"),(z=We.current)==null||z.focus()},[e,t,n,pe]),Wt=p.useCallback(()=>{He.current=null,Or(null)},[]),Rs=p.useCallback(()=>{var A;const b=He.current;if(!b)return;const R=((A=n==null?void 0:n.props)==null?void 0:A.shapes)??[],_=R.find(q=>q.id===b.shapeId);if(!_)return;const O=Gr(_,b);if(O.type!=="arrow"&&(O.width===0||O.height===0))return;const P=R.map(q=>q.id===b.shapeId?O:q);e.applyOperation(J(t,{shapes:P}))},[e,t,n]),Ts=p.useCallback(b=>{var _;const R=We.current;if((_=R==null?void 0:R.hasPointerCapture)!=null&&_.call(R,b)&&R.releasePointerCapture(b),ze.current){Ut();return}if(bt.current){Vt();return}if(gt.current){Yt();return}if(He.current){Wt();return}if(Lt.current){Ht();return}Dt.current&&Ft()},[Ut,Vt,Yt,Wt,Ht,Ft]),zc=p.useCallback(b=>{var O,P,A,q,W;if(b.key==="Backspace"||b.key==="Delete"){if(le.size===0)return;b.preventDefault();const z=((O=n==null?void 0:n.props)==null?void 0:O.strokes)??[],X=((P=n==null?void 0:n.props)==null?void 0:P.shapes)??[];e.applyOperation(J(t,{strokes:z.filter(ie=>!le.has(ie.id)),shapes:X.filter(ie=>!le.has(ie.id))})),rt(new Set);return}if(sa[b.key]&&!b.ctrlKey&&!b.metaKey){if(le.size===0)return;b.preventDefault();const z=b.shiftKey?Ch:Ih,[X,ie]=sa[b.key],ot=X*z,Ce=ie*z,je=((A=n==null?void 0:n.props)==null?void 0:A.strokes)??[],Se=((q=n==null?void 0:n.props)==null?void 0:q.shapes)??[];e.applyOperation(J(t,{strokes:je.map(fe=>le.has(fe.id)?yn(fe,ot,Ce):fe),shapes:Se.map(fe=>le.has(fe.id)?xn(fe,ot,Ce):fe)}));return}if(b.key==="Enter"&&!b.ctrlKey&&!b.metaKey){if(le.size!==1)return;const[z]=le,X=(((W=n==null?void 0:n.props)==null?void 0:W.shapes)??[]).find(ie=>ie.id===z&&ie.type==="text");if(!X)return;b.preventDefault(),Pn(X);return}if(!(b.ctrlKey||b.metaKey))return;const _=b.key.toLowerCase();if(_==="c"){if(le.size===0)return;b.preventDefault(),Mr()}else if(_==="v"){if(_r.current.length===0)return;b.preventDefault(),Lr()}else if(_==="d"){if(le.size===0)return;b.preventDefault(),Mr(),Lr()}else if(b.shiftKey&&(_==="]"||_==="[")){if(le.size===0)return;b.preventDefault(),Kt(_==="]")}},[e,t,n,le,Mr,Lr,Kt,Pn]),kt={x:de.x,y:de.y,size:Oe},Ar=p.useCallback(b=>{const R=We.current;if(!R)return;if(b.preventDefault(),b.ctrlKey||b.metaKey){St(O=>{const P=b.deltaY<0?qn:1/qn,A=Math.min(Wr,Math.max(Kr,O.zoom*P)),q=Tt/A,{x:W,y:z}=uh(b,R,{x:O.x,y:O.y,size:Tt/O.zoom},q);return{x:W,y:z,zoom:A}});return}const _=Yr(R,Oe);St(O=>({...O,x:O.x+b.deltaX/_,y:O.y+b.deltaY/_}))},[Oe]);p.useEffect(()=>{const b=We.current;if(b)return b.addEventListener("wheel",Ar,{passive:!1}),()=>b.removeEventListener("wheel",Ar)},[Ar]);const Hc=p.useCallback(()=>{St(b=>{const R=Math.min(Wr,b.zoom*qn),_=Tt/R,{x:O,y:P}=ea({x:b.x,y:b.y,size:Tt/b.zoom},_);return{x:O,y:P,zoom:R}})},[]),Fc=p.useCallback(()=>{St(b=>{const R=Math.max(Kr,b.zoom/qn),_=Tt/R,{x:O,y:P}=ea({x:b.x,y:b.y,size:Tt/b.zoom},_);return{x:O,y:P,zoom:R}})},[]),Uc=p.useCallback(()=>{St({x:0,y:0,zoom:1})},[]),Vc=p.useCallback(()=>{if(!n)return;const b=Si(n),R=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(b)}`,_=new Image;_.onload=()=>{const O=document.createElement("canvas");O.width=n.props.width,O.height=n.props.height;const P=O.getContext("2d");if(!P)return;P.drawImage(_,0,0,O.width,O.height);const A=document.createElement("a");A.href=O.toDataURL("image/png"),A.download="canvas.png",document.body.appendChild(A),A.click(),document.body.removeChild(A)},_.src=R},[n]),Yc=p.useCallback(b=>{var W;if(s!=="select")return;const R=We.current;if(!R)return;const[_,O]=qe(b,R,{x:de.x,y:de.y,size:Oe}),P=((W=n==null?void 0:n.props)==null?void 0:W.shapes)??[],A=ji(_,O,P),q=P.find(z=>z.id===A);(q==null?void 0:q.type)==="text"&&(rt(new Set([q.id])),Pn(q))},[s,de.x,de.y,Oe,n,Pn]),Kc=p.useCallback(b=>{var P,A,q,W,z,X,ie,ot,Ce;const R=We.current;if(!R)return;if(b.pointerType==="touch"&&(Fe.current.set(b.pointerId,{x:b.clientX,y:b.clientY}),Fe.current.size>=2)){if(b.preventDefault(),(P=R.setPointerCapture)==null||P.call(R,b.pointerId),!yt.current){for(const Se of Fe.current.keys())Se!==b.pointerId&&Ts(Se);const je=ia(Fe.current);yt.current={startCenterX:je.x,startCenterY:je.y,startViewX:de.x,startViewY:de.y}}return}if(pe){if((q=(A=b.target)==null?void 0:A.closest)!=null&&q.call(A,".be-canvas-text-editor"))return;if((z=(W=document.activeElement)==null?void 0:W.blur)==null||z.call(W),s==="text"){let[je,Se]=qe(b,R,kt);x&&([je,Se]=[Ae(je),Ae(Se)]),Nr(je,Se),a("text");return}}if(b.button===1){b.preventDefault(),(X=R.setPointerCapture)==null||X.call(R,b.pointerId),Rt.current={startClientX:b.clientX,startClientY:b.clientY,startViewX:de.x,startViewY:de.y};return}if(!b.isPrimary||b.button!==void 0&&b.button!==0)return;b.preventDefault(),(ie=R.setPointerCapture)==null||ie.call(R,b.pointerId);const[_,O]=qe(b,R,kt);if(s==="eraser")mt.current=new Set,Ct.current=new Set,At.current=new Map,Dt.current=!0,Dn(_,O);else if(Xr.has(s)){const je=x?Ae(_):_,Se=x?Ae(O):O;ze.current={type:s,x1:je,y1:Se,x2:je,y2:Se},Br(qr(ze.current,c,d,m))}else if(s==="select"){const je=((ot=n==null?void 0:n.props)==null?void 0:ot.strokes)??[],Se=((Ce=n==null?void 0:n.props)==null?void 0:Ce.shapes)??[],fe=le.size===1?Se.find(st=>le.has(st.id))??null:null,Hn=$h(_,O,fe);if(Hn){if(Hn==="rotate"){const{cx:st,cy:qt}=Rr(fe),Gt=Math.atan2(O-qt,_-st)*180/Math.PI;He.current={mode:"rotate",shapeId:fe.id,cx:st,cy:qt,startAngle:Gt,startRotation:fe.rotation??0,rotation:fe.rotation??0}}else if(fe.type==="arrow")He.current={mode:"arrow-endpoint",shapeId:fe.id,endpoint:Hn,x:_,y:O};else{const[st,qt]=so(fe)[Dh[Hn]];He.current={mode:"rect-corner",shapeId:fe.id,fixedX:st,fixedY:qt,x:_,y:O}}Or(Gr(fe,He.current));return}const Xt=Ah(_,O,je,Se);if(Xt){if(b.shiftKey){rt(qt=>{const Gt=new Set(qt);return Gt.has(Xt.id)?Gt.delete(Xt.id):Gt.add(Xt.id),Gt});return}const st=le.has(Xt.id)?le:new Set([Xt.id]);rt(st),bt.current={ids:[...st],startX:_,startY:O,dx:0,dy:0},R.focus()}else gt.current={startX:_,startY:O,x:_,y:O}}else s==="text"?Nr(x?Ae(_):_,x?Ae(O):O):s==="pen"&&(fn.current=[[_,O,b.pressure||.5]],Lt.current=!0)},[s,Dn,de.x,de.y,Oe,c,d,m,x,n,le,Nr,pe,Ts]),Wc=p.useCallback(b=>{var _;const R=We.current;if(R){if(b.pointerType==="touch"&&Fe.current.has(b.pointerId)&&(Fe.current.set(b.pointerId,{x:b.clientX,y:b.clientY}),yt.current)){b.preventDefault();const O=Yr(R,Oe),P=ia(Fe.current),{startCenterX:A,startCenterY:q,startViewX:W,startViewY:z}=yt.current,X=(P.x-A)/O,ie=(P.y-q)/O;St(ot=>({...ot,x:W-X,y:z-ie}));return}if(Rt.current){const O=Yr(R,Oe),{startClientX:P,startClientY:A,startViewX:q,startViewY:W}=Rt.current,z=(b.clientX-P)/O,X=(b.clientY-A)/O;St(ie=>({...ie,x:q-z,y:W-X}));return}if(ze.current){let[O,P]=qe(b,R,kt);x&&([O,P]=[Ae(O),Ae(P)]),ze.current={...ze.current,x2:O,y2:P},Br(qr(ze.current,c,d,m));return}if(bt.current){const[O,P]=qe(b,R,kt),A=bt.current;A.dx=x?Ae(O-A.startX):O-A.startX,A.dy=x?Ae(P-A.startY):P-A.startY,bs({ids:A.ids,dx:A.dx,dy:A.dy});return}if(gt.current){const[O,P]=qe(b,R,kt),A=gt.current;A.x=O,A.y=P,gs(wn(A.startX,A.startY,A.x,A.y));return}if(He.current){let[O,P]=qe(b,R,kt);const A=He.current;if(A.mode==="rotate"){const z=Math.atan2(P-A.cy,O-A.cx)*180/Math.PI,X=A.startRotation+(z-A.startAngle);A.rotation=x?Eh(X):X}else x&&([O,P]=[Ae(O),Ae(P)]),A.x=O,A.y=P;const W=(((_=n==null?void 0:n.props)==null?void 0:_.shapes)??[]).find(z=>z.id===A.shapeId);W&&Or(Gr(W,A));return}if(Lt.current){const[O,P]=qe(b,R,kt);fn.current.push([O,P,b.pressure||.5]),ys(d)}else if(Dt.current){const[O,P]=qe(b,R,kt);Dn(O,P)}}},[ys,Dn,de.x,de.y,Oe,d,c,m,x,n]),ve=p.useCallback(b=>{var _;const R=We.current;(_=R==null?void 0:R.hasPointerCapture)!=null&&_.call(R,b.pointerId)&&R.releasePointerCapture(b.pointerId)},[]),Xc=p.useCallback(b=>{if(b.pointerType==="touch"&&(Fe.current.delete(b.pointerId),yt.current)){ve(b),Fe.current.size<2&&(yt.current=null);return}if(Rt.current){ve(b),Rt.current=null;return}if(ze.current){ve(b),Is(),Ut();return}if(bt.current){ve(b),Cs(),Vt();return}if(gt.current){ve(b),Ss(),Yt();return}if(He.current){ve(b),Rs(),Wt();return}Lt.current?(ve(b),ks(),Ht()):Dt.current&&(ve(b),ws(),Ft())},[ve,Is,Ut,Cs,Vt,Ss,Yt,Rs,Wt,ks,Ht,ws,Ft]),qc=p.useCallback(b=>{if(b.pointerType==="touch"&&(Fe.current.delete(b.pointerId),yt.current)){ve(b),Fe.current.size<2&&(yt.current=null);return}if(Rt.current){ve(b),Rt.current=null;return}if(ze.current){ve(b),Ut();return}if(bt.current){ve(b),Vt();return}if(gt.current){ve(b),Yt();return}if(He.current){ve(b),Wt();return}Lt.current?(ve(b),Ht()):Dt.current&&(ve(b),Ft())},[ve,Ut,Vt,Yt,Wt,Ht,Ft]),Gc=p.useCallback(b=>{var R,_;xs(b,{startX:b.clientX,startY:b.clientY,startWidth:((R=n==null?void 0:n.props)==null?void 0:R.width)??qo,startHeight:((_=n==null?void 0:n.props)==null?void 0:_.height)??Go})},[xs,n]);if(!n)return null;const{strokes:js=[],shapes:Es=[],width:Jc,height:Zc}=n.props,Bs=(zt==null?void 0:zt.width)??Jc,Qc=(zt==null?void 0:zt.height)??Zc,$n=6,zn=[...le].map(b=>{var P;const R=da(n,b);if(!R)return null;let{kind:_,item:O}=R;return(P=we==null?void 0:we.ids)!=null&&P.includes(b)?O=_==="stroke"?yn(O,we.dx,we.dy):xn(O,we.dx,we.dy):_==="shape"&&(xt==null?void 0:xt.id)===b&&(O=xt),{id:b,kind:_,item:O,box:Nh(_,O),rotation:_==="shape"?O.rotation:0}}).filter(Boolean),Dr=zn.length===1&&zn[0].kind==="shape"?zn[0]:null,Ne=(Dr==null?void 0:Dr.item)??null,eu=Ne&&Ne.type==="arrow"?[["start",Ne.x1,Ne.y1],["end",Ne.x2,Ne.y2]]:Ne&&!Ne.rotation?Object.entries(so(Ne)).map(([b,[R,_]])=>[b,R,_]):[],Pr=Ne&&Ne.type!=="arrow"?Bi(Ne):null;return l.jsxs("div",{className:r,"data-block-id":t,"data-tool":s,contentEditable:!1,tabIndex:-1,children:[l.jsxs("div",{className:"be-canvas-toolbar",contentEditable:!1,children:[l.jsx("button",{type:"button",className:`be-canvas-toolbar-btn${s==="pen"?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s==="pen","aria-label":"Pen",title:"Pen",onClick:()=>a("pen"),children:l.jsx(Ya,{size:14})}),l.jsxs("div",{className:"be-canvas-picker-wrap",children:[l.jsx("button",{ref:ke,type:"button",className:`be-canvas-toolbar-btn${s==="eraser"?" be-canvas-toolbar-btn-active":""}`,"aria-haspopup":"true","aria-expanded":K,"aria-pressed":s==="eraser","aria-label":"Eraser",title:"Eraser",onClick:()=>Q(b=>!b),children:(()=>{var R;const b=((R=ua.find(_=>_.mode===i))==null?void 0:R.Icon)??Ja;return l.jsx(b,{size:14})})()}),K&&l.jsx("div",{ref:he,className:"be-canvas-picker be-canvas-shape-picker",role:"menu","aria-label":"Eraser",children:ua.map(({mode:b,label:R,Icon:_})=>l.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-btn${s==="eraser"&&i===b?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s==="eraser"&&i===b,"aria-label":R,title:R,onClick:()=>{a("eraser"),u(b),us()},children:l.jsx(_,{size:14})},b))})]}),l.jsx("button",{type:"button",className:`be-canvas-toolbar-btn${s==="select"?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s==="select","aria-label":"Select",title:"Select",onClick:()=>a("select"),children:l.jsx(cd,{size:14})}),l.jsx("button",{type:"button",className:`be-canvas-toolbar-btn${s==="text"?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s==="text","aria-label":"Text",title:"Text",onClick:()=>a("text"),children:l.jsx(Eo,{size:14})}),l.jsxs("div",{className:"be-canvas-picker-wrap",children:[l.jsx("button",{ref:Te,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":$,"aria-label":`Font size: ${pe?pe.fontSize:k}`,title:"Font size",onClick:()=>V(b=>!b),children:l.jsx("span",{className:"be-canvas-font-size-trigger",children:"A"})}),$&&l.jsxs("div",{ref:ce,className:"be-canvas-picker be-canvas-size-picker",role:"dialog","aria-label":"Font size",children:[l.jsx("span",{className:"be-canvas-size-preview","aria-hidden":"true",children:l.jsx("span",{className:"be-canvas-font-size-preview-letter",style:{fontSize:pe?pe.fontSize:k},children:"A"})}),l.jsx("input",{type:"range",className:"be-canvas-size-slider",min:Th,max:jh,value:pe?pe.fontSize:k,onChange:b=>{const R=Number(b.target.value);w(R),pe&&$t(_=>_&&{..._,fontSize:R})},"aria-label":"Font size"}),l.jsxs("span",{className:"be-canvas-size-value",children:[pe?pe.fontSize:k,"px"]})]})]}),l.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Bring to front",title:"Bring to front",onClick:Ac,disabled:le.size===0,children:l.jsx(hr,{size:14})}),l.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Send to back",title:"Send to back",onClick:Dc,disabled:le.size===0,children:l.jsx(mr,{size:14})}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsxs("div",{className:"be-canvas-picker-wrap",children:[l.jsx("button",{ref:oe,type:"button",className:`be-canvas-toolbar-btn${Xr.has(s)?" be-canvas-toolbar-btn-active":""}`,"aria-haspopup":"true","aria-expanded":S,"aria-label":"Shape",title:"Shape",onClick:()=>N(b=>!b),children:(()=>{var R;const b=((R=ca.find(_=>_.type===(Xr.has(s)?s:v)))==null?void 0:R.Icon)??Ga;return l.jsx(b,{size:14})})()}),S&&l.jsx("div",{ref:ge,className:"be-canvas-picker be-canvas-shape-picker",role:"menu","aria-label":"Shape",children:ca.map(({type:b,label:R,Icon:_})=>l.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-btn${s===b?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s===b,"aria-label":R,title:R,onClick:()=>{a(b),j(b),cs()},children:l.jsx(_,{size:14})},b))})]}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsxs("div",{className:"be-canvas-picker-wrap",children:[l.jsx("button",{ref:D,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":I,"aria-label":`Color: ${c}`,title:"Color",onClick:()=>C(b=>!b),children:l.jsx("span",{className:"be-canvas-color-trigger-dot",style:{backgroundColor:c}})}),I&&l.jsxs("div",{ref:F,className:"be-canvas-picker be-canvas-color-picker",role:"menu","aria-label":"Pen color",children:[na.map(b=>l.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-swatch${c===b?" be-canvas-toolbar-swatch-active":""}`,style:{backgroundColor:b},"aria-pressed":c===b,"aria-label":`Color ${b}`,title:`Color ${b}`,onClick:()=>{f(b),is()}},b)),l.jsx("label",{className:"be-canvas-custom-swatch",title:"Custom color","aria-label":"Custom color",children:l.jsx("input",{type:"color",value:c,onChange:b=>f(b.target.value)})})]})]}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsxs("div",{className:"be-canvas-picker-wrap",children:[l.jsx("button",{ref:re,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":T,"aria-label":`Fill: ${m??"none"}`,title:"Fill",onClick:()=>M(b=>!b),children:l.jsx("span",{className:`be-canvas-fill-trigger-dot${m?"":" be-canvas-fill-trigger-dot-none"}`,style:m?{backgroundColor:m}:void 0})}),T&&l.jsxs("div",{ref:H,className:"be-canvas-picker be-canvas-color-picker",role:"menu","aria-label":"Shape fill",children:[l.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-swatch be-canvas-fill-swatch-none${m===null?" be-canvas-toolbar-swatch-active":""}`,"aria-pressed":m===null,"aria-label":"No fill",title:"No fill",onClick:()=>{g(null),Er()}}),na.map(b=>l.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-swatch${m===b?" be-canvas-toolbar-swatch-active":""}`,style:{backgroundColor:b},"aria-pressed":m===b,"aria-label":`Fill ${b}`,title:`Fill ${b}`,onClick:()=>{g(b),Er()}},b)),l.jsx("label",{className:"be-canvas-custom-swatch",title:"Custom fill","aria-label":"Custom fill",children:l.jsx("input",{type:"color",value:m??ta,onChange:b=>g(b.target.value)})})]})]}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsxs("div",{className:"be-canvas-picker-wrap",children:[l.jsx("button",{ref:ne,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":B,"aria-label":`Stroke size: ${d}`,title:"Stroke size",onClick:()=>L(b=>!b),children:l.jsx("span",{className:"be-canvas-size-trigger-dot",style:{width:Math.min(d,16),height:Math.min(d,16)}})}),B&&l.jsxs("div",{ref:se,className:"be-canvas-picker be-canvas-size-picker",role:"dialog","aria-label":"Stroke size",children:[l.jsx("span",{className:"be-canvas-size-preview","aria-hidden":"true",children:l.jsx("span",{className:"be-canvas-size-preview-dot",style:{width:d,height:d}})}),l.jsx("input",{type:"range",className:"be-canvas-size-slider",min:xh,max:yh,value:d,onChange:b=>h(Number(b.target.value)),"aria-label":"Stroke size"}),l.jsxs("span",{className:"be-canvas-size-value",children:[d,"px"]})]})]}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsx("button",{type:"button",className:`be-canvas-toolbar-btn${x?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":x,"aria-label":"Snap to grid",title:x?"Snap to grid: ON — drawing, moving, resizing and rotating align to the dotted grid. Click to turn off.":"Snap to grid: OFF — click to turn on (aligns drawing, moving, resizing and rotating to a grid)",onClick:()=>y(b=>!b),children:l.jsx(dd,{size:14})}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Zoom out",title:"Zoom out",onClick:Fc,disabled:de.zoom<=Kr,children:"−"}),l.jsxs("button",{type:"button",className:"be-canvas-zoom-label","aria-label":`Zoom: ${Math.round(de.zoom*100)}%. Click to reset to 100%.`,title:"Reset zoom to 100%",onClick:Uc,children:[Math.round(de.zoom*100),"%"]}),l.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Zoom in",title:"Zoom in",onClick:Hc,disabled:de.zoom>=Wr,children:"+"}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Export PNG",title:"Export as PNG",onClick:Vc,disabled:js.length===0&&Es.length===0,children:l.jsx(ud,{size:14})})]}),l.jsxs("svg",{ref:We,className:"be-canvas-surface",viewBox:`${de.x} ${de.y} ${Oe} ${Oe}`,width:Bs,height:Qc,tabIndex:-1,onPointerDown:Kc,onPointerMove:Wc,onPointerUp:Xc,onPointerCancel:qc,onDoubleClick:Yc,onKeyDown:zc,children:[x&&l.jsxs(l.Fragment,{children:[l.jsx("defs",{children:l.jsx("pattern",{id:`be-canvas-grid-${t}`,width:la,height:la,patternUnits:"userSpaceOnUse",children:l.jsx("circle",{cx:1,cy:1,r:1.5,className:"be-canvas-grid-dot"})})}),l.jsx("rect",{className:"be-canvas-grid-background",x:de.x,y:de.y,width:Oe,height:Oe,fill:`url(#be-canvas-grid-${t})`})]}),js.map(b=>{var O;const _=((O=we==null?void 0:we.ids)==null?void 0:O.includes(b.id))?ar(yn(b,we.dx,we.dy).points,{size:b.size}):o(b);return l.jsx("path",{d:_,fill:b.color,fillRule:"nonzero",opacity:Lc.has(b.id)?.25:1},b.id)}),ds&&l.jsx("path",{d:ds,fill:c,fillRule:"nonzero"}),Es.map(b=>{var _;let R=b;return(_=we==null?void 0:we.ids)!=null&&_.includes(b.id)?R=xn(b,we.dx,we.dy):(xt==null?void 0:xt.id)===b.id&&(R=xt),l.jsx(pa,{shape:R,opacity:Nc.has(b.id)?.25:1},b.id)}),ms&&l.jsx(pa,{shape:ms,opacity:.6}),zn.map(({id:b,box:R,rotation:_})=>l.jsx("g",{transform:_?`rotate(${_} ${R.x+R.width/2} ${R.y+R.height/2})`:void 0,children:l.jsx("rect",{className:"be-canvas-selection-box",x:R.x-$n,y:R.y-$n,width:R.width+$n*2,height:R.height+$n*2,fill:"none"})},b)),eu.map(([b,R,_])=>l.jsx("rect",{className:"be-canvas-selection-handle",x:R-kn/2,y:_-kn/2,width:kn,height:kn},b)),Pr&&l.jsx("circle",{className:"be-canvas-rotate-handle",cx:Pr[0],cy:Pr[1],r:kn/2}),hn&&l.jsx("rect",{className:"be-canvas-marquee",x:hn.x,y:hn.y,width:hn.width,height:hn.height}),pe&&l.jsx("foreignObject",{x:pe.x,y:pe.y,width:pe.width,height:pe.height,children:l.jsx("textarea",{xmlns:"http://www.w3.org/1999/xhtml",ref:b=>b==null?void 0:b.focus(),className:"be-canvas-text-editor",value:pe.text,style:{color:pe.color,fontSize:pe.fontSize},onChange:b=>$t(R=>R&&{...R,text:b.target.value}),onBlur:()=>$c(),onKeyDown:b=>{b.key==="Escape"&&(b.preventDefault(),Pc()),b.stopPropagation()}})})]}),l.jsx("div",{className:"be-canvas-resize-handle",onMouseDown:Gc,role:"slider","aria-label":"Resize canvas","aria-valuemin":ra,"aria-valuenow":Bs,contentEditable:!1})]})}function Hh(t){const{strokes:e=[],shapes:n=[]}=t.props;return!e.length&&!n.length?"<p></p>":Si(t)}function Fh(){return""}function Uh(){return null}function Vh(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o}){const s=t.getRun(n),a=(s==null?void 0:s.value)??"";t.applyOperation(ue(n,{value:a.slice(0,r)+a.slice(o)}));const i=yr(t,e,mh());return nt(t,i,te("paragraph")),i}const _i={component:zh,isLeaf:!0,defaultProps:{strokes:[],shapes:[],width:qo,height:Go},toHTML:Hh,toPlainText:Fh,fromHTML:Uh,slashCommand:{label:"Canvas",icon:Zu,keywords:["canvas","draw","drawing","sketch","freehand"],run:Vh}};function Oi(t){Mi(t,{paragraph:Il,heading:Cl,listItem:Ml,...Li,...Ni,divider:ei,callout:ni,blockquote:ri,code:si,toggleHeading:ai,button:ii,embed:pi,canvas:_i})}function Mi(t,e){for(const[n,r]of Object.entries(e))t.register(n,r)}const Li={table:ql,tableRow:Xl,tableCell:Wl},Ni={layout:Ql,layoutColumn:Zl};function Yh({id:t}){const e=G(),n=wt(t),r=p.useCallback(i=>{e.applyOperation(ue(t,{data:{...n==null?void 0:n.data,selectedValue:i}}))},[e,t,n==null?void 0:n.data]);if(!n)return null;const{options:o=[],selectedValue:s="",placeholder:a="Select…"}=n.data??{};return l.jsx("span",{className:"be-inline-select",onMouseDown:i=>{i.preventDefault(),i.stopPropagation()},onKeyDown:i=>i.stopPropagation(),children:l.jsx(Mt,{value:s,options:o,onChange:r,placeholder:a,ariaLabel:"Select an option"})})}function Tr(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o},s){const a=t.getRun(n),i=(a==null?void 0:a.value)??"",u=i.slice(0,r),c=i.slice(o),f=s(),d={...a,value:u},h={id:E(),type:"text",value:c,marks:{...a==null?void 0:a.marks}};t.applyOperation(_t(e,[n],[d,f,h])),ye(h.id)}function Kh(t){return String(t).replace(/&/g,"&amp;").replace(/"/g,"&quot;")}function Ai(t){var r;const{options:e=[],selectedValue:n=""}=t.data??{};return((r=e.find(o=>o.value===n))==null?void 0:r.label)??""}function Wh(t){var n,r;const e=Ai(t)||((n=t.data)==null?void 0:n.placeholder)||"";return`<span data-inline-type="select" data-selected-value="${Kh(((r=t.data)==null?void 0:r.selectedValue)??"")}">${e}</span>`}function Xh(t){return Ai(t)}function qh(t){var e;return((e=t.getAttribute)==null?void 0:e.call(t,"data-inline-type"))!=="select"?null:{id:E(),type:"select",value:"",marks:{},data:{options:[],selectedValue:t.getAttribute("data-selected-value")??""}}}const Di={component:Yh,isAtomic:!0,toHTML:Wh,toPlainText:Xh,fromHTML:qh,slashCommand:{label:"Select",icon:sl,keywords:["select","dropdown","choice","picker"],run:(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o})=>Tr(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o},()=>({id:E(),type:"select",value:"",marks:{},data:{options:[],selectedValue:"",placeholder:"Select…"}}))}};function Gh({id:t}){const e=G(),n=wt(t),r=p.useCallback(s=>{e.applyOperation(ue(t,{data:{...n==null?void 0:n.data,isoDate:s.target.value}}))},[e,t,n==null?void 0:n.data]);if(!n)return null;const{isoDate:o=""}=n.data??{};return l.jsx("span",{className:"be-inline-date",onMouseDown:s=>s.stopPropagation(),onKeyDown:s=>s.stopPropagation(),children:l.jsx("input",{type:"date",value:o,onChange:r})})}function Jh(t){return String(t).replace(/&/g,"&amp;").replace(/"/g,"&quot;")}function Pi(t){if(!t)return"";const e=new Date(`${t}T00:00:00`);return Number.isNaN(e.getTime())?t:e.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Zh(t){var n;const e=((n=t.data)==null?void 0:n.isoDate)??"";return`<span data-inline-type="date" data-iso-date="${Jh(e)}">${Pi(e)}</span>`}function Qh(t){var e;return Pi(((e=t.data)==null?void 0:e.isoDate)??"")}function em(t){var e;return((e=t.getAttribute)==null?void 0:e.call(t,"data-inline-type"))!=="date"?null:{id:E(),type:"date",value:"",marks:{},data:{isoDate:t.getAttribute("data-iso-date")??""}}}function tm(){return new Date().toISOString().slice(0,10)}const $i={component:Gh,isAtomic:!0,toHTML:Zh,toPlainText:Qh,fromHTML:em,slashCommand:{label:"Date",icon:gd,keywords:["date","when","schedule","calendar"],run:(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o})=>Tr(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o},()=>({id:E(),type:"date",value:"",marks:{},data:{isoDate:tm()}}))}};function nm({id:t}){const e=G(),n=wt(t),r=p.useCallback(i=>{e.applyOperation(ue(t,{data:{...n==null?void 0:n.data,checked:i.target.checked}}))},[e,t,n==null?void 0:n.data]),o=p.useCallback(i=>{e.applyOperation(ue(t,{data:{...n==null?void 0:n.data,label:i.target.value}}))},[e,t,n==null?void 0:n.data]);if(!n)return null;const{checked:s=!1,label:a=""}=n.data??{};return l.jsxs("span",{className:"be-inline-checkbox",onMouseDown:i=>i.stopPropagation(),onKeyDown:i=>i.stopPropagation(),children:[l.jsx("input",{type:"checkbox",className:"be-inline-checkbox-input",checked:s,onChange:r}),l.jsx("input",{type:"text",className:"be-inline-checkbox-label",value:a,onChange:o,placeholder:"Label…"})]})}function rm(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function om(t){const{checked:e=!1,label:n=""}=t.data??{};return`<span data-inline-type="checkbox" data-checked="${e}">${e?"☑":"☐"} ${rm(n)}</span>`}function sm(t){const{checked:e=!1,label:n=""}=t.data??{};return`${e?"[x]":"[ ]"} ${n}`.trim()}function am(t){var e;return((e=t.getAttribute)==null?void 0:e.call(t,"data-inline-type"))!=="checkbox"?null:{id:E(),type:"checkbox",value:"",marks:{},data:{checked:t.getAttribute("data-checked")==="true",label:(t.textContent??"").replace(/^[☑☐]\s*/,"")}}}const zi={component:nm,isAtomic:!0,toHTML:om,toPlainText:sm,fromHTML:am,slashCommand:{label:"Checkbox",icon:Oo,keywords:["checkbox","todo","check","toggle"],run:(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o})=>Tr(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o},()=>({id:E(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:""}}))}};function lm({id:t,blockId:e}){var m;const n=G(),r=wt(t),o=e?n.getBlock(e):null,s=o?n.getBlock(o.parentId):null,a=(s==null?void 0:s.parentId)??null,i=be(a),u=s?s.contentIds.indexOf(e):-1,f=(((m=(i&&s?$e(i,s.contentIds.length):[])[u])==null?void 0:m.options)??[]).map((g,x)=>({...g,color:g.color??Tn(x)})),d=p.useCallback((g,x)=>{n.applyOperation(ue(t,{data:{selectedValue:g,selectedLabel:(x==null?void 0:x.label)??""}}))},[n,t]);if(!r)return null;const{selectedValue:h=""}=r.data??{};return l.jsx("span",{className:"be-inline-table-select",onMouseDown:g=>{g.preventDefault(),g.stopPropagation()},onKeyDown:g=>g.stopPropagation(),children:l.jsx(Mt,{value:h,options:f,onChange:d,placeholder:"Select…",ariaLabel:"Select an option",variant:"tag"})})}function Hi(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function im(t){return Hi(t).replace(/"/g,"&quot;")}function cm(t){const{selectedValue:e="",selectedLabel:n=""}=t.data??{};return`<span data-inline-type="tableSelect" data-selected-value="${im(e)}">${Hi(n)}</span>`}function um(t){var e;return((e=t.data)==null?void 0:e.selectedLabel)??""}function dm(t){var e;return((e=t.getAttribute)==null?void 0:e.call(t,"data-inline-type"))!=="tableSelect"?null:{id:E(),type:"tableSelect",value:"",marks:{},data:{selectedValue:t.getAttribute("data-selected-value")??"",selectedLabel:t.textContent??""}}}const Fi={component:lm,isAtomic:!0,toHTML:cm,toPlainText:um,fromHTML:dm},Ui={};function Vi(t){Yi(t,{select:Di,date:$i,checkbox:zi,...Ki,emoji:Ui})}function Yi(t,e){for(const[n,r]of Object.entries(e))t.register(n,r)}const Ki={tableSelect:Fi};function pm(){const t="root",e=E(),n=E();return{rootId:t,blocks:[{id:t,type:"page",parentId:null,contentIds:[e],props:{}},{id:e,type:"paragraph",parentId:t,contentIds:[n],props:{}}],runs:[{id:n,type:"text",value:"",marks:{}}]}}function fm({doc:t,history:e=!0,registerBlocks:n,registerInlineTypes:r}={}){return p.useMemo(()=>{const o=cl();(n??Oi)(o);const s=dl();(r??Vi)(s);const a=new ur(t??pm());return{store:e?new ka(a):a,registry:o,inlineRegistry:s}},[])}function Wi({minHeight:t=180,className:e="be-trailing-space"}){const n=G(),[r]=Co(),o=p.useCallback(()=>{var c;if(r)return;const s=n.getRootId(),a=n.getBlock(s),i=(c=a==null?void 0:a.contentIds)==null?void 0:c[a.contentIds.length-1];if(!i){const f=un(n);f&&Ys(n,f);return}const u=n.getBlock(i);(u==null?void 0:u.type)==="paragraph"?Ys(n,i):nt(n,i,te("paragraph"))},[n,r]);return l.jsx("div",{className:e,style:{minHeight:t},onClick:o})}async function ao(t,e,n,r){var a,i,u;const{html:o,text:s}=En(t,e,r,n);if(typeof ClipboardItem<"u"&&((a=navigator.clipboard)!=null&&a.write)){await navigator.clipboard.write([new ClipboardItem({"text/plain":new Blob([s],{type:"text/plain"}),"text/html":new Blob([o],{type:"text/html"})})]);return}await((u=(i=navigator.clipboard)==null?void 0:i.writeText)==null?void 0:u.call(i,s))}function Jo(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function In(t,e){e.length!==0&&Jo(t,e.map(n=>ee(n)))}function Xi(t,e){if(e.length===0)return!1;const n=t.getBlock(e[0]);if(!n)return!1;const r=t.getBlock(n.parentId);if(!r)return!1;const o=r.contentIds.indexOf(e[0]),s=r.contentIds.indexOf(e[e.length-1]);if(o<=0)return!1;const a=r.contentIds[o-1];return t.applyOperation(ct(a,n.parentId,s)),!0}function qi(t,e){if(e.length===0)return!1;const n=t.getBlock(e[0]);if(!n)return!1;const r=t.getBlock(n.parentId);if(!r)return!1;const o=r.contentIds.indexOf(e[0]),s=r.contentIds.indexOf(e[e.length-1]);if(s===-1||s>=r.contentIds.length-1)return!1;const a=r.contentIds[s+1];return t.applyOperation(ct(a,n.parentId,o)),!0}function Gi(t,e){return e.length>0&&e.every(n=>{var r,o;return!!((o=(r=t.getBlock(n))==null?void 0:r.props)!=null&&o.hidden)})}function Ji(t,e,n){e.length!==0&&Jo(t,e.map(r=>J(r,{hidden:n})))}function hm(t,e,n,r){const o=n.filter(a=>{var i;return Ho((i=t.getBlock(a))==null?void 0:i.type)});if(o.length===0)return;const s=o.flatMap(a=>jl(t,e,a,r).ops);Jo(t,s)}function mm(t,e){if(e.length===0)return[];const n=t.getBlock(e[0]),r=n&&t.getBlock(n.parentId);if(!r)return e;const o=new Set(e);return r.contentIds.filter(s=>o.has(s))}function Zi(){const t=G(),e=vt(),n=tt(),[r,o]=_n(),[s,a]=p.useState(null),i=p.useRef(null),u=p.useRef(null),c=r.length>0,f=Ln(i,c,(s==null?void 0:s.bottom)!=null?s.bottom+4:null,s==null?void 0:s.left),d=p.useCallback(()=>o([]),[o]);kr(i,c,d,void 0),p.useEffect(()=>{if(!c){a(null);return}const C=()=>{const T=r[r.length-1],M=document.querySelector(`[data-block-row-id="${T}"]`);a((M==null?void 0:M.getBoundingClientRect())??null)};return C(),window.addEventListener("scroll",C,!0),window.addEventListener("resize",C),()=>{window.removeEventListener("scroll",C,!0),window.removeEventListener("resize",C)}},[c,r]),p.useEffect(()=>{if(!c)return;const C=M=>{var B,L,S,N;(B=i.current)!=null&&B.contains(M.target)||(L=u.current)!=null&&L.contains(M.target)||(N=(S=M.target).closest)!=null&&N.call(S,".be-block-gutter")||d()},T=M=>{M.key==="Escape"?d():(M.key==="Delete"||M.key==="Backspace")&&(M.preventDefault(),In(t,r),d())};return document.addEventListener("mousedown",C),document.addEventListener("keydown",T),()=>{document.removeEventListener("mousedown",C),document.removeEventListener("keydown",T)}},[c,t,r,d]);const h=C=>C===1?"block":"blocks",m=p.useCallback(()=>{ao(t,e,n,r),xe(`${r.length} ${h(r.length)} copied`),d()},[t,e,n,r,d]),g=p.useCallback(async()=>{await ao(t,e,n,r);const C=r.length;In(t,r),xe(`${C} ${h(C)} cut`),d()},[t,e,n,r,d]),x=p.useCallback(()=>{const C=r.length;In(t,r),xe(`${C} ${h(C)} deleted`),d()},[t,r,d]),y=p.useCallback(()=>{Xi(t,r)&&xe(`${r.length} ${h(r.length)} moved up`),d()},[t,r,d]),k=p.useCallback(()=>{qi(t,r)&&xe(`${r.length} ${h(r.length)} moved down`),d()},[t,r,d]),w=Gi(t,r),v=p.useCallback(()=>{Ji(t,r,!w),xe(w?`${r.length} ${h(r.length)} shown in preview`:`${r.length} ${h(r.length)} hidden in preview`),d()},[t,r,w,d]),j=r.some(C=>{var T;return Ho((T=t.getBlock(C))==null?void 0:T.type)}),I=p.useCallback(C=>{const T=r.length;hm(t,e,r,C),xe(`${T} ${h(T)} turned into ${C.label}`),d()},[t,e,r,d]);return!c||!f?null:Ve.createPortal(l.jsxs("div",{ref:i,role:"menu","aria-label":"Selected blocks options",className:"be-block-range-menu",style:{position:"fixed",top:f.top,left:f.left},children:[l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:m,children:[l.jsx(jo,{size:15})," Copy"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:g,children:[l.jsx(pd,{size:15})," Cut"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:y,children:[l.jsx(hr,{size:15})," Move up"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:k,children:[l.jsx(mr,{size:15})," Move down"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:v,children:[w?l.jsx(Mo,{size:15}):l.jsx(Lo,{size:15}),w?"Show in preview":"Hide in preview"]}),j&&l.jsx(El,{onSelect:I,onClose:()=>{},containerRef:u,menuClassName:"be-block-range-menu",itemClassName:"be-block-range-menu-item"}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item be-block-range-menu-item-danger",onClick:x,children:[l.jsx(On,{size:15})," Delete"]})]}),document.body)}const lr="application/x-block-editor-blocks+json";function Zo(t){return t.split(/\r\n|\r|\n/).filter(e=>e.length>0).map(e=>{const n=E();return{block:{id:E(),type:"paragraph",parentId:null,contentIds:[n],props:{}},runs:[{id:n,type:"text",value:e,marks:{}}]}})}function Qi(t,e,n){const r=new DOMParser().parseFromString(t,"text/html"),o={registry:e,inlineRegistry:n},s=e.listHtmlMatchers(),a=[],i=c=>{var h;const f=c.tagName==="OL",d=[];for(const m of c.children){if(m.tagName!=="LI")continue;const g=(h=e.get("listItem"))==null?void 0:h.fromHTML(m,o);g&&(g.block.props.ordered=f,d.push(g))}return d},u=c=>{var d;const f=Array.from(c.children).filter(h=>h.tagName==="P");if(f.length===0){const h=(d=e.get("blockquote"))==null?void 0:d.fromHTML(c,o);return h?[h]:[]}return f.map(h=>{const m=Ye(h,o);return{block:{id:E(),type:"blockquote",parentId:null,contentIds:m.map(g=>g.id),props:{}},runs:m}})};for(const c of r.body.childNodes){if(c.nodeType===3){const d=c.textContent.trim();d&&a.push(...Zo(d));continue}if(c.nodeType!==1)continue;if(c.tagName==="UL"||c.tagName==="OL"){a.push(...i(c));continue}if(c.tagName==="BLOCKQUOTE"){a.push(...u(c));continue}let f=null;for(const d of s){const h=d.fromHTML(c,o);if(h){f=h;break}}if(f)a.push(f);else if(c.textContent.trim()){const d=Ye(c,o);a.push({block:{id:E(),type:"paragraph",parentId:null,contentIds:d.map(h=>h.id),props:{}},runs:d})}}return a}function ec(t,e,n){const r=t.types??[];if(r.includes(lr)){const s=t.getData(lr);if(s)return bm(s)}if(r.includes("text/html")){const s=t.getData("text/html");if(s)return Qi(s,e,n)}const o=t.getData("text/plain")??"";return Zo(o)}function bm(t){return JSON.parse(t).blocks.map(n=>dr(n))}function lo(t,e){var r;const n=t.getBlock(e);return((r=n.props)==null?void 0:r.titleRunIds)??n.contentIds}function tr(){return{id:E(),type:"text",value:"",marks:{}}}function io(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function Qo(t,e,n){const{startRunId:r,startOffset:o,endRunId:s,endOffset:a}=n,i=lo(t,e),u=i.indexOf(r),c=i.indexOf(s);if(u===-1||c===-1)return null;const[f,d]=u<=c?[u,c]:[c,u],h=u<=c?o:a,m=u<=c?a:o,g=i.slice(0,f).map(I=>t.getRun(I)),x=i.slice(d+1).map(I=>t.getRun(I)),y=i.slice(f,d+1).map(I=>t.getRun(I)),k=[];let w=null,v=0;if(f===d){const I=y[0];if(I.type==="text"){const C=Math.max(0,Math.min(h,m)),T=Math.min(I.value.length,Math.max(h,m)),M={...I,value:I.value.slice(0,C)+I.value.slice(T)};k.push(M),w=M.id,v=C}}else y.forEach((I,C)=>{if(I.type!=="text")return;const T=C===0,M=C===y.length-1,B=T?I.value.slice(0,h):"";if(T&&B){const L={...I,value:B};k.push(L),w=L.id,v=B.length}if(M&&!T){const L=I.value.slice(m);if(L){const S={id:E(),type:"text",value:L,marks:I.marks};k.push(S),w===null&&(w=S.id,v=0)}}});let j=[...g,...k,...x];if(j.length===0){const I=tr();j=[I],w=I.id,v=0}else if(w===null){const I=g[g.length-1];I?(w=I.id,v=I.type==="text"?I.value.length:0):x[0]&&(w=x[0].id,v=0)}return t.applyOperation(Me(e,j)),{blockId:e,runId:w,offset:v}}function es(t,e){const{blockIds:n,startBlockId:r,startRunId:o,startOffset:s,endBlockId:a,endRunId:i,endOffset:u}=e;if(!n||n.length===0)return null;const c=n.indexOf(r),f=n.indexOf(a);if(c===-1||f===-1)return null;const[d,h]=c<=f?[c,f]:[f,c],m=c<=f,g=m?o:i,x=m?s:u,y=m?i:o,k=m?u:s;if(d===h)return Qo(t,n[d],{startRunId:g,startOffset:x,endRunId:y,endOffset:k});const w=n[d],v=n[h],j=t.getBlock(w),I=t.getBlock(v),C=lo(t,w),T=C.indexOf(g),M=C.slice(0,T).map(ce=>t.getRun(ce)),B=t.getRun(g),L=B.type==="text"&&x>0?{...B,value:B.value.slice(0,x)}:null,S=lo(t,v),N=S.indexOf(y),$=S.slice(N+1).map(ce=>t.getRun(ce)),V=t.getRun(y),K=V.type==="text"&&k<V.value.length?{id:E(),type:"text",value:V.value.slice(k),marks:V.marks}:null,Q=[...M,...L?[L]:[]],D=[...K?[K]:[],...$],F=[];for(let ce=d+1;ce<h;ce+=1)F.push(ee(n[ce]));const re=wl(j.type,I.type),H=t.getBlock(j.parentId),ne=h-d-1+(re?1:0),se=H&&H.contentIds.length-ne===1;let oe,ge,Te;if(re){const ce=[...Q,...D];if(ce.length===0&&se&&j.type!=="paragraph"){const{block:he,runs:U}=te("paragraph")(H.id);return F.push({type:"insertBlock",block:he,parentId:H.id,index:0,subtree:{blocks:[he],runs:U}}),F.push(ee(w)),F.push(ee(v)),io(t,F),{blockId:he.id,runId:he.contentIds[0],offset:0}}const ke=ce.length?ce:[tr()];if(F.push(Me(w,ke)),F.push(ee(v)),Te=w,L)oe=L.id,ge=L.value.length;else if(M.length){const he=M[M.length-1];oe=he.id,ge=he.type==="text"?he.value.length:0}else K?(oe=K.id,ge=0):$.length?(oe=$[0].id,ge=0):(oe=ke[0].id,ge=0)}else{const ce=Q.length?Q:[tr()];if(F.push(Me(w,ce)),F.push(Me(v,D.length?D:[tr()])),Te=w,L)oe=L.id,ge=L.value.length;else if(M.length){const ke=M[M.length-1];oe=ke.id,ge=ke.type==="text"?ke.value.length:0}else oe=ce[0].id,ge=0}return io(t,F),{blockId:Te,runId:oe,offset:ge}}function ir(t,e=""){var i;const n=t.getRootId(),r=((i=t.getBlock(n))==null?void 0:i.contentIds)??[];if(r.length===0)return null;const o=r.map(u=>ee(u)),{block:s,runs:a}=te("paragraph")(n);return e&&(a[0].value=e),o.push(me(s,n,0,{blocks:[s],runs:a})),io(t,o),{blockId:s.id,runId:s.contentIds[0],offset:e.length}}function co(t){var n;let e=(t==null?void 0:t.nodeType)===1?t:t==null?void 0:t.parentElement;for(;e&&typeof e.hasAttribute=="function"&&!e.hasAttribute("data-block-id");)e=e.parentElement;return((n=e==null?void 0:e.getAttribute)==null?void 0:n.call(e,"data-block-id"))??null}function gm(t){var d;const e=(d=window.getSelection)==null?void 0:d.call(window);if(!e||e.rangeCount===0)return[];const n=co(e.anchorNode),r=co(e.focusNode);if(!n)return[];if(!r||n===r)return[n];const o=t.getBlock(n),s=o&&t.getBlock(o.parentId);if(!s)return[n];const a=s.contentIds,i=a.indexOf(n),u=a.indexOf(r);if(i===-1||u===-1)return[n];const[c,f]=i<=u?[i,u]:[u,i];return a.slice(c,f+1)}function fa(t){const e=ln();if(e)return Qo(t,e.blockId,e);const n=rn(t);return n?es(t,n):null}function xm(t,e,n){const r=t.getRun(e.runId);if(!r||r.type!=="text")return null;const o=r.value??"",s=o.slice(0,e.offset)+n+o.slice(e.offset);return t.applyOperation(ue(r.id,{value:s})),{blockId:e.blockId,runId:r.id,offset:e.offset+n.length}}function Jr(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function tc(){const t=G(),e=vt(),n=tt(),[r,o]=Io(),[s,a]=_n(),i=p.useCallback(f=>{var x;const d=r?((x=t.getBlock(t.getRootId()))==null?void 0:x.contentIds)??[]:s.length>0?s:gm(t);if(d.length===0)return;const{html:h,text:m,json:g}=En(t,e,d,n);f.clipboardData.setData("text/plain",m),f.clipboardData.setData("text/html",h),f.clipboardData.setData(lr,g),f.preventDefault()},[t,e,n,r,s]),u=p.useCallback(f=>{if(i(f),r){const h=ir(t);o(!1),h!=null&&h.runId&&Je(h.runId,h.offset);return}if(s.length>0){In(t,s),a([]);return}const d=fa(t);d!=null&&d.runId&&Je(d.runId,d.offset)},[i,t,r,o,s,a]),c=p.useCallback(f=>{var v,j,I;const d=ec(f.clipboardData,e,n);if(d.length===0)return;if(r){const C=t.getRootId(),M=(((v=t.getBlock(C))==null?void 0:v.contentIds)??[]).map(L=>ee(L));let B=0;for(const{block:L,runs:S,subtreeBlocks:N=[]}of d)L.parentId=C,M.push(me(L,C,B,{blocks:[L,...N],runs:S})),B+=1;Jr(t,M),o(!1),f.preventDefault();return}if(s.length>0){const C=t.getBlock(s[0]),T=(C==null?void 0:C.parentId)??null,M=T&&t.getBlock(T);let B=M?M.contentIds.indexOf(s[0]):0;const L=s.map(S=>ee(S));for(const{block:S,runs:N,subtreeBlocks:$=[]}of d)S.parentId=T,L.push(me(S,T,B,{blocks:[S,...$],runs:N})),B+=1;Jr(t,L),a([]),f.preventDefault();return}const h=fa(t);if(d.length===1&&d[0].runs.every(C=>C.type==="text")&&(d[0].subtreeBlocks??[]).length===0){const C=h?{blockId:h.blockId,runId:h.runId,offset:h.offset}:lt();if(C){const T=d[0].runs.map(B=>B.value).join(""),M=xm(t,C,T);if(M){Je(M.runId,M.offset),f.preventDefault();return}}}const g=(h==null?void 0:h.blockId)??co((I=(j=window.getSelection)==null?void 0:j.call(window))==null?void 0:I.anchorNode);if(!g)return;const x=t.getBlock(g);if(!x)return;let k=t.getBlock(x.parentId).contentIds.indexOf(g)+1;const w=[];for(const{block:C,runs:T,subtreeBlocks:M=[]}of d)C.parentId=x.parentId,w.push(me(C,x.parentId,k,{blocks:[C,...M],runs:T})),k+=1;Jr(t,w),f.preventDefault()},[t,e,n,r,o,s,a]);return{onCopy:i,onCut:u,onPaste:c}}const ym=["bold","italic","underline","strike","subscript","superscript","code"],km=["color","highlight","link"];function on(t,e){var r;const n=t.getBlock(e);return((r=n.props)==null?void 0:r.titleRunIds)??n.contentIds}function vm(t,e){return t===e?!0:t&&e&&typeof t=="object"?JSON.stringify(t)===JSON.stringify(e):!1}function nc(t){var n;const e={};if(t.length===0)return e;for(const r of ym)e[r]=t.every(o=>{var s;return(s=o.marks)==null?void 0:s[r]});for(const r of km){const o=((n=t[0].marks)==null?void 0:n[r])??null;e[r]=t.every(s=>{var a;return vm(((a=s.marks)==null?void 0:a[r])??null,o)})?o:null}return e}function ts(t,e,n){const{startRunId:r,startOffset:o,endRunId:s,endOffset:a}=n,i=on(t,e),u=i.indexOf(r),c=i.indexOf(s);if(u===-1||c===-1)return{};const[f,d]=u<=c?[u,c]:[c,u],h=i.slice(f,d+1).map(m=>t.getRun(m)).filter(m=>m&&m.type==="text");return nc(h)}function ns(t,e){const{blockIds:n,startBlockId:r,endBlockId:o}=e,s=n.indexOf(r),a=n.indexOf(o);if(s===-1||a===-1)return{};const[i,u]=s<=a?[s,a]:[a,s],c=[];for(let f=i;f<=u;f+=1)for(const d of on(t,n[f])){const h=t.getRun(d);h&&h.type==="text"&&c.push(h)}return nc(c)}function rc(t,e){const n={...t};for(const[r,o]of Object.entries(e))o!=null?n[r]=o:delete n[r];return n}function oc(t,e,n,r,o,s){const a=rc(n.marks,s);if(r===0&&o===n.value.length)return t.applyOperation({type:"updateRun",id:n.id,patch:{marks:a}}),n.id;const i=n.value.slice(0,r),u=n.value.slice(r,o),c=n.value.slice(o),f=[];i&&f.push({id:E(),type:"text",value:i,marks:{...n.marks}});const d={id:E(),type:"text",value:u,marks:a};return f.push(d),c&&f.push({id:E(),type:"text",value:c,marks:{...n.marks}}),t.applyOperation(_t(e,[n.id],f)),d.id}function wm(t,e,n,r){const{startRunId:o,startOffset:s,endRunId:a,endOffset:i}=n,u=on(t,e),c=u.indexOf(o),f=u.indexOf(a);if(c===-1||f===-1)return null;const[d,h]=c<=f?[c,f]:[f,c],m=c<=f?s:i,g=c<=f?i:s,x=u.slice(d,h+1),y=x.map(v=>t.getRun(v));if(d===h){const v=y[0];if(v.type!=="text")return v.id;const j=Math.max(0,Math.min(m,g)),I=Math.min(v.value.length,Math.max(m,g));return j===I?v.id:oc(t,e,v,j,I,r)}const k=[];let w=null;return y.forEach((v,j)=>{if(v.type!=="text"){k.push(v),w=v.id;return}const I=j===0,C=j===y.length-1,T=I?m:0,M=C?g:v.value.length,B=v.value.slice(0,T),L=v.value.slice(T,M),S=v.value.slice(M);B&&k.push({id:E(),type:"text",value:B,marks:{...v.marks}});const N={id:E(),type:"text",value:L,marks:rc(v.marks,r)};k.push(N),w=N.id,S&&k.push({id:E(),type:"text",value:S,marks:{...v.marks}})}),t.applyOperation(_t(e,x,k)),w}function Im(t,e,n,r){var g;const{startRunId:o,startOffset:s,endRunId:a,endOffset:i}=n,u=on(t,e),c=u.indexOf(o),f=u.indexOf(a);if(c===-1||f===-1)return!0;const[d,h]=c<=f?[c,f]:[f,c],m=u.slice(d,h+1).map(x=>t.getRun(x)).filter(x=>x.type==="text");if(m.length===0)return!0;if(d===h){const x=Math.max(0,Math.min(s,i)),y=Math.min(m[0].value.length,Math.max(s,i));if(x===y)return!((g=m[0].marks)!=null&&g[r])}return!m.every(x=>{var y;return(y=x.marks)==null?void 0:y[r]})}function Cm(t,e,n,r,o,s){var d;const a=t.getRun(n),i=a.value??"",u=Math.max(0,Math.min(r,o)),c=Math.min(i.length,Math.max(r,o));if(u===c)return n;const f=!((d=a.marks)!=null&&d[s]);return oc(t,e,a,u,c,{[s]:f?!0:null})}function sn(t,e,n,r){return wm(t,e,n,r)}function rs(t,e,n,r){const o=Im(t,e,n,r);return sn(t,e,n,{[r]:o?!0:null})}function os(t,e,n){return cr(t,e,r=>({[n]:r?null:!0}),n)}function cr(t,e,n,r){var C;const{blockIds:o,startBlockId:s,startRunId:a,startOffset:i,endBlockId:u,endRunId:c,endOffset:f}=e;if(!o||o.length===0)return null;const d=o.indexOf(s),h=o.indexOf(u);if(d===-1||h===-1)return null;const[m,g]=d<=h?[d,h]:[h,d],x=d<=h,y=x?a:c,k=x?i:f,w=x?c:a,v=x?f:i;let j=n;if(typeof n=="function"){let T=!1,M=!0;for(let B=m;B<=g;B+=1){const L=on(t,o[B]).map(S=>t.getRun(S)).filter(S=>S.type==="text");L.length!==0&&(T=!0,L.every(S=>{var N;return(N=S.marks)==null?void 0:N[r]})||(M=!1))}j=n(T&&M)}if(m===g)return sn(t,o[m],{startRunId:y,startOffset:k,endRunId:w,endOffset:v},j);let I=null;for(let T=m;T<=g;T+=1){const M=o[T],B=on(t,M),L=B[0],S=B[B.length-1],N=t.getRun(S),$=((C=N==null?void 0:N.value)==null?void 0:C.length)??0;let V;T===m&&T===g?V={startRunId:y,startOffset:k,endRunId:w,endOffset:v}:T===m?V={startRunId:y,startOffset:k,endRunId:S,endOffset:$}:T===g?V={startRunId:L,startOffset:0,endRunId:w,endOffset:v}:V={startRunId:L,startOffset:0,endRunId:S,endOffset:$},I=sn(t,M,V,j)}return I}function sc(t,e){var r;const n=t.getBlock(e);return((r=n==null?void 0:n.props)==null?void 0:r.titleRunIds)??(n==null?void 0:n.contentIds)??[]}function ac(t){const e=ln();if(!e)return!1;const{blockId:n,startRunId:r,startOffset:o,endRunId:s,endOffset:a}=e,i=sc(t,n);if(i.length===0)return!1;const u=i.indexOf(r),c=i.indexOf(s);if(u===-1||c===-1)return!1;const[f,d]=u<=c?[u,c]:[c,u],h=u<=c?o:a,m=u<=c?a:o;if(f!==0||d!==i.length-1||h!==0)return!1;const g=t.getRun(i[i.length-1]),x=(g==null?void 0:g.type)==="text"?(g.value??"").length:1;return m===x}function Sm(t){const e=lt();return e?Le(t,sc(t,e.blockId)):!1}function Rm(t,e,n){var m,g;const r=t.getBlock(e);if(!r){n(null);return}const o=t.getBlock(r.parentId),s=o?o.contentIds.indexOf(e):-1,a=s>0?o.contentIds[s-1]:null,i=s!==-1&&s<o.contentIds.length-1?o.contentIds[s+1]:null;t.applyOperation(ee(e)),n(null);const u=un(t),c=a??i??u;if(!c)return;const f=t.getBlock(c);if(Mn(t,f)){n(c),requestAnimationFrame(()=>{var x;return(x=document.querySelector(`[data-block-id="${c}"]`))==null?void 0:x.focus()});return}const d=(m=f==null?void 0:f.props)==null?void 0:m.titleRunIds,h=((g=f==null?void 0:f.contentIds)==null?void 0:g[f.contentIds.length-1])??(d==null?void 0:d[d.length-1]);h&&ye(h)}function an(t){var o,s;const e=(o=t.getPendingSelection)==null?void 0:o.call(t);if(e){Je(e.runId,e.offset);return}const r=(((s=t.getPendingAffectedBlockIds)==null?void 0:s.call(t))??[]).find(a=>t.getBlock(a));r&&Re(t,r)}const ha={b:"bold",i:"italic",u:"underline"};function lc(t){const e=G(),[n,r]=Io(),{getSelectedBlockId:o,setSelectedBlockId:s}=ut();p.useEffect(()=>{const a=t.current;if(!a)return;const i=c=>{var d,h;if(o()&&(c.key==="Backspace"||c.key==="Delete")&&!c.defaultPrevented){c.preventDefault(),c.stopPropagation(),Rm(e,o(),s);return}if(o()&&c.key!=="Backspace"&&c.key!=="Delete"&&s(null),c.metaKey||c.ctrlKey){const m=c.key.toLowerCase();if(m==="z"&&!c.shiftKey){c.preventDefault(),(d=e.undo)!=null&&d.call(e)&&an(e);return}if(m==="z"&&c.shiftKey||m==="y"){c.preventDefault(),(h=e.redo)!=null&&h.call(e)&&an(e);return}if(m==="a"){if(n)return;(ac(e)||Sm(e))&&(c.preventDefault(),r(!0));return}if(ha[m]){if(n)return;c.preventDefault();const g=ha[m],x=ln();if(x){const k=rs(e,x.blockId,x,g);k&&ye(k);return}const y=rn(e);if(y){const k=os(e,y,g);k&&ye(k)}}return}if(n){if(c.key==="Backspace"||c.key==="Delete"){c.preventDefault(),c.stopPropagation();const m=ir(e);r(!1),m!=null&&m.runId&&Je(m.runId,m.offset);return}if(c.key.length===1){c.preventDefault(),c.stopPropagation();const m=ir(e,c.key);r(!1),m!=null&&m.runId&&Je(m.runId,m.offset);return}if(r(!1),c.key==="Escape")return}if(c.key==="Backspace"||c.key==="Delete"){const m=rn(e);if(!m)return;c.preventDefault(),c.stopPropagation();const g=es(e,m);g!=null&&g.runId&&Je(g.runId,g.offset)}},u=()=>{n&&r(!1),o()&&s(null)};return a.addEventListener("keydown",i),a.addEventListener("mousedown",u),()=>{a.removeEventListener("keydown",i),a.removeEventListener("mousedown",u)}},[t,e,n,r,o,s])}const Tm=4;function jm(t,e,n){const r=t.getBlock(e);if(!r)return[];const o=t.getBlock(r.parentId);if(!o)return[e];const s=o.contentIds,a=s.indexOf(e),i=n?s.indexOf(n):a;if(a===-1)return[e];const[u,c]=i===-1?[a,a]:[Math.min(a,i),Math.max(a,i)];return s.slice(u,c+1)}function Em(){var t,e;return typeof window<"u"&&((e=(t=window.matchMedia)==null?void 0:t.call(window,"(pointer: coarse)"))==null?void 0:e.matches)===!0}function ic(t){const e=G(),[,n]=_n(),r=p.useRef(null),o=p.useRef(!1),s=p.useRef(null),a=p.useCallback(f=>{var m,g,x,y,k;if(!r.current)return;if(!o.current){const{x:w,y:v}=s.current??{x:f.clientX,y:f.clientY};if(Math.hypot(f.clientX-w,f.clientY-v)<Tm)return;o.current=!0,document.documentElement.classList.add("be-block-range-dragging"),(g=(m=window.getSelection)==null?void 0:m.call(window))==null||g.removeAllRanges()}(y=(x=window.getSelection)==null?void 0:x.call(window))==null||y.removeAllRanges(),f.preventDefault();const d=(k=document.elementFromPoint(f.clientX,f.clientY))==null?void 0:k.closest("[data-block-row-id]"),h=(d==null?void 0:d.getAttribute("data-block-row-id"))??null;n(jm(e,r.current,h))},[e,n]),i=p.useCallback(()=>{r.current=null,o.current=!1,s.current=null,document.documentElement.classList.remove("be-block-range-dragging")},[]),u=p.useCallback((f,d)=>{r.current=f,o.current=!1,s.current={x:d.clientX,y:d.clientY}},[]),c=p.useCallback(f=>{var x,y;if(f.button!==0||Em()||(y=(x=f.target).closest)!=null&&y.call(x,"button, input, textarea, select"))return;const d=f.target.closest("[data-block-row-id]");if(d){if(f.target.closest(".be-block-row-content"))return;u(d.getAttribute("data-block-row-id"),f);return}const h=t==null?void 0:t.current;if(!h)return;const g=[...h.querySelectorAll("[data-block-row-id]")].find(k=>{const w=k.getBoundingClientRect();return f.clientY>=w.top&&f.clientY<=w.bottom});g&&u(g.getAttribute("data-block-row-id"),f)},[t,u]);p.useEffect(()=>(document.addEventListener("mousedown",c),document.addEventListener("mousemove",a),document.addEventListener("mouseup",i),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",i),document.documentElement.classList.remove("be-block-range-dragging")}),[c,a,i])}const Bm=340;function _m(t,e,n,r){p.useEffect(()=>{if(!t||!e)return;const o=document.querySelector(`[data-run-id="${e}"]`);if(o)return o.setAttribute("aria-expanded","true"),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-controls",r),n&&o.setAttribute("aria-activedescendant",n),()=>{o.removeAttribute("aria-expanded"),o.removeAttribute("aria-haspopup"),o.removeAttribute("aria-controls"),o.removeAttribute("aria-activedescendant")}},[t,e,n,r])}function nr({isOpen:t,rect:e,commands:n,runId:r,onSelect:o,onClose:s,menuId:a="be-slash-menu",ariaLabel:i="Slash commands"}){const[u,c]=p.useState(0),f=p.useRef(null),d=p.useRef(null),h=Sr(),m=Ul(d,t&&n.length>0&&!!e,e==null?void 0:e.left);p.useEffect(()=>{c(0)},[n.length]),p.useEffect(()=>{var v,j;(j=(v=f.current)==null?void 0:v.scrollIntoView)==null||j.call(v,{block:"nearest"})},[u]),p.useEffect(()=>{if(!t)return;const v=j=>{j.key==="ArrowDown"?(j.preventDefault(),j.stopPropagation(),c(I=>Math.min(I+1,Math.max(n.length-1,0)))):j.key==="ArrowUp"?(j.preventDefault(),j.stopPropagation(),c(I=>Math.max(I-1,0))):j.key==="Enter"?(j.preventDefault(),j.stopPropagation(),n[u]&&o(n[u])):j.key==="Escape"&&(j.preventDefault(),j.stopPropagation(),s())};return document.addEventListener("keydown",v,!0),()=>document.removeEventListener("keydown",v,!0)},[t,n,u,o,s]);const x=n[u]?`${a}-option-${u}`:null;if(_m(t,r,x,a),!t||n.length===0||!e||m==null)return null;const y=window.innerHeight-h,w=e.bottom+Bm>y?{bottom:window.innerHeight-e.top+4}:{top:e.bottom+4};return l.jsx("div",{ref:d,id:a,role:"listbox","aria-label":i,className:"be-slash-menu",style:{position:"fixed",left:m,zIndex:1e3,...w},children:n.map((v,j)=>{const I=v.icon;return l.jsxs("div",{ref:j===u?f:void 0,id:`${a}-option-${j}`,role:"option","aria-selected":j===u,className:`be-slash-menu-item${j===u?" be-slash-menu-item-active":""}`,onMouseDown:C=>{C.preventDefault(),o(v)},onMouseEnter:()=>c(j),children:[I&&l.jsx("span",{className:"be-slash-menu-item-icon",children:l.jsx(I,{size:16})}),l.jsx("span",{className:"be-slash-menu-item-label",children:v.label})]},v.label)})})}function Om(t,e){var r;if(!e)return!0;const n=e.toLowerCase();return t.label.toLowerCase().includes(n)||((r=t.keywords)==null?void 0:r.some(o=>o.toLowerCase().includes(n)))}function Mm(t,e){const n=e.anchorNode,r=e.anchorOffset;let o;if(n===t){o="";for(let s=0;s<r&&s<t.childNodes.length;s+=1)o+=t.childNodes[s].textContent??""}else n&&n.parentElement===t?o=(n.textContent??"").slice(0,r):o=t.textContent??"";return at(o).length}function ss(t,e,n){const r=G(),[o,s]=p.useState(null);p.useEffect(()=>{const c=t.current;if(!c)return;const f=()=>{var I,C,T,M;const h=(I=window.getSelection)==null?void 0:I.call(window),m=h==null?void 0:h.anchorNode;let g=(m==null?void 0:m.nodeType)===1?m:m==null?void 0:m.parentElement;for(;g&&typeof g.hasAttribute=="function"&&!g.hasAttribute("data-run-id");)g=g.parentElement;const x=(C=g==null?void 0:g.getAttribute)==null?void 0:C.call(g,"data-run-id");if(!x||!h){s(null);return}const y=Mm(g,h),k=at(g.textContent).slice(0,y),w=e.exec(k);if(!w){s(null);return}const v=(M=(T=g.closest)==null?void 0:T.call(g,"[data-block-id]"))==null?void 0:M.getAttribute("data-block-id");if(!v){s(null);return}const j=w.index+w[1].length;s({query:w[2],blockId:v,runId:x,sliceStart:j,sliceEnd:y,rect:g.getBoundingClientRect()})},d=h=>{h.key==="Escape"&&s(null)};return c.addEventListener("input",f),c.addEventListener("keydown",d),()=>{c.removeEventListener("input",f),c.removeEventListener("keydown",d)}},[t,e]);const a=o?n().filter(c=>Om(c,o.query)):[],i=p.useCallback(c=>{o&&(c.run(r,{blockId:o.blockId,runId:o.runId,sliceStart:o.sliceStart,sliceEnd:o.sliceEnd}),s(null))},[o,r]),u=p.useCallback(()=>s(null),[]);return{isOpen:!!o,query:(o==null?void 0:o.query)??"",rect:(o==null?void 0:o.rect)??null,runId:(o==null?void 0:o.runId)??null,commands:a,selectCommand:i,close:u}}const Lm=/(^|\s)\/(\w*)$/;function cc(t){const e=vt(),n=tt(),r=p.useCallback(()=>[...e.listSlashCommands(),...(n==null?void 0:n.listSlashCommands())??[]],[e,n]);return ss(t,Lm,r)}const Nm=[{char:"😀",name:"grinning face",keywords:["smile","happy"]},{char:"😂",name:"face with tears of joy",keywords:["laugh","lol"]},{char:"😍",name:"heart eyes",keywords:["love","crush"]},{char:"😎",name:"cool",keywords:["sunglasses"]},{char:"🤔",name:"thinking face",keywords:["hmm"]},{char:"😉",name:"winking face",keywords:["wink"]},{char:"😢",name:"crying face",keywords:["sad","tear"]},{char:"😡",name:"angry face",keywords:["mad","rage"]},{char:"😱",name:"screaming face",keywords:["shock","scared"]},{char:"🥳",name:"party face",keywords:["celebrate","birthday"]},{char:"🙏",name:"folded hands",keywords:["please","pray","thanks"]},{char:"👍",name:"thumbs up",keywords:["approve","yes","like"]},{char:"👎",name:"thumbs down",keywords:["disapprove","no"]},{char:"👏",name:"clapping hands",keywords:["applause","congrats"]},{char:"🙌",name:"raised hands",keywords:["hooray","yay"]},{char:"👋",name:"waving hand",keywords:["hello","bye"]},{char:"✌️",name:"victory hand",keywords:["peace"]},{char:"💪",name:"flexed biceps",keywords:["strong","muscle"]},{char:"🤝",name:"handshake",keywords:["deal","agree"]},{char:"❤️",name:"red heart",keywords:["love"]},{char:"🔥",name:"fire",keywords:["hot","lit"]},{char:"⭐",name:"star",keywords:["favorite"]},{char:"✨",name:"sparkles",keywords:["shiny","magic"]},{char:"🎉",name:"party popper",keywords:["celebrate","congrats"]},{char:"🎊",name:"confetti ball",keywords:["celebrate"]},{char:"💡",name:"light bulb",keywords:["idea","tip"]},{char:"✅",name:"check mark",keywords:["done","yes","complete"]},{char:"❌",name:"cross mark",keywords:["no","wrong","delete"]},{char:"⚠️",name:"warning",keywords:["caution","alert"]},{char:"❓",name:"question mark",keywords:["question","help"]},{char:"❗",name:"exclamation mark",keywords:["important","alert"]},{char:"🚀",name:"rocket",keywords:["launch","fast","ship"]},{char:"🐛",name:"bug",keywords:["bug","issue"]},{char:"🔧",name:"wrench",keywords:["fix","tool","settings"]},{char:"📌",name:"pushpin",keywords:["pin","note"]},{char:"📎",name:"paperclip",keywords:["attachment","clip"]},{char:"📅",name:"calendar",keywords:["date","schedule"]},{char:"⏰",name:"alarm clock",keywords:["time","reminder"]},{char:"📈",name:"chart increasing",keywords:["growth","stats"]},{char:"📉",name:"chart decreasing",keywords:["decline","stats"]},{char:"💰",name:"money bag",keywords:["money","cash"]},{char:"💬",name:"speech balloon",keywords:["comment","chat"]},{char:"📝",name:"memo",keywords:["note","write"]},{char:"📚",name:"books",keywords:["reading","docs"]},{char:"🔗",name:"link",keywords:["url","chain"]},{char:"🔒",name:"locked",keywords:["private","secure"]},{char:"🔑",name:"key",keywords:["password","access"]},{char:"☕",name:"coffee",keywords:["coffee","break"]},{char:"🍕",name:"pizza",keywords:["food"]},{char:"🎂",name:"birthday cake",keywords:["birthday","cake"]},{char:"🎁",name:"gift",keywords:["present"]},{char:"🌟",name:"glowing star",keywords:["star","shiny"]},{char:"🌈",name:"rainbow",keywords:["colorful"]},{char:"☀️",name:"sun",keywords:["sunny","weather"]},{char:"🌧️",name:"rain cloud",keywords:["rainy","weather"]},{char:"🐶",name:"dog face",keywords:["dog","pet"]},{char:"🐱",name:"cat face",keywords:["cat","pet"]},{char:"🌍",name:"globe",keywords:["world","earth"]},{char:"🎯",name:"direct hit",keywords:["target","goal"]},{char:"🏆",name:"trophy",keywords:["win","award"]},{char:"🕐",name:"clock",keywords:["time"]},{char:"📣",name:"megaphone",keywords:["announce","shout"]},{char:"🧠",name:"brain",keywords:["smart","idea","mind"]},{char:"👀",name:"eyes",keywords:["look","watching"]}];function Am(t,{runId:e,sliceStart:n,sliceEnd:r},o){const s=t.getRun(e),a=(s==null?void 0:s.value)??"",i=a.slice(0,n)+o+a.slice(r);t.applyOperation(ue(e,{value:i})),Je(e,n+o.length)}const Dm=Nm.map(({char:t,name:e,keywords:n})=>({label:`${t} ${e}`,keywords:n,run:(r,o)=>Am(r,o,t)})),Pm=/(^|\s):(\w*)$/,$m=()=>Dm;function uc(t){return ss(t,Pm,$m)}const zm=/(^|\s)@(\w*)$/;function dc(t){const e=tt(),n=p.useCallback(()=>(e==null?void 0:e.listAtCommands())??[],[e]);return ss(t,zm,n)}function as(t,e,n,r,o){const[s,a]=p.useState(!1),i=p.useCallback(y=>{const k=e==="same-block"?sn(t,n.blockId,n,y):cr(t,r,y);return k&&ye(k),k},[t,e,n,r]),u=p.useCallback(y=>{const k=e==="same-block"?rs(t,n.blockId,n,y):os(t,r,y);k&&ye(k)},[t,e,n,r]),c=p.useCallback(y=>{const k=y==="subscript"?"superscript":"subscript",w=!o[y];i({[y]:w?!0:null,[k]:null})},[o,i]),f=p.useRef(null),d=p.useCallback(()=>{f.current={kind:e,selection:n,crossSelection:r},a(!0)},[e,n,r]),h=p.useCallback(()=>a(!1),[]),m=p.useCallback(y=>{const k=f.current;if(!k)return;const w=k.kind==="same-block"?sn(t,k.selection.blockId,k.selection,y):cr(t,k.crossSelection,y);w&&ye(w),a(!1)},[t]),g=p.useCallback((y,k)=>m({link:{href:y,target:k}}),[m]),x=p.useCallback(()=>m({link:null}),[m]);return{applyPatch:i,toggleBoolean:u,setSubSuper:c,isLinkModalOpen:s,openLinkModal:d,closeLinkModal:h,handleSaveLink:g,handleRemoveLink:x}}const Hm="be-touch-input";function Fm(){var t,e;return typeof window<"u"&&((e=(t=window.matchMedia)==null?void 0:t.call(window,"(pointer: coarse)"))==null?void 0:e.matches)===!0}function ls(){const[t,e]=p.useState(Fm);return p.useEffect(()=>{if(typeof window>"u")return;const n=r=>{e(r.pointerType==="touch"||r.pointerType==="pen")};return window.addEventListener("pointerdown",n,{passive:!0}),()=>window.removeEventListener("pointerdown",n)},[]),p.useEffect(()=>{var n;(n=document.documentElement)==null||n.classList.toggle(Hm,t)},[t]),t}const Um=[{markName:"bold",Icon:Fa,title:"Bold (Ctrl+B)"},{markName:"italic",Icon:Ua,title:"Italic (Ctrl+I)"},{markName:"underline",Icon:Va,title:"Underline (Ctrl+U)"},{markName:"strike",Icon:td,title:"Strikethrough"}],Vm=[{label:"Default",value:null},{label:"Red",value:"#e03131"},{label:"Orange",value:"#e8590c"},{label:"Green",value:"#2f9e44"},{label:"Blue",value:"#1971c2"},{label:"Purple",value:"#9c36b5"}],Ym=[{label:"None",value:null},{label:"Yellow",value:"#fff3bf"},{label:"Green",value:"#d3f9d8"},{label:"Blue",value:"#d0ebff"},{label:"Pink",value:"#ffdeeb"},{label:"Gray",value:"#e9ecef"}];function pc({isOpen:t,rect:e,kind:n,selection:r,crossSelection:o,marks:s,store:a,onComment:i,commentAuthorId:u}){var K,Q;const c=ls(),[f,d]=p.useState(null),[h,m]=p.useState(null),g=p.useRef(null),{applyPatch:x,toggleBoolean:y,setSubSuper:k,isLinkModalOpen:w,openLinkModal:v,closeLinkModal:j,handleSaveLink:I,handleRemoveLink:C}=as(a,n,r,o,s),T=p.useRef(null);T.current=h;function M(){var D,F,re,H;(F=(D=document.activeElement)==null?void 0:D.blur)==null||F.call(D),(H=(re=window.getSelection)==null?void 0:re.call(window))==null||H.removeAllRanges()}function B(){if(!r)return;const D=E(),F=vo(a,r,D);F&&a.applyOperation(F),m({commentId:D}),d("comment")}function L(){const D=T.current;if(D){for(const F of wo(a,D.commentId))a.applyOperation(F);m(null),M()}}function S(D){!h||!r||(a.applyOperation(Cn({id:h.commentId,blockId:r.blockId,anchorRunIds:[r.startRunId,r.endRunId],resolved:!1,messages:[{id:E(),authorId:u,text:D,createdAt:Date.now()}]})),m(null),d(null),M())}function N(){L(),d(null)}p.useEffect(()=>{if(!t||n!=="same-block"||!(i||u))return;const D=F=>{(F.metaKey||F.ctrlKey)&&F.altKey&&F.code==="KeyM"&&(F.preventDefault(),i?i(r):B())};return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},[t,n,i,u,r]),p.useEffect(()=>{if(!f)return;const D=re=>{g.current&&!g.current.contains(re.target)&&(L(),d(null))},F=re=>{re.key==="Escape"&&(L(),d(null))};return document.addEventListener("mousedown",D),document.addEventListener("keydown",F),()=>{document.removeEventListener("mousedown",D),document.removeEventListener("keydown",F)}},[f]),p.useEffect(()=>{L(),d(null)},[e,n]);const $=Vl(g,!!(t&&e),e?e.left+e.width/2:null);if(c||(!t||!e)&&!w)return null;const V=!i&&f==="comment";return l.jsxs(l.Fragment,{children:[t&&e&&$!=null&&V&&l.jsxs("div",{ref:g,className:"be-floating-toolbar be-floating-toolbar-comment-standalone",role:"dialog","aria-label":"Add comment",style:{position:"fixed",top:e.top-44,left:$,transform:"translateX(-50%)"},onMouseDown:D=>{D.target.tagName!=="TEXTAREA"&&D.preventDefault()},children:[l.jsx(gl,{title:"Add comment",onClose:N}),l.jsx(No,{authorId:u,autoFocus:!0,onSubmit:S,onCancel:N})]}),t&&e&&$!=null&&!V&&l.jsxs("div",{ref:g,className:"be-floating-toolbar",role:"toolbar","aria-label":"Text formatting",style:{position:"fixed",top:e.top-44,left:$,transform:"translateX(-50%)"},onMouseDown:D=>{D.target.tagName!=="TEXTAREA"&&D.preventDefault()},children:[Um.map(({markName:D,Icon:F,title:re})=>l.jsx("button",{type:"button",className:`be-floating-toolbar-btn${s[D]?" be-floating-toolbar-btn-active":""}`,title:re,"aria-label":re,"aria-pressed":!!s[D],onClick:()=>y(D),children:l.jsx(F,{})},D)),l.jsx("button",{type:"button",className:`be-floating-toolbar-btn${s.subscript?" be-floating-toolbar-btn-active":""}`,title:"Subscript","aria-pressed":!!s.subscript,onClick:()=>k("subscript"),children:"X₂"}),l.jsx("button",{type:"button",className:`be-floating-toolbar-btn${s.superscript?" be-floating-toolbar-btn-active":""}`,title:"Superscript","aria-pressed":!!s.superscript,onClick:()=>k("superscript"),children:"X²"}),l.jsx("span",{className:"be-floating-toolbar-divider"}),l.jsxs("div",{className:"be-floating-toolbar-picker-wrap",children:[l.jsx("button",{type:"button",className:"be-floating-toolbar-btn",title:"Text color","aria-haspopup":"true","aria-expanded":f==="color",onClick:()=>d(D=>D==="color"?null:"color"),children:l.jsx("span",{style:{color:s.color||"inherit",fontWeight:700},children:"A"})}),f==="color"&&l.jsx("div",{className:"be-floating-toolbar-picker",role:"menu","aria-label":"Text color",children:Vm.map(D=>l.jsx("button",{type:"button",role:"menuitem",className:"be-floating-toolbar-swatch",title:D.label,onClick:()=>{x({color:D.value}),d(null)},children:l.jsx("span",{style:{color:D.value||"#1a1a1a",fontWeight:700},children:"A"})},D.label))})]}),l.jsxs("div",{className:"be-floating-toolbar-picker-wrap",children:[l.jsx("button",{type:"button",className:"be-floating-toolbar-btn",title:"Highlight","aria-haspopup":"true","aria-expanded":f==="highlight",onClick:()=>d(D=>D==="highlight"?null:"highlight"),children:l.jsx("span",{style:{backgroundColor:s.highlight||"transparent",padding:"0 2px",borderRadius:2},children:"H"})}),f==="highlight"&&l.jsx("div",{className:"be-floating-toolbar-picker",role:"menu","aria-label":"Highlight color",children:Ym.map(D=>l.jsx("button",{type:"button",role:"menuitem",className:"be-floating-toolbar-swatch",style:{backgroundColor:D.value||"transparent"},title:D.label,onClick:()=>{x({highlight:D.value}),d(null)}},D.label))})]}),l.jsx("span",{className:"be-floating-toolbar-divider"}),l.jsx("button",{type:"button",className:`be-floating-toolbar-btn${s.link?" be-floating-toolbar-btn-active":""}`,title:"Link","aria-label":"Link","aria-pressed":!!s.link,onClick:v,children:l.jsx(Ka,{})}),(i||u)&&n==="same-block"&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"be-floating-toolbar-divider"}),l.jsx("button",{type:"button",className:"be-floating-toolbar-btn",title:"Comment (Ctrl+Alt+M)","aria-label":"Comment",onClick:()=>i?i(r):B(),children:l.jsx(Wa,{})})]})]}),l.jsx(bl,{isOpen:w,initialHref:((K=s.link)==null?void 0:K.href)??"",initialTarget:((Q=s.link)==null?void 0:Q.target)??"_self",hasExistingLink:!!s.link,onSave:I,onRemove:C,onClose:j})]})}function fc(t){const e=G(),[n,r]=p.useState(null);return p.useEffect(()=>{const o=t.current;if(!o)return;const s=()=>{var f,d,h,m,g;if((d=(f=document.activeElement)==null?void 0:f.closest)!=null&&d.call(f,".be-floating-toolbar"))return;const a=(h=window.getSelection)==null?void 0:h.call(window);if(!a||a.rangeCount===0||a.isCollapsed){r(null);return}if(!o.contains(a.anchorNode)||!o.contains(a.focusNode)){r(null);return}const i=((g=(m=a.getRangeAt(0)).getBoundingClientRect)==null?void 0:g.call(m))??{top:0,left:0,right:0,bottom:0,width:0,height:0},u=ln();if(u){r({kind:"same-block",rect:i,selection:u,marks:ts(e,u.blockId,u)});return}const c=rn(e);if(c){r({kind:"cross-block",rect:i,crossSelection:c,marks:ns(e,c)});return}r(null)};return document.addEventListener("selectionchange",s),window.addEventListener("scroll",s,!0),window.addEventListener("resize",s),()=>{document.removeEventListener("selectionchange",s),window.removeEventListener("scroll",s,!0),window.removeEventListener("resize",s)}},[t,e]),{isOpen:!!n,rect:(n==null?void 0:n.rect)??null,kind:(n==null?void 0:n.kind)??null,selection:(n==null?void 0:n.selection)??null,crossSelection:(n==null?void 0:n.crossSelection)??null,marks:(n==null?void 0:n.marks)??{},close:()=>r(null)}}function Km({store:t,rootId:e,onComment:n,commentAuthorId:r}){const o=p.useRef(null),{onCopy:s,onCut:a,onPaste:i}=tc(),u=cc(o),c=uc(o),f=dc(o),d=fc(o);return lc(o),ic(o),l.jsxs("div",{ref:o,role:"document","aria-label":"Document editor",onCopy:s,onCut:a,onPaste:i,children:[l.jsx(Zi,{}),l.jsx(ht,{parentId:e,isTopLevel:!0}),l.jsx(Wi,{}),l.jsx(nr,{isOpen:u.isOpen,rect:u.rect,commands:u.commands,runId:u.runId,onSelect:u.selectCommand,onClose:u.close}),l.jsx(nr,{isOpen:c.isOpen,rect:c.rect,commands:c.commands,runId:c.runId,onSelect:c.selectCommand,onClose:c.close,menuId:"be-emoji-menu",ariaLabel:"Emoji"}),l.jsx(nr,{isOpen:f.isOpen,rect:f.rect,commands:f.commands,runId:f.runId,onSelect:f.selectCommand,onClose:f.close,menuId:"be-at-menu",ariaLabel:"Mention"}),l.jsx(pc,{isOpen:d.isOpen,rect:d.rect,kind:d.kind,selection:d.selection,crossSelection:d.crossSelection,marks:d.marks,store:t,onComment:n,commentAuthorId:r})]})}function Wm({editor:t,className:e,style:n,theme:r,getBlockClassName:o,onComment:s,commentAuthorId:a,showCommentsPanel:i,children:u}){const{store:c,registry:f,inlineRegistry:d}=t,h=c.getRootId();return l.jsxs(Pa,{store:c,registry:f,inlineRegistry:d,history:c,className:e,style:n,theme:r,getBlockClassName:o,commentAuthorId:a,children:[l.jsx(Km,{store:c,rootId:h,onComment:s,commentAuthorId:a}),i&&l.jsx(ll,{authorId:a}),u]})}const Xm="$fieldTypes";function hc(){const t=G(),e=p.useCallback(r=>t.subscribe(Xm,r),[t]),n=p.useCallback(()=>t.getFieldTypes(),[t]);return p.useSyncExternalStore(e,n)}const qm={canUndo:!1,canRedo:!1};function mc(){const{history:t}=Pe(),e=p.useCallback(o=>t?t.subscribeToHistory(o):()=>{},[t]),n=p.useCallback(()=>t?t.getUndoRedoSnapshot():qm,[t]),r=p.useSyncExternalStore(e,n);return t?{...r,undo:()=>{const o=t.undo();return o&&an(t),o},redo:()=>{const o=t.redo();return o&&an(t),o},getHistoryLog:()=>t.getHistoryLog()}:null}function Gm({store:t,docId:e,debounceMs:n,onError:r}){const[o,s]=p.useState(!1);return p.useEffect(()=>{let a=!1;s(!1),Ca(e).then(c=>{if(!a&&c){const f=t.store??t;f.blocks=new Map((c.blocks??[]).map(d=>[d.id,d])),f.runs=new Map((c.runs??[]).map(d=>[d.id,d])),f.rootId=c.rootId??null,f.fieldTypes=new Map((c.fieldTypes??[]).map(d=>[d.id,d])),f._fieldTypesSnapshot=null,f._orders=new Map,f._notify([...f.blocks.keys(),...f.runs.keys()])}}).catch(c=>r==null?void 0:r(c)).finally(()=>{a||s(!0)});const{stop:i,flush:u}=Ta({store:t,docId:e,debounceMs:n,onError:r});return()=>{a=!0,u(),i()}},[e]),{isLoaded:o}}function Jm(t){const[e,n]=p.useState(()=>(t==null?void 0:t.getPresence())??new Map);return p.useEffect(()=>{if(!t){n(new Map);return}return n(t.getPresence()),t.onPresenceChange(n)},[t]),e}function Zm(){const[t,e]=p.useState(!1),[n,r]=p.useState(null);p.useEffect(()=>{if(!navigator.serviceWorker)return;let s=!1;function a(i){if(!i)return;const u=()=>{i.waiting&&(r(i.waiting),e(!0))};u(),i.addEventListener("updatefound",()=>{const c=i.installing;c&&c.addEventListener("statechange",()=>{c.state==="installed"&&navigator.serviceWorker.controller&&u()})})}return navigator.serviceWorker.getRegistration().then(i=>{s||a(i)}),()=>{s=!0}},[]);const o=p.useCallback(()=>{if(!n)return;const s=()=>window.location.reload();navigator.serviceWorker.addEventListener("controllerchange",s,{once:!0}),n.postMessage({type:"SKIP_WAITING"})},[n]);return{updateAvailable:t,applyUpdate:o}}const bc=[{phrases:["new paragraph","next paragraph"],description:"Start a new paragraph",action:{type:"insertParagraph"}},{phrases:["heading one","heading 1"],description:"Convert the current block to a heading 1",action:{type:"convertBlock",blockType:"heading",props:{level:1}}},{phrases:["heading two","heading 2"],description:"Convert the current block to a heading 2",action:{type:"convertBlock",blockType:"heading",props:{level:2}}},{phrases:["heading three","heading 3"],description:"Convert the current block to a heading 3",action:{type:"convertBlock",blockType:"heading",props:{level:3}}},{phrases:["bulleted list","bullet point","bullet list"],description:"Convert the current block to a bulleted list item",action:{type:"convertBlock",blockType:"listItem",props:{ordered:!1,titleRunIds:[]}}},{phrases:["numbered list","ordered list"],description:"Convert the current block to a numbered list item",action:{type:"convertBlock",blockType:"listItem",props:{ordered:!0,titleRunIds:[]}}},{phrases:["checklist","to-do","to do","to-do list","to do list"],description:"Convert the current block to a to-do item",action:{type:"convertBlock",blockType:"listItem",props:{ordered:!1,checked:!1,titleRunIds:[]}}},{phrases:["quote"],description:"Convert the current block to a quote",action:{type:"convertBlock",blockType:"blockquote",props:{}}},{phrases:["code block","code"],description:"Convert the current block to a code block",action:{type:"convertBlock",blockType:"code",props:{language:"plaintext"}}},{phrases:["undo"],description:"Undo the last edit",action:{type:"undo"}},{phrases:["redo"],description:"Redo the last undone edit",action:{type:"redo"}},{phrases:["stop dictation","stop listening","stop"],description:"Stop dictation",action:{type:"stopDictation"}}],gc=new Map;for(const{phrases:t,action:e}of bc)for(const n of t)gc.set(n,e);function Qm(t){return(t??"").toLowerCase().trim().replace(/\s+/g," ").replace(/[.,!?]+$/,"")}function eb(t){return gc.get(Qm(t))??null}function tb(){return bc.map(({phrases:t,description:e})=>({phrases:[...t],description:e}))}function nb(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function rb(t){var e;return((e=t==null?void 0:t.props)==null?void 0:e.titleRunIds)??(t==null?void 0:t.contentIds)??[]}function ob(t,e,n){var r,o;if(n.type==="insertParagraph"){nt(t,e,te("paragraph"));return}if(n.type==="convertBlock"){const s=t.getBlock(e);if(!s)return;const a=rb(s),{ops:i}=Po(t,e,n.blockType,n.props,a);nb(t,i),a[0]&&br(a[0]);return}if(n.type==="undo"){(r=t.undo)!=null&&r.call(t)&&an(t);return}n.type==="redo"&&(o=t.redo)!=null&&o.call(t)&&an(t)}function ma(){return typeof window>"u"?null:window.SpeechRecognition??window.webkitSpeechRecognition??null}const sb="Microphone access is blocked. Enable it in your browser's site settings, then try again.";function ab({shortcut:t=!0}={}){const e=G(),[n,r]=p.useState(!1),[o,s]=p.useState("idle"),[a,i]=p.useState("unknown"),[u,c]=p.useState(null),f=p.useRef(null),d=p.useRef(null),h=p.useRef(null),m=p.useRef(0),g=ma()!==null;p.useEffect(()=>{var T;if(!((T=navigator.permissions)!=null&&T.query))return;let I,C=!1;return navigator.permissions.query({name:"microphone"}).then(M=>{C||(I=M,i(M.state),I.onchange=()=>i(I.state))}).catch(()=>{}),()=>{C=!0,I&&(I.onchange=null)}},[]);const x=p.useCallback(()=>{if(!d.current){const I=lt();if(!I)return null;d.current=I}return{runId:d.current.runId,blockId:d.current.blockId,startOffset:d.current.offset,insertedLength:0}},[]),y=p.useCallback((I,C)=>{const T=e.getRun(I.runId);if(!T||T.type!=="text")return;const M=T.value??"",B=M.slice(0,I.startOffset);if(I.needsLeadingSpace===void 0){const N=B[B.length-1];I.needsLeadingSpace=I.startOffset>0&&N!==void 0&&!/\s/.test(N)}const L=(I.needsLeadingSpace?" ":"")+C,S=M.slice(I.startOffset+I.insertedLength);Ve.flushSync(()=>e.applyOperation(ue(I.runId,{value:B+L+S}))),I.insertedLength=L.length,$s(I.runId,I.startOffset+L.length),d.current={runId:I.runId,blockId:I.blockId,offset:I.startOffset+L.length}},[e]),k=p.useCallback(I=>{const C=e.getRun(I.runId);if(!C||C.type!=="text")return;const T=C.value??"",M=T.slice(0,I.startOffset)+T.slice(I.startOffset+I.insertedLength);Ve.flushSync(()=>e.applyOperation(ue(I.runId,{value:M}))),$s(I.runId,I.startOffset),d.current={runId:I.runId,blockId:I.blockId,offset:I.startOffset}},[e]),w=p.useCallback(I=>{var B,L;let C="",T=!1;const M=Math.max(I.resultIndex,m.current);for(let S=M;S<I.results.length;S+=1){const N=I.results[S],$=((B=N[0])==null?void 0:B.transcript)??"";if(!N.isFinal){C+=(C?" ":"")+$,T=!0;continue}const V=h.current??x();if(h.current=null,m.current=S+1,!V)continue;const K=eb($);K?(k(V),K.type==="stopDictation"?(L=f.current)==null||L.stop():(ob(e,V.blockId,K),d.current=null,s("listening"))):(y(V,$),s("listening"))}if(T){const S=h.current??x();S&&(h.current=S,y(S,C))}},[e,x,y,k]),v=p.useCallback(()=>{if(!g||f.current)return;c(null),d.current=lt(),h.current=null,m.current=0;const I=ma(),C=new I;C.continuous=!0,C.interimResults=!0,C.onresult=w,C.onstart=()=>s("listening"),C.onspeechstart=()=>s("listening"),C.onspeechend=()=>s("processing"),C.onerror=T=>{T.error==="not-allowed"||T.error==="service-not-allowed"?(i("denied"),c(sb)):c(T.error??"Voice typing stopped unexpectedly.")},C.onend=()=>{f.current=null,d.current=null,h.current=null,m.current=0,r(!1),s("idle")},f.current=C,C.start(),r(!0)},[g,w]),j=p.useCallback(()=>{var I;(I=f.current)==null||I.stop()},[]);return p.useEffect(()=>()=>{var I;return(I=f.current)==null?void 0:I.stop()},[]),p.useEffect(()=>{if(!t||!g)return;const I=C=>{!(C.metaKey||C.ctrlKey)||!C.shiftKey||C.key.toLowerCase()!=="m"||(C.preventDefault(),f.current?j():v())};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[t,g,v,j]),{isSupported:g,isListening:n,status:o,permissionState:a,error:u,start:v,stop:j}}function lb({voice:t}){const[e,n]=p.useState(!1);p.useEffect(()=>{n(!1)},[t==null?void 0:t.error]);const r=(t==null?void 0:t.permissionState)==="denied"&&!e;return l.jsxs(dt,{isOpen:r,onClose:()=>n(!0),title:"Microphone access blocked",children:[l.jsx("p",{children:(t==null?void 0:t.error)||"Microphone access is blocked. Enable it in your browser's site settings, then try again."}),l.jsxs("div",{className:"be-modal-actions",children:[l.jsx("button",{type:"button",className:"be-modal-cancel",onClick:()=>n(!0),children:"Dismiss"}),l.jsx("button",{type:"button",className:"be-modal-save",onClick:()=>{var o;return(o=t==null?void 0:t.start)==null?void 0:o.call(t)},children:"Try again"})]})]})}function xc(t){const[e,n]=p.useState(null);return p.useEffect(()=>{if(!t){n(null);return}const r=()=>{var u,c,f,d;const o=(u=window.getSelection)==null?void 0:u.call(window);if(!o||o.rangeCount===0||!o.isCollapsed){n(null);return}const s=o.anchorNode,a=(s==null?void 0:s.nodeType)===1?s:s==null?void 0:s.parentElement;if(!((c=a==null?void 0:a.closest)!=null&&c.call(a,"[data-run-id]"))){n(null);return}const i=((d=(f=o.getRangeAt(0)).getBoundingClientRect)==null?void 0:d.call(f))??{top:0,left:0,right:0,bottom:0,width:0,height:0};n(i)};return r(),document.addEventListener("selectionchange",r),window.addEventListener("scroll",r,!0),window.addEventListener("resize",r),()=>{document.removeEventListener("selectionchange",r),window.removeEventListener("scroll",r,!0),window.removeEventListener("resize",r)}},[t]),e}function ib({voice:t}){const e=!!(t!=null&&t.isListening),n=xc(e),r=p.useRef(null),o=Vl(r,!!(e&&n),n==null?void 0:n.left);if(!e||!n||o==null)return null;const s=t.status==="processing";return Ve.createPortal(l.jsxs("div",{ref:r,className:`be-voice-indicator${s?" be-voice-indicator-processing":""}`,contentEditable:!1,style:{position:"fixed",top:n.top-8,left:o,transform:"translate(-50%, -100%)"},children:[l.jsx("span",{className:"be-voice-indicator-dot"}),l.jsx(vd,{size:12}),l.jsx("span",{className:"be-voice-indicator-label",children:s?"Processing…":"Listening…"})]}),document.body)}function yc({isOpen:t,onClose:e,onSelectCommand:n}){const r=vt(),o=tt(),s=p.useMemo(()=>[...(r==null?void 0:r.listSlashCommands())??[],...(o==null?void 0:o.listSlashCommands())??[]],[r,o]);return l.jsx(dt,{isOpen:t,onClose:e,title:"Add a block",variant:"sheet",children:l.jsx("div",{className:"be-mobile-picker-list",role:"listbox","aria-label":"Insertable blocks",children:s.map(a=>{const i=a.icon;return l.jsxs("button",{type:"button",role:"option",className:"be-mobile-picker-item",onClick:()=>n(a),children:[i&&l.jsx("span",{className:"be-mobile-picker-item-icon",children:l.jsx(i,{size:18})}),l.jsx("span",{className:"be-mobile-picker-item-label",children:a.label})]},a.label)})})})}function kc({isOpen:t,onClose:e,store:n,blockId:r}){var i;const o=r?n.getBlock(r):null,s=!!((i=o==null?void 0:o.props)!=null&&i.hidden),a=p.useCallback(u=>{u(),e()},[e]);return l.jsx(dt,{isOpen:t,onClose:e,title:"Block options",variant:"sheet",children:l.jsxs("div",{className:"be-mobile-picker-list",role:"menu","aria-label":"Block options",children:[l.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{Fo(n,r),xe("Block duplicated")}),children:[l.jsx("span",{className:"be-mobile-picker-item-icon",children:l.jsx(jo,{size:18})}),l.jsx("span",{className:"be-mobile-picker-item-label",children:"Duplicate"})]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{Uo(n,r)&&xe("Block moved up")}),children:[l.jsx("span",{className:"be-mobile-picker-item-icon",children:l.jsx(hr,{size:18})}),l.jsx("span",{className:"be-mobile-picker-item-label",children:"Move up"})]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{Vo(n,r)&&xe("Block moved down")}),children:[l.jsx("span",{className:"be-mobile-picker-item-icon",children:l.jsx(mr,{size:18})}),l.jsx("span",{className:"be-mobile-picker-item-label",children:"Move down"})]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{n.applyOperation(J(r,{hidden:!s})),xe(s?"Block shown in preview":"Block hidden in preview")}),children:[l.jsx("span",{className:"be-mobile-picker-item-icon",children:s?l.jsx(Mo,{size:18}):l.jsx(Lo,{size:18})}),l.jsx("span",{className:"be-mobile-picker-item-label",children:s?"Show in preview":"Hide in preview"})]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item be-mobile-picker-item-danger",onClick:()=>a(()=>{vr(n,r),xe("Block deleted")}),children:[l.jsx("span",{className:"be-mobile-picker-item-icon",children:l.jsx(On,{size:18})}),l.jsx("span",{className:"be-mobile-picker-item-label",children:"Delete"})]})]})})}const cb=oi.map(t=>({value:t,label:t}));function ub(t,e){const[n,r]=p.useState(!1),[o,s]=p.useState(null),[a,i]=p.useState(null),[u,c]=p.useState(null);return p.useEffect(()=>{const f=t.current;if(!f)return;const d=()=>r(!0),h=m=>{f.contains(m.relatedTarget)||r(!1)};return f.addEventListener("focusin",d),f.addEventListener("focusout",h),()=>{f.removeEventListener("focusin",d),f.removeEventListener("focusout",h)}},[t]),p.useEffect(()=>{if(!n){s(null);return}const f=()=>{var g;const d=t.current,h=(g=window.getSelection)==null?void 0:g.call(window);if(!d||!h||h.rangeCount===0){s(null);return}if(!h.isCollapsed){if(!d.contains(h.anchorNode)||!d.contains(h.focusNode)){s(null);return}const x=ln();if(x){i({kind:"same-block",selection:x,crossSelection:null,marks:ts(e,x.blockId,x)}),s("selection");return}const y=rn(e);if(y){i({kind:"cross-block",selection:null,crossSelection:y,marks:ns(e,y)}),s("selection");return}s(null);return}const m=lt();if(!m||!d.contains(h.anchorNode)){s(null);return}c(m),s("caret")};return f(),document.addEventListener("selectionchange",f),()=>document.removeEventListener("selectionchange",f)},[n,e,t]),{isFocused:n,mode:o,selectionState:a,caretState:u}}function db({store:t,selectionState:e}){const{kind:n,selection:r,crossSelection:o,marks:s}=e,{toggleBoolean:a,openLinkModal:i}=as(t,n,r,o,s);return l.jsxs(l.Fragment,{children:[l.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.bold?" be-mobile-bar-btn-active":""}`,"aria-label":"Bold",onClick:()=>a("bold"),children:l.jsx(Fa,{size:18})}),l.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.italic?" be-mobile-bar-btn-active":""}`,"aria-label":"Italic",onClick:()=>a("italic"),children:l.jsx(Ua,{size:18})}),l.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.underline?" be-mobile-bar-btn-active":""}`,"aria-label":"Underline",onClick:()=>a("underline"),children:l.jsx(Va,{size:18})}),l.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.link?" be-mobile-bar-btn-active":""}`,"aria-label":"Link",onClick:i,children:l.jsx(Ka,{size:18})})]})}function pb({store:t,blockId:e}){const n=p.useCallback(()=>{const o=t.getBlock(e),s=o&&t.getBlock(o.parentId);s&&Ko(t,s.id)},[t,e]),r=p.useCallback(()=>{const o=t.getBlock(e),s=o&&t.getBlock(o.parentId),a=s&&t.getBlock(s.parentId);if(!a||!s)return;const i=s.contentIds.indexOf(e);i!==-1&&sr(t,a.id,i)},[t,e]);return l.jsxs(l.Fragment,{children:[l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Insert row below",onClick:n,children:"+ Row"}),l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Insert column right",onClick:r,children:"+ Column"})]})}function fb({store:t,blockId:e}){var o;const n=t.getBlock(e),r=p.useCallback(s=>t.applyOperation(J(e,{language:s})),[t,e]);return l.jsx(Mt,{className:"be-mobile-bar-select",value:((o=n==null?void 0:n.props)==null?void 0:o.language)??"plaintext",options:cb,onChange:r,ariaLabel:"Code language"})}function hb({store:t,blockId:e}){var o;const n=t.getBlock(e),r=(o=n==null?void 0:n.props)==null?void 0:o.color;return l.jsx("div",{className:"be-mobile-bar-swatches",children:ti.map(s=>l.jsx("button",{type:"button",className:`be-callout-color-option be-callout-color-option-${s.value}${s.value===r?" be-callout-color-option-active":""}`,"aria-label":s.label,title:s.label,onClick:()=>t.applyOperation(J(e,{color:s.value}))},s.value))})}const vc={tableCell:pb,code:fb,callout:hb};function mb(t,e){let n=t.getBlock(e);for(;n;){if(vc[n.type])return n;n=n.parentId?t.getBlock(n.parentId):null}return null}function bb(t,e){const n=t.getRootId();let r=t.getBlock(e);for(;r&&r.parentId!==n;)r=t.getBlock(r.parentId);return r}function gb({containerRef:t}){var T,M;const e=G(),n=mc(),r=ls(),o=Sr(),{isFocused:s,mode:a,selectionState:i,caretState:u}=ub(t,e),[c,f]=p.useState(!1),[d,h]=p.useState(!1),m=p.useCallback(()=>f(!0),[]),g=p.useCallback(()=>f(!1),[]),x=p.useCallback(()=>h(!0),[]),y=p.useCallback(()=>h(!1),[]),k=p.useCallback(B=>{const L=lt()??u;L&&(B.run(e,{blockId:L.blockId,runId:L.runId,sliceStart:L.offset,sliceEnd:L.offset}),g())},[e,u,g]),w=p.useCallback(()=>{var B,L;(L=(B=document.activeElement)==null?void 0:B.blur)==null||L.call(B)},[]);if(!r||!s)return null;const v=a==="caret"&&u?mb(e,u.blockId):null,j=v?vc[v.type]:null,I=a==="caret"&&u?u.blockId:((T=i==null?void 0:i.selection)==null?void 0:T.blockId)??((M=i==null?void 0:i.crossSelection)==null?void 0:M.startBlockId)??null,C=I?bb(e,I):null;return l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"be-mobile-action-bar",role:"toolbar","aria-label":"Editor actions",style:{bottom:o},onMouseDown:B=>B.preventDefault(),children:[a==="selection"&&i&&l.jsx(db,{store:e,selectionState:i}),a!=="selection"&&l.jsxs(l.Fragment,{children:[l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Add block",onClick:m,children:l.jsx(To,{size:18})}),j&&v&&l.jsx(j,{store:e,blockId:v.id}),n&&l.jsxs(l.Fragment,{children:[l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Undo",disabled:!n.canUndo,onClick:n.undo,children:"↶"}),l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Redo",disabled:!n.canRedo,onClick:n.redo,children:"↷"})]})]}),l.jsx("span",{className:"be-mobile-bar-spacer"}),C&&l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Block options",onClick:x,children:l.jsx(Ju,{size:18})}),l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Dismiss keyboard",onClick:w,children:l.jsx(fr,{size:18})})]}),l.jsx(yc,{isOpen:c,onClose:g,onSelectCommand:k}),l.jsx(kc,{isOpen:d,onClose:y,store:e,blockId:C==null?void 0:C.id})]})}const wc={heading:["level"],listItem:["ordered","checked","collapsed"],toggleHeading:["level","collapsed"],code:["language"],button:["href","color","customAttrs"],embed:["kind","src","name","alt","mimeType","align","width"],callout:["icon"]},Ic=new Set(["listItem","toggleHeading"]),Cc=new Set(["divider","embed"]);function Sc(t,e,n,r){var i,u,c;const o=n.type,s={};for(const f of wc[o]??[])((i=n.props)==null?void 0:i[f])!==void 0&&(s[f]=n.props[f]);if(o==="table"){const f=n.contentIds[0]&&t.getBlock(n.contentIds[0]);return s.columns=$e(n,((u=f==null?void 0:f.contentIds)==null?void 0:u.length)??0),s.rows=n.contentIds.map(d=>t.getBlock(d).contentIds.map(m=>{const g=t.getBlock(m);return Hr(g.contentIds.map(x=>t.getRun(x)),r)})),{id:n.id,type:o,data:s}}if(Ic.has(o)){const f=((c=n.props)==null?void 0:c.titleRunIds)??[];s.text=Hr(f.map(d=>t.getRun(d)),r)}else e.isLeaf(o)&&!Cc.has(o)&&(s.text=Hr(n.contentIds.map(f=>t.getRun(f)),r));const a={id:n.id,type:o,data:s};return e.isLeaf(o)||(a.children=n.contentIds.map(f=>Sc(t,e,t.getBlock(f),r))),a}function Rc(t,e,n,{pretty:r=!0}={}){const o={store:t,registry:e,inlineRegistry:n},a=t.getBlock(t.getRootId()).contentIds.map(i=>Sc(t,e,t.getBlock(i),o));return JSON.stringify({version:1,blocks:a},null,r?2:0)}function uo(t,e){const n=new DOMParser().parseFromString(`<div>${t??""}</div>`,"text/html");return Ye(n.body.firstChild,e)}function xb(t,e,n,r,o){const{id:s=E(),data:a={}}=t,i=(a.rows??[]).map(c=>{const f=E(),d=c.map(h=>{const m=E(),g=uo(h,o);return r.push(...g),n.push({id:m,type:"tableCell",parentId:f,contentIds:g.map(x=>x.id),props:{}}),m});return n.push({id:f,type:"tableRow",parentId:e,contentIds:d,props:{}}),f}),u={id:s,type:"table",parentId:e,contentIds:i,props:{columns:a.columns??[]}};return n.push(u),u}function po(t,e,n,r,o,s){const{id:a=E(),type:i,data:u={},children:c=[]}=t;if(i==="table")return xb(t,e,o,s,r);const f={};for(const h of wc[i]??[])u[h]!==void 0&&(f[h]=u[h]);const d={id:a,type:i,parentId:e,contentIds:[],props:f};if(o.push(d),Ic.has(i)){const h=uo(u.text,r);s.push(...h),d.props.titleRunIds=h.map(m=>m.id),d.contentIds=c.map(m=>po(m,a,n,r,o,s).id)}else if(n.isLeaf(i)){if(!Cc.has(i)){const h=uo(u.text,r);s.push(...h),d.contentIds=h.map(m=>m.id)}}else d.contentIds=c.map(h=>po(h,a,n,r,o,s).id);return d}function yb(t,e,n){const r=typeof t=="string"?JSON.parse(t):t,o={registry:e,inlineRegistry:n},s=E(),a=[],i=[],u=(r.blocks??[]).map(c=>po(c,s,e,o,a,i).id);return a.push({id:s,type:"page",parentId:null,contentIds:u,props:{}}),{rootId:s,blocks:a,runs:i}}const kb=[{value:"json",label:"JSON"},{value:"simpleJson",label:"Simple JSON"},{value:"html",label:"HTML"},{value:"text",label:"Text"}];function vb({label:t="View source",className:e=""}){const n=G(),r=vt(),o=tt(),[s,a]=p.useState(!1),[i,u]=p.useState("json"),[c,f]=p.useState(!1),d=p.useCallback(()=>{f(!1),a(!0)},[]),h=p.useCallback(()=>a(!1),[]),m=p.useMemo(()=>s?i==="json"?ko(n):i==="simpleJson"?Rc(n,r,o):i==="html"?Ea(n,r,o):Ba(n,r,o):"",[s,i,n,r,o]),g=p.useCallback(async()=>{try{await navigator.clipboard.writeText(m),f(!0),setTimeout(()=>f(!1),1500)}catch{}},[m]);return l.jsxs(l.Fragment,{children:[l.jsxs("button",{type:"button",className:`be-export-trigger ${e}`.trim(),onClick:d,children:[l.jsx(_o,{size:14})," ",t]}),l.jsxs(dt,{isOpen:s,onClose:h,title:"Document source",size:"large",children:[l.jsx("div",{className:"be-export-tabs",role:"tablist",children:kb.map(x=>l.jsx("button",{type:"button",role:"tab","aria-selected":i===x.value,className:`be-export-tab${i===x.value?" be-export-tab-active":""}`,onClick:()=>u(x.value),children:x.label},x.value))}),l.jsx("pre",{className:"be-export-pre",children:l.jsx("code",{children:m})}),l.jsxs("div",{className:"be-modal-actions",children:[l.jsx("button",{type:"button",className:"be-modal-cancel",onClick:h,children:"Close"}),l.jsx("button",{type:"button",className:"be-modal-save",onClick:g,children:c?"Copied!":"Copy"})]})]})]})}function wb({id:t,label:e,placeholder:n,variant:r,options:o,onManage:s,mention:a=!1}){const i=G(),u=wt(t),c=p.useCallback((m,g)=>{i.applyOperation(ue(t,{data:{selectedValue:m,selectedLabel:(g==null?void 0:g.label)??"",selectedColor:g==null?void 0:g.color}}))},[i,t]);if(!u)return null;const{selectedValue:f="",selectedLabel:d="",selectedColor:h}=u.data??{};return l.jsx("span",{className:"be-inline-select",onMouseDown:m=>{m.preventDefault(),m.stopPropagation()},onKeyDown:m=>m.stopPropagation(),children:l.jsx(Mt,{value:f,selectedLabel:d,selectedColor:h,options:o,onChange:c,placeholder:n,variant:r,ariaLabel:e,onManageOptions:s,mention:a})})}function Tc(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function ba(t){return Tc(t).replace(/"/g,"&quot;")}function jc({type:t,label:e,placeholder:n="Select…",variant:r="default",icon:o,options:s,onManage:a,triggers:i=["slash"],mention:u=i.includes("at")}){function c(g){var k,w;const x=((k=g.data)==null?void 0:k.selectedLabel)||"",y=u&&x?`@${x}`:x;return`<span data-inline-type="${ba(t)}" data-selected-value="${ba(((w=g.data)==null?void 0:w.selectedValue)??"")}">${Tc(y)}</span>`}function f(g){var y;const x=((y=g.data)==null?void 0:y.selectedLabel)??"";return u&&x?`@${x}`:x}function d(g){var k;if(((k=g.getAttribute)==null?void 0:k.call(g,"data-inline-type"))!==t)return null;const x=g.textContent??"",y=u&&x.startsWith("@")?x.slice(1):x;return{id:E(),type:t,value:"",marks:{},data:{selectedValue:g.getAttribute("data-selected-value")??"",selectedLabel:y}}}function h({id:g}){return l.jsx(wb,{id:g,label:e,placeholder:n,variant:r,options:s,onManage:a,mention:u})}const m={label:e,icon:o??sl,keywords:[e.toLowerCase(),"select","field"],run:(g,{blockId:x,runId:y,sliceStart:k,sliceEnd:w})=>Tr(g,{blockId:x,runId:y,sliceStart:k,sliceEnd:w},()=>({id:E(),type:t,value:"",marks:{},data:{selectedValue:"",selectedLabel:"",selectedColor:void 0}}))};return{component:h,isAtomic:!0,toHTML:c,toPlainText:f,fromHTML:d,slashCommand:i.includes("slash")?m:void 0,atCommand:i.includes("at")?m:void 0}}function Ec(t,e,{onManage:n}={}){for(const r of t.getFieldTypes())e.register(r.id,jc({type:r.id,label:r.label,placeholder:r.placeholder,variant:r.variant,options:r.options??[],onManage:n?()=>n(r.id):void 0}))}function Bc(){const t=G(),e=tt(),n=hc(),{openEdit:r}=So(),o=p.useRef([]);p.useEffect(()=>{if(!e)return;const s=new Set(n.map(a=>a.id));for(const a of o.current)s.has(a)||e.unregister(a);Ec(t,e,{onManage:r}),o.current=[...s]},[t,e,n,r])}function Ib(){Bc();const t=G(),{target:e,close:n}=So(),r=e!==null,o=r&&e!=="new",[s,a]=p.useState(""),[i,u]=p.useState([]),[c,f]=p.useState("");p.useEffect(()=>{if(r){if(o){const y=t.getFieldType(e);a((y==null?void 0:y.label)??""),u((y==null?void 0:y.options)??[])}else a(""),u([]);f("")}},[r,o,e,t]);const d=p.useCallback((y,k)=>{u(w=>w.map(v=>v.value===y?{...v,label:k}:v))},[]),h=p.useCallback(y=>{u(k=>k.filter(w=>w.value!==y))},[]),m=p.useCallback(()=>{const y=c.trim();f(""),y&&u(k=>[...k,{value:E(),label:y,color:Tn(k.length)}])},[c]),g=p.useCallback(()=>{const y=s.trim();y&&(o?t.applyOperation(mo(e,{label:y,options:i})):t.applyOperation(ho({id:E(),label:y,placeholder:"Select…",variant:"tag",options:i})),n())},[t,o,e,s,i,n]),x=p.useCallback(()=>{o&&t.applyOperation(bo(e)),n()},[t,o,e,n]);return l.jsxs(dt,{isOpen:r,onClose:n,title:o?"Edit field type":"New field type",children:[l.jsxs("label",{className:"be-modal-field",children:[l.jsx("span",{children:"Name"}),l.jsx("input",{type:"text",value:s,onChange:y=>a(y.target.value),placeholder:"e.g. Priority, Status…",autoFocus:!0})]}),l.jsxs("div",{className:"be-modal-field",children:[l.jsx("span",{children:"Options"}),i.map((y,k)=>l.jsxs("div",{className:"be-table-header-menu-option-row",children:[l.jsx("span",{className:"be-table-header-menu-option-swatch",style:{background:(y.color??Tn(k)).bg},"aria-hidden":"true"}),l.jsx("input",{className:"be-table-header-menu-option-input",value:y.label,onChange:w=>d(y.value,w.target.value),"aria-label":`Rename option ${y.label}`}),l.jsx("button",{type:"button",className:"be-table-header-menu-option-remove",onClick:()=>h(y.value),"aria-label":`Remove option ${y.label}`,children:l.jsx(Ot,{size:14})})]},y.value)),l.jsxs("div",{className:"be-table-header-menu-option-row",children:[l.jsx("input",{className:"be-table-header-menu-option-input",value:c,onChange:y=>f(y.target.value),placeholder:"New option…",onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),m())}}),l.jsx("button",{type:"button",className:"be-table-header-menu-option-add",onClick:m,"aria-label":"Add option",children:"+"})]})]}),l.jsxs("div",{className:"be-modal-actions",children:[o&&l.jsx("button",{type:"button",className:"be-modal-delete",onClick:x,children:"Delete field type"}),l.jsx("button",{type:"button",className:"be-modal-cancel",onClick:n,children:"Cancel"}),l.jsx("button",{type:"button",className:"be-modal-save",onClick:g,children:"Save"})]})]})}exports.APP_MIME=lr;exports.BlockChildren=ht;exports.BlockErrorBoundary=Sl;exports.BlockGutterRow=Bl;exports.BlockRangeActionMenu=Zi;exports.BlockRegistry=il;exports.BlockRenderer=zo;exports.COLUMN_TYPES=Ll;exports.CollabSession=ku;exports.CommentAvatar=Ro;exports.CommentComposer=No;exports.CommentThreadCard=Ao;exports.CommentsPanel=ll;exports.DEFAULT_COLUMN_TYPE=wr;exports.DEFAULT_COLUMN_WIDTH=Ir;exports.DocumentExportButton=vb;exports.EditableBlockContent=pt;exports.EditorProvider=Pa;exports.EditorStore=ur;exports.EditorTrailingSpace=Wi;exports.FieldClockRegistry=en;exports.FieldTypeEditorModal=Ib;exports.FloatingToolbar=pc;exports.HLC=Sn;exports.History=ka;exports.InlineRegistry=ul;exports.LAYOUT_BLOCKS=Ni;exports.ListCrdtState=Qt;exports.MESSAGE_TYPE=Ge;exports.MIN_COLUMN_WIDTH=or;exports.MobileActionBar=gb;exports.MobileBlockOptionsSheet=kc;exports.MobileBlockPickerSheet=yc;exports.Modal=dt;exports.NoteloomEditor=Wm;exports.PeerConnection=wa;exports.Select=Mt;exports.SlashMenu=nr;exports.TABLE_BLOCKS=Li;exports.TABLE_SELECT_INLINE_TYPES=Ki;exports.TableHeaderRow=Yl;exports.TemplatePicker=Du;exports.VoiceListeningIndicator=ib;exports.VoicePermissionModal=lb;exports.addComment=Yu;exports.addCommentMarkOverRange=vo;exports.applyDocumentTemplate=Lu;exports.blankRunForType=Nl;exports.blockquoteBlockType=ri;exports.buttonBlockType=ii;exports.calloutBlockType=ni;exports.canvasBlockType=_i;exports.captureBlockTemplate=Mu;exports.captureSubtree=Bn;exports.checkboxInlineType=zi;exports.codeBlockType=si;exports.convertRunToType=Al;exports.copyBlockRangeToClipboard=ao;exports.createAutoPersistence=Ta;exports.createBlockRegistry=cl;exports.createCellForColumn=Cr;exports.createDefaultColumns=Yo;exports.createInlineRegistry=dl;exports.createPeriodicTombstoneGC=cu;exports.createPeriodicVersionSnapshotter=zu;exports.createSelectFieldType=jc;exports.createWebSocketSignaling=vu;exports.dateInlineType=$i;exports.decodeMessage=va;exports.deleteBlockAndFocusSibling=vr;exports.deleteBlockRange=In;exports.deleteColumn=$l;exports.deleteComment=Na;exports.deleteDocumentVersion=Ra;exports.deleteEntireDocument=ir;exports.deleteOverBlockRange=es;exports.deletePersistedDocument=Cu;exports.deleteRow=Pl;exports.deleteRunRangeInBlock=Qo;exports.deleteTemplate=ju;exports.deserializeClipboard=ec;exports.dividerBlockType=ei;exports.duplicateBlock=Fo;exports.embedBlockType=pi;exports.emojiInlineType=Ui;exports.encodeMessage=Jt;exports.ensureRootNonEmpty=un;exports.exportDocumentHTML=Ea;exports.exportDocumentJSON=ko;exports.exportDocumentSimpleJSON=Rc;exports.exportDocumentText=Ba;exports.focusRunAtOffset=Je;exports.focusRunEnd=ye;exports.focusRunStart=br;exports.genPeerId=xa;exports.getMarksSummaryOverBlockRange=ns;exports.getMarksSummaryOverSelection=ts;exports.headingBlockType=Cl;exports.importDocumentSimpleJSON=yb;exports.injectDefaultStyles=Aa;exports.insertBlockTemplate=ja;exports.insertColumnAfter=sr;exports.insertRowAfter=Ko;exports.isEntireBlockRangeHidden=Gi;exports.isEntireBlockSelected=ac;exports.layoutBlockType=Ql;exports.layoutColumnBlockType=Zl;exports.listDocumentVersions=rr;exports.listItemBlockType=Ml;exports.listPersistedDocumentIds=Su;exports.listTemplates=Qr;exports.listVoiceCommands=tb;exports.loadDocumentVersion=Eu;exports.loadPersistedDocument=Ca;exports.loadTemplate=Tu;exports.moveBlockDown=Vo;exports.moveBlockRangeDown=qi;exports.moveBlockRangeUp=Xi;exports.moveBlockUp=Uo;exports.operations=ru;exports.paragraphBlockType=Il;exports.registerBlockTemplates=Nu;exports.registerBlocks=Mi;exports.registerBuiltInBlocks=Oi;exports.registerBuiltInInlineTypes=Vi;exports.registerInlineTypes=Yi;exports.registerStoredFieldTypes=Ec;exports.remapSubtreeIds=dr;exports.removeCommentMarkEverywhere=wo;exports.renameColumn=Hl;exports.reorderBlockRangeFromStore=mm;exports.replyToComment=Ma;exports.resolveCollapsedCaret=lt;exports.resolveColumns=$e;exports.resolveComment=La;exports.resolveCrossBlockSelection=rn;exports.resolveMultiRunSelection=ln;exports.resolveRunSelection=Pd;exports.saveDocumentVersion=Sa;exports.savePersistedDocument=Ia;exports.saveTemplate=Ru;exports.selectInlineType=Di;exports.serializeBlockRange=En;exports.setBlockRangeHidden=Ji;exports.setColumnOptions=Zn;exports.setColumnType=Fl;exports.setColumnWidth=zl;exports.setMarksOverBlockRange=cr;exports.setMarksOverSelection=sn;exports.tableBlockType=ql;exports.tableCellBlockType=Wl;exports.tableRowBlockType=Xl;exports.tableSelectInlineType=Fi;exports.textToParagraphs=Zo;exports.toggleHeadingBlockType=ai;exports.toggleMarkOnRunRange=Cm;exports.toggleMarkOverBlockRange=os;exports.toggleMarkOverSelection=rs;exports.useAtMenuTrigger=dc;exports.useBlock=be;exports.useBlockChildren=$o;exports.useBlockClassName=Ie;exports.useBlockRangeDrag=ic;exports.useBlockRangeSelection=_n;exports.useBlockRegistry=vt;exports.useCaretRect=xc;exports.useClipboardHandlers=tc;exports.useCoarsePointer=ls;exports.useCommentAuthorId=$a;exports.useComments=za;exports.useDocumentVersions=Hu;exports.useEditor=fm;exports.useEditorKeyboardShortcuts=lc;exports.useEditorStore=G;exports.useEmojiMenuTrigger=uc;exports.useFieldTypeEditor=So;exports.useFieldTypes=hc;exports.useFloatingToolbarTrigger=fc;exports.useHistory=mc;exports.useInlineRegistry=tt;exports.usePersistedDocument=Gm;exports.usePresence=Jm;exports.usePreviewMode=Co;exports.useRegisterFieldTypes=Bc;exports.useRun=wt;exports.useSelectedBlock=ut;exports.useServiceWorkerUpdate=Zm;exports.useSlashMenuTrigger=cc;exports.useTemplates=Au;exports.useTextFormattingActions=as;exports.useVirtualKeyboardInset=Sr;exports.useVoiceTyping=ab;exports.useWholeDocumentSelection=Io;exports.walkDomToBlocks=Qi;
3208
+ ${o}`:r}function Kf(t,e){if(t.tagName!=="DETAILS")return null;const n=[...t.children].find(u=>u.tagName==="SUMMARY"),r=n==null?void 0:n.querySelector("h1,h2,h3,h4,h5,h6"),o=r?Math.min(6,Math.max(1,Number(r.tagName[1]))):2,s=r?Ye(r,e):[{id:_(),type:"text",value:"",marks:{}}],a=_(),i=[],d=[],c=[];for(const u of t.children){if(u===n||u.tagName!=="P")continue;const h=Ye(u,e),m={id:_(),type:"paragraph",parentId:a,contentIds:h.map(g=>g.id),props:{}};i.push(m),d.push(...h),c.push(m.id)}if(c.length===0){const{block:u,runs:h}=te("paragraph")(a);i.push(u),d.push(...h),c.push(u.id)}return{block:{id:a,type:"toggleHeading",parentId:null,contentIds:c,props:{level:o,collapsed:!t.hasAttribute("open"),titleRunIds:s.map(u=>u.id)}},runs:[...s,...d],subtreeBlocks:i}}const mi={component:Ff,isLeaf:!1,defaultProps:{level:2,collapsed:!1,titleRunIds:[]},toHTML:Vf,toPlainText:Yf,fromHTML:Kf,slashCommands:[1,2,3].map(t=>({label:`Toggle heading ${t}`,icon:Et,keywords:["toggle","heading","collapse","section"],run:(e,n)=>Be(e,n,Uf({level:t}))}))},Yr=[{label:"Blue",value:"#2b6fd6"},{label:"Green",value:"#2f9e44"},{label:"Red",value:"#e03131"},{label:"Purple",value:"#9c36b5"},{label:"Gray",value:"#495057"},{label:"Black",value:"#1a1a1a"}];function Wf(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function qf({isOpen:t,onClose:e,store:n,blockId:r}){const[o,s]=p.useState(""),[a,i]=p.useState(""),[d,c]=p.useState(Yr[0].value),[f,u]=p.useState([{key:"",value:""}]);p.useEffect(()=>{var v,w,B;if(!t)return;const x=n.getBlock(r);if(!x)return;const y=x.contentIds.map(I=>{var C;return((C=n.getRun(I))==null?void 0:C.value)??""}).join(""),k=((v=x.props)==null?void 0:v.customAttrs)??[];s(y),i(((w=x.props)==null?void 0:w.href)??""),c(((B=x.props)==null?void 0:B.color)??Yr[0].value),u([...k,{key:"",value:""}])},[t,r,n]);const h=p.useCallback((x,y)=>{u(k=>{const v=k.map((B,I)=>I===x?{...B,...y}:B),w=v[v.length-1];return(w.key.trim()||w.value.trim())&&v.push({key:"",value:""}),v})},[]),m=p.useCallback(x=>{u(y=>y.filter((k,v)=>v!==x))},[]),g=p.useCallback(()=>{const x={id:_(),type:"text",value:o,marks:{}},y=f.filter(k=>k.key.trim());Wf(n,[Me(r,[x]),J(r,{href:a.trim(),color:d,customAttrs:y})]),e()},[n,r,o,a,d,f,e]);return l.jsxs(pt,{isOpen:t,onClose:e,title:"Edit button",children:[l.jsxs("label",{className:"be-modal-field",children:[l.jsx("span",{children:"Label"}),l.jsx("input",{type:"text",value:o,onChange:x=>s(x.target.value),placeholder:"Button"})]}),l.jsxs("label",{className:"be-modal-field",children:[l.jsx("span",{children:"Link URL"}),l.jsx("input",{type:"url",value:a,onChange:x=>i(x.target.value),placeholder:"https://example.com"})]}),l.jsxs("div",{className:"be-modal-field",children:[l.jsx("span",{children:"Color"}),l.jsx("div",{className:"be-modal-color-row",children:Yr.map(x=>l.jsx("button",{type:"button",className:`be-modal-color-swatch${d===x.value?" be-modal-color-swatch-active":""}`,style:{backgroundColor:x.value},title:x.label,"aria-label":x.label,onClick:()=>c(x.value)},x.value))})]}),l.jsxs("div",{className:"be-modal-field",children:[l.jsx("span",{children:"Custom attributes"}),f.map((x,y)=>l.jsxs("div",{className:"be-modal-attr-row",children:[l.jsx("input",{type:"text",placeholder:"name",value:x.key,onChange:k=>h(y,{key:k.target.value})}),l.jsx("input",{type:"text",placeholder:"value",value:x.value,onChange:k=>h(y,{value:k.target.value})}),(x.key||x.value)&&l.jsx("button",{type:"button",className:"be-modal-attr-remove",onClick:()=>m(y),"aria-label":"Remove attribute",children:l.jsx(wt,{size:14})})]},y))]}),l.jsxs("div",{className:"be-modal-actions",children:[l.jsx("button",{type:"button",className:"be-modal-cancel",onClick:e,children:"Cancel"}),l.jsx("button",{type:"button",className:"be-modal-save",onClick:g,children:"Save"})]})]})}const Xf="#2b6fd6";function Gf({id:t}){var v,w,B,I;const e=G(),n=be(t),{setSelectedBlockId:r}=ut(),[o,s]=p.useState(!1),a=p.useCallback(()=>{cn(e,t,(n==null?void 0:n.contentIds)??[],te("paragraph"))},[e,t,n]),i=p.useCallback(()=>{const C=Dn(e,t);un(e,C,t,r)},[e,t,r]),d=p.useCallback(()=>_e(e,t,"up"),[e,t]),c=p.useCallback(()=>_e(e,t,"down"),[e,t]),f=p.useCallback(()=>{var R;const C=(R=n==null?void 0:n.props)==null?void 0:R.href;C&&window.open(C,"_blank","noopener,noreferrer")},[(v=n==null?void 0:n.props)==null?void 0:v.href]),u=Ie("be-button-block",n);if(!n)return null;const h=((w=n.props)==null?void 0:w.href)??"",m=((B=n.props)==null?void 0:B.color)??Xf,g=((I=n.props)==null?void 0:I.customAttrs)??[],x=Oe(e,n.contentIds),y={};for(const{key:C,value:R}of g)C.trim()&&(y[`data-${C.trim()}`]=R);const k=it(e,n);return l.jsxs("div",{className:u,"data-block-id":t,dir:k,children:[l.jsxs("div",{className:"be-button-block-pill",style:{backgroundColor:m},...y,children:[l.jsx("span",{className:"be-button-block-label","data-empty":x?"":void 0,"data-placeholder":"Button",children:l.jsx(ft,{blockId:t,runIds:n.contentIds,dir:k,onEnter:a,onBackspaceAtStart:i,onArrowUp:d,onArrowDown:c})}),l.jsx("button",{type:"button",className:"be-button-block-open",onClick:f,disabled:!h,title:h||"No link set","aria-label":"Open link",children:"↗"}),l.jsx("button",{type:"button",className:"be-button-block-settings",onClick:()=>s(!0),"aria-label":"Edit button",title:"Edit label, link, color…",children:"⚙"})]}),l.jsx(qf,{isOpen:o,onClose:()=>s(!1),store:e,blockId:t})]})}function Jf({href:t="",label:e="Button",color:n="",customAttrs:r=[]}={}){return function(s,a){const i=_(),d=a!=null&&a.length?a:[{id:_(),type:"text",value:e,marks:{}}];return{block:{id:i,type:"button",parentId:s,contentIds:d.map(c=>c.id),props:{href:t,color:n,customAttrs:r}},runs:d}}}const bi="be-button-block-link";function Zf(t,e){var d,c,f;const n=t.contentIds.map(u=>e.store.getRun(u)),r=((d=t.props)==null?void 0:d.href)??"",o=(c=t.props)==null?void 0:c.color,s=o?` style="background-color:${Ee(o)}"`:"",i=(((f=t.props)==null?void 0:f.customAttrs)??[]).filter(u=>{var h;return(h=u.key)==null?void 0:h.trim()}).map(u=>` data-${Ee(u.key.trim())}="${Ee(u.value??"")}"`).join("");return`<a class="${bi}" href="${Ee(r)}"${s}${i}>${n.map(u=>ht(u,e)).join("")}</a>`}function Qf(t,e){return t.contentIds.map(n=>Ct(e.store.getRun(n),e)).join("")}function eh(t,e){var s;if(t.tagName!=="A"||!t.classList.contains(bi))return null;const n=Ye(t,e),r=[];for(const a of t.attributes)a.name.startsWith("data-")&&r.push({key:a.name.slice(5),value:a.value});return{block:{id:_(),type:"button",parentId:null,contentIds:n.map(a=>a.id),props:{href:t.getAttribute("href")??"",color:((s=t.style)==null?void 0:s.backgroundColor)||void 0,customAttrs:r}},runs:n}}const gi={component:Gf,isLeaf:!0,defaultProps:{href:"",color:"",customAttrs:[]},toHTML:Zf,toPlainText:Qf,fromHTML:eh,slashCommand:{label:"Button",icon:xu,keywords:["button","link","cta","action"],run:(t,e)=>Be(t,e,Jf())}};function ra(t){return new Promise((e,n)=>{const r=new FileReader;r.onload=()=>e(r.result),r.onerror=()=>n(r.error),r.readAsDataURL(t)})}const Xn={image:"image",video:"video",audio:"audio",file:"file"},th={image:"image/*",video:"video/*",audio:"audio/*",file:"*/*"},xi=20,yi=100,nh=[{value:"left",Icon:Ja,label:"Align left"},{value:"center",Icon:au,label:"Align center"},{value:"right",Icon:Za,label:"Align right"}];function rh(t){return Math.min(yi,Math.max(xi,Math.round(t)))}function oh({kind:t,src:e,name:n,alt:r}){return t==="image"?l.jsx("img",{className:"be-embed-image",src:e,alt:r||""}):t==="video"?l.jsx("video",{className:"be-embed-video",src:e,controls:!0}):t==="audio"?l.jsx("audio",{className:"be-embed-audio",src:e,controls:!0}):l.jsxs("a",{className:"be-embed-file-link",href:e,download:n||void 0,target:"_blank",rel:"noopener noreferrer",children:[l.jsx(Va,{size:14})," ",n||e]})}function sh({id:t}){var re;const e=G(),n=be(t),[r,o]=p.useState(""),[s,a]=p.useState(!1),[i,d]=p.useState(null),[c,f]=p.useState(!1),[u,h]=p.useState(""),m=p.useRef(null),g=p.useRef(null),x=p.useCallback(H=>e.applyOperation(J(t,H)),[e,t]),y=p.useCallback(()=>{var H;h(((H=n==null?void 0:n.props)==null?void 0:H.alt)??""),f(!0)},[(re=n==null?void 0:n.props)==null?void 0:re.alt]),k=p.useCallback(()=>f(!1),[]),v=p.useCallback(H=>{H.preventDefault(),x({alt:u.trim()}),f(!1)},[u,x]),w=p.useCallback(async H=>{var oe;const ne=(oe=H.target.files)==null?void 0:oe[0];if(!ne)return;const se=await ra(ne);x({src:se,name:ne.name,mimeType:ne.type})},[x]),B=p.useCallback(async H=>{var oe;H.preventDefault(),a(!1);const ne=(oe=H.dataTransfer.files)==null?void 0:oe[0];if(!ne)return;const se=await ra(ne);x({src:se,name:ne.name,mimeType:ne.type})},[x]),I=p.useCallback(H=>{H.preventDefault(),a(!0)},[]),C=p.useCallback(()=>a(!1),[]),R=p.useCallback(()=>{const H=r.trim();H&&(x({src:H,name:H}),o(""))},[r,x]),E=p.useCallback(()=>x({src:"",name:"",mimeType:""}),[x]),T=p.useCallback(H=>{H.preventDefault();const ne=m.current,se=g.current;if(!ne||!se)return;const oe=ne.getBoundingClientRect().width,ge=se.getBoundingClientRect().width,Re=H.clientX,ce=U=>rh((ge+(U.clientX-Re))/oe*100),ke=U=>d(ce(U)),he=U=>{document.removeEventListener("mousemove",ke),document.removeEventListener("mouseup",he),x({width:ce(U)}),d(null)};document.addEventListener("mousemove",ke),document.addEventListener("mouseup",he)},[x]),O=Ie("be-embed",n);if(!n)return null;const{kind:S="file",src:L,name:$,alt:Y="",align:K="left",width:Q=100}=n.props,D=S==="image"||S==="video",F=i??Q;return l.jsxs("div",{className:O,"data-block-id":t,"data-kind":S,contentEditable:!1,tabIndex:-1,children:[L?l.jsx("div",{ref:m,className:`be-embed-preview be-embed-align-${K}`,children:l.jsxs("div",{ref:g,className:"be-embed-frame",style:D?{width:`${F}%`}:void 0,children:[l.jsxs("div",{className:"be-embed-toolbar",contentEditable:!1,children:[nh.map(({value:H,Icon:ne,label:se})=>l.jsx("button",{type:"button",className:`be-embed-toolbar-btn${K===H?" be-embed-toolbar-btn-active":""}`,title:se,"aria-label":se,"aria-pressed":K===H,onClick:()=>x({align:H}),children:l.jsx(ne,{size:14})},H)),S==="image"&&l.jsx("button",{type:"button",className:"be-embed-toolbar-btn be-embed-alt-text-btn",onClick:y,children:"Alt text"}),l.jsx("button",{type:"button",className:"be-embed-remove",onClick:E,"aria-label":`Remove ${Xn[S]}`,children:"Remove"})]}),l.jsx(oh,{kind:S,src:L,name:$,alt:Y}),D&&l.jsx("div",{className:"be-embed-resize-handle",onMouseDown:T,role:"slider","aria-label":`Resize ${Xn[S]}`,"aria-valuemin":xi,"aria-valuemax":yi,"aria-valuenow":F})]})}):l.jsxs("div",{className:`be-embed-dropzone${s?" be-embed-dropzone-active":""}`,onDrop:B,onDragOver:I,onDragLeave:C,children:[l.jsxs("label",{className:"be-embed-upload-btn",children:["Upload ",Xn[S],l.jsx("input",{type:"file",accept:th[S],onChange:w,hidden:!0})]}),l.jsx("span",{className:"be-embed-dropzone-hint",children:"or drop a file, or paste a URL below"}),l.jsxs("div",{className:"be-embed-url-row",children:[l.jsx("input",{type:"text",className:"be-embed-url-input",placeholder:`https://... ${Xn[S]} URL`,value:r,onChange:H=>o(H.target.value),onKeyDown:H=>H.key==="Enter"&&R()}),l.jsx("button",{type:"button",className:"be-embed-url-commit",onClick:R,children:"Embed"})]})]}),l.jsx(pt,{isOpen:c,onClose:k,title:"Alt text",children:l.jsxs("form",{onSubmit:v,children:[l.jsxs("label",{className:"be-modal-field",children:[l.jsx("span",{children:"Describe this image for screen readers"}),l.jsx("input",{type:"text",value:u,onChange:H=>h(H.target.value),placeholder:"e.g. A hand-drawn diagram of the release process",autoFocus:!0})]}),l.jsxs("div",{className:"be-modal-actions",children:[l.jsx("button",{type:"button",className:"be-modal-cancel",onClick:k,children:"Cancel"}),l.jsx("button",{type:"submit",className:"be-modal-save",children:"Save"})]})]})})]})}function ah({kind:t="file",src:e="",name:n="",alt:r="",mimeType:o="",align:s="left",width:a=100}={}){return function(d){return{block:{id:_(),type:"embed",parentId:d,contentIds:[],props:{kind:t,src:e,name:n,alt:r,mimeType:o,align:s,width:a}},runs:[]}}}const lh={image:wu,video:Iu,audio:Cu,file:Va},ki="be-embed-file-link";function ih(t,e,n){if(t!=="image"&&t!=="video")return"";const r=[];return n!==100&&r.push(`width:${n}%`),e==="center"?r.push("display:block","margin-left:auto","margin-right:auto"):e==="right"&&r.push("display:block","margin-left:auto"),r.length?` style="${r.join(";")}"`:""}function oa(t){var o,s,a,i;const e=(o=t.style)==null?void 0:o.width,n=e&&e.endsWith("%")?parseInt(e,10):100;let r="left";return((s=t.style)==null?void 0:s.marginLeft)==="auto"&&((a=t.style)==null?void 0:a.marginRight)==="auto"?r="center":((i=t.style)==null?void 0:i.marginLeft)==="auto"&&(r="right"),{align:r,width:Number.isFinite(n)?n:100}}function ch(t){const{kind:e,src:n,name:r,alt:o="",align:s="left",width:a=100}=t.props;if(!n)return"<p></p>";const i=ih(e,s,a);return e==="image"?`<img src="${Ee(n)}" alt="${Ee(o)}"${i}>`:e==="video"?`<video src="${Ee(n)}" controls${i}></video>`:e==="audio"?`<audio src="${Ee(n)}" controls></audio>`:`<a class="${ki}" href="${Ee(n)}">${Bt(r||n)}</a>`}function dh(t){const{kind:e,src:n,name:r}=t.props;return n?`[${e}: ${r||n}]`:""}function uh(t){return t.tagName==="IMG"?Gn("image",t.getAttribute("src")??"","",{...oa(t),alt:t.getAttribute("alt")??""}):t.tagName==="VIDEO"?Gn("video",t.getAttribute("src")??"","",oa(t)):t.tagName==="AUDIO"?Gn("audio",t.getAttribute("src")??"",""):t.tagName==="A"&&t.classList.contains(ki)?Gn("file",t.getAttribute("href")??"",t.textContent??""):null}function Gn(t,e,n,{align:r="left",width:o=100,alt:s=""}={}){return{block:{id:_(),type:"embed",parentId:null,contentIds:[],props:{kind:t,src:e,name:n,alt:s,align:r,width:o}},runs:[]}}function ph(t){return(e,{blockId:n,runId:r,sliceStart:o,sliceEnd:s})=>{const a=e.getRun(r),i=(a==null?void 0:a.value)??"";e.applyOperation(de(r,{value:i.slice(0,o)+i.slice(s)}));const d=vr(e,n,ah({kind:t}));return nt(e,d,te("paragraph")),d}}const vi={component:sh,isLeaf:!0,defaultProps:{kind:"file",src:"",name:"",alt:"",mimeType:"",align:"left",width:100},toHTML:ch,toPlainText:dh,fromHTML:uh,slashCommands:["image","video","audio","file"].map(t=>({label:t.charAt(0).toUpperCase()+t.slice(1),icon:lh[t],keywords:["embed","upload","insert",t],run:ph(t)}))},wi=8,Ii=.5,fh=.5,hh=4,Kr=.15,mh=8;function Ci(t,e){return Math.hypot(t[0]-e[0],t[1]-e[1])}function nr(t,e,n){return Math.min(n,Math.max(e,t))}function Jn(t){return Math.round(t*100)/100}const Si=.5;function bh(t){return t.some(([,,e])=>e!==void 0&&e!==Si)}function gh(t,{size:e=wi,thinning:n=Ii}={}){const r=e/2,o=t.length;if(!bh(t))return new Array(o).fill(r);const a=new Array(o);let i=0;for(let c=0;c<o;c+=1){if(c>0){const g=Ci(t[c],t[c-1]);i=i*.8+g*.2}const f=nr(i/mh,0,1),u=t[c][2]??Si,h=.4+.6*nr(u,0,1),m=nr(r*h*(1-n*f),r*Kr,r);a[c]=m}const d=Math.min(hh,Math.floor(o/2));for(let c=0;c<d;c+=1){const f=(c+1)/(d+1),u=Kr+(1-Kr)*f;a[c]*=u,a[o-1-c]*=u}return a}function xh(t,e){const n=t.length;if(n<3||e<=0)return t;const r=new Array(n);r[0]=t[0],r[n-1]=t[n-1];for(let o=1;o<n-1;o+=1){const s=(t[o-1][0]+t[o+1][0])/2,a=(t[o-1][1]+t[o+1][1])/2,i=t[o][0]+(s-t[o][0])*e,d=t[o][1]+(a-t[o][1])*e;r[o]=[i,d,t[o][2]]}return r}function yh(t,e){const n=t.length,r=new Array(n),o=new Array(n);for(let s=0;s<n;s+=1){const a=t[Math.max(0,s-1)],i=t[Math.min(n-1,s+1)];let d=i[0]-a[0],c=i[1]-a[1];const f=Math.hypot(d,c)||1;d/=f,c/=f;const u=-c,h=d,m=e[s];r[s]=[t[s][0]+u*m,t[s][1]+h*m],o[s]=[t[s][0]-u*m,t[s][1]-h*m]}return{left:r,right:o}}function ji(t){if(t.length===0)return"";let e=`M${Jn(t[0][0])},${Jn(t[0][1])}`;for(let n=1;n<t.length;n+=1)e+=` L${Jn(t[n][0])},${Jn(t[n][1])}`;return e}function kh([t,e],n){const o=[];for(let s=0;s<12;s+=1){const a=s/12*Math.PI*2;o.push([t+Math.cos(a)*n,e+Math.sin(a)*n])}return`${ji(o)} Z`}function cr(t,e={}){const{size:n=wi,thinning:r=Ii,smoothing:o=fh}=e;if(!t||t.length===0)return"";const s=[t[0]];for(let u=1;u<t.length;u+=1)Ci(t[u],s[s.length-1])>.1&&s.push(t[u]);if(s.length===1){const u=s[0][2]??.5,h=n/2*(.4+.6*nr(u,0,1));return kh(s[0],h)}const a=gh(s,{size:n,thinning:r}),i=xh(s,o),{left:d,right:c}=yh(i,a),f=[...d,...c.slice().reverse()];return`${ji(f)} Z`}function rr(t){if(!t||t.length===0)return{minX:0,minY:0,maxX:0,maxY:0};let e=1/0,n=1/0,r=-1/0,o=-1/0;for(const[s,a]of t)s<e&&(e=s),a<n&&(n=a),s>r&&(r=s),a>o&&(o=a);return{minX:e,minY:n,maxX:r,maxY:o}}function Go(t,e){const n=t.getBoundingClientRect(),r=n.width||1,o=n.height||1,s=Math.min(r/e,o/e),a=(r-e*s)/2,i=(o-e*s)/2;return{rect:n,scale:s,offsetX:a,offsetY:i}}function Ge(t,e,n={x:0,y:0,size:1e3}){const{rect:r,scale:o,offsetX:s,offsetY:a}=Go(e,n.size),i=n.x+(t.clientX-r.left-s)/o,d=n.y+(t.clientY-r.top-a)/o;return[i,d]}function Wr(t,e){return Go(t,e).scale}function vh(t,e,n,r){const[o,s]=Ge(t,e,n),{rect:a,scale:i,offsetX:d,offsetY:c}=Go(e,r),f=o-(t.clientX-a.left-d)/i,u=s-(t.clientY-a.top-c)/i;return{x:f,y:u}}function sa(t,e){const n=t.x+t.size/2,r=t.y+t.size/2;return{x:n-e/2,y:r-e/2}}function gn(t,e,n=0){return t.minX-n<=e.maxX&&t.maxX+n>=e.minX&&t.minY-n<=e.maxY&&t.maxY+n>=e.minY}function wn(t,e,n,r){const o=Math.min(t,n),s=Math.min(e,r),a=Math.abs(n-t),i=Math.abs(r-e);return{x:o,y:s,width:a,height:i}}function Ri(t,e,n,r,o){const s=o*Math.PI/180,a=Math.cos(s),i=Math.sin(s),d=t-n,c=e-r;return[n+d*a-c*i,r+d*i+c*a]}function Ti(t,e,n){return t>=n.x&&t<=n.x+n.width&&e>=n.y&&e<=n.y+n.height}function wh(t,e,n){const r=n.width/2,o=n.height/2;if(r===0||o===0)return!1;const s=n.x+r,a=n.y+o,i=(t-s)/r,d=(e-a)/o;return i*i+d*d<=1}function Ih(t,e,n,r,o,s){const a=o-n,i=s-r,d=a*a+i*i;if(d===0)return Math.hypot(t-n,e-r);let c=((t-n)*a+(e-r)*i)/d;c=Math.min(1,Math.max(0,c));const f=n+c*a,u=r+c*i;return Math.hypot(t-f,e-u)}function Ei(t,e,n,r,o,s,a){return Ih(t,e,n,r,o,s)<=a}function Bi(t){const{x:e,y:n,width:r,height:o}=t;return[[e+r/2,n],[e+r,n+o/2],[e+r/2,n+o],[e,n+o/2]]}function _i(t){const{x:e,y:n,width:r,height:o}=t;return[[e+r/2,n],[e+r,n+o],[e,n+o]]}function Ni(t,e=5){const{x:n,y:r,width:o,height:s}=t,a=n+o/2,i=r+s/2,d=o/2,c=s/2,f=.4,u=[],h=Math.PI/e;let m=-Math.PI/2;for(let g=0;g<e*2;g+=1){const x=g%2===0,y=x?d:d*f,k=x?c:c*f;u.push([a+Math.cos(m)*y,i+Math.sin(m)*k]),m+=h}return u}function Ch(t,e,n){let r=!1;for(let o=0,s=n.length-1;o<n.length;s=o,o+=1){const[a,i]=n[o],[d,c]=n[s];i>e!=c>e&&t<(d-a)*(e-i)/(c-i)+a&&(r=!r)}return r}function Mi(t,e,n,r,o=24){const s=n-t,a=r-e,i=Math.hypot(s,a),[d,c]=i===0?[1,0]:[s/i,a/i],f=n-d*o,u=r-c*o,h=-c,m=d,g=o/2;return[[n,r],[f+h*g,u+m*g],[f-h*g,u-m*g]]}function Sh({compute:t,onCommit:e}){const[n,r]=p.useState(null),o=p.useCallback((s,a)=>{s.preventDefault();const i=c=>r(t(c,a)),d=c=>{document.removeEventListener("mousemove",i),document.removeEventListener("mouseup",d),e(t(c,a)),r(null)};document.addEventListener("mousemove",i),document.addEventListener("mouseup",d)},[t,e]);return{dragValue:n,startDrag:o}}const Jo=480,Zo=320;function jh({strokes:t=[],shapes:e=[],width:n=Jo,height:r=Zo}={}){return function(s){return{block:{id:_(),type:"canvas",parentId:s,contentIds:[],props:{strokes:t,shapes:e,width:n,height:r}},runs:[]}}}const Rh={diamond:Bi,triangle:_i,star:Ni};function Th(t){const e=t.strokeWidth??8,n=Ee(t.color);if(t.type==="arrow"){const i=Math.max(16,e*3),c=Mi(t.x1,t.y1,t.x2,t.y2,i).map(([f,u])=>`${f},${u}`).join(" ");return`<line x1="${t.x1}" y1="${t.y1}" x2="${t.x2}" y2="${t.y2}" stroke="${n}" stroke-width="${e}"></line><polygon points="${c}" fill="${n}"></polygon>`}const r=t.fillColor?Ee(t.fillColor):"none";let o;if(t.type==="rectangle")o=`<rect x="${t.x}" y="${t.y}" width="${t.width}" height="${t.height}" fill="${r}" stroke="${n}" stroke-width="${e}"></rect>`;else if(t.type==="ellipse"){const i=t.x+t.width/2,d=t.y+t.height/2;o=`<ellipse cx="${i}" cy="${d}" rx="${t.width/2}" ry="${t.height/2}" fill="${r}" stroke="${n}" stroke-width="${e}"></ellipse>`}else if(t.type==="text"){const i=t.fontSize??28,d=Bt(t.text??"");o=`<foreignObject x="${t.x}" y="${t.y}" width="${t.width}" height="${t.height}"><div xmlns="http://www.w3.org/1999/xhtml" style="width:100%;height:100%;overflow:hidden;color:${n};font-size:${i}px;line-height:1.3;white-space:pre-wrap;word-break:break-word;">${d}</div></foreignObject>`}else{const i=Rh[t.type];if(!i)return"";const d={x:t.x,y:t.y,width:t.width,height:t.height};o=`<polygon points="${i(d).map(([f,u])=>`${f},${u}`).join(" ")}" fill="${r}" stroke="${n}" stroke-width="${e}"></polygon>`}if(!t.rotation)return o;const s=t.x+t.width/2,a=t.y+t.height/2;return`<g transform="rotate(${t.rotation} ${s} ${a})">${o}</g>`}function Oi(t){const{strokes:e=[],shapes:n=[],width:r,height:o}=t.props,s=e.map(i=>`<path fill="${Ee(i.color)}" d="${cr(i.points,{size:i.size})}"></path>`).join(""),a=n.map(Th).join("");return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 1000" width="${r}" height="${o}">${s}${a}</svg>`}const Tt=1e3,aa="#1a1a1a",Li=8,la=["#1a1a1a","#e03131","#2f9e44","#1971c2","#f08c00"],Eh=2,Bh=40,_h=24,Nh=6,ia=160,Mh=120,qr=.5,Xr=4,Zn=1.1,ca=4,Qn=24,Oh=1,Lh=10,da={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]},Ah=220,Dh=60,so=28,Ph=12,$h=96,ao=10,ua=15,pa=ao*5;function Ae(t){return Math.round(t/ao)*ao}function zh(t){return Math.round(t/ua)*ua}function Hh(){const t=p.useRef(new WeakMap);return e=>{const n=t.current;let r=n.get(e);return r===void 0&&(r=cr(e.points,{size:e.size}),n.set(e,r)),r}}function Fh(t,e,n){return{minX:t-n,minY:e-n,maxX:t+n,maxY:e+n}}function fa(t){let e=0,n=0;for(const o of t.values())e+=o.x,n+=o.y;const r=t.size||1;return{x:e/r,y:n/r}}function Uh(t,e,n,r){const o=t.points;if(o.length===1){const[s,a]=o[0];return Math.hypot(e-s,n-a)<=r}for(let s=0;s<o.length-1;s+=1){const[a,i]=o[s],[d,c]=o[s+1];if(Ei(e,n,a,i,d,c,r))return!0}return!1}const Gr=new Set(["rectangle","ellipse","arrow","diamond","triangle","star"]),Ai={diamond:Bi,triangle:_i,star:Ni},ha=[{type:"rectangle",label:"Rectangle",Icon:Qa},{type:"ellipse",label:"Ellipse",Icon:iu},{type:"arrow",label:"Arrow",Icon:cu},{type:"diamond",label:"Diamond",Icon:du},{type:"triangle",label:"Triangle",Icon:uu},{type:"star",label:"Star",Icon:pu}],ma=[{mode:"object",label:"Object Eraser",Icon:el},{mode:"precise",label:"Precise Eraser",Icon:wt}];function Jr(t,e,n,r){return t.type==="arrow"?{type:"arrow",x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,color:e,strokeWidth:n}:{type:t.type,...wn(t.x1,t.y1,t.x2,t.y2),color:e,strokeWidth:n,fillColor:r}}const Vh=16;function Di(t,e,n){for(let r=n.length-1;r>=0;r-=1){const o=n[r];if(o.type==="arrow"){if(Ei(t,e,o.x1,o.y1,o.x2,o.y2,Vh))return o.id;continue}const s={x:o.x,y:o.y,width:o.width,height:o.height};let[a,i]=[t,e];if(o.rotation){const{cx:f,cy:u}=Tr(o);[a,i]=Ri(t,e,f,u,-o.rotation)}const d=Ai[o.type];let c;if(d?c=Ch(a,i,d(s)):c=o.type==="ellipse"?wh(a,i,s):Ti(a,i,s),c)return o.id}return null}function xn(t,e,n){return t.type==="arrow"?{...t,x1:t.x1+e,y1:t.y1+n,x2:t.x2+e,y2:t.y2+n}:{...t,x:t.x+e,y:t.y+n}}function En(t){return t.type==="arrow"?{x:Math.min(t.x1,t.x2),y:Math.min(t.y1,t.y2),width:Math.abs(t.x2-t.x1),height:Math.abs(t.y2-t.y1)}:{x:t.x,y:t.y,width:t.width,height:t.height}}function Tr(t){const e=En(t);return{cx:e.x+e.width/2,cy:e.y+e.height/2}}function yn(t,e,n){return{...t,points:t.points.map(([r,o,s])=>[r+e,o+n,s])}}function Yh(t,e){const n=[];let r=[];for(let o=0;o<t.length;o+=1)e.has(o)?(r.length>0&&n.push(r),r=[]):r.push(t[o]);return r.length>0&&n.push(r),n}function Pi(t){const e=rr(t.points);return{x:e.minX,y:e.minY,width:e.maxX-e.minX,height:e.maxY-e.minY}}function Kh(t,e){return t==="stroke"?Pi(e):En(e)}function ba(t,e){var a,i;const n=((a=t==null?void 0:t.props)==null?void 0:a.strokes)??[],r=((i=t==null?void 0:t.props)==null?void 0:i.shapes)??[],o=n.find(d=>d.id===e);if(o)return{kind:"stroke",item:o};const s=r.find(d=>d.id===e);return s?{kind:"shape",item:s}:null}function Wh(t,e,n,r){const o=Di(t,e,r);if(o)return{kind:"shape",id:o};for(let s=n.length-1;s>=0;s-=1){const a=n[s];if(Ti(t,e,Pi(a)))return{kind:"stroke",id:a.id}}return null}const er=24,kn=14;function lo(t){return{nw:[t.x,t.y],ne:[t.x+t.width,t.y],sw:[t.x,t.y+t.height],se:[t.x+t.width,t.y+t.height]}}const qh={nw:"se",ne:"sw",sw:"ne",se:"nw"},Xh=32;function $i(t){const e=En(t),n=e.x+e.width/2,r=e.y-Xh;if(!t.rotation)return[n,r];const{cx:o,cy:s}=Tr(t);return Ri(n,r,o,s,t.rotation)}function Gh(t,e,n){if(!n)return null;if(n.type==="arrow")return Math.hypot(t-n.x1,e-n.y1)<=er?"start":Math.hypot(t-n.x2,e-n.y2)<=er?"end":null;const[r,o]=$i(n);if(Math.hypot(t-r,e-o)<=er)return"rotate";if(n.rotation)return null;for(const[s,[a,i]]of Object.entries(lo(n)))if(Math.hypot(t-a,e-i)<=er)return s;return null}function Zr(t,e){return e.mode==="arrow-endpoint"?e.endpoint==="start"?{...t,x1:e.x,y1:e.y}:{...t,x2:e.x,y2:e.y}:e.mode==="rotate"?{...t,rotation:e.rotation}:{...t,...wn(e.fixedX,e.fixedY,e.x,e.y)}}function ga({shape:t,opacity:e=1}){const n=t.strokeWidth??Li;let r;if(t.type==="rectangle")r=l.jsx("rect",{x:t.x,y:t.y,width:t.width,height:t.height,fill:t.fillColor??"none",stroke:t.color,strokeWidth:n,opacity:e});else if(t.type==="ellipse")r=l.jsx("ellipse",{cx:t.x+t.width/2,cy:t.y+t.height/2,rx:t.width/2,ry:t.height/2,fill:t.fillColor??"none",stroke:t.color,strokeWidth:n,opacity:e});else if(t.type==="arrow"){const a=Math.max(16,n*3),i=Mi(t.x1,t.y1,t.x2,t.y2,a);return l.jsxs("g",{opacity:e,children:[l.jsx("line",{x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,stroke:t.color,strokeWidth:n}),l.jsx("polygon",{points:i.map(([d,c])=>`${d},${c}`).join(" "),fill:t.color})]})}else if(t.type==="text")r=l.jsx("foreignObject",{x:t.x,y:t.y,width:t.width,height:t.height,opacity:e,children:l.jsx("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{width:"100%",height:"100%",overflow:"hidden",color:t.color,fontSize:t.fontSize??so,lineHeight:1.3,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"inherit"},children:t.text})});else{const a=Ai[t.type];if(!a)return null;const i={x:t.x,y:t.y,width:t.width,height:t.height},d=a(i).map(([c,f])=>`${c},${f}`).join(" ");r=l.jsx("polygon",{points:d,fill:t.fillColor??"none",stroke:t.color,strokeWidth:n,opacity:e})}if(!t.rotation)return r;const{cx:o,cy:s}=Tr(t);return l.jsx("g",{transform:`rotate(${t.rotation} ${o} ${s})`,children:r})}function Jh({id:t}){const e=G(),n=be(t),r=Ie("be-canvas",n),o=Hh(),[s,a]=p.useState("pen"),[i,d]=p.useState("object"),[c,f]=p.useState(aa),[u,h]=p.useState(Li),[m,g]=p.useState(null),[x,y]=p.useState(!0),[k,v]=p.useState(so),[w,B]=p.useState("rectangle"),[I,C]=p.useState(!1),[R,E]=p.useState(!1),[T,O]=p.useState(!1),[S,L]=p.useState(!1),[$,Y]=p.useState(!1),[K,Q]=p.useState(!1),D=p.useRef(null),F=p.useRef(null),re=p.useRef(null),H=p.useRef(null),ne=p.useRef(null),se=p.useRef(null),oe=p.useRef(null),ge=p.useRef(null),Re=p.useRef(null),ce=p.useRef(null),ke=p.useRef(null),he=p.useRef(null),U=p.useMemo(()=>[D,F],[]),ae=p.useMemo(()=>[re,H],[]),We=p.useMemo(()=>[ne,se],[]),Pn=p.useMemo(()=>[oe,ge],[]),Br=p.useMemo(()=>[Re,ce],[]),zc=p.useMemo(()=>[ke,he],[]),ds=p.useCallback(()=>C(!1),[]),_r=p.useCallback(()=>E(!1),[]),Hc=p.useCallback(()=>O(!1),[]),us=p.useCallback(()=>L(!1),[]),Fc=p.useCallback(()=>Y(!1),[]),ps=p.useCallback(()=>Q(!1),[]);Ve(U,I,ds),Ve(ae,R,_r),Ve(We,T,Hc),Ve(Pn,S,us),Ve(Br,$,Fc),Ve(zc,K,ps);const qe=p.useRef(null),fn=p.useRef([]),Ot=p.useRef(!1),Lt=p.useRef(null),[fs,hs]=p.useState(null),bt=p.useRef(new Set),St=p.useRef(new Set),At=p.useRef(new Map),Dt=p.useRef(!1),Pt=p.useRef(null),[Uc,ms]=p.useState(()=>new Set),[Vc,bs]=p.useState(()=>new Set),He=p.useRef(null),[gs,Nr]=p.useState(null),[le,rt]=p.useState(()=>new Set),gt=p.useRef(null),[we,xs]=p.useState(null),xt=p.useRef(null),[hn,ys]=p.useState(null),Mr=p.useRef([]),[pe,$t]=p.useState(null),Fe=p.useRef(null),[yt,Or]=p.useState(null),[ue,jt]=p.useState({x:0,y:0,zoom:1}),Ne=Tt/ue.zoom,Rt=p.useRef(null),Ue=p.useRef(new Map),kt=p.useRef(null),{dragValue:zt,startDrag:ks}=Sh({compute:(b,j)=>({width:Math.max(ia,Math.round(j.startWidth+(b.clientX-j.startX))),height:Math.max(Mh,Math.round(j.startHeight+(b.clientY-j.startY)))}),onCommit:b=>e.applyOperation(J(t,b))}),vs=p.useCallback(b=>{Lt.current==null&&(Lt.current=requestAnimationFrame(()=>{Lt.current=null,hs(cr(fn.current,{size:b}))}))},[]),Ht=p.useCallback(()=>{Ot.current=!1,Lt.current!=null&&(cancelAnimationFrame(Lt.current),Lt.current=null),fn.current=[],hs(null)},[]),ws=p.useCallback(()=>{var M;const b=fn.current;if(b.length===0)return;const j={id:_(),points:b,color:c,size:u},N=((M=n==null?void 0:n.props)==null?void 0:M.strokes)??[];e.applyOperation(J(t,{strokes:[...N,j]}))},[e,t,n,c,u]),Is=p.useCallback(()=>{Pt.current==null&&(Pt.current=requestAnimationFrame(()=>{Pt.current=null,ms(new Set(bt.current)),bs(new Set(St.current))}))},[]),$n=p.useCallback((b,j)=>{var X,W;const N=i==="precise"?Nh:_h,M=Fh(b,j,N),P=((X=n==null?void 0:n.props)==null?void 0:X.strokes)??[];for(const z of P){if(i==="precise"){const ot=rr(z.points);if(!gn(ot,M,z.size/2))continue;let Ce=At.current.get(z.id);z.points.forEach(([Te,Se],fe)=>{Ce!=null&&Ce.has(fe)||Math.hypot(Te-b,Se-j)>N||(Ce||(Ce=new Set,At.current.set(z.id,Ce)),Ce.add(fe))}),Ce!=null&&Ce.size&&bt.current.add(z.id);continue}if(bt.current.has(z.id))continue;const q=z.size/2,ie=rr(z.points);gn(ie,M,q)&&Uh(z,b,j,N+q)&&bt.current.add(z.id)}const A=((W=n==null?void 0:n.props)==null?void 0:W.shapes)??[];for(const z of A){if(St.current.has(z.id))continue;const q=En(z),ie={minX:q.x,minY:q.y,maxX:q.x+q.width,maxY:q.y+q.height};gn(ie,M)&&St.current.add(z.id)}Is()},[n,i,Is]),Ft=p.useCallback(()=>{Dt.current=!1,Pt.current!=null&&(cancelAnimationFrame(Pt.current),Pt.current=null),bt.current=new Set,St.current=new Set,At.current=new Map,ms(new Set),bs(new Set)},[]),Cs=p.useCallback(()=>{var A,X;const b=i!=="precise"&&bt.current.size>0,j=i==="precise"&&At.current.size>0;if(!b&&!j&&St.current.size===0)return;const N=((A=n==null?void 0:n.props)==null?void 0:A.strokes)??[],M=((X=n==null?void 0:n.props)==null?void 0:X.shapes)??[];let P;if(b)P=N.filter(W=>!bt.current.has(W.id));else if(j){P=[];for(const W of N){const z=At.current.get(W.id);if(!z||z.size===0){P.push(W);continue}Yh(W.points,z).forEach((q,ie)=>{P.push({...W,id:ie===0?W.id:_(),points:q})})}}else P=N;e.applyOperation(J(t,{strokes:P,shapes:M.filter(W=>!St.current.has(W.id))}))},[e,t,n,i]),Ut=p.useCallback(()=>{He.current=null,Nr(null)},[]),Ss=p.useCallback(()=>{var M;const b=He.current;if(!b)return;if(b.type==="arrow"){if(b.x1===b.x2&&b.y1===b.y2)return}else{const P=wn(b.x1,b.y1,b.x2,b.y2);if(P.width===0||P.height===0)return}const j={id:_(),...Jr(b,c,u,m)},N=((M=n==null?void 0:n.props)==null?void 0:M.shapes)??[];e.applyOperation(J(t,{shapes:[...N,j]}))},[e,t,n,c,u,m]),Vt=p.useCallback(()=>{gt.current=null,xs(null)},[]),js=p.useCallback(()=>{var X,W;const b=gt.current;if(!b||b.dx===0&&b.dy===0)return;const j=new Set(b.ids),N=((X=n==null?void 0:n.props)==null?void 0:X.strokes)??[],M=((W=n==null?void 0:n.props)==null?void 0:W.shapes)??[],P=N.map(z=>j.has(z.id)?yn(z,b.dx,b.dy):z),A=M.map(z=>j.has(z.id)?xn(z,b.dx,b.dy):z);e.applyOperation(J(t,{strokes:P,shapes:A}))},[e,t,n]),Yt=p.useCallback(()=>{xt.current=null,ys(null)},[]),Rs=p.useCallback(()=>{var X,W;const b=xt.current;if(!b)return;const j=wn(b.startX,b.startY,b.x,b.y);if(j.width<ca&&j.height<ca){rt(new Set);return}const N={minX:j.x,minY:j.y,maxX:j.x+j.width,maxY:j.y+j.height},M=((X=n==null?void 0:n.props)==null?void 0:X.strokes)??[],P=((W=n==null?void 0:n.props)==null?void 0:W.shapes)??[],A=[];for(const z of M)gn(rr(z.points),N)&&A.push(z.id);for(const z of P){const q=En(z),ie={minX:q.x,minY:q.y,maxX:q.x+q.width,maxY:q.y+q.height};gn(ie,N)&&A.push(z.id)}rt(new Set(A))},[n]),Lr=p.useCallback(()=>{le.size!==0&&(Mr.current=[...le].map(b=>ba(n,b)).filter(Boolean))},[n,le]),Ar=p.useCallback(()=>{var X,W;const b=Mr.current;if(b.length===0)return;const j=((X=n==null?void 0:n.props)==null?void 0:X.strokes)??[],N=((W=n==null?void 0:n.props)==null?void 0:W.shapes)??[],M=[],P=[],A=[];for(const{kind:z,item:q}of b){const ie=_();A.push(ie),z==="stroke"?M.push({...yn(q,Qn,Qn),id:ie}):P.push({...xn(q,Qn,Qn),id:ie})}e.applyOperation(J(t,{strokes:[...j,...M],shapes:[...N,...P]})),rt(new Set(A)),a("select")},[e,t,n]),Kt=p.useCallback(b=>{var P,A;if(le.size===0)return;const j=X=>{const W=X.filter(q=>le.has(q.id));if(W.length===0)return X;const z=X.filter(q=>!le.has(q.id));return b?[...z,...W]:[...W,...z]},N=((P=n==null?void 0:n.props)==null?void 0:P.strokes)??[],M=((A=n==null?void 0:n.props)==null?void 0:A.shapes)??[];e.applyOperation(J(t,{strokes:j(N),shapes:j(M)}))},[e,t,n,le]),Yc=p.useCallback(()=>Kt(!0),[Kt]),Kc=p.useCallback(()=>Kt(!1),[Kt]),Dr=p.useCallback((b,j)=>{$t({id:null,x:b,y:j,width:Ah,height:Dh,text:"",color:c,fontSize:k})},[c,k]),zn=p.useCallback(b=>{$t({id:b.id,x:b.x,y:b.y,width:b.width,height:b.height,text:b.text,color:b.color,fontSize:b.fontSize??so})},[]),Wc=p.useCallback(()=>{$t(null)},[]),qc=p.useCallback(()=>{var X,W,z;const b=pe;if(!b)return;$t(null);const j=((X=n==null?void 0:n.props)==null?void 0:X.shapes)??[],N=b.text;if(!N.trim()){b.id&&(e.applyOperation(J(t,{shapes:j.filter(q=>q.id!==b.id)})),rt(new Set)),(W=qe.current)==null||W.focus();return}const M=b.id??_(),P={id:M,type:"text",x:b.x,y:b.y,width:b.width,height:b.height,text:N,color:b.color,fontSize:b.fontSize},A=b.id?j.map(q=>q.id===b.id?P:q):[...j,P];e.applyOperation(J(t,{shapes:A})),rt(new Set([M])),a("select"),(z=qe.current)==null||z.focus()},[e,t,n,pe]),Wt=p.useCallback(()=>{Fe.current=null,Or(null)},[]),Ts=p.useCallback(()=>{var A;const b=Fe.current;if(!b)return;const j=((A=n==null?void 0:n.props)==null?void 0:A.shapes)??[],N=j.find(X=>X.id===b.shapeId);if(!N)return;const M=Zr(N,b);if(M.type!=="arrow"&&(M.width===0||M.height===0))return;const P=j.map(X=>X.id===b.shapeId?M:X);e.applyOperation(J(t,{shapes:P}))},[e,t,n]),Es=p.useCallback(b=>{var N;const j=qe.current;if((N=j==null?void 0:j.hasPointerCapture)!=null&&N.call(j,b)&&j.releasePointerCapture(b),He.current){Ut();return}if(gt.current){Vt();return}if(xt.current){Yt();return}if(Fe.current){Wt();return}if(Ot.current){Ht();return}Dt.current&&Ft()},[Ut,Vt,Yt,Wt,Ht,Ft]),Xc=p.useCallback(b=>{var M,P,A,X,W;if(b.key==="Backspace"||b.key==="Delete"){if(le.size===0)return;b.preventDefault();const z=((M=n==null?void 0:n.props)==null?void 0:M.strokes)??[],q=((P=n==null?void 0:n.props)==null?void 0:P.shapes)??[];e.applyOperation(J(t,{strokes:z.filter(ie=>!le.has(ie.id)),shapes:q.filter(ie=>!le.has(ie.id))})),rt(new Set);return}if(da[b.key]&&!b.ctrlKey&&!b.metaKey){if(le.size===0)return;b.preventDefault();const z=b.shiftKey?Lh:Oh,[q,ie]=da[b.key],ot=q*z,Ce=ie*z,Te=((A=n==null?void 0:n.props)==null?void 0:A.strokes)??[],Se=((X=n==null?void 0:n.props)==null?void 0:X.shapes)??[];e.applyOperation(J(t,{strokes:Te.map(fe=>le.has(fe.id)?yn(fe,ot,Ce):fe),shapes:Se.map(fe=>le.has(fe.id)?xn(fe,ot,Ce):fe)}));return}if(b.key==="Enter"&&!b.ctrlKey&&!b.metaKey){if(le.size!==1)return;const[z]=le,q=(((W=n==null?void 0:n.props)==null?void 0:W.shapes)??[]).find(ie=>ie.id===z&&ie.type==="text");if(!q)return;b.preventDefault(),zn(q);return}if(!(b.ctrlKey||b.metaKey))return;const N=b.key.toLowerCase();if(N==="c"){if(le.size===0)return;b.preventDefault(),Lr()}else if(N==="v"){if(Mr.current.length===0)return;b.preventDefault(),Ar()}else if(N==="d"){if(le.size===0)return;b.preventDefault(),Lr(),Ar()}else if(b.shiftKey&&(N==="]"||N==="[")){if(le.size===0)return;b.preventDefault(),Kt(N==="]")}},[e,t,n,le,Lr,Ar,Kt,zn]),vt={x:ue.x,y:ue.y,size:Ne},Pr=p.useCallback(b=>{const j=qe.current;if(!j)return;if(b.preventDefault(),b.ctrlKey||b.metaKey){jt(M=>{const P=b.deltaY<0?Zn:1/Zn,A=Math.min(Xr,Math.max(qr,M.zoom*P)),X=Tt/A,{x:W,y:z}=vh(b,j,{x:M.x,y:M.y,size:Tt/M.zoom},X);return{x:W,y:z,zoom:A}});return}const N=Wr(j,Ne);jt(M=>({...M,x:M.x+b.deltaX/N,y:M.y+b.deltaY/N}))},[Ne]);p.useEffect(()=>{const b=qe.current;if(b)return b.addEventListener("wheel",Pr,{passive:!1}),()=>b.removeEventListener("wheel",Pr)},[Pr]);const Gc=p.useCallback(()=>{jt(b=>{const j=Math.min(Xr,b.zoom*Zn),N=Tt/j,{x:M,y:P}=sa({x:b.x,y:b.y,size:Tt/b.zoom},N);return{x:M,y:P,zoom:j}})},[]),Jc=p.useCallback(()=>{jt(b=>{const j=Math.max(qr,b.zoom/Zn),N=Tt/j,{x:M,y:P}=sa({x:b.x,y:b.y,size:Tt/b.zoom},N);return{x:M,y:P,zoom:j}})},[]),Zc=p.useCallback(()=>{jt({x:0,y:0,zoom:1})},[]),Qc=p.useCallback(()=>{if(!n)return;const b=Oi(n),j=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(b)}`,N=new Image;N.onload=()=>{const M=document.createElement("canvas");M.width=n.props.width,M.height=n.props.height;const P=M.getContext("2d");if(!P)return;P.drawImage(N,0,0,M.width,M.height);const A=document.createElement("a");A.href=M.toDataURL("image/png"),A.download="canvas.png",document.body.appendChild(A),A.click(),document.body.removeChild(A)},N.src=j},[n]),ed=p.useCallback(b=>{var W;if(s!=="select")return;const j=qe.current;if(!j)return;const[N,M]=Ge(b,j,{x:ue.x,y:ue.y,size:Ne}),P=((W=n==null?void 0:n.props)==null?void 0:W.shapes)??[],A=Di(N,M,P),X=P.find(z=>z.id===A);(X==null?void 0:X.type)==="text"&&(rt(new Set([X.id])),zn(X))},[s,ue.x,ue.y,Ne,n,zn]),td=p.useCallback(b=>{var P,A,X,W,z,q,ie,ot,Ce;const j=qe.current;if(!j)return;if(b.pointerType==="touch"&&(Ue.current.set(b.pointerId,{x:b.clientX,y:b.clientY}),Ue.current.size>=2)){if(b.preventDefault(),(P=j.setPointerCapture)==null||P.call(j,b.pointerId),!kt.current){for(const Se of Ue.current.keys())Se!==b.pointerId&&Es(Se);const Te=fa(Ue.current);kt.current={startCenterX:Te.x,startCenterY:Te.y,startViewX:ue.x,startViewY:ue.y}}return}if(pe){if((X=(A=b.target)==null?void 0:A.closest)!=null&&X.call(A,".be-canvas-text-editor"))return;if((z=(W=document.activeElement)==null?void 0:W.blur)==null||z.call(W),s==="text"){let[Te,Se]=Ge(b,j,vt);x&&([Te,Se]=[Ae(Te),Ae(Se)]),Dr(Te,Se),a("text");return}}if(b.button===1){b.preventDefault(),(q=j.setPointerCapture)==null||q.call(j,b.pointerId),Rt.current={startClientX:b.clientX,startClientY:b.clientY,startViewX:ue.x,startViewY:ue.y};return}if(!b.isPrimary||b.button!==void 0&&b.button!==0)return;b.preventDefault(),(ie=j.setPointerCapture)==null||ie.call(j,b.pointerId);const[N,M]=Ge(b,j,vt);if(s==="eraser")bt.current=new Set,St.current=new Set,At.current=new Map,Dt.current=!0,$n(N,M);else if(Gr.has(s)){const Te=x?Ae(N):N,Se=x?Ae(M):M;He.current={type:s,x1:Te,y1:Se,x2:Te,y2:Se},Nr(Jr(He.current,c,u,m))}else if(s==="select"){const Te=((ot=n==null?void 0:n.props)==null?void 0:ot.strokes)??[],Se=((Ce=n==null?void 0:n.props)==null?void 0:Ce.shapes)??[],fe=le.size===1?Se.find(st=>le.has(st.id))??null:null,Un=Gh(N,M,fe);if(Un){if(Un==="rotate"){const{cx:st,cy:Xt}=Tr(fe),Gt=Math.atan2(M-Xt,N-st)*180/Math.PI;Fe.current={mode:"rotate",shapeId:fe.id,cx:st,cy:Xt,startAngle:Gt,startRotation:fe.rotation??0,rotation:fe.rotation??0}}else if(fe.type==="arrow")Fe.current={mode:"arrow-endpoint",shapeId:fe.id,endpoint:Un,x:N,y:M};else{const[st,Xt]=lo(fe)[qh[Un]];Fe.current={mode:"rect-corner",shapeId:fe.id,fixedX:st,fixedY:Xt,x:N,y:M}}Or(Zr(fe,Fe.current));return}const qt=Wh(N,M,Te,Se);if(qt){if(b.shiftKey){rt(Xt=>{const Gt=new Set(Xt);return Gt.has(qt.id)?Gt.delete(qt.id):Gt.add(qt.id),Gt});return}const st=le.has(qt.id)?le:new Set([qt.id]);rt(st),gt.current={ids:[...st],startX:N,startY:M,dx:0,dy:0},j.focus()}else xt.current={startX:N,startY:M,x:N,y:M}}else s==="text"?Dr(x?Ae(N):N,x?Ae(M):M):s==="pen"&&(fn.current=[[N,M,b.pressure||.5]],Ot.current=!0)},[s,$n,ue.x,ue.y,Ne,c,u,m,x,n,le,Dr,pe,Es]),nd=p.useCallback(b=>{var N;const j=qe.current;if(j){if(b.pointerType==="touch"&&Ue.current.has(b.pointerId)&&(Ue.current.set(b.pointerId,{x:b.clientX,y:b.clientY}),kt.current)){b.preventDefault();const M=Wr(j,Ne),P=fa(Ue.current),{startCenterX:A,startCenterY:X,startViewX:W,startViewY:z}=kt.current,q=(P.x-A)/M,ie=(P.y-X)/M;jt(ot=>({...ot,x:W-q,y:z-ie}));return}if(Rt.current){const M=Wr(j,Ne),{startClientX:P,startClientY:A,startViewX:X,startViewY:W}=Rt.current,z=(b.clientX-P)/M,q=(b.clientY-A)/M;jt(ie=>({...ie,x:X-z,y:W-q}));return}if(He.current){let[M,P]=Ge(b,j,vt);x&&([M,P]=[Ae(M),Ae(P)]),He.current={...He.current,x2:M,y2:P},Nr(Jr(He.current,c,u,m));return}if(gt.current){const[M,P]=Ge(b,j,vt),A=gt.current;A.dx=x?Ae(M-A.startX):M-A.startX,A.dy=x?Ae(P-A.startY):P-A.startY,xs({ids:A.ids,dx:A.dx,dy:A.dy});return}if(xt.current){const[M,P]=Ge(b,j,vt),A=xt.current;A.x=M,A.y=P,ys(wn(A.startX,A.startY,A.x,A.y));return}if(Fe.current){let[M,P]=Ge(b,j,vt);const A=Fe.current;if(A.mode==="rotate"){const z=Math.atan2(P-A.cy,M-A.cx)*180/Math.PI,q=A.startRotation+(z-A.startAngle);A.rotation=x?zh(q):q}else x&&([M,P]=[Ae(M),Ae(P)]),A.x=M,A.y=P;const W=(((N=n==null?void 0:n.props)==null?void 0:N.shapes)??[]).find(z=>z.id===A.shapeId);W&&Or(Zr(W,A));return}if(Ot.current){const[M,P]=Ge(b,j,vt);fn.current.push([M,P,b.pressure||.5]),vs(u)}else if(Dt.current){const[M,P]=Ge(b,j,vt);$n(M,P)}}},[vs,$n,ue.x,ue.y,Ne,u,c,m,x,n]),ve=p.useCallback(b=>{var N;const j=qe.current;(N=j==null?void 0:j.hasPointerCapture)!=null&&N.call(j,b.pointerId)&&j.releasePointerCapture(b.pointerId)},[]),rd=p.useCallback(b=>{if(b.pointerType==="touch"&&(Ue.current.delete(b.pointerId),kt.current)){ve(b),Ue.current.size<2&&(kt.current=null);return}if(Rt.current){ve(b),Rt.current=null;return}if(He.current){ve(b),Ss(),Ut();return}if(gt.current){ve(b),js(),Vt();return}if(xt.current){ve(b),Rs(),Yt();return}if(Fe.current){ve(b),Ts(),Wt();return}Ot.current?(ve(b),ws(),Ht()):Dt.current&&(ve(b),Cs(),Ft())},[ve,Ss,Ut,js,Vt,Rs,Yt,Ts,Wt,ws,Ht,Cs,Ft]),od=p.useCallback(b=>{if(b.pointerType==="touch"&&(Ue.current.delete(b.pointerId),kt.current)){ve(b),Ue.current.size<2&&(kt.current=null);return}if(Rt.current){ve(b),Rt.current=null;return}if(He.current){ve(b),Ut();return}if(gt.current){ve(b),Vt();return}if(xt.current){ve(b),Yt();return}if(Fe.current){ve(b),Wt();return}Ot.current?(ve(b),Ht()):Dt.current&&(ve(b),Ft())},[ve,Ut,Vt,Yt,Wt,Ht,Ft]),sd=p.useCallback(b=>{var j,N;ks(b,{startX:b.clientX,startY:b.clientY,startWidth:((j=n==null?void 0:n.props)==null?void 0:j.width)??Jo,startHeight:((N=n==null?void 0:n.props)==null?void 0:N.height)??Zo})},[ks,n]);if(!n)return null;const{strokes:Bs=[],shapes:_s=[],width:ad,height:ld}=n.props,Ns=(zt==null?void 0:zt.width)??ad,id=(zt==null?void 0:zt.height)??ld,Hn=6,Fn=[...le].map(b=>{var P;const j=ba(n,b);if(!j)return null;let{kind:N,item:M}=j;return(P=we==null?void 0:we.ids)!=null&&P.includes(b)?M=N==="stroke"?yn(M,we.dx,we.dy):xn(M,we.dx,we.dy):N==="shape"&&(yt==null?void 0:yt.id)===b&&(M=yt),{id:b,kind:N,item:M,box:Kh(N,M),rotation:N==="shape"?M.rotation:0}}).filter(Boolean),$r=Fn.length===1&&Fn[0].kind==="shape"?Fn[0]:null,Le=($r==null?void 0:$r.item)??null,cd=Le&&Le.type==="arrow"?[["start",Le.x1,Le.y1],["end",Le.x2,Le.y2]]:Le&&!Le.rotation?Object.entries(lo(Le)).map(([b,[j,N]])=>[b,j,N]):[],zr=Le&&Le.type!=="arrow"?$i(Le):null;return l.jsxs("div",{className:r,"data-block-id":t,"data-tool":s,contentEditable:!1,tabIndex:-1,children:[l.jsxs("div",{className:"be-canvas-toolbar",contentEditable:!1,children:[l.jsx("button",{type:"button",className:`be-canvas-toolbar-btn${s==="pen"?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s==="pen","aria-label":"Pen",title:"Pen",onClick:()=>a("pen"),children:l.jsx(qa,{size:14})}),l.jsxs("div",{className:"be-canvas-picker-wrap",children:[l.jsx("button",{ref:ke,type:"button",className:`be-canvas-toolbar-btn${s==="eraser"?" be-canvas-toolbar-btn-active":""}`,"aria-haspopup":"true","aria-expanded":K,"aria-pressed":s==="eraser","aria-label":"Eraser",title:"Eraser",onClick:()=>Q(b=>!b),children:(()=>{var j;const b=((j=ma.find(N=>N.mode===i))==null?void 0:j.Icon)??el;return l.jsx(b,{size:14})})()}),K&&l.jsx("div",{ref:he,className:"be-canvas-picker be-canvas-shape-picker",role:"menu","aria-label":"Eraser",children:ma.map(({mode:b,label:j,Icon:N})=>l.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-btn${s==="eraser"&&i===b?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s==="eraser"&&i===b,"aria-label":j,title:j,onClick:()=>{a("eraser"),d(b),ps()},children:l.jsx(N,{size:14})},b))})]}),l.jsx("button",{type:"button",className:`be-canvas-toolbar-btn${s==="select"?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s==="select","aria-label":"Select",title:"Select",onClick:()=>a("select"),children:l.jsx(fu,{size:14})}),l.jsx("button",{type:"button",className:`be-canvas-toolbar-btn${s==="text"?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s==="text","aria-label":"Text",title:"Text",onClick:()=>a("text"),children:l.jsx(Eo,{size:14})}),l.jsxs("div",{className:"be-canvas-picker-wrap",children:[l.jsx("button",{ref:Re,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":$,"aria-label":`Font size: ${pe?pe.fontSize:k}`,title:"Font size",onClick:()=>Y(b=>!b),children:l.jsx("span",{className:"be-canvas-font-size-trigger",children:"A"})}),$&&l.jsxs("div",{ref:ce,className:"be-canvas-picker be-canvas-size-picker",role:"dialog","aria-label":"Font size",children:[l.jsx("span",{className:"be-canvas-size-preview","aria-hidden":"true",children:l.jsx("span",{className:"be-canvas-font-size-preview-letter",style:{fontSize:pe?pe.fontSize:k},children:"A"})}),l.jsx("input",{type:"range",className:"be-canvas-size-slider",min:Ph,max:$h,value:pe?pe.fontSize:k,onChange:b=>{const j=Number(b.target.value);v(j),pe&&$t(N=>N&&{...N,fontSize:j})},"aria-label":"Font size"}),l.jsxs("span",{className:"be-canvas-size-value",children:[pe?pe.fontSize:k,"px"]})]})]}),l.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Bring to front",title:"Bring to front",onClick:Yc,disabled:le.size===0,children:l.jsx(br,{size:14})}),l.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Send to back",title:"Send to back",onClick:Kc,disabled:le.size===0,children:l.jsx(gr,{size:14})}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsxs("div",{className:"be-canvas-picker-wrap",children:[l.jsx("button",{ref:oe,type:"button",className:`be-canvas-toolbar-btn${Gr.has(s)?" be-canvas-toolbar-btn-active":""}`,"aria-haspopup":"true","aria-expanded":S,"aria-label":"Shape",title:"Shape",onClick:()=>L(b=>!b),children:(()=>{var j;const b=((j=ha.find(N=>N.type===(Gr.has(s)?s:w)))==null?void 0:j.Icon)??Qa;return l.jsx(b,{size:14})})()}),S&&l.jsx("div",{ref:ge,className:"be-canvas-picker be-canvas-shape-picker",role:"menu","aria-label":"Shape",children:ha.map(({type:b,label:j,Icon:N})=>l.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-btn${s===b?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":s===b,"aria-label":j,title:j,onClick:()=>{a(b),B(b),us()},children:l.jsx(N,{size:14})},b))})]}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsxs("div",{className:"be-canvas-picker-wrap",children:[l.jsx("button",{ref:D,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":I,"aria-label":`Color: ${c}`,title:"Color",onClick:()=>C(b=>!b),children:l.jsx("span",{className:"be-canvas-color-trigger-dot",style:{backgroundColor:c}})}),I&&l.jsxs("div",{ref:F,className:"be-canvas-picker be-canvas-color-picker",role:"menu","aria-label":"Pen color",children:[la.map(b=>l.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-swatch${c===b?" be-canvas-toolbar-swatch-active":""}`,style:{backgroundColor:b},"aria-pressed":c===b,"aria-label":`Color ${b}`,title:`Color ${b}`,onClick:()=>{f(b),ds()}},b)),l.jsx("label",{className:"be-canvas-custom-swatch",title:"Custom color","aria-label":"Custom color",children:l.jsx("input",{type:"color",value:c,onChange:b=>f(b.target.value)})})]})]}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsxs("div",{className:"be-canvas-picker-wrap",children:[l.jsx("button",{ref:re,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":R,"aria-label":`Fill: ${m??"none"}`,title:"Fill",onClick:()=>E(b=>!b),children:l.jsx("span",{className:`be-canvas-fill-trigger-dot${m?"":" be-canvas-fill-trigger-dot-none"}`,style:m?{backgroundColor:m}:void 0})}),R&&l.jsxs("div",{ref:H,className:"be-canvas-picker be-canvas-color-picker",role:"menu","aria-label":"Shape fill",children:[l.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-swatch be-canvas-fill-swatch-none${m===null?" be-canvas-toolbar-swatch-active":""}`,"aria-pressed":m===null,"aria-label":"No fill",title:"No fill",onClick:()=>{g(null),_r()}}),la.map(b=>l.jsx("button",{type:"button",role:"menuitem",className:`be-canvas-toolbar-swatch${m===b?" be-canvas-toolbar-swatch-active":""}`,style:{backgroundColor:b},"aria-pressed":m===b,"aria-label":`Fill ${b}`,title:`Fill ${b}`,onClick:()=>{g(b),_r()}},b)),l.jsx("label",{className:"be-canvas-custom-swatch",title:"Custom fill","aria-label":"Custom fill",children:l.jsx("input",{type:"color",value:m??aa,onChange:b=>g(b.target.value)})})]})]}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsxs("div",{className:"be-canvas-picker-wrap",children:[l.jsx("button",{ref:ne,type:"button",className:"be-canvas-toolbar-btn","aria-haspopup":"true","aria-expanded":T,"aria-label":`Stroke size: ${u}`,title:"Stroke size",onClick:()=>O(b=>!b),children:l.jsx("span",{className:"be-canvas-size-trigger-dot",style:{width:Math.min(u,16),height:Math.min(u,16)}})}),T&&l.jsxs("div",{ref:se,className:"be-canvas-picker be-canvas-size-picker",role:"dialog","aria-label":"Stroke size",children:[l.jsx("span",{className:"be-canvas-size-preview","aria-hidden":"true",children:l.jsx("span",{className:"be-canvas-size-preview-dot",style:{width:u,height:u}})}),l.jsx("input",{type:"range",className:"be-canvas-size-slider",min:Eh,max:Bh,value:u,onChange:b=>h(Number(b.target.value)),"aria-label":"Stroke size"}),l.jsxs("span",{className:"be-canvas-size-value",children:[u,"px"]})]})]}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsx("button",{type:"button",className:`be-canvas-toolbar-btn${x?" be-canvas-toolbar-btn-active":""}`,"aria-pressed":x,"aria-label":"Snap to grid",title:x?"Snap to grid: ON — drawing, moving, resizing and rotating align to the dotted grid. Click to turn off.":"Snap to grid: OFF — click to turn on (aligns drawing, moving, resizing and rotating to a grid)",onClick:()=>y(b=>!b),children:l.jsx(mu,{size:14})}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Zoom out",title:"Zoom out",onClick:Jc,disabled:ue.zoom<=qr,children:"−"}),l.jsxs("button",{type:"button",className:"be-canvas-zoom-label","aria-label":`Zoom: ${Math.round(ue.zoom*100)}%. Click to reset to 100%.`,title:"Reset zoom to 100%",onClick:Zc,children:[Math.round(ue.zoom*100),"%"]}),l.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Zoom in",title:"Zoom in",onClick:Gc,disabled:ue.zoom>=Xr,children:"+"}),l.jsx("span",{className:"be-canvas-toolbar-divider"}),l.jsx("button",{type:"button",className:"be-canvas-toolbar-btn","aria-label":"Export PNG",title:"Export as PNG",onClick:Qc,disabled:Bs.length===0&&_s.length===0,children:l.jsx(hu,{size:14})})]}),l.jsxs("svg",{ref:qe,className:"be-canvas-surface",viewBox:`${ue.x} ${ue.y} ${Ne} ${Ne}`,width:Ns,height:id,tabIndex:-1,onPointerDown:td,onPointerMove:nd,onPointerUp:rd,onPointerCancel:od,onDoubleClick:ed,onKeyDown:Xc,children:[x&&l.jsxs(l.Fragment,{children:[l.jsx("defs",{children:l.jsx("pattern",{id:`be-canvas-grid-${t}`,width:pa,height:pa,patternUnits:"userSpaceOnUse",children:l.jsx("circle",{cx:1,cy:1,r:1.5,className:"be-canvas-grid-dot"})})}),l.jsx("rect",{className:"be-canvas-grid-background",x:ue.x,y:ue.y,width:Ne,height:Ne,fill:`url(#be-canvas-grid-${t})`})]}),Bs.map(b=>{var M;const N=((M=we==null?void 0:we.ids)==null?void 0:M.includes(b.id))?cr(yn(b,we.dx,we.dy).points,{size:b.size}):o(b);return l.jsx("path",{d:N,fill:b.color,fillRule:"nonzero",opacity:Uc.has(b.id)?.25:1},b.id)}),fs&&l.jsx("path",{d:fs,fill:c,fillRule:"nonzero"}),_s.map(b=>{var N;let j=b;return(N=we==null?void 0:we.ids)!=null&&N.includes(b.id)?j=xn(b,we.dx,we.dy):(yt==null?void 0:yt.id)===b.id&&(j=yt),l.jsx(ga,{shape:j,opacity:Vc.has(b.id)?.25:1},b.id)}),gs&&l.jsx(ga,{shape:gs,opacity:.6}),Fn.map(({id:b,box:j,rotation:N})=>l.jsx("g",{transform:N?`rotate(${N} ${j.x+j.width/2} ${j.y+j.height/2})`:void 0,children:l.jsx("rect",{className:"be-canvas-selection-box",x:j.x-Hn,y:j.y-Hn,width:j.width+Hn*2,height:j.height+Hn*2,fill:"none"})},b)),cd.map(([b,j,N])=>l.jsx("rect",{className:"be-canvas-selection-handle",x:j-kn/2,y:N-kn/2,width:kn,height:kn},b)),zr&&l.jsx("circle",{className:"be-canvas-rotate-handle",cx:zr[0],cy:zr[1],r:kn/2}),hn&&l.jsx("rect",{className:"be-canvas-marquee",x:hn.x,y:hn.y,width:hn.width,height:hn.height}),pe&&l.jsx("foreignObject",{x:pe.x,y:pe.y,width:pe.width,height:pe.height,children:l.jsx("textarea",{xmlns:"http://www.w3.org/1999/xhtml",ref:b=>b==null?void 0:b.focus(),className:"be-canvas-text-editor",value:pe.text,style:{color:pe.color,fontSize:pe.fontSize},onChange:b=>$t(j=>j&&{...j,text:b.target.value}),onBlur:()=>qc(),onKeyDown:b=>{b.key==="Escape"&&(b.preventDefault(),Wc()),b.stopPropagation()}})})]}),l.jsx("div",{className:"be-canvas-resize-handle",onMouseDown:sd,role:"slider","aria-label":"Resize canvas","aria-valuemin":ia,"aria-valuenow":Ns,contentEditable:!1})]})}function Zh(t){const{strokes:e=[],shapes:n=[]}=t.props;return!e.length&&!n.length?"<p></p>":Oi(t)}function Qh(){return""}function em(){return null}function tm(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o}){const s=t.getRun(n),a=(s==null?void 0:s.value)??"";t.applyOperation(de(n,{value:a.slice(0,r)+a.slice(o)}));const i=vr(t,e,jh());return nt(t,i,te("paragraph")),i}const zi={component:Jh,isLeaf:!0,defaultProps:{strokes:[],shapes:[],width:Jo,height:Zo},toHTML:Zh,toPlainText:Qh,fromHTML:em,slashCommand:{label:"Canvas",icon:eu,keywords:["canvas","draw","drawing","sketch","freehand"],run:tm}};function Hi(t){Fi(t,{paragraph:Nl,heading:Ml,listItem:Fl,...Ui,...Vi,divider:ci,callout:ui,blockquote:pi,code:hi,toggleHeading:mi,button:gi,embed:vi,canvas:zi})}function Fi(t,e){for(const[n,r]of Object.entries(e))t.register(n,r)}const Ui={table:oi,tableRow:ri,tableCell:ni},Vi={layout:ii,layoutColumn:li};function nm({id:t}){const e=G(),n=It(t),r=p.useCallback(i=>{e.applyOperation(de(t,{data:{...n==null?void 0:n.data,selectedValue:i}}))},[e,t,n==null?void 0:n.data]);if(!n)return null;const{options:o=[],selectedValue:s="",placeholder:a="Select…"}=n.data??{};return l.jsx("span",{className:"be-inline-select",onMouseDown:i=>{i.preventDefault(),i.stopPropagation()},onKeyDown:i=>i.stopPropagation(),children:l.jsx(Mt,{value:s,options:o,onChange:r,placeholder:a,ariaLabel:"Select an option"})})}function Er(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o},s){const a=t.getRun(n),i=(a==null?void 0:a.value)??"",d=i.slice(0,r),c=i.slice(o),f=s(),u={...a,value:d},h={id:_(),type:"text",value:c,marks:{...a==null?void 0:a.marks}};t.applyOperation(Nt(e,[n],[u,f,h])),ye(h.id)}function rm(t){return String(t).replace(/&/g,"&amp;").replace(/"/g,"&quot;")}function Yi(t){var r;const{options:e=[],selectedValue:n=""}=t.data??{};return((r=e.find(o=>o.value===n))==null?void 0:r.label)??""}function om(t){var n,r;const e=Yi(t)||((n=t.data)==null?void 0:n.placeholder)||"";return`<span data-inline-type="select" data-selected-value="${rm(((r=t.data)==null?void 0:r.selectedValue)??"")}">${e}</span>`}function sm(t){return Yi(t)}function am(t){var e;return((e=t.getAttribute)==null?void 0:e.call(t,"data-inline-type"))!=="select"?null:{id:_(),type:"select",value:"",marks:{},data:{options:[],selectedValue:t.getAttribute("data-selected-value")??""}}}const Ki={component:nm,isAtomic:!0,toHTML:om,toPlainText:sm,fromHTML:am,slashCommand:{label:"Select",icon:il,keywords:["select","dropdown","choice","picker"],run:(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o})=>Er(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o},()=>({id:_(),type:"select",value:"",marks:{},data:{options:[],selectedValue:"",placeholder:"Select…"}}))}};function lm({id:t}){const e=G(),n=It(t),r=p.useCallback(s=>{e.applyOperation(de(t,{data:{...n==null?void 0:n.data,isoDate:s.target.value}}))},[e,t,n==null?void 0:n.data]);if(!n)return null;const{isoDate:o=""}=n.data??{};return l.jsx("span",{className:"be-inline-date",onMouseDown:s=>s.stopPropagation(),onKeyDown:s=>s.stopPropagation(),children:l.jsx("input",{type:"date",value:o,onChange:r})})}function im(t){return String(t).replace(/&/g,"&amp;").replace(/"/g,"&quot;")}function Wi(t){if(!t)return"";const e=new Date(`${t}T00:00:00`);return Number.isNaN(e.getTime())?t:e.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function cm(t){var n;const e=((n=t.data)==null?void 0:n.isoDate)??"";return`<span data-inline-type="date" data-iso-date="${im(e)}">${Wi(e)}</span>`}function dm(t){var e;return Wi(((e=t.data)==null?void 0:e.isoDate)??"")}function um(t){var e;return((e=t.getAttribute)==null?void 0:e.call(t,"data-inline-type"))!=="date"?null:{id:_(),type:"date",value:"",marks:{},data:{isoDate:t.getAttribute("data-iso-date")??""}}}function pm(){return new Date().toISOString().slice(0,10)}const qi={component:lm,isAtomic:!0,toHTML:cm,toPlainText:dm,fromHTML:um,slashCommand:{label:"Date",icon:vu,keywords:["date","when","schedule","calendar"],run:(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o})=>Er(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o},()=>({id:_(),type:"date",value:"",marks:{},data:{isoDate:pm()}}))}};function fm({id:t}){const e=G(),n=It(t),r=p.useCallback(i=>{e.applyOperation(de(t,{data:{...n==null?void 0:n.data,checked:i.target.checked}}))},[e,t,n==null?void 0:n.data]),o=p.useCallback(i=>{e.applyOperation(de(t,{data:{...n==null?void 0:n.data,label:i.target.value}}))},[e,t,n==null?void 0:n.data]);if(!n)return null;const{checked:s=!1,label:a=""}=n.data??{};return l.jsxs("span",{className:"be-inline-checkbox",onMouseDown:i=>i.stopPropagation(),onKeyDown:i=>i.stopPropagation(),children:[l.jsx("input",{type:"checkbox",className:"be-inline-checkbox-input",checked:s,onChange:r}),l.jsx("input",{type:"text",className:"be-inline-checkbox-label",value:a,onChange:o,placeholder:"Label…"})]})}function hm(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function mm(t){const{checked:e=!1,label:n=""}=t.data??{};return`<span data-inline-type="checkbox" data-checked="${e}">${e?"☑":"☐"} ${hm(n)}</span>`}function bm(t){const{checked:e=!1,label:n=""}=t.data??{};return`${e?"[x]":"[ ]"} ${n}`.trim()}function gm(t){var e;return((e=t.getAttribute)==null?void 0:e.call(t,"data-inline-type"))!=="checkbox"?null:{id:_(),type:"checkbox",value:"",marks:{},data:{checked:t.getAttribute("data-checked")==="true",label:(t.textContent??"").replace(/^[☑☐]\s*/,"")}}}const Xi={component:fm,isAtomic:!0,toHTML:mm,toPlainText:bm,fromHTML:gm,slashCommand:{label:"Checkbox",icon:No,keywords:["checkbox","todo","check","toggle"],run:(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o})=>Er(t,{blockId:e,runId:n,sliceStart:r,sliceEnd:o},()=>({id:_(),type:"checkbox",value:"",marks:{},data:{checked:!1,label:""}}))}};function xm({id:t,blockId:e}){var m;const n=G(),r=It(t),o=e?n.getBlock(e):null,s=o?n.getBlock(o.parentId):null,a=(s==null?void 0:s.parentId)??null,i=be(a),d=s?s.contentIds.indexOf(e):-1,f=(((m=(i&&s?ze(i,s.contentIds.length):[])[d])==null?void 0:m.options)??[]).map((g,x)=>({...g,color:g.color??Tn(x)})),u=p.useCallback((g,x)=>{n.applyOperation(de(t,{data:{selectedValue:g,selectedLabel:(x==null?void 0:x.label)??""}}))},[n,t]);if(!r)return null;const{selectedValue:h=""}=r.data??{};return l.jsx("span",{className:"be-inline-table-select",onMouseDown:g=>{g.preventDefault(),g.stopPropagation()},onKeyDown:g=>g.stopPropagation(),children:l.jsx(Mt,{value:h,options:f,onChange:u,placeholder:"Select…",ariaLabel:"Select an option",variant:"tag"})})}function Gi(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function ym(t){return Gi(t).replace(/"/g,"&quot;")}function km(t){const{selectedValue:e="",selectedLabel:n=""}=t.data??{};return`<span data-inline-type="tableSelect" data-selected-value="${ym(e)}">${Gi(n)}</span>`}function vm(t){var e;return((e=t.data)==null?void 0:e.selectedLabel)??""}function wm(t){var e;return((e=t.getAttribute)==null?void 0:e.call(t,"data-inline-type"))!=="tableSelect"?null:{id:_(),type:"tableSelect",value:"",marks:{},data:{selectedValue:t.getAttribute("data-selected-value")??"",selectedLabel:t.textContent??""}}}const Ji={component:xm,isAtomic:!0,toHTML:km,toPlainText:vm,fromHTML:wm},Zi={};function Qi(t){ec(t,{select:Ki,date:qi,checkbox:Xi,...tc,emoji:Zi})}function ec(t,e){for(const[n,r]of Object.entries(e))t.register(n,r)}const tc={tableSelect:Ji};function Im(){const t="root",e=_(),n=_();return{rootId:t,blocks:[{id:t,type:"page",parentId:null,contentIds:[e],props:{}},{id:e,type:"paragraph",parentId:t,contentIds:[n],props:{}}],runs:[{id:n,type:"text",value:"",marks:{}}]}}function Cm({doc:t,history:e=!0,currentUserId:n=null,registerBlocks:r,registerInlineTypes:o}={}){return p.useMemo(()=>{const s=xl();(r??Hi)(s);const a=kl();(o??Qi)(a);const i=new Bn(t??Im());return{store:e?new Sa(i,{defaultActorId:n}):i,registry:s,inlineRegistry:a}},[])}function nc({minHeight:t=180,className:e="be-trailing-space"}){const n=G(),[r]=So(),o=p.useCallback(()=>{var c;if(r)return;const s=n.getRootId(),a=n.getBlock(s),i=(c=a==null?void 0:a.contentIds)==null?void 0:c[a.contentIds.length-1];if(!i){const f=dn(n);f&&Gs(n,f);return}const d=n.getBlock(i);(d==null?void 0:d.type)==="paragraph"?Gs(n,i):nt(n,i,te("paragraph"))},[n,r]);return l.jsx("div",{className:e,style:{minHeight:t},onClick:o})}async function io(t,e,n,r){var a,i,d;const{html:o,text:s}=_n(t,e,r,n);if(typeof ClipboardItem<"u"&&((a=navigator.clipboard)!=null&&a.write)){await navigator.clipboard.write([new ClipboardItem({"text/plain":new Blob([s],{type:"text/plain"}),"text/html":new Blob([o],{type:"text/html"})})]);return}await((d=(i=navigator.clipboard)==null?void 0:i.writeText)==null?void 0:d.call(i,s))}function Qo(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function In(t,e){e.length!==0&&Qo(t,e.map(n=>ee(n)))}function rc(t,e){if(e.length===0)return!1;const n=t.getBlock(e[0]);if(!n)return!1;const r=t.getBlock(n.parentId);if(!r)return!1;const o=r.contentIds.indexOf(e[0]),s=r.contentIds.indexOf(e[e.length-1]);if(o<=0)return!1;const a=r.contentIds[o-1];return t.applyOperation(ct(a,n.parentId,s)),!0}function oc(t,e){if(e.length===0)return!1;const n=t.getBlock(e[0]);if(!n)return!1;const r=t.getBlock(n.parentId);if(!r)return!1;const o=r.contentIds.indexOf(e[0]),s=r.contentIds.indexOf(e[e.length-1]);if(s===-1||s>=r.contentIds.length-1)return!1;const a=r.contentIds[s+1];return t.applyOperation(ct(a,n.parentId,o)),!0}function sc(t,e){return e.length>0&&e.every(n=>{var r,o;return!!((o=(r=t.getBlock(n))==null?void 0:r.props)!=null&&o.hidden)})}function ac(t,e,n){e.length!==0&&Qo(t,e.map(r=>J(r,{hidden:n})))}function Sm(t,e,n,r){const o=n.filter(a=>{var i;return Uo((i=t.getBlock(a))==null?void 0:i.type)});if(o.length===0)return;const s=o.flatMap(a=>Dl(t,e,a,r).ops);Qo(t,s)}function jm(t,e){if(e.length===0)return[];const n=t.getBlock(e[0]),r=n&&t.getBlock(n.parentId);if(!r)return e;const o=new Set(e);return r.contentIds.filter(s=>o.has(s))}function lc(){const t=G(),e=dt(),n=Ke(),[r,o]=Mn(),[s,a]=p.useState(null),i=p.useRef(null),d=p.useRef(null),c=r.length>0,f=An(i,c,(s==null?void 0:s.bottom)!=null?s.bottom+4:null,s==null?void 0:s.left),u=p.useCallback(()=>o([]),[o]);wr(i,c,u,void 0),p.useEffect(()=>{if(!c){a(null);return}const C=()=>{const R=r[r.length-1],E=document.querySelector(`[data-block-row-id="${R}"]`);a((E==null?void 0:E.getBoundingClientRect())??null)};return C(),window.addEventListener("scroll",C,!0),window.addEventListener("resize",C),()=>{window.removeEventListener("scroll",C,!0),window.removeEventListener("resize",C)}},[c,r]),p.useEffect(()=>{if(!c)return;const C=E=>{var T,O,S,L;(T=i.current)!=null&&T.contains(E.target)||(O=d.current)!=null&&O.contains(E.target)||(L=(S=E.target).closest)!=null&&L.call(S,".be-block-gutter")||u()},R=E=>{E.key==="Escape"?u():(E.key==="Delete"||E.key==="Backspace")&&(E.preventDefault(),In(t,r),u())};return document.addEventListener("mousedown",C),document.addEventListener("keydown",R),()=>{document.removeEventListener("mousedown",C),document.removeEventListener("keydown",R)}},[c,t,r,u]);const h=C=>C===1?"block":"blocks",m=p.useCallback(()=>{io(t,e,n,r),xe(`${r.length} ${h(r.length)} copied`),u()},[t,e,n,r,u]),g=p.useCallback(async()=>{await io(t,e,n,r);const C=r.length;In(t,r),xe(`${C} ${h(C)} cut`),u()},[t,e,n,r,u]),x=p.useCallback(()=>{const C=r.length;In(t,r),xe(`${C} ${h(C)} deleted`),u()},[t,r,u]),y=p.useCallback(()=>{rc(t,r)&&xe(`${r.length} ${h(r.length)} moved up`),u()},[t,r,u]),k=p.useCallback(()=>{oc(t,r)&&xe(`${r.length} ${h(r.length)} moved down`),u()},[t,r,u]),v=sc(t,r),w=p.useCallback(()=>{ac(t,r,!v),xe(v?`${r.length} ${h(r.length)} shown in preview`:`${r.length} ${h(r.length)} hidden in preview`),u()},[t,r,v,u]),B=r.some(C=>{var R;return Uo((R=t.getBlock(C))==null?void 0:R.type)}),I=p.useCallback(C=>{const R=r.length;Sm(t,e,r,C),xe(`${R} ${h(R)} turned into ${C.label}`),u()},[t,e,r,u]);return!c||!f?null:De.createPortal(l.jsxs("div",{ref:i,role:"menu","aria-label":"Selected blocks options",className:"be-block-range-menu",style:{position:"fixed",top:f.top,left:f.left},children:[l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:m,children:[l.jsx(To,{size:15})," Copy"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:g,children:[l.jsx(bu,{size:15})," Cut"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:y,children:[l.jsx(br,{size:15})," Move up"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:k,children:[l.jsx(gr,{size:15})," Move down"]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item",onClick:w,children:[v?l.jsx(Mo,{size:15}):l.jsx(Oo,{size:15}),v?"Show in preview":"Hide in preview"]}),B&&l.jsx(Pl,{onSelect:I,onClose:()=>{},containerRef:d,menuClassName:"be-block-range-menu",itemClassName:"be-block-range-menu-item"}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-block-range-menu-item be-block-range-menu-item-danger",onClick:x,children:[l.jsx(On,{size:15})," Delete"]})]}),document.body)}const dr="application/x-block-editor-blocks+json";function es(t){return t.split(/\r\n|\r|\n/).filter(e=>e.length>0).map(e=>{const n=_();return{block:{id:_(),type:"paragraph",parentId:null,contentIds:[n],props:{}},runs:[{id:n,type:"text",value:e,marks:{}}]}})}function ic(t,e,n){const r=new DOMParser().parseFromString(t,"text/html"),o={registry:e,inlineRegistry:n},s=e.listHtmlMatchers(),a=[],i=c=>{var h;const f=c.tagName==="OL",u=[];for(const m of c.children){if(m.tagName!=="LI")continue;const g=(h=e.get("listItem"))==null?void 0:h.fromHTML(m,o);g&&(g.block.props.ordered=f,u.push(g))}return u},d=c=>{var u;const f=Array.from(c.children).filter(h=>h.tagName==="P");if(f.length===0){const h=(u=e.get("blockquote"))==null?void 0:u.fromHTML(c,o);return h?[h]:[]}return f.map(h=>{const m=Ye(h,o);return{block:{id:_(),type:"blockquote",parentId:null,contentIds:m.map(g=>g.id),props:{}},runs:m}})};for(const c of r.body.childNodes){if(c.nodeType===3){const u=c.textContent.trim();u&&a.push(...es(u));continue}if(c.nodeType!==1)continue;if(c.tagName==="UL"||c.tagName==="OL"){a.push(...i(c));continue}if(c.tagName==="BLOCKQUOTE"){a.push(...d(c));continue}let f=null;for(const u of s){const h=u.fromHTML(c,o);if(h){f=h;break}}if(f)a.push(f);else if(c.textContent.trim()){const u=Ye(c,o);a.push({block:{id:_(),type:"paragraph",parentId:null,contentIds:u.map(h=>h.id),props:{}},runs:u})}}return a}function cc(t,e,n){const r=t.types??[];if(r.includes(dr)){const s=t.getData(dr);if(s)return Rm(s)}if(r.includes("text/html")){const s=t.getData("text/html");if(s)return ic(s,e,n)}const o=t.getData("text/plain")??"";return es(o)}function Rm(t){return JSON.parse(t).blocks.map(n=>fr(n))}function co(t,e){var r;const n=t.getBlock(e);return((r=n.props)==null?void 0:r.titleRunIds)??n.contentIds}function or(){return{id:_(),type:"text",value:"",marks:{}}}function uo(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function ts(t,e,n){const{startRunId:r,startOffset:o,endRunId:s,endOffset:a}=n,i=co(t,e),d=i.indexOf(r),c=i.indexOf(s);if(d===-1||c===-1)return null;const[f,u]=d<=c?[d,c]:[c,d],h=d<=c?o:a,m=d<=c?a:o,g=i.slice(0,f).map(I=>t.getRun(I)),x=i.slice(u+1).map(I=>t.getRun(I)),y=i.slice(f,u+1).map(I=>t.getRun(I)),k=[];let v=null,w=0;if(f===u){const I=y[0];if(I.type==="text"){const C=Math.max(0,Math.min(h,m)),R=Math.min(I.value.length,Math.max(h,m)),E={...I,value:I.value.slice(0,C)+I.value.slice(R)};k.push(E),v=E.id,w=C}}else y.forEach((I,C)=>{if(I.type!=="text")return;const R=C===0,E=C===y.length-1,T=R?I.value.slice(0,h):"";if(R&&T){const O={...I,value:T};k.push(O),v=O.id,w=T.length}if(E&&!R){const O=I.value.slice(m);if(O){const S={id:_(),type:"text",value:O,marks:I.marks};k.push(S),v===null&&(v=S.id,w=0)}}});let B=[...g,...k,...x];if(B.length===0){const I=or();B=[I],v=I.id,w=0}else if(v===null){const I=g[g.length-1];I?(v=I.id,w=I.type==="text"?I.value.length:0):x[0]&&(v=x[0].id,w=0)}return t.applyOperation(Me(e,B)),{blockId:e,runId:v,offset:w}}function ns(t,e){const{blockIds:n,startBlockId:r,startRunId:o,startOffset:s,endBlockId:a,endRunId:i,endOffset:d}=e;if(!n||n.length===0)return null;const c=n.indexOf(r),f=n.indexOf(a);if(c===-1||f===-1)return null;const[u,h]=c<=f?[c,f]:[f,c],m=c<=f,g=m?o:i,x=m?s:d,y=m?i:o,k=m?d:s;if(u===h)return ts(t,n[u],{startRunId:g,startOffset:x,endRunId:y,endOffset:k});const v=n[u],w=n[h],B=t.getBlock(v),I=t.getBlock(w),C=co(t,v),R=C.indexOf(g),E=C.slice(0,R).map(ce=>t.getRun(ce)),T=t.getRun(g),O=T.type==="text"&&x>0?{...T,value:T.value.slice(0,x)}:null,S=co(t,w),L=S.indexOf(y),$=S.slice(L+1).map(ce=>t.getRun(ce)),Y=t.getRun(y),K=Y.type==="text"&&k<Y.value.length?{id:_(),type:"text",value:Y.value.slice(k),marks:Y.marks}:null,Q=[...E,...O?[O]:[]],D=[...K?[K]:[],...$],F=[];for(let ce=u+1;ce<h;ce+=1)F.push(ee(n[ce]));const re=_l(B.type,I.type),H=t.getBlock(B.parentId),ne=h-u-1+(re?1:0),se=H&&H.contentIds.length-ne===1;let oe,ge,Re;if(re){const ce=[...Q,...D];if(ce.length===0&&se&&B.type!=="paragraph"){const{block:he,runs:U}=te("paragraph")(H.id);return F.push({type:"insertBlock",block:he,parentId:H.id,index:0,subtree:{blocks:[he],runs:U}}),F.push(ee(v)),F.push(ee(w)),uo(t,F),{blockId:he.id,runId:he.contentIds[0],offset:0}}const ke=ce.length?ce:[or()];if(F.push(Me(v,ke)),F.push(ee(w)),Re=v,O)oe=O.id,ge=O.value.length;else if(E.length){const he=E[E.length-1];oe=he.id,ge=he.type==="text"?he.value.length:0}else K?(oe=K.id,ge=0):$.length?(oe=$[0].id,ge=0):(oe=ke[0].id,ge=0)}else{const ce=Q.length?Q:[or()];if(F.push(Me(v,ce)),F.push(Me(w,D.length?D:[or()])),Re=v,O)oe=O.id,ge=O.value.length;else if(E.length){const ke=E[E.length-1];oe=ke.id,ge=ke.type==="text"?ke.value.length:0}else oe=ce[0].id,ge=0}return uo(t,F),{blockId:Re,runId:oe,offset:ge}}function ur(t,e=""){var i;const n=t.getRootId(),r=((i=t.getBlock(n))==null?void 0:i.contentIds)??[];if(r.length===0)return null;const o=r.map(d=>ee(d)),{block:s,runs:a}=te("paragraph")(n);return e&&(a[0].value=e),o.push(me(s,n,0,{blocks:[s],runs:a})),uo(t,o),{blockId:s.id,runId:s.contentIds[0],offset:e.length}}function po(t){var n;let e=(t==null?void 0:t.nodeType)===1?t:t==null?void 0:t.parentElement;for(;e&&typeof e.hasAttribute=="function"&&!e.hasAttribute("data-block-id");)e=e.parentElement;return((n=e==null?void 0:e.getAttribute)==null?void 0:n.call(e,"data-block-id"))??null}function Tm(t){var u;const e=(u=window.getSelection)==null?void 0:u.call(window);if(!e||e.rangeCount===0)return[];const n=po(e.anchorNode),r=po(e.focusNode);if(!n)return[];if(!r||n===r)return[n];const o=t.getBlock(n),s=o&&t.getBlock(o.parentId);if(!s)return[n];const a=s.contentIds,i=a.indexOf(n),d=a.indexOf(r);if(i===-1||d===-1)return[n];const[c,f]=i<=d?[i,d]:[d,i];return a.slice(c,f+1)}function xa(t){const e=ln();if(e)return ts(t,e.blockId,e);const n=rn(t);return n?ns(t,n):null}function Em(t,e,n){const r=t.getRun(e.runId);if(!r||r.type!=="text")return null;const o=r.value??"",s=o.slice(0,e.offset)+n+o.slice(e.offset);return t.applyOperation(de(r.id,{value:s})),{blockId:e.blockId,runId:r.id,offset:e.offset+n.length}}function Qr(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function dc(){const t=G(),e=dt(),n=Ke(),[r,o]=Co(),[s,a]=Mn(),i=p.useCallback(f=>{var x;const u=r?((x=t.getBlock(t.getRootId()))==null?void 0:x.contentIds)??[]:s.length>0?s:Tm(t);if(u.length===0)return;const{html:h,text:m,json:g}=_n(t,e,u,n);f.clipboardData.setData("text/plain",m),f.clipboardData.setData("text/html",h),f.clipboardData.setData(dr,g),f.preventDefault()},[t,e,n,r,s]),d=p.useCallback(f=>{if(i(f),r){const h=ur(t);o(!1),h!=null&&h.runId&&Ze(h.runId,h.offset);return}if(s.length>0){In(t,s),a([]);return}const u=xa(t);u!=null&&u.runId&&Ze(u.runId,u.offset)},[i,t,r,o,s,a]),c=p.useCallback(f=>{var w,B,I;const u=cc(f.clipboardData,e,n);if(u.length===0)return;if(r){const C=t.getRootId(),E=(((w=t.getBlock(C))==null?void 0:w.contentIds)??[]).map(O=>ee(O));let T=0;for(const{block:O,runs:S,subtreeBlocks:L=[]}of u)O.parentId=C,E.push(me(O,C,T,{blocks:[O,...L],runs:S})),T+=1;Qr(t,E),o(!1),f.preventDefault();return}if(s.length>0){const C=t.getBlock(s[0]),R=(C==null?void 0:C.parentId)??null,E=R&&t.getBlock(R);let T=E?E.contentIds.indexOf(s[0]):0;const O=s.map(S=>ee(S));for(const{block:S,runs:L,subtreeBlocks:$=[]}of u)S.parentId=R,O.push(me(S,R,T,{blocks:[S,...$],runs:L})),T+=1;Qr(t,O),a([]),f.preventDefault();return}const h=xa(t);if(u.length===1&&u[0].runs.every(C=>C.type==="text")&&(u[0].subtreeBlocks??[]).length===0){const C=h?{blockId:h.blockId,runId:h.runId,offset:h.offset}:lt();if(C){const R=u[0].runs.map(T=>T.value).join(""),E=Em(t,C,R);if(E){Ze(E.runId,E.offset),f.preventDefault();return}}}const g=(h==null?void 0:h.blockId)??po((I=(B=window.getSelection)==null?void 0:B.call(window))==null?void 0:I.anchorNode);if(!g)return;const x=t.getBlock(g);if(!x)return;let k=t.getBlock(x.parentId).contentIds.indexOf(g)+1;const v=[];for(const{block:C,runs:R,subtreeBlocks:E=[]}of u)C.parentId=x.parentId,v.push(me(C,x.parentId,k,{blocks:[C,...E],runs:R})),k+=1;Qr(t,v),f.preventDefault()},[t,e,n,r,o,s,a]);return{onCopy:i,onCut:d,onPaste:c}}const Bm=["bold","italic","underline","strike","subscript","superscript","code"],_m=["color","highlight","link"];function on(t,e){var r;const n=t.getBlock(e);return((r=n.props)==null?void 0:r.titleRunIds)??n.contentIds}function Nm(t,e){return t===e?!0:t&&e&&typeof t=="object"?JSON.stringify(t)===JSON.stringify(e):!1}function uc(t){var n;const e={};if(t.length===0)return e;for(const r of Bm)e[r]=t.every(o=>{var s;return(s=o.marks)==null?void 0:s[r]});for(const r of _m){const o=((n=t[0].marks)==null?void 0:n[r])??null;e[r]=t.every(s=>{var a;return Nm(((a=s.marks)==null?void 0:a[r])??null,o)})?o:null}return e}function rs(t,e,n){const{startRunId:r,startOffset:o,endRunId:s,endOffset:a}=n,i=on(t,e),d=i.indexOf(r),c=i.indexOf(s);if(d===-1||c===-1)return{};const[f,u]=d<=c?[d,c]:[c,d],h=i.slice(f,u+1).map(m=>t.getRun(m)).filter(m=>m&&m.type==="text");return uc(h)}function os(t,e){const{blockIds:n,startBlockId:r,endBlockId:o}=e,s=n.indexOf(r),a=n.indexOf(o);if(s===-1||a===-1)return{};const[i,d]=s<=a?[s,a]:[a,s],c=[];for(let f=i;f<=d;f+=1)for(const u of on(t,n[f])){const h=t.getRun(u);h&&h.type==="text"&&c.push(h)}return uc(c)}function pc(t,e){const n={...t};for(const[r,o]of Object.entries(e))o!=null?n[r]=o:delete n[r];return n}function fc(t,e,n,r,o,s){const a=pc(n.marks,s);if(r===0&&o===n.value.length)return t.applyOperation({type:"updateRun",id:n.id,patch:{marks:a}}),n.id;const i=n.value.slice(0,r),d=n.value.slice(r,o),c=n.value.slice(o),f=[];i&&f.push({id:_(),type:"text",value:i,marks:{...n.marks}});const u={id:_(),type:"text",value:d,marks:a};return f.push(u),c&&f.push({id:_(),type:"text",value:c,marks:{...n.marks}}),t.applyOperation(Nt(e,[n.id],f)),u.id}function Mm(t,e,n,r){const{startRunId:o,startOffset:s,endRunId:a,endOffset:i}=n,d=on(t,e),c=d.indexOf(o),f=d.indexOf(a);if(c===-1||f===-1)return null;const[u,h]=c<=f?[c,f]:[f,c],m=c<=f?s:i,g=c<=f?i:s,x=d.slice(u,h+1),y=x.map(w=>t.getRun(w));if(u===h){const w=y[0];if(w.type!=="text")return w.id;const B=Math.max(0,Math.min(m,g)),I=Math.min(w.value.length,Math.max(m,g));return B===I?w.id:fc(t,e,w,B,I,r)}const k=[];let v=null;return y.forEach((w,B)=>{if(w.type!=="text"){k.push(w),v=w.id;return}const I=B===0,C=B===y.length-1,R=I?m:0,E=C?g:w.value.length,T=w.value.slice(0,R),O=w.value.slice(R,E),S=w.value.slice(E);T&&k.push({id:_(),type:"text",value:T,marks:{...w.marks}});const L={id:_(),type:"text",value:O,marks:pc(w.marks,r)};k.push(L),v=L.id,S&&k.push({id:_(),type:"text",value:S,marks:{...w.marks}})}),t.applyOperation(Nt(e,x,k)),v}function Om(t,e,n,r){var g;const{startRunId:o,startOffset:s,endRunId:a,endOffset:i}=n,d=on(t,e),c=d.indexOf(o),f=d.indexOf(a);if(c===-1||f===-1)return!0;const[u,h]=c<=f?[c,f]:[f,c],m=d.slice(u,h+1).map(x=>t.getRun(x)).filter(x=>x.type==="text");if(m.length===0)return!0;if(u===h){const x=Math.max(0,Math.min(s,i)),y=Math.min(m[0].value.length,Math.max(s,i));if(x===y)return!((g=m[0].marks)!=null&&g[r])}return!m.every(x=>{var y;return(y=x.marks)==null?void 0:y[r]})}function Lm(t,e,n,r,o,s){var u;const a=t.getRun(n),i=a.value??"",d=Math.max(0,Math.min(r,o)),c=Math.min(i.length,Math.max(r,o));if(d===c)return n;const f=!((u=a.marks)!=null&&u[s]);return fc(t,e,a,d,c,{[s]:f?!0:null})}function sn(t,e,n,r){return Mm(t,e,n,r)}function ss(t,e,n,r){const o=Om(t,e,n,r);return sn(t,e,n,{[r]:o?!0:null})}function as(t,e,n){return pr(t,e,r=>({[n]:r?null:!0}),n)}function pr(t,e,n,r){var C;const{blockIds:o,startBlockId:s,startRunId:a,startOffset:i,endBlockId:d,endRunId:c,endOffset:f}=e;if(!o||o.length===0)return null;const u=o.indexOf(s),h=o.indexOf(d);if(u===-1||h===-1)return null;const[m,g]=u<=h?[u,h]:[h,u],x=u<=h,y=x?a:c,k=x?i:f,v=x?c:a,w=x?f:i;let B=n;if(typeof n=="function"){let R=!1,E=!0;for(let T=m;T<=g;T+=1){const O=on(t,o[T]).map(S=>t.getRun(S)).filter(S=>S.type==="text");O.length!==0&&(R=!0,O.every(S=>{var L;return(L=S.marks)==null?void 0:L[r]})||(E=!1))}B=n(R&&E)}if(m===g)return sn(t,o[m],{startRunId:y,startOffset:k,endRunId:v,endOffset:w},B);let I=null;for(let R=m;R<=g;R+=1){const E=o[R],T=on(t,E),O=T[0],S=T[T.length-1],L=t.getRun(S),$=((C=L==null?void 0:L.value)==null?void 0:C.length)??0;let Y;R===m&&R===g?Y={startRunId:y,startOffset:k,endRunId:v,endOffset:w}:R===m?Y={startRunId:y,startOffset:k,endRunId:S,endOffset:$}:R===g?Y={startRunId:O,startOffset:0,endRunId:v,endOffset:w}:Y={startRunId:O,startOffset:0,endRunId:S,endOffset:$},I=sn(t,E,Y,B)}return I}function hc(t,e){var r;const n=t.getBlock(e);return((r=n==null?void 0:n.props)==null?void 0:r.titleRunIds)??(n==null?void 0:n.contentIds)??[]}function mc(t){const e=ln();if(!e)return!1;const{blockId:n,startRunId:r,startOffset:o,endRunId:s,endOffset:a}=e,i=hc(t,n);if(i.length===0)return!1;const d=i.indexOf(r),c=i.indexOf(s);if(d===-1||c===-1)return!1;const[f,u]=d<=c?[d,c]:[c,d],h=d<=c?o:a,m=d<=c?a:o;if(f!==0||u!==i.length-1||h!==0)return!1;const g=t.getRun(i[i.length-1]),x=(g==null?void 0:g.type)==="text"?(g.value??"").length:1;return m===x}function Am(t){const e=lt();return e?Oe(t,hc(t,e.blockId)):!1}function Dm(t,e,n){var m,g;const r=t.getBlock(e);if(!r){n(null);return}const o=t.getBlock(r.parentId),s=o?o.contentIds.indexOf(e):-1,a=s>0?o.contentIds[s-1]:null,i=s!==-1&&s<o.contentIds.length-1?o.contentIds[s+1]:null;t.applyOperation(ee(e)),n(null);const d=dn(t),c=a??i??d;if(!c)return;const f=t.getBlock(c);if(Ln(t,f)){n(c),requestAnimationFrame(()=>{var x;return(x=document.querySelector(`[data-block-id="${c}"]`))==null?void 0:x.focus()});return}const u=(m=f==null?void 0:f.props)==null?void 0:m.titleRunIds,h=((g=f==null?void 0:f.contentIds)==null?void 0:g[f.contentIds.length-1])??(u==null?void 0:u[u.length-1]);h&&ye(h)}function an(t){var o,s;const e=(o=t.getPendingSelection)==null?void 0:o.call(t);if(e){Ze(e.runId,e.offset);return}const r=(((s=t.getPendingAffectedBlockIds)==null?void 0:s.call(t))??[]).find(a=>t.getBlock(a));r&&je(t,r)}const ya={b:"bold",i:"italic",u:"underline"};function bc(t){const e=G(),[n,r]=Co(),{getSelectedBlockId:o,setSelectedBlockId:s}=ut();p.useEffect(()=>{const a=t.current;if(!a)return;const i=c=>{var u,h;if(o()&&(c.key==="Backspace"||c.key==="Delete")&&!c.defaultPrevented){c.preventDefault(),c.stopPropagation(),Dm(e,o(),s);return}if(o()&&c.key!=="Backspace"&&c.key!=="Delete"&&s(null),c.metaKey||c.ctrlKey){const m=c.key.toLowerCase();if(m==="z"&&!c.shiftKey){c.preventDefault(),(u=e.undo)!=null&&u.call(e)&&an(e);return}if(m==="z"&&c.shiftKey||m==="y"){c.preventDefault(),(h=e.redo)!=null&&h.call(e)&&an(e);return}if(m==="a"){if(n)return;(mc(e)||Am(e))&&(c.preventDefault(),r(!0));return}if(ya[m]){if(n)return;c.preventDefault();const g=ya[m],x=ln();if(x){const k=ss(e,x.blockId,x,g);k&&ye(k);return}const y=rn(e);if(y){const k=as(e,y,g);k&&ye(k)}}return}if(n){if(c.key==="Backspace"||c.key==="Delete"){c.preventDefault(),c.stopPropagation();const m=ur(e);r(!1),m!=null&&m.runId&&Ze(m.runId,m.offset);return}if(c.key.length===1){c.preventDefault(),c.stopPropagation();const m=ur(e,c.key);r(!1),m!=null&&m.runId&&Ze(m.runId,m.offset);return}if(r(!1),c.key==="Escape")return}if(c.key==="Backspace"||c.key==="Delete"){const m=rn(e);if(!m)return;c.preventDefault(),c.stopPropagation();const g=ns(e,m);g!=null&&g.runId&&Ze(g.runId,g.offset)}},d=()=>{n&&r(!1),o()&&s(null)};return a.addEventListener("keydown",i),a.addEventListener("mousedown",d),()=>{a.removeEventListener("keydown",i),a.removeEventListener("mousedown",d)}},[t,e,n,r,o,s])}const Pm=4;function $m(t,e,n){const r=t.getBlock(e);if(!r)return[];const o=t.getBlock(r.parentId);if(!o)return[e];const s=o.contentIds,a=s.indexOf(e),i=n?s.indexOf(n):a;if(a===-1)return[e];const[d,c]=i===-1?[a,a]:[Math.min(a,i),Math.max(a,i)];return s.slice(d,c+1)}function zm(){var t,e;return typeof window<"u"&&((e=(t=window.matchMedia)==null?void 0:t.call(window,"(pointer: coarse)"))==null?void 0:e.matches)===!0}function gc(t){const e=G(),[,n]=Mn(),r=p.useRef(null),o=p.useRef(!1),s=p.useRef(null),a=p.useCallback(f=>{var m,g,x,y,k;if(!r.current)return;if(!o.current){const{x:v,y:w}=s.current??{x:f.clientX,y:f.clientY};if(Math.hypot(f.clientX-v,f.clientY-w)<Pm)return;o.current=!0,document.documentElement.classList.add("be-block-range-dragging"),(g=(m=window.getSelection)==null?void 0:m.call(window))==null||g.removeAllRanges()}(y=(x=window.getSelection)==null?void 0:x.call(window))==null||y.removeAllRanges(),f.preventDefault();const u=(k=document.elementFromPoint(f.clientX,f.clientY))==null?void 0:k.closest("[data-block-row-id]"),h=(u==null?void 0:u.getAttribute("data-block-row-id"))??null;n($m(e,r.current,h))},[e,n]),i=p.useCallback(()=>{r.current=null,o.current=!1,s.current=null,document.documentElement.classList.remove("be-block-range-dragging")},[]),d=p.useCallback((f,u)=>{r.current=f,o.current=!1,s.current={x:u.clientX,y:u.clientY}},[]),c=p.useCallback(f=>{var x,y;if(f.button!==0||zm()||(y=(x=f.target).closest)!=null&&y.call(x,"button, input, textarea, select"))return;const u=f.target.closest("[data-block-row-id]");if(u){if(f.target.closest(".be-block-row-content"))return;d(u.getAttribute("data-block-row-id"),f);return}const h=t==null?void 0:t.current;if(!h)return;const g=[...h.querySelectorAll("[data-block-row-id]")].find(k=>{const v=k.getBoundingClientRect();return f.clientY>=v.top&&f.clientY<=v.bottom});g&&d(g.getAttribute("data-block-row-id"),f)},[t,d]);p.useEffect(()=>(document.addEventListener("mousedown",c),document.addEventListener("mousemove",a),document.addEventListener("mouseup",i),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",i),document.documentElement.classList.remove("be-block-range-dragging")}),[c,a,i])}const Hm=340;function Fm(t,e,n,r){p.useEffect(()=>{if(!t||!e)return;const o=document.querySelector(`[data-run-id="${e}"]`);if(o)return o.setAttribute("aria-expanded","true"),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-controls",r),n&&o.setAttribute("aria-activedescendant",n),()=>{o.removeAttribute("aria-expanded"),o.removeAttribute("aria-haspopup"),o.removeAttribute("aria-controls"),o.removeAttribute("aria-activedescendant")}},[t,e,n,r])}function sr({isOpen:t,rect:e,commands:n,runId:r,onSelect:o,onClose:s,menuId:a="be-slash-menu",ariaLabel:i="Slash commands"}){const[d,c]=p.useState(0),f=p.useRef(null),u=p.useRef(null),h=Rr(),m=Zl(u,t&&n.length>0&&!!e,e==null?void 0:e.left);p.useEffect(()=>{c(0)},[n.length]),p.useEffect(()=>{var w,B;(B=(w=f.current)==null?void 0:w.scrollIntoView)==null||B.call(w,{block:"nearest"})},[d]),p.useEffect(()=>{if(!t)return;const w=B=>{B.key==="ArrowDown"?(B.preventDefault(),B.stopPropagation(),c(I=>Math.min(I+1,Math.max(n.length-1,0)))):B.key==="ArrowUp"?(B.preventDefault(),B.stopPropagation(),c(I=>Math.max(I-1,0))):B.key==="Enter"?(B.preventDefault(),B.stopPropagation(),n[d]&&o(n[d])):B.key==="Escape"&&(B.preventDefault(),B.stopPropagation(),s())};return document.addEventListener("keydown",w,!0),()=>document.removeEventListener("keydown",w,!0)},[t,n,d,o,s]);const x=n[d]?`${a}-option-${d}`:null;if(Fm(t,r,x,a),!t||n.length===0||!e||m==null)return null;const y=window.innerHeight-h,v=e.bottom+Hm>y?{bottom:window.innerHeight-e.top+4}:{top:e.bottom+4};return l.jsx("div",{ref:u,id:a,role:"listbox","aria-label":i,className:"be-slash-menu",style:{position:"fixed",left:m,zIndex:1e3,...v},children:n.map((w,B)=>{const I=w.icon;return l.jsxs("div",{ref:B===d?f:void 0,id:`${a}-option-${B}`,role:"option","aria-selected":B===d,className:`be-slash-menu-item${B===d?" be-slash-menu-item-active":""}`,onMouseDown:C=>{C.preventDefault(),o(w)},onMouseEnter:()=>c(B),children:[I&&l.jsx("span",{className:"be-slash-menu-item-icon",children:l.jsx(I,{size:16})}),l.jsx("span",{className:"be-slash-menu-item-label",children:w.label})]},w.label)})})}function Um(t,e){var r;if(!e)return!0;const n=e.toLowerCase();return t.label.toLowerCase().includes(n)||((r=t.keywords)==null?void 0:r.some(o=>o.toLowerCase().includes(n)))}function Vm(t,e){const n=e.anchorNode,r=e.anchorOffset;let o;if(n===t){o="";for(let s=0;s<r&&s<t.childNodes.length;s+=1)o+=t.childNodes[s].textContent??""}else n&&n.parentElement===t?o=(n.textContent??"").slice(0,r):o=t.textContent??"";return at(o).length}function ls(t,e,n){const r=G(),[o,s]=p.useState(null);p.useEffect(()=>{const c=t.current;if(!c)return;const f=()=>{var I,C,R,E;const h=(I=window.getSelection)==null?void 0:I.call(window),m=h==null?void 0:h.anchorNode;let g=(m==null?void 0:m.nodeType)===1?m:m==null?void 0:m.parentElement;for(;g&&typeof g.hasAttribute=="function"&&!g.hasAttribute("data-run-id");)g=g.parentElement;const x=(C=g==null?void 0:g.getAttribute)==null?void 0:C.call(g,"data-run-id");if(!x||!h){s(null);return}const y=Vm(g,h),k=at(g.textContent).slice(0,y),v=e.exec(k);if(!v){s(null);return}const w=(E=(R=g.closest)==null?void 0:R.call(g,"[data-block-id]"))==null?void 0:E.getAttribute("data-block-id");if(!w){s(null);return}const B=v.index+v[1].length;s({query:v[2],blockId:w,runId:x,sliceStart:B,sliceEnd:y,rect:g.getBoundingClientRect()})},u=h=>{h.key==="Escape"&&s(null)};return c.addEventListener("input",f),c.addEventListener("keydown",u),()=>{c.removeEventListener("input",f),c.removeEventListener("keydown",u)}},[t,e]);const a=o?n().filter(c=>Um(c,o.query)):[],i=p.useCallback(c=>{o&&(c.run(r,{blockId:o.blockId,runId:o.runId,sliceStart:o.sliceStart,sliceEnd:o.sliceEnd}),s(null))},[o,r]),d=p.useCallback(()=>s(null),[]);return{isOpen:!!o,query:(o==null?void 0:o.query)??"",rect:(o==null?void 0:o.rect)??null,runId:(o==null?void 0:o.runId)??null,commands:a,selectCommand:i,close:d}}const Ym=/(^|\s)\/(\w*)$/;function xc(t){const e=dt(),n=Ke(),r=p.useCallback(()=>[...e.listSlashCommands(),...(n==null?void 0:n.listSlashCommands())??[]],[e,n]);return ls(t,Ym,r)}const Km=[{char:"😀",name:"grinning face",keywords:["smile","happy"]},{char:"😂",name:"face with tears of joy",keywords:["laugh","lol"]},{char:"😍",name:"heart eyes",keywords:["love","crush"]},{char:"😎",name:"cool",keywords:["sunglasses"]},{char:"🤔",name:"thinking face",keywords:["hmm"]},{char:"😉",name:"winking face",keywords:["wink"]},{char:"😢",name:"crying face",keywords:["sad","tear"]},{char:"😡",name:"angry face",keywords:["mad","rage"]},{char:"😱",name:"screaming face",keywords:["shock","scared"]},{char:"🥳",name:"party face",keywords:["celebrate","birthday"]},{char:"🙏",name:"folded hands",keywords:["please","pray","thanks"]},{char:"👍",name:"thumbs up",keywords:["approve","yes","like"]},{char:"👎",name:"thumbs down",keywords:["disapprove","no"]},{char:"👏",name:"clapping hands",keywords:["applause","congrats"]},{char:"🙌",name:"raised hands",keywords:["hooray","yay"]},{char:"👋",name:"waving hand",keywords:["hello","bye"]},{char:"✌️",name:"victory hand",keywords:["peace"]},{char:"💪",name:"flexed biceps",keywords:["strong","muscle"]},{char:"🤝",name:"handshake",keywords:["deal","agree"]},{char:"❤️",name:"red heart",keywords:["love"]},{char:"🔥",name:"fire",keywords:["hot","lit"]},{char:"⭐",name:"star",keywords:["favorite"]},{char:"✨",name:"sparkles",keywords:["shiny","magic"]},{char:"🎉",name:"party popper",keywords:["celebrate","congrats"]},{char:"🎊",name:"confetti ball",keywords:["celebrate"]},{char:"💡",name:"light bulb",keywords:["idea","tip"]},{char:"✅",name:"check mark",keywords:["done","yes","complete"]},{char:"❌",name:"cross mark",keywords:["no","wrong","delete"]},{char:"⚠️",name:"warning",keywords:["caution","alert"]},{char:"❓",name:"question mark",keywords:["question","help"]},{char:"❗",name:"exclamation mark",keywords:["important","alert"]},{char:"🚀",name:"rocket",keywords:["launch","fast","ship"]},{char:"🐛",name:"bug",keywords:["bug","issue"]},{char:"🔧",name:"wrench",keywords:["fix","tool","settings"]},{char:"📌",name:"pushpin",keywords:["pin","note"]},{char:"📎",name:"paperclip",keywords:["attachment","clip"]},{char:"📅",name:"calendar",keywords:["date","schedule"]},{char:"⏰",name:"alarm clock",keywords:["time","reminder"]},{char:"📈",name:"chart increasing",keywords:["growth","stats"]},{char:"📉",name:"chart decreasing",keywords:["decline","stats"]},{char:"💰",name:"money bag",keywords:["money","cash"]},{char:"💬",name:"speech balloon",keywords:["comment","chat"]},{char:"📝",name:"memo",keywords:["note","write"]},{char:"📚",name:"books",keywords:["reading","docs"]},{char:"🔗",name:"link",keywords:["url","chain"]},{char:"🔒",name:"locked",keywords:["private","secure"]},{char:"🔑",name:"key",keywords:["password","access"]},{char:"☕",name:"coffee",keywords:["coffee","break"]},{char:"🍕",name:"pizza",keywords:["food"]},{char:"🎂",name:"birthday cake",keywords:["birthday","cake"]},{char:"🎁",name:"gift",keywords:["present"]},{char:"🌟",name:"glowing star",keywords:["star","shiny"]},{char:"🌈",name:"rainbow",keywords:["colorful"]},{char:"☀️",name:"sun",keywords:["sunny","weather"]},{char:"🌧️",name:"rain cloud",keywords:["rainy","weather"]},{char:"🐶",name:"dog face",keywords:["dog","pet"]},{char:"🐱",name:"cat face",keywords:["cat","pet"]},{char:"🌍",name:"globe",keywords:["world","earth"]},{char:"🎯",name:"direct hit",keywords:["target","goal"]},{char:"🏆",name:"trophy",keywords:["win","award"]},{char:"🕐",name:"clock",keywords:["time"]},{char:"📣",name:"megaphone",keywords:["announce","shout"]},{char:"🧠",name:"brain",keywords:["smart","idea","mind"]},{char:"👀",name:"eyes",keywords:["look","watching"]}];function Wm(t,{runId:e,sliceStart:n,sliceEnd:r},o){const s=t.getRun(e),a=(s==null?void 0:s.value)??"",i=a.slice(0,n)+o+a.slice(r);t.applyOperation(de(e,{value:i})),Ze(e,n+o.length)}const qm=Km.map(({char:t,name:e,keywords:n})=>({label:`${t} ${e}`,keywords:n,run:(r,o)=>Wm(r,o,t)})),Xm=/(^|\s):(\w*)$/,Gm=()=>qm;function yc(t){return ls(t,Xm,Gm)}const Jm=/(^|\s)@(\w*)$/;function kc(t){const e=Ke(),n=p.useCallback(()=>(e==null?void 0:e.listAtCommands())??[],[e]);return ls(t,Jm,n)}function is(t,e,n,r,o){const[s,a]=p.useState(!1),i=p.useCallback(y=>{const k=e==="same-block"?sn(t,n.blockId,n,y):pr(t,r,y);return k&&ye(k),k},[t,e,n,r]),d=p.useCallback(y=>{const k=e==="same-block"?ss(t,n.blockId,n,y):as(t,r,y);k&&ye(k)},[t,e,n,r]),c=p.useCallback(y=>{const k=y==="subscript"?"superscript":"subscript",v=!o[y];i({[y]:v?!0:null,[k]:null})},[o,i]),f=p.useRef(null),u=p.useCallback(()=>{f.current={kind:e,selection:n,crossSelection:r},a(!0)},[e,n,r]),h=p.useCallback(()=>a(!1),[]),m=p.useCallback(y=>{const k=f.current;if(!k)return;const v=k.kind==="same-block"?sn(t,k.selection.blockId,k.selection,y):pr(t,k.crossSelection,y);v&&ye(v),a(!1)},[t]),g=p.useCallback((y,k)=>m({link:{href:y,target:k}}),[m]),x=p.useCallback(()=>m({link:null}),[m]);return{applyPatch:i,toggleBoolean:d,setSubSuper:c,isLinkModalOpen:s,openLinkModal:u,closeLinkModal:h,handleSaveLink:g,handleRemoveLink:x}}const Zm="be-touch-input";function Qm(){var t,e;return typeof window<"u"&&((e=(t=window.matchMedia)==null?void 0:t.call(window,"(pointer: coarse)"))==null?void 0:e.matches)===!0}function cs(){const[t,e]=p.useState(Qm);return p.useEffect(()=>{if(typeof window>"u")return;const n=r=>{e(r.pointerType==="touch"||r.pointerType==="pen")};return window.addEventListener("pointerdown",n,{passive:!0}),()=>window.removeEventListener("pointerdown",n)},[]),p.useEffect(()=>{var n;(n=document.documentElement)==null||n.classList.toggle(Zm,t)},[t]),t}const eb=[{markName:"bold",Icon:Ya,title:"Bold (Ctrl+B)"},{markName:"italic",Icon:Ka,title:"Italic (Ctrl+I)"},{markName:"underline",Icon:Wa,title:"Underline (Ctrl+U)"},{markName:"strike",Icon:su,title:"Strikethrough"}],tb=[{label:"Default",value:null},{label:"Red",value:"#e03131"},{label:"Orange",value:"#e8590c"},{label:"Green",value:"#2f9e44"},{label:"Blue",value:"#1971c2"},{label:"Purple",value:"#9c36b5"}],nb=[{label:"None",value:null},{label:"Yellow",value:"#fff3bf"},{label:"Green",value:"#d3f9d8"},{label:"Blue",value:"#d0ebff"},{label:"Pink",value:"#ffdeeb"},{label:"Gray",value:"#e9ecef"}];function vc({isOpen:t,rect:e,kind:n,selection:r,crossSelection:o,marks:s,store:a,onComment:i,commentAuthorId:d}){var K,Q;const c=cs(),[f,u]=p.useState(null),[h,m]=p.useState(null),g=p.useRef(null),{applyPatch:x,toggleBoolean:y,setSubSuper:k,isLinkModalOpen:v,openLinkModal:w,closeLinkModal:B,handleSaveLink:I,handleRemoveLink:C}=is(a,n,r,o,s),R=p.useRef(null);R.current=h;function E(){var D,F,re,H;(F=(D=document.activeElement)==null?void 0:D.blur)==null||F.call(D),(H=(re=window.getSelection)==null?void 0:re.call(window))==null||H.removeAllRanges()}function T(){if(!r)return;const D=_(),F=Lo(a,r,D);F&&a.applyOperation(F),m({commentId:D}),u("comment")}function O(){const D=R.current;if(D){for(const F of Ao(a,D.commentId))a.applyOperation(F);m(null),E()}}function S(D){!h||!r||(a.applyOperation(Cn({id:h.commentId,blockId:r.blockId,anchorRunIds:[r.startRunId,r.endRunId],resolved:!1,messages:[{id:_(),authorId:d,text:D,createdAt:Date.now()}]})),m(null),u(null),E())}function L(){O(),u(null)}p.useEffect(()=>{if(!t||n!=="same-block"||!(i||d))return;const D=F=>{(F.metaKey||F.ctrlKey)&&F.altKey&&F.code==="KeyM"&&(F.preventDefault(),i?i(r):T())};return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},[t,n,i,d,r]),p.useEffect(()=>{if(!f)return;const D=re=>{g.current&&!g.current.contains(re.target)&&(O(),u(null))},F=re=>{re.key==="Escape"&&(O(),u(null))};return document.addEventListener("mousedown",D),document.addEventListener("keydown",F),()=>{document.removeEventListener("mousedown",D),document.removeEventListener("keydown",F)}},[f]),p.useEffect(()=>{O(),u(null)},[e,n]);const $=Ql(g,!!(t&&e),e?e.left+e.width/2:null);if(c||(!t||!e)&&!v)return null;const Y=!i&&f==="comment";return l.jsxs(l.Fragment,{children:[t&&e&&$!=null&&Y&&l.jsxs("div",{ref:g,className:"be-floating-toolbar be-floating-toolbar-comment-standalone",role:"dialog","aria-label":"Add comment",style:{position:"fixed",top:e.top-44,left:$,transform:"translateX(-50%)"},onMouseDown:D=>{D.target.tagName!=="TEXTAREA"&&D.preventDefault()},children:[l.jsx(jl,{title:"Add comment",onClose:L}),l.jsx(Do,{authorId:d,autoFocus:!0,onSubmit:S,onCancel:L})]}),t&&e&&$!=null&&!Y&&l.jsxs("div",{ref:g,className:"be-floating-toolbar",role:"toolbar","aria-label":"Text formatting",style:{position:"fixed",top:e.top-44,left:$,transform:"translateX(-50%)"},onMouseDown:D=>{D.target.tagName!=="TEXTAREA"&&D.preventDefault()},children:[eb.map(({markName:D,Icon:F,title:re})=>l.jsx("button",{type:"button",className:`be-floating-toolbar-btn${s[D]?" be-floating-toolbar-btn-active":""}`,title:re,"aria-label":re,"aria-pressed":!!s[D],onClick:()=>y(D),children:l.jsx(F,{})},D)),l.jsx("button",{type:"button",className:`be-floating-toolbar-btn${s.subscript?" be-floating-toolbar-btn-active":""}`,title:"Subscript","aria-pressed":!!s.subscript,onClick:()=>k("subscript"),children:"X₂"}),l.jsx("button",{type:"button",className:`be-floating-toolbar-btn${s.superscript?" be-floating-toolbar-btn-active":""}`,title:"Superscript","aria-pressed":!!s.superscript,onClick:()=>k("superscript"),children:"X²"}),l.jsx("span",{className:"be-floating-toolbar-divider"}),l.jsxs("div",{className:"be-floating-toolbar-picker-wrap",children:[l.jsx("button",{type:"button",className:"be-floating-toolbar-btn",title:"Text color","aria-haspopup":"true","aria-expanded":f==="color",onClick:()=>u(D=>D==="color"?null:"color"),children:l.jsx("span",{style:{color:s.color||"inherit",fontWeight:700},children:"A"})}),f==="color"&&l.jsx("div",{className:"be-floating-toolbar-picker",role:"menu","aria-label":"Text color",children:tb.map(D=>l.jsx("button",{type:"button",role:"menuitem",className:"be-floating-toolbar-swatch",title:D.label,onClick:()=>{x({color:D.value}),u(null)},children:l.jsx("span",{style:{color:D.value||"#1a1a1a",fontWeight:700},children:"A"})},D.label))})]}),l.jsxs("div",{className:"be-floating-toolbar-picker-wrap",children:[l.jsx("button",{type:"button",className:"be-floating-toolbar-btn",title:"Highlight","aria-haspopup":"true","aria-expanded":f==="highlight",onClick:()=>u(D=>D==="highlight"?null:"highlight"),children:l.jsx("span",{style:{backgroundColor:s.highlight||"transparent",padding:"0 2px",borderRadius:2},children:"H"})}),f==="highlight"&&l.jsx("div",{className:"be-floating-toolbar-picker",role:"menu","aria-label":"Highlight color",children:nb.map(D=>l.jsx("button",{type:"button",role:"menuitem",className:"be-floating-toolbar-swatch",style:{backgroundColor:D.value||"transparent"},title:D.label,onClick:()=>{x({highlight:D.value}),u(null)}},D.label))})]}),l.jsx("span",{className:"be-floating-toolbar-divider"}),l.jsx("button",{type:"button",className:`be-floating-toolbar-btn${s.link?" be-floating-toolbar-btn-active":""}`,title:"Link","aria-label":"Link","aria-pressed":!!s.link,onClick:w,children:l.jsx(Xa,{})}),(i||d)&&n==="same-block"&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"be-floating-toolbar-divider"}),l.jsx("button",{type:"button",className:"be-floating-toolbar-btn",title:"Comment (Ctrl+Alt+M)","aria-label":"Comment",onClick:()=>i?i(r):T(),children:l.jsx(Ga,{})})]})]}),l.jsx(Sl,{isOpen:v,initialHref:((K=s.link)==null?void 0:K.href)??"",initialTarget:((Q=s.link)==null?void 0:Q.target)??"_self",hasExistingLink:!!s.link,onSave:I,onRemove:C,onClose:B})]})}function wc(t){const e=G(),[n,r]=p.useState(null);return p.useEffect(()=>{const o=t.current;if(!o)return;const s=()=>{var f,u,h,m,g;if((u=(f=document.activeElement)==null?void 0:f.closest)!=null&&u.call(f,".be-floating-toolbar"))return;const a=(h=window.getSelection)==null?void 0:h.call(window);if(!a||a.rangeCount===0||a.isCollapsed){r(null);return}if(!o.contains(a.anchorNode)||!o.contains(a.focusNode)){r(null);return}const i=((g=(m=a.getRangeAt(0)).getBoundingClientRect)==null?void 0:g.call(m))??{top:0,left:0,right:0,bottom:0,width:0,height:0},d=ln();if(d){r({kind:"same-block",rect:i,selection:d,marks:rs(e,d.blockId,d)});return}const c=rn(e);if(c){r({kind:"cross-block",rect:i,crossSelection:c,marks:os(e,c)});return}r(null)};return document.addEventListener("selectionchange",s),window.addEventListener("scroll",s,!0),window.addEventListener("resize",s),()=>{document.removeEventListener("selectionchange",s),window.removeEventListener("scroll",s,!0),window.removeEventListener("resize",s)}},[t,e]),{isOpen:!!n,rect:(n==null?void 0:n.rect)??null,kind:(n==null?void 0:n.kind)??null,selection:(n==null?void 0:n.selection)??null,crossSelection:(n==null?void 0:n.crossSelection)??null,marks:(n==null?void 0:n.marks)??{},close:()=>r(null)}}function rb({store:t,rootId:e,onComment:n,commentAuthorId:r}){const o=p.useRef(null),{onCopy:s,onCut:a,onPaste:i}=dc(),d=xc(o),c=yc(o),f=kc(o),u=wc(o);return bc(o),gc(o),l.jsxs("div",{ref:o,role:"document","aria-label":"Document editor",onCopy:s,onCut:a,onPaste:i,children:[l.jsx(lc,{}),l.jsx(mt,{parentId:e,isTopLevel:!0}),l.jsx(nc,{}),l.jsx(sr,{isOpen:d.isOpen,rect:d.rect,commands:d.commands,runId:d.runId,onSelect:d.selectCommand,onClose:d.close}),l.jsx(sr,{isOpen:c.isOpen,rect:c.rect,commands:c.commands,runId:c.runId,onSelect:c.selectCommand,onClose:c.close,menuId:"be-emoji-menu",ariaLabel:"Emoji"}),l.jsx(sr,{isOpen:f.isOpen,rect:f.rect,commands:f.commands,runId:f.runId,onSelect:f.selectCommand,onClose:f.close,menuId:"be-at-menu",ariaLabel:"Mention"}),l.jsx(vc,{isOpen:u.isOpen,rect:u.rect,kind:u.kind,selection:u.selection,crossSelection:u.crossSelection,marks:u.marks,store:t,onComment:n,commentAuthorId:r})]})}function ob({editor:t,className:e,style:n,theme:r,getBlockClassName:o,onComment:s,commentAuthorId:a,showCommentsPanel:i,children:d}){const{store:c,registry:f,inlineRegistry:u}=t,h=c.getRootId();return l.jsxs(Ha,{store:c,registry:f,inlineRegistry:u,history:c,className:e,style:n,theme:r,getBlockClassName:o,commentAuthorId:a,children:[l.jsx(rb,{store:c,rootId:h,onComment:s,commentAuthorId:a}),i&&l.jsx(bl,{authorId:a}),d]})}const sb="$fieldTypes";function Ic(){const t=G(),e=p.useCallback(r=>t.subscribe(sb,r),[t]),n=p.useCallback(()=>t.getFieldTypes(),[t]);return p.useSyncExternalStore(e,n)}const ab={canUndo:!1,canRedo:!1};function Cc(){const{history:t}=$e(),e=p.useCallback(o=>t?t.subscribeToHistory(o):()=>{},[t]),n=p.useCallback(()=>t?t.getUndoRedoSnapshot():ab,[t]),r=p.useSyncExternalStore(e,n);return t?{...r,undo:()=>{const o=t.undo();return o&&an(t),o},redo:()=>{const o=t.redo();return o&&an(t),o},getHistoryLog:()=>t.getHistoryLog()}:null}function lb({store:t,docId:e,debounceMs:n,onError:r}){const[o,s]=p.useState(!1);return p.useEffect(()=>{let a=!1;s(!1),Ea(e).then(c=>{if(!a&&c){const f=t.store??t;f.blocks=new Map((c.blocks??[]).map(u=>[u.id,u])),f.runs=new Map((c.runs??[]).map(u=>[u.id,u])),f.rootId=c.rootId??null,f.fieldTypes=new Map((c.fieldTypes??[]).map(u=>[u.id,u])),f._fieldTypesSnapshot=null,f._orders=new Map,f._notify([...f.blocks.keys(),...f.runs.keys()])}}).catch(c=>r==null?void 0:r(c)).finally(()=>{a||s(!0)});const{stop:i,flush:d}=Na({store:t,docId:e,debounceMs:n,onError:r});return()=>{a=!0,d(),i()}},[e]),{isLoaded:o}}function ib(t){const[e,n]=p.useState(()=>(t==null?void 0:t.getPresence())??new Map);return p.useEffect(()=>{if(!t){n(new Map);return}return n(t.getPresence()),t.onPresenceChange(n)},[t]),e}function cb(){const[t,e]=p.useState(!1),[n,r]=p.useState(null);p.useEffect(()=>{if(!navigator.serviceWorker)return;let s=!1;function a(i){if(!i)return;const d=()=>{i.waiting&&(r(i.waiting),e(!0))};d(),i.addEventListener("updatefound",()=>{const c=i.installing;c&&c.addEventListener("statechange",()=>{c.state==="installed"&&navigator.serviceWorker.controller&&d()})})}return navigator.serviceWorker.getRegistration().then(i=>{s||a(i)}),()=>{s=!0}},[]);const o=p.useCallback(()=>{if(!n)return;const s=()=>window.location.reload();navigator.serviceWorker.addEventListener("controllerchange",s,{once:!0}),n.postMessage({type:"SKIP_WAITING"})},[n]);return{updateAvailable:t,applyUpdate:o}}const Sc=[{phrases:["new paragraph","next paragraph"],description:"Start a new paragraph",action:{type:"insertParagraph"}},{phrases:["heading one","heading 1"],description:"Convert the current block to a heading 1",action:{type:"convertBlock",blockType:"heading",props:{level:1}}},{phrases:["heading two","heading 2"],description:"Convert the current block to a heading 2",action:{type:"convertBlock",blockType:"heading",props:{level:2}}},{phrases:["heading three","heading 3"],description:"Convert the current block to a heading 3",action:{type:"convertBlock",blockType:"heading",props:{level:3}}},{phrases:["bulleted list","bullet point","bullet list"],description:"Convert the current block to a bulleted list item",action:{type:"convertBlock",blockType:"listItem",props:{ordered:!1,titleRunIds:[]}}},{phrases:["numbered list","ordered list"],description:"Convert the current block to a numbered list item",action:{type:"convertBlock",blockType:"listItem",props:{ordered:!0,titleRunIds:[]}}},{phrases:["checklist","to-do","to do","to-do list","to do list"],description:"Convert the current block to a to-do item",action:{type:"convertBlock",blockType:"listItem",props:{ordered:!1,checked:!1,titleRunIds:[]}}},{phrases:["quote"],description:"Convert the current block to a quote",action:{type:"convertBlock",blockType:"blockquote",props:{}}},{phrases:["code block","code"],description:"Convert the current block to a code block",action:{type:"convertBlock",blockType:"code",props:{language:"plaintext"}}},{phrases:["undo"],description:"Undo the last edit",action:{type:"undo"}},{phrases:["redo"],description:"Redo the last undone edit",action:{type:"redo"}},{phrases:["stop dictation","stop listening","stop"],description:"Stop dictation",action:{type:"stopDictation"}}],jc=new Map;for(const{phrases:t,action:e}of Sc)for(const n of t)jc.set(n,e);function db(t){return(t??"").toLowerCase().trim().replace(/\s+/g," ").replace(/[.,!?]+$/,"")}function ub(t){return jc.get(db(t))??null}function pb(){return Sc.map(({phrases:t,description:e})=>({phrases:[...t],description:e}))}function fb(t,e){if(typeof t.performBatch=="function")t.performBatch(e);else for(const n of e)t.applyOperation(n)}function hb(t){var e;return((e=t==null?void 0:t.props)==null?void 0:e.titleRunIds)??(t==null?void 0:t.contentIds)??[]}function mb(t,e,n){var r,o;if(n.type==="insertParagraph"){nt(t,e,te("paragraph"));return}if(n.type==="convertBlock"){const s=t.getBlock(e);if(!s)return;const a=hb(s),{ops:i}=zo(t,e,n.blockType,n.props,a);fb(t,i),a[0]&&xr(a[0]);return}if(n.type==="undo"){(r=t.undo)!=null&&r.call(t)&&an(t);return}n.type==="redo"&&(o=t.redo)!=null&&o.call(t)&&an(t)}function ka(){return typeof window>"u"?null:window.SpeechRecognition??window.webkitSpeechRecognition??null}const bb="Microphone access is blocked. Enable it in your browser's site settings, then try again.";function gb({shortcut:t=!0}={}){const e=G(),[n,r]=p.useState(!1),[o,s]=p.useState("idle"),[a,i]=p.useState("unknown"),[d,c]=p.useState(null),f=p.useRef(null),u=p.useRef(null),h=p.useRef(null),m=p.useRef(0),g=ka()!==null;p.useEffect(()=>{var R;if(!((R=navigator.permissions)!=null&&R.query))return;let I,C=!1;return navigator.permissions.query({name:"microphone"}).then(E=>{C||(I=E,i(E.state),I.onchange=()=>i(I.state))}).catch(()=>{}),()=>{C=!0,I&&(I.onchange=null)}},[]);const x=p.useCallback(()=>{if(!u.current){const I=lt();if(!I)return null;u.current=I}return{runId:u.current.runId,blockId:u.current.blockId,startOffset:u.current.offset,insertedLength:0}},[]),y=p.useCallback((I,C)=>{const R=e.getRun(I.runId);if(!R||R.type!=="text")return;const E=R.value??"",T=E.slice(0,I.startOffset);if(I.needsLeadingSpace===void 0){const L=T[T.length-1];I.needsLeadingSpace=I.startOffset>0&&L!==void 0&&!/\s/.test(L)}const O=(I.needsLeadingSpace?" ":"")+C,S=E.slice(I.startOffset+I.insertedLength);De.flushSync(()=>e.applyOperation(de(I.runId,{value:T+O+S}))),I.insertedLength=O.length,Vs(I.runId,I.startOffset+O.length),u.current={runId:I.runId,blockId:I.blockId,offset:I.startOffset+O.length}},[e]),k=p.useCallback(I=>{const C=e.getRun(I.runId);if(!C||C.type!=="text")return;const R=C.value??"",E=R.slice(0,I.startOffset)+R.slice(I.startOffset+I.insertedLength);De.flushSync(()=>e.applyOperation(de(I.runId,{value:E}))),Vs(I.runId,I.startOffset),u.current={runId:I.runId,blockId:I.blockId,offset:I.startOffset}},[e]),v=p.useCallback(I=>{var T,O;let C="",R=!1;const E=Math.max(I.resultIndex,m.current);for(let S=E;S<I.results.length;S+=1){const L=I.results[S],$=((T=L[0])==null?void 0:T.transcript)??"";if(!L.isFinal){C+=(C?" ":"")+$,R=!0;continue}const Y=h.current??x();if(h.current=null,m.current=S+1,!Y)continue;const K=ub($);K?(k(Y),K.type==="stopDictation"?(O=f.current)==null||O.stop():(mb(e,Y.blockId,K),u.current=null,s("listening"))):(y(Y,$),s("listening"))}if(R){const S=h.current??x();S&&(h.current=S,y(S,C))}},[e,x,y,k]),w=p.useCallback(()=>{if(!g||f.current)return;c(null),u.current=lt(),h.current=null,m.current=0;const I=ka(),C=new I;C.continuous=!0,C.interimResults=!0,C.onresult=v,C.onstart=()=>s("listening"),C.onspeechstart=()=>s("listening"),C.onspeechend=()=>s("processing"),C.onerror=R=>{R.error==="not-allowed"||R.error==="service-not-allowed"?(i("denied"),c(bb)):c(R.error??"Voice typing stopped unexpectedly.")},C.onend=()=>{f.current=null,u.current=null,h.current=null,m.current=0,r(!1),s("idle")},f.current=C,C.start(),r(!0)},[g,v]),B=p.useCallback(()=>{var I;(I=f.current)==null||I.stop()},[]);return p.useEffect(()=>()=>{var I;return(I=f.current)==null?void 0:I.stop()},[]),p.useEffect(()=>{if(!t||!g)return;const I=C=>{!(C.metaKey||C.ctrlKey)||!C.shiftKey||C.key.toLowerCase()!=="m"||(C.preventDefault(),f.current?B():w())};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[t,g,w,B]),{isSupported:g,isListening:n,status:o,permissionState:a,error:d,start:w,stop:B}}function xb({voice:t}){const[e,n]=p.useState(!1);p.useEffect(()=>{n(!1)},[t==null?void 0:t.error]);const r=(t==null?void 0:t.permissionState)==="denied"&&!e;return l.jsxs(pt,{isOpen:r,onClose:()=>n(!0),title:"Microphone access blocked",children:[l.jsx("p",{children:(t==null?void 0:t.error)||"Microphone access is blocked. Enable it in your browser's site settings, then try again."}),l.jsxs("div",{className:"be-modal-actions",children:[l.jsx("button",{type:"button",className:"be-modal-cancel",onClick:()=>n(!0),children:"Dismiss"}),l.jsx("button",{type:"button",className:"be-modal-save",onClick:()=>{var o;return(o=t==null?void 0:t.start)==null?void 0:o.call(t)},children:"Try again"})]})]})}function Rc(t){const[e,n]=p.useState(null);return p.useEffect(()=>{if(!t){n(null);return}const r=()=>{var d,c,f,u;const o=(d=window.getSelection)==null?void 0:d.call(window);if(!o||o.rangeCount===0||!o.isCollapsed){n(null);return}const s=o.anchorNode,a=(s==null?void 0:s.nodeType)===1?s:s==null?void 0:s.parentElement;if(!((c=a==null?void 0:a.closest)!=null&&c.call(a,"[data-run-id]"))){n(null);return}const i=((u=(f=o.getRangeAt(0)).getBoundingClientRect)==null?void 0:u.call(f))??{top:0,left:0,right:0,bottom:0,width:0,height:0};n(i)};return r(),document.addEventListener("selectionchange",r),window.addEventListener("scroll",r,!0),window.addEventListener("resize",r),()=>{document.removeEventListener("selectionchange",r),window.removeEventListener("scroll",r,!0),window.removeEventListener("resize",r)}},[t]),e}function yb({voice:t}){const e=!!(t!=null&&t.isListening),n=Rc(e),r=p.useRef(null),o=Ql(r,!!(e&&n),n==null?void 0:n.left);if(!e||!n||o==null)return null;const s=t.status==="processing";return De.createPortal(l.jsxs("div",{ref:r,className:`be-voice-indicator${s?" be-voice-indicator-processing":""}`,contentEditable:!1,style:{position:"fixed",top:n.top-8,left:o,transform:"translate(-50%, -100%)"},children:[l.jsx("span",{className:"be-voice-indicator-dot"}),l.jsx(Su,{size:12}),l.jsx("span",{className:"be-voice-indicator-label",children:s?"Processing…":"Listening…"})]}),document.body)}function Tc({isOpen:t,onClose:e,onSelectCommand:n}){const r=dt(),o=Ke(),s=p.useMemo(()=>[...(r==null?void 0:r.listSlashCommands())??[],...(o==null?void 0:o.listSlashCommands())??[]],[r,o]);return l.jsx(pt,{isOpen:t,onClose:e,title:"Add a block",variant:"sheet",children:l.jsx("div",{className:"be-mobile-picker-list",role:"listbox","aria-label":"Insertable blocks",children:s.map(a=>{const i=a.icon;return l.jsxs("button",{type:"button",role:"option",className:"be-mobile-picker-item",onClick:()=>n(a),children:[i&&l.jsx("span",{className:"be-mobile-picker-item-icon",children:l.jsx(i,{size:18})}),l.jsx("span",{className:"be-mobile-picker-item-label",children:a.label})]},a.label)})})})}function Ec({isOpen:t,onClose:e,store:n,blockId:r}){var i;const o=r?n.getBlock(r):null,s=!!((i=o==null?void 0:o.props)!=null&&i.hidden),a=p.useCallback(d=>{d(),e()},[e]);return l.jsx(pt,{isOpen:t,onClose:e,title:"Block options",variant:"sheet",children:l.jsxs("div",{className:"be-mobile-picker-list",role:"menu","aria-label":"Block options",children:[l.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{Vo(n,r),xe("Block duplicated")}),children:[l.jsx("span",{className:"be-mobile-picker-item-icon",children:l.jsx(To,{size:18})}),l.jsx("span",{className:"be-mobile-picker-item-label",children:"Duplicate"})]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{Yo(n,r)&&xe("Block moved up")}),children:[l.jsx("span",{className:"be-mobile-picker-item-icon",children:l.jsx(br,{size:18})}),l.jsx("span",{className:"be-mobile-picker-item-label",children:"Move up"})]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{Ko(n,r)&&xe("Block moved down")}),children:[l.jsx("span",{className:"be-mobile-picker-item-icon",children:l.jsx(gr,{size:18})}),l.jsx("span",{className:"be-mobile-picker-item-label",children:"Move down"})]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item",onClick:()=>a(()=>{n.applyOperation(J(r,{hidden:!s})),xe(s?"Block shown in preview":"Block hidden in preview")}),children:[l.jsx("span",{className:"be-mobile-picker-item-icon",children:s?l.jsx(Mo,{size:18}):l.jsx(Oo,{size:18})}),l.jsx("span",{className:"be-mobile-picker-item-label",children:s?"Show in preview":"Hide in preview"})]}),l.jsxs("button",{type:"button",role:"menuitem",className:"be-mobile-picker-item be-mobile-picker-item-danger",onClick:()=>a(()=>{Ir(n,r),xe("Block deleted")}),children:[l.jsx("span",{className:"be-mobile-picker-item-icon",children:l.jsx(On,{size:18})}),l.jsx("span",{className:"be-mobile-picker-item-label",children:"Delete"})]})]})})}const kb=fi.map(t=>({value:t,label:t}));function vb(t,e){const[n,r]=p.useState(!1),[o,s]=p.useState(null),[a,i]=p.useState(null),[d,c]=p.useState(null);return p.useEffect(()=>{const f=t.current;if(!f)return;const u=()=>r(!0),h=m=>{f.contains(m.relatedTarget)||r(!1)};return f.addEventListener("focusin",u),f.addEventListener("focusout",h),()=>{f.removeEventListener("focusin",u),f.removeEventListener("focusout",h)}},[t]),p.useEffect(()=>{if(!n){s(null);return}const f=()=>{var g;const u=t.current,h=(g=window.getSelection)==null?void 0:g.call(window);if(!u||!h||h.rangeCount===0){s(null);return}if(!h.isCollapsed){if(!u.contains(h.anchorNode)||!u.contains(h.focusNode)){s(null);return}const x=ln();if(x){i({kind:"same-block",selection:x,crossSelection:null,marks:rs(e,x.blockId,x)}),s("selection");return}const y=rn(e);if(y){i({kind:"cross-block",selection:null,crossSelection:y,marks:os(e,y)}),s("selection");return}s(null);return}const m=lt();if(!m||!u.contains(h.anchorNode)){s(null);return}c(m),s("caret")};return f(),document.addEventListener("selectionchange",f),()=>document.removeEventListener("selectionchange",f)},[n,e,t]),{isFocused:n,mode:o,selectionState:a,caretState:d}}function wb({store:t,selectionState:e}){const{kind:n,selection:r,crossSelection:o,marks:s}=e,{toggleBoolean:a,openLinkModal:i}=is(t,n,r,o,s);return l.jsxs(l.Fragment,{children:[l.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.bold?" be-mobile-bar-btn-active":""}`,"aria-label":"Bold",onClick:()=>a("bold"),children:l.jsx(Ya,{size:18})}),l.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.italic?" be-mobile-bar-btn-active":""}`,"aria-label":"Italic",onClick:()=>a("italic"),children:l.jsx(Ka,{size:18})}),l.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.underline?" be-mobile-bar-btn-active":""}`,"aria-label":"Underline",onClick:()=>a("underline"),children:l.jsx(Wa,{size:18})}),l.jsx("button",{type:"button",className:`be-mobile-bar-btn${s.link?" be-mobile-bar-btn-active":""}`,"aria-label":"Link",onClick:i,children:l.jsx(Xa,{size:18})})]})}function Ib({store:t,blockId:e}){const n=p.useCallback(()=>{const o=t.getBlock(e),s=o&&t.getBlock(o.parentId);s&&qo(t,s.id)},[t,e]),r=p.useCallback(()=>{const o=t.getBlock(e),s=o&&t.getBlock(o.parentId),a=s&&t.getBlock(s.parentId);if(!a||!s)return;const i=s.contentIds.indexOf(e);i!==-1&&ir(t,a.id,i)},[t,e]);return l.jsxs(l.Fragment,{children:[l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Insert row below",onClick:n,children:"+ Row"}),l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Insert column right",onClick:r,children:"+ Column"})]})}function Cb({store:t,blockId:e}){var o;const n=t.getBlock(e),r=p.useCallback(s=>t.applyOperation(J(e,{language:s})),[t,e]);return l.jsx(Mt,{className:"be-mobile-bar-select",value:((o=n==null?void 0:n.props)==null?void 0:o.language)??"plaintext",options:kb,onChange:r,ariaLabel:"Code language"})}function Sb({store:t,blockId:e}){var o;const n=t.getBlock(e),r=(o=n==null?void 0:n.props)==null?void 0:o.color;return l.jsx("div",{className:"be-mobile-bar-swatches",children:di.map(s=>l.jsx("button",{type:"button",className:`be-callout-color-option be-callout-color-option-${s.value}${s.value===r?" be-callout-color-option-active":""}`,"aria-label":s.label,title:s.label,onClick:()=>t.applyOperation(J(e,{color:s.value}))},s.value))})}const Bc={tableCell:Ib,code:Cb,callout:Sb};function jb(t,e){let n=t.getBlock(e);for(;n;){if(Bc[n.type])return n;n=n.parentId?t.getBlock(n.parentId):null}return null}function Rb(t,e){const n=t.getRootId();let r=t.getBlock(e);for(;r&&r.parentId!==n;)r=t.getBlock(r.parentId);return r}function Tb({containerRef:t}){var R,E;const e=G(),n=Cc(),r=cs(),o=Rr(),{isFocused:s,mode:a,selectionState:i,caretState:d}=vb(t,e),[c,f]=p.useState(!1),[u,h]=p.useState(!1),m=p.useCallback(()=>f(!0),[]),g=p.useCallback(()=>f(!1),[]),x=p.useCallback(()=>h(!0),[]),y=p.useCallback(()=>h(!1),[]),k=p.useCallback(T=>{const O=lt()??d;O&&(T.run(e,{blockId:O.blockId,runId:O.runId,sliceStart:O.offset,sliceEnd:O.offset}),g())},[e,d,g]),v=p.useCallback(()=>{var T,O;(O=(T=document.activeElement)==null?void 0:T.blur)==null||O.call(T)},[]);if(!r||!s)return null;const w=a==="caret"&&d?jb(e,d.blockId):null,B=w?Bc[w.type]:null,I=a==="caret"&&d?d.blockId:((R=i==null?void 0:i.selection)==null?void 0:R.blockId)??((E=i==null?void 0:i.crossSelection)==null?void 0:E.startBlockId)??null,C=I?Rb(e,I):null;return l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"be-mobile-action-bar",role:"toolbar","aria-label":"Editor actions",style:{bottom:o},onMouseDown:T=>T.preventDefault(),children:[a==="selection"&&i&&l.jsx(wb,{store:e,selectionState:i}),a!=="selection"&&l.jsxs(l.Fragment,{children:[l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Add block",onClick:m,children:l.jsx(Ro,{size:18})}),B&&w&&l.jsx(B,{store:e,blockId:w.id}),n&&l.jsxs(l.Fragment,{children:[l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Undo",disabled:!n.canUndo,onClick:n.undo,children:"↶"}),l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Redo",disabled:!n.canRedo,onClick:n.redo,children:"↷"})]})]}),l.jsx("span",{className:"be-mobile-bar-spacer"}),C&&l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Block options",onClick:x,children:l.jsx(Qd,{size:18})}),l.jsx("button",{type:"button",className:"be-mobile-bar-btn","aria-label":"Dismiss keyboard",onClick:v,children:l.jsx(mr,{size:18})})]}),l.jsx(Tc,{isOpen:c,onClose:g,onSelectCommand:k}),l.jsx(Ec,{isOpen:u,onClose:y,store:e,blockId:C==null?void 0:C.id})]})}const _c={heading:["level"],listItem:["ordered","checked","collapsed"],toggleHeading:["level","collapsed"],code:["language"],button:["href","color","customAttrs"],embed:["kind","src","name","alt","mimeType","align","width"],callout:["icon"]},Nc=new Set(["listItem","toggleHeading"]),Mc=new Set(["divider","embed"]);function Oc(t,e,n,r){var i,d,c;const o=n.type,s={};for(const f of _c[o]??[])((i=n.props)==null?void 0:i[f])!==void 0&&(s[f]=n.props[f]);if(o==="table"){const f=n.contentIds[0]&&t.getBlock(n.contentIds[0]);return s.columns=ze(n,((d=f==null?void 0:f.contentIds)==null?void 0:d.length)??0),s.rows=n.contentIds.map(u=>t.getBlock(u).contentIds.map(m=>{const g=t.getBlock(m);return Ur(g.contentIds.map(x=>t.getRun(x)),r)})),{id:n.id,type:o,data:s}}if(Nc.has(o)){const f=((c=n.props)==null?void 0:c.titleRunIds)??[];s.text=Ur(f.map(u=>t.getRun(u)),r)}else e.isLeaf(o)&&!Mc.has(o)&&(s.text=Ur(n.contentIds.map(f=>t.getRun(f)),r));const a={id:n.id,type:o,data:s};return e.isLeaf(o)||(a.children=n.contentIds.map(f=>Oc(t,e,t.getBlock(f),r))),a}function Lc(t,e,n,{pretty:r=!0}={}){const o={store:t,registry:e,inlineRegistry:n},a=t.getBlock(t.getRootId()).contentIds.map(i=>Oc(t,e,t.getBlock(i),o));return JSON.stringify({version:1,blocks:a},null,r?2:0)}function fo(t,e){const n=new DOMParser().parseFromString(`<div>${t??""}</div>`,"text/html");return Ye(n.body.firstChild,e)}function Eb(t,e,n,r,o){const{id:s=_(),data:a={}}=t,i=(a.rows??[]).map(c=>{const f=_(),u=c.map(h=>{const m=_(),g=fo(h,o);return r.push(...g),n.push({id:m,type:"tableCell",parentId:f,contentIds:g.map(x=>x.id),props:{}}),m});return n.push({id:f,type:"tableRow",parentId:e,contentIds:u,props:{}}),f}),d={id:s,type:"table",parentId:e,contentIds:i,props:{columns:a.columns??[]}};return n.push(d),d}function ho(t,e,n,r,o,s){const{id:a=_(),type:i,data:d={},children:c=[]}=t;if(i==="table")return Eb(t,e,o,s,r);const f={};for(const h of _c[i]??[])d[h]!==void 0&&(f[h]=d[h]);const u={id:a,type:i,parentId:e,contentIds:[],props:f};if(o.push(u),Nc.has(i)){const h=fo(d.text,r);s.push(...h),u.props.titleRunIds=h.map(m=>m.id),u.contentIds=c.map(m=>ho(m,a,n,r,o,s).id)}else if(n.isLeaf(i)){if(!Mc.has(i)){const h=fo(d.text,r);s.push(...h),u.contentIds=h.map(m=>m.id)}}else u.contentIds=c.map(h=>ho(h,a,n,r,o,s).id);return u}function Bb(t,e,n){const r=typeof t=="string"?JSON.parse(t):t,o={registry:e,inlineRegistry:n},s=_(),a=[],i=[],d=(r.blocks??[]).map(c=>ho(c,s,e,o,a,i).id);return a.push({id:s,type:"page",parentId:null,contentIds:d,props:{}}),{rootId:s,blocks:a,runs:i}}const _b=[{value:"json",label:"JSON"},{value:"simpleJson",label:"Simple JSON"},{value:"html",label:"HTML"},{value:"text",label:"Text"}];function Nb({label:t="View source",className:e=""}){const n=G(),r=dt(),o=Ke(),[s,a]=p.useState(!1),[i,d]=p.useState("json"),[c,f]=p.useState(!1),u=p.useCallback(()=>{f(!1),a(!0)},[]),h=p.useCallback(()=>a(!1),[]),m=p.useMemo(()=>s?i==="json"?wo(n):i==="simpleJson"?Lc(n,r,o):i==="html"?Io(n,r,o):La(n,r,o):"",[s,i,n,r,o]),g=p.useCallback(async()=>{try{await navigator.clipboard.writeText(m),f(!0),setTimeout(()=>f(!1),1500)}catch{}},[m]);return l.jsxs(l.Fragment,{children:[l.jsxs("button",{type:"button",className:`be-export-trigger ${e}`.trim(),onClick:u,children:[l.jsx(_o,{size:14})," ",t]}),l.jsxs(pt,{isOpen:s,onClose:h,title:"Document source",size:"large",children:[l.jsx("div",{className:"be-export-tabs",role:"tablist",children:_b.map(x=>l.jsx("button",{type:"button",role:"tab","aria-selected":i===x.value,className:`be-export-tab${i===x.value?" be-export-tab-active":""}`,onClick:()=>d(x.value),children:x.label},x.value))}),l.jsx("pre",{className:"be-export-pre",children:l.jsx("code",{children:m})}),l.jsxs("div",{className:"be-modal-actions",children:[l.jsx("button",{type:"button",className:"be-modal-cancel",onClick:h,children:"Close"}),l.jsx("button",{type:"button",className:"be-modal-save",onClick:g,children:c?"Copied!":"Copy"})]})]})]})}function Mb({id:t,label:e,placeholder:n,variant:r,options:o,onManage:s,mention:a=!1}){const i=G(),d=It(t),c=p.useCallback((m,g)=>{i.applyOperation(de(t,{data:{selectedValue:m,selectedLabel:(g==null?void 0:g.label)??"",selectedColor:g==null?void 0:g.color}}))},[i,t]);if(!d)return null;const{selectedValue:f="",selectedLabel:u="",selectedColor:h}=d.data??{};return l.jsx("span",{className:"be-inline-select",onMouseDown:m=>{m.preventDefault(),m.stopPropagation()},onKeyDown:m=>m.stopPropagation(),children:l.jsx(Mt,{value:f,selectedLabel:u,selectedColor:h,options:o,onChange:c,placeholder:n,variant:r,ariaLabel:e,onManageOptions:s,mention:a})})}function Ac(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function va(t){return Ac(t).replace(/"/g,"&quot;")}function Dc({type:t,label:e,placeholder:n="Select…",variant:r="default",icon:o,options:s,onManage:a,triggers:i=["slash"],mention:d=i.includes("at")}){function c(g){var k,v;const x=((k=g.data)==null?void 0:k.selectedLabel)||"",y=d&&x?`@${x}`:x;return`<span data-inline-type="${va(t)}" data-selected-value="${va(((v=g.data)==null?void 0:v.selectedValue)??"")}">${Ac(y)}</span>`}function f(g){var y;const x=((y=g.data)==null?void 0:y.selectedLabel)??"";return d&&x?`@${x}`:x}function u(g){var k;if(((k=g.getAttribute)==null?void 0:k.call(g,"data-inline-type"))!==t)return null;const x=g.textContent??"",y=d&&x.startsWith("@")?x.slice(1):x;return{id:_(),type:t,value:"",marks:{},data:{selectedValue:g.getAttribute("data-selected-value")??"",selectedLabel:y}}}function h({id:g}){return l.jsx(Mb,{id:g,label:e,placeholder:n,variant:r,options:s,onManage:a,mention:d})}const m={label:e,icon:o??il,keywords:[e.toLowerCase(),"select","field"],run:(g,{blockId:x,runId:y,sliceStart:k,sliceEnd:v})=>Er(g,{blockId:x,runId:y,sliceStart:k,sliceEnd:v},()=>({id:_(),type:t,value:"",marks:{},data:{selectedValue:"",selectedLabel:"",selectedColor:void 0}}))};return{component:h,isAtomic:!0,toHTML:c,toPlainText:f,fromHTML:u,slashCommand:i.includes("slash")?m:void 0,atCommand:i.includes("at")?m:void 0}}function Pc(t,e,{onManage:n}={}){for(const r of t.getFieldTypes())e.register(r.id,Dc({type:r.id,label:r.label,placeholder:r.placeholder,variant:r.variant,options:r.options??[],onManage:n?()=>n(r.id):void 0}))}function $c(){const t=G(),e=Ke(),n=Ic(),{openEdit:r}=jo(),o=p.useRef([]);p.useEffect(()=>{if(!e)return;const s=new Set(n.map(a=>a.id));for(const a of o.current)s.has(a)||e.unregister(a);Pc(t,e,{onManage:r}),o.current=[...s]},[t,e,n,r])}function Ob(){$c();const t=G(),{target:e,close:n}=jo(),r=e!==null,o=r&&e!=="new",[s,a]=p.useState(""),[i,d]=p.useState([]),[c,f]=p.useState("");p.useEffect(()=>{if(r){if(o){const y=t.getFieldType(e);a((y==null?void 0:y.label)??""),d((y==null?void 0:y.options)??[])}else a(""),d([]);f("")}},[r,o,e,t]);const u=p.useCallback((y,k)=>{d(v=>v.map(w=>w.value===y?{...w,label:k}:w))},[]),h=p.useCallback(y=>{d(k=>k.filter(v=>v.value!==y))},[]),m=p.useCallback(()=>{const y=c.trim();f(""),y&&d(k=>[...k,{value:_(),label:y,color:Tn(k.length)}])},[c]),g=p.useCallback(()=>{const y=s.trim();y&&(o?t.applyOperation(go(e,{label:y,options:i})):t.applyOperation(bo({id:_(),label:y,placeholder:"Select…",variant:"tag",options:i})),n())},[t,o,e,s,i,n]),x=p.useCallback(()=>{o&&t.applyOperation(xo(e)),n()},[t,o,e,n]);return l.jsxs(pt,{isOpen:r,onClose:n,title:o?"Edit field type":"New field type",children:[l.jsxs("label",{className:"be-modal-field",children:[l.jsx("span",{children:"Name"}),l.jsx("input",{type:"text",value:s,onChange:y=>a(y.target.value),placeholder:"e.g. Priority, Status…",autoFocus:!0})]}),l.jsxs("div",{className:"be-modal-field",children:[l.jsx("span",{children:"Options"}),i.map((y,k)=>l.jsxs("div",{className:"be-table-header-menu-option-row",children:[l.jsx("span",{className:"be-table-header-menu-option-swatch",style:{background:(y.color??Tn(k)).bg},"aria-hidden":"true"}),l.jsx("input",{className:"be-table-header-menu-option-input",value:y.label,onChange:v=>u(y.value,v.target.value),"aria-label":`Rename option ${y.label}`}),l.jsx("button",{type:"button",className:"be-table-header-menu-option-remove",onClick:()=>h(y.value),"aria-label":`Remove option ${y.label}`,children:l.jsx(wt,{size:14})})]},y.value)),l.jsxs("div",{className:"be-table-header-menu-option-row",children:[l.jsx("input",{className:"be-table-header-menu-option-input",value:c,onChange:y=>f(y.target.value),placeholder:"New option…",onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),m())}}),l.jsx("button",{type:"button",className:"be-table-header-menu-option-add",onClick:m,"aria-label":"Add option",children:"+"})]})]}),l.jsxs("div",{className:"be-modal-actions",children:[o&&l.jsx("button",{type:"button",className:"be-modal-delete",onClick:x,children:"Delete field type"}),l.jsx("button",{type:"button",className:"be-modal-cancel",onClick:n,children:"Cancel"}),l.jsx("button",{type:"button",className:"be-modal-save",onClick:g,children:"Save"})]})]})}exports.APP_MIME=dr;exports.BlockChildren=mt;exports.BlockErrorBoundary=Ol;exports.BlockGutterRow=$l;exports.BlockRangeActionMenu=lc;exports.BlockRegistry=gl;exports.BlockRenderer=Fo;exports.COLUMN_TYPES=Ul;exports.CollabSession=Ed;exports.CommentAvatar=jn;exports.CommentComposer=Do;exports.CommentThreadCard=Po;exports.CommentsPanel=bl;exports.DEFAULT_COLUMN_TYPE=Cr;exports.DEFAULT_COLUMN_WIDTH=Sr;exports.DocumentExportButton=Nb;exports.EditableBlockContent=ft;exports.EditorProvider=Ha;exports.EditorStore=Bn;exports.EditorTrailingSpace=nc;exports.FieldClockRegistry=en;exports.FieldTypeEditorModal=Ob;exports.FloatingToolbar=vc;exports.HLC=Sn;exports.History=Sa;exports.InlineRegistry=yl;exports.LAYOUT_BLOCKS=Vi;exports.ListCrdtState=Qt;exports.MESSAGE_TYPE=Je;exports.MIN_COLUMN_WIDTH=lr;exports.MobileActionBar=Tb;exports.MobileBlockOptionsSheet=Ec;exports.MobileBlockPickerSheet=Tc;exports.Modal=pt;exports.NoteloomEditor=ob;exports.PeerConnection=Ra;exports.Select=Mt;exports.SlashMenu=sr;exports.TABLE_BLOCKS=Ui;exports.TABLE_SELECT_INLINE_TYPES=tc;exports.TableHeaderRow=ei;exports.TemplatePicker=Yd;exports.VersionHistory=Ru;exports.VoiceListeningIndicator=yb;exports.VoicePermissionModal=xb;exports.addComment=_u;exports.addCommentMarkOverRange=Lo;exports.applyDocumentTemplate=Oa;exports.blankRunForType=Vl;exports.blockquoteBlockType=pi;exports.buttonBlockType=gi;exports.calloutBlockType=ui;exports.canvasBlockType=zi;exports.captureBlockTemplate=Fd;exports.captureSubtree=Nn;exports.checkboxInlineType=Xi;exports.codeBlockType=hi;exports.convertRunToType=Yl;exports.copyBlockRangeToClipboard=io;exports.createAutoPersistence=Na;exports.createAutoVersionHistory=Aa;exports.createBlockRegistry=xl;exports.createCellForColumn=jr;exports.createDefaultColumns=Wo;exports.createInlineRegistry=kl;exports.createPeriodicTombstoneGC=xd;exports.createSelectFieldType=Dc;exports.createWebSocketSignaling=Bd;exports.dateInlineType=qi;exports.decodeMessage=ja;exports.deleteBlockAndFocusSibling=Ir;exports.deleteBlockRange=In;exports.deleteColumn=ql;exports.deleteComment=fl;exports.deleteDocumentVersion=_a;exports.deleteEntireDocument=ur;exports.deleteOverBlockRange=ns;exports.deletePersistedDocument=Md;exports.deleteRow=Wl;exports.deleteRunRangeInBlock=ts;exports.deleteTemplate=Dd;exports.deserializeClipboard=cc;exports.diffDocumentsHTML=Da;exports.dividerBlockType=ci;exports.duplicateBlock=Vo;exports.embedBlockType=vi;exports.emojiInlineType=Zi;exports.encodeMessage=Jt;exports.ensureRootNonEmpty=dn;exports.exportDocumentHTML=Io;exports.exportDocumentJSON=wo;exports.exportDocumentSimpleJSON=Lc;exports.exportDocumentText=La;exports.focusRunAtOffset=Ze;exports.focusRunEnd=ye;exports.focusRunStart=xr;exports.genPeerId=Ia;exports.getMarksSummaryOverBlockRange=os;exports.getMarksSummaryOverSelection=rs;exports.headingBlockType=Ml;exports.importDocumentSimpleJSON=Bb;exports.injectDefaultStyles=$a;exports.insertBlockTemplate=Ma;exports.insertColumnAfter=ir;exports.insertRowAfter=qo;exports.isEntireBlockRangeHidden=sc;exports.isEntireBlockSelected=mc;exports.layoutBlockType=ii;exports.layoutColumnBlockType=li;exports.listDocumentVersions=ar;exports.listItemBlockType=Fl;exports.listPersistedDocumentIds=Od;exports.listTemplates=to;exports.listVoiceCommands=pb;exports.loadDocumentVersion=Pd;exports.loadPersistedDocument=Ea;exports.loadTemplate=Ad;exports.moveBlockDown=Ko;exports.moveBlockRangeDown=oc;exports.moveBlockRangeUp=rc;exports.moveBlockUp=Yo;exports.operations=pd;exports.paragraphBlockType=Nl;exports.registerBlockTemplates=Ud;exports.registerBlocks=Fi;exports.registerBuiltInBlocks=Hi;exports.registerBuiltInInlineTypes=Qi;exports.registerInlineTypes=ec;exports.registerStoredFieldTypes=Pc;exports.remapSubtreeIds=fr;exports.removeCommentMarkEverywhere=Ao;exports.renameColumn=Gl;exports.reorderBlockRangeFromStore=jm;exports.replyToComment=ul;exports.resolveCollapsedCaret=lt;exports.resolveColumns=ze;exports.resolveComment=pl;exports.resolveCrossBlockSelection=rn;exports.resolveMultiRunSelection=ln;exports.resolveRunSelection=Xu;exports.saveDocumentVersion=Ba;exports.savePersistedDocument=Ta;exports.saveTemplate=Ld;exports.selectInlineType=Ki;exports.serializeBlockRange=_n;exports.setBlockRangeHidden=ac;exports.setColumnOptions=tr;exports.setColumnType=Jl;exports.setColumnWidth=Xl;exports.setMarksOverBlockRange=pr;exports.setMarksOverSelection=sn;exports.tableBlockType=oi;exports.tableCellBlockType=ni;exports.tableRowBlockType=ri;exports.tableSelectInlineType=Ji;exports.textToParagraphs=es;exports.toggleHeadingBlockType=mi;exports.toggleMarkOnRunRange=Lm;exports.toggleMarkOverBlockRange=as;exports.toggleMarkOverSelection=ss;exports.useAtMenuTrigger=kc;exports.useBlock=be;exports.useBlockChildren=Ho;exports.useBlockClassName=Ie;exports.useBlockRangeDrag=gc;exports.useBlockRangeSelection=Mn;exports.useBlockRegistry=dt;exports.useCaretRect=Rc;exports.useClipboardHandlers=dc;exports.useCoarsePointer=cs;exports.useCommentAuthorId=Fa;exports.useComments=hl;exports.useDocumentVersions=Pa;exports.useEditor=Cm;exports.useEditorKeyboardShortcuts=bc;exports.useEditorStore=G;exports.useEmojiMenuTrigger=yc;exports.useFieldTypeEditor=jo;exports.useFieldTypes=Ic;exports.useFloatingToolbarTrigger=wc;exports.useHistory=Cc;exports.useInlineRegistry=Ke;exports.usePersistedDocument=lb;exports.usePresence=ib;exports.usePreviewMode=So;exports.useRegisterFieldTypes=$c;exports.useRun=It;exports.useSelectedBlock=ut;exports.useServiceWorkerUpdate=cb;exports.useSlashMenuTrigger=xc;exports.useTemplates=Vd;exports.useTextFormattingActions=is;exports.useVirtualKeyboardInset=Rr;exports.useVoiceTyping=gb;exports.useWholeDocumentSelection=Co;exports.walkDomToBlocks=ic;
2927
3209
  //# sourceMappingURL=noteloom.cjs.map