@panphora/clayjs 1.18.0 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +1 -1
  2. package/dist/all.js +1 -1
  3. package/dist/clay-dom.js +1 -1
  4. package/dist/clay-events.js +1 -1
  5. package/dist/clay-internals.js +1 -1
  6. package/dist/clay-options.js +1 -1
  7. package/dist/clay-router.js +1 -1
  8. package/dist/clay-ui.js +1 -1
  9. package/dist/clay-utils.js +1 -1
  10. package/dist/clay.js +1 -1
  11. package/dist/clay.standalone.js +618 -399
  12. package/dist/m/{c-6DB2OLRJ.js → c-2RARVIAK.js} +1 -1
  13. package/dist/m/{c-UORXLSD3.js → c-2Y4DOHSY.js} +1 -1
  14. package/dist/m/{c-4TXNLX4K.js → c-4FJTBE6I.js} +3 -3
  15. package/dist/m/{c-6UGWFMQC.js → c-7PYNAULW.js} +1 -1
  16. package/dist/m/{c-AMU3BPPR.js → c-AIWN4QN4.js} +2 -2
  17. package/dist/m/{c-COPTL5WB.js → c-AXGY2WTB.js} +1 -1
  18. package/dist/m/{c-IMZCWYHR.js → c-BAUBNYXK.js} +1 -1
  19. package/dist/m/{c-MWXFLW4J.js → c-CQQDL6O4.js} +1 -1
  20. package/dist/m/{c-KP64LT2A.js → c-DHUCEMXE.js} +1 -1
  21. package/dist/m/{c-VILENZTD.js → c-EXEDYU4H.js} +1 -1
  22. package/dist/m/{c-2GRUM77Q.js → c-F6G2OGYG.js} +2 -2
  23. package/dist/m/{c-SPZPGD3R.js → c-FCNAO2MI.js} +1 -1
  24. package/dist/m/{c-372N6H3B.js → c-FOOE4GML.js} +1 -1
  25. package/dist/m/{c-AMYEFA2E.js → c-FTQKI7SP.js} +1 -1
  26. package/dist/m/{c-URSMSFCB.js → c-GWNC3UGL.js} +1 -1
  27. package/dist/m/{c-BUAYFEV5.js → c-HUISJXHF.js} +1 -1
  28. package/dist/m/{c-K3ADYNLU.js → c-HXPHZN7Q.js} +1 -1
  29. package/dist/m/{c-OTMKN2OO.js → c-I4MQHOEY.js} +1 -1
  30. package/dist/m/{c-HHGJBU4D.js → c-JCP3XDSJ.js} +1 -1
  31. package/dist/m/{c-JNLX3RJB.js → c-JDARJDOT.js} +1 -1
  32. package/dist/m/{c-TTB5EK4S.js → c-JK3PHE7J.js} +1 -1
  33. package/dist/m/{c-B5UJQT7W.js → c-K72SY2TL.js} +1 -1
  34. package/dist/m/{c-5ONTYIUI.js → c-L6FLIUXP.js} +1 -1
  35. package/dist/m/{c-5OOVFCJM.js → c-LACAAQFB.js} +1 -1
  36. package/dist/m/{c-U7SHNWDH.js → c-LPCZOYTX.js} +1 -1
  37. package/dist/m/{c-X5TSXZYJ.js → c-MIKZEG5I.js} +1 -1
  38. package/dist/m/{c-EVYAISP3.js → c-MMXKAX2W.js} +1 -1
  39. package/dist/m/{c-PLN76GF3.js → c-O4JMKN6U.js} +2 -2
  40. package/dist/m/{c-RND3G2S2.js → c-P3CK66NT.js} +1 -1
  41. package/dist/m/{c-YBKHUAK7.js → c-QINHDETP.js} +1 -1
  42. package/dist/m/{c-OPLUZR3A.js → c-RRZJWFLE.js} +1 -1
  43. package/dist/m/{c-HMV6P4RX.js → c-UXFUJEZO.js} +1 -1
  44. package/dist/m/{c-SW4YEG2D.js → c-V52FE5FI.js} +1 -1
  45. package/dist/m/{c-D5IKEKXW.js → c-VE7RKNKZ.js} +1 -1
  46. package/dist/m/{c-CCQ25GFY.js → c-WKNRJX3C.js} +1 -1
  47. package/dist/m/{c-C6IPRG34.js → c-XSZKP646.js} +1 -1
  48. package/dist/m/{c-ZK4GIZH2.js → c-ZGDYHKG3.js} +1 -1
  49. package/dist/m/{c-T637T7SN.js → c-ZKNBMNN3.js} +1 -1
  50. package/dist/m/{c-W6DQSHXI.js → c-ZRUQ5FSU.js} +1 -1
  51. package/dist/m/{c-4YU3BR4D.js → c-ZS4US2XV.js} +1 -1
  52. package/dist/m/core/{autosave-S6OMNDCK.js → autosave-RVJPYLRT.js} +1 -1
  53. package/dist/m/core/{conflict-notice-IWHMHH43.js → conflict-notice-2WGT52LH.js} +1 -1
  54. package/dist/m/core/{recovery-DRFZRJED.js → recovery-ZOUOJVIX.js} +1 -1
  55. package/dist/m/core/{save-LYY7K6U7.js → save-A5JXV6ME.js} +1 -1
  56. package/dist/m/core/{unsaved-warning-7QTKEN7Z.js → unsaved-warning-4ZPEV7BF.js} +1 -1
  57. package/dist/m/loader-34YPFKOH.js +1 -0
  58. package/dist/m/manifest-0D166F4F.js +1 -0
  59. package/dist/m/manifest-edit-3877153E.js +1 -0
  60. package/dist/m/manifest.json +566 -555
  61. package/dist/m/page/{editor-6LRB3GE4.js → editor-WRQGHDSG.js} +2 -2
  62. package/dist/m/plugins/{ai-edit-UTV7YO2I.js → ai-edit-X2L2KIEP.js} +1 -1
  63. package/dist/m/plugins/like-EV7MTZ56.js +1 -0
  64. package/dist/m/plugins/{live-AD4H6XSL.js → live-7C36XEI2.js} +1 -1
  65. package/dist/m/plugins/{menu-M5WW7DBF.js → menu-MFC4DI5E.js} +1 -1
  66. package/dist/m/plugins/{page-MD3T2ZX3.js → page-BSW6MGDO.js} +2 -2
  67. package/dist/m/plugins/{page-view-PAWVZNFY.js → page-view-WFZVTPQK.js} +1 -1
  68. package/dist/m/plugins/{wire-VBWXEXU2.js → wire-6OSIL3I7.js} +1 -1
  69. package/dist/m/{reader-core-4W2KYEWQ.js → reader-core-PLZYLYLT.js} +2 -2
  70. package/dist/m/sync/{live-sync-MO5DH33W.js → live-sync-UXNI6ZF6.js} +1 -1
  71. package/dist/offline-manifest.json +312 -300
  72. package/docs/guide.md +1 -0
  73. package/package.json +2 -1
  74. package/src/loader-logic.js +5 -1
  75. package/src/loader.js +2 -0
  76. package/src/plugins/like.js +254 -0
  77. package/dist/m/loader-3BBNZZGM.js +0 -1
  78. package/dist/m/manifest-F449FF98.js +0 -1
  79. package/dist/m/manifest-edit-4396A009.js +0 -1
  80. /package/dist/m/{c-X5LNHET5.js → c-5JLFROUB.js} +0 -0
@@ -1,4 +1,4 @@
1
1
  import{A as Kt,B as Ht,C as jt,E as ot,H as lt,I as dt,J as V,a as O,b as D,ba as Ut,ca as ut,d as $,da as Ft,e as Z,f as Vt,g as tt,ga as Wt,ha as Gt,ia as Xt,j as L,k as et,m as T,ma as ft,n as nt,q as Rt,t as qt,ta as Qt,v as ct,z as _t}from"./c-QIXT3Q7C.js";var be=e=>e==="left"||e==="right"?e:null,{Plugin:wt,PluginKey:ke,TextSelection:I,NodeSelection:Yt,Selection:st}=D,M=T.nodes,S=e=>e.type===M.list_item,A=e=>e.type===M.toggle,k=e=>e.attrs.parent??null,Et="page-step",q="page-move",Mt=e=>e&&(n=>e(Z.closeHistory(n).setMeta(Et,!0)));function y(e,n=null){let t=[],o=new Map,r=[];e.forEach((s,a)=>{let i=t.length,l=t[i-1],c=k(s),d=c!==null&&o.has(c)?o.get(c):-1,f=d;if(S(s)){for(l&&S(l.node)&&k(l.node)===c||(r=[]);r.length&&t[r[r.length-1]].node.attrs.indent>=s.attrs.indent;)r.pop();r.length&&(f=r[r.length-1]),r.push(i)}else r=[];let p=A(s)&&(s.attrs.open||!!n?.has(s.attrs.id)),u=d>=0&&(t[d].hidden||!t[d].open);t.push({node:s,at:a,end:a+s.nodeSize,i,up:f,depth:d>=0?t[d].depth+1:0,hidden:u,open:p,subEnd:i}),A(s)&&s.attrs.id&&o.set(s.attrs.id,i)});for(let s=t.length-1;s>=0;s--){let a=t[s].up;a>=0&&t[s].subEnd>t[a].subEnd&&(t[a].subEnd=t[s].subEnd)}return t}var Jn=(e,n)=>({from:e[n].at,to:e[e[n].subEnd].end});function xe(e,n=null){let t=new Map;n?.forEach(c=>{c.attrs.id&&t.set(c.attrs.id,k(c))}),e.forEach(c=>{c.attrs.id&&t.set(c.attrs.id,k(c))});let o=[];e.forEach((c,d)=>o.push({node:c,at:d}));let r=new Array(o.length).fill(null);for(let c=o.length-2;c>=0;c--){let d=k(o[c+1].node);r[c]=d!==k(o[c].node)?d:r[c+1]}let s=[],a=[null],i=null,l=[];return o.forEach(({node:c,at:d},f)=>{let p=k(c),u=new Set;for(;p!==null&&!a.includes(p)&&!u.has(p);)u.add(p),p=t.has(p)?t.get(p):null;a.includes(p)||(p=null);let h=r[f];a.indexOf(h)>a.indexOf(p)&&(p=h);let m=a.slice(0,a.indexOf(p)+1),g=c.attrs.indent;if(S(c)){let E=Number.isInteger(g)&&g>0?g:0,b=i&&S(i.node)&&i.parent===p;for(b||(l=[]);l.length&&l[l.length-1].orig>E;)l.pop();let N=0;if(l.length){let C=l[l.length-1];N=C.shift,C.orig===E&&l.pop()}g=Math.max(0,Math.min(E-N,b?i.indent+1:0)),l.push({orig:E,shift:E-g})}else l=[];(p!==k(c)||S(c)&&g!==c.attrs.indent)&&s.push({at:d,attrs:{...c.attrs,parent:p,...S(c)?{indent:g}:{}}}),i={node:c,parent:p,indent:g},a=A(c)&&c.attrs.id?[...m,c.attrs.id]:m}),s}function Zn(){let e=new WeakSet;return new wt({appendTransaction(n,t,o){if(!n.some(a=>a.docChanged&&!a.getMeta(ot)))return null;if(e.has(t.doc)&&je(t.doc,o.doc))return e.add(o.doc),null;let r=xe(o.doc,t.doc);if(!r.length)return e.add(o.doc),null;let s=o.tr;for(let a of r)s.setNodeMarkup(a.at,null,a.attrs);return s}})}function at(e,n,t){let o=e.resolve(n.from).index(0),r=Math.min(e.resolve(n.to).index(0),t.length-1);return r>o&&n.to<=t[r].at&&r--,[Math.min(o,t.length-1),r]}var ne=at;function z(e,n,t){let o=n;for(;e[o].up>=0&&t>e[e[o].up].subEnd;)o=e[o].up;let r=e[o].up,s=e[o].subEnd;for(;s<t;)s=e[s+1].subEnd;return{lo:o,hi:s,up:r}}var ye=(e,n,t)=>{let o=e.resolve(Math.max(0,Math.min(n,e.content.size)));return o.depth===0?o.pos:t<0?o.before(1):o.after(1)},Jt=e=>({id:e.node.attrs.id,at:e.at,node:e.node}),bt=(e,n)=>n.id?e.node.attrs.id===n.id:e.at===n.at&&e.node.type===n.node.type&&e.node.content.eq(n.node.content);function Ae(e,n,t){let o=[];for(let r=n;r<=t;r=e[r].subEnd+1)o.push(Jt(e[r]));return{roots:o,members:e.slice(n,t+1).map(Jt)}}function Se(e,n){let t=n.roots.map(a=>e.findIndex(i=>bt(i,a))).filter(a=>a>=0);if(!t.length||t.some(a=>e[a].hidden))return null;let o=t[0],r=e[o].up,s=e[o].subEnd;for(let a of t.slice(1)){if(a!==s+1||e[a].up!==r)return null;s=e[a].subEnd}return e.slice(o,s+1).some(a=>!n.members.some(i=>bt(a,i)))?null:{lo:o,hi:s}}var we=(e,n)=>{let t=o=>({...o,at:n.map(o.at,1)});return{roots:e.roots.map(t),members:e.members.map(t)}},x=class e extends st{map(n,t){return this.getBookmark().map(t).resolve(n)}eq(n){return n instanceof e&&n.anchor===this.anchor&&n.head===this.head}toJSON(){return{type:"page-block",anchor:this.anchor,head:this.head}}static fromJSON(n,t){return new e(n.resolve(t.anchor),n.resolve(t.head))}getBookmark(){let{lo:n,hi:t}=this.span();return new kt(this.anchor,this.head,Ae(y(this.$from.doc),n,t))}span(n=this.$from.doc){return{lo:n.resolve(this.from).index(0),hi:n.resolve(this.to).index(0)-1}}};x.prototype.visible=!1;st.jsonID("page-block",x);var kt=class e{constructor(n,t,o){this.anchor=n,this.head=t,this.span=o}map(n){let t=this.anchor<=this.head;return new e(n.map(this.anchor,t?1:-1),n.map(this.head,t?-1:1),we(this.span,n))}resolve(n){let t=y(n),o=Se(t,this.span);if(!o){let a=t.find(i=>bt(i,this.span.roots[0]));return st.near(n.resolve(a?.at??ye(n,Math.min(this.anchor,this.head),-1)))}let r=t[o.lo].at,s=t[o.hi].end;return this.anchor<=this.head?new x(n.resolve(r),n.resolve(s)):new x(n.resolve(s),n.resolve(r))}},oe=(e,n)=>{for(let t=n-1;t>=0;t--)if(e[t].up===e[n].up)return t;return-1};function G(e,n,t,o,r=()=>null){let s=r(e[n])||{},a="parent"in s?s.parent:k(e[n].node),i=null;for(let d=0;d<e.length&&e[d].end<=o;d++)d>=n&&d<=t||k(e[d].node)===a&&(i=e[d].node.attrs.id);let l=[],c={};for(let d=n;d<=t;d++){let f=e[d].node,p=r(e[d]);l.push(f.attrs.id),p&&"indent"in p&&p.indent!==f.attrs.indent&&(c[f.attrs.id]={indent:p.indent})}return{ids:l,afterId:i,parent:a,attrs:c}}function re(e,n,t,o,r,s=()=>null,a=e.selection){let i=n[t].at,l=n[o].end,c=l-i,d=[];for(let h=t;h<=o;h++){let m=n[h].node;d.push(m.type.create({...m.attrs,...s(n[h])||{},pos:null},m.content,m.marks))}let f=e.tr.delete(i,l),p=r>i?r-c:r;f.insert(p,d);let u=p-i;return a instanceof x?f.setSelection(new x(f.doc.resolve(a.anchor+u),f.doc.resolve(a.head+u))):a instanceof Yt?f.setSelection(Yt.create(f.doc,a.from+u)):f.setSelection(I.create(f.doc,a.anchor+u,a.head+u)),f.setMeta(q,G(n,t,o,r,s))}function xt(e,n,t){let o=e[t].node;if(A(o)){let s=o.attrs.id,a=k(o);return i=>k(i.node)===s?{parent:a}:null}let r=o.attrs.indent-e[n].node.attrs.indent;return s=>S(s.node)?{indent:s.node.attrs.indent+r}:null}var Zt=e=>(n,t)=>{t=Mt(t);let o=y(n.doc);if(!o.length)return!1;let[r,s]=at(n.doc,n.selection,o),{lo:a,hi:i,up:l}=z(o,r,s),c,d=()=>null;if(e<0){let f=oe(o,a);if(f>=0)c=o[f].at;else if(l>=0)c=o[l].at,d=xt(o,a,l);else return!0}else{let f=i+1;if(f<o.length&&o[f].up===l)c=o[o[f].subEnd].end;else if(l>=0)c=o[o[l].subEnd].end,d=xt(o,a,l);else return!0}return t&&t(re(n,o,a,i,c,d).scrollIntoView()),!0},Ee=8,rt=(e,n)=>S(e.node)&&S(n.node)&&k(e.node)===k(n.node);function Me(e,n){n=Mt(n);let t=y(e.doc);if(!t.length)return!1;let[o,r]=at(e.doc,e.selection,t),s=t[o];if(S(s.node)&&o>0&&rt(t[o-1],s)){if(s.node.attrs.indent>t[o-1].node.attrs.indent)return!0;for(let i=o;i<=Math.max(r,s.subEnd);i++)if(t[i].node.attrs.indent>=Ee)return!0;if(n){let i=e.tr,l=r;for(let d=o;d<=l;d++)l=Math.max(l,t[d].subEnd);let c=o-1;for(let d=o;d<=l&&rt(t[d],s);d++)i.setNodeMarkup(t[d].at,null,{...t[d].node.attrs,indent:t[d].node.attrs.indent+1}),c=d;i.setMeta(q,G(t,o,c,t[o].at,d=>d.i>=o&&d.i<=c?{indent:d.node.attrs.indent+1}:null)),n(i)}return!0}let a=oe(t,o);if(a<0||!A(t[a].node)||t[a].subEnd!==o-1)return!0;if(n){let{hi:i}=z(t,o,r),l=e.tr,c=k(s.node),d=t[a].node.attrs.id,f=[];for(let u=o;u<=i;u++)k(t[u].node)===c&&(l.setNodeMarkup(t[u].at,null,{...t[u].node.attrs,parent:d}),f.push(t[u].node.attrs.id));t[a].node.attrs.open||l.setNodeMarkup(t[a].at,null,{...t[a].node.attrs,open:!0});let p=G(t,o,i,t[o].at,u=>u.i>=o&&u.i<=i&&k(u.node)===c?{parent:d}:null);l.setMeta(q,{...p,ids:f,attrs:t[a].node.attrs.open?p.attrs:{...p.attrs,[d]:{open:!0}}}),n(l)}return!0}function vt(e,n){n=Mt(n);let t=y(e.doc);if(!t.length)return!1;let[o,r]=at(e.doc,e.selection,t),s=t[o];if(S(s.node)&&s.node.attrs.indent>0){if(n){let{lo:d,hi:f}=z(t,o,r),p=e.tr,u=new Set;for(let h=o;h<=r;){let m=t[h];if(S(m.node)&&m.node.attrs.indent>0)for(let g=h;g<=m.subEnd;g++)S(t[g].node)&&(p.setNodeMarkup(t[g].at,null,{...t[g].node.attrs,indent:t[g].node.attrs.indent-1}),u.add(g));h=m.subEnd+1}p.setMeta(q,G(t,d,f,t[d].at,h=>u.has(h.i)?{indent:h.node.attrs.indent-1}:null)),n(p)}return!0}if(k(s.node)===null)return!0;let{lo:i,hi:l}=z(t,o,r),c=t[i].up;for(;c>=0&&!A(t[c].node);)c=t[c].up;if(c<0)return!0;if(n){let d=xt(t,i,c),f=t[c].subEnd;if(l===f){let p=e.tr;for(let u=i;u<=l;u++){let h=d(t[u]);h&&p.setNodeMarkup(t[u].at,null,{...t[u].node.attrs,...h})}p.setMeta(q,G(t,i,l,t[i].at,d)),n(p)}else n(re(e,t,i,l,t[f].end,d).scrollIntoView())}return!0}function se(e){let n=e.tr;return e.selection.empty||n.deleteSelection(),n}function ve(e,n){let{$from:t,$to:o,empty:r}=e.selection;if(t.depth!==1||!S(t.parent)||!t.sameParent(o))return!1;if(r&&t.parent.content.size===0){let h=t.parent;return h.attrs.indent>0?vt(e,n):(n&&n(e.tr.setNodeMarkup(t.before(),M.paragraph,{id:h.attrs.id,pos:h.attrs.pos,parent:h.attrs.parent})),!0)}let s=se(e),a=s.selection.$from,i=a.parent,l=y(s.doc),c=a.index(0),d=a.parentOffset===0,f=a.parentOffset===i.content.size,p=l[c+1],u=f&&p&&rt(p,l[c])&&p.node.attrs.indent>i.attrs.indent;return d?(s.split(a.pos,1,[{type:M.list_item,attrs:i.attrs}]),s.setNodeMarkup(l[c].at,null,{...i.attrs,checked:!1})):s.split(a.pos,1,[{type:M.list_item,attrs:{...i.attrs,checked:!1,indent:i.attrs.indent+(u?1:0)}}]),n&&n(s.scrollIntoView()),!0}function Te(e,n){let{$from:t,$to:o}=e.selection;if(t.depth!==1||!A(t.parent)||!t.sameParent(o))return!1;let r=se(e),s=r.selection.$from,a=s.parent,i=y(r.doc),l=s.index(0),c=i[l],d=c.subEnd>l;if(a.content.size===0&&!d)return r.setNodeMarkup(c.at,M.paragraph,{id:a.attrs.id,pos:a.attrs.pos,parent:a.attrs.parent}),n&&n(r),!0;if(s.parentOffset===0&&a.content.size>0)return r.insert(c.at,M.paragraph.create({parent:k(a)})),n&&n(r.scrollIntoView()),!0;let f=a.content.cut(s.parentOffset);if(a.attrs.open)r.split(s.pos,1,[{type:M.paragraph,attrs:{parent:a.attrs.id}}]);else{let p=i[c.subEnd].end,u=r.steps.length;r.delete(s.pos,c.end-1);let h=r.mapping.slice(u).map(p);r.insert(h,M.toggle.create({parent:k(a),open:!1},f)),r.setSelection(I.create(r.doc,h+1))}return n&&n(r.scrollIntoView()),!0}function Ne(e,n){let{$from:t,empty:o}=e.selection;if(!o||t.depth!==1||t.parent.type!==M.paragraph||t.parent.content.size)return!1;let r=k(t.parent);if(r===null)return!1;let s=y(e.doc),a=t.index(0),i=s.findIndex(l=>l.node.attrs.id===r);if(i<0||s[i].subEnd!==a)return!1;if(n){let l=s[a].node.attrs.id,c=k(s[i].node),d=a>0?s[a-1].node:null,f=e.tr.setNodeMarkup(s[a].at,null,{...t.parent.attrs,parent:c});f.setMeta(q,{ids:[l],afterId:d?d.attrs.id:null,parent:k(d??s[a].node),attrs:{[l]:{parent:c}}}),n(f)}return!0}function Ie(e,n){let{$from:t,empty:o}=e.selection;if(!o||t.depth!==1||!t.parent.isTextblock||t.parent.type.spec.code)return!1;let r=t.parent;if(S(r)||A(r)||k(r)===null||t.parentOffset!==r.content.size)return!1;if(n){let s=e.tr.split(t.pos,1,[{type:M.paragraph,attrs:{parent:k(r)}}]);n(s.scrollIntoView())}return!0}function Ce(e,n){let{$from:t,empty:o}=e.selection;if(!o||t.depth!==1||!S(t.parent)||t.parentOffset!==0)return!1;if(t.parent.attrs.indent>0)return vt(e,n);let r=t.parent;return n&&n(e.tr.setNodeMarkup(t.before(),M.paragraph,{id:r.attrs.id,pos:r.attrs.pos,parent:r.attrs.parent})),!0}function Oe(e,n){let{$from:t,empty:o}=e.selection;if(!o||t.depth!==1||!A(t.parent)||t.parentOffset!==0)return!1;let r=t.parent;return n&&n(e.tr.setNodeMarkup(t.before(),M.paragraph,{id:r.attrs.id,pos:r.attrs.pos,parent:r.attrs.parent})),!0}function Tt(e,n){if(n<=0||!e[n-1].hidden)return-1;let t=n-1;for(;t>=0&&e[t].hidden;)t--;return t>=0&&A(e[t].node)&&e[t].subEnd>=n-1?t:-1}function Nt(e,n,t,o){let r=e.tr,s=n[o],a=n[t].end-1;return r.delete(s.at,s.end),s.node.content.size&&r.insert(a,s.node.content),r.setSelection(I.create(r.doc,a))}function De(e,n){let{$from:t,empty:o}=e.selection;if(!o||t.depth!==1||t.parentOffset!==0||!t.parent.isTextblock)return!1;let r=y(e.doc),s=t.index(0),a=Tt(r,s);return a<0?!1:(n&&n(Nt(e,r,a,s).scrollIntoView()),!0)}function $e(e,n){let{$from:t,empty:o}=e.selection;if(!o||t.depth!==1||!A(t.parent)||t.parent.attrs.open||t.parentOffset!==t.parent.content.size)return!1;let r=y(e.doc),s=t.index(0),a=r[s].subEnd+1;return a===s+1?!1:(a>=r.length||!r[a].node.isTextblock||n&&n(Nt(e,r,s,a).scrollIntoView()),!0)}function Le(e,n){let{$from:t,empty:o}=e.selection;if(!o||t.depth!==1)return!1;let r=t.parent,s=t.index(0);if(!r.isTextblock||r.type.spec.code||A(r)||!r.content.size||t.parentOffset!==r.content.size||s+1>=e.doc.childCount||!A(e.doc.child(s+1)))return!1;if(n&&r.type!==M.paragraph)n(e.tr.setSelection(I.create(e.doc,t.after()+1)).scrollIntoView());else if(n){let a=t.before(),i=e.tr.insert(t.after()+1,r.content).delete(a,t.after());n(i.setSelection(I.create(i.doc,a+1+r.content.size)).scrollIntoView())}return!0}var ae=e=>(n,t)=>{let{$from:o,empty:r}=n.selection;if(!r||o.depth!==1||!o.parent.isTextblock)return!1;let s=o.parent,a=o.index(0);if(o.parentOffset!==(e<0?0:s.content.size))return!1;let i=y(n.doc),l=e<0?Tt(i,a):-1,c=l>=0?l:a+e;if(c<0||c>=i.length)return!1;let d=i[c].node;if(!d.isTextblock||!s.type.spec.code&&!d.type.spec.code)return!1;if(!t)return!0;let f=n.tr,p=i[a],u=i[c],h=e<0?u.end-1:u.at+1;return!s.content.size&&!s.type.spec.code?f.delete(p.at,p.end).setSelection(I.create(f.doc,f.mapping.map(h))):!d.content.size&&!d.type.spec.code?f.delete(u.at,u.end):f.setSelection(I.create(f.doc,h)),t(f.scrollIntoView()),!0},Be=ae(-1),Pe=ae(1);function ze(e,n){let{$from:t,empty:o}=e.selection;if(!o||t.depth!==1||t.parentOffset!==0||!t.parent.isTextblock)return!1;let r=t.parent;if(S(r)||A(r)||k(r)===null)return!1;let s=t.index(0);return e.doc.child(s-1).attrs.id!==k(r)?!1:(n&&n(Nt(e,y(e.doc),s-1,s).scrollIntoView()),!0)}var It="page-reveal";function to(e,n){return n.length?e.setMeta(It,{add:n}):e}function ie(e,n,t,o=y(e.doc)){let r=o[n];return e.tr.setNodeMarkup(r.at,null,{...r.node.attrs,open:t}).setMeta("addToHistory",!1).setMeta(It,{clear:[r.node.attrs.id]})}function Ve(e,n){let{$from:t}=e.selection;return t.depth!==1||!A(t.parent)?!1:(n&&n(ie(e,t.index(0),!t.parent.attrs.open)),!0)}function Re(e){let n=[];for(let t of e)!A(t.node)||t.hidden||t.open||t.subEnd===t.i||n.push({line:t.at+1,sumEnd:t.end-1,from:t.end,to:e[t.subEnd].end});return n}var yt=(e,n)=>n>e.from&&n<e.to;function At(e,n,t,o){if(o>0){let r=t.to;for(;;){let s=st.findFrom(e.resolve(r),1,!0);if(!s)break;let a=n.find(i=>yt(i,s.head));if(!a)return s.head;r=a.to}}return t.sumEnd}function te(e,n,t,o=-1,r=!1){if(!t.length)return null;let{anchor:s,head:a}=n;if(!(n instanceof I)){let c=t.find(d=>n.from>=d.from&&n.from<d.to);return c?I.create(e,c.sumEnd):null}let i=t.find(c=>yt(c,a));i&&(a=At(e,t,i,o));let l=t.find(c=>yt(c,s));if(l&&(s=l.sumEnd),!r&&s!==a){let c=Math.min(s,a),d=Math.max(s,a),f=t.find(p=>(c>p.line||c===p.sumEnd)&&c<p.from&&d>=p.to);if(f){let p=c===f.sumEnd?At(e,t,f,1):f.line;s<a?s=p:a=p}}return s===n.anchor&&a===n.head?null:I.create(e,s,a)}var qe=e=>{let n="";for(;e>0;)e--,n=String.fromCharCode(97+e%26)+n,e=Math.floor(e/26);return n},_e=e=>[[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"]].reduce((n,[t,o])=>{for(;e>=t;)n+=o,e-=t;return n},"");function Ke(e){let n=new Map,t=[];return e.forEach((o,r)=>{if(!S(o.node)){t=[];return}r>0&&!rt(e[r-1],o)&&(t=[]);let s=o.node.attrs.indent;if(t.length=s+1,o.node.attrs.kind!=="ordered"){t[s]=0;return}t[s]=(t[s]||0)+1;let a=t[s];n.set(r,`${s%3===0?a:s%3===1?qe(a):_e(a)}.`)}),n}var F=new ke("page-collapse"),He=["id","parent","indent","kind","open"];function je(e,n){if(e.childCount!==n.childCount)return!1;for(let t=0;t<e.childCount;t++){let o=e.child(t),r=n.child(t);if(o!==r){if(o.type!==r.type)return!1;for(let s of He)if(o.attrs[s]!==r.attrs[s])return!1}}return!0}var Ue=new Set;function pt(e,n=Ue){let t=y(e,n);return{decos:Ge(e,t),ranges:Re(t),reveal:n}}var Fe=null,We=()=>Fe??=class extends $.DecorationSet{forChild(e,n){if(n.isLeaf)return $.DecorationSet.empty;let t=this.children,o=0,r=t.length/3;for(;o<r;){let s=o+r>>1;t[s*3]<e?o=s+1:r=s}return o*3<t.length&&t[o*3]===e?t[o*3+2]:$.DecorationSet.empty}};function Ge(e,n=y(e)){let{Decoration:t,DecorationSet:o}=$,r=Ke(n),s=[],a=[];for(let i of n){let l={};if(i.hidden&&(l.class="page-hidden",l["aria-hidden"]="true"),i.depth&&(l.style=`--page-depth:${i.depth}`),r.has(i.i)&&(l["data-marker"]=r.get(i.i)),A(i.node)&&(l["aria-expanded"]=i.open?"true":"false"),Object.keys(l).length&&s.push(t.node(i.at,i.end,l)),A(i.node)&&!i.hidden){let c=t.widget(0,()=>Xe(i.node,i.open),{side:-1,ignoreSelection:!0,key:`t:${i.node.attrs.id}:${i.open}`});a.push(i.at,i.end,new o([c],[]))}}return!s.length&&!a.length?o.empty:new(We())(s,a)}function Xe(e,n=e.attrs.open){let t=document.createElement("button");return t.type="button",t.className="page-toggle-button",t.contentEditable="false",t.setAttribute("aria-label",n?"Collapse":"Expand"),t.setAttribute("data-toggle",e.attrs.id||""),t}function eo(){let e=!1;return new wt({key:F,state:{init:(n,t)=>pt(t.doc),apply(n,t,o,r){let s=n.getMeta(It);if(s){let a=new Set(t.reveal);for(let i of s.add??[])a.add(i);for(let i of s.clear??[])a.delete(i);return pt(r.doc,a)}return n.docChanged?pt(r.doc,t.reveal):t}},appendTransaction(n,t,o){if(!n.some(i=>i.docChanged||i.selectionSet))return null;let s=n.some(i=>i.selectionSet)&&o.selection.head>=t.selection.head?1:-1,a=te(o.doc,o.selection,F.getState(o).ranges,s,e);return a?o.tr.setSelection(a):null},props:{decorations:n=>F.getState(n).decos,handleDOMEvents:{mousedown:(n,t)=>{let o=t.target.closest?.(".page-toggle-button");if(o){t.preventDefault();let a=y(n.state.doc),i=a.findIndex(l=>l.node.attrs.id===o.dataset.toggle);return i>=0&&n.dispatch(ie(n.state,i,!a[i].node.attrs.open,a)),!0}e=!0;let r=n.dom.ownerDocument.defaultView,s=()=>{e=!1,r.removeEventListener("mouseup",s,!0);let a=te(n.state.doc,n.state.selection,F.getState(n.state).ranges,1,!1);a&&n.dispatch(n.state.tr.setSelection(a))};return r.addEventListener("mouseup",s,!0),!1}},handleKeyDown(n,t){let o={ArrowDown:1,ArrowRight:1,ArrowUp:-1,ArrowLeft:-1}[t.key];if(!o||t.altKey||t.metaKey||t.ctrlKey)return!1;let{head:r}=n.state.selection,a=t.key==="ArrowDown"||t.key==="ArrowUp"?o>0?"down":"up":o>0?"forward":"backward";if(!n.endOfTextblock(a))return!1;let i=y(n.state.doc),{ranges:l}=F.getState(n.state),d=n.state.doc.resolve(r).index(0),f=null;if(o>0){let u=l.find(h=>h.from===i[d].end);u&&(f=At(n.state.doc,l,u,1))}else{let u=Tt(i,d);u>=0&&(f=t.shiftKey?i[u].at+1:i[u].end-1)}if(f===null||f===r)return!1;let p=t.shiftKey?n.state.selection.anchor:f;return n.dispatch(n.state.tr.setSelection(I.create(n.state.doc,p,f)).scrollIntoView()),!0}}})}var ee=/^([ \t]*)(?:([-*+•])|(\d+)[.)])[ \t]+(?:\[([ xX])\][ \t]+)?(.*)$/;function Qe(e){let n=e.replace(/\r\n?/g,`
2
2
  `).split(`
3
- `);if(!n.some(r=>ee.test(r)))return null;let t=[],o=[];for(let r of n){if(!r.trim())continue;let s=ee.exec(r);if(!s){t.length=0,o.push(M.paragraph.create(null,r.trim()?T.text(r.trim()):null));continue}let a=s[1].replace(/\t/g," ").length;for(;t.length&&t[t.length-1]>a;)t.pop();(!t.length||t[t.length-1]<a)&&t.push(a);let i=Math.min(t.length-1,o.length&&S(o[o.length-1])?o[o.length-1].attrs.indent+1:0),l=s[4]!==void 0?"check":s[3]!==void 0?"ordered":"bullet";o.push(M.list_item.create({kind:l,indent:i,checked:s[4]==="x"||s[4]==="X"},s[5]?T.text(s[5]):null))}return new O.Slice(O.Fragment.from(o),0,0)}var ht=new Set(["UL","OL"]),mt=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","PRE","BLOCKQUOTE","UL","OL","LI","DETAILS","SUMMARY","TABLE","HR","FIGURE"]);function Ye(e){let n=e.querySelector(":scope > input[type=checkbox], :scope > p > input[type=checkbox], :scope > label > input[type=checkbox]");if(n)return{check:!0,checked:n.checked||n.hasAttribute("checked")};if(e.getAttribute("role")==="checkbox"||e.hasAttribute("aria-checked"))return{check:!0,checked:e.getAttribute("aria-checked")==="true"};if(e.hasAttribute("data-checked"))return{check:!0,checked:e.getAttribute("data-checked")==="true"};let o=e.className||"";return/\b(checked|task-list-item|to-do)\b/.test(o)||e.closest?.("ul.to-do-list, ul.contains-task-list")?{check:!0,checked:/\bchecked\b/.test(o)||!!e.querySelector(".checkbox-on")}:{check:!1,checked:!1}}function Je(e){let n=(e.getAttribute("style")||"")+";"+(e.parentElement?.getAttribute("style")||""),t=/list-style-type\s*:\s*([a-z-]+)/i.exec(e.getAttribute("style")||"")?.[1];return t?/decimal|alpha|roman|latin|greek/.test(t)?"ordered":"bullet":e.parentElement?.tagName==="OL"?"ordered":"bullet"}function Ze(e,n=globalThis.document){let t=n.createElement("div");t.innerHTML=e;for(let u of t.querySelectorAll('b[style*="font-weight:normal"], b[style*="font-weight: normal"]'))u.replaceWith(...u.childNodes);let o=0,r=n.createElement("div"),s=u=>{let h=parseInt(u.getAttribute("aria-level"),10);if(h>0)return h-1;let m=-1;for(let g=u.parentElement;g&&g!==t;g=g.parentElement)ht.has(g.tagName)&&m++;return Math.max(0,m)},a=[];function i(u,h,m){let g=n.createElement("div"),{check:E,checked:b}=Ye(u);g.setAttribute("data-page-li",""),g.setAttribute("data-kind",E?"check":Je(u)),g.setAttribute("data-checked",b?"true":"false"),g.dataset.depth=String(s(u)),h&&g.setAttribute("data-page-parent",h);let N=!0,C=[];for(let w of[...u.childNodes]){if(w.nodeType===1&&ht.has(w.tagName)){C.push(w);continue}if(!(w.nodeType===1&&w.tagName==="INPUT")){if(w.nodeType===1&&mt.has(w.tagName)){N||g.appendChild(n.createElement("br"));for(let P of[...w.childNodes])P.nodeType===1&&P.tagName==="INPUT"||g.appendChild(P);N=!1;continue}g.appendChild(w),(w.nodeType!==3||w.textContent.trim())&&(N=!1)}}m.appendChild(g),a.push(g);for(let w of C)l(w,h,m)}function l(u,h,m){let g=null,E=b=>{g||(g=n.createElement("p"),h&&g.setAttribute("data-page-parent",h),m.appendChild(g)),g.appendChild(b)};for(let b of[...u.childNodes])if(!(b.nodeType===1&&(b.tagName==="META"||b.tagName==="STYLE"))){if(b.nodeType===1&&b.tagName==="BR"){g=null;continue}if(b.nodeType!==1){b.nodeType===3&&(g||b.textContent.trim())&&E(b);continue}if(!mt.has(b.tagName)&&b.tagName!=="ASIDE"){E(b);continue}if(g=null,ht.has(b.tagName)){l(b,h,m);continue}if(b.tagName==="LI"){i(b,h,m);continue}if(b.tagName==="DETAILS"){let N=`paste-${++o}`,C=b.querySelector(":scope > summary"),w=n.createElement("div");w.setAttribute("data-page-toggle",N),b.hasAttribute("open")&&w.setAttribute("data-open","true"),h&&w.setAttribute("data-page-parent",h);let P=C?.querySelector(":scope > h1, :scope > h2, :scope > h3");P?(w.setAttribute("data-level",P.tagName[1]),w.append(...P.childNodes)):C&&w.append(...C.childNodes),m.appendChild(w);for(let Pt of[...b.childNodes])if(Pt!==C){let zt=n.createElement("div");zt.appendChild(Pt),l(zt,N,m)}continue}if(b.tagName==="DIV"&&!b.hasAttribute("data-page-li")&&[...b.children].some(N=>mt.has(N.tagName))){l(b,h,m);continue}h&&b.setAttribute("data-page-parent",h),m.appendChild(b)}}l(t,null,r);let c=a.length?Math.min(...a.map(u=>+u.dataset.depth)):0,d=null;for(let u of a){let h=+u.dataset.depth-c,m=d&&u.previousElementSibling===d?+d.getAttribute("data-indent")+1:0;u.setAttribute("data-indent",String(Math.min(h,m))),u.removeAttribute("data-depth"),d=u}let f=u=>{if(u.nodeType!==1||u.tagName==="IMG")return[u.cloneNode(!0)];let h=[],m=u.cloneNode(!1);for(let g of u.childNodes)for(let E of f(g))E.nodeType===1&&E.tagName==="IMG"?(m.hasChildNodes()&&h.push(m),h.push(E),m=u.cloneNode(!1)):m.appendChild(E);return(m.hasChildNodes()||!h.length)&&h.push(m),h};for(let u of[...r.children]){if(!u.matches("p, h1, h2, h3, h4, h5, h6, aside, div[data-page-li], div.page-li")||!u.querySelector("img"))continue;let h=f(u),m=u.getAttribute("data-page-parent");if(m)for(let g of h)g.setAttribute("data-page-parent",m);u.replaceWith(...h)}let p=t.querySelector("[data-pm-slice]");return p&&r.firstElementChild?.setAttribute("data-pm-slice",p.dataset.pmSlice),r.innerHTML}var gt=(e,n=0)=>e!==null&&e!==""&&Number.isInteger(+e)&&+e>=n?+e:null,v=e=>e.getAttribute("data-page-parent")||null,tn=Rt([]).type,en=Object.create(T,{marks:{value:{...T.marks,[nt]:tn}}}),ce=e=>{let n;try{n=Qt(e)}catch{return null}return!n||typeof n.t!="string"||n.t==="opaque_block"||Object.hasOwn(Ft,n.t)?null:n},nn=e=>{let n=ce(e);return n?{raw:n,parent:v(e)}:!1},on=e=>{let n=ce(e);if(!n||typeof n.c!="string"||!n.c)return O.Fragment.empty;let t=Ht(n.m,n.c.length);return O.Fragment.from(jt(T,n.c,t,T.nodes.opaque_block))},rn=e=>{try{return{entries:Wt(e.getAttribute(ut))}}catch{return!1}},X=null,sn=()=>import("./c-IMZCWYHR.js").then(e=>{X=e},()=>{}),an=new O.DOMParser(en,[{tag:"table",node:"table",getAttrs:e=>X?.table(e)??!1,getContent:e=>X.rows(e)},{tag:`div[${Ut}]`,node:"opaque_block",getAttrs:nn,getContent:on},{tag:`span[${ut}]`,mark:nt,getAttrs:rn},{tag:"div[data-page-li]",node:"list_item",getAttrs:e=>({kind:e.getAttribute("data-kind")||"bullet",indent:+e.getAttribute("data-indent")||0,checked:e.getAttribute("data-checked")==="true",parent:v(e)})},{tag:"div.page-li",node:"list_item",getAttrs:e=>({kind:e.getAttribute("data-kind")||"bullet",indent:+e.getAttribute("data-indent")||0,checked:e.getAttribute("data-checked")==="true",parent:v(e)})},{tag:"div[data-page-toggle]",node:"toggle",getAttrs:e=>({id:e.getAttribute("data-page-toggle"),open:e.getAttribute("data-open")==="true",parent:v(e),level:ft(Number(e.getAttribute("data-level")))})},{tag:"div.page-toggle",node:"toggle",getAttrs:e=>({id:e.getAttribute("data-id"),open:e.getAttribute("data-open")==="true",parent:null,level:ft(Number(e.getAttribute("data-level")))})},{tag:"h1",node:"heading",getAttrs:e=>({level:1,parent:v(e)})},{tag:"h2",node:"heading",getAttrs:e=>({level:2,parent:v(e)})},{tag:"h3",node:"heading",getAttrs:e=>({level:3,parent:v(e)})},{tag:"h4",node:"heading",getAttrs:e=>({level:3,parent:v(e)})},{tag:"pre",node:"code_block",preserveWhitespace:"full",getAttrs:e=>({lang:e.getAttribute("data-lang")||"",parent:v(e)})},{tag:"hr",node:"divider",getAttrs:e=>({parent:v(e)})},{tag:"aside.page-callout",node:"callout",getAttrs:e=>({parent:v(e)})},{tag:'figure:not([data-type]), figure[data-type="image"]',node:"image",getAttrs:e=>{let n=e.querySelector("img"),t=et(n?.getAttribute("src"));return t?{src:t,alt:n.getAttribute("alt")||"",caption:e.querySelector("figcaption")?.textContent||"",width:gt(e.getAttribute("data-width")??n.getAttribute("width"),1),align:be(e.getAttribute("data-align")),parent:v(e)}:!1}},{tag:"img[src]",node:"image",getAttrs:e=>{let n=et(e.getAttribute("src"));return n?{src:n,alt:e.getAttribute("alt")||"",width:gt(e.getAttribute("width"),1),parent:v(e)}:!1}},{tag:'div.page-file, div[data-type="file"]',node:"file",getAttrs:e=>{let n=L(e.getAttribute("data-src"));return n?{src:n,name:e.getAttribute("data-name")||"file",size:gt(e.getAttribute("data-size")),mime:e.getAttribute("data-mime")||null,parent:v(e)}:!1}},{tag:"p",node:"paragraph",getAttrs:e=>({parent:v(e)})},{tag:"br",node:"hard_break"},{tag:"strong",mark:"strong"},{tag:"b",mark:"strong",getAttrs:e=>/font-weight\s*:\s*(normal|[1-5]00)\b/.test(e.getAttribute("style")||"")?!1:null},{tag:"span",mark:"strong",getAttrs:e=>/font-weight\s*:\s*(bold|[6-9]00)\b/.test(e.getAttribute("style")||"")?null:!1},{tag:"em",mark:"em"},{tag:"i",mark:"em"},{tag:"span",mark:"em",getAttrs:e=>/font-style\s*:\s*italic/.test(e.getAttribute("style")||"")?null:!1},{tag:"s",mark:"strike"},{tag:"del",mark:"strike"},{tag:"code",mark:"code"},{tag:"a[href]",mark:"link",getAttrs:e=>{let n=L(e.getAttribute("href"));return n?{href:n}:!1}},{tag:"blockquote",node:"quote",getAttrs:e=>({parent:v(e)})},{tag:"u",mark:"underline"},{tag:"mark",mark:"highlight",getAttrs:e=>ct("highlight",{color:e.getAttribute("data-color")})??!1},{tag:"span[data-color]",mark:"text_color",getAttrs:e=>ct("text_color",{color:e.getAttribute("data-color")})??!1}]);function cn(e,n){let t=n.selection.$from,o=n.selection instanceof x,r=o?n.doc.child(n.selection.span().lo):t.depth>=1?t.node(1):null,s=r?k(r):null,a=r&&S(r)?r.attrs.indent:0,i=new Map;e.content.forEach(m=>{A(m)&&m.attrs.id&&i.set(m.attrs.id,V())});let l=[];e.content.forEach(m=>{if(!m.type.spec.group?.includes("block")){l.push(m);return}let g=k(m),E={...m.attrs,pos:null,id:A(m)?i.get(m.attrs.id)??null:null,parent:g!==null&&i.has(g)?i.get(g):s};S(m)&&(E.indent=m.attrs.indent+a),l.push(m.type.create(E,m.content,m.marks))});let c=!r||!(S(r)||A(r)),d=m=>m&&(S(m)||A(m)),f=c&&d(l[0])?0:e.openStart,p=l[l.length-1],u=new Set(i.values()),h=c&&(d(p)||p&&u.has(k(p)))?0:e.openEnd;return new O.Slice(O.Fragment.from(l),o?0:f,o?0:h)}var St=class extends O.DOMSerializer{serializeFragment(n,t,o){let r=super.serializeFragment(n,t,o);if(!n.firstChild?.isBlock)return r;let s=[...r.childNodes];return n.forEach((a,i,l)=>{let c=s[l];!c||c.nodeType!==1||(k(a)!==null&&c.setAttribute("data-page-parent",k(a)),A(a)&&a.attrs.id&&c.setAttribute("data-page-toggle",a.attrs.id),a.type===M.image&&a.attrs.width&&c.setAttribute("data-width",String(a.attrs.width)))}),X?.copy(n,s),r}},le=O.DOMSerializer.fromSchema(T),ln=e=>{let{t:n,...t}=e.attrs.raw??{},{c:o,m:r}=_t(e.content);return o?{t:n,...t,c:o,...r.some(Boolean)?{m:Kt(r)}:{}}:{t:n,...t}},dn=e=>["div",{"data-type":"newer-format",...Gt(ln(e))},0],un=e=>["span",Xt(e.attrs.entries),0],fn={...le.nodes,opaque_block:dn},pn={...le.marks,[nt]:un},hn=new St(fn,pn);function mn(e,n,t){let{$from:o}=e.state.selection,r=o.depth>=1?o.node(1):null;if(!r||!A(r)||r.attrs.open||t.content.childCount<2)return!1;let s=e.state.tr.setNodeMarkup(o.before(1),null,{...r.attrs,open:!0}).replaceSelection(t);return e.dispatch(s.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function gn(e){let n=!1;return e?.content?.descendants(t=>n?!1:((t.type===M.quote||t.isText&&t.marks.some(o=>qt.has(o.type.name)))&&(n=!0),!n)),n}function bn(e,n,t){let o=e.state.selection.from,r=e.state.selection.to,s=e.state.doc,a=()=>{let i=t.content.textBetween(0,t.content.size,`
4
- `," ");return!e.isDestroyed&&i&&e.state.doc===s&&e.dispatch(e.state.tr.insertText(i,o,r)),!1};return import("./c-6UGWFMQC.js").then(({pasteFormats:i})=>i(e,t,o,r),a),!0}function no(){return new wt({view(){return sn(),{}},props:{handlePaste(e,n,t){return gn(t)?bn(e,n,t):mn(e,n,t)},clipboardSerializer:hn,clipboardTextSerializer:e=>X?.text(e),transformPastedHTML:e=>Ze(e),clipboardParser:an,clipboardTextParser:(e,n,t)=>t?null:Qe(e),transformPasted:(e,n)=>cn(e,n.state)}})}var W=tt.chainCommands(Ce,Oe,Be,ze,De),R=tt.chainCommands($e,Le,Pe),oo={Enter:tt.chainCommands(ve,Te,Ne,Ie),Backspace:W,"Shift-Backspace":W,"Mod-Backspace":W,"Alt-Backspace":W,"Ctrl-h":W,Delete:R,"Shift-Delete":R,"Mod-Delete":R,"Alt-Delete":R,"Ctrl-d":R,"Ctrl-Alt-Backspace":R,Tab:Me,"Shift-Tab":vt,"Mod-Shift-ArrowUp":Zt(-1),"Mod-Shift-ArrowDown":Zt(1),"Mod-Enter":Ve};function io(){return new D.Plugin({view(e){let n=e.dom.ownerDocument.createElement("div");return n.className="page-live",n.setAttribute("role","status"),n.setAttribute("aria-live","polite"),e.dom.parentElement.appendChild(n),{destroy:()=>n.remove()}}})}function Ct(e,n){let t=e.dom.parentElement?.querySelector(".page-live");t&&(t.textContent="",t.textContent=n)}var de=new D.PluginKey("tableRect");var{Selection:kn,TextSelection:K,NodeSelection:xn,Plugin:yn,PluginKey:An}=D,Q=T.nodes,H=e=>Z.closeHistory(e).setMeta(Et,!0);function Y(e,n,t=n,o=y(e)){let{lo:r,hi:s}=z(o,Math.min(n,t),Math.max(n,t)),a=o[r].at,i=o[s].end;return n<=t?new x(e.resolve(a),e.resolve(i)):new x(e.resolve(i),e.resolve(a))}function Sn(e,n=y(e.doc)){let[t,o]=ne(e.doc,e.selection,n);return z(n,t,o)}var _=(e,n,t)=>{for(let o=n;o>=0&&o<e.length;o+=t)if(!e[o].hidden)return o;return-1};function wn(e,n){if(e.selection instanceof x)return!1;let t=Math.min(e.selection.$head.index(0),e.doc.childCount-1);return n&&n(e.tr.setSelection(Y(e.doc,t))),!0}var ue=e=>(n,t)=>{let o=n.selection;if(!(o instanceof x))return!1;let r=y(n.doc),{lo:s,hi:a}=o.span(n.doc),i=e<0?_(r,s-1,-1):_(r,a+1,1);return i<0||t&&t(n.tr.setSelection(Y(n.doc,i)).scrollIntoView()),!0};function Dt(e,n,t,o){if(o<0)return n;let r=n;for(;e[r].subEnd<t;)r=e[r].subEnd+1;return r}function En(e,n){for(let t=n-1;t>=0;t--)if(e[t].up===e[n].up)return t;return n}var fe=e=>(n,t)=>{let o=n.selection;if(!(o instanceof x))return!1;let r=y(n.doc),{lo:s,hi:a}=o.span(n.doc),i=o.anchor<=o.head,l=i?s:Dt(r,s,a,1),c=i?Dt(r,s,a,1):s;return e>0?i||s===a||c===l?c=_(r,(i?a:c)+1,1):c=_(r,r[c].subEnd+1,1):!i||c===l?c=_(r,(i?c:s)-1,-1):c=En(r,c),c<0||t&&t(n.tr.setSelection(Y(n.doc,l,c,r)).scrollIntoView()),!0};function it(e,n){let t=e.selection;if(!(t instanceof x))return!1;if(n){let o=e.tr.delete(t.from,t.to);o.doc.content.size===0&&o.insert(0,Q.paragraph.create()),o.setSelection(kn.near(o.doc.resolve(Math.min(t.from,o.doc.content.size)),-1)),n(H(o).scrollIntoView())}return!0}function Mn({columns:e={},cards:n={}}){let t=dt(e),o=new Map(t.map(a=>[a,V("c")])),r=lt(null,null,t.length),s={};for(let a of new Set([...t,...Object.values(n).map(i=>i.col)])){let i=dt(Object.fromEntries(Object.entries(n).filter(([,c])=>c.col===a))),l=lt(null,null,i.length);i.forEach((c,d)=>{s[V("k")]={...n[c],col:o.get(a)??a,pos:l[d]}})}return{columns:Object.fromEntries(t.map((a,i)=>[o.get(a),{...e[a],pos:r[i]}])),cards:s}}function vn(e,n){let t=y(e.doc);if(!t.length)return!1;let{lo:o,hi:r}=Sn(e,t);if(n){let s=new Map;for(let f=o;f<=r;f++)t[f].node.type===Q.toggle&&t[f].node.attrs.id&&s.set(t[f].node.attrs.id,V());let a=[];for(let f=o;f<=r;f++){let p=t[f].node,u=p.attrs.parent??null;a.push(p.type.create({...p.attrs,...p.type===Q.board?Mn(p.attrs):{},id:s.get(p.attrs.id)??null,pos:null,parent:s.get(u)??u},p.content,p.marks))}let i=t[r].end,l=i-t[o].at,c=e.tr.insert(i,a),d=e.selection;c.setSelection(d instanceof x?new x(c.doc.resolve(i),c.doc.resolve(i+l)):K.create(c.doc,d.anchor+l,d.head+l)),n(H(c).scrollIntoView())}return!0}var he=(e,n,t,o)=>{for(let r=t;r<=o;r++)if(n[r].node.isTextblock)return n[r].end-1;return-1};function pe(e,n){let t=e.selection;if(!(t instanceof x))return!1;let o=y(e.doc),{lo:r,hi:s}=t.span(e.doc);if(n){let a=he(e.doc,o,r,s);n(e.tr.setSelection(a>=0?K.create(e.doc,a):xn.create(e.doc,o[r].at)))}return!0}var Tn=({$from:e,$to:n})=>{if(e.depth<2||n.depth<2)return null;let t=e.node(1);return t.type.name==="table"&&n.node(1)===t?{from:e.before(1),to:e.after(1)}:null};function Nn(e,n){let t=e.selection,{$from:o,$to:r}=t,s=o.parent.isTextblock&&o.sameParent(r)&&!de.getState(e),a=s&&o.parentOffset===0&&r.parentOffset===r.parent.content.size;if(s&&!a&&o.parent.content.size)return n&&n(e.tr.setSelection(K.create(e.doc,o.start(),o.end()))),!0;let i=Tn(t);return i&&!(t instanceof x&&t.from===i.from&&t.to===i.to)?(n&&n(e.tr.setSelection(new x(e.doc.resolve(i.from),e.doc.resolve(i.to)))),!0):(n&&n(e.tr.setSelection(new x(e.doc.resolve(0),e.doc.resolve(e.doc.content.size)))),!0)}var In=(e,n)=>{let t=e.state,o=t.selection;if(!(o instanceof x))return!1;let r=y(t.doc),{lo:s,hi:a}=o.span(t.doc),i=he(t.doc,r,s,a),l=t.tr;if(i<0){let c=r[a].end;l.insert(c,Q.paragraph.create({parent:r[s].node.attrs.parent??null})),l.setSelection(K.create(l.doc,c+1)),H(l)}else l.setSelection(K.create(l.doc,i));return l.insertText(n),e.dispatch(l.scrollIntoView()),!0},Cn=(e,n,t)=>{let o=e.selection;if(!(o instanceof K)||!t?.endOfTextblock("down"))return!1;let{$anchor:r,$head:s}=o;if(r.depth!==1||r.parent.type!==Q.toggle||r.parent.attrs.open||r.index(0)!==s.index(0))return!1;let a=y(e.doc),i=r.index(0),l=_(a,a[i].subEnd+1,1);return l<0?!1:(n&&n(e.tr.setSelection(Y(e.doc,i,l,a)).scrollIntoView()),!0)},On=e=>(n,t,o)=>n.selection instanceof x&&e(n,t,o),Dn={Escape:(e,n)=>pe(e,n)||wn(e,n),Enter:On(pe),ArrowUp:ue(-1),ArrowDown:ue(1),"Shift-ArrowUp":fe(-1),"Shift-ArrowDown":(e,n,t)=>fe(1)(e,n)||Cn(e,n,t),Backspace:it,"Alt-Backspace":it,"Ctrl-h":it,Delete:it,"Mod-d":vn,"Mod-a":Nn},Ot=new An("page-blocksel"),$n=e=>{let n=e.selection,{lo:t,hi:o}=n.span(e.doc);return y(e.doc).filter(r=>r.i>=t&&r.i<=o&&!r.hidden).length};function ko(){let e=Vt.keymap(Dn);return new yn({key:Ot,state:{init:()=>0,apply:(n,t,o,r)=>n.getMeta(ot)&&o.selection instanceof x&&!(r.selection instanceof x)?t+1:t},props:{handleKeyDown:(n,t)=>e.props.handleKeyDown(n,t),handleTextInput:(n,t,o,r)=>In(n,r),decorations(n){let t=n.selection;if(!(t instanceof x))return null;let o=[];return n.doc.nodesBetween(t.from,t.to,(r,s)=>(o.push($.Decoration.node(s,s+r.nodeSize,{class:"page-block-selected"})),!1)),$.DecorationSet.create(n.doc,o)},createSelectionBetween(n,t,o){let r=n.state.selection;return r instanceof x&&t.pos===r.anchor&&o.pos===r.head?r:null},handleDOMEvents:{mousedown(n,t){let o=n.state.selection;if(!t.shiftKey||!(o instanceof x)||t.button!==0)return!1;let r=n.posAtCoords({left:t.clientX,top:t.clientY});if(!r)return!1;let s=y(n.state.doc),a=Math.min(n.state.doc.resolve(r.inside>=0?r.inside:r.pos).index(0),s.length-1),{lo:i,hi:l}=o.span(n.state.doc),c=o.anchor<=o.head?i:Dt(s,i,l,1);return t.preventDefault(),n.dispatch(n.state.tr.setSelection(Y(n.state.doc,c,a,s))),!0}}},view:()=>({update(n,t){let o=n.state.selection,r=t.selection;if(o instanceof x&&!o.eq(r)){let s=$n(n.state);Ct(n,`${s} ${s===1?"block":"blocks"} selected`)}else r instanceof x&&!(o instanceof x)&&Ct(n,Ot.getState(n.state)!==Ot.getState(t)?"Block selection cleared because the document changed":"Selection cleared")}})})}var{Plugin:Ln,PluginKey:Bn,TextSelection:J}=D,{Decoration:Pn,DecorationSet:zn}=$,U=T.marks.link,Vn=e=>/^(https?:\/\/|mailto:|tel:|www\.)\S+$/i.test(e.trim())&&L(e)!==null;function $t(e,n){let t=e.resolve(n);if(!t.parent.inlineContent)return null;let o=U.isInSet((t.nodeAfter??t.nodeBefore)?.marks??[]);if(!o)return null;let r=[];t.parent.forEach((c,d)=>r.push({n:c,off:d}));let s=r.findIndex(({n:c,off:d})=>d<=t.parentOffset&&t.parentOffset<=d+c.nodeSize&&o.isInSet(c.marks));if(s<0)return null;let a=s,i=s;for(;a>0&&o.isInSet(r[a-1].n.marks);)a--;for(;i<r.length-1&&o.isInSet(r[i+1].n.marks);)i++;let l=t.start();return{from:l+r[a].off,to:l+r[i].off+r[i].n.nodeSize,href:o.attrs.href}}function me(e,n,t,o){let r=e.tr.removeMark(n,t,U);return o&&r.addMark(n,t,U.create({href:o})),H(r)}var B=new Bn("page-link"),Lt=new WeakMap,ge=e=>`<svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${e}</svg>`,Rn=ge('<path d="M9 3h4v4M13 3 7.5 8.5M11 9.5V13H3V5h3.5"/>'),qn=ge('<path d="M4 4l8 8M12 4l-8 8"/>');function j(e,n,t,o={}){let r=e.createElement(n);t&&(r.className=t);for(let[s,a]of Object.entries(o))r.setAttribute(s,a);return r}function _n(e,n,t){let o=null;return e.doc.nodesBetween(n,t,r=>{let s=U.isInSet(r.marks);s&&(o=s.attrs.href)}),o}var Bt=class{constructor(n){this.view=n,this.shell=n.dom.parentElement,this.doc=n.dom.ownerDocument,this.mode=null,this.range=null;let t=this.doc;this.dom=j(t,"div","page-link",{role:"dialog","aria-label":"Link",hidden:""}),this.input=j(t,"input","page-link-input",{type:"url","aria-label":"Link address",placeholder:"Paste or type a link",autocomplete:"off",spellcheck:"false"}),this.url=j(t,"a","page-link-url",{target:"_blank",rel:"noopener noreferrer"}),this.open=j(t,"a","page-link-btn",{"data-act":"open",target:"_blank",rel:"noopener noreferrer","aria-label":"Open link in a new tab",title:"Open in a new tab"}),this.open.innerHTML=Rn,this.edit=j(t,"button","page-link-btn",{type:"button","data-act":"edit"}),this.edit.textContent="Edit",this.remove=j(t,"button","page-link-btn",{type:"button","data-act":"remove","aria-label":"Remove link",title:"Remove link"}),this.remove.innerHTML=qn,this.dom.append(this.input,this.url,this.open,this.edit,this.remove),this.shell.append(this.dom),Lt.set(n,this),this.dom.addEventListener("mousedown",o=>{o.target!==this.input&&o.preventDefault()}),this.edit.addEventListener("click",()=>this.openEdit()),this.remove.addEventListener("click",()=>this.apply("")),this.input.addEventListener("keydown",o=>{o.isComposing||o.keyCode===229||(o.key==="Enter"?(o.preventDefault(),this.apply(this.input.value)):o.key==="Escape"&&(o.preventDefault(),this.close()))}),this.onDocDown=o=>{this.mode==="edit"&&!this.dom.contains(o.target)&&this.close(!1)},this.doc.addEventListener("mousedown",this.onDocDown,!0)}openEdit(){let n=this.view.state,t=n.selection;if(!(t instanceof J)||!t.$from.sameParent(t.$to)||!t.$from.parent.inlineContent||t.$from.parent.type.spec.code)return!1;let o=t.empty?$t(n.doc,t.head):null;return this.range=o??{from:t.from,to:t.to,href:t.empty?null:_n(n,t.from,t.to)},this.mode="edit",this.view.dispatch(n.tr.setMeta(B,{from:this.range.from,to:this.range.to})),this.render(),this.input.value=this.range.href??"",this.input.removeAttribute("aria-invalid"),this.input.focus(),this.input.select(),!0}apply(n){let t=String(n).trim(),o=t?L(t):null;if(t&&!o){this.input.setAttribute("aria-invalid","true");return}let r=this.view.state,s=B.getState(r)??(this.mode==="view"?this.range:null);if(!s)return this.close();let a;if(s.from===s.to){if(!o)return this.close();a=r.tr.insert(s.from,T.text(t,[U.create({href:o})])),a.setSelection(J.create(a.doc,s.from+t.length))}else a=me(r,s.from,s.to,o),a.setSelection(J.create(a.doc,s.to));this.view.dispatch(H(a).setMeta(B,null)),this.close()}close(n=!0){this.mode=null,this.range=null,B.getState(this.view.state)&&this.view.dispatch(this.view.state.tr.setMeta(B,null)),this.dom.hidden=!0,this.dom.dataset.mode="",n&&this.view.focus(),this.update(this.view)}render(){let n=this.mode==="edit",t=L(this.range?.href);this.dom.dataset.mode=this.mode??"",this.input.hidden=!n,this.url.hidden=n,this.edit.hidden=n,this.open.hidden=!t,this.remove.hidden=!this.range?.href,t?(this.open.href=t,this.url.href=t,this.url.textContent=t.replace(/^https?:\/\//,"")):(this.open.removeAttribute("href"),this.url.removeAttribute("href"),this.url.textContent=""),this.dom.hidden=!1,this.place()}place(){let n=this.range;if(!n)return;let t=this.shell.getBoundingClientRect(),o=this.view.coordsAtPos(n.from),r=this.view.coordsAtPos(n.to,-1);this.dom.style.setProperty("--page-pop-x",`${Math.min(o.left,r.left)-t.left}px`),this.dom.style.setProperty("--page-pop-y",`${Math.max(o.bottom,r.bottom)-t.top+6}px`)}update(n){if(this.view=n,this.mode==="edit"){let r=B.getState(n.state);if(r)return this.range={...this.range,...r},this.place();this.mode=null,this.range=null,this.dom.hidden=!0,this.dom.dataset.mode="";return}let t=n.state.selection,o=t instanceof J&&t.empty&&n.hasFocus()?$t(n.state.doc,t.head):null;if(!o||t.head===o.from||t.head===o.to){this.mode=null,this.range=null,this.dom.hidden=!0,this.dom.dataset.mode="";return}this.mode="view",this.range=o,this.render()}destroy(){this.doc.removeEventListener("mousedown",this.onDocDown,!0),this.dom.remove(),Lt.delete(this.view)}},Kn=e=>Lt.get(e)?.openEdit()??!1;function Hn(e,n){if(n.clipboardData?.files?.length)return!1;let t=n.clipboardData?.getData("text/plain")??"";if(!Vn(t))return!1;let o=e.state.selection;if(!(o instanceof J)||!o.$from.sameParent(o.$to)||o.$from.parent.type.spec.code)return!1;let r=L(t),s=o.empty?e.state.tr.replaceSelectionWith(T.text(t.trim(),[U.create({href:r})]),!1):me(e.state,o.from,o.to,r);return e.dispatch(s.scrollIntoView().setMeta("uiEvent","paste")),!0}function Eo(){return new Ln({key:B,state:{init:()=>null,apply(e,n){let t=e.getMeta(B);if(t!==void 0)return t;if(!n||!e.docChanged)return n;let o=e.mapping.mapResult(n.from,1),r=e.mapping.mapResult(n.to,n.from===n.to?1:-1);return o.deletedAcross||r.deletedAcross||n.from!==n.to&&o.pos>=r.pos?null:{from:o.pos,to:r.pos}}},view:e=>new Bt(e),props:{decorations(e){let n=B.getState(e);return n&&n.from<n.to?zn.create(e.doc,[Pn.inline(n.from,n.to,{class:"page-link-pending"})]):null},handleKeyDown(e,n){return(n.metaKey||n.ctrlKey)&&!n.altKey&&!n.shiftKey&&n.key.toLowerCase()==="k"?(n.preventDefault(),Kn(e)||!0):!1},handlePaste:Hn,handleClick(e,n,t){if(!(t.metaKey||t.ctrlKey))return!1;let o=$t(e.state.doc,n),r=L(o?.href);return r?(e.dom.ownerDocument.defaultView.open(r,"_blank","noopener,noreferrer"),!0):!1}}})}export{Kn as a,Eo as b,io as c,Ct as d,de as e,Et as f,q as g,y as h,Jn as i,xe as j,Zn as k,z as l,Ae as m,Se as n,x as o,G as p,re as q,Zt as r,Ee as s,Me as t,vt as u,to as v,eo as w,an as x,hn as y,no as z,oo as A,H as B,Y as C,Sn as D,it as E,vn as F,In as G,ko as H};
3
+ `);if(!n.some(r=>ee.test(r)))return null;let t=[],o=[];for(let r of n){if(!r.trim())continue;let s=ee.exec(r);if(!s){t.length=0,o.push(M.paragraph.create(null,r.trim()?T.text(r.trim()):null));continue}let a=s[1].replace(/\t/g," ").length;for(;t.length&&t[t.length-1]>a;)t.pop();(!t.length||t[t.length-1]<a)&&t.push(a);let i=Math.min(t.length-1,o.length&&S(o[o.length-1])?o[o.length-1].attrs.indent+1:0),l=s[4]!==void 0?"check":s[3]!==void 0?"ordered":"bullet";o.push(M.list_item.create({kind:l,indent:i,checked:s[4]==="x"||s[4]==="X"},s[5]?T.text(s[5]):null))}return new O.Slice(O.Fragment.from(o),0,0)}var ht=new Set(["UL","OL"]),mt=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","PRE","BLOCKQUOTE","UL","OL","LI","DETAILS","SUMMARY","TABLE","HR","FIGURE"]);function Ye(e){let n=e.querySelector(":scope > input[type=checkbox], :scope > p > input[type=checkbox], :scope > label > input[type=checkbox]");if(n)return{check:!0,checked:n.checked||n.hasAttribute("checked")};if(e.getAttribute("role")==="checkbox"||e.hasAttribute("aria-checked"))return{check:!0,checked:e.getAttribute("aria-checked")==="true"};if(e.hasAttribute("data-checked"))return{check:!0,checked:e.getAttribute("data-checked")==="true"};let o=e.className||"";return/\b(checked|task-list-item|to-do)\b/.test(o)||e.closest?.("ul.to-do-list, ul.contains-task-list")?{check:!0,checked:/\bchecked\b/.test(o)||!!e.querySelector(".checkbox-on")}:{check:!1,checked:!1}}function Je(e){let n=(e.getAttribute("style")||"")+";"+(e.parentElement?.getAttribute("style")||""),t=/list-style-type\s*:\s*([a-z-]+)/i.exec(e.getAttribute("style")||"")?.[1];return t?/decimal|alpha|roman|latin|greek/.test(t)?"ordered":"bullet":e.parentElement?.tagName==="OL"?"ordered":"bullet"}function Ze(e,n=globalThis.document){let t=n.createElement("div");t.innerHTML=e;for(let u of t.querySelectorAll('b[style*="font-weight:normal"], b[style*="font-weight: normal"]'))u.replaceWith(...u.childNodes);let o=0,r=n.createElement("div"),s=u=>{let h=parseInt(u.getAttribute("aria-level"),10);if(h>0)return h-1;let m=-1;for(let g=u.parentElement;g&&g!==t;g=g.parentElement)ht.has(g.tagName)&&m++;return Math.max(0,m)},a=[];function i(u,h,m){let g=n.createElement("div"),{check:E,checked:b}=Ye(u);g.setAttribute("data-page-li",""),g.setAttribute("data-kind",E?"check":Je(u)),g.setAttribute("data-checked",b?"true":"false"),g.dataset.depth=String(s(u)),h&&g.setAttribute("data-page-parent",h);let N=!0,C=[];for(let w of[...u.childNodes]){if(w.nodeType===1&&ht.has(w.tagName)){C.push(w);continue}if(!(w.nodeType===1&&w.tagName==="INPUT")){if(w.nodeType===1&&mt.has(w.tagName)){N||g.appendChild(n.createElement("br"));for(let P of[...w.childNodes])P.nodeType===1&&P.tagName==="INPUT"||g.appendChild(P);N=!1;continue}g.appendChild(w),(w.nodeType!==3||w.textContent.trim())&&(N=!1)}}m.appendChild(g),a.push(g);for(let w of C)l(w,h,m)}function l(u,h,m){let g=null,E=b=>{g||(g=n.createElement("p"),h&&g.setAttribute("data-page-parent",h),m.appendChild(g)),g.appendChild(b)};for(let b of[...u.childNodes])if(!(b.nodeType===1&&(b.tagName==="META"||b.tagName==="STYLE"))){if(b.nodeType===1&&b.tagName==="BR"){g=null;continue}if(b.nodeType!==1){b.nodeType===3&&(g||b.textContent.trim())&&E(b);continue}if(!mt.has(b.tagName)&&b.tagName!=="ASIDE"){E(b);continue}if(g=null,ht.has(b.tagName)){l(b,h,m);continue}if(b.tagName==="LI"){i(b,h,m);continue}if(b.tagName==="DETAILS"){let N=`paste-${++o}`,C=b.querySelector(":scope > summary"),w=n.createElement("div");w.setAttribute("data-page-toggle",N),b.hasAttribute("open")&&w.setAttribute("data-open","true"),h&&w.setAttribute("data-page-parent",h);let P=C?.querySelector(":scope > h1, :scope > h2, :scope > h3");P?(w.setAttribute("data-level",P.tagName[1]),w.append(...P.childNodes)):C&&w.append(...C.childNodes),m.appendChild(w);for(let Pt of[...b.childNodes])if(Pt!==C){let zt=n.createElement("div");zt.appendChild(Pt),l(zt,N,m)}continue}if(b.tagName==="DIV"&&!b.hasAttribute("data-page-li")&&[...b.children].some(N=>mt.has(N.tagName))){l(b,h,m);continue}h&&b.setAttribute("data-page-parent",h),m.appendChild(b)}}l(t,null,r);let c=a.length?Math.min(...a.map(u=>+u.dataset.depth)):0,d=null;for(let u of a){let h=+u.dataset.depth-c,m=d&&u.previousElementSibling===d?+d.getAttribute("data-indent")+1:0;u.setAttribute("data-indent",String(Math.min(h,m))),u.removeAttribute("data-depth"),d=u}let f=u=>{if(u.nodeType!==1||u.tagName==="IMG")return[u.cloneNode(!0)];let h=[],m=u.cloneNode(!1);for(let g of u.childNodes)for(let E of f(g))E.nodeType===1&&E.tagName==="IMG"?(m.hasChildNodes()&&h.push(m),h.push(E),m=u.cloneNode(!1)):m.appendChild(E);return(m.hasChildNodes()||!h.length)&&h.push(m),h};for(let u of[...r.children]){if(!u.matches("p, h1, h2, h3, h4, h5, h6, aside, div[data-page-li], div.page-li")||!u.querySelector("img"))continue;let h=f(u),m=u.getAttribute("data-page-parent");if(m)for(let g of h)g.setAttribute("data-page-parent",m);u.replaceWith(...h)}let p=t.querySelector("[data-pm-slice]");return p&&r.firstElementChild?.setAttribute("data-pm-slice",p.dataset.pmSlice),r.innerHTML}var gt=(e,n=0)=>e!==null&&e!==""&&Number.isInteger(+e)&&+e>=n?+e:null,v=e=>e.getAttribute("data-page-parent")||null,tn=Rt([]).type,en=Object.create(T,{marks:{value:{...T.marks,[nt]:tn}}}),ce=e=>{let n;try{n=Qt(e)}catch{return null}return!n||typeof n.t!="string"||n.t==="opaque_block"||Object.hasOwn(Ft,n.t)?null:n},nn=e=>{let n=ce(e);return n?{raw:n,parent:v(e)}:!1},on=e=>{let n=ce(e);if(!n||typeof n.c!="string"||!n.c)return O.Fragment.empty;let t=Ht(n.m,n.c.length);return O.Fragment.from(jt(T,n.c,t,T.nodes.opaque_block))},rn=e=>{try{return{entries:Wt(e.getAttribute(ut))}}catch{return!1}},X=null,sn=()=>import("./c-BAUBNYXK.js").then(e=>{X=e},()=>{}),an=new O.DOMParser(en,[{tag:"table",node:"table",getAttrs:e=>X?.table(e)??!1,getContent:e=>X.rows(e)},{tag:`div[${Ut}]`,node:"opaque_block",getAttrs:nn,getContent:on},{tag:`span[${ut}]`,mark:nt,getAttrs:rn},{tag:"div[data-page-li]",node:"list_item",getAttrs:e=>({kind:e.getAttribute("data-kind")||"bullet",indent:+e.getAttribute("data-indent")||0,checked:e.getAttribute("data-checked")==="true",parent:v(e)})},{tag:"div.page-li",node:"list_item",getAttrs:e=>({kind:e.getAttribute("data-kind")||"bullet",indent:+e.getAttribute("data-indent")||0,checked:e.getAttribute("data-checked")==="true",parent:v(e)})},{tag:"div[data-page-toggle]",node:"toggle",getAttrs:e=>({id:e.getAttribute("data-page-toggle"),open:e.getAttribute("data-open")==="true",parent:v(e),level:ft(Number(e.getAttribute("data-level")))})},{tag:"div.page-toggle",node:"toggle",getAttrs:e=>({id:e.getAttribute("data-id"),open:e.getAttribute("data-open")==="true",parent:null,level:ft(Number(e.getAttribute("data-level")))})},{tag:"h1",node:"heading",getAttrs:e=>({level:1,parent:v(e)})},{tag:"h2",node:"heading",getAttrs:e=>({level:2,parent:v(e)})},{tag:"h3",node:"heading",getAttrs:e=>({level:3,parent:v(e)})},{tag:"h4",node:"heading",getAttrs:e=>({level:3,parent:v(e)})},{tag:"pre",node:"code_block",preserveWhitespace:"full",getAttrs:e=>({lang:e.getAttribute("data-lang")||"",parent:v(e)})},{tag:"hr",node:"divider",getAttrs:e=>({parent:v(e)})},{tag:"aside.page-callout",node:"callout",getAttrs:e=>({parent:v(e)})},{tag:'figure:not([data-type]), figure[data-type="image"]',node:"image",getAttrs:e=>{let n=e.querySelector("img"),t=et(n?.getAttribute("src"));return t?{src:t,alt:n.getAttribute("alt")||"",caption:e.querySelector("figcaption")?.textContent||"",width:gt(e.getAttribute("data-width")??n.getAttribute("width"),1),align:be(e.getAttribute("data-align")),parent:v(e)}:!1}},{tag:"img[src]",node:"image",getAttrs:e=>{let n=et(e.getAttribute("src"));return n?{src:n,alt:e.getAttribute("alt")||"",width:gt(e.getAttribute("width"),1),parent:v(e)}:!1}},{tag:'div.page-file, div[data-type="file"]',node:"file",getAttrs:e=>{let n=L(e.getAttribute("data-src"));return n?{src:n,name:e.getAttribute("data-name")||"file",size:gt(e.getAttribute("data-size")),mime:e.getAttribute("data-mime")||null,parent:v(e)}:!1}},{tag:"p",node:"paragraph",getAttrs:e=>({parent:v(e)})},{tag:"br",node:"hard_break"},{tag:"strong",mark:"strong"},{tag:"b",mark:"strong",getAttrs:e=>/font-weight\s*:\s*(normal|[1-5]00)\b/.test(e.getAttribute("style")||"")?!1:null},{tag:"span",mark:"strong",getAttrs:e=>/font-weight\s*:\s*(bold|[6-9]00)\b/.test(e.getAttribute("style")||"")?null:!1},{tag:"em",mark:"em"},{tag:"i",mark:"em"},{tag:"span",mark:"em",getAttrs:e=>/font-style\s*:\s*italic/.test(e.getAttribute("style")||"")?null:!1},{tag:"s",mark:"strike"},{tag:"del",mark:"strike"},{tag:"code",mark:"code"},{tag:"a[href]",mark:"link",getAttrs:e=>{let n=L(e.getAttribute("href"));return n?{href:n}:!1}},{tag:"blockquote",node:"quote",getAttrs:e=>({parent:v(e)})},{tag:"u",mark:"underline"},{tag:"mark",mark:"highlight",getAttrs:e=>ct("highlight",{color:e.getAttribute("data-color")})??!1},{tag:"span[data-color]",mark:"text_color",getAttrs:e=>ct("text_color",{color:e.getAttribute("data-color")})??!1}]);function cn(e,n){let t=n.selection.$from,o=n.selection instanceof x,r=o?n.doc.child(n.selection.span().lo):t.depth>=1?t.node(1):null,s=r?k(r):null,a=r&&S(r)?r.attrs.indent:0,i=new Map;e.content.forEach(m=>{A(m)&&m.attrs.id&&i.set(m.attrs.id,V())});let l=[];e.content.forEach(m=>{if(!m.type.spec.group?.includes("block")){l.push(m);return}let g=k(m),E={...m.attrs,pos:null,id:A(m)?i.get(m.attrs.id)??null:null,parent:g!==null&&i.has(g)?i.get(g):s};S(m)&&(E.indent=m.attrs.indent+a),l.push(m.type.create(E,m.content,m.marks))});let c=!r||!(S(r)||A(r)),d=m=>m&&(S(m)||A(m)),f=c&&d(l[0])?0:e.openStart,p=l[l.length-1],u=new Set(i.values()),h=c&&(d(p)||p&&u.has(k(p)))?0:e.openEnd;return new O.Slice(O.Fragment.from(l),o?0:f,o?0:h)}var St=class extends O.DOMSerializer{serializeFragment(n,t,o){let r=super.serializeFragment(n,t,o);if(!n.firstChild?.isBlock)return r;let s=[...r.childNodes];return n.forEach((a,i,l)=>{let c=s[l];!c||c.nodeType!==1||(k(a)!==null&&c.setAttribute("data-page-parent",k(a)),A(a)&&a.attrs.id&&c.setAttribute("data-page-toggle",a.attrs.id),a.type===M.image&&a.attrs.width&&c.setAttribute("data-width",String(a.attrs.width)))}),X?.copy(n,s),r}},le=O.DOMSerializer.fromSchema(T),ln=e=>{let{t:n,...t}=e.attrs.raw??{},{c:o,m:r}=_t(e.content);return o?{t:n,...t,c:o,...r.some(Boolean)?{m:Kt(r)}:{}}:{t:n,...t}},dn=e=>["div",{"data-type":"newer-format",...Gt(ln(e))},0],un=e=>["span",Xt(e.attrs.entries),0],fn={...le.nodes,opaque_block:dn},pn={...le.marks,[nt]:un},hn=new St(fn,pn);function mn(e,n,t){let{$from:o}=e.state.selection,r=o.depth>=1?o.node(1):null;if(!r||!A(r)||r.attrs.open||t.content.childCount<2)return!1;let s=e.state.tr.setNodeMarkup(o.before(1),null,{...r.attrs,open:!0}).replaceSelection(t);return e.dispatch(s.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function gn(e){let n=!1;return e?.content?.descendants(t=>n?!1:((t.type===M.quote||t.isText&&t.marks.some(o=>qt.has(o.type.name)))&&(n=!0),!n)),n}function bn(e,n,t){let o=e.state.selection.from,r=e.state.selection.to,s=e.state.doc,a=()=>{let i=t.content.textBetween(0,t.content.size,`
4
+ `," ");return!e.isDestroyed&&i&&e.state.doc===s&&e.dispatch(e.state.tr.insertText(i,o,r)),!1};return import("./c-7PYNAULW.js").then(({pasteFormats:i})=>i(e,t,o,r),a),!0}function no(){return new wt({view(){return sn(),{}},props:{handlePaste(e,n,t){return gn(t)?bn(e,n,t):mn(e,n,t)},clipboardSerializer:hn,clipboardTextSerializer:e=>X?.text(e),transformPastedHTML:e=>Ze(e),clipboardParser:an,clipboardTextParser:(e,n,t)=>t?null:Qe(e),transformPasted:(e,n)=>cn(e,n.state)}})}var W=tt.chainCommands(Ce,Oe,Be,ze,De),R=tt.chainCommands($e,Le,Pe),oo={Enter:tt.chainCommands(ve,Te,Ne,Ie),Backspace:W,"Shift-Backspace":W,"Mod-Backspace":W,"Alt-Backspace":W,"Ctrl-h":W,Delete:R,"Shift-Delete":R,"Mod-Delete":R,"Alt-Delete":R,"Ctrl-d":R,"Ctrl-Alt-Backspace":R,Tab:Me,"Shift-Tab":vt,"Mod-Shift-ArrowUp":Zt(-1),"Mod-Shift-ArrowDown":Zt(1),"Mod-Enter":Ve};function io(){return new D.Plugin({view(e){let n=e.dom.ownerDocument.createElement("div");return n.className="page-live",n.setAttribute("role","status"),n.setAttribute("aria-live","polite"),e.dom.parentElement.appendChild(n),{destroy:()=>n.remove()}}})}function Ct(e,n){let t=e.dom.parentElement?.querySelector(".page-live");t&&(t.textContent="",t.textContent=n)}var de=new D.PluginKey("tableRect");var{Selection:kn,TextSelection:K,NodeSelection:xn,Plugin:yn,PluginKey:An}=D,Q=T.nodes,H=e=>Z.closeHistory(e).setMeta(Et,!0);function Y(e,n,t=n,o=y(e)){let{lo:r,hi:s}=z(o,Math.min(n,t),Math.max(n,t)),a=o[r].at,i=o[s].end;return n<=t?new x(e.resolve(a),e.resolve(i)):new x(e.resolve(i),e.resolve(a))}function Sn(e,n=y(e.doc)){let[t,o]=ne(e.doc,e.selection,n);return z(n,t,o)}var _=(e,n,t)=>{for(let o=n;o>=0&&o<e.length;o+=t)if(!e[o].hidden)return o;return-1};function wn(e,n){if(e.selection instanceof x)return!1;let t=Math.min(e.selection.$head.index(0),e.doc.childCount-1);return n&&n(e.tr.setSelection(Y(e.doc,t))),!0}var ue=e=>(n,t)=>{let o=n.selection;if(!(o instanceof x))return!1;let r=y(n.doc),{lo:s,hi:a}=o.span(n.doc),i=e<0?_(r,s-1,-1):_(r,a+1,1);return i<0||t&&t(n.tr.setSelection(Y(n.doc,i)).scrollIntoView()),!0};function Dt(e,n,t,o){if(o<0)return n;let r=n;for(;e[r].subEnd<t;)r=e[r].subEnd+1;return r}function En(e,n){for(let t=n-1;t>=0;t--)if(e[t].up===e[n].up)return t;return n}var fe=e=>(n,t)=>{let o=n.selection;if(!(o instanceof x))return!1;let r=y(n.doc),{lo:s,hi:a}=o.span(n.doc),i=o.anchor<=o.head,l=i?s:Dt(r,s,a,1),c=i?Dt(r,s,a,1):s;return e>0?i||s===a||c===l?c=_(r,(i?a:c)+1,1):c=_(r,r[c].subEnd+1,1):!i||c===l?c=_(r,(i?c:s)-1,-1):c=En(r,c),c<0||t&&t(n.tr.setSelection(Y(n.doc,l,c,r)).scrollIntoView()),!0};function it(e,n){let t=e.selection;if(!(t instanceof x))return!1;if(n){let o=e.tr.delete(t.from,t.to);o.doc.content.size===0&&o.insert(0,Q.paragraph.create()),o.setSelection(kn.near(o.doc.resolve(Math.min(t.from,o.doc.content.size)),-1)),n(H(o).scrollIntoView())}return!0}function Mn({columns:e={},cards:n={}}){let t=dt(e),o=new Map(t.map(a=>[a,V("c")])),r=lt(null,null,t.length),s={};for(let a of new Set([...t,...Object.values(n).map(i=>i.col)])){let i=dt(Object.fromEntries(Object.entries(n).filter(([,c])=>c.col===a))),l=lt(null,null,i.length);i.forEach((c,d)=>{s[V("k")]={...n[c],col:o.get(a)??a,pos:l[d]}})}return{columns:Object.fromEntries(t.map((a,i)=>[o.get(a),{...e[a],pos:r[i]}])),cards:s}}function vn(e,n){let t=y(e.doc);if(!t.length)return!1;let{lo:o,hi:r}=Sn(e,t);if(n){let s=new Map;for(let f=o;f<=r;f++)t[f].node.type===Q.toggle&&t[f].node.attrs.id&&s.set(t[f].node.attrs.id,V());let a=[];for(let f=o;f<=r;f++){let p=t[f].node,u=p.attrs.parent??null;a.push(p.type.create({...p.attrs,...p.type===Q.board?Mn(p.attrs):{},id:s.get(p.attrs.id)??null,pos:null,parent:s.get(u)??u},p.content,p.marks))}let i=t[r].end,l=i-t[o].at,c=e.tr.insert(i,a),d=e.selection;c.setSelection(d instanceof x?new x(c.doc.resolve(i),c.doc.resolve(i+l)):K.create(c.doc,d.anchor+l,d.head+l)),n(H(c).scrollIntoView())}return!0}var he=(e,n,t,o)=>{for(let r=t;r<=o;r++)if(n[r].node.isTextblock)return n[r].end-1;return-1};function pe(e,n){let t=e.selection;if(!(t instanceof x))return!1;let o=y(e.doc),{lo:r,hi:s}=t.span(e.doc);if(n){let a=he(e.doc,o,r,s);n(e.tr.setSelection(a>=0?K.create(e.doc,a):xn.create(e.doc,o[r].at)))}return!0}var Tn=({$from:e,$to:n})=>{if(e.depth<2||n.depth<2)return null;let t=e.node(1);return t.type.name==="table"&&n.node(1)===t?{from:e.before(1),to:e.after(1)}:null};function Nn(e,n){let t=e.selection,{$from:o,$to:r}=t,s=o.parent.isTextblock&&o.sameParent(r)&&!de.getState(e),a=s&&o.parentOffset===0&&r.parentOffset===r.parent.content.size;if(s&&!a&&o.parent.content.size)return n&&n(e.tr.setSelection(K.create(e.doc,o.start(),o.end()))),!0;let i=Tn(t);return i&&!(t instanceof x&&t.from===i.from&&t.to===i.to)?(n&&n(e.tr.setSelection(new x(e.doc.resolve(i.from),e.doc.resolve(i.to)))),!0):(n&&n(e.tr.setSelection(new x(e.doc.resolve(0),e.doc.resolve(e.doc.content.size)))),!0)}var In=(e,n)=>{let t=e.state,o=t.selection;if(!(o instanceof x))return!1;let r=y(t.doc),{lo:s,hi:a}=o.span(t.doc),i=he(t.doc,r,s,a),l=t.tr;if(i<0){let c=r[a].end;l.insert(c,Q.paragraph.create({parent:r[s].node.attrs.parent??null})),l.setSelection(K.create(l.doc,c+1)),H(l)}else l.setSelection(K.create(l.doc,i));return l.insertText(n),e.dispatch(l.scrollIntoView()),!0},Cn=(e,n,t)=>{let o=e.selection;if(!(o instanceof K)||!t?.endOfTextblock("down"))return!1;let{$anchor:r,$head:s}=o;if(r.depth!==1||r.parent.type!==Q.toggle||r.parent.attrs.open||r.index(0)!==s.index(0))return!1;let a=y(e.doc),i=r.index(0),l=_(a,a[i].subEnd+1,1);return l<0?!1:(n&&n(e.tr.setSelection(Y(e.doc,i,l,a)).scrollIntoView()),!0)},On=e=>(n,t,o)=>n.selection instanceof x&&e(n,t,o),Dn={Escape:(e,n)=>pe(e,n)||wn(e,n),Enter:On(pe),ArrowUp:ue(-1),ArrowDown:ue(1),"Shift-ArrowUp":fe(-1),"Shift-ArrowDown":(e,n,t)=>fe(1)(e,n)||Cn(e,n,t),Backspace:it,"Alt-Backspace":it,"Ctrl-h":it,Delete:it,"Mod-d":vn,"Mod-a":Nn},Ot=new An("page-blocksel"),$n=e=>{let n=e.selection,{lo:t,hi:o}=n.span(e.doc);return y(e.doc).filter(r=>r.i>=t&&r.i<=o&&!r.hidden).length};function ko(){let e=Vt.keymap(Dn);return new yn({key:Ot,state:{init:()=>0,apply:(n,t,o,r)=>n.getMeta(ot)&&o.selection instanceof x&&!(r.selection instanceof x)?t+1:t},props:{handleKeyDown:(n,t)=>e.props.handleKeyDown(n,t),handleTextInput:(n,t,o,r)=>In(n,r),decorations(n){let t=n.selection;if(!(t instanceof x))return null;let o=[];return n.doc.nodesBetween(t.from,t.to,(r,s)=>(o.push($.Decoration.node(s,s+r.nodeSize,{class:"page-block-selected"})),!1)),$.DecorationSet.create(n.doc,o)},createSelectionBetween(n,t,o){let r=n.state.selection;return r instanceof x&&t.pos===r.anchor&&o.pos===r.head?r:null},handleDOMEvents:{mousedown(n,t){let o=n.state.selection;if(!t.shiftKey||!(o instanceof x)||t.button!==0)return!1;let r=n.posAtCoords({left:t.clientX,top:t.clientY});if(!r)return!1;let s=y(n.state.doc),a=Math.min(n.state.doc.resolve(r.inside>=0?r.inside:r.pos).index(0),s.length-1),{lo:i,hi:l}=o.span(n.state.doc),c=o.anchor<=o.head?i:Dt(s,i,l,1);return t.preventDefault(),n.dispatch(n.state.tr.setSelection(Y(n.state.doc,c,a,s))),!0}}},view:()=>({update(n,t){let o=n.state.selection,r=t.selection;if(o instanceof x&&!o.eq(r)){let s=$n(n.state);Ct(n,`${s} ${s===1?"block":"blocks"} selected`)}else r instanceof x&&!(o instanceof x)&&Ct(n,Ot.getState(n.state)!==Ot.getState(t)?"Block selection cleared because the document changed":"Selection cleared")}})})}var{Plugin:Ln,PluginKey:Bn,TextSelection:J}=D,{Decoration:Pn,DecorationSet:zn}=$,U=T.marks.link,Vn=e=>/^(https?:\/\/|mailto:|tel:|www\.)\S+$/i.test(e.trim())&&L(e)!==null;function $t(e,n){let t=e.resolve(n);if(!t.parent.inlineContent)return null;let o=U.isInSet((t.nodeAfter??t.nodeBefore)?.marks??[]);if(!o)return null;let r=[];t.parent.forEach((c,d)=>r.push({n:c,off:d}));let s=r.findIndex(({n:c,off:d})=>d<=t.parentOffset&&t.parentOffset<=d+c.nodeSize&&o.isInSet(c.marks));if(s<0)return null;let a=s,i=s;for(;a>0&&o.isInSet(r[a-1].n.marks);)a--;for(;i<r.length-1&&o.isInSet(r[i+1].n.marks);)i++;let l=t.start();return{from:l+r[a].off,to:l+r[i].off+r[i].n.nodeSize,href:o.attrs.href}}function me(e,n,t,o){let r=e.tr.removeMark(n,t,U);return o&&r.addMark(n,t,U.create({href:o})),H(r)}var B=new Bn("page-link"),Lt=new WeakMap,ge=e=>`<svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${e}</svg>`,Rn=ge('<path d="M9 3h4v4M13 3 7.5 8.5M11 9.5V13H3V5h3.5"/>'),qn=ge('<path d="M4 4l8 8M12 4l-8 8"/>');function j(e,n,t,o={}){let r=e.createElement(n);t&&(r.className=t);for(let[s,a]of Object.entries(o))r.setAttribute(s,a);return r}function _n(e,n,t){let o=null;return e.doc.nodesBetween(n,t,r=>{let s=U.isInSet(r.marks);s&&(o=s.attrs.href)}),o}var Bt=class{constructor(n){this.view=n,this.shell=n.dom.parentElement,this.doc=n.dom.ownerDocument,this.mode=null,this.range=null;let t=this.doc;this.dom=j(t,"div","page-link",{role:"dialog","aria-label":"Link",hidden:""}),this.input=j(t,"input","page-link-input",{type:"url","aria-label":"Link address",placeholder:"Paste or type a link",autocomplete:"off",spellcheck:"false"}),this.url=j(t,"a","page-link-url",{target:"_blank",rel:"noopener noreferrer"}),this.open=j(t,"a","page-link-btn",{"data-act":"open",target:"_blank",rel:"noopener noreferrer","aria-label":"Open link in a new tab",title:"Open in a new tab"}),this.open.innerHTML=Rn,this.edit=j(t,"button","page-link-btn",{type:"button","data-act":"edit"}),this.edit.textContent="Edit",this.remove=j(t,"button","page-link-btn",{type:"button","data-act":"remove","aria-label":"Remove link",title:"Remove link"}),this.remove.innerHTML=qn,this.dom.append(this.input,this.url,this.open,this.edit,this.remove),this.shell.append(this.dom),Lt.set(n,this),this.dom.addEventListener("mousedown",o=>{o.target!==this.input&&o.preventDefault()}),this.edit.addEventListener("click",()=>this.openEdit()),this.remove.addEventListener("click",()=>this.apply("")),this.input.addEventListener("keydown",o=>{o.isComposing||o.keyCode===229||(o.key==="Enter"?(o.preventDefault(),this.apply(this.input.value)):o.key==="Escape"&&(o.preventDefault(),this.close()))}),this.onDocDown=o=>{this.mode==="edit"&&!this.dom.contains(o.target)&&this.close(!1)},this.doc.addEventListener("mousedown",this.onDocDown,!0)}openEdit(){let n=this.view.state,t=n.selection;if(!(t instanceof J)||!t.$from.sameParent(t.$to)||!t.$from.parent.inlineContent||t.$from.parent.type.spec.code)return!1;let o=t.empty?$t(n.doc,t.head):null;return this.range=o??{from:t.from,to:t.to,href:t.empty?null:_n(n,t.from,t.to)},this.mode="edit",this.view.dispatch(n.tr.setMeta(B,{from:this.range.from,to:this.range.to})),this.render(),this.input.value=this.range.href??"",this.input.removeAttribute("aria-invalid"),this.input.focus(),this.input.select(),!0}apply(n){let t=String(n).trim(),o=t?L(t):null;if(t&&!o){this.input.setAttribute("aria-invalid","true");return}let r=this.view.state,s=B.getState(r)??(this.mode==="view"?this.range:null);if(!s)return this.close();let a;if(s.from===s.to){if(!o)return this.close();a=r.tr.insert(s.from,T.text(t,[U.create({href:o})])),a.setSelection(J.create(a.doc,s.from+t.length))}else a=me(r,s.from,s.to,o),a.setSelection(J.create(a.doc,s.to));this.view.dispatch(H(a).setMeta(B,null)),this.close()}close(n=!0){this.mode=null,this.range=null,B.getState(this.view.state)&&this.view.dispatch(this.view.state.tr.setMeta(B,null)),this.dom.hidden=!0,this.dom.dataset.mode="",n&&this.view.focus(),this.update(this.view)}render(){let n=this.mode==="edit",t=L(this.range?.href);this.dom.dataset.mode=this.mode??"",this.input.hidden=!n,this.url.hidden=n,this.edit.hidden=n,this.open.hidden=!t,this.remove.hidden=!this.range?.href,t?(this.open.href=t,this.url.href=t,this.url.textContent=t.replace(/^https?:\/\//,"")):(this.open.removeAttribute("href"),this.url.removeAttribute("href"),this.url.textContent=""),this.dom.hidden=!1,this.place()}place(){let n=this.range;if(!n)return;let t=this.shell.getBoundingClientRect(),o=this.view.coordsAtPos(n.from),r=this.view.coordsAtPos(n.to,-1);this.dom.style.setProperty("--page-pop-x",`${Math.min(o.left,r.left)-t.left}px`),this.dom.style.setProperty("--page-pop-y",`${Math.max(o.bottom,r.bottom)-t.top+6}px`)}update(n){if(this.view=n,this.mode==="edit"){let r=B.getState(n.state);if(r)return this.range={...this.range,...r},this.place();this.mode=null,this.range=null,this.dom.hidden=!0,this.dom.dataset.mode="";return}let t=n.state.selection,o=t instanceof J&&t.empty&&n.hasFocus()?$t(n.state.doc,t.head):null;if(!o||t.head===o.from||t.head===o.to){this.mode=null,this.range=null,this.dom.hidden=!0,this.dom.dataset.mode="";return}this.mode="view",this.range=o,this.render()}destroy(){this.doc.removeEventListener("mousedown",this.onDocDown,!0),this.dom.remove(),Lt.delete(this.view)}},Kn=e=>Lt.get(e)?.openEdit()??!1;function Hn(e,n){if(n.clipboardData?.files?.length)return!1;let t=n.clipboardData?.getData("text/plain")??"";if(!Vn(t))return!1;let o=e.state.selection;if(!(o instanceof J)||!o.$from.sameParent(o.$to)||o.$from.parent.type.spec.code)return!1;let r=L(t),s=o.empty?e.state.tr.replaceSelectionWith(T.text(t.trim(),[U.create({href:r})]),!1):me(e.state,o.from,o.to,r);return e.dispatch(s.scrollIntoView().setMeta("uiEvent","paste")),!0}function Eo(){return new Ln({key:B,state:{init:()=>null,apply(e,n){let t=e.getMeta(B);if(t!==void 0)return t;if(!n||!e.docChanged)return n;let o=e.mapping.mapResult(n.from,1),r=e.mapping.mapResult(n.to,n.from===n.to?1:-1);return o.deletedAcross||r.deletedAcross||n.from!==n.to&&o.pos>=r.pos?null:{from:o.pos,to:r.pos}}},view:e=>new Bt(e),props:{decorations(e){let n=B.getState(e);return n&&n.from<n.to?zn.create(e.doc,[Pn.inline(n.from,n.to,{class:"page-link-pending"})]):null},handleKeyDown(e,n){return(n.metaKey||n.ctrlKey)&&!n.altKey&&!n.shiftKey&&n.key.toLowerCase()==="k"?(n.preventDefault(),Kn(e)||!0):!1},handlePaste:Hn,handleClick(e,n,t){if(!(t.metaKey||t.ctrlKey))return!1;let o=$t(e.state.doc,n),r=L(o?.href);return r?(e.dom.ownerDocument.defaultView.open(r,"_blank","noopener,noreferrer"),!0):!1}}})}export{Kn as a,Eo as b,io as c,Ct as d,de as e,Et as f,q as g,y as h,Jn as i,xe as j,Zn as k,z as l,Ae as m,Se as n,x as o,G as p,re as q,Zt as r,Ee as s,Me as t,vt as u,to as v,eo as w,an as x,hn as y,no as z,oo as A,H as B,Y as C,Sn as D,it as E,vn as F,In as G,ko as H};
@@ -1 +1 @@
1
- import{a as ae}from"./c-LKSL4AUJ.js";import{i as ne,j as re}from"./c-4TXNLX4K.js";import"./c-EXKHPOVC.js";import"./c-L5VFATT6.js";import"./c-MWXFLW4J.js";import"./c-ZK4GIZH2.js";import"./c-W4JCVLAB.js";import"./c-7K4SCQB7.js";import"./c-WMRJKQ2V.js";import{B as se}from"./c-AMU3BPPR.js";import{A as J,H as D,I as Z,J as N,O as ee,b as Y,j as U,k as G,m as K,na as te,ra as oe,x as Q}from"./c-QIXT3Q7C.js";import"./c-WCXLG3MV.js";import"./c-57XDY6HC.js";import{a as W}from"./c-I2SCCUEW.js";import"./c-EK63G3CG.js";import"./c-VHNSBD2M.js";var be="iframe, frame, frameset, object, embed, applet, meta, base, link, form, style, animate, set, animateMotion, animateTransform, portal",ye=/^(srcdoc|data|formaction|codebase|archive|ping|background|poster|lowsrc|dynsrc)$/i,we=/^\s*(javascript|vbscript|data):/i;function xe(o){let l=document.createElement("template");l.innerHTML=o;for(let a of l.content.querySelectorAll(be))a.remove();for(let a of l.content.querySelectorAll("*"))for(let{name:i,value:h}of[...a.attributes])(ye.test(i)||we.test(h.replace(/[\u0000-\u0020]/g,"")))&&a.removeAttribute(i);return l.innerHTML}var F=2*1024*1024,ce=32,le=1e4,P=class extends Error{constructor(l,a){super(a),this.name="MarkdownImportError",this.code=l}},pe="\uFFFC",de={type:"hard_break"},ue=new Set(["paragraph","heading","list","blockquote","code","table","hr","html","def","space"]),Me=new TextEncoder,ie=K.marks,fe=o=>o.slice().sort((l,a)=>l.type.rank-a.type.rank);function j(o,l,a){return o.some(i=>i.type===ie[l])?o:fe([...o,ie[l].create(a)])}function Se(o,{images:l=!0,refused:a=[],unsupported:i=[]}={}){let h=[],k="",z=[],S=()=>{k&&h.push({c:k,m:z}),k="",z=[]},O=(A,g)=>{let p=String(A??"");if(!p)return;let C=Q(fe(g));k+=p;for(let b=0;b<p.length;b++)z.push(C)},$=A=>{k+=pe,z.push("@"+JSON.stringify(A))},E=(A,g)=>{for(let p of A??[]){let C=p?.type;if(typeof C!="string")throw new P("malformed-input","A Markdown token has no type.");switch(C){case"text":Array.isArray(p.tokens)?E(p.tokens.filter(b=>typeof b?.type=="string"&&!ue.has(b.type)),g):O(p.text,g);break;case"escape":O(p.text,g);break;case"strong":E(p.tokens,j(g,"strong"));break;case"em":E(p.tokens,j(g,"em"));break;case"del":case"strike":E(p.tokens,j(g,"strike"));break;case"codespan":O(p.text,j(g,"code"));break;case"br":$(de);break;case"link":{let b=U(p.href);b?E(p.tokens,j(g,"link",{href:b})):(a.push({type:"link",href:String(p.href??"")}),E(p.tokens,g));break}case"image":{let b={src:String(p.href??""),alt:String(p.text??""),title:p.title??""};if(!l){O(b.alt,g);break}S(),h.push({image:b});break}case"html":O(p.text??p.raw,g);break;case"checkbox":break;default:i.push({type:C,text:String(p.raw??p.text??"")}),O(p.raw??p.text,g);break}}};return E(o,[]),S(),{parts:h}}function me(o){if(!Array.isArray(o))throw new P("malformed-input","Markdown import needs the lexer's token list.");let l=0;for(let e of o){if(!e||typeof e!="object"||typeof e.type!="string")throw new P("malformed-input","A Markdown token has no type.");l+=Me.encode(String(e.raw??"")).length}if(l>F)throw new P("input-too-large",`Markdown import is limited to ${F} bytes; this file is ${l}.`);let a=[],i=[],h=[],k=new Set,z=e=>{let t=N(e);for(;k.has(t);)t=N(e);return k.add(t),t},S=e=>{if(a.length+1>le)throw new P("too-many-blocks",`Markdown import is limited to ${le} blocks.`);a.push(e)},O=e=>{let t=e.depth+1;if(t>ce)throw new P("nesting-too-deep",`Markdown import is limited to ${ce} levels of nesting.`);return t},$=(e,t,{c:n,m:u})=>{let r={t:e,...t,c:n};return u.some(Boolean)&&(r.m=J(u)),r},E=e=>{let t=G(e.src);return t?{t:"image",src:t,...e.alt?{alt:e.alt}:{},...e.title?{caption:e.title}:{}}:(h.push({type:"image",href:e.src}),e.alt?$("paragraph",{},{c:e.alt,m:[]}):null)},A=(e,t,n)=>{for(let u of n.parts){if(!u.image){S($(e,t,u));continue}let r=E(u.image);r&&S(r)}},g=(e,t)=>A(t.quote?"quote":"paragraph",{},e),p=(e,t={})=>Se(e,{refused:h,unsupported:i,...t}),C=e=>{let t=String(e.raw??e.text??"");i.push({type:e.type,text:t}),S({t:"code_block",lang:"markdown",c:t})},b=(e,t)=>{for(let n of e??[]){let u=n?.type;if(typeof u!="string")throw new P("malformed-input","A Markdown token has no type.");switch(u){case"space":break;case"heading":{let r=Math.min(6,Math.max(1,Number.parseInt(n.depth,10)||1));A("heading",r===2?{}:{level:r},p(n.tokens,{images:!1}));break}case"paragraph":case"text":g(p(n.tokens??[n]),t);break;case"hr":S({t:"divider"});break;case"code":S({t:"code_block",...n.lang?{lang:String(n.lang)}:{},c:String(n.text??"")});break;case"html":{let r=String(n.text??n.raw??"");i.push({type:"HTML block cleaned",text:r}),S({t:"preserved",html:xe(oe(document).fallback(r))});break}case"blockquote":{let r=O(t);b(n.tokens,{...t,depth:r,quote:!0});break}case"list":{let r=O(t),s=t.indent??0,f=n.ordered?"ordered":"bullet";for(let c of n.items??[]){let m={c:"",m:[]},d=[];for(let y of c?.tokens??[]){let M=y?.type;if(!(M==="checkbox"||M==="space"))if(M==="text"||M==="paragraph"){m.c&&(m={c:m.c+pe,m:[...m.m,"@"+JSON.stringify(de)]});let v=M==="paragraph"?y.tokens??[]:[y];for(let x of p(v,{images:!1}).parts)m={c:m.c+x.c,m:[...m.m,...x.m]};d.push(...(y.tokens??[]).filter(x=>typeof x?.type=="string"&&ue.has(x.type)&&x.type!=="space"))}else d.push(y)}let w=c?.task?"check":f,B={...w==="bullet"?{}:{kind:w},...s?{indent:s}:{},...c?.task&&c.checked?{checked:!0}:{}};S($("list_item",B,m)),d.length&&b(d,{...t,depth:r,indent:s+1,quote:!1})}break}case"table":{let r=n.header??[];if(!r.length){C(n);break}let s=y=>p(y,{images:!1}).parts[0]??{c:"",m:[]},f=r.map(()=>z("c")),c=D(null,null,r.length),m=Object.fromEntries(f.map((y,M)=>[y,{pos:c[M],name:s(r[M]?.tokens).c}])),d=n.rows?.length?n.rows:[[]],w=D(null,null,d.length),B=d.map(y=>Object.fromEntries(f.map((M,v)=>{let x=s(y?.[v]?.tokens);return[M,x.m.some(Boolean)?{c:x.c,m:J(x.m)}:x.c]})));S({t:"table",cols:m,rows:Object.fromEntries(B.map((y,M)=>[z("r"),{pos:w[M],cells:y}]))});break}default:C(n);break}}};b(o,{depth:0,indent:0,quote:!1});let _=D(null,null,a.length),R={};return a.forEach((e,t)=>{R[z("b")]={...e,pos:_[t]}}),{blocks:R,unsupported:i,refused:h}}var Ee="markdown-import-preview",Te=new TextEncoder,Ae=o=>{let l=String(o??"").replace(/\s+/g," ").trim();return l.length>60?`${l.slice(0,60)}\u2026`:l},Oe=o=>typeof o.text=="function"?o.text():new Promise((l,a)=>{let i=new FileReader;i.onload=()=>l(i.result),i.onerror=()=>a(i.error),i.readAsText(o)}),ze=()=>globalThis.clay?.assets?.load?.("marked")??import("./c-XN6MBKI6.js"),$e=(o,l)=>{let a=-1;return o.forEach((i,h,k)=>{a<0&&i.attrs.id===l&&(a=k)}),a};function Ce(o){let l=o.selection.$from;if(l.depth>=1)return{node:l.node(1),at:l.before(1),textblock:l.parent.isTextblock};let a=Math.min(l.index(0),Math.max(0,o.doc.childCount-1)),i=0;for(let h=0;h<a;h++)i+=o.doc.child(h).nodeSize;return{node:o.doc.child(a),at:i,textblock:!1}}function ve(o){let{node:l,at:a,textblock:i}=Ce(o),h=o.selection,k=i?Math.max(0,h.from-a-1):0;return{id:l.attrs.id,textblock:i,size:l.isTextblock?l.content.size:0,fromOff:k,toOff:i?Math.max(k,h.to-a-1):0}}var Pe=o=>{try{return ae(te(o))>0}catch{return!0}},Be=o=>o?.code==="page-format-upgrade-required"?"This document needs a newer page format before Markdown can be added. The preview stays open.":o?.code==="page-format-unsupported"?"This host cannot record the newer page format this file needs. The preview stays open.":o?.code==="stale-target"?"The place this import was started from changed. The preview stays open.":o?.code==="empty-import"?"This file holds nothing that can be inserted.":"The Markdown could not be inserted. The preview stays open.";function Ue({view:o=null,load:l=ze}={}){if(!o)return{run:()=>Promise.resolve({ok:!1,code:"not-editing"}),dispose(){}};let a=o.dom.ownerDocument,i=null,h=null,k=!1,z=W({id:Ee,isPending:()=>i!==null}),S=()=>h??=Promise.resolve().then(l).catch(e=>{throw h=null,e});function O(){try{let e=o.dom.parentElement?.getBoundingClientRect?.()??{left:0,top:0},t=o.coordsAtPos(Math.min(o.state.selection.from,o.state.doc.content.size));return{x:Math.max(8,t.left-e.left),y:t.bottom+6-e.top}}catch{return null}}function $(){let e=i;if(!e)return!1;i=null;for(let[t,n,u,r]of e.listen)t.removeEventListener(n,u,r);return e.panel.remove(),!0}function E(){return $()?(o.focus?.(),{ok:!0,cancelled:!0}):{ok:!1,code:"cancelled"}}function A(e){let t=[],n=(c,m)=>{let d=a.createElement("div");return d.className=c,d.textContent=m,d};if(t.push(n("page-menu-title",e.error?"Couldn't read that Markdown":`Import ${e.name}`)),!e.error){let c=[`${e.count} block${e.count===1?"":"s"}`];e.unsupported.length&&c.push(`${e.unsupported.length} kept as written`),e.refused.length&&c.push(`${e.refused.length} address${e.refused.length===1?"":"es"} left out`),t.push(n("page-menu-title page-import-summary",c.join(" \xB7 ")))}let u=(c,m)=>{let d=a.createElement("div");return d.className=c,d.replaceChildren(...m.map(w=>n("page-import-row",w))),d};e.unsupported.length&&t.push(u("page-import-unsupported",e.unsupported.map(c=>`${c.type}: ${Ae(c.text)}`))),e.refused.length&&t.push(u("page-import-refused",e.refused.map(c=>`${c.type}: ${c.href}`)));let r=e.error??e.notice??null;if(r){let c=a.createElement("p");c.className="page-import-error",c.setAttribute("role","alert"),c.textContent=r,t.push(c)}let s=(c,m)=>{let d=a.createElement("button");return d.type="button",d.className="page-menu-item",d.dataset.import=c,d.textContent=m,d.addEventListener("mousedown",w=>w.preventDefault()),d.addEventListener("click",()=>c==="insert"?p():E()),d},f=s("insert","Insert at the selection");f.disabled=!!e.error,t.push(f,s("cancel","Cancel")),e.panel.replaceChildren(...t)}function g(e,t){let n=o.state,u=n.doc,r=$e(u,e.id);if(r<0)return{ok:!1,code:"stale-target"};let s=u.child(r);if(e.textblock?!s.isTextblock||s.content.size!==e.size:s.isTextblock)return{ok:!1,code:"stale-target"};let f=Z(t).map(T=>ee(K,T,{...t[T],pos:null,parent:null}));if(!f.length)return{ok:!1,code:"empty-import"};let c=0;for(let T=0;T<r;T++)c+=u.child(T).nodeSize;let m=u.maybeChild(r+1),d=s.type.name==="toggle",w=e.textblock&&!d&&s.content.size>0,B=w||e.textblock&&!d&&s.content.size===0,y=w?Math.min(e.fromOff,s.content.size):0,M=w?Math.min(Math.max(y,e.toOff),s.content.size):0,v=w&&y>0?s.type.create({...s.attrs},s.content.cut(0,y)):null,x=w?s.content.cut(M):null,I=x&&x.size?s.type.create({...s.attrs,id:N(),pos:null},x):null,he=w&&!v?r>0?u.child(r-1).attrs.pos:null:s.attrs.pos,V=D(he,m?.attrs.pos??null,f.length+(I?1:0)),ke=d?s.attrs.id:s.attrs.parent??null,L=f.map((T,ge)=>T.type.create({...T.attrs,pos:V[ge],parent:ke},T.content,T.marks)),H=I?I.type.create({...I.attrs,pos:V[f.length]},I.content,I.marks):null,q=n.tr;B?q.replaceWith(c,c+s.nodeSize,[...v?[v]:[],...L,...H?[H]:[]]):q.insert(c+s.nodeSize,L),d&&!s.attrs.open&&L.length>0&&q.setNodeMarkup(c,null,{...s.attrs,open:!0});let X=c+(B?v?v.nodeSize:0:s.nodeSize);for(let T of L)X+=T.nodeSize;return q.setSelection(Y.TextSelection.near(q.doc.resolve(H?X:Math.max(0,X-1)),H?1:-1)),o.dispatch(se(q).scrollIntoView()),o.focus?.(),{ok:!0,blocks:L.length}}async function p(){let e=i;if(!e||e.error)return e?{ok:!1,code:"no-import"}:{ok:!1,code:"not-editing"};e.notice&&(e.notice=null,A(e));let t=()=>g(e.target,e.blocks),n=e.floor?await ne(o,t):t();return n?.ok?($(),n):(i===e&&(e.notice=Be(n),A(e)),n??{ok:!1,code:"import-failed"})}function C(e){!i||re(e,o)||(e.key==="Escape"?(e.preventDefault(),e.stopPropagation(),E()):e.key==="Enter"&&!e.target?.closest?.("[data-import]")&&(e.preventDefault(),e.stopPropagation(),p()))}function b(){return new Promise(e=>{let t=a.createElement("input");t.type="file",t.accept=".md,.markdown,text/markdown,text/plain",t.hidden=!0,t.className="page-markdown-input";let n=u=>{t.remove(),e(u)};t.addEventListener("change",()=>n(t.files?.[0]??null)),t.addEventListener("cancel",()=>n(null)),(o.dom.parentElement??a.body).appendChild(t),t.click()})}async function _(e,t=null){e.error=t;let n=a.createElement("div");n.className="page-menu page-import-preview",n.setAttribute("role","dialog"),n.setAttribute("aria-label","Import Markdown"),e.panel=n,i=e;let u=(f,c,m,d)=>{f.addEventListener(c,m,d),e.listen.push([f,c,m,d])};u(a,"keydown",f=>C(f),!0),u(a,"mousedown",f=>{e.panel.contains(f.target)||E()},!0),(o.dom.parentElement??a.body).appendChild(n),A(e);let r=O();r&&(n.style.setProperty("--page-pop-x",`${r.x}px`),n.style.setProperty("--page-pop-y",`${r.y}px`));let s=n.querySelector('[data-import="insert"]');return s&&!s.disabled&&s.focus?.(),{ok:!0,preview:!0}}async function R(e={}){if(k||o.isDestroyed)return{ok:!1,code:"not-editing"};$();let t=ve(o.state),n=e?.file??await b();if(!n)return{ok:!1,code:"cancelled"};if(typeof n.size=="number"&&n.size>F)return{ok:!1,code:"input-too-large"};let u;try{u=await Oe(n)}catch(f){return{ok:!1,code:"unreadable",error:f}}if(k||o.isDestroyed)return{ok:!1,code:"not-editing"};if(Te.encode(u).length>F)return{ok:!1,code:"input-too-large"};let r={target:t,name:String(n.name??"Markdown"),blocks:{},count:0,unsupported:[],refused:[],floor:0,panel:null,error:null,notice:null,listen:[]},s;try{let f=await S();s=me(new f.Marked().lexer(u))}catch(f){return k||o.isDestroyed?{ok:!1,code:"not-editing"}:_(r,String(f?.message??"The Markdown could not be read."))}return k||o.isDestroyed?{ok:!1,code:"not-editing"}:(r.blocks=s.blocks,r.count=Object.keys(s.blocks).length,r.unsupported=s.unsupported,r.refused=s.refused,r.floor=Pe(s.blocks)?1:0,_(r))}return{async run(e){return R(e)},dispose(){k=!0,$(),z.dispose()}}}export{Ue as createFeature};
1
+ import{a as ae}from"./c-LKSL4AUJ.js";import{i as ne,j as re}from"./c-4FJTBE6I.js";import"./c-EXKHPOVC.js";import"./c-L5VFATT6.js";import"./c-CQQDL6O4.js";import"./c-ZGDYHKG3.js";import"./c-W4JCVLAB.js";import"./c-7K4SCQB7.js";import"./c-WMRJKQ2V.js";import{B as se}from"./c-AIWN4QN4.js";import{A as J,H as D,I as Z,J as N,O as ee,b as Y,j as U,k as G,m as K,na as te,ra as oe,x as Q}from"./c-QIXT3Q7C.js";import"./c-WCXLG3MV.js";import"./c-57XDY6HC.js";import{a as W}from"./c-I2SCCUEW.js";import"./c-EK63G3CG.js";import"./c-VHNSBD2M.js";var be="iframe, frame, frameset, object, embed, applet, meta, base, link, form, style, animate, set, animateMotion, animateTransform, portal",ye=/^(srcdoc|data|formaction|codebase|archive|ping|background|poster|lowsrc|dynsrc)$/i,we=/^\s*(javascript|vbscript|data):/i;function xe(o){let l=document.createElement("template");l.innerHTML=o;for(let a of l.content.querySelectorAll(be))a.remove();for(let a of l.content.querySelectorAll("*"))for(let{name:i,value:h}of[...a.attributes])(ye.test(i)||we.test(h.replace(/[\u0000-\u0020]/g,"")))&&a.removeAttribute(i);return l.innerHTML}var F=2*1024*1024,ce=32,le=1e4,P=class extends Error{constructor(l,a){super(a),this.name="MarkdownImportError",this.code=l}},pe="\uFFFC",de={type:"hard_break"},ue=new Set(["paragraph","heading","list","blockquote","code","table","hr","html","def","space"]),Me=new TextEncoder,ie=K.marks,fe=o=>o.slice().sort((l,a)=>l.type.rank-a.type.rank);function j(o,l,a){return o.some(i=>i.type===ie[l])?o:fe([...o,ie[l].create(a)])}function Se(o,{images:l=!0,refused:a=[],unsupported:i=[]}={}){let h=[],k="",z=[],S=()=>{k&&h.push({c:k,m:z}),k="",z=[]},O=(A,g)=>{let p=String(A??"");if(!p)return;let C=Q(fe(g));k+=p;for(let b=0;b<p.length;b++)z.push(C)},$=A=>{k+=pe,z.push("@"+JSON.stringify(A))},E=(A,g)=>{for(let p of A??[]){let C=p?.type;if(typeof C!="string")throw new P("malformed-input","A Markdown token has no type.");switch(C){case"text":Array.isArray(p.tokens)?E(p.tokens.filter(b=>typeof b?.type=="string"&&!ue.has(b.type)),g):O(p.text,g);break;case"escape":O(p.text,g);break;case"strong":E(p.tokens,j(g,"strong"));break;case"em":E(p.tokens,j(g,"em"));break;case"del":case"strike":E(p.tokens,j(g,"strike"));break;case"codespan":O(p.text,j(g,"code"));break;case"br":$(de);break;case"link":{let b=U(p.href);b?E(p.tokens,j(g,"link",{href:b})):(a.push({type:"link",href:String(p.href??"")}),E(p.tokens,g));break}case"image":{let b={src:String(p.href??""),alt:String(p.text??""),title:p.title??""};if(!l){O(b.alt,g);break}S(),h.push({image:b});break}case"html":O(p.text??p.raw,g);break;case"checkbox":break;default:i.push({type:C,text:String(p.raw??p.text??"")}),O(p.raw??p.text,g);break}}};return E(o,[]),S(),{parts:h}}function me(o){if(!Array.isArray(o))throw new P("malformed-input","Markdown import needs the lexer's token list.");let l=0;for(let e of o){if(!e||typeof e!="object"||typeof e.type!="string")throw new P("malformed-input","A Markdown token has no type.");l+=Me.encode(String(e.raw??"")).length}if(l>F)throw new P("input-too-large",`Markdown import is limited to ${F} bytes; this file is ${l}.`);let a=[],i=[],h=[],k=new Set,z=e=>{let t=N(e);for(;k.has(t);)t=N(e);return k.add(t),t},S=e=>{if(a.length+1>le)throw new P("too-many-blocks",`Markdown import is limited to ${le} blocks.`);a.push(e)},O=e=>{let t=e.depth+1;if(t>ce)throw new P("nesting-too-deep",`Markdown import is limited to ${ce} levels of nesting.`);return t},$=(e,t,{c:n,m:u})=>{let r={t:e,...t,c:n};return u.some(Boolean)&&(r.m=J(u)),r},E=e=>{let t=G(e.src);return t?{t:"image",src:t,...e.alt?{alt:e.alt}:{},...e.title?{caption:e.title}:{}}:(h.push({type:"image",href:e.src}),e.alt?$("paragraph",{},{c:e.alt,m:[]}):null)},A=(e,t,n)=>{for(let u of n.parts){if(!u.image){S($(e,t,u));continue}let r=E(u.image);r&&S(r)}},g=(e,t)=>A(t.quote?"quote":"paragraph",{},e),p=(e,t={})=>Se(e,{refused:h,unsupported:i,...t}),C=e=>{let t=String(e.raw??e.text??"");i.push({type:e.type,text:t}),S({t:"code_block",lang:"markdown",c:t})},b=(e,t)=>{for(let n of e??[]){let u=n?.type;if(typeof u!="string")throw new P("malformed-input","A Markdown token has no type.");switch(u){case"space":break;case"heading":{let r=Math.min(6,Math.max(1,Number.parseInt(n.depth,10)||1));A("heading",r===2?{}:{level:r},p(n.tokens,{images:!1}));break}case"paragraph":case"text":g(p(n.tokens??[n]),t);break;case"hr":S({t:"divider"});break;case"code":S({t:"code_block",...n.lang?{lang:String(n.lang)}:{},c:String(n.text??"")});break;case"html":{let r=String(n.text??n.raw??"");i.push({type:"HTML block cleaned",text:r}),S({t:"preserved",html:xe(oe(document).fallback(r))});break}case"blockquote":{let r=O(t);b(n.tokens,{...t,depth:r,quote:!0});break}case"list":{let r=O(t),s=t.indent??0,f=n.ordered?"ordered":"bullet";for(let c of n.items??[]){let m={c:"",m:[]},d=[];for(let y of c?.tokens??[]){let M=y?.type;if(!(M==="checkbox"||M==="space"))if(M==="text"||M==="paragraph"){m.c&&(m={c:m.c+pe,m:[...m.m,"@"+JSON.stringify(de)]});let v=M==="paragraph"?y.tokens??[]:[y];for(let x of p(v,{images:!1}).parts)m={c:m.c+x.c,m:[...m.m,...x.m]};d.push(...(y.tokens??[]).filter(x=>typeof x?.type=="string"&&ue.has(x.type)&&x.type!=="space"))}else d.push(y)}let w=c?.task?"check":f,B={...w==="bullet"?{}:{kind:w},...s?{indent:s}:{},...c?.task&&c.checked?{checked:!0}:{}};S($("list_item",B,m)),d.length&&b(d,{...t,depth:r,indent:s+1,quote:!1})}break}case"table":{let r=n.header??[];if(!r.length){C(n);break}let s=y=>p(y,{images:!1}).parts[0]??{c:"",m:[]},f=r.map(()=>z("c")),c=D(null,null,r.length),m=Object.fromEntries(f.map((y,M)=>[y,{pos:c[M],name:s(r[M]?.tokens).c}])),d=n.rows?.length?n.rows:[[]],w=D(null,null,d.length),B=d.map(y=>Object.fromEntries(f.map((M,v)=>{let x=s(y?.[v]?.tokens);return[M,x.m.some(Boolean)?{c:x.c,m:J(x.m)}:x.c]})));S({t:"table",cols:m,rows:Object.fromEntries(B.map((y,M)=>[z("r"),{pos:w[M],cells:y}]))});break}default:C(n);break}}};b(o,{depth:0,indent:0,quote:!1});let _=D(null,null,a.length),R={};return a.forEach((e,t)=>{R[z("b")]={...e,pos:_[t]}}),{blocks:R,unsupported:i,refused:h}}var Ee="markdown-import-preview",Te=new TextEncoder,Ae=o=>{let l=String(o??"").replace(/\s+/g," ").trim();return l.length>60?`${l.slice(0,60)}\u2026`:l},Oe=o=>typeof o.text=="function"?o.text():new Promise((l,a)=>{let i=new FileReader;i.onload=()=>l(i.result),i.onerror=()=>a(i.error),i.readAsText(o)}),ze=()=>globalThis.clay?.assets?.load?.("marked")??import("./c-XN6MBKI6.js"),$e=(o,l)=>{let a=-1;return o.forEach((i,h,k)=>{a<0&&i.attrs.id===l&&(a=k)}),a};function Ce(o){let l=o.selection.$from;if(l.depth>=1)return{node:l.node(1),at:l.before(1),textblock:l.parent.isTextblock};let a=Math.min(l.index(0),Math.max(0,o.doc.childCount-1)),i=0;for(let h=0;h<a;h++)i+=o.doc.child(h).nodeSize;return{node:o.doc.child(a),at:i,textblock:!1}}function ve(o){let{node:l,at:a,textblock:i}=Ce(o),h=o.selection,k=i?Math.max(0,h.from-a-1):0;return{id:l.attrs.id,textblock:i,size:l.isTextblock?l.content.size:0,fromOff:k,toOff:i?Math.max(k,h.to-a-1):0}}var Pe=o=>{try{return ae(te(o))>0}catch{return!0}},Be=o=>o?.code==="page-format-upgrade-required"?"This document needs a newer page format before Markdown can be added. The preview stays open.":o?.code==="page-format-unsupported"?"This host cannot record the newer page format this file needs. The preview stays open.":o?.code==="stale-target"?"The place this import was started from changed. The preview stays open.":o?.code==="empty-import"?"This file holds nothing that can be inserted.":"The Markdown could not be inserted. The preview stays open.";function Ue({view:o=null,load:l=ze}={}){if(!o)return{run:()=>Promise.resolve({ok:!1,code:"not-editing"}),dispose(){}};let a=o.dom.ownerDocument,i=null,h=null,k=!1,z=W({id:Ee,isPending:()=>i!==null}),S=()=>h??=Promise.resolve().then(l).catch(e=>{throw h=null,e});function O(){try{let e=o.dom.parentElement?.getBoundingClientRect?.()??{left:0,top:0},t=o.coordsAtPos(Math.min(o.state.selection.from,o.state.doc.content.size));return{x:Math.max(8,t.left-e.left),y:t.bottom+6-e.top}}catch{return null}}function $(){let e=i;if(!e)return!1;i=null;for(let[t,n,u,r]of e.listen)t.removeEventListener(n,u,r);return e.panel.remove(),!0}function E(){return $()?(o.focus?.(),{ok:!0,cancelled:!0}):{ok:!1,code:"cancelled"}}function A(e){let t=[],n=(c,m)=>{let d=a.createElement("div");return d.className=c,d.textContent=m,d};if(t.push(n("page-menu-title",e.error?"Couldn't read that Markdown":`Import ${e.name}`)),!e.error){let c=[`${e.count} block${e.count===1?"":"s"}`];e.unsupported.length&&c.push(`${e.unsupported.length} kept as written`),e.refused.length&&c.push(`${e.refused.length} address${e.refused.length===1?"":"es"} left out`),t.push(n("page-menu-title page-import-summary",c.join(" \xB7 ")))}let u=(c,m)=>{let d=a.createElement("div");return d.className=c,d.replaceChildren(...m.map(w=>n("page-import-row",w))),d};e.unsupported.length&&t.push(u("page-import-unsupported",e.unsupported.map(c=>`${c.type}: ${Ae(c.text)}`))),e.refused.length&&t.push(u("page-import-refused",e.refused.map(c=>`${c.type}: ${c.href}`)));let r=e.error??e.notice??null;if(r){let c=a.createElement("p");c.className="page-import-error",c.setAttribute("role","alert"),c.textContent=r,t.push(c)}let s=(c,m)=>{let d=a.createElement("button");return d.type="button",d.className="page-menu-item",d.dataset.import=c,d.textContent=m,d.addEventListener("mousedown",w=>w.preventDefault()),d.addEventListener("click",()=>c==="insert"?p():E()),d},f=s("insert","Insert at the selection");f.disabled=!!e.error,t.push(f,s("cancel","Cancel")),e.panel.replaceChildren(...t)}function g(e,t){let n=o.state,u=n.doc,r=$e(u,e.id);if(r<0)return{ok:!1,code:"stale-target"};let s=u.child(r);if(e.textblock?!s.isTextblock||s.content.size!==e.size:s.isTextblock)return{ok:!1,code:"stale-target"};let f=Z(t).map(T=>ee(K,T,{...t[T],pos:null,parent:null}));if(!f.length)return{ok:!1,code:"empty-import"};let c=0;for(let T=0;T<r;T++)c+=u.child(T).nodeSize;let m=u.maybeChild(r+1),d=s.type.name==="toggle",w=e.textblock&&!d&&s.content.size>0,B=w||e.textblock&&!d&&s.content.size===0,y=w?Math.min(e.fromOff,s.content.size):0,M=w?Math.min(Math.max(y,e.toOff),s.content.size):0,v=w&&y>0?s.type.create({...s.attrs},s.content.cut(0,y)):null,x=w?s.content.cut(M):null,I=x&&x.size?s.type.create({...s.attrs,id:N(),pos:null},x):null,he=w&&!v?r>0?u.child(r-1).attrs.pos:null:s.attrs.pos,V=D(he,m?.attrs.pos??null,f.length+(I?1:0)),ke=d?s.attrs.id:s.attrs.parent??null,L=f.map((T,ge)=>T.type.create({...T.attrs,pos:V[ge],parent:ke},T.content,T.marks)),H=I?I.type.create({...I.attrs,pos:V[f.length]},I.content,I.marks):null,q=n.tr;B?q.replaceWith(c,c+s.nodeSize,[...v?[v]:[],...L,...H?[H]:[]]):q.insert(c+s.nodeSize,L),d&&!s.attrs.open&&L.length>0&&q.setNodeMarkup(c,null,{...s.attrs,open:!0});let X=c+(B?v?v.nodeSize:0:s.nodeSize);for(let T of L)X+=T.nodeSize;return q.setSelection(Y.TextSelection.near(q.doc.resolve(H?X:Math.max(0,X-1)),H?1:-1)),o.dispatch(se(q).scrollIntoView()),o.focus?.(),{ok:!0,blocks:L.length}}async function p(){let e=i;if(!e||e.error)return e?{ok:!1,code:"no-import"}:{ok:!1,code:"not-editing"};e.notice&&(e.notice=null,A(e));let t=()=>g(e.target,e.blocks),n=e.floor?await ne(o,t):t();return n?.ok?($(),n):(i===e&&(e.notice=Be(n),A(e)),n??{ok:!1,code:"import-failed"})}function C(e){!i||re(e,o)||(e.key==="Escape"?(e.preventDefault(),e.stopPropagation(),E()):e.key==="Enter"&&!e.target?.closest?.("[data-import]")&&(e.preventDefault(),e.stopPropagation(),p()))}function b(){return new Promise(e=>{let t=a.createElement("input");t.type="file",t.accept=".md,.markdown,text/markdown,text/plain",t.hidden=!0,t.className="page-markdown-input";let n=u=>{t.remove(),e(u)};t.addEventListener("change",()=>n(t.files?.[0]??null)),t.addEventListener("cancel",()=>n(null)),(o.dom.parentElement??a.body).appendChild(t),t.click()})}async function _(e,t=null){e.error=t;let n=a.createElement("div");n.className="page-menu page-import-preview",n.setAttribute("role","dialog"),n.setAttribute("aria-label","Import Markdown"),e.panel=n,i=e;let u=(f,c,m,d)=>{f.addEventListener(c,m,d),e.listen.push([f,c,m,d])};u(a,"keydown",f=>C(f),!0),u(a,"mousedown",f=>{e.panel.contains(f.target)||E()},!0),(o.dom.parentElement??a.body).appendChild(n),A(e);let r=O();r&&(n.style.setProperty("--page-pop-x",`${r.x}px`),n.style.setProperty("--page-pop-y",`${r.y}px`));let s=n.querySelector('[data-import="insert"]');return s&&!s.disabled&&s.focus?.(),{ok:!0,preview:!0}}async function R(e={}){if(k||o.isDestroyed)return{ok:!1,code:"not-editing"};$();let t=ve(o.state),n=e?.file??await b();if(!n)return{ok:!1,code:"cancelled"};if(typeof n.size=="number"&&n.size>F)return{ok:!1,code:"input-too-large"};let u;try{u=await Oe(n)}catch(f){return{ok:!1,code:"unreadable",error:f}}if(k||o.isDestroyed)return{ok:!1,code:"not-editing"};if(Te.encode(u).length>F)return{ok:!1,code:"input-too-large"};let r={target:t,name:String(n.name??"Markdown"),blocks:{},count:0,unsupported:[],refused:[],floor:0,panel:null,error:null,notice:null,listen:[]},s;try{let f=await S();s=me(new f.Marked().lexer(u))}catch(f){return k||o.isDestroyed?{ok:!1,code:"not-editing"}:_(r,String(f?.message??"The Markdown could not be read."))}return k||o.isDestroyed?{ok:!1,code:"not-editing"}:(r.blocks=s.blocks,r.count=Object.keys(s.blocks).length,r.unsupported=s.unsupported,r.refused=s.refused,r.floor=Pe(s.blocks)?1:0,_(r))}return{async run(e){return R(e)},dispose(){k=!0,$(),z.dispose()}}}export{Ue as createFeature};
@@ -1,4 +1,4 @@
1
- import{x as O}from"./c-AMU3BPPR.js";import{H as x,I as C,J as $,a as A,m as N}from"./c-QIXT3Q7C.js";import"./c-VHNSBD2M.js";var g=N.nodes,H=e=>e.attrs.parent??null,_=e=>{let a=new Set;return e.forEach(t=>t.forEach(o=>a.add(o.attrs.col))),C(e.attrs.cols).filter(t=>a.has(t))};function S(e,a){let t=a.ownerDocument,o=t.createElement("thead").appendChild(t.createElement("tr"));for(let s of _(e)){let p=e.attrs.cols[s],r=o.appendChild(t.createElement("th"));r.setAttribute("data-col",s),r.setAttribute("scope","col"),p.kind&&r.setAttribute("data-kind",p.kind),p.width&&(r.setAttribute("data-width",String(p.width)),r.style.width=`${p.width}px`),r.textContent=p.name??""}a.prepend(o.parentNode),e.attrs.sort&&a.setAttribute("data-sort",JSON.stringify(e.attrs.sort))}function v(e,a){let t=[];e.forEach((o,s,p)=>{let r=a[p];if(!r||r.nodeType!==1)return;if(o.type===g.table&&S(o,r),o.type!==g.list_item||H(o)!==null){t=[];return}let f=r.ownerDocument,{indent:d,kind:i}=o.attrs,l=i==="ordered"?"OL":"UL";for(;t.length&&t.at(-1).indent>d;)t.pop();if(t.at(-1)?.indent===d&&t.at(-1).list.tagName!==l&&t.pop(),!t.length||t.at(-1).indent<d){let c=f.createElement(l);t.length?t.at(-1).li.append(c):r.before(c),t.push({indent:d,list:c,li:null})}let u=f.createElement("li");i==="check"&&(u.innerHTML=`<input type="checkbox" disabled${o.attrs.checked?" checked":""}>`),u.append(...r.childNodes),t.at(-1).list.append(u),t.at(-1).li=u,r.remove()})}var T=e=>/[\t\n\r"]/.test(e)?`"${e.replace(/"/g,'""')}"`:e;function q(e){if(!e.content.firstChild?.type.spec.group?.includes("block"))return null;let a="",t=[],o=!1;return e.content.forEach((s,p,r)=>{let f=s.type===g.list_item,d=s.textBetween(0,s.content.size,`
1
+ import{x as O}from"./c-AIWN4QN4.js";import{H as x,I as C,J as $,a as A,m as N}from"./c-QIXT3Q7C.js";import"./c-VHNSBD2M.js";var g=N.nodes,H=e=>e.attrs.parent??null,_=e=>{let a=new Set;return e.forEach(t=>t.forEach(o=>a.add(o.attrs.col))),C(e.attrs.cols).filter(t=>a.has(t))};function S(e,a){let t=a.ownerDocument,o=t.createElement("thead").appendChild(t.createElement("tr"));for(let s of _(e)){let p=e.attrs.cols[s],r=o.appendChild(t.createElement("th"));r.setAttribute("data-col",s),r.setAttribute("scope","col"),p.kind&&r.setAttribute("data-kind",p.kind),p.width&&(r.setAttribute("data-width",String(p.width)),r.style.width=`${p.width}px`),r.textContent=p.name??""}a.prepend(o.parentNode),e.attrs.sort&&a.setAttribute("data-sort",JSON.stringify(e.attrs.sort))}function v(e,a){let t=[];e.forEach((o,s,p)=>{let r=a[p];if(!r||r.nodeType!==1)return;if(o.type===g.table&&S(o,r),o.type!==g.list_item||H(o)!==null){t=[];return}let f=r.ownerDocument,{indent:d,kind:i}=o.attrs,l=i==="ordered"?"OL":"UL";for(;t.length&&t.at(-1).indent>d;)t.pop();if(t.at(-1)?.indent===d&&t.at(-1).list.tagName!==l&&t.pop(),!t.length||t.at(-1).indent<d){let c=f.createElement(l);t.length?t.at(-1).li.append(c):r.before(c),t.push({indent:d,list:c,li:null})}let u=f.createElement("li");i==="check"&&(u.innerHTML=`<input type="checkbox" disabled${o.attrs.checked?" checked":""}>`),u.append(...r.childNodes),t.at(-1).list.append(u),t.at(-1).li=u,r.remove()})}var T=e=>/[\t\n\r"]/.test(e)?`"${e.replace(/"/g,'""')}"`:e;function q(e){if(!e.content.firstChild?.type.spec.group?.includes("block"))return null;let a="",t=[],o=!1;return e.content.forEach((s,p,r)=>{let f=s.type===g.list_item,d=s.textBetween(0,s.content.size,`
2
2
 
3
3
  `);if(f){let{indent:i,kind:l}=s.attrs;for(;t.length&&t.at(-1).indent>i;)t.pop();t.at(-1)?.indent===i&&t.at(-1).kind!==l&&t.pop(),(!t.length||t.at(-1).indent<i)&&t.push({indent:i,kind:l,n:0});let u=t.at(-1),c=l==="ordered"?`${++u.n}.`:l==="check"?`- [${s.attrs.checked?"x":" "}]`:"-";d=`${" ".repeat(t.length-1)}${c} ${d}`}else t=[];if(s.type===g.table){let i=[_(s).map(l=>T(s.attrs.cols[l].name??""))];s.forEach(l=>{let u=[];l.forEach(c=>u.push(T(c.textContent))),i.push(u)}),d=i.map(l=>l.join(" ")).join(`
4
4
  `)}a+=(r?o&&f?`
@@ -1 +1 @@
1
- import{B as h,d as f,h as x}from"./c-AMU3BPPR.js";import{J as g,b as E,l as I,m as $}from"./c-QIXT3Q7C.js";var{Plugin:B,PluginKey:j}=E,k=$.nodes,m=new j("page-media"),L=1.5*1024*1024,u=new WeakMap,C=new WeakMap,U=(t,o)=>{let s=t.resolve(Math.max(0,Math.min(o,t.content.size)));return s.depth===0?s.pos:s.after(1)};function b(t,o){let s=x(t.doc),e=s[Math.min(o,s.length-1)],a=e.node.type===k.paragraph&&e.node.content.size===0;return{hostId:e.node.attrs.id,at:a?e.at:s[e.subEnd].end,parent:e.node.attrs.parent??null,replaceId:a?e.node.attrs.id:null}}var O={init:()=>({items:[],placed:{},picker:null}),apply(t,o){let{items:s,placed:e,picker:a}=o;if(t.docChanged&&(s=s.map(r=>({...r,pos:U(t.doc,t.mapping.map(r.pos,-1))}))),a&&t.docChanged&&(a={...a,place:{...a.place,at:U(t.doc,t.mapping.map(a.place.at,-1))}},a.remove)){let r=t.mapping.map(a.remove.from,1),c=t.mapping.map(a.remove.to,-1);a=r<=c&&t.doc.textBetween(r,c)===a.remove.text?{...a,remove:{...a.remove,from:r,to:c}}:null}let n=t.getMeta(m);if(n?.picker!==void 0&&(a=n.picker),n?.add&&(s=[...s,...n.add]),n?.update&&(s=s.map(r=>r.id===n.update.id?{...r,...n.update}:r)),n?.placed){let{id:r,at:c,size:d,blockId:p}=n.placed,i=o.items.find(l=>l.id===r);s=s.filter(l=>l.id!==r).map(l=>i&&l.pos===c&&l.group===i.group&&l.order>i.order?{...l,pos:l.pos+d}:l),i&&(e={...e,[i.group]:[...e[i.group]||[],p]})}n?.remove&&(s=s.filter(r=>r.id!==n.remove));for(let r of Object.keys(e))s.some(c=>c.group===r)||(e={...e},delete e[r]);return{items:s,placed:e,picker:a}}};function R(t,o,s){if(!o)return;let e=null,a=null;t.doc.forEach((n,r)=>{n.attrs.id===o&&e&&s.includes(e.attrs.id)&&(a={n,off:r}),e=n}),a&&a.n.type===k.paragraph&&a.n.content.size===0&&t.delete(a.off,a.off+a.n.nodeSize)}function P(t,o,s){let{items:e,placed:a}=m.getState(t),n=e.find(i=>i.id===o);if(!n)return null;let r=U(t.doc,n.pos),c=g(),d=(n.kind==="image"?k.image:k.file).create({...s,id:c,pos:null,parent:n.parent}),p=t.tr.insert(r,d);return e.some(i=>i.group===n.group&&i.id!==o)||R(p,n.replaceId,[...a[n.group]||[],c]),h(p).setMeta(m,{placed:{id:o,at:r,size:d.nodeSize,blockId:c}})}function F(t,o){let{items:s,placed:e}=m.getState(t),a=s.find(r=>r.id===o);if(!a)return null;let n=t.tr;return s.some(r=>r.group===a.group&&r.id!==o)||R(n,a.replaceId,e[a.group]||[]),n.docChanged&&h(n),n.setMeta(m,{remove:o})}function y(t,o,s=b(t.state,t.state.selection.$head.index(0))){if(o=[...o].filter(Boolean),!o.length)return!1;let e=g("g"),a=o.map((n,r)=>{let c=/^image\//.test(n.type||"")?"image":"file";return{id:g("u"),pos:s.at,group:e,order:r,file:n,kind:c,name:n.name||(c==="image"?"image":"file"),parent:s.parent,replaceId:s.replaceId,state:"uploading",percent:0,preview:c==="image"&&globalThis.URL?.createObjectURL?URL.createObjectURL(n):null}});t.dispatch(t.state.tr.setMeta(m,{add:a}));for(let n of a)H(t,n);return f(t,o.length===1?`Uploading ${a[0].name}`:`Uploading ${o.length} files`),!0}var z=(t,o)=>m.getState(t.state).items.find(s=>s.id===o),M=(t,o,s)=>t.dispatch(t.state.tr.setMeta(m,{update:{id:o,...s}})),A=(t,o)=>t.kind==="image"?{src:o,alt:"",caption:""}:{src:o,name:t.name,size:t.file.size??null,mime:t.file.type||null};function T(t,o,s){t.preview&&URL.revokeObjectURL?.(t.preview),s&&o.dispatch(s)}async function H(t,o){let s=u.get(t),e=new AbortController;s.aborts.set(o.id,e);let a=-5,n=({percent:d})=>{d-a<5&&d!==100||(a=d,u.has(t)&&z(t,o.id)&&M(t,o.id,{percent:d}))},r;try{r=await s.upload(o.file,{onProgress:n,signal:e.signal})}catch{r={code:"network",msg:"Upload failed"}}if(s.aborts.delete(o.id),!u.has(t)||!z(t,o.id))return;if(r?.ok){let d=I(r.uploads?.[0]?.url);if(d){T(o,t,P(t.state,o.id,A(o,d))),f(t,`${o.name} added`);return}r={code:"bad-response",msg:"The upload returned an invalid address"}}if((!r||typeof r!="object")&&(r={code:"bad-response",msg:"The upload returned an invalid response"}),r.code==="aborted")return T(o,t,F(t.state,o.id));if(r.code==="unsupported"){let d=/^image\/(png|jpeg|gif|webp)$/i.test(o.file.type)&&o.file.size<=L,p=d?"This host doesn't store files. You can keep this image inside the document, which makes the document larger.":o.kind==="image"&&o.file.size>L?"This host doesn't store files, and this image is over 1.5 MB, too large to keep inside the document.":"This host doesn't store files.";M(t,o.id,{state:d?"embed-choice":"error",code:r.code,message:p}),f(t,`${o.name}: ${p}`);return}let c=r.code==="timeout"?"The upload timed out. It may have arrived; trying again is safe.":r.msg||"Upload failed";M(t,o.id,{state:"error",code:r.code,message:c}),f(t,`${o.name}: ${c}`)}var Y=t=>t.replace(/<(meta|style|img)\b[^>]*>/gi,"").replace(/<[^>]+>/g,"").trim()!=="";function Q({upload:t,features:o=null}){let s=e=>{!o||o.has("media")||!u.has(e)||o.ensure("media").catch(()=>{})};return new B({key:m,state:O,view(e){let n=e.dom.ownerDocument.createElement("input");n.type="file",n.multiple=!0,n.hidden=!0,n.className="page-file-input",e.dom.parentElement.append(n),u.set(e,{upload:t,aborts:new Map,input:n}),n.addEventListener("change",()=>{let c=[...n.files??[]],d=m.getState(e.state).picker;if(e.dispatch(e.state.tr.setMeta(m,{picker:null})),c.length&&d){let{remove:p}=d;p&&e.state.doc.textBetween(p.from,p.to)===p.text&&e.dispatch(h(e.state.tr.delete(p.from,p.to)));let i=_(e.state.doc,d.place.hostId);(!d.place.hostId||i>=0)&&(y(e,c,i>=0?b(e.state,i):d.place),s(e))}n.value="",e.focus()}),n.addEventListener("cancel",()=>e.dispatch(e.state.tr.setMeta(m,{picker:null})));let r=c=>{let d=c.target.closest?.(".page-upload-btn");if(!d)return;c.preventDefault();let p=C.get(e),i=d.dataset.upload;d.dataset.act==="retry"?p?.retryUpload(e,i):d.dataset.act==="embed"?p?.embedUpload(e,i):p?.cancelUpload(e,i)};return e.dom.addEventListener("click",r),{destroy(){e.dom.removeEventListener("click",r);let c=u.get(e);u.delete(e);for(let d of m.getState(e.state).items)d.preview&&URL.revokeObjectURL?.(d.preview);for(let d of c.aborts.values())d.abort();n.remove()}}},props:{handlePaste(e,a){let n=a.clipboardData,r=[...n?.files??[]];if(!r.length||e.state.selection.$from.parent.type.spec.code||Y(n.getData("text/html")||""))return!1;let c=b(e.state,e.state.selection.$head.index(0));return a.preventDefault(),y(e,r,c),s(e),!0},handleDrop(e,a,n,r){let c=[...a.dataTransfer?.files??[]];if(r||!c.length)return!1;let d=e.posAtCoords({left:a.clientX,top:a.clientY});if(!d)return!1;let p=x(e.state.doc),i=Math.min(e.state.doc.resolve(d.pos).index(0),p.length-1),l=e.nodeDOM(p[i].at)?.getBoundingClientRect?.(),D=l&&a.clientY<l.top+l.height/2;a.preventDefault();let S={at:D?p[i].at:p[p[i].subEnd].end,parent:p[i].node.attrs.parent??null,replaceId:null};return y(e,c,S),s(e),!0}}})}var _=(t,o)=>{let s=-1;return t.forEach((e,a,n)=>{e.attrs.id===o&&(s=n)}),s};function V(t,o,s=b(t.state,t.state.selection.$head.index(0)),e=null){let a=u.get(t);if(!a)return!1;let n={place:s,remove:e&&{...e,text:t.state.doc.textBetween(e.from,e.to)}};return t.dispatch(t.state.tr.setMeta(m,{picker:n})),a.input.accept=o,a.input.click(),!0}export{m as a,L as b,u as c,C as d,U as e,b as f,P as g,F as h,z as i,M as j,A as k,T as l,H as m,Q as n,V as o};
1
+ import{B as h,d as f,h as x}from"./c-AIWN4QN4.js";import{J as g,b as E,l as I,m as $}from"./c-QIXT3Q7C.js";var{Plugin:B,PluginKey:j}=E,k=$.nodes,m=new j("page-media"),L=1.5*1024*1024,u=new WeakMap,C=new WeakMap,U=(t,o)=>{let s=t.resolve(Math.max(0,Math.min(o,t.content.size)));return s.depth===0?s.pos:s.after(1)};function b(t,o){let s=x(t.doc),e=s[Math.min(o,s.length-1)],a=e.node.type===k.paragraph&&e.node.content.size===0;return{hostId:e.node.attrs.id,at:a?e.at:s[e.subEnd].end,parent:e.node.attrs.parent??null,replaceId:a?e.node.attrs.id:null}}var O={init:()=>({items:[],placed:{},picker:null}),apply(t,o){let{items:s,placed:e,picker:a}=o;if(t.docChanged&&(s=s.map(r=>({...r,pos:U(t.doc,t.mapping.map(r.pos,-1))}))),a&&t.docChanged&&(a={...a,place:{...a.place,at:U(t.doc,t.mapping.map(a.place.at,-1))}},a.remove)){let r=t.mapping.map(a.remove.from,1),c=t.mapping.map(a.remove.to,-1);a=r<=c&&t.doc.textBetween(r,c)===a.remove.text?{...a,remove:{...a.remove,from:r,to:c}}:null}let n=t.getMeta(m);if(n?.picker!==void 0&&(a=n.picker),n?.add&&(s=[...s,...n.add]),n?.update&&(s=s.map(r=>r.id===n.update.id?{...r,...n.update}:r)),n?.placed){let{id:r,at:c,size:d,blockId:p}=n.placed,i=o.items.find(l=>l.id===r);s=s.filter(l=>l.id!==r).map(l=>i&&l.pos===c&&l.group===i.group&&l.order>i.order?{...l,pos:l.pos+d}:l),i&&(e={...e,[i.group]:[...e[i.group]||[],p]})}n?.remove&&(s=s.filter(r=>r.id!==n.remove));for(let r of Object.keys(e))s.some(c=>c.group===r)||(e={...e},delete e[r]);return{items:s,placed:e,picker:a}}};function R(t,o,s){if(!o)return;let e=null,a=null;t.doc.forEach((n,r)=>{n.attrs.id===o&&e&&s.includes(e.attrs.id)&&(a={n,off:r}),e=n}),a&&a.n.type===k.paragraph&&a.n.content.size===0&&t.delete(a.off,a.off+a.n.nodeSize)}function P(t,o,s){let{items:e,placed:a}=m.getState(t),n=e.find(i=>i.id===o);if(!n)return null;let r=U(t.doc,n.pos),c=g(),d=(n.kind==="image"?k.image:k.file).create({...s,id:c,pos:null,parent:n.parent}),p=t.tr.insert(r,d);return e.some(i=>i.group===n.group&&i.id!==o)||R(p,n.replaceId,[...a[n.group]||[],c]),h(p).setMeta(m,{placed:{id:o,at:r,size:d.nodeSize,blockId:c}})}function F(t,o){let{items:s,placed:e}=m.getState(t),a=s.find(r=>r.id===o);if(!a)return null;let n=t.tr;return s.some(r=>r.group===a.group&&r.id!==o)||R(n,a.replaceId,e[a.group]||[]),n.docChanged&&h(n),n.setMeta(m,{remove:o})}function y(t,o,s=b(t.state,t.state.selection.$head.index(0))){if(o=[...o].filter(Boolean),!o.length)return!1;let e=g("g"),a=o.map((n,r)=>{let c=/^image\//.test(n.type||"")?"image":"file";return{id:g("u"),pos:s.at,group:e,order:r,file:n,kind:c,name:n.name||(c==="image"?"image":"file"),parent:s.parent,replaceId:s.replaceId,state:"uploading",percent:0,preview:c==="image"&&globalThis.URL?.createObjectURL?URL.createObjectURL(n):null}});t.dispatch(t.state.tr.setMeta(m,{add:a}));for(let n of a)H(t,n);return f(t,o.length===1?`Uploading ${a[0].name}`:`Uploading ${o.length} files`),!0}var z=(t,o)=>m.getState(t.state).items.find(s=>s.id===o),M=(t,o,s)=>t.dispatch(t.state.tr.setMeta(m,{update:{id:o,...s}})),A=(t,o)=>t.kind==="image"?{src:o,alt:"",caption:""}:{src:o,name:t.name,size:t.file.size??null,mime:t.file.type||null};function T(t,o,s){t.preview&&URL.revokeObjectURL?.(t.preview),s&&o.dispatch(s)}async function H(t,o){let s=u.get(t),e=new AbortController;s.aborts.set(o.id,e);let a=-5,n=({percent:d})=>{d-a<5&&d!==100||(a=d,u.has(t)&&z(t,o.id)&&M(t,o.id,{percent:d}))},r;try{r=await s.upload(o.file,{onProgress:n,signal:e.signal})}catch{r={code:"network",msg:"Upload failed"}}if(s.aborts.delete(o.id),!u.has(t)||!z(t,o.id))return;if(r?.ok){let d=I(r.uploads?.[0]?.url);if(d){T(o,t,P(t.state,o.id,A(o,d))),f(t,`${o.name} added`);return}r={code:"bad-response",msg:"The upload returned an invalid address"}}if((!r||typeof r!="object")&&(r={code:"bad-response",msg:"The upload returned an invalid response"}),r.code==="aborted")return T(o,t,F(t.state,o.id));if(r.code==="unsupported"){let d=/^image\/(png|jpeg|gif|webp)$/i.test(o.file.type)&&o.file.size<=L,p=d?"This host doesn't store files. You can keep this image inside the document, which makes the document larger.":o.kind==="image"&&o.file.size>L?"This host doesn't store files, and this image is over 1.5 MB, too large to keep inside the document.":"This host doesn't store files.";M(t,o.id,{state:d?"embed-choice":"error",code:r.code,message:p}),f(t,`${o.name}: ${p}`);return}let c=r.code==="timeout"?"The upload timed out. It may have arrived; trying again is safe.":r.msg||"Upload failed";M(t,o.id,{state:"error",code:r.code,message:c}),f(t,`${o.name}: ${c}`)}var Y=t=>t.replace(/<(meta|style|img)\b[^>]*>/gi,"").replace(/<[^>]+>/g,"").trim()!=="";function Q({upload:t,features:o=null}){let s=e=>{!o||o.has("media")||!u.has(e)||o.ensure("media").catch(()=>{})};return new B({key:m,state:O,view(e){let n=e.dom.ownerDocument.createElement("input");n.type="file",n.multiple=!0,n.hidden=!0,n.className="page-file-input",e.dom.parentElement.append(n),u.set(e,{upload:t,aborts:new Map,input:n}),n.addEventListener("change",()=>{let c=[...n.files??[]],d=m.getState(e.state).picker;if(e.dispatch(e.state.tr.setMeta(m,{picker:null})),c.length&&d){let{remove:p}=d;p&&e.state.doc.textBetween(p.from,p.to)===p.text&&e.dispatch(h(e.state.tr.delete(p.from,p.to)));let i=_(e.state.doc,d.place.hostId);(!d.place.hostId||i>=0)&&(y(e,c,i>=0?b(e.state,i):d.place),s(e))}n.value="",e.focus()}),n.addEventListener("cancel",()=>e.dispatch(e.state.tr.setMeta(m,{picker:null})));let r=c=>{let d=c.target.closest?.(".page-upload-btn");if(!d)return;c.preventDefault();let p=C.get(e),i=d.dataset.upload;d.dataset.act==="retry"?p?.retryUpload(e,i):d.dataset.act==="embed"?p?.embedUpload(e,i):p?.cancelUpload(e,i)};return e.dom.addEventListener("click",r),{destroy(){e.dom.removeEventListener("click",r);let c=u.get(e);u.delete(e);for(let d of m.getState(e.state).items)d.preview&&URL.revokeObjectURL?.(d.preview);for(let d of c.aborts.values())d.abort();n.remove()}}},props:{handlePaste(e,a){let n=a.clipboardData,r=[...n?.files??[]];if(!r.length||e.state.selection.$from.parent.type.spec.code||Y(n.getData("text/html")||""))return!1;let c=b(e.state,e.state.selection.$head.index(0));return a.preventDefault(),y(e,r,c),s(e),!0},handleDrop(e,a,n,r){let c=[...a.dataTransfer?.files??[]];if(r||!c.length)return!1;let d=e.posAtCoords({left:a.clientX,top:a.clientY});if(!d)return!1;let p=x(e.state.doc),i=Math.min(e.state.doc.resolve(d.pos).index(0),p.length-1),l=e.nodeDOM(p[i].at)?.getBoundingClientRect?.(),D=l&&a.clientY<l.top+l.height/2;a.preventDefault();let S={at:D?p[i].at:p[p[i].subEnd].end,parent:p[i].node.attrs.parent??null,replaceId:null};return y(e,c,S),s(e),!0}}})}var _=(t,o)=>{let s=-1;return t.forEach((e,a,n)=>{e.attrs.id===o&&(s=n)}),s};function V(t,o,s=b(t.state,t.state.selection.$head.index(0)),e=null){let a=u.get(t);if(!a)return!1;let n={place:s,remove:e&&{...e,text:t.state.doc.textBetween(e.from,e.to)}};return t.dispatch(t.state.tr.setMeta(m,{picker:n})),a.input.accept=o,a.input.click(),!0}export{m as a,L as b,u as c,C as d,U as e,b as f,P as g,F as h,z as i,M as j,A as k,T as l,H as m,Q as n,V as o};
@@ -1,4 +1,4 @@
1
- import{a as L,c as f,d as c,e as C,g as D,h as B,i as l,j as S,k as $,l as b,m as P}from"./c-MWXFLW4J.js";import{c as R}from"./c-W4JCVLAB.js";import{B as m,d as N}from"./c-AMU3BPPR.js";import{d as y,j as M,m as A}from"./c-QIXT3Q7C.js";import"./c-VHNSBD2M.js";var d=new WeakMap;var{Decoration:U,DecorationSet:F}=y,re=A.nodes,H=new Set(["timeout","network","error","bad-response"]),I=`
1
+ import{a as L,c as f,d as c,e as C,g as D,h as B,i as l,j as S,k as $,l as b,m as P}from"./c-CQQDL6O4.js";import{c as R}from"./c-W4JCVLAB.js";import{B as m,d as N}from"./c-AIWN4QN4.js";import{d as y,j as M,m as A}from"./c-QIXT3Q7C.js";import"./c-VHNSBD2M.js";var d=new WeakMap;var{Decoration:U,DecorationSet:F}=y,re=A.nodes,H=new Set(["timeout","network","error","bad-response"]),I=`
2
2
  .page-editor .page-image { margin-inline: 0; }
3
3
  .page-image-frame { position: relative; margin: 0 auto; max-width: 100%; }
4
4
  .page-image-frame img { display: block; width: 100%; height: auto; border-radius: var(--page-image-radius, 6px); }
@@ -1 +1 @@
1
- var o={table:{types:["table"],views:["table","table_cell"],module:"page/features/table.js",load:()=>import("./c-TTB5EK4S.js")},board:{types:["board"],module:"page/features/board.js",load:()=>import("./c-W6DQSHXI.js")},chart:{types:["chart"],views:["chart"],module:"page/features/chart.js",load:()=>import("./c-5ONTYIUI.js")},checklist:{types:[],views:[],match:e=>e.type.name==="list_item"&&e.attrs.kind==="check",module:"page/features/checklist.js",load:()=>import("./c-K3ADYNLU.js")},code:{types:["code_block"],module:"page/features/code.js",load:()=>import("./c-OPLUZR3A.js")},toc:{types:["toc"],module:"page/features/toc.js",load:()=>import("./c-URSMSFCB.js")},titleIcon:{types:[],views:["heading"],match:e=>e.attrs.pageIcon!=null||e.attrs.pageCoverSrc!=null,module:"page/features/title-icon.js",load:()=>import("./c-PLN76GF3.js")},media:{types:["image","file"],module:"page/features/media.js",load:()=>import("./c-KP64LT2A.js")},tool:{types:["tool"],module:"page/features/tool.js",boot:["page/tools.js","page/tool-data.js"],load:()=>import("./c-CCQ25GFY.js")}},r=e=>Object.keys(o).find(t=>o[t].types.includes(e))??null,s=e=>{for(let t of Object.keys(o)){let a=o[t];if(a.match?a.match(e):a.types.includes(e.type.name))return t}return null},l={mentions:{module:"page/features/mentions.js",load:()=>import("./c-X5TSXZYJ.js")},dates:{module:"page/features/dates.js",load:()=>import("./c-372N6H3B.js")},emoji:{module:"page/features/emoji.js",load:()=>import("./c-HMV6P4RX.js")},titleIcon:{module:"page/features/title-icon.js",load:()=>import("./c-PLN76GF3.js")},titleCover:{module:"page/features/title-cover.js",load:()=>import("./c-YBKHUAK7.js")},exportHtml:{module:"page/features/export-html.js",load:()=>import("./c-DKLS74XB.js")},importMarkdown:{module:"page/features/import-markdown.js",load:()=>import("./c-COPTL5WB.js")},exportMarkdown:{module:"page/features/export-markdown.js",load:()=>import("./c-ERQSNR6K.js")}};export{o as a,r as b,s as c,l as d};
1
+ var o={table:{types:["table"],views:["table","table_cell"],module:"page/features/table.js",load:()=>import("./c-JK3PHE7J.js")},board:{types:["board"],module:"page/features/board.js",load:()=>import("./c-ZRUQ5FSU.js")},chart:{types:["chart"],views:["chart"],module:"page/features/chart.js",load:()=>import("./c-L6FLIUXP.js")},checklist:{types:[],views:[],match:e=>e.type.name==="list_item"&&e.attrs.kind==="check",module:"page/features/checklist.js",load:()=>import("./c-HXPHZN7Q.js")},code:{types:["code_block"],module:"page/features/code.js",load:()=>import("./c-RRZJWFLE.js")},toc:{types:["toc"],module:"page/features/toc.js",load:()=>import("./c-GWNC3UGL.js")},titleIcon:{types:[],views:["heading"],match:e=>e.attrs.pageIcon!=null||e.attrs.pageCoverSrc!=null,module:"page/features/title-icon.js",load:()=>import("./c-O4JMKN6U.js")},media:{types:["image","file"],module:"page/features/media.js",load:()=>import("./c-DHUCEMXE.js")},tool:{types:["tool"],module:"page/features/tool.js",boot:["page/tools.js","page/tool-data.js"],load:()=>import("./c-WKNRJX3C.js")}},r=e=>Object.keys(o).find(t=>o[t].types.includes(e))??null,s=e=>{for(let t of Object.keys(o)){let a=o[t];if(a.match?a.match(e):a.types.includes(e.type.name))return t}return null},l={mentions:{module:"page/features/mentions.js",load:()=>import("./c-MIKZEG5I.js")},dates:{module:"page/features/dates.js",load:()=>import("./c-FOOE4GML.js")},emoji:{module:"page/features/emoji.js",load:()=>import("./c-UXFUJEZO.js")},titleIcon:{module:"page/features/title-icon.js",load:()=>import("./c-O4JMKN6U.js")},titleCover:{module:"page/features/title-cover.js",load:()=>import("./c-QINHDETP.js")},exportHtml:{module:"page/features/export-html.js",load:()=>import("./c-DKLS74XB.js")},importMarkdown:{module:"page/features/import-markdown.js",load:()=>import("./c-AXGY2WTB.js")},exportMarkdown:{module:"page/features/export-markdown.js",load:()=>import("./c-ERQSNR6K.js")}};export{o as a,r as b,s as c,l as d};
@@ -1,4 +1,4 @@
1
- import{a as Ct,b as It,c as At,d as ze,e as Ye,f as Kn,g as Tt,h as Hn,i as qn,j as Pt,l as Rt}from"./c-QIKT6SKM.js";import{a as Et,b as Jn,c as Ro,f as Yo}from"./c-UPD33ZPE.js";import{a as Bn,b as Dn,c as zn,d as it,e as Mt,f as $o}from"./c-DHBRA6DL.js";import{a as Po}from"./c-L3F5ZLIV.js";import{b as Co,c as Io}from"./c-BIJALSRD.js";import"./c-IW6GGOU2.js";import"./c-HAWFNBYG.js";import{a as Re,b as $n,p as Nn,q as Fn,u as Ao,v as To}from"./c-4TXNLX4K.js";import{A as Cn,B as Be,C as ot,D as In,E as An,F as De,G as Tn,H as Pe,I as rt,J as Pn,K as xt,L as Rn,M as st,N as Yn,O as ue,a as Le,b as bt,c as yn,d as vn,f as wn,j as xn,m as Eo,p as Sn,q as On,r as Mn,s as En,t as yt,v as vt,x as wt,z as Oe}from"./c-EXKHPOVC.js";import{a as me,b as pn,d as Me,e as _e,g as xe,h as Ne,i as ye,j as Ee,k as mn,l as Fe,m as nt,n as be,o as hn,p as gn,q as Se,r as Ce,u as bn,v as kn,w as kt}from"./c-L5VFATT6.js";import"./c-MWXFLW4J.js";import"./c-ZK4GIZH2.js";import"./c-W4JCVLAB.js";import"./c-7K4SCQB7.js";import{f as Zt,g as en,i as Qe,j as Ze,k as ut,n as dt,o as et,p as tn,s as pt,t as nn,u as Ae,v as de,w as Te,x as mt,y as on}from"./c-WMRJKQ2V.js";import{g as Ln,o as Ot}from"./c-AMU3BPPR.js";import{F as an,N as ht,Q as gt,R as fn,b as pe,c as rn,e as sn,m as fe,oa as je,p as ln,r as cn,ra as un,sa as dn,ua as tt}from"./c-QIXT3Q7C.js";import{b as Ut}from"./c-L7JL5TL3.js";import{a as jn,b as _n,c as St}from"./c-WCXLG3MV.js";import{a as Xt}from"./c-TCCA5BZN.js";import"./c-3LDGIBMN.js";import{c as Qt}from"./c-57XDY6HC.js";import"./c-OYRZ7XG2.js";import{a as Gt,b as ft}from"./c-QTTJYJMA.js";import"./c-Q26MME6N.js";import{d as Vt,e as Wt}from"./c-T637T7SN.js";import"./c-4ASQPRQL.js";import"./c-GQ6F6IDK.js";import"./c-I2SCCUEW.js";import"./c-5VYOWDTI.js";import"./c-FWKHM4E7.js";import"./c-X5LNHET5.js";import"./c-WYFDLITL.js";import"./c-UGHH4MB3.js";import"./c-ZWIOJGMT.js";import"./c-B7J4K2AE.js";import"./c-ATKAOH23.js";import"./c-EK63G3CG.js";import"./c-NQJRVJ56.js";import"./c-XGH4GS2T.js";import"./c-IJUK2GPW.js";import"./c-3O7OBDCM.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-7MG5RU63.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-VG5XIN4T.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-DCFSEJZG.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var Yt=new Set(["paragraph","heading","list_item","callout","quote","code_block","toggle"]),Je=(e,o)=>je(e)===je(o);function $t(e,o){let n=o.createElement("article");return n.setAttribute("data-page",""),n.innerHTML=dn([{id:e.id,t:"paragraph",c:e.c??"",...e.m?{m:e.m}:{}}],{clean:un(o)}),n}function jo(e,o){let n=new Map(e.map((f,u)=>[f.id,u])),r=new Set(o.map(f=>f.id)),t=new Map,s=0;return o.map(f=>{let u=n.get(f.id);if(u!==void 0)return s=u+1,f;let p={c:f.c??"",m:f.m??null};for(let b=s;b<e.length;b++){let C=e[b];if(!(r.has(C.id)||C.t!==f.t||!Je({c:C.c??"",m:C.m??null},p)))return r.add(C.id),s=b+1,t.set(f.id,C.id),{...f,id:C.id}}return f}).map(f=>t.has(f.parent)?{...f,parent:t.get(f.parent)}:f)}function jt(e,o,n,{doc:r,merge3:t,mergeJson:s}){let a=[],f=jo(e,n),u=new Map(e.map(c=>[c.id,c])),p=new Map(o.map(c=>[c.id,c])),b=new Map(f.map(c=>[c.id,c])),C=o.map(c=>({...c})),M=f.map(c=>({...c})),h=new Map(C.map(c=>[c.id,c])),w=new Map(M.map(c=>[c.id,c]));for(let[c,E]of u){let i=p.get(c),g=b.get(c);if(!i||!g||!Yt.has(E.t)||!Yt.has(i.t)||!Yt.has(g.t))continue;let A={c:E.c??"",m:E.m??null},z={c:i.c??"",m:i.m??null},W={c:g.c??"",m:g.m??null};if(Je(z,A)||Je(W,A)||Je(z,W))continue;if(E.t==="code_block"){for(let P of[h.get(c),w.get(c)])P.c=g.c??"",g.m?P.m=g.m:delete P.m;a.push({id:c,kind:"text",local:i.c??"",remote:g.c??""});continue}let T=t($t(E,r),$t(i,r),$t(g,r));for(let P of T.conflicts)a.push({id:c,kind:"text",local:P.local?.textContent??null,remote:P.remote?.textContent??null});let[U]=tt(T.root,{seed:"",known:new Map});for(let P of[h.get(c),w.get(c)])P.c=U.c,U.m?P.m=U.m:delete P.m}let y=o.map(c=>c.id);for(let[c,E]of u){let i=h.get(c);if(!i||b.has(c)||Je(p.get(c),E))continue;let g=y.indexOf(c)-1;for(;g>=0&&!w.has(y[g]);)g--;let A=g<0?0:M.findIndex(z=>z.id===y[g])+1;M.splice(A,0,{...i}),w.set(c,M[A]),a.push({id:c,kind:"kept-edit"})}let N=s(e,C,M,{onConflict:c=>a.push({kind:"field",path:c.path,local:c.local,remote:c.remote,resolved:c.resolved})}),B=new Set(N.map(c=>c.id)),v=c=>(p.get(c)??u.get(c)??b.get(c))?.parent??null,L=N.map(c=>{let E=c.parent??null;for(;E&&!B.has(E);)E=v(E);return E===(c.parent??null)?c:{...c,parent:E}}),Y=new Map(L.map(c=>[c.id,c.parent??null])),$=c=>{let E=new Set([c]);for(let i=Y.get(c);i;i=Y.get(i)){if(E.has(i))return!0;E.add(i)}return!1};for(let c of L)if($(c.id)){for(let E of[p.get(c.id)?.parent,u.get(c.id)?.parent,null])if(Y.set(c.id,E&&B.has(E)?E:null),!$(c.id))break}return{items:L.map(c=>(c.parent??null)===Y.get(c.id)?c:{...c,parent:Y.get(c.id)}),conflicts:a}}var _o=e=>{try{return Xt(e)}catch{return null}},$e={ok:!0,outcome:"unchanged"},Ke={ok:!1,outcome:"disposed",reason:"adoption-disposed"},He={ok:!1,outcome:"refused",reason:"adoption-refused"},No={ok:!1,outcome:"refused",reason:"adoption-timeout"},Fo={ok:!1,outcome:"error",reason:"adoption-error"},Lo={ok:!0,outcome:"writer-adopts"},Vn=e=>({ok:!0,outcome:"adopted",counts:e}),Wn=1e4;function Bo(e){let o=e.querySelector(Et);return o?{article:o.cloneNode(!0),tags:Jn(e).map(n=>_o(n.textContent))}:null}function Un(e){return new Promise(o=>{if(!e.composing)return o();e.dom.addEventListener("compositionend",()=>setTimeout(()=>o(Un(e)),0),{once:!0})})}function Do({view:e,source:o=null,ready:n=Promise.resolve(),isAdopter:r=()=>!0,idle:t=()=>Un(e),requestCheckpoint:s=()=>{},notice:a=()=>{},snapshot:f=()=>null,mergeTagless:u=!1,seeded:p=!1,writerReady:b=()=>Promise.resolve(),adopted:C=()=>{},hold:M=Vt,release:h=Wt,holdMs:w=Wn,doc:y=document}){let N=o?o.article.innerHTML:null,B=o?o.article:null,v=new Map,L=P=>{let I=P.getAttribute("data-rev");if(!I)return;let K=v.get(I)??[];v.delete(I),v.set(I,K),K.push(P),K.length>10&&K.shift(),v.size>20&&v.delete(v.keys().next().value)};B&&L(B);let Y=Promise.resolve(),$=!1,x,c=new Promise(P=>x=P);async function E(){let P,I=new Promise(K=>{P=setTimeout(()=>K("timeout"),w)});try{return await Promise.race([Promise.resolve(n).then(()=>t()).then(()=>"ready"),c.then(()=>"disposed"),I])}finally{clearTimeout(P)}}function i(P,I,K,j){let{HyperMorph:Q}=Gt(),le=jt(K,I,j,{doc:y,merge3:Q.merge3,mergeJson:Q.mergeJson}),ee=le.conflicts.filter(D=>D.kind==="text"||D.kind==="field"),m=ee.length?f():null,l=Dn(P,le.items,I),k=l&&zn(e.state,l);if(!k)return null;e.dispatch(k),e.dispatch(sn.closeHistory(e.state.tr));let F={edited:l.edited.size,created:l.created.size,deleted:l.deleted.length,moved:l.reordered},{displaced:R}=k.getMeta(Bn);return Object.keys(R).length&&(F.displaced=R),ee.length&&(F.conflicts=ee),m&&(F.copy=m),F}async function g(P){if(u&&!P.tags.length)return A(P);let I=Mt(P.article,P.tags);if(I.kind==="unbased"&&console.warn("page: the article and its data changed together; kept the data"),I.kind!=="adopt")return $e;if(!r())return Lo;M();try{if(await ft(),$)return Ke;if(!r())return He;let K=await E();if(K==="timeout"&&console.warn("page: gave up waiting for the editor; the hand edit was not adopted"),K==="disposed"||$)return Ke;if(K!=="ready")return No;if(!r())return He;let j=ht(e.state.doc),Q=i(j,it(j,y),I.baseItems,I.parsed);return Q?(C(I.A),Vn(Q)):$e}finally{h()}}async function A(P){let I=P.article.getAttribute("data-rev"),K=I&&v.get(I)||[],j=K.at(-1)??B;if(K.slice(0,-1).some(Q=>Q.innerHTML===P.article.innerHTML)||(L(P.article),B=P.article,!j)||j.outerHTML===P.article.outerHTML)return $e;M();try{if(await ft(),$)return Ke;if(!r())return He;if(await b(),$)return Ke;if(!r())return He;if(await E()==="disposed"||$)return Ke;if(!r())return He;let le=ht(e.state.doc),ee=it(le,y),m=new Map(ee.map(F=>[F.id,F])),l=F=>tt(F,{seed:F.getAttribute("data-rev")??"",known:m}),k=i(le,ee,l(j),l(P.article));return k?Vn(k):$e}finally{h()}}async function z(P){try{return await g(P)}catch(I){return console.error("page: adoption failed",I),Fo}}let W=null;function T(P,I=!1){return Y=Y.then(()=>z(P)).then(K=>(I&&(W=K),!K.ok||K.outcome!=="adopted"||(s(),a(K.counts),y.dispatchEvent(new CustomEvent("clay:page-adopted",{detail:K.counts}))),K)),Y}function U(P){let I=P.detail?.html;if($||typeof I!="string")return;let K=Bo(new DOMParser().parseFromString(I,"text/html"));!K||K.article.innerHTML===N||(N=K.article.innerHTML,T(K))}return y.addEventListener("clay:sync-applied",U),o&&!p&&T(o,!0),{idle:async()=>(await Y,W),saved(P){if(!u||typeof P!="string")return;let I=new DOMParser().parseFromString(P,"text/html").querySelector(Et);I&&(L(I),B=I)},dispose(){$=!0,x(),y.removeEventListener("clay:sync-applied",U)}}}var Gn='["text-delete",',Xn=(e,o)=>o instanceof nn&&o._item&&o._item.parent===e.attrs&&typeof o._item.parentSub=="string"?o._item.parentSub:null,Qn=e=>e==="t"||e==="parent",_t=e=>e.content instanceof de&&e.content.embed.b!==void 0,zo=e=>e.content instanceof mt||e.content instanceof Te||e.content instanceof de&&e.content.embed.b===void 0,eo=e=>{let o=new Map;for(let n of e.stops)(o.get(n.client)??o.set(n.client,[]).get(n.client)).push(n);return o},to=(e,o)=>{let n=o.get(e.id.client);if(!n)return!1;let r=e.id.clock,t=r+e.length;return n.some(s=>s.clock<t&&r<s.clock+s.len)},Jo=(e,o)=>{for(let n=e.left;n;n=n.left){if(n.deleted){if(to(n,o))return null;continue}if(_t(n))return n}return null};function no(e,o,n){let r=eo(n),t=new Set,s=new Set,a=o.changed.get(e.tableFields)??new Set;for(let[h,w]of o.changed){if(h===e.flow)continue;if(h===e.attrs){if(!o.local)return null;for(let N of w){let B=e.attrs.get(N);if(!(B instanceof Ae)||B._item.left||B._item.id.clock<(o.beforeState.get(B._item.id.client)??0))return null;s.add(N)}if(s.size>1)return null;continue}if(h===e.tableFields){for(let N of w){let B=e.tableFields.has(N)?On(N,e.tableFields.get(N)):null;if(B===null)return null;t.add(B)}continue}let y=Xn(e,h);if(y!==null){for(let N of w)if(Qn(N))return null;t.add(y);continue}if(h!==e.gone)return null;for(let N of w)if(typeof N!="string"||!N.startsWith(Gn))return null}let f=e.ydoc.store,u=null,p=null,b=!1,C=h=>{if(!(h instanceof on))return!1;if(h.parent===e.gone)return typeof h.parentSub=="string"&&h.parentSub.startsWith(Gn);if(h.parent===e.tableFields)return a.has(h.parentSub);if(h.parent===e.attrs)return s.has(h.parentSub);if(h.parent!==e.flow){let y=Xn(e,h.parent);return y!==null&&(s.has(y)||t.has(y)&&!Qn(h.parentSub))}if(_t(h)){if(h.deleted||!s.has(h.content.embed.b))return!1;p=h}else if(!zo(h))return!1;let w=Jo(h,r);return!w||u&&w!==u?!1:(u=w,h.content instanceof Te&&(b=!0),!0)};for(let[h,w]of o.afterState)for(let y=o.beforeState.get(h)??0;y<w;){let N=et(f,{client:h,clock:y});if(!C(N))return null;y=N.id.clock+N.length}let M=!1;for(let[h,w]of o.deleteSet.clients)for(let{clock:y,len:N}of w)for(let B=y;B<y+N;){let v=et(f,{client:h,clock:B});if(!C(v))return null;M=!0,B=v.id.clock+v.length}return s.size&&!p?null:u||t.size?{marker:u,split:p,deleted:M,formats:b,fields:t,remote:!o.local}:null}var Ko=e=>{for(let o in e)return{...e};return null};function oo(e,o,n,r=null){let t=r?.formats??!0,s=r?.split??null,a=o.visible,f=-1,u=0;for(let i=0;i<a.length;i++){let g=a[i];if(g.brk&&g.brk.client===n.id.client&&g.brk.clock===n.id.clock){f=i;break}u+=g.len}if(f<0)return null;let p=a[f];if(p.implicit||p.atom||p.opaque||p.recovered||p.hide)return null;let b=p.runs.findIndex(i=>i.hole!==void 0);if(b>=0&&t||p.items&&o.copies.has(p.baseId))return null;let C=eo(o),M={...p.fmtIn??{}},h=null,w={...p,runs:[],len:1};p.items&&(w.items=[]);let y=w,N=!1,B=Ye(o.holes,u),v=B+1;for(let i=n.right;i;i=i.right){if(i.deleted){if(to(i,C))return null;continue}if(_t(i)&&(i!==s||y!==w)){N=!0;break}let g=v;i.countable&&(v+=i.length);let A=i.content;if(i===s){let z=A.embed.b,W=e.attrs.get(z)?.get("t")||"paragraph";if(!Object.hasOwn(fe.nodes,W)||!fe.nodes[W].isTextblock)return null;let T=Ko(M);w.fmtOut=T,y={kind:"b",id:z,baseId:z,brk:{client:i.id.client,clock:i.id.clock},implicit:!1,runs:[],len:1,atom:!1,items:null,fmtIn:T,fmtOut:null,t:W,opaque:!1},h=null;continue}if(A instanceof Te){A.value===null?delete M[A.key]:M[A.key]=A.value,h=null;continue}if(A instanceof de){y.runs.push({br:!0}),y.items&&y.items.push({at:g,id:Ee(i.id),client:i.id.client,clock:i.id.clock,length:i.length,kind:"br",text:null,blockId:null,raw:{...M}}),y.len+=1;continue}if(A instanceof mt){if(!h){let z=kn(M,y.t);h={marks:z,mk:bn(z)}}y.runs.push({text:A.str,marks:h.marks,mk:h.mk}),y.items&&y.items.push({at:g,id:Ee(i.id),client:i.id.client,clock:i.id.clock,length:i.length,kind:"text",text:A.str,blockId:null,raw:{...M}}),y.len+=A.str.length}else if(i.countable)return null}let L=p.len;if(b<0){if(!ye(M,p.fmtOut??{}))return null}else{if(!N||y.t!==p.t)return null;L=1;for(let i=0;i<b;i++)L+=p.runs[i].br?1:p.runs[i].text.length}let Y=y===w?[w]:[w,y],$=Y.reduce((i,g)=>i+g.len,0)-L,x=B+L,c=i=>i.at>=x?{...i,at:i.at+$}:i;y.fmtOut=p.fmtOut,b>=0&&(y.runs=y.runs.concat(p.runs.slice(b)),y.len+=p.len-L,y.items&&(y.items=y.items.concat(p.items.filter(i=>i.at>=x).map(c))));let E={...o,visible:a.slice(),tokens:o.tokens+$};if(E.visible.splice(f,1,...Y),$){let i=u+L;E.holes=o.holes.map(g=>g.at>=i?{at:g.at+$,len:g.len}:g),E.hidden=o.hidden.map(g=>g.at>=x?{...g,at:g.at+$,items:g.items.map(c)}:g);for(let g=f+Y.length;g<E.visible.length;g+=1){let A=E.visible[g];A.items?.length&&(E.visible[g]={...A,items:A.items.map(c)})}}return E}var Ho=e=>e.br?`
1
+ import{a as Ct,b as It,c as At,d as ze,e as Ye,f as Kn,g as Tt,h as Hn,i as qn,j as Pt,l as Rt}from"./c-QIKT6SKM.js";import{a as Et,b as Jn,c as Ro,f as Yo}from"./c-UPD33ZPE.js";import{a as Bn,b as Dn,c as zn,d as it,e as Mt,f as $o}from"./c-DHBRA6DL.js";import{a as Po}from"./c-L3F5ZLIV.js";import{b as Co,c as Io}from"./c-BIJALSRD.js";import"./c-IW6GGOU2.js";import"./c-HAWFNBYG.js";import{a as Re,b as $n,p as Nn,q as Fn,u as Ao,v as To}from"./c-4FJTBE6I.js";import{A as Cn,B as Be,C as ot,D as In,E as An,F as De,G as Tn,H as Pe,I as rt,J as Pn,K as xt,L as Rn,M as st,N as Yn,O as ue,a as Le,b as bt,c as yn,d as vn,f as wn,j as xn,m as Eo,p as Sn,q as On,r as Mn,s as En,t as yt,v as vt,x as wt,z as Oe}from"./c-EXKHPOVC.js";import{a as me,b as pn,d as Me,e as _e,g as xe,h as Ne,i as ye,j as Ee,k as mn,l as Fe,m as nt,n as be,o as hn,p as gn,q as Se,r as Ce,u as bn,v as kn,w as kt}from"./c-L5VFATT6.js";import"./c-CQQDL6O4.js";import"./c-ZGDYHKG3.js";import"./c-W4JCVLAB.js";import"./c-7K4SCQB7.js";import{f as Zt,g as en,i as Qe,j as Ze,k as ut,n as dt,o as et,p as tn,s as pt,t as nn,u as Ae,v as de,w as Te,x as mt,y as on}from"./c-WMRJKQ2V.js";import{g as Ln,o as Ot}from"./c-AIWN4QN4.js";import{F as an,N as ht,Q as gt,R as fn,b as pe,c as rn,e as sn,m as fe,oa as je,p as ln,r as cn,ra as un,sa as dn,ua as tt}from"./c-QIXT3Q7C.js";import{b as Ut}from"./c-L7JL5TL3.js";import{a as jn,b as _n,c as St}from"./c-WCXLG3MV.js";import{a as Xt}from"./c-TCCA5BZN.js";import"./c-3LDGIBMN.js";import{c as Qt}from"./c-57XDY6HC.js";import"./c-OYRZ7XG2.js";import{a as Gt,b as ft}from"./c-QTTJYJMA.js";import"./c-Q26MME6N.js";import{d as Vt,e as Wt}from"./c-ZKNBMNN3.js";import"./c-4ASQPRQL.js";import"./c-GQ6F6IDK.js";import"./c-I2SCCUEW.js";import"./c-5VYOWDTI.js";import"./c-FWKHM4E7.js";import"./c-5JLFROUB.js";import"./c-WYFDLITL.js";import"./c-UGHH4MB3.js";import"./c-ZWIOJGMT.js";import"./c-B7J4K2AE.js";import"./c-ATKAOH23.js";import"./c-EK63G3CG.js";import"./c-NQJRVJ56.js";import"./c-XGH4GS2T.js";import"./c-IJUK2GPW.js";import"./c-3O7OBDCM.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-7MG5RU63.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-VG5XIN4T.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-DCFSEJZG.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var Yt=new Set(["paragraph","heading","list_item","callout","quote","code_block","toggle"]),Je=(e,o)=>je(e)===je(o);function $t(e,o){let n=o.createElement("article");return n.setAttribute("data-page",""),n.innerHTML=dn([{id:e.id,t:"paragraph",c:e.c??"",...e.m?{m:e.m}:{}}],{clean:un(o)}),n}function jo(e,o){let n=new Map(e.map((f,u)=>[f.id,u])),r=new Set(o.map(f=>f.id)),t=new Map,s=0;return o.map(f=>{let u=n.get(f.id);if(u!==void 0)return s=u+1,f;let p={c:f.c??"",m:f.m??null};for(let b=s;b<e.length;b++){let C=e[b];if(!(r.has(C.id)||C.t!==f.t||!Je({c:C.c??"",m:C.m??null},p)))return r.add(C.id),s=b+1,t.set(f.id,C.id),{...f,id:C.id}}return f}).map(f=>t.has(f.parent)?{...f,parent:t.get(f.parent)}:f)}function jt(e,o,n,{doc:r,merge3:t,mergeJson:s}){let a=[],f=jo(e,n),u=new Map(e.map(c=>[c.id,c])),p=new Map(o.map(c=>[c.id,c])),b=new Map(f.map(c=>[c.id,c])),C=o.map(c=>({...c})),M=f.map(c=>({...c})),h=new Map(C.map(c=>[c.id,c])),w=new Map(M.map(c=>[c.id,c]));for(let[c,E]of u){let i=p.get(c),g=b.get(c);if(!i||!g||!Yt.has(E.t)||!Yt.has(i.t)||!Yt.has(g.t))continue;let A={c:E.c??"",m:E.m??null},z={c:i.c??"",m:i.m??null},W={c:g.c??"",m:g.m??null};if(Je(z,A)||Je(W,A)||Je(z,W))continue;if(E.t==="code_block"){for(let P of[h.get(c),w.get(c)])P.c=g.c??"",g.m?P.m=g.m:delete P.m;a.push({id:c,kind:"text",local:i.c??"",remote:g.c??""});continue}let T=t($t(E,r),$t(i,r),$t(g,r));for(let P of T.conflicts)a.push({id:c,kind:"text",local:P.local?.textContent??null,remote:P.remote?.textContent??null});let[U]=tt(T.root,{seed:"",known:new Map});for(let P of[h.get(c),w.get(c)])P.c=U.c,U.m?P.m=U.m:delete P.m}let y=o.map(c=>c.id);for(let[c,E]of u){let i=h.get(c);if(!i||b.has(c)||Je(p.get(c),E))continue;let g=y.indexOf(c)-1;for(;g>=0&&!w.has(y[g]);)g--;let A=g<0?0:M.findIndex(z=>z.id===y[g])+1;M.splice(A,0,{...i}),w.set(c,M[A]),a.push({id:c,kind:"kept-edit"})}let N=s(e,C,M,{onConflict:c=>a.push({kind:"field",path:c.path,local:c.local,remote:c.remote,resolved:c.resolved})}),B=new Set(N.map(c=>c.id)),v=c=>(p.get(c)??u.get(c)??b.get(c))?.parent??null,L=N.map(c=>{let E=c.parent??null;for(;E&&!B.has(E);)E=v(E);return E===(c.parent??null)?c:{...c,parent:E}}),Y=new Map(L.map(c=>[c.id,c.parent??null])),$=c=>{let E=new Set([c]);for(let i=Y.get(c);i;i=Y.get(i)){if(E.has(i))return!0;E.add(i)}return!1};for(let c of L)if($(c.id)){for(let E of[p.get(c.id)?.parent,u.get(c.id)?.parent,null])if(Y.set(c.id,E&&B.has(E)?E:null),!$(c.id))break}return{items:L.map(c=>(c.parent??null)===Y.get(c.id)?c:{...c,parent:Y.get(c.id)}),conflicts:a}}var _o=e=>{try{return Xt(e)}catch{return null}},$e={ok:!0,outcome:"unchanged"},Ke={ok:!1,outcome:"disposed",reason:"adoption-disposed"},He={ok:!1,outcome:"refused",reason:"adoption-refused"},No={ok:!1,outcome:"refused",reason:"adoption-timeout"},Fo={ok:!1,outcome:"error",reason:"adoption-error"},Lo={ok:!0,outcome:"writer-adopts"},Vn=e=>({ok:!0,outcome:"adopted",counts:e}),Wn=1e4;function Bo(e){let o=e.querySelector(Et);return o?{article:o.cloneNode(!0),tags:Jn(e).map(n=>_o(n.textContent))}:null}function Un(e){return new Promise(o=>{if(!e.composing)return o();e.dom.addEventListener("compositionend",()=>setTimeout(()=>o(Un(e)),0),{once:!0})})}function Do({view:e,source:o=null,ready:n=Promise.resolve(),isAdopter:r=()=>!0,idle:t=()=>Un(e),requestCheckpoint:s=()=>{},notice:a=()=>{},snapshot:f=()=>null,mergeTagless:u=!1,seeded:p=!1,writerReady:b=()=>Promise.resolve(),adopted:C=()=>{},hold:M=Vt,release:h=Wt,holdMs:w=Wn,doc:y=document}){let N=o?o.article.innerHTML:null,B=o?o.article:null,v=new Map,L=P=>{let I=P.getAttribute("data-rev");if(!I)return;let K=v.get(I)??[];v.delete(I),v.set(I,K),K.push(P),K.length>10&&K.shift(),v.size>20&&v.delete(v.keys().next().value)};B&&L(B);let Y=Promise.resolve(),$=!1,x,c=new Promise(P=>x=P);async function E(){let P,I=new Promise(K=>{P=setTimeout(()=>K("timeout"),w)});try{return await Promise.race([Promise.resolve(n).then(()=>t()).then(()=>"ready"),c.then(()=>"disposed"),I])}finally{clearTimeout(P)}}function i(P,I,K,j){let{HyperMorph:Q}=Gt(),le=jt(K,I,j,{doc:y,merge3:Q.merge3,mergeJson:Q.mergeJson}),ee=le.conflicts.filter(D=>D.kind==="text"||D.kind==="field"),m=ee.length?f():null,l=Dn(P,le.items,I),k=l&&zn(e.state,l);if(!k)return null;e.dispatch(k),e.dispatch(sn.closeHistory(e.state.tr));let F={edited:l.edited.size,created:l.created.size,deleted:l.deleted.length,moved:l.reordered},{displaced:R}=k.getMeta(Bn);return Object.keys(R).length&&(F.displaced=R),ee.length&&(F.conflicts=ee),m&&(F.copy=m),F}async function g(P){if(u&&!P.tags.length)return A(P);let I=Mt(P.article,P.tags);if(I.kind==="unbased"&&console.warn("page: the article and its data changed together; kept the data"),I.kind!=="adopt")return $e;if(!r())return Lo;M();try{if(await ft(),$)return Ke;if(!r())return He;let K=await E();if(K==="timeout"&&console.warn("page: gave up waiting for the editor; the hand edit was not adopted"),K==="disposed"||$)return Ke;if(K!=="ready")return No;if(!r())return He;let j=ht(e.state.doc),Q=i(j,it(j,y),I.baseItems,I.parsed);return Q?(C(I.A),Vn(Q)):$e}finally{h()}}async function A(P){let I=P.article.getAttribute("data-rev"),K=I&&v.get(I)||[],j=K.at(-1)??B;if(K.slice(0,-1).some(Q=>Q.innerHTML===P.article.innerHTML)||(L(P.article),B=P.article,!j)||j.outerHTML===P.article.outerHTML)return $e;M();try{if(await ft(),$)return Ke;if(!r())return He;if(await b(),$)return Ke;if(!r())return He;if(await E()==="disposed"||$)return Ke;if(!r())return He;let le=ht(e.state.doc),ee=it(le,y),m=new Map(ee.map(F=>[F.id,F])),l=F=>tt(F,{seed:F.getAttribute("data-rev")??"",known:m}),k=i(le,ee,l(j),l(P.article));return k?Vn(k):$e}finally{h()}}async function z(P){try{return await g(P)}catch(I){return console.error("page: adoption failed",I),Fo}}let W=null;function T(P,I=!1){return Y=Y.then(()=>z(P)).then(K=>(I&&(W=K),!K.ok||K.outcome!=="adopted"||(s(),a(K.counts),y.dispatchEvent(new CustomEvent("clay:page-adopted",{detail:K.counts}))),K)),Y}function U(P){let I=P.detail?.html;if($||typeof I!="string")return;let K=Bo(new DOMParser().parseFromString(I,"text/html"));!K||K.article.innerHTML===N||(N=K.article.innerHTML,T(K))}return y.addEventListener("clay:sync-applied",U),o&&!p&&T(o,!0),{idle:async()=>(await Y,W),saved(P){if(!u||typeof P!="string")return;let I=new DOMParser().parseFromString(P,"text/html").querySelector(Et);I&&(L(I),B=I)},dispose(){$=!0,x(),y.removeEventListener("clay:sync-applied",U)}}}var Gn='["text-delete",',Xn=(e,o)=>o instanceof nn&&o._item&&o._item.parent===e.attrs&&typeof o._item.parentSub=="string"?o._item.parentSub:null,Qn=e=>e==="t"||e==="parent",_t=e=>e.content instanceof de&&e.content.embed.b!==void 0,zo=e=>e.content instanceof mt||e.content instanceof Te||e.content instanceof de&&e.content.embed.b===void 0,eo=e=>{let o=new Map;for(let n of e.stops)(o.get(n.client)??o.set(n.client,[]).get(n.client)).push(n);return o},to=(e,o)=>{let n=o.get(e.id.client);if(!n)return!1;let r=e.id.clock,t=r+e.length;return n.some(s=>s.clock<t&&r<s.clock+s.len)},Jo=(e,o)=>{for(let n=e.left;n;n=n.left){if(n.deleted){if(to(n,o))return null;continue}if(_t(n))return n}return null};function no(e,o,n){let r=eo(n),t=new Set,s=new Set,a=o.changed.get(e.tableFields)??new Set;for(let[h,w]of o.changed){if(h===e.flow)continue;if(h===e.attrs){if(!o.local)return null;for(let N of w){let B=e.attrs.get(N);if(!(B instanceof Ae)||B._item.left||B._item.id.clock<(o.beforeState.get(B._item.id.client)??0))return null;s.add(N)}if(s.size>1)return null;continue}if(h===e.tableFields){for(let N of w){let B=e.tableFields.has(N)?On(N,e.tableFields.get(N)):null;if(B===null)return null;t.add(B)}continue}let y=Xn(e,h);if(y!==null){for(let N of w)if(Qn(N))return null;t.add(y);continue}if(h!==e.gone)return null;for(let N of w)if(typeof N!="string"||!N.startsWith(Gn))return null}let f=e.ydoc.store,u=null,p=null,b=!1,C=h=>{if(!(h instanceof on))return!1;if(h.parent===e.gone)return typeof h.parentSub=="string"&&h.parentSub.startsWith(Gn);if(h.parent===e.tableFields)return a.has(h.parentSub);if(h.parent===e.attrs)return s.has(h.parentSub);if(h.parent!==e.flow){let y=Xn(e,h.parent);return y!==null&&(s.has(y)||t.has(y)&&!Qn(h.parentSub))}if(_t(h)){if(h.deleted||!s.has(h.content.embed.b))return!1;p=h}else if(!zo(h))return!1;let w=Jo(h,r);return!w||u&&w!==u?!1:(u=w,h.content instanceof Te&&(b=!0),!0)};for(let[h,w]of o.afterState)for(let y=o.beforeState.get(h)??0;y<w;){let N=et(f,{client:h,clock:y});if(!C(N))return null;y=N.id.clock+N.length}let M=!1;for(let[h,w]of o.deleteSet.clients)for(let{clock:y,len:N}of w)for(let B=y;B<y+N;){let v=et(f,{client:h,clock:B});if(!C(v))return null;M=!0,B=v.id.clock+v.length}return s.size&&!p?null:u||t.size?{marker:u,split:p,deleted:M,formats:b,fields:t,remote:!o.local}:null}var Ko=e=>{for(let o in e)return{...e};return null};function oo(e,o,n,r=null){let t=r?.formats??!0,s=r?.split??null,a=o.visible,f=-1,u=0;for(let i=0;i<a.length;i++){let g=a[i];if(g.brk&&g.brk.client===n.id.client&&g.brk.clock===n.id.clock){f=i;break}u+=g.len}if(f<0)return null;let p=a[f];if(p.implicit||p.atom||p.opaque||p.recovered||p.hide)return null;let b=p.runs.findIndex(i=>i.hole!==void 0);if(b>=0&&t||p.items&&o.copies.has(p.baseId))return null;let C=eo(o),M={...p.fmtIn??{}},h=null,w={...p,runs:[],len:1};p.items&&(w.items=[]);let y=w,N=!1,B=Ye(o.holes,u),v=B+1;for(let i=n.right;i;i=i.right){if(i.deleted){if(to(i,C))return null;continue}if(_t(i)&&(i!==s||y!==w)){N=!0;break}let g=v;i.countable&&(v+=i.length);let A=i.content;if(i===s){let z=A.embed.b,W=e.attrs.get(z)?.get("t")||"paragraph";if(!Object.hasOwn(fe.nodes,W)||!fe.nodes[W].isTextblock)return null;let T=Ko(M);w.fmtOut=T,y={kind:"b",id:z,baseId:z,brk:{client:i.id.client,clock:i.id.clock},implicit:!1,runs:[],len:1,atom:!1,items:null,fmtIn:T,fmtOut:null,t:W,opaque:!1},h=null;continue}if(A instanceof Te){A.value===null?delete M[A.key]:M[A.key]=A.value,h=null;continue}if(A instanceof de){y.runs.push({br:!0}),y.items&&y.items.push({at:g,id:Ee(i.id),client:i.id.client,clock:i.id.clock,length:i.length,kind:"br",text:null,blockId:null,raw:{...M}}),y.len+=1;continue}if(A instanceof mt){if(!h){let z=kn(M,y.t);h={marks:z,mk:bn(z)}}y.runs.push({text:A.str,marks:h.marks,mk:h.mk}),y.items&&y.items.push({at:g,id:Ee(i.id),client:i.id.client,clock:i.id.clock,length:i.length,kind:"text",text:A.str,blockId:null,raw:{...M}}),y.len+=A.str.length}else if(i.countable)return null}let L=p.len;if(b<0){if(!ye(M,p.fmtOut??{}))return null}else{if(!N||y.t!==p.t)return null;L=1;for(let i=0;i<b;i++)L+=p.runs[i].br?1:p.runs[i].text.length}let Y=y===w?[w]:[w,y],$=Y.reduce((i,g)=>i+g.len,0)-L,x=B+L,c=i=>i.at>=x?{...i,at:i.at+$}:i;y.fmtOut=p.fmtOut,b>=0&&(y.runs=y.runs.concat(p.runs.slice(b)),y.len+=p.len-L,y.items&&(y.items=y.items.concat(p.items.filter(i=>i.at>=x).map(c))));let E={...o,visible:a.slice(),tokens:o.tokens+$};if(E.visible.splice(f,1,...Y),$){let i=u+L;E.holes=o.holes.map(g=>g.at>=i?{at:g.at+$,len:g.len}:g),E.hidden=o.hidden.map(g=>g.at>=x?{...g,at:g.at+$,items:g.items.map(c)}:g);for(let g=f+Y.length;g<E.visible.length;g+=1){let A=E.visible[g];A.items?.length&&(E.visible[g]={...A,items:A.items.map(c)})}}return E}var Ho=e=>e.br?`
2
2
  `:e.hole!==void 0?{hole:e.hole}:{text:e.text,mk:e.mk},qo=e=>{let o=[];for(let n of e.map(Ho)){let r=o[o.length-1];r&&typeof r=="object"&&typeof n=="object"&&r.text!==void 0&&n.text!==void 0&&r.mk===n.mk?o[o.length-1]={text:r.text+n.text,mk:n.mk}:o.push(n)}return o},Zn=(e,o)=>{let n=et(e.ydoc.store,{client:o.client,clock:o.clock});return{client:n.id.client,clock:n.id.clock,len:n.length}},Ve=(e,o)=>rt({...o,copies:[...o.copies],fences:o.fences.map(n=>Zn(e,n)),stops:o.stops.map(n=>Zn(e,n)),visible:o.visible.map(n=>({...n,runs:qo(n.runs)}))});var ro=e=>e===!0?{}:e,so=(e,o)=>ye(ro(e),ro(o));function co(e,o,n,r){let t=e.attrs.get(o);t||(t=new Ae,e.attrs.set(o,t));let s=fe.nodes[n];if(!s){t.get("t")!==n&&t.set("t",n);for(let[p,b]of Object.entries(r??{}))p==="t"||p==="pos"||ye(t.has(p)?t.get(p):void 0,b)||t.set(p,b);return}let a=n==="table"&&t.get("t")==="table"&&!xt(o),f=n==="board"&&!xt(o),u=a?Mn(e.tableFields,o,En(e,o)):f?vt(e.boardFields,o):null;t.get("t")!==n&&t.set("t",n);for(let p of xe(s)){if(a&&(p==="rows"||p==="cols")||f&&(p==="columns"||p==="cards"))continue;let b=t.has(p)?t.get(p):Ne(s,p);ye(b,r[p])||t.set(p,r[p])}a&&yt(e,o,u,r),f&&wt(e,o,u,r)}function io(e,o){let n=new Map,r=o;for(let t=e.flow._start;t&&r>0;t=t.right){if(t.deleted)continue;let s=t.content;s instanceof Te?s.value===null?n.delete(s.key):n.set(s.key,s.value):t.countable&&(r-=t.length)}return n}function Vo(e){let o=new Set;for(let[r,t]of e)Ce(r)&&t&&o.add(r.split("!")[0]);let n=[];for(let[r,t]of e)!Ce(r)&&t!==null&&t!==void 0&&!o.has(r)&&fe.marks[Se(r)]&&n.push([r,t]);return n}function ao(e){let o=new Set;for(let[r,t]of e)Ce(r)&&t&&o.add(r.split("!")[0]);let n=[];for(let[r,t]of e)!Ce(r)&&t!==null&&t!==void 0&&!o.has(r)&&!fe.marks[Se(r)]&&n.push([r,t]);return n}function fo(e,o={}){let n={},r=!1;for(let[t,s]of e)(Ce(t)||fe.marks[Se(t)])&&(n[t]=s);for(let[t,s]of ao(e))r=!0,o[Se(t)]!==void 0&&(n[t]=s);return{attrs:n,opaque:r}}function Wo(e,o,n){let r=be(e),t={},s=Vo(o),a=new Set;for(let[u,p]of s){let b=Se(u),C=n[b];C!==void 0&&so(C,p)?a.add(b):t[`${u}!${r}`]=!0}for(let[u,p]of ao(o)){let b=Se(u);n[b]!==void 0&&so(n[b],p)&&a.add(b)}for(let[u,p]of Object.entries(n))a.has(u)||(t[`${u}~${be(e)}`]=p);let f=fo(o,n);if(!(!Object.keys(t).length&&!f.opaque))return{...f.attrs,...t}}var Nt=2e3;function Uo(e){let o=[],n=[],r=0;for(let t=0;t<e.length;t++)if(n.push(e[t]),r+=1,r>=Nt&&t+1<e.length){let s=e[t];if(s.k==="c"&&Fe(s.ch.charCodeAt(0)))continue;o.push(n),n=[],r=0}return n.length&&o.push(n),o}function lt(e,o,n,r=s=>s(),t=null){let s=o;for(let a of Uo(n))r(()=>{s+=Xo(e,s,a,t)});return s-o}var Go=(e,o,n)=>{if(!n||!n.length)return null;let r=o,t=e.flow._start;for(;t&&r>0;){if(!t.deleted&&t.countable){if(r<t.length)return null;r-=t.length}t=t.right}for(;t&&(t.deleted||!t.countable);t=t.right)if(t.deleted&&n.some(s=>s.client===t.id.client&&s.clock>=t.id.clock&&s.clock<t.id.clock+t.length))return t;return null},We=(e,o,n,r)=>{let t=Go(e,o,n);if(!t)return r();t.deleted=!1;try{return r()}finally{t.deleted=!0,e.flow._searchMarker&&(e.flow._searchMarker.length=0)}};function Xo(e,o,n,r=null){let t=o,s="",a=null,f=null,u=()=>{if(!s)return;let b=Wo(e,io(e,t),f??{});We(e,t,r,()=>e.flow.insert(t,s,b)),t+=s.length,s=""},p=b=>{let C=fo(io(e,t)).attrs;We(e,t,r,()=>e.flow.insertEmbed(t,b,C)),t+=1};for(let b of n)b.k==="c"?(a!==null&&b.mk!==a&&u(),a=b.mk,f=b.ma,s+=b.ch):b.k==="h"?(u(),a=null,p({br:1})):(u(),a=null,p({b:b.id}),co(e,b.id,b.t,b.attrs));return u(),t-o}var Qo=(e,o,n,r)=>{let t=0;for(let s=e.flow._start;s&&t<r;s=s.right){if(s.deleted||!s.countable)continue;let a=t;if(t+=s.length,t<=n||s.content instanceof de&&s.content.embed?.b!==void 0)continue;let f=Math.max(0,n-a),u=Math.min(s.length,r-a);u<=f||e.gone.set(An(s.id.client,s.id.clock+f,o.operationId),{length:u-f,actor:e.ydoc.clientID,sv:o.sv})}};function lo(e,o,n,r=null){for(let t=n.length-1;t>=0;t--){let[s,a]=n[t];if(a<=s)continue;let f=o.physicalRanges(s,a);for(let u=f.length-1;u>=0;u--){let[p,b]=f[u];b<=p||(r&&Qo(e,r,p,b),e.flow.delete(p,b-p))}}}function Zo(e,o,n){let r=!1;for(let t=e.flow._start;t;t=t.right){let s=Ee(t.id);if(s===o){r=!0;continue}if(!r)continue;let a=t.content instanceof de?t.content.embed:null;if(a&&a.b!==void 0&&a.b!==n)return s}return null}function Ft(e,o,n,r,t=null){let{pd:s,map:a,bt:f}=e,u=i=>t===null||t[i],p=0;for(;p<n.length&&p<r.length&&ze(n[p],r[p])&&u(p);)p++;let b=0;for(;b<n.length-p&&b<r.length-p&&ze(n[n.length-1-b],r[r.length-1-b])&&u(n.length-1-b);)b++;let C=i=>i&&i.k==="c"?i.ch.charCodeAt(0):-1;p>0&&Fe(C(n[p-1]))&&(nt(C(n[p]))||nt(C(r[p])))&&p--,b>0&&nt(C(n[n.length-b]))&&(Fe(C(n[n.length-b-1]))||Fe(C(r[r.length-b-1])))&&b--;let M=n.slice(p,n.length-b),h=r.slice(p,r.length-b),w=o+p,y=w+M.length,N=M.filter(i=>i.k==="b").map(i=>i.id).join(",");if(!(M.some(i=>i.k==="b")&&N===h.filter(i=>i.k==="b").map(i=>i.id).join(","))){let i=Le(s.origins);try{for(let T of M){if(T.k!=="b"||!T.brk)continue;let U=i.resolve(T.brk);i.boundaryOf(U)||e.tx(()=>i.recordBoundary(U,{blockId:T.id,kind:"removed"}))}}finally{i.dispose()}let g=new Set;M.forEach((T,U)=>{if(T.k!=="b"||!T.brk)return;let P=w+U,I=P+1;for(;I<f.length&&f[I].k!=="b";)I++;let K=I<=y&&I!==P+1,j=I<f.length?f[I].brk:null;K&&(e.tx(()=>s.gone.set(Be(Ee(T.brk),e.operationId),{blockId:T.id,end:j?Ee(j):null,sv:e.sv})),g.add(P))});let A=[],z=w;for(let T=w;T<y;T++)g.has(T)&&(T>z&&A.push([z,T]),z=T+1);y>z&&A.push([z,y]),e.tx(()=>lo(s,a,A,M.some(T=>T.k==="b")?null:e));let W=new Set(h.filter(T=>T.k==="b").map(T=>T.id));for(let T of M)if(!(T.k!=="b"||!T.brk||W.has(T.id)))for(let U of e.copies.get(T.id)??[]){let P=Be(U,e.operationId);s.gone.has(P)||e.tx(()=>s.gone.set(P,{blockId:T.id,end:Zo(s,U,T.id),sv:e.sv}))}h.length&&lt(s,a.toPhysical(w,"before"),h,e.tx,e.fences);return}let v=[],L=[],Y=[],$=w,x=0,c=0;for(;x<M.length||c<h.length;){let i=x;for(;i<M.length&&M[i].k!=="b";)i++;let g=c;for(;g<h.length&&h[g].k!=="b";)g++;let A=M.slice(x,i),z=h.slice(c,g);if(A.length&&v.push([$,$+A.length]),z.length&&L.push({at:$,toks:z}),$+=A.length,i<M.length&&(Y.push([M[i],h[g]]),$+=1),x=i+(i<M.length?1:0),c=g+(g<h.length?1:0),i>=M.length&&g>=h.length)break}let E=[...v.map(i=>({at:i[0],d:i})),...L.map(i=>({at:i.at,i}))].sort((i,g)=>g.at-i.at||(i.d?-1:1));for(let i of E)i.d?e.tx(()=>lo(s,a,[i.d],e)):lt(s,a.toPhysical(i.at,"before"),i.i.toks,e.tx,e.fences);for(let[i,g]of Y)e.tx(()=>{if(!fe.nodes[g.t])return;let A=e.recovered.get(i.id);if(A){i.t!==g.t&&s.gone.set(De(A,"t"),g.t);for(let T of xe(fe.nodes[g.t]))ye(i.attrs[T],g.attrs[T])||s.gone.set(De(A,T),g.attrs[T]);return}let z=i.id,W=s.attrs.get(z);if(W){let T=i.t==="table"&&g.t==="table"&&W.get("t")==="table",U=g.t==="board",P=U?i.t==="board"&&W.get("t")==="board"?i.attrs:vt(s.boardFields,z):null;i.t!==g.t&&W.set("t",g.t);for(let I of xe(fe.nodes[g.t])){if(T&&(I==="rows"||I==="cols")||U&&(I==="columns"||I==="cards"))continue;let K=W.has(I)?W.get(I):Ne(fe.nodes[g.t],I);ye(K,g.attrs[I])||W.set(I,g.attrs[I])}T&&yt(s,z,i.attrs,g.attrs),U&&wt(s,z,P,g.attrs)}else co(s,z,g.t,g.attrs)})}function Lt(e,o,n,r,t,s){let{pd:a,map:f}=e,u=`${r}~${be(a)}`,p=be(a),b=o;for(;b<n;){if(s[b].k!=="c"){b++;continue}let C=b;for(;C<n&&s[C].k==="c";)C++;let M=f.physicalRanges(b,C);if(t!==null)for(let[h,w]of M)a.flow.format(h,w-h,{[u]:t});else{let h=0;for(let w of a.flow.toDelta()){let y=typeof w.insert=="string"?w.insert.length:1;for(let[N,B]of M){if(h>=B)break;let v=Math.max(h,N),L=Math.min(h+y,B);if(L>v&&w.attributes){let Y={};for(let[$,x]of Object.entries(w.attributes))Se($)===r&&!Ce($)&&x!==null&&(Y[`${$}!${p}`]=!0);Object.keys(Y).length&&a.flow.format(v,L-v,Y)}}h+=y}}b=C}}var{AddMarkStep:uo,RemoveMarkStep:er,AttrStep:tr,ReplaceStep:nr,Mapping:ct}=rn,po=(e,o,n)=>{let r=e.resolve(o),t=e.resolve(n);return[r.depth&&r.node(1).type.name==="table"?r.before(1):o,t.depth&&t.node(1).type.name==="table"?t.after(1):n]},or=(e,o,n)=>{let r=!1;return e.nodesBetween(o,n,t=>(t.type.name==="table"&&(r=!0),!r&&t.type.name!=="table")),r};function mo(e,o,n,r,t=null,s=!0,a=null,{join:f=!1,open:u=!1}={}){let p=()=>{if(a){let l=a;a=null,l()}},b=[],C=[],M=[];for(let l of o)l.steps.forEach((k,F)=>{b.push(k),C.push(l.docs[F]),M.push(k.getMap())});if(!b.length)return;let h=new ct(M),w=[...Qe(Ze(e.ydoc)).entries()].sort((l,k)=>l[0]-k[0]),y=be(e),N=C[0],B=o[o.length-1].doc,v=n.visible.length===0&&N.childCount===1&&N.firstChild.type.name==="paragraph"?[{id:N.firstChild.attrs.id,implicit:!0,t:"paragraph",len:0}]:n.visible,L=new Map,Y=[];{let l=0;v.forEach(k=>{k.implicit&&Y.push({tok:l,id:k.id,t:k.t}),l+=k.len})}Y.sort((l,k)=>k.tok-l.tok);for(let l of Y)l.alias=hn(e),L.set(l.id,l.alias);let $=L.size?n.holes.map(l=>({at:l.at+Y.filter(k=>k.tok<l.at).length,len:l.len})):n.holes,x=Tt(n.tokens+L.size,$,e.flow.length+L.size),c=[],E=[];b.forEach((l,k)=>{let F=l instanceof uo||l instanceof er;if(F&&!or(C[k],l.from,l.to)){E.push({i:k,step:l});return}let R=new ct(M.slice(0,k)).invert(),D=new ct(M.slice(k+1)),q=[];l instanceof tr?q.push([l.pos,l.pos+1,l.pos,l.pos+1]):F?q.push([l.from,l.to,l.from,l.to]):l.getMap().forEach((O,te,X,G)=>q.push([O,te,X,G]));for(let[O,te,X,G]of q){let[Z,oe]=po(N,R.map(O,-1),R.map(te,1)),[ne,Ge]=po(B,D.map(X,-1),D.map(G,1));c.push({oa:Z,ob:oe,na:ne,nb:Ge})}}),c.sort((l,k)=>l.oa-k.oa||l.na-k.na);let i=[];for(let l of c){let k=i[i.length-1];k&&(l.oa<=k.ob||l.na<=k.nb)?(k.ob=Math.max(k.ob,l.ob),k.nb=Math.max(k.nb,l.nb)):i.push({...l})}let g=!Y.length&&!E.length&&b.every(l=>l instanceof nr)&&o.every(fn),A=g?null:It(N,L,v),z=g?null:It(B,L,v),W=g?[]:Ct(N,L,v),T=g?[]:Ct(B,L,v),U=g?i.map(l=>({r:l,old:At(N,l.oa,l.ob),next:At(B,l.na,l.nb)})):null,P=g?U.reduce((l,k)=>l+k.next.end-k.next.start,0):i.reduce((l,k)=>l+(z[k.nb]-z[k.na]),0),I=P>Nt,K=I?l=>e.ydoc.transact(k=>{k.meta.set(_e,s),p(),l()},me):l=>l(),j={pd:e,map:x,bt:W,tx:K,copies:n.copies,fences:n.fences,sv:w,operationId:y,recovered:new Map(n.visible.filter(l=>l.recovered).map(l=>[l.id,l.sourceKey]))},Q=l=>l.filter(k=>k.k==="b").map(k=>`${k.id}|${k.t}|${JSON.stringify(k.attrs)}`).join(`
3
3
  `),le=!g&&(E.length>0||Q(W)!==Q(T)),ee=()=>{for(let F of Y)lt(e,Ye(n.holes,F.tok),[{k:"b",id:F.alias,t:F.t,attrs:Object.fromEntries(xe(fe.nodes[F.t]).map(R=>[R,Ne(fe.nodes[F.t],R)]))}],K);for(let F=i.length-1;F>=0;F--)if(g){let{r:R,old:D,next:q}=U[F],O=D.tokens.map((te,X)=>{let G=h.mapResult(R.oa+X,1),Z=h.mapResult(R.oa+X+1,-1),oe=G.pos-R.na;return!G.deleted&&!Z.deleted&&Z.pos===G.pos+1&&oe>=0&&oe<q.tokens.length&&ze(te,q.tokens[oe])});Ft(j,D.start,D.tokens,q.tokens,O)}else{let R=i[F],D=A[R.oa],q=A[R.ob];Ft(j,D,W.slice(D,q),T.slice(z[R.na],z[R.nb]))}let l=E.length?ue(e):null,k=l?{...j,map:Tt(l.tokens,l.holes,e.flow.length)}:null;for(let{i:F,step:R}of E){let D=new ct(M.slice(F+1)),q=z[D.map(R.from,1)],O=z[D.map(R.to,-1)];if(O<=q)continue;let te=R.mark.type.name,X=R instanceof uo?R.mark.attrs&&Object.keys(R.mark.attrs).length?{...R.mark.attrs}:!0:null;if(ln(R.mark)){if(X===null)continue;let G=cn(R.mark.attrs.entries);K(()=>{for(let[Z,oe]of Object.entries(G))Lt(k,q,O,Z,oe,T)});continue}K(()=>Lt(k,q,O,te,X,T))}};f||t?.stopCapturing();let m=t?.captureTimeout;t&&(t.captureTimeout=1/0);try{I?ee():e.ydoc.transact(l=>{l.meta.set(_e,s),p(),ee()},me)}finally{t&&(t.captureTimeout=m),u||t?.stopCapturing()}r.groups++,r.lastGroup={chunked:I,structural:le,regional:g,span:P}}var ke=e=>({status:"refused",code:e}),ho=e=>{if(!e)return"";let o=[];for(let n of Object.keys(e).sort())o.push(`${n}=${JSON.stringify(e[n])}`);return o.join(`
4
4
  `)},rr=(e,o,n)=>{let r=n?n.state.doc:null,s=r&&r.childCount===o.visible.length&&o.visible.every((f,u)=>r.child(u).attrs.id===f.id)?r:Re(e,o),a=[];return s.forEach(f=>{f.attrs.id===null||f.attrs.id===void 0||a.push({id:f.attrs.id,parent:f.attrs.parent??null,t:f.type.name})}),a},sr=(e,o)=>{let n=[],r=e.get(o)?.parent??null,t=0;for(;r!=null&&t++<=e.size;)n.push(r),r=e.get(r)?.parent??null;return n},bo=(e,o,n)=>sr(e,n).includes(o),Bt=(e,o,n)=>o===n||bo(e,n,o),Dt=(e,o,n,r,t)=>{if(o?.recovered){let a=De(o.sourceKey,r);(e.gone.has(a)?e.gone.get(a):o.fields?.[r]??null)!==t&&e.gone.set(a,t);return}let s=e.attrs.get(n);s||(s=new Ae,e.attrs.set(n,s)),s.get(r)!==t&&s.set(r,t)},at=(e,o,n,r)=>Dt(e,o,n,"parent",r),ir=8,go={indent:(e,o)=>o.t==="list_item"&&Number.isInteger(e)&&e>=0&&e<=ir,open:(e,o)=>o.t==="toggle"&&typeof e=="boolean",parent:(e,o,n)=>e===null||typeof e=="string"&&n.get(e)?.t==="toggle"&&!Bt(n,e,o.id)},lr=(e,o)=>{if(e?.attrs===void 0)return[];if(!e.attrs||typeof e.attrs!="object"||Array.isArray(e.attrs))return null;let n=[];for(let[r,t]of Object.entries(e.attrs)){let s=o.get(r);if(!s||!t||typeof t!="object"||Array.isArray(t))return null;for(let[a,f]of Object.entries(t)){if(!go[a]||!go[a](f,s,o))return null;n.push({id:r,field:a,value:f})}}return n},cr=(e,o)=>{let n=bt(e.flow,0,e.flow.length),r=[],t=0;for(let s of e.flow.toDelta()){let a=s.attributes;if(typeof s.insert=="string")for(let f=0;f<s.insert.length;f++)r.push({ch:s.insert[f],attrs:a,source:o.resolve(n[t++])});else r.push({embed:s.insert,attrs:a,source:o.resolve(n[t++])})}if(t!==n.length)throw new Error(`The flow delta has ${t} units but the document has ${n.length}`);return r},ar=(e,o,n)=>{let r=new Map;for(let s of o.visible)n.has(s.id)&&s.brk&&r.set(Oe(s.brk),s.id);for(let s of n)for(let a of o.copies.get(s)??[])r.set(a,s);let t=[];for(let s=e.flow._start;s;s=s.right){if(s.deleted||!(s.content instanceof de))continue;let a=s.content.embed?.b;if(a===void 0||r.get(Oe(s.id))!==a)continue;let f=null;for(let u=s.right;u;u=u.right){if(u.deleted||!(u.content instanceof de))continue;let p=u.content.embed?.b;if(!(p===void 0||p===a)){f=Oe(u.id);break}}t.push({key:Oe(s.id),blockId:a,end:f})}return t};function zt({pd:e,view:o,um:n,origins:r,render:t,walked:s=null},a={}){let f=Array.isArray(a?.ids)?[...new Set(a.ids)]:[],u=a?.afterId===void 0?null:a.afterId,p=a?.parent!==void 0,b=s??ue(e,r),C=new Set(b.visible.filter(m=>m.opaque).map(m=>m.id)),M=rr(e,b,o),h=new Map(M.map(m=>[m.id,m])),w=M.map(m=>m.id);if(!f.length)return ke("missing-source");for(let m of f)if(!h.has(m))return ke("missing-source");let y=lr(a,h);if(!y)return ke("invalid-attrs");let N=y.filter(m=>m.field==="parent"),B=new Set(f.filter(m=>!f.some(l=>l!==m&&bo(h,l,m)))),v=M.filter(m=>f.some(l=>Bt(h,m.id,l))),L=new Set(v.map(m=>m.id));if(v.some(m=>C.has(m.id))||y.some(m=>C.has(m.id)))return ke("unsupported-format");let Y=new Map(b.visible.map(m=>[m.id,m]));for(let m of v){let l=Y.get(m.id);if(!l||l.implicit||!l.brk)return ke("missing-source")}let $;if(p)$=a.parent??null;else{let m=new Set(v.filter(l=>B.has(l.id)).map(l=>l.parent));if(m.size!==1)return ke("invalid-parent");$=[...m][0]}if(p&&$!==null){let m=h.get($);if(!m||m.t!=="toggle")return ke("invalid-parent");if(L.has($))return ke("cycle")}if(u!==null){if(typeof u!="string"||!h.has(u))return ke("missing-destination");if(L.has(u))return ke("cycle");if(h.get(u).parent!==$)return ke("missing-destination")}let x=M.filter(m=>!L.has(m.id)),c=0;if(u===null){if($!==null){let m=x.findIndex(k=>k.parent===$),l=x.findIndex(k=>k.id===$);c=m>=0?m:l<0?0:l+1}}else for(c=x.findIndex(m=>m.id===u)+1;c<x.length&&Bt(h,x[c].id,u);)c++;let E=[...x.slice(0,c),...v,...x.slice(c)],i=E.length===w.length&&E.every((m,l)=>m.id===w[l]),g=v.filter(m=>B.has(m.id)&&m.parent!==$),A=v.map(m=>m.id);if(i&&!g.length&&!y.length)return{status:"unchanged"};let z=(()=>{let m=o?.state.selection;if(!(m instanceof pe.TextSelection))return null;let l=R=>{let D=o.state.doc.resolve(R);return D.depth?{id:D.node(1).attrs.id,offset:D.parentOffset}:null},k=l(m.anchor),F=l(m.head);return k&&F&&(L.has(k.id)||L.has(F.id))?{anchor:k,head:F}:null})(),W=()=>{if(!z||!o)return;let m=({id:F,offset:R})=>{let D=null;return o.state.doc.forEach((q,O)=>{D===null&&q.attrs.id===F&&(D=O+1+Math.min(R,q.content.size))}),D},l=m(z.anchor),k=m(z.head);l!==null&&k!==null&&o.dispatch(o.state.tr.setSelection(pe.TextSelection.create(o.state.doc,l,k)).setMeta(Me,!0).setMeta("addToHistory",!1))};if(i)return n?.stopCapturing(),e.ydoc.transact(()=>{if(N.length)for(let m of N)at(e,Y.get(m.id),m.id,m.value);else for(let m of g)at(e,Y.get(m.id),m.id,$);for(let m of y)m.field!=="parent"&&Dt(e,Y.get(m.id),m.id,m.field,m.value)},me),n?.stopCapturing(),t(),W(),{status:"moved",ids:A};let T=[...Qe(Ze(e.ydoc)).entries()].sort((m,l)=>m[0]-l[0]),U=be(e),P=cr(e,r),I=kt(b,e.flow.length),K=[],j=0;for(let m of b.visible){if(L.has(m.id)){let l=[];for(let[k,F]of I.physicalRanges(j,j+m.len))for(let R=k;R<F;R++)l.push(P[R]);K.push({seg:m,units:l})}j+=m.len}for(let m=0;m<K.length;m++){let l=K[m];if(l.seg.id!==A[m])throw new Error(`Captured ${l.seg.id} where ${A[m]} was expected`);if(!l.units.length||l.units[0].embed===void 0||l.units[0].embed.b!==l.seg.id)throw new Error(`The selected block ${l.seg.id} has no physical marker to copy`)}let Q=ar(e,b,L),le=Pe(e.gone),ee=new Map;for(let m of v){let l=Y.get(m.id);if(!l.recovered)continue;let k=b.removals.filter(D=>D.sourceKey===l.sourceKey),F=Rn(l.sourceKey,k,le),R=le.restores.find(D=>D.key===F?.key)?.baseline??{type:l.t,attrs:l.fields??{}};ee.set(l.sourceKey,{covers:k.map(D=>D.key),baseline:JSON.parse(JSON.stringify(R))})}if(!Q.length)throw new Error("The selected blocks have no live physical markers to retire");return n?.stopCapturing(),e.ydoc.transact(()=>{for(let O of Q)e.gone.set(Be(O.key,U),{blockId:O.blockId,end:O.end,sv:T});let m=ue(e,r),l=kt(m,e.flow.length),k=m.visible.map(O=>O.id),F=0;if(c>0){let O=k.indexOf(x[c-1].id);F=O<0?0:O+1}let R=0;for(let O=0;O<F;O++)R+=m.visible[O].len;let D=l.toPhysical(R,"before"),q=[];for(let O of K){let te=D,X=null,G=null,Z=()=>{X!==null&&(We(e,D,m.fences,()=>e.flow.insert(D,X,G??void 0)),D+=X.length,X=null)};for(let ne of O.units)ne.ch!==void 0?(X!==null&&ho(ne.attrs)!==ho(G)&&Z(),X===null&&(X="",G=ne.attrs),X+=ne.ch):(Z(),We(e,D,m.fences,()=>e.flow.insertEmbed(D,ne.embed,ne.attrs)),D+=1);Z();let oe=bt(e.flow,te,D);if(oe.length!==O.units.length)throw new Error(`Copied ${O.seg.id} as ${oe.length} units instead of ${O.units.length}`);for(let ne=1;ne<O.units.length;ne++)q.push({dest:oe[ne],source:O.units[ne].source});r.recordBoundary(oe[0],O.seg.recovered?{blockId:O.seg.id,kind:"copy",recoveryOf:O.seg.sourceKey}:{blockId:O.seg.id,kind:"copy"}),O.seg.recovered&&e.gone.set(ot(O.seg.sourceKey,U),ee.get(O.seg.sourceKey)),e.gone.set(In(Oe(oe[0])),!0)}if(q.length&&r.recordSpans(q),N.length)for(let O of N)at(e,Y.get(O.id),O.id,O.value);else for(let O of g)at(e,Y.get(O.id),O.id,$);for(let O of y)O.field!=="parent"&&Dt(e,Y.get(O.id),O.id,O.field,O.value)},me),n?.stopCapturing(),t(),W(),{status:"moved",ids:A}}var Jt=e=>{let o=[];return e.forEach(n=>o.push([n.type.name,JSON.stringify(Object.fromEntries(xe(n.type).map(r=>[r,n.attrs[r]]))),n.isTextblock||n.type.name==="table"?JSON.stringify(n.content.toJSON()):null])),JSON.stringify(o)};function fr(e,o){if(e.childCount!==o.childCount)return!1;for(let n=0;n<e.childCount;n++){let r=e.child(n),t=o.child(n);if(r!==t&&(r.type!==t.type||xe(r.type).some(s=>!ye(r.attrs[s],t.attrs[s]))||(r.isTextblock||r.type.name==="table")&&!r.content.eq(t.content)))return!1}return!0}var ur=e=>{let o=[];return e.forEach((n,r)=>{n.type.name==="opaque_block"&&o.push([r,r+n.nodeSize])}),o},dr=(e,o)=>{let n=typeof e.from=="number"?e.from:typeof e.pos=="number"?e.pos:null;if(n===null)return!1;let r=typeof e.to=="number"?e.to:n+1;return o.some(([t,s])=>n<s&&r>t)},Ue=(e,o)=>{let n=e.resolve(o);return n.depth&&n.node(1).type.name==="table"?[n.before(1),n.after(1)]:null};function ko(e,o){let n=e.content.findDiffStart(o.content);if(n===null)return null;let{a:r,b:t}=e.content.findDiffEnd(o.content),s=n-Math.min(r,t);s>0&&(r+=s,t+=s);let a=(f,u)=>{let p=f.resolve(n);return p.parent.isTextblock&&p.sameParent(f.resolve(u))};return(Ue(e,n)||Ue(e,r))&&!(a(e,r)&&a(o,t))?(n=Ue(e,n)?.[0]??n,r=Ue(e,r)?.[1]??r,t=Ue(o,t)?.[1]??t,{start:n,endA:r,endB:t,tables:!0}):{start:n,endA:r,endB:t}}function Kt(e,o=null){let n=new Map;o?.forEach(u=>{u.attrs.id&&n.set(u.attrs.id,u)});let r=[];e.forEach(u=>r.push(u));let t=r.map(u=>({id:u.attrs.id,pos:n.get(u.attrs.id)?.attrs.pos??u.attrs.pos})),s=gt(t,"b"),a=!1,f=r.map((u,p)=>{let b=s[p]?.pos??t[p].pos,C=u.content;if(u.type.name==="table"){let w=[];u.forEach(v=>w.push(v));let y=w.map(v=>({id:v.attrs.id,pos:v.attrs.pos})),N=gt(y,"r"),B=w.map((v,L)=>{let Y=N[L]?.pos??y[L].pos;return Y===v.attrs.pos?v:v.type.create({...v.attrs,pos:Y},v.content,v.marks)});B.some((v,L)=>v!==w[L])&&(C=B)}if(b===u.attrs.pos&&C===u.content)return u;a=!0;let M={...u.attrs,pos:b},h=n.get(u.attrs.id);return h&&C===u.content&&h.hasMarkup(u.type,M,u.marks)&&h.content.eq(C)?h:u.type.create(M,C,u.marks)});return a?e.type.create(e.attrs,f):e}var yo=e=>{let o=new Set,n=null;for(let r=0;r<e.childCount;r++){let{id:t,pos:s}=e.child(r).attrs;if(!t||o.has(t)||!an(s)||n!==null&&n>=s)return!1;o.add(t),n=s}return!0},pr=(e,o)=>{for(let n in e.attrs)if(n!=="pos"&&e.attrs[n]!==o.attrs[n])return!1;return!0};function mr(e,o){if(e.childCount!==o.childCount||!yo(e))return!1;for(let n=0;n<e.childCount;n++){let r=e.child(n),t=o.child(n);if(r===t)continue;if(!(r.type===t.type&&r.marks===t.marks&&pr(r,t))&&!r.hasMarkup(t.type,{...t.attrs,pos:r.attrs.pos},t.marks)||!r.content.eq(t.content)||r.type.name==="table"&&!yo(r))return!1}return!0}var wo=e=>{if(e&&typeof e=="object"){for(let o of Object.keys(e))wo(e[o]);Object.freeze(e)}return e},vo=e=>wo(JSON.parse(JSON.stringify(e))),hr=(e,o)=>{let n=mn(o),r=0;for(let t=e.flow._start;t;t=t.right){if(t.id.client===n.client&&t.id.clock===n.clock)return t.deleted?r:r+t.length;!t.deleted&&t.countable&&(r+=t.length)}return r},gr=(e,o)=>{let n=null;for(let r=e.flow._start;r;r=r.right)r.id.client!==e.ydoc.clientID||!(r.content instanceof de)||r.content.embed?.b!==o||(!n||r.id.clock>n.clock)&&(n=r.id);return n};function xo({pd:e,onNotice:o=()=>{},ownedTokens:n=[],authorToken:r=null,stats:t={groups:0,mismatch:0,renders:0,first:null},captureTimeout:s=500}){let a=null,f=null,u=0,p=-1,b=null,C=0,M=new WeakMap,h=Le(e.origins);f=ue(e,h);let w=new tn([e.flow,e.attrs,e.gone,e.tableFields,e.boardFields],{trackedOrigins:new Set([me]),captureTimeout:s,captureTransaction:d=>d.meta.get(_e)!==!1,deleteFilter:d=>{if(d.parent!==e.flow||!(d.content instanceof de))return!0;let S=h.resolve(d.id);return S.client!==d.id.client||S.clock!==d.id.clock||h.boundaryOf(d.id)?.kind!=="copy"}}),y=yn(e,w,h,d=>Pe(d).textDeletes),N=new Set,B=new Set(r?[...n,r]:n),v=r?()=>{let d=Cn(e.ydoc.clientID);e.origins.get(d)!==r&&e.origins.set(d,r)}:null,L=new Set,Y=new Set,$=0,x=null,c=null,E=d=>{let S=new Set;for(let J of d.blocks)for(let V of J.runs){if(!V.displaced)continue;let H=Tn(V.source)?.client===e.ydoc.clientID;V.author&&(H||B.has(V.author))?S.add(V.author):H&&S.add(null)}if(!S.size)return null;let _=[...S].filter(Boolean).sort();return{kind:"recovered-change",source:d.source,revision:d.revision,blockId:d.blockId,author:_[0]??null,authors:_}},i=d=>{let S=d.list.filter(J=>J.recoverable).map(J=>vo(J)),_=vo(S.map(J=>E(J)).filter(J=>J&&!L.has(`${J.source}\0${J.revision}`)));return Object.freeze({recoverable:Object.freeze(S),notices:Object.freeze(_)})},g=(d,S)=>{if(JSON.stringify(i(st(e,{index:h,walked:S})))===JSON.stringify(d)){t.provedRecoveries=(t.provedRecoveries??0)+1;return}throw t.walkMismatch=(t.walkMismatch??0)+1,new Error("Recovery snapshot built from the displacing sources diverged from a full reduction")},A=()=>{if(x&&x.version===$)return x.snapshot;let d=p===u?f:void 0,S=i(Yn(e,{index:h,walked:d}));return t.proveWalks&&g(S,d),x={version:$,snapshot:S},S},z=d=>rt({recoverable:d.recoverable.map(S=>[S.source,S.revision]),notices:d.notices}),W=()=>{$++;let d=A();for(let _ of d.notices){let J=`${_.source}\0${_.revision}`;N.has(J)||(N.add(J),o(_))}if(!Y.size){c=null;return}let S=z(d);if(S!==c){c=S;for(let _ of[...Y])_(d)}},T=d=>{f=d,p=u,b=null,C=0},U=()=>p===u?f:null,P=d=>{let S=Ve(e,d),_=Ve(e,ue(e));if(S===_){t.provedWalks=(t.provedWalks??0)+1;return}throw t.walkMismatch=(t.walkMismatch??0)+1,new Error(`Incremental walk diverged from the full walk:
@@ -27,4 +27,4 @@ ${_}`)},Q=()=>{if(JSON.stringify(i(st(e,{index:h,walked:f})))!==JSON.stringify(A
27
27
  .page-recover-row button, .page-recover-head button { min-height: 44px; }
28
28
  }
29
29
  `,yr={heading:"Heading",list_item:"List item",toggle:"Toggle",quote:"Quote",code_block:"Code",callout:"Callout",table:"Table",image:"Image"},qt=280,ve=(e,o,n,r={})=>{let t=e.createElement(o);n&&(t.className=n);for(let[s,a]of Object.entries(r))t.setAttribute(s,a);return t};function vr(e,o){let n=ve(e,"div","page-recover-text"),r=0;for(let t of o.blocks){for(let s of t.runs){if(s.kind!=="text"||r>=qt)continue;let a=s.text.slice(0,qt-r);r+=a.length,n.append(s.displaced?Object.assign(e.createElement("mark"),{textContent:a}):e.createTextNode(a))}r<qt&&t!==o.blocks[o.blocks.length-1]&&n.append(e.createTextNode(" / "))}return n.textContent||(n.textContent="(no text)"),n}function wr(e){let o=new Set;for(let n of e.blocks)for(let r of n.runs)r.displaced&&o.add(r.author??null);return[...o]}function xr(e,o){let n=null;return e.state.doc.forEach((r,t)=>{n===null&&r.attrs.id===o&&(n=r.isTextblock?t+1:t)}),n===null?!1:(e.dispatch(e.state.tr.setSelection(pe.Selection.near(e.state.doc.resolve(n))).scrollIntoView()),e.focus(),!0)}function Sr({binding:e,mount:o,ownTokens:n=[],onRestored:r=()=>{},onStale:t=()=>{}}){let s=o.ownerDocument,a=new Set(n.filter(Boolean)),f=ve(s,"button","page-recover",{type:"button","aria-haspopup":"dialog","aria-expanded":"false"}),u=ve(s,"div","page-recover-panel",{role:"dialog","aria-label":"Recover changes"});f.hidden=!0,u.hidden=!0;let p=ve(s,"div","page-recover-root");p.append(f,u);let b=Ut({name:"page-recover",content:p,css:[kr],parent:o}),C={recoverable:[],notices:[]},M=null,h="",w=x=>x.some(c=>a.has(c))?x.length>1?"You and others":"You":x.some(c=>c!==null)?"Another editor":"An earlier edit",y=()=>{u.hidden=!0,M=null,f.setAttribute("aria-expanded","false")},N=x=>{let c;try{c=e.restore(x.source,x.revision)}catch(E){return console.error("[clay] Restore failed:",E),jn("This change could not be restored.","error"),{status:"failed"}}return c.status==="restored"||c.status==="resolved"?r(c.id):c.status==="stale"&&t(c),c},B=()=>{u.replaceChildren();let x=ve(s,"div","page-recover-head");x.append(s.createTextNode("Recover changes"));let c=ve(s,"button","",{type:"button"});c.textContent="Close",c.addEventListener("click",()=>{y(),f.focus()}),x.append(c);let E=ve(s,"p","page-recover-note");E.textContent="Text typed while its block was moved or removed. Restore puts it back as a new block.",u.append(x,E);for(let i of C.recoverable){let g=ve(s,"div","page-recover-row",{"data-source":i.source});i.source===M&&g.classList.add("is-target");let A=ve(s,"div","page-recover-meta");A.textContent=`${yr[i.type]??"Paragraph"} \xB7 ${w(wr(i))}`;let z=ve(s,"button","",{type:"button"});z.textContent="Restore",z.addEventListener("click",()=>N(i)),g.append(A,vr(s,i),z),u.append(g)}},v=(x=null)=>{if(!C.recoverable.length)return;M=x,u.hidden=!1,f.setAttribute("aria-expanded","true"),B();let c=[...u.querySelectorAll(".page-recover-row")];(c.find(i=>i.dataset.source===x)??c[0])?.querySelector("button")?.focus()},L=x=>{let c=x.map(E=>`${E.source}\0${E.revision}`).join(`
30
- `);if(c!==h){if(h=c,!x.length){St(Ht);return}_n(Ht,"warning",{actions:[{label:"Review",onClick:()=>v(x[0].source)},{label:"Dismiss",onClick:()=>{for(let E of x)e.dismiss(E.source,E.revision)}}]})}},Y=x=>{C=x;let c=x.recoverable.length;f.hidden=c===0,f.textContent=`Recover changes (${c})`,c?u.hidden||B():y(),L(x.notices)};f.addEventListener("click",()=>u.hidden?v():y()),u.addEventListener("keydown",x=>{x.key==="Escape"&&(x.stopPropagation(),y(),f.focus())});let $=e.subscribeRecovery(Y);return{open:v,close:y,restore:N,get count(){return C.recoverable.length},destroy(){$(),St(Ht),b.remove()}}}import("./page/editor-6LRB3GE4.js").catch(()=>null);export{Wn as ADOPTION_TIMEOUT_MS,Yo as acceptedPageState,Po as blocksFromYValue,je as canon,Mt as classifyFile,Io as createFeatureLoader,Sr as createRecoverList,br as createYPageBinding,xr as focusBlock,To as heldSlashRange,Ao as holdSlashRange,Do as installAdoption,jt as mergePageModels,Co as observeDocumentTitle,it as readBack,Ro as renderFromTags,$o as seedPageFromArticle,Eo as yValueOf};
30
+ `);if(c!==h){if(h=c,!x.length){St(Ht);return}_n(Ht,"warning",{actions:[{label:"Review",onClick:()=>v(x[0].source)},{label:"Dismiss",onClick:()=>{for(let E of x)e.dismiss(E.source,E.revision)}}]})}},Y=x=>{C=x;let c=x.recoverable.length;f.hidden=c===0,f.textContent=`Recover changes (${c})`,c?u.hidden||B():y(),L(x.notices)};f.addEventListener("click",()=>u.hidden?v():y()),u.addEventListener("keydown",x=>{x.key==="Escape"&&(x.stopPropagation(),y(),f.focus())});let $=e.subscribeRecovery(Y);return{open:v,close:y,restore:N,get count(){return C.recoverable.length},destroy(){$(),St(Ht),b.remove()}}}import("./page/editor-WRQGHDSG.js").catch(()=>null);export{Wn as ADOPTION_TIMEOUT_MS,Yo as acceptedPageState,Po as blocksFromYValue,je as canon,Mt as classifyFile,Io as createFeatureLoader,Sr as createRecoverList,br as createYPageBinding,xr as focusBlock,To as heldSlashRange,Ao as holdSlashRange,Do as installAdoption,jt as mergePageModels,Co as observeDocumentTitle,it as readBack,Ro as renderFromTags,$o as seedPageFromArticle,Eo as yValueOf};