@jant/core 0.6.9 → 0.6.10

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 (43) hide show
  1. package/dist/{app-C-jxWmAV.js → app-CGHkOdme.js} +396 -234
  2. package/dist/app-D24n0DoH.js +6 -0
  3. package/dist/client/.vite/manifest.json +3 -3
  4. package/dist/client/_assets/{client-DWy1LEEk.js → client-DYrWuaIk.js} +1 -1
  5. package/dist/client/_assets/{client-auth-Blg-a5Ep.js → client-auth-B5Re0uCd.js} +26 -24
  6. package/dist/client/_assets/client-xWDl78yi.css +2 -0
  7. package/dist/{export-C2DIB7mm.js → export-DY1v5Iqu.js} +1 -1
  8. package/dist/{github-sync-BEFCfLKK.js → github-sync-2_T7nbOv.js} +1 -1
  9. package/dist/{github-sync-7XQ5ZM6z.js → github-sync-LefaslGJ.js} +2 -2
  10. package/dist/index.js +3 -3
  11. package/dist/node.js +4 -4
  12. package/package.json +1 -1
  13. package/src/client/components/__tests__/jant-settings-avatar.test.ts +3 -0
  14. package/src/client/components/__tests__/jant-settings-general.test.ts +9 -4
  15. package/src/client/components/jant-settings-general.ts +18 -3
  16. package/src/client/components/settings-types.ts +2 -0
  17. package/src/client/tiptap/__tests__/link-toolbar.test.ts +41 -0
  18. package/src/client/tiptap/link-toolbar.ts +63 -1
  19. package/src/i18n/locales/settings/en.po +258 -18
  20. package/src/i18n/locales/settings/en.ts +1 -1
  21. package/src/i18n/locales/settings/zh-Hans.po +258 -18
  22. package/src/i18n/locales/settings/zh-Hans.ts +1 -1
  23. package/src/i18n/locales/settings/zh-Hant.po +258 -18
  24. package/src/i18n/locales/settings/zh-Hant.ts +1 -1
  25. package/src/lib/__tests__/feed.test.ts +5 -1
  26. package/src/lib/feed.ts +6 -3
  27. package/src/routes/dash/settings.tsx +7 -2
  28. package/src/routes/feed/__tests__/feed.test.ts +58 -19
  29. package/src/routes/feed/feed.ts +37 -28
  30. package/src/routes/pages/featured.tsx +17 -0
  31. package/src/routes/pages/latest.tsx +25 -0
  32. package/src/services/post.ts +1 -1
  33. package/src/styles/tokens.css +15 -0
  34. package/src/styles/ui.css +44 -1
  35. package/src/ui/__tests__/color-themes.test.ts +2 -2
  36. package/src/ui/color-themes.ts +32 -0
  37. package/src/ui/dash/appearance/ColorThemeContent.tsx +264 -29
  38. package/src/ui/dash/settings/GeneralContent.tsx +16 -0
  39. package/src/ui/dash/settings/__tests__/GeneralContent.test.tsx +3 -2
  40. package/src/ui/layouts/BaseLayout.tsx +2 -2
  41. package/src/ui/layouts/__tests__/BaseLayout.test.tsx +4 -4
  42. package/dist/app-DqHzOwL5.js +0 -6
  43. package/dist/client/_assets/client-CGf2m3qp.css +0 -2
@@ -1,4 +1,4 @@
1
- import{a as e,n as t,o as n,t as r}from"./chunks/url-pLre2DM_.js";import{_ as i,a,b as o,c as s,d as c,f as l,g as u,h as d,i as f,l as p,m,n as h,o as g,p as _,r as v,s as y,t as b,u as x,v as S,y as C}from"./client-DWy1LEEk.js";var ee={maxShortSide:1920,maxLongSide:8192,quality:.85,mimeType:`image/webp`};function te(e){return new Promise((t,n)=>{let r=new Image;r.onload=()=>{URL.revokeObjectURL(r.src),t(r)},r.onerror=()=>n(Error(`Failed to load image`)),r.src=URL.createObjectURL(e)})}function ne(e,t,n){if(Math.max(e,t)>n.maxLongSide)return{passthrough:!0,width:e,height:t};let r=Math.min(e,t);if(r<=n.maxShortSide)return{passthrough:!1,width:e,height:t};let i=n.maxShortSide/r;return{passthrough:!1,width:Math.round(e*i),height:Math.round(t*i)}}async function re(e,t,n){let r=await new Promise((r,i)=>{e.toBlob(e=>e?r(e):i(Error(`Failed to create blob`)),t,n)});return t!==`image/png`&&r.type===`image/png`?new Promise((t,r)=>{e.toBlob(e=>e?t(e):r(Error(`Failed to create blob`)),`image/jpeg`,n)}):r}async function ie(e,t={}){let n={...ee,...t},r=await te(e),i=ne(r.width,r.height,n);if(i.passthrough)return{blob:e,width:i.width,height:i.height,processed:!1};let a=document.createElement(`canvas`);a.width=i.width,a.height=i.height;let o=a.getContext(`2d`);if(!o)throw Error(`Failed to get canvas context`);return o.drawImage(r,0,0,i.width,i.height),{blob:await re(a,n.mimeType,n.quality),width:i.width,height:i.height,processed:!0}}async function ae(e,t={}){let n=await ie(e,t);if(!n.processed)return{file:e,width:n.width,height:n.height};let r={"image/webp":`webp`,"image/jpeg":`jpg`,"image/png":`png`}[n.blob.type]??`png`,i=`${e.name.replace(/\.[^.]+$/,``)}.${r}`;return{file:new File([n.blob],i,{type:n.blob.type}),width:n.width,height:n.height}}var oe={process:ie,processToFile:ae},se={ICO_16:16,ICO_32:32,APPLE_TOUCH:512};function ce(e){let t=e.length*16,n=6+t,r=new ArrayBuffer(6+t),i=new DataView(r);i.setUint16(0,0,!0),i.setUint16(2,1,!0),i.setUint16(4,e.length,!0);let a=[];for(let t=0;t<e.length;t++){let r=e[t],o=6+t*16;i.setUint8(o+0,r.size<256?r.size:0),i.setUint8(o+1,r.size<256?r.size:0),i.setUint8(o+2,0),i.setUint8(o+3,0),i.setUint16(o+4,1,!0),i.setUint16(o+6,32,!0),i.setUint32(o+8,r.png.byteLength,!0),i.setUint32(o+12,n,!0),n+=r.png.byteLength,a.push(r.png)}return new Blob([r,...a],{type:`image/x-icon`})}function le(e){return typeof e==`object`&&!!e}function w(e,t){if(!le(e))return;let n=e[t];return typeof n==`string`?n:void 0}function ue(e,t){if(!le(e))return;let n=e[t];return typeof n==`boolean`?n:void 0}function de(e,t){if(!le(e))return;let n=e[t];return typeof n==`number`?n:void 0}async function fe(e){let t=await e.text();if(!t.trim())return{};try{let e=JSON.parse(t);return le(e)?e:{}}catch{throw Error(`Expected JSON (HTTP ${e.status}) but got: ${ge(t.trim(),200)}`)}}async function pe(e,t){let n;try{n=await e.text()}catch{return t}return he(n,t)}function me(e,t){return he(e,t)}function he(e,t){let n=e.trim();if(!n)return t;try{let e=JSON.parse(n);if(le(e)){let t=w(e,`error`);if(t)return t}}catch{}return ge(n,200)}function ge(e,t){return e.length>t?`${e.slice(0,t)}…`:e}var _e=180;function ve(e){return new Promise((t,n)=>{let r=new Image;r.onload=()=>{URL.revokeObjectURL(r.src),t(r)},r.onerror=()=>n(Error(`Failed to load image`)),r.src=URL.createObjectURL(e)})}function ye(e,t){let n=document.createElement(`canvas`);n.width=t,n.height=t;let r=n.getContext(`2d`);if(!r)throw Error(`Failed to get canvas context`);r.imageSmoothingEnabled=!0,r.imageSmoothingQuality=`high`;let i=Math.max(t/e.width,t/e.height),a=t/i,o=t/i,s=(e.width-a)/2,c=(e.height-o)/2;return r.drawImage(e,s,c,a,o,0,0,t,t),new Promise((e,t)=>{n.toBlob(n=>{n?e(n):t(Error(`Failed to create PNG blob`))},`image/png`)})}function be(e,t){return e.type===`image/png`&&t.width===t.height&&t.width>=_e&&t.height>=_e}async function xe(e,t){let n=e.closest(`form`)?.querySelector(`label`),r=n?.textContent??``;try{n&&(n.textContent=e.dataset.textProcessing||`Processing...`);let r=await ve(t),i=t,a=t.name;if(t.type!==`image/svg+xml`){let e=await ye(r,512);i=new File([e],t.name.replace(/\.[^.]+$/,`.png`),{type:`image/png`}),a=i.name}let s=be(t,r)?Promise.resolve(t):ye(r,se.APPLE_TOUCH),[c,l,u]=await Promise.all([ye(r,16),ye(r,32),s]),[d,f]=await Promise.all([c.arrayBuffer(),l.arrayBuffer()]),p=ce([{size:16,png:d},{size:32,png:f}]);n&&(n.textContent=e.dataset.textUploading||`Uploading...`);let m=new FormData;m.append(`file`,i,a),m.append(`favicon`,p,`favicon.ico`),m.append(`appleTouch`,u,`apple-touch-icon.png`);let h=await fetch(o(`/settings/avatar`),{method:`POST`,headers:{Accept:`application/json`},body:m});if(!h.ok){let t=e.dataset.textError||`Upload failed. Please try again.`;try{let e=await fe(h);t=w(e,`error`)??w(e,`message`)??t}catch{}throw Error(t)}let g=await fe(h),_=w(g,`status`),v=w(g,`url`);if(_===`redirect`&&v){window.location.href=v;return}window.location.href=o(`/settings/avatar?saved`)}catch(t){n&&(n.textContent=r),a(t instanceof Error&&t.message?t.message:e.dataset.textError||`Upload failed. Please try again.`,`error`)}e.value=``}function Se(){document.addEventListener(`change`,e=>{let t=e.target.closest(`[data-avatar-upload]`);t?.files?.[0]&&(e.stopPropagation(),xe(t,t.files[0]))})}Se();var Ce=`default`,we=class extends _{static properties={_open:{state:!0},_title:{state:!0},_message:{state:!0},_confirmLabel:{state:!0},_cancelLabel:{state:!0},_tone:{state:!0}};#e=[];#t=null;createRenderRoot(){return this.innerHTML=``,this}constructor(){super(),this._open=!1,this._title=``,this._message=``,this._confirmLabel=``,this._cancelLabel=``,this._tone=Ce}disconnectedCallback(){super.disconnectedCallback();let e=this.#t;this.#t=null,e?.resolve(!1);for(let e of this.#e.splice(0))e.resolve(!1)}async confirm(e){return await new Promise(t=>{this.#e.push({...e,tone:e.tone??Ce,resolve:t}),this.#t||this.#n()})}async#n(){if(this.#t||this.#e.length===0)return;let e=this.#e.shift();if(!e)return;this.#t=e,this._title=e.title??``,this._message=e.message,this._confirmLabel=e.confirmLabel,this._cancelLabel=e.cancelLabel,this._tone=e.tone??Ce,this._open=!0,await this.updateComplete;let t=this.querySelector(`.confirm-dialog`);t&&(t.open||t.showModal(),t.querySelector(`.confirm-dialog-panel`)?.focus())}#r(e){let t=this.#t;if(!t)return;this.#t=null;let n=this.querySelector(`.confirm-dialog`);n?.open&&n.close(),this._open=!1,this._title=``,this._message=``,this._confirmLabel=``,this._cancelLabel=``,this._tone=Ce,t.resolve(e),queueMicrotask(()=>void this.#n())}#i=e=>{e.preventDefault(),this.#r(!1)};#a=e=>{e.target===e.currentTarget&&this.#r(!1)};#o=e=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),this.#r(!1);return}let t=e.target,n=t instanceof HTMLButtonElement||t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement||t instanceof HTMLAnchorElement;e.key===`Enter`&&!e.defaultPrevented&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&!e.shiftKey&&!n&&(e.preventDefault(),this.#r(!0))};#s(){if(this._title)return{title:this._title,message:this._message};let e=this._message.match(/^(.+?[??])\s+(.+)$/u);return e?{title:e[1],message:e[2]}:{title:this._message,message:``}}render(){if(!this._open)return m;let{title:e,message:t}=this.#s(),n=this._tone===`danger`?`btn-destructive`:`btn`;return u`
1
+ import{a as e,n as t,o as n,t as r}from"./chunks/url-pLre2DM_.js";import{_ as i,a,b as o,c as s,d as c,f as l,g as u,h as d,i as f,l as p,m,n as h,o as g,p as _,r as v,s as y,t as b,u as x,v as S,y as C}from"./client-DYrWuaIk.js";var ee={maxShortSide:1920,maxLongSide:8192,quality:.85,mimeType:`image/webp`};function te(e){return new Promise((t,n)=>{let r=new Image;r.onload=()=>{URL.revokeObjectURL(r.src),t(r)},r.onerror=()=>n(Error(`Failed to load image`)),r.src=URL.createObjectURL(e)})}function ne(e,t,n){if(Math.max(e,t)>n.maxLongSide)return{passthrough:!0,width:e,height:t};let r=Math.min(e,t);if(r<=n.maxShortSide)return{passthrough:!1,width:e,height:t};let i=n.maxShortSide/r;return{passthrough:!1,width:Math.round(e*i),height:Math.round(t*i)}}async function re(e,t,n){let r=await new Promise((r,i)=>{e.toBlob(e=>e?r(e):i(Error(`Failed to create blob`)),t,n)});return t!==`image/png`&&r.type===`image/png`?new Promise((t,r)=>{e.toBlob(e=>e?t(e):r(Error(`Failed to create blob`)),`image/jpeg`,n)}):r}async function ie(e,t={}){let n={...ee,...t},r=await te(e),i=ne(r.width,r.height,n);if(i.passthrough)return{blob:e,width:i.width,height:i.height,processed:!1};let a=document.createElement(`canvas`);a.width=i.width,a.height=i.height;let o=a.getContext(`2d`);if(!o)throw Error(`Failed to get canvas context`);return o.drawImage(r,0,0,i.width,i.height),{blob:await re(a,n.mimeType,n.quality),width:i.width,height:i.height,processed:!0}}async function ae(e,t={}){let n=await ie(e,t);if(!n.processed)return{file:e,width:n.width,height:n.height};let r={"image/webp":`webp`,"image/jpeg":`jpg`,"image/png":`png`}[n.blob.type]??`png`,i=`${e.name.replace(/\.[^.]+$/,``)}.${r}`;return{file:new File([n.blob],i,{type:n.blob.type}),width:n.width,height:n.height}}var oe={process:ie,processToFile:ae},se={ICO_16:16,ICO_32:32,APPLE_TOUCH:512};function ce(e){let t=e.length*16,n=6+t,r=new ArrayBuffer(6+t),i=new DataView(r);i.setUint16(0,0,!0),i.setUint16(2,1,!0),i.setUint16(4,e.length,!0);let a=[];for(let t=0;t<e.length;t++){let r=e[t],o=6+t*16;i.setUint8(o+0,r.size<256?r.size:0),i.setUint8(o+1,r.size<256?r.size:0),i.setUint8(o+2,0),i.setUint8(o+3,0),i.setUint16(o+4,1,!0),i.setUint16(o+6,32,!0),i.setUint32(o+8,r.png.byteLength,!0),i.setUint32(o+12,n,!0),n+=r.png.byteLength,a.push(r.png)}return new Blob([r,...a],{type:`image/x-icon`})}function le(e){return typeof e==`object`&&!!e}function w(e,t){if(!le(e))return;let n=e[t];return typeof n==`string`?n:void 0}function ue(e,t){if(!le(e))return;let n=e[t];return typeof n==`boolean`?n:void 0}function de(e,t){if(!le(e))return;let n=e[t];return typeof n==`number`?n:void 0}async function fe(e){let t=await e.text();if(!t.trim())return{};try{let e=JSON.parse(t);return le(e)?e:{}}catch{throw Error(`Expected JSON (HTTP ${e.status}) but got: ${ge(t.trim(),200)}`)}}async function pe(e,t){let n;try{n=await e.text()}catch{return t}return he(n,t)}function me(e,t){return he(e,t)}function he(e,t){let n=e.trim();if(!n)return t;try{let e=JSON.parse(n);if(le(e)){let t=w(e,`error`);if(t)return t}}catch{}return ge(n,200)}function ge(e,t){return e.length>t?`${e.slice(0,t)}…`:e}var _e=180;function ve(e){return new Promise((t,n)=>{let r=new Image;r.onload=()=>{URL.revokeObjectURL(r.src),t(r)},r.onerror=()=>n(Error(`Failed to load image`)),r.src=URL.createObjectURL(e)})}function ye(e,t){let n=document.createElement(`canvas`);n.width=t,n.height=t;let r=n.getContext(`2d`);if(!r)throw Error(`Failed to get canvas context`);r.imageSmoothingEnabled=!0,r.imageSmoothingQuality=`high`;let i=Math.max(t/e.width,t/e.height),a=t/i,o=t/i,s=(e.width-a)/2,c=(e.height-o)/2;return r.drawImage(e,s,c,a,o,0,0,t,t),new Promise((e,t)=>{n.toBlob(n=>{n?e(n):t(Error(`Failed to create PNG blob`))},`image/png`)})}function be(e,t){return e.type===`image/png`&&t.width===t.height&&t.width>=_e&&t.height>=_e}async function xe(e,t){let n=e.closest(`form`)?.querySelector(`label`),r=n?.textContent??``;try{n&&(n.textContent=e.dataset.textProcessing||`Processing...`);let r=await ve(t),i=t,a=t.name;if(t.type!==`image/svg+xml`){let e=await ye(r,512);i=new File([e],t.name.replace(/\.[^.]+$/,`.png`),{type:`image/png`}),a=i.name}let s=be(t,r)?Promise.resolve(t):ye(r,se.APPLE_TOUCH),[c,l,u]=await Promise.all([ye(r,16),ye(r,32),s]),[d,f]=await Promise.all([c.arrayBuffer(),l.arrayBuffer()]),p=ce([{size:16,png:d},{size:32,png:f}]);n&&(n.textContent=e.dataset.textUploading||`Uploading...`);let m=new FormData;m.append(`file`,i,a),m.append(`favicon`,p,`favicon.ico`),m.append(`appleTouch`,u,`apple-touch-icon.png`);let h=await fetch(o(`/settings/avatar`),{method:`POST`,headers:{Accept:`application/json`},body:m});if(!h.ok){let t=e.dataset.textError||`Upload failed. Please try again.`;try{let e=await fe(h);t=w(e,`error`)??w(e,`message`)??t}catch{}throw Error(t)}let g=await fe(h),_=w(g,`status`),v=w(g,`url`);if(_===`redirect`&&v){window.location.href=v;return}window.location.href=o(`/settings/avatar?saved`)}catch(t){n&&(n.textContent=r),a(t instanceof Error&&t.message?t.message:e.dataset.textError||`Upload failed. Please try again.`,`error`)}e.value=``}function Se(){document.addEventListener(`change`,e=>{let t=e.target.closest(`[data-avatar-upload]`);t?.files?.[0]&&(e.stopPropagation(),xe(t,t.files[0]))})}Se();var Ce=`default`,we=class extends _{static properties={_open:{state:!0},_title:{state:!0},_message:{state:!0},_confirmLabel:{state:!0},_cancelLabel:{state:!0},_tone:{state:!0}};#e=[];#t=null;createRenderRoot(){return this.innerHTML=``,this}constructor(){super(),this._open=!1,this._title=``,this._message=``,this._confirmLabel=``,this._cancelLabel=``,this._tone=Ce}disconnectedCallback(){super.disconnectedCallback();let e=this.#t;this.#t=null,e?.resolve(!1);for(let e of this.#e.splice(0))e.resolve(!1)}async confirm(e){return await new Promise(t=>{this.#e.push({...e,tone:e.tone??Ce,resolve:t}),this.#t||this.#n()})}async#n(){if(this.#t||this.#e.length===0)return;let e=this.#e.shift();if(!e)return;this.#t=e,this._title=e.title??``,this._message=e.message,this._confirmLabel=e.confirmLabel,this._cancelLabel=e.cancelLabel,this._tone=e.tone??Ce,this._open=!0,await this.updateComplete;let t=this.querySelector(`.confirm-dialog`);t&&(t.open||t.showModal(),t.querySelector(`.confirm-dialog-panel`)?.focus())}#r(e){let t=this.#t;if(!t)return;this.#t=null;let n=this.querySelector(`.confirm-dialog`);n?.open&&n.close(),this._open=!1,this._title=``,this._message=``,this._confirmLabel=``,this._cancelLabel=``,this._tone=Ce,t.resolve(e),queueMicrotask(()=>void this.#n())}#i=e=>{e.preventDefault(),this.#r(!1)};#a=e=>{e.target===e.currentTarget&&this.#r(!1)};#o=e=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),this.#r(!1);return}let t=e.target,n=t instanceof HTMLButtonElement||t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement||t instanceof HTMLAnchorElement;e.key===`Enter`&&!e.defaultPrevented&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&!e.shiftKey&&!n&&(e.preventDefault(),this.#r(!0))};#s(){if(this._title)return{title:this._title,message:this._message};let e=this._message.match(/^(.+?[??])\s+(.+)$/u);return e?{title:e[1],message:e[2]}:{title:this._message,message:``}}render(){if(!this._open)return m;let{title:e,message:t}=this.#s(),n=this._tone===`danger`?`btn-destructive`:`btn`;return u`
2
2
  <dialog
3
3
  class="dialog confirm-dialog"
4
4
  @cancel=${this.#i}
@@ -46,15 +46,15 @@ import{a as e,n as t,o as n,t as r}from"./chunks/url-pLre2DM_.js";import{_ as i,
46
46
  `)}};at.empty=new at(!0);var ot=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==``&&this.tokens.pop(),this.tokens[0]==``&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw SyntaxError(e+` (in content expression '`+this.string+`')`)}};function st(e){let t=[];do t.push(ct(e));while(e.eat(`|`));return t.length==1?t[0]:{type:`choice`,exprs:t}}function ct(e){let t=[];do t.push(lt(e));while(e.next&&e.next!=`)`&&e.next!=`|`);return t.length==1?t[0]:{type:`seq`,exprs:t}}function lt(e){let t=pt(e);for(;;)if(e.eat(`+`))t={type:`plus`,expr:t};else if(e.eat(`*`))t={type:`star`,expr:t};else if(e.eat(`?`))t={type:`opt`,expr:t};else if(e.eat(`{`))t=dt(e,t);else break;return t}function ut(e){/\D/.test(e.next)&&e.err(`Expected number, got '`+e.next+`'`);let t=Number(e.next);return e.pos++,t}function dt(e,t){let n=ut(e),r=n;return e.eat(`,`)&&(r=e.next==`}`?-1:ut(e)),e.eat(`}`)||e.err(`Unclosed braced range`),{type:`range`,min:n,max:r,expr:t}}function ft(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let i=[];for(let e in n){let r=n[e];r.isInGroup(t)&&i.push(r)}return i.length==0&&e.err(`No node type or group '`+t+`' found`),i}function pt(e){if(e.eat(`(`)){let t=st(e);return e.eat(`)`)||e.err(`Missing closing paren`),t}else if(/\W/.test(e.next))e.err(`Unexpected token '`+e.next+`'`);else{let t=ft(e,e.next).map(t=>(e.inline==null?e.inline=t.isInline:e.inline!=t.isInline&&e.err(`Mixing inline and block content`),{type:`name`,value:t}));return e.pos++,t.length==1?t[0]:{type:`choice`,exprs:t}}}function mt(e){let t=[[]];return i(a(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let i={term:r,to:n};return t[e].push(i),i}function i(e,t){e.forEach(e=>e.to=t)}function a(e,t){if(e.type==`choice`)return e.exprs.reduce((e,n)=>e.concat(a(n,t)),[]);if(e.type==`seq`)for(let r=0;;r++){let o=a(e.exprs[r],t);if(r==e.exprs.length-1)return o;i(o,t=n())}else if(e.type==`star`){let o=n();return r(t,o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`plus`){let o=n();return i(a(e.expr,t),o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`opt`)return[r(t)].concat(a(e.expr,t));else if(e.type==`range`){let o=t;for(let t=0;t<e.min;t++){let t=n();i(a(e.expr,o),t),o=t}if(e.max==-1)i(a(e.expr,o),o);else for(let t=e.min;t<e.max;t++){let t=n();r(o,t),i(a(e.expr,o),t),o=t}return[r(o)]}else if(e.type==`name`)return[r(t,void 0,e.value)];else throw Error(`Unknown expr type`)}}function ht(e,t){return t-e}function gt(e,t){let n=[];return r(t),n.sort(ht);function r(t){let i=e[t];if(i.length==1&&!i[0].term)return r(i[0].to);n.push(t);for(let e=0;e<i.length;e++){let{term:t,to:a}=i[e];!t&&n.indexOf(a)==-1&&r(a)}}}function _t(e){let t=Object.create(null);return n(gt(e,0));function n(r){let i=[];r.forEach(t=>{e[t].forEach(({term:t,to:n})=>{if(!t)return;let r;for(let e=0;e<i.length;e++)i[e][0]==t&&(r=i[e][1]);gt(e,n).forEach(e=>{r||i.push([t,r=[]]),r.indexOf(e)==-1&&r.push(e)})})});let a=t[r.join(`,`)]=new at(r.indexOf(e.length-1)>-1);for(let e=0;e<i.length;e++){let r=i[e][1].sort(ht);a.next.push({type:i[e][0],next:t[r.join(`,`)]||n(r)})}return a}}function vt(e,t){for(let n=0,r=[e];n<r.length;n++){let e=r[n],i=!e.validEnd,a=[];for(let t=0;t<e.next.length;t++){let{type:n,next:o}=e.next[t];a.push(n.name),i&&!(n.isText||n.hasRequiredAttrs())&&(i=!1),r.indexOf(o)==-1&&r.push(o)}i&&t.err(`Only non-generatable nodes (`+a.join(`, `)+`) in a required position (see https://prosemirror.net/docs/guide/#generatable)`)}}function yt(e){let t=Object.create(null);for(let n in e){let r=e[n];if(!r.hasDefault)return null;t[n]=r.default}return t}function bt(e,t){let n=Object.create(null);for(let r in e){let i=t&&t[r];if(i===void 0){let t=e[r];if(t.hasDefault)i=t.default;else throw RangeError(`No value supplied for attribute `+r)}n[r]=i}return n}function xt(e,t,n,r){for(let r in t)if(!(r in e))throw RangeError(`Unsupported attribute ${r} for ${n} of type ${r}`);for(let n in e){let r=e[n];r.validate&&r.validate(t[n])}}function St(e,t){let n=Object.create(null);if(t)for(let r in t)n[r]=new Tt(e,r,t[r]);return n}var Ct=class e{constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.markSet=null,this.groups=n.group?n.group.split(` `):[],this.attrs=St(e,n.attrs),this.defaultAttrs=yt(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||e==`text`),this.isText=e==`text`}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==at.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?`pre`:`normal`)}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:bt(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error(`NodeType.create can't construct text nodes`);return new nt(this,this.computeAttrs(e),E.from(t),Ie.setFrom(n))}createChecked(e=null,t,n){return t=E.from(t),this.checkContent(t),new nt(this,this.computeAttrs(e),t,Ie.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=E.from(t),t.size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let r=this.contentMatch.matchFragment(t),i=r&&r.fillBefore(E.empty,!0);return i?new nt(this,e,t.append(i),Ie.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let t=0;t<e.childCount;t++)if(!this.allowsMarks(e.child(t).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){xt(this.attrs,e,`node`,this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let t;for(let n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||=e.slice(0,n);return t?t.length?t:Ie.none:e}static compile(t,n){let r=Object.create(null);t.forEach((t,i)=>r[t]=new e(t,n,i));let i=n.spec.topNode||`doc`;if(!r[i])throw RangeError(`Schema is missing its top node type ('`+i+`')`);if(!r.text)throw RangeError(`Every schema needs a 'text' type`);for(let e in r.text.attrs)throw RangeError(`The text node type should not have attributes`);return r}};function wt(e,t,n){let r=n.split(`|`);return n=>{let i=n===null?`null`:typeof n;if(r.indexOf(i)<0)throw RangeError(`Expected value of type ${r} for attribute ${t} on type ${e}, got ${i}`)}}var Tt=class{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,`default`),this.default=n.default,this.validate=typeof n.validate==`string`?wt(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}},Et=class e{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=St(e,r.attrs),this.excluded=null;let i=yt(this.attrs);this.instance=i?new Ie(this,i):null}create(e=null){return!e&&this.instance?this.instance:new Ie(this,bt(this.attrs,e))}static compile(t,n){let r=Object.create(null),i=0;return t.forEach((t,a)=>r[t]=new e(t,i++,n,a)),r}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){xt(this.attrs,e,`mark`,this.name)}excludes(e){return this.excluded.indexOf(e)>-1}},Dt=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=Ae.from(e.nodes),t.marks=Ae.from(e.marks||{}),this.nodes=Ct.compile(this.spec.nodes,this),this.marks=Et.compile(this.spec.marks,this);let n=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw RangeError(e+` can not be both a node and a mark`);let t=this.nodes[e],r=t.spec.content||``,i=t.spec.marks;if(t.contentMatch=n[r]||(n[r]=at.parse(r,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw RangeError(`Multiple linebreak nodes defined`);if(!t.isInline||!t.isLeaf)throw RangeError(`Linebreak replacement nodes must be inline leaf nodes`);this.linebreakReplacement=t}t.markSet=i==`_`?null:i?Ot(this,i.split(` `)):i==``||!t.inlineContent?[]:null}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=n==null?[t]:n==``?[]:Ot(this,n.split(` `))}this.nodeFromJSON=e=>nt.fromJSON(this,e),this.markFromJSON=e=>Ie.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||`doc`],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if(typeof e==`string`)e=this.nodeType(e);else if(!(e instanceof Ct))throw RangeError(`Invalid node type: `+e);else if(e.schema!=this)throw RangeError(`Node type from different schema used (`+e.name+`)`);return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new rt(n,n.defaultAttrs,e,Ie.setFrom(t))}mark(e,t){return typeof e==`string`&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw RangeError(`Unknown node type: `+e);return t}};function Ot(e,t){let n=[];for(let r=0;r<t.length;r++){let i=t[r],a=e.marks[i],o=a;if(a)n.push(a);else for(let t in e.marks){let r=e.marks[t];(i==`_`||r.spec.group&&r.spec.group.split(` `).indexOf(i)>-1)&&n.push(o=r)}if(!o)throw SyntaxError(`Unknown mark type: '`+t[r]+`'`)}return n}function kt(e){return e.tag!=null}function At(e){return e.style!=null}var jt=class e{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(kt(e))this.tags.push(e);else if(At(e)){let t=/[^=]*/.exec(e.style)[0];n.indexOf(t)<0&&n.push(t),this.styles.push(e)}}),this.normalizeLists=!this.tags.some(t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)})}parse(e,t={}){let n=new Bt(this,t,!1);return n.addAll(e,Ie.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new Bt(this,t,!0);return n.addAll(e,Ie.none,t.from,t.to),D.maxOpen(n.finish())}matchTag(e,t,n){for(let r=n?this.tags.indexOf(n)+1:0;r<this.tags.length;r++){let n=this.tags[r];if(Ht(e,n.tag)&&(n.namespace===void 0||e.namespaceURI==n.namespace)&&(!n.context||t.matchesContext(n.context))){if(n.getAttrs){let t=n.getAttrs(e);if(t===!1)continue;n.attrs=t||void 0}return n}}}matchStyle(e,t,n,r){for(let i=r?this.styles.indexOf(r)+1:0;i<this.styles.length;i++){let r=this.styles[i],a=r.style;if(!(a.indexOf(e)!=0||r.context&&!n.matchesContext(r.context)||a.length>e.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=t))){if(r.getAttrs){let e=r.getAttrs(t);if(e===!1)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=e.priority==null?50:e.priority,r=0;for(;r<t.length;r++){let e=t[r];if((e.priority==null?50:e.priority)<n)break}t.splice(r,0,e)}for(let t in e.marks){let r=e.marks[t].spec.parseDOM;r&&r.forEach(e=>{n(e=Ut(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let r=e.nodes[t].spec.parseDOM;r&&r.forEach(e=>{n(e=Ut(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new e(t,e.schemaRules(t)))}},Mt={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Nt={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Pt={ol:!0,ul:!0},Ft=1,It=2,Lt=4;function Rt(e,t,n){return t==null?e&&e.whitespace==`pre`?Ft|It:n&~Lt:(t?Ft:0)|(t===`full`?It:0)}var zt=class{constructor(e,t,n,r,i,a){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=a,this.content=[],this.activeMarks=Ie.none,this.match=i||(a&Lt?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(E.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let t=this.type.contentMatch,n;return(n=t.findWrapping(e.type))?(this.match=t,n):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Ft)){let e=this.content[this.content.length-1],t;if(e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))){let n=e;e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-t[0].length))}}let t=E.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(E.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Mt.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Bt=class{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r=t.topNode,i,a=Rt(null,t.preserveWhitespace,0)|(n?Lt:0);i=r?new zt(r.type,r.attrs,Ie.none,!0,t.topMatch||r.type.contentMatch,a):n?new zt(null,null,Ie.none,!0,null,a):new zt(e.schema.topNodeType,null,Ie.none,!0,null,a),this.nodes=[i],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,r=this.top,i=r.options&It?`full`:this.localPreserveWS||(r.options&Ft)>0,{schema:a}=this.parser;if(i===`full`||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(!i){if(n=n.replace(/[ \t\r\n\u000c]+/g,` `),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=r.content[r.content.length-1],i=e.previousSibling;(!t||i&&i.nodeName==`BR`||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}}else if(i===`full`)n=n.replace(/\r\n?/g,`
47
47
  `);else if(a.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(a.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n<e.length;n++)n&&this.insertNode(a.linebreakReplacement.create(),t,!0),e[n]&&this.insertNode(a.text(e[n]),t,!/\S/.test(e[n]));n=``}else n=n.replace(/\r?\n|\r/g,` `);n&&this.insertNode(a.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let r=this.localPreserveWS,i=this.top;(e.tagName==`PRE`||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let a=e.nodeName.toLowerCase(),o;Pt.hasOwnProperty(a)&&this.parser.normalizeLists&&Vt(e);let s=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,n));out:if(s?s.ignore:Nt.hasOwnProperty(a))this.findInside(e),this.ignoreFallback(e,t);else if(!s||s.skip||s.closeParent){s&&s.closeParent?this.open=Math.max(0,this.open-1):s&&s.skip.nodeType&&(e=s.skip);let n,r=this.needsBlock;if(Mt.hasOwnProperty(a))i.content.length&&i.content[0].isInline&&this.open&&(this.open--,i=this.top),n=!0,i.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break out}let o=s&&s.skip?t:this.readStyles(e,t);o&&this.addAll(e,o),n&&this.sync(i),this.needsBlock=r}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,s,n,s.consuming===!1?o:void 0)}this.localPreserveWS=r}leafFallback(e,t){e.nodeName==`BR`&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
48
48
  `),t)}ignoreFallback(e,t){e.nodeName==`BR`&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text(`-`),t,!0)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let e=0;e<this.parser.matchedStyles.length;e++){let r=this.parser.matchedStyles[e],i=n.getPropertyValue(r);if(i)for(let e;;){let n=this.parser.matchStyle(r,i,this,e);if(!n)break;if(n.ignore)return null;if(t=n.clearMark?t.filter(e=>!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),n.consuming===!1)e=n;else break}}return t}addElementByRule(e,t,n,r){let i,a;if(t.node)if(a=this.parser.schema.nodes[t.node],a.isLeaf)this.insertNode(a.create(t.attrs),n,e.nodeName==`BR`)||this.leafFallback(e,n);else{let e=this.enter(a,t.attrs||null,n,t.preserveWhitespace);e&&(i=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let o=this.top;if(a&&a.isLeaf)this.findInside(e);else if(r)this.addElement(e,n,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let r=e;typeof t.contentElement==`string`?r=e.querySelector(t.contentElement):typeof t.contentElement==`function`?r=t.contentElement(e):t.contentElement&&(r=t.contentElement),this.findAround(e,r,!0),this.addAll(r,n),this.findAround(e,r,!1)}i&&this.sync(o)&&this.open--}addAll(e,t,n,r){let i=n||0;for(let a=n?e.childNodes[n]:e.firstChild,o=r==null?null:e.childNodes[r];a!=o;a=a.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(a,t);this.findAtPoint(e,i)}findPlace(e,t,n){let r,i;for(let t=this.open,a=0;t>=0;t--){let o=this.nodes[t],s=o.findWrapping(e);if(s&&(!r||r.length>s.length+a)&&(r=s,i=o,!s.length))break;if(o.solid){if(n)break;a+=2}}if(!r)return null;this.sync(i);for(let e=0;e<r.length;e++)t=this.enterInner(r[e],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let e=this.textblockFromContext();e&&(t=this.enterInner(e,null,t))}let r=this.findPlace(e,t,n);if(r){this.closeExtra();let t=this.top;t.match&&=t.match.matchType(e.type);let n=Ie.none;for(let i of r.concat(e.marks))(t.type?t.type.allowsMarkType(i.type):Wt(i.type,e.type))&&(n=i.addToSet(n));return t.content.push(e.mark(n)),!0}return!1}enter(e,t,n,r){let i=this.findPlace(e.create(t),n,!1);return i&&=this.enterInner(e,t,n,!0,r),i}enterInner(e,t,n,r=!1,i){this.closeExtra();let a=this.top;a.match=a.match&&a.match.matchType(e);let o=Rt(e,i,a.options);a.options&Lt&&a.content.length==0&&(o|=Lt);let s=Ie.none;return n=n.filter(t=>(a.type?a.type.allowsMarkType(t.type):Wt(t.type,e))?(s=t.addToSet(s),!1):!0),this.nodes.push(new zt(e,t,s,r,null,o)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;else this.localPreserveWS&&(this.nodes[t].options|=Ft);return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&this.find[n].offset==t&&(this.find[n].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].pos==null&&e.nodeType==1&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let r=0;r<this.find.length;r++)this.find[r].pos==null&&e.nodeType==1&&e.contains(this.find[r].node)&&t.compareDocumentPosition(this.find[r].node)&(n?2:4)&&(this.find[r].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf(`|`)>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split(`/`),n=this.options.context,r=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),i=-(n?n.depth+1:0)+(r?0:1),a=(e,o)=>{for(;e>=0;e--){let s=t[e];if(s==``){if(e==t.length-1||e==0)continue;for(;o>=i;o--)if(a(e-1,o))return!0;return!1}else{let e=o>0||o==0&&r?this.nodes[o].type:n&&o>=i?n.node(o-i).type:null;if(!e||e.name!=s&&!e.isInGroup(s))return!1;o--}}return!0};return a(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}};function Vt(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=t.nodeType==1?t.nodeName.toLowerCase():null;e&&Pt.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):e==`li`?n=t:e&&(n=null)}}function Ht(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function Ut(e){let t={};for(let n in e)t[n]=e[n];return t}function Wt(e,t){let n=t.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(e))continue;let a=[],o=e=>{a.push(e);for(let n=0;n<e.edgeCount;n++){let{type:r,next:i}=e.edge(n);if(r==t||a.indexOf(i)<0&&o(i))return!0}};if(o(i.contentMatch))return!0}}var Gt=class e{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||=qt(t).createDocumentFragment();let r=n,i=[];return e.forEach(e=>{if(i.length||e.marks.length){let n=0,a=0;for(;n<i.length&&a<e.marks.length;){let t=e.marks[a];if(!this.marks[t.type.name]){a++;continue}if(!t.eq(i[n][0])||t.type.spec.spanning===!1)break;n++,a++}for(;n<i.length;)r=i.pop()[1];for(;a<e.marks.length;){let n=e.marks[a++],o=this.serializeMark(n,e.isInline,t);o&&(i.push([n,r]),r.appendChild(o.dom),r=o.contentDOM||o.dom)}}r.appendChild(this.serializeNodeInner(e,t))}),n}serializeNodeInner(e,t){let{dom:n,contentDOM:r}=Zt(qt(t),this.nodes[e.type.name](e),null,e.attrs);if(r){if(e.isLeaf)throw RangeError(`Content hole not allowed in a leaf node spec`);this.serializeFragment(e.content,t,r)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let r=e.marks.length-1;r>=0;r--){let i=this.serializeMark(e.marks[r],e.isInline,t);i&&((i.contentDOM||i.dom).appendChild(n),n=i.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&Zt(qt(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return Zt(e,t,n,r)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new e(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(e){let t=Kt(e.nodes);return t.text||=e=>e.text,t}static marksFromSchema(e){return Kt(e.marks)}};function Kt(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function qt(e){return e.document||window.document}var Jt=new WeakMap;function Yt(e){let t=Jt.get(e);return t===void 0&&Jt.set(e,t=Xt(e)),t}function Xt(e){let t=null;function n(e){if(e&&typeof e==`object`)if(Array.isArray(e))if(typeof e[0]==`string`)t||=[],t.push(e);else for(let t=0;t<e.length;t++)n(e[t]);else for(let t in e)n(e[t])}return n(e),t}function Zt(e,t,n,r){if(typeof t==`string`)return{dom:e.createTextNode(t)};if(t.nodeType!=null)return{dom:t};if(t.dom&&t.dom.nodeType!=null)return t;let i=t[0],a;if(typeof i!=`string`)throw RangeError(`Invalid array passed to renderSpec`);if(r&&(a=Yt(r))&&a.indexOf(t)>-1)throw RangeError(`Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.`);let o=i.indexOf(` `);o>0&&(n=i.slice(0,o),i=i.slice(o+1));let s,c=n?e.createElementNS(n,i):e.createElement(i),l=t[1],u=1;if(l&&typeof l==`object`&&l.nodeType==null&&!Array.isArray(l)){u=2;for(let e in l)if(l[e]!=null){let t=e.indexOf(` `);t>0?c.setAttributeNS(e.slice(0,t),e.slice(t+1),l[e]):e==`style`&&c.style?c.style.cssText=l[e]:c.setAttribute(e,l[e])}}for(let i=u;i<t.length;i++){let a=t[i];if(a===0){if(i<t.length-1||i>u)throw RangeError(`Content hole must be the only child of its parent node`);return{dom:c,contentDOM:c}}else{let{dom:t,contentDOM:i}=Zt(e,a,n,r);if(c.appendChild(t),i){if(s)throw RangeError(`Multiple content holes`);s=i}}}return{dom:c,contentDOM:s}}var Qt=65535,$t=2**16;function en(e,t){return e+t*$t}function tn(e){return e&Qt}function nn(e){return(e-(e&Qt))/$t}var rn=1,an=2,on=4,sn=8,cn=class{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&sn)>0}get deletedBefore(){return(this.delInfo&(rn|on))>0}get deletedAfter(){return(this.delInfo&(an|on))>0}get deletedAcross(){return(this.delInfo&on)>0}},ln=class e{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&e.empty)return e.empty}recover(e){let t=0,n=tn(e);if(!this.inverted)for(let e=0;e<n;e++)t+=this.ranges[e*3+2]-this.ranges[e*3+1];return this.ranges[n*3]+t+nn(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,n){let r=0,i=this.inverted?2:1,a=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let s=this.ranges[o]-(this.inverted?r:0);if(s>e)break;let c=this.ranges[o+i],l=this.ranges[o+a],u=s+c;if(e<=u){let i=c?e==s?-1:e==u?1:t:t,a=s+r+(i<0?0:l);if(n)return a;let d=e==(t<0?s:u)?null:en(o/3,e-s),f=e==s?an:e==u?rn:on;return(t<0?e!=s:e!=u)&&(f|=sn),new cn(a,f,d)}r+=l-c}return n?e+r:new cn(e+r,0,null)}touches(e,t){let n=0,r=tn(t),i=this.inverted?2:1,a=this.inverted?1:2;for(let t=0;t<this.ranges.length;t+=3){let o=this.ranges[t]-(this.inverted?n:0);if(o>e)break;let s=this.ranges[t+i];if(e<=o+s&&t==r*3)return!0;n+=this.ranges[t+a]-s}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r<this.ranges.length;r+=3){let a=this.ranges[r],o=a-(this.inverted?i:0),s=a+(this.inverted?0:i),c=this.ranges[r+t],l=this.ranges[r+n];e(o,o+c,s,s+l),i+=l-c}}invert(){return new e(this.ranges,!this.inverted)}toString(){return(this.inverted?`-`:``)+JSON.stringify(this.ranges)}static offset(t){return t==0?e.empty:new e(t<0?[0,-t,0]:[0,0,t])}};ln.empty=new ln([]);var un=class e{constructor(e,t,n=0,r=e?e.length:0){this.mirror=t,this.from=n,this.to=r,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(t=0,n=this.maps.length){return new e(this._maps,this.mirror,t,n)}appendMap(e,t){this.ownData||=(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),!0),this.to=this._maps.push(e),t!=null&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,n=this._maps.length;t<e._maps.length;t++){let r=e.getMirror(t);this.appendMap(e._maps[t],r!=null&&r<t?n+r:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||=[],this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,n=this._maps.length+e._maps.length;t>=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),r!=null&&r>t?n-r-1:void 0)}}invert(){let t=new e;return t.appendMappingInverted(this),t}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;n<this.to;n++)e=this._maps[n].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,n){let r=0;for(let n=this.from;n<this.to;n++){let i=this._maps[n].mapResult(e,t);if(i.recover!=null){let t=this.getMirror(n);if(t!=null&&t>n&&t<this.to){n=t,e=this._maps[t].recover(i.recover);continue}}r|=i.delInfo,e=i.pos}return n?e:new cn(e,r,null)}},dn=Object.create(null),fn=class{getMap(){return ln.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw RangeError(`Invalid input for Step.fromJSON`);let n=dn[t.stepType];if(!n)throw RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in dn)throw RangeError(`Duplicate use of step JSON ID `+e);return dn[e]=t,t.prototype.jsonID=e,t}},pn=class e{constructor(e,t){this.doc=e,this.failed=t}static ok(t){return new e(t,null)}static fail(t){return new e(null,t)}static fromReplace(t,n,r,i){try{return e.ok(t.replace(n,r,i))}catch(t){if(t instanceof Le)return e.fail(t.message);throw t}}};function mn(e,t,n){let r=[];for(let i=0;i<e.childCount;i++){let a=e.child(i);a.content.size&&(a=a.copy(mn(a.content,t,a))),a.isInline&&(a=t(a,n,i)),r.push(a)}return E.fromArray(r)}var hn=class e extends fn{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=e.resolve(this.from),r=n.node(n.sharedDepth(this.to)),i=new D(mn(t.content,(e,t)=>!e.isAtom||!t.type.allowsMarkType(this.mark.type)?e:e.mark(this.mark.addToSet(e.marks)),r),t.openStart,t.openEnd);return pn.fromReplace(e,this.from,this.to,i)}invert(){return new gn(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`addMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for AddMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};fn.jsonID(`addMark`,hn);var gn=class e extends fn{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new D(mn(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return pn.fromReplace(e,this.from,this.to,n)}invert(){return new hn(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`removeMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for RemoveMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};fn.jsonID(`removeMark`,gn);var _n=class e extends fn{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return pn.fail(`No node at mark step's position`);let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return pn.fromReplace(e,this.pos,this.pos+1,new D(E.from(n),0,t.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);if(n){let t=this.mark.addToSet(n.marks);if(t.length==n.marks.length){for(let r=0;r<n.marks.length;r++)if(!n.marks[r].isInSet(t))return new e(this.pos,n.marks[r]);return new e(this.pos,this.mark)}}return new vn(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.mark)}toJSON(){return{stepType:`addNodeMark`,pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for AddNodeMarkStep.fromJSON`);return new e(n.pos,t.markFromJSON(n.mark))}};fn.jsonID(`addNodeMark`,_n);var vn=class e extends fn{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return pn.fail(`No node at mark step's position`);let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return pn.fromReplace(e,this.pos,this.pos+1,new D(E.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new _n(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.mark)}toJSON(){return{stepType:`removeNodeMark`,pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for RemoveNodeMarkStep.fromJSON`);return new e(n.pos,t.markFromJSON(n.mark))}};fn.jsonID(`removeNodeMark`,vn);var yn=class e extends fn{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&xn(e,this.from,this.to)?pn.fail(`Structure replace would overwrite content`):pn.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new ln([this.from,this.to-this.from,this.slice.size])}invert(t){return new e(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deletedAcross&&r.deletedAcross?null:new e(n.pos,Math.max(n.pos,r.pos),this.slice,this.structure)}merge(t){if(!(t instanceof e)||t.structure||this.structure)return null;if(this.from+this.slice.size==t.from&&!this.slice.openEnd&&!t.slice.openStart){let n=this.slice.size+t.slice.size==0?D.empty:new D(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new e(this.from,this.to+(t.to-t.from),n,this.structure)}else if(t.to==this.from&&!this.slice.openStart&&!t.slice.openEnd){let n=this.slice.size+t.slice.size==0?D.empty:new D(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new e(t.from,this.to,n,this.structure)}else return null}toJSON(){let e={stepType:`replace`,from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for ReplaceStep.fromJSON`);return new e(n.from,n.to,D.fromJSON(t,n.slice),!!n.structure)}};fn.jsonID(`replace`,yn);var bn=class e extends fn{constructor(e,t,n,r,i,a,o=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=i,this.insert=a,this.structure=o}apply(e){if(this.structure&&(xn(e,this.from,this.gapFrom)||xn(e,this.gapTo,this.to)))return pn.fail(`Structure gap-replace would overwrite content`);let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return pn.fail(`Gap is not a flat range`);let n=this.slice.insertAt(this.insert,t.content);return n?pn.fromReplace(e,this.from,this.to,n):pn.fail(`Content does not fit in gap`)}getMap(){return new ln([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let n=this.gapTo-this.gapFrom;return new e(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),i=this.from==this.gapFrom?n.pos:t.map(this.gapFrom,-1),a=this.to==this.gapTo?r.pos:t.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||i<n.pos||a>r.pos?null:new e(n.pos,r.pos,i,a,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:`replaceAround`,from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`||typeof n.gapFrom!=`number`||typeof n.gapTo!=`number`||typeof n.insert!=`number`)throw RangeError(`Invalid input for ReplaceAroundStep.fromJSON`);return new e(n.from,n.to,n.gapFrom,n.gapTo,D.fromJSON(t,n.slice),n.insert,!!n.structure)}};fn.jsonID(`replaceAround`,bn);function xn(e,t,n){let r=e.resolve(t),i=n-t,a=r.depth;for(;i>0&&a>0&&r.indexAfter(a)==r.node(a).childCount;)a--,i--;if(i>0){let e=r.node(a).maybeChild(r.indexAfter(a));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}function Sn(e,t,n,r){let i=[],a=[],o,s;e.doc.nodesBetween(t,n,(e,c,l)=>{if(!e.isInline)return;let u=e.marks;if(!r.isInSet(u)&&l.type.allowsMarkType(r.type)){let l=Math.max(c,t),d=Math.min(c+e.nodeSize,n),f=r.addToSet(u);for(let e=0;e<u.length;e++)u[e].isInSet(f)||(o&&o.to==l&&o.mark.eq(u[e])?o.to=d:i.push(o=new gn(l,d,u[e])));s&&s.to==l?s.to=d:a.push(s=new hn(l,d,r))}}),i.forEach(t=>e.step(t)),a.forEach(t=>e.step(t))}function Cn(e,t,n,r){let i=[],a=0;e.doc.nodesBetween(t,n,(e,o)=>{if(!e.isInline)return;a++;let s=null;if(r instanceof Et){let t=e.marks,n;for(;n=r.isInSet(t);)(s||=[]).push(n),t=n.removeFromSet(t)}else r?r.isInSet(e.marks)&&(s=[r]):s=e.marks;if(s&&s.length){let r=Math.min(o+e.nodeSize,n);for(let e=0;e<s.length;e++){let n=s[e],c;for(let e=0;e<i.length;e++){let t=i[e];t.step==a-1&&n.eq(i[e].style)&&(c=t)}c?(c.to=r,c.step=a):i.push({style:n,from:Math.max(o,t),to:r,step:a})}}}),i.forEach(t=>e.step(new gn(t.from,t.to,t.style)))}function wn(e,t,n,r=n.contentMatch,i=!0){let a=e.doc.nodeAt(t),o=[],s=t+1;for(let t=0;t<a.childCount;t++){let c=a.child(t),l=s+c.nodeSize,u=r.matchType(c.type);if(!u)o.push(new yn(s,l,D.empty));else{r=u;for(let t=0;t<c.marks.length;t++)n.allowsMarkType(c.marks[t].type)||e.step(new gn(s,l,c.marks[t]));if(i&&c.isText&&n.whitespace!=`pre`){let e,t=/\r?\n|\r/g,r;for(;e=t.exec(c.text);)r||=new D(E.from(n.schema.text(` `,n.allowedMarks(c.marks))),0,0),o.push(new yn(s+e.index,s+e.index+e[0].length,r))}}s=l}if(!r.validEnd){let t=r.fillBefore(E.empty,!0);e.replace(s,s,new D(t,0,0))}for(let t=o.length-1;t>=0;t--)e.step(o[t])}function Tn(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function En(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth,r=0,i=0;;--n){let a=e.$from.node(n),o=e.$from.index(n)+r,s=e.$to.indexAfter(n)-i;if(n<e.depth&&a.canReplace(o,s,t))return n;if(n==0||a.type.spec.isolating||!Tn(a,o,s))break;o&&(r=1),s<a.childCount&&(i=1)}return null}function Dn(e,t,n){let{$from:r,$to:i,depth:a}=t,o=r.before(a+1),s=i.after(a+1),c=o,l=s,u=E.empty,d=0;for(let e=a,t=!1;e>n;e--)t||r.index(e)>0?(t=!0,u=E.from(r.node(e).copy(u)),d++):c--;let f=E.empty,p=0;for(let e=a,t=!1;e>n;e--)t||i.after(e+1)<i.end(e)?(t=!0,f=E.from(i.node(e).copy(f)),p++):l++;e.step(new bn(c,l,o,s,new D(u.append(f),d,p),u.size-d,!0))}function On(e,t,n=null,r=e){let i=An(e,t),a=i&&jn(r,t);return a?i.map(kn).concat({type:t,attrs:n}).concat(a.map(kn)):null}function kn(e){return{type:e,attrs:null}}function An(e,t){let{parent:n,startIndex:r,endIndex:i}=e,a=n.contentMatchAt(r).findWrapping(t);if(!a)return null;let o=a.length?a[0]:t;return n.canReplaceWith(r,i,o)?a:null}function jn(e,t){let{parent:n,startIndex:r,endIndex:i}=e,a=n.child(r),o=t.contentMatch.findWrapping(a.type);if(!o)return null;let s=(o.length?o[o.length-1]:t).contentMatch;for(let e=r;s&&e<i;e++)s=s.matchType(n.child(e).type);return!s||!s.validEnd?null:o}function Mn(e,t,n){let r=E.empty;for(let e=n.length-1;e>=0;e--){if(r.size){let t=n[e].type.contentMatch.matchFragment(r);if(!t||!t.validEnd)throw RangeError(`Wrapper type given to Transform.wrap does not form valid content of its parent wrapper`)}r=E.from(n[e].type.create(n[e].attrs,r))}let i=t.start,a=t.end;e.step(new bn(i,a,i,a,new D(r,0,0),n.length,!0))}function Nn(e,t,n,r,i){if(!r.isTextblock)throw RangeError(`Type given to setBlockType should be a textblock`);let a=e.steps.length;e.doc.nodesBetween(t,n,(t,n)=>{let o=typeof i==`function`?i(t):i;if(t.isTextblock&&!t.hasMarkup(r,o)&&In(e.doc,e.mapping.slice(a).map(n),r)){let i=null;if(r.schema.linebreakReplacement){let e=r.whitespace==`pre`,t=!!r.contentMatch.matchType(r.schema.linebreakReplacement);e&&!t?i=!1:!e&&t&&(i=!0)}i===!1&&Fn(e,t,n,a),wn(e,e.mapping.slice(a).map(n,1),r,void 0,i===null);let s=e.mapping.slice(a),c=s.map(n,1),l=s.map(n+t.nodeSize,1);return e.step(new bn(c,l,c+1,l-1,new D(E.from(r.create(o,null,t.marks)),0,0),1,!0)),i===!0&&Pn(e,t,n,a),!1}})}function Pn(e,t,n,r){t.forEach((i,a)=>{if(i.isText){let o,s=/\r?\n|\r/g;for(;o=s.exec(i.text);){let i=e.mapping.slice(r).map(n+1+a+o.index);e.replaceWith(i,i+1,t.type.schema.linebreakReplacement.create())}}})}function Fn(e,t,n,r){t.forEach((i,a)=>{if(i.type==i.type.schema.linebreakReplacement){let i=e.mapping.slice(r).map(n+1+a);e.replaceWith(i,i+1,t.type.schema.text(`
49
- `))}})}function In(e,t,n){let r=e.resolve(t),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function Ln(e,t,n,r,i){let a=e.doc.nodeAt(t);if(!a)throw RangeError(`No node at given position`);n||=a.type;let o=n.create(r,null,i||a.marks);if(a.isLeaf)return e.replaceWith(t,t+a.nodeSize,o);if(!n.validContent(a.content))throw RangeError(`Invalid content for node type `+n.name);e.step(new bn(t,t+a.nodeSize,t+1,t+a.nodeSize-1,new D(E.from(o),0,0),1,!0))}function Rn(e,t,n=1,r){let i=e.resolve(t),a=i.depth-n,o=r&&r[r.length-1]||i.parent;if(a<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let e=i.depth-1,t=n-2;e>a;e--,t--){let n=i.node(e),a=i.index(e);if(n.type.spec.isolating)return!1;let o=n.content.cutByIndex(a,n.childCount),s=r&&r[t+1];s&&(o=o.replaceChild(0,s.type.create(s.attrs)));let c=r&&r[t]||n;if(!n.canReplace(a+1,n.childCount)||!c.type.validContent(o))return!1}let s=i.indexAfter(a),c=r&&r[0];return i.node(a).canReplaceWith(s,s,c?c.type:i.node(a+1).type)}function zn(e,t,n=1,r){let i=e.doc.resolve(t),a=E.empty,o=E.empty;for(let e=i.depth,t=i.depth-n,s=n-1;e>t;e--,s--){a=E.from(i.node(e).copy(a));let t=r&&r[s];o=E.from(t?t.type.create(t.attrs,o):i.node(e).copy(o))}e.step(new yn(t,t,new D(a.append(o),n,n),!0))}function Bn(e,t){let n=e.resolve(t),r=n.index();return Hn(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Vn(e,t){t.content.size||e.type.compatibleContent(t.type);let n=e.contentMatchAt(e.childCount),{linebreakReplacement:r}=e.type.schema;for(let i=0;i<t.childCount;i++){let a=t.child(i),o=a.type==r?e.type.schema.nodes.text:a.type;if(n=n.matchType(o),!n||!e.type.allowsMarks(a.marks))return!1}return n.validEnd}function Hn(e,t){return!!(e&&t&&!e.isLeaf&&Vn(e,t))}function Un(e,t,n=-1){let r=e.resolve(t);for(let e=r.depth;;e--){let i,a,o=r.index(e);if(e==r.depth?(i=r.nodeBefore,a=r.nodeAfter):n>0?(i=r.node(e+1),o++,a=r.node(e).maybeChild(o)):(i=r.node(e).maybeChild(o-1),a=r.node(e+1)),i&&!i.isTextblock&&Hn(i,a)&&r.node(e).canReplace(o,o+1))return t;if(e==0)break;t=n<0?r.before(e):r.after(e)}}function Wn(e,t,n){let r=null,{linebreakReplacement:i}=e.doc.type.schema,a=e.doc.resolve(t-n),o=a.node().type;if(i&&o.inlineContent){let e=o.whitespace==`pre`,t=!!o.contentMatch.matchType(i);e&&!t?r=!1:!e&&t&&(r=!0)}let s=e.steps.length;if(r===!1){let r=e.doc.resolve(t+n);Fn(e,r.node(),r.before(),s)}o.inlineContent&&wn(e,t+n-1,o,a.node().contentMatchAt(a.index()),r==null);let c=e.mapping.slice(s),l=c.map(t-n);if(e.step(new yn(l,c.map(t+n,-1),D.empty,!0)),r===!0){let t=e.doc.resolve(l);Pn(e,t.node(),t.before(),e.steps.length)}return e}function Gn(e,t,n){let r=e.resolve(t);if(r.parent.canReplaceWith(r.index(),r.index(),n))return t;if(r.parentOffset==0)for(let e=r.depth-1;e>=0;e--){let t=r.index(e);if(r.node(e).canReplaceWith(t,t,n))return r.before(e+1);if(t>0)return null}if(r.parentOffset==r.parent.content.size)for(let e=r.depth-1;e>=0;e--){let t=r.indexAfter(e);if(r.node(e).canReplaceWith(t,t,n))return r.after(e+1);if(t<r.node(e).childCount)return null}return null}function Kn(e,t,n){let r=e.resolve(t);if(!n.content.size)return t;let i=n.content;for(let e=0;e<n.openStart;e++)i=i.firstChild.content;for(let e=1;e<=(n.openStart==0&&n.size?2:1);e++)for(let t=r.depth;t>=0;t--){let n=t==r.depth?0:r.pos<=(r.start(t+1)+r.end(t+1))/2?-1:1,a=r.index(t)+(n>0?1:0),o=r.node(t),s=!1;if(e==1)s=o.canReplace(a,a,i);else{let e=o.contentMatchAt(a).findWrapping(i.firstChild.type);s=e&&o.canReplaceWith(a,a,e[0])}if(s)return n==0?r.pos:n<0?r.before(t+1):r.after(t+1)}return null}function qn(e,t,n=t,r=D.empty){if(t==n&&!r.size)return null;let i=e.resolve(t),a=e.resolve(n);return Jn(i,a,r)?new yn(t,n,r):new Yn(i,a,r).fit()}function Jn(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}var Yn=class{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=E.empty;for(let t=0;t<=e.depth;t++){let n=e.node(t);this.frontier.push({type:n.type,match:n.contentMatchAt(e.indexAfter(t))})}for(let t=e.depth;t>0;t--)this.placed=E.from(e.node(t).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let e=this.findFittable();e?this.placeNodes(e):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,r=this.close(e<0?this.$to:n.doc.resolve(e));if(!r)return null;let i=this.placed,a=n.depth,o=r.depth;for(;a&&o&&i.childCount==1;)i=i.firstChild.content,a--,o--;let s=new D(i,a,o);return e>-1?new bn(n.pos,e,this.$to.pos,this.$to.end(),s,t):s.size||n.pos!=this.$to.pos?new yn(n.pos,r.pos,s):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,r=this.unplaced.openEnd;n<e;n++){let i=t.firstChild;if(t.childCount>1&&(r=0),i.type.spec.isolating&&r<=n){e=n;break}t=i.content}for(let t=1;t<=2;t++)for(let n=t==1?e:this.unplaced.openStart;n>=0;n--){let e,r=null;n?(r=Qn(this.unplaced.content,n-1).firstChild,e=r.content):e=this.unplaced.content;let i=e.firstChild;for(let e=this.depth;e>=0;e--){let{type:a,match:o}=this.frontier[e],s,c=null;if(t==1&&(i?o.matchType(i.type)||(c=o.fillBefore(E.from(i),!1)):r&&a.compatibleContent(r.type)))return{sliceDepth:n,frontierDepth:e,parent:r,inject:c};if(t==2&&i&&(s=o.findWrapping(i.type)))return{sliceDepth:n,frontierDepth:e,parent:r,wrap:s};if(r&&o.matchType(r.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=Qn(e,t);return!r.childCount||r.firstChild.isLeaf?!1:(this.unplaced=new D(e,t+1,Math.max(n,r.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=Qn(e,t);if(r.childCount<=1&&t>0){let i=e.size-t<=t+r.size;this.unplaced=new D(Xn(e,t-1,1),t-1,i?t-1:n)}else this.unplaced=new D(Xn(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:r,wrap:i}){for(;this.depth>t;)this.closeFrontierNode();if(i)for(let e=0;e<i.length;e++)this.openFrontierNode(i[e]);let a=this.unplaced,o=n?n.content:a.content,s=a.openStart-e,c=0,l=[],{match:u,type:d}=this.frontier[t];if(r){for(let e=0;e<r.childCount;e++)l.push(r.child(e));u=u.matchFragment(r)}let f=o.size+e-(a.content.size-a.openEnd);for(;c<o.childCount;){let e=o.child(c),t=u.matchType(e.type);if(!t)break;c++,(c>1||s==0||e.content.size)&&(u=t,l.push($n(e.mark(d.allowedMarks(e.marks)),c==1?s:0,c==o.childCount?f:-1)))}let p=c==o.childCount;p||(f=-1),this.placed=Zn(this.placed,t,E.from(l)),this.frontier[t].match=u,p&&f<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let e=0,t=o;e<f;e++){let e=t.lastChild;this.frontier.push({type:e.type,match:e.contentMatchAt(e.childCount)}),t=e.content}this.unplaced=p?e==0?D.empty:new D(Xn(a.content,e-1,1),e-1,f<0?a.openEnd:e-1):new D(Xn(a.content,e,c),a.openStart,a.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!er(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:n}=this.$to,r=this.$to.after(n);for(;n>1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(e){scan:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:r}=this.frontier[t],i=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),a=er(e,t,r,n,i);if(a){for(let n=t-1;n>=0;n--){let{match:t,type:r}=this.frontier[n],i=er(e,n,r,t,!0);if(!i||i.childCount)continue scan}return{depth:t,fit:a,move:i?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Zn(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),r=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,r)}return e}openFrontierNode(e,t=null,n){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=Zn(this.placed,this.depth,E.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(E.empty,!0);e.childCount&&(this.placed=Zn(this.placed,this.frontier.length,e))}};function Xn(e,t,n){return t==0?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(Xn(e.firstChild.content,t-1,n)))}function Zn(e,t,n){return t==0?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(Zn(e.lastChild.content,t-1,n)))}function Qn(e,t){for(let n=0;n<t;n++)e=e.firstChild.content;return e}function $n(e,t,n){if(t<=0)return e;let r=e.content;return t>1&&(r=r.replaceChild(0,$n(r.firstChild,t-1,r.childCount==1?n-1:0))),t>0&&(r=e.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(e.type.contentMatch.matchFragment(r).fillBefore(E.empty,!0)))),e.copy(r)}function er(e,t,n,r,i){let a=e.node(t),o=i?e.indexAfter(t):e.index(t);if(o==a.childCount&&!n.compatibleContent(a.type))return null;let s=r.fillBefore(a.content,!0,o);return s&&!tr(n,a.content,o)?s:null}function tr(e,t,n){for(let r=n;r<t.childCount;r++)if(!e.allowsMarks(t.child(r).marks))return!0;return!1}function nr(e){return e.spec.defining||e.spec.definingForContent}function rr(e,t,n,r){if(!r.size)return e.deleteRange(t,n);let i=e.doc.resolve(t),a=e.doc.resolve(n);if(Jn(i,a,r))return e.step(new yn(t,n,r));let o=sr(i,a);o[o.length-1]==0&&o.pop();let s=-(i.depth+1);o.unshift(s);for(let e=i.depth,t=i.pos-1;e>0;e--,t--){let n=i.node(e).type.spec;if(n.defining||n.definingAsContext||n.isolating)break;o.indexOf(e)>-1?s=e:i.before(e)==t&&o.splice(1,0,-e)}let c=o.indexOf(s),l=[],u=r.openStart;for(let e=r.content,t=0;;t++){let n=e.firstChild;if(l.push(n),t==r.openStart)break;e=n.content}for(let e=u-1;e>=0;e--){let t=l[e],n=nr(t.type);if(n&&!t.sameMarkup(i.node(Math.abs(s)-1)))u=e;else if(n||!t.type.isTextblock)break}for(let t=r.openStart;t>=0;t--){let s=(t+u+1)%(r.openStart+1),d=l[s];if(d)for(let t=0;t<o.length;t++){let l=o[(t+c)%o.length],u=!0;l<0&&(u=!1,l=-l);let f=i.node(l-1),p=i.index(l-1);if(f.canReplaceWith(p,p,d.type,d.marks))return e.replace(i.before(l),u?a.after(l):n,new D(ir(r.content,0,r.openStart,s),s,r.openEnd))}}let d=e.steps.length;for(let s=o.length-1;s>=0&&(e.replace(t,n,r),!(e.steps.length>d));s--){let e=o[s];e<0||(t=i.before(e),n=a.after(e))}}function ir(e,t,n,r,i){if(t<n){let i=e.firstChild;e=e.replaceChild(0,i.copy(ir(i.content,t+1,n,r,i)))}if(t>r){let t=i.contentMatchAt(0),n=t.fillBefore(e).append(e);e=n.append(t.matchFragment(n).fillBefore(E.empty,!0))}return e}function ar(e,t,n,r){if(!r.isInline&&t==n&&e.doc.resolve(t).parent.content.size){let i=Gn(e.doc,t,r.type);i!=null&&(t=n=i)}e.replaceRange(t,n,new D(E.from(r),0,0))}function or(e,t,n){let r=e.doc.resolve(t),i=e.doc.resolve(n),a=sr(r,i);for(let t=0;t<a.length;t++){let n=a[t],o=t==a.length-1;if(o&&n==0||r.node(n).type.contentMatch.validEnd)return e.delete(r.start(n),i.end(n));if(n>0&&(o||r.node(n-1).canReplace(r.index(n-1),i.indexAfter(n-1))))return e.delete(r.before(n),i.after(n))}for(let a=1;a<=r.depth&&a<=i.depth;a++)if(t-r.start(a)==r.depth-a&&n>r.end(a)&&i.end(a)-n!=i.depth-a&&r.start(a-1)==i.start(a-1)&&r.node(a-1).canReplace(r.index(a-1),i.index(a-1)))return e.delete(r.before(a),n);e.delete(t,n)}function sr(e,t){let n=[],r=Math.min(e.depth,t.depth);for(let i=r;i>=0;i--){let r=e.start(i);if(r<e.pos-(e.depth-i)||t.end(i)>t.pos+(t.depth-i)||e.node(i).type.spec.isolating||t.node(i).type.spec.isolating)break;(r==t.start(i)||i==e.depth&&i==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&i&&t.start(i-1)==r-1)&&n.push(i)}return n}var cr=class e extends fn{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return pn.fail(`No node at attribute step's position`);let n=Object.create(null);for(let e in t.attrs)n[e]=t.attrs[e];n[this.attr]=this.value;let r=t.type.create(n,null,t.marks);return pn.fromReplace(e,this.pos,this.pos+1,new D(E.from(r),0,t.isLeaf?0:1))}getMap(){return ln.empty}invert(t){return new e(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.attr,this.value)}toJSON(){return{stepType:`attr`,pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.pos!=`number`||typeof n.attr!=`string`)throw RangeError(`Invalid input for AttrStep.fromJSON`);return new e(n.pos,n.attr,n.value)}};fn.jsonID(`attr`,cr);var lr=class e extends fn{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let n in e.attrs)t[n]=e.attrs[n];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return pn.ok(n)}getMap(){return ln.empty}invert(t){return new e(this.attr,t.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:`docAttr`,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.attr!=`string`)throw RangeError(`Invalid input for DocAttrStep.fromJSON`);return new e(n.attr,n.value)}};fn.jsonID(`docAttr`,lr);var ur=class extends Error{};ur=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},ur.prototype=Object.create(Error.prototype),ur.prototype.constructor=ur,ur.prototype.name=`TransformError`;var dr=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new un}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new ur(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let n=0;n<this.mapping.maps.length;n++){let r=this.mapping.maps[n];n&&(e=r.map(e,1),t=r.map(t,-1)),r.forEach((n,r,i,a)=>{e=Math.min(e,i),t=Math.max(t,a)})}return e==1e9?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=D.empty){let r=qn(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new D(E.from(n),0,0))}delete(e,t){return this.replace(e,t,D.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return rr(this,e,t,n),this}replaceRangeWith(e,t,n){return ar(this,e,t,n),this}deleteRange(e,t){return or(this,e,t),this}lift(e,t){return Dn(this,e,t),this}join(e,t=1){return Wn(this,e,t),this}wrap(e,t){return Mn(this,e,t),this}setBlockType(e,t=e,n,r=null){return Nn(this,e,t,n,r),this}setNodeMarkup(e,t,n=null,r){return Ln(this,e,t,n,r),this}setNodeAttribute(e,t,n){return this.step(new cr(e,t,n)),this}setDocAttribute(e,t){return this.step(new lr(e,t)),this}addNodeMark(e,t){return this.step(new _n(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw RangeError(`No node at position `+e);if(t instanceof Ie)t.isInSet(n.marks)&&this.step(new vn(e,t));else{let r=n.marks,i,a=[];for(;i=t.isInSet(r);)a.push(new vn(e,i)),r=i.removeFromSet(r);for(let e=a.length-1;e>=0;e--)this.step(a[e])}return this}split(e,t=1,n){return zn(this,e,t,n),this}addMark(e,t,n){return Sn(this,e,t,n),this}removeMark(e,t,n){return Cn(this,e,t,n),this}clearIncompatible(e,t,n){return wn(this,e,t,n),this}},fr=Object.create(null),O=class{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new pr(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=D.empty){let n=t.content.lastChild,r=null;for(let e=0;e<t.openEnd;e++)r=n,n=n.lastChild;let i=e.steps.length,a=this.ranges;for(let o=0;o<a.length;o++){let{$from:s,$to:c}=a[o],l=e.mapping.slice(i);e.replaceRange(l.map(s.pos),l.map(c.pos),o?D.empty:t),o==0&&xr(e,i,(n?n.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,r=this.ranges;for(let i=0;i<r.length;i++){let{$from:a,$to:o}=r[i],s=e.mapping.slice(n),c=s.map(a.pos),l=s.map(o.pos);i?e.deleteRange(c,l):(e.replaceRangeWith(c,l,t),xr(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let r=e.parent.inlineContent?new k(e):br(e.node(0),e.parent,e.pos,e.index(),t,n);if(r)return r;for(let r=e.depth-1;r>=0;r--){let i=t<0?br(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):br(e.node(0),e.node(r),e.after(r+1),e.index(r)+1,t,n);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new vr(e.node(0))}static atStart(e){return br(e,e,0,0,1)||new vr(e)}static atEnd(e){return br(e,e,e.content.size,e.childCount,-1)||new vr(e)}static fromJSON(e,t){if(!t||!t.type)throw RangeError(`Invalid input for Selection.fromJSON`);let n=fr[t.type];if(!n)throw RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in fr)throw RangeError(`Duplicate use of selection JSON ID `+e);return fr[e]=t,t.prototype.jsonID=e,t}getBookmark(){return k.between(this.$anchor,this.$head).getBookmark()}};O.prototype.visible=!0;var pr=class{constructor(e,t){this.$from=e,this.$to=t}},mr=!1;function hr(e){!mr&&!e.parent.inlineContent&&(mr=!0,console.warn(`TextSelection endpoint not pointing into a node with inline content (`+e.parent.type.name+`)`))}var k=class e extends O{constructor(e,t=e){hr(e),hr(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return O.near(r);let i=t.resolve(n.map(this.anchor));return new e(i.parent.inlineContent?i:r,r)}replace(e,t=D.empty){if(super.replace(e,t),t==D.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(t){return t instanceof e&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new gr(this.anchor,this.head)}toJSON(){return{type:`text`,anchor:this.anchor,head:this.head}}static fromJSON(t,n){if(typeof n.anchor!=`number`||typeof n.head!=`number`)throw RangeError(`Invalid input for TextSelection.fromJSON`);return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(t,n,r){let i=t.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let e=O.findFrom(n,r,!0)||O.findFrom(n,-r,!0);if(e)n=e.$head;else return O.near(n,r)}return t.parent.inlineContent||(i==0?t=n:(t=(O.findFrom(t,-r,!0)||O.findFrom(t,r,!0)).$anchor,t.pos<n.pos!=i<0&&(t=n))),new e(t,n)}};O.jsonID(`text`,k);var gr=class e{constructor(e,t){this.anchor=e,this.head=t}map(t){return new e(t.map(this.anchor),t.map(this.head))}resolve(e){return k.between(e.resolve(this.anchor),e.resolve(this.head))}},A=class e extends O{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(t,n){let{deleted:r,pos:i}=n.mapResult(this.anchor),a=t.resolve(i);return r?O.near(a):new e(a)}content(){return new D(E.from(this.node),0,0)}eq(t){return t instanceof e&&t.anchor==this.anchor}toJSON(){return{type:`node`,anchor:this.anchor}}getBookmark(){return new _r(this.anchor)}static fromJSON(t,n){if(typeof n.anchor!=`number`)throw RangeError(`Invalid input for NodeSelection.fromJSON`);return new e(t.resolve(n.anchor))}static create(t,n){return new e(t.resolve(n))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}};A.prototype.visible=!1,O.jsonID(`node`,A);var _r=class e{constructor(e){this.anchor=e}map(t){let{deleted:n,pos:r}=t.mapResult(this.anchor);return n?new gr(r,r):new e(r)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&A.isSelectable(n)?new A(t):O.near(t)}},vr=class e extends O{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=D.empty){if(t==D.empty){e.delete(0,e.doc.content.size);let t=O.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:`all`}}static fromJSON(t){return new e(t)}map(t){return new e(t)}eq(t){return t instanceof e}getBookmark(){return yr}};O.jsonID(`all`,vr);var yr={map(){return this},resolve(e){return new vr(e)}};function br(e,t,n,r,i,a=!1){if(t.inlineContent)return k.create(e,n);for(let o=r-(i>0?0:1);i>0?o<t.childCount:o>=0;o+=i){let r=t.child(o);if(!r.isAtom){let t=br(e,r,n+i,i<0?r.childCount:0,i,a);if(t)return t}else if(!a&&A.isSelectable(r))return A.create(e,n-(i<0?r.nodeSize:0));n+=r.nodeSize*i}return null}function xr(e,t,n){let r=e.steps.length-1;if(r<t)return;let i=e.steps[r];if(!(i instanceof yn||i instanceof bn))return;let a=e.mapping.maps[r],o;a.forEach((e,t,n,r)=>{o??=r}),e.setSelection(O.near(e.doc.resolve(o),n))}var Sr=1,Cr=2,wr=4,Tr=class extends dr{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw RangeError(`Selection passed to setSelection must point at the current document`);return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|Sr)&~Cr,this.storedMarks=null,this}get selectionSet(){return(this.updated&Sr)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Cr,this}ensureMarks(e){return Ie.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Cr)>0}addStep(e,t){super.addStep(e,t),this.updated&=~Cr,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||Ie.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let r=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(n??=t,!e)return this.deleteRange(t,n);let i=this.storedMarks;if(!i){let e=this.doc.resolve(t);i=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,r.text(e,i)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection(O.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e==`string`?e:e.key]=t,this}getMeta(e){return this.meta[typeof e==`string`?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=wr,this}get scrolledIntoView(){return(this.updated&wr)>0}};function Er(e,t){return!t||!e?e:e.bind(t)}var Dr=class{constructor(e,t,n){this.name=e,this.init=Er(t.init,n),this.apply=Er(t.apply,n)}},Or=[new Dr(`doc`,{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new Dr(`selection`,{init(e,t){return e.selection||O.atStart(t.doc)},apply(e){return e.selection}}),new Dr(`storedMarks`,{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new Dr(`scrollToSelection`,{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}})],kr=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Or.slice(),t&&t.forEach(e=>{if(this.pluginsByKey[e.key])throw RangeError(`Adding different instances of a keyed plugin (`+e.key+`)`);this.plugins.push(e),this.pluginsByKey[e.key]=e,e.spec.state&&this.fields.push(new Dr(e.key,e.spec.state,e))})}},Ar=class e{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;n<this.config.plugins.length;n++)if(n!=t){let t=this.config.plugins[n];if(t.spec.filterTransaction&&!t.spec.filterTransaction.call(t,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),r=null;for(;;){let i=!1;for(let a=0;a<this.config.plugins.length;a++){let o=this.config.plugins[a];if(o.spec.appendTransaction){let s=r?r[a].n:0,c=r?r[a].state:this,l=s<t.length&&o.spec.appendTransaction.call(o,s?t.slice(s):t,c,n);if(l&&n.filterTransaction(l,a)){if(l.setMeta(`appendedTransaction`,e),!r){r=[];for(let e=0;e<this.config.plugins.length;e++)r.push(e<a?{state:n,n:t.length}:{state:this,n:0})}t.push(l),n=n.applyInner(l),i=!0}r&&(r[a]={state:n,n:t.length})}}if(!i)return{state:n,transactions:t}}}applyInner(t){if(!t.before.eq(this.doc))throw RangeError(`Applying a mismatched transaction`);let n=new e(this.config),r=this.config.fields;for(let e=0;e<r.length;e++){let i=r[e];n[i.name]=i.apply(t,this[i.name],this,n)}return n}get tr(){return new Tr(this)}static create(t){let n=new kr(t.doc?t.doc.type.schema:t.schema,t.plugins),r=new e(n);for(let e=0;e<n.fields.length;e++)r[n.fields[e].name]=n.fields[e].init(t,r);return r}reconfigure(t){let n=new kr(this.schema,t.plugins),r=n.fields,i=new e(n);for(let e=0;e<r.length;e++){let n=r[e].name;i[n]=this.hasOwnProperty(n)?this[n]:r[e].init(t,i)}return i}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(e=>e.toJSON())),e&&typeof e==`object`)for(let n in e){if(n==`doc`||n==`selection`)throw RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[n],i=r.spec.state;i&&i.toJSON&&(t[n]=i.toJSON.call(r,this[r.key]))}return t}static fromJSON(t,n,r){if(!n)throw RangeError(`Invalid input for EditorState.fromJSON`);if(!t.schema)throw RangeError(`Required config field 'schema' missing`);let i=new kr(t.schema,t.plugins),a=new e(i);return i.fields.forEach(e=>{if(e.name==`doc`)a.doc=nt.fromJSON(t.schema,n.doc);else if(e.name==`selection`)a.selection=O.fromJSON(a.doc,n.selection);else if(e.name==`storedMarks`)n.storedMarks&&(a.storedMarks=n.storedMarks.map(t.schema.markFromJSON));else{if(r)for(let i in r){let o=r[i],s=o.spec.state;if(o.key==e.name&&s&&s.fromJSON&&Object.prototype.hasOwnProperty.call(n,i)){a[e.name]=s.fromJSON.call(o,t,n[i],a);return}}a[e.name]=e.init(t,a)}}),a}};function jr(e,t,n){for(let r in e){let i=e[r];i instanceof Function?i=i.bind(t):r==`handleDOMEvents`&&(i=jr(i,t,{})),n[r]=i}return n}var Mr=class{constructor(e){this.spec=e,this.props={},e.props&&jr(e.props,this,this.props),this.key=e.key?e.key.key:Pr(`plugin`)}getState(e){return e[this.key]}},Nr=Object.create(null);function Pr(e){return e in Nr?e+`$`+ ++Nr[e]:(Nr[e]=0,e+`$`)}var Fr=class{constructor(e=`key`){this.key=Pr(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}},Ir=(e,t)=>e.selection.empty?!1:(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function Lr(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`backward`,e):n.parentOffset>0)?null:n}var Rr=(e,t,n)=>{let r=Lr(e,n);if(!r)return!1;let i=Wr(r);if(!i){let n=r.blockRange(),i=n&&En(n);return i==null?!1:(t&&t(e.tr.lift(n,i).scrollIntoView()),!0)}let a=i.nodeBefore;if(ci(e,i,t,-1))return!0;if(r.parent.content.size==0&&(Hr(a,`end`)||A.isSelectable(a)))for(let n=r.depth;;n--){let o=qn(e.doc,r.before(n),r.after(n),D.empty);if(o&&o.slice.size<o.to-o.from){if(t){let n=e.tr.step(o);n.setSelection(Hr(a,`end`)?O.findFrom(n.doc.resolve(n.mapping.map(i.pos,-1)),-1):A.create(n.doc,i.pos-a.nodeSize)),t(n.scrollIntoView())}return!0}if(n==1||r.node(n-1).childCount>1)break}return a.isAtom&&i.depth==r.depth-1?(t&&t(e.tr.delete(i.pos-a.nodeSize,i.pos).scrollIntoView()),!0):!1},zr=(e,t,n)=>{let r=Lr(e,n);if(!r)return!1;let i=Wr(r);return i?Vr(e,i,t):!1},Br=(e,t,n)=>{let r=Gr(e,n);if(!r)return!1;let i=Jr(r);return i?Vr(e,i,t):!1};function Vr(e,t,n){let r=t.nodeBefore,i=t.pos-1;for(;!r.isTextblock;i--){if(r.type.spec.isolating)return!1;let e=r.lastChild;if(!e)return!1;r=e}let a=t.nodeAfter,o=t.pos+1;for(;!a.isTextblock;o++){if(a.type.spec.isolating)return!1;let e=a.firstChild;if(!e)return!1;a=e}let s=qn(e.doc,i,o,D.empty);if(!s||s.from!=i||s instanceof yn&&s.slice.size>=o-i)return!1;if(n){let t=e.tr.step(s);t.setSelection(k.create(t.doc,i)),n(t.scrollIntoView())}return!0}function Hr(e,t,n=!1){for(let r=e;r;r=t==`start`?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&r.childCount!=1)return!1}return!1}var Ur=(e,t,n)=>{let{$head:r,empty:i}=e.selection,a=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`backward`,e):r.parentOffset>0)return!1;a=Wr(r)}let o=a&&a.nodeBefore;return!o||!A.isSelectable(o)?!1:(t&&t(e.tr.setSelection(A.create(e.doc,a.pos-o.nodeSize)).scrollIntoView()),!0)};function Wr(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){if(e.index(t)>0)return e.doc.resolve(e.before(t+1));if(e.node(t).type.spec.isolating)break}return null}function Gr(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`forward`,e):n.parentOffset<n.parent.content.size)?null:n}var Kr=(e,t,n)=>{let r=Gr(e,n);if(!r)return!1;let i=Jr(r);if(!i)return!1;let a=i.nodeAfter;if(ci(e,i,t,1))return!0;if(r.parent.content.size==0&&(Hr(a,`start`)||A.isSelectable(a))){let n=qn(e.doc,r.before(),r.after(),D.empty);if(n&&n.slice.size<n.to-n.from){if(t){let r=e.tr.step(n);r.setSelection(Hr(a,`start`)?O.findFrom(r.doc.resolve(r.mapping.map(i.pos)),1):A.create(r.doc,r.mapping.map(i.pos))),t(r.scrollIntoView())}return!0}}return a.isAtom&&i.depth==r.depth-1?(t&&t(e.tr.delete(i.pos,i.pos+a.nodeSize).scrollIntoView()),!0):!1},qr=(e,t,n)=>{let{$head:r,empty:i}=e.selection,a=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`forward`,e):r.parentOffset<r.parent.content.size)return!1;a=Jr(r)}let o=a&&a.nodeAfter;return!o||!A.isSelectable(o)?!1:(t&&t(e.tr.setSelection(A.create(e.doc,a.pos)).scrollIntoView()),!0)};function Jr(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){let n=e.node(t);if(e.index(t)+1<n.childCount)return e.doc.resolve(e.after(t+1));if(n.type.spec.isolating)break}return null}var Yr=(e,t)=>{let n=e.selection,r=n instanceof A,i;if(r){if(n.node.isTextblock||!Bn(e.doc,n.from))return!1;i=n.from}else if(i=Un(e.doc,n.from,-1),i==null)return!1;if(t){let n=e.tr.join(i);r&&n.setSelection(A.create(n.doc,i-e.doc.resolve(i).nodeBefore.nodeSize)),t(n.scrollIntoView())}return!0},Xr=(e,t)=>{let n=e.selection,r;if(n instanceof A){if(n.node.isTextblock||!Bn(e.doc,n.to))return!1;r=n.to}else if(r=Un(e.doc,n.to,1),r==null)return!1;return t&&t(e.tr.join(r).scrollIntoView()),!0},Zr=(e,t)=>{let{$from:n,$to:r}=e.selection,i=n.blockRange(r),a=i&&En(i);return a==null?!1:(t&&t(e.tr.lift(i,a).scrollIntoView()),!0)},Qr=(e,t)=>{let{$head:n,$anchor:r}=e.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(t&&t(e.tr.insertText(`
50
- `).scrollIntoView()),!0)};function $r(e){for(let t=0;t<e.edgeCount;t++){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}var ei=(e,t)=>{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),a=n.indexAfter(-1),o=$r(i.contentMatchAt(a));if(!o||!i.canReplaceWith(a,a,o))return!1;if(t){let r=n.after(),i=e.tr.replaceWith(r,r,o.createAndFill());i.setSelection(O.near(i.doc.resolve(r),1)),t(i.scrollIntoView())}return!0},ti=(e,t)=>{let n=e.selection,{$from:r,$to:i}=n;if(n instanceof vr||r.parent.inlineContent||i.parent.inlineContent)return!1;let a=$r(i.parent.contentMatchAt(i.indexAfter()));if(!a||!a.isTextblock)return!1;if(t){let n=(!r.parentOffset&&i.index()<i.parent.childCount?r:i).pos,o=e.tr.insert(n,a.createAndFill());o.setSelection(k.create(o.doc,n+1)),t(o.scrollIntoView())}return!0},ni=(e,t)=>{let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(Rn(e.doc,r))return t&&t(e.tr.split(r).scrollIntoView()),!0}let r=n.blockRange(),i=r&&En(r);return i==null?!1:(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)};function ri(e){return(t,n)=>{let{$from:r,$to:i}=t.selection;if(t.selection instanceof A&&t.selection.node.isBlock)return!r.parentOffset||!Rn(t.doc,r.pos)?!1:(n&&n(t.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let a=[],o,s,c=!1,l=!1;for(let t=r.depth;;t--)if(r.node(t).isBlock){c=r.end(t)==r.pos+(r.depth-t),l=r.start(t)==r.pos-(r.depth-t),s=$r(r.node(t-1).contentMatchAt(r.indexAfter(t-1)));let n=e&&e(i.parent,c,r);a.unshift(n||(c&&s?{type:s}:null)),o=t;break}else{if(t==1)return!1;a.unshift(null)}let u=t.tr;(t.selection instanceof k||t.selection instanceof vr)&&u.deleteSelection();let d=u.mapping.map(r.pos),f=Rn(u.doc,d,a.length,a);if(f||=(a[0]=s?{type:s}:null,Rn(u.doc,d,a.length,a)),!f)return!1;if(u.split(d,a.length,a),!c&&l&&r.node(o).type!=s){let e=u.mapping.map(r.before(o)),t=u.doc.resolve(e);s&&r.node(o-1).canReplaceWith(t.index(),t.index()+1,s)&&u.setNodeMarkup(u.mapping.map(r.before(o)),s)}return n&&n(u.scrollIntoView()),!0}}var ii=ri(),ai=(e,t)=>{let{$from:n,to:r}=e.selection,i,a=n.sharedDepth(r);return a==0?!1:(i=n.before(a),t&&t(e.tr.setSelection(A.create(e.doc,i))),!0)},oi=(e,t)=>(t&&t(e.tr.setSelection(new vr(e.doc))),!0);function si(e,t,n){let r=t.nodeBefore,i=t.nodeAfter,a=t.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&t.parent.canReplace(a-1,a)?(n&&n(e.tr.delete(t.pos-r.nodeSize,t.pos).scrollIntoView()),!0):!t.parent.canReplace(a,a+1)||!(i.isTextblock||Bn(e.doc,t.pos))?!1:(n&&n(e.tr.join(t.pos).scrollIntoView()),!0)}function ci(e,t,n,r){let i=t.nodeBefore,a=t.nodeAfter,o,s,c=i.type.spec.isolating||a.type.spec.isolating;if(!c&&si(e,t,n))return!0;let l=!c&&t.parent.canReplace(t.index(),t.index()+1);if(l&&(o=(s=i.contentMatchAt(i.childCount)).findWrapping(a.type))&&s.matchType(o[0]||a.type).validEnd){if(n){let r=t.pos+a.nodeSize,s=E.empty;for(let e=o.length-1;e>=0;e--)s=E.from(o[e].create(null,s));s=E.from(i.copy(s));let c=e.tr.step(new bn(t.pos-1,r,t.pos,r,new D(s,1,0),o.length,!0)),l=c.doc.resolve(r+2*o.length);l.nodeAfter&&l.nodeAfter.type==i.type&&Bn(c.doc,l.pos)&&c.join(l.pos),n(c.scrollIntoView())}return!0}let u=a.type.spec.isolating||r>0&&c?null:O.findFrom(t,1),d=u&&u.$from.blockRange(u.$to),f=d&&En(d);if(f!=null&&f>=t.depth)return n&&n(e.tr.lift(d,f).scrollIntoView()),!0;if(l&&Hr(a,`start`,!0)&&Hr(i,`end`)){let r=i,o=[];for(;o.push(r),!r.isTextblock;)r=r.lastChild;let s=a,c=1;for(;!s.isTextblock;s=s.firstChild)c++;if(r.canReplace(r.childCount,r.childCount,s.content)){if(n){let r=E.empty;for(let e=o.length-1;e>=0;e--)r=E.from(o[e].copy(r));n(e.tr.step(new bn(t.pos-o.length,t.pos+a.nodeSize,t.pos+c,t.pos+a.nodeSize-c,new D(r,o.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function li(e){return function(t,n){let r=t.selection,i=e<0?r.$from:r.$to,a=i.depth;for(;i.node(a).isInline;){if(!a)return!1;a--}return i.node(a).isTextblock?(n&&n(t.tr.setSelection(k.create(t.doc,e<0?i.start(a):i.end(a)))),!0):!1}}var ui=li(-1),di=li(1);function fi(e,t=null){return function(n,r){let{$from:i,$to:a}=n.selection,o=i.blockRange(a),s=o&&On(o,e,t);return s?(r&&r(n.tr.wrap(o,s).scrollIntoView()),!0):!1}}function pi(e,t=null){return function(n,r){let i=!1;for(let r=0;r<n.selection.ranges.length&&!i;r++){let{$from:{pos:a},$to:{pos:o}}=n.selection.ranges[r];n.doc.nodesBetween(a,o,(r,a)=>{if(i)return!1;if(!(!r.isTextblock||r.hasMarkup(e,t)))if(r.type==e)i=!0;else{let t=n.doc.resolve(a),r=t.index();i=t.parent.canReplaceWith(r,r+1,e)}})}if(!i)return!1;if(r){let i=n.tr;for(let r=0;r<n.selection.ranges.length;r++){let{$from:{pos:a},$to:{pos:o}}=n.selection.ranges[r];i.setBlockType(a,o,e,t)}r(i.scrollIntoView())}return!0}}function mi(...e){return function(t,n,r){for(let i=0;i<e.length;i++)if(e[i](t,n,r))return!0;return!1}}var hi=mi(Ir,Rr,Ur),gi=mi(Ir,Kr,qr),_i={Enter:mi(Qr,ti,ni,ii),"Mod-Enter":ei,Backspace:hi,"Mod-Backspace":hi,"Shift-Backspace":hi,Delete:gi,"Mod-Delete":gi,"Mod-a":oi},vi={"Ctrl-h":_i.Backspace,"Alt-Backspace":_i[`Mod-Backspace`],"Ctrl-d":_i.Delete,"Ctrl-Alt-Backspace":_i[`Mod-Delete`],"Alt-Delete":_i[`Mod-Delete`],"Alt-d":_i[`Mod-Delete`],"Ctrl-a":ui,"Ctrl-e":di};for(let e in _i)vi[e]=_i[e];typeof navigator<`u`?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<`u`&&os.platform&&os.platform();function yi(e,t=null){return function(n,r){let{$from:i,$to:a}=n.selection,o=i.blockRange(a);if(!o)return!1;let s=r?n.tr:null;return bi(s,o,e,t)?(r&&r(s.scrollIntoView()),!0):!1}}function bi(e,t,n,r=null){let i=!1,a=t,o=t.$from.doc;if(t.depth>=2&&t.$from.node(t.depth-1).type.compatibleContent(n)&&t.startIndex==0){if(t.$from.index(t.depth-1)==0)return!1;let e=o.resolve(t.start-2);a=new et(e,e,t.depth),t.endIndex<t.parent.childCount&&(t=new et(t.$from,o.resolve(t.$to.end(t.depth)),t.depth)),i=!0}let s=On(a,n,r,t);return s?(e&&xi(e,t,s,i,n),!0):!1}function xi(e,t,n,r,i){let a=E.empty;for(let e=n.length-1;e>=0;e--)a=E.from(n[e].type.create(n[e].attrs,a));e.step(new bn(t.start-(r?2:0),t.end,t.start,t.end,new D(a,0,0),n.length,!0));let o=0;for(let e=0;e<n.length;e++)n[e].type==i&&(o=e+1);let s=n.length-o,c=t.start+n.length-(r?2:0),l=t.parent;for(let n=t.startIndex,r=t.endIndex,i=!0;n<r;n++,i=!1)!i&&Rn(e.doc,c,s)&&(e.split(c,s),c+=2*s),c+=l.child(n).nodeSize;return e}function Si(e){return function(t,n){let{$from:r,$to:i}=t.selection,a=r.blockRange(i,t=>t.childCount>0&&t.firstChild.type==e);return a?n?r.node(a.depth-1).type==e?Ci(t,n,e,a):wi(t,n,a):!0:!1}}function Ci(e,t,n,r){let i=e.tr,a=r.end,o=r.$to.end(r.depth);a<o&&(i.step(new bn(a-1,o,a,o,new D(E.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new et(i.doc.resolve(r.$from.pos),i.doc.resolve(o),r.depth));let s=En(r);if(s==null)return!1;i.lift(r,s);let c=i.doc.resolve(i.mapping.map(a,-1)-1);return Bn(i.doc,c.pos)&&c.nodeBefore.type==c.nodeAfter.type&&i.join(c.pos),t(i.scrollIntoView()),!0}function wi(e,t,n){let r=e.tr,i=n.parent;for(let e=n.end,t=n.endIndex-1,a=n.startIndex;t>a;t--)e-=i.child(t).nodeSize,r.delete(e-1,e+1);let a=r.doc.resolve(n.start),o=a.nodeAfter;if(r.mapping.map(n.end)!=n.start+a.nodeAfter.nodeSize)return!1;let s=n.startIndex==0,c=n.endIndex==i.childCount,l=a.node(-1),u=a.index(-1);if(!l.canReplace(u+(s?0:1),u+1,o.content.append(c?E.empty:E.from(i))))return!1;let d=a.pos,f=d+o.nodeSize;return r.step(new bn(d-(s?1:0),f+(c?1:0),d+1,f-1,new D((s?E.empty:E.from(i.copy(E.empty))).append(c?E.empty:E.from(i.copy(E.empty))),s?0:1,c?0:1),s?0:1)),t(r.scrollIntoView()),!0}function Ti(e){return function(t,n){let{$from:r,$to:i}=t.selection,a=r.blockRange(i,t=>t.childCount>0&&t.firstChild.type==e);if(!a)return!1;let o=a.startIndex;if(o==0)return!1;let s=a.parent,c=s.child(o-1);if(c.type!=e)return!1;if(n){let r=c.lastChild&&c.lastChild.type==s.type,i=E.from(r?e.create():null),o=new D(E.from(e.create(null,E.from(s.type.create(null,i)))),r?3:1,0),l=a.start,u=a.end;n(t.tr.step(new bn(l-(r?3:1),u,l,u,o,1,!0)).scrollIntoView())}return!0}}var Ei=function(e){for(var t=0;;t++)if(e=e.previousSibling,!e)return t},Di=function(e){let t=e.assignedSlot||e.parentNode;return t&&t.nodeType==11?t.host:t},Oi=null,ki=function(e,t,n){let r=Oi||=document.createRange();return r.setEnd(e,n??e.nodeValue.length),r.setStart(e,t||0),r},Ai=function(){Oi=null},ji=function(e,t,n,r){return n&&(Ni(e,t,n,r,-1)||Ni(e,t,n,r,1))},Mi=/^(img|br|input|textarea|hr)$/i;function Ni(e,t,n,r,i){for(;;){if(e==n&&t==r)return!0;if(t==(i<0?0:Pi(e))){let n=e.parentNode;if(!n||n.nodeType!=1||Ri(e)||Mi.test(e.nodeName)||e.contentEditable==`false`)return!1;t=Ei(e)+(i<0?0:1),e=n}else if(e.nodeType==1){let n=e.childNodes[t+(i<0?-1:0)];if(n.nodeType==1&&n.contentEditable==`false`)if(n.pmViewDesc?.ignoreForSelection)t+=i;else return!1;else e=n,t=i<0?Pi(e):0}else return!1}}function Pi(e){return e.nodeType==3?e.nodeValue.length:e.childNodes.length}function Fi(e,t){for(;;){if(e.nodeType==3&&t)return e;if(e.nodeType==1&&t>0){if(e.contentEditable==`false`)return null;e=e.childNodes[t-1],t=Pi(e)}else if(e.parentNode&&!Ri(e))t=Ei(e),e=e.parentNode;else return null}}function Ii(e,t){for(;;){if(e.nodeType==3&&t<e.nodeValue.length)return e;if(e.nodeType==1&&t<e.childNodes.length){if(e.contentEditable==`false`)return null;e=e.childNodes[t],t=0}else if(e.parentNode&&!Ri(e))t=Ei(e)+1,e=e.parentNode;else return null}}function Li(e,t,n){for(let r=t==0,i=t==Pi(e);r||i;){if(e==n)return!0;let t=Ei(e);if(e=e.parentNode,!e)return!1;r&&=t==0,i&&=t==Pi(e)}}function Ri(e){let t;for(let n=e;n&&!(t=n.pmViewDesc);n=n.parentNode);return t&&t.node&&t.node.isBlock&&(t.dom==e||t.contentDOM==e)}var zi=function(e){return e.focusNode&&ji(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function Bi(e,t){let n=document.createEvent(`Event`);return n.initEvent(`keydown`,!0,!0),n.keyCode=e,n.key=n.code=t,n}function Vi(e){let t=e.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}function Hi(e,t,n){if(e.caretPositionFromPoint)try{let r=e.caretPositionFromPoint(t,n);if(r)return{node:r.offsetNode,offset:Math.min(Pi(r.offsetNode),r.offset)}}catch{}if(e.caretRangeFromPoint){let r=e.caretRangeFromPoint(t,n);if(r)return{node:r.startContainer,offset:Math.min(Pi(r.startContainer),r.startOffset)}}}var Ui=typeof navigator<`u`?navigator:null,Wi=typeof document<`u`?document:null,Gi=Ui&&Ui.userAgent||``,Ki=/Edge\/(\d+)/.exec(Gi),qi=/MSIE \d/.exec(Gi),Ji=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Gi),Yi=!!(qi||Ji||Ki),Xi=qi?document.documentMode:Ji?+Ji[1]:Ki?+Ki[1]:0,Zi=!Yi&&/gecko\/(\d+)/i.test(Gi);Zi&&+(/Firefox\/(\d+)/.exec(Gi)||[0,0])[1];var Qi=!Yi&&/Chrome\/(\d+)/.exec(Gi),$i=!!Qi,ea=Qi?+Qi[1]:0,ta=!Yi&&!!Ui&&/Apple Computer/.test(Ui.vendor),na=ta&&(/Mobile\/\w+/.test(Gi)||!!Ui&&Ui.maxTouchPoints>2),ra=na||(Ui?/Mac/.test(Ui.platform):!1),ia=Ui?/Win/.test(Ui.platform):!1,aa=/Android \d/.test(Gi),oa=!!Wi&&`webkitFontSmoothing`in Wi.documentElement.style,sa=oa?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function ca(e){let t=e.defaultView&&e.defaultView.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}function la(e,t){return typeof e==`number`?e:e[t]}function ua(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,r=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*r}}function da(e,t,n){let r=e.someProp(`scrollThreshold`)||0,i=e.someProp(`scrollMargin`)||5,a=e.dom.ownerDocument;for(let o=n||e.dom;o;){if(o.nodeType!=1){o=Di(o);continue}let e=o,n=e==a.body,s=n?ca(a):ua(e),c=0,l=0;if(t.top<s.top+la(r,`top`)?l=-(s.top-t.top+la(i,`top`)):t.bottom>s.bottom-la(r,`bottom`)&&(l=t.bottom-t.top>s.bottom-s.top?t.top+la(i,`top`)-s.top:t.bottom-s.bottom+la(i,`bottom`)),t.left<s.left+la(r,`left`)?c=-(s.left-t.left+la(i,`left`)):t.right>s.right-la(r,`right`)&&(c=t.right-s.right+la(i,`right`)),c||l)if(n)a.defaultView.scrollBy(c,l);else{let n=e.scrollLeft,r=e.scrollTop;l&&(e.scrollTop+=l),c&&(e.scrollLeft+=c);let i=e.scrollLeft-n,a=e.scrollTop-r;t={left:t.left-i,top:t.top-a,right:t.right-i,bottom:t.bottom-a}}let u=n?`fixed`:getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(u))break;o=u==`absolute`?o.offsetParent:Di(o)}}function fa(e){let t=e.dom.getBoundingClientRect(),n=Math.max(0,t.top),r,i;for(let a=(t.left+t.right)/2,o=n+1;o<Math.min(innerHeight,t.bottom);o+=5){let t=e.root.elementFromPoint(a,o);if(!t||t==e.dom||!e.dom.contains(t))continue;let s=t.getBoundingClientRect();if(s.top>=n-20){r=t,i=s.top;break}}return{refDOM:r,refTop:i,stack:pa(e.dom)}}function pa(e){let t=[],n=e.ownerDocument;for(let r=e;r&&(t.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),e!=n);r=Di(r));return t}function ma({refDOM:e,refTop:t,stack:n}){let r=e?e.getBoundingClientRect().top:0;ha(n,r==0?0:r-t)}function ha(e,t){for(let n=0;n<e.length;n++){let{dom:r,top:i,left:a}=e[n];r.scrollTop!=i+t&&(r.scrollTop=i+t),r.scrollLeft!=a&&(r.scrollLeft=a)}}var ga=null;function _a(e){if(e.setActive)return e.setActive();if(ga)return e.focus(ga);let t=pa(e);e.focus(ga==null?{get preventScroll(){return ga={preventScroll:!0},!0}}:void 0),ga||(ga=!1,ha(t,0))}function va(e,t){let n,r=2e8,i,a=0,o=t.top,s=t.top,c,l;for(let u=e.firstChild,d=0;u;u=u.nextSibling,d++){let e;if(u.nodeType==1)e=u.getClientRects();else if(u.nodeType==3)e=ki(u).getClientRects();else continue;for(let f=0;f<e.length;f++){let p=e[f];if(p.top<=o&&p.bottom>=s){o=Math.max(p.bottom,o),s=Math.min(p.top,s);let e=p.left>t.left?p.left-t.left:p.right<t.left?t.left-p.right:0;if(e<r){n=u,r=e,i=e&&n.nodeType==3?{left:p.right<t.left?p.right:p.left,top:t.top}:t,u.nodeType==1&&e&&(a=d+(t.left>=(p.left+p.right)/2?1:0));continue}}else p.top>t.top&&!c&&p.left<=t.left&&p.right>=t.left&&(c=u,l={left:Math.max(p.left,Math.min(p.right,t.left)),top:p.top});!n&&(t.left>=p.right&&t.top>=p.top||t.left>=p.left&&t.top>=p.bottom)&&(a=d+1)}}return!n&&c&&(n=c,i=l,r=0),n&&n.nodeType==3?ya(n,i):!n||r&&n.nodeType==1?{node:e,offset:a}:va(n,i)}function ya(e,t){let n=e.nodeValue.length,r=document.createRange(),i;for(let a=0;a<n;a++){r.setEnd(e,a+1),r.setStart(e,a);let n=Da(r,1);if(n.top!=n.bottom&&ba(t,n)){i={node:e,offset:a+(t.left>=(n.left+n.right)/2?1:0)};break}}return r.detach(),i||{node:e,offset:0}}function ba(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function xa(e,t){let n=e.parentNode;return n&&/^li$/i.test(n.nodeName)&&t.left<e.getBoundingClientRect().left?n:e}function Sa(e,t,n){let{node:r,offset:i}=va(t,n),a=-1;if(r.nodeType==1&&!r.firstChild){let e=r.getBoundingClientRect();a=e.left!=e.right&&n.left>(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(r,i,a)}function Ca(e,t,n,r){let i=-1;for(let n=t,a=!1;n!=e.dom;){let t=e.docView.nearestDesc(n,!0),o;if(!t)return null;if(t.dom.nodeType==1&&(t.node.isBlock&&t.parent||!t.contentDOM)&&((o=t.dom.getBoundingClientRect()).width||o.height)&&(t.node.isBlock&&t.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(t.dom.nodeName)&&(!a&&o.left>r.left||o.top>r.top?i=t.posBefore:(!a&&o.right<r.left||o.bottom<r.top)&&(i=t.posAfter),a=!0),!t.contentDOM&&i<0&&!t.node.isText))return(t.node.isBlock?r.top<(o.top+o.bottom)/2:r.left<(o.left+o.right)/2)?t.posBefore:t.posAfter;n=t.dom.parentNode}return i>-1?i:e.docView.posFromDOM(t,n,-1)}function wa(e,t,n){let r=e.childNodes.length;if(r&&n.top<n.bottom)for(let i=Math.max(0,Math.min(r-1,Math.floor(r*(t.top-n.top)/(n.bottom-n.top))-2)),a=i;;){let n=e.childNodes[a];if(n.nodeType==1){let e=n.getClientRects();for(let r=0;r<e.length;r++){let i=e[r];if(ba(t,i))return wa(n,t,i)}}if((a=(a+1)%r)==i)break}return e}function Ta(e,t){let n=e.dom.ownerDocument,r,i=0,a=Hi(n,t.left,t.top);a&&({node:r,offset:i}=a);let o=(e.root.elementFromPoint?e.root:n).elementFromPoint(t.left,t.top),s;if(!o||!e.dom.contains(o.nodeType==1?o:o.parentNode)){let n=e.dom.getBoundingClientRect();if(!ba(t,n)||(o=wa(e.dom,t,n),!o))return null}if(ta)for(let e=o;r&&e;e=Di(e))e.draggable&&(r=void 0);if(o=xa(o,t),r){if(Zi&&r.nodeType==1&&(i=Math.min(i,r.childNodes.length),i<r.childNodes.length)){let e=r.childNodes[i],n;e.nodeName==`IMG`&&(n=e.getBoundingClientRect()).right<=t.left&&n.bottom>t.top&&i++}let n;oa&&i&&r.nodeType==1&&(n=r.childNodes[i-1]).nodeType==1&&n.contentEditable==`false`&&n.getBoundingClientRect().top>=t.top&&i--,r==e.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&t.top>r.lastChild.getBoundingClientRect().bottom?s=e.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!=`BR`)&&(s=Ca(e,r,i,t))}s??=Sa(e,o,t);let c=e.docView.nearestDesc(o,!0);return{pos:s,inside:c?c.posAtStart-c.border:-1}}function Ea(e){return e.top<e.bottom||e.left<e.right}function Da(e,t){let n=e.getClientRects();if(n.length){let e=n[t<0?0:n.length-1];if(Ea(e))return e}return Array.prototype.find.call(n,Ea)||e.getBoundingClientRect()}var Oa=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function ka(e,t,n){let{node:r,offset:i,atom:a}=e.docView.domFromPos(t,n<0?-1:1),o=oa||Zi;if(r.nodeType==3)if(o&&(Oa.test(r.nodeValue)||(n<0?!i:i==r.nodeValue.length))){let e=Da(ki(r,i,i),n);if(Zi&&i&&/\s/.test(r.nodeValue[i-1])&&i<r.nodeValue.length){let t=Da(ki(r,i-1,i-1),-1);if(t.top==e.top){let n=Da(ki(r,i,i+1),-1);if(n.top!=e.top)return Aa(n,n.left<t.left)}}return e}else{let e=i,t=i,a=n<0?1:-1;return n<0&&!i?(t++,a=-1):n>=0&&i==r.nodeValue.length?(e--,a=1):n<0?e--:t++,Aa(Da(ki(r,e,t),a),a<0)}if(!e.state.doc.resolve(t-(a||0)).parent.inlineContent){if(a==null&&i&&(n<0||i==Pi(r))){let e=r.childNodes[i-1];if(e.nodeType==1)return ja(e.getBoundingClientRect(),!1)}if(a==null&&i<Pi(r)){let e=r.childNodes[i];if(e.nodeType==1)return ja(e.getBoundingClientRect(),!0)}return ja(r.getBoundingClientRect(),n>=0)}if(a==null&&i&&(n<0||i==Pi(r))){let e=r.childNodes[i-1],t=e.nodeType==3?ki(e,Pi(e)-(o?0:1)):e.nodeType==1&&(e.nodeName!=`BR`||!e.nextSibling)?e:null;if(t)return Aa(Da(t,1),!1)}if(a==null&&i<Pi(r)){let e=r.childNodes[i];for(;e.pmViewDesc&&e.pmViewDesc.ignoreForCoords;)e=e.nextSibling;let t=e?e.nodeType==3?ki(e,0,o?0:1):e.nodeType==1?e:null:null;if(t)return Aa(Da(t,-1),!0)}return Aa(Da(r.nodeType==3?ki(r):r,-n),n>=0)}function Aa(e,t){if(e.width==0)return e;let n=t?e.left:e.right;return{top:e.top,bottom:e.bottom,left:n,right:n}}function ja(e,t){if(e.height==0)return e;let n=t?e.top:e.bottom;return{top:n,bottom:n,left:e.left,right:e.right}}function Ma(e,t,n){let r=e.state,i=e.root.activeElement;r!=t&&e.updateState(t),i!=e.dom&&e.focus();try{return n()}finally{r!=t&&e.updateState(r),i!=e.dom&&i&&i.focus()}}function Na(e,t,n){let r=t.selection,i=n==`up`?r.$from:r.$to;return Ma(e,t,()=>{let{node:t}=e.docView.domFromPos(i.pos,n==`up`?-1:1);for(;;){let n=e.docView.nearestDesc(t,!0);if(!n)break;if(n.node.isBlock){t=n.contentDOM||n.dom;break}t=n.dom.parentNode}let r=ka(e,i.pos,1);for(let e=t.firstChild;e;e=e.nextSibling){let t;if(e.nodeType==1)t=e.getClientRects();else if(e.nodeType==3)t=ki(e,0,e.nodeValue.length).getClientRects();else continue;for(let e=0;e<t.length;e++){let i=t[e];if(i.bottom>i.top+1&&(n==`up`?r.top-i.top>(i.bottom-r.top)*2:i.bottom-r.bottom>(r.bottom-i.top)*2))return!1}}return!0})}var Pa=/[\u0590-\u08ac]/;function Fa(e,t,n){let{$head:r}=t.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,a=!i,o=i==r.parent.content.size,s=e.domSelection();return s?!Pa.test(r.parent.textContent)||!s.modify?n==`left`||n==`backward`?a:o:Ma(e,t,()=>{let{focusNode:t,focusOffset:i,anchorNode:a,anchorOffset:o}=e.domSelectionRange(),c=s.caretBidiLevel;s.modify(`move`,n,`character`);let l=r.depth?e.docView.domAfterPos(r.before()):e.dom,{focusNode:u,focusOffset:d}=e.domSelectionRange(),f=u&&!l.contains(u.nodeType==1?u:u.parentNode)||t==u&&i==d;try{s.collapse(a,o),t&&(t!=a||i!=o)&&s.extend&&s.extend(t,i)}catch{}return c!=null&&(s.caretBidiLevel=c),f}):r.pos==r.start()||r.pos==r.end()}var Ia=null,La=null,Ra=!1;function za(e,t,n){return Ia==t&&La==n?Ra:(Ia=t,La=n,Ra=n==`up`||n==`down`?Na(e,t,n):Fa(e,t,n))}var Ba=0,Va=1,Ha=2,Ua=3,Wa=class{constructor(e,t,n,r){this.parent=e,this.children=t,this.dom=n,this.contentDOM=r,this.dirty=Ba,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let t=0,n=this.posAtStart;;t++){let r=this.children[t];if(r==e)return n;n+=r.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,t,n){if(this.contentDOM&&this.contentDOM.contains(e.nodeType==1?e:e.parentNode))if(n<0){let n,r;if(e==this.contentDOM)n=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.previousSibling}for(;n&&!((r=n.pmViewDesc)&&r.parent==this);)n=n.previousSibling;return n?this.posBeforeChild(r)+r.size:this.posAtStart}else{let n,r;if(e==this.contentDOM)n=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.nextSibling}for(;n&&!((r=n.pmViewDesc)&&r.parent==this);)n=n.nextSibling;return n?this.posBeforeChild(r):this.posAtEnd}let r;if(e==this.dom&&this.contentDOM)r=t>Ei(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))r=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!1;break}if(t.previousSibling)break}if(r==null&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!0;break}if(t.nextSibling)break}}return r??n>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,r=e;r;r=r.parentNode){let i=this.getDesc(r),a;if(i&&(!t||i.node))if(n&&(a=i.nodeDOM)&&!(a.nodeType==1?a.contains(e.nodeType==1?e:e.parentNode):a==e))n=!1;else return i}}getDesc(e){let t=e.pmViewDesc;for(let e=t;e;e=e.parent)if(e==this)return t}posFromDOM(e,t,n){for(let r=e;r;r=r.parentNode){let i=this.getDesc(r);if(i)return i.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let r=this.children[t],i=n+r.size;if(n==e&&i!=n){for(;!r.border&&r.children.length;)for(let e=0;e<r.children.length;e++){let t=r.children[e];if(t.size){r=t;break}}return r}if(e<i)return r.descAt(e-n-r.border);n=i}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n=0,r=0;for(let t=0;n<this.children.length;n++){let i=this.children[n],a=t+i.size;if(a>e||i instanceof Za){r=e-t;break}t=a}if(r)return this.children[n].domFromPos(r-this.children[n].border,t);for(let e;n&&!(e=this.children[n-1]).size&&e instanceof Ga&&e.side>=0;n--);if(t<=0){let e,r=!0;for(;e=n?this.children[n-1]:null,!(!e||e.dom.parentNode==this.contentDOM);n--,r=!1);return e&&t&&r&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?Ei(e.dom)+1:0}}else{let e,r=!0;for(;e=n<this.children.length?this.children[n]:null,!(!e||e.dom.parentNode==this.contentDOM);n++,r=!1);return e&&r&&!e.border&&!e.domAtom?e.domFromPos(0,t):{node:this.contentDOM,offset:e?Ei(e.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,n=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let r=-1,i=-1;for(let a=n,o=0;;o++){let n=this.children[o],s=a+n.size;if(r==-1&&e<=s){let i=a+n.border;if(e>=i&&t<=s-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,i);e=a;for(let t=o;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){r=Ei(n.dom)+1;break}e-=n.size}r==-1&&(r=0)}if(r>-1&&(s>t||o==this.children.length-1)){t=s;for(let e=o+1;e<this.children.length;e++){let n=this.children[e];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(-1)){i=Ei(n.dom);break}t+=n.size}i==-1&&(i=this.contentDOM.childNodes.length);break}a=s}return{node:this.contentDOM,from:e,to:t,fromOffset:r,toOffset:i}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return t.size==0||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:n}=this.domFromPos(e,0);if(t.nodeType!=1||n==t.childNodes.length)throw RangeError(`No node after pos `+e);return t.childNodes[n]}setSelection(e,t,n,r=!1){let i=Math.min(e,t),a=Math.max(e,t);for(let o=0,s=0;o<this.children.length;o++){let c=this.children[o],l=s+c.size;if(i>s&&a<l)return c.setSelection(e-s-c.border,t-s-c.border,n,r);s=l}let o=this.domFromPos(e,e?-1:1),s=t==e?o:this.domFromPos(t,t?-1:1),c=n.root.getSelection(),l=n.domSelectionRange(),u=!1;if((Zi||ta)&&e==t){let{node:e,offset:t}=o;if(e.nodeType==3){if(u=!!(t&&e.nodeValue[t-1]==`
51
- `),u&&t==e.nodeValue.length)for(let t=e,n;t;t=t.parentNode){if(n=t.nextSibling){n.nodeName==`BR`&&(o=s={node:n.parentNode,offset:Ei(n)+1});break}let e=t.pmViewDesc;if(e&&e.node&&e.node.isBlock)break}}else{let n=e.childNodes[t-1];u=n&&(n.nodeName==`BR`||n.contentEditable==`false`)}}if(Zi&&l.focusNode&&l.focusNode!=s.node&&l.focusNode.nodeType==1){let e=l.focusNode.childNodes[l.focusOffset];e&&e.contentEditable==`false`&&(r=!0)}if(!(r||u&&ta)&&ji(o.node,o.offset,l.anchorNode,l.anchorOffset)&&ji(s.node,s.offset,l.focusNode,l.focusOffset))return;let d=!1;if((c.extend||e==t)&&!(u&&Zi)){c.collapse(o.node,o.offset);try{e!=t&&c.extend(s.node,s.offset),d=!0}catch{}}if(!d){if(e>t){let e=o;o=s,s=e}let n=document.createRange();n.setEnd(s.node,s.offset),n.setStart(o.node,o.offset),c.removeAllRanges(),c.addRange(n)}}ignoreMutation(e){return!this.contentDOM&&e.type!=`selection`}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,r=0;r<this.children.length;r++){let i=this.children[r],a=n+i.size;if(n==a?e<=a&&t>=n:e<a&&t>n){let r=n+i.border,o=a-i.border;if(e>=r&&t<=o){this.dirty=e==n||t==a?Ha:Va,e==r&&t==o&&(i.contentLost||i.dom.parentNode!=this.contentDOM)?i.dirty=Ua:i.markDirty(e-r,t-r);return}else i.dirty=i.dom==i.contentDOM&&i.dom.parentNode==this.contentDOM&&!i.children.length?Ha:Ua}n=a}this.dirty=Ha}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?Ha:Va;t.dirty<n&&(t.dirty=n)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}},Ga=class extends Wa{constructor(e,t,n,r){let i,a=t.type.toDOM;if(typeof a==`function`&&(a=a(n,()=>{if(!i)return r;if(i.parent)return i.parent.posBeforeChild(i)})),!t.type.spec.raw){if(a.nodeType!=1){let e=document.createElement(`span`);e.appendChild(a),a=e}a.contentEditable=`false`,a.classList.add(`ProseMirror-widget`)}super(e,[],a,null),this.widget=t,this.widget=t,i=this}matchesWidget(e){return this.dirty==Ba&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!=`selection`||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}},Ka=class extends Wa{constructor(e,t,n,r){super(e,[],t,null),this.textDOM=n,this.text=r}get size(){return this.text.length}localPosFromDOM(e,t){return e==this.textDOM?this.posAtStart+t:this.posAtStart+(t?this.size:0)}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type===`characterData`&&e.target.nodeValue==e.oldValue}},qa=class e extends Wa{constructor(e,t,n,r,i){super(e,[],n,r),this.mark=t,this.spec=i}static create(t,n,r,i){let a=i.nodeViews[n.type.name],o=a&&a(n,i,r);return(!o||!o.dom)&&(o=Gt.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new e(t,n,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&Ua||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Ua&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Ba){let e=this.parent;for(;!e.node;)e=e.parent;e.dirty<this.dirty&&(e.dirty=this.dirty),this.dirty=Ba}}slice(t,n,r){let i=e.create(this.parent,this.mark,!0,r),a=this.children,o=this.size;n<o&&(a=ho(a,n,o,r)),t>0&&(a=ho(a,0,t,r));for(let e=0;e<a.length;e++)a[e].parent=i;return i.children=a,i}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}},Ja=class e extends Wa{constructor(e,t,n,r,i,a,o,s,c){super(e,[],i,a),this.node=t,this.outerDeco=n,this.innerDeco=r,this.nodeDOM=o}static create(t,n,r,i,a,o){let s=a.nodeViews[n.type.name],c,l=s&&s(n,a,()=>{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),u=l&&l.dom,d=l&&l.contentDOM;if(n.isText){if(!u)u=document.createTextNode(n.text);else if(u.nodeType!=3)throw RangeError(`Text must be rendered as a DOM text node`)}else if(!u){let e=Gt.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs);({dom:u,contentDOM:d}=e)}!d&&!n.isText&&u.nodeName!=`BR`&&(u.hasAttribute(`contenteditable`)||(u.contentEditable=`false`),n.type.spec.draggable&&(u.draggable=!0));let f=u;return u=ao(u,r,n),l?c=new Qa(t,n,r,i,u,d||null,f,l,a,o+1):n.isText?new Xa(t,n,r,i,u,f,a):new e(t,n,r,i,u,d||null,f,a,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace==`pre`&&(e.preserveWhitespace=`full`),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>E.empty)}return e}matchesNode(e,t,n){return this.dirty==Ba&&e.eq(this.node)&&oo(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let n=this.node.inlineContent,r=t,i=e.composing?this.localCompositionInfo(e,t):null,a=i&&i.pos>-1?i:null,o=i&&i.pos<0,s=new co(this,a&&a.node,e);fo(this.node,this.innerDeco,(t,i,a)=>{t.spec.marks?s.syncToMarks(t.spec.marks,n,e,i):t.type.side>=0&&!a&&s.syncToMarks(i==this.node.childCount?Ie.none:this.node.child(i).marks,n,e,i),s.placeWidget(t,e,r)},(t,a,c,l)=>{s.syncToMarks(t.marks,n,e,l);let u;s.findNodeMatch(t,a,c,l)||o&&e.state.selection.from>r&&e.state.selection.to<r+t.nodeSize&&(u=s.findIndexWithChild(i.node))>-1&&s.updateNodeAt(t,a,c,u,e)||s.updateNextNode(t,a,c,e,l,r)||s.addNode(t,a,c,e,r),r+=t.nodeSize}),s.syncToMarks([],n,e,0),this.node.isTextblock&&s.addTextblockHacks(),s.destroyRest(),(s.changed||this.dirty==Ha)&&(a&&this.protectLocalComposition(e,a),$a(this.contentDOM,this.children,e),na&&po(this.dom))}localCompositionInfo(e,t){let{from:n,to:r}=e.state.selection;if(!(e.state.selection instanceof k)||n<t||r>t+this.node.content.size)return null;let i=e.input.compositionNode;if(!i||!this.dom.contains(i.parentNode))return null;if(this.node.inlineContent){let e=i.nodeValue,a=mo(this.node.content,e,n-t,r-t);return a<0?null:{node:i,pos:a,text:e}}else return{node:i,pos:-1,text:``}}protectLocalComposition(e,{node:t,pos:n,text:r}){if(this.getDesc(t))return;let i=t;for(;i.parentNode!=this.contentDOM;i=i.parentNode){for(;i.previousSibling;)i.parentNode.removeChild(i.previousSibling);for(;i.nextSibling;)i.parentNode.removeChild(i.nextSibling);i.pmViewDesc&&=void 0}let a=new Ka(this,i,t,r);e.input.compositionNodes.push(a),this.children=ho(this.children,n,n+r.length,e,a)}update(e,t,n,r){return this.dirty==Ua||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,n,r),!0)}updateInner(e,t,n,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=Ba}updateOuterDeco(e){if(oo(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,n=this.dom;this.dom=ro(this.dom,this.nodeDOM,no(this.outerDeco,this.node,t),no(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.add(`ProseMirror-selectednode`),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove(`ProseMirror-selectednode`),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute(`draggable`))}get domAtom(){return this.node.isAtom}};function Ya(e,t,n,r,i){ao(r,t,e);let a=new Ja(void 0,e,t,n,r,r,r,i,0);return a.contentDOM&&a.updateChildren(i,0),a}var Xa=class e extends Ja{constructor(e,t,n,r,i,a,o){super(e,t,n,r,i,null,a,o,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,r){return this.dirty==Ua||this.dirty!=Ba&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Ba||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=Ba,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return e.type!=`characterData`&&e.type!=`selection`}slice(t,n,r){let i=this.node.cut(t,n),a=document.createTextNode(i.text);return new e(this.parent,i,this.outerDeco,this.innerDeco,a,a,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Ua)}get domAtom(){return!1}isText(e){return this.node.text==e}},Za=class extends Wa{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Ba&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName==`IMG`}},Qa=class extends Ja{constructor(e,t,n,r,i,a,o,s,c,l){super(e,t,n,r,i,a,o,c,l),this.spec=s}update(e,t,n,r){if(this.dirty==Ua)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let i=this.spec.update(e,t,n);return i&&this.updateInner(e,t,n,r),i}else if(!this.contentDOM&&!e.isLeaf)return!1;else return super.update(e,t,n,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,r){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function $a(e,t,n){let r=e.firstChild,i=!1;for(let a=0;a<t.length;a++){let o=t[a],s=o.dom;if(s.parentNode==e){for(;s!=r;)r=so(r),i=!0;r=r.nextSibling}else i=!0,e.insertBefore(s,r);if(o instanceof qa){let t=r?r.previousSibling:e.lastChild;$a(o.contentDOM,o.children,n),r=t?t.nextSibling:e.firstChild}}for(;r;)r=so(r),i=!0;i&&n.trackWrites==e&&(n.trackWrites=null)}var eo=function(e){e&&(this.nodeName=e)};eo.prototype=Object.create(null);var to=[new eo];function no(e,t,n){if(e.length==0)return to;let r=n?to[0]:new eo,i=[r];for(let a=0;a<e.length;a++){let o=e[a].type.attrs;if(o){o.nodeName&&i.push(r=new eo(o.nodeName));for(let e in o){let a=o[e];a!=null&&(n&&i.length==1&&i.push(r=new eo(t.isInline?`span`:`div`)),e==`class`?r.class=(r.class?r.class+` `:``)+a:e==`style`?r.style=(r.style?r.style+`;`:``)+a:e!=`nodeName`&&(r[e]=a))}}}return i}function ro(e,t,n,r){if(n==to&&r==to)return t;let i=t;for(let t=0;t<r.length;t++){let a=r[t],o=n[t];if(t){let t;o&&o.nodeName==a.nodeName&&i!=e&&(t=i.parentNode)&&t.nodeName.toLowerCase()==a.nodeName?i=t:(t=document.createElement(a.nodeName),t.pmIsDeco=!0,t.appendChild(i),o=to[0],i=t)}io(i,o||to[0],a)}return i}function io(e,t,n){for(let r in t)r!=`class`&&r!=`style`&&r!=`nodeName`&&!(r in n)&&e.removeAttribute(r);for(let r in n)r!=`class`&&r!=`style`&&r!=`nodeName`&&n[r]!=t[r]&&e.setAttribute(r,n[r]);if(t.class!=n.class){let r=t.class?t.class.split(` `).filter(Boolean):[],i=n.class?n.class.split(` `).filter(Boolean):[];for(let t=0;t<r.length;t++)i.indexOf(r[t])==-1&&e.classList.remove(r[t]);for(let t=0;t<i.length;t++)r.indexOf(i[t])==-1&&e.classList.add(i[t]);e.classList.length==0&&e.removeAttribute(`class`)}if(t.style!=n.style){if(t.style){let n=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,r;for(;r=n.exec(t.style);)e.style.removeProperty(r[1])}n.style&&(e.style.cssText+=n.style)}}function ao(e,t,n){return ro(e,e,to,no(t,n,e.nodeType!=1))}function oo(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].type.eq(t[n].type))return!1;return!0}function so(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}var co=class{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=lo(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let n=e;n<t;n++)this.top.children[n].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,n,r){let i=0,a=this.stack.length>>1,o=Math.min(a,e.length);for(;i<o&&(i==a-1?this.top:this.stack[i+1<<1]).matchesMark(e[i])&&e[i].type.spec.spanning!==!1;)i++;for(;i<a;)this.destroyRest(),this.top.dirty=Ba,this.index=this.stack.pop(),this.top=this.stack.pop(),a--;for(;a<e.length;){this.stack.push(this.top,this.index+1);let i=-1,o=this.top.children.length;r<this.preMatch.index&&(o=Math.min(this.index+3,o));for(let t=this.index;t<o;t++){let n=this.top.children[t];if(n.matchesMark(e[a])&&!this.isLocked(n.dom)){i=t;break}}if(i>-1)i>this.index&&(this.changed=!0,this.destroyBetween(this.index,i)),this.top=this.top.children[this.index];else{let r=qa.create(this.top,e[a],t,n);this.top.children.splice(this.index,0,r),this.top=r,this.changed=!0}this.index=0,a++}}findNodeMatch(e,t,n,r){let i=-1,a;if(r>=this.preMatch.index&&(a=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&a.matchesNode(e,t,n))i=this.top.children.indexOf(a,this.index);else for(let r=this.index,a=Math.min(this.top.children.length,r+5);r<a;r++){let a=this.top.children[r];if(a.matchesNode(e,t,n)&&!this.preMatch.matched.has(a)){i=r;break}}return i<0?!1:(this.destroyBetween(this.index,i),this.index++,!0)}updateNodeAt(e,t,n,r,i){let a=this.top.children[r];return a.dirty==Ua&&a.dom==a.contentDOM&&(a.dirty=Ha),a.update(e,t,n,i)?(this.destroyBetween(this.index,r),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let t=e.pmViewDesc;if(t){for(let e=this.index;e<this.top.children.length;e++)if(this.top.children[e]==t)return e}return-1}e=t}}updateNextNode(e,t,n,r,i,a){for(let o=this.index;o<this.top.children.length;o++){let s=this.top.children[o];if(s instanceof Ja){let c=this.preMatch.matched.get(s);if(c!=null&&c!=i)return!1;let l=s.dom,u,d=this.isLocked(l)&&!(e.isText&&s.node&&s.node.isText&&s.nodeDOM.nodeValue==e.text&&s.dirty!=Ua&&oo(t,s.outerDeco));if(!d&&s.update(e,t,n,r))return this.destroyBetween(this.index,o),s.dom!=l&&(this.changed=!0),this.index++,!0;if(!d&&(u=this.recreateWrapper(s,e,t,n,r,a)))return this.destroyBetween(this.index,o),this.top.children[this.index]=u,u.contentDOM&&(u.dirty=Ha,u.updateChildren(r,a+1),u.dirty=Ba),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,r,i,a){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!oo(n,e.outerDeco)||!r.eq(e.innerDeco))return null;let o=Ja.create(this.top,t,n,r,i,a);if(o.contentDOM){o.children=e.children,e.children=[];for(let e of o.children)e.parent=o}return e.destroy(),o}addNode(e,t,n,r,i){let a=Ja.create(this.top,e,t,n,r,i);a.contentDOM&&a.updateChildren(r,i+1),this.top.children.splice(this.index++,0,a),this.changed=!0}placeWidget(e,t,n){let r=this.index<this.top.children.length?this.top.children[this.index]:null;if(r&&r.matchesWidget(e)&&(e==r.widget||!r.widget.type.toDOM.parentNode))this.index++;else{let r=new Ga(this.top,e,t,n);this.top.children.splice(this.index++,0,r),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof qa;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof Xa)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((ta||$i)&&e&&e.dom.contentEditable==`false`&&this.addHackNode(`IMG`,t),this.addHackNode(`BR`,this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.children[this.index].matchesHack(e))this.index++;else{let n=document.createElement(e);e==`IMG`&&(n.className=`ProseMirror-separator`,n.alt=``),e==`BR`&&(n.className=`ProseMirror-trailingBreak`);let r=new Za(this.top,[],n,null);t==this.top?t.children.splice(this.index++,0,r):t.children.push(r),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||e.nodeType==1&&e.contains(this.lock.parentNode))}};function lo(e,t){let n=t,r=n.children.length,i=e.childCount,a=new Map,o=[];outer:for(;i>0;){let s;for(;;)if(r){let e=n.children[r-1];if(e instanceof qa)n=e,r=e.children.length;else{s=e,r--;break}}else if(n==t)break outer;else r=n.parent.children.indexOf(n),n=n.parent;let c=s.node;if(c){if(c!=e.child(i-1))break;--i,a.set(s,i),o.push(s)}}return{index:i,matched:a,matches:o.reverse()}}function uo(e,t){return e.type.side-t.type.side}function fo(e,t,n,r){let i=t.locals(e),a=0;if(i.length==0){for(let n=0;n<e.childCount;n++){let o=e.child(n);r(o,i,t.forChild(a,o),n),a+=o.nodeSize}return}let o=0,s=[],c=null;for(let l=0;;){let u,d;for(;o<i.length&&i[o].to==a;){let e=i[o++];e.widget&&(u?(d||=[u]).push(e):u=e)}if(u)if(d){d.sort(uo);for(let e=0;e<d.length;e++)n(d[e],l,!!c)}else n(u,l,!!c);let f,p;if(c)p=-1,f=c,c=null;else if(l<e.childCount)p=l,f=e.child(l++);else break;for(let e=0;e<s.length;e++)s[e].to<=a&&s.splice(e--,1);for(;o<i.length&&i[o].from<=a&&i[o].to>a;)s.push(i[o++]);let m=a+f.nodeSize;if(f.isText){let e=m;o<i.length&&i[o].from<e&&(e=i[o].from);for(let t=0;t<s.length;t++)s[t].to<e&&(e=s[t].to);e<m&&(c=f.cut(e-a),f=f.cut(0,e-a),m=e,p=-1)}else for(;o<i.length&&i[o].to<m;)o++;let h=f.isInline&&!f.isLeaf?s.filter(e=>!e.inline):s.slice();r(f,h,t.forChild(a,f),p),a=m}}function po(e){if(e.nodeName==`UL`||e.nodeName==`OL`){let t=e.style.cssText;e.style.cssText=t+`; list-style: square !important`,window.getComputedStyle(e).listStyle,e.style.cssText=t}}function mo(e,t,n,r){for(let i=0,a=0;i<e.childCount&&a<=r;){let o=e.child(i++),s=a;if(a+=o.nodeSize,!o.isText)continue;let c=o.text;for(;i<e.childCount;){let t=e.child(i++);if(a+=t.nodeSize,!t.isText)break;c+=t.text}if(a>=n){if(a>=r&&c.slice(r-t.length-s,r-s)==t)return r-t.length;let e=s<r?c.lastIndexOf(t,r-s-1):-1;if(e>=0&&e+t.length+s>=n)return s+e;if(n==r&&c.length>=r+t.length-s&&c.slice(r-s,r-s+t.length)==t)return r}}return-1}function ho(e,t,n,r,i){let a=[];for(let o=0,s=0;o<e.length;o++){let c=e[o],l=s,u=s+=c.size;l>=n||u<=t?a.push(c):(l<t&&a.push(c.slice(0,t-l,r)),i&&=(a.push(i),void 0),u>n&&a.push(c.slice(n-l,c.size,r)))}return a}function go(e,t=null){let n=e.domSelectionRange(),r=e.state.doc;if(!n.focusNode)return null;let i=e.docView.nearestDesc(n.focusNode),a=i&&i.size==0,o=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(o<0)return null;let s=r.resolve(o),c,l;if(zi(n)){for(c=o;i&&!i.node;)i=i.parent;let e=i.node;if(i&&e.isAtom&&A.isSelectable(e)&&i.parent&&!(e.isInline&&Li(n.focusNode,n.focusOffset,i.dom))){let e=i.posBefore;l=new A(o==e?s:r.resolve(e))}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=o,i=o;for(let r=0;r<n.rangeCount;r++){let a=n.getRangeAt(r);t=Math.min(t,e.docView.posFromDOM(a.startContainer,a.startOffset,1)),i=Math.max(i,e.docView.posFromDOM(a.endContainer,a.endOffset,-1))}if(t<0)return null;[c,o]=i==e.state.selection.anchor?[i,t]:[t,i],s=r.resolve(o)}else c=e.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(c<0)return null}let u=r.resolve(c);if(!l){let n=t==`pointer`||e.state.selection.head<s.pos&&!a?1:-1;l=Do(e,u,s,n)}return l}function _o(e){return e.editable?e.hasFocus():ko(e)&&document.activeElement&&document.activeElement.contains(e.dom)}function vo(e,t=!1){let n=e.state.selection;if(To(e,n),_o(e)){if(!t&&e.input.mouseDown&&e.input.mouseDown.allowDefault&&$i){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&ji(t.anchorNode,t.anchorOffset,n.anchorNode,n.anchorOffset)){e.input.mouseDown.delayedSelectionSync=!0,e.domObserver.setCurSelection();return}}if(e.domObserver.disconnectSelection(),e.cursorWrapper)wo(e);else{let{anchor:r,head:i}=n,a,o;yo&&!(n instanceof k)&&(n.$from.parent.inlineContent||(a=bo(e,n.from)),!n.empty&&!n.$from.parent.inlineContent&&(o=bo(e,n.to))),e.docView.setSelection(r,i,e,t),yo&&(a&&So(a),o&&So(o)),n.visible?e.dom.classList.remove(`ProseMirror-hideselection`):(e.dom.classList.add(`ProseMirror-hideselection`),`onselectionchange`in document&&Co(e))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}}var yo=ta||$i&&ea<63;function bo(e,t){let{node:n,offset:r}=e.docView.domFromPos(t,0),i=r<n.childNodes.length?n.childNodes[r]:null,a=r?n.childNodes[r-1]:null;if(ta&&i&&i.contentEditable==`false`)return xo(i);if((!i||i.contentEditable==`false`)&&(!a||a.contentEditable==`false`)){if(i)return xo(i);if(a)return xo(a)}}function xo(e){return e.contentEditable=`true`,ta&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function So(e){e.contentEditable=`false`,e.wasDraggable&&=(e.draggable=!0,null)}function Co(e){let t=e.dom.ownerDocument;t.removeEventListener(`selectionchange`,e.input.hideSelectionGuard);let n=e.domSelectionRange(),r=n.anchorNode,i=n.anchorOffset;t.addEventListener(`selectionchange`,e.input.hideSelectionGuard=()=>{(n.anchorNode!=r||n.anchorOffset!=i)&&(t.removeEventListener(`selectionchange`,e.input.hideSelectionGuard),setTimeout(()=>{(!_o(e)||e.state.selection.visible)&&e.dom.classList.remove(`ProseMirror-hideselection`)},20))})}function wo(e){let t=e.domSelection();if(!t)return;let n=e.cursorWrapper.dom,r=n.nodeName==`IMG`;r?t.collapse(n.parentNode,Ei(n)+1):t.collapse(n,0),!r&&!e.state.selection.visible&&Yi&&Xi<=11&&(n.disabled=!0,n.disabled=!1)}function To(e,t){if(t instanceof A){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(Eo(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else Eo(e)}function Eo(e){e.lastSelectedViewDesc&&=(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),void 0)}function Do(e,t,n,r){return e.someProp(`createSelectionBetween`,r=>r(e,t,n))||k.between(t,n,r)}function Oo(e){return e.editable&&!e.hasFocus()?!1:ko(e)}function ko(e){let t=e.domSelectionRange();if(!t.anchorNode)return!1;try{return e.dom.contains(t.anchorNode.nodeType==3?t.anchorNode.parentNode:t.anchorNode)&&(e.editable||e.dom.contains(t.focusNode.nodeType==3?t.focusNode.parentNode:t.focusNode))}catch{return!1}}function Ao(e){let t=e.docView.domFromPos(e.state.selection.anchor,0),n=e.domSelectionRange();return ji(t.node,t.offset,n.anchorNode,n.anchorOffset)}function jo(e,t){let{$anchor:n,$head:r}=e.selection,i=t>0?n.max(r):n.min(r),a=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):null:i;return a&&O.findFrom(a,t)}function Mo(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function No(e,t,n){let r=e.state.selection;if(r instanceof k){if(n.indexOf(`s`)>-1){let{$head:n}=r,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!i||i.isText||!i.isLeaf)return!1;let a=e.state.doc.resolve(n.pos+i.nodeSize*(t<0?-1:1));return Mo(e,new k(r.$anchor,a))}else if(!r.empty)return!1;else if(e.endOfTextblock(t>0?`forward`:`backward`)){let n=jo(e.state,t);return n&&n instanceof A?Mo(e,n):!1}else if(!(ra&&n.indexOf(`m`)>-1)){let n=r.$head,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter,a;if(!i||i.isText)return!1;let o=t<0?n.pos-i.nodeSize:n.pos;return i.isAtom||(a=e.docView.descAt(o))&&!a.contentDOM?A.isSelectable(i)?Mo(e,new A(t<0?e.state.doc.resolve(n.pos-i.nodeSize):n)):oa?Mo(e,new k(e.state.doc.resolve(t<0?o:o+i.nodeSize))):!1:!1}}else if(r instanceof A&&r.node.isInline)return Mo(e,new k(t>0?r.$to:r.$from));else{let n=jo(e.state,t);return n?Mo(e,n):!1}}function Po(e){return e.nodeType==3?e.nodeValue.length:e.childNodes.length}function Fo(e,t){let n=e.pmViewDesc;return n&&n.size==0&&(t<0||e.nextSibling||e.nodeName!=`BR`)}function Io(e,t){return t<0?Lo(e):Ro(e)}function Lo(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i,a,o=!1;for(Zi&&n.nodeType==1&&r<Po(n)&&Fo(n.childNodes[r],-1)&&(o=!0);;)if(r>0){if(n.nodeType!=1)break;{let e=n.childNodes[r-1];if(Fo(e,-1))i=n,a=--r;else if(e.nodeType==3)n=e,r=n.nodeValue.length;else break}}else if(zo(n))break;else{let t=n.previousSibling;for(;t&&Fo(t,-1);)i=n.parentNode,a=Ei(t),t=t.previousSibling;if(t)n=t,r=Po(n);else{if(n=n.parentNode,n==e.dom)break;r=0}}o?Ho(e,n,r):i&&Ho(e,i,a)}function Ro(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i=Po(n),a,o;for(;;)if(r<i){if(n.nodeType!=1)break;let e=n.childNodes[r];if(Fo(e,1))a=n,o=++r;else break}else if(zo(n))break;else{let t=n.nextSibling;for(;t&&Fo(t,1);)a=t.parentNode,o=Ei(t)+1,t=t.nextSibling;if(t)n=t,r=0,i=Po(n);else{if(n=n.parentNode,n==e.dom)break;r=i=0}}a&&Ho(e,a,o)}function zo(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function Bo(e,t){for(;e&&t==e.childNodes.length&&!Ri(e);)t=Ei(e)+1,e=e.parentNode;for(;e&&t<e.childNodes.length;){let n=e.childNodes[t];if(n.nodeType==3)return n;if(n.nodeType==1&&n.contentEditable==`false`)break;e=n,t=0}}function Vo(e,t){for(;e&&!t&&!Ri(e);)t=Ei(e),e=e.parentNode;for(;e&&t;){let n=e.childNodes[t-1];if(n.nodeType==3)return n;if(n.nodeType==1&&n.contentEditable==`false`)break;e=n,t=e.childNodes.length}}function Ho(e,t,n){if(t.nodeType!=3){let e,r;(r=Bo(t,n))?(t=r,n=0):(e=Vo(t,n))&&(t=e,n=e.nodeValue.length)}let r=e.domSelection();if(!r)return;if(zi(r)){let e=document.createRange();e.setEnd(t,n),e.setStart(t,n),r.removeAllRanges(),r.addRange(e)}else r.extend&&r.extend(t,n);e.domObserver.setCurSelection();let{state:i}=e;setTimeout(()=>{e.state==i&&vo(e)},50)}function Uo(e,t){let n=e.state.doc.resolve(t);if(!($i||ia)&&n.parent.inlineContent){let r=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),i=(n.top+n.bottom)/2;if(i>r.top&&i<r.bottom&&Math.abs(n.left-r.left)>1)return n.left<r.left?`ltr`:`rtl`}if(t<n.end()){let n=e.coordsAtPos(t+1),i=(n.top+n.bottom)/2;if(i>r.top&&i<r.bottom&&Math.abs(n.left-r.left)>1)return n.left>r.left?`ltr`:`rtl`}}return getComputedStyle(e.dom).direction==`rtl`?`rtl`:`ltr`}function Wo(e,t,n){let r=e.state.selection;if(r instanceof k&&!r.empty||n.indexOf(`s`)>-1||ra&&n.indexOf(`m`)>-1)return!1;let{$from:i,$to:a}=r;if(!i.parent.inlineContent||e.endOfTextblock(t<0?`up`:`down`)){let n=jo(e.state,t);if(n&&n instanceof A)return Mo(e,n)}if(!i.parent.inlineContent){let n=t<0?i:a,o=r instanceof vr?O.near(n,t):O.findFrom(n,t);return o?Mo(e,o):!1}return!1}function Go(e,t){if(!(e.state.selection instanceof k))return!0;let{$head:n,$anchor:r,empty:i}=e.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(e.endOfTextblock(t>0?`forward`:`backward`))return!0;let a=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(a&&!a.isText){let r=e.state.tr;return t<0?r.delete(n.pos-a.nodeSize,n.pos):r.delete(n.pos,n.pos+a.nodeSize),e.dispatch(r),!0}return!1}function Ko(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function qo(e){if(!ta||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(t&&t.nodeType==1&&n==0&&t.firstChild&&t.firstChild.contentEditable==`false`){let n=t.firstChild;Ko(e,n,`true`),setTimeout(()=>Ko(e,n,`false`),20)}return!1}function Jo(e){let t=``;return e.ctrlKey&&(t+=`c`),e.metaKey&&(t+=`m`),e.altKey&&(t+=`a`),e.shiftKey&&(t+=`s`),t}function Yo(e,t){let n=t.keyCode,r=Jo(t);if(n==8||ra&&n==72&&r==`c`)return Go(e,-1)||Io(e,-1);if(n==46&&!t.shiftKey||ra&&n==68&&r==`c`)return Go(e,1)||Io(e,1);if(n==13||n==27)return!0;if(n==37||ra&&n==66&&r==`c`){let t=n==37?Uo(e,e.state.selection.from)==`ltr`?-1:1:-1;return No(e,t,r)||Io(e,t)}else if(n==39||ra&&n==70&&r==`c`){let t=n==39?Uo(e,e.state.selection.from)==`ltr`?1:-1:1;return No(e,t,r)||Io(e,t)}else if(n==38||ra&&n==80&&r==`c`)return Wo(e,-1,r)||Io(e,-1);else if(n==40||ra&&n==78&&r==`c`)return qo(e)||Wo(e,1,r)||Io(e,1);else if(r==(ra?`m`:`c`)&&(n==66||n==73||n==89||n==90))return!0;return!1}function Xo(e,t){e.someProp(`transformCopied`,n=>{t=n(t,e)});let n=[],{content:r,openStart:i,openEnd:a}=t;for(;i>1&&a>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,a--;let e=r.firstChild;n.push(e.type.name,e.attrs==e.type.defaultAttrs?null:e.attrs),r=e.content}let o=e.someProp(`clipboardSerializer`)||Gt.fromSchema(e.state.schema),s=cs(),c=s.createElement(`div`);c.appendChild(o.serializeFragment(r,{document:s}));let l=c.firstChild,u,d=0;for(;l&&l.nodeType==1&&(u=as[l.nodeName.toLowerCase()]);){for(let e=u.length-1;e>=0;e--){let t=s.createElement(u[e]);for(;c.firstChild;)t.appendChild(c.firstChild);c.appendChild(t),d++}l=c.firstChild}return l&&l.nodeType==1&&l.setAttribute(`data-pm-slice`,`${i} ${a}${d?` -${d}`:``} ${JSON.stringify(n)}`),{dom:c,text:e.someProp(`clipboardTextSerializer`,n=>n(t,e))||t.content.textBetween(0,t.content.size,`
49
+ `))}})}function In(e,t,n){let r=e.resolve(t),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function Ln(e,t,n,r,i){let a=e.doc.nodeAt(t);if(!a)throw RangeError(`No node at given position`);n||=a.type;let o=n.create(r,null,i||a.marks);if(a.isLeaf)return e.replaceWith(t,t+a.nodeSize,o);if(!n.validContent(a.content))throw RangeError(`Invalid content for node type `+n.name);e.step(new bn(t,t+a.nodeSize,t+1,t+a.nodeSize-1,new D(E.from(o),0,0),1,!0))}function Rn(e,t,n=1,r){let i=e.resolve(t),a=i.depth-n,o=r&&r[r.length-1]||i.parent;if(a<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let e=i.depth-1,t=n-2;e>a;e--,t--){let n=i.node(e),a=i.index(e);if(n.type.spec.isolating)return!1;let o=n.content.cutByIndex(a,n.childCount),s=r&&r[t+1];s&&(o=o.replaceChild(0,s.type.create(s.attrs)));let c=r&&r[t]||n;if(!n.canReplace(a+1,n.childCount)||!c.type.validContent(o))return!1}let s=i.indexAfter(a),c=r&&r[0];return i.node(a).canReplaceWith(s,s,c?c.type:i.node(a+1).type)}function zn(e,t,n=1,r){let i=e.doc.resolve(t),a=E.empty,o=E.empty;for(let e=i.depth,t=i.depth-n,s=n-1;e>t;e--,s--){a=E.from(i.node(e).copy(a));let t=r&&r[s];o=E.from(t?t.type.create(t.attrs,o):i.node(e).copy(o))}e.step(new yn(t,t,new D(a.append(o),n,n),!0))}function Bn(e,t){let n=e.resolve(t),r=n.index();return Hn(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Vn(e,t){t.content.size||e.type.compatibleContent(t.type);let n=e.contentMatchAt(e.childCount),{linebreakReplacement:r}=e.type.schema;for(let i=0;i<t.childCount;i++){let a=t.child(i),o=a.type==r?e.type.schema.nodes.text:a.type;if(n=n.matchType(o),!n||!e.type.allowsMarks(a.marks))return!1}return n.validEnd}function Hn(e,t){return!!(e&&t&&!e.isLeaf&&Vn(e,t))}function Un(e,t,n=-1){let r=e.resolve(t);for(let e=r.depth;;e--){let i,a,o=r.index(e);if(e==r.depth?(i=r.nodeBefore,a=r.nodeAfter):n>0?(i=r.node(e+1),o++,a=r.node(e).maybeChild(o)):(i=r.node(e).maybeChild(o-1),a=r.node(e+1)),i&&!i.isTextblock&&Hn(i,a)&&r.node(e).canReplace(o,o+1))return t;if(e==0)break;t=n<0?r.before(e):r.after(e)}}function Wn(e,t,n){let r=null,{linebreakReplacement:i}=e.doc.type.schema,a=e.doc.resolve(t-n),o=a.node().type;if(i&&o.inlineContent){let e=o.whitespace==`pre`,t=!!o.contentMatch.matchType(i);e&&!t?r=!1:!e&&t&&(r=!0)}let s=e.steps.length;if(r===!1){let r=e.doc.resolve(t+n);Fn(e,r.node(),r.before(),s)}o.inlineContent&&wn(e,t+n-1,o,a.node().contentMatchAt(a.index()),r==null);let c=e.mapping.slice(s),l=c.map(t-n);if(e.step(new yn(l,c.map(t+n,-1),D.empty,!0)),r===!0){let t=e.doc.resolve(l);Pn(e,t.node(),t.before(),e.steps.length)}return e}function Gn(e,t,n){let r=e.resolve(t);if(r.parent.canReplaceWith(r.index(),r.index(),n))return t;if(r.parentOffset==0)for(let e=r.depth-1;e>=0;e--){let t=r.index(e);if(r.node(e).canReplaceWith(t,t,n))return r.before(e+1);if(t>0)return null}if(r.parentOffset==r.parent.content.size)for(let e=r.depth-1;e>=0;e--){let t=r.indexAfter(e);if(r.node(e).canReplaceWith(t,t,n))return r.after(e+1);if(t<r.node(e).childCount)return null}return null}function Kn(e,t,n){let r=e.resolve(t);if(!n.content.size)return t;let i=n.content;for(let e=0;e<n.openStart;e++)i=i.firstChild.content;for(let e=1;e<=(n.openStart==0&&n.size?2:1);e++)for(let t=r.depth;t>=0;t--){let n=t==r.depth?0:r.pos<=(r.start(t+1)+r.end(t+1))/2?-1:1,a=r.index(t)+(n>0?1:0),o=r.node(t),s=!1;if(e==1)s=o.canReplace(a,a,i);else{let e=o.contentMatchAt(a).findWrapping(i.firstChild.type);s=e&&o.canReplaceWith(a,a,e[0])}if(s)return n==0?r.pos:n<0?r.before(t+1):r.after(t+1)}return null}function qn(e,t,n=t,r=D.empty){if(t==n&&!r.size)return null;let i=e.resolve(t),a=e.resolve(n);return Jn(i,a,r)?new yn(t,n,r):new Yn(i,a,r).fit()}function Jn(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}var Yn=class{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=E.empty;for(let t=0;t<=e.depth;t++){let n=e.node(t);this.frontier.push({type:n.type,match:n.contentMatchAt(e.indexAfter(t))})}for(let t=e.depth;t>0;t--)this.placed=E.from(e.node(t).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let e=this.findFittable();e?this.placeNodes(e):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,r=this.close(e<0?this.$to:n.doc.resolve(e));if(!r)return null;let i=this.placed,a=n.depth,o=r.depth;for(;a&&o&&i.childCount==1;)i=i.firstChild.content,a--,o--;let s=new D(i,a,o);return e>-1?new bn(n.pos,e,this.$to.pos,this.$to.end(),s,t):s.size||n.pos!=this.$to.pos?new yn(n.pos,r.pos,s):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,r=this.unplaced.openEnd;n<e;n++){let i=t.firstChild;if(t.childCount>1&&(r=0),i.type.spec.isolating&&r<=n){e=n;break}t=i.content}for(let t=1;t<=2;t++)for(let n=t==1?e:this.unplaced.openStart;n>=0;n--){let e,r=null;n?(r=Qn(this.unplaced.content,n-1).firstChild,e=r.content):e=this.unplaced.content;let i=e.firstChild;for(let e=this.depth;e>=0;e--){let{type:a,match:o}=this.frontier[e],s,c=null;if(t==1&&(i?o.matchType(i.type)||(c=o.fillBefore(E.from(i),!1)):r&&a.compatibleContent(r.type)))return{sliceDepth:n,frontierDepth:e,parent:r,inject:c};if(t==2&&i&&(s=o.findWrapping(i.type)))return{sliceDepth:n,frontierDepth:e,parent:r,wrap:s};if(r&&o.matchType(r.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=Qn(e,t);return!r.childCount||r.firstChild.isLeaf?!1:(this.unplaced=new D(e,t+1,Math.max(n,r.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=Qn(e,t);if(r.childCount<=1&&t>0){let i=e.size-t<=t+r.size;this.unplaced=new D(Xn(e,t-1,1),t-1,i?t-1:n)}else this.unplaced=new D(Xn(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:r,wrap:i}){for(;this.depth>t;)this.closeFrontierNode();if(i)for(let e=0;e<i.length;e++)this.openFrontierNode(i[e]);let a=this.unplaced,o=n?n.content:a.content,s=a.openStart-e,c=0,l=[],{match:u,type:d}=this.frontier[t];if(r){for(let e=0;e<r.childCount;e++)l.push(r.child(e));u=u.matchFragment(r)}let f=o.size+e-(a.content.size-a.openEnd);for(;c<o.childCount;){let e=o.child(c),t=u.matchType(e.type);if(!t)break;c++,(c>1||s==0||e.content.size)&&(u=t,l.push($n(e.mark(d.allowedMarks(e.marks)),c==1?s:0,c==o.childCount?f:-1)))}let p=c==o.childCount;p||(f=-1),this.placed=Zn(this.placed,t,E.from(l)),this.frontier[t].match=u,p&&f<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let e=0,t=o;e<f;e++){let e=t.lastChild;this.frontier.push({type:e.type,match:e.contentMatchAt(e.childCount)}),t=e.content}this.unplaced=p?e==0?D.empty:new D(Xn(a.content,e-1,1),e-1,f<0?a.openEnd:e-1):new D(Xn(a.content,e,c),a.openStart,a.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!er(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:n}=this.$to,r=this.$to.after(n);for(;n>1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(e){scan:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:r}=this.frontier[t],i=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),a=er(e,t,r,n,i);if(a){for(let n=t-1;n>=0;n--){let{match:t,type:r}=this.frontier[n],i=er(e,n,r,t,!0);if(!i||i.childCount)continue scan}return{depth:t,fit:a,move:i?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Zn(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),r=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,r)}return e}openFrontierNode(e,t=null,n){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=Zn(this.placed,this.depth,E.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(E.empty,!0);e.childCount&&(this.placed=Zn(this.placed,this.frontier.length,e))}};function Xn(e,t,n){return t==0?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(Xn(e.firstChild.content,t-1,n)))}function Zn(e,t,n){return t==0?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(Zn(e.lastChild.content,t-1,n)))}function Qn(e,t){for(let n=0;n<t;n++)e=e.firstChild.content;return e}function $n(e,t,n){if(t<=0)return e;let r=e.content;return t>1&&(r=r.replaceChild(0,$n(r.firstChild,t-1,r.childCount==1?n-1:0))),t>0&&(r=e.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(e.type.contentMatch.matchFragment(r).fillBefore(E.empty,!0)))),e.copy(r)}function er(e,t,n,r,i){let a=e.node(t),o=i?e.indexAfter(t):e.index(t);if(o==a.childCount&&!n.compatibleContent(a.type))return null;let s=r.fillBefore(a.content,!0,o);return s&&!tr(n,a.content,o)?s:null}function tr(e,t,n){for(let r=n;r<t.childCount;r++)if(!e.allowsMarks(t.child(r).marks))return!0;return!1}function nr(e){return e.spec.defining||e.spec.definingForContent}function rr(e,t,n,r){if(!r.size)return e.deleteRange(t,n);let i=e.doc.resolve(t),a=e.doc.resolve(n);if(Jn(i,a,r))return e.step(new yn(t,n,r));let o=sr(i,a);o[o.length-1]==0&&o.pop();let s=-(i.depth+1);o.unshift(s);for(let e=i.depth,t=i.pos-1;e>0;e--,t--){let n=i.node(e).type.spec;if(n.defining||n.definingAsContext||n.isolating)break;o.indexOf(e)>-1?s=e:i.before(e)==t&&o.splice(1,0,-e)}let c=o.indexOf(s),l=[],u=r.openStart;for(let e=r.content,t=0;;t++){let n=e.firstChild;if(l.push(n),t==r.openStart)break;e=n.content}for(let e=u-1;e>=0;e--){let t=l[e],n=nr(t.type);if(n&&!t.sameMarkup(i.node(Math.abs(s)-1)))u=e;else if(n||!t.type.isTextblock)break}for(let t=r.openStart;t>=0;t--){let s=(t+u+1)%(r.openStart+1),d=l[s];if(d)for(let t=0;t<o.length;t++){let l=o[(t+c)%o.length],u=!0;l<0&&(u=!1,l=-l);let f=i.node(l-1),p=i.index(l-1);if(f.canReplaceWith(p,p,d.type,d.marks))return e.replace(i.before(l),u?a.after(l):n,new D(ir(r.content,0,r.openStart,s),s,r.openEnd))}}let d=e.steps.length;for(let s=o.length-1;s>=0&&(e.replace(t,n,r),!(e.steps.length>d));s--){let e=o[s];e<0||(t=i.before(e),n=a.after(e))}}function ir(e,t,n,r,i){if(t<n){let i=e.firstChild;e=e.replaceChild(0,i.copy(ir(i.content,t+1,n,r,i)))}if(t>r){let t=i.contentMatchAt(0),n=t.fillBefore(e).append(e);e=n.append(t.matchFragment(n).fillBefore(E.empty,!0))}return e}function ar(e,t,n,r){if(!r.isInline&&t==n&&e.doc.resolve(t).parent.content.size){let i=Gn(e.doc,t,r.type);i!=null&&(t=n=i)}e.replaceRange(t,n,new D(E.from(r),0,0))}function or(e,t,n){let r=e.doc.resolve(t),i=e.doc.resolve(n),a=sr(r,i);for(let t=0;t<a.length;t++){let n=a[t],o=t==a.length-1;if(o&&n==0||r.node(n).type.contentMatch.validEnd)return e.delete(r.start(n),i.end(n));if(n>0&&(o||r.node(n-1).canReplace(r.index(n-1),i.indexAfter(n-1))))return e.delete(r.before(n),i.after(n))}for(let a=1;a<=r.depth&&a<=i.depth;a++)if(t-r.start(a)==r.depth-a&&n>r.end(a)&&i.end(a)-n!=i.depth-a&&r.start(a-1)==i.start(a-1)&&r.node(a-1).canReplace(r.index(a-1),i.index(a-1)))return e.delete(r.before(a),n);e.delete(t,n)}function sr(e,t){let n=[],r=Math.min(e.depth,t.depth);for(let i=r;i>=0;i--){let r=e.start(i);if(r<e.pos-(e.depth-i)||t.end(i)>t.pos+(t.depth-i)||e.node(i).type.spec.isolating||t.node(i).type.spec.isolating)break;(r==t.start(i)||i==e.depth&&i==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&i&&t.start(i-1)==r-1)&&n.push(i)}return n}var cr=class e extends fn{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return pn.fail(`No node at attribute step's position`);let n=Object.create(null);for(let e in t.attrs)n[e]=t.attrs[e];n[this.attr]=this.value;let r=t.type.create(n,null,t.marks);return pn.fromReplace(e,this.pos,this.pos+1,new D(E.from(r),0,t.isLeaf?0:1))}getMap(){return ln.empty}invert(t){return new e(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.attr,this.value)}toJSON(){return{stepType:`attr`,pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.pos!=`number`||typeof n.attr!=`string`)throw RangeError(`Invalid input for AttrStep.fromJSON`);return new e(n.pos,n.attr,n.value)}};fn.jsonID(`attr`,cr);var lr=class e extends fn{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let n in e.attrs)t[n]=e.attrs[n];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return pn.ok(n)}getMap(){return ln.empty}invert(t){return new e(this.attr,t.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:`docAttr`,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.attr!=`string`)throw RangeError(`Invalid input for DocAttrStep.fromJSON`);return new e(n.attr,n.value)}};fn.jsonID(`docAttr`,lr);var ur=class extends Error{};ur=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},ur.prototype=Object.create(Error.prototype),ur.prototype.constructor=ur,ur.prototype.name=`TransformError`;var dr=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new un}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new ur(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let n=0;n<this.mapping.maps.length;n++){let r=this.mapping.maps[n];n&&(e=r.map(e,1),t=r.map(t,-1)),r.forEach((n,r,i,a)=>{e=Math.min(e,i),t=Math.max(t,a)})}return e==1e9?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=D.empty){let r=qn(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new D(E.from(n),0,0))}delete(e,t){return this.replace(e,t,D.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return rr(this,e,t,n),this}replaceRangeWith(e,t,n){return ar(this,e,t,n),this}deleteRange(e,t){return or(this,e,t),this}lift(e,t){return Dn(this,e,t),this}join(e,t=1){return Wn(this,e,t),this}wrap(e,t){return Mn(this,e,t),this}setBlockType(e,t=e,n,r=null){return Nn(this,e,t,n,r),this}setNodeMarkup(e,t,n=null,r){return Ln(this,e,t,n,r),this}setNodeAttribute(e,t,n){return this.step(new cr(e,t,n)),this}setDocAttribute(e,t){return this.step(new lr(e,t)),this}addNodeMark(e,t){return this.step(new _n(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw RangeError(`No node at position `+e);if(t instanceof Ie)t.isInSet(n.marks)&&this.step(new vn(e,t));else{let r=n.marks,i,a=[];for(;i=t.isInSet(r);)a.push(new vn(e,i)),r=i.removeFromSet(r);for(let e=a.length-1;e>=0;e--)this.step(a[e])}return this}split(e,t=1,n){return zn(this,e,t,n),this}addMark(e,t,n){return Sn(this,e,t,n),this}removeMark(e,t,n){return Cn(this,e,t,n),this}clearIncompatible(e,t,n){return wn(this,e,t,n),this}},fr=Object.create(null),O=class{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new pr(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=D.empty){let n=t.content.lastChild,r=null;for(let e=0;e<t.openEnd;e++)r=n,n=n.lastChild;let i=e.steps.length,a=this.ranges;for(let o=0;o<a.length;o++){let{$from:s,$to:c}=a[o],l=e.mapping.slice(i);e.replaceRange(l.map(s.pos),l.map(c.pos),o?D.empty:t),o==0&&xr(e,i,(n?n.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,r=this.ranges;for(let i=0;i<r.length;i++){let{$from:a,$to:o}=r[i],s=e.mapping.slice(n),c=s.map(a.pos),l=s.map(o.pos);i?e.deleteRange(c,l):(e.replaceRangeWith(c,l,t),xr(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let r=e.parent.inlineContent?new k(e):br(e.node(0),e.parent,e.pos,e.index(),t,n);if(r)return r;for(let r=e.depth-1;r>=0;r--){let i=t<0?br(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):br(e.node(0),e.node(r),e.after(r+1),e.index(r)+1,t,n);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new vr(e.node(0))}static atStart(e){return br(e,e,0,0,1)||new vr(e)}static atEnd(e){return br(e,e,e.content.size,e.childCount,-1)||new vr(e)}static fromJSON(e,t){if(!t||!t.type)throw RangeError(`Invalid input for Selection.fromJSON`);let n=fr[t.type];if(!n)throw RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in fr)throw RangeError(`Duplicate use of selection JSON ID `+e);return fr[e]=t,t.prototype.jsonID=e,t}getBookmark(){return k.between(this.$anchor,this.$head).getBookmark()}};O.prototype.visible=!0;var pr=class{constructor(e,t){this.$from=e,this.$to=t}},mr=!1;function hr(e){!mr&&!e.parent.inlineContent&&(mr=!0,console.warn(`TextSelection endpoint not pointing into a node with inline content (`+e.parent.type.name+`)`))}var k=class e extends O{constructor(e,t=e){hr(e),hr(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return O.near(r);let i=t.resolve(n.map(this.anchor));return new e(i.parent.inlineContent?i:r,r)}replace(e,t=D.empty){if(super.replace(e,t),t==D.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(t){return t instanceof e&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new gr(this.anchor,this.head)}toJSON(){return{type:`text`,anchor:this.anchor,head:this.head}}static fromJSON(t,n){if(typeof n.anchor!=`number`||typeof n.head!=`number`)throw RangeError(`Invalid input for TextSelection.fromJSON`);return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(t,n,r){let i=t.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let e=O.findFrom(n,r,!0)||O.findFrom(n,-r,!0);if(e)n=e.$head;else return O.near(n,r)}return t.parent.inlineContent||(i==0?t=n:(t=(O.findFrom(t,-r,!0)||O.findFrom(t,r,!0)).$anchor,t.pos<n.pos!=i<0&&(t=n))),new e(t,n)}};O.jsonID(`text`,k);var gr=class e{constructor(e,t){this.anchor=e,this.head=t}map(t){return new e(t.map(this.anchor),t.map(this.head))}resolve(e){return k.between(e.resolve(this.anchor),e.resolve(this.head))}},A=class e extends O{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(t,n){let{deleted:r,pos:i}=n.mapResult(this.anchor),a=t.resolve(i);return r?O.near(a):new e(a)}content(){return new D(E.from(this.node),0,0)}eq(t){return t instanceof e&&t.anchor==this.anchor}toJSON(){return{type:`node`,anchor:this.anchor}}getBookmark(){return new _r(this.anchor)}static fromJSON(t,n){if(typeof n.anchor!=`number`)throw RangeError(`Invalid input for NodeSelection.fromJSON`);return new e(t.resolve(n.anchor))}static create(t,n){return new e(t.resolve(n))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}};A.prototype.visible=!1,O.jsonID(`node`,A);var _r=class e{constructor(e){this.anchor=e}map(t){let{deleted:n,pos:r}=t.mapResult(this.anchor);return n?new gr(r,r):new e(r)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&A.isSelectable(n)?new A(t):O.near(t)}},vr=class e extends O{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=D.empty){if(t==D.empty){e.delete(0,e.doc.content.size);let t=O.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:`all`}}static fromJSON(t){return new e(t)}map(t){return new e(t)}eq(t){return t instanceof e}getBookmark(){return yr}};O.jsonID(`all`,vr);var yr={map(){return this},resolve(e){return new vr(e)}};function br(e,t,n,r,i,a=!1){if(t.inlineContent)return k.create(e,n);for(let o=r-(i>0?0:1);i>0?o<t.childCount:o>=0;o+=i){let r=t.child(o);if(!r.isAtom){let t=br(e,r,n+i,i<0?r.childCount:0,i,a);if(t)return t}else if(!a&&A.isSelectable(r))return A.create(e,n-(i<0?r.nodeSize:0));n+=r.nodeSize*i}return null}function xr(e,t,n){let r=e.steps.length-1;if(r<t)return;let i=e.steps[r];if(!(i instanceof yn||i instanceof bn))return;let a=e.mapping.maps[r],o;a.forEach((e,t,n,r)=>{o??=r}),e.setSelection(O.near(e.doc.resolve(o),n))}var Sr=1,Cr=2,wr=4,Tr=class extends dr{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw RangeError(`Selection passed to setSelection must point at the current document`);return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|Sr)&~Cr,this.storedMarks=null,this}get selectionSet(){return(this.updated&Sr)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Cr,this}ensureMarks(e){return Ie.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Cr)>0}addStep(e,t){super.addStep(e,t),this.updated&=~Cr,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||Ie.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let r=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(n??=t,!e)return this.deleteRange(t,n);let i=this.storedMarks;if(!i){let e=this.doc.resolve(t);i=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,r.text(e,i)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection(O.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e==`string`?e:e.key]=t,this}getMeta(e){return this.meta[typeof e==`string`?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=wr,this}get scrolledIntoView(){return(this.updated&wr)>0}};function Er(e,t){return!t||!e?e:e.bind(t)}var Dr=class{constructor(e,t,n){this.name=e,this.init=Er(t.init,n),this.apply=Er(t.apply,n)}},Or=[new Dr(`doc`,{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new Dr(`selection`,{init(e,t){return e.selection||O.atStart(t.doc)},apply(e){return e.selection}}),new Dr(`storedMarks`,{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new Dr(`scrollToSelection`,{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}})],kr=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Or.slice(),t&&t.forEach(e=>{if(this.pluginsByKey[e.key])throw RangeError(`Adding different instances of a keyed plugin (`+e.key+`)`);this.plugins.push(e),this.pluginsByKey[e.key]=e,e.spec.state&&this.fields.push(new Dr(e.key,e.spec.state,e))})}},Ar=class e{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;n<this.config.plugins.length;n++)if(n!=t){let t=this.config.plugins[n];if(t.spec.filterTransaction&&!t.spec.filterTransaction.call(t,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),r=null;for(;;){let i=!1;for(let a=0;a<this.config.plugins.length;a++){let o=this.config.plugins[a];if(o.spec.appendTransaction){let s=r?r[a].n:0,c=r?r[a].state:this,l=s<t.length&&o.spec.appendTransaction.call(o,s?t.slice(s):t,c,n);if(l&&n.filterTransaction(l,a)){if(l.setMeta(`appendedTransaction`,e),!r){r=[];for(let e=0;e<this.config.plugins.length;e++)r.push(e<a?{state:n,n:t.length}:{state:this,n:0})}t.push(l),n=n.applyInner(l),i=!0}r&&(r[a]={state:n,n:t.length})}}if(!i)return{state:n,transactions:t}}}applyInner(t){if(!t.before.eq(this.doc))throw RangeError(`Applying a mismatched transaction`);let n=new e(this.config),r=this.config.fields;for(let e=0;e<r.length;e++){let i=r[e];n[i.name]=i.apply(t,this[i.name],this,n)}return n}get tr(){return new Tr(this)}static create(t){let n=new kr(t.doc?t.doc.type.schema:t.schema,t.plugins),r=new e(n);for(let e=0;e<n.fields.length;e++)r[n.fields[e].name]=n.fields[e].init(t,r);return r}reconfigure(t){let n=new kr(this.schema,t.plugins),r=n.fields,i=new e(n);for(let e=0;e<r.length;e++){let n=r[e].name;i[n]=this.hasOwnProperty(n)?this[n]:r[e].init(t,i)}return i}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(e=>e.toJSON())),e&&typeof e==`object`)for(let n in e){if(n==`doc`||n==`selection`)throw RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[n],i=r.spec.state;i&&i.toJSON&&(t[n]=i.toJSON.call(r,this[r.key]))}return t}static fromJSON(t,n,r){if(!n)throw RangeError(`Invalid input for EditorState.fromJSON`);if(!t.schema)throw RangeError(`Required config field 'schema' missing`);let i=new kr(t.schema,t.plugins),a=new e(i);return i.fields.forEach(e=>{if(e.name==`doc`)a.doc=nt.fromJSON(t.schema,n.doc);else if(e.name==`selection`)a.selection=O.fromJSON(a.doc,n.selection);else if(e.name==`storedMarks`)n.storedMarks&&(a.storedMarks=n.storedMarks.map(t.schema.markFromJSON));else{if(r)for(let i in r){let o=r[i],s=o.spec.state;if(o.key==e.name&&s&&s.fromJSON&&Object.prototype.hasOwnProperty.call(n,i)){a[e.name]=s.fromJSON.call(o,t,n[i],a);return}}a[e.name]=e.init(t,a)}}),a}};function jr(e,t,n){for(let r in e){let i=e[r];i instanceof Function?i=i.bind(t):r==`handleDOMEvents`&&(i=jr(i,t,{})),n[r]=i}return n}var j=class{constructor(e){this.spec=e,this.props={},e.props&&jr(e.props,this,this.props),this.key=e.key?e.key.key:Nr(`plugin`)}getState(e){return e[this.key]}},Mr=Object.create(null);function Nr(e){return e in Mr?e+`$`+ ++Mr[e]:(Mr[e]=0,e+`$`)}var Pr=class{constructor(e=`key`){this.key=Nr(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}},Fr=(e,t)=>e.selection.empty?!1:(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function Ir(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`backward`,e):n.parentOffset>0)?null:n}var Lr=(e,t,n)=>{let r=Ir(e,n);if(!r)return!1;let i=Ur(r);if(!i){let n=r.blockRange(),i=n&&En(n);return i==null?!1:(t&&t(e.tr.lift(n,i).scrollIntoView()),!0)}let a=i.nodeBefore;if(si(e,i,t,-1))return!0;if(r.parent.content.size==0&&(Vr(a,`end`)||A.isSelectable(a)))for(let n=r.depth;;n--){let o=qn(e.doc,r.before(n),r.after(n),D.empty);if(o&&o.slice.size<o.to-o.from){if(t){let n=e.tr.step(o);n.setSelection(Vr(a,`end`)?O.findFrom(n.doc.resolve(n.mapping.map(i.pos,-1)),-1):A.create(n.doc,i.pos-a.nodeSize)),t(n.scrollIntoView())}return!0}if(n==1||r.node(n-1).childCount>1)break}return a.isAtom&&i.depth==r.depth-1?(t&&t(e.tr.delete(i.pos-a.nodeSize,i.pos).scrollIntoView()),!0):!1},Rr=(e,t,n)=>{let r=Ir(e,n);if(!r)return!1;let i=Ur(r);return i?Br(e,i,t):!1},zr=(e,t,n)=>{let r=Wr(e,n);if(!r)return!1;let i=qr(r);return i?Br(e,i,t):!1};function Br(e,t,n){let r=t.nodeBefore,i=t.pos-1;for(;!r.isTextblock;i--){if(r.type.spec.isolating)return!1;let e=r.lastChild;if(!e)return!1;r=e}let a=t.nodeAfter,o=t.pos+1;for(;!a.isTextblock;o++){if(a.type.spec.isolating)return!1;let e=a.firstChild;if(!e)return!1;a=e}let s=qn(e.doc,i,o,D.empty);if(!s||s.from!=i||s instanceof yn&&s.slice.size>=o-i)return!1;if(n){let t=e.tr.step(s);t.setSelection(k.create(t.doc,i)),n(t.scrollIntoView())}return!0}function Vr(e,t,n=!1){for(let r=e;r;r=t==`start`?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&r.childCount!=1)return!1}return!1}var Hr=(e,t,n)=>{let{$head:r,empty:i}=e.selection,a=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`backward`,e):r.parentOffset>0)return!1;a=Ur(r)}let o=a&&a.nodeBefore;return!o||!A.isSelectable(o)?!1:(t&&t(e.tr.setSelection(A.create(e.doc,a.pos-o.nodeSize)).scrollIntoView()),!0)};function Ur(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){if(e.index(t)>0)return e.doc.resolve(e.before(t+1));if(e.node(t).type.spec.isolating)break}return null}function Wr(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`forward`,e):n.parentOffset<n.parent.content.size)?null:n}var Gr=(e,t,n)=>{let r=Wr(e,n);if(!r)return!1;let i=qr(r);if(!i)return!1;let a=i.nodeAfter;if(si(e,i,t,1))return!0;if(r.parent.content.size==0&&(Vr(a,`start`)||A.isSelectable(a))){let n=qn(e.doc,r.before(),r.after(),D.empty);if(n&&n.slice.size<n.to-n.from){if(t){let r=e.tr.step(n);r.setSelection(Vr(a,`start`)?O.findFrom(r.doc.resolve(r.mapping.map(i.pos)),1):A.create(r.doc,r.mapping.map(i.pos))),t(r.scrollIntoView())}return!0}}return a.isAtom&&i.depth==r.depth-1?(t&&t(e.tr.delete(i.pos,i.pos+a.nodeSize).scrollIntoView()),!0):!1},Kr=(e,t,n)=>{let{$head:r,empty:i}=e.selection,a=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`forward`,e):r.parentOffset<r.parent.content.size)return!1;a=qr(r)}let o=a&&a.nodeAfter;return!o||!A.isSelectable(o)?!1:(t&&t(e.tr.setSelection(A.create(e.doc,a.pos)).scrollIntoView()),!0)};function qr(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){let n=e.node(t);if(e.index(t)+1<n.childCount)return e.doc.resolve(e.after(t+1));if(n.type.spec.isolating)break}return null}var Jr=(e,t)=>{let n=e.selection,r=n instanceof A,i;if(r){if(n.node.isTextblock||!Bn(e.doc,n.from))return!1;i=n.from}else if(i=Un(e.doc,n.from,-1),i==null)return!1;if(t){let n=e.tr.join(i);r&&n.setSelection(A.create(n.doc,i-e.doc.resolve(i).nodeBefore.nodeSize)),t(n.scrollIntoView())}return!0},Yr=(e,t)=>{let n=e.selection,r;if(n instanceof A){if(n.node.isTextblock||!Bn(e.doc,n.to))return!1;r=n.to}else if(r=Un(e.doc,n.to,1),r==null)return!1;return t&&t(e.tr.join(r).scrollIntoView()),!0},Xr=(e,t)=>{let{$from:n,$to:r}=e.selection,i=n.blockRange(r),a=i&&En(i);return a==null?!1:(t&&t(e.tr.lift(i,a).scrollIntoView()),!0)},Zr=(e,t)=>{let{$head:n,$anchor:r}=e.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(t&&t(e.tr.insertText(`
50
+ `).scrollIntoView()),!0)};function Qr(e){for(let t=0;t<e.edgeCount;t++){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}var $r=(e,t)=>{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),a=n.indexAfter(-1),o=Qr(i.contentMatchAt(a));if(!o||!i.canReplaceWith(a,a,o))return!1;if(t){let r=n.after(),i=e.tr.replaceWith(r,r,o.createAndFill());i.setSelection(O.near(i.doc.resolve(r),1)),t(i.scrollIntoView())}return!0},ei=(e,t)=>{let n=e.selection,{$from:r,$to:i}=n;if(n instanceof vr||r.parent.inlineContent||i.parent.inlineContent)return!1;let a=Qr(i.parent.contentMatchAt(i.indexAfter()));if(!a||!a.isTextblock)return!1;if(t){let n=(!r.parentOffset&&i.index()<i.parent.childCount?r:i).pos,o=e.tr.insert(n,a.createAndFill());o.setSelection(k.create(o.doc,n+1)),t(o.scrollIntoView())}return!0},ti=(e,t)=>{let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(Rn(e.doc,r))return t&&t(e.tr.split(r).scrollIntoView()),!0}let r=n.blockRange(),i=r&&En(r);return i==null?!1:(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)};function ni(e){return(t,n)=>{let{$from:r,$to:i}=t.selection;if(t.selection instanceof A&&t.selection.node.isBlock)return!r.parentOffset||!Rn(t.doc,r.pos)?!1:(n&&n(t.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let a=[],o,s,c=!1,l=!1;for(let t=r.depth;;t--)if(r.node(t).isBlock){c=r.end(t)==r.pos+(r.depth-t),l=r.start(t)==r.pos-(r.depth-t),s=Qr(r.node(t-1).contentMatchAt(r.indexAfter(t-1)));let n=e&&e(i.parent,c,r);a.unshift(n||(c&&s?{type:s}:null)),o=t;break}else{if(t==1)return!1;a.unshift(null)}let u=t.tr;(t.selection instanceof k||t.selection instanceof vr)&&u.deleteSelection();let d=u.mapping.map(r.pos),f=Rn(u.doc,d,a.length,a);if(f||=(a[0]=s?{type:s}:null,Rn(u.doc,d,a.length,a)),!f)return!1;if(u.split(d,a.length,a),!c&&l&&r.node(o).type!=s){let e=u.mapping.map(r.before(o)),t=u.doc.resolve(e);s&&r.node(o-1).canReplaceWith(t.index(),t.index()+1,s)&&u.setNodeMarkup(u.mapping.map(r.before(o)),s)}return n&&n(u.scrollIntoView()),!0}}var ri=ni(),ii=(e,t)=>{let{$from:n,to:r}=e.selection,i,a=n.sharedDepth(r);return a==0?!1:(i=n.before(a),t&&t(e.tr.setSelection(A.create(e.doc,i))),!0)},ai=(e,t)=>(t&&t(e.tr.setSelection(new vr(e.doc))),!0);function oi(e,t,n){let r=t.nodeBefore,i=t.nodeAfter,a=t.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&t.parent.canReplace(a-1,a)?(n&&n(e.tr.delete(t.pos-r.nodeSize,t.pos).scrollIntoView()),!0):!t.parent.canReplace(a,a+1)||!(i.isTextblock||Bn(e.doc,t.pos))?!1:(n&&n(e.tr.join(t.pos).scrollIntoView()),!0)}function si(e,t,n,r){let i=t.nodeBefore,a=t.nodeAfter,o,s,c=i.type.spec.isolating||a.type.spec.isolating;if(!c&&oi(e,t,n))return!0;let l=!c&&t.parent.canReplace(t.index(),t.index()+1);if(l&&(o=(s=i.contentMatchAt(i.childCount)).findWrapping(a.type))&&s.matchType(o[0]||a.type).validEnd){if(n){let r=t.pos+a.nodeSize,s=E.empty;for(let e=o.length-1;e>=0;e--)s=E.from(o[e].create(null,s));s=E.from(i.copy(s));let c=e.tr.step(new bn(t.pos-1,r,t.pos,r,new D(s,1,0),o.length,!0)),l=c.doc.resolve(r+2*o.length);l.nodeAfter&&l.nodeAfter.type==i.type&&Bn(c.doc,l.pos)&&c.join(l.pos),n(c.scrollIntoView())}return!0}let u=a.type.spec.isolating||r>0&&c?null:O.findFrom(t,1),d=u&&u.$from.blockRange(u.$to),f=d&&En(d);if(f!=null&&f>=t.depth)return n&&n(e.tr.lift(d,f).scrollIntoView()),!0;if(l&&Vr(a,`start`,!0)&&Vr(i,`end`)){let r=i,o=[];for(;o.push(r),!r.isTextblock;)r=r.lastChild;let s=a,c=1;for(;!s.isTextblock;s=s.firstChild)c++;if(r.canReplace(r.childCount,r.childCount,s.content)){if(n){let r=E.empty;for(let e=o.length-1;e>=0;e--)r=E.from(o[e].copy(r));n(e.tr.step(new bn(t.pos-o.length,t.pos+a.nodeSize,t.pos+c,t.pos+a.nodeSize-c,new D(r,o.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function ci(e){return function(t,n){let r=t.selection,i=e<0?r.$from:r.$to,a=i.depth;for(;i.node(a).isInline;){if(!a)return!1;a--}return i.node(a).isTextblock?(n&&n(t.tr.setSelection(k.create(t.doc,e<0?i.start(a):i.end(a)))),!0):!1}}var li=ci(-1),ui=ci(1);function di(e,t=null){return function(n,r){let{$from:i,$to:a}=n.selection,o=i.blockRange(a),s=o&&On(o,e,t);return s?(r&&r(n.tr.wrap(o,s).scrollIntoView()),!0):!1}}function fi(e,t=null){return function(n,r){let i=!1;for(let r=0;r<n.selection.ranges.length&&!i;r++){let{$from:{pos:a},$to:{pos:o}}=n.selection.ranges[r];n.doc.nodesBetween(a,o,(r,a)=>{if(i)return!1;if(!(!r.isTextblock||r.hasMarkup(e,t)))if(r.type==e)i=!0;else{let t=n.doc.resolve(a),r=t.index();i=t.parent.canReplaceWith(r,r+1,e)}})}if(!i)return!1;if(r){let i=n.tr;for(let r=0;r<n.selection.ranges.length;r++){let{$from:{pos:a},$to:{pos:o}}=n.selection.ranges[r];i.setBlockType(a,o,e,t)}r(i.scrollIntoView())}return!0}}function pi(...e){return function(t,n,r){for(let i=0;i<e.length;i++)if(e[i](t,n,r))return!0;return!1}}var mi=pi(Fr,Lr,Hr),hi=pi(Fr,Gr,Kr),gi={Enter:pi(Zr,ei,ti,ri),"Mod-Enter":$r,Backspace:mi,"Mod-Backspace":mi,"Shift-Backspace":mi,Delete:hi,"Mod-Delete":hi,"Mod-a":ai},_i={"Ctrl-h":gi.Backspace,"Alt-Backspace":gi[`Mod-Backspace`],"Ctrl-d":gi.Delete,"Ctrl-Alt-Backspace":gi[`Mod-Delete`],"Alt-Delete":gi[`Mod-Delete`],"Alt-d":gi[`Mod-Delete`],"Ctrl-a":li,"Ctrl-e":ui};for(let e in gi)_i[e]=gi[e];typeof navigator<`u`?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<`u`&&os.platform&&os.platform();function vi(e,t=null){return function(n,r){let{$from:i,$to:a}=n.selection,o=i.blockRange(a);if(!o)return!1;let s=r?n.tr:null;return yi(s,o,e,t)?(r&&r(s.scrollIntoView()),!0):!1}}function yi(e,t,n,r=null){let i=!1,a=t,o=t.$from.doc;if(t.depth>=2&&t.$from.node(t.depth-1).type.compatibleContent(n)&&t.startIndex==0){if(t.$from.index(t.depth-1)==0)return!1;let e=o.resolve(t.start-2);a=new et(e,e,t.depth),t.endIndex<t.parent.childCount&&(t=new et(t.$from,o.resolve(t.$to.end(t.depth)),t.depth)),i=!0}let s=On(a,n,r,t);return s?(e&&bi(e,t,s,i,n),!0):!1}function bi(e,t,n,r,i){let a=E.empty;for(let e=n.length-1;e>=0;e--)a=E.from(n[e].type.create(n[e].attrs,a));e.step(new bn(t.start-(r?2:0),t.end,t.start,t.end,new D(a,0,0),n.length,!0));let o=0;for(let e=0;e<n.length;e++)n[e].type==i&&(o=e+1);let s=n.length-o,c=t.start+n.length-(r?2:0),l=t.parent;for(let n=t.startIndex,r=t.endIndex,i=!0;n<r;n++,i=!1)!i&&Rn(e.doc,c,s)&&(e.split(c,s),c+=2*s),c+=l.child(n).nodeSize;return e}function xi(e){return function(t,n){let{$from:r,$to:i}=t.selection,a=r.blockRange(i,t=>t.childCount>0&&t.firstChild.type==e);return a?n?r.node(a.depth-1).type==e?Si(t,n,e,a):Ci(t,n,a):!0:!1}}function Si(e,t,n,r){let i=e.tr,a=r.end,o=r.$to.end(r.depth);a<o&&(i.step(new bn(a-1,o,a,o,new D(E.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new et(i.doc.resolve(r.$from.pos),i.doc.resolve(o),r.depth));let s=En(r);if(s==null)return!1;i.lift(r,s);let c=i.doc.resolve(i.mapping.map(a,-1)-1);return Bn(i.doc,c.pos)&&c.nodeBefore.type==c.nodeAfter.type&&i.join(c.pos),t(i.scrollIntoView()),!0}function Ci(e,t,n){let r=e.tr,i=n.parent;for(let e=n.end,t=n.endIndex-1,a=n.startIndex;t>a;t--)e-=i.child(t).nodeSize,r.delete(e-1,e+1);let a=r.doc.resolve(n.start),o=a.nodeAfter;if(r.mapping.map(n.end)!=n.start+a.nodeAfter.nodeSize)return!1;let s=n.startIndex==0,c=n.endIndex==i.childCount,l=a.node(-1),u=a.index(-1);if(!l.canReplace(u+(s?0:1),u+1,o.content.append(c?E.empty:E.from(i))))return!1;let d=a.pos,f=d+o.nodeSize;return r.step(new bn(d-(s?1:0),f+(c?1:0),d+1,f-1,new D((s?E.empty:E.from(i.copy(E.empty))).append(c?E.empty:E.from(i.copy(E.empty))),s?0:1,c?0:1),s?0:1)),t(r.scrollIntoView()),!0}function wi(e){return function(t,n){let{$from:r,$to:i}=t.selection,a=r.blockRange(i,t=>t.childCount>0&&t.firstChild.type==e);if(!a)return!1;let o=a.startIndex;if(o==0)return!1;let s=a.parent,c=s.child(o-1);if(c.type!=e)return!1;if(n){let r=c.lastChild&&c.lastChild.type==s.type,i=E.from(r?e.create():null),o=new D(E.from(e.create(null,E.from(s.type.create(null,i)))),r?3:1,0),l=a.start,u=a.end;n(t.tr.step(new bn(l-(r?3:1),u,l,u,o,1,!0)).scrollIntoView())}return!0}}var Ti=function(e){for(var t=0;;t++)if(e=e.previousSibling,!e)return t},Ei=function(e){let t=e.assignedSlot||e.parentNode;return t&&t.nodeType==11?t.host:t},Di=null,Oi=function(e,t,n){let r=Di||=document.createRange();return r.setEnd(e,n??e.nodeValue.length),r.setStart(e,t||0),r},ki=function(){Di=null},Ai=function(e,t,n,r){return n&&(Mi(e,t,n,r,-1)||Mi(e,t,n,r,1))},ji=/^(img|br|input|textarea|hr)$/i;function Mi(e,t,n,r,i){for(;;){if(e==n&&t==r)return!0;if(t==(i<0?0:Ni(e))){let n=e.parentNode;if(!n||n.nodeType!=1||Li(e)||ji.test(e.nodeName)||e.contentEditable==`false`)return!1;t=Ti(e)+(i<0?0:1),e=n}else if(e.nodeType==1){let n=e.childNodes[t+(i<0?-1:0)];if(n.nodeType==1&&n.contentEditable==`false`)if(n.pmViewDesc?.ignoreForSelection)t+=i;else return!1;else e=n,t=i<0?Ni(e):0}else return!1}}function Ni(e){return e.nodeType==3?e.nodeValue.length:e.childNodes.length}function Pi(e,t){for(;;){if(e.nodeType==3&&t)return e;if(e.nodeType==1&&t>0){if(e.contentEditable==`false`)return null;e=e.childNodes[t-1],t=Ni(e)}else if(e.parentNode&&!Li(e))t=Ti(e),e=e.parentNode;else return null}}function Fi(e,t){for(;;){if(e.nodeType==3&&t<e.nodeValue.length)return e;if(e.nodeType==1&&t<e.childNodes.length){if(e.contentEditable==`false`)return null;e=e.childNodes[t],t=0}else if(e.parentNode&&!Li(e))t=Ti(e)+1,e=e.parentNode;else return null}}function Ii(e,t,n){for(let r=t==0,i=t==Ni(e);r||i;){if(e==n)return!0;let t=Ti(e);if(e=e.parentNode,!e)return!1;r&&=t==0,i&&=t==Ni(e)}}function Li(e){let t;for(let n=e;n&&!(t=n.pmViewDesc);n=n.parentNode);return t&&t.node&&t.node.isBlock&&(t.dom==e||t.contentDOM==e)}var Ri=function(e){return e.focusNode&&Ai(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function zi(e,t){let n=document.createEvent(`Event`);return n.initEvent(`keydown`,!0,!0),n.keyCode=e,n.key=n.code=t,n}function Bi(e){let t=e.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}function Vi(e,t,n){if(e.caretPositionFromPoint)try{let r=e.caretPositionFromPoint(t,n);if(r)return{node:r.offsetNode,offset:Math.min(Ni(r.offsetNode),r.offset)}}catch{}if(e.caretRangeFromPoint){let r=e.caretRangeFromPoint(t,n);if(r)return{node:r.startContainer,offset:Math.min(Ni(r.startContainer),r.startOffset)}}}var Hi=typeof navigator<`u`?navigator:null,Ui=typeof document<`u`?document:null,Wi=Hi&&Hi.userAgent||``,Gi=/Edge\/(\d+)/.exec(Wi),Ki=/MSIE \d/.exec(Wi),qi=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Wi),Ji=!!(Ki||qi||Gi),Yi=Ki?document.documentMode:qi?+qi[1]:Gi?+Gi[1]:0,Xi=!Ji&&/gecko\/(\d+)/i.test(Wi);Xi&&+(/Firefox\/(\d+)/.exec(Wi)||[0,0])[1];var Zi=!Ji&&/Chrome\/(\d+)/.exec(Wi),Qi=!!Zi,$i=Zi?+Zi[1]:0,ea=!Ji&&!!Hi&&/Apple Computer/.test(Hi.vendor),ta=ea&&(/Mobile\/\w+/.test(Wi)||!!Hi&&Hi.maxTouchPoints>2),na=ta||(Hi?/Mac/.test(Hi.platform):!1),ra=Hi?/Win/.test(Hi.platform):!1,ia=/Android \d/.test(Wi),aa=!!Ui&&`webkitFontSmoothing`in Ui.documentElement.style,oa=aa?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function sa(e){let t=e.defaultView&&e.defaultView.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}function ca(e,t){return typeof e==`number`?e:e[t]}function la(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,r=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*r}}function ua(e,t,n){let r=e.someProp(`scrollThreshold`)||0,i=e.someProp(`scrollMargin`)||5,a=e.dom.ownerDocument;for(let o=n||e.dom;o;){if(o.nodeType!=1){o=Ei(o);continue}let e=o,n=e==a.body,s=n?sa(a):la(e),c=0,l=0;if(t.top<s.top+ca(r,`top`)?l=-(s.top-t.top+ca(i,`top`)):t.bottom>s.bottom-ca(r,`bottom`)&&(l=t.bottom-t.top>s.bottom-s.top?t.top+ca(i,`top`)-s.top:t.bottom-s.bottom+ca(i,`bottom`)),t.left<s.left+ca(r,`left`)?c=-(s.left-t.left+ca(i,`left`)):t.right>s.right-ca(r,`right`)&&(c=t.right-s.right+ca(i,`right`)),c||l)if(n)a.defaultView.scrollBy(c,l);else{let n=e.scrollLeft,r=e.scrollTop;l&&(e.scrollTop+=l),c&&(e.scrollLeft+=c);let i=e.scrollLeft-n,a=e.scrollTop-r;t={left:t.left-i,top:t.top-a,right:t.right-i,bottom:t.bottom-a}}let u=n?`fixed`:getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(u))break;o=u==`absolute`?o.offsetParent:Ei(o)}}function da(e){let t=e.dom.getBoundingClientRect(),n=Math.max(0,t.top),r,i;for(let a=(t.left+t.right)/2,o=n+1;o<Math.min(innerHeight,t.bottom);o+=5){let t=e.root.elementFromPoint(a,o);if(!t||t==e.dom||!e.dom.contains(t))continue;let s=t.getBoundingClientRect();if(s.top>=n-20){r=t,i=s.top;break}}return{refDOM:r,refTop:i,stack:fa(e.dom)}}function fa(e){let t=[],n=e.ownerDocument;for(let r=e;r&&(t.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),e!=n);r=Ei(r));return t}function pa({refDOM:e,refTop:t,stack:n}){let r=e?e.getBoundingClientRect().top:0;ma(n,r==0?0:r-t)}function ma(e,t){for(let n=0;n<e.length;n++){let{dom:r,top:i,left:a}=e[n];r.scrollTop!=i+t&&(r.scrollTop=i+t),r.scrollLeft!=a&&(r.scrollLeft=a)}}var ha=null;function ga(e){if(e.setActive)return e.setActive();if(ha)return e.focus(ha);let t=fa(e);e.focus(ha==null?{get preventScroll(){return ha={preventScroll:!0},!0}}:void 0),ha||(ha=!1,ma(t,0))}function _a(e,t){let n,r=2e8,i,a=0,o=t.top,s=t.top,c,l;for(let u=e.firstChild,d=0;u;u=u.nextSibling,d++){let e;if(u.nodeType==1)e=u.getClientRects();else if(u.nodeType==3)e=Oi(u).getClientRects();else continue;for(let f=0;f<e.length;f++){let p=e[f];if(p.top<=o&&p.bottom>=s){o=Math.max(p.bottom,o),s=Math.min(p.top,s);let e=p.left>t.left?p.left-t.left:p.right<t.left?t.left-p.right:0;if(e<r){n=u,r=e,i=e&&n.nodeType==3?{left:p.right<t.left?p.right:p.left,top:t.top}:t,u.nodeType==1&&e&&(a=d+(t.left>=(p.left+p.right)/2?1:0));continue}}else p.top>t.top&&!c&&p.left<=t.left&&p.right>=t.left&&(c=u,l={left:Math.max(p.left,Math.min(p.right,t.left)),top:p.top});!n&&(t.left>=p.right&&t.top>=p.top||t.left>=p.left&&t.top>=p.bottom)&&(a=d+1)}}return!n&&c&&(n=c,i=l,r=0),n&&n.nodeType==3?va(n,i):!n||r&&n.nodeType==1?{node:e,offset:a}:_a(n,i)}function va(e,t){let n=e.nodeValue.length,r=document.createRange(),i;for(let a=0;a<n;a++){r.setEnd(e,a+1),r.setStart(e,a);let n=Ea(r,1);if(n.top!=n.bottom&&ya(t,n)){i={node:e,offset:a+(t.left>=(n.left+n.right)/2?1:0)};break}}return r.detach(),i||{node:e,offset:0}}function ya(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function ba(e,t){let n=e.parentNode;return n&&/^li$/i.test(n.nodeName)&&t.left<e.getBoundingClientRect().left?n:e}function xa(e,t,n){let{node:r,offset:i}=_a(t,n),a=-1;if(r.nodeType==1&&!r.firstChild){let e=r.getBoundingClientRect();a=e.left!=e.right&&n.left>(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(r,i,a)}function Sa(e,t,n,r){let i=-1;for(let n=t,a=!1;n!=e.dom;){let t=e.docView.nearestDesc(n,!0),o;if(!t)return null;if(t.dom.nodeType==1&&(t.node.isBlock&&t.parent||!t.contentDOM)&&((o=t.dom.getBoundingClientRect()).width||o.height)&&(t.node.isBlock&&t.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(t.dom.nodeName)&&(!a&&o.left>r.left||o.top>r.top?i=t.posBefore:(!a&&o.right<r.left||o.bottom<r.top)&&(i=t.posAfter),a=!0),!t.contentDOM&&i<0&&!t.node.isText))return(t.node.isBlock?r.top<(o.top+o.bottom)/2:r.left<(o.left+o.right)/2)?t.posBefore:t.posAfter;n=t.dom.parentNode}return i>-1?i:e.docView.posFromDOM(t,n,-1)}function Ca(e,t,n){let r=e.childNodes.length;if(r&&n.top<n.bottom)for(let i=Math.max(0,Math.min(r-1,Math.floor(r*(t.top-n.top)/(n.bottom-n.top))-2)),a=i;;){let n=e.childNodes[a];if(n.nodeType==1){let e=n.getClientRects();for(let r=0;r<e.length;r++){let i=e[r];if(ya(t,i))return Ca(n,t,i)}}if((a=(a+1)%r)==i)break}return e}function wa(e,t){let n=e.dom.ownerDocument,r,i=0,a=Vi(n,t.left,t.top);a&&({node:r,offset:i}=a);let o=(e.root.elementFromPoint?e.root:n).elementFromPoint(t.left,t.top),s;if(!o||!e.dom.contains(o.nodeType==1?o:o.parentNode)){let n=e.dom.getBoundingClientRect();if(!ya(t,n)||(o=Ca(e.dom,t,n),!o))return null}if(ea)for(let e=o;r&&e;e=Ei(e))e.draggable&&(r=void 0);if(o=ba(o,t),r){if(Xi&&r.nodeType==1&&(i=Math.min(i,r.childNodes.length),i<r.childNodes.length)){let e=r.childNodes[i],n;e.nodeName==`IMG`&&(n=e.getBoundingClientRect()).right<=t.left&&n.bottom>t.top&&i++}let n;aa&&i&&r.nodeType==1&&(n=r.childNodes[i-1]).nodeType==1&&n.contentEditable==`false`&&n.getBoundingClientRect().top>=t.top&&i--,r==e.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&t.top>r.lastChild.getBoundingClientRect().bottom?s=e.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!=`BR`)&&(s=Sa(e,r,i,t))}s??=xa(e,o,t);let c=e.docView.nearestDesc(o,!0);return{pos:s,inside:c?c.posAtStart-c.border:-1}}function Ta(e){return e.top<e.bottom||e.left<e.right}function Ea(e,t){let n=e.getClientRects();if(n.length){let e=n[t<0?0:n.length-1];if(Ta(e))return e}return Array.prototype.find.call(n,Ta)||e.getBoundingClientRect()}var Da=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function Oa(e,t,n){let{node:r,offset:i,atom:a}=e.docView.domFromPos(t,n<0?-1:1),o=aa||Xi;if(r.nodeType==3)if(o&&(Da.test(r.nodeValue)||(n<0?!i:i==r.nodeValue.length))){let e=Ea(Oi(r,i,i),n);if(Xi&&i&&/\s/.test(r.nodeValue[i-1])&&i<r.nodeValue.length){let t=Ea(Oi(r,i-1,i-1),-1);if(t.top==e.top){let n=Ea(Oi(r,i,i+1),-1);if(n.top!=e.top)return ka(n,n.left<t.left)}}return e}else{let e=i,t=i,a=n<0?1:-1;return n<0&&!i?(t++,a=-1):n>=0&&i==r.nodeValue.length?(e--,a=1):n<0?e--:t++,ka(Ea(Oi(r,e,t),a),a<0)}if(!e.state.doc.resolve(t-(a||0)).parent.inlineContent){if(a==null&&i&&(n<0||i==Ni(r))){let e=r.childNodes[i-1];if(e.nodeType==1)return Aa(e.getBoundingClientRect(),!1)}if(a==null&&i<Ni(r)){let e=r.childNodes[i];if(e.nodeType==1)return Aa(e.getBoundingClientRect(),!0)}return Aa(r.getBoundingClientRect(),n>=0)}if(a==null&&i&&(n<0||i==Ni(r))){let e=r.childNodes[i-1],t=e.nodeType==3?Oi(e,Ni(e)-(o?0:1)):e.nodeType==1&&(e.nodeName!=`BR`||!e.nextSibling)?e:null;if(t)return ka(Ea(t,1),!1)}if(a==null&&i<Ni(r)){let e=r.childNodes[i];for(;e.pmViewDesc&&e.pmViewDesc.ignoreForCoords;)e=e.nextSibling;let t=e?e.nodeType==3?Oi(e,0,o?0:1):e.nodeType==1?e:null:null;if(t)return ka(Ea(t,-1),!0)}return ka(Ea(r.nodeType==3?Oi(r):r,-n),n>=0)}function ka(e,t){if(e.width==0)return e;let n=t?e.left:e.right;return{top:e.top,bottom:e.bottom,left:n,right:n}}function Aa(e,t){if(e.height==0)return e;let n=t?e.top:e.bottom;return{top:n,bottom:n,left:e.left,right:e.right}}function ja(e,t,n){let r=e.state,i=e.root.activeElement;r!=t&&e.updateState(t),i!=e.dom&&e.focus();try{return n()}finally{r!=t&&e.updateState(r),i!=e.dom&&i&&i.focus()}}function Ma(e,t,n){let r=t.selection,i=n==`up`?r.$from:r.$to;return ja(e,t,()=>{let{node:t}=e.docView.domFromPos(i.pos,n==`up`?-1:1);for(;;){let n=e.docView.nearestDesc(t,!0);if(!n)break;if(n.node.isBlock){t=n.contentDOM||n.dom;break}t=n.dom.parentNode}let r=Oa(e,i.pos,1);for(let e=t.firstChild;e;e=e.nextSibling){let t;if(e.nodeType==1)t=e.getClientRects();else if(e.nodeType==3)t=Oi(e,0,e.nodeValue.length).getClientRects();else continue;for(let e=0;e<t.length;e++){let i=t[e];if(i.bottom>i.top+1&&(n==`up`?r.top-i.top>(i.bottom-r.top)*2:i.bottom-r.bottom>(r.bottom-i.top)*2))return!1}}return!0})}var Na=/[\u0590-\u08ac]/;function Pa(e,t,n){let{$head:r}=t.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,a=!i,o=i==r.parent.content.size,s=e.domSelection();return s?!Na.test(r.parent.textContent)||!s.modify?n==`left`||n==`backward`?a:o:ja(e,t,()=>{let{focusNode:t,focusOffset:i,anchorNode:a,anchorOffset:o}=e.domSelectionRange(),c=s.caretBidiLevel;s.modify(`move`,n,`character`);let l=r.depth?e.docView.domAfterPos(r.before()):e.dom,{focusNode:u,focusOffset:d}=e.domSelectionRange(),f=u&&!l.contains(u.nodeType==1?u:u.parentNode)||t==u&&i==d;try{s.collapse(a,o),t&&(t!=a||i!=o)&&s.extend&&s.extend(t,i)}catch{}return c!=null&&(s.caretBidiLevel=c),f}):r.pos==r.start()||r.pos==r.end()}var Fa=null,Ia=null,La=!1;function Ra(e,t,n){return Fa==t&&Ia==n?La:(Fa=t,Ia=n,La=n==`up`||n==`down`?Ma(e,t,n):Pa(e,t,n))}var za=0,Ba=1,Va=2,Ha=3,Ua=class{constructor(e,t,n,r){this.parent=e,this.children=t,this.dom=n,this.contentDOM=r,this.dirty=za,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let t=0,n=this.posAtStart;;t++){let r=this.children[t];if(r==e)return n;n+=r.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,t,n){if(this.contentDOM&&this.contentDOM.contains(e.nodeType==1?e:e.parentNode))if(n<0){let n,r;if(e==this.contentDOM)n=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.previousSibling}for(;n&&!((r=n.pmViewDesc)&&r.parent==this);)n=n.previousSibling;return n?this.posBeforeChild(r)+r.size:this.posAtStart}else{let n,r;if(e==this.contentDOM)n=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.nextSibling}for(;n&&!((r=n.pmViewDesc)&&r.parent==this);)n=n.nextSibling;return n?this.posBeforeChild(r):this.posAtEnd}let r;if(e==this.dom&&this.contentDOM)r=t>Ti(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))r=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!1;break}if(t.previousSibling)break}if(r==null&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!0;break}if(t.nextSibling)break}}return r??n>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,r=e;r;r=r.parentNode){let i=this.getDesc(r),a;if(i&&(!t||i.node))if(n&&(a=i.nodeDOM)&&!(a.nodeType==1?a.contains(e.nodeType==1?e:e.parentNode):a==e))n=!1;else return i}}getDesc(e){let t=e.pmViewDesc;for(let e=t;e;e=e.parent)if(e==this)return t}posFromDOM(e,t,n){for(let r=e;r;r=r.parentNode){let i=this.getDesc(r);if(i)return i.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let r=this.children[t],i=n+r.size;if(n==e&&i!=n){for(;!r.border&&r.children.length;)for(let e=0;e<r.children.length;e++){let t=r.children[e];if(t.size){r=t;break}}return r}if(e<i)return r.descAt(e-n-r.border);n=i}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n=0,r=0;for(let t=0;n<this.children.length;n++){let i=this.children[n],a=t+i.size;if(a>e||i instanceof Xa){r=e-t;break}t=a}if(r)return this.children[n].domFromPos(r-this.children[n].border,t);for(let e;n&&!(e=this.children[n-1]).size&&e instanceof Wa&&e.side>=0;n--);if(t<=0){let e,r=!0;for(;e=n?this.children[n-1]:null,!(!e||e.dom.parentNode==this.contentDOM);n--,r=!1);return e&&t&&r&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?Ti(e.dom)+1:0}}else{let e,r=!0;for(;e=n<this.children.length?this.children[n]:null,!(!e||e.dom.parentNode==this.contentDOM);n++,r=!1);return e&&r&&!e.border&&!e.domAtom?e.domFromPos(0,t):{node:this.contentDOM,offset:e?Ti(e.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,n=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let r=-1,i=-1;for(let a=n,o=0;;o++){let n=this.children[o],s=a+n.size;if(r==-1&&e<=s){let i=a+n.border;if(e>=i&&t<=s-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,i);e=a;for(let t=o;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){r=Ti(n.dom)+1;break}e-=n.size}r==-1&&(r=0)}if(r>-1&&(s>t||o==this.children.length-1)){t=s;for(let e=o+1;e<this.children.length;e++){let n=this.children[e];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(-1)){i=Ti(n.dom);break}t+=n.size}i==-1&&(i=this.contentDOM.childNodes.length);break}a=s}return{node:this.contentDOM,from:e,to:t,fromOffset:r,toOffset:i}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return t.size==0||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:n}=this.domFromPos(e,0);if(t.nodeType!=1||n==t.childNodes.length)throw RangeError(`No node after pos `+e);return t.childNodes[n]}setSelection(e,t,n,r=!1){let i=Math.min(e,t),a=Math.max(e,t);for(let o=0,s=0;o<this.children.length;o++){let c=this.children[o],l=s+c.size;if(i>s&&a<l)return c.setSelection(e-s-c.border,t-s-c.border,n,r);s=l}let o=this.domFromPos(e,e?-1:1),s=t==e?o:this.domFromPos(t,t?-1:1),c=n.root.getSelection(),l=n.domSelectionRange(),u=!1;if((Xi||ea)&&e==t){let{node:e,offset:t}=o;if(e.nodeType==3){if(u=!!(t&&e.nodeValue[t-1]==`
51
+ `),u&&t==e.nodeValue.length)for(let t=e,n;t;t=t.parentNode){if(n=t.nextSibling){n.nodeName==`BR`&&(o=s={node:n.parentNode,offset:Ti(n)+1});break}let e=t.pmViewDesc;if(e&&e.node&&e.node.isBlock)break}}else{let n=e.childNodes[t-1];u=n&&(n.nodeName==`BR`||n.contentEditable==`false`)}}if(Xi&&l.focusNode&&l.focusNode!=s.node&&l.focusNode.nodeType==1){let e=l.focusNode.childNodes[l.focusOffset];e&&e.contentEditable==`false`&&(r=!0)}if(!(r||u&&ea)&&Ai(o.node,o.offset,l.anchorNode,l.anchorOffset)&&Ai(s.node,s.offset,l.focusNode,l.focusOffset))return;let d=!1;if((c.extend||e==t)&&!(u&&Xi)){c.collapse(o.node,o.offset);try{e!=t&&c.extend(s.node,s.offset),d=!0}catch{}}if(!d){if(e>t){let e=o;o=s,s=e}let n=document.createRange();n.setEnd(s.node,s.offset),n.setStart(o.node,o.offset),c.removeAllRanges(),c.addRange(n)}}ignoreMutation(e){return!this.contentDOM&&e.type!=`selection`}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,r=0;r<this.children.length;r++){let i=this.children[r],a=n+i.size;if(n==a?e<=a&&t>=n:e<a&&t>n){let r=n+i.border,o=a-i.border;if(e>=r&&t<=o){this.dirty=e==n||t==a?Va:Ba,e==r&&t==o&&(i.contentLost||i.dom.parentNode!=this.contentDOM)?i.dirty=Ha:i.markDirty(e-r,t-r);return}else i.dirty=i.dom==i.contentDOM&&i.dom.parentNode==this.contentDOM&&!i.children.length?Va:Ha}n=a}this.dirty=Va}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?Va:Ba;t.dirty<n&&(t.dirty=n)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}},Wa=class extends Ua{constructor(e,t,n,r){let i,a=t.type.toDOM;if(typeof a==`function`&&(a=a(n,()=>{if(!i)return r;if(i.parent)return i.parent.posBeforeChild(i)})),!t.type.spec.raw){if(a.nodeType!=1){let e=document.createElement(`span`);e.appendChild(a),a=e}a.contentEditable=`false`,a.classList.add(`ProseMirror-widget`)}super(e,[],a,null),this.widget=t,this.widget=t,i=this}matchesWidget(e){return this.dirty==za&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!=`selection`||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}},Ga=class extends Ua{constructor(e,t,n,r){super(e,[],t,null),this.textDOM=n,this.text=r}get size(){return this.text.length}localPosFromDOM(e,t){return e==this.textDOM?this.posAtStart+t:this.posAtStart+(t?this.size:0)}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type===`characterData`&&e.target.nodeValue==e.oldValue}},Ka=class e extends Ua{constructor(e,t,n,r,i){super(e,[],n,r),this.mark=t,this.spec=i}static create(t,n,r,i){let a=i.nodeViews[n.type.name],o=a&&a(n,i,r);return(!o||!o.dom)&&(o=Gt.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new e(t,n,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&Ha||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Ha&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=za){let e=this.parent;for(;!e.node;)e=e.parent;e.dirty<this.dirty&&(e.dirty=this.dirty),this.dirty=za}}slice(t,n,r){let i=e.create(this.parent,this.mark,!0,r),a=this.children,o=this.size;n<o&&(a=mo(a,n,o,r)),t>0&&(a=mo(a,0,t,r));for(let e=0;e<a.length;e++)a[e].parent=i;return i.children=a,i}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}},qa=class e extends Ua{constructor(e,t,n,r,i,a,o,s,c){super(e,[],i,a),this.node=t,this.outerDeco=n,this.innerDeco=r,this.nodeDOM=o}static create(t,n,r,i,a,o){let s=a.nodeViews[n.type.name],c,l=s&&s(n,a,()=>{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),u=l&&l.dom,d=l&&l.contentDOM;if(n.isText){if(!u)u=document.createTextNode(n.text);else if(u.nodeType!=3)throw RangeError(`Text must be rendered as a DOM text node`)}else if(!u){let e=Gt.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs);({dom:u,contentDOM:d}=e)}!d&&!n.isText&&u.nodeName!=`BR`&&(u.hasAttribute(`contenteditable`)||(u.contentEditable=`false`),n.type.spec.draggable&&(u.draggable=!0));let f=u;return u=io(u,r,n),l?c=new Za(t,n,r,i,u,d||null,f,l,a,o+1):n.isText?new Ya(t,n,r,i,u,f,a):new e(t,n,r,i,u,d||null,f,a,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace==`pre`&&(e.preserveWhitespace=`full`),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>E.empty)}return e}matchesNode(e,t,n){return this.dirty==za&&e.eq(this.node)&&ao(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let n=this.node.inlineContent,r=t,i=e.composing?this.localCompositionInfo(e,t):null,a=i&&i.pos>-1?i:null,o=i&&i.pos<0,s=new so(this,a&&a.node,e);uo(this.node,this.innerDeco,(t,i,a)=>{t.spec.marks?s.syncToMarks(t.spec.marks,n,e,i):t.type.side>=0&&!a&&s.syncToMarks(i==this.node.childCount?Ie.none:this.node.child(i).marks,n,e,i),s.placeWidget(t,e,r)},(t,a,c,l)=>{s.syncToMarks(t.marks,n,e,l);let u;s.findNodeMatch(t,a,c,l)||o&&e.state.selection.from>r&&e.state.selection.to<r+t.nodeSize&&(u=s.findIndexWithChild(i.node))>-1&&s.updateNodeAt(t,a,c,u,e)||s.updateNextNode(t,a,c,e,l,r)||s.addNode(t,a,c,e,r),r+=t.nodeSize}),s.syncToMarks([],n,e,0),this.node.isTextblock&&s.addTextblockHacks(),s.destroyRest(),(s.changed||this.dirty==Va)&&(a&&this.protectLocalComposition(e,a),Qa(this.contentDOM,this.children,e),ta&&fo(this.dom))}localCompositionInfo(e,t){let{from:n,to:r}=e.state.selection;if(!(e.state.selection instanceof k)||n<t||r>t+this.node.content.size)return null;let i=e.input.compositionNode;if(!i||!this.dom.contains(i.parentNode))return null;if(this.node.inlineContent){let e=i.nodeValue,a=po(this.node.content,e,n-t,r-t);return a<0?null:{node:i,pos:a,text:e}}else return{node:i,pos:-1,text:``}}protectLocalComposition(e,{node:t,pos:n,text:r}){if(this.getDesc(t))return;let i=t;for(;i.parentNode!=this.contentDOM;i=i.parentNode){for(;i.previousSibling;)i.parentNode.removeChild(i.previousSibling);for(;i.nextSibling;)i.parentNode.removeChild(i.nextSibling);i.pmViewDesc&&=void 0}let a=new Ga(this,i,t,r);e.input.compositionNodes.push(a),this.children=mo(this.children,n,n+r.length,e,a)}update(e,t,n,r){return this.dirty==Ha||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,n,r),!0)}updateInner(e,t,n,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=za}updateOuterDeco(e){if(ao(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,n=this.dom;this.dom=no(this.dom,this.nodeDOM,to(this.outerDeco,this.node,t),to(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.add(`ProseMirror-selectednode`),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove(`ProseMirror-selectednode`),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute(`draggable`))}get domAtom(){return this.node.isAtom}};function Ja(e,t,n,r,i){io(r,t,e);let a=new qa(void 0,e,t,n,r,r,r,i,0);return a.contentDOM&&a.updateChildren(i,0),a}var Ya=class e extends qa{constructor(e,t,n,r,i,a,o){super(e,t,n,r,i,null,a,o,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,r){return this.dirty==Ha||this.dirty!=za&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=za||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=za,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return e.type!=`characterData`&&e.type!=`selection`}slice(t,n,r){let i=this.node.cut(t,n),a=document.createTextNode(i.text);return new e(this.parent,i,this.outerDeco,this.innerDeco,a,a,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Ha)}get domAtom(){return!1}isText(e){return this.node.text==e}},Xa=class extends Ua{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==za&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName==`IMG`}},Za=class extends qa{constructor(e,t,n,r,i,a,o,s,c,l){super(e,t,n,r,i,a,o,c,l),this.spec=s}update(e,t,n,r){if(this.dirty==Ha)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let i=this.spec.update(e,t,n);return i&&this.updateInner(e,t,n,r),i}else if(!this.contentDOM&&!e.isLeaf)return!1;else return super.update(e,t,n,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,r){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function Qa(e,t,n){let r=e.firstChild,i=!1;for(let a=0;a<t.length;a++){let o=t[a],s=o.dom;if(s.parentNode==e){for(;s!=r;)r=oo(r),i=!0;r=r.nextSibling}else i=!0,e.insertBefore(s,r);if(o instanceof Ka){let t=r?r.previousSibling:e.lastChild;Qa(o.contentDOM,o.children,n),r=t?t.nextSibling:e.firstChild}}for(;r;)r=oo(r),i=!0;i&&n.trackWrites==e&&(n.trackWrites=null)}var $a=function(e){e&&(this.nodeName=e)};$a.prototype=Object.create(null);var eo=[new $a];function to(e,t,n){if(e.length==0)return eo;let r=n?eo[0]:new $a,i=[r];for(let a=0;a<e.length;a++){let o=e[a].type.attrs;if(o){o.nodeName&&i.push(r=new $a(o.nodeName));for(let e in o){let a=o[e];a!=null&&(n&&i.length==1&&i.push(r=new $a(t.isInline?`span`:`div`)),e==`class`?r.class=(r.class?r.class+` `:``)+a:e==`style`?r.style=(r.style?r.style+`;`:``)+a:e!=`nodeName`&&(r[e]=a))}}}return i}function no(e,t,n,r){if(n==eo&&r==eo)return t;let i=t;for(let t=0;t<r.length;t++){let a=r[t],o=n[t];if(t){let t;o&&o.nodeName==a.nodeName&&i!=e&&(t=i.parentNode)&&t.nodeName.toLowerCase()==a.nodeName?i=t:(t=document.createElement(a.nodeName),t.pmIsDeco=!0,t.appendChild(i),o=eo[0],i=t)}ro(i,o||eo[0],a)}return i}function ro(e,t,n){for(let r in t)r!=`class`&&r!=`style`&&r!=`nodeName`&&!(r in n)&&e.removeAttribute(r);for(let r in n)r!=`class`&&r!=`style`&&r!=`nodeName`&&n[r]!=t[r]&&e.setAttribute(r,n[r]);if(t.class!=n.class){let r=t.class?t.class.split(` `).filter(Boolean):[],i=n.class?n.class.split(` `).filter(Boolean):[];for(let t=0;t<r.length;t++)i.indexOf(r[t])==-1&&e.classList.remove(r[t]);for(let t=0;t<i.length;t++)r.indexOf(i[t])==-1&&e.classList.add(i[t]);e.classList.length==0&&e.removeAttribute(`class`)}if(t.style!=n.style){if(t.style){let n=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,r;for(;r=n.exec(t.style);)e.style.removeProperty(r[1])}n.style&&(e.style.cssText+=n.style)}}function io(e,t,n){return no(e,e,eo,to(t,n,e.nodeType!=1))}function ao(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].type.eq(t[n].type))return!1;return!0}function oo(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}var so=class{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=co(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let n=e;n<t;n++)this.top.children[n].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,n,r){let i=0,a=this.stack.length>>1,o=Math.min(a,e.length);for(;i<o&&(i==a-1?this.top:this.stack[i+1<<1]).matchesMark(e[i])&&e[i].type.spec.spanning!==!1;)i++;for(;i<a;)this.destroyRest(),this.top.dirty=za,this.index=this.stack.pop(),this.top=this.stack.pop(),a--;for(;a<e.length;){this.stack.push(this.top,this.index+1);let i=-1,o=this.top.children.length;r<this.preMatch.index&&(o=Math.min(this.index+3,o));for(let t=this.index;t<o;t++){let n=this.top.children[t];if(n.matchesMark(e[a])&&!this.isLocked(n.dom)){i=t;break}}if(i>-1)i>this.index&&(this.changed=!0,this.destroyBetween(this.index,i)),this.top=this.top.children[this.index];else{let r=Ka.create(this.top,e[a],t,n);this.top.children.splice(this.index,0,r),this.top=r,this.changed=!0}this.index=0,a++}}findNodeMatch(e,t,n,r){let i=-1,a;if(r>=this.preMatch.index&&(a=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&a.matchesNode(e,t,n))i=this.top.children.indexOf(a,this.index);else for(let r=this.index,a=Math.min(this.top.children.length,r+5);r<a;r++){let a=this.top.children[r];if(a.matchesNode(e,t,n)&&!this.preMatch.matched.has(a)){i=r;break}}return i<0?!1:(this.destroyBetween(this.index,i),this.index++,!0)}updateNodeAt(e,t,n,r,i){let a=this.top.children[r];return a.dirty==Ha&&a.dom==a.contentDOM&&(a.dirty=Va),a.update(e,t,n,i)?(this.destroyBetween(this.index,r),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let t=e.pmViewDesc;if(t){for(let e=this.index;e<this.top.children.length;e++)if(this.top.children[e]==t)return e}return-1}e=t}}updateNextNode(e,t,n,r,i,a){for(let o=this.index;o<this.top.children.length;o++){let s=this.top.children[o];if(s instanceof qa){let c=this.preMatch.matched.get(s);if(c!=null&&c!=i)return!1;let l=s.dom,u,d=this.isLocked(l)&&!(e.isText&&s.node&&s.node.isText&&s.nodeDOM.nodeValue==e.text&&s.dirty!=Ha&&ao(t,s.outerDeco));if(!d&&s.update(e,t,n,r))return this.destroyBetween(this.index,o),s.dom!=l&&(this.changed=!0),this.index++,!0;if(!d&&(u=this.recreateWrapper(s,e,t,n,r,a)))return this.destroyBetween(this.index,o),this.top.children[this.index]=u,u.contentDOM&&(u.dirty=Va,u.updateChildren(r,a+1),u.dirty=za),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,r,i,a){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!ao(n,e.outerDeco)||!r.eq(e.innerDeco))return null;let o=qa.create(this.top,t,n,r,i,a);if(o.contentDOM){o.children=e.children,e.children=[];for(let e of o.children)e.parent=o}return e.destroy(),o}addNode(e,t,n,r,i){let a=qa.create(this.top,e,t,n,r,i);a.contentDOM&&a.updateChildren(r,i+1),this.top.children.splice(this.index++,0,a),this.changed=!0}placeWidget(e,t,n){let r=this.index<this.top.children.length?this.top.children[this.index]:null;if(r&&r.matchesWidget(e)&&(e==r.widget||!r.widget.type.toDOM.parentNode))this.index++;else{let r=new Wa(this.top,e,t,n);this.top.children.splice(this.index++,0,r),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof Ka;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof Ya)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((ea||Qi)&&e&&e.dom.contentEditable==`false`&&this.addHackNode(`IMG`,t),this.addHackNode(`BR`,this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.children[this.index].matchesHack(e))this.index++;else{let n=document.createElement(e);e==`IMG`&&(n.className=`ProseMirror-separator`,n.alt=``),e==`BR`&&(n.className=`ProseMirror-trailingBreak`);let r=new Xa(this.top,[],n,null);t==this.top?t.children.splice(this.index++,0,r):t.children.push(r),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||e.nodeType==1&&e.contains(this.lock.parentNode))}};function co(e,t){let n=t,r=n.children.length,i=e.childCount,a=new Map,o=[];outer:for(;i>0;){let s;for(;;)if(r){let e=n.children[r-1];if(e instanceof Ka)n=e,r=e.children.length;else{s=e,r--;break}}else if(n==t)break outer;else r=n.parent.children.indexOf(n),n=n.parent;let c=s.node;if(c){if(c!=e.child(i-1))break;--i,a.set(s,i),o.push(s)}}return{index:i,matched:a,matches:o.reverse()}}function lo(e,t){return e.type.side-t.type.side}function uo(e,t,n,r){let i=t.locals(e),a=0;if(i.length==0){for(let n=0;n<e.childCount;n++){let o=e.child(n);r(o,i,t.forChild(a,o),n),a+=o.nodeSize}return}let o=0,s=[],c=null;for(let l=0;;){let u,d;for(;o<i.length&&i[o].to==a;){let e=i[o++];e.widget&&(u?(d||=[u]).push(e):u=e)}if(u)if(d){d.sort(lo);for(let e=0;e<d.length;e++)n(d[e],l,!!c)}else n(u,l,!!c);let f,p;if(c)p=-1,f=c,c=null;else if(l<e.childCount)p=l,f=e.child(l++);else break;for(let e=0;e<s.length;e++)s[e].to<=a&&s.splice(e--,1);for(;o<i.length&&i[o].from<=a&&i[o].to>a;)s.push(i[o++]);let m=a+f.nodeSize;if(f.isText){let e=m;o<i.length&&i[o].from<e&&(e=i[o].from);for(let t=0;t<s.length;t++)s[t].to<e&&(e=s[t].to);e<m&&(c=f.cut(e-a),f=f.cut(0,e-a),m=e,p=-1)}else for(;o<i.length&&i[o].to<m;)o++;let h=f.isInline&&!f.isLeaf?s.filter(e=>!e.inline):s.slice();r(f,h,t.forChild(a,f),p),a=m}}function fo(e){if(e.nodeName==`UL`||e.nodeName==`OL`){let t=e.style.cssText;e.style.cssText=t+`; list-style: square !important`,window.getComputedStyle(e).listStyle,e.style.cssText=t}}function po(e,t,n,r){for(let i=0,a=0;i<e.childCount&&a<=r;){let o=e.child(i++),s=a;if(a+=o.nodeSize,!o.isText)continue;let c=o.text;for(;i<e.childCount;){let t=e.child(i++);if(a+=t.nodeSize,!t.isText)break;c+=t.text}if(a>=n){if(a>=r&&c.slice(r-t.length-s,r-s)==t)return r-t.length;let e=s<r?c.lastIndexOf(t,r-s-1):-1;if(e>=0&&e+t.length+s>=n)return s+e;if(n==r&&c.length>=r+t.length-s&&c.slice(r-s,r-s+t.length)==t)return r}}return-1}function mo(e,t,n,r,i){let a=[];for(let o=0,s=0;o<e.length;o++){let c=e[o],l=s,u=s+=c.size;l>=n||u<=t?a.push(c):(l<t&&a.push(c.slice(0,t-l,r)),i&&=(a.push(i),void 0),u>n&&a.push(c.slice(n-l,c.size,r)))}return a}function ho(e,t=null){let n=e.domSelectionRange(),r=e.state.doc;if(!n.focusNode)return null;let i=e.docView.nearestDesc(n.focusNode),a=i&&i.size==0,o=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(o<0)return null;let s=r.resolve(o),c,l;if(Ri(n)){for(c=o;i&&!i.node;)i=i.parent;let e=i.node;if(i&&e.isAtom&&A.isSelectable(e)&&i.parent&&!(e.isInline&&Ii(n.focusNode,n.focusOffset,i.dom))){let e=i.posBefore;l=new A(o==e?s:r.resolve(e))}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=o,i=o;for(let r=0;r<n.rangeCount;r++){let a=n.getRangeAt(r);t=Math.min(t,e.docView.posFromDOM(a.startContainer,a.startOffset,1)),i=Math.max(i,e.docView.posFromDOM(a.endContainer,a.endOffset,-1))}if(t<0)return null;[c,o]=i==e.state.selection.anchor?[i,t]:[t,i],s=r.resolve(o)}else c=e.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(c<0)return null}let u=r.resolve(c);if(!l){let n=t==`pointer`||e.state.selection.head<s.pos&&!a?1:-1;l=Eo(e,u,s,n)}return l}function go(e){return e.editable?e.hasFocus():Oo(e)&&document.activeElement&&document.activeElement.contains(e.dom)}function _o(e,t=!1){let n=e.state.selection;if(wo(e,n),go(e)){if(!t&&e.input.mouseDown&&e.input.mouseDown.allowDefault&&Qi){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&Ai(t.anchorNode,t.anchorOffset,n.anchorNode,n.anchorOffset)){e.input.mouseDown.delayedSelectionSync=!0,e.domObserver.setCurSelection();return}}if(e.domObserver.disconnectSelection(),e.cursorWrapper)Co(e);else{let{anchor:r,head:i}=n,a,o;vo&&!(n instanceof k)&&(n.$from.parent.inlineContent||(a=yo(e,n.from)),!n.empty&&!n.$from.parent.inlineContent&&(o=yo(e,n.to))),e.docView.setSelection(r,i,e,t),vo&&(a&&xo(a),o&&xo(o)),n.visible?e.dom.classList.remove(`ProseMirror-hideselection`):(e.dom.classList.add(`ProseMirror-hideselection`),`onselectionchange`in document&&So(e))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}}var vo=ea||Qi&&$i<63;function yo(e,t){let{node:n,offset:r}=e.docView.domFromPos(t,0),i=r<n.childNodes.length?n.childNodes[r]:null,a=r?n.childNodes[r-1]:null;if(ea&&i&&i.contentEditable==`false`)return bo(i);if((!i||i.contentEditable==`false`)&&(!a||a.contentEditable==`false`)){if(i)return bo(i);if(a)return bo(a)}}function bo(e){return e.contentEditable=`true`,ea&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function xo(e){e.contentEditable=`false`,e.wasDraggable&&=(e.draggable=!0,null)}function So(e){let t=e.dom.ownerDocument;t.removeEventListener(`selectionchange`,e.input.hideSelectionGuard);let n=e.domSelectionRange(),r=n.anchorNode,i=n.anchorOffset;t.addEventListener(`selectionchange`,e.input.hideSelectionGuard=()=>{(n.anchorNode!=r||n.anchorOffset!=i)&&(t.removeEventListener(`selectionchange`,e.input.hideSelectionGuard),setTimeout(()=>{(!go(e)||e.state.selection.visible)&&e.dom.classList.remove(`ProseMirror-hideselection`)},20))})}function Co(e){let t=e.domSelection();if(!t)return;let n=e.cursorWrapper.dom,r=n.nodeName==`IMG`;r?t.collapse(n.parentNode,Ti(n)+1):t.collapse(n,0),!r&&!e.state.selection.visible&&Ji&&Yi<=11&&(n.disabled=!0,n.disabled=!1)}function wo(e,t){if(t instanceof A){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(To(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else To(e)}function To(e){e.lastSelectedViewDesc&&=(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),void 0)}function Eo(e,t,n,r){return e.someProp(`createSelectionBetween`,r=>r(e,t,n))||k.between(t,n,r)}function Do(e){return e.editable&&!e.hasFocus()?!1:Oo(e)}function Oo(e){let t=e.domSelectionRange();if(!t.anchorNode)return!1;try{return e.dom.contains(t.anchorNode.nodeType==3?t.anchorNode.parentNode:t.anchorNode)&&(e.editable||e.dom.contains(t.focusNode.nodeType==3?t.focusNode.parentNode:t.focusNode))}catch{return!1}}function ko(e){let t=e.docView.domFromPos(e.state.selection.anchor,0),n=e.domSelectionRange();return Ai(t.node,t.offset,n.anchorNode,n.anchorOffset)}function Ao(e,t){let{$anchor:n,$head:r}=e.selection,i=t>0?n.max(r):n.min(r),a=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):null:i;return a&&O.findFrom(a,t)}function jo(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function Mo(e,t,n){let r=e.state.selection;if(r instanceof k){if(n.indexOf(`s`)>-1){let{$head:n}=r,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!i||i.isText||!i.isLeaf)return!1;let a=e.state.doc.resolve(n.pos+i.nodeSize*(t<0?-1:1));return jo(e,new k(r.$anchor,a))}else if(!r.empty)return!1;else if(e.endOfTextblock(t>0?`forward`:`backward`)){let n=Ao(e.state,t);return n&&n instanceof A?jo(e,n):!1}else if(!(na&&n.indexOf(`m`)>-1)){let n=r.$head,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter,a;if(!i||i.isText)return!1;let o=t<0?n.pos-i.nodeSize:n.pos;return i.isAtom||(a=e.docView.descAt(o))&&!a.contentDOM?A.isSelectable(i)?jo(e,new A(t<0?e.state.doc.resolve(n.pos-i.nodeSize):n)):aa?jo(e,new k(e.state.doc.resolve(t<0?o:o+i.nodeSize))):!1:!1}}else if(r instanceof A&&r.node.isInline)return jo(e,new k(t>0?r.$to:r.$from));else{let n=Ao(e.state,t);return n?jo(e,n):!1}}function No(e){return e.nodeType==3?e.nodeValue.length:e.childNodes.length}function Po(e,t){let n=e.pmViewDesc;return n&&n.size==0&&(t<0||e.nextSibling||e.nodeName!=`BR`)}function Fo(e,t){return t<0?Io(e):Lo(e)}function Io(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i,a,o=!1;for(Xi&&n.nodeType==1&&r<No(n)&&Po(n.childNodes[r],-1)&&(o=!0);;)if(r>0){if(n.nodeType!=1)break;{let e=n.childNodes[r-1];if(Po(e,-1))i=n,a=--r;else if(e.nodeType==3)n=e,r=n.nodeValue.length;else break}}else if(Ro(n))break;else{let t=n.previousSibling;for(;t&&Po(t,-1);)i=n.parentNode,a=Ti(t),t=t.previousSibling;if(t)n=t,r=No(n);else{if(n=n.parentNode,n==e.dom)break;r=0}}o?Vo(e,n,r):i&&Vo(e,i,a)}function Lo(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i=No(n),a,o;for(;;)if(r<i){if(n.nodeType!=1)break;let e=n.childNodes[r];if(Po(e,1))a=n,o=++r;else break}else if(Ro(n))break;else{let t=n.nextSibling;for(;t&&Po(t,1);)a=t.parentNode,o=Ti(t)+1,t=t.nextSibling;if(t)n=t,r=0,i=No(n);else{if(n=n.parentNode,n==e.dom)break;r=i=0}}a&&Vo(e,a,o)}function Ro(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function zo(e,t){for(;e&&t==e.childNodes.length&&!Li(e);)t=Ti(e)+1,e=e.parentNode;for(;e&&t<e.childNodes.length;){let n=e.childNodes[t];if(n.nodeType==3)return n;if(n.nodeType==1&&n.contentEditable==`false`)break;e=n,t=0}}function Bo(e,t){for(;e&&!t&&!Li(e);)t=Ti(e),e=e.parentNode;for(;e&&t;){let n=e.childNodes[t-1];if(n.nodeType==3)return n;if(n.nodeType==1&&n.contentEditable==`false`)break;e=n,t=e.childNodes.length}}function Vo(e,t,n){if(t.nodeType!=3){let e,r;(r=zo(t,n))?(t=r,n=0):(e=Bo(t,n))&&(t=e,n=e.nodeValue.length)}let r=e.domSelection();if(!r)return;if(Ri(r)){let e=document.createRange();e.setEnd(t,n),e.setStart(t,n),r.removeAllRanges(),r.addRange(e)}else r.extend&&r.extend(t,n);e.domObserver.setCurSelection();let{state:i}=e;setTimeout(()=>{e.state==i&&_o(e)},50)}function Ho(e,t){let n=e.state.doc.resolve(t);if(!(Qi||ra)&&n.parent.inlineContent){let r=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),i=(n.top+n.bottom)/2;if(i>r.top&&i<r.bottom&&Math.abs(n.left-r.left)>1)return n.left<r.left?`ltr`:`rtl`}if(t<n.end()){let n=e.coordsAtPos(t+1),i=(n.top+n.bottom)/2;if(i>r.top&&i<r.bottom&&Math.abs(n.left-r.left)>1)return n.left>r.left?`ltr`:`rtl`}}return getComputedStyle(e.dom).direction==`rtl`?`rtl`:`ltr`}function Uo(e,t,n){let r=e.state.selection;if(r instanceof k&&!r.empty||n.indexOf(`s`)>-1||na&&n.indexOf(`m`)>-1)return!1;let{$from:i,$to:a}=r;if(!i.parent.inlineContent||e.endOfTextblock(t<0?`up`:`down`)){let n=Ao(e.state,t);if(n&&n instanceof A)return jo(e,n)}if(!i.parent.inlineContent){let n=t<0?i:a,o=r instanceof vr?O.near(n,t):O.findFrom(n,t);return o?jo(e,o):!1}return!1}function Wo(e,t){if(!(e.state.selection instanceof k))return!0;let{$head:n,$anchor:r,empty:i}=e.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(e.endOfTextblock(t>0?`forward`:`backward`))return!0;let a=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(a&&!a.isText){let r=e.state.tr;return t<0?r.delete(n.pos-a.nodeSize,n.pos):r.delete(n.pos,n.pos+a.nodeSize),e.dispatch(r),!0}return!1}function Go(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function Ko(e){if(!ea||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(t&&t.nodeType==1&&n==0&&t.firstChild&&t.firstChild.contentEditable==`false`){let n=t.firstChild;Go(e,n,`true`),setTimeout(()=>Go(e,n,`false`),20)}return!1}function qo(e){let t=``;return e.ctrlKey&&(t+=`c`),e.metaKey&&(t+=`m`),e.altKey&&(t+=`a`),e.shiftKey&&(t+=`s`),t}function Jo(e,t){let n=t.keyCode,r=qo(t);if(n==8||na&&n==72&&r==`c`)return Wo(e,-1)||Fo(e,-1);if(n==46&&!t.shiftKey||na&&n==68&&r==`c`)return Wo(e,1)||Fo(e,1);if(n==13||n==27)return!0;if(n==37||na&&n==66&&r==`c`){let t=n==37?Ho(e,e.state.selection.from)==`ltr`?-1:1:-1;return Mo(e,t,r)||Fo(e,t)}else if(n==39||na&&n==70&&r==`c`){let t=n==39?Ho(e,e.state.selection.from)==`ltr`?1:-1:1;return Mo(e,t,r)||Fo(e,t)}else if(n==38||na&&n==80&&r==`c`)return Uo(e,-1,r)||Fo(e,-1);else if(n==40||na&&n==78&&r==`c`)return Ko(e)||Uo(e,1,r)||Fo(e,1);else if(r==(na?`m`:`c`)&&(n==66||n==73||n==89||n==90))return!0;return!1}function Yo(e,t){e.someProp(`transformCopied`,n=>{t=n(t,e)});let n=[],{content:r,openStart:i,openEnd:a}=t;for(;i>1&&a>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,a--;let e=r.firstChild;n.push(e.type.name,e.attrs==e.type.defaultAttrs?null:e.attrs),r=e.content}let o=e.someProp(`clipboardSerializer`)||Gt.fromSchema(e.state.schema),s=ss(),c=s.createElement(`div`);c.appendChild(o.serializeFragment(r,{document:s}));let l=c.firstChild,u,d=0;for(;l&&l.nodeType==1&&(u=is[l.nodeName.toLowerCase()]);){for(let e=u.length-1;e>=0;e--){let t=s.createElement(u[e]);for(;c.firstChild;)t.appendChild(c.firstChild);c.appendChild(t),d++}l=c.firstChild}return l&&l.nodeType==1&&l.setAttribute(`data-pm-slice`,`${i} ${a}${d?` -${d}`:``} ${JSON.stringify(n)}`),{dom:c,text:e.someProp(`clipboardTextSerializer`,n=>n(t,e))||t.content.textBetween(0,t.content.size,`
52
52
 
53
- `),slice:t}}function Zo(e,t,n,r,i){let a=i.parent.type.spec.code,o,s;if(!n&&!t)return null;let c=!!t&&(r||a||!n);if(c){if(e.someProp(`transformPastedText`,n=>{t=n(t,a||r,e)}),a)return s=new D(E.from(e.state.schema.text(t.replace(/\r\n?/g,`
54
- `))),0,0),e.someProp(`transformPasted`,t=>{s=t(s,e,!0)}),s;let n=e.someProp(`clipboardTextParser`,n=>n(t,i,r,e));if(n)s=n;else{let n=i.marks(),{schema:r}=e.state,a=Gt.fromSchema(r);o=document.createElement(`div`),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=o.appendChild(document.createElement(`p`));e&&t.appendChild(a.serializeNode(r.text(e,n)))})}}else e.someProp(`transformPastedHTML`,t=>{n=t(n,e)}),o=ds(n),oa&&fs(o);let l=o&&o.querySelector(`[data-pm-slice]`),u=l&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(l.getAttribute(`data-pm-slice`)||``);if(u&&u[3])for(let e=+u[3];e>0;e--){let e=o.firstChild;for(;e&&e.nodeType!=1;)e=e.nextSibling;if(!e)break;o=e}if(s||=(e.someProp(`clipboardParser`)||e.someProp(`domParser`)||jt.fromSchema(e.state.schema)).parseSlice(o,{preserveWhitespace:!!(c||u),context:i,ruleFromNode(e){return e.nodeName==`BR`&&!e.nextSibling&&e.parentNode&&!Qo.test(e.parentNode.nodeName)?{ignore:!0}:null}}),u)s=ps(is(s,+u[1],+u[2]),u[4]);else if(s=D.maxOpen($o(s.content,i),!0),s.openStart||s.openEnd){let e=0,t=0;for(let t=s.content.firstChild;e<s.openStart&&!t.type.spec.isolating;e++,t=t.firstChild);for(let e=s.content.lastChild;t<s.openEnd&&!e.type.spec.isolating;t++,e=e.lastChild);s=is(s,e,t)}return e.someProp(`transformPasted`,t=>{s=t(s,e,c)}),s}var Qo=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function $o(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.index(n)),i,a=[];if(e.forEach(e=>{if(!a)return;let t=r.findWrapping(e.type),n;if(!t)return a=null;if(n=a.length&&i.length&&ts(t,i,e,a[a.length-1],0))a[a.length-1]=n;else{a.length&&(a[a.length-1]=ns(a[a.length-1],i.length));let n=es(e,t);a.push(n),r=r.matchType(n.type),i=t}}),a)return E.from(a)}return e}function es(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,E.from(e));return e}function ts(e,t,n,r,i){if(i<e.length&&i<t.length&&e[i]==t[i]){let a=ts(e,t,n,r.lastChild,i+1);if(a)return r.copy(r.content.replaceChild(r.childCount-1,a));if(r.contentMatchAt(r.childCount).matchType(i==e.length-1?n.type:e[i+1]))return r.copy(r.content.append(E.from(es(n,e,i+1))))}}function ns(e,t){if(t==0)return e;let n=e.content.replaceChild(e.childCount-1,ns(e.lastChild,t-1)),r=e.contentMatchAt(e.childCount).fillBefore(E.empty,!0);return e.copy(n.append(r))}function rs(e,t,n,r,i,a){let o=t<0?e.firstChild:e.lastChild,s=o.content;return e.childCount>1&&(a=0),i<r-1&&(s=rs(s,t,n,r,i+1,a)),i>=n&&(s=t<0?o.contentMatchAt(0).fillBefore(s,a<=i).append(s):s.append(o.contentMatchAt(o.childCount).fillBefore(E.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(s))}function is(e,t,n){return t<e.openStart&&(e=new D(rs(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new D(rs(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}var as={thead:[`table`],tbody:[`table`],tfoot:[`table`],caption:[`table`],colgroup:[`table`],col:[`table`,`colgroup`],tr:[`table`,`tbody`],td:[`table`,`tbody`,`tr`],th:[`table`,`tbody`,`tr`]},ss=null;function cs(){return ss||=document.implementation.createHTMLDocument(`title`)}var ls=null;function us(e){let t=window.trustedTypes;return t?(ls||=t.defaultPolicy||t.createPolicy(`ProseMirrorClipboard`,{createHTML:e=>e}),ls.createHTML(e)):e}function ds(e){let t=/^(\s*<meta [^>]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n=cs().createElement(`div`),r=/<([a-z][^>\s]+)/i.exec(e),i;if((i=r&&as[r[1].toLowerCase()])&&(e=i.map(e=>`<`+e+`>`).join(``)+e+i.map(e=>`</`+e+`>`).reverse().join(``)),n.innerHTML=us(e),i)for(let e=0;e<i.length;e++)n=n.querySelector(i[e])||n;return n}function fs(e){let t=e.querySelectorAll($i?`span:not([class]):not([style])`:`span.Apple-converted-space`);for(let n=0;n<t.length;n++){let r=t[n];r.childNodes.length==1&&r.textContent==`\xA0`&&r.parentNode&&r.parentNode.replaceChild(e.ownerDocument.createTextNode(` `),r)}}function ps(e,t){if(!e.size)return e;let n=e.content.firstChild.type.schema,r;try{r=JSON.parse(t)}catch{return e}let{content:i,openStart:a,openEnd:o}=e;for(let e=r.length-2;e>=0;e-=2){let t=n.nodes[r[e]];if(!t||t.hasRequiredAttrs())break;i=E.from(t.create(r[e+1],i)),a++,o++}return new D(i,a,o)}var ms={},hs={},gs={touchstart:!0,touchmove:!0},_s=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:``,button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function vs(e){for(let t in ms){let n=ms[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{Cs(e,t)&&!Ss(e,t)&&(e.editable||!(t.type in hs))&&n(e,t)},gs[t]?{passive:!0}:void 0)}ta&&e.dom.addEventListener(`input`,()=>null),xs(e)}function ys(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function bs(e){e.domObserver.stop();for(let t in e.input.eventHandlers)e.dom.removeEventListener(t,e.input.eventHandlers[t]);clearTimeout(e.input.composingTimeout),clearTimeout(e.input.lastIOSEnterFallbackTimeout)}function xs(e){e.someProp(`handleDOMEvents`,t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>Ss(e,t))})}function Ss(e,t){return e.someProp(`handleDOMEvents`,n=>{let r=n[t.type];return r?r(e,t)||t.defaultPrevented:!1})}function Cs(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target;n!=e.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}function ws(e,t){!Ss(e,t)&&ms[t.type]&&(e.editable||!(t.type in hs))&&ms[t.type](e,t)}hs.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=n.keyCode==16||n.shiftKey,!Rs(e,n)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!(aa&&$i&&n.keyCode==13)))if(n.keyCode!=229&&e.domObserver.forceFlush(),na&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{e.input.lastIOSEnter==t&&(e.someProp(`handleKeyDown`,t=>t(e,Bi(13,`Enter`))),e.input.lastIOSEnter=0)},200)}else e.someProp(`handleKeyDown`,t=>t(e,n))||Yo(e,n)?n.preventDefault():ys(e,`key`)},hs.keyup=(e,t)=>{t.keyCode==16&&(e.input.shiftKey=!1)},hs.keypress=(e,t)=>{let n=t;if(Rs(e,n)||!n.charCode||n.ctrlKey&&!n.altKey||ra&&n.metaKey)return;if(e.someProp(`handleKeyPress`,t=>t(e,n))){n.preventDefault();return}let r=e.state.selection;if(!(r instanceof k)||!r.$from.sameParent(r.$to)){let t=String.fromCharCode(n.charCode),i=()=>e.state.tr.insertText(t).scrollIntoView();!/[\r\n]/.test(t)&&!e.someProp(`handleTextInput`,n=>n(e,r.$from.pos,r.$to.pos,t,i))&&e.dispatch(i()),n.preventDefault()}};function Ts(e){return{left:e.clientX,top:e.clientY}}function Es(e,t){let n=t.x-e.clientX,r=t.y-e.clientY;return n*n+r*r<100}function Ds(e,t,n,r,i){if(r==-1)return!1;let a=e.state.doc.resolve(r);for(let r=a.depth+1;r>0;r--)if(e.someProp(t,t=>r>a.depth?t(e,n,a.nodeAfter,a.before(r),i,!0):t(e,n,a.node(r),a.before(r),i,!1)))return!0;return!1}function Os(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let r=e.state.tr.setSelection(t);n==`pointer`&&r.setMeta(`pointer`,!0),e.dispatch(r)}function ks(e,t){if(t==-1)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return r&&r.isAtom&&A.isSelectable(r)?(Os(e,new A(n),`pointer`),!0):!1}function As(e,t){if(t==-1)return!1;let n=e.state.selection,r,i;n instanceof A&&(r=n.node);let a=e.state.doc.resolve(t);for(let e=a.depth+1;e>0;e--){let t=e>a.depth?a.nodeAfter:a.node(e);if(A.isSelectable(t)){i=r&&n.$from.depth>0&&e>=n.$from.depth&&a.before(n.$from.depth+1)==n.$from.pos?a.before(n.$from.depth):a.before(e);break}}return i==null?!1:(Os(e,A.create(e.state.doc,i),`pointer`),!0)}function js(e,t,n,r,i){return Ds(e,`handleClickOn`,t,n,r)||e.someProp(`handleClick`,n=>n(e,t,r))||(i?As(e,n):ks(e,n))}function Ms(e,t,n,r){return Ds(e,`handleDoubleClickOn`,t,n,r)||e.someProp(`handleDoubleClick`,n=>n(e,t,r))}function Ns(e,t,n,r){return Ds(e,`handleTripleClickOn`,t,n,r)||e.someProp(`handleTripleClick`,n=>n(e,t,r))||Ps(e,n,r)}function Ps(e,t,n){if(n.button!=0)return!1;let r=e.state.doc;if(t==-1)return r.inlineContent?(Os(e,k.create(r,0,r.content.size),`pointer`),!0):!1;let i=r.resolve(t);for(let t=i.depth+1;t>0;t--){let n=t>i.depth?i.nodeAfter:i.node(t),a=i.before(t);if(n.inlineContent)Os(e,k.create(r,a+1,a+1+n.content.size),`pointer`);else if(A.isSelectable(n))Os(e,A.create(r,a),`pointer`);else continue;return!0}}function Fs(e){return Gs(e)}var Is=ra?`metaKey`:`ctrlKey`;ms.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let r=Fs(e),i=Date.now(),a=`singleClick`;i-e.input.lastClick.time<500&&Es(n,e.input.lastClick)&&!n[Is]&&e.input.lastClick.button==n.button&&(e.input.lastClick.type==`singleClick`?a=`doubleClick`:e.input.lastClick.type==`doubleClick`&&(a=`tripleClick`)),e.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:a,button:n.button};let o=e.posAtCoords(Ts(n));o&&(a==`singleClick`?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new Ls(e,o,n,!!r)):(a==`doubleClick`?Ms:Ns)(e,o.pos,o.inside,n)?n.preventDefault():ys(e,`pointer`))};var Ls=class{constructor(e,t,n,r){this.view=e,this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[Is],this.allowDefault=n.shiftKey;let i,a;if(t.inside>-1)i=e.state.doc.nodeAt(t.inside),a=t.inside;else{let n=e.state.doc.resolve(t.pos);i=n.parent,a=n.depth?n.before():0}let o=r?null:n.target,s=o?e.docView.nearestDesc(o,!0):null;this.target=s&&s.nodeDOM.nodeType==1?s.nodeDOM:null;let{selection:c}=e.state;(n.button==0&&i.type.spec.draggable&&i.type.spec.selectable!==!1||c instanceof A&&c.from<=a&&c.to>a)&&(this.mightDrag={node:i,pos:a,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Zi&&!this.target.hasAttribute(`contentEditable`))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute(`contentEditable`,`false`)},20),this.view.domObserver.start()),e.root.addEventListener(`mouseup`,this.up=this.up.bind(this)),e.root.addEventListener(`mousemove`,this.move=this.move.bind(this)),ys(e,`pointer`)}done(){this.view.root.removeEventListener(`mouseup`,this.up),this.view.root.removeEventListener(`mousemove`,this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute(`draggable`),this.mightDrag.setUneditable&&this.target.removeAttribute(`contentEditable`),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>vo(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(Ts(e))),this.updateAllowDefault(e),this.allowDefault||!t?ys(this.view,`pointer`):js(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||ta&&this.mightDrag&&!this.mightDrag.node.isAtom||$i&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(Os(this.view,O.near(this.view.state.doc.resolve(t.pos)),`pointer`),e.preventDefault()):ys(this.view,`pointer`)}move(e){this.updateAllowDefault(e),ys(this.view,`pointer`),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}};ms.touchstart=e=>{e.input.lastTouch=Date.now(),Fs(e),ys(e,`pointer`)},ms.touchmove=e=>{e.input.lastTouch=Date.now(),ys(e,`pointer`)},ms.contextmenu=e=>Fs(e);function Rs(e,t){return e.composing?!0:ta&&Math.abs(t.timeStamp-e.input.compositionEndedAt)<500?(e.input.compositionEndedAt=-2e8,!0):!1}var zs=aa?5e3:-1;hs.compositionstart=hs.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof k&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>e.type.spec.inclusive===!1)||$i&&ia&&Bs(e)))e.markCursor=e.state.storedMarks||n.marks(),Gs(e,!0),e.markCursor=null;else if(Gs(e,!t.selection.empty),Zi&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,r=t.focusOffset;n&&n.nodeType==1&&r!=0;){let t=r<0?n.lastChild:n.childNodes[r-1];if(!t)break;if(t.nodeType==3){let n=e.domSelection();n&&n.collapse(t,t.nodeValue.length);break}else n=t,r=-1}}e.input.composing=!0}Vs(e,zs)};function Bs(e){let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(!t||t.nodeType!=1||n>=t.childNodes.length)return!1;let r=t.childNodes[n];return r.nodeType==1&&r.contentEditable==`false`}hs.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=t.timeStamp,e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.badSafariComposition?e.domObserver.forceFlush():e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,Vs(e,20))};function Vs(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>Gs(e),t))}function Hs(e){for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=Ws());e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function Us(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=Fi(t.focusNode,t.focusOffset),r=Ii(t.focusNode,t.focusOffset);if(n&&r&&n!=r){let t=r.pmViewDesc,i=e.domObserver.lastChangedTextNode;if(n==i||r==i)return i;if(!t||!t.isText(r.nodeValue))return r;if(e.input.compositionNode==r){let e=n.pmViewDesc;if(!(!e||!e.isText(n.nodeValue)))return r}}return n||r}function Ws(){let e=document.createEvent(`Event`);return e.initEvent(`event`,!0,!0),e.timeStamp}function Gs(e,t=!1){if(!(aa&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),Hs(e),t||e.docView&&e.docView.dirty){let n=go(e),r=e.state.selection;return n&&!n.eq(r)?e.dispatch(e.state.tr.setSelection(n)):(e.markCursor||t)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?e.dispatch(e.state.tr.deleteSelection()):e.updateState(e.state),!0}return!1}}function Ks(e,t){if(!e.dom.parentNode)return;let n=e.dom.parentNode.appendChild(document.createElement(`div`));n.appendChild(t),n.style.cssText=`position: fixed; left: -10000px; top: 10px`;let r=getSelection(),i=document.createRange();i.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}var qs=Yi&&Xi<15||na&&sa<604;ms.copy=hs.cut=(e,t)=>{let n=t,r=e.state.selection,i=n.type==`cut`;if(r.empty)return;let a=qs?null:n.clipboardData,{dom:o,text:s}=Xo(e,r.content());a?(n.preventDefault(),a.clearData(),a.setData(`text/html`,o.innerHTML),a.setData(`text/plain`,s)):Ks(e,o),i&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta(`uiEvent`,`cut`))};function Js(e){return e.openStart==0&&e.openEnd==0&&e.content.childCount==1?e.content.firstChild:null}function Ys(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,r=e.dom.parentNode.appendChild(document.createElement(n?`textarea`:`div`));n||(r.contentEditable=`true`),r.style.cssText=`position: fixed; left: -10000px; top: 10px`,r.focus();let i=e.input.shiftKey&&e.input.lastKeyCode!=45;setTimeout(()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?Xs(e,r.value,null,i,t):Xs(e,r.textContent,r.innerHTML,i,t)},50)}function Xs(e,t,n,r,i){let a=Zo(e,t,n,r,e.state.selection.$from);if(e.someProp(`handlePaste`,t=>t(e,i,a||D.empty)))return!0;if(!a)return!1;let o=Js(a),s=o?e.state.tr.replaceSelectionWith(o,r):e.state.tr.replaceSelection(a);return e.dispatch(s.scrollIntoView().setMeta(`paste`,!0).setMeta(`uiEvent`,`paste`)),!0}function Zs(e){let t=e.getData(`text/plain`)||e.getData(`Text`);if(t)return t;let n=e.getData(`text/uri-list`);return n?n.replace(/\r?\n/g,` `):``}hs.paste=(e,t)=>{let n=t;if(e.composing&&!aa)return;let r=qs?null:n.clipboardData,i=e.input.shiftKey&&e.input.lastKeyCode!=45;r&&Xs(e,Zs(r),r.getData(`text/html`),i,n)?n.preventDefault():Ys(e,n)};var Qs=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},$s=ra?`altKey`:`ctrlKey`;function ec(e,t){return e.someProp(`dragCopies`,e=>!e(t))??!t[$s]}ms.dragstart=(e,t)=>{let n=t,r=e.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=e.state.selection,a=i.empty?null:e.posAtCoords(Ts(n)),o;if(!(a&&a.pos>=i.from&&a.pos<=(i instanceof A?i.to-1:i.to))){if(r&&r.mightDrag)o=A.create(e.state.doc,r.mightDrag.pos);else if(n.target&&n.target.nodeType==1){let t=e.docView.nearestDesc(n.target,!0);t&&t.node.type.spec.draggable&&t!=e.docView&&(o=A.create(e.state.doc,t.posBefore))}}let{dom:s,text:c,slice:l}=Xo(e,(o||e.state.selection).content());(!n.dataTransfer.files.length||!$i||ea>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(qs?`Text`:`text/html`,s.innerHTML),n.dataTransfer.effectAllowed=`copyMove`,qs||n.dataTransfer.setData(`text/plain`,c),e.dragging=new Qs(l,ec(e,n),o)},ms.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},hs.dragover=hs.dragenter=(e,t)=>t.preventDefault(),hs.drop=(e,t)=>{try{tc(e,t,e.dragging)}finally{e.dragging=null}};function tc(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(Ts(t));if(!r)return;let i=e.state.doc.resolve(r.pos),a=n&&n.slice;a?e.someProp(`transformPasted`,t=>{a=t(a,e,!1)}):a=Zo(e,Zs(t.dataTransfer),qs?null:t.dataTransfer.getData(`text/html`),!1,i);let o=!!(n&&ec(e,t));if(e.someProp(`handleDrop`,n=>n(e,t,a||D.empty,o))){t.preventDefault();return}if(!a)return;t.preventDefault();let s=a?Kn(e.state.doc,i.pos,a):i.pos;s??=i.pos;let c=e.state.tr;if(o){let{node:e}=n;e?e.replace(c):c.deleteSelection()}let l=c.mapping.map(s),u=a.openStart==0&&a.openEnd==0&&a.content.childCount==1,d=c.doc;if(u?c.replaceRangeWith(l,l,a.content.firstChild):c.replaceRange(l,l,a),c.doc.eq(d))return;let f=c.doc.resolve(l);if(u&&A.isSelectable(a.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(a.content.firstChild))c.setSelection(new A(f));else{let t=c.mapping.map(s);c.mapping.maps[c.mapping.maps.length-1].forEach((e,n,r,i)=>t=i),c.setSelection(Do(e,f,c.doc.resolve(t)))}e.focus(),e.dispatch(c.setMeta(`uiEvent`,`drop`))}ms.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add(`ProseMirror-focused`),e.domObserver.start(),e.focused=!0,setTimeout(()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&vo(e)},20))},ms.blur=(e,t)=>{let n=t;e.focused&&=(e.domObserver.stop(),e.dom.classList.remove(`ProseMirror-focused`),e.domObserver.start(),n.relatedTarget&&e.dom.contains(n.relatedTarget)&&e.domObserver.currentSelection.clear(),!1)},ms.beforeinput=(e,t)=>{if($i&&aa&&t.inputType==`deleteContentBackward`){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t||(e.dom.blur(),e.focus(),e.someProp(`handleKeyDown`,t=>t(e,Bi(8,`Backspace`)))))return;let{$cursor:n}=e.state.selection;n&&n.pos>0&&e.dispatch(e.state.tr.delete(n.pos-1,n.pos).scrollIntoView())},50)}};for(let e in hs)ms[e]=hs[e];function nc(e,t){if(e==t)return!0;for(let n in e)if(e[n]!==t[n])return!1;for(let n in t)if(!(n in e))return!1;return!0}var rc=class e{constructor(e,t){this.toDOM=e,this.spec=t||cc,this.side=this.spec.side||0}map(e,t,n,r){let{pos:i,deleted:a}=e.mapResult(t.from+r,this.side<0?-1:1);return a?null:new oc(i-n,i-n,this)}valid(){return!0}eq(t){return this==t||t instanceof e&&(this.spec.key&&this.spec.key==t.spec.key||this.toDOM==t.toDOM&&nc(this.spec,t.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},ic=class e{constructor(e,t){this.attrs=e,this.spec=t||cc}map(e,t,n,r){let i=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-n,a=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-n;return i>=a?null:new oc(i,a,this)}valid(e,t){return t.from<t.to}eq(t){return this==t||t instanceof e&&nc(this.attrs,t.attrs)&&nc(this.spec,t.spec)}static is(t){return t.type instanceof e}destroy(){}},ac=class e{constructor(e,t){this.attrs=e,this.spec=t||cc}map(e,t,n,r){let i=e.mapResult(t.from+r,1);if(i.deleted)return null;let a=e.mapResult(t.to+r,-1);return a.deleted||a.pos<=i.pos?null:new oc(i.pos-n,a.pos-n,this)}valid(e,t){let{index:n,offset:r}=e.content.findIndex(t.from),i;return r==t.from&&!(i=e.child(n)).isText&&r+i.nodeSize==t.to}eq(t){return this==t||t instanceof e&&nc(this.attrs,t.attrs)&&nc(this.spec,t.spec)}destroy(){}},oc=class e{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(t,n){return new e(t,n,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,n){return this.type.map(e,this,t,n)}static widget(t,n,r){return new e(t,t,new rc(n,r))}static inline(t,n,r,i){return new e(t,n,new ic(r,i))}static node(t,n,r,i){return new e(t,n,new ac(r,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof ic}get widget(){return this.type instanceof rc}},sc=[],cc={},lc=class e{constructor(e,t){this.local=e.length?e:sc,this.children=t.length?t:sc}static create(e,t){return t.length?_c(t,e,0,cc):uc}find(e,t,n){let r=[];return this.findInner(e??0,t??1e9,r,0,n),r}findInner(e,t,n,r,i){for(let a=0;a<this.local.length;a++){let o=this.local[a];o.from<=t&&o.to>=e&&(!i||i(o.spec))&&n.push(o.copy(o.from+r,o.to+r))}for(let a=0;a<this.children.length;a+=3)if(this.children[a]<t&&this.children[a+1]>e){let o=this.children[a]+1;this.children[a+2].findInner(e-o,t-o,n,r+o,i)}}map(e,t,n){return this==uc||e.maps.length==0?this:this.mapInner(e,t,0,0,n||cc)}mapInner(t,n,r,i,a){let o;for(let e=0;e<this.local.length;e++){let s=this.local[e].map(t,r,i);s&&s.type.valid(n,s)?(o||=[]).push(s):a.onRemove&&a.onRemove(this.local[e].spec)}return this.children.length?fc(this.children,o||[],t,n,r,i,a):o?new e(o.sort(vc),sc):uc}add(t,n){return n.length?this==uc?e.create(t,n):this.addInner(t,n,0):this}addInner(t,n,r){let i,a=0;t.forEach((e,t)=>{let o=t+r,s;if(s=hc(n,e,o)){for(i||=this.children.slice();a<i.length&&i[a]<t;)a+=3;i[a]==t?i[a+2]=i[a+2].addInner(e,s,o+1):i.splice(a,0,t,t+e.nodeSize,_c(s,e,o+1,cc)),a+=3}});let o=pc(a?gc(n):n,-r);for(let e=0;e<o.length;e++)o[e].type.valid(t,o[e])||o.splice(e--,1);return new e(o.length?this.local.concat(o).sort(vc):this.local,i||this.children)}remove(e){return e.length==0||this==uc?this:this.removeInner(e,0)}removeInner(t,n){let r=this.children,i=this.local;for(let e=0;e<r.length;e+=3){let i,a=r[e]+n,o=r[e+1]+n;for(let e=0,n;e<t.length;e++)(n=t[e])&&n.from>a&&n.to<o&&(t[e]=null,(i||=[]).push(n));if(!i)continue;r==this.children&&(r=this.children.slice());let s=r[e+2].removeInner(i,a+1);s==uc?(r.splice(e,3),e-=3):r[e+2]=s}if(i.length){for(let e=0,r;e<t.length;e++)if(r=t[e])for(let e=0;e<i.length;e++)i[e].eq(r,n)&&(i==this.local&&(i=this.local.slice()),i.splice(e--,1))}return r==this.children&&i==this.local?this:i.length||r.length?new e(i,r):uc}forChild(t,n){if(this==uc)return this;if(n.isLeaf)return e.empty;let r,i;for(let e=0;e<this.children.length;e+=3)if(this.children[e]>=t){this.children[e]==t&&(r=this.children[e+2]);break}let a=t+1,o=a+n.content.size;for(let e=0;e<this.local.length;e++){let t=this.local[e];if(t.from<o&&t.to>a&&t.type instanceof ic){let e=Math.max(a,t.from)-a,n=Math.min(o,t.to)-a;e<n&&(i||=[]).push(t.copy(e,n))}}if(i){let t=new e(i.sort(vc),sc);return r?new dc([t,r]):t}return r||uc}eq(t){if(this==t)return!0;if(!(t instanceof e)||this.local.length!=t.local.length||this.children.length!=t.children.length)return!1;for(let e=0;e<this.local.length;e++)if(!this.local[e].eq(t.local[e]))return!1;for(let e=0;e<this.children.length;e+=3)if(this.children[e]!=t.children[e]||this.children[e+1]!=t.children[e+1]||!this.children[e+2].eq(t.children[e+2]))return!1;return!0}locals(e){return yc(this.localsInner(e))}localsInner(e){if(this==uc)return sc;if(e.inlineContent||!this.local.some(ic.is))return this.local;let t=[];for(let e=0;e<this.local.length;e++)this.local[e].type instanceof ic||t.push(this.local[e]);return t}forEachSet(e){e(this)}};lc.empty=new lc([],[]),lc.removeOverlap=yc;var uc=lc.empty,dc=class e{constructor(e){this.members=e}map(t,n){let r=this.members.map(e=>e.map(t,n,cc));return e.from(r)}forChild(t,n){if(n.isLeaf)return lc.empty;let r=[];for(let i=0;i<this.members.length;i++){let a=this.members[i].forChild(t,n);a!=uc&&(a instanceof e?r=r.concat(a.members):r.push(a))}return e.from(r)}eq(t){if(!(t instanceof e)||t.members.length!=this.members.length)return!1;for(let e=0;e<this.members.length;e++)if(!this.members[e].eq(t.members[e]))return!1;return!0}locals(e){let t,n=!0;for(let r=0;r<this.members.length;r++){let i=this.members[r].localsInner(e);if(i.length)if(!t)t=i;else{n&&=(t=t.slice(),!1);for(let e=0;e<i.length;e++)t.push(i[e])}}return t?yc(n?t:t.sort(vc)):sc}static from(t){switch(t.length){case 0:return uc;case 1:return t[0];default:return new e(t.every(e=>e instanceof lc)?t:t.reduce((e,t)=>e.concat(t instanceof lc?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}};function fc(e,t,n,r,i,a,o){let s=e.slice();for(let e=0,t=a;e<n.maps.length;e++){let r=0;n.maps[e].forEach((e,n,i,a)=>{let o=a-i-(n-e);for(let i=0;i<s.length;i+=3){let a=s[i+1];if(a<0||e>a+t-r)continue;let c=s[i]+t-r;n>=c?s[i+1]=e<=c?-2:-1:e>=t&&o&&(s[i]+=o,s[i+1]+=o)}r+=o}),t=n.maps[e].map(t,-1)}let c=!1;for(let t=0;t<s.length;t+=3)if(s[t+1]<0){if(s[t+1]==-2){c=!0,s[t+1]=-1;continue}let l=n.map(e[t]+a),u=l-i;if(u<0||u>=r.content.size){c=!0;continue}let d=n.map(e[t+1]+a,-1)-i,{index:f,offset:p}=r.content.findIndex(u),m=r.maybeChild(f);if(m&&p==u&&p+m.nodeSize==d){let r=s[t+2].mapInner(n,m,l+1,e[t]+a+1,o);r==uc?(s[t+1]=-2,c=!0):(s[t]=u,s[t+1]=d,s[t+2]=r)}else c=!0}if(c){let c=_c(mc(s,e,t,n,i,a,o),r,0,o);t=c.local;for(let e=0;e<s.length;e+=3)s[e+1]<0&&(s.splice(e,3),e-=3);for(let e=0,t=0;e<c.children.length;e+=3){let n=c.children[e];for(;t<s.length&&s[t]<n;)t+=3;s.splice(t,0,c.children[e],c.children[e+1],c.children[e+2])}}return new lc(t.sort(vc),s)}function pc(e,t){if(!t||!e.length)return e;let n=[];for(let r=0;r<e.length;r++){let i=e[r];n.push(new oc(i.from+t,i.to+t,i.type))}return n}function mc(e,t,n,r,i,a,o){function s(e,t){for(let a=0;a<e.local.length;a++){let s=e.local[a].map(r,i,t);s?n.push(s):o.onRemove&&o.onRemove(e.local[a].spec)}for(let n=0;n<e.children.length;n+=3)s(e.children[n+2],e.children[n]+t+1)}for(let n=0;n<e.length;n+=3)e[n+1]==-1&&s(e[n+2],t[n]+a+1);return n}function hc(e,t,n){if(t.isLeaf)return null;let r=n+t.nodeSize,i=null;for(let t=0,a;t<e.length;t++)(a=e[t])&&a.from>n&&a.to<r&&((i||=[]).push(a),e[t]=null);return i}function gc(e){let t=[];for(let n=0;n<e.length;n++)e[n]!=null&&t.push(e[n]);return t}function _c(e,t,n,r){let i=[],a=!1;t.forEach((t,o)=>{let s=hc(e,t,o+n);if(s){a=!0;let e=_c(s,t,n+o+1,r);e!=uc&&i.push(o,o+t.nodeSize,e)}});let o=pc(a?gc(e):e,-n).sort(vc);for(let e=0;e<o.length;e++)o[e].type.valid(t,o[e])||(r.onRemove&&r.onRemove(o[e].spec),o.splice(e--,1));return o.length||i.length?new lc(o,i):uc}function vc(e,t){return e.from-t.from||e.to-t.to}function yc(e){let t=e;for(let n=0;n<t.length-1;n++){let r=t[n];if(r.from!=r.to)for(let i=n+1;i<t.length;i++){let a=t[i];if(a.from==r.from){a.to!=r.to&&(t==e&&(t=e.slice()),t[i]=a.copy(a.from,r.to),bc(t,i+1,a.copy(r.to,a.to)));continue}else{a.from<r.to&&(t==e&&(t=e.slice()),t[n]=r.copy(r.from,a.from),bc(t,i,r.copy(a.from,r.to)));break}}}return t}function bc(e,t,n){for(;t<e.length&&vc(n,e[t])>0;)t++;e.splice(t,0,n)}function xc(e){let t=[];return e.someProp(`decorations`,n=>{let r=n(e.state);r&&r!=uc&&t.push(r)}),e.cursorWrapper&&t.push(lc.create(e.state.doc,[e.cursorWrapper.deco])),dc.from(t)}var Sc={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Cc=Yi&&Xi<=11,wc=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}},Tc=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new wc,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(t=>{for(let e=0;e<t.length;e++)this.queue.push(t[e]);Yi&&Xi<=11&&t.some(e=>e.type==`childList`&&e.removedNodes.length||e.type==`characterData`&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():ta&&e.composing&&t.some(e=>e.type==`childList`&&e.target.nodeName==`TR`)?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),Cc&&(this.onCharData=e=>{this.queue.push({target:e.target,type:`characterData`,oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,Sc)),this.onCharData&&this.view.dom.addEventListener(`DOMCharacterDataModified`,this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener(`DOMCharacterDataModified`,this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener(`selectionchange`,this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener(`selectionchange`,this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(Oo(this.view)){if(this.suppressingSelectionUpdates)return vo(this.view);if(Yi&&Xi<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&ji(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,n;for(let n=e.focusNode;n;n=Di(n))t.add(n);for(let r=e.anchorNode;r;r=Di(r))if(t.has(r)){n=r;break}let r=n&&this.view.docView.nearestDesc(n);if(r&&r.ignoreMutation({type:`selection`,target:n.nodeType==3?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&Oo(e)&&!this.ignoreSelectionChange(n),i=-1,a=-1,o=!1,s=[];if(e.editable)for(let e=0;e<t.length;e++){let n=this.registerMutation(t[e],s);n&&(i=i<0?n.from:Math.min(n.from,i),a=a<0?n.to:Math.max(n.to,a),n.typeOver&&(o=!0))}if(s.some(e=>e.nodeName==`BR`)&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46)){for(let e of s)if(e.nodeName==`BR`&&e.parentNode){let t=e.nextSibling;for(;t&&t.nodeType==1;){if(t.contentEditable==`false`){e.parentNode.removeChild(e);break}t=t.firstChild}}}else if(Zi&&s.length){let t=s.filter(e=>e.nodeName==`BR`);if(t.length==2){let[e,n]=t;e.parentNode&&e.parentNode.parentNode==n.parentNode?n.remove():e.remove()}else{let{focusNode:n}=this.currentSelection;for(let r of t){let t=r.parentNode;t&&t.nodeName==`LI`&&(!n||jc(e,n)!=t)&&r.remove()}}}let c=null;i<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&zi(n)&&(c=go(e))&&c.eq(O.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,vo(e),this.currentSelection.set(n),e.scrollToSelection()):(i>-1||r)&&(i>-1&&(e.docView.markDirty(i,a),Oc(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,Mc(e,s)),this.handleDOMChange(i,a,o,s),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||vo(e),this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if(e.type==`attributes`&&(n==this.view.docView||e.attributeName==`contenteditable`||e.attributeName==`style`&&!e.oldValue&&!e.target.getAttribute(`style`))||!n||n.ignoreMutation(e))return null;if(e.type==`childList`){for(let n=0;n<e.addedNodes.length;n++){let r=e.addedNodes[n];t.push(r),r.nodeType==3&&(this.lastChangedTextNode=r)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let r=e.previousSibling,i=e.nextSibling;if(Yi&&Xi<=11&&e.addedNodes.length)for(let t=0;t<e.addedNodes.length;t++){let{previousSibling:n,nextSibling:a}=e.addedNodes[t];(!n||Array.prototype.indexOf.call(e.addedNodes,n)<0)&&(r=n),(!a||Array.prototype.indexOf.call(e.addedNodes,a)<0)&&(i=a)}let a=r&&r.parentNode==e.target?Ei(r)+1:0,o=n.localPosFromDOM(e.target,a,-1),s=i&&i.parentNode==e.target?Ei(i):e.target.childNodes.length;return{from:o,to:n.localPosFromDOM(e.target,s,1)}}else if(e.type==`attributes`)return{from:n.posAtStart-n.border,to:n.posAtEnd+n.border};else return this.lastChangedTextNode=e.target,{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}}},Ec=new WeakMap,Dc=!1;function Oc(e){if(!Ec.has(e)&&(Ec.set(e,null),[`normal`,`nowrap`,`pre-line`].indexOf(getComputedStyle(e.dom).whiteSpace)!==-1)){if(e.requiresGeckoHackNode=Zi,Dc)return;console.warn(`ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package.`),Dc=!0}}function kc(e,t){let n=t.startContainer,r=t.startOffset,i=t.endContainer,a=t.endOffset,o=e.domAtPos(e.state.selection.anchor);return ji(o.node,o.offset,i,a)&&([n,r,i,a]=[i,a,n,r]),{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}}function Ac(e,t){if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return kc(e,n)}let n;function r(e){e.preventDefault(),e.stopImmediatePropagation(),n=e.getTargetRanges()[0]}return e.dom.addEventListener(`beforeinput`,r,!0),document.execCommand(`indent`),e.dom.removeEventListener(`beforeinput`,r,!0),n?kc(e,n):null}function jc(e,t){for(let n=t.parentNode;n&&n!=e.dom;n=n.parentNode){let t=e.docView.nearestDesc(n,!0);if(t&&t.node.isBlock)return n}return null}function Mc(e,t){let{focusNode:n,focusOffset:r}=e.domSelectionRange();for(let i of t)if(i.parentNode?.nodeName==`TR`){let t=i.nextSibling;for(;t&&t.nodeName!=`TD`&&t.nodeName!=`TH`;)t=t.nextSibling;if(t){let a=t;for(;;){let e=a.firstChild;if(!e||e.nodeType!=1||e.contentEditable==`false`||/^(BR|IMG)$/.test(e.nodeName))break;a=e}a.insertBefore(i,a.firstChild),n==i&&e.domSelection().collapse(i,r)}else i.parentNode.removeChild(i)}}function Nc(e,t,n){let{node:r,fromOffset:i,toOffset:a,from:o,to:s}=e.docView.parseRange(t,n),c=e.domSelectionRange(),l,u=c.anchorNode;if(u&&e.dom.contains(u.nodeType==1?u:u.parentNode)&&(l=[{node:u,offset:c.anchorOffset}],zi(c)||l.push({node:c.focusNode,offset:c.focusOffset})),$i&&e.input.lastKeyCode===8)for(let e=a;e>i;e--){let t=r.childNodes[e-1],n=t.pmViewDesc;if(t.nodeName==`BR`&&!n){a=e;break}if(!n||n.size)break}let d=e.state.doc,f=e.someProp(`domParser`)||jt.fromSchema(e.state.schema),p=d.resolve(o),m=null,h=f.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:a,preserveWhitespace:p.parent.type.whitespace==`pre`?`full`:!0,findPositions:l,ruleFromNode:Pc,context:p});if(l&&l[0].pos!=null){let e=l[0].pos,t=l[1]&&l[1].pos;t??=e,m={anchor:e+o,head:t+o}}return{doc:h,sel:m,from:o,to:s}}function Pc(e){let t=e.pmViewDesc;if(t)return t.parseRule();if(e.nodeName==`BR`&&e.parentNode){if(ta&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let e=document.createElement(`div`);return e.appendChild(document.createElement(`li`)),{skip:e}}else if(e.parentNode.lastChild==e||ta&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if(e.nodeName==`IMG`&&e.getAttribute(`mark-placeholder`))return{ignore:!0};return null}var Fc=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function Ic(e,t,n,r,i){let a=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);if(e.input.compositionPendingChanges=0,t<0){let t=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,n=go(e,t);if(n&&!e.state.selection.eq(n)){if($i&&aa&&e.input.lastKeyCode===13&&Date.now()-100<e.input.lastKeyCodeTime&&e.someProp(`handleKeyDown`,t=>t(e,Bi(13,`Enter`))))return;let r=e.state.tr.setSelection(n);t==`pointer`?r.setMeta(`pointer`,!0):t==`key`&&r.scrollIntoView(),a&&r.setMeta(`composition`,a),e.dispatch(r)}return}let o=e.state.doc.resolve(t),s=o.sharedDepth(n);t=o.before(s+1),n=e.state.doc.resolve(n).after(s+1);let c=e.state.selection,l=Nc(e,t,n),u=e.state.doc,d=u.slice(l.from,l.to),f,p;e.input.lastKeyCode===8&&Date.now()-100<e.input.lastKeyCodeTime?(f=e.state.selection.to,p=`end`):(f=e.state.selection.from,p=`start`),e.input.lastKeyCode=null;let m=Vc(d.content,l.doc.content,l.from,f,p);if(m&&e.input.domChangeCount++,(na&&e.input.lastIOSEnter>Date.now()-225||aa)&&i.some(e=>e.nodeType==1&&!Fc.test(e.nodeName))&&(!m||m.endA>=m.endB)&&e.someProp(`handleKeyDown`,t=>t(e,Bi(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(!m)if(r&&c instanceof k&&!c.empty&&c.$head.sameParent(c.$anchor)&&!e.composing&&!(l.sel&&l.sel.anchor!=l.sel.head))m={start:c.from,endA:c.to,endB:c.to};else{if(l.sel){let t=Lc(e,e.state.doc,l.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);a&&n.setMeta(`composition`,a),e.dispatch(n)}}return}e.state.selection.from<e.state.selection.to&&m.start==m.endB&&e.state.selection instanceof k&&(m.start>e.state.selection.from&&m.start<=e.state.selection.from+2&&e.state.selection.from>=l.from?m.start=e.state.selection.from:m.endA<e.state.selection.to&&m.endA>=e.state.selection.to-2&&e.state.selection.to<=l.to&&(m.endB+=e.state.selection.to-m.endA,m.endA=e.state.selection.to)),Yi&&Xi<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>l.from&&l.doc.textBetween(m.start-l.from-1,m.start-l.from+1)==` \xA0`&&(m.start--,m.endA--,m.endB--);let h=l.doc.resolveNoCache(m.start-l.from),g=l.doc.resolveNoCache(m.endB-l.from),_=u.resolve(m.start),v=h.sameParent(g)&&h.parent.inlineContent&&_.end()>=m.endA;if((na&&e.input.lastIOSEnter>Date.now()-225&&(!v||i.some(e=>e.nodeName==`DIV`||e.nodeName==`P`))||!v&&h.pos<l.doc.content.size&&(!h.sameParent(g)||!h.parent.inlineContent)&&h.pos<g.pos&&!/\S/.test(l.doc.textBetween(h.pos,g.pos,``,``)))&&e.someProp(`handleKeyDown`,t=>t(e,Bi(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(e.state.selection.anchor>m.start&&zc(u,m.start,m.endA,h,g)&&e.someProp(`handleKeyDown`,t=>t(e,Bi(8,`Backspace`)))){aa&&$i&&e.domObserver.suppressSelectionUpdates();return}$i&&m.endB==m.start&&(e.input.lastChromeDelete=Date.now()),aa&&!v&&h.start()!=g.start()&&g.parentOffset==0&&h.depth==g.depth&&l.sel&&l.sel.anchor==l.sel.head&&l.sel.head==m.endA&&(m.endB-=2,g=l.doc.resolveNoCache(m.endB-l.from),setTimeout(()=>{e.someProp(`handleKeyDown`,function(t){return t(e,Bi(13,`Enter`))})},20));let y=m.start,b=m.endA,x=t=>{let n=t||e.state.tr.replace(y,b,l.doc.slice(m.start-l.from,m.endB-l.from));if(l.sel){let t=Lc(e,n.doc,l.sel);t&&!($i&&e.composing&&t.empty&&(m.start!=m.endB||e.input.lastChromeDelete<Date.now()-100)&&(t.head==y||t.head==n.mapping.map(b)-1)||Yi&&t.empty&&t.head==y)&&n.setSelection(t)}return a&&n.setMeta(`composition`,a),n.scrollIntoView()},S;if(v)if(h.pos==g.pos){Yi&&Xi<=11&&h.parentOffset==0&&(e.domObserver.suppressSelectionUpdates(),setTimeout(()=>vo(e),20));let t=x(e.state.tr.delete(y,b)),n=u.resolve(m.start).marksAcross(u.resolve(m.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(m.endA==m.endB&&(S=Rc(h.parent.content.cut(h.parentOffset,g.parentOffset),_.parent.content.cut(_.parentOffset,m.endA-_.start())))){let t=x(e.state.tr);S.type==`add`?t.addMark(y,b,S.mark):t.removeMark(y,b,S.mark),e.dispatch(t)}else if(h.parent.child(h.index()).isText&&h.index()==g.index()-(g.textOffset?0:1)){let t=h.parent.textBetween(h.parentOffset,g.parentOffset),n=()=>x(e.state.tr.insertText(t,y,b));e.someProp(`handleTextInput`,r=>r(e,y,b,t,n))||e.dispatch(n())}else e.dispatch(x());else e.dispatch(x())}function Lc(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:Do(e,t.resolve(n.anchor),t.resolve(n.head))}function Rc(e,t){let n=e.firstChild.marks,r=t.firstChild.marks,i=n,a=r,o,s,c;for(let e=0;e<r.length;e++)i=r[e].removeFromSet(i);for(let e=0;e<n.length;e++)a=n[e].removeFromSet(a);if(i.length==1&&a.length==0)s=i[0],o=`add`,c=e=>e.mark(s.addToSet(e.marks));else if(i.length==0&&a.length==1)s=a[0],o=`remove`,c=e=>e.mark(s.removeFromSet(e.marks));else return null;let l=[];for(let e=0;e<t.childCount;e++)l.push(c(t.child(e)));if(E.from(l).eq(e))return{mark:s,type:o}}function zc(e,t,n,r,i){if(n-t<=i.pos-r.pos||Bc(r,!0,!1)<i.pos)return!1;let a=e.resolve(t);if(!r.parent.isTextblock){let e=a.nodeAfter;return e!=null&&n==t+e.nodeSize}if(a.parentOffset<a.parent.content.size||!a.parent.isTextblock)return!1;let o=e.resolve(Bc(a,!0,!0));return!o.parent.isTextblock||o.pos>n||Bc(o,!0,!1)<n?!1:r.parent.content.cut(r.parentOffset).eq(o.parent.content)}function Bc(e,t,n){let r=e.depth,i=t?e.end():e.pos;for(;r>0&&(t||e.indexAfter(r)==e.node(r).childCount);)r--,i++,t=!1;if(n){let t=e.node(r).maybeChild(e.indexAfter(r));for(;t&&!t.isLeaf;)t=t.firstChild,i++}return i}function Vc(e,t,n,r,i){let a=e.findDiffStart(t,n);if(a==null)return null;let{a:o,b:s}=e.findDiffEnd(t,n+e.size,n+t.size);if(i==`end`){let e=Math.max(0,a-Math.min(o,s));r-=o+e-a}if(o<a&&e.size<t.size){let e=r<=a&&r>=o?a-r:0;a-=e,a&&a<t.size&&Hc(t.textBetween(a-1,a+1))&&(a+=e?1:-1),s=a+(s-o),o=a}else if(s<a){let t=r<=a&&r>=s?a-r:0;a-=t,a&&a<e.size&&Hc(e.textBetween(a-1,a+1))&&(a+=t?1:-1),o=a+(o-s),s=a}return{start:a,endA:o,endB:s}}function Hc(e){if(e.length!=2)return!1;let t=e.charCodeAt(0),n=e.charCodeAt(1);return t>=56320&&t<=57343&&n>=55296&&n<=56319}var Uc=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new _s,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Xc),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement(`div`),e&&(e.appendChild?e.appendChild(this.dom):typeof e==`function`?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=Kc(this),Gc(this),this.nodeViews=Jc(this),this.docView=Ya(this.state.doc,Wc(this),xc(this),this.dom,this),this.domObserver=new Tc(this,(e,t,n,r)=>Ic(this,e,t,n,r)),this.domObserver.start(),vs(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&xs(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Xc),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let e in this._props)t[e]=this._props[e];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){let n=this.state,r=!1,i=!1;e.storedMarks&&this.composing&&(Hs(this),i=!0),this.state=e;let a=n.plugins!=e.plugins||this._props.plugins!=t.plugins;if(a||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=Jc(this);Yc(e,this.nodeViews)&&(this.nodeViews=e,r=!0)}(a||t.handleDOMEvents!=this._props.handleDOMEvents)&&xs(this),this.editable=Kc(this),Gc(this);let o=xc(this),s=Wc(this),c=n.plugins!=e.plugins&&!n.doc.eq(e.doc)?`reset`:e.scrollToSelection>n.scrollToSelection?`to selection`:`preserve`,l=r||!this.docView.matchesNode(e.doc,s,o);(l||!e.selection.eq(n.selection))&&(i=!0);let u=c==`preserve`&&i&&this.dom.style.overflowAnchor==null&&fa(this);if(i){this.domObserver.stop();let t=l&&(Yi||$i)&&!this.composing&&!n.selection.empty&&!e.selection.empty&&qc(n.selection,e.selection);if(l){let n=$i?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=Us(this)),(r||!this.docView.update(e.doc,s,o,this))&&(this.docView.updateOuterDeco(s),this.docView.destroy(),this.docView=Ya(e.doc,s,o,this.dom,this)),n&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(t=!0)}t||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Ao(this))?vo(this,t):(To(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(n),this.dragging?.node&&!n.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,n),c==`reset`?this.dom.scrollTop=0:c==`to selection`?this.scrollToSelection():u&&ma(u)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))&&!this.someProp(`handleScrollToSelection`,e=>e(this)))if(this.state.selection instanceof A){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&da(this,t.getBoundingClientRect(),e)}else da(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let e=0;e<this.directPlugins.length;e++){let t=this.directPlugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}for(let e=0;e<this.state.plugins.length;e++){let t=this.state.plugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let n=this.pluginViews[t];n.update&&n.update(this,e)}}updateDraggedNode(e,t){let n=e.node,r=-1;if(n.from<this.state.doc.content.size&&this.state.doc.nodeAt(n.from)==n.node)r=n.from;else{let e=n.from+(this.state.doc.content.size-t.doc.content.size);(e>0&&e<this.state.doc.content.size&&this.state.doc.nodeAt(e))==n.node&&(r=e)}this.dragging=new Qs(e.slice,e.move,r<0?void 0:A.create(this.state.doc,r))}someProp(e,t){let n=this._props&&this._props[e],r;if(n!=null&&(r=t?t(n):n))return r;for(let n=0;n<this.directPlugins.length;n++){let i=this.directPlugins[n].props[e];if(i!=null&&(r=t?t(i):i))return r}let i=this.state.plugins;if(i)for(let n=0;n<i.length;n++){let a=i[n].props[e];if(a!=null&&(r=t?t(a):a))return r}}hasFocus(){if(Yi){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if(e.contentEditable==`false`)return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&_a(this.dom),vo(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let e=this.dom.parentNode;e;e=e.parentNode)if(e.nodeType==9||e.nodeType==11&&e.host)return e.getSelection||(Object.getPrototypeOf(e).getSelection=()=>e.ownerDocument.getSelection()),this._root=e}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Ta(this,e)}coordsAtPos(e,t=1){return ka(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let r=this.docView.posFromDOM(e,t,n);if(r==null)throw RangeError(`DOM position not inside the editor`);return r}endOfTextblock(e,t){return za(this,t||this.state,e)}pasteHTML(e,t){return Xs(this,``,e,!1,t||new ClipboardEvent(`paste`))}pasteText(e,t){return Xs(this,e,null,!0,t||new ClipboardEvent(`paste`))}serializeForClipboard(e){return Xo(this,e)}destroy(){this.docView&&(bs(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],xc(this),this),this.dom.textContent=``):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Ai())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return ws(this,e)}domSelectionRange(){let e=this.domSelection();return e?ta&&this.root.nodeType===11&&Vi(this.dom.ownerDocument)==this.dom&&Ac(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};Uc.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};function Wc(e){let t=Object.create(null);return t.class=`ProseMirror`,t.contenteditable=String(e.editable),e.someProp(`attributes`,n=>{if(typeof n==`function`&&(n=n(e.state)),n)for(let e in n)e==`class`?t.class+=` `+n[e]:e==`style`?t.style=(t.style?t.style+`;`:``)+n[e]:!t[e]&&e!=`contenteditable`&&e!=`nodeName`&&(t[e]=String(n[e]))}),t.translate||=`no`,[oc.node(0,e.state.doc.content.size,t)]}function Gc(e){if(e.markCursor){let t=document.createElement(`img`);t.className=`ProseMirror-separator`,t.setAttribute(`mark-placeholder`,`true`),t.setAttribute(`alt`,``),e.cursorWrapper={dom:t,deco:oc.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function Kc(e){return!e.someProp(`editable`,t=>t(e.state)===!1)}function qc(e,t){let n=Math.min(e.$anchor.sharedDepth(e.head),t.$anchor.sharedDepth(t.head));return e.$anchor.start(n)!=t.$anchor.start(n)}function Jc(e){let t=Object.create(null);function n(e){for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])}return e.someProp(`nodeViews`,n),e.someProp(`markViews`,n),t}function Yc(e,t){let n=0,r=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let e in t)r++;return n!=r}function Xc(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw RangeError(`Plugins passed directly to the view must not have a state component`)}for(var Zc={8:`Backspace`,9:`Tab`,10:`Enter`,12:`NumLock`,13:`Enter`,16:`Shift`,17:`Control`,18:`Alt`,20:`CapsLock`,27:`Escape`,32:` `,33:`PageUp`,34:`PageDown`,35:`End`,36:`Home`,37:`ArrowLeft`,38:`ArrowUp`,39:`ArrowRight`,40:`ArrowDown`,44:`PrintScreen`,45:`Insert`,46:`Delete`,59:`;`,61:`=`,91:`Meta`,92:`Meta`,106:`*`,107:`+`,108:`,`,109:`-`,110:`.`,111:`/`,144:`NumLock`,145:`ScrollLock`,160:`Shift`,161:`Shift`,162:`Control`,163:`Control`,164:`Alt`,165:`Alt`,173:`-`,186:`;`,187:`=`,188:`,`,189:`-`,190:`.`,191:`/`,192:"`",219:`[`,220:`\\`,221:`]`,222:`'`},Qc={48:`)`,49:`!`,50:`@`,51:`#`,52:`$`,53:`%`,54:`^`,55:`&`,56:`*`,57:`(`,59:`:`,61:`+`,173:`_`,186:`:`,187:`+`,188:`<`,189:`_`,190:`>`,191:`?`,192:`~`,219:`{`,220:`|`,221:`}`,222:`"`},$c=typeof navigator<`u`&&/Mac/.test(navigator.platform),el=typeof navigator<`u`&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),tl=0;tl<10;tl++)Zc[48+tl]=Zc[96+tl]=String(tl);for(var tl=1;tl<=24;tl++)Zc[tl+111]=`F`+tl;for(var tl=65;tl<=90;tl++)Zc[tl]=String.fromCharCode(tl+32),Qc[tl]=String.fromCharCode(tl);for(var nl in Zc)Qc.hasOwnProperty(nl)||(Qc[nl]=Zc[nl]);function rl(e){var t=!($c&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||el&&e.shiftKey&&e.key&&e.key.length==1||e.key==`Unidentified`)&&e.key||(e.shiftKey?Qc:Zc)[e.keyCode]||e.key||`Unidentified`;return t==`Esc`&&(t=`Escape`),t==`Del`&&(t=`Delete`),t==`Left`&&(t=`ArrowLeft`),t==`Up`&&(t=`ArrowUp`),t==`Right`&&(t=`ArrowRight`),t==`Down`&&(t=`ArrowDown`),t}var il=typeof navigator<`u`&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),al=typeof navigator<`u`&&/Win/.test(navigator.platform);function ol(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n==`Space`&&(n=` `);let r,i,a,o;for(let e=0;e<t.length-1;e++){let n=t[e];if(/^(cmd|meta|m)$/i.test(n))o=!0;else if(/^a(lt)?$/i.test(n))r=!0;else if(/^(c|ctrl|control)$/i.test(n))i=!0;else if(/^s(hift)?$/i.test(n))a=!0;else if(/^mod$/i.test(n))il?o=!0:i=!0;else throw Error(`Unrecognized modifier name: `+n)}return r&&(n=`Alt-`+n),i&&(n=`Ctrl-`+n),o&&(n=`Meta-`+n),a&&(n=`Shift-`+n),n}function sl(e){let t=Object.create(null);for(let n in e)t[ol(n)]=e[n];return t}function cl(e,t,n=!0){return t.altKey&&(e=`Alt-`+e),t.ctrlKey&&(e=`Ctrl-`+e),t.metaKey&&(e=`Meta-`+e),n&&t.shiftKey&&(e=`Shift-`+e),e}function ll(e){return new Mr({props:{handleKeyDown:ul(e)}})}function ul(e){let t=sl(e);return function(e,n){let r=rl(n),i,a=t[cl(r,n)];if(a&&a(e.state,e.dispatch,e))return!0;if(r.length==1&&r!=` `){if(n.shiftKey){let i=t[cl(r,n,!1)];if(i&&i(e.state,e.dispatch,e))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(al&&n.ctrlKey&&n.altKey)&&(i=Zc[n.keyCode])&&i!=r){let r=t[cl(i,n)];if(r&&r(e.state,e.dispatch,e))return!0}}return!1}}var dl=Object.defineProperty,fl=(e,t)=>{for(var n in t)dl(e,n,{get:t[n],enumerable:!0})};function pl(e){let{state:t,transaction:n}=e,{selection:r}=n,{doc:i}=n,{storedMarks:a}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return a},get selection(){return r},get doc(){return i},get tr(){return r=n.selection,i=n.doc,a=n.storedMarks,n}}}var ml=class{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){let{rawCommands:e,editor:t,state:n}=this,{view:r}=t,{tr:i}=n,a=this.buildProps(i);return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,(...e)=>{let n=t(...e)(a);return!i.getMeta(`preventDispatch`)&&!this.hasCustomState&&r.dispatch(i),n}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,o=[],s=!!e,c=e||i.tr,l=()=>(!s&&t&&!c.getMeta(`preventDispatch`)&&!this.hasCustomState&&a.dispatch(c),o.every(e=>e===!0)),u={...Object.fromEntries(Object.entries(n).map(([e,n])=>[e,(...e)=>{let r=this.buildProps(c,t),i=n(...e)(r);return o.push(i),u}])),run:l};return u}createCan(e){let{rawCommands:t,state:n}=this,r=e||n.tr,i=this.buildProps(r,!1);return{...Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>t(...e)({...i,dispatch:void 0})])),chain:()=>this.createChain(r,!1)}}buildProps(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,o={tr:e,editor:r,view:a,state:pl({state:i,transaction:e}),dispatch:t?()=>void 0:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,(...e)=>t(...e)(o)]))}};return o}},hl={};fl(hl,{blur:()=>gl,clearContent:()=>_l,clearNodes:()=>vl,command:()=>yl,createParagraphNear:()=>bl,cut:()=>xl,deleteCurrentNode:()=>Sl,deleteNode:()=>wl,deleteRange:()=>Tl,deleteSelection:()=>El,enter:()=>Dl,exitCode:()=>Ol,extendMarkRange:()=>Fl,first:()=>Il,focus:()=>Ul,forEach:()=>Wl,insertContent:()=>Gl,insertContentAt:()=>Zl,joinBackward:()=>eu,joinDown:()=>$l,joinForward:()=>tu,joinItemBackward:()=>nu,joinItemForward:()=>ru,joinTextblockBackward:()=>iu,joinTextblockForward:()=>au,joinUp:()=>Ql,keyboardShortcut:()=>cu,lift:()=>uu,liftEmptyBlock:()=>du,liftListItem:()=>fu,newlineInCode:()=>pu,resetAttributes:()=>gu,scrollIntoView:()=>_u,selectAll:()=>vu,selectNodeBackward:()=>yu,selectNodeForward:()=>bu,selectParentNode:()=>xu,selectTextblockEnd:()=>Su,selectTextblockStart:()=>Cu,setContent:()=>Tu,setMark:()=>Cd,setMeta:()=>wd,setNode:()=>Td,setNodeSelection:()=>Ed,setTextDirection:()=>Dd,setTextSelection:()=>Od,sinkListItem:()=>kd,splitBlock:()=>jd,splitListItem:()=>Md,toggleList:()=>Fd,toggleMark:()=>Id,toggleNode:()=>Ld,toggleWrap:()=>Rd,undoInputRule:()=>zd,unsetAllMarks:()=>Bd,unsetMark:()=>Vd,unsetTextDirection:()=>Hd,updateAttributes:()=>Ud,wrapIn:()=>Wd,wrapInList:()=>Gd});var gl=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),(n=window==null?void 0:window.getSelection())==null||n.removeAllRanges())}),!0),_l=(e=!0)=>({commands:t})=>t.setContent(``,{emitUpdate:e}),vl=()=>({state:e,tr:t,dispatch:n})=>{let{selection:r}=t,{ranges:i}=r;return n&&i.forEach(({$from:n,$to:r})=>{e.doc.nodesBetween(n.pos,r.pos,(e,n)=>{if(e.type.isText)return;let{doc:r,mapping:i}=t,a=r.resolve(i.map(n)),o=r.resolve(i.map(n+e.nodeSize)),s=a.blockRange(o);if(!s)return;let c=En(s);if(e.type.isTextblock){let{defaultType:e}=a.parent.contentMatchAt(a.index());t.setNodeMarkup(s.start,e)}(c||c===0)&&t.lift(s,c)})}),!0},yl=e=>t=>e(t),bl=()=>({state:e,dispatch:t})=>ti(e,t),xl=(e,t)=>({editor:n,tr:r})=>{let{state:i}=n,a=i.doc.slice(e.from,e.to);r.deleteRange(e.from,e.to);let o=r.mapping.map(t);return r.insert(o,a.content),r.setSelection(new k(r.doc.resolve(Math.max(o-1,0)))),!0},Sl=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;let i=e.selection.$anchor;for(let n=i.depth;n>0;--n)if(i.node(n).type===r.type){if(t){let t=i.before(n),r=i.after(n);e.delete(t,r).scrollIntoView()}return!0}return!1};function Cl(e,t){if(typeof e==`string`){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}var wl=e=>({tr:t,state:n,dispatch:r})=>{let i=Cl(e,n.schema),a=t.selection.$anchor;for(let e=a.depth;e>0;--e)if(a.node(e).type===i){if(r){let n=a.before(e),r=a.after(e);t.delete(n,r).scrollIntoView()}return!0}return!1},Tl=e=>({tr:t,dispatch:n})=>{let{from:r,to:i}=e;return n&&t.delete(r,i),!0},El=()=>({state:e,dispatch:t})=>Ir(e,t),Dl=()=>({commands:e})=>e.keyboardShortcut(`Enter`),Ol=()=>({state:e,dispatch:t})=>ei(e,t);function kl(e){return Object.prototype.toString.call(e)===`[object RegExp]`}function Al(e,t,n={strict:!0}){let r=Object.keys(t);return r.length?r.every(r=>n.strict?t[r]===e[r]:kl(t[r])?t[r].test(e[r]):t[r]===e[r]):!0}function jl(e,t,n={}){return e.find(e=>e.type===t&&Al(Object.fromEntries(Object.keys(n).map(t=>[t,e.attrs[t]])),n))}function Ml(e,t,n={}){return!!jl(e,t,n)}function Nl(e,t,n){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if((!r.node||!r.node.marks.some(e=>e.type===t))&&(r=e.parent.childBefore(e.parentOffset)),!r.node||!r.node.marks.some(e=>e.type===t))return;if(!n){let e=r.node.marks.find(e=>e.type===t);e&&(n=e.attrs)}if(!jl([...r.node.marks],t,n))return;let i=r.index,a=e.start()+r.offset,o=i+1,s=a+r.node.nodeSize;for(;i>0&&Ml([...e.parent.child(i-1).marks],t,n);)--i,a-=e.parent.child(i).nodeSize;for(;o<e.parent.childCount&&Ml([...e.parent.child(o).marks],t,n);)s+=e.parent.child(o).nodeSize,o+=1;return{from:a,to:s}}function Pl(e,t){if(typeof e==`string`){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}var Fl=(e,t)=>({tr:n,state:r,dispatch:i})=>{let a=Pl(e,r.schema),{doc:o,selection:s}=n,{$from:c,from:l,to:u}=s;if(i){let e=Nl(c,a,t);if(e&&e.from<=l&&e.to>=u){let t=k.create(o,e.from,e.to);n.setSelection(t)}}return!0},Il=e=>t=>{let n=typeof e==`function`?e(t):e;for(let e=0;e<n.length;e+=1)if(n[e](t))return!0;return!1};function Ll(e){return e instanceof k}function Rl(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function zl(e,t=null){if(!t)return null;let n=O.atStart(e),r=O.atEnd(e);if(t===`start`||t===!0)return n;if(t===`end`)return r;let i=n.from,a=r.to;return t===`all`?k.create(e,Rl(0,i,a),Rl(e.content.size,i,a)):k.create(e,Rl(t,i,a),Rl(t,i,a))}function Bl(){return navigator.platform===`Android`||/android/i.test(navigator.userAgent)}function Vl(){return[`iPad Simulator`,`iPhone Simulator`,`iPod Simulator`,`iPad`,`iPhone`,`iPod`].includes(navigator.platform)||navigator.userAgent.includes(`Mac`)&&`ontouchend`in document}function Hl(){return typeof navigator<`u`?/^((?!chrome|android).)*safari/i.test(navigator.userAgent):!1}var Ul=(e=null,t={})=>({editor:n,view:r,tr:i,dispatch:a})=>{t={scrollIntoView:!0,...t};let o=()=>{(Vl()||Bl())&&r.dom.focus(),Hl()&&!Vl()&&!Bl()&&r.dom.focus({preventScroll:!0}),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),t?.scrollIntoView&&n.commands.scrollIntoView())})};try{if(r.hasFocus()&&e===null||e===!1)return!0}catch{return!1}if(a&&e===null&&!Ll(n.state.selection))return o(),!0;let s=zl(i.doc,e)||n.state.selection,c=n.state.selection.eq(s);return a&&(c||i.setSelection(s),c&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},Wl=(e,t)=>n=>e.every((e,r)=>t(e,{...n,index:r})),Gl=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t),Kl=e=>{let t=e.childNodes;for(let n=t.length-1;n>=0;--n){let r=t[n];r.nodeType===3&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?e.removeChild(r):r.nodeType===1&&Kl(r)}return e};function ql(e){if(typeof window>`u`)throw Error(`[tiptap error]: there is no window object available, so this function cannot be used`);let t=`<body>${e}</body>`,n=new window.DOMParser().parseFromString(t,`text/html`).body;return Kl(n)}function Jl(e,t,n){if(e instanceof nt||e instanceof E)return e;n={slice:!0,parseOptions:{},...n};let r=typeof e==`object`&&!!e,i=typeof e==`string`;if(r)try{if(Array.isArray(e)&&e.length>0)return E.fromArray(e.map(e=>t.nodeFromJSON(e)));let r=t.nodeFromJSON(e);return n.errorOnInvalidContent&&r.check(),r}catch(r){if(n.errorOnInvalidContent)throw Error(`[tiptap error]: Invalid JSON content`,{cause:r});return console.warn(`[tiptap warn]: Invalid content.`,`Passed value:`,e,`Error:`,r),Jl(``,t,n)}if(i){if(n.errorOnInvalidContent){let r=!1,i=``,a=new Dt({topNode:t.spec.topNode,marks:t.spec.marks,nodes:t.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:`inline*`,group:`block`,parseDOM:[{tag:`*`,getAttrs:e=>(r=!0,i=typeof e==`string`?e:e.outerHTML,null)}]}})});if(n.slice?jt.fromSchema(a).parseSlice(ql(e),n.parseOptions):jt.fromSchema(a).parse(ql(e),n.parseOptions),n.errorOnInvalidContent&&r)throw Error(`[tiptap error]: Invalid HTML content`,{cause:Error(`Invalid element found: ${i}`)})}let r=jt.fromSchema(t);return n.slice?r.parseSlice(ql(e),n.parseOptions).content:r.parse(ql(e),n.parseOptions)}return Jl(``,t,n)}function Yl(e,t,n){let r=e.steps.length-1;if(r<t)return;let i=e.steps[r];if(!(i instanceof yn||i instanceof bn))return;let a=e.mapping.maps[r],o=0;a.forEach((e,t,n,r)=>{o===0&&(o=r)}),e.setSelection(O.near(e.doc.resolve(o),n))}var Xl=e=>!(`type`in e),Zl=(e,t,n)=>({tr:r,dispatch:i,editor:a})=>{if(i){n={parseOptions:a.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let i,o=e=>{a.emit(`contentError`,{editor:a,error:e,disableCollaboration:()=>{`collaboration`in a.storage&&typeof a.storage.collaboration==`object`&&a.storage.collaboration&&(a.storage.collaboration.isDisabled=!0)}})},s={preserveWhitespace:`full`,...n.parseOptions};if(!n.errorOnInvalidContent&&!a.options.enableContentCheck&&a.options.emitContentError)try{Jl(t,a.schema,{parseOptions:s,errorOnInvalidContent:!0})}catch(e){o(e)}try{i=Jl(t,a.schema,{parseOptions:s,errorOnInvalidContent:n.errorOnInvalidContent??a.options.enableContentCheck})}catch(e){return o(e),!1}let{from:c,to:l}=typeof e==`number`?{from:e,to:e}:{from:e.from,to:e.to},u=!0,d=!0;if((Xl(i)?i:[i]).forEach(e=>{e.check(),u=u?e.isText&&e.marks.length===0:!1,d=d?e.isBlock:!1}),c===l&&d){let{parent:e}=r.doc.resolve(c);e.isTextblock&&!e.type.spec.code&&!e.childCount&&(--c,l+=1)}let f;if(u){if(Array.isArray(t))f=t.map(e=>e.text||``).join(``);else if(t instanceof E){let e=``;t.forEach(t=>{t.text&&(e+=t.text)}),f=e}else f=typeof t==`object`&&t&&t.text?t.text:t;r.insertText(f,c,l)}else{f=i;let e=r.doc.resolve(c),t=e.node(),n=e.parentOffset===0,a=t.isText||t.isTextblock,o=t.content.size>0;n&&a&&o&&(c=Math.max(0,c-1)),r.replaceWith(c,l,f)}n.updateSelection&&Yl(r,r.steps.length-1,-1),n.applyInputRules&&r.setMeta(`applyInputRules`,{from:c,text:f}),n.applyPasteRules&&r.setMeta(`applyPasteRules`,{from:c,text:f})}return!0},Ql=()=>({state:e,dispatch:t})=>Yr(e,t),$l=()=>({state:e,dispatch:t})=>Xr(e,t),eu=()=>({state:e,dispatch:t})=>Rr(e,t),tu=()=>({state:e,dispatch:t})=>Kr(e,t),nu=()=>({state:e,dispatch:t,tr:n})=>{try{let r=Un(e.doc,e.selection.$from.pos,-1);return r==null?!1:(n.join(r,2),t&&t(n),!0)}catch{return!1}},ru=()=>({state:e,dispatch:t,tr:n})=>{try{let r=Un(e.doc,e.selection.$from.pos,1);return r==null?!1:(n.join(r,2),t&&t(n),!0)}catch{return!1}},iu=()=>({state:e,dispatch:t})=>zr(e,t),au=()=>({state:e,dispatch:t})=>Br(e,t);function ou(){return typeof navigator<`u`?/Mac/.test(navigator.platform):!1}function su(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n===`Space`&&(n=` `);let r,i,a,o;for(let e=0;e<t.length-1;e+=1){let n=t[e];if(/^(cmd|meta|m)$/i.test(n))o=!0;else if(/^a(lt)?$/i.test(n))r=!0;else if(/^(c|ctrl|control)$/i.test(n))i=!0;else if(/^s(hift)?$/i.test(n))a=!0;else if(/^mod$/i.test(n))Vl()||ou()?o=!0:i=!0;else throw Error(`Unrecognized modifier name: ${n}`)}return r&&(n=`Alt-${n}`),i&&(n=`Ctrl-${n}`),o&&(n=`Meta-${n}`),a&&(n=`Shift-${n}`),n}var cu=e=>({editor:t,view:n,tr:r,dispatch:i})=>{let a=su(e).split(/-(?!$)/),o=a.find(e=>![`Alt`,`Ctrl`,`Meta`,`Shift`].includes(e)),s=new KeyboardEvent(`keydown`,{key:o===`Space`?` `:o,altKey:a.includes(`Alt`),ctrlKey:a.includes(`Ctrl`),metaKey:a.includes(`Meta`),shiftKey:a.includes(`Shift`),bubbles:!0,cancelable:!0});return t.captureTransaction(()=>{n.someProp(`handleKeyDown`,e=>e(n,s))})?.steps.forEach(e=>{let t=e.map(r.mapping);t&&i&&r.maybeStep(t)}),!0};function lu(e,t,n={}){let{from:r,to:i,empty:a}=e.selection,o=t?Cl(t,e.schema):null,s=[];e.doc.nodesBetween(r,i,(e,t)=>{if(e.isText)return;let n=Math.max(r,t),a=Math.min(i,t+e.nodeSize);s.push({node:e,from:n,to:a})});let c=i-r,l=s.filter(e=>o?o.name===e.node.type.name:!0).filter(e=>Al(e.node.attrs,n,{strict:!1}));return a?!!l.length:l.reduce((e,t)=>e+t.to-t.from,0)>=c}var uu=(e,t={})=>({state:n,dispatch:r})=>lu(n,Cl(e,n.schema),t)?Zr(n,r):!1,du=()=>({state:e,dispatch:t})=>ni(e,t),fu=e=>({state:t,dispatch:n})=>Si(Cl(e,t.schema))(t,n),pu=()=>({state:e,dispatch:t})=>Qr(e,t);function mu(e,t){return t.nodes[e]?`node`:t.marks[e]?`mark`:null}function hu(e,t){let n=typeof t==`string`?[t]:t;return Object.keys(e).reduce((t,r)=>(n.includes(r)||(t[r]=e[r]),t),{})}var gu=(e,t)=>({tr:n,state:r,dispatch:i})=>{let a=null,o=null,s=mu(typeof e==`string`?e:e.name,r.schema);if(!s)return!1;s===`node`&&(a=Cl(e,r.schema)),s===`mark`&&(o=Pl(e,r.schema));let c=!1;return n.selection.ranges.forEach(e=>{r.doc.nodesBetween(e.$from.pos,e.$to.pos,(e,r)=>{a&&a===e.type&&(c=!0,i&&n.setNodeMarkup(r,void 0,hu(e.attrs,t))),o&&e.marks.length&&e.marks.forEach(a=>{o===a.type&&(c=!0,i&&n.addMark(r,r+e.nodeSize,o.create(hu(a.attrs,t))))})})}),c},_u=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),vu=()=>({tr:e,dispatch:t})=>{if(t){let t=new vr(e.doc);e.setSelection(t)}return!0},yu=()=>({state:e,dispatch:t})=>Ur(e,t),bu=()=>({state:e,dispatch:t})=>qr(e,t),xu=()=>({state:e,dispatch:t})=>ai(e,t),Su=()=>({state:e,dispatch:t})=>di(e,t),Cu=()=>({state:e,dispatch:t})=>ui(e,t);function wu(e,t,n={},r={}){return Jl(e,t,{slice:!1,parseOptions:n,errorOnInvalidContent:r.errorOnInvalidContent})}var Tu=(e,{errorOnInvalidContent:t,emitUpdate:n=!0,parseOptions:r={}}={})=>({editor:i,tr:a,dispatch:o,commands:s})=>{let{doc:c}=a;if(r.preserveWhitespace!==`full`){let s=wu(e,i.schema,r,{errorOnInvalidContent:t??i.options.enableContentCheck});return o&&a.replaceWith(0,c.content.size,s).setMeta(`preventUpdate`,!n),!0}return o&&a.setMeta(`preventUpdate`,!n),s.insertContentAt({from:0,to:c.content.size},e,{parseOptions:r,errorOnInvalidContent:t??i.options.enableContentCheck})};function Eu(e,t){let n=Pl(t,e.schema),{from:r,to:i,empty:a}=e.selection,o=[];a?(e.storedMarks&&o.push(...e.storedMarks),o.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,i,e=>{o.push(...e.marks)});let s=o.find(e=>e.type.name===n.name);return s?{...s.attrs}:{}}function Du(e,t){let n=new dr(e);return t.forEach(e=>{e.steps.forEach(e=>{n.step(e)})}),n}function Ou(e){for(let t=0;t<e.edgeCount;t+=1){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}function ku(e,t,n){let r=[];return e.nodesBetween(t.from,t.to,(e,t)=>{n(e)&&r.push({node:e,pos:t})}),r}function Au(e,t){for(let n=e.depth;n>0;--n){let r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function ju(e){return t=>Au(t.$from,e)}function j(e,t,n){return e.config[t]===void 0&&e.parent?j(e.parent,t,n):typeof e.config[t]==`function`?e.config[t].bind({...n,parent:e.parent?j(e.parent,t,n):null}):e.config[t]}function Mu(e){return e.map(e=>{let t=j(e,`addExtensions`,{name:e.name,options:e.options,storage:e.storage});return t?[e,...Mu(t())]:e}).flat(10)}function Nu(e,t){let n=Gt.fromSchema(t).serializeFragment(e),r=document.implementation.createHTMLDocument().createElement(`div`);return r.appendChild(n),r.innerHTML}function Pu(e){return typeof e==`function`}function M(e,t=void 0,...n){return Pu(e)?t?e.bind(t)(...n):e(...n):e}function Fu(e={}){return Object.keys(e).length===0&&e.constructor===Object}function Iu(e){return{baseExtensions:e.filter(e=>e.type===`extension`),nodeExtensions:e.filter(e=>e.type===`node`),markExtensions:e.filter(e=>e.type===`mark`)}}function Lu(e){let t=[],{nodeExtensions:n,markExtensions:r}=Iu(e),i=[...n,...r],a={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1},o=n.filter(e=>e.name!==`text`).map(e=>e.name),s=r.map(e=>e.name),c=[...o,...s];return e.forEach(e=>{let n=j(e,`addGlobalAttributes`,{name:e.name,options:e.options,storage:e.storage,extensions:i});n&&n().forEach(e=>{let n;n=Array.isArray(e.types)?e.types:e.types===`*`?c:e.types===`nodes`?o:e.types===`marks`?s:[],n.forEach(n=>{Object.entries(e.attributes).forEach(([e,r])=>{t.push({type:n,name:e,attribute:{...a,...r}})})})})}),i.forEach(e=>{let n=j(e,`addAttributes`,{name:e.name,options:e.options,storage:e.storage});if(!n)return;let r=n();Object.entries(r).forEach(([n,r])=>{let i={...a,...r};typeof i?.default==`function`&&(i.default=i.default()),i?.isRequired&&i?.default===void 0&&delete i.default,t.push({type:e.name,name:n,attribute:i})})}),t}function Ru(e){let t=[],n=``,r=!1,i=!1,a=0,o=e.length;for(let s=0;s<o;s+=1){let o=e[s];if(o===`'`&&!i){r=!r,n+=o;continue}if(o===`"`&&!r){i=!i,n+=o;continue}if(!r&&!i){if(o===`(`){a+=1,n+=o;continue}if(o===`)`&&a>0){--a,n+=o;continue}if(o===`;`&&a===0){t.push(n),n=``;continue}}n+=o}return n&&t.push(n),t}function zu(e){let t=[],n=Ru(e||``),r=n.length;for(let e=0;e<r;e+=1){let r=n[e],i=r.indexOf(`:`);if(i===-1)continue;let a=r.slice(0,i).trim(),o=r.slice(i+1).trim();a&&o&&t.push([a,o])}return t}function Bu(...e){return e.filter(e=>!!e).reduce((e,t)=>{let n={...e};return Object.entries(t).forEach(([e,t])=>{if(!n[e]){n[e]=t;return}if(e===`class`){let r=t?String(t).split(` `):[],i=n[e]?n[e].split(` `):[],a=r.filter(e=>!i.includes(e));n[e]=[...i,...a].join(` `)}else if(e===`style`){let r=new Map([...zu(n[e]),...zu(t)]);n[e]=Array.from(r.entries()).map(([e,t])=>`${e}: ${t}`).join(`; `)}else n[e]=t}),n},{})}function Vu(e,t){return t.filter(t=>t.type===e.type.name).filter(e=>e.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(e.attrs)||{}:{[t.name]:e.attrs[t.name]}).reduce((e,t)=>Bu(e,t),{})}function Hu(e){return typeof e==`string`?e.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(e):e===`true`?!0:e===`false`?!1:e:e}function Uu(e,t){return`style`in e?e:{...e,getAttrs:n=>{let r=e.getAttrs?e.getAttrs(n):e.attrs;if(r===!1)return!1;let i=t.reduce((e,t)=>{let r=t.attribute.parseHTML?t.attribute.parseHTML(n):Hu(n.getAttribute(t.name));return r==null?e:{...e,[t.name]:r}},{});return{...r,...i}}}}function Wu(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>e===`attrs`&&Fu(t)?!1:t!=null))}function Gu(e){let t={};return!e?.attribute?.isRequired&&`default`in(e?.attribute||{})&&(t.default=e.attribute.default),e?.attribute?.validate!==void 0&&(t.validate=e.attribute.validate),[e.name,t]}function Ku(e,t){let n=Lu(e),{nodeExtensions:r,markExtensions:i}=Iu(e);return new Dt({topNode:r.find(e=>j(e,`topNode`))?.name,nodes:Object.fromEntries(r.map(r=>{let i=n.filter(e=>e.type===r.name),a={name:r.name,options:r.options,storage:r.storage,editor:t},o=Wu({...e.reduce((e,t)=>{let n=j(t,`extendNodeSchema`,a);return{...e,...n?n(r):{}}},{}),content:M(j(r,`content`,a)),marks:M(j(r,`marks`,a)),group:M(j(r,`group`,a)),inline:M(j(r,`inline`,a)),atom:M(j(r,`atom`,a)),selectable:M(j(r,`selectable`,a)),draggable:M(j(r,`draggable`,a)),code:M(j(r,`code`,a)),whitespace:M(j(r,`whitespace`,a)),linebreakReplacement:M(j(r,`linebreakReplacement`,a)),defining:M(j(r,`defining`,a)),isolating:M(j(r,`isolating`,a)),attrs:Object.fromEntries(i.map(Gu))}),s=M(j(r,`parseHTML`,a));s&&(o.parseDOM=s.map(e=>Uu(e,i)));let c=j(r,`renderHTML`,a);c&&(o.toDOM=e=>c({node:e,HTMLAttributes:Vu(e,i)}));let l=j(r,`renderText`,a);return l&&(o.toText=l),[r.name,o]})),marks:Object.fromEntries(i.map(r=>{let i=n.filter(e=>e.type===r.name),a={name:r.name,options:r.options,storage:r.storage,editor:t},o=Wu({...e.reduce((e,t)=>{let n=j(t,`extendMarkSchema`,a);return{...e,...n?n(r):{}}},{}),inclusive:M(j(r,`inclusive`,a)),excludes:M(j(r,`excludes`,a)),group:M(j(r,`group`,a)),spanning:M(j(r,`spanning`,a)),code:M(j(r,`code`,a)),attrs:Object.fromEntries(i.map(Gu))}),s=M(j(r,`parseHTML`,a));s&&(o.parseDOM=s.map(e=>Uu(e,i)));let c=j(r,`renderHTML`,a);return c&&(o.toDOM=e=>c({mark:e,HTMLAttributes:Vu(e,i)})),[r.name,o]}))})}function qu(e){let t=e.filter((t,n)=>e.indexOf(t)!==n);return Array.from(new Set(t))}function Ju(e){return e.sort((e,t)=>{let n=j(e,`priority`)||100,r=j(t,`priority`)||100;return n>r?-1:n<r?1:0})}function Yu(e){let t=Ju(Mu(e)),n=qu(t.map(e=>e.name));return n.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${n.map(e=>`'${e}'`).join(`, `)}]. This can lead to issues.`),t}function Xu(e,t){return Ku(Yu(e),t)}function Zu(e,t){let n=Xu(t),r=ql(e);return jt.fromSchema(n).parse(r).toJSON()}function Qu(e,t,n){let{from:r,to:i}=t,{blockSeparator:a=`
53
+ `),slice:t}}function Xo(e,t,n,r,i){let a=i.parent.type.spec.code,o,s;if(!n&&!t)return null;let c=!!t&&(r||a||!n);if(c){if(e.someProp(`transformPastedText`,n=>{t=n(t,a||r,e)}),a)return s=new D(E.from(e.state.schema.text(t.replace(/\r\n?/g,`
54
+ `))),0,0),e.someProp(`transformPasted`,t=>{s=t(s,e,!0)}),s;let n=e.someProp(`clipboardTextParser`,n=>n(t,i,r,e));if(n)s=n;else{let n=i.marks(),{schema:r}=e.state,a=Gt.fromSchema(r);o=document.createElement(`div`),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=o.appendChild(document.createElement(`p`));e&&t.appendChild(a.serializeNode(r.text(e,n)))})}}else e.someProp(`transformPastedHTML`,t=>{n=t(n,e)}),o=us(n),aa&&ds(o);let l=o&&o.querySelector(`[data-pm-slice]`),u=l&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(l.getAttribute(`data-pm-slice`)||``);if(u&&u[3])for(let e=+u[3];e>0;e--){let e=o.firstChild;for(;e&&e.nodeType!=1;)e=e.nextSibling;if(!e)break;o=e}if(s||=(e.someProp(`clipboardParser`)||e.someProp(`domParser`)||jt.fromSchema(e.state.schema)).parseSlice(o,{preserveWhitespace:!!(c||u),context:i,ruleFromNode(e){return e.nodeName==`BR`&&!e.nextSibling&&e.parentNode&&!Zo.test(e.parentNode.nodeName)?{ignore:!0}:null}}),u)s=fs(rs(s,+u[1],+u[2]),u[4]);else if(s=D.maxOpen(Qo(s.content,i),!0),s.openStart||s.openEnd){let e=0,t=0;for(let t=s.content.firstChild;e<s.openStart&&!t.type.spec.isolating;e++,t=t.firstChild);for(let e=s.content.lastChild;t<s.openEnd&&!e.type.spec.isolating;t++,e=e.lastChild);s=rs(s,e,t)}return e.someProp(`transformPasted`,t=>{s=t(s,e,c)}),s}var Zo=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function Qo(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.index(n)),i,a=[];if(e.forEach(e=>{if(!a)return;let t=r.findWrapping(e.type),n;if(!t)return a=null;if(n=a.length&&i.length&&es(t,i,e,a[a.length-1],0))a[a.length-1]=n;else{a.length&&(a[a.length-1]=ts(a[a.length-1],i.length));let n=$o(e,t);a.push(n),r=r.matchType(n.type),i=t}}),a)return E.from(a)}return e}function $o(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,E.from(e));return e}function es(e,t,n,r,i){if(i<e.length&&i<t.length&&e[i]==t[i]){let a=es(e,t,n,r.lastChild,i+1);if(a)return r.copy(r.content.replaceChild(r.childCount-1,a));if(r.contentMatchAt(r.childCount).matchType(i==e.length-1?n.type:e[i+1]))return r.copy(r.content.append(E.from($o(n,e,i+1))))}}function ts(e,t){if(t==0)return e;let n=e.content.replaceChild(e.childCount-1,ts(e.lastChild,t-1)),r=e.contentMatchAt(e.childCount).fillBefore(E.empty,!0);return e.copy(n.append(r))}function ns(e,t,n,r,i,a){let o=t<0?e.firstChild:e.lastChild,s=o.content;return e.childCount>1&&(a=0),i<r-1&&(s=ns(s,t,n,r,i+1,a)),i>=n&&(s=t<0?o.contentMatchAt(0).fillBefore(s,a<=i).append(s):s.append(o.contentMatchAt(o.childCount).fillBefore(E.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(s))}function rs(e,t,n){return t<e.openStart&&(e=new D(ns(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new D(ns(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}var is={thead:[`table`],tbody:[`table`],tfoot:[`table`],caption:[`table`],colgroup:[`table`],col:[`table`,`colgroup`],tr:[`table`,`tbody`],td:[`table`,`tbody`,`tr`],th:[`table`,`tbody`,`tr`]},as=null;function ss(){return as||=document.implementation.createHTMLDocument(`title`)}var cs=null;function ls(e){let t=window.trustedTypes;return t?(cs||=t.defaultPolicy||t.createPolicy(`ProseMirrorClipboard`,{createHTML:e=>e}),cs.createHTML(e)):e}function us(e){let t=/^(\s*<meta [^>]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n=ss().createElement(`div`),r=/<([a-z][^>\s]+)/i.exec(e),i;if((i=r&&is[r[1].toLowerCase()])&&(e=i.map(e=>`<`+e+`>`).join(``)+e+i.map(e=>`</`+e+`>`).reverse().join(``)),n.innerHTML=ls(e),i)for(let e=0;e<i.length;e++)n=n.querySelector(i[e])||n;return n}function ds(e){let t=e.querySelectorAll(Qi?`span:not([class]):not([style])`:`span.Apple-converted-space`);for(let n=0;n<t.length;n++){let r=t[n];r.childNodes.length==1&&r.textContent==`\xA0`&&r.parentNode&&r.parentNode.replaceChild(e.ownerDocument.createTextNode(` `),r)}}function fs(e,t){if(!e.size)return e;let n=e.content.firstChild.type.schema,r;try{r=JSON.parse(t)}catch{return e}let{content:i,openStart:a,openEnd:o}=e;for(let e=r.length-2;e>=0;e-=2){let t=n.nodes[r[e]];if(!t||t.hasRequiredAttrs())break;i=E.from(t.create(r[e+1],i)),a++,o++}return new D(i,a,o)}var ps={},ms={},hs={touchstart:!0,touchmove:!0},gs=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:``,button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function _s(e){for(let t in ps){let n=ps[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{Ss(e,t)&&!xs(e,t)&&(e.editable||!(t.type in ms))&&n(e,t)},hs[t]?{passive:!0}:void 0)}ea&&e.dom.addEventListener(`input`,()=>null),bs(e)}function vs(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function ys(e){e.domObserver.stop();for(let t in e.input.eventHandlers)e.dom.removeEventListener(t,e.input.eventHandlers[t]);clearTimeout(e.input.composingTimeout),clearTimeout(e.input.lastIOSEnterFallbackTimeout)}function bs(e){e.someProp(`handleDOMEvents`,t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>xs(e,t))})}function xs(e,t){return e.someProp(`handleDOMEvents`,n=>{let r=n[t.type];return r?r(e,t)||t.defaultPrevented:!1})}function Ss(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target;n!=e.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}function Cs(e,t){!xs(e,t)&&ps[t.type]&&(e.editable||!(t.type in ms))&&ps[t.type](e,t)}ms.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=n.keyCode==16||n.shiftKey,!Ls(e,n)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!(ia&&Qi&&n.keyCode==13)))if(n.keyCode!=229&&e.domObserver.forceFlush(),ta&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{e.input.lastIOSEnter==t&&(e.someProp(`handleKeyDown`,t=>t(e,zi(13,`Enter`))),e.input.lastIOSEnter=0)},200)}else e.someProp(`handleKeyDown`,t=>t(e,n))||Jo(e,n)?n.preventDefault():vs(e,`key`)},ms.keyup=(e,t)=>{t.keyCode==16&&(e.input.shiftKey=!1)},ms.keypress=(e,t)=>{let n=t;if(Ls(e,n)||!n.charCode||n.ctrlKey&&!n.altKey||na&&n.metaKey)return;if(e.someProp(`handleKeyPress`,t=>t(e,n))){n.preventDefault();return}let r=e.state.selection;if(!(r instanceof k)||!r.$from.sameParent(r.$to)){let t=String.fromCharCode(n.charCode),i=()=>e.state.tr.insertText(t).scrollIntoView();!/[\r\n]/.test(t)&&!e.someProp(`handleTextInput`,n=>n(e,r.$from.pos,r.$to.pos,t,i))&&e.dispatch(i()),n.preventDefault()}};function ws(e){return{left:e.clientX,top:e.clientY}}function Ts(e,t){let n=t.x-e.clientX,r=t.y-e.clientY;return n*n+r*r<100}function Es(e,t,n,r,i){if(r==-1)return!1;let a=e.state.doc.resolve(r);for(let r=a.depth+1;r>0;r--)if(e.someProp(t,t=>r>a.depth?t(e,n,a.nodeAfter,a.before(r),i,!0):t(e,n,a.node(r),a.before(r),i,!1)))return!0;return!1}function Ds(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let r=e.state.tr.setSelection(t);n==`pointer`&&r.setMeta(`pointer`,!0),e.dispatch(r)}function Os(e,t){if(t==-1)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return r&&r.isAtom&&A.isSelectable(r)?(Ds(e,new A(n),`pointer`),!0):!1}function ks(e,t){if(t==-1)return!1;let n=e.state.selection,r,i;n instanceof A&&(r=n.node);let a=e.state.doc.resolve(t);for(let e=a.depth+1;e>0;e--){let t=e>a.depth?a.nodeAfter:a.node(e);if(A.isSelectable(t)){i=r&&n.$from.depth>0&&e>=n.$from.depth&&a.before(n.$from.depth+1)==n.$from.pos?a.before(n.$from.depth):a.before(e);break}}return i==null?!1:(Ds(e,A.create(e.state.doc,i),`pointer`),!0)}function As(e,t,n,r,i){return Es(e,`handleClickOn`,t,n,r)||e.someProp(`handleClick`,n=>n(e,t,r))||(i?ks(e,n):Os(e,n))}function js(e,t,n,r){return Es(e,`handleDoubleClickOn`,t,n,r)||e.someProp(`handleDoubleClick`,n=>n(e,t,r))}function Ms(e,t,n,r){return Es(e,`handleTripleClickOn`,t,n,r)||e.someProp(`handleTripleClick`,n=>n(e,t,r))||Ns(e,n,r)}function Ns(e,t,n){if(n.button!=0)return!1;let r=e.state.doc;if(t==-1)return r.inlineContent?(Ds(e,k.create(r,0,r.content.size),`pointer`),!0):!1;let i=r.resolve(t);for(let t=i.depth+1;t>0;t--){let n=t>i.depth?i.nodeAfter:i.node(t),a=i.before(t);if(n.inlineContent)Ds(e,k.create(r,a+1,a+1+n.content.size),`pointer`);else if(A.isSelectable(n))Ds(e,A.create(r,a),`pointer`);else continue;return!0}}function Ps(e){return Ws(e)}var Fs=na?`metaKey`:`ctrlKey`;ps.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let r=Ps(e),i=Date.now(),a=`singleClick`;i-e.input.lastClick.time<500&&Ts(n,e.input.lastClick)&&!n[Fs]&&e.input.lastClick.button==n.button&&(e.input.lastClick.type==`singleClick`?a=`doubleClick`:e.input.lastClick.type==`doubleClick`&&(a=`tripleClick`)),e.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:a,button:n.button};let o=e.posAtCoords(ws(n));o&&(a==`singleClick`?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new Is(e,o,n,!!r)):(a==`doubleClick`?js:Ms)(e,o.pos,o.inside,n)?n.preventDefault():vs(e,`pointer`))};var Is=class{constructor(e,t,n,r){this.view=e,this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[Fs],this.allowDefault=n.shiftKey;let i,a;if(t.inside>-1)i=e.state.doc.nodeAt(t.inside),a=t.inside;else{let n=e.state.doc.resolve(t.pos);i=n.parent,a=n.depth?n.before():0}let o=r?null:n.target,s=o?e.docView.nearestDesc(o,!0):null;this.target=s&&s.nodeDOM.nodeType==1?s.nodeDOM:null;let{selection:c}=e.state;(n.button==0&&i.type.spec.draggable&&i.type.spec.selectable!==!1||c instanceof A&&c.from<=a&&c.to>a)&&(this.mightDrag={node:i,pos:a,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Xi&&!this.target.hasAttribute(`contentEditable`))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute(`contentEditable`,`false`)},20),this.view.domObserver.start()),e.root.addEventListener(`mouseup`,this.up=this.up.bind(this)),e.root.addEventListener(`mousemove`,this.move=this.move.bind(this)),vs(e,`pointer`)}done(){this.view.root.removeEventListener(`mouseup`,this.up),this.view.root.removeEventListener(`mousemove`,this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute(`draggable`),this.mightDrag.setUneditable&&this.target.removeAttribute(`contentEditable`),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>_o(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(ws(e))),this.updateAllowDefault(e),this.allowDefault||!t?vs(this.view,`pointer`):As(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||ea&&this.mightDrag&&!this.mightDrag.node.isAtom||Qi&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(Ds(this.view,O.near(this.view.state.doc.resolve(t.pos)),`pointer`),e.preventDefault()):vs(this.view,`pointer`)}move(e){this.updateAllowDefault(e),vs(this.view,`pointer`),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}};ps.touchstart=e=>{e.input.lastTouch=Date.now(),Ps(e),vs(e,`pointer`)},ps.touchmove=e=>{e.input.lastTouch=Date.now(),vs(e,`pointer`)},ps.contextmenu=e=>Ps(e);function Ls(e,t){return e.composing?!0:ea&&Math.abs(t.timeStamp-e.input.compositionEndedAt)<500?(e.input.compositionEndedAt=-2e8,!0):!1}var Rs=ia?5e3:-1;ms.compositionstart=ms.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof k&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>e.type.spec.inclusive===!1)||Qi&&ra&&zs(e)))e.markCursor=e.state.storedMarks||n.marks(),Ws(e,!0),e.markCursor=null;else if(Ws(e,!t.selection.empty),Xi&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,r=t.focusOffset;n&&n.nodeType==1&&r!=0;){let t=r<0?n.lastChild:n.childNodes[r-1];if(!t)break;if(t.nodeType==3){let n=e.domSelection();n&&n.collapse(t,t.nodeValue.length);break}else n=t,r=-1}}e.input.composing=!0}Bs(e,Rs)};function zs(e){let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(!t||t.nodeType!=1||n>=t.childNodes.length)return!1;let r=t.childNodes[n];return r.nodeType==1&&r.contentEditable==`false`}ms.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=t.timeStamp,e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.badSafariComposition?e.domObserver.forceFlush():e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,Bs(e,20))};function Bs(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>Ws(e),t))}function Vs(e){for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=Us());e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function Hs(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=Pi(t.focusNode,t.focusOffset),r=Fi(t.focusNode,t.focusOffset);if(n&&r&&n!=r){let t=r.pmViewDesc,i=e.domObserver.lastChangedTextNode;if(n==i||r==i)return i;if(!t||!t.isText(r.nodeValue))return r;if(e.input.compositionNode==r){let e=n.pmViewDesc;if(!(!e||!e.isText(n.nodeValue)))return r}}return n||r}function Us(){let e=document.createEvent(`Event`);return e.initEvent(`event`,!0,!0),e.timeStamp}function Ws(e,t=!1){if(!(ia&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),Vs(e),t||e.docView&&e.docView.dirty){let n=ho(e),r=e.state.selection;return n&&!n.eq(r)?e.dispatch(e.state.tr.setSelection(n)):(e.markCursor||t)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?e.dispatch(e.state.tr.deleteSelection()):e.updateState(e.state),!0}return!1}}function Gs(e,t){if(!e.dom.parentNode)return;let n=e.dom.parentNode.appendChild(document.createElement(`div`));n.appendChild(t),n.style.cssText=`position: fixed; left: -10000px; top: 10px`;let r=getSelection(),i=document.createRange();i.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}var Ks=Ji&&Yi<15||ta&&oa<604;ps.copy=ms.cut=(e,t)=>{let n=t,r=e.state.selection,i=n.type==`cut`;if(r.empty)return;let a=Ks?null:n.clipboardData,{dom:o,text:s}=Yo(e,r.content());a?(n.preventDefault(),a.clearData(),a.setData(`text/html`,o.innerHTML),a.setData(`text/plain`,s)):Gs(e,o),i&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta(`uiEvent`,`cut`))};function qs(e){return e.openStart==0&&e.openEnd==0&&e.content.childCount==1?e.content.firstChild:null}function Js(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,r=e.dom.parentNode.appendChild(document.createElement(n?`textarea`:`div`));n||(r.contentEditable=`true`),r.style.cssText=`position: fixed; left: -10000px; top: 10px`,r.focus();let i=e.input.shiftKey&&e.input.lastKeyCode!=45;setTimeout(()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?Ys(e,r.value,null,i,t):Ys(e,r.textContent,r.innerHTML,i,t)},50)}function Ys(e,t,n,r,i){let a=Xo(e,t,n,r,e.state.selection.$from);if(e.someProp(`handlePaste`,t=>t(e,i,a||D.empty)))return!0;if(!a)return!1;let o=qs(a),s=o?e.state.tr.replaceSelectionWith(o,r):e.state.tr.replaceSelection(a);return e.dispatch(s.scrollIntoView().setMeta(`paste`,!0).setMeta(`uiEvent`,`paste`)),!0}function Xs(e){let t=e.getData(`text/plain`)||e.getData(`Text`);if(t)return t;let n=e.getData(`text/uri-list`);return n?n.replace(/\r?\n/g,` `):``}ms.paste=(e,t)=>{let n=t;if(e.composing&&!ia)return;let r=Ks?null:n.clipboardData,i=e.input.shiftKey&&e.input.lastKeyCode!=45;r&&Ys(e,Xs(r),r.getData(`text/html`),i,n)?n.preventDefault():Js(e,n)};var Zs=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},Qs=na?`altKey`:`ctrlKey`;function $s(e,t){return e.someProp(`dragCopies`,e=>!e(t))??!t[Qs]}ps.dragstart=(e,t)=>{let n=t,r=e.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=e.state.selection,a=i.empty?null:e.posAtCoords(ws(n)),o;if(!(a&&a.pos>=i.from&&a.pos<=(i instanceof A?i.to-1:i.to))){if(r&&r.mightDrag)o=A.create(e.state.doc,r.mightDrag.pos);else if(n.target&&n.target.nodeType==1){let t=e.docView.nearestDesc(n.target,!0);t&&t.node.type.spec.draggable&&t!=e.docView&&(o=A.create(e.state.doc,t.posBefore))}}let{dom:s,text:c,slice:l}=Yo(e,(o||e.state.selection).content());(!n.dataTransfer.files.length||!Qi||$i>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(Ks?`Text`:`text/html`,s.innerHTML),n.dataTransfer.effectAllowed=`copyMove`,Ks||n.dataTransfer.setData(`text/plain`,c),e.dragging=new Zs(l,$s(e,n),o)},ps.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},ms.dragover=ms.dragenter=(e,t)=>t.preventDefault(),ms.drop=(e,t)=>{try{ec(e,t,e.dragging)}finally{e.dragging=null}};function ec(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(ws(t));if(!r)return;let i=e.state.doc.resolve(r.pos),a=n&&n.slice;a?e.someProp(`transformPasted`,t=>{a=t(a,e,!1)}):a=Xo(e,Xs(t.dataTransfer),Ks?null:t.dataTransfer.getData(`text/html`),!1,i);let o=!!(n&&$s(e,t));if(e.someProp(`handleDrop`,n=>n(e,t,a||D.empty,o))){t.preventDefault();return}if(!a)return;t.preventDefault();let s=a?Kn(e.state.doc,i.pos,a):i.pos;s??=i.pos;let c=e.state.tr;if(o){let{node:e}=n;e?e.replace(c):c.deleteSelection()}let l=c.mapping.map(s),u=a.openStart==0&&a.openEnd==0&&a.content.childCount==1,d=c.doc;if(u?c.replaceRangeWith(l,l,a.content.firstChild):c.replaceRange(l,l,a),c.doc.eq(d))return;let f=c.doc.resolve(l);if(u&&A.isSelectable(a.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(a.content.firstChild))c.setSelection(new A(f));else{let t=c.mapping.map(s);c.mapping.maps[c.mapping.maps.length-1].forEach((e,n,r,i)=>t=i),c.setSelection(Eo(e,f,c.doc.resolve(t)))}e.focus(),e.dispatch(c.setMeta(`uiEvent`,`drop`))}ps.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add(`ProseMirror-focused`),e.domObserver.start(),e.focused=!0,setTimeout(()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&_o(e)},20))},ps.blur=(e,t)=>{let n=t;e.focused&&=(e.domObserver.stop(),e.dom.classList.remove(`ProseMirror-focused`),e.domObserver.start(),n.relatedTarget&&e.dom.contains(n.relatedTarget)&&e.domObserver.currentSelection.clear(),!1)},ps.beforeinput=(e,t)=>{if(Qi&&ia&&t.inputType==`deleteContentBackward`){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t||(e.dom.blur(),e.focus(),e.someProp(`handleKeyDown`,t=>t(e,zi(8,`Backspace`)))))return;let{$cursor:n}=e.state.selection;n&&n.pos>0&&e.dispatch(e.state.tr.delete(n.pos-1,n.pos).scrollIntoView())},50)}};for(let e in ms)ps[e]=ms[e];function tc(e,t){if(e==t)return!0;for(let n in e)if(e[n]!==t[n])return!1;for(let n in t)if(!(n in e))return!1;return!0}var nc=class e{constructor(e,t){this.toDOM=e,this.spec=t||sc,this.side=this.spec.side||0}map(e,t,n,r){let{pos:i,deleted:a}=e.mapResult(t.from+r,this.side<0?-1:1);return a?null:new ac(i-n,i-n,this)}valid(){return!0}eq(t){return this==t||t instanceof e&&(this.spec.key&&this.spec.key==t.spec.key||this.toDOM==t.toDOM&&tc(this.spec,t.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},rc=class e{constructor(e,t){this.attrs=e,this.spec=t||sc}map(e,t,n,r){let i=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-n,a=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-n;return i>=a?null:new ac(i,a,this)}valid(e,t){return t.from<t.to}eq(t){return this==t||t instanceof e&&tc(this.attrs,t.attrs)&&tc(this.spec,t.spec)}static is(t){return t.type instanceof e}destroy(){}},ic=class e{constructor(e,t){this.attrs=e,this.spec=t||sc}map(e,t,n,r){let i=e.mapResult(t.from+r,1);if(i.deleted)return null;let a=e.mapResult(t.to+r,-1);return a.deleted||a.pos<=i.pos?null:new ac(i.pos-n,a.pos-n,this)}valid(e,t){let{index:n,offset:r}=e.content.findIndex(t.from),i;return r==t.from&&!(i=e.child(n)).isText&&r+i.nodeSize==t.to}eq(t){return this==t||t instanceof e&&tc(this.attrs,t.attrs)&&tc(this.spec,t.spec)}destroy(){}},ac=class e{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(t,n){return new e(t,n,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,n){return this.type.map(e,this,t,n)}static widget(t,n,r){return new e(t,t,new nc(n,r))}static inline(t,n,r,i){return new e(t,n,new rc(r,i))}static node(t,n,r,i){return new e(t,n,new ic(r,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof rc}get widget(){return this.type instanceof nc}},oc=[],sc={},cc=class e{constructor(e,t){this.local=e.length?e:oc,this.children=t.length?t:oc}static create(e,t){return t.length?gc(t,e,0,sc):lc}find(e,t,n){let r=[];return this.findInner(e??0,t??1e9,r,0,n),r}findInner(e,t,n,r,i){for(let a=0;a<this.local.length;a++){let o=this.local[a];o.from<=t&&o.to>=e&&(!i||i(o.spec))&&n.push(o.copy(o.from+r,o.to+r))}for(let a=0;a<this.children.length;a+=3)if(this.children[a]<t&&this.children[a+1]>e){let o=this.children[a]+1;this.children[a+2].findInner(e-o,t-o,n,r+o,i)}}map(e,t,n){return this==lc||e.maps.length==0?this:this.mapInner(e,t,0,0,n||sc)}mapInner(t,n,r,i,a){let o;for(let e=0;e<this.local.length;e++){let s=this.local[e].map(t,r,i);s&&s.type.valid(n,s)?(o||=[]).push(s):a.onRemove&&a.onRemove(this.local[e].spec)}return this.children.length?dc(this.children,o||[],t,n,r,i,a):o?new e(o.sort(_c),oc):lc}add(t,n){return n.length?this==lc?e.create(t,n):this.addInner(t,n,0):this}addInner(t,n,r){let i,a=0;t.forEach((e,t)=>{let o=t+r,s;if(s=mc(n,e,o)){for(i||=this.children.slice();a<i.length&&i[a]<t;)a+=3;i[a]==t?i[a+2]=i[a+2].addInner(e,s,o+1):i.splice(a,0,t,t+e.nodeSize,gc(s,e,o+1,sc)),a+=3}});let o=fc(a?hc(n):n,-r);for(let e=0;e<o.length;e++)o[e].type.valid(t,o[e])||o.splice(e--,1);return new e(o.length?this.local.concat(o).sort(_c):this.local,i||this.children)}remove(e){return e.length==0||this==lc?this:this.removeInner(e,0)}removeInner(t,n){let r=this.children,i=this.local;for(let e=0;e<r.length;e+=3){let i,a=r[e]+n,o=r[e+1]+n;for(let e=0,n;e<t.length;e++)(n=t[e])&&n.from>a&&n.to<o&&(t[e]=null,(i||=[]).push(n));if(!i)continue;r==this.children&&(r=this.children.slice());let s=r[e+2].removeInner(i,a+1);s==lc?(r.splice(e,3),e-=3):r[e+2]=s}if(i.length){for(let e=0,r;e<t.length;e++)if(r=t[e])for(let e=0;e<i.length;e++)i[e].eq(r,n)&&(i==this.local&&(i=this.local.slice()),i.splice(e--,1))}return r==this.children&&i==this.local?this:i.length||r.length?new e(i,r):lc}forChild(t,n){if(this==lc)return this;if(n.isLeaf)return e.empty;let r,i;for(let e=0;e<this.children.length;e+=3)if(this.children[e]>=t){this.children[e]==t&&(r=this.children[e+2]);break}let a=t+1,o=a+n.content.size;for(let e=0;e<this.local.length;e++){let t=this.local[e];if(t.from<o&&t.to>a&&t.type instanceof rc){let e=Math.max(a,t.from)-a,n=Math.min(o,t.to)-a;e<n&&(i||=[]).push(t.copy(e,n))}}if(i){let t=new e(i.sort(_c),oc);return r?new uc([t,r]):t}return r||lc}eq(t){if(this==t)return!0;if(!(t instanceof e)||this.local.length!=t.local.length||this.children.length!=t.children.length)return!1;for(let e=0;e<this.local.length;e++)if(!this.local[e].eq(t.local[e]))return!1;for(let e=0;e<this.children.length;e+=3)if(this.children[e]!=t.children[e]||this.children[e+1]!=t.children[e+1]||!this.children[e+2].eq(t.children[e+2]))return!1;return!0}locals(e){return vc(this.localsInner(e))}localsInner(e){if(this==lc)return oc;if(e.inlineContent||!this.local.some(rc.is))return this.local;let t=[];for(let e=0;e<this.local.length;e++)this.local[e].type instanceof rc||t.push(this.local[e]);return t}forEachSet(e){e(this)}};cc.empty=new cc([],[]),cc.removeOverlap=vc;var lc=cc.empty,uc=class e{constructor(e){this.members=e}map(t,n){let r=this.members.map(e=>e.map(t,n,sc));return e.from(r)}forChild(t,n){if(n.isLeaf)return cc.empty;let r=[];for(let i=0;i<this.members.length;i++){let a=this.members[i].forChild(t,n);a!=lc&&(a instanceof e?r=r.concat(a.members):r.push(a))}return e.from(r)}eq(t){if(!(t instanceof e)||t.members.length!=this.members.length)return!1;for(let e=0;e<this.members.length;e++)if(!this.members[e].eq(t.members[e]))return!1;return!0}locals(e){let t,n=!0;for(let r=0;r<this.members.length;r++){let i=this.members[r].localsInner(e);if(i.length)if(!t)t=i;else{n&&=(t=t.slice(),!1);for(let e=0;e<i.length;e++)t.push(i[e])}}return t?vc(n?t:t.sort(_c)):oc}static from(t){switch(t.length){case 0:return lc;case 1:return t[0];default:return new e(t.every(e=>e instanceof cc)?t:t.reduce((e,t)=>e.concat(t instanceof cc?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}};function dc(e,t,n,r,i,a,o){let s=e.slice();for(let e=0,t=a;e<n.maps.length;e++){let r=0;n.maps[e].forEach((e,n,i,a)=>{let o=a-i-(n-e);for(let i=0;i<s.length;i+=3){let a=s[i+1];if(a<0||e>a+t-r)continue;let c=s[i]+t-r;n>=c?s[i+1]=e<=c?-2:-1:e>=t&&o&&(s[i]+=o,s[i+1]+=o)}r+=o}),t=n.maps[e].map(t,-1)}let c=!1;for(let t=0;t<s.length;t+=3)if(s[t+1]<0){if(s[t+1]==-2){c=!0,s[t+1]=-1;continue}let l=n.map(e[t]+a),u=l-i;if(u<0||u>=r.content.size){c=!0;continue}let d=n.map(e[t+1]+a,-1)-i,{index:f,offset:p}=r.content.findIndex(u),m=r.maybeChild(f);if(m&&p==u&&p+m.nodeSize==d){let r=s[t+2].mapInner(n,m,l+1,e[t]+a+1,o);r==lc?(s[t+1]=-2,c=!0):(s[t]=u,s[t+1]=d,s[t+2]=r)}else c=!0}if(c){let c=gc(pc(s,e,t,n,i,a,o),r,0,o);t=c.local;for(let e=0;e<s.length;e+=3)s[e+1]<0&&(s.splice(e,3),e-=3);for(let e=0,t=0;e<c.children.length;e+=3){let n=c.children[e];for(;t<s.length&&s[t]<n;)t+=3;s.splice(t,0,c.children[e],c.children[e+1],c.children[e+2])}}return new cc(t.sort(_c),s)}function fc(e,t){if(!t||!e.length)return e;let n=[];for(let r=0;r<e.length;r++){let i=e[r];n.push(new ac(i.from+t,i.to+t,i.type))}return n}function pc(e,t,n,r,i,a,o){function s(e,t){for(let a=0;a<e.local.length;a++){let s=e.local[a].map(r,i,t);s?n.push(s):o.onRemove&&o.onRemove(e.local[a].spec)}for(let n=0;n<e.children.length;n+=3)s(e.children[n+2],e.children[n]+t+1)}for(let n=0;n<e.length;n+=3)e[n+1]==-1&&s(e[n+2],t[n]+a+1);return n}function mc(e,t,n){if(t.isLeaf)return null;let r=n+t.nodeSize,i=null;for(let t=0,a;t<e.length;t++)(a=e[t])&&a.from>n&&a.to<r&&((i||=[]).push(a),e[t]=null);return i}function hc(e){let t=[];for(let n=0;n<e.length;n++)e[n]!=null&&t.push(e[n]);return t}function gc(e,t,n,r){let i=[],a=!1;t.forEach((t,o)=>{let s=mc(e,t,o+n);if(s){a=!0;let e=gc(s,t,n+o+1,r);e!=lc&&i.push(o,o+t.nodeSize,e)}});let o=fc(a?hc(e):e,-n).sort(_c);for(let e=0;e<o.length;e++)o[e].type.valid(t,o[e])||(r.onRemove&&r.onRemove(o[e].spec),o.splice(e--,1));return o.length||i.length?new cc(o,i):lc}function _c(e,t){return e.from-t.from||e.to-t.to}function vc(e){let t=e;for(let n=0;n<t.length-1;n++){let r=t[n];if(r.from!=r.to)for(let i=n+1;i<t.length;i++){let a=t[i];if(a.from==r.from){a.to!=r.to&&(t==e&&(t=e.slice()),t[i]=a.copy(a.from,r.to),yc(t,i+1,a.copy(r.to,a.to)));continue}else{a.from<r.to&&(t==e&&(t=e.slice()),t[n]=r.copy(r.from,a.from),yc(t,i,r.copy(a.from,r.to)));break}}}return t}function yc(e,t,n){for(;t<e.length&&_c(n,e[t])>0;)t++;e.splice(t,0,n)}function bc(e){let t=[];return e.someProp(`decorations`,n=>{let r=n(e.state);r&&r!=lc&&t.push(r)}),e.cursorWrapper&&t.push(cc.create(e.state.doc,[e.cursorWrapper.deco])),uc.from(t)}var xc={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Sc=Ji&&Yi<=11,Cc=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}},wc=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Cc,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(t=>{for(let e=0;e<t.length;e++)this.queue.push(t[e]);Ji&&Yi<=11&&t.some(e=>e.type==`childList`&&e.removedNodes.length||e.type==`characterData`&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():ea&&e.composing&&t.some(e=>e.type==`childList`&&e.target.nodeName==`TR`)?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),Sc&&(this.onCharData=e=>{this.queue.push({target:e.target,type:`characterData`,oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,xc)),this.onCharData&&this.view.dom.addEventListener(`DOMCharacterDataModified`,this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener(`DOMCharacterDataModified`,this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener(`selectionchange`,this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener(`selectionchange`,this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(Do(this.view)){if(this.suppressingSelectionUpdates)return _o(this.view);if(Ji&&Yi<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Ai(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,n;for(let n=e.focusNode;n;n=Ei(n))t.add(n);for(let r=e.anchorNode;r;r=Ei(r))if(t.has(r)){n=r;break}let r=n&&this.view.docView.nearestDesc(n);if(r&&r.ignoreMutation({type:`selection`,target:n.nodeType==3?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(n)&&Do(e)&&!this.ignoreSelectionChange(n),i=-1,a=-1,o=!1,s=[];if(e.editable)for(let e=0;e<t.length;e++){let n=this.registerMutation(t[e],s);n&&(i=i<0?n.from:Math.min(n.from,i),a=a<0?n.to:Math.max(n.to,a),n.typeOver&&(o=!0))}if(s.some(e=>e.nodeName==`BR`)&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46)){for(let e of s)if(e.nodeName==`BR`&&e.parentNode){let t=e.nextSibling;for(;t&&t.nodeType==1;){if(t.contentEditable==`false`){e.parentNode.removeChild(e);break}t=t.firstChild}}}else if(Xi&&s.length){let t=s.filter(e=>e.nodeName==`BR`);if(t.length==2){let[e,n]=t;e.parentNode&&e.parentNode.parentNode==n.parentNode?n.remove():e.remove()}else{let{focusNode:n}=this.currentSelection;for(let r of t){let t=r.parentNode;t&&t.nodeName==`LI`&&(!n||Ac(e,n)!=t)&&r.remove()}}}let c=null;i<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&Ri(n)&&(c=ho(e))&&c.eq(O.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,_o(e),this.currentSelection.set(n),e.scrollToSelection()):(i>-1||r)&&(i>-1&&(e.docView.markDirty(i,a),Dc(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,jc(e,s)),this.handleDOMChange(i,a,o,s),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(n)||_o(e),this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if(e.type==`attributes`&&(n==this.view.docView||e.attributeName==`contenteditable`||e.attributeName==`style`&&!e.oldValue&&!e.target.getAttribute(`style`))||!n||n.ignoreMutation(e))return null;if(e.type==`childList`){for(let n=0;n<e.addedNodes.length;n++){let r=e.addedNodes[n];t.push(r),r.nodeType==3&&(this.lastChangedTextNode=r)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let r=e.previousSibling,i=e.nextSibling;if(Ji&&Yi<=11&&e.addedNodes.length)for(let t=0;t<e.addedNodes.length;t++){let{previousSibling:n,nextSibling:a}=e.addedNodes[t];(!n||Array.prototype.indexOf.call(e.addedNodes,n)<0)&&(r=n),(!a||Array.prototype.indexOf.call(e.addedNodes,a)<0)&&(i=a)}let a=r&&r.parentNode==e.target?Ti(r)+1:0,o=n.localPosFromDOM(e.target,a,-1),s=i&&i.parentNode==e.target?Ti(i):e.target.childNodes.length;return{from:o,to:n.localPosFromDOM(e.target,s,1)}}else if(e.type==`attributes`)return{from:n.posAtStart-n.border,to:n.posAtEnd+n.border};else return this.lastChangedTextNode=e.target,{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}}},Tc=new WeakMap,Ec=!1;function Dc(e){if(!Tc.has(e)&&(Tc.set(e,null),[`normal`,`nowrap`,`pre-line`].indexOf(getComputedStyle(e.dom).whiteSpace)!==-1)){if(e.requiresGeckoHackNode=Xi,Ec)return;console.warn(`ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package.`),Ec=!0}}function Oc(e,t){let n=t.startContainer,r=t.startOffset,i=t.endContainer,a=t.endOffset,o=e.domAtPos(e.state.selection.anchor);return Ai(o.node,o.offset,i,a)&&([n,r,i,a]=[i,a,n,r]),{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}}function kc(e,t){if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return Oc(e,n)}let n;function r(e){e.preventDefault(),e.stopImmediatePropagation(),n=e.getTargetRanges()[0]}return e.dom.addEventListener(`beforeinput`,r,!0),document.execCommand(`indent`),e.dom.removeEventListener(`beforeinput`,r,!0),n?Oc(e,n):null}function Ac(e,t){for(let n=t.parentNode;n&&n!=e.dom;n=n.parentNode){let t=e.docView.nearestDesc(n,!0);if(t&&t.node.isBlock)return n}return null}function jc(e,t){let{focusNode:n,focusOffset:r}=e.domSelectionRange();for(let i of t)if(i.parentNode?.nodeName==`TR`){let t=i.nextSibling;for(;t&&t.nodeName!=`TD`&&t.nodeName!=`TH`;)t=t.nextSibling;if(t){let a=t;for(;;){let e=a.firstChild;if(!e||e.nodeType!=1||e.contentEditable==`false`||/^(BR|IMG)$/.test(e.nodeName))break;a=e}a.insertBefore(i,a.firstChild),n==i&&e.domSelection().collapse(i,r)}else i.parentNode.removeChild(i)}}function Mc(e,t,n){let{node:r,fromOffset:i,toOffset:a,from:o,to:s}=e.docView.parseRange(t,n),c=e.domSelectionRange(),l,u=c.anchorNode;if(u&&e.dom.contains(u.nodeType==1?u:u.parentNode)&&(l=[{node:u,offset:c.anchorOffset}],Ri(c)||l.push({node:c.focusNode,offset:c.focusOffset})),Qi&&e.input.lastKeyCode===8)for(let e=a;e>i;e--){let t=r.childNodes[e-1],n=t.pmViewDesc;if(t.nodeName==`BR`&&!n){a=e;break}if(!n||n.size)break}let d=e.state.doc,f=e.someProp(`domParser`)||jt.fromSchema(e.state.schema),p=d.resolve(o),m=null,h=f.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:a,preserveWhitespace:p.parent.type.whitespace==`pre`?`full`:!0,findPositions:l,ruleFromNode:Nc,context:p});if(l&&l[0].pos!=null){let e=l[0].pos,t=l[1]&&l[1].pos;t??=e,m={anchor:e+o,head:t+o}}return{doc:h,sel:m,from:o,to:s}}function Nc(e){let t=e.pmViewDesc;if(t)return t.parseRule();if(e.nodeName==`BR`&&e.parentNode){if(ea&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let e=document.createElement(`div`);return e.appendChild(document.createElement(`li`)),{skip:e}}else if(e.parentNode.lastChild==e||ea&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if(e.nodeName==`IMG`&&e.getAttribute(`mark-placeholder`))return{ignore:!0};return null}var Pc=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function Fc(e,t,n,r,i){let a=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);if(e.input.compositionPendingChanges=0,t<0){let t=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,n=ho(e,t);if(n&&!e.state.selection.eq(n)){if(Qi&&ia&&e.input.lastKeyCode===13&&Date.now()-100<e.input.lastKeyCodeTime&&e.someProp(`handleKeyDown`,t=>t(e,zi(13,`Enter`))))return;let r=e.state.tr.setSelection(n);t==`pointer`?r.setMeta(`pointer`,!0):t==`key`&&r.scrollIntoView(),a&&r.setMeta(`composition`,a),e.dispatch(r)}return}let o=e.state.doc.resolve(t),s=o.sharedDepth(n);t=o.before(s+1),n=e.state.doc.resolve(n).after(s+1);let c=e.state.selection,l=Mc(e,t,n),u=e.state.doc,d=u.slice(l.from,l.to),f,p;e.input.lastKeyCode===8&&Date.now()-100<e.input.lastKeyCodeTime?(f=e.state.selection.to,p=`end`):(f=e.state.selection.from,p=`start`),e.input.lastKeyCode=null;let m=Bc(d.content,l.doc.content,l.from,f,p);if(m&&e.input.domChangeCount++,(ta&&e.input.lastIOSEnter>Date.now()-225||ia)&&i.some(e=>e.nodeType==1&&!Pc.test(e.nodeName))&&(!m||m.endA>=m.endB)&&e.someProp(`handleKeyDown`,t=>t(e,zi(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(!m)if(r&&c instanceof k&&!c.empty&&c.$head.sameParent(c.$anchor)&&!e.composing&&!(l.sel&&l.sel.anchor!=l.sel.head))m={start:c.from,endA:c.to,endB:c.to};else{if(l.sel){let t=Ic(e,e.state.doc,l.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);a&&n.setMeta(`composition`,a),e.dispatch(n)}}return}e.state.selection.from<e.state.selection.to&&m.start==m.endB&&e.state.selection instanceof k&&(m.start>e.state.selection.from&&m.start<=e.state.selection.from+2&&e.state.selection.from>=l.from?m.start=e.state.selection.from:m.endA<e.state.selection.to&&m.endA>=e.state.selection.to-2&&e.state.selection.to<=l.to&&(m.endB+=e.state.selection.to-m.endA,m.endA=e.state.selection.to)),Ji&&Yi<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>l.from&&l.doc.textBetween(m.start-l.from-1,m.start-l.from+1)==` \xA0`&&(m.start--,m.endA--,m.endB--);let h=l.doc.resolveNoCache(m.start-l.from),g=l.doc.resolveNoCache(m.endB-l.from),_=u.resolve(m.start),v=h.sameParent(g)&&h.parent.inlineContent&&_.end()>=m.endA;if((ta&&e.input.lastIOSEnter>Date.now()-225&&(!v||i.some(e=>e.nodeName==`DIV`||e.nodeName==`P`))||!v&&h.pos<l.doc.content.size&&(!h.sameParent(g)||!h.parent.inlineContent)&&h.pos<g.pos&&!/\S/.test(l.doc.textBetween(h.pos,g.pos,``,``)))&&e.someProp(`handleKeyDown`,t=>t(e,zi(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(e.state.selection.anchor>m.start&&Rc(u,m.start,m.endA,h,g)&&e.someProp(`handleKeyDown`,t=>t(e,zi(8,`Backspace`)))){ia&&Qi&&e.domObserver.suppressSelectionUpdates();return}Qi&&m.endB==m.start&&(e.input.lastChromeDelete=Date.now()),ia&&!v&&h.start()!=g.start()&&g.parentOffset==0&&h.depth==g.depth&&l.sel&&l.sel.anchor==l.sel.head&&l.sel.head==m.endA&&(m.endB-=2,g=l.doc.resolveNoCache(m.endB-l.from),setTimeout(()=>{e.someProp(`handleKeyDown`,function(t){return t(e,zi(13,`Enter`))})},20));let y=m.start,b=m.endA,x=t=>{let n=t||e.state.tr.replace(y,b,l.doc.slice(m.start-l.from,m.endB-l.from));if(l.sel){let t=Ic(e,n.doc,l.sel);t&&!(Qi&&e.composing&&t.empty&&(m.start!=m.endB||e.input.lastChromeDelete<Date.now()-100)&&(t.head==y||t.head==n.mapping.map(b)-1)||Ji&&t.empty&&t.head==y)&&n.setSelection(t)}return a&&n.setMeta(`composition`,a),n.scrollIntoView()},S;if(v)if(h.pos==g.pos){Ji&&Yi<=11&&h.parentOffset==0&&(e.domObserver.suppressSelectionUpdates(),setTimeout(()=>_o(e),20));let t=x(e.state.tr.delete(y,b)),n=u.resolve(m.start).marksAcross(u.resolve(m.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(m.endA==m.endB&&(S=Lc(h.parent.content.cut(h.parentOffset,g.parentOffset),_.parent.content.cut(_.parentOffset,m.endA-_.start())))){let t=x(e.state.tr);S.type==`add`?t.addMark(y,b,S.mark):t.removeMark(y,b,S.mark),e.dispatch(t)}else if(h.parent.child(h.index()).isText&&h.index()==g.index()-(g.textOffset?0:1)){let t=h.parent.textBetween(h.parentOffset,g.parentOffset),n=()=>x(e.state.tr.insertText(t,y,b));e.someProp(`handleTextInput`,r=>r(e,y,b,t,n))||e.dispatch(n())}else e.dispatch(x());else e.dispatch(x())}function Ic(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:Eo(e,t.resolve(n.anchor),t.resolve(n.head))}function Lc(e,t){let n=e.firstChild.marks,r=t.firstChild.marks,i=n,a=r,o,s,c;for(let e=0;e<r.length;e++)i=r[e].removeFromSet(i);for(let e=0;e<n.length;e++)a=n[e].removeFromSet(a);if(i.length==1&&a.length==0)s=i[0],o=`add`,c=e=>e.mark(s.addToSet(e.marks));else if(i.length==0&&a.length==1)s=a[0],o=`remove`,c=e=>e.mark(s.removeFromSet(e.marks));else return null;let l=[];for(let e=0;e<t.childCount;e++)l.push(c(t.child(e)));if(E.from(l).eq(e))return{mark:s,type:o}}function Rc(e,t,n,r,i){if(n-t<=i.pos-r.pos||zc(r,!0,!1)<i.pos)return!1;let a=e.resolve(t);if(!r.parent.isTextblock){let e=a.nodeAfter;return e!=null&&n==t+e.nodeSize}if(a.parentOffset<a.parent.content.size||!a.parent.isTextblock)return!1;let o=e.resolve(zc(a,!0,!0));return!o.parent.isTextblock||o.pos>n||zc(o,!0,!1)<n?!1:r.parent.content.cut(r.parentOffset).eq(o.parent.content)}function zc(e,t,n){let r=e.depth,i=t?e.end():e.pos;for(;r>0&&(t||e.indexAfter(r)==e.node(r).childCount);)r--,i++,t=!1;if(n){let t=e.node(r).maybeChild(e.indexAfter(r));for(;t&&!t.isLeaf;)t=t.firstChild,i++}return i}function Bc(e,t,n,r,i){let a=e.findDiffStart(t,n);if(a==null)return null;let{a:o,b:s}=e.findDiffEnd(t,n+e.size,n+t.size);if(i==`end`){let e=Math.max(0,a-Math.min(o,s));r-=o+e-a}if(o<a&&e.size<t.size){let e=r<=a&&r>=o?a-r:0;a-=e,a&&a<t.size&&Vc(t.textBetween(a-1,a+1))&&(a+=e?1:-1),s=a+(s-o),o=a}else if(s<a){let t=r<=a&&r>=s?a-r:0;a-=t,a&&a<e.size&&Vc(e.textBetween(a-1,a+1))&&(a+=t?1:-1),o=a+(o-s),s=a}return{start:a,endA:o,endB:s}}function Vc(e){if(e.length!=2)return!1;let t=e.charCodeAt(0),n=e.charCodeAt(1);return t>=56320&&t<=57343&&n>=55296&&n<=56319}var Hc=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new gs,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Yc),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement(`div`),e&&(e.appendChild?e.appendChild(this.dom):typeof e==`function`?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=Gc(this),Wc(this),this.nodeViews=qc(this),this.docView=Ja(this.state.doc,Uc(this),bc(this),this.dom,this),this.domObserver=new wc(this,(e,t,n,r)=>Fc(this,e,t,n,r)),this.domObserver.start(),_s(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&bs(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Yc),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let e in this._props)t[e]=this._props[e];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){let n=this.state,r=!1,i=!1;e.storedMarks&&this.composing&&(Vs(this),i=!0),this.state=e;let a=n.plugins!=e.plugins||this._props.plugins!=t.plugins;if(a||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=qc(this);Jc(e,this.nodeViews)&&(this.nodeViews=e,r=!0)}(a||t.handleDOMEvents!=this._props.handleDOMEvents)&&bs(this),this.editable=Gc(this),Wc(this);let o=bc(this),s=Uc(this),c=n.plugins!=e.plugins&&!n.doc.eq(e.doc)?`reset`:e.scrollToSelection>n.scrollToSelection?`to selection`:`preserve`,l=r||!this.docView.matchesNode(e.doc,s,o);(l||!e.selection.eq(n.selection))&&(i=!0);let u=c==`preserve`&&i&&this.dom.style.overflowAnchor==null&&da(this);if(i){this.domObserver.stop();let t=l&&(Ji||Qi)&&!this.composing&&!n.selection.empty&&!e.selection.empty&&Kc(n.selection,e.selection);if(l){let n=Qi?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=Hs(this)),(r||!this.docView.update(e.doc,s,o,this))&&(this.docView.updateOuterDeco(s),this.docView.destroy(),this.docView=Ja(e.doc,s,o,this.dom,this)),n&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(t=!0)}t||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&ko(this))?_o(this,t):(wo(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(n),this.dragging?.node&&!n.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,n),c==`reset`?this.dom.scrollTop=0:c==`to selection`?this.scrollToSelection():u&&pa(u)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))&&!this.someProp(`handleScrollToSelection`,e=>e(this)))if(this.state.selection instanceof A){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&ua(this,t.getBoundingClientRect(),e)}else ua(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let e=0;e<this.directPlugins.length;e++){let t=this.directPlugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}for(let e=0;e<this.state.plugins.length;e++){let t=this.state.plugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let n=this.pluginViews[t];n.update&&n.update(this,e)}}updateDraggedNode(e,t){let n=e.node,r=-1;if(n.from<this.state.doc.content.size&&this.state.doc.nodeAt(n.from)==n.node)r=n.from;else{let e=n.from+(this.state.doc.content.size-t.doc.content.size);(e>0&&e<this.state.doc.content.size&&this.state.doc.nodeAt(e))==n.node&&(r=e)}this.dragging=new Zs(e.slice,e.move,r<0?void 0:A.create(this.state.doc,r))}someProp(e,t){let n=this._props&&this._props[e],r;if(n!=null&&(r=t?t(n):n))return r;for(let n=0;n<this.directPlugins.length;n++){let i=this.directPlugins[n].props[e];if(i!=null&&(r=t?t(i):i))return r}let i=this.state.plugins;if(i)for(let n=0;n<i.length;n++){let a=i[n].props[e];if(a!=null&&(r=t?t(a):a))return r}}hasFocus(){if(Ji){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if(e.contentEditable==`false`)return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&ga(this.dom),_o(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let e=this.dom.parentNode;e;e=e.parentNode)if(e.nodeType==9||e.nodeType==11&&e.host)return e.getSelection||(Object.getPrototypeOf(e).getSelection=()=>e.ownerDocument.getSelection()),this._root=e}return e||document}updateRoot(){this._root=null}posAtCoords(e){return wa(this,e)}coordsAtPos(e,t=1){return Oa(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let r=this.docView.posFromDOM(e,t,n);if(r==null)throw RangeError(`DOM position not inside the editor`);return r}endOfTextblock(e,t){return Ra(this,t||this.state,e)}pasteHTML(e,t){return Ys(this,``,e,!1,t||new ClipboardEvent(`paste`))}pasteText(e,t){return Ys(this,e,null,!0,t||new ClipboardEvent(`paste`))}serializeForClipboard(e){return Yo(this,e)}destroy(){this.docView&&(ys(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],bc(this),this),this.dom.textContent=``):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,ki())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Cs(this,e)}domSelectionRange(){let e=this.domSelection();return e?ea&&this.root.nodeType===11&&Bi(this.dom.ownerDocument)==this.dom&&kc(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};Hc.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};function Uc(e){let t=Object.create(null);return t.class=`ProseMirror`,t.contenteditable=String(e.editable),e.someProp(`attributes`,n=>{if(typeof n==`function`&&(n=n(e.state)),n)for(let e in n)e==`class`?t.class+=` `+n[e]:e==`style`?t.style=(t.style?t.style+`;`:``)+n[e]:!t[e]&&e!=`contenteditable`&&e!=`nodeName`&&(t[e]=String(n[e]))}),t.translate||=`no`,[ac.node(0,e.state.doc.content.size,t)]}function Wc(e){if(e.markCursor){let t=document.createElement(`img`);t.className=`ProseMirror-separator`,t.setAttribute(`mark-placeholder`,`true`),t.setAttribute(`alt`,``),e.cursorWrapper={dom:t,deco:ac.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function Gc(e){return!e.someProp(`editable`,t=>t(e.state)===!1)}function Kc(e,t){let n=Math.min(e.$anchor.sharedDepth(e.head),t.$anchor.sharedDepth(t.head));return e.$anchor.start(n)!=t.$anchor.start(n)}function qc(e){let t=Object.create(null);function n(e){for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])}return e.someProp(`nodeViews`,n),e.someProp(`markViews`,n),t}function Jc(e,t){let n=0,r=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let e in t)r++;return n!=r}function Yc(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw RangeError(`Plugins passed directly to the view must not have a state component`)}for(var Xc={8:`Backspace`,9:`Tab`,10:`Enter`,12:`NumLock`,13:`Enter`,16:`Shift`,17:`Control`,18:`Alt`,20:`CapsLock`,27:`Escape`,32:` `,33:`PageUp`,34:`PageDown`,35:`End`,36:`Home`,37:`ArrowLeft`,38:`ArrowUp`,39:`ArrowRight`,40:`ArrowDown`,44:`PrintScreen`,45:`Insert`,46:`Delete`,59:`;`,61:`=`,91:`Meta`,92:`Meta`,106:`*`,107:`+`,108:`,`,109:`-`,110:`.`,111:`/`,144:`NumLock`,145:`ScrollLock`,160:`Shift`,161:`Shift`,162:`Control`,163:`Control`,164:`Alt`,165:`Alt`,173:`-`,186:`;`,187:`=`,188:`,`,189:`-`,190:`.`,191:`/`,192:"`",219:`[`,220:`\\`,221:`]`,222:`'`},Zc={48:`)`,49:`!`,50:`@`,51:`#`,52:`$`,53:`%`,54:`^`,55:`&`,56:`*`,57:`(`,59:`:`,61:`+`,173:`_`,186:`:`,187:`+`,188:`<`,189:`_`,190:`>`,191:`?`,192:`~`,219:`{`,220:`|`,221:`}`,222:`"`},Qc=typeof navigator<`u`&&/Mac/.test(navigator.platform),$c=typeof navigator<`u`&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),el=0;el<10;el++)Xc[48+el]=Xc[96+el]=String(el);for(var el=1;el<=24;el++)Xc[el+111]=`F`+el;for(var el=65;el<=90;el++)Xc[el]=String.fromCharCode(el+32),Zc[el]=String.fromCharCode(el);for(var tl in Xc)Zc.hasOwnProperty(tl)||(Zc[tl]=Xc[tl]);function nl(e){var t=!(Qc&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||$c&&e.shiftKey&&e.key&&e.key.length==1||e.key==`Unidentified`)&&e.key||(e.shiftKey?Zc:Xc)[e.keyCode]||e.key||`Unidentified`;return t==`Esc`&&(t=`Escape`),t==`Del`&&(t=`Delete`),t==`Left`&&(t=`ArrowLeft`),t==`Up`&&(t=`ArrowUp`),t==`Right`&&(t=`ArrowRight`),t==`Down`&&(t=`ArrowDown`),t}var rl=typeof navigator<`u`&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),il=typeof navigator<`u`&&/Win/.test(navigator.platform);function al(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n==`Space`&&(n=` `);let r,i,a,o;for(let e=0;e<t.length-1;e++){let n=t[e];if(/^(cmd|meta|m)$/i.test(n))o=!0;else if(/^a(lt)?$/i.test(n))r=!0;else if(/^(c|ctrl|control)$/i.test(n))i=!0;else if(/^s(hift)?$/i.test(n))a=!0;else if(/^mod$/i.test(n))rl?o=!0:i=!0;else throw Error(`Unrecognized modifier name: `+n)}return r&&(n=`Alt-`+n),i&&(n=`Ctrl-`+n),o&&(n=`Meta-`+n),a&&(n=`Shift-`+n),n}function ol(e){let t=Object.create(null);for(let n in e)t[al(n)]=e[n];return t}function sl(e,t,n=!0){return t.altKey&&(e=`Alt-`+e),t.ctrlKey&&(e=`Ctrl-`+e),t.metaKey&&(e=`Meta-`+e),n&&t.shiftKey&&(e=`Shift-`+e),e}function cl(e){return new j({props:{handleKeyDown:ll(e)}})}function ll(e){let t=ol(e);return function(e,n){let r=nl(n),i,a=t[sl(r,n)];if(a&&a(e.state,e.dispatch,e))return!0;if(r.length==1&&r!=` `){if(n.shiftKey){let i=t[sl(r,n,!1)];if(i&&i(e.state,e.dispatch,e))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(il&&n.ctrlKey&&n.altKey)&&(i=Xc[n.keyCode])&&i!=r){let r=t[sl(i,n)];if(r&&r(e.state,e.dispatch,e))return!0}}return!1}}var ul=Object.defineProperty,dl=(e,t)=>{for(var n in t)ul(e,n,{get:t[n],enumerable:!0})};function fl(e){let{state:t,transaction:n}=e,{selection:r}=n,{doc:i}=n,{storedMarks:a}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return a},get selection(){return r},get doc(){return i},get tr(){return r=n.selection,i=n.doc,a=n.storedMarks,n}}}var pl=class{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){let{rawCommands:e,editor:t,state:n}=this,{view:r}=t,{tr:i}=n,a=this.buildProps(i);return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,(...e)=>{let n=t(...e)(a);return!i.getMeta(`preventDispatch`)&&!this.hasCustomState&&r.dispatch(i),n}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,o=[],s=!!e,c=e||i.tr,l=()=>(!s&&t&&!c.getMeta(`preventDispatch`)&&!this.hasCustomState&&a.dispatch(c),o.every(e=>e===!0)),u={...Object.fromEntries(Object.entries(n).map(([e,n])=>[e,(...e)=>{let r=this.buildProps(c,t),i=n(...e)(r);return o.push(i),u}])),run:l};return u}createCan(e){let{rawCommands:t,state:n}=this,r=e||n.tr,i=this.buildProps(r,!1);return{...Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>t(...e)({...i,dispatch:void 0})])),chain:()=>this.createChain(r,!1)}}buildProps(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,o={tr:e,editor:r,view:a,state:fl({state:i,transaction:e}),dispatch:t?()=>void 0:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,(...e)=>t(...e)(o)]))}};return o}},ml={};dl(ml,{blur:()=>hl,clearContent:()=>gl,clearNodes:()=>_l,command:()=>vl,createParagraphNear:()=>yl,cut:()=>bl,deleteCurrentNode:()=>xl,deleteNode:()=>Cl,deleteRange:()=>wl,deleteSelection:()=>Tl,enter:()=>El,exitCode:()=>Dl,extendMarkRange:()=>Pl,first:()=>Fl,focus:()=>Hl,forEach:()=>Ul,insertContent:()=>Wl,insertContentAt:()=>Xl,joinBackward:()=>$l,joinDown:()=>Ql,joinForward:()=>eu,joinItemBackward:()=>tu,joinItemForward:()=>nu,joinTextblockBackward:()=>ru,joinTextblockForward:()=>iu,joinUp:()=>Zl,keyboardShortcut:()=>su,lift:()=>lu,liftEmptyBlock:()=>uu,liftListItem:()=>du,newlineInCode:()=>fu,resetAttributes:()=>hu,scrollIntoView:()=>gu,selectAll:()=>_u,selectNodeBackward:()=>vu,selectNodeForward:()=>yu,selectParentNode:()=>bu,selectTextblockEnd:()=>xu,selectTextblockStart:()=>Su,setContent:()=>wu,setMark:()=>Cd,setMeta:()=>wd,setNode:()=>Td,setNodeSelection:()=>Ed,setTextDirection:()=>Dd,setTextSelection:()=>Od,sinkListItem:()=>kd,splitBlock:()=>jd,splitListItem:()=>Md,toggleList:()=>Fd,toggleMark:()=>Id,toggleNode:()=>Ld,toggleWrap:()=>Rd,undoInputRule:()=>zd,unsetAllMarks:()=>Bd,unsetMark:()=>Vd,unsetTextDirection:()=>Hd,updateAttributes:()=>Ud,wrapIn:()=>Wd,wrapInList:()=>Gd});var hl=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),(n=window==null?void 0:window.getSelection())==null||n.removeAllRanges())}),!0),gl=(e=!0)=>({commands:t})=>t.setContent(``,{emitUpdate:e}),_l=()=>({state:e,tr:t,dispatch:n})=>{let{selection:r}=t,{ranges:i}=r;return n&&i.forEach(({$from:n,$to:r})=>{e.doc.nodesBetween(n.pos,r.pos,(e,n)=>{if(e.type.isText)return;let{doc:r,mapping:i}=t,a=r.resolve(i.map(n)),o=r.resolve(i.map(n+e.nodeSize)),s=a.blockRange(o);if(!s)return;let c=En(s);if(e.type.isTextblock){let{defaultType:e}=a.parent.contentMatchAt(a.index());t.setNodeMarkup(s.start,e)}(c||c===0)&&t.lift(s,c)})}),!0},vl=e=>t=>e(t),yl=()=>({state:e,dispatch:t})=>ei(e,t),bl=(e,t)=>({editor:n,tr:r})=>{let{state:i}=n,a=i.doc.slice(e.from,e.to);r.deleteRange(e.from,e.to);let o=r.mapping.map(t);return r.insert(o,a.content),r.setSelection(new k(r.doc.resolve(Math.max(o-1,0)))),!0},xl=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;let i=e.selection.$anchor;for(let n=i.depth;n>0;--n)if(i.node(n).type===r.type){if(t){let t=i.before(n),r=i.after(n);e.delete(t,r).scrollIntoView()}return!0}return!1};function Sl(e,t){if(typeof e==`string`){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}var Cl=e=>({tr:t,state:n,dispatch:r})=>{let i=Sl(e,n.schema),a=t.selection.$anchor;for(let e=a.depth;e>0;--e)if(a.node(e).type===i){if(r){let n=a.before(e),r=a.after(e);t.delete(n,r).scrollIntoView()}return!0}return!1},wl=e=>({tr:t,dispatch:n})=>{let{from:r,to:i}=e;return n&&t.delete(r,i),!0},Tl=()=>({state:e,dispatch:t})=>Fr(e,t),El=()=>({commands:e})=>e.keyboardShortcut(`Enter`),Dl=()=>({state:e,dispatch:t})=>$r(e,t);function Ol(e){return Object.prototype.toString.call(e)===`[object RegExp]`}function kl(e,t,n={strict:!0}){let r=Object.keys(t);return r.length?r.every(r=>n.strict?t[r]===e[r]:Ol(t[r])?t[r].test(e[r]):t[r]===e[r]):!0}function Al(e,t,n={}){return e.find(e=>e.type===t&&kl(Object.fromEntries(Object.keys(n).map(t=>[t,e.attrs[t]])),n))}function jl(e,t,n={}){return!!Al(e,t,n)}function Ml(e,t,n){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if((!r.node||!r.node.marks.some(e=>e.type===t))&&(r=e.parent.childBefore(e.parentOffset)),!r.node||!r.node.marks.some(e=>e.type===t))return;if(!n){let e=r.node.marks.find(e=>e.type===t);e&&(n=e.attrs)}if(!Al([...r.node.marks],t,n))return;let i=r.index,a=e.start()+r.offset,o=i+1,s=a+r.node.nodeSize;for(;i>0&&jl([...e.parent.child(i-1).marks],t,n);)--i,a-=e.parent.child(i).nodeSize;for(;o<e.parent.childCount&&jl([...e.parent.child(o).marks],t,n);)s+=e.parent.child(o).nodeSize,o+=1;return{from:a,to:s}}function Nl(e,t){if(typeof e==`string`){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}var Pl=(e,t)=>({tr:n,state:r,dispatch:i})=>{let a=Nl(e,r.schema),{doc:o,selection:s}=n,{$from:c,from:l,to:u}=s;if(i){let e=Ml(c,a,t);if(e&&e.from<=l&&e.to>=u){let t=k.create(o,e.from,e.to);n.setSelection(t)}}return!0},Fl=e=>t=>{let n=typeof e==`function`?e(t):e;for(let e=0;e<n.length;e+=1)if(n[e](t))return!0;return!1};function Il(e){return e instanceof k}function Ll(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function Rl(e,t=null){if(!t)return null;let n=O.atStart(e),r=O.atEnd(e);if(t===`start`||t===!0)return n;if(t===`end`)return r;let i=n.from,a=r.to;return t===`all`?k.create(e,Ll(0,i,a),Ll(e.content.size,i,a)):k.create(e,Ll(t,i,a),Ll(t,i,a))}function zl(){return navigator.platform===`Android`||/android/i.test(navigator.userAgent)}function Bl(){return[`iPad Simulator`,`iPhone Simulator`,`iPod Simulator`,`iPad`,`iPhone`,`iPod`].includes(navigator.platform)||navigator.userAgent.includes(`Mac`)&&`ontouchend`in document}function Vl(){return typeof navigator<`u`?/^((?!chrome|android).)*safari/i.test(navigator.userAgent):!1}var Hl=(e=null,t={})=>({editor:n,view:r,tr:i,dispatch:a})=>{t={scrollIntoView:!0,...t};let o=()=>{(Bl()||zl())&&r.dom.focus(),Vl()&&!Bl()&&!zl()&&r.dom.focus({preventScroll:!0}),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),t?.scrollIntoView&&n.commands.scrollIntoView())})};try{if(r.hasFocus()&&e===null||e===!1)return!0}catch{return!1}if(a&&e===null&&!Il(n.state.selection))return o(),!0;let s=Rl(i.doc,e)||n.state.selection,c=n.state.selection.eq(s);return a&&(c||i.setSelection(s),c&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},Ul=(e,t)=>n=>e.every((e,r)=>t(e,{...n,index:r})),Wl=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t),Gl=e=>{let t=e.childNodes;for(let n=t.length-1;n>=0;--n){let r=t[n];r.nodeType===3&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?e.removeChild(r):r.nodeType===1&&Gl(r)}return e};function Kl(e){if(typeof window>`u`)throw Error(`[tiptap error]: there is no window object available, so this function cannot be used`);let t=`<body>${e}</body>`,n=new window.DOMParser().parseFromString(t,`text/html`).body;return Gl(n)}function ql(e,t,n){if(e instanceof nt||e instanceof E)return e;n={slice:!0,parseOptions:{},...n};let r=typeof e==`object`&&!!e,i=typeof e==`string`;if(r)try{if(Array.isArray(e)&&e.length>0)return E.fromArray(e.map(e=>t.nodeFromJSON(e)));let r=t.nodeFromJSON(e);return n.errorOnInvalidContent&&r.check(),r}catch(r){if(n.errorOnInvalidContent)throw Error(`[tiptap error]: Invalid JSON content`,{cause:r});return console.warn(`[tiptap warn]: Invalid content.`,`Passed value:`,e,`Error:`,r),ql(``,t,n)}if(i){if(n.errorOnInvalidContent){let r=!1,i=``,a=new Dt({topNode:t.spec.topNode,marks:t.spec.marks,nodes:t.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:`inline*`,group:`block`,parseDOM:[{tag:`*`,getAttrs:e=>(r=!0,i=typeof e==`string`?e:e.outerHTML,null)}]}})});if(n.slice?jt.fromSchema(a).parseSlice(Kl(e),n.parseOptions):jt.fromSchema(a).parse(Kl(e),n.parseOptions),n.errorOnInvalidContent&&r)throw Error(`[tiptap error]: Invalid HTML content`,{cause:Error(`Invalid element found: ${i}`)})}let r=jt.fromSchema(t);return n.slice?r.parseSlice(Kl(e),n.parseOptions).content:r.parse(Kl(e),n.parseOptions)}return ql(``,t,n)}function Jl(e,t,n){let r=e.steps.length-1;if(r<t)return;let i=e.steps[r];if(!(i instanceof yn||i instanceof bn))return;let a=e.mapping.maps[r],o=0;a.forEach((e,t,n,r)=>{o===0&&(o=r)}),e.setSelection(O.near(e.doc.resolve(o),n))}var Yl=e=>!(`type`in e),Xl=(e,t,n)=>({tr:r,dispatch:i,editor:a})=>{if(i){n={parseOptions:a.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let i,o=e=>{a.emit(`contentError`,{editor:a,error:e,disableCollaboration:()=>{`collaboration`in a.storage&&typeof a.storage.collaboration==`object`&&a.storage.collaboration&&(a.storage.collaboration.isDisabled=!0)}})},s={preserveWhitespace:`full`,...n.parseOptions};if(!n.errorOnInvalidContent&&!a.options.enableContentCheck&&a.options.emitContentError)try{ql(t,a.schema,{parseOptions:s,errorOnInvalidContent:!0})}catch(e){o(e)}try{i=ql(t,a.schema,{parseOptions:s,errorOnInvalidContent:n.errorOnInvalidContent??a.options.enableContentCheck})}catch(e){return o(e),!1}let{from:c,to:l}=typeof e==`number`?{from:e,to:e}:{from:e.from,to:e.to},u=!0,d=!0;if((Yl(i)?i:[i]).forEach(e=>{e.check(),u=u?e.isText&&e.marks.length===0:!1,d=d?e.isBlock:!1}),c===l&&d){let{parent:e}=r.doc.resolve(c);e.isTextblock&&!e.type.spec.code&&!e.childCount&&(--c,l+=1)}let f;if(u){if(Array.isArray(t))f=t.map(e=>e.text||``).join(``);else if(t instanceof E){let e=``;t.forEach(t=>{t.text&&(e+=t.text)}),f=e}else f=typeof t==`object`&&t&&t.text?t.text:t;r.insertText(f,c,l)}else{f=i;let e=r.doc.resolve(c),t=e.node(),n=e.parentOffset===0,a=t.isText||t.isTextblock,o=t.content.size>0;n&&a&&o&&(c=Math.max(0,c-1)),r.replaceWith(c,l,f)}n.updateSelection&&Jl(r,r.steps.length-1,-1),n.applyInputRules&&r.setMeta(`applyInputRules`,{from:c,text:f}),n.applyPasteRules&&r.setMeta(`applyPasteRules`,{from:c,text:f})}return!0},Zl=()=>({state:e,dispatch:t})=>Jr(e,t),Ql=()=>({state:e,dispatch:t})=>Yr(e,t),$l=()=>({state:e,dispatch:t})=>Lr(e,t),eu=()=>({state:e,dispatch:t})=>Gr(e,t),tu=()=>({state:e,dispatch:t,tr:n})=>{try{let r=Un(e.doc,e.selection.$from.pos,-1);return r==null?!1:(n.join(r,2),t&&t(n),!0)}catch{return!1}},nu=()=>({state:e,dispatch:t,tr:n})=>{try{let r=Un(e.doc,e.selection.$from.pos,1);return r==null?!1:(n.join(r,2),t&&t(n),!0)}catch{return!1}},ru=()=>({state:e,dispatch:t})=>Rr(e,t),iu=()=>({state:e,dispatch:t})=>zr(e,t);function au(){return typeof navigator<`u`?/Mac/.test(navigator.platform):!1}function ou(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n===`Space`&&(n=` `);let r,i,a,o;for(let e=0;e<t.length-1;e+=1){let n=t[e];if(/^(cmd|meta|m)$/i.test(n))o=!0;else if(/^a(lt)?$/i.test(n))r=!0;else if(/^(c|ctrl|control)$/i.test(n))i=!0;else if(/^s(hift)?$/i.test(n))a=!0;else if(/^mod$/i.test(n))Bl()||au()?o=!0:i=!0;else throw Error(`Unrecognized modifier name: ${n}`)}return r&&(n=`Alt-${n}`),i&&(n=`Ctrl-${n}`),o&&(n=`Meta-${n}`),a&&(n=`Shift-${n}`),n}var su=e=>({editor:t,view:n,tr:r,dispatch:i})=>{let a=ou(e).split(/-(?!$)/),o=a.find(e=>![`Alt`,`Ctrl`,`Meta`,`Shift`].includes(e)),s=new KeyboardEvent(`keydown`,{key:o===`Space`?` `:o,altKey:a.includes(`Alt`),ctrlKey:a.includes(`Ctrl`),metaKey:a.includes(`Meta`),shiftKey:a.includes(`Shift`),bubbles:!0,cancelable:!0});return t.captureTransaction(()=>{n.someProp(`handleKeyDown`,e=>e(n,s))})?.steps.forEach(e=>{let t=e.map(r.mapping);t&&i&&r.maybeStep(t)}),!0};function cu(e,t,n={}){let{from:r,to:i,empty:a}=e.selection,o=t?Sl(t,e.schema):null,s=[];e.doc.nodesBetween(r,i,(e,t)=>{if(e.isText)return;let n=Math.max(r,t),a=Math.min(i,t+e.nodeSize);s.push({node:e,from:n,to:a})});let c=i-r,l=s.filter(e=>o?o.name===e.node.type.name:!0).filter(e=>kl(e.node.attrs,n,{strict:!1}));return a?!!l.length:l.reduce((e,t)=>e+t.to-t.from,0)>=c}var lu=(e,t={})=>({state:n,dispatch:r})=>cu(n,Sl(e,n.schema),t)?Xr(n,r):!1,uu=()=>({state:e,dispatch:t})=>ti(e,t),du=e=>({state:t,dispatch:n})=>xi(Sl(e,t.schema))(t,n),fu=()=>({state:e,dispatch:t})=>Zr(e,t);function pu(e,t){return t.nodes[e]?`node`:t.marks[e]?`mark`:null}function mu(e,t){let n=typeof t==`string`?[t]:t;return Object.keys(e).reduce((t,r)=>(n.includes(r)||(t[r]=e[r]),t),{})}var hu=(e,t)=>({tr:n,state:r,dispatch:i})=>{let a=null,o=null,s=pu(typeof e==`string`?e:e.name,r.schema);if(!s)return!1;s===`node`&&(a=Sl(e,r.schema)),s===`mark`&&(o=Nl(e,r.schema));let c=!1;return n.selection.ranges.forEach(e=>{r.doc.nodesBetween(e.$from.pos,e.$to.pos,(e,r)=>{a&&a===e.type&&(c=!0,i&&n.setNodeMarkup(r,void 0,mu(e.attrs,t))),o&&e.marks.length&&e.marks.forEach(a=>{o===a.type&&(c=!0,i&&n.addMark(r,r+e.nodeSize,o.create(mu(a.attrs,t))))})})}),c},gu=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),_u=()=>({tr:e,dispatch:t})=>{if(t){let t=new vr(e.doc);e.setSelection(t)}return!0},vu=()=>({state:e,dispatch:t})=>Hr(e,t),yu=()=>({state:e,dispatch:t})=>Kr(e,t),bu=()=>({state:e,dispatch:t})=>ii(e,t),xu=()=>({state:e,dispatch:t})=>ui(e,t),Su=()=>({state:e,dispatch:t})=>li(e,t);function Cu(e,t,n={},r={}){return ql(e,t,{slice:!1,parseOptions:n,errorOnInvalidContent:r.errorOnInvalidContent})}var wu=(e,{errorOnInvalidContent:t,emitUpdate:n=!0,parseOptions:r={}}={})=>({editor:i,tr:a,dispatch:o,commands:s})=>{let{doc:c}=a;if(r.preserveWhitespace!==`full`){let s=Cu(e,i.schema,r,{errorOnInvalidContent:t??i.options.enableContentCheck});return o&&a.replaceWith(0,c.content.size,s).setMeta(`preventUpdate`,!n),!0}return o&&a.setMeta(`preventUpdate`,!n),s.insertContentAt({from:0,to:c.content.size},e,{parseOptions:r,errorOnInvalidContent:t??i.options.enableContentCheck})};function Tu(e,t){let n=Nl(t,e.schema),{from:r,to:i,empty:a}=e.selection,o=[];a?(e.storedMarks&&o.push(...e.storedMarks),o.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,i,e=>{o.push(...e.marks)});let s=o.find(e=>e.type.name===n.name);return s?{...s.attrs}:{}}function Eu(e,t){let n=new dr(e);return t.forEach(e=>{e.steps.forEach(e=>{n.step(e)})}),n}function Du(e){for(let t=0;t<e.edgeCount;t+=1){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}function Ou(e,t,n){let r=[];return e.nodesBetween(t.from,t.to,(e,t)=>{n(e)&&r.push({node:e,pos:t})}),r}function ku(e,t){for(let n=e.depth;n>0;--n){let r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function Au(e){return t=>ku(t.$from,e)}function M(e,t,n){return e.config[t]===void 0&&e.parent?M(e.parent,t,n):typeof e.config[t]==`function`?e.config[t].bind({...n,parent:e.parent?M(e.parent,t,n):null}):e.config[t]}function ju(e){return e.map(e=>{let t=M(e,`addExtensions`,{name:e.name,options:e.options,storage:e.storage});return t?[e,...ju(t())]:e}).flat(10)}function Mu(e,t){let n=Gt.fromSchema(t).serializeFragment(e),r=document.implementation.createHTMLDocument().createElement(`div`);return r.appendChild(n),r.innerHTML}function Nu(e){return typeof e==`function`}function Pu(e,t=void 0,...n){return Nu(e)?t?e.bind(t)(...n):e(...n):e}function Fu(e={}){return Object.keys(e).length===0&&e.constructor===Object}function Iu(e){return{baseExtensions:e.filter(e=>e.type===`extension`),nodeExtensions:e.filter(e=>e.type===`node`),markExtensions:e.filter(e=>e.type===`mark`)}}function Lu(e){let t=[],{nodeExtensions:n,markExtensions:r}=Iu(e),i=[...n,...r],a={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1},o=n.filter(e=>e.name!==`text`).map(e=>e.name),s=r.map(e=>e.name),c=[...o,...s];return e.forEach(e=>{let n=M(e,`addGlobalAttributes`,{name:e.name,options:e.options,storage:e.storage,extensions:i});n&&n().forEach(e=>{let n;n=Array.isArray(e.types)?e.types:e.types===`*`?c:e.types===`nodes`?o:e.types===`marks`?s:[],n.forEach(n=>{Object.entries(e.attributes).forEach(([e,r])=>{t.push({type:n,name:e,attribute:{...a,...r}})})})})}),i.forEach(e=>{let n=M(e,`addAttributes`,{name:e.name,options:e.options,storage:e.storage});if(!n)return;let r=n();Object.entries(r).forEach(([n,r])=>{let i={...a,...r};typeof i?.default==`function`&&(i.default=i.default()),i?.isRequired&&i?.default===void 0&&delete i.default,t.push({type:e.name,name:n,attribute:i})})}),t}function Ru(e){let t=[],n=``,r=!1,i=!1,a=0,o=e.length;for(let s=0;s<o;s+=1){let o=e[s];if(o===`'`&&!i){r=!r,n+=o;continue}if(o===`"`&&!r){i=!i,n+=o;continue}if(!r&&!i){if(o===`(`){a+=1,n+=o;continue}if(o===`)`&&a>0){--a,n+=o;continue}if(o===`;`&&a===0){t.push(n),n=``;continue}}n+=o}return n&&t.push(n),t}function zu(e){let t=[],n=Ru(e||``),r=n.length;for(let e=0;e<r;e+=1){let r=n[e],i=r.indexOf(`:`);if(i===-1)continue;let a=r.slice(0,i).trim(),o=r.slice(i+1).trim();a&&o&&t.push([a,o])}return t}function Bu(...e){return e.filter(e=>!!e).reduce((e,t)=>{let n={...e};return Object.entries(t).forEach(([e,t])=>{if(!n[e]){n[e]=t;return}if(e===`class`){let r=t?String(t).split(` `):[],i=n[e]?n[e].split(` `):[],a=r.filter(e=>!i.includes(e));n[e]=[...i,...a].join(` `)}else if(e===`style`){let r=new Map([...zu(n[e]),...zu(t)]);n[e]=Array.from(r.entries()).map(([e,t])=>`${e}: ${t}`).join(`; `)}else n[e]=t}),n},{})}function Vu(e,t){return t.filter(t=>t.type===e.type.name).filter(e=>e.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(e.attrs)||{}:{[t.name]:e.attrs[t.name]}).reduce((e,t)=>Bu(e,t),{})}function Hu(e){return typeof e==`string`?e.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(e):e===`true`?!0:e===`false`?!1:e:e}function Uu(e,t){return`style`in e?e:{...e,getAttrs:n=>{let r=e.getAttrs?e.getAttrs(n):e.attrs;if(r===!1)return!1;let i=t.reduce((e,t)=>{let r=t.attribute.parseHTML?t.attribute.parseHTML(n):Hu(n.getAttribute(t.name));return r==null?e:{...e,[t.name]:r}},{});return{...r,...i}}}}function Wu(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>e===`attrs`&&Fu(t)?!1:t!=null))}function Gu(e){let t={};return!e?.attribute?.isRequired&&`default`in(e?.attribute||{})&&(t.default=e.attribute.default),e?.attribute?.validate!==void 0&&(t.validate=e.attribute.validate),[e.name,t]}function Ku(e,t){let n=Lu(e),{nodeExtensions:r,markExtensions:i}=Iu(e);return new Dt({topNode:r.find(e=>M(e,`topNode`))?.name,nodes:Object.fromEntries(r.map(r=>{let i=n.filter(e=>e.type===r.name),a={name:r.name,options:r.options,storage:r.storage,editor:t},o=Wu({...e.reduce((e,t)=>{let n=M(t,`extendNodeSchema`,a);return{...e,...n?n(r):{}}},{}),content:Pu(M(r,`content`,a)),marks:Pu(M(r,`marks`,a)),group:Pu(M(r,`group`,a)),inline:Pu(M(r,`inline`,a)),atom:Pu(M(r,`atom`,a)),selectable:Pu(M(r,`selectable`,a)),draggable:Pu(M(r,`draggable`,a)),code:Pu(M(r,`code`,a)),whitespace:Pu(M(r,`whitespace`,a)),linebreakReplacement:Pu(M(r,`linebreakReplacement`,a)),defining:Pu(M(r,`defining`,a)),isolating:Pu(M(r,`isolating`,a)),attrs:Object.fromEntries(i.map(Gu))}),s=Pu(M(r,`parseHTML`,a));s&&(o.parseDOM=s.map(e=>Uu(e,i)));let c=M(r,`renderHTML`,a);c&&(o.toDOM=e=>c({node:e,HTMLAttributes:Vu(e,i)}));let l=M(r,`renderText`,a);return l&&(o.toText=l),[r.name,o]})),marks:Object.fromEntries(i.map(r=>{let i=n.filter(e=>e.type===r.name),a={name:r.name,options:r.options,storage:r.storage,editor:t},o=Wu({...e.reduce((e,t)=>{let n=M(t,`extendMarkSchema`,a);return{...e,...n?n(r):{}}},{}),inclusive:Pu(M(r,`inclusive`,a)),excludes:Pu(M(r,`excludes`,a)),group:Pu(M(r,`group`,a)),spanning:Pu(M(r,`spanning`,a)),code:Pu(M(r,`code`,a)),attrs:Object.fromEntries(i.map(Gu))}),s=Pu(M(r,`parseHTML`,a));s&&(o.parseDOM=s.map(e=>Uu(e,i)));let c=M(r,`renderHTML`,a);return c&&(o.toDOM=e=>c({mark:e,HTMLAttributes:Vu(e,i)})),[r.name,o]}))})}function qu(e){let t=e.filter((t,n)=>e.indexOf(t)!==n);return Array.from(new Set(t))}function Ju(e){return e.sort((e,t)=>{let n=M(e,`priority`)||100,r=M(t,`priority`)||100;return n>r?-1:n<r?1:0})}function Yu(e){let t=Ju(ju(e)),n=qu(t.map(e=>e.name));return n.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${n.map(e=>`'${e}'`).join(`, `)}]. This can lead to issues.`),t}function Xu(e,t){return Ku(Yu(e),t)}function Zu(e,t){let n=Xu(t),r=Kl(e);return jt.fromSchema(n).parse(r).toJSON()}function Qu(e,t,n){let{from:r,to:i}=t,{blockSeparator:a=`
55
55
 
56
- `,textSerializers:o={}}=n||{},s=``;return e.nodesBetween(r,i,(e,n,c,l)=>{e.isBlock&&n>r&&(s+=a);let u=o?.[e.type.name];if(u)return c&&(s+=u({node:e,pos:n,parent:c,index:l,range:t})),!1;e.isText&&(s+=(e?.text)?.slice(Math.max(r,n)-n,i-n))}),s}function $u(e,t){return Qu(e,{from:0,to:e.content.size},t)}function ed(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function td(e,t){let n=Cl(t,e.schema),{from:r,to:i}=e.selection,a=[];e.doc.nodesBetween(r,i,e=>{a.push(e)});let o=a.reverse().find(e=>e.type.name===n.name);return o?{...o.attrs}:{}}function nd(e,t){let n=mu(typeof t==`string`?t:t.name,e.schema);return n===`node`?td(e,t):n===`mark`?Eu(e,t):{}}function rd(e,t=JSON.stringify){let n={};return e.filter(e=>{let r=t(e);return Object.prototype.hasOwnProperty.call(n,r)?!1:n[r]=!0})}function id(e){let t=rd(e);return t.length===1?t:t.filter((e,n)=>!t.filter((e,t)=>t!==n).some(t=>e.oldRange.from>=t.oldRange.from&&e.oldRange.to<=t.oldRange.to&&e.newRange.from>=t.newRange.from&&e.newRange.to<=t.newRange.to))}function ad(e){let{mapping:t,steps:n}=e,r=[];return t.maps.forEach((e,i)=>{let a=[];if(e.ranges.length)e.forEach((e,t)=>{a.push({from:e,to:t})});else{let{from:e,to:t}=n[i];if(e===void 0||t===void 0)return;a.push({from:e,to:t})}a.forEach(({from:e,to:n})=>{let a=t.slice(i).map(e,-1),o=t.slice(i).map(n),s=t.invert().map(a,-1),c=t.invert().map(o);r.push({oldRange:{from:s,to:c},newRange:{from:a,to:o}})})}),id(r)}function od(e,t,n){let r=[];return e===t?n.resolve(e).marks().forEach(t=>{let i=Nl(n.resolve(e),t.type);i&&r.push({mark:t,...i})}):n.nodesBetween(e,t,(e,t)=>{!e||e?.nodeSize===void 0||r.push(...e.marks.map(n=>({from:t,to:t+e.nodeSize,mark:n})))}),r}var sd=(e,t,n,r=20)=>{let i=e.doc.resolve(n),a=r,o=null;for(;a>0&&o===null;){let e=i.node(a);e?.type.name===t?o=e:--a}return[o,a]};function cd(e,t){return t.nodes[e]||t.marks[e]||null}function ld(e,t,n){return Object.fromEntries(Object.entries(n).filter(([n])=>{let r=e.find(e=>e.type===t&&e.name===n);return r?r.attribute.keepOnSplit:!1}))}var ud=(e,t=500)=>{let n=``,r=e.parentOffset;return e.parent.nodesBetween(Math.max(0,r-t),r,(e,t,i,a)=>{var o;let s=(o=e.type.spec).toText?.call(o,{node:e,pos:t,parent:i,index:a})||e.textContent||`%leaf%`;n+=e.isAtom&&!e.isText?s:s.slice(0,Math.max(0,r-t))}),n};function dd(e,t,n={}){let{empty:r,ranges:i}=e.selection,a=t?Pl(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(e=>a?a.name===e.type.name:!0).find(e=>Al(e.attrs,n,{strict:!1}));let o=0,s=[];if(i.forEach(({$from:t,$to:n})=>{let r=t.pos,i=n.pos;e.doc.nodesBetween(r,i,(e,t)=>{if(a&&e.inlineContent&&!e.type.allowsMarkType(a))return!1;if(!e.isText&&!e.marks.length)return;let n=Math.max(r,t),c=Math.min(i,t+e.nodeSize),l=c-n;o+=l,s.push(...e.marks.map(e=>({mark:e,from:n,to:c})))})}),o===0)return!1;let c=s.filter(e=>a?a.name===e.mark.type.name:!0).filter(e=>Al(e.mark.attrs,n,{strict:!1})).reduce((e,t)=>e+t.to-t.from,0),l=s.filter(e=>a?e.mark.type!==a&&e.mark.type.excludes(a):!0).reduce((e,t)=>e+t.to-t.from,0);return(c>0?c+l:c)>=o}function fd(e,t,n={}){if(!t)return lu(e,null,n)||dd(e,null,n);let r=mu(t,e.schema);return r===`node`?lu(e,t,n):r===`mark`?dd(e,t,n):!1}var pd=(e,t)=>{let{$from:n,$to:r,$anchor:i}=e.selection;if(t){let n=ju(e=>e.type.name===t)(e.selection);if(!n)return!1;let r=e.doc.resolve(n.pos+1);return i.pos+1===r.end()}return!(r.parentOffset<r.parent.nodeSize-2||n.pos!==r.pos)},md=e=>{let{$from:t,$to:n}=e.selection;return!(t.parentOffset>0||t.pos!==n.pos)};function hd(e,t){return Array.isArray(t)?t.some(t=>(typeof t==`string`?t:t.name)===e.name):t}function gd(e,t){let{nodeExtensions:n}=Iu(t),r=n.find(t=>t.name===e);if(!r)return!1;let i=M(j(r,`group`,{name:r.name,options:r.options,storage:r.storage}));return typeof i==`string`?i.split(` `).includes(`list`):!1}function _d(e,{checkChildren:t=!0,ignoreWhitespace:n=!1}={}){if(n){if(e.type.name===`hardBreak`)return!0;if(e.isText)return!/\S/.test(e.text??``)}if(e.isText)return!e.text;if(e.isAtom||e.isLeaf)return!1;if(e.content.childCount===0)return!0;if(t){let r=!0;return e.content.forEach(e=>{r!==!1&&(_d(e,{ignoreWhitespace:n,checkChildren:t})||(r=!1))}),r}return!1}function vd(e){return e instanceof A}var yd=class e{constructor(e){this.position=e}static fromJSON(t){return new e(t.position)}toJSON(){return{position:this.position}}};function bd(e,t){let n=t.mapping.mapResult(e.position);return{position:new yd(n.pos),mapResult:n}}function xd(e){return new yd(e)}function Sd(e,t,n){let{selection:r}=t,i=null;if(Ll(r)&&(i=r.$cursor),i){let t=e.storedMarks??i.marks();return i.parent.type.allowsMarkType(n)&&(!!n.isInSet(t)||!t.some(e=>e.type.excludes(n)))}let{ranges:a}=r;return a.some(({$from:t,$to:r})=>{let i=t.depth===0?e.doc.inlineContent&&e.doc.type.allowsMarkType(n):!1;return e.doc.nodesBetween(t.pos,r.pos,(e,t,r)=>{if(i)return!1;if(e.isInline){let t=!r||r.type.allowsMarkType(n),a=!!n.isInSet(e.marks)||!e.marks.some(e=>e.type.excludes(n));i=t&&a}return!i}),i})}var Cd=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{selection:a}=n,{empty:o,ranges:s}=a,c=Pl(e,r.schema);if(i)if(o){let e=Eu(r,c);n.addStoredMark(c.create({...e,...t}))}else s.forEach(e=>{let i=e.$from.pos,a=e.$to.pos;r.doc.nodesBetween(i,a,(e,r)=>{let o=Math.max(r,i),s=Math.min(r+e.nodeSize,a);e.marks.find(e=>e.type===c)?e.marks.forEach(e=>{c===e.type&&n.addMark(o,s,c.create({...e.attrs,...t}))}):n.addMark(o,s,c.create(t))})});return Sd(r,n,c)},wd=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),Td=(e,t={})=>({state:n,dispatch:r,chain:i})=>{let a=Cl(e,n.schema),o;return n.selection.$anchor.sameParent(n.selection.$head)&&(o=n.selection.$anchor.parent.attrs),a.isTextblock?i().command(({commands:e})=>pi(a,{...o,...t})(n)?!0:e.clearNodes()).command(({state:e})=>pi(a,{...o,...t})(e,r)).run():(console.warn(`[tiptap warn]: Currently "setNode()" only supports text block nodes.`),!1)},Ed=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,r=Rl(e,0,n.content.size),i=A.create(n,r);t.setSelection(i)}return!0},Dd=(e,t)=>({tr:n,state:r,dispatch:i})=>{let{selection:a}=r,o,s;return typeof t==`number`?(o=t,s=t):t&&`from`in t&&`to`in t?(o=t.from,s=t.to):(o=a.from,s=a.to),i&&n.doc.nodesBetween(o,s,(t,r)=>{t.isText||n.setNodeMarkup(r,void 0,{...t.attrs,dir:e})}),!0},Od=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,{from:r,to:i}=typeof e==`number`?{from:e,to:e}:e,a=k.atStart(n).from,o=k.atEnd(n).to,s=Rl(r,a,o),c=Rl(i,a,o),l=k.create(n,s,c);t.setSelection(l)}return!0},kd=e=>({state:t,dispatch:n})=>Ti(Cl(e,t.schema))(t,n);function Ad(e,t){let n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){let r=n.filter(e=>t?.includes(e.type.name));e.tr.ensureMarks(r)}}var jd=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:i})=>{let{selection:a,doc:o}=t,{$from:s,$to:c}=a,l=i.extensionManager.attributes,u=ld(l,s.node().type.name,s.node().attrs);if(a instanceof A&&a.node.isBlock)return!s.parentOffset||!Rn(o,s.pos)?!1:(r&&(e&&Ad(n,i.extensionManager.splittableMarks),t.split(s.pos).scrollIntoView()),!0);if(!s.parent.isBlock)return!1;let d=c.parentOffset===c.parent.content.size,f=s.depth===0?void 0:Ou(s.node(-1).contentMatchAt(s.indexAfter(-1))),p=d&&f?[{type:f,attrs:u}]:void 0,m=Rn(t.doc,t.mapping.map(s.pos),1,p);if(!p&&!m&&Rn(t.doc,t.mapping.map(s.pos),1,f?[{type:f}]:void 0)&&(m=!0,p=f?[{type:f,attrs:u}]:void 0),r){if(m&&(a instanceof k&&t.deleteSelection(),t.split(t.mapping.map(s.pos),1,p),f&&!d&&!s.parentOffset&&s.parent.type!==f)){let e=t.mapping.map(s.before()),n=t.doc.resolve(e);s.node(-1).canReplaceWith(n.index(),n.index()+1,f)&&t.setNodeMarkup(t.mapping.map(s.before()),f)}e&&Ad(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return m},Md=(e,t={})=>({tr:n,state:r,dispatch:i,editor:a})=>{let o=Cl(e,r.schema),{$from:s,$to:c}=r.selection,l=r.selection.node;if(l&&l.isBlock||s.depth<2||!s.sameParent(c))return!1;let u=s.node(-1);if(u.type!==o)return!1;let d=a.extensionManager.attributes;if(s.parent.content.size===0&&s.node(-1).childCount===s.indexAfter(-1)){if(s.depth===2||s.node(-3).type!==o||s.index(-2)!==s.node(-2).childCount-1)return!1;if(i){let e=E.empty,r=s.index(-1)?1:s.index(-2)?2:3;for(let t=s.depth-r;t>=s.depth-3;--t)e=E.from(s.node(t).copy(e));let i=s.indexAfter(-1)<s.node(-2).childCount?1:s.indexAfter(-2)<s.node(-3).childCount?2:3,a={...ld(d,s.node().type.name,s.node().attrs),...t},c=o.contentMatch.defaultType?.createAndFill(a)||void 0;e=e.append(E.from(o.createAndFill(null,c)||void 0));let l=s.before(s.depth-(r-1));n.replace(l,s.after(-i),new D(e,4-r,0));let u=-1;n.doc.nodesBetween(l,n.doc.content.size,(e,t)=>{if(u>-1)return!1;e.isTextblock&&e.content.size===0&&(u=t+1)}),u>-1&&n.setSelection(k.near(n.doc.resolve(u))),n.scrollIntoView()}return!0}let f=c.pos===s.end()?u.contentMatchAt(0).defaultType:null,p={...ld(d,u.type.name,u.attrs),...t},m={...ld(d,s.node().type.name,s.node().attrs),...t};n.delete(s.pos,c.pos);let h=f?[{type:o,attrs:p},{type:f,attrs:m}]:[{type:o,attrs:p}];if(!Rn(n.doc,s.pos,2))return!1;if(i){let{selection:e,storedMarks:t}=r,{splittableMarks:o}=a.extensionManager,c=t||e.$to.parentOffset&&e.$from.marks();if(n.split(s.pos,2,h).scrollIntoView(),!c||!i)return!0;let l=c.filter(e=>o.includes(e.type.name));n.ensureMarks(l)}return!0},Nd=(e,t)=>{let n=ju(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;let i=e.doc.nodeAt(r);return n.node.type===i?.type&&Bn(e.doc,n.pos)&&e.join(n.pos),!0},Pd=(e,t)=>{let n=ju(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;let i=e.doc.nodeAt(r);return n.node.type===i?.type&&Bn(e.doc,r)&&e.join(r),!0},Fd=(e,t,n,r={})=>({editor:i,tr:a,state:o,dispatch:s,chain:c,commands:l,can:u})=>{let{extensions:d,splittableMarks:f}=i.extensionManager,p=Cl(e,o.schema),m=Cl(t,o.schema),{selection:h,storedMarks:g}=o,{$from:_,$to:v}=h,y=_.blockRange(v),b=g||h.$to.parentOffset&&h.$from.marks();if(!y)return!1;let x=ju(e=>gd(e.type.name,d))(h);if(y.depth>=1&&x&&y.depth-x.depth<=1){if(x.node.type===p)return l.liftListItem(m);if(gd(x.node.type.name,d)&&p.validContent(x.node.content)&&s)return c().command(()=>(a.setNodeMarkup(x.pos,p),!0)).command(()=>Nd(a,p)).command(()=>Pd(a,p)).run()}return!n||!b||!s?c().command(()=>u().wrapInList(p,r)?!0:l.clearNodes()).wrapInList(p,r).command(()=>Nd(a,p)).command(()=>Pd(a,p)).run():c().command(()=>{let e=u().wrapInList(p,r),t=b.filter(e=>f.includes(e.type.name));return a.ensureMarks(t),e?!0:l.clearNodes()}).wrapInList(p,r).command(()=>Nd(a,p)).command(()=>Pd(a,p)).run()},Id=(e,t={},n={})=>({state:r,commands:i})=>{let{extendEmptyMarkRange:a=!1}=n,o=Pl(e,r.schema);return dd(r,o,t)?i.unsetMark(o,{extendEmptyMarkRange:a}):i.setMark(o,t)},Ld=(e,t,n={})=>({state:r,commands:i})=>{let a=Cl(e,r.schema),o=Cl(t,r.schema),s=lu(r,a,n),c;return r.selection.$anchor.sameParent(r.selection.$head)&&(c=r.selection.$anchor.parent.attrs),s?i.setNode(o,c):i.setNode(a,{...c,...n})},Rd=(e,t={})=>({state:n,commands:r})=>{let i=Cl(e,n.schema);return lu(n,i,t)?r.lift(i):r.wrapIn(i,t)},zd=()=>({state:e,dispatch:t})=>{let n=e.plugins;for(let r=0;r<n.length;r+=1){let i=n[r],a;if(i.spec.isInputRules&&(a=i.getState(e))){if(t){let t=e.tr,n=a.transform;for(let e=n.steps.length-1;e>=0;--e)t.step(n.steps[e].invert(n.docs[e]));if(a.text){let n=t.doc.resolve(a.from).marks();t.replaceWith(a.from,a.to,e.schema.text(a.text,n))}else t.delete(a.from,a.to)}return!0}}return!1},Bd=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,{empty:r,ranges:i}=n;return r||t&&i.forEach(t=>{e.removeMark(t.$from.pos,t.$to.pos)}),!0},Vd=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{extendEmptyMarkRange:a=!1}=t,{selection:o}=n,s=Pl(e,r.schema),{$from:c,empty:l,ranges:u}=o;if(!i)return!0;if(l&&a){let{from:e,to:t}=o,r=Nl(c,s,c.marks().find(e=>e.type===s)?.attrs);r&&(e=r.from,t=r.to),n.removeMark(e,t,s)}else u.forEach(e=>{n.removeMark(e.$from.pos,e.$to.pos,s)});return n.removeStoredMark(s),!0},Hd=e=>({tr:t,state:n,dispatch:r})=>{let{selection:i}=n,a,o;return typeof e==`number`?(a=e,o=e):e&&`from`in e&&`to`in e?(a=e.from,o=e.to):(a=i.from,o=i.to),r&&t.doc.nodesBetween(a,o,(e,n)=>{if(e.isText)return;let r={...e.attrs};delete r.dir,t.setNodeMarkup(n,void 0,r)}),!0},Ud=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let a=null,o=null,s=mu(typeof e==`string`?e:e.name,r.schema);if(!s)return!1;s===`node`&&(a=Cl(e,r.schema)),s===`mark`&&(o=Pl(e,r.schema));let c=!1;return n.selection.ranges.forEach(e=>{let s=e.$from.pos,l=e.$to.pos,u,d,f,p;n.selection.empty?r.doc.nodesBetween(s,l,(e,t)=>{a&&a===e.type&&(c=!0,f=Math.max(t,s),p=Math.min(t+e.nodeSize,l),u=t,d=e)}):r.doc.nodesBetween(s,l,(e,r)=>{r<s&&a&&a===e.type&&(c=!0,f=Math.max(r,s),p=Math.min(r+e.nodeSize,l),u=r,d=e),r>=s&&r<=l&&(a&&a===e.type&&(c=!0,i&&n.setNodeMarkup(r,void 0,{...e.attrs,...t})),o&&e.marks.length&&e.marks.forEach(a=>{if(o===a.type&&(c=!0,i)){let i=Math.max(r,s),c=Math.min(r+e.nodeSize,l);n.addMark(i,c,o.create({...a.attrs,...t}))}}))}),d&&(u!==void 0&&i&&n.setNodeMarkup(u,void 0,{...d.attrs,...t}),o&&d.marks.length&&d.marks.forEach(e=>{o===e.type&&i&&n.addMark(f,p,o.create({...e.attrs,...t}))}))}),c},Wd=(e,t={})=>({state:n,dispatch:r})=>fi(Cl(e,n.schema),t)(n,r),Gd=(e,t={})=>({state:n,dispatch:r})=>yi(Cl(e,n.schema),t)(n,r),Kd=class{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){let n=this.callbacks[e];return n&&n.forEach(e=>e.apply(this,t)),this}off(e,t){let n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e]),this}once(e,t){let n=(...r)=>{this.off(e,n),t.apply(this,r)};return this.on(e,n)}removeAllListeners(){this.callbacks={}}},qd=class{constructor(e){this.find=e.find,this.handler=e.handler,this.undoable=e.undoable??!0}},Jd=(e,t)=>{if(kl(t))return t.exec(e);let n=t(e);if(!n)return null;let r=[n.text];return r.index=n.index,r.input=e,r.data=n.data,n.replaceWith&&(n.text.includes(n.replaceWith)||console.warn(`[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".`),r.push(n.replaceWith)),r};function Yd(e){let{editor:t,from:n,to:r,text:i,rules:a,plugin:o}=e,{view:s}=t;if(s.composing)return!1;let c=s.state.doc.resolve(n);if(c.parent.type.spec.code||(c.nodeBefore||c.nodeAfter)?.marks.find(e=>e.type.spec.code))return!1;let l=!1,u=ud(c)+i;return a.forEach(e=>{if(l)return;let a=Jd(u,e.find);if(!a)return;let c=s.state.tr,d=pl({state:s.state,transaction:c}),f={from:n-(a[0].length-i.length),to:r},{commands:p,chain:m,can:h}=new ml({editor:t,state:d});e.handler({state:d,range:f,match:a,commands:p,chain:m,can:h})===null||!c.steps.length||(e.undoable&&c.setMeta(o,{transform:c,from:n,to:r,text:i}),s.dispatch(c),l=!0)}),l}function Xd(e){let{editor:t,rules:n}=e,r=new Mr({state:{init(){return null},apply(e,i,a){let o=e.getMeta(r);if(o)return o;let s=e.getMeta(`applyInputRules`);return s&&setTimeout(()=>{let{text:e}=s;e=typeof e==`string`?e:Nu(E.from(e),a.schema);let{from:i}=s;Yd({editor:t,from:i,to:i+e.length,text:e,rules:n,plugin:r})}),e.selectionSet||e.docChanged?null:i}},props:{handleTextInput(e,i,a,o){return Yd({editor:t,from:i,to:a,text:o,rules:n,plugin:r})},handleDOMEvents:{compositionend:e=>(setTimeout(()=>{let{$cursor:i}=e.state.selection;i&&Yd({editor:t,from:i.pos,to:i.pos,text:``,rules:n,plugin:r})}),!1)},handleKeyDown(e,i){if(i.key!==`Enter`)return!1;let{$cursor:a}=e.state.selection;return a?Yd({editor:t,from:a.pos,to:a.pos,text:`
57
- `,rules:n,plugin:r}):!1}},isInputRules:!0});return r}function Zd(e){return Object.prototype.toString.call(e).slice(8,-1)}function Qd(e){return Zd(e)===`Object`?e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype:!1}function $d(e,t){let n={...e};return Qd(e)&&Qd(t)&&Object.keys(t).forEach(r=>{Qd(t[r])&&Qd(e[r])?n[r]=$d(e[r],t[r]):n[r]=t[r]}),n}var ef=class{constructor(e={}){this.type=`extendable`,this.parent=null,this.child=null,this.name=``,this.config={name:this.name},this.config={...this.config,...e},this.name=this.config.name}get options(){return{...M(j(this,`addOptions`,{name:this.name}))||{}}}get storage(){return{...M(j(this,`addStorage`,{name:this.name,options:this.options}))||{}}}configure(e={}){let t=this.extend({...this.config,addOptions:()=>$d(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){let t=new this.constructor({...this.config,...e});return t.parent=this,this.child=t,t.name=`name`in e?e.name:t.parent.name,t}},tf=class e extends ef{constructor(){super(...arguments),this.type=`mark`}static create(t={}){return new e(typeof t==`function`?t():t)}static handleExit({editor:e,mark:t}){let{tr:n}=e.state,r=e.state.selection.$from;if(r.pos===r.end()){let i=r.marks();if(!i.find(e=>e?.type.name===t.name))return!1;let a=i.find(e=>e?.type.name===t.name);return a&&n.removeStoredMark(a),n.insertText(` `,r.pos),e.view.dispatch(n),!0}return!1}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}};function nf(e){return typeof e==`number`}var rf=class{constructor(e){this.find=e.find,this.handler=e.handler}},af=(e,t,n)=>{if(kl(t))return[...e.matchAll(t)];let r=t(e,n);return r?r.map(t=>{let n=[t.text];return n.index=t.index,n.input=e,n.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn(`[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".`),n.push(t.replaceWith)),n}):[]};function of(e){let{editor:t,state:n,from:r,to:i,rule:a,pasteEvent:o,dropEvent:s}=e,{commands:c,chain:l,can:u}=new ml({editor:t,state:n}),d=[];return n.doc.nodesBetween(r,i,(e,t)=>{if(e.type?.spec?.code||!(e.isText||e.isTextblock||e.isInline))return;let f=e.content?.size??e.nodeSize??0,p=Math.max(r,t),m=Math.min(i,t+f);p>=m||af(e.isText?e.text||``:e.textBetween(p-t,m-t,void 0,``),a.find,o).forEach(e=>{if(e.index===void 0)return;let t=p+e.index+1,r=t+e[0].length,i={from:n.tr.mapping.map(t),to:n.tr.mapping.map(r)},f=a.handler({state:n,range:i,match:e,commands:c,chain:l,can:u,pasteEvent:o,dropEvent:s});d.push(f)})}),d.every(e=>e!==null)}var sf=null,cf=e=>{var t;let n=new ClipboardEvent(`paste`,{clipboardData:new DataTransfer});return(t=n.clipboardData)==null||t.setData(`text/html`,e),n};function lf(e){let{editor:t,rules:n}=e,r=null,i=!1,a=!1,o=typeof ClipboardEvent<`u`?new ClipboardEvent(`paste`):null,s;try{s=typeof DragEvent<`u`?new DragEvent(`drop`):null}catch{s=null}let c=({state:e,from:n,to:r,rule:i,pasteEvt:a})=>{let c=e.tr;if(!(!of({editor:t,state:pl({state:e,transaction:c}),from:Math.max(n-1,0),to:r.b-1,rule:i,pasteEvent:a,dropEvent:s})||!c.steps.length)){try{s=typeof DragEvent<`u`?new DragEvent(`drop`):null}catch{s=null}return o=typeof ClipboardEvent<`u`?new ClipboardEvent(`paste`):null,c}};return n.map(e=>new Mr({view(e){let n=n=>{r=e.dom.parentElement?.contains(n.target)?e.dom.parentElement:null,r&&(sf=t)},i=()=>{sf&&=null};return window.addEventListener(`dragstart`,n),window.addEventListener(`dragend`,i),{destroy(){window.removeEventListener(`dragstart`,n),window.removeEventListener(`dragend`,i)}}},props:{handleDOMEvents:{drop:(e,t)=>{if(a=r===e.dom.parentElement,s=t,!a){let e=sf;e?.isEditable&&setTimeout(()=>{let t=e.state.selection;t&&e.commands.deleteRange({from:t.from,to:t.to})},10)}return!1},paste:(e,t)=>{let n=t.clipboardData?.getData(`text/html`);return o=t,i=!!n?.includes(`data-pm-slice`),!1}}},appendTransaction:(t,n,r)=>{let s=t[0],l=s.getMeta(`uiEvent`)===`paste`&&!i,u=s.getMeta(`uiEvent`)===`drop`&&!a,d=s.getMeta(`applyPasteRules`),f=!!d;if(!l&&!u&&!f)return;if(f){let{text:t}=d;t=typeof t==`string`?t:Nu(E.from(t),r.schema);let{from:n}=d,i=n+t.length,a=cf(t);return c({rule:e,state:r,from:n,to:{b:i},pasteEvt:a})}let p=n.doc.content.findDiffStart(r.doc.content),m=n.doc.content.findDiffEnd(r.doc.content);if(!(!nf(p)||!m||p===m.b))return c({rule:e,state:r,from:p,to:m,pasteEvt:o})}}))}var uf=class{constructor(e,t){this.splittableMarks=[],this.editor=t,this.baseExtensions=e,this.extensions=Yu(e),this.schema=Ku(this.extensions,t),this.setupExtensions()}get commands(){return this.extensions.reduce((e,t)=>{let n=j(t,`addCommands`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:this.editor,type:cd(t.name,this.schema)});return n?{...e,...n()}:e},{})}get plugins(){let{editor:e}=this;return Ju([...this.extensions].reverse()).flatMap(t=>{let n={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:cd(t.name,this.schema)},r=[],i=j(t,`addKeyboardShortcuts`,n),a={};if(t.type===`mark`&&j(t,`exitable`,n)&&(a.ArrowRight=()=>tf.handleExit({editor:e,mark:t})),i){let t=Object.fromEntries(Object.entries(i()).map(([t,n])=>[t,()=>n({editor:e})]));a={...a,...t}}let o=ll(a);r.push(o);let s=j(t,`addInputRules`,n);if(hd(t,e.options.enableInputRules)&&s){let t=s();if(t&&t.length){let n=Xd({editor:e,rules:t}),i=Array.isArray(n)?n:[n];r.push(...i)}}let c=j(t,`addPasteRules`,n);if(hd(t,e.options.enablePasteRules)&&c){let t=c();if(t&&t.length){let n=lf({editor:e,rules:t});r.push(...n)}}let l=j(t,`addProseMirrorPlugins`,n);if(l){let e=l();r.push(...e)}return r})}get attributes(){return Lu(this.extensions)}get nodeViews(){let{editor:e}=this,{nodeExtensions:t}=Iu(this.extensions);return Object.fromEntries(t.filter(e=>!!j(e,`addNodeView`)).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r=j(t,`addNodeView`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:Cl(t.name,this.schema)});if(!r)return[];let i=r();return i?[t.name,(r,a,o,s,c)=>i({node:r,view:a,getPos:o,decorations:s,innerDecorations:c,editor:e,extension:t,HTMLAttributes:Vu(r,n)})]:[]}))}dispatchTransaction(e){let{editor:t}=this;return Ju([...this.extensions].reverse()).reduceRight((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:cd(n.name,this.schema)},i=j(n,`dispatchTransaction`,r);return i?t=>{i.call(r,{transaction:t,next:e})}:e},e)}transformPastedHTML(e){let{editor:t}=this;return Ju([...this.extensions]).reduce((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:cd(n.name,this.schema)},i=j(n,`transformPastedHTML`,r);return i?(t,n)=>{let a=e(t,n);return i.call(r,a)}:e},e||(e=>e))}get markViews(){let{editor:e}=this,{markExtensions:t}=Iu(this.extensions);return Object.fromEntries(t.filter(e=>!!j(e,`addMarkView`)).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r=j(t,`addMarkView`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:Pl(t.name,this.schema)});return r?[t.name,(i,a,o)=>{let s=Vu(i,n);return r()({mark:i,view:a,inline:o,editor:e,extension:t,HTMLAttributes:s,updateAttributes:t=>{Uf(i,e,t)}})}]:[]}))}setupExtensions(){let e=this.extensions;this.editor.extensionStorage=Object.fromEntries(e.map(e=>[e.name,e.storage])),e.forEach(e=>{let t={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:cd(e.name,this.schema)};e.type===`mark`&&(M(j(e,`keepOnSplit`,t))??!0)&&this.splittableMarks.push(e.name);let n=j(e,`onBeforeCreate`,t),r=j(e,`onCreate`,t),i=j(e,`onUpdate`,t),a=j(e,`onSelectionUpdate`,t),o=j(e,`onTransaction`,t),s=j(e,`onFocus`,t),c=j(e,`onBlur`,t),l=j(e,`onDestroy`,t);n&&this.editor.on(`beforeCreate`,n),r&&this.editor.on(`create`,r),i&&this.editor.on(`update`,i),a&&this.editor.on(`selectionUpdate`,a),o&&this.editor.on(`transaction`,o),s&&this.editor.on(`focus`,s),c&&this.editor.on(`blur`,c),l&&this.editor.on(`destroy`,l)})}};uf.resolve=Yu,uf.sort=Ju,uf.flatten=Mu,fl({},{ClipboardTextSerializer:()=>df,Commands:()=>ff,Delete:()=>pf,Drop:()=>mf,Editable:()=>hf,FocusEvents:()=>_f,Keymap:()=>vf,Paste:()=>yf,Tabindex:()=>bf,TextDirection:()=>xf,focusEventsPluginKey:()=>gf});var N=class e extends ef{constructor(){super(...arguments),this.type=`extension`}static create(t={}){return new e(typeof t==`function`?t():t)}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}},df=N.create({name:`clipboardTextSerializer`,addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new Mr({key:new Fr(`clipboardTextSerializer`),props:{clipboardTextSerializer:()=>{let{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:i}=t,{ranges:a}=i,o=Math.min(...a.map(e=>e.$from.pos)),s=Math.max(...a.map(e=>e.$to.pos)),c=ed(n);return Qu(r,{from:o,to:s},{...this.options.blockSeparator===void 0?{}:{blockSeparator:this.options.blockSeparator},textSerializers:c})}}})]}}),ff=N.create({name:`commands`,addCommands(){return{...hl}}}),pf=N.create({name:`delete`,onUpdate({transaction:e,appendedTransactions:t}){let n=()=>{var n;if(((n=this.editor.options.coreExtensionOptions?.delete)?.filterTransaction)?.call(n,e)??e.getMeta(`y-sync$`))return;let r=Du(e.before,[e,...t]);ad(r).forEach(t=>{r.mapping.mapResult(t.oldRange.from).deletedAfter&&r.mapping.mapResult(t.oldRange.to).deletedBefore&&r.before.nodesBetween(t.oldRange.from,t.oldRange.to,(n,i)=>{let a=i+n.nodeSize-2,o=t.oldRange.from<=i&&a<=t.oldRange.to;this.editor.emit(`delete`,{type:`node`,node:n,from:i,to:a,newFrom:r.mapping.map(i),newTo:r.mapping.map(a),deletedRange:t.oldRange,newRange:t.newRange,partial:!o,editor:this.editor,transaction:e,combinedTransform:r})})});let i=r.mapping;r.steps.forEach((t,n)=>{if(t instanceof gn){let a=i.slice(n).map(t.from,-1),o=i.slice(n).map(t.to),s=i.invert().map(a,-1),c=i.invert().map(o),l=a>0?r.doc.nodeAt(a-1)?.marks.some(e=>e.eq(t.mark)):!1,u=r.doc.nodeAt(o)?.marks.some(e=>e.eq(t.mark));this.editor.emit(`delete`,{type:`mark`,mark:t.mark,from:t.from,to:t.to,deletedRange:{from:s,to:c},newRange:{from:a,to:o},partial:!!(u||l),editor:this.editor,transaction:e,combinedTransform:r})}})};this.editor.options.coreExtensionOptions?.delete?.async??!0?setTimeout(n,0):n()}}),mf=N.create({name:`drop`,addProseMirrorPlugins(){return[new Mr({key:new Fr(`tiptapDrop`),props:{handleDrop:(e,t,n,r)=>{this.editor.emit(`drop`,{editor:this.editor,event:t,slice:n,moved:r})}}})]}}),hf=N.create({name:`editable`,addProseMirrorPlugins(){return[new Mr({key:new Fr(`editable`),props:{editable:()=>this.editor.options.editable}})]}}),gf=new Fr(`focusEvents`),_f=N.create({name:`focusEvents`,addProseMirrorPlugins(){let{editor:e}=this;return[new Mr({key:gf,props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;let r=e.state.tr.setMeta(`focus`,{event:n}).setMeta(`addToHistory`,!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;let r=e.state.tr.setMeta(`blur`,{event:n}).setMeta(`addToHistory`,!1);return t.dispatch(r),!1}}}})]}}),vf=N.create({name:`keymap`,addKeyboardShortcuts(){let e=()=>this.editor.commands.first(({commands:e})=>[()=>e.undoInputRule(),()=>e.command(({tr:t})=>{let{selection:n,doc:r}=t,{empty:i,$anchor:a}=n,{pos:o,parent:s}=a,c=a.parent.isTextblock&&o>0?t.doc.resolve(o-1):a,l=c.parent.type.spec.isolating,u=a.pos-a.parentOffset,d=l&&c.parent.childCount===1?u===a.pos:O.atStart(r).from===o;return!i||!s.type.isTextblock||s.textContent.length||!d||d&&a.parent.type.name===`paragraph`?!1:e.clearNodes()}),()=>e.deleteSelection(),()=>e.joinBackward(),()=>e.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:e})=>[()=>e.deleteSelection(),()=>e.deleteCurrentNode(),()=>e.joinForward(),()=>e.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:e})=>[()=>e.newlineInCode(),()=>e.createParagraphNear(),()=>e.liftEmptyBlock(),()=>e.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},r={...n},i={...n,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Vl()||ou()?i:r},addProseMirrorPlugins(){return[new Mr({key:new Fr(`clearDocument`),appendTransaction:(e,t,n)=>{if(e.some(e=>e.getMeta(`composition`)))return;let r=e.some(e=>e.docChanged)&&!t.doc.eq(n.doc),i=e.some(e=>e.getMeta(`preventClearDocument`));if(!r||i)return;let{empty:a,from:o,to:s}=t.selection,c=O.atStart(t.doc).from,l=O.atEnd(t.doc).to;if(a||!(o===c&&s===l)||!_d(n.doc))return;let u=n.tr,d=pl({state:n,transaction:u}),{commands:f}=new ml({editor:this.editor,state:d});if(f.clearNodes(),u.steps.length)return u}})]}}),yf=N.create({name:`paste`,addProseMirrorPlugins(){return[new Mr({key:new Fr(`tiptapPaste`),props:{handlePaste:(e,t,n)=>{this.editor.emit(`paste`,{editor:this.editor,event:t,slice:n})}}})]}}),bf=N.create({name:`tabindex`,addProseMirrorPlugins(){return[new Mr({key:new Fr(`tabindex`),props:{attributes:()=>this.editor.isEditable?{tabindex:`0`}:{}}})]}}),xf=N.create({name:`textDirection`,addOptions(){return{direction:void 0}},addGlobalAttributes(){if(!this.options.direction)return[];let{nodeExtensions:e}=Iu(this.extensions);return[{types:e.filter(e=>e.name!==`text`).map(e=>e.name),attributes:{dir:{default:this.options.direction,parseHTML:e=>{let t=e.getAttribute(`dir`);return t&&(t===`ltr`||t===`rtl`||t===`auto`)?t:this.options.direction},renderHTML:e=>e.dir?{dir:e.dir}:{}}}}]},addProseMirrorPlugins(){return[new Mr({key:new Fr(`textDirection`),props:{attributes:()=>{let e=this.options.direction;return e?{dir:e}:{}}}})]}}),Sf=class e{constructor(e,t,n=!1,r=null){this.currentNode=null,this.actualDepth=null,this.isBlock=n,this.resolvedPos=e,this.editor=t,this.currentNode=r}get name(){return this.node.type.name}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){return this.actualDepth??this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,n=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can\u2019t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}t=this.from+1,n=this.to-1}this.editor.commands.insertContentAt({from:t,to:n},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+(this.node.isText?0:1)}get parent(){if(this.depth===0)return null;let t=this.resolvedPos.start(this.resolvedPos.depth-1);return new e(this.resolvedPos.doc.resolve(t),this.editor)}get before(){let t=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.from-3)),new e(t,this.editor)}get after(){let t=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.to+3)),new e(t,this.editor)}get children(){let t=[];return this.node.content.forEach((n,r)=>{let i=n.isBlock&&!n.isTextblock,a=n.isAtom&&!n.isText,o=n.isInline,s=this.pos+r+(a?0:1);if(s<0||s>this.resolvedPos.doc.nodeSize-2)return;let c=this.resolvedPos.doc.resolve(s);if(!i&&!o&&c.depth<=this.depth)return;let l=new e(c,this.editor,i,i||o?n:null);i&&(l.actualDepth=this.depth+1),t.push(l)}),t}get firstChild(){return this.children[0]||null}get lastChild(){let e=this.children;return e[e.length-1]||null}closest(e,t={}){let n=null,r=this.parent;for(;r&&!n;){if(r.node.type.name===e)if(Object.keys(t).length>0){let e=r.node.attrs,n=Object.keys(t);for(let r=0;r<n.length;r+=1){let i=n[r];if(e[i]!==t[i])break}}else n=r;r=r.parent}return n}querySelector(e,t={}){return this.querySelectorAll(e,t,!0)[0]||null}querySelectorAll(e,t={},n=!1){let r=[];if(!this.children||this.children.length===0)return r;let i=Object.keys(t);return this.children.forEach(a=>{n&&r.length>0||(a.node.type.name===e&&i.every(e=>t[e]===a.node.attrs[e])&&r.push(a),!(n&&r.length>0)&&(r=r.concat(a.querySelectorAll(e,t,n))))}),r}setAttribute(e){let{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}},Cf=`.ProseMirror {
56
+ `,textSerializers:o={}}=n||{},s=``;return e.nodesBetween(r,i,(e,n,c,l)=>{e.isBlock&&n>r&&(s+=a);let u=o?.[e.type.name];if(u)return c&&(s+=u({node:e,pos:n,parent:c,index:l,range:t})),!1;e.isText&&(s+=(e?.text)?.slice(Math.max(r,n)-n,i-n))}),s}function $u(e,t){return Qu(e,{from:0,to:e.content.size},t)}function ed(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function td(e,t){let n=Sl(t,e.schema),{from:r,to:i}=e.selection,a=[];e.doc.nodesBetween(r,i,e=>{a.push(e)});let o=a.reverse().find(e=>e.type.name===n.name);return o?{...o.attrs}:{}}function nd(e,t){let n=pu(typeof t==`string`?t:t.name,e.schema);return n===`node`?td(e,t):n===`mark`?Tu(e,t):{}}function rd(e,t=JSON.stringify){let n={};return e.filter(e=>{let r=t(e);return Object.prototype.hasOwnProperty.call(n,r)?!1:n[r]=!0})}function id(e){let t=rd(e);return t.length===1?t:t.filter((e,n)=>!t.filter((e,t)=>t!==n).some(t=>e.oldRange.from>=t.oldRange.from&&e.oldRange.to<=t.oldRange.to&&e.newRange.from>=t.newRange.from&&e.newRange.to<=t.newRange.to))}function ad(e){let{mapping:t,steps:n}=e,r=[];return t.maps.forEach((e,i)=>{let a=[];if(e.ranges.length)e.forEach((e,t)=>{a.push({from:e,to:t})});else{let{from:e,to:t}=n[i];if(e===void 0||t===void 0)return;a.push({from:e,to:t})}a.forEach(({from:e,to:n})=>{let a=t.slice(i).map(e,-1),o=t.slice(i).map(n),s=t.invert().map(a,-1),c=t.invert().map(o);r.push({oldRange:{from:s,to:c},newRange:{from:a,to:o}})})}),id(r)}function od(e,t,n){let r=[];return e===t?n.resolve(e).marks().forEach(t=>{let i=Ml(n.resolve(e),t.type);i&&r.push({mark:t,...i})}):n.nodesBetween(e,t,(e,t)=>{!e||e?.nodeSize===void 0||r.push(...e.marks.map(n=>({from:t,to:t+e.nodeSize,mark:n})))}),r}var sd=(e,t,n,r=20)=>{let i=e.doc.resolve(n),a=r,o=null;for(;a>0&&o===null;){let e=i.node(a);e?.type.name===t?o=e:--a}return[o,a]};function cd(e,t){return t.nodes[e]||t.marks[e]||null}function ld(e,t,n){return Object.fromEntries(Object.entries(n).filter(([n])=>{let r=e.find(e=>e.type===t&&e.name===n);return r?r.attribute.keepOnSplit:!1}))}var ud=(e,t=500)=>{let n=``,r=e.parentOffset;return e.parent.nodesBetween(Math.max(0,r-t),r,(e,t,i,a)=>{var o;let s=(o=e.type.spec).toText?.call(o,{node:e,pos:t,parent:i,index:a})||e.textContent||`%leaf%`;n+=e.isAtom&&!e.isText?s:s.slice(0,Math.max(0,r-t))}),n};function dd(e,t,n={}){let{empty:r,ranges:i}=e.selection,a=t?Nl(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(e=>a?a.name===e.type.name:!0).find(e=>kl(e.attrs,n,{strict:!1}));let o=0,s=[];if(i.forEach(({$from:t,$to:n})=>{let r=t.pos,i=n.pos;e.doc.nodesBetween(r,i,(e,t)=>{if(a&&e.inlineContent&&!e.type.allowsMarkType(a))return!1;if(!e.isText&&!e.marks.length)return;let n=Math.max(r,t),c=Math.min(i,t+e.nodeSize),l=c-n;o+=l,s.push(...e.marks.map(e=>({mark:e,from:n,to:c})))})}),o===0)return!1;let c=s.filter(e=>a?a.name===e.mark.type.name:!0).filter(e=>kl(e.mark.attrs,n,{strict:!1})).reduce((e,t)=>e+t.to-t.from,0),l=s.filter(e=>a?e.mark.type!==a&&e.mark.type.excludes(a):!0).reduce((e,t)=>e+t.to-t.from,0);return(c>0?c+l:c)>=o}function fd(e,t,n={}){if(!t)return cu(e,null,n)||dd(e,null,n);let r=pu(t,e.schema);return r===`node`?cu(e,t,n):r===`mark`?dd(e,t,n):!1}var pd=(e,t)=>{let{$from:n,$to:r,$anchor:i}=e.selection;if(t){let n=Au(e=>e.type.name===t)(e.selection);if(!n)return!1;let r=e.doc.resolve(n.pos+1);return i.pos+1===r.end()}return!(r.parentOffset<r.parent.nodeSize-2||n.pos!==r.pos)},md=e=>{let{$from:t,$to:n}=e.selection;return!(t.parentOffset>0||t.pos!==n.pos)};function hd(e,t){return Array.isArray(t)?t.some(t=>(typeof t==`string`?t:t.name)===e.name):t}function gd(e,t){let{nodeExtensions:n}=Iu(t),r=n.find(t=>t.name===e);if(!r)return!1;let i=Pu(M(r,`group`,{name:r.name,options:r.options,storage:r.storage}));return typeof i==`string`?i.split(` `).includes(`list`):!1}function _d(e,{checkChildren:t=!0,ignoreWhitespace:n=!1}={}){if(n){if(e.type.name===`hardBreak`)return!0;if(e.isText)return!/\S/.test(e.text??``)}if(e.isText)return!e.text;if(e.isAtom||e.isLeaf)return!1;if(e.content.childCount===0)return!0;if(t){let r=!0;return e.content.forEach(e=>{r!==!1&&(_d(e,{ignoreWhitespace:n,checkChildren:t})||(r=!1))}),r}return!1}function vd(e){return e instanceof A}var yd=class e{constructor(e){this.position=e}static fromJSON(t){return new e(t.position)}toJSON(){return{position:this.position}}};function bd(e,t){let n=t.mapping.mapResult(e.position);return{position:new yd(n.pos),mapResult:n}}function xd(e){return new yd(e)}function Sd(e,t,n){let{selection:r}=t,i=null;if(Il(r)&&(i=r.$cursor),i){let t=e.storedMarks??i.marks();return i.parent.type.allowsMarkType(n)&&(!!n.isInSet(t)||!t.some(e=>e.type.excludes(n)))}let{ranges:a}=r;return a.some(({$from:t,$to:r})=>{let i=t.depth===0?e.doc.inlineContent&&e.doc.type.allowsMarkType(n):!1;return e.doc.nodesBetween(t.pos,r.pos,(e,t,r)=>{if(i)return!1;if(e.isInline){let t=!r||r.type.allowsMarkType(n),a=!!n.isInSet(e.marks)||!e.marks.some(e=>e.type.excludes(n));i=t&&a}return!i}),i})}var Cd=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{selection:a}=n,{empty:o,ranges:s}=a,c=Nl(e,r.schema);if(i)if(o){let e=Tu(r,c);n.addStoredMark(c.create({...e,...t}))}else s.forEach(e=>{let i=e.$from.pos,a=e.$to.pos;r.doc.nodesBetween(i,a,(e,r)=>{let o=Math.max(r,i),s=Math.min(r+e.nodeSize,a);e.marks.find(e=>e.type===c)?e.marks.forEach(e=>{c===e.type&&n.addMark(o,s,c.create({...e.attrs,...t}))}):n.addMark(o,s,c.create(t))})});return Sd(r,n,c)},wd=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),Td=(e,t={})=>({state:n,dispatch:r,chain:i})=>{let a=Sl(e,n.schema),o;return n.selection.$anchor.sameParent(n.selection.$head)&&(o=n.selection.$anchor.parent.attrs),a.isTextblock?i().command(({commands:e})=>fi(a,{...o,...t})(n)?!0:e.clearNodes()).command(({state:e})=>fi(a,{...o,...t})(e,r)).run():(console.warn(`[tiptap warn]: Currently "setNode()" only supports text block nodes.`),!1)},Ed=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,r=Ll(e,0,n.content.size),i=A.create(n,r);t.setSelection(i)}return!0},Dd=(e,t)=>({tr:n,state:r,dispatch:i})=>{let{selection:a}=r,o,s;return typeof t==`number`?(o=t,s=t):t&&`from`in t&&`to`in t?(o=t.from,s=t.to):(o=a.from,s=a.to),i&&n.doc.nodesBetween(o,s,(t,r)=>{t.isText||n.setNodeMarkup(r,void 0,{...t.attrs,dir:e})}),!0},Od=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,{from:r,to:i}=typeof e==`number`?{from:e,to:e}:e,a=k.atStart(n).from,o=k.atEnd(n).to,s=Ll(r,a,o),c=Ll(i,a,o),l=k.create(n,s,c);t.setSelection(l)}return!0},kd=e=>({state:t,dispatch:n})=>wi(Sl(e,t.schema))(t,n);function Ad(e,t){let n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){let r=n.filter(e=>t?.includes(e.type.name));e.tr.ensureMarks(r)}}var jd=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:i})=>{let{selection:a,doc:o}=t,{$from:s,$to:c}=a,l=i.extensionManager.attributes,u=ld(l,s.node().type.name,s.node().attrs);if(a instanceof A&&a.node.isBlock)return!s.parentOffset||!Rn(o,s.pos)?!1:(r&&(e&&Ad(n,i.extensionManager.splittableMarks),t.split(s.pos).scrollIntoView()),!0);if(!s.parent.isBlock)return!1;let d=c.parentOffset===c.parent.content.size,f=s.depth===0?void 0:Du(s.node(-1).contentMatchAt(s.indexAfter(-1))),p=d&&f?[{type:f,attrs:u}]:void 0,m=Rn(t.doc,t.mapping.map(s.pos),1,p);if(!p&&!m&&Rn(t.doc,t.mapping.map(s.pos),1,f?[{type:f}]:void 0)&&(m=!0,p=f?[{type:f,attrs:u}]:void 0),r){if(m&&(a instanceof k&&t.deleteSelection(),t.split(t.mapping.map(s.pos),1,p),f&&!d&&!s.parentOffset&&s.parent.type!==f)){let e=t.mapping.map(s.before()),n=t.doc.resolve(e);s.node(-1).canReplaceWith(n.index(),n.index()+1,f)&&t.setNodeMarkup(t.mapping.map(s.before()),f)}e&&Ad(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return m},Md=(e,t={})=>({tr:n,state:r,dispatch:i,editor:a})=>{let o=Sl(e,r.schema),{$from:s,$to:c}=r.selection,l=r.selection.node;if(l&&l.isBlock||s.depth<2||!s.sameParent(c))return!1;let u=s.node(-1);if(u.type!==o)return!1;let d=a.extensionManager.attributes;if(s.parent.content.size===0&&s.node(-1).childCount===s.indexAfter(-1)){if(s.depth===2||s.node(-3).type!==o||s.index(-2)!==s.node(-2).childCount-1)return!1;if(i){let e=E.empty,r=s.index(-1)?1:s.index(-2)?2:3;for(let t=s.depth-r;t>=s.depth-3;--t)e=E.from(s.node(t).copy(e));let i=s.indexAfter(-1)<s.node(-2).childCount?1:s.indexAfter(-2)<s.node(-3).childCount?2:3,a={...ld(d,s.node().type.name,s.node().attrs),...t},c=o.contentMatch.defaultType?.createAndFill(a)||void 0;e=e.append(E.from(o.createAndFill(null,c)||void 0));let l=s.before(s.depth-(r-1));n.replace(l,s.after(-i),new D(e,4-r,0));let u=-1;n.doc.nodesBetween(l,n.doc.content.size,(e,t)=>{if(u>-1)return!1;e.isTextblock&&e.content.size===0&&(u=t+1)}),u>-1&&n.setSelection(k.near(n.doc.resolve(u))),n.scrollIntoView()}return!0}let f=c.pos===s.end()?u.contentMatchAt(0).defaultType:null,p={...ld(d,u.type.name,u.attrs),...t},m={...ld(d,s.node().type.name,s.node().attrs),...t};n.delete(s.pos,c.pos);let h=f?[{type:o,attrs:p},{type:f,attrs:m}]:[{type:o,attrs:p}];if(!Rn(n.doc,s.pos,2))return!1;if(i){let{selection:e,storedMarks:t}=r,{splittableMarks:o}=a.extensionManager,c=t||e.$to.parentOffset&&e.$from.marks();if(n.split(s.pos,2,h).scrollIntoView(),!c||!i)return!0;let l=c.filter(e=>o.includes(e.type.name));n.ensureMarks(l)}return!0},Nd=(e,t)=>{let n=Au(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;let i=e.doc.nodeAt(r);return n.node.type===i?.type&&Bn(e.doc,n.pos)&&e.join(n.pos),!0},Pd=(e,t)=>{let n=Au(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;let i=e.doc.nodeAt(r);return n.node.type===i?.type&&Bn(e.doc,r)&&e.join(r),!0},Fd=(e,t,n,r={})=>({editor:i,tr:a,state:o,dispatch:s,chain:c,commands:l,can:u})=>{let{extensions:d,splittableMarks:f}=i.extensionManager,p=Sl(e,o.schema),m=Sl(t,o.schema),{selection:h,storedMarks:g}=o,{$from:_,$to:v}=h,y=_.blockRange(v),b=g||h.$to.parentOffset&&h.$from.marks();if(!y)return!1;let x=Au(e=>gd(e.type.name,d))(h);if(y.depth>=1&&x&&y.depth-x.depth<=1){if(x.node.type===p)return l.liftListItem(m);if(gd(x.node.type.name,d)&&p.validContent(x.node.content)&&s)return c().command(()=>(a.setNodeMarkup(x.pos,p),!0)).command(()=>Nd(a,p)).command(()=>Pd(a,p)).run()}return!n||!b||!s?c().command(()=>u().wrapInList(p,r)?!0:l.clearNodes()).wrapInList(p,r).command(()=>Nd(a,p)).command(()=>Pd(a,p)).run():c().command(()=>{let e=u().wrapInList(p,r),t=b.filter(e=>f.includes(e.type.name));return a.ensureMarks(t),e?!0:l.clearNodes()}).wrapInList(p,r).command(()=>Nd(a,p)).command(()=>Pd(a,p)).run()},Id=(e,t={},n={})=>({state:r,commands:i})=>{let{extendEmptyMarkRange:a=!1}=n,o=Nl(e,r.schema);return dd(r,o,t)?i.unsetMark(o,{extendEmptyMarkRange:a}):i.setMark(o,t)},Ld=(e,t,n={})=>({state:r,commands:i})=>{let a=Sl(e,r.schema),o=Sl(t,r.schema),s=cu(r,a,n),c;return r.selection.$anchor.sameParent(r.selection.$head)&&(c=r.selection.$anchor.parent.attrs),s?i.setNode(o,c):i.setNode(a,{...c,...n})},Rd=(e,t={})=>({state:n,commands:r})=>{let i=Sl(e,n.schema);return cu(n,i,t)?r.lift(i):r.wrapIn(i,t)},zd=()=>({state:e,dispatch:t})=>{let n=e.plugins;for(let r=0;r<n.length;r+=1){let i=n[r],a;if(i.spec.isInputRules&&(a=i.getState(e))){if(t){let t=e.tr,n=a.transform;for(let e=n.steps.length-1;e>=0;--e)t.step(n.steps[e].invert(n.docs[e]));if(a.text){let n=t.doc.resolve(a.from).marks();t.replaceWith(a.from,a.to,e.schema.text(a.text,n))}else t.delete(a.from,a.to)}return!0}}return!1},Bd=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,{empty:r,ranges:i}=n;return r||t&&i.forEach(t=>{e.removeMark(t.$from.pos,t.$to.pos)}),!0},Vd=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{extendEmptyMarkRange:a=!1}=t,{selection:o}=n,s=Nl(e,r.schema),{$from:c,empty:l,ranges:u}=o;if(!i)return!0;if(l&&a){let{from:e,to:t}=o,r=Ml(c,s,c.marks().find(e=>e.type===s)?.attrs);r&&(e=r.from,t=r.to),n.removeMark(e,t,s)}else u.forEach(e=>{n.removeMark(e.$from.pos,e.$to.pos,s)});return n.removeStoredMark(s),!0},Hd=e=>({tr:t,state:n,dispatch:r})=>{let{selection:i}=n,a,o;return typeof e==`number`?(a=e,o=e):e&&`from`in e&&`to`in e?(a=e.from,o=e.to):(a=i.from,o=i.to),r&&t.doc.nodesBetween(a,o,(e,n)=>{if(e.isText)return;let r={...e.attrs};delete r.dir,t.setNodeMarkup(n,void 0,r)}),!0},Ud=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let a=null,o=null,s=pu(typeof e==`string`?e:e.name,r.schema);if(!s)return!1;s===`node`&&(a=Sl(e,r.schema)),s===`mark`&&(o=Nl(e,r.schema));let c=!1;return n.selection.ranges.forEach(e=>{let s=e.$from.pos,l=e.$to.pos,u,d,f,p;n.selection.empty?r.doc.nodesBetween(s,l,(e,t)=>{a&&a===e.type&&(c=!0,f=Math.max(t,s),p=Math.min(t+e.nodeSize,l),u=t,d=e)}):r.doc.nodesBetween(s,l,(e,r)=>{r<s&&a&&a===e.type&&(c=!0,f=Math.max(r,s),p=Math.min(r+e.nodeSize,l),u=r,d=e),r>=s&&r<=l&&(a&&a===e.type&&(c=!0,i&&n.setNodeMarkup(r,void 0,{...e.attrs,...t})),o&&e.marks.length&&e.marks.forEach(a=>{if(o===a.type&&(c=!0,i)){let i=Math.max(r,s),c=Math.min(r+e.nodeSize,l);n.addMark(i,c,o.create({...a.attrs,...t}))}}))}),d&&(u!==void 0&&i&&n.setNodeMarkup(u,void 0,{...d.attrs,...t}),o&&d.marks.length&&d.marks.forEach(e=>{o===e.type&&i&&n.addMark(f,p,o.create({...e.attrs,...t}))}))}),c},Wd=(e,t={})=>({state:n,dispatch:r})=>di(Sl(e,n.schema),t)(n,r),Gd=(e,t={})=>({state:n,dispatch:r})=>vi(Sl(e,n.schema),t)(n,r),Kd=class{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){let n=this.callbacks[e];return n&&n.forEach(e=>e.apply(this,t)),this}off(e,t){let n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e]),this}once(e,t){let n=(...r)=>{this.off(e,n),t.apply(this,r)};return this.on(e,n)}removeAllListeners(){this.callbacks={}}},qd=class{constructor(e){this.find=e.find,this.handler=e.handler,this.undoable=e.undoable??!0}},Jd=(e,t)=>{if(Ol(t))return t.exec(e);let n=t(e);if(!n)return null;let r=[n.text];return r.index=n.index,r.input=e,r.data=n.data,n.replaceWith&&(n.text.includes(n.replaceWith)||console.warn(`[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".`),r.push(n.replaceWith)),r};function Yd(e){let{editor:t,from:n,to:r,text:i,rules:a,plugin:o}=e,{view:s}=t;if(s.composing)return!1;let c=s.state.doc.resolve(n);if(c.parent.type.spec.code||(c.nodeBefore||c.nodeAfter)?.marks.find(e=>e.type.spec.code))return!1;let l=!1,u=ud(c)+i;return a.forEach(e=>{if(l)return;let a=Jd(u,e.find);if(!a)return;let c=s.state.tr,d=fl({state:s.state,transaction:c}),f={from:n-(a[0].length-i.length),to:r},{commands:p,chain:m,can:h}=new pl({editor:t,state:d});e.handler({state:d,range:f,match:a,commands:p,chain:m,can:h})===null||!c.steps.length||(e.undoable&&c.setMeta(o,{transform:c,from:n,to:r,text:i}),s.dispatch(c),l=!0)}),l}function Xd(e){let{editor:t,rules:n}=e,r=new j({state:{init(){return null},apply(e,i,a){let o=e.getMeta(r);if(o)return o;let s=e.getMeta(`applyInputRules`);return s&&setTimeout(()=>{let{text:e}=s;e=typeof e==`string`?e:Mu(E.from(e),a.schema);let{from:i}=s;Yd({editor:t,from:i,to:i+e.length,text:e,rules:n,plugin:r})}),e.selectionSet||e.docChanged?null:i}},props:{handleTextInput(e,i,a,o){return Yd({editor:t,from:i,to:a,text:o,rules:n,plugin:r})},handleDOMEvents:{compositionend:e=>(setTimeout(()=>{let{$cursor:i}=e.state.selection;i&&Yd({editor:t,from:i.pos,to:i.pos,text:``,rules:n,plugin:r})}),!1)},handleKeyDown(e,i){if(i.key!==`Enter`)return!1;let{$cursor:a}=e.state.selection;return a?Yd({editor:t,from:a.pos,to:a.pos,text:`
57
+ `,rules:n,plugin:r}):!1}},isInputRules:!0});return r}function Zd(e){return Object.prototype.toString.call(e).slice(8,-1)}function Qd(e){return Zd(e)===`Object`?e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype:!1}function $d(e,t){let n={...e};return Qd(e)&&Qd(t)&&Object.keys(t).forEach(r=>{Qd(t[r])&&Qd(e[r])?n[r]=$d(e[r],t[r]):n[r]=t[r]}),n}var ef=class{constructor(e={}){this.type=`extendable`,this.parent=null,this.child=null,this.name=``,this.config={name:this.name},this.config={...this.config,...e},this.name=this.config.name}get options(){return{...Pu(M(this,`addOptions`,{name:this.name}))||{}}}get storage(){return{...Pu(M(this,`addStorage`,{name:this.name,options:this.options}))||{}}}configure(e={}){let t=this.extend({...this.config,addOptions:()=>$d(this.options,e)});return t.name=this.name,t.parent=this.parent,t}extend(e={}){let t=new this.constructor({...this.config,...e});return t.parent=this,this.child=t,t.name=`name`in e?e.name:t.parent.name,t}},tf=class e extends ef{constructor(){super(...arguments),this.type=`mark`}static create(t={}){return new e(typeof t==`function`?t():t)}static handleExit({editor:e,mark:t}){let{tr:n}=e.state,r=e.state.selection.$from;if(r.pos===r.end()){let i=r.marks();if(!i.find(e=>e?.type.name===t.name))return!1;let a=i.find(e=>e?.type.name===t.name);return a&&n.removeStoredMark(a),n.insertText(` `,r.pos),e.view.dispatch(n),!0}return!1}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}};function nf(e){return typeof e==`number`}var rf=class{constructor(e){this.find=e.find,this.handler=e.handler}},af=(e,t,n)=>{if(Ol(t))return[...e.matchAll(t)];let r=t(e,n);return r?r.map(t=>{let n=[t.text];return n.index=t.index,n.input=e,n.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn(`[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".`),n.push(t.replaceWith)),n}):[]};function of(e){let{editor:t,state:n,from:r,to:i,rule:a,pasteEvent:o,dropEvent:s}=e,{commands:c,chain:l,can:u}=new pl({editor:t,state:n}),d=[];return n.doc.nodesBetween(r,i,(e,t)=>{if(e.type?.spec?.code||!(e.isText||e.isTextblock||e.isInline))return;let f=e.content?.size??e.nodeSize??0,p=Math.max(r,t),m=Math.min(i,t+f);p>=m||af(e.isText?e.text||``:e.textBetween(p-t,m-t,void 0,``),a.find,o).forEach(e=>{if(e.index===void 0)return;let t=p+e.index+1,r=t+e[0].length,i={from:n.tr.mapping.map(t),to:n.tr.mapping.map(r)},f=a.handler({state:n,range:i,match:e,commands:c,chain:l,can:u,pasteEvent:o,dropEvent:s});d.push(f)})}),d.every(e=>e!==null)}var sf=null,cf=e=>{var t;let n=new ClipboardEvent(`paste`,{clipboardData:new DataTransfer});return(t=n.clipboardData)==null||t.setData(`text/html`,e),n};function lf(e){let{editor:t,rules:n}=e,r=null,i=!1,a=!1,o=typeof ClipboardEvent<`u`?new ClipboardEvent(`paste`):null,s;try{s=typeof DragEvent<`u`?new DragEvent(`drop`):null}catch{s=null}let c=({state:e,from:n,to:r,rule:i,pasteEvt:a})=>{let c=e.tr;if(!(!of({editor:t,state:fl({state:e,transaction:c}),from:Math.max(n-1,0),to:r.b-1,rule:i,pasteEvent:a,dropEvent:s})||!c.steps.length)){try{s=typeof DragEvent<`u`?new DragEvent(`drop`):null}catch{s=null}return o=typeof ClipboardEvent<`u`?new ClipboardEvent(`paste`):null,c}};return n.map(e=>new j({view(e){let n=n=>{r=e.dom.parentElement?.contains(n.target)?e.dom.parentElement:null,r&&(sf=t)},i=()=>{sf&&=null};return window.addEventListener(`dragstart`,n),window.addEventListener(`dragend`,i),{destroy(){window.removeEventListener(`dragstart`,n),window.removeEventListener(`dragend`,i)}}},props:{handleDOMEvents:{drop:(e,t)=>{if(a=r===e.dom.parentElement,s=t,!a){let e=sf;e?.isEditable&&setTimeout(()=>{let t=e.state.selection;t&&e.commands.deleteRange({from:t.from,to:t.to})},10)}return!1},paste:(e,t)=>{let n=t.clipboardData?.getData(`text/html`);return o=t,i=!!n?.includes(`data-pm-slice`),!1}}},appendTransaction:(t,n,r)=>{let s=t[0],l=s.getMeta(`uiEvent`)===`paste`&&!i,u=s.getMeta(`uiEvent`)===`drop`&&!a,d=s.getMeta(`applyPasteRules`),f=!!d;if(!l&&!u&&!f)return;if(f){let{text:t}=d;t=typeof t==`string`?t:Mu(E.from(t),r.schema);let{from:n}=d,i=n+t.length,a=cf(t);return c({rule:e,state:r,from:n,to:{b:i},pasteEvt:a})}let p=n.doc.content.findDiffStart(r.doc.content),m=n.doc.content.findDiffEnd(r.doc.content);if(!(!nf(p)||!m||p===m.b))return c({rule:e,state:r,from:p,to:m,pasteEvt:o})}}))}var uf=class{constructor(e,t){this.splittableMarks=[],this.editor=t,this.baseExtensions=e,this.extensions=Yu(e),this.schema=Ku(this.extensions,t),this.setupExtensions()}get commands(){return this.extensions.reduce((e,t)=>{let n=M(t,`addCommands`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:this.editor,type:cd(t.name,this.schema)});return n?{...e,...n()}:e},{})}get plugins(){let{editor:e}=this;return Ju([...this.extensions].reverse()).flatMap(t=>{let n={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:cd(t.name,this.schema)},r=[],i=M(t,`addKeyboardShortcuts`,n),a={};if(t.type===`mark`&&M(t,`exitable`,n)&&(a.ArrowRight=()=>tf.handleExit({editor:e,mark:t})),i){let t=Object.fromEntries(Object.entries(i()).map(([t,n])=>[t,()=>n({editor:e})]));a={...a,...t}}let o=cl(a);r.push(o);let s=M(t,`addInputRules`,n);if(hd(t,e.options.enableInputRules)&&s){let t=s();if(t&&t.length){let n=Xd({editor:e,rules:t}),i=Array.isArray(n)?n:[n];r.push(...i)}}let c=M(t,`addPasteRules`,n);if(hd(t,e.options.enablePasteRules)&&c){let t=c();if(t&&t.length){let n=lf({editor:e,rules:t});r.push(...n)}}let l=M(t,`addProseMirrorPlugins`,n);if(l){let e=l();r.push(...e)}return r})}get attributes(){return Lu(this.extensions)}get nodeViews(){let{editor:e}=this,{nodeExtensions:t}=Iu(this.extensions);return Object.fromEntries(t.filter(e=>!!M(e,`addNodeView`)).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r=M(t,`addNodeView`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:Sl(t.name,this.schema)});if(!r)return[];let i=r();return i?[t.name,(r,a,o,s,c)=>i({node:r,view:a,getPos:o,decorations:s,innerDecorations:c,editor:e,extension:t,HTMLAttributes:Vu(r,n)})]:[]}))}dispatchTransaction(e){let{editor:t}=this;return Ju([...this.extensions].reverse()).reduceRight((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:cd(n.name,this.schema)},i=M(n,`dispatchTransaction`,r);return i?t=>{i.call(r,{transaction:t,next:e})}:e},e)}transformPastedHTML(e){let{editor:t}=this;return Ju([...this.extensions]).reduce((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:cd(n.name,this.schema)},i=M(n,`transformPastedHTML`,r);return i?(t,n)=>{let a=e(t,n);return i.call(r,a)}:e},e||(e=>e))}get markViews(){let{editor:e}=this,{markExtensions:t}=Iu(this.extensions);return Object.fromEntries(t.filter(e=>!!M(e,`addMarkView`)).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r=M(t,`addMarkView`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:Nl(t.name,this.schema)});return r?[t.name,(i,a,o)=>{let s=Vu(i,n);return r()({mark:i,view:a,inline:o,editor:e,extension:t,HTMLAttributes:s,updateAttributes:t=>{Uf(i,e,t)}})}]:[]}))}setupExtensions(){let e=this.extensions;this.editor.extensionStorage=Object.fromEntries(e.map(e=>[e.name,e.storage])),e.forEach(e=>{let t={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:cd(e.name,this.schema)};e.type===`mark`&&(Pu(M(e,`keepOnSplit`,t))??!0)&&this.splittableMarks.push(e.name);let n=M(e,`onBeforeCreate`,t),r=M(e,`onCreate`,t),i=M(e,`onUpdate`,t),a=M(e,`onSelectionUpdate`,t),o=M(e,`onTransaction`,t),s=M(e,`onFocus`,t),c=M(e,`onBlur`,t),l=M(e,`onDestroy`,t);n&&this.editor.on(`beforeCreate`,n),r&&this.editor.on(`create`,r),i&&this.editor.on(`update`,i),a&&this.editor.on(`selectionUpdate`,a),o&&this.editor.on(`transaction`,o),s&&this.editor.on(`focus`,s),c&&this.editor.on(`blur`,c),l&&this.editor.on(`destroy`,l)})}};uf.resolve=Yu,uf.sort=Ju,uf.flatten=ju,dl({},{ClipboardTextSerializer:()=>df,Commands:()=>ff,Delete:()=>pf,Drop:()=>mf,Editable:()=>hf,FocusEvents:()=>_f,Keymap:()=>vf,Paste:()=>yf,Tabindex:()=>bf,TextDirection:()=>xf,focusEventsPluginKey:()=>gf});var N=class e extends ef{constructor(){super(...arguments),this.type=`extension`}static create(t={}){return new e(typeof t==`function`?t():t)}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}},df=N.create({name:`clipboardTextSerializer`,addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new j({key:new Pr(`clipboardTextSerializer`),props:{clipboardTextSerializer:()=>{let{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:i}=t,{ranges:a}=i,o=Math.min(...a.map(e=>e.$from.pos)),s=Math.max(...a.map(e=>e.$to.pos)),c=ed(n);return Qu(r,{from:o,to:s},{...this.options.blockSeparator===void 0?{}:{blockSeparator:this.options.blockSeparator},textSerializers:c})}}})]}}),ff=N.create({name:`commands`,addCommands(){return{...ml}}}),pf=N.create({name:`delete`,onUpdate({transaction:e,appendedTransactions:t}){let n=()=>{var n;if(((n=this.editor.options.coreExtensionOptions?.delete)?.filterTransaction)?.call(n,e)??e.getMeta(`y-sync$`))return;let r=Eu(e.before,[e,...t]);ad(r).forEach(t=>{r.mapping.mapResult(t.oldRange.from).deletedAfter&&r.mapping.mapResult(t.oldRange.to).deletedBefore&&r.before.nodesBetween(t.oldRange.from,t.oldRange.to,(n,i)=>{let a=i+n.nodeSize-2,o=t.oldRange.from<=i&&a<=t.oldRange.to;this.editor.emit(`delete`,{type:`node`,node:n,from:i,to:a,newFrom:r.mapping.map(i),newTo:r.mapping.map(a),deletedRange:t.oldRange,newRange:t.newRange,partial:!o,editor:this.editor,transaction:e,combinedTransform:r})})});let i=r.mapping;r.steps.forEach((t,n)=>{if(t instanceof gn){let a=i.slice(n).map(t.from,-1),o=i.slice(n).map(t.to),s=i.invert().map(a,-1),c=i.invert().map(o),l=a>0?r.doc.nodeAt(a-1)?.marks.some(e=>e.eq(t.mark)):!1,u=r.doc.nodeAt(o)?.marks.some(e=>e.eq(t.mark));this.editor.emit(`delete`,{type:`mark`,mark:t.mark,from:t.from,to:t.to,deletedRange:{from:s,to:c},newRange:{from:a,to:o},partial:!!(u||l),editor:this.editor,transaction:e,combinedTransform:r})}})};this.editor.options.coreExtensionOptions?.delete?.async??!0?setTimeout(n,0):n()}}),mf=N.create({name:`drop`,addProseMirrorPlugins(){return[new j({key:new Pr(`tiptapDrop`),props:{handleDrop:(e,t,n,r)=>{this.editor.emit(`drop`,{editor:this.editor,event:t,slice:n,moved:r})}}})]}}),hf=N.create({name:`editable`,addProseMirrorPlugins(){return[new j({key:new Pr(`editable`),props:{editable:()=>this.editor.options.editable}})]}}),gf=new Pr(`focusEvents`),_f=N.create({name:`focusEvents`,addProseMirrorPlugins(){let{editor:e}=this;return[new j({key:gf,props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;let r=e.state.tr.setMeta(`focus`,{event:n}).setMeta(`addToHistory`,!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;let r=e.state.tr.setMeta(`blur`,{event:n}).setMeta(`addToHistory`,!1);return t.dispatch(r),!1}}}})]}}),vf=N.create({name:`keymap`,addKeyboardShortcuts(){let e=()=>this.editor.commands.first(({commands:e})=>[()=>e.undoInputRule(),()=>e.command(({tr:t})=>{let{selection:n,doc:r}=t,{empty:i,$anchor:a}=n,{pos:o,parent:s}=a,c=a.parent.isTextblock&&o>0?t.doc.resolve(o-1):a,l=c.parent.type.spec.isolating,u=a.pos-a.parentOffset,d=l&&c.parent.childCount===1?u===a.pos:O.atStart(r).from===o;return!i||!s.type.isTextblock||s.textContent.length||!d||d&&a.parent.type.name===`paragraph`?!1:e.clearNodes()}),()=>e.deleteSelection(),()=>e.joinBackward(),()=>e.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:e})=>[()=>e.deleteSelection(),()=>e.deleteCurrentNode(),()=>e.joinForward(),()=>e.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:e})=>[()=>e.newlineInCode(),()=>e.createParagraphNear(),()=>e.liftEmptyBlock(),()=>e.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},r={...n},i={...n,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Bl()||au()?i:r},addProseMirrorPlugins(){return[new j({key:new Pr(`clearDocument`),appendTransaction:(e,t,n)=>{if(e.some(e=>e.getMeta(`composition`)))return;let r=e.some(e=>e.docChanged)&&!t.doc.eq(n.doc),i=e.some(e=>e.getMeta(`preventClearDocument`));if(!r||i)return;let{empty:a,from:o,to:s}=t.selection,c=O.atStart(t.doc).from,l=O.atEnd(t.doc).to;if(a||!(o===c&&s===l)||!_d(n.doc))return;let u=n.tr,d=fl({state:n,transaction:u}),{commands:f}=new pl({editor:this.editor,state:d});if(f.clearNodes(),u.steps.length)return u}})]}}),yf=N.create({name:`paste`,addProseMirrorPlugins(){return[new j({key:new Pr(`tiptapPaste`),props:{handlePaste:(e,t,n)=>{this.editor.emit(`paste`,{editor:this.editor,event:t,slice:n})}}})]}}),bf=N.create({name:`tabindex`,addProseMirrorPlugins(){return[new j({key:new Pr(`tabindex`),props:{attributes:()=>this.editor.isEditable?{tabindex:`0`}:{}}})]}}),xf=N.create({name:`textDirection`,addOptions(){return{direction:void 0}},addGlobalAttributes(){if(!this.options.direction)return[];let{nodeExtensions:e}=Iu(this.extensions);return[{types:e.filter(e=>e.name!==`text`).map(e=>e.name),attributes:{dir:{default:this.options.direction,parseHTML:e=>{let t=e.getAttribute(`dir`);return t&&(t===`ltr`||t===`rtl`||t===`auto`)?t:this.options.direction},renderHTML:e=>e.dir?{dir:e.dir}:{}}}}]},addProseMirrorPlugins(){return[new j({key:new Pr(`textDirection`),props:{attributes:()=>{let e=this.options.direction;return e?{dir:e}:{}}}})]}}),Sf=class e{constructor(e,t,n=!1,r=null){this.currentNode=null,this.actualDepth=null,this.isBlock=n,this.resolvedPos=e,this.editor=t,this.currentNode=r}get name(){return this.node.type.name}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){return this.actualDepth??this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,n=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can\u2019t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}t=this.from+1,n=this.to-1}this.editor.commands.insertContentAt({from:t,to:n},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+(this.node.isText?0:1)}get parent(){if(this.depth===0)return null;let t=this.resolvedPos.start(this.resolvedPos.depth-1);return new e(this.resolvedPos.doc.resolve(t),this.editor)}get before(){let t=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.from-3)),new e(t,this.editor)}get after(){let t=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.to+3)),new e(t,this.editor)}get children(){let t=[];return this.node.content.forEach((n,r)=>{let i=n.isBlock&&!n.isTextblock,a=n.isAtom&&!n.isText,o=n.isInline,s=this.pos+r+(a?0:1);if(s<0||s>this.resolvedPos.doc.nodeSize-2)return;let c=this.resolvedPos.doc.resolve(s);if(!i&&!o&&c.depth<=this.depth)return;let l=new e(c,this.editor,i,i||o?n:null);i&&(l.actualDepth=this.depth+1),t.push(l)}),t}get firstChild(){return this.children[0]||null}get lastChild(){let e=this.children;return e[e.length-1]||null}closest(e,t={}){let n=null,r=this.parent;for(;r&&!n;){if(r.node.type.name===e)if(Object.keys(t).length>0){let e=r.node.attrs,n=Object.keys(t);for(let r=0;r<n.length;r+=1){let i=n[r];if(e[i]!==t[i])break}}else n=r;r=r.parent}return n}querySelector(e,t={}){return this.querySelectorAll(e,t,!0)[0]||null}querySelectorAll(e,t={},n=!1){let r=[];if(!this.children||this.children.length===0)return r;let i=Object.keys(t);return this.children.forEach(a=>{n&&r.length>0||(a.node.type.name===e&&i.every(e=>t[e]===a.node.attrs[e])&&r.push(a),!(n&&r.length>0)&&(r=r.concat(a.querySelectorAll(e,t,n))))}),r}setAttribute(e){let{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}},Cf=`.ProseMirror {
58
58
  position: relative;
59
59
  }
60
60
 
@@ -124,9 +124,9 @@ img.ProseMirror-separator {
124
124
 
125
125
  .ProseMirror-focused .ProseMirror-gapcursor {
126
126
  display: block;
127
- }`;function wf(e,t,n){let r=document.querySelector(`style[data-tiptap-style${n?`-${n}`:``}]`);if(r!==null)return r;let i=document.createElement(`style`);return t&&i.setAttribute(`nonce`,t),i.setAttribute(`data-tiptap-style${n?`-${n}`:``}`,``),i.innerHTML=e,document.getElementsByTagName(`head`)[0].appendChild(i),i}var Tf=class extends Kd{constructor(e={}){super(),this.css=null,this.className=`tiptap`,this.editorView=null,this.isFocused=!1,this.isInitialized=!1,this.extensionStorage={},this.instanceId=Math.random().toString(36).slice(2,9),this.options={element:typeof document<`u`?document.createElement(`div`):null,content:``,injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,textDirection:void 0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onMount:()=>null,onUnmount:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:e})=>{throw e},onPaste:()=>null,onDrop:()=>null,onDelete:()=>null,enableExtensionDispatchTransaction:!0},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.utils={getUpdatedPosition:bd,createMappablePosition:xd},this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on(`beforeCreate`,this.options.onBeforeCreate),this.emit(`beforeCreate`,{editor:this}),this.on(`mount`,this.options.onMount),this.on(`unmount`,this.options.onUnmount),this.on(`contentError`,this.options.onContentError),this.on(`create`,this.options.onCreate),this.on(`update`,this.options.onUpdate),this.on(`selectionUpdate`,this.options.onSelectionUpdate),this.on(`transaction`,this.options.onTransaction),this.on(`focus`,this.options.onFocus),this.on(`blur`,this.options.onBlur),this.on(`destroy`,this.options.onDestroy),this.on(`drop`,({event:e,slice:t,moved:n})=>this.options.onDrop(e,t,n)),this.on(`paste`,({event:e,slice:t})=>this.options.onPaste(e,t)),this.on(`delete`,this.options.onDelete);let t=this.createDoc(),n=zl(t,this.options.autofocus);this.editorState=Ar.create({doc:t,schema:this.schema,selection:n||void 0}),this.options.element&&this.mount(this.options.element)}mount(e){if(typeof document>`u`)throw Error(`[tiptap error]: The editor cannot be mounted because there is no 'document' defined in this environment.`);this.createView(e),this.emit(`mount`,{editor:this}),this.css&&!document.head.contains(this.css)&&document.head.appendChild(this.css),window.setTimeout(()=>{this.isDestroyed||(this.options.autofocus!==!1&&this.options.autofocus!==null&&this.commands.focus(this.options.autofocus),this.emit(`create`,{editor:this}),this.isInitialized=!0)},0)}unmount(){if(this.editorView){let e=this.editorView.dom;e?.editor&&delete e.editor,this.editorView.destroy()}if(this.editorView=null,this.isInitialized=!1,this.css&&!document.querySelectorAll(`.${this.className}`).length)try{typeof this.css.remove==`function`?this.css.remove():this.css.parentNode&&this.css.parentNode.removeChild(this.css)}catch(e){console.warn(`Failed to remove CSS element:`,e)}this.css=null,this.emit(`unmount`,{editor:this})}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager.chain()}can(){return this.commandManager.can()}injectCSS(){this.options.injectCSS&&typeof document<`u`&&(this.css=wf(Cf,this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},!(!this.editorView||!this.state||this.isDestroyed)&&(this.options.editorProps&&this.view.setProps(this.options.editorProps),this.view.updateState(this.state))}setEditable(e,t=!0){this.setOptions({editable:e}),t&&this.emit(`update`,{editor:this,transaction:this.state.tr,appendedTransactions:[]})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get view(){return this.editorView?this.editorView:new Proxy({state:this.editorState,updateState:e=>{this.editorState=e},dispatch:e=>{this.dispatchTransaction(e)},composing:!1,dragging:null,editable:!0,isDestroyed:!1},{get:(e,t)=>{if(this.editorView)return this.editorView[t];if(t===`state`)return this.editorState;if(t in e)return Reflect.get(e,t);throw Error(`[tiptap error]: The editor view is not available. Cannot access view['${t}']. The editor may not be mounted yet.`)}})}get state(){return this.editorView&&(this.editorState=this.view.state),this.editorState}registerPlugin(e,t){let n=Pu(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}unregisterPlugin(e){if(this.isDestroyed)return;let t=this.state.plugins,n=t;if([].concat(e).forEach(e=>{let t=typeof e==`string`?`${e}$`:e.key;n=n.filter(e=>!e.key.startsWith(t))}),t.length===n.length)return;let r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}createExtensionManager(){this.extensionManager=new uf([...this.options.enableCoreExtensions?[hf,df.configure({blockSeparator:this.options.coreExtensionOptions?.clipboardTextSerializer?.blockSeparator}),ff,_f,vf,bf,mf,yf,pf,xf.configure({direction:this.options.textDirection})].filter(e=>typeof this.options.enableCoreExtensions==`object`?this.options.enableCoreExtensions[e.name]!==!1:!0):[],...this.options.extensions].filter(e=>[`extension`,`node`,`mark`].includes(e?.type)),this)}createCommandManager(){this.commandManager=new ml({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createDoc(){let e;try{e=wu(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(t){if(!(t instanceof Error)||![`[tiptap error]: Invalid JSON content`,`[tiptap error]: Invalid HTML content`].includes(t.message))throw t;this.emit(`contentError`,{editor:this,error:t,disableCollaboration:()=>{`collaboration`in this.storage&&typeof this.storage.collaboration==`object`&&this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(e=>e.name!==`collaboration`),this.createExtensionManager()}}),e=wu(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1})}return e}createView(e){let{editorProps:t,enableExtensionDispatchTransaction:n}=this.options,r=t.dispatchTransaction||this.dispatchTransaction.bind(this),i=n?this.extensionManager.dispatchTransaction(r):r,a=t.transformPastedHTML,o=this.extensionManager.transformPastedHTML(a);this.editorView=new Uc(e,{...t,attributes:{role:`textbox`,...t?.attributes},dispatchTransaction:i,transformPastedHTML:o,state:this.editorState,markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews});let s=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(s),this.prependClass(),this.injectCSS();let c=this.view.dom;c.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`${this.className} ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;let t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=e;return}e.steps.forEach(e=>this.capturedTransaction?.step(e));return}let{state:t,transactions:n}=this.state.applyTransaction(e),r=!this.state.selection.eq(t.selection),i=n.includes(e),a=this.state;if(this.emit(`beforeTransaction`,{editor:this,transaction:e,nextState:t}),!i)return;this.view.updateState(t),this.emit(`transaction`,{editor:this,transaction:e,appendedTransactions:n.slice(1)}),r&&this.emit(`selectionUpdate`,{editor:this,transaction:e});let o=n.findLast(e=>e.getMeta(`focus`)||e.getMeta(`blur`)),s=o?.getMeta(`focus`),c=o?.getMeta(`blur`);s&&this.emit(`focus`,{editor:this,event:s.event,transaction:o}),c&&this.emit(`blur`,{editor:this,event:c.event,transaction:o}),!(e.getMeta(`preventUpdate`)||!n.some(e=>e.docChanged)||a.doc.eq(t.doc))&&this.emit(`update`,{editor:this,transaction:e,appendedTransactions:n.slice(1)})}getAttributes(e){return nd(this.state,e)}isActive(e,t){let n=typeof e==`string`?e:null,r=typeof e==`string`?t:e;return fd(this.state,n,r)}getJSON(){return this.state.doc.toJSON()}getHTML(){return Nu(this.state.doc.content,this.schema)}getText(e){let{blockSeparator:t=`
127
+ }`;function wf(e,t,n){let r=document.querySelector(`style[data-tiptap-style${n?`-${n}`:``}]`);if(r!==null)return r;let i=document.createElement(`style`);return t&&i.setAttribute(`nonce`,t),i.setAttribute(`data-tiptap-style${n?`-${n}`:``}`,``),i.innerHTML=e,document.getElementsByTagName(`head`)[0].appendChild(i),i}var Tf=class extends Kd{constructor(e={}){super(),this.css=null,this.className=`tiptap`,this.editorView=null,this.isFocused=!1,this.isInitialized=!1,this.extensionStorage={},this.instanceId=Math.random().toString(36).slice(2,9),this.options={element:typeof document<`u`?document.createElement(`div`):null,content:``,injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,textDirection:void 0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onMount:()=>null,onUnmount:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:e})=>{throw e},onPaste:()=>null,onDrop:()=>null,onDelete:()=>null,enableExtensionDispatchTransaction:!0},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.utils={getUpdatedPosition:bd,createMappablePosition:xd},this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on(`beforeCreate`,this.options.onBeforeCreate),this.emit(`beforeCreate`,{editor:this}),this.on(`mount`,this.options.onMount),this.on(`unmount`,this.options.onUnmount),this.on(`contentError`,this.options.onContentError),this.on(`create`,this.options.onCreate),this.on(`update`,this.options.onUpdate),this.on(`selectionUpdate`,this.options.onSelectionUpdate),this.on(`transaction`,this.options.onTransaction),this.on(`focus`,this.options.onFocus),this.on(`blur`,this.options.onBlur),this.on(`destroy`,this.options.onDestroy),this.on(`drop`,({event:e,slice:t,moved:n})=>this.options.onDrop(e,t,n)),this.on(`paste`,({event:e,slice:t})=>this.options.onPaste(e,t)),this.on(`delete`,this.options.onDelete);let t=this.createDoc(),n=Rl(t,this.options.autofocus);this.editorState=Ar.create({doc:t,schema:this.schema,selection:n||void 0}),this.options.element&&this.mount(this.options.element)}mount(e){if(typeof document>`u`)throw Error(`[tiptap error]: The editor cannot be mounted because there is no 'document' defined in this environment.`);this.createView(e),this.emit(`mount`,{editor:this}),this.css&&!document.head.contains(this.css)&&document.head.appendChild(this.css),window.setTimeout(()=>{this.isDestroyed||(this.options.autofocus!==!1&&this.options.autofocus!==null&&this.commands.focus(this.options.autofocus),this.emit(`create`,{editor:this}),this.isInitialized=!0)},0)}unmount(){if(this.editorView){let e=this.editorView.dom;e?.editor&&delete e.editor,this.editorView.destroy()}if(this.editorView=null,this.isInitialized=!1,this.css&&!document.querySelectorAll(`.${this.className}`).length)try{typeof this.css.remove==`function`?this.css.remove():this.css.parentNode&&this.css.parentNode.removeChild(this.css)}catch(e){console.warn(`Failed to remove CSS element:`,e)}this.css=null,this.emit(`unmount`,{editor:this})}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager.chain()}can(){return this.commandManager.can()}injectCSS(){this.options.injectCSS&&typeof document<`u`&&(this.css=wf(Cf,this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},!(!this.editorView||!this.state||this.isDestroyed)&&(this.options.editorProps&&this.view.setProps(this.options.editorProps),this.view.updateState(this.state))}setEditable(e,t=!0){this.setOptions({editable:e}),t&&this.emit(`update`,{editor:this,transaction:this.state.tr,appendedTransactions:[]})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get view(){return this.editorView?this.editorView:new Proxy({state:this.editorState,updateState:e=>{this.editorState=e},dispatch:e=>{this.dispatchTransaction(e)},composing:!1,dragging:null,editable:!0,isDestroyed:!1},{get:(e,t)=>{if(this.editorView)return this.editorView[t];if(t===`state`)return this.editorState;if(t in e)return Reflect.get(e,t);throw Error(`[tiptap error]: The editor view is not available. Cannot access view['${t}']. The editor may not be mounted yet.`)}})}get state(){return this.editorView&&(this.editorState=this.view.state),this.editorState}registerPlugin(e,t){let n=Nu(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}unregisterPlugin(e){if(this.isDestroyed)return;let t=this.state.plugins,n=t;if([].concat(e).forEach(e=>{let t=typeof e==`string`?`${e}$`:e.key;n=n.filter(e=>!e.key.startsWith(t))}),t.length===n.length)return;let r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}createExtensionManager(){this.extensionManager=new uf([...this.options.enableCoreExtensions?[hf,df.configure({blockSeparator:this.options.coreExtensionOptions?.clipboardTextSerializer?.blockSeparator}),ff,_f,vf,bf,mf,yf,pf,xf.configure({direction:this.options.textDirection})].filter(e=>typeof this.options.enableCoreExtensions==`object`?this.options.enableCoreExtensions[e.name]!==!1:!0):[],...this.options.extensions].filter(e=>[`extension`,`node`,`mark`].includes(e?.type)),this)}createCommandManager(){this.commandManager=new pl({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createDoc(){let e;try{e=Cu(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(t){if(!(t instanceof Error)||![`[tiptap error]: Invalid JSON content`,`[tiptap error]: Invalid HTML content`].includes(t.message))throw t;this.emit(`contentError`,{editor:this,error:t,disableCollaboration:()=>{`collaboration`in this.storage&&typeof this.storage.collaboration==`object`&&this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(e=>e.name!==`collaboration`),this.createExtensionManager()}}),e=Cu(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1})}return e}createView(e){let{editorProps:t,enableExtensionDispatchTransaction:n}=this.options,r=t.dispatchTransaction||this.dispatchTransaction.bind(this),i=n?this.extensionManager.dispatchTransaction(r):r,a=t.transformPastedHTML,o=this.extensionManager.transformPastedHTML(a);this.editorView=new Hc(e,{...t,attributes:{role:`textbox`,...t?.attributes},dispatchTransaction:i,transformPastedHTML:o,state:this.editorState,markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews});let s=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(s),this.prependClass(),this.injectCSS();let c=this.view.dom;c.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`${this.className} ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;let t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=e;return}e.steps.forEach(e=>this.capturedTransaction?.step(e));return}let{state:t,transactions:n}=this.state.applyTransaction(e),r=!this.state.selection.eq(t.selection),i=n.includes(e),a=this.state;if(this.emit(`beforeTransaction`,{editor:this,transaction:e,nextState:t}),!i)return;this.view.updateState(t),this.emit(`transaction`,{editor:this,transaction:e,appendedTransactions:n.slice(1)}),r&&this.emit(`selectionUpdate`,{editor:this,transaction:e});let o=n.findLast(e=>e.getMeta(`focus`)||e.getMeta(`blur`)),s=o?.getMeta(`focus`),c=o?.getMeta(`blur`);s&&this.emit(`focus`,{editor:this,event:s.event,transaction:o}),c&&this.emit(`blur`,{editor:this,event:c.event,transaction:o}),!(e.getMeta(`preventUpdate`)||!n.some(e=>e.docChanged)||a.doc.eq(t.doc))&&this.emit(`update`,{editor:this,transaction:e,appendedTransactions:n.slice(1)})}getAttributes(e){return nd(this.state,e)}isActive(e,t){let n=typeof e==`string`?e:null,r=typeof e==`string`?t:e;return fd(this.state,n,r)}getJSON(){return this.state.doc.toJSON()}getHTML(){return Mu(this.state.doc.content,this.schema)}getText(e){let{blockSeparator:t=`
128
128
 
129
- `,textSerializers:n={}}=e||{};return $u(this.state.doc,{blockSeparator:t,textSerializers:{...ed(this.schema),...n}})}get isEmpty(){return _d(this.state.doc)}destroy(){this.emit(`destroy`),this.unmount(),this.removeAllListeners()}get isDestroyed(){return this.editorView?.isDestroyed??!0}$node(e,t){return this.$doc?.querySelector(e,t)||null}$nodes(e,t){return this.$doc?.querySelectorAll(e,t)||null}$pos(e){return new Sf(this.state.doc.resolve(e),this)}get $doc(){return this.$pos(0)}};function Ef(e){return new qd({find:e.find,handler:({state:t,range:n,match:r})=>{let i=M(e.getAttributes,void 0,r);if(i===!1||i===null)return null;let{tr:a}=t,o=r[r.length-1],s=r[0];if(o){let r=s.search(/\S/),c=n.from+s.indexOf(o),l=c+o.length;if(od(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>c).length)return null;l<n.to&&a.delete(l,n.to),c>n.from&&a.delete(n.from+r,c);let u=n.from+r+o.length;a.addMark(n.from+r,u,e.type.create(i||{})),a.removeStoredMark(e.type)}},undoable:e.undoable})}function Df(e){return new qd({find:e.find,handler:({state:t,range:n,match:r})=>{let i=M(e.getAttributes,void 0,r)||{},{tr:a}=t,o=n.from,s=n.to,c=e.type.create(i);if(r[1]){let e=o+r[0].lastIndexOf(r[1]);e>s?e=s:s=e+r[1].length;let t=r[0][r[0].length-1];a.insertText(t,o+r[0].length-1),a.replaceWith(e,s,c)}else if(r[0]){let t=e.type.isInline?o:o-1;a.insert(t,e.type.create(i)).delete(a.mapping.map(o),a.mapping.map(s))}a.scrollIntoView()},undoable:e.undoable})}function Of(e){return new qd({find:e.find,handler:({state:t,range:n,match:r})=>{let i=t.doc.resolve(n.from),a=M(e.getAttributes,void 0,r)||{};if(!i.node(-1).canReplaceWith(i.index(-1),i.indexAfter(-1),e.type))return null;t.tr.delete(n.from,n.to).setBlockType(n.from,n.from,e.type,a)},undoable:e.undoable})}function kf(e){return new qd({find:e.find,handler:({state:t,range:n,match:r,chain:i})=>{let a=M(e.getAttributes,void 0,r)||{},o=t.tr.delete(n.from,n.to),s=o.doc.resolve(n.from).blockRange(),c=s&&On(s,e.type,a);if(!c)return null;if(o.wrap(s,c),e.keepMarks&&e.editor){let{selection:n,storedMarks:r}=t,{splittableMarks:i}=e.editor.extensionManager,a=r||n.$to.parentOffset&&n.$from.marks();if(a){let e=a.filter(e=>i.includes(e.type.name));o.ensureMarks(e)}}if(e.keepAttributes){let t=e.type.name===`bulletList`||e.type.name===`orderedList`?`listItem`:`taskList`;i().updateAttributes(t,a).run()}let l=o.doc.resolve(n.from-1).nodeBefore;l&&l.type===e.type&&Bn(o.doc,n.from-1)&&(!e.joinPredicate||e.joinPredicate(r,l))&&o.join(n.from-1)},undoable:e.undoable})}function Af(e,t){let{selection:n}=e,{$from:r}=n;if(n instanceof A){let e=r.index();return r.parent.canReplaceWith(e,e+1,t)}let i=r.depth;for(;i>=0;){let e=r.index(i);if(r.node(i).contentMatchAt(e).matchType(t))return!0;--i}return!1}function jf(e){return e.replace(/[-/\\^$*+?.()|[\]{}]/g,`\\$&`)}function Mf(e){return e.replace(/&lt;/g,`<`).replace(/&gt;/g,`>`).replace(/&quot;/g,`"`).replace(/&amp;/g,`&`)}function Nf(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}fl({},{createAtomBlockMarkdownSpec:()=>If,createBlockMarkdownSpec:()=>Lf,createInlineMarkdownSpec:()=>Bf,parseAttributes:()=>Pf,parseIndentedBlocks:()=>Vf,renderNestedMarkdownContent:()=>Hf,serializeAttributes:()=>Ff});function Pf(e){if(!e?.trim())return{};let t={},n=[],r=e.replace(/["']([^"']*)["']/g,e=>(n.push(e),`__QUOTED_${n.length-1}__`)),i=r.match(/(?:^|\s)\.([a-zA-Z][\w-]*)/g);i&&(t.class=i.map(e=>e.trim().slice(1)).join(` `));let a=r.match(/(?:^|\s)#([a-zA-Z][\w-]*)/);a&&(t.id=a[1]),Array.from(r.matchAll(/([a-zA-Z][\w-]*)\s*=\s*(__QUOTED_\d+__)/g)).forEach(([,e,r])=>{let i=n[parseInt(r.match(/__QUOTED_(\d+)__/)?.[1]||`0`,10)];i&&(t[e]=i.slice(1,-1))});let o=r.replace(/(?:^|\s)\.([a-zA-Z][\w-]*)/g,``).replace(/(?:^|\s)#([a-zA-Z][\w-]*)/g,``).replace(/([a-zA-Z][\w-]*)\s*=\s*__QUOTED_\d+__/g,``).trim();return o&&o.split(/\s+/).filter(Boolean).forEach(e=>{e.match(/^[a-zA-Z][\w-]*$/)&&(t[e]=!0)}),t}function Ff(e){if(!e||Object.keys(e).length===0)return``;let t=[];return e.class&&String(e.class).split(/\s+/).filter(Boolean).forEach(e=>t.push(`.${e}`)),e.id&&t.push(`#${e.id}`),Object.entries(e).forEach(([e,n])=>{e===`class`||e===`id`||(n===!0?t.push(e):n!==!1&&n!=null&&t.push(`${e}="${String(n)}"`))}),t.join(` `)}function If(e){let{nodeName:t,name:n,parseAttributes:r=Pf,serializeAttributes:i=Ff,defaultAttributes:a={},requiredAttributes:o=[],allowedAttributes:s}=e,c=n||t,l=e=>{if(!s)return e;let t={};return s.forEach(n=>{n in e&&(t[n]=e[n])}),t};return{parseMarkdown:(e,n)=>{let r={...a,...e.attributes};return n.createNode(t,r,[])},markdownTokenizer:{name:t,level:`block`,start(e){let t=RegExp(`^:::${c}(?:\\s|$)`,`m`),n=e.match(t)?.index;return n===void 0?-1:n},tokenize(e,n,i){let a=RegExp(`^:::${c}(?:\\s+\\{([^}]*)\\})?\\s*:::(?:\\n|$)`),s=e.match(a);if(!s)return;let l=r(s[1]||``);if(!o.find(e=>!(e in l)))return{type:t,raw:s[0],attributes:l}}},renderMarkdown:e=>{let t=i(l(e.attrs||{}));return`:::${c}${t?` {${t}}`:``} :::`}}}function Lf(e){let{nodeName:t,name:n,getContent:r,parseAttributes:i=Pf,serializeAttributes:a=Ff,defaultAttributes:o={},content:s=`block`,allowedAttributes:c}=e,l=n||t,u=e=>{if(!c)return e;let t={};return c.forEach(n=>{n in e&&(t[n]=e[n])}),t};return{parseMarkdown:(e,n)=>{let i;if(r){let t=r(e);i=typeof t==`string`?[{type:`text`,text:t}]:t}else i=s===`block`?n.parseChildren(e.tokens||[]):n.parseInline(e.tokens||[]);let a={...o,...e.attributes};return n.createNode(t,a,i)},markdownTokenizer:{name:t,level:`block`,start(e){let t=RegExp(`^:::${l}`,`m`),n=e.match(t)?.index;return n===void 0?-1:n},tokenize(e,n,r){let a=RegExp(`^:::${l}(?:\\s+\\{([^}]*)\\})?\\s*\\n`),o=e.match(a);if(!o)return;let[c,u=``]=o,d=i(u),f=1,p=c.length,m=``,h=/^:::([\w-]*)(\s.*)?/gm,g=e.slice(p);for(h.lastIndex=0;;){let n=h.exec(g);if(n===null)break;let i=n.index,a=n[1];if(!n[2]?.endsWith(`:::`)){if(a)f+=1;else if(--f,f===0){let a=g.slice(0,i);m=a.trim();let o=e.slice(0,p+i+n[0].length),c=[];if(m)if(s===`block`)for(c=r.blockTokens(a),c.forEach(e=>{e.text&&(!e.tokens||e.tokens.length===0)&&(e.tokens=r.inlineTokens(e.text))});c.length>0;){let e=c[c.length-1];if(e.type===`paragraph`&&(!e.text||e.text.trim()===``))c.pop();else break}else c=r.inlineTokens(m);return{type:t,raw:o,attributes:d,content:m,tokens:c}}}}}},renderMarkdown:(e,t)=>{let n=a(u(e.attrs||{}));return`:::${l}${n?` {${n}}`:``}
129
+ `,textSerializers:n={}}=e||{};return $u(this.state.doc,{blockSeparator:t,textSerializers:{...ed(this.schema),...n}})}get isEmpty(){return _d(this.state.doc)}destroy(){this.emit(`destroy`),this.unmount(),this.removeAllListeners()}get isDestroyed(){return this.editorView?.isDestroyed??!0}$node(e,t){return this.$doc?.querySelector(e,t)||null}$nodes(e,t){return this.$doc?.querySelectorAll(e,t)||null}$pos(e){return new Sf(this.state.doc.resolve(e),this)}get $doc(){return this.$pos(0)}};function Ef(e){return new qd({find:e.find,handler:({state:t,range:n,match:r})=>{let i=Pu(e.getAttributes,void 0,r);if(i===!1||i===null)return null;let{tr:a}=t,o=r[r.length-1],s=r[0];if(o){let r=s.search(/\S/),c=n.from+s.indexOf(o),l=c+o.length;if(od(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>c).length)return null;l<n.to&&a.delete(l,n.to),c>n.from&&a.delete(n.from+r,c);let u=n.from+r+o.length;a.addMark(n.from+r,u,e.type.create(i||{})),a.removeStoredMark(e.type)}},undoable:e.undoable})}function Df(e){return new qd({find:e.find,handler:({state:t,range:n,match:r})=>{let i=Pu(e.getAttributes,void 0,r)||{},{tr:a}=t,o=n.from,s=n.to,c=e.type.create(i);if(r[1]){let e=o+r[0].lastIndexOf(r[1]);e>s?e=s:s=e+r[1].length;let t=r[0][r[0].length-1];a.insertText(t,o+r[0].length-1),a.replaceWith(e,s,c)}else if(r[0]){let t=e.type.isInline?o:o-1;a.insert(t,e.type.create(i)).delete(a.mapping.map(o),a.mapping.map(s))}a.scrollIntoView()},undoable:e.undoable})}function Of(e){return new qd({find:e.find,handler:({state:t,range:n,match:r})=>{let i=t.doc.resolve(n.from),a=Pu(e.getAttributes,void 0,r)||{};if(!i.node(-1).canReplaceWith(i.index(-1),i.indexAfter(-1),e.type))return null;t.tr.delete(n.from,n.to).setBlockType(n.from,n.from,e.type,a)},undoable:e.undoable})}function kf(e){return new qd({find:e.find,handler:({state:t,range:n,match:r,chain:i})=>{let a=Pu(e.getAttributes,void 0,r)||{},o=t.tr.delete(n.from,n.to),s=o.doc.resolve(n.from).blockRange(),c=s&&On(s,e.type,a);if(!c)return null;if(o.wrap(s,c),e.keepMarks&&e.editor){let{selection:n,storedMarks:r}=t,{splittableMarks:i}=e.editor.extensionManager,a=r||n.$to.parentOffset&&n.$from.marks();if(a){let e=a.filter(e=>i.includes(e.type.name));o.ensureMarks(e)}}if(e.keepAttributes){let t=e.type.name===`bulletList`||e.type.name===`orderedList`?`listItem`:`taskList`;i().updateAttributes(t,a).run()}let l=o.doc.resolve(n.from-1).nodeBefore;l&&l.type===e.type&&Bn(o.doc,n.from-1)&&(!e.joinPredicate||e.joinPredicate(r,l))&&o.join(n.from-1)},undoable:e.undoable})}function Af(e,t){let{selection:n}=e,{$from:r}=n;if(n instanceof A){let e=r.index();return r.parent.canReplaceWith(e,e+1,t)}let i=r.depth;for(;i>=0;){let e=r.index(i);if(r.node(i).contentMatchAt(e).matchType(t))return!0;--i}return!1}function jf(e){return e.replace(/[-/\\^$*+?.()|[\]{}]/g,`\\$&`)}function Mf(e){return e.replace(/&lt;/g,`<`).replace(/&gt;/g,`>`).replace(/&quot;/g,`"`).replace(/&amp;/g,`&`)}function Nf(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}dl({},{createAtomBlockMarkdownSpec:()=>If,createBlockMarkdownSpec:()=>Lf,createInlineMarkdownSpec:()=>Bf,parseAttributes:()=>Pf,parseIndentedBlocks:()=>Vf,renderNestedMarkdownContent:()=>Hf,serializeAttributes:()=>Ff});function Pf(e){if(!e?.trim())return{};let t={},n=[],r=e.replace(/["']([^"']*)["']/g,e=>(n.push(e),`__QUOTED_${n.length-1}__`)),i=r.match(/(?:^|\s)\.([a-zA-Z][\w-]*)/g);i&&(t.class=i.map(e=>e.trim().slice(1)).join(` `));let a=r.match(/(?:^|\s)#([a-zA-Z][\w-]*)/);a&&(t.id=a[1]),Array.from(r.matchAll(/([a-zA-Z][\w-]*)\s*=\s*(__QUOTED_\d+__)/g)).forEach(([,e,r])=>{let i=n[parseInt(r.match(/__QUOTED_(\d+)__/)?.[1]||`0`,10)];i&&(t[e]=i.slice(1,-1))});let o=r.replace(/(?:^|\s)\.([a-zA-Z][\w-]*)/g,``).replace(/(?:^|\s)#([a-zA-Z][\w-]*)/g,``).replace(/([a-zA-Z][\w-]*)\s*=\s*__QUOTED_\d+__/g,``).trim();return o&&o.split(/\s+/).filter(Boolean).forEach(e=>{e.match(/^[a-zA-Z][\w-]*$/)&&(t[e]=!0)}),t}function Ff(e){if(!e||Object.keys(e).length===0)return``;let t=[];return e.class&&String(e.class).split(/\s+/).filter(Boolean).forEach(e=>t.push(`.${e}`)),e.id&&t.push(`#${e.id}`),Object.entries(e).forEach(([e,n])=>{e===`class`||e===`id`||(n===!0?t.push(e):n!==!1&&n!=null&&t.push(`${e}="${String(n)}"`))}),t.join(` `)}function If(e){let{nodeName:t,name:n,parseAttributes:r=Pf,serializeAttributes:i=Ff,defaultAttributes:a={},requiredAttributes:o=[],allowedAttributes:s}=e,c=n||t,l=e=>{if(!s)return e;let t={};return s.forEach(n=>{n in e&&(t[n]=e[n])}),t};return{parseMarkdown:(e,n)=>{let r={...a,...e.attributes};return n.createNode(t,r,[])},markdownTokenizer:{name:t,level:`block`,start(e){let t=RegExp(`^:::${c}(?:\\s|$)`,`m`),n=e.match(t)?.index;return n===void 0?-1:n},tokenize(e,n,i){let a=RegExp(`^:::${c}(?:\\s+\\{([^}]*)\\})?\\s*:::(?:\\n|$)`),s=e.match(a);if(!s)return;let l=r(s[1]||``);if(!o.find(e=>!(e in l)))return{type:t,raw:s[0],attributes:l}}},renderMarkdown:e=>{let t=i(l(e.attrs||{}));return`:::${c}${t?` {${t}}`:``} :::`}}}function Lf(e){let{nodeName:t,name:n,getContent:r,parseAttributes:i=Pf,serializeAttributes:a=Ff,defaultAttributes:o={},content:s=`block`,allowedAttributes:c}=e,l=n||t,u=e=>{if(!c)return e;let t={};return c.forEach(n=>{n in e&&(t[n]=e[n])}),t};return{parseMarkdown:(e,n)=>{let i;if(r){let t=r(e);i=typeof t==`string`?[{type:`text`,text:t}]:t}else i=s===`block`?n.parseChildren(e.tokens||[]):n.parseInline(e.tokens||[]);let a={...o,...e.attributes};return n.createNode(t,a,i)},markdownTokenizer:{name:t,level:`block`,start(e){let t=RegExp(`^:::${l}`,`m`),n=e.match(t)?.index;return n===void 0?-1:n},tokenize(e,n,r){let a=RegExp(`^:::${l}(?:\\s+\\{([^}]*)\\})?\\s*\\n`),o=e.match(a);if(!o)return;let[c,u=``]=o,d=i(u),f=1,p=c.length,m=``,h=/^:::([\w-]*)(\s.*)?/gm,g=e.slice(p);for(h.lastIndex=0;;){let n=h.exec(g);if(n===null)break;let i=n.index,a=n[1];if(!n[2]?.endsWith(`:::`)){if(a)f+=1;else if(--f,f===0){let a=g.slice(0,i);m=a.trim();let o=e.slice(0,p+i+n[0].length),c=[];if(m)if(s===`block`)for(c=r.blockTokens(a),c.forEach(e=>{e.text&&(!e.tokens||e.tokens.length===0)&&(e.tokens=r.inlineTokens(e.text))});c.length>0;){let e=c[c.length-1];if(e.type===`paragraph`&&(!e.text||e.text.trim()===``))c.pop();else break}else c=r.inlineTokens(m);return{type:t,raw:o,attributes:d,content:m,tokens:c}}}}}},renderMarkdown:(e,t)=>{let n=a(u(e.attrs||{}));return`:::${l}${n?` {${n}}`:``}
130
130
 
131
131
  ${t.renderChildren(e.content||[],`
132
132
 
@@ -143,7 +143,7 @@ ${t.renderChildren(e.content||[],`
143
143
  `);s+=e.type===`paragraph`?`
144
144
 
145
145
  ${n}`:`
146
- ${n}`}}),s}function Uf(e,t,n={}){let{state:r}=t,{doc:i,tr:a}=r,o=e;i.descendants((t,r)=>{let i=a.mapping.map(r),s=a.mapping.map(r)+t.nodeSize,c=null;if(t.marks.forEach(e=>{if(e!==o)return!1;c=e}),!c)return;let l=!1;if(Object.keys(n).forEach(e=>{n[e]!==c.attrs[e]&&(l=!0)}),l){let t=e.type.create({...e.attrs,...n});a.removeMark(i,s,e.type),a.addMark(i,s,t)}}),a.docChanged&&t.view.dispatch(a)}var Wf=class e extends ef{constructor(){super(...arguments),this.type=`node`}static create(t={}){return new e(typeof t==`function`?t():t)}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}};function Gf(e){return new rf({find:e.find,handler:({state:t,range:n,match:r,pasteEvent:i})=>{let a=M(e.getAttributes,void 0,r,i);if(a===!1||a===null)return null;let{tr:o}=t,s=r[r.length-1],c=r[0],l=n.to;if(s){let r=c.search(/\S/),i=n.from+c.indexOf(s),u=i+s.length;if(od(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>i).length)return null;u<n.to&&o.delete(u,n.to),i>n.from&&o.delete(n.from+r,i),l=n.from+r+s.length,o.addMark(n.from+r,l,e.type.create(a||{})),o.removeStoredMark(e.type)}}})}function Kf(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var qf=Kf();function Jf(e){qf=e}var Yf={exec:()=>null};function P(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(Zf.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var Xf=(()=>{try{return!0}catch{return!1}})(),Zf={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,`i`),blockquoteBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}>`)},Qf=/^(?:[ \t]*(?:\n|$))+/,$f=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,ep=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,tp=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,np=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,rp=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,ip=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,ap=P(ip).replace(/bull/g,rp).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),op=P(ip).replace(/bull/g,rp).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),sp=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,cp=/^[^\n]+/,lp=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,up=P(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,lp).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),dp=P(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,rp).getRegex(),fp=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,pp=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,mp=P(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,pp).replace(`tag`,fp).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),hp=P(sp).replace(`hr`,tp).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,fp).getRegex(),gp={blockquote:P(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,hp).getRegex(),code:$f,def:up,fences:ep,heading:np,hr:tp,html:mp,lheading:ap,list:dp,newline:Qf,paragraph:hp,table:Yf,text:cp},_p=P(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,tp).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,fp).getRegex(),vp={...gp,lheading:op,table:_p,paragraph:P(sp).replace(`hr`,tp).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,_p).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,fp).getRegex()},yp={...gp,html:P(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,pp).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Yf,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:P(sp).replace(`hr`,tp).replace(`heading`,` *#{1,6} *[^
146
+ ${n}`}}),s}function Uf(e,t,n={}){let{state:r}=t,{doc:i,tr:a}=r,o=e;i.descendants((t,r)=>{let i=a.mapping.map(r),s=a.mapping.map(r)+t.nodeSize,c=null;if(t.marks.forEach(e=>{if(e!==o)return!1;c=e}),!c)return;let l=!1;if(Object.keys(n).forEach(e=>{n[e]!==c.attrs[e]&&(l=!0)}),l){let t=e.type.create({...e.attrs,...n});a.removeMark(i,s,e.type),a.addMark(i,s,t)}}),a.docChanged&&t.view.dispatch(a)}var Wf=class e extends ef{constructor(){super(...arguments),this.type=`node`}static create(t={}){return new e(typeof t==`function`?t():t)}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}};function Gf(e){return new rf({find:e.find,handler:({state:t,range:n,match:r,pasteEvent:i})=>{let a=Pu(e.getAttributes,void 0,r,i);if(a===!1||a===null)return null;let{tr:o}=t,s=r[r.length-1],c=r[0],l=n.to;if(s){let r=c.search(/\S/),i=n.from+c.indexOf(s),u=i+s.length;if(od(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>i).length)return null;u<n.to&&o.delete(u,n.to),i>n.from&&o.delete(n.from+r,i),l=n.from+r+s.length,o.addMark(n.from+r,l,e.type.create(a||{})),o.removeStoredMark(e.type)}}})}function Kf(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var qf=Kf();function Jf(e){qf=e}var Yf={exec:()=>null};function P(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(Zf.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var Xf=(()=>{try{return!0}catch{return!1}})(),Zf={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,`i`),blockquoteBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}>`)},Qf=/^(?:[ \t]*(?:\n|$))+/,$f=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,ep=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,tp=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,np=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,rp=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,ip=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,ap=P(ip).replace(/bull/g,rp).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),op=P(ip).replace(/bull/g,rp).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),sp=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,cp=/^[^\n]+/,lp=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,up=P(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,lp).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),dp=P(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,rp).getRegex(),fp=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,pp=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,mp=P(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,pp).replace(`tag`,fp).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),hp=P(sp).replace(`hr`,tp).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,fp).getRegex(),gp={blockquote:P(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,hp).getRegex(),code:$f,def:up,fences:ep,heading:np,hr:tp,html:mp,lheading:ap,list:dp,newline:Qf,paragraph:hp,table:Yf,text:cp},_p=P(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,tp).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,fp).getRegex(),vp={...gp,lheading:op,table:_p,paragraph:P(sp).replace(`hr`,tp).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,_p).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,fp).getRegex()},yp={...gp,html:P(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,pp).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Yf,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:P(sp).replace(`hr`,tp).replace(`heading`,` *#{1,6} *[^
147
147
  ]`).replace(`lheading`,ap).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},bp=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,xp=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Sp=/^( {2,}|\\)\n(?!\s*$)/,Cp=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,wp=/[\p{P}\p{S}]/u,Tp=/[\s\p{P}\p{S}]/u,Ep=/[^\s\p{P}\p{S}]/u,Dp=P(/^((?![*_])punctSpace)/,`u`).replace(/punctSpace/g,Tp).getRegex(),Op=/(?!~)[\p{P}\p{S}]/u,kp=/(?!~)[\s\p{P}\p{S}]/u,Ap=/(?:[^\s\p{P}\p{S}]|~)/u,jp=/(?![*_])[\p{P}\p{S}]/u,Mp=/(?![*_])[\s\p{P}\p{S}]/u,Np=/(?:[^\s\p{P}\p{S}]|[*_])/u,Pp=P(/link|precode-code|html/,`g`).replace(`link`,/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace(`precode-`,Xf?"(?<!`)()":"(^^|[^`])").replace(`code`,/(?<b>`+)[^`]+\k<b>(?!`)/).replace(`html`,/<(?! )[^<>]*?>/).getRegex(),Fp=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,Ip=P(Fp,`u`).replace(/punct/g,wp).getRegex(),Lp=P(Fp,`u`).replace(/punct/g,Op).getRegex(),Rp=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,zp=P(Rp,`gu`).replace(/notPunctSpace/g,Ep).replace(/punctSpace/g,Tp).replace(/punct/g,wp).getRegex(),Bp=P(Rp,`gu`).replace(/notPunctSpace/g,Ap).replace(/punctSpace/g,kp).replace(/punct/g,Op).getRegex(),Vp=P(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,Ep).replace(/punctSpace/g,Tp).replace(/punct/g,wp).getRegex(),Hp=P(/^~~?(?:((?!~)punct)|[^\s~])/,`u`).replace(/punct/g,jp).getRegex(),Up=P(`^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,Np).replace(/punctSpace/g,Mp).replace(/punct/g,jp).getRegex(),Wp=P(/\\(punct)/,`gu`).replace(/punct/g,wp).getRegex(),Gp=P(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace(`scheme`,/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace(`email`,/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Kp=P(pp).replace(`(?:-->|$)`,`-->`).getRegex(),qp=P(`^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>`).replace(`comment`,Kp).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Jp=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,Yp=P(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace(`label`,Jp).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace(`title`,/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Xp=P(/^!?\[(label)\]\[(ref)\]/).replace(`label`,Jp).replace(`ref`,lp).getRegex(),Zp=P(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,lp).getRegex(),Qp=P(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,Xp).replace(`nolink`,Zp).getRegex(),$p=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,em={_backpedal:Yf,anyPunctuation:Wp,autolink:Gp,blockSkip:Pp,br:Sp,code:xp,del:Yf,delLDelim:Yf,delRDelim:Yf,emStrongLDelim:Ip,emStrongRDelimAst:zp,emStrongRDelimUnd:Vp,escape:bp,link:Yp,nolink:Zp,punctuation:Dp,reflink:Xp,reflinkSearch:Qp,tag:qp,text:Cp,url:Yf},tm={...em,link:P(/^!?\[(label)\]\((.*?)\)/).replace(`label`,Jp).getRegex(),reflink:P(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,Jp).getRegex()},nm={...em,emStrongRDelimAst:Bp,emStrongLDelim:Lp,delLDelim:Hp,delRDelim:Up,url:P(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace(`protocol`,$p).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:P(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace(`protocol`,$p).getRegex()},rm={...nm,br:P(Sp).replace(`{2,}`,`*`).getRegex(),text:P(nm.text).replace(`\\b_`,`\\b_| {2,}\\n`).replace(/\{2,\}/g,`*`).getRegex()},im={normal:gp,gfm:vp,pedantic:yp},am={normal:em,gfm:nm,breaks:rm,pedantic:tm},om={"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`},sm=e=>om[e];function cm(e,t){if(t){if(Zf.escapeTest.test(e))return e.replace(Zf.escapeReplace,sm)}else if(Zf.escapeTestNoEncode.test(e))return e.replace(Zf.escapeReplaceNoEncode,sm);return e}function lm(e){try{e=encodeURI(e).replace(Zf.percentDecode,`%`)}catch{return null}return e}function um(e,t){let n=e.replace(Zf.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(Zf.splitPipe),r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push(``);for(;r<n.length;r++)n[r]=n[r].trim().replace(Zf.slashPipe,`|`);return n}function dm(e,t,n){let r=e.length;if(r===0)return``;let i=0;for(;i<r;){let a=e.charAt(r-i-1);if(a===t&&!n)i++;else if(a!==t&&n)i++;else break}return e.slice(0,r-i)}function fm(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let r=0;r<e.length;r++)if(e[r]===`\\`)r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}function pm(e,t=0){let n=t,r=``;for(let t of e)if(t===` `){let e=4-n%4;r+=` `.repeat(e),n+=e}else r+=t,n++;return r}function mm(e,t,n,r,i){let a=t.href,o=t.title||null,s=e[1].replace(i.other.outputLinkReplace,`$1`);r.state.inLink=!0;let c={type:e[0].charAt(0)===`!`?`image`:`link`,raw:n,href:a,title:o,text:s,tokens:r.inlineTokens(s)};return r.state.inLink=!1,c}function hm(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(`
148
148
  `).map(e=>{let t=e.match(n.other.beginningSpace);if(t===null)return e;let[r]=t;return r.length>=i.length?e.slice(i.length):e}).join(`
149
149
  `)}var gm=class{options;rules;lexer;constructor(e){this.options=e||qf}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:`space`,raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let e=t[0].replace(this.rules.other.codeRemoveIndent,``);return{type:`code`,raw:t[0],codeBlockStyle:`indented`,text:this.options.pedantic?e:dm(e,`
@@ -203,12 +203,12 @@ ${e}</tr>
203
203
  `}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${cm(e,!0)}</code>`}br(e){return`<br>`}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),i=lm(e);if(i===null)return r;e=i;let a=`<a href="`+e+`"`;return t&&(a+=` title="`+cm(t)+`"`),a+=`>`+r+`</a>`,a}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=lm(e);if(i===null)return cm(n);e=i;let a=`<img src="${e}" alt="${cm(n)}"`;return t&&(a+=` title="${cm(t)}"`),a+=`>`,a}text(e){return`tokens`in e&&e.tokens?this.parser.parseInline(e.tokens):`escaped`in e&&e.escaped?e.text:cm(e.text)}},ym=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return``+e}image({text:e}){return``+e}br(){return``}checkbox({raw:e}){return e}},bm=class e{options;renderer;textRenderer;constructor(e){this.options=e||qf,this.options.renderer=this.options.renderer||new vm,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new ym}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n];if(this.options.extensions?.renderers?.[r.type]){let e=r,n=this.options.extensions.renderers[e.type].call({parser:this},e);if(n!==!1||![`space`,`hr`,`heading`,`code`,`table`,`blockquote`,`list`,`html`,`def`,`paragraph`,`text`].includes(e.type)){t+=n||``;continue}}let i=r;switch(i.type){case`space`:t+=this.renderer.space(i);break;case`hr`:t+=this.renderer.hr(i);break;case`heading`:t+=this.renderer.heading(i);break;case`code`:t+=this.renderer.code(i);break;case`table`:t+=this.renderer.table(i);break;case`blockquote`:t+=this.renderer.blockquote(i);break;case`list`:t+=this.renderer.list(i);break;case`checkbox`:t+=this.renderer.checkbox(i);break;case`html`:t+=this.renderer.html(i);break;case`def`:t+=this.renderer.def(i);break;case`paragraph`:t+=this.renderer.paragraph(i);break;case`text`:t+=this.renderer.text(i);break;default:{let e=`Token with "`+i.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return t}parseInline(e,t=this.renderer){let n=``;for(let r=0;r<e.length;r++){let i=e[r];if(this.options.extensions?.renderers?.[i.type]){let e=this.options.extensions.renderers[i.type].call({parser:this},i);if(e!==!1||![`escape`,`html`,`link`,`image`,`strong`,`em`,`codespan`,`br`,`del`,`text`].includes(i.type)){n+=e||``;continue}}let a=i;switch(a.type){case`escape`:n+=t.text(a);break;case`html`:n+=t.html(a);break;case`link`:n+=t.link(a);break;case`image`:n+=t.image(a);break;case`checkbox`:n+=t.checkbox(a);break;case`strong`:n+=t.strong(a);break;case`em`:n+=t.em(a);break;case`codespan`:n+=t.codespan(a);break;case`br`:n+=t.br(a);break;case`del`:n+=t.del(a);break;case`text`:n+=t.text(a);break;default:{let e=`Token with "`+a.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return n}},xm=class{options;block;constructor(e){this.options=e||qf}static passThroughHooks=new Set([`preprocess`,`postprocess`,`processAllTokens`,`emStrongMask`]);static passThroughHooksRespectAsync=new Set([`preprocess`,`postprocess`,`processAllTokens`]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(){return this.block?_m.lex:_m.lexInline}provideParser(){return this.block?bm.parse:bm.parseInline}},Sm=new class{defaults=Kf();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=bm;Renderer=vm;TextRenderer=ym;Lexer=_m;Tokenizer=gm;Hooks=xm;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch(n=n.concat(t.call(this,r)),r.type){case`table`:{let e=r;for(let r of e.header)n=n.concat(this.walkTokens(r.tokens,t));for(let r of e.rows)for(let e of r)n=n.concat(this.walkTokens(e.tokens,t));break}case`list`:{let e=r;n=n.concat(this.walkTokens(e.items,t));break}default:{let e=r;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach(r=>{let i=e[r].flat(1/0);n=n.concat(this.walkTokens(i,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach(e=>{if(!e.name)throw Error(`extension name required`);if(`renderer`in e){let n=t.renderers[e.name];n?t.renderers[e.name]=function(...t){let r=e.renderer.apply(this,t);return r===!1&&(r=n.apply(this,t)),r}:t.renderers[e.name]=e.renderer}if(`tokenizer`in e){if(!e.level||e.level!==`block`&&e.level!==`inline`)throw Error(`extension level must be 'block' or 'inline'`);let n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&(e.level===`block`?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:e.level===`inline`&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}`childTokens`in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)}),n.extensions=t),e.renderer){let t=this.defaults.renderer||new vm(this.defaults);for(let n in e.renderer){if(!(n in t))throw Error(`renderer '${n}' does not exist`);if([`options`,`parser`].includes(n))continue;let r=n,i=e.renderer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n||``}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new gm(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw Error(`tokenizer '${n}' does not exist`);if([`options`,`rules`,`lexer`].includes(n))continue;let r=n,i=e.tokenizer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new xm;for(let n in e.hooks){if(!(n in t))throw Error(`hook '${n}' does not exist`);if([`options`,`block`].includes(n))continue;let r=n,i=e.hooks[r],a=t[r];xm.passThroughHooks.has(n)?t[r]=e=>{if(this.defaults.async&&xm.passThroughHooksRespectAsync.has(n))return(async()=>{let n=await i.call(t,e);return a.call(t,n)})();let r=i.call(t,e);return a.call(t,r)}:t[r]=(...e)=>{if(this.defaults.async)return(async()=>{let n=await i.apply(t,e);return n===!1&&(n=await a.apply(t,e)),n})();let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return _m.lex(e,t??this.defaults)}parser(e,t){return bm.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},i={...this.defaults,...r},a=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return a(Error(`marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.`));if(typeof t>`u`||t===null)return a(Error(`marked(): input parameter is undefined or null`));if(typeof t!=`string`)return a(Error(`marked(): input parameter is of type `+Object.prototype.toString.call(t)+`, string expected`));if(i.hooks&&(i.hooks.options=i,i.hooks.block=e),i.async)return(async()=>{let n=i.hooks?await i.hooks.preprocess(t):t,r=await(i.hooks?await i.hooks.provideLexer():e?_m.lex:_m.lexInline)(n,i),a=i.hooks?await i.hooks.processAllTokens(r):r;i.walkTokens&&await Promise.all(this.walkTokens(a,i.walkTokens));let o=await(i.hooks?await i.hooks.provideParser():e?bm.parse:bm.parseInline)(a,i);return i.hooks?await i.hooks.postprocess(o):o})().catch(a);try{i.hooks&&(t=i.hooks.preprocess(t));let n=(i.hooks?i.hooks.provideLexer():e?_m.lex:_m.lexInline)(t,i);i.hooks&&(n=i.hooks.processAllTokens(n)),i.walkTokens&&this.walkTokens(n,i.walkTokens);let r=(i.hooks?i.hooks.provideParser():e?bm.parse:bm.parseInline)(n,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(e){return a(e)}}}onError(e,t){return n=>{if(n.message+=`
204
204
  Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error occurred:</p><pre>`+cm(n.message+``,!0)+`</pre>`;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function Cm(e,t){return Sm.parse(e,t)}Cm.options=Cm.setOptions=function(e){return Sm.setOptions(e),Cm.defaults=Sm.defaults,Jf(Cm.defaults),Cm},Cm.getDefaults=Kf,Cm.defaults=qf,Cm.use=function(...e){return Sm.use(...e),Cm.defaults=Sm.defaults,Jf(Cm.defaults),Cm},Cm.walkTokens=function(e,t){return Sm.walkTokens(e,t)},Cm.parseInline=Sm.parseInline,Cm.Parser=bm,Cm.parser=bm.parse,Cm.Renderer=vm,Cm.TextRenderer=ym,Cm.Lexer=_m,Cm.lexer=_m.lex,Cm.Tokenizer=gm,Cm.Hooks=xm,Cm.parse=Cm,Cm.options,Cm.setOptions,Cm.use,Cm.walkTokens,Cm.parseInline,bm.parse,_m.lex;function wm(e,t){let n=t.split(`
205
205
  `).flatMap(e=>[e,``]).map(t=>`${e}${t}`).join(`
206
- `);return n.slice(0,n.length-1)}function Tm(e,t){let n=[];return Array.from(e.keys()).forEach(e=>{(!t||!t.marks||!t.marks.map(e=>e.type).includes(e))&&n.push(e)}),n}function Em(e,t){let n=[];return Array.from(t.entries()).forEach(([t,r])=>{e.has(t)||n.push({type:t,mark:r})}),n}function Dm(e,t,n,r){let i=!n,a=n&&n.type===`text`&&(!n.marks||n.marks.length===0),o=n&&n.type===`text`&&n.marks&&!r(t,new Map(n.marks.map(e=>[e.type,e]))),s=[];if(i||a||o)if(n&&n.type===`text`&&n.marks){let t=new Map(n.marks.map(e=>[e.type,e]));Array.from(e.keys()).reverse().forEach(e=>{t.has(e)||s.push(e)})}else (i||a)&&s.push(...Array.from(e.keys()).reverse());return s}function Om(e,t){let n=``;return Array.from(e.keys()).reverse().forEach(r=>{let i=t(r,e.get(r));i&&(n=i+n)}),e.clear(),n}function km(e,t,n){let r=``;return Array.from(e.entries()).forEach(([e,i])=>{let a=n(e,i);a&&(r+=a),t.set(e,i)}),r}function Am(e){let t=(e.raw||e.text||``).match(/^(\s*)[-+*]\s+\[([ xX])\]\s+/);return t?{isTask:!0,checked:t[2].toLowerCase()===`x`,indentLevel:t[1].length}:{isTask:!1,indentLevel:0}}function jm(e,t){return typeof e==`string`?t:`json`}var Mm=class{constructor(e){this.activeParseLexer=null,this.baseExtensions=[],this.extensions=[],this.codeTypes=new Set,this.lastParseResult=null,this.markedInstance=e?.marked??Cm,this.indentStyle=e?.indentation?.style??`space`,this.indentSize=e?.indentation?.size??2,this.baseExtensions=e?.extensions||[],e?.markedOptions&&typeof this.markedInstance.setOptions==`function`&&this.markedInstance.setOptions(e.markedOptions),this.registry=new Map,this.nodeTypeRegistry=new Map,e?.extensions&&(this.baseExtensions=e.extensions,Mu(e.extensions).forEach(e=>this.registerExtension(e)))}get instance(){return this.markedInstance}get indentCharacter(){return this.indentStyle===`space`?` `:` `}get indentString(){return this.indentCharacter.repeat(this.indentSize)}hasMarked(){return!!this.markedInstance}registerExtension(e){this.extensions.push(e);let t=M(j(e,`code`)),n=e.name;t&&this.codeTypes.add(n);let r=j(e,`markdownTokenName`)||n,i=j(e,`parseMarkdown`),a=j(e,`renderMarkdown`),o=j(e,`markdownTokenizer`),s=j(e,`markdownOptions`)??null,c={tokenName:r,nodeName:n,parseMarkdown:i,renderMarkdown:a,isIndenting:s?.indentsContent??!1,htmlReopen:s?.htmlReopen,tokenizer:o};if(r&&i){let e=this.registry.get(r)||[];e.push(c),this.registry.set(r,e)}if(a){let e=this.nodeTypeRegistry.get(n)||[];e.push(c),this.nodeTypeRegistry.set(n,e)}o&&this.hasMarked()&&this.registerTokenizer(o)}createLexer(){return new this.markedInstance.Lexer}createTokenizerHelpers(e){return{inlineTokens:t=>e.inlineTokens(t),blockTokens:t=>e.blockTokens(t)}}tokenizeInline(e){return(this.activeParseLexer??this.createLexer()).inlineTokens(e)}registerTokenizer(e){if(!this.hasMarked())return;let{name:t,start:n,level:r=`inline`,tokenize:i}=e,a=this.createTokenizerHelpers.bind(this),o=this.createLexer.bind(this),s;s=n?typeof n==`function`?n:e=>e.indexOf(n):e=>{let t=i(e,[],this.createTokenizerHelpers(this.createLexer()));return t&&t.raw?e.indexOf(t.raw):-1};let c={name:t,level:r,start:s,tokenizer(e,n){let r=i(e,n,this.lexer?a(this.lexer):a(o()));if(r&&r.type)return{...r,type:r.type||t,raw:r.raw||``,tokens:r.tokens||[]}},childTokens:[]};this.markedInstance.use({extensions:[c]})}getHandlersForToken(e){try{return this.registry.get(e)||[]}catch{return[]}}getHandlerForToken(e){let t=this.getHandlersForToken(e);if(t.length>0)return t[0];let n=this.getHandlersForNodeType(e);return n.length>0?n[0]:void 0}getHandlersForNodeType(e){try{return this.nodeTypeRegistry.get(e)||[]}catch{return[]}}serialize(e){if(!e)return``;let t=this.renderNodes(e,e);return this.isEmptyOutput(t)?``:t}isEmptyOutput(e){return!e||e.trim()===``?!0:e.replace(/&nbsp;/g,``).replace(/\u00A0/g,``).trim()===``}parse(e){if(!this.hasMarked())throw Error(`No marked instance available for parsing`);let t=this.activeParseLexer,n=this.createLexer();this.activeParseLexer=n;try{let t=n.lex(e);return{type:`doc`,content:this.parseTokens(t,!0)}}finally{this.activeParseLexer=t}}parseTokens(e,t=!1){let n=e.reduce((e,t,n)=>(t.type!==`space`&&e.push(n),e),[]),r=-1,i=0;return e.flatMap((e,a)=>{for(;i<n.length&&n[i]<a;)r=n[i],i+=1;if(t&&e.type===`space`){let t=n[i]??-1;return this.createImplicitEmptyParagraphsFromSpace(e,r,t)}let o=this.parseToken(e,t);return o===null?[]:Array.isArray(o)?o:[o]})}createImplicitEmptyParagraphsFromSpace(e,t,n){let r=this.countParagraphSeparators(e.raw||``);if(r===0)return[];let i=t===-1||n===-1,a=Math.max(r-(i?0:1),0);return Array.from({length:a},()=>({type:`paragraph`,content:[]}))}countParagraphSeparators(e){return(e.replace(/\r\n/g,`
206
+ `);return n.slice(0,n.length-1)}function Tm(e,t){let n=[];return Array.from(e.keys()).forEach(e=>{(!t||!t.marks||!t.marks.map(e=>e.type).includes(e))&&n.push(e)}),n}function Em(e,t){let n=[];return Array.from(t.entries()).forEach(([t,r])=>{e.has(t)||n.push({type:t,mark:r})}),n}function Dm(e,t,n,r){let i=!n,a=n&&n.type===`text`&&(!n.marks||n.marks.length===0),o=n&&n.type===`text`&&n.marks&&!r(t,new Map(n.marks.map(e=>[e.type,e]))),s=[];if(i||a||o)if(n&&n.type===`text`&&n.marks){let t=new Map(n.marks.map(e=>[e.type,e]));Array.from(e.keys()).reverse().forEach(e=>{t.has(e)||s.push(e)})}else (i||a)&&s.push(...Array.from(e.keys()).reverse());return s}function Om(e,t){let n=``;return Array.from(e.keys()).reverse().forEach(r=>{let i=t(r,e.get(r));i&&(n=i+n)}),e.clear(),n}function km(e,t,n){let r=``;return Array.from(e.entries()).forEach(([e,i])=>{let a=n(e,i);a&&(r+=a),t.set(e,i)}),r}function Am(e){let t=(e.raw||e.text||``).match(/^(\s*)[-+*]\s+\[([ xX])\]\s+/);return t?{isTask:!0,checked:t[2].toLowerCase()===`x`,indentLevel:t[1].length}:{isTask:!1,indentLevel:0}}function jm(e,t){return typeof e==`string`?t:`json`}var Mm=class{constructor(e){this.activeParseLexer=null,this.baseExtensions=[],this.extensions=[],this.codeTypes=new Set,this.lastParseResult=null,this.markedInstance=e?.marked??Cm,this.indentStyle=e?.indentation?.style??`space`,this.indentSize=e?.indentation?.size??2,this.baseExtensions=e?.extensions||[],e?.markedOptions&&typeof this.markedInstance.setOptions==`function`&&this.markedInstance.setOptions(e.markedOptions),this.registry=new Map,this.nodeTypeRegistry=new Map,e?.extensions&&(this.baseExtensions=e.extensions,ju(e.extensions).forEach(e=>this.registerExtension(e)))}get instance(){return this.markedInstance}get indentCharacter(){return this.indentStyle===`space`?` `:` `}get indentString(){return this.indentCharacter.repeat(this.indentSize)}hasMarked(){return!!this.markedInstance}registerExtension(e){this.extensions.push(e);let t=Pu(M(e,`code`)),n=e.name;t&&this.codeTypes.add(n);let r=M(e,`markdownTokenName`)||n,i=M(e,`parseMarkdown`),a=M(e,`renderMarkdown`),o=M(e,`markdownTokenizer`),s=M(e,`markdownOptions`)??null,c={tokenName:r,nodeName:n,parseMarkdown:i,renderMarkdown:a,isIndenting:s?.indentsContent??!1,htmlReopen:s?.htmlReopen,tokenizer:o};if(r&&i){let e=this.registry.get(r)||[];e.push(c),this.registry.set(r,e)}if(a){let e=this.nodeTypeRegistry.get(n)||[];e.push(c),this.nodeTypeRegistry.set(n,e)}o&&this.hasMarked()&&this.registerTokenizer(o)}createLexer(){return new this.markedInstance.Lexer}createTokenizerHelpers(e){return{inlineTokens:t=>e.inlineTokens(t),blockTokens:t=>e.blockTokens(t)}}tokenizeInline(e){return(this.activeParseLexer??this.createLexer()).inlineTokens(e)}registerTokenizer(e){if(!this.hasMarked())return;let{name:t,start:n,level:r=`inline`,tokenize:i}=e,a=this.createTokenizerHelpers.bind(this),o=this.createLexer.bind(this),s;s=n?typeof n==`function`?n:e=>e.indexOf(n):e=>{let t=i(e,[],this.createTokenizerHelpers(this.createLexer()));return t&&t.raw?e.indexOf(t.raw):-1};let c={name:t,level:r,start:s,tokenizer(e,n){let r=i(e,n,this.lexer?a(this.lexer):a(o()));if(r&&r.type)return{...r,type:r.type||t,raw:r.raw||``,tokens:r.tokens||[]}},childTokens:[]};this.markedInstance.use({extensions:[c]})}getHandlersForToken(e){try{return this.registry.get(e)||[]}catch{return[]}}getHandlerForToken(e){let t=this.getHandlersForToken(e);if(t.length>0)return t[0];let n=this.getHandlersForNodeType(e);return n.length>0?n[0]:void 0}getHandlersForNodeType(e){try{return this.nodeTypeRegistry.get(e)||[]}catch{return[]}}serialize(e){if(!e)return``;let t=this.renderNodes(e,e);return this.isEmptyOutput(t)?``:t}isEmptyOutput(e){return!e||e.trim()===``?!0:e.replace(/&nbsp;/g,``).replace(/\u00A0/g,``).trim()===``}parse(e){if(!this.hasMarked())throw Error(`No marked instance available for parsing`);let t=this.activeParseLexer,n=this.createLexer();this.activeParseLexer=n;try{let t=n.lex(e);return{type:`doc`,content:this.parseTokens(t,!0)}}finally{this.activeParseLexer=t}}parseTokens(e,t=!1){let n=e.reduce((e,t,n)=>(t.type!==`space`&&e.push(n),e),[]),r=-1,i=0;return e.flatMap((e,a)=>{for(;i<n.length&&n[i]<a;)r=n[i],i+=1;if(t&&e.type===`space`){let t=n[i]??-1;return this.createImplicitEmptyParagraphsFromSpace(e,r,t)}let o=this.parseToken(e,t);return o===null?[]:Array.isArray(o)?o:[o]})}createImplicitEmptyParagraphsFromSpace(e,t,n){let r=this.countParagraphSeparators(e.raw||``);if(r===0)return[];let i=t===-1||n===-1,a=Math.max(r-(i?0:1),0);return Array.from({length:a},()=>({type:`paragraph`,content:[]}))}countParagraphSeparators(e){return(e.replace(/\r\n/g,`
207
207
  `).match(/\n\n/g)||[]).length}parseToken(e,t=!1){if(!e.type)return null;if(e.type===`list`)return this.parseListToken(e);let n=this.getHandlersForToken(e.type),r=this.createParseHelpers();if(n.find(t=>{if(!t.parseMarkdown)return!1;let n=t.parseMarkdown(e,r),i=this.normalizeParseResult(n);return i&&(!Array.isArray(i)||i.length>0)?(this.lastParseResult=i,!0):!1})&&this.lastParseResult){let e=this.lastParseResult;return this.lastParseResult=null,e}return this.parseFallbackToken(e,t)}parseListToken(e){if(!e.items||e.items.length===0)return this.parseTokenWithHandlers(e);let t=e.items.some(e=>Am(e).isTask),n=e.items.some(e=>!Am(e).isTask);if(!t||!n||this.getHandlersForToken(`taskList`).length===0)return this.parseTokenWithHandlers(e);let r=[],i=[],a=null;for(let t=0;t<e.items.length;t+=1){let n=e.items[t],{isTask:o,checked:s,indentLevel:c}=Am(n),l=n;if(o){let e=(n.raw||n.text||``).split(`
208
208
  `),t=e[0].match(/^\s*[-+*]\s+\[([ xX])\]\s+(.*)$/),r=t?t[2]:``,i=[];if(e.length>1&&e.slice(1).join(`
209
209
  `).trim()){let t=e.slice(1),n=t.filter(e=>e.trim());if(n.length>0){let e=Math.min(...n.map(e=>e.length-e.trimStart().length)),r=t.map(t=>t.trim()?t.slice(e):``).join(`
210
210
  `).trim();r&&(i=this.markedInstance.lexer(`${r}
211
- `))}}l={type:`taskItem`,raw:``,mainContent:r,indentLevel:c,checked:s??!1,text:r,tokens:this.tokenizeInline(r),nestedTokens:i}}let u=o?`taskList`:`list`;a===u?i.push(l):(i.length>0&&r.push({type:a,items:i}),i=[l],a=u)}i.length>0&&r.push({type:a,items:i});let o=[];for(let t=0;t<r.length;t+=1){let n=r[t],i={...e,type:n.type,items:n.items},a=this.parseToken(i);a&&(Array.isArray(a)?o.push(...a):o.push(a))}return o.length>0?o:null}parseTokenWithHandlers(e){if(!e.type)return null;let t=this.getHandlersForToken(e.type),n=this.createParseHelpers();if(t.find(t=>{if(!t.parseMarkdown)return!1;let r=t.parseMarkdown(e,n),i=this.normalizeParseResult(r);return i&&(!Array.isArray(i)||i.length>0)?(this.lastParseResult=i,!0):!1})&&this.lastParseResult){let e=this.lastParseResult;return this.lastParseResult=null,e}return this.parseFallbackToken(e)}createParseHelpers(){return{parseInline:e=>this.parseInlineTokens(e),parseChildren:e=>this.parseTokens(e),parseBlockChildren:e=>this.parseTokens(e,!0),createTextNode:(e,t)=>({type:`text`,text:e,marks:t||void 0}),createNode:(e,t,n)=>{let r={type:e,attrs:t||void 0,content:n||void 0};return(!t||Object.keys(t).length===0)&&delete r.attrs,r},applyMark:(e,t,n)=>({mark:e,content:t,attrs:n&&Object.keys(n).length>0?n:void 0})}}escapeRegex(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}parseInlineTokens(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e[n];if(r.type===`text`)t.push({type:`text`,text:Mf(r.text||``)});else if(r.type===`html`){let i=(r.raw??r.text??``).toString(),a=/^<\/[\s]*[\w-]+/i.test(i),o=i.match(/^<[\s]*([\w-]+)(\s|>|\/|$)/i);if(!a&&o&&!/\/>$/.test(i)){let r=o[1],a=this.escapeRegex(r),s=RegExp(`^<\\/\\s*${a}\\b`,`i`),c=-1,l=[i];for(let t=n+1;t<e.length;t+=1){let n=e[t],r=(n.raw??n.text??``).toString();if(l.push(r),n.type===`html`&&s.test(r)){c=t;break}}if(c!==-1){let e=l.join(``),r={type:`html`,raw:e,text:e,block:!1},i=this.parseHTMLToken(r);if(i){let e=this.normalizeParseResult(i);Array.isArray(e)?t.push(...e):e&&t.push(e)}n=c;continue}}let s=this.parseHTMLToken(r);if(s){let e=this.normalizeParseResult(s);Array.isArray(e)?t.push(...e):e&&t.push(e)}}else if(r.type){let e=this.getHandlerForToken(r.type);if(e&&e.parseMarkdown){let n=this.createParseHelpers(),i=e.parseMarkdown(r,n);if(this.isMarkResult(i)){let e=this.applyMarkToContent(i.mark,i.content,i.attrs);t.push(...e)}else{let e=this.normalizeParseResult(i);Array.isArray(e)?t.push(...e):e&&t.push(e)}}else r.tokens&&t.push(...this.parseInlineTokens(r.tokens))}}return t}applyMarkToContent(e,t,n){return t.map(t=>{if(t.type===`text`){let r=t.marks||[],i=n?{type:e,attrs:n}:{type:e};return{...t,marks:[...r,i]}}return{...t,content:t.content?this.applyMarkToContent(e,t.content,n):void 0}})}isMarkResult(e){return e&&typeof e==`object`&&`mark`in e}normalizeParseResult(e){return e?this.isMarkResult(e)?e.content:e:null}parseFallbackToken(e,t=!1){switch(e.type){case`paragraph`:return{type:`paragraph`,content:e.tokens?this.parseInlineTokens(e.tokens):[]};case`heading`:return{type:`heading`,attrs:{level:e.depth||1},content:e.tokens?this.parseInlineTokens(e.tokens):[]};case`text`:return{type:`text`,text:Mf(e.text||``)};case`html`:return this.parseHTMLToken(e);case`space`:return null;default:return e.tokens?this.parseTokens(e.tokens,t):null}}parseHTMLToken(e){let t=e.text||e.raw||``;if(!t.trim())return null;if(typeof window>`u`)return e.block?{type:`paragraph`,content:[{type:`text`,text:t}]}:{type:`text`,text:t};try{let n=Zu(t,this.baseExtensions);return n.type===`doc`&&n.content?e.block?n.content:n.content.length===1&&n.content[0].type===`paragraph`&&n.content[0].content?n.content[0].content:n.content:n}catch(e){throw Error(`Failed to parse HTML in markdown: ${e}`)}}encodeTextForMarkdown(e,t,n){return n?.type!=null&&this.codeTypes.has(n.type)||(t.marks||[]).some(e=>this.codeTypes.has(typeof e==`string`?e:e.type))?e:Nf(e)}renderNodeToMarkdown(e,t,n=0,r=0,i={}){if(e.type===`text`)return this.encodeTextForMarkdown(e.text||``,e,t);if(!e.type)return``;let a=this.getHandlerForToken(e.type);if(!a)return``;let o=Array.isArray(t?.content)&&n>0?t.content[n-1]:void 0,s={renderChildren:(t,i)=>{let o=a.isIndenting?r+1:r;return!Array.isArray(t)&&t.content?this.renderNodes(t.content,e,i||``,n,o):this.renderNodes(t,e,i||``,n,o)},renderChild:(t,n)=>{let i=a.isIndenting?r+1:r;return this.renderNodeToMarkdown(t,e,n,i)},indent:e=>this.indentString+e,wrapInBlock:wm},c={index:n,level:r,parentType:t?.type,previousNode:o,meta:{parentAttrs:t?.attrs,...i}};return a.renderMarkdown?.call(a,e,s,c)||``}renderNodes(e,t,n=``,r=0,i=0){return Array.isArray(e)?this.renderNodesWithMarkBoundaries(e,t,n,i):e.type?this.renderNodeToMarkdown(e,t,r,i):``}renderNodesWithMarkBoundaries(e,t,n=``,r=0){let i=[],a=new Map,o=new Set,s=new Map;return e.forEach((n,c)=>{let l=c<e.length-1?e[c+1]:null;if(n.type)if(n.type===`text`){let e=this.encodeTextForMarkdown(n.text||``,n,t),r=new Map((n.marks||[]).map(e=>[e.type,e])),c=Em(a,r),u=Tm(r,l),d=u.filter(e=>a.has(e)),f=d.length>0&&c.length>0,p=``;if(u.length>0&&!f){let t=e.match(/(\s+)$/);t&&(p=t[1],e=e.slice(0,-p.length))}f||u.forEach(t=>{if(!a.has(t))return;let n=r.get(t),i=this.getMarkClosing(t,n,s.get(t));i&&(e+=i),a.has(t)&&(a.delete(t),s.delete(t))});let m=``;if(c.length>0){let t=e.match(/^(\s+)/);t&&(m=t[1],e=e.slice(m.length))}c.forEach(({type:t,mark:n})=>{let r=o.has(t)?`html`:`markdown`,i=this.getMarkOpening(t,n,r);i&&(e=i+e),s.set(t,r),o.delete(t)}),f||c.slice().reverse().forEach(({type:e,mark:t})=>{a.set(e,t)}),e=m+e;let h;if(f){let e=new Set((l?.marks||[]).map(e=>e.type));c.forEach(({type:t})=>{e.has(t)&&this.getHtmlReopenTags(t)&&o.add(t)}),h=[...c.map(e=>e.type),...d]}else h=Dm(a,r,l,this.markSetsEqual.bind(this));let g=``;if(h.length>0){let t=e.match(/(\s+)$/);t&&(g=t[1],e=e.slice(0,-g.length))}h.forEach(t=>{let n=a.get(t)??r.get(t),i=this.getMarkClosing(t,n,s.get(t));i&&(e+=i),a.delete(t),s.delete(t)}),e+=g,e+=p,i.push(e)}else{let e=new Map(a),o=new Map(s),l=Om(a,(e,t)=>this.getMarkClosing(e,t,s.get(e)));s.clear();let u=this.renderNodeToMarkdown(n,t,c,r),d=n.type===`hardBreak`?``:km(e,a,(e,t)=>{let n=o.get(e)??`markdown`;return s.set(e,n),this.getMarkOpening(e,t,n)});i.push(l+u+d)}}),i.join(n)}getMarkOpening(e,t,n=`markdown`){if(n===`html`)return this.getHtmlReopenTags(e)?.open||``;let r=this.getHandlersForNodeType(e),i=r.length>0?r[0]:void 0;if(!i||!i.renderMarkdown)return``;let a=`__TIPTAP_MARKDOWN_PLACEHOLDER__`,o={type:e,attrs:t.attrs||{},content:[{type:`text`,text:a}]};try{let e=i.renderMarkdown(o,{renderChildren:()=>a,renderChild:()=>a,indent:e=>e,wrapInBlock:(e,t)=>e+t},{index:0,level:0,parentType:`text`,meta:{}}),t=e.indexOf(a);return t>=0?e.substring(0,t):``}catch(t){throw Error(`Failed to get mark opening for ${e}: ${t}`)}}getMarkClosing(e,t,n=`markdown`){if(n===`html`)return this.getHtmlReopenTags(e)?.close||``;let r=this.getHandlersForNodeType(e),i=r.length>0?r[0]:void 0;if(!i||!i.renderMarkdown)return``;let a=`__TIPTAP_MARKDOWN_PLACEHOLDER__`,o={type:e,attrs:t.attrs||{},content:[{type:`text`,text:a}]};try{let e=i.renderMarkdown(o,{renderChildren:()=>a,renderChild:()=>a,indent:e=>e,wrapInBlock:(e,t)=>e+t},{index:0,level:0,parentType:`text`,meta:{}}),t=e.indexOf(a),n=t+33;return t>=0?e.substring(n):``}catch(t){throw Error(`Failed to get mark closing for ${e}: ${t}`)}}getHtmlReopenTags(e){let t=this.getHandlersForNodeType(e);return(t.length>0?t[0]:void 0)?.htmlReopen}markSetsEqual(e,t){return e.size===t.size?Array.from(e.keys()).every(e=>t.has(e)):!1}},Nm=Mm,Pm=N.create({name:`markdown`,addOptions(){return{indentation:{style:`space`,size:2},marked:void 0,markedOptions:{}}},addCommands(){return{setContent:(e,t)=>{if(!t?.contentType||jm(e,t?.contentType)!==`markdown`||!this.editor.markdown)return hl.setContent(e,t);let n=this.editor.markdown.parse(e);return hl.setContent(n,t)},insertContent:(e,t)=>{if(!t?.contentType||jm(e,t?.contentType)!==`markdown`||!this.editor.markdown)return hl.insertContent(e,t);let n=this.editor.markdown.parse(e);return hl.insertContent(n,t)},insertContentAt:(e,t,n)=>{if(!n?.contentType||jm(t,n?.contentType)!==`markdown`||!this.editor.markdown)return hl.insertContentAt(e,t,n);let r=this.editor.markdown.parse(t);return hl.insertContentAt(e,r,n)}}},addStorage(){return{manager:new Nm({indentation:this.options.indentation,marked:this.options.marked,markedOptions:this.options.markedOptions,extensions:[]})}},onBeforeCreate(){if(this.editor.markdown){console.error("[tiptap][markdown]: There is already a `markdown` property on the editor instance. This might lead to unexpected behavior.");return}if(this.storage.manager=new Nm({indentation:this.options.indentation,marked:this.options.marked,markedOptions:this.options.markedOptions,extensions:this.editor.extensionManager.baseExtensions}),this.editor.markdown=this.storage.manager,this.editor.getMarkdown=()=>this.storage.manager.serialize(this.editor.getJSON()),!this.editor.options.contentType||jm(this.editor.options.content,this.editor.options.contentType)!==`markdown`)return;if(!this.editor.markdown)throw Error('[tiptap][markdown]: The `contentType` option is set to "markdown", but the Markdown extension is not added to the editor. Please add the Markdown extension to use this feature.');if(this.editor.options.content===void 0||typeof this.editor.options.content!=`string`)throw Error('[tiptap][markdown]: The `contentType` option is set to "markdown", but the initial content is not a string. Please provide the initial content as a markdown string.');let e=this.editor.markdown.parse(this.editor.options.content);this.editor.options.content=e}}),Fm=4,Im=/^```([a-z]+)?[\s\n]$/,Lm=/^~~~([a-z]+)?[\s\n]$/,Rm=Wf.create({name:`codeBlock`,addOptions(){return{languageClassPrefix:`language-`,exitOnTripleEnter:!0,exitOnArrowDown:!0,defaultLanguage:null,enableTabIndentation:!1,tabSize:Fm,HTMLAttributes:{}}},content:`text*`,marks:``,group:`block`,code:!0,defining:!0,addAttributes(){return{language:{default:this.options.defaultLanguage,parseHTML:e=>{let{languageClassPrefix:t}=this.options;return t&&[...e.firstElementChild?.classList||[]].filter(e=>e.startsWith(t)).map(e=>e.replace(t,``))[0]||null},rendered:!1}}},parseHTML(){return[{tag:`pre`,preserveWhitespace:`full`}]},renderHTML({node:e,HTMLAttributes:t}){return[`pre`,Bu(this.options.HTMLAttributes,t),[`code`,{class:e.attrs.language?this.options.languageClassPrefix+e.attrs.language:null},0]]},markdownTokenName:`code`,parseMarkdown:(e,t)=>e.raw?.startsWith("```")===!1&&e.raw?.startsWith(`~~~`)===!1&&e.codeBlockStyle!==`indented`?[]:t.createNode(`codeBlock`,{language:e.lang||null},e.text?[t.createTextNode(e.text)]:[]),renderMarkdown:(e,t)=>{let n=``,r=e.attrs?.language||``;return n=e.content?[`\`\`\`${r}`,t.renderChildren(e.content),"```"].join(`
211
+ `))}}l={type:`taskItem`,raw:``,mainContent:r,indentLevel:c,checked:s??!1,text:r,tokens:this.tokenizeInline(r),nestedTokens:i}}let u=o?`taskList`:`list`;a===u?i.push(l):(i.length>0&&r.push({type:a,items:i}),i=[l],a=u)}i.length>0&&r.push({type:a,items:i});let o=[];for(let t=0;t<r.length;t+=1){let n=r[t],i={...e,type:n.type,items:n.items},a=this.parseToken(i);a&&(Array.isArray(a)?o.push(...a):o.push(a))}return o.length>0?o:null}parseTokenWithHandlers(e){if(!e.type)return null;let t=this.getHandlersForToken(e.type),n=this.createParseHelpers();if(t.find(t=>{if(!t.parseMarkdown)return!1;let r=t.parseMarkdown(e,n),i=this.normalizeParseResult(r);return i&&(!Array.isArray(i)||i.length>0)?(this.lastParseResult=i,!0):!1})&&this.lastParseResult){let e=this.lastParseResult;return this.lastParseResult=null,e}return this.parseFallbackToken(e)}createParseHelpers(){return{parseInline:e=>this.parseInlineTokens(e),parseChildren:e=>this.parseTokens(e),parseBlockChildren:e=>this.parseTokens(e,!0),createTextNode:(e,t)=>({type:`text`,text:e,marks:t||void 0}),createNode:(e,t,n)=>{let r={type:e,attrs:t||void 0,content:n||void 0};return(!t||Object.keys(t).length===0)&&delete r.attrs,r},applyMark:(e,t,n)=>({mark:e,content:t,attrs:n&&Object.keys(n).length>0?n:void 0})}}escapeRegex(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}parseInlineTokens(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e[n];if(r.type===`text`)t.push({type:`text`,text:Mf(r.text||``)});else if(r.type===`html`){let i=(r.raw??r.text??``).toString(),a=/^<\/[\s]*[\w-]+/i.test(i),o=i.match(/^<[\s]*([\w-]+)(\s|>|\/|$)/i);if(!a&&o&&!/\/>$/.test(i)){let r=o[1],a=this.escapeRegex(r),s=RegExp(`^<\\/\\s*${a}\\b`,`i`),c=-1,l=[i];for(let t=n+1;t<e.length;t+=1){let n=e[t],r=(n.raw??n.text??``).toString();if(l.push(r),n.type===`html`&&s.test(r)){c=t;break}}if(c!==-1){let e=l.join(``),r={type:`html`,raw:e,text:e,block:!1},i=this.parseHTMLToken(r);if(i){let e=this.normalizeParseResult(i);Array.isArray(e)?t.push(...e):e&&t.push(e)}n=c;continue}}let s=this.parseHTMLToken(r);if(s){let e=this.normalizeParseResult(s);Array.isArray(e)?t.push(...e):e&&t.push(e)}}else if(r.type){let e=this.getHandlerForToken(r.type);if(e&&e.parseMarkdown){let n=this.createParseHelpers(),i=e.parseMarkdown(r,n);if(this.isMarkResult(i)){let e=this.applyMarkToContent(i.mark,i.content,i.attrs);t.push(...e)}else{let e=this.normalizeParseResult(i);Array.isArray(e)?t.push(...e):e&&t.push(e)}}else r.tokens&&t.push(...this.parseInlineTokens(r.tokens))}}return t}applyMarkToContent(e,t,n){return t.map(t=>{if(t.type===`text`){let r=t.marks||[],i=n?{type:e,attrs:n}:{type:e};return{...t,marks:[...r,i]}}return{...t,content:t.content?this.applyMarkToContent(e,t.content,n):void 0}})}isMarkResult(e){return e&&typeof e==`object`&&`mark`in e}normalizeParseResult(e){return e?this.isMarkResult(e)?e.content:e:null}parseFallbackToken(e,t=!1){switch(e.type){case`paragraph`:return{type:`paragraph`,content:e.tokens?this.parseInlineTokens(e.tokens):[]};case`heading`:return{type:`heading`,attrs:{level:e.depth||1},content:e.tokens?this.parseInlineTokens(e.tokens):[]};case`text`:return{type:`text`,text:Mf(e.text||``)};case`html`:return this.parseHTMLToken(e);case`space`:return null;default:return e.tokens?this.parseTokens(e.tokens,t):null}}parseHTMLToken(e){let t=e.text||e.raw||``;if(!t.trim())return null;if(typeof window>`u`)return e.block?{type:`paragraph`,content:[{type:`text`,text:t}]}:{type:`text`,text:t};try{let n=Zu(t,this.baseExtensions);return n.type===`doc`&&n.content?e.block?n.content:n.content.length===1&&n.content[0].type===`paragraph`&&n.content[0].content?n.content[0].content:n.content:n}catch(e){throw Error(`Failed to parse HTML in markdown: ${e}`)}}encodeTextForMarkdown(e,t,n){return n?.type!=null&&this.codeTypes.has(n.type)||(t.marks||[]).some(e=>this.codeTypes.has(typeof e==`string`?e:e.type))?e:Nf(e)}renderNodeToMarkdown(e,t,n=0,r=0,i={}){if(e.type===`text`)return this.encodeTextForMarkdown(e.text||``,e,t);if(!e.type)return``;let a=this.getHandlerForToken(e.type);if(!a)return``;let o=Array.isArray(t?.content)&&n>0?t.content[n-1]:void 0,s={renderChildren:(t,i)=>{let o=a.isIndenting?r+1:r;return!Array.isArray(t)&&t.content?this.renderNodes(t.content,e,i||``,n,o):this.renderNodes(t,e,i||``,n,o)},renderChild:(t,n)=>{let i=a.isIndenting?r+1:r;return this.renderNodeToMarkdown(t,e,n,i)},indent:e=>this.indentString+e,wrapInBlock:wm},c={index:n,level:r,parentType:t?.type,previousNode:o,meta:{parentAttrs:t?.attrs,...i}};return a.renderMarkdown?.call(a,e,s,c)||``}renderNodes(e,t,n=``,r=0,i=0){return Array.isArray(e)?this.renderNodesWithMarkBoundaries(e,t,n,i):e.type?this.renderNodeToMarkdown(e,t,r,i):``}renderNodesWithMarkBoundaries(e,t,n=``,r=0){let i=[],a=new Map,o=new Set,s=new Map;return e.forEach((n,c)=>{let l=c<e.length-1?e[c+1]:null;if(n.type)if(n.type===`text`){let e=this.encodeTextForMarkdown(n.text||``,n,t),r=new Map((n.marks||[]).map(e=>[e.type,e])),c=Em(a,r),u=Tm(r,l),d=u.filter(e=>a.has(e)),f=d.length>0&&c.length>0,p=``;if(u.length>0&&!f){let t=e.match(/(\s+)$/);t&&(p=t[1],e=e.slice(0,-p.length))}f||u.forEach(t=>{if(!a.has(t))return;let n=r.get(t),i=this.getMarkClosing(t,n,s.get(t));i&&(e+=i),a.has(t)&&(a.delete(t),s.delete(t))});let m=``;if(c.length>0){let t=e.match(/^(\s+)/);t&&(m=t[1],e=e.slice(m.length))}c.forEach(({type:t,mark:n})=>{let r=o.has(t)?`html`:`markdown`,i=this.getMarkOpening(t,n,r);i&&(e=i+e),s.set(t,r),o.delete(t)}),f||c.slice().reverse().forEach(({type:e,mark:t})=>{a.set(e,t)}),e=m+e;let h;if(f){let e=new Set((l?.marks||[]).map(e=>e.type));c.forEach(({type:t})=>{e.has(t)&&this.getHtmlReopenTags(t)&&o.add(t)}),h=[...c.map(e=>e.type),...d]}else h=Dm(a,r,l,this.markSetsEqual.bind(this));let g=``;if(h.length>0){let t=e.match(/(\s+)$/);t&&(g=t[1],e=e.slice(0,-g.length))}h.forEach(t=>{let n=a.get(t)??r.get(t),i=this.getMarkClosing(t,n,s.get(t));i&&(e+=i),a.delete(t),s.delete(t)}),e+=g,e+=p,i.push(e)}else{let e=new Map(a),o=new Map(s),l=Om(a,(e,t)=>this.getMarkClosing(e,t,s.get(e)));s.clear();let u=this.renderNodeToMarkdown(n,t,c,r),d=n.type===`hardBreak`?``:km(e,a,(e,t)=>{let n=o.get(e)??`markdown`;return s.set(e,n),this.getMarkOpening(e,t,n)});i.push(l+u+d)}}),i.join(n)}getMarkOpening(e,t,n=`markdown`){if(n===`html`)return this.getHtmlReopenTags(e)?.open||``;let r=this.getHandlersForNodeType(e),i=r.length>0?r[0]:void 0;if(!i||!i.renderMarkdown)return``;let a=`__TIPTAP_MARKDOWN_PLACEHOLDER__`,o={type:e,attrs:t.attrs||{},content:[{type:`text`,text:a}]};try{let e=i.renderMarkdown(o,{renderChildren:()=>a,renderChild:()=>a,indent:e=>e,wrapInBlock:(e,t)=>e+t},{index:0,level:0,parentType:`text`,meta:{}}),t=e.indexOf(a);return t>=0?e.substring(0,t):``}catch(t){throw Error(`Failed to get mark opening for ${e}: ${t}`)}}getMarkClosing(e,t,n=`markdown`){if(n===`html`)return this.getHtmlReopenTags(e)?.close||``;let r=this.getHandlersForNodeType(e),i=r.length>0?r[0]:void 0;if(!i||!i.renderMarkdown)return``;let a=`__TIPTAP_MARKDOWN_PLACEHOLDER__`,o={type:e,attrs:t.attrs||{},content:[{type:`text`,text:a}]};try{let e=i.renderMarkdown(o,{renderChildren:()=>a,renderChild:()=>a,indent:e=>e,wrapInBlock:(e,t)=>e+t},{index:0,level:0,parentType:`text`,meta:{}}),t=e.indexOf(a),n=t+33;return t>=0?e.substring(n):``}catch(t){throw Error(`Failed to get mark closing for ${e}: ${t}`)}}getHtmlReopenTags(e){let t=this.getHandlersForNodeType(e);return(t.length>0?t[0]:void 0)?.htmlReopen}markSetsEqual(e,t){return e.size===t.size?Array.from(e.keys()).every(e=>t.has(e)):!1}},Nm=Mm,Pm=N.create({name:`markdown`,addOptions(){return{indentation:{style:`space`,size:2},marked:void 0,markedOptions:{}}},addCommands(){return{setContent:(e,t)=>{if(!t?.contentType||jm(e,t?.contentType)!==`markdown`||!this.editor.markdown)return ml.setContent(e,t);let n=this.editor.markdown.parse(e);return ml.setContent(n,t)},insertContent:(e,t)=>{if(!t?.contentType||jm(e,t?.contentType)!==`markdown`||!this.editor.markdown)return ml.insertContent(e,t);let n=this.editor.markdown.parse(e);return ml.insertContent(n,t)},insertContentAt:(e,t,n)=>{if(!n?.contentType||jm(t,n?.contentType)!==`markdown`||!this.editor.markdown)return ml.insertContentAt(e,t,n);let r=this.editor.markdown.parse(t);return ml.insertContentAt(e,r,n)}}},addStorage(){return{manager:new Nm({indentation:this.options.indentation,marked:this.options.marked,markedOptions:this.options.markedOptions,extensions:[]})}},onBeforeCreate(){if(this.editor.markdown){console.error("[tiptap][markdown]: There is already a `markdown` property on the editor instance. This might lead to unexpected behavior.");return}if(this.storage.manager=new Nm({indentation:this.options.indentation,marked:this.options.marked,markedOptions:this.options.markedOptions,extensions:this.editor.extensionManager.baseExtensions}),this.editor.markdown=this.storage.manager,this.editor.getMarkdown=()=>this.storage.manager.serialize(this.editor.getJSON()),!this.editor.options.contentType||jm(this.editor.options.content,this.editor.options.contentType)!==`markdown`)return;if(!this.editor.markdown)throw Error('[tiptap][markdown]: The `contentType` option is set to "markdown", but the Markdown extension is not added to the editor. Please add the Markdown extension to use this feature.');if(this.editor.options.content===void 0||typeof this.editor.options.content!=`string`)throw Error('[tiptap][markdown]: The `contentType` option is set to "markdown", but the initial content is not a string. Please provide the initial content as a markdown string.');let e=this.editor.markdown.parse(this.editor.options.content);this.editor.options.content=e}}),Fm=4,Im=/^```([a-z]+)?[\s\n]$/,Lm=/^~~~([a-z]+)?[\s\n]$/,Rm=Wf.create({name:`codeBlock`,addOptions(){return{languageClassPrefix:`language-`,exitOnTripleEnter:!0,exitOnArrowDown:!0,defaultLanguage:null,enableTabIndentation:!1,tabSize:Fm,HTMLAttributes:{}}},content:`text*`,marks:``,group:`block`,code:!0,defining:!0,addAttributes(){return{language:{default:this.options.defaultLanguage,parseHTML:e=>{let{languageClassPrefix:t}=this.options;return t&&[...e.firstElementChild?.classList||[]].filter(e=>e.startsWith(t)).map(e=>e.replace(t,``))[0]||null},rendered:!1}}},parseHTML(){return[{tag:`pre`,preserveWhitespace:`full`}]},renderHTML({node:e,HTMLAttributes:t}){return[`pre`,Bu(this.options.HTMLAttributes,t),[`code`,{class:e.attrs.language?this.options.languageClassPrefix+e.attrs.language:null},0]]},markdownTokenName:`code`,parseMarkdown:(e,t)=>e.raw?.startsWith("```")===!1&&e.raw?.startsWith(`~~~`)===!1&&e.codeBlockStyle!==`indented`?[]:t.createNode(`codeBlock`,{language:e.lang||null},e.text?[t.createTextNode(e.text)]:[]),renderMarkdown:(e,t)=>{let n=``,r=e.attrs?.language||``;return n=e.content?[`\`\`\`${r}`,t.renderChildren(e.content),"```"].join(`
212
212
  `):`\`\`\`${r}
213
213
 
214
214
  \`\`\``,n},addCommands(){return{setCodeBlock:e=>({commands:t})=>t.setNode(this.name,e),toggleCodeBlock:e=>({commands:t})=>t.toggleNode(this.name,`paragraph`,e)}},addKeyboardShortcuts(){return{"Mod-Alt-c":()=>this.editor.commands.toggleCodeBlock(),Backspace:()=>{let{empty:e,$anchor:t}=this.editor.state.selection,n=t.pos===1;return!e||t.parent.type.name!==this.name?!1:n||!t.parent.textContent.length?this.editor.commands.clearNodes():!1},Tab:({editor:e})=>{if(!this.options.enableTabIndentation)return!1;let t=this.options.tabSize??Fm,{state:n}=e,{selection:r}=n,{$from:i,empty:a}=r;if(i.parent.type!==this.type)return!1;let o=` `.repeat(t);return a?e.commands.insertContent(o):e.commands.command(({tr:e})=>{let{from:t,to:i}=r,a=n.doc.textBetween(t,i,`
@@ -224,7 +224,7 @@ Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error
224
224
  `).map(e=>{let n=e.match(/^ */)?.[0]||``,r=Math.min(n.length,t);return e.slice(r)}).join(`
225
225
  `);return e.replaceWith(i,a,n.schema.text(o)),!0}):!1},Enter:({editor:e})=>{if(!this.options.exitOnTripleEnter)return!1;let{state:t}=e,{selection:n}=t,{$from:r,empty:i}=n;if(!i||r.parent.type!==this.type)return!1;let a=r.parentOffset===r.parent.nodeSize-2,o=r.parent.textContent.endsWith(`
226
226
 
227
- `);return!a||!o?!1:e.chain().command(({tr:e})=>(e.delete(r.pos-2,r.pos),!0)).exitCode().run()},ArrowDown:({editor:e})=>{if(!this.options.exitOnArrowDown)return!1;let{state:t}=e,{selection:n,doc:r}=t,{$from:i,empty:a}=n;if(!a||i.parent.type!==this.type||i.parentOffset!==i.parent.nodeSize-2)return!1;let o=i.after();return o===void 0?!1:r.nodeAt(o)?e.commands.command(({tr:e})=>(e.setSelection(O.near(r.resolve(o))),!0)):e.commands.exitCode()}}},addInputRules(){return[Of({find:Im,type:this.type,getAttributes:e=>({language:e[1]})}),Of({find:Lm,type:this.type,getAttributes:e=>({language:e[1]})})]},addProseMirrorPlugins(){return[new Mr({key:new Fr(`codeBlockVSCodeHandler`),props:{handlePaste:(e,t)=>{if(!t.clipboardData||this.editor.isActive(this.type.name))return!1;let n=t.clipboardData.getData(`text/plain`),r=t.clipboardData.getData(`vscode-editor-data`),i=(r?JSON.parse(r):void 0)?.mode;if(!n||!i)return!1;let{tr:a,schema:o}=e.state,s=o.text(n.replace(/\r\n?/g,`
227
+ `);return!a||!o?!1:e.chain().command(({tr:e})=>(e.delete(r.pos-2,r.pos),!0)).exitCode().run()},ArrowDown:({editor:e})=>{if(!this.options.exitOnArrowDown)return!1;let{state:t}=e,{selection:n,doc:r}=t,{$from:i,empty:a}=n;if(!a||i.parent.type!==this.type||i.parentOffset!==i.parent.nodeSize-2)return!1;let o=i.after();return o===void 0?!1:r.nodeAt(o)?e.commands.command(({tr:e})=>(e.setSelection(O.near(r.resolve(o))),!0)):e.commands.exitCode()}}},addInputRules(){return[Of({find:Im,type:this.type,getAttributes:e=>({language:e[1]})}),Of({find:Lm,type:this.type,getAttributes:e=>({language:e[1]})})]},addProseMirrorPlugins(){return[new j({key:new Pr(`codeBlockVSCodeHandler`),props:{handlePaste:(e,t)=>{if(!t.clipboardData||this.editor.isActive(this.type.name))return!1;let n=t.clipboardData.getData(`text/plain`),r=t.clipboardData.getData(`vscode-editor-data`),i=(r?JSON.parse(r):void 0)?.mode;if(!n||!i)return!1;let{tr:a,schema:o}=e.state,s=o.text(n.replace(/\r\n?/g,`
228
228
  `));return a.replaceSelectionWith(this.type.create({language:i},s)),a.selection.$from.parent.type!==this.type&&a.setSelection(k.near(a.doc.resolve(Math.max(0,a.selection.from-2)))),a.setMeta(`paste`,!0),e.dispatch(a),!0}}})]}}),zm=Rm,Bm=(e,t)=>{if(e===`slot`)return 0;if(e instanceof Function)return e(t);let{children:n,...r}=t??{};if(e===`svg`)throw Error(`SVG elements are not supported in the JSX syntax, use the array syntax instead`);return[e,r,n]},Vm=/^\s*>\s$/,Hm=Wf.create({name:`blockquote`,addOptions(){return{HTMLAttributes:{}}},content:`block+`,group:`block`,defining:!0,parseHTML(){return[{tag:`blockquote`}]},renderHTML({HTMLAttributes:e}){return Bm(`blockquote`,{...Bu(this.options.HTMLAttributes,e),children:Bm(`slot`,{})})},parseMarkdown:(e,t)=>{let n=t.parseBlockChildren??t.parseChildren;return t.createNode(`blockquote`,void 0,n(e.tokens||[]))},renderMarkdown:(e,t)=>{if(!e.content)return``;let n=[];return e.content.forEach((e,r)=>{let i=(t.renderChild?.call(t,e,r)??t.renderChildren([e])).split(`
229
229
  `).map(e=>e.trim()===``?`>`:`> ${e}`);n.push(i.join(`
230
230
  `))}),n.join(`
@@ -237,8 +237,8 @@ Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error
237
237
  `,Ng=`️`,Pg=`‍`,Fg=``,Ig=null,Lg=null;function Rg(e=[]){let t={};xh.groups=t;let n=new xh;Ig??=Hg(oh),Lg??=Hg(sh),I(n,`'`,$h),I(n,`{`,Ih),I(n,`}`,Lh),I(n,`[`,Rh),I(n,`]`,zh),I(n,`(`,Bh),I(n,`)`,Vh),I(n,`<`,Hh),I(n,`>`,Uh),I(n,`(`,Wh),I(n,`)`,Gh),I(n,`「`,Kh),I(n,`」`,qh),I(n,`『`,Jh),I(n,`』`,Yh),I(n,`<`,Xh),I(n,`>`,Zh),I(n,`&`,Qh),I(n,`*`,eg),I(n,`@`,tg),I(n,"`",rg),I(n,`^`,ig),I(n,`:`,ag),I(n,`,`,og),I(n,`$`,sg),I(n,`.`,cg),I(n,`=`,lg),I(n,`!`,ug),I(n,`-`,dg),I(n,`%`,fg),I(n,`|`,pg),I(n,`+`,mg),I(n,`#`,hg),I(n,`?`,gg),I(n,`"`,_g),I(n,`/`,bg),I(n,`;`,yg),I(n,`~`,xg),I(n,`_`,Sg),I(n,`\\`,ng),I(n,`・`,vg);let r=Sh(n,kg,Nh,{[ch]:!0});Sh(r,kg,r);let i=Sh(r,Eg,Eh,{[dh]:!0}),a=Sh(r,Dg,Dh,{[fh]:!0}),o=Sh(n,Eg,wh,{[lh]:!0});Sh(o,kg,i),Sh(o,Eg,o),Sh(i,kg,i),Sh(i,Eg,i);let s=Sh(n,Dg,Th,{[uh]:!0});Sh(s,Eg),Sh(s,kg,a),Sh(s,Dg,s),Sh(a,kg,a),Sh(a,Eg),Sh(a,Dg,a);let c=I(n,Mg,Fh,{[_h]:!0}),l=I(n,jg,Ph,{[_h]:!0}),u=Sh(n,Ag,Ph,{[_h]:!0});I(n,Fg,u),I(l,Mg,c),I(l,Fg,u),Sh(l,Ag,u),I(u,jg),I(u,Mg),Sh(u,Ag,u),I(u,Fg,u);let d=Sh(n,Og,Cg,{[mh]:!0});I(d,`#`),Sh(d,Og,d),I(d,Ng,d);let f=I(d,Pg);I(f,`#`),Sh(f,Og,d);let p=[[Eg,o],[kg,i]],m=[[Eg,null],[Dg,s],[kg,a]];for(let e=0;e<Ig.length;e++)Vg(n,Ig[e],kh,wh,p);for(let e=0;e<Lg.length;e++)Vg(n,Lg[e],Ah,Th,m);yh(kh,{tld:!0,ascii:!0},t),yh(Ah,{utld:!0,alpha:!0},t),Vg(n,`file`,jh,wh,p),Vg(n,`mailto`,jh,wh,p),Vg(n,`http`,Mh,wh,p),Vg(n,`https`,Mh,wh,p),Vg(n,`ftp`,Mh,wh,p),Vg(n,`ftps`,Mh,wh,p),yh(jh,{scheme:!0,ascii:!0},t),yh(Mh,{slashscheme:!0,ascii:!0},t),e=e.sort((e,t)=>e[0]>t[0]?1:-1);for(let t=0;t<e.length;t++){let r=e[t][0],i=e[t][1]?{[hh]:!0}:{[gh]:!0};r.indexOf(`-`)>=0?i[ph]=!0:Eg.test(r)?kg.test(r)?i[dh]=!0:i[lh]=!0:i[ch]=!0,Ch(n,r,r,i)}return Ch(n,`localhost`,Oh,{ascii:!0}),n.jd=new xh(wg),{start:n,tokens:Object.assign({groups:t},Tg)}}function zg(e,t){let n=Bg(t.replace(/[A-Z]/g,e=>e.toLowerCase())),r=n.length,i=[],a=0,o=0;for(;o<r;){let s=e,c=null,l=0,u=null,d=-1,f=-1;for(;o<r&&(c=s.go(n[o]));)s=c,s.accepts()?(d=0,f=0,u=s):d>=0&&(d+=n[o].length,f++),l+=n[o].length,a+=n[o].length,o++;a-=d,o-=f,l-=d,i.push({t:u.t,v:t.slice(a-l,a),s:a-l,e:a})}return i}function Bg(e){let t=[],n=e.length,r=0;for(;r<n;){let i=e.charCodeAt(r),a,o=i<55296||i>56319||r+1===n||(a=e.charCodeAt(r+1))<56320||a>57343?e[r]:e.slice(r,r+2);t.push(o),r+=o.length}return t}function Vg(e,t,n,r,i){let a,o=t.length;for(let n=0;n<o-1;n++){let o=t[n];e.j[o]?a=e.j[o]:(a=new xh(r),a.jr=i.slice(),e.j[o]=a),e=a}return a=new xh(n),a.jr=i.slice(),e.j[t[o-1]]=a,a}function Hg(e){let t=[],n=[],r=0;for(;r<e.length;){let i=0;for(;`0123456789`.indexOf(e[r+i])>=0;)i++;if(i>0){t.push(n.join(``));for(let t=parseInt(e.substring(r,r+i),10);t>0;t--)n.pop();r+=i}else n.push(e[r]),r++}return t}var Ug={defaultProtocol:`http`,events:null,format:Gg,formatHref:Gg,nl2br:!1,tagName:`a`,target:null,rel:null,validate:!0,truncate:1/0,className:null,attributes:null,ignoreTags:[],render:null};function Wg(e,t=null){let n=Object.assign({},Ug);e&&(n=Object.assign(n,e instanceof Wg?e.o:e));let r=n.ignoreTags,i=[];for(let e=0;e<r.length;e++)i.push(r[e].toUpperCase());this.o=n,t&&(this.defaultRender=t),this.ignoreTags=i}Wg.prototype={o:Ug,ignoreTags:[],defaultRender(e){return e},check(e){return this.get(`validate`,e.toString(),e)},get(e,t,n){let r=t!=null,i=this.o[e];return i&&(typeof i==`object`?(i=n.t in i?i[n.t]:Ug[e],typeof i==`function`&&r&&(i=i(t,n))):typeof i==`function`&&r&&(i=i(t,n.t,n)),i)},getObj(e,t,n){let r=this.o[e];return typeof r==`function`&&t!=null&&(r=r(t,n.t,n)),r},render(e){let t=e.render(this);return(this.get(`render`,null,e)||this.defaultRender)(t,e.t,e)}};function Gg(e){return e}function Kg(e,t){this.t=`token`,this.v=e,this.tk=t}Kg.prototype={isLink:!1,toString(){return this.v},toHref(e){return this.toString()},toFormattedString(e){let t=this.toString(),n=e.get(`truncate`,t,this),r=e.get(`format`,t,this);return n&&r.length>n?r.substring(0,n)+`…`:r},toFormattedHref(e){return e.get(`formatHref`,this.toHref(e.get(`defaultProtocol`)),this)},startIndex(){return this.tk[0].s},endIndex(){return this.tk[this.tk.length-1].e},toObject(e=Ug.defaultProtocol){return{type:this.t,value:this.toString(),isLink:this.isLink,href:this.toHref(e),start:this.startIndex(),end:this.endIndex()}},toFormattedObject(e){return{type:this.t,value:this.toFormattedString(e),isLink:this.isLink,href:this.toFormattedHref(e),start:this.startIndex(),end:this.endIndex()}},validate(e){return e.get(`validate`,this.toString(),this)},render(e){let t=this,n=this.toHref(e.get(`defaultProtocol`)),r=e.get(`formatHref`,n,this),i=e.get(`tagName`,n,t),a=this.toFormattedString(e),o={},s=e.get(`className`,n,t),c=e.get(`target`,n,t),l=e.get(`rel`,n,t),u=e.getObj(`attributes`,n,t),d=e.getObj(`events`,n,t);return o.href=r,s&&(o.class=s),c&&(o.target=c),l&&(o.rel=l),u&&Object.assign(o,u),{tagName:i,attributes:o,content:a,eventListeners:d}}};function qg(e,t){class n extends Kg{constructor(t,n){super(t,n),this.t=e}}for(let e in t)n.prototype[e]=t[e];return n.t=e,n}var Jg=qg(`email`,{isLink:!0,toHref(){return`mailto:`+this.toString()}}),Yg=qg(`text`),Xg=qg(`nl`),Zg=qg(`url`,{isLink:!0,toHref(e=Ug.defaultProtocol){return this.hasProtocol()?this.v:`${e}://${this.v}`},hasProtocol(){let e=this.tk;return e.length>=2&&e[0].t!==Oh&&e[1].t===ag}}),Qg=e=>new xh(e);function $g({groups:e}){let t=e.domain.concat([Qh,eg,tg,ng,rg,ig,sg,lg,dg,Nh,fg,pg,mg,hg,bg,wg,xg,Sg]),n=[$h,ag,og,cg,ug,fg,gg,_g,yg,Hh,Uh,Ih,Lh,zh,Rh,Bh,Vh,Wh,Gh,Kh,qh,Jh,Yh,Xh,Zh],r=[Qh,$h,eg,ng,rg,ig,sg,lg,dg,Ih,Lh,fg,pg,mg,hg,gg,bg,wg,xg,Sg],i=Qg(),a=I(i,xg);F(a,r,a),F(a,e.domain,a);let o=Qg(),s=Qg(),c=Qg();F(i,e.domain,o),F(i,e.scheme,s),F(i,e.slashscheme,c),F(o,r,a),F(o,e.domain,o);let l=I(o,tg);I(a,tg,l),I(s,tg,l),I(c,tg,l);let u=I(a,cg);F(u,r,a),F(u,e.domain,a);let d=Qg();F(l,e.domain,d),F(d,e.domain,d);let f=I(d,cg);F(f,e.domain,d);let p=Qg(Jg);F(f,e.tld,p),F(f,e.utld,p),I(l,Oh,p);let m=I(d,dg);I(m,dg,m),F(m,e.domain,d),F(p,e.domain,d),I(p,cg,f),I(p,dg,m),F(I(p,ag),e.numeric,Jg);let h=I(o,dg),g=I(o,cg);I(h,dg,h),F(h,e.domain,o),F(g,r,a),F(g,e.domain,o);let _=Qg(Zg);F(g,e.tld,_),F(g,e.utld,_),F(_,e.domain,o),F(_,r,a),I(_,cg,g),I(_,dg,h),I(_,tg,l);let v=I(_,ag),y=Qg(Zg);F(v,e.numeric,y);let b=Qg(Zg),x=Qg();F(b,t,b),F(b,n,x),F(x,t,b),F(x,n,x),I(_,bg,b),I(y,bg,b);let S=I(s,ag),C=I(I(I(c,ag),bg),bg);F(s,e.domain,o),I(s,cg,g),I(s,dg,h),F(c,e.domain,o),I(c,cg,g),I(c,dg,h),F(S,e.domain,b),I(S,bg,b),I(S,gg,b),F(C,e.domain,b),F(C,t,b),I(C,bg,b);let ee=[[Ih,Lh],[Rh,zh],[Bh,Vh],[Hh,Uh],[Wh,Gh],[Kh,qh],[Jh,Yh],[Xh,Zh]];for(let e=0;e<ee.length;e++){let[r,i]=ee[e],a=I(b,r);I(x,r,a),I(a,i,b);let o=Qg(Zg);F(a,t,o);let s=Qg();F(a,n),F(o,t,o),F(o,n,s),F(s,t,o),F(s,n,s),I(o,i,b),I(s,i,b)}return I(i,Oh,_),I(i,Fh,Xg),{start:i,tokens:Tg}}function e_(e,t,n){let r=n.length,i=0,a=[],o=[];for(;i<r;){let s=e,c=null,l=null,u=0,d=null,f=-1;for(;i<r&&!(c=s.go(n[i].t));)o.push(n[i++]);for(;i<r&&(l=c||s.go(n[i].t));)c=null,s=l,s.accepts()?(f=0,d=s):f>=0&&f++,i++,u++;if(f<0)i-=u,i<r&&(o.push(n[i]),i++);else{o.length>0&&(a.push(t_(Yg,t,o)),o=[]),i-=f,u-=f;let e=d.t,r=n.slice(i-u,i);a.push(t_(e,t,r))}}return o.length>0&&a.push(t_(Yg,t,o)),a}function t_(e,t,n){let r=n[0].s,i=n[n.length-1].e;return new e(t.slice(r,i),n)}var n_=typeof console<`u`&&console&&console.warn||(()=>{}),r_=`until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.`,i_={scanner:null,parser:null,tokenQueue:[],pluginQueue:[],customSchemes:[],initialized:!1};function a_(){return xh.groups={},i_.scanner=null,i_.parser=null,i_.tokenQueue=[],i_.pluginQueue=[],i_.customSchemes=[],i_.initialized=!1,i_}function o_(e,t=!1){if(i_.initialized&&n_(`linkifyjs: already initialized - will not register custom scheme "${e}" ${r_}`),!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(e))throw Error(`linkifyjs: incorrect scheme format.
238
238
  1. Must only contain digits, lowercase ASCII letters or "-"
239
239
  2. Cannot start or end with "-"
240
- 3. "-" cannot repeat`);i_.customSchemes.push([e,t])}function s_(){i_.scanner=Rg(i_.customSchemes);for(let e=0;e<i_.tokenQueue.length;e++)i_.tokenQueue[e][1]({scanner:i_.scanner});i_.parser=$g(i_.scanner.tokens);for(let e=0;e<i_.pluginQueue.length;e++)i_.pluginQueue[e][1]({scanner:i_.scanner,parser:i_.parser});return i_.initialized=!0,i_}function c_(e){return i_.initialized||s_(),e_(i_.parser.start,e,zg(i_.scanner.start,e))}c_.scan=zg;function l_(e,t=null,n=null){if(t&&typeof t==`object`){if(n)throw Error(`linkifyjs: Invalid link type ${t}; must be a string`);n=t,t=null}let r=new Wg(n),i=c_(e),a=[];for(let e=0;e<i.length;e++){let n=i[e];n.isLink&&(!t||n.t===t)&&r.check(n)&&a.push(n.toFormattedObject(r))}return a}var u_=`[\0- \xA0 ᠎ -\u2029  ]`,d_=new RegExp(u_),f_=RegExp(`${u_}$`),p_=new RegExp(u_,`g`);function m_(e){return e.length===1?e[0].isLink:e.length===3&&e[1].isLink?[`()`,`[]`].includes(e[0].value+e[2].value):!1}function h_(e){return new Mr({key:new Fr(`autolink`),appendTransaction:(t,n,r)=>{let i=t.some(e=>e.docChanged)&&!n.doc.eq(r.doc),a=t.some(e=>e.getMeta(`preventAutolink`));if(!i||a)return;let{tr:o}=r;if(ad(Du(n.doc,[...t])).forEach(({newRange:t})=>{let n=ku(r.doc,t,e=>e.isTextblock),i,a;if(n.length>1)i=n[0],a=r.doc.textBetween(i.pos,i.pos+i.node.nodeSize,void 0,` `);else if(n.length){let e=r.doc.textBetween(t.from,t.to,` `,` `);if(!f_.test(e))return;i=n[0],a=r.doc.textBetween(i.pos,t.to,void 0,` `)}if(i&&a){let t=a.split(d_).filter(Boolean);if(t.length<=0)return!1;let n=t[t.length-1],s=i.pos+a.lastIndexOf(n);if(!n)return!1;let c=c_(n).map(t=>t.toObject(e.defaultProtocol));if(!m_(c))return!1;c.filter(e=>e.isLink).map(e=>({...e,from:s+e.start+1,to:s+e.end+1})).filter(e=>r.schema.marks.code?!r.doc.rangeHasMark(e.from,e.to,r.schema.marks.code):!0).filter(t=>e.validate(t.value)).filter(t=>e.shouldAutoLink(t.value)).forEach(t=>{od(t.from,t.to,r.doc).some(t=>t.mark.type===e.type)||o.addMark(t.from,t.to,e.type.create({href:t.href}))})}}),o.steps.length)return o}})}function g_(e){return new Mr({key:new Fr(`handleClickLink`),props:{handleClick:(t,n,r)=>{if(r.button!==0||!t.editable)return!1;let i=null;if(r.target instanceof HTMLAnchorElement)i=r.target;else{let t=r.target;if(!t)return!1;let n=e.editor.view.dom;i=t.closest(`a`),i&&!n.contains(i)&&(i=null)}if(!i)return!1;let a=!1;if(e.enableClickSelection&&(a=e.editor.commands.extendMarkRange(e.type.name)),e.openOnClick){let n=nd(t.state,e.type.name),r=i.href??n.href,o=i.target??n.target;r&&(window.open(r,o),a=!0)}return a}}})}function __(e){return new Mr({key:new Fr(`handlePasteLink`),props:{handlePaste:(t,n,r)=>{let{shouldAutoLink:i}=e,{state:a}=t,{selection:o}=a,{empty:s}=o;if(s)return!1;let c=``;r.content.forEach(e=>{c+=e.textContent});let l=l_(c,{defaultProtocol:e.defaultProtocol}).find(e=>e.isLink&&e.value===c);return!c||!l||i!==void 0&&!i(l.value)?!1:e.editor.commands.setMark(e.type,{href:l.href})}}})}function v_(e,t){let n=[`http`,`https`,`ftp`,`ftps`,`mailto`,`tel`,`callto`,`sms`,`cid`,`xmpp`];return t&&t.forEach(e=>{let t=typeof e==`string`?e:e.scheme;t&&n.push(t)}),!e||e.replace(p_,``).match(RegExp(`^(?:(?:${n.join(`|`)}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,`i`))}var y_=tf.create({name:`link`,priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate,console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.")),this.options.protocols.forEach(e=>{if(typeof e==`string`){o_(e);return}o_(e.scheme,e.optionalSlashes)})},onDestroy(){a_()},inclusive(){return this.options.autolink},addOptions(){return{openOnClick:!0,enableClickSelection:!1,linkOnPaste:!0,autolink:!0,protocols:[],defaultProtocol:`http`,HTMLAttributes:{target:`_blank`,rel:`noopener noreferrer nofollow`,class:null},isAllowedUri:(e,t)=>!!v_(e,t.protocols),validate:e=>!!e,shouldAutoLink:e=>{let t=/^[a-z][a-z0-9+.-]*:\/\//i.test(e),n=/^[a-z][a-z0-9+.-]*:/i.test(e);if(t||n&&!e.includes(`@`))return!0;let r=(e.includes(`@`)?e.split(`@`).pop():e).split(/[/?#:]/)[0];return!(/^\d{1,3}(\.\d{1,3}){3}$/.test(r)||!/\./.test(r))}}},addAttributes(){return{href:{default:null,parseHTML(e){return e.getAttribute(`href`)}},target:{default:this.options.HTMLAttributes.target},rel:{default:this.options.HTMLAttributes.rel},class:{default:this.options.HTMLAttributes.class},title:{default:null}}},parseHTML(){return[{tag:`a[href]`,getAttrs:e=>{let t=e.getAttribute(`href`);return!t||!this.options.isAllowedUri(t,{defaultValidate:e=>!!v_(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:null}}]},renderHTML({HTMLAttributes:e}){return this.options.isAllowedUri(e.href,{defaultValidate:e=>!!v_(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?[`a`,Bu(this.options.HTMLAttributes,e),0]:[`a`,Bu(this.options.HTMLAttributes,{...e,href:``}),0]},markdownTokenName:`link`,parseMarkdown:(e,t)=>t.applyMark(`link`,t.parseInline(e.tokens||[]),{href:e.href,title:e.title||null}),renderMarkdown:(e,t)=>{let n=e.attrs?.href??``,r=e.attrs?.title??``,i=t.renderChildren(e);return r?`[${i}](${n} "${r}")`:`[${i}](${n})`},addCommands(){return{setLink:e=>({chain:t})=>{let{href:n}=e;return this.options.isAllowedUri(n,{defaultValidate:e=>!!v_(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?t().setMark(this.name,e).setMeta(`preventAutolink`,!0).run():!1},toggleLink:e=>({chain:t})=>{let{href:n}=e||{};return n&&!this.options.isAllowedUri(n,{defaultValidate:e=>!!v_(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:t().toggleMark(this.name,e,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()},unsetLink:()=>({chain:e})=>e().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()}},addPasteRules(){return[Gf({find:e=>{let t=[];if(e){let{protocols:n,defaultProtocol:r}=this.options,i=l_(e).filter(e=>e.isLink&&this.options.isAllowedUri(e.value,{defaultValidate:e=>!!v_(e,n),protocols:n,defaultProtocol:r}));i.length&&i.forEach(e=>{this.options.shouldAutoLink(e.value)&&t.push({text:e.value,data:{href:e.href},index:e.start})})}return t},type:this.type,getAttributes:e=>({href:e.data?.href})})]},addProseMirrorPlugins(){let e=[],{protocols:t,defaultProtocol:n}=this.options;return this.options.autolink&&e.push(h_({type:this.type,defaultProtocol:this.options.defaultProtocol,validate:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!v_(e,t),protocols:t,defaultProtocol:n}),shouldAutoLink:this.options.shouldAutoLink})),e.push(g_({type:this.type,editor:this.editor,openOnClick:this.options.openOnClick===`whenNotEditable`?!0:this.options.openOnClick,enableClickSelection:this.options.enableClickSelection})),this.options.linkOnPaste&&e.push(__({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type,shouldAutoLink:this.options.shouldAutoLink})),e}}),b_=Object.defineProperty,x_=(e,t)=>{for(var n in t)b_(e,n,{get:t[n],enumerable:!0})},S_=`listItem`,C_=`textStyle`,w_=/^\s*([-+*])\s$/,T_=Wf.create({name:`bulletList`,addOptions(){return{itemTypeName:`listItem`,HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:`block list`,content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul`}]},renderHTML({HTMLAttributes:e}){return[`ul`,Bu(this.options.HTMLAttributes,e),0]},markdownTokenName:`list`,parseMarkdown:(e,t)=>e.type!==`list`||e.ordered?[]:{type:`bulletList`,content:e.items?t.parseChildren(e.items):[]},renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,`
241
- `):``,markdownOptions:{indentsContent:!0},addCommands(){return{toggleBulletList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(S_,this.editor.getAttributes(C_)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let e=kf({find:w_,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(e=kf({find:w_,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(C_),editor:this.editor})),[e]}}),E_=Wf.create({name:`listItem`,addOptions(){return{HTMLAttributes:{},bulletListTypeName:`bulletList`,orderedListTypeName:`orderedList`}},content:`paragraph block*`,defining:!0,parseHTML(){return[{tag:`li`}]},renderHTML({HTMLAttributes:e}){return[`li`,Bu(this.options.HTMLAttributes,e),0]},markdownTokenName:`list_item`,parseMarkdown:(e,t)=>{if(e.type!==`list_item`)return[];let n=t.parseBlockChildren??t.parseChildren,r=[];if(e.tokens&&e.tokens.length>0)if(e.tokens.some(e=>e.type===`paragraph`))r=n(e.tokens);else{let i=e.tokens[0];if(i&&i.type===`text`&&i.tokens&&i.tokens.length>0){if(r=[{type:`paragraph`,content:t.parseInline(i.tokens)}],e.tokens.length>1){let t=n(e.tokens.slice(1));r.push(...t)}}else r=n(e.tokens)}return r.length===0&&(r=[{type:`paragraph`,content:[]}]),{type:`listItem`,content:r}},renderMarkdown:(e,t,n)=>Hf(e,t,e=>e.parentType===`bulletList`?`- `:e.parentType===`orderedList`?`${(e.meta?.parentAttrs?.start||1)+e.index}. `:`- `,n),addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}});x_({},{findListItemPos:()=>D_,getNextListDepth:()=>O_,handleBackspace:()=>M_,handleDelete:()=>F_,hasListBefore:()=>k_,hasListItemAfter:()=>I_,hasListItemBefore:()=>A_,listItemHasSubList:()=>j_,nextListIsDeeper:()=>N_,nextListIsHigher:()=>P_});var D_=(e,t)=>{let{$from:n}=t.selection,r=Cl(e,t.schema),i=null,a=n.depth,o=n.pos,s=null;for(;a>0&&s===null;)i=n.node(a),i.type===r?s=a:(--a,--o);return s===null?null:{$pos:t.doc.resolve(o),depth:s}},O_=(e,t)=>{let n=D_(e,t);if(!n)return!1;let[,r]=sd(t,e,n.$pos.pos+4);return r},k_=(e,t,n)=>{let{$anchor:r}=e.selection,i=Math.max(0,r.pos-2),a=e.doc.resolve(i).node();return!(!a||!n.includes(a.type.name))},A_=(e,t)=>{let{$anchor:n}=t.selection,r=t.doc.resolve(n.pos-2);return!(r.index()===0||r.nodeBefore?.type.name!==e)},j_=(e,t,n)=>{if(!n)return!1;let r=Cl(e,t.schema),i=!1;return n.descendants(e=>{e.type===r&&(i=!0)}),i},M_=(e,t,n)=>{if(e.commands.undoInputRule())return!0;if(e.state.selection.from!==e.state.selection.to)return!1;if(!lu(e.state,t)&&k_(e.state,t,n)){let{$anchor:n}=e.state.selection,r=e.state.doc.resolve(n.before()-1),i=[];r.node().descendants((e,n)=>{e.type.name===t&&i.push({node:e,pos:n})});let a=i.at(-1);if(!a)return!1;let o=e.state.doc.resolve(r.start()+a.pos+1);return e.chain().cut({from:n.start()-1,to:n.end()+1},o.end()).joinForward().run()}if(!lu(e.state,t)||!md(e.state))return!1;let r=D_(t,e.state);if(!r)return!1;let i=e.state.doc.resolve(r.$pos.pos-2).node(r.depth),a=j_(t,e.state,i);return A_(t,e.state)&&!a?e.commands.joinItemBackward():e.chain().liftListItem(t).run()},N_=(e,t)=>{let n=O_(e,t),r=D_(e,t);return!r||!n?!1:n>r.depth},P_=(e,t)=>{let n=O_(e,t),r=D_(e,t);return!r||!n?!1:n<r.depth},F_=(e,t)=>{if(!lu(e.state,t)||!pd(e.state,t))return!1;let{selection:n}=e.state,{$from:r,$to:i}=n;return!n.empty&&r.sameParent(i)?!1:N_(t,e.state)?e.chain().focus(e.state.selection.from+4).lift(t).joinBackward().run():P_(t,e.state)?e.chain().joinForward().joinBackward().run():e.commands.joinItemForward()},I_=(e,t)=>{let{$anchor:n}=t.selection,r=t.doc.resolve(n.pos-n.parentOffset-2);return!(r.index()===r.parent.childCount-1||r.nodeAfter?.type.name!==e)},L_=N.create({name:`listKeymap`,addOptions(){return{listTypes:[{itemName:`listItem`,wrapperNames:[`bulletList`,`orderedList`]},{itemName:`taskItem`,wrapperNames:[`taskList`]}]}},addKeyboardShortcuts(){return{Delete:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{e.state.schema.nodes[n]!==void 0&&F_(e,n)&&(t=!0)}),t},"Mod-Delete":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{e.state.schema.nodes[n]!==void 0&&F_(e,n)&&(t=!0)}),t},Backspace:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{e.state.schema.nodes[n]!==void 0&&M_(e,n,r)&&(t=!0)}),t},"Mod-Backspace":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{e.state.schema.nodes[n]!==void 0&&M_(e,n,r)&&(t=!0)}),t}}}}),R_=/^(\s*)(\d+)\.\s+(.*)$/,z_=/^\s/;function B_(e){let t=[],n=0,r=0;for(;n<e.length;){let i=e[n],a=i.match(R_);if(!a)break;let[,o,s,c]=a,l=o.length,u=c,d=n+1,f=[i];for(;d<e.length;){let t=e[d];if(t.match(R_))break;if(t.trim()===``)f.push(t),u+=`
240
+ 3. "-" cannot repeat`);i_.customSchemes.push([e,t])}function s_(){i_.scanner=Rg(i_.customSchemes);for(let e=0;e<i_.tokenQueue.length;e++)i_.tokenQueue[e][1]({scanner:i_.scanner});i_.parser=$g(i_.scanner.tokens);for(let e=0;e<i_.pluginQueue.length;e++)i_.pluginQueue[e][1]({scanner:i_.scanner,parser:i_.parser});return i_.initialized=!0,i_}function c_(e){return i_.initialized||s_(),e_(i_.parser.start,e,zg(i_.scanner.start,e))}c_.scan=zg;function l_(e,t=null,n=null){if(t&&typeof t==`object`){if(n)throw Error(`linkifyjs: Invalid link type ${t}; must be a string`);n=t,t=null}let r=new Wg(n),i=c_(e),a=[];for(let e=0;e<i.length;e++){let n=i[e];n.isLink&&(!t||n.t===t)&&r.check(n)&&a.push(n.toFormattedObject(r))}return a}var u_=`[\0- \xA0 ᠎ -\u2029  ]`,d_=new RegExp(u_),f_=RegExp(`${u_}$`),p_=new RegExp(u_,`g`);function m_(e){return e.length===1?e[0].isLink:e.length===3&&e[1].isLink?[`()`,`[]`].includes(e[0].value+e[2].value):!1}function h_(e){return new j({key:new Pr(`autolink`),appendTransaction:(t,n,r)=>{let i=t.some(e=>e.docChanged)&&!n.doc.eq(r.doc),a=t.some(e=>e.getMeta(`preventAutolink`));if(!i||a)return;let{tr:o}=r;if(ad(Eu(n.doc,[...t])).forEach(({newRange:t})=>{let n=Ou(r.doc,t,e=>e.isTextblock),i,a;if(n.length>1)i=n[0],a=r.doc.textBetween(i.pos,i.pos+i.node.nodeSize,void 0,` `);else if(n.length){let e=r.doc.textBetween(t.from,t.to,` `,` `);if(!f_.test(e))return;i=n[0],a=r.doc.textBetween(i.pos,t.to,void 0,` `)}if(i&&a){let t=a.split(d_).filter(Boolean);if(t.length<=0)return!1;let n=t[t.length-1],s=i.pos+a.lastIndexOf(n);if(!n)return!1;let c=c_(n).map(t=>t.toObject(e.defaultProtocol));if(!m_(c))return!1;c.filter(e=>e.isLink).map(e=>({...e,from:s+e.start+1,to:s+e.end+1})).filter(e=>r.schema.marks.code?!r.doc.rangeHasMark(e.from,e.to,r.schema.marks.code):!0).filter(t=>e.validate(t.value)).filter(t=>e.shouldAutoLink(t.value)).forEach(t=>{od(t.from,t.to,r.doc).some(t=>t.mark.type===e.type)||o.addMark(t.from,t.to,e.type.create({href:t.href}))})}}),o.steps.length)return o}})}function g_(e){return new j({key:new Pr(`handleClickLink`),props:{handleClick:(t,n,r)=>{if(r.button!==0||!t.editable)return!1;let i=null;if(r.target instanceof HTMLAnchorElement)i=r.target;else{let t=r.target;if(!t)return!1;let n=e.editor.view.dom;i=t.closest(`a`),i&&!n.contains(i)&&(i=null)}if(!i)return!1;let a=!1;if(e.enableClickSelection&&(a=e.editor.commands.extendMarkRange(e.type.name)),e.openOnClick){let n=nd(t.state,e.type.name),r=i.href??n.href,o=i.target??n.target;r&&(window.open(r,o),a=!0)}return a}}})}function __(e){return new j({key:new Pr(`handlePasteLink`),props:{handlePaste:(t,n,r)=>{let{shouldAutoLink:i}=e,{state:a}=t,{selection:o}=a,{empty:s}=o;if(s)return!1;let c=``;r.content.forEach(e=>{c+=e.textContent});let l=l_(c,{defaultProtocol:e.defaultProtocol}).find(e=>e.isLink&&e.value===c);return!c||!l||i!==void 0&&!i(l.value)?!1:e.editor.commands.setMark(e.type,{href:l.href})}}})}function v_(e,t){let n=[`http`,`https`,`ftp`,`ftps`,`mailto`,`tel`,`callto`,`sms`,`cid`,`xmpp`];return t&&t.forEach(e=>{let t=typeof e==`string`?e:e.scheme;t&&n.push(t)}),!e||e.replace(p_,``).match(RegExp(`^(?:(?:${n.join(`|`)}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,`i`))}var y_=tf.create({name:`link`,priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate,console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.")),this.options.protocols.forEach(e=>{if(typeof e==`string`){o_(e);return}o_(e.scheme,e.optionalSlashes)})},onDestroy(){a_()},inclusive(){return this.options.autolink},addOptions(){return{openOnClick:!0,enableClickSelection:!1,linkOnPaste:!0,autolink:!0,protocols:[],defaultProtocol:`http`,HTMLAttributes:{target:`_blank`,rel:`noopener noreferrer nofollow`,class:null},isAllowedUri:(e,t)=>!!v_(e,t.protocols),validate:e=>!!e,shouldAutoLink:e=>{let t=/^[a-z][a-z0-9+.-]*:\/\//i.test(e),n=/^[a-z][a-z0-9+.-]*:/i.test(e);if(t||n&&!e.includes(`@`))return!0;let r=(e.includes(`@`)?e.split(`@`).pop():e).split(/[/?#:]/)[0];return!(/^\d{1,3}(\.\d{1,3}){3}$/.test(r)||!/\./.test(r))}}},addAttributes(){return{href:{default:null,parseHTML(e){return e.getAttribute(`href`)}},target:{default:this.options.HTMLAttributes.target},rel:{default:this.options.HTMLAttributes.rel},class:{default:this.options.HTMLAttributes.class},title:{default:null}}},parseHTML(){return[{tag:`a[href]`,getAttrs:e=>{let t=e.getAttribute(`href`);return!t||!this.options.isAllowedUri(t,{defaultValidate:e=>!!v_(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:null}}]},renderHTML({HTMLAttributes:e}){return this.options.isAllowedUri(e.href,{defaultValidate:e=>!!v_(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?[`a`,Bu(this.options.HTMLAttributes,e),0]:[`a`,Bu(this.options.HTMLAttributes,{...e,href:``}),0]},markdownTokenName:`link`,parseMarkdown:(e,t)=>t.applyMark(`link`,t.parseInline(e.tokens||[]),{href:e.href,title:e.title||null}),renderMarkdown:(e,t)=>{let n=e.attrs?.href??``,r=e.attrs?.title??``,i=t.renderChildren(e);return r?`[${i}](${n} "${r}")`:`[${i}](${n})`},addCommands(){return{setLink:e=>({chain:t})=>{let{href:n}=e;return this.options.isAllowedUri(n,{defaultValidate:e=>!!v_(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?t().setMark(this.name,e).setMeta(`preventAutolink`,!0).run():!1},toggleLink:e=>({chain:t})=>{let{href:n}=e||{};return n&&!this.options.isAllowedUri(n,{defaultValidate:e=>!!v_(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:t().toggleMark(this.name,e,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()},unsetLink:()=>({chain:e})=>e().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()}},addPasteRules(){return[Gf({find:e=>{let t=[];if(e){let{protocols:n,defaultProtocol:r}=this.options,i=l_(e).filter(e=>e.isLink&&this.options.isAllowedUri(e.value,{defaultValidate:e=>!!v_(e,n),protocols:n,defaultProtocol:r}));i.length&&i.forEach(e=>{this.options.shouldAutoLink(e.value)&&t.push({text:e.value,data:{href:e.href},index:e.start})})}return t},type:this.type,getAttributes:e=>({href:e.data?.href})})]},addProseMirrorPlugins(){let e=[],{protocols:t,defaultProtocol:n}=this.options;return this.options.autolink&&e.push(h_({type:this.type,defaultProtocol:this.options.defaultProtocol,validate:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!v_(e,t),protocols:t,defaultProtocol:n}),shouldAutoLink:this.options.shouldAutoLink})),e.push(g_({type:this.type,editor:this.editor,openOnClick:this.options.openOnClick===`whenNotEditable`?!0:this.options.openOnClick,enableClickSelection:this.options.enableClickSelection})),this.options.linkOnPaste&&e.push(__({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type,shouldAutoLink:this.options.shouldAutoLink})),e}}),b_=Object.defineProperty,x_=(e,t)=>{for(var n in t)b_(e,n,{get:t[n],enumerable:!0})},S_=`listItem`,C_=`textStyle`,w_=/^\s*([-+*])\s$/,T_=Wf.create({name:`bulletList`,addOptions(){return{itemTypeName:`listItem`,HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:`block list`,content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul`}]},renderHTML({HTMLAttributes:e}){return[`ul`,Bu(this.options.HTMLAttributes,e),0]},markdownTokenName:`list`,parseMarkdown:(e,t)=>e.type!==`list`||e.ordered?[]:{type:`bulletList`,content:e.items?t.parseChildren(e.items):[]},renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,`
241
+ `):``,markdownOptions:{indentsContent:!0},addCommands(){return{toggleBulletList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(S_,this.editor.getAttributes(C_)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let e=kf({find:w_,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(e=kf({find:w_,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(C_),editor:this.editor})),[e]}}),E_=Wf.create({name:`listItem`,addOptions(){return{HTMLAttributes:{},bulletListTypeName:`bulletList`,orderedListTypeName:`orderedList`}},content:`paragraph block*`,defining:!0,parseHTML(){return[{tag:`li`}]},renderHTML({HTMLAttributes:e}){return[`li`,Bu(this.options.HTMLAttributes,e),0]},markdownTokenName:`list_item`,parseMarkdown:(e,t)=>{if(e.type!==`list_item`)return[];let n=t.parseBlockChildren??t.parseChildren,r=[];if(e.tokens&&e.tokens.length>0)if(e.tokens.some(e=>e.type===`paragraph`))r=n(e.tokens);else{let i=e.tokens[0];if(i&&i.type===`text`&&i.tokens&&i.tokens.length>0){if(r=[{type:`paragraph`,content:t.parseInline(i.tokens)}],e.tokens.length>1){let t=n(e.tokens.slice(1));r.push(...t)}}else r=n(e.tokens)}return r.length===0&&(r=[{type:`paragraph`,content:[]}]),{type:`listItem`,content:r}},renderMarkdown:(e,t,n)=>Hf(e,t,e=>e.parentType===`bulletList`?`- `:e.parentType===`orderedList`?`${(e.meta?.parentAttrs?.start||1)+e.index}. `:`- `,n),addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}});x_({},{findListItemPos:()=>D_,getNextListDepth:()=>O_,handleBackspace:()=>M_,handleDelete:()=>F_,hasListBefore:()=>k_,hasListItemAfter:()=>I_,hasListItemBefore:()=>A_,listItemHasSubList:()=>j_,nextListIsDeeper:()=>N_,nextListIsHigher:()=>P_});var D_=(e,t)=>{let{$from:n}=t.selection,r=Sl(e,t.schema),i=null,a=n.depth,o=n.pos,s=null;for(;a>0&&s===null;)i=n.node(a),i.type===r?s=a:(--a,--o);return s===null?null:{$pos:t.doc.resolve(o),depth:s}},O_=(e,t)=>{let n=D_(e,t);if(!n)return!1;let[,r]=sd(t,e,n.$pos.pos+4);return r},k_=(e,t,n)=>{let{$anchor:r}=e.selection,i=Math.max(0,r.pos-2),a=e.doc.resolve(i).node();return!(!a||!n.includes(a.type.name))},A_=(e,t)=>{let{$anchor:n}=t.selection,r=t.doc.resolve(n.pos-2);return!(r.index()===0||r.nodeBefore?.type.name!==e)},j_=(e,t,n)=>{if(!n)return!1;let r=Sl(e,t.schema),i=!1;return n.descendants(e=>{e.type===r&&(i=!0)}),i},M_=(e,t,n)=>{if(e.commands.undoInputRule())return!0;if(e.state.selection.from!==e.state.selection.to)return!1;if(!cu(e.state,t)&&k_(e.state,t,n)){let{$anchor:n}=e.state.selection,r=e.state.doc.resolve(n.before()-1),i=[];r.node().descendants((e,n)=>{e.type.name===t&&i.push({node:e,pos:n})});let a=i.at(-1);if(!a)return!1;let o=e.state.doc.resolve(r.start()+a.pos+1);return e.chain().cut({from:n.start()-1,to:n.end()+1},o.end()).joinForward().run()}if(!cu(e.state,t)||!md(e.state))return!1;let r=D_(t,e.state);if(!r)return!1;let i=e.state.doc.resolve(r.$pos.pos-2).node(r.depth),a=j_(t,e.state,i);return A_(t,e.state)&&!a?e.commands.joinItemBackward():e.chain().liftListItem(t).run()},N_=(e,t)=>{let n=O_(e,t),r=D_(e,t);return!r||!n?!1:n>r.depth},P_=(e,t)=>{let n=O_(e,t),r=D_(e,t);return!r||!n?!1:n<r.depth},F_=(e,t)=>{if(!cu(e.state,t)||!pd(e.state,t))return!1;let{selection:n}=e.state,{$from:r,$to:i}=n;return!n.empty&&r.sameParent(i)?!1:N_(t,e.state)?e.chain().focus(e.state.selection.from+4).lift(t).joinBackward().run():P_(t,e.state)?e.chain().joinForward().joinBackward().run():e.commands.joinItemForward()},I_=(e,t)=>{let{$anchor:n}=t.selection,r=t.doc.resolve(n.pos-n.parentOffset-2);return!(r.index()===r.parent.childCount-1||r.nodeAfter?.type.name!==e)},L_=N.create({name:`listKeymap`,addOptions(){return{listTypes:[{itemName:`listItem`,wrapperNames:[`bulletList`,`orderedList`]},{itemName:`taskItem`,wrapperNames:[`taskList`]}]}},addKeyboardShortcuts(){return{Delete:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{e.state.schema.nodes[n]!==void 0&&F_(e,n)&&(t=!0)}),t},"Mod-Delete":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{e.state.schema.nodes[n]!==void 0&&F_(e,n)&&(t=!0)}),t},Backspace:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{e.state.schema.nodes[n]!==void 0&&M_(e,n,r)&&(t=!0)}),t},"Mod-Backspace":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{e.state.schema.nodes[n]!==void 0&&M_(e,n,r)&&(t=!0)}),t}}}}),R_=/^(\s*)(\d+)\.\s+(.*)$/,z_=/^\s/;function B_(e){let t=[],n=0,r=0;for(;n<e.length;){let i=e[n],a=i.match(R_);if(!a)break;let[,o,s,c]=a,l=o.length,u=c,d=n+1,f=[i];for(;d<e.length;){let t=e[d];if(t.match(R_))break;if(t.trim()===``)f.push(t),u+=`
242
242
  `,d+=1;else if(t.match(z_))f.push(t),u+=`
243
243
  ${t.slice(l+2)}`,d+=1;else break}t.push({indent:l,number:parseInt(s,10),content:u.trim(),raw:f.join(`
244
244
  `)}),r=d,n=d}return[t,r]}function V_(e,t,n){let r=[],i=0;for(;i<e.length;){let a=e[i];if(a.indent===t){let o=a.content.split(`
@@ -248,11 +248,11 @@ ${t.slice(l+2)}`,d+=1;else break}t.push({indent:l,number:parseInt(s,10),content:
248
248
  `):``,markdownTokenizer:{name:`orderedList`,level:`block`,start:e=>{let t=e.match(/^(\s*)(\d+)\.\s+/)?.index;return t===void 0?-1:t},tokenize:(e,t,n)=>{let r=e.split(`
249
249
  `),[i,a]=B_(r);if(i.length===0)return;let o=V_(i,0,n);if(o.length!==0)return{type:`list`,ordered:!0,start:i[0]?.number||1,items:o,raw:r.slice(0,a).join(`
250
250
  `)}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleOrderedList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(U_,this.editor.getAttributes(W_)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addInputRules(){let e=kf({find:G_,type:this.type,getAttributes:e=>({start:+e[1]}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1]});return(this.options.keepMarks||this.options.keepAttributes)&&(e=kf({find:G_,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:e=>({start:+e[1],...this.editor.getAttributes(W_)}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1],editor:this.editor})),[e]}}),q_=/^\s*(\[([( |x])?\])\s$/,J_=Wf.create({name:`taskItem`,addOptions(){return{nested:!1,HTMLAttributes:{},taskListTypeName:`taskList`,a11y:void 0}},content(){return this.options.nested?`paragraph block*`:`paragraph+`},defining:!0,addAttributes(){return{checked:{default:!1,keepOnSplit:!1,parseHTML:e=>{let t=e.getAttribute(`data-checked`);return t===``||t===`true`},renderHTML:e=>({"data-checked":e.checked})}}},parseHTML(){return[{tag:`li[data-type="${this.name}"]`,priority:51}]},renderHTML({node:e,HTMLAttributes:t}){return[`li`,Bu(this.options.HTMLAttributes,t,{"data-type":this.name}),[`label`,[`input`,{type:`checkbox`,checked:e.attrs.checked?`checked`:null}],[`span`]],[`div`,0]]},parseMarkdown:(e,t)=>{let n=[];if(e.tokens&&e.tokens.length>0?n.push(t.createNode(`paragraph`,{},t.parseInline(e.tokens))):e.text?n.push(t.createNode(`paragraph`,{},[t.createNode(`text`,{text:e.text})])):n.push(t.createNode(`paragraph`,{},[])),e.nestedTokens&&e.nestedTokens.length>0){let r=t.parseChildren(e.nestedTokens);n.push(...r)}return t.createNode(`taskItem`,{checked:e.checked||!1},n)},renderMarkdown:(e,t)=>Hf(e,t,`- [${e.attrs?.checked?`x`:` `}] `),addKeyboardShortcuts(){let e={Enter:()=>this.editor.commands.splitListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)};return this.options.nested?{...e,Tab:()=>this.editor.commands.sinkListItem(this.name)}:e},addNodeView(){return({node:e,HTMLAttributes:t,getPos:n,editor:r})=>{let i=document.createElement(`li`),a=document.createElement(`label`),o=document.createElement(`span`),s=document.createElement(`input`),c=document.createElement(`div`),l=e=>{var t;s.ariaLabel=((t=this.options.a11y)?.checkboxLabel)?.call(t,e,s.checked)||`Task item checkbox for ${e.textContent||`empty task item`}`};l(e),a.contentEditable=`false`,s.type=`checkbox`,s.addEventListener(`mousedown`,e=>e.preventDefault()),s.addEventListener(`change`,t=>{if(!r.isEditable&&!this.options.onReadOnlyChecked){s.checked=!s.checked;return}let{checked:i}=t.target;r.isEditable&&typeof n==`function`&&r.chain().focus(void 0,{scrollIntoView:!1}).command(({tr:e})=>{let t=n();if(typeof t!=`number`)return!1;let r=e.doc.nodeAt(t);return e.setNodeMarkup(t,void 0,{...r?.attrs,checked:i}),!0}).run(),!r.isEditable&&this.options.onReadOnlyChecked&&(this.options.onReadOnlyChecked(e,i)||(s.checked=!s.checked))}),Object.entries(this.options.HTMLAttributes).forEach(([e,t])=>{i.setAttribute(e,t)}),i.dataset.checked=e.attrs.checked,s.checked=e.attrs.checked,a.append(s,o),i.append(a,c),Object.entries(t).forEach(([e,t])=>{i.setAttribute(e,t)});let u=new Set(Object.keys(t));return{dom:i,contentDOM:c,update:e=>{if(e.type!==this.type)return!1;i.dataset.checked=e.attrs.checked,s.checked=e.attrs.checked,l(e);let t=r.extensionManager.attributes,n=Vu(e,t),a=new Set(Object.keys(n)),o=this.options.HTMLAttributes;return u.forEach(e=>{a.has(e)||(e in o?i.setAttribute(e,o[e]):i.removeAttribute(e))}),Object.entries(n).forEach(([e,t])=>{t==null?e in o?i.setAttribute(e,o[e]):i.removeAttribute(e):i.setAttribute(e,t)}),u=a,!0}}}},addInputRules(){return[kf({find:q_,type:this.type,getAttributes:e=>({checked:e[e.length-1]===`x`})})]}}),Y_=Wf.create({name:`taskList`,addOptions(){return{itemTypeName:`taskItem`,HTMLAttributes:{}}},group:`block list`,content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul[data-type="${this.name}"]`,priority:51}]},renderHTML({HTMLAttributes:e}){return[`ul`,Bu(this.options.HTMLAttributes,e,{"data-type":this.name}),0]},parseMarkdown:(e,t)=>t.createNode(`taskList`,{},t.parseChildren(e.items||[])),renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,`
251
- `):``,markdownTokenizer:{name:`taskList`,level:`block`,start(e){let t=e.match(/^\s*[-+*]\s+\[([ xX])\]\s+/)?.index;return t===void 0?-1:t},tokenize(e,t,n){let r=e=>{let t=Vf(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);return t?[{type:`taskList`,raw:t.raw,items:t.items}]:n.blockTokens(e)},i=Vf(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);if(i)return{type:`taskList`,raw:i.raw,items:i.items}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleTaskList:()=>({commands:e})=>e.toggleList(this.name,this.options.itemTypeName)}},addKeyboardShortcuts(){return{"Mod-Shift-9":()=>this.editor.commands.toggleTaskList()}}});N.create({name:`listKit`,addExtensions(){let e=[];return this.options.bulletList!==!1&&e.push(T_.configure(this.options.bulletList)),this.options.listItem!==!1&&e.push(E_.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(L_.configure(this.options.listKeymap)),this.options.orderedList!==!1&&e.push(K_.configure(this.options.orderedList)),this.options.taskItem!==!1&&e.push(J_.configure(this.options.taskItem)),this.options.taskList!==!1&&e.push(Y_.configure(this.options.taskList)),e}});var X_=`&nbsp;`,Z_=`\xA0`,Q_=Wf.create({name:`paragraph`,priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:`block`,content:`inline*`,parseHTML(){return[{tag:`p`}]},renderHTML({HTMLAttributes:e}){return[`p`,Bu(this.options.HTMLAttributes,e),0]},parseMarkdown:(e,t)=>{let n=e.tokens||[];if(n.length===1&&n[0].type===`image`)return t.parseChildren([n[0]]);let r=t.parseInline(n);return n.length===1&&n[0].type===`text`&&(n[0].raw===X_||n[0].text===X_||n[0].raw===Z_||n[0].text===Z_)&&r.length===1&&r[0].type===`text`&&(r[0].text===X_||r[0].text===Z_)?t.createNode(`paragraph`,void 0,[]):t.createNode(`paragraph`,void 0,r)},renderMarkdown:(e,t,n)=>{if(!e)return``;let r=Array.isArray(e.content)?e.content:[];if(r.length===0){let e=Array.isArray(n?.previousNode?.content)?n.previousNode.content:[];return n?.previousNode?.type===`paragraph`&&e.length===0?X_:``}return t.renderChildren(r)},addCommands(){return{setParagraph:()=>({commands:e})=>e.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),$_=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,ev=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,tv=tf.create({name:`strike`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`s`},{tag:`del`},{tag:`strike`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`line-through`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`s`,Bu(this.options.HTMLAttributes,e),0]},markdownTokenName:`del`,parseMarkdown:(e,t)=>t.applyMark(`strike`,t.parseInline(e.tokens||[])),renderMarkdown:(e,t)=>`~~${t.renderChildren(e)}~~`,addCommands(){return{setStrike:()=>({commands:e})=>e.setMark(this.name),toggleStrike:()=>({commands:e})=>e.toggleMark(this.name),unsetStrike:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[Ef({find:$_,type:this.type})]},addPasteRules(){return[Gf({find:ev,type:this.type})]}}),nv=Wf.create({name:`text`,group:`inline`,parseMarkdown:e=>({type:`text`,text:e.text||``}),renderMarkdown:e=>e.text||``}),rv=tf.create({name:`underline`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`u`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`underline`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`u`,Bu(this.options.HTMLAttributes,e),0]},parseMarkdown(e,t){return t.applyMark(this.name||`underline`,t.parseInline(e.tokens||[]))},renderMarkdown(e,t){return`++${t.renderChildren(e)}++`},markdownTokenizer:{name:`underline`,level:`inline`,start(e){return e.indexOf(`++`)},tokenize(e,t,n){let r=/^(\+\+)([\s\S]+?)(\+\+)/.exec(e);if(!r)return;let i=r[2].trim();return{type:`underline`,raw:r[0],text:i,tokens:n.inlineTokens(i)}}},addCommands(){return{setUnderline:()=>({commands:e})=>e.setMark(this.name),toggleUnderline:()=>({commands:e})=>e.toggleMark(this.name),unsetUnderline:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}});function iv(e={}){return new Mr({view(t){return new av(t,e)}})}var av=class{constructor(e,t){this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=t.width??1,this.color=t.color===!1?void 0:t.color||`black`,this.class=t.class,this.handlers=[`dragover`,`dragend`,`drop`,`dragleave`].map(t=>{let n=e=>{this[t](e)};return e.dom.addEventListener(t,n),{name:t,handler:n}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,n,r=this.editorView.dom,i=r.getBoundingClientRect(),a=i.width/r.offsetWidth,o=i.height/r.offsetHeight;if(t){let t=e.nodeBefore,r=e.nodeAfter;if(t||r){let e=this.editorView.nodeDOM(this.cursorPos-(t?t.nodeSize:0));if(e){let i=e.getBoundingClientRect(),a=t?i.bottom:i.top;t&&r&&(a=(a+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let s=this.width/2*o;n={left:i.left,right:i.right,top:a-s,bottom:a+s}}}}if(!n){let e=this.editorView.coordsAtPos(this.cursorPos),t=this.width/2*a;n={left:e.left-t,right:e.left+t,top:e.top,bottom:e.bottom}}let s=this.editorView.dom.offsetParent;this.element||(this.element=s.appendChild(document.createElement(`div`)),this.class&&(this.element.className=this.class),this.element.style.cssText=`position: absolute; z-index: 50; pointer-events: none;`,this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle(`prosemirror-dropcursor-block`,t),this.element.classList.toggle(`prosemirror-dropcursor-inline`,!t);let c,l;if(!s||s==document.body&&getComputedStyle(s).position==`static`)c=-pageXOffset,l=-pageYOffset;else{let e=s.getBoundingClientRect(),t=e.width/s.offsetWidth,n=e.height/s.offsetHeight;c=e.left-s.scrollLeft*t,l=e.top-s.scrollTop*n}this.element.style.left=(n.left-c)/a+`px`,this.element.style.top=(n.top-l)/o+`px`,this.element.style.width=(n.right-n.left)/a+`px`,this.element.style.height=(n.bottom-n.top)/o+`px`}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=n&&n.type.spec.disableDropCursor,i=typeof r==`function`?r(this.editorView,t,e):r;if(t&&!i){let e=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let t=Kn(this.editorView.state.doc,e,this.editorView.dragging.slice);t!=null&&(e=t)}this.setCursor(e),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}},ov=class e extends O{constructor(e){super(e,e)}map(t,n){let r=t.resolve(n.map(this.head));return e.valid(r)?new e(r):O.near(r)}content(){return D.empty}eq(t){return t instanceof e&&t.head==this.head}toJSON(){return{type:`gapcursor`,pos:this.head}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for GapCursor.fromJSON`);return new e(t.resolve(n.pos))}getBookmark(){return new sv(this.anchor)}static valid(e){let t=e.parent;if(t.inlineContent||!lv(e)||!uv(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(t,n,r=!1){search:for(;;){if(!r&&e.valid(t))return t;let i=t.pos,a=null;for(let r=t.depth;;r--){let o=t.node(r);if(n>0?t.indexAfter(r)<o.childCount:t.index(r)>0){a=o.child(n>0?t.indexAfter(r):t.index(r)-1);break}else if(r==0)return null;i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}for(;;){let o=n>0?a.firstChild:a.lastChild;if(!o){if(a.isAtom&&!a.isText&&!A.isSelectable(a)){t=t.doc.resolve(i+a.nodeSize*n),r=!1;continue search}break}a=o,i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}return null}}};ov.prototype.visible=!1,ov.findFrom=ov.findGapCursorFrom,O.jsonID(`gapcursor`,ov);var sv=class e{constructor(e){this.pos=e}map(t){return new e(t.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return ov.valid(t)?new ov(t):O.near(t)}};function cv(e){return e.isAtom||e.spec.isolating||e.spec.createGapCursor}function lv(e){for(let t=e.depth;t>=0;t--){let n=e.index(t),r=e.node(t);if(n==0){if(r.type.spec.isolating)return!0;continue}for(let e=r.child(n-1);;e=e.lastChild){if(e.childCount==0&&!e.inlineContent||cv(e.type))return!0;if(e.inlineContent)return!1}}return!0}function uv(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),r=e.node(t);if(n==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let e=r.child(n);;e=e.firstChild){if(e.childCount==0&&!e.inlineContent||cv(e.type))return!0;if(e.inlineContent)return!1}}return!0}function dv(){return new Mr({props:{decorations:gv,createSelectionBetween(e,t,n){return t.pos==n.pos&&ov.valid(n)?new ov(n):null},handleClick:mv,handleKeyDown:fv,handleDOMEvents:{beforeinput:hv}}})}var fv=ul({ArrowLeft:pv(`horiz`,-1),ArrowRight:pv(`horiz`,1),ArrowUp:pv(`vert`,-1),ArrowDown:pv(`vert`,1)});function pv(e,t){let n=e==`vert`?t>0?`down`:`up`:t>0?`right`:`left`;return function(e,r,i){let a=e.selection,o=t>0?a.$to:a.$from,s=a.empty;if(a instanceof k){if(!i.endOfTextblock(n)||o.depth==0)return!1;s=!1,o=e.doc.resolve(t>0?o.after():o.before())}let c=ov.findGapCursorFrom(o,t,s);return c?(r&&r(e.tr.setSelection(new ov(c))),!0):!1}}function mv(e,t,n){if(!e||!e.editable)return!1;let r=e.state.doc.resolve(t);if(!ov.valid(r))return!1;let i=e.posAtCoords({left:n.clientX,top:n.clientY});return i&&i.inside>-1&&A.isSelectable(e.state.doc.nodeAt(i.inside))?!1:(e.dispatch(e.state.tr.setSelection(new ov(r))),!0)}function hv(e,t){if(t.inputType!=`insertCompositionText`||!(e.state.selection instanceof ov))return!1;let{$from:n}=e.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!r)return!1;let i=E.empty;for(let e=r.length-1;e>=0;e--)i=E.from(r[e].createAndFill(null,i));let a=e.state.tr.replace(n.pos,n.pos,new D(i,0,0));return a.setSelection(k.near(a.doc.resolve(n.pos+1))),e.dispatch(a),!1}function gv(e){if(!(e.selection instanceof ov))return null;let t=document.createElement(`div`);return t.className=`ProseMirror-gapcursor`,lc.create(e.doc,[oc.widget(e.selection.head,t,{key:`gapcursor`})])}var _v=200,vv=function(){};vv.prototype.append=function(e){return e.length?(e=vv.from(e),!this.length&&e||e.length<_v&&this.leafAppend(e)||this.length<_v&&e.leafPrepend(this)||this.appendInner(e)):this},vv.prototype.prepend=function(e){return e.length?vv.from(e).append(this):this},vv.prototype.appendInner=function(e){return new bv(this,e)},vv.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?vv.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},vv.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},vv.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},vv.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var r=[];return this.forEach(function(t,n){return r.push(e(t,n))},t,n),r},vv.from=function(e){return e instanceof vv?e:e&&e.length?new yv(e):vv.empty};var yv=function(e){function t(t){e.call(this),this.values=t}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var n={length:{configurable:!0},depth:{configurable:!0}};return t.prototype.flatten=function(){return this.values},t.prototype.sliceInner=function(e,n){return e==0&&n==this.length?this:new t(this.values.slice(e,n))},t.prototype.getInner=function(e){return this.values[e]},t.prototype.forEachInner=function(e,t,n,r){for(var i=t;i<n;i++)if(e(this.values[i],r+i)===!1)return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){for(var i=t-1;i>=n;i--)if(e(this.values[i],r+i)===!1)return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=_v)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=_v)return new t(e.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(t.prototype,n),t}(vv);vv.empty=new yv([]);var bv=function(e){function t(t,n){e.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},t.prototype.getInner=function(e){return e<this.left.length?this.left.get(e):this.right.get(e-this.left.length)},t.prototype.forEachInner=function(e,t,n,r){var i=this.left.length;if(t<i&&this.left.forEachInner(e,t,Math.min(n,i),r)===!1||n>i&&this.right.forEachInner(e,Math.max(t-i,0),Math.min(this.length,n)-i,r+i)===!1)return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){var i=this.left.length;if(t>i&&this.right.forEachInvertedInner(e,t-i,Math.max(n,i)-i,r+i)===!1||n<i&&this.left.forEachInvertedInner(e,Math.min(t,i),n,r)===!1)return!1},t.prototype.sliceInner=function(e,t){if(e==0&&t==this.length)return this;var n=this.left.length;return t<=n?this.left.slice(e,t):e>=n?this.right.slice(e-n,t-n):this.left.slice(e,n).append(this.right.slice(0,t-n))},t.prototype.leafAppend=function(e){var n=this.right.leafAppend(e);if(n)return new t(this.left,n)},t.prototype.leafPrepend=function(e){var n=this.left.leafPrepend(e);if(n)return new t(n,this.right)},t.prototype.appendInner=function(e){return this.left.depth>=Math.max(this.right.depth,e.depth)+1?new t(this.left,new t(this.right,e)):new t(this,e)},t}(vv),xv=500,Sv=class e{constructor(e,t){this.items=e,this.eventCount=t}popEvent(t,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,a;n&&(i=this.remapping(r,this.items.length),a=i.maps.length);let o=t.tr,s,c,l=[],u=[];return this.items.forEach((t,n)=>{if(!t.step){i||(i=this.remapping(r,n+1),a=i.maps.length),a--,u.push(t);return}if(i){u.push(new wv(t.map));let e=t.step.map(i.slice(a)),n;e&&o.maybeStep(e).doc&&(n=o.mapping.maps[o.mapping.maps.length-1],l.push(new wv(n,void 0,void 0,l.length+u.length))),a--,n&&i.appendMap(n,a)}else o.maybeStep(t.step);if(t.selection)return s=i?t.selection.map(i.slice(a)):t.selection,c=new e(this.items.slice(0,r).append(u.reverse().concat(l)),this.eventCount-1),!1},this.items.length,0),{remaining:c,transform:o,selection:s}}addTransform(t,n,r,i){let a=[],o=this.eventCount,s=this.items,c=!i&&s.length?s.get(s.length-1):null;for(let e=0;e<t.steps.length;e++){let r=t.steps[e].invert(t.docs[e]),l=new wv(t.mapping.maps[e],r,n),u;(u=c&&c.merge(l))&&(l=u,e?a.pop():s=s.slice(0,s.length-1)),a.push(l),n&&=(o++,void 0),i||(c=l)}let l=o-r.depth;return l>Ev&&(s=Cv(s,l),o-=l),new e(s.append(a),o)}remapping(e,t){let n=new un;return this.items.forEach((t,r)=>{let i=t.mirrorOffset!=null&&r-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,i)},e,t),n}addMaps(t){return this.eventCount==0?this:new e(this.items.append(t.map(e=>new wv(e))),this.eventCount)}rebased(t,n){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-n),a=t.mapping,o=t.steps.length,s=this.eventCount;this.items.forEach(e=>{e.selection&&s--},i);let c=n;this.items.forEach(e=>{let n=a.getMirror(--c);if(n==null)return;o=Math.min(o,n);let i=a.maps[n];if(e.step){let o=t.steps[n].invert(t.docs[n]),l=e.selection&&e.selection.map(a.slice(c+1,n));l&&s++,r.push(new wv(i,o,l))}else r.push(new wv(i))},i);let l=[];for(let e=n;e<o;e++)l.push(new wv(a.maps[e]));let u=new e(this.items.slice(0,i).append(l).append(r),s);return u.emptyItemCount()>xv&&(u=u.compress(this.items.length-r.length)),u}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(t=this.items.length){let n=this.remapping(0,t),r=n.maps.length,i=[],a=0;return this.items.forEach((e,o)=>{if(o>=t)i.push(e),e.selection&&a++;else if(e.step){let t=e.step.map(n.slice(r)),o=t&&t.getMap();if(r--,o&&n.appendMap(o,r),t){let s=e.selection&&e.selection.map(n.slice(r));s&&a++;let c=new wv(o.invert(),t,s),l,u=i.length-1;(l=i.length&&i[u].merge(c))?i[u]=l:i.push(c)}}else e.map&&r--},this.items.length,0),new e(vv.from(i.reverse()),a)}};Sv.empty=new Sv(vv.empty,0);function Cv(e,t){let n;return e.forEach((e,r)=>{if(e.selection&&t--==0)return n=r,!1}),e.slice(n)}var wv=class e{constructor(e,t,n,r){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=r}merge(t){if(this.step&&t.step&&!t.selection){let n=t.step.merge(this.step);if(n)return new e(n.getMap().invert(),n,this.selection)}}},Tv=class{constructor(e,t,n,r,i){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=r,this.prevComposition=i}},Ev=20;function Dv(e,t,n,r){let i=n.getMeta(Iv),a;if(i)return i.historyState;n.getMeta(Lv)&&(e=new Tv(e.done,e.undone,null,0,-1));let o=n.getMeta(`appendedTransaction`);if(n.steps.length==0)return e;if(o&&o.getMeta(Iv))return o.getMeta(Iv).redo?new Tv(e.done.addTransform(n,void 0,r,Pv(t)),e.undone,kv(n.mapping.maps),e.prevTime,e.prevComposition):new Tv(e.done,e.undone.addTransform(n,void 0,r,Pv(t)),null,e.prevTime,e.prevComposition);if(n.getMeta(`addToHistory`)!==!1&&!(o&&o.getMeta(`addToHistory`)===!1)){let i=n.getMeta(`composition`),a=e.prevTime==0||!o&&e.prevComposition!=i&&(e.prevTime<(n.time||0)-r.newGroupDelay||!Ov(n,e.prevRanges)),s=o?Av(e.prevRanges,n.mapping):kv(n.mapping.maps);return new Tv(e.done.addTransform(n,a?t.selection.getBookmark():void 0,r,Pv(t)),Sv.empty,s,n.time,i??e.prevComposition)}else if(a=n.getMeta(`rebased`))return new Tv(e.done.rebased(n,a),e.undone.rebased(n,a),Av(e.prevRanges,n.mapping),e.prevTime,e.prevComposition);else return new Tv(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),Av(e.prevRanges,n.mapping),e.prevTime,e.prevComposition)}function Ov(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((e,r)=>{for(let i=0;i<t.length;i+=2)e<=t[i+1]&&r>=t[i]&&(n=!0)}),n}function kv(e){let t=[];for(let n=e.length-1;n>=0&&t.length==0;n--)e[n].forEach((e,n,r,i)=>t.push(r,i));return t}function Av(e,t){if(!e)return null;let n=[];for(let r=0;r<e.length;r+=2){let i=t.map(e[r],1),a=t.map(e[r+1],-1);i<=a&&n.push(i,a)}return n}function jv(e,t,n){let r=Pv(t),i=Iv.get(t).spec.config,a=(n?e.undone:e.done).popEvent(t,r);if(!a)return null;let o=a.selection.resolve(a.transform.doc),s=(n?e.done:e.undone).addTransform(a.transform,t.selection.getBookmark(),i,r),c=new Tv(n?s:a.remaining,n?a.remaining:s,null,0,-1);return a.transform.setSelection(o).setMeta(Iv,{redo:n,historyState:c})}var Mv=!1,Nv=null;function Pv(e){let t=e.plugins;if(Nv!=t){Mv=!1,Nv=t;for(let e=0;e<t.length;e++)if(t[e].spec.historyPreserveItems){Mv=!0;break}}return Mv}function Fv(e){return e.setMeta(Lv,!0)}var Iv=new Fr(`history`),Lv=new Fr(`closeHistory`);function Rv(e={}){return e={depth:e.depth||100,newGroupDelay:e.newGroupDelay||500},new Mr({key:Iv,state:{init(){return new Tv(Sv.empty,Sv.empty,null,0,-1)},apply(t,n,r){return Dv(n,r,t,e)}},config:e,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,r=n==`historyUndo`?Bv:n==`historyRedo`?Vv:null;return!r||!e.editable?!1:(t.preventDefault(),r(e.state,e.dispatch))}}}})}function zv(e,t){return(n,r)=>{let i=Iv.getState(n);if(!i||(e?i.undone:i.done).eventCount==0)return!1;if(r){let a=jv(i,n,e);a&&r(t?a.scrollIntoView():a)}return!0}}var Bv=zv(!1,!0),Vv=zv(!0,!0);N.create({name:`characterCount`,addOptions(){return{limit:null,mode:`textSize`,textCounter:e=>e.length,wordCounter:e=>e.split(` `).filter(e=>e!==``).length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=e=>{let t=e?.node||this.editor.state.doc;if((e?.mode||this.options.mode)===`textSize`){let e=t.textBetween(0,t.content.size,void 0,` `);return this.options.textCounter(e)}return t.nodeSize},this.storage.words=e=>{let t=e?.node||this.editor.state.doc,n=t.textBetween(0,t.content.size,` `,` `);return this.options.wordCounter(n)}},addProseMirrorPlugins(){let e=!1;return[new Mr({key:new Fr(`characterCount`),appendTransaction:(t,n,r)=>{if(e)return;let i=this.options.limit;if(i==null||i===0){e=!0;return}let a=this.storage.characters({node:r.doc});if(a>i){let t=a-i;console.warn(`[CharacterCount] Initial content exceeded limit of ${i} characters. Content was automatically trimmed.`);let n=r.tr.deleteRange(0,t);return e=!0,n}e=!0},filterTransaction:(e,t)=>{let n=this.options.limit;if(!e.docChanged||n===0||n==null)return!0;let r=this.storage.characters({node:t.doc}),i=this.storage.characters({node:e.doc});if(i<=n||r>n&&i>n&&i<=r)return!0;if(r>n&&i>n&&i>r||!e.getMeta(`paste`))return!1;let a=e.selection.$head.pos,o=a-(i-n),s=a;return e.deleteRange(o,s),!(this.storage.characters({node:e.doc})>n)}})]}});var Hv=N.create({name:`dropCursor`,addOptions(){return{color:`currentColor`,width:1,class:void 0}},addProseMirrorPlugins(){return[iv(this.options)]}});N.create({name:`focus`,addOptions(){return{className:`has-focus`,mode:`all`}},addProseMirrorPlugins(){return[new Mr({key:new Fr(`focus`),props:{decorations:({doc:e,selection:t})=>{let{isEditable:n,isFocused:r}=this.editor,{anchor:i}=t,a=[];if(!n||!r)return lc.create(e,[]);let o=0;this.options.mode===`deepest`&&e.descendants((e,t)=>{if(!e.isText){if(!(i>=t&&i<=t+e.nodeSize-1))return!1;o+=1}});let s=0;return e.descendants((e,t)=>{if(e.isText||!(i>=t&&i<=t+e.nodeSize-1))return!1;if(s+=1,this.options.mode===`deepest`&&o-s>0||this.options.mode===`shallowest`&&s>1)return this.options.mode===`deepest`;a.push(oc.node(t,t+e.nodeSize,{class:this.options.className}))}),lc.create(e,a)}}})]}});var Uv=N.create({name:`gapCursor`,addProseMirrorPlugins(){return[dv()]},extendNodeSchema(e){return{allowGapCursor:M(j(e,`allowGapCursor`,{name:e.name,options:e.options,storage:e.storage}))??null}}}),Wv=`placeholder`;function Gv(e){return e.replace(/\s+/g,`-`).replace(/[^a-zA-Z0-9-]/g,``).replace(/^[0-9-]+/,``).replace(/^-+/,``).toLowerCase()}var Kv=N.create({name:`placeholder`,addOptions(){return{emptyEditorClass:`is-editor-empty`,emptyNodeClass:`is-empty`,dataAttribute:Wv,placeholder:`Write something …`,showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){let e=this.options.dataAttribute?`data-${Gv(this.options.dataAttribute)}`:`data-${Wv}`;return[new Mr({key:new Fr(`placeholder`),props:{decorations:({doc:t,selection:n})=>{let r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:i}=n,a=[];if(!r)return null;let o=this.editor.isEmpty;return t.descendants((t,n)=>{let r=i>=n&&i<=n+t.nodeSize,s=!t.isLeaf&&_d(t);if(!t.type.isTextblock)return this.options.includeChildren;if((r||!this.options.showOnlyCurrent)&&s){let i=[this.options.emptyNodeClass];o&&i.push(this.options.emptyEditorClass);let s=oc.node(n,n+t.nodeSize,{class:i.join(` `),[e]:typeof this.options.placeholder==`function`?this.options.placeholder({editor:this.editor,node:t,pos:n,hasAnchor:r}):this.options.placeholder});a.push(s)}return this.options.includeChildren}),lc.create(t,a)}}})]}});N.create({name:`selection`,addOptions(){return{className:`selection`}},addProseMirrorPlugins(){let{editor:e,options:t}=this;return[new Mr({key:new Fr(`selection`),props:{decorations(n){return n.selection.empty||e.isFocused||!e.isEditable||vd(n.selection)||e.view.dragging?null:lc.create(n.doc,[oc.inline(n.selection.from,n.selection.to,{class:t.className})])}}})]}});function qv({types:e,node:t}){return t&&Array.isArray(e)&&e.includes(t.type)||t?.type===e}var Jv=N.create({name:`trailingNode`,addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){let e=new Fr(this.name),t=this.options.node||this.editor.schema.topNodeType.contentMatch.defaultType?.name||`paragraph`,n=Object.entries(this.editor.schema.nodes).map(([,e])=>e).filter(e=>(this.options.notAfter||[]).concat(t).includes(e.name));return[new Mr({key:e,appendTransaction:(n,r,i)=>{let{doc:a,tr:o,schema:s}=i,c=e.getState(i),l=a.content.size,u=s.nodes[t];if(!n.some(e=>e.getMeta(`skipTrailingNode`))&&c)return o.insert(l,u.create())},state:{init:(e,t)=>{let r=t.tr.doc.lastChild;return!qv({node:r,types:n})},apply:(e,t)=>{if(!e.docChanged||e.getMeta(`__uniqueIDTransaction`))return t;let r=e.doc.lastChild;return!qv({node:r,types:n})}}})]}}),Yv=N.create({name:`undoRedo`,addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:e,dispatch:t})=>Bv(e,t),redo:()=>({state:e,dispatch:t})=>Vv(e,t)}},addProseMirrorPlugins(){return[Rv(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),Xv=N.create({name:`starterKit`,addExtensions(){let e=[];return this.options.bold!==!1&&e.push(qm.configure(this.options.bold)),this.options.blockquote!==!1&&e.push(Hm.configure(this.options.blockquote)),this.options.bulletList!==!1&&e.push(T_.configure(this.options.bulletList)),this.options.code!==!1&&e.push(Xm.configure(this.options.code)),this.options.codeBlock!==!1&&e.push(Rm.configure(this.options.codeBlock)),this.options.document!==!1&&e.push(Zm.configure(this.options.document)),this.options.dropcursor!==!1&&e.push(Hv.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&e.push(Uv.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&e.push(Qm.configure(this.options.hardBreak)),this.options.heading!==!1&&e.push($m.configure(this.options.heading)),this.options.undoRedo!==!1&&e.push(Yv.configure(this.options.undoRedo)),this.options.horizontalRule!==!1&&e.push(eh.configure(this.options.horizontalRule)),this.options.italic!==!1&&e.push(ah.configure(this.options.italic)),this.options.listItem!==!1&&e.push(E_.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(L_.configure(this.options?.listKeymap)),this.options.link!==!1&&e.push(y_.configure(this.options?.link)),this.options.orderedList!==!1&&e.push(K_.configure(this.options.orderedList)),this.options.paragraph!==!1&&e.push(Q_.configure(this.options.paragraph)),this.options.strike!==!1&&e.push(tv.configure(this.options.strike)),this.options.text!==!1&&e.push(nv.configure(this.options.text)),this.options.underline!==!1&&e.push(rv.configure(this.options?.underline)),this.options.trailingNode!==!1&&e.push(Jv.configure(this.options?.trailingNode)),e}}),Zv,Qv;if(typeof WeakMap<`u`){let e=new WeakMap;Zv=t=>e.get(t),Qv=(t,n)=>(e.set(t,n),n)}else{let e=[],t=0;Zv=t=>{for(let n=0;n<e.length;n+=2)if(e[n]==t)return e[n+1]},Qv=(n,r)=>(t==10&&(t=0),e[t++]=n,e[t++]=r)}var $v=class{constructor(e,t,n,r){this.width=e,this.height=t,this.map=n,this.problems=r}findCell(e){for(let t=0;t<this.map.length;t++){let n=this.map[t];if(n!=e)continue;let r=t%this.width,i=t/this.width|0,a=r+1,o=i+1;for(let e=1;a<this.width&&this.map[t+e]==n;e++)a++;for(let e=1;o<this.height&&this.map[t+this.width*e]==n;e++)o++;return{left:r,top:i,right:a,bottom:o}}throw RangeError(`No cell with offset ${e} found`)}colCount(e){for(let t=0;t<this.map.length;t++)if(this.map[t]==e)return t%this.width;throw RangeError(`No cell with offset ${e} found`)}nextCell(e,t,n){let{left:r,right:i,top:a,bottom:o}=this.findCell(e);return t==`horiz`?(n<0?r==0:i==this.width)?null:this.map[a*this.width+(n<0?r-1:i)]:(n<0?a==0:o==this.height)?null:this.map[r+this.width*(n<0?a-1:o)]}rectBetween(e,t){let{left:n,right:r,top:i,bottom:a}=this.findCell(e),{left:o,right:s,top:c,bottom:l}=this.findCell(t);return{left:Math.min(n,o),top:Math.min(i,c),right:Math.max(r,s),bottom:Math.max(a,l)}}cellsInRect(e){let t=[],n={};for(let r=e.top;r<e.bottom;r++)for(let i=e.left;i<e.right;i++){let a=r*this.width+i,o=this.map[a];n[o]||(n[o]=!0,!(i==e.left&&i&&this.map[a-1]==o||r==e.top&&r&&this.map[a-this.width]==o)&&t.push(o))}return t}positionAt(e,t,n){for(let r=0,i=0;;r++){let a=i+n.child(r).nodeSize;if(r==e){let n=t+e*this.width,r=(e+1)*this.width;for(;n<r&&this.map[n]<i;)n++;return n==r?a-1:this.map[n]}i=a}}static get(e){return Zv(e)||Qv(e,ey(e))}};function ey(e){if(e.type.spec.tableRole!=`table`)throw RangeError(`Not a table node: `+e.type.name);let t=ty(e),n=e.childCount,r=[],i=0,a=null,o=[];for(let e=0,i=t*n;e<i;e++)r[e]=0;for(let s=0,c=0;s<n;s++){let l=e.child(s);c++;for(let e=0;;e++){for(;i<r.length&&r[i]!=0;)i++;if(e==l.childCount)break;let u=l.child(e),{colspan:d,rowspan:f,colwidth:p}=u.attrs;for(let e=0;e<f;e++){if(e+s>=n){(a||=[]).push({type:`overlong_rowspan`,pos:c,n:f-e});break}let l=i+e*t;for(let e=0;e<d;e++){r[l+e]==0?r[l+e]=c:(a||=[]).push({type:`collision`,row:s,pos:c,n:d-e});let n=p&&p[e];if(n){let r=(l+e)%t*2,i=o[r];i==null||i!=n&&o[r+1]==1?(o[r]=n,o[r+1]=1):i==n&&o[r+1]++}}}i+=d,c+=u.nodeSize}let u=(s+1)*t,d=0;for(;i<u;)r[i++]==0&&d++;d&&(a||=[]).push({type:`missing`,row:s,n:d}),c++}(t===0||n===0)&&(a||=[]).push({type:`zero_sized`});let s=new $v(t,n,r,a),c=!1;for(let e=0;!c&&e<o.length;e+=2)o[e]!=null&&o[e+1]<n&&(c=!0);return c&&ny(s,o,e),s}function ty(e){let t=-1,n=!1;for(let r=0;r<e.childCount;r++){let i=e.child(r),a=0;if(n)for(let t=0;t<r;t++){let n=e.child(t);for(let e=0;e<n.childCount;e++){let i=n.child(e);t+i.attrs.rowspan>r&&(a+=i.attrs.colspan)}}for(let e=0;e<i.childCount;e++){let t=i.child(e);a+=t.attrs.colspan,t.attrs.rowspan>1&&(n=!0)}t==-1?t=a:t!=a&&(t=Math.max(t,a))}return t}function ny(e,t,n){e.problems||=[];let r={};for(let i=0;i<e.map.length;i++){let a=e.map[i];if(r[a])continue;r[a]=!0;let o=n.nodeAt(a);if(!o)throw RangeError(`No cell with offset ${a} found`);let s=null,c=o.attrs;for(let n=0;n<c.colspan;n++){let r=t[(i+n)%e.width*2];r!=null&&(!c.colwidth||c.colwidth[n]!=r)&&((s||=ry(c))[n]=r)}s&&e.problems.unshift({type:`colwidth mismatch`,pos:a,colwidth:s})}}function ry(e){if(e.colwidth)return e.colwidth.slice();let t=[];for(let n=0;n<e.colspan;n++)t.push(0);return t}function iy(e){let t=e.cached.tableNodeTypes;if(!t){t=e.cached.tableNodeTypes={};for(let n in e.nodes){let r=e.nodes[n],i=r.spec.tableRole;i&&(t[i]=r)}}return t}var ay=new Fr(`selectingCells`);function oy(e){for(let t=e.depth-1;t>0;t--)if(e.node(t).type.spec.tableRole==`row`)return e.node(0).resolve(e.before(t+1));return null}function sy(e){for(let t=e.depth;t>0;t--){let n=e.node(t).type.spec.tableRole;if(n===`cell`||n===`header_cell`)return e.node(t)}return null}function cy(e){let t=e.selection.$head;for(let e=t.depth;e>0;e--)if(t.node(e).type.spec.tableRole==`row`)return!0;return!1}function ly(e){let t=e.selection;if(`$anchorCell`in t&&t.$anchorCell)return t.$anchorCell.pos>t.$headCell.pos?t.$anchorCell:t.$headCell;if(`node`in t&&t.node&&t.node.type.spec.tableRole==`cell`)return t.$anchor;let n=oy(t.$head)||uy(t.$head);if(n)return n;throw RangeError(`No cell found around position ${t.head}`)}function uy(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){let r=t.type.spec.tableRole;if(r==`cell`||r==`header_cell`)return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){let r=t.type.spec.tableRole;if(r==`cell`||r==`header_cell`)return e.doc.resolve(n-t.nodeSize)}}function dy(e){return e.parent.type.spec.tableRole==`row`&&!!e.nodeAfter}function fy(e){return e.node(0).resolve(e.pos+e.nodeAfter.nodeSize)}function py(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function my(e,t,n){let r=e.node(-1),i=$v.get(r),a=e.start(-1),o=i.nextCell(e.pos-a,t,n);return o==null?null:e.node(0).resolve(a+o)}function hy(e,t,n=1){let r={...e,colspan:e.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(t,n),r.colwidth.some(e=>e>0)||(r.colwidth=null)),r}function gy(e,t,n=1){let r={...e,colspan:e.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let e=0;e<n;e++)r.colwidth.splice(t,0,0)}return r}function _y(e,t,n){let r=iy(t.type.schema).header_cell;for(let i=0;i<e.height;i++)if(t.nodeAt(e.map[n+i*e.width]).type!=r)return!1;return!0}var vy=class e extends O{constructor(e,t=e){let n=e.node(-1),r=$v.get(n),i=e.start(-1),a=r.rectBetween(e.pos-i,t.pos-i),o=e.node(0),s=r.cellsInRect(a).filter(e=>e!=t.pos-i);s.unshift(t.pos-i);let c=s.map(e=>{let t=n.nodeAt(e);if(!t)throw RangeError(`No cell with offset ${e} found`);let r=i+e+1;return new pr(o.resolve(r),o.resolve(r+t.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=t}map(t,n){let r=t.resolve(n.map(this.$anchorCell.pos)),i=t.resolve(n.map(this.$headCell.pos));if(dy(r)&&dy(i)&&py(r,i)){let t=this.$anchorCell.node(-1)!=r.node(-1);return t&&this.isRowSelection()?e.rowSelection(r,i):t&&this.isColSelection()?e.colSelection(r,i):new e(r,i)}return k.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=$v.get(e),n=this.$anchorCell.start(-1),r=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),i={},a=[];for(let n=r.top;n<r.bottom;n++){let o=[];for(let a=n*t.width+r.left,s=r.left;s<r.right;s++,a++){let n=t.map[a];if(i[n])continue;i[n]=!0;let s=t.findCell(n),c=e.nodeAt(n);if(!c)throw RangeError(`No cell with offset ${n} found`);let l=r.left-s.left,u=s.right-r.right;if(l>0||u>0){let e=c.attrs;if(l>0&&(e=hy(e,0,l)),u>0&&(e=hy(e,e.colspan-u,u)),s.left<r.left){if(c=c.type.createAndFill(e),!c)throw RangeError(`Could not create cell with attrs ${JSON.stringify(e)}`)}else c=c.type.create(e,c.content)}if(s.top<r.top||s.bottom>r.bottom){let e={...c.attrs,rowspan:Math.min(s.bottom,r.bottom)-Math.max(s.top,r.top)};c=s.top<r.top?c.type.createAndFill(e):c.type.create(e,c.content)}o.push(c)}a.push(e.child(n).copy(E.from(o)))}let o=this.isColSelection()&&this.isRowSelection()?e:a;return new D(E.from(o),1,1)}replace(e,t=D.empty){let n=e.steps.length,r=this.ranges;for(let i=0;i<r.length;i++){let{$from:a,$to:o}=r[i],s=e.mapping.slice(n);e.replace(s.map(a.pos),s.map(o.pos),i?D.empty:t)}let i=O.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)),-1);i&&e.setSelection(i)}replaceWith(e,t){this.replace(e,new D(E.from(t),0,0))}forEachCell(e){let t=this.$anchorCell.node(-1),n=$v.get(t),r=this.$anchorCell.start(-1),i=n.cellsInRect(n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r));for(let n=0;n<i.length;n++)e(t.nodeAt(i[n]),r+i[n])}isColSelection(){let e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);if(Math.min(e,t)>0)return!1;let n=e+this.$anchorCell.nodeAfter.attrs.rowspan,r=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(n,r)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){let r=t.node(-1),i=$v.get(r),a=t.start(-1),o=i.findCell(t.pos-a),s=i.findCell(n.pos-a),c=t.node(0);return o.top<=s.top?(o.top>0&&(t=c.resolve(a+i.map[o.left])),s.bottom<i.height&&(n=c.resolve(a+i.map[i.width*(i.height-1)+s.right-1]))):(s.top>0&&(n=c.resolve(a+i.map[s.left])),o.bottom<i.height&&(t=c.resolve(a+i.map[i.width*(i.height-1)+o.right-1]))),new e(t,n)}isRowSelection(){let e=this.$anchorCell.node(-1),t=$v.get(e),n=this.$anchorCell.start(-1),r=t.colCount(this.$anchorCell.pos-n),i=t.colCount(this.$headCell.pos-n);if(Math.min(r,i)>0)return!1;let a=r+this.$anchorCell.nodeAfter.attrs.colspan,o=i+this.$headCell.nodeAfter.attrs.colspan;return Math.max(a,o)==t.width}eq(t){return t instanceof e&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){let r=t.node(-1),i=$v.get(r),a=t.start(-1),o=i.findCell(t.pos-a),s=i.findCell(n.pos-a),c=t.node(0);return o.left<=s.left?(o.left>0&&(t=c.resolve(a+i.map[o.top*i.width])),s.right<i.width&&(n=c.resolve(a+i.map[i.width*(s.top+1)-1]))):(s.left>0&&(n=c.resolve(a+i.map[s.top*i.width])),o.right<i.width&&(t=c.resolve(a+i.map[i.width*(o.top+1)-1]))),new e(t,n)}toJSON(){return{type:`cell`,anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(t,n){return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){return new e(t.resolve(n),t.resolve(r))}getBookmark(){return new yy(this.$anchorCell.pos,this.$headCell.pos)}};vy.prototype.visible=!1,O.jsonID(`cell`,vy);var yy=class e{constructor(e,t){this.anchor=e,this.head=t}map(t){return new e(t.map(this.anchor),t.map(this.head))}resolve(e){let t=e.resolve(this.anchor),n=e.resolve(this.head);return t.parent.type.spec.tableRole==`row`&&n.parent.type.spec.tableRole==`row`&&t.index()<t.parent.childCount&&n.index()<n.parent.childCount&&py(t,n)?new vy(t,n):O.near(n,1)}};function by(e){if(!(e.selection instanceof vy))return null;let t=[];return e.selection.forEachCell((e,n)=>{t.push(oc.node(n,n+e.nodeSize,{class:`selectedCell`}))}),lc.create(e.doc,t)}function xy({$from:e,$to:t}){if(e.pos==t.pos||e.pos<t.pos-6)return!1;let n=e.pos,r=t.pos,i=e.depth;for(;i>=0&&!(e.after(i+1)<e.end(i));i--,n++);for(let e=t.depth;e>=0&&!(t.before(e+1)>t.start(e));e--,r--);return n==r&&/row|table/.test(e.node(i).type.spec.tableRole)}function Sy({$from:e,$to:t}){let n,r;for(let t=e.depth;t>0;t--){let r=e.node(t);if(r.type.spec.tableRole===`cell`||r.type.spec.tableRole===`header_cell`){n=r;break}}for(let e=t.depth;e>0;e--){let n=t.node(e);if(n.type.spec.tableRole===`cell`||n.type.spec.tableRole===`header_cell`){r=n;break}}return n!==r&&t.parentOffset===0}function Cy(e,t,n){let r=(t||e).selection,i=(t||e).doc,a,o;if(r instanceof A&&(o=r.node.type.spec.tableRole)){if(o==`cell`||o==`header_cell`)a=vy.create(i,r.from);else if(o==`row`){let e=i.resolve(r.from+1);a=vy.rowSelection(e,e)}else if(!n){let e=$v.get(r.node),t=r.from+1,n=t+e.map[e.width*e.height-1];a=vy.create(i,t+1,n)}}else r instanceof k&&xy(r)?a=k.create(i,r.from):r instanceof k&&Sy(r)&&(a=k.create(i,r.$from.start(),r.$from.end()));return a&&(t||=e.tr).setSelection(a),t}var wy=new Fr(`fix-tables`);function Ty(e,t,n,r){let i=e.childCount,a=t.childCount;outer:for(let o=0,s=0;o<a;o++){let a=t.child(o);for(let t=s,r=Math.min(i,o+3);t<r;t++)if(e.child(t)==a){s=t+1,n+=a.nodeSize;continue outer}r(a,n),s<i&&e.child(s).sameMarkup(a)?Ty(e.child(s),a,n+1,r):a.nodesBetween(0,a.content.size,r,n+1),n+=a.nodeSize}}function Ey(e,t){let n,r=(t,r)=>{t.type.spec.tableRole==`table`&&(n=Dy(e,t,r,n))};return t?t.doc!=e.doc&&Ty(t.doc,e.doc,0,r):e.doc.descendants(r),n}function Dy(e,t,n,r){let i=$v.get(t);if(!i.problems)return r;r||=e.tr;let a=[];for(let e=0;e<i.height;e++)a.push(0);for(let e=0;e<i.problems.length;e++){let o=i.problems[e];if(o.type==`collision`){let e=t.nodeAt(o.pos);if(!e)continue;let i=e.attrs;for(let e=0;e<i.rowspan;e++)a[o.row+e]+=o.n;r.setNodeMarkup(r.mapping.map(n+1+o.pos),null,hy(i,i.colspan-o.n,o.n))}else if(o.type==`missing`)a[o.row]+=o.n;else if(o.type==`overlong_rowspan`){let e=t.nodeAt(o.pos);if(!e)continue;r.setNodeMarkup(r.mapping.map(n+1+o.pos),null,{...e.attrs,rowspan:e.attrs.rowspan-o.n})}else if(o.type==`colwidth mismatch`){let e=t.nodeAt(o.pos);if(!e)continue;r.setNodeMarkup(r.mapping.map(n+1+o.pos),null,{...e.attrs,colwidth:o.colwidth})}else if(o.type==`zero_sized`){let e=r.mapping.map(n);r.delete(e,e+t.nodeSize)}}let o,s;for(let e=0;e<a.length;e++)a[e]&&(o??=e,s=e);for(let c=0,l=n+1;c<i.height;c++){let n=t.child(c),i=l+n.nodeSize,u=a[c];if(u>0){let t=`cell`;n.firstChild&&(t=n.firstChild.type.spec.tableRole);let a=[];for(let n=0;n<u;n++){let n=iy(e.schema)[t].createAndFill();n&&a.push(n)}let d=(c==0||o==c-1)&&s==c?l+1:i-1;r.insert(r.mapping.map(d),a)}l=i}return r.setMeta(wy,{fixTables:!0})}function Oy(e){let t=e.selection,n=ly(e),r=n.node(-1),i=n.start(-1),a=$v.get(r);return{...t instanceof vy?a.rectBetween(t.$anchorCell.pos-i,t.$headCell.pos-i):a.findCell(n.pos-i),tableStart:i,map:a,table:r}}function ky(e,{map:t,tableStart:n,table:r},i){let a=i>0?-1:0;_y(t,r,i+a)&&(a=i==0||i==t.width?null:0);for(let o=0;o<t.height;o++){let s=o*t.width+i;if(i>0&&i<t.width&&t.map[s-1]==t.map[s]){let a=t.map[s],c=r.nodeAt(a);e.setNodeMarkup(e.mapping.map(n+a),null,gy(c.attrs,i-t.colCount(a))),o+=c.attrs.rowspan-1}else{let c=a==null?iy(r.type.schema).cell:r.nodeAt(t.map[s+a]).type,l=t.positionAt(o,i,r);e.insert(e.mapping.map(n+l),c.createAndFill())}}return e}function Ay(e,t){if(!cy(e))return!1;if(t){let n=Oy(e);t(ky(e.tr,n,n.left))}return!0}function jy(e,t){if(!cy(e))return!1;if(t){let n=Oy(e);t(ky(e.tr,n,n.right))}return!0}function My(e,{map:t,table:n,tableStart:r},i){let a=e.mapping.maps.length;for(let o=0;o<t.height;){let s=o*t.width+i,c=t.map[s],l=n.nodeAt(c),u=l.attrs;if(i>0&&t.map[s-1]==c||i<t.width-1&&t.map[s+1]==c)e.setNodeMarkup(e.mapping.slice(a).map(r+c),null,hy(u,i-t.colCount(c)));else{let t=e.mapping.slice(a).map(r+c);e.delete(t,t+l.nodeSize)}o+=u.rowspan}}function Ny(e,t){if(!cy(e))return!1;if(t){let n=Oy(e),r=e.tr;if(n.left==0&&n.right==n.map.width)return!1;for(let e=n.right-1;My(r,n,e),e!=n.left;e--){let e=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!e)throw RangeError(`No table found`);n.table=e,n.map=$v.get(e)}t(r)}return!0}function Py(e,t,n){let r=iy(t.type.schema).header_cell;for(let i=0;i<e.width;i++)if(t.nodeAt(e.map[i+n*e.width])?.type!=r)return!1;return!0}function Fy(e,{map:t,tableStart:n,table:r},i){let a=n;for(let e=0;e<i;e++)a+=r.child(e).nodeSize;let o=[],s=i>0?-1:0;Py(t,r,i+s)&&(s=i==0||i==t.height?null:0);for(let a=0,c=t.width*i;a<t.width;a++,c++)if(i>0&&i<t.height&&t.map[c]==t.map[c-t.width]){let i=t.map[c],o=r.nodeAt(i).attrs;e.setNodeMarkup(n+i,null,{...o,rowspan:o.rowspan+1}),a+=o.colspan-1}else{let e=(s==null?iy(r.type.schema).cell:r.nodeAt(t.map[c+s*t.width])?.type)?.createAndFill();e&&o.push(e)}return e.insert(a,iy(r.type.schema).row.create(null,o)),e}function Iy(e,t){if(!cy(e))return!1;if(t){let n=Oy(e);t(Fy(e.tr,n,n.top))}return!0}function Ly(e,t){if(!cy(e))return!1;if(t){let n=Oy(e);t(Fy(e.tr,n,n.bottom))}return!0}function Ry(e,{map:t,table:n,tableStart:r},i){let a=0;for(let e=0;e<i;e++)a+=n.child(e).nodeSize;let o=a+n.child(i).nodeSize,s=e.mapping.maps.length;e.delete(a+r,o+r);let c=new Set;for(let a=0,o=i*t.width;a<t.width;a++,o++){let l=t.map[o];if(!c.has(l)){if(c.add(l),i>0&&l==t.map[o-t.width]){let t=n.nodeAt(l).attrs;e.setNodeMarkup(e.mapping.slice(s).map(l+r),null,{...t,rowspan:t.rowspan-1}),a+=t.colspan-1}else if(i<t.height&&l==t.map[o+t.width]){let o=n.nodeAt(l),c=o.attrs,u=o.type.create({...c,rowspan:o.attrs.rowspan-1},o.content),d=t.positionAt(i+1,a,n);e.insert(e.mapping.slice(s).map(r+d),u),a+=c.colspan-1}}}}function zy(e,t){if(!cy(e))return!1;if(t){let n=Oy(e),r=e.tr;if(n.top==0&&n.bottom==n.map.height)return!1;for(let e=n.bottom-1;Ry(r,n,e),e!=n.top;e--){let e=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!e)throw RangeError(`No table found`);n.table=e,n.map=$v.get(n.table)}t(r)}return!0}function By(e){let t=e.content;return t.childCount==1&&t.child(0).isTextblock&&t.child(0).childCount==0}function Vy({width:e,height:t,map:n},r){let i=r.top*e+r.left,a=i,o=(r.bottom-1)*e+r.left,s=i+(r.right-r.left-1);for(let t=r.top;t<r.bottom;t++){if(r.left>0&&n[a]==n[a-1]||r.right<e&&n[s]==n[s+1])return!0;a+=e,s+=e}for(let a=r.left;a<r.right;a++){if(r.top>0&&n[i]==n[i-e]||r.bottom<t&&n[o]==n[o+e])return!0;i++,o++}return!1}function Hy(e,t){let n=e.selection;if(!(n instanceof vy)||n.$anchorCell.pos==n.$headCell.pos)return!1;let r=Oy(e),{map:i}=r;if(Vy(i,r))return!1;if(t){let n=e.tr,a={},o=E.empty,s,c;for(let e=r.top;e<r.bottom;e++)for(let t=r.left;t<r.right;t++){let l=i.map[e*i.width+t],u=r.table.nodeAt(l);if(!(a[l]||!u))if(a[l]=!0,s==null)s=l,c=u;else{By(u)||(o=o.append(u.content));let e=n.mapping.map(l+r.tableStart);n.delete(e,e+u.nodeSize)}}if(s==null||c==null)return!0;if(n.setNodeMarkup(s+r.tableStart,null,{...gy(c.attrs,c.attrs.colspan,r.right-r.left-c.attrs.colspan),rowspan:r.bottom-r.top}),o.size>0){let e=s+1+c.content.size,t=By(c)?s+1:e;n.replaceWith(t+r.tableStart,e+r.tableStart,o)}n.setSelection(new vy(n.doc.resolve(s+r.tableStart))),t(n)}return!0}function Uy(e,t){let n=iy(e.schema);return Wy(({node:e})=>n[e.type.spec.tableRole])(e,t)}function Wy(e){return(t,n)=>{let r=t.selection,i,a;if(r instanceof vy){if(r.$anchorCell.pos!=r.$headCell.pos)return!1;i=r.$anchorCell.nodeAfter,a=r.$anchorCell.pos}else{if(i=sy(r.$from),!i)return!1;a=oy(r.$from)?.pos}if(i==null||a==null||i.attrs.colspan==1&&i.attrs.rowspan==1)return!1;if(n){let o=i.attrs,s=[],c=o.colwidth;o.rowspan>1&&(o={...o,rowspan:1}),o.colspan>1&&(o={...o,colspan:1});let l=Oy(t),u=t.tr;for(let e=0;e<l.right-l.left;e++)s.push(c?{...o,colwidth:c&&c[e]?[c[e]]:null}:o);let d;for(let t=l.top;t<l.bottom;t++){let n=l.map.positionAt(t,l.left,l.table);t==l.top&&(n+=i.nodeSize);for(let r=l.left,a=0;r<l.right;r++,a++)r==l.left&&t==l.top||u.insert(d=u.mapping.map(n+l.tableStart,1),e({node:i,row:t,col:r}).createAndFill(s[a]))}u.setNodeMarkup(a,e({node:i,row:l.top,col:l.left}),s[0]),r instanceof vy&&u.setSelection(new vy(u.doc.resolve(r.$anchorCell.pos),d?u.doc.resolve(d):void 0)),n(u)}return!0}}function Gy(e,t){return function(n,r){if(!cy(n))return!1;let i=ly(n);if(i.nodeAfter.attrs[e]===t)return!1;if(r){let a=n.tr;n.selection instanceof vy?n.selection.forEachCell((n,r)=>{n.attrs[e]!==t&&a.setNodeMarkup(r,null,{...n.attrs,[e]:t})}):a.setNodeMarkup(i.pos,null,{...i.nodeAfter.attrs,[e]:t}),r(a)}return!0}}function Ky(e){return function(t,n){if(!cy(t))return!1;if(n){let r=iy(t.schema),i=Oy(t),a=t.tr,o=i.map.cellsInRect(e==`column`?{left:i.left,top:0,right:i.right,bottom:i.map.height}:e==`row`?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),s=o.map(e=>i.table.nodeAt(e));for(let e=0;e<o.length;e++)s[e].type==r.header_cell&&a.setNodeMarkup(i.tableStart+o[e],r.cell,s[e].attrs);if(a.steps.length===0)for(let e=0;e<o.length;e++)a.setNodeMarkup(i.tableStart+o[e],r.header_cell,s[e].attrs);n(a)}return!0}}function qy(e,t,n){let r=t.map.cellsInRect({left:0,top:0,right:e==`row`?t.map.width:1,bottom:e==`column`?t.map.height:1});for(let e=0;e<r.length;e++){let i=t.table.nodeAt(r[e]);if(i&&i.type!==n.header_cell)return!1}return!0}function Jy(e,t){return t||={useDeprecatedLogic:!1},t.useDeprecatedLogic?Ky(e):function(t,n){if(!cy(t))return!1;if(n){let r=iy(t.schema),i=Oy(t),a=t.tr,o=qy(`row`,i,r),s=qy(`column`,i,r),c=(e===`column`?o:e===`row`&&s)?1:0,l=e==`column`?{left:0,top:c,right:1,bottom:i.map.height}:e==`row`?{left:c,top:0,right:i.map.width,bottom:1}:i,u=e==`column`?s?r.cell:r.header_cell:e==`row`?o?r.cell:r.header_cell:r.cell;i.map.cellsInRect(l).forEach(e=>{let t=e+i.tableStart,n=a.doc.nodeAt(t);n&&a.setNodeMarkup(t,u,n.attrs)}),n(a)}return!0}}Jy(`row`,{useDeprecatedLogic:!0}),Jy(`column`,{useDeprecatedLogic:!0});var Yy=Jy(`cell`,{useDeprecatedLogic:!0});function Xy(e,t){if(t<0){let t=e.nodeBefore;if(t)return e.pos-t.nodeSize;for(let t=e.index(-1)-1,n=e.before();t>=0;t--){let r=e.node(-1).child(t),i=r.lastChild;if(i)return n-1-i.nodeSize;n-=r.nodeSize}}else{if(e.index()<e.parent.childCount-1)return e.pos+e.nodeAfter.nodeSize;let t=e.node(-1);for(let n=e.indexAfter(-1),r=e.after();n<t.childCount;n++){let e=t.child(n);if(e.childCount)return r+1;r+=e.nodeSize}}return null}function Zy(e){return function(t,n){if(!cy(t))return!1;let r=Xy(ly(t),e);if(r==null)return!1;if(n){let e=t.doc.resolve(r);n(t.tr.setSelection(k.between(e,fy(e))).scrollIntoView())}return!0}}function Qy(e,t){let n=e.selection.$anchor;for(let r=n.depth;r>0;r--)if(n.node(r).type.spec.tableRole==`table`)return t&&t(e.tr.delete(n.before(r),n.after(r)).scrollIntoView()),!0;return!1}function $y(e,t){let n=e.selection;if(!(n instanceof vy))return!1;if(t){let r=e.tr,i=iy(e.schema).cell.createAndFill().content;n.forEachCell((e,t)=>{e.content.eq(i)||r.replace(r.mapping.map(t+1),r.mapping.map(t+e.nodeSize-1),new D(i,0,0))}),r.docChanged&&t(r)}return!0}function eb(e){if(e.size===0)return null;let{content:t,openStart:n,openEnd:r}=e;for(;t.childCount==1&&(n>0&&r>0||t.child(0).type.spec.tableRole==`table`);)n--,r--,t=t.child(0).content;let i=t.child(0),a=i.type.spec.tableRole,o=i.type.schema,s=[];if(a==`row`)for(let e=0;e<t.childCount;e++){let i=t.child(e).content,a=e?0:Math.max(0,n-1),c=e<t.childCount-1?0:Math.max(0,r-1);(a||c)&&(i=nb(iy(o).row,new D(i,a,c)).content),s.push(i)}else if(a==`cell`||a==`header_cell`)s.push(n||r?nb(iy(o).row,new D(t,n,r)).content:t);else return null;return tb(o,s)}function tb(e,t){let n=[];for(let e=0;e<t.length;e++){let r=t[e];for(let t=r.childCount-1;t>=0;t--){let{rowspan:i,colspan:a}=r.child(t).attrs;for(let t=e;t<e+i;t++)n[t]=(n[t]||0)+a}}let r=0;for(let e=0;e<n.length;e++)r=Math.max(r,n[e]);for(let i=0;i<n.length;i++)if(i>=t.length&&t.push(E.empty),n[i]<r){let a=iy(e).cell.createAndFill(),o=[];for(let e=n[i];e<r;e++)o.push(a);t[i]=t[i].append(E.from(o))}return{height:t.length,width:r,rows:t}}function nb(e,t){let n=e.createAndFill();return new dr(n).replace(0,n.content.size,t).doc}function rb({width:e,height:t,rows:n},r,i){if(e!=r){let t=[],i=[];for(let e=0;e<n.length;e++){let a=n[e],o=[];for(let n=t[e]||0,i=0;n<r;i++){let s=a.child(i%a.childCount);n+s.attrs.colspan>r&&(s=s.type.createChecked(hy(s.attrs,s.attrs.colspan,n+s.attrs.colspan-r),s.content)),o.push(s),n+=s.attrs.colspan;for(let n=1;n<s.attrs.rowspan;n++)t[e+n]=(t[e+n]||0)+s.attrs.colspan}i.push(E.from(o))}n=i,e=r}if(t!=i){let e=[];for(let r=0,a=0;r<i;r++,a++){let o=[],s=n[a%t];for(let e=0;e<s.childCount;e++){let t=s.child(e);r+t.attrs.rowspan>i&&(t=t.type.create({...t.attrs,rowspan:Math.max(1,i-t.attrs.rowspan)},t.content)),o.push(t)}e.push(E.from(o))}n=e,t=i}return{width:e,height:t,rows:n}}function ib(e,t,n,r,i,a,o){let s=e.doc.type.schema,c=iy(s),l,u;if(i>t.width)for(let a=0,s=0;a<t.height;a++){let d=n.child(a);s+=d.nodeSize;let f=[],p;p=d.lastChild==null||d.lastChild.type==c.cell?l||=c.cell.createAndFill():u||=c.header_cell.createAndFill();for(let e=t.width;e<i;e++)f.push(p);e.insert(e.mapping.slice(o).map(s-1+r),f)}if(a>t.height){let s=[];for(let e=0,r=(t.height-1)*t.width;e<Math.max(t.width,i);e++){let i=e>=t.width?!1:n.nodeAt(t.map[r+e]).type==c.header_cell;s.push(i?u||=c.header_cell.createAndFill():l||=c.cell.createAndFill())}let d=c.row.create(null,E.from(s)),f=[];for(let e=t.height;e<a;e++)f.push(d);e.insert(e.mapping.slice(o).map(r+n.nodeSize-2),f)}return!!(l||u)}function ab(e,t,n,r,i,a,o,s){if(o==0||o==t.height)return!1;let c=!1;for(let l=i;l<a;l++){let i=o*t.width+l,a=t.map[i];if(t.map[i-t.width]==a){c=!0;let i=n.nodeAt(a),{top:u,left:d}=t.findCell(a);e.setNodeMarkup(e.mapping.slice(s).map(a+r),null,{...i.attrs,rowspan:o-u}),e.insert(e.mapping.slice(s).map(t.positionAt(o,d,n)),i.type.createAndFill({...i.attrs,rowspan:u+i.attrs.rowspan-o})),l+=i.attrs.colspan-1}}return c}function ob(e,t,n,r,i,a,o,s){if(o==0||o==t.width)return!1;let c=!1;for(let l=i;l<a;l++){let i=l*t.width+o,a=t.map[i];if(t.map[i-1]==a){c=!0;let i=n.nodeAt(a),u=t.colCount(a),d=e.mapping.slice(s).map(a+r);e.setNodeMarkup(d,null,hy(i.attrs,o-u,i.attrs.colspan-(o-u))),e.insert(d+i.nodeSize,i.type.createAndFill(hy(i.attrs,0,o-u))),l+=i.attrs.rowspan-1}}return c}function sb(e,t,n,r,i){let a=n?e.doc.nodeAt(n-1):e.doc;if(!a)throw Error(`No table found`);let o=$v.get(a),{top:s,left:c}=r,l=c+i.width,u=s+i.height,d=e.tr,f=0;function p(){if(a=n?d.doc.nodeAt(n-1):d.doc,!a)throw Error(`No table found`);o=$v.get(a),f=d.mapping.maps.length}ib(d,o,a,n,l,u,f)&&p(),ab(d,o,a,n,c,l,s,f)&&p(),ab(d,o,a,n,c,l,u,f)&&p(),ob(d,o,a,n,s,u,c,f)&&p(),ob(d,o,a,n,s,u,l,f)&&p();for(let e=s;e<u;e++){let t=o.positionAt(e,c,a),r=o.positionAt(e,l,a);d.replace(d.mapping.slice(f).map(t+n),d.mapping.slice(f).map(r+n),new D(i.rows[e-s],0,0))}p(),d.setSelection(new vy(d.doc.resolve(n+o.positionAt(s,c,a)),d.doc.resolve(n+o.positionAt(u-1,l-1,a)))),t(d)}var cb=ul({ArrowLeft:ub(`horiz`,-1),ArrowRight:ub(`horiz`,1),ArrowUp:ub(`vert`,-1),ArrowDown:ub(`vert`,1),"Shift-ArrowLeft":db(`horiz`,-1),"Shift-ArrowRight":db(`horiz`,1),"Shift-ArrowUp":db(`vert`,-1),"Shift-ArrowDown":db(`vert`,1),Backspace:$y,"Mod-Backspace":$y,Delete:$y,"Mod-Delete":$y});function lb(e,t,n){return n.eq(e.selection)?!1:(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function ub(e,t){return(n,r,i)=>{if(!i)return!1;let a=n.selection;if(a instanceof vy)return lb(n,r,O.near(a.$headCell,t));if(e!=`horiz`&&!a.empty)return!1;let o=hb(i,e,t);if(o==null)return!1;if(e==`horiz`)return lb(n,r,O.near(n.doc.resolve(a.head+t),t));{let i=n.doc.resolve(o),a=my(i,e,t),s;return s=a?O.near(a,1):t<0?O.near(n.doc.resolve(i.before(-1)),-1):O.near(n.doc.resolve(i.after(-1)),1),lb(n,r,s)}}}function db(e,t){return(n,r,i)=>{if(!i)return!1;let a=n.selection,o;if(a instanceof vy)o=a;else{let r=hb(i,e,t);if(r==null)return!1;o=new vy(n.doc.resolve(r))}let s=my(o.$headCell,e,t);return s?lb(n,r,new vy(o.$anchorCell,s)):!1}}function fb(e,t){let n=e.state.doc,r=oy(n.resolve(t));return r?(e.dispatch(e.state.tr.setSelection(new vy(r))),!0):!1}function pb(e,t,n){if(!cy(e.state))return!1;let r=eb(n),i=e.state.selection;if(i instanceof vy){r||={width:1,height:1,rows:[E.from(nb(iy(e.state.schema).cell,n))]};let t=i.$anchorCell.node(-1),a=i.$anchorCell.start(-1),o=$v.get(t).rectBetween(i.$anchorCell.pos-a,i.$headCell.pos-a);return r=rb(r,o.right-o.left,o.bottom-o.top),sb(e.state,e.dispatch,a,o,r),!0}else if(r){let t=ly(e.state),n=t.start(-1);return sb(e.state,e.dispatch,n,$v.get(t.node(-1)).findCell(t.pos-n),r),!0}else return!1}function mb(e,t){if(t.button!=0||t.ctrlKey||t.metaKey)return;let n=gb(e,t.target),r;if(t.shiftKey&&e.state.selection instanceof vy)i(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&n&&(r=oy(e.state.selection.$anchor))!=null&&_b(e,t)?.pos!=r.pos)i(r,t),t.preventDefault();else if(!n)return;function i(t,n){let r=_b(e,n),i=ay.getState(e.state)==null;if(!r||!py(t,r))if(i)r=t;else return;let a=new vy(t,r);if(i||!e.state.selection.eq(a)){let n=e.state.tr.setSelection(a);i&&n.setMeta(ay,t.pos),e.dispatch(n)}}function a(){e.root.removeEventListener(`mouseup`,a),e.root.removeEventListener(`dragstart`,a),e.root.removeEventListener(`mousemove`,o),ay.getState(e.state)!=null&&e.dispatch(e.state.tr.setMeta(ay,-1))}function o(r){let o=r,s=ay.getState(e.state),c;if(s!=null)c=e.state.doc.resolve(s);else if(gb(e,o.target)!=n&&(c=_b(e,t),!c))return a();c&&i(c,o)}e.root.addEventListener(`mouseup`,a),e.root.addEventListener(`dragstart`,a),e.root.addEventListener(`mousemove`,o)}function hb(e,t,n){if(!(e.state.selection instanceof k))return null;let{$head:r}=e.state.selection;for(let i=r.depth-1;i>=0;i--){let a=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:a.childCount))return null;if(a.type.spec.tableRole==`cell`||a.type.spec.tableRole==`header_cell`){let a=r.before(i),o=t==`vert`?n>0?`down`:`up`:n>0?`right`:`left`;return e.endOfTextblock(o)?a:null}}return null}function gb(e,t){for(;t&&t!=e.dom;t=t.parentNode)if(t.nodeName==`TD`||t.nodeName==`TH`)return t;return null}function _b(e,t){let n=e.posAtCoords({left:t.clientX,top:t.clientY});if(!n)return null;let{inside:r,pos:i}=n;return r>=0&&oy(e.state.doc.resolve(r))||oy(e.state.doc.resolve(i))}var vb=class{constructor(e,t){this.node=e,this.defaultCellMinWidth=t,this.dom=document.createElement(`div`),this.dom.className=`tableWrapper`,this.table=this.dom.appendChild(document.createElement(`table`)),this.table.style.setProperty(`--default-cell-min-width`,`${t}px`),this.colgroup=this.table.appendChild(document.createElement(`colgroup`)),yb(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement(`tbody`))}update(e){return e.type==this.node.type?(this.node=e,yb(e,this.colgroup,this.table,this.defaultCellMinWidth),!0):!1}ignoreMutation(e){return e.type==`attributes`&&(e.target==this.table||this.colgroup.contains(e.target))}};function yb(e,t,n,r,i,a){let o=0,s=!0,c=t.firstChild,l=e.firstChild;if(l){for(let e=0,n=0;e<l.childCount;e++){let{colspan:u,colwidth:d}=l.child(e).attrs;for(let e=0;e<u;e++,n++){let l=i==n?a:d&&d[e],u=l?l+`px`:``;if(o+=l||r,l||(s=!1),c)c.style.width!=u&&(c.style.width=u),c=c.nextSibling;else{let e=document.createElement(`col`);e.style.width=u,t.appendChild(e)}}}for(;c;){var u;let e=c.nextSibling;(u=c.parentNode)==null||u.removeChild(c),c=e}s?(n.style.width=o+`px`,n.style.minWidth=``):(n.style.width=``,n.style.minWidth=o+`px`)}}var bb=new Fr(`tableColumnResizing`);function xb({handleWidth:e=5,cellMinWidth:t=25,defaultCellMinWidth:n=100,View:r=vb,lastColumnResizable:i=!0}={}){let a=new Mr({key:bb,state:{init(e,t){var i;let o=(i=a.spec)==null||(i=i.props)==null?void 0:i.nodeViews,s=iy(t.schema).table.name;return r&&o&&(o[s]=(e,t)=>new r(e,n,t)),new Sb(-1,!1)},apply(e,t){return t.apply(e)}},props:{attributes:e=>{let t=bb.getState(e);return t&&t.activeHandle>-1?{class:`resize-cursor`}:{}},handleDOMEvents:{mousemove:(t,n)=>{Cb(t,n,e,i)},mouseleave:e=>{wb(e)},mousedown:(e,r)=>{Tb(e,r,t,n)}},decorations:e=>{let t=bb.getState(e);if(t&&t.activeHandle>-1)return Pb(e,t.activeHandle)},nodeViews:{}}});return a}var Sb=class e{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(t){let n=this,r=t.getMeta(bb);if(r&&r.setHandle!=null)return new e(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new e(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&t.docChanged){let r=t.mapping.map(n.activeHandle,-1);return dy(t.doc.resolve(r))||(r=-1),new e(r,n.dragging)}return n}};function Cb(e,t,n,r){if(!e.editable)return;let i=bb.getState(e.state);if(i&&!i.dragging){let a=Db(t.target),o=-1;if(a){let{left:r,right:i}=a.getBoundingClientRect();t.clientX-r<=n?o=Ob(e,t,`left`,n):i-t.clientX<=n&&(o=Ob(e,t,`right`,n))}if(o!=i.activeHandle){if(!r&&o!==-1){let t=e.state.doc.resolve(o),n=t.node(-1),r=$v.get(n),i=t.start(-1);if(r.colCount(t.pos-i)+t.nodeAfter.attrs.colspan-1==r.width-1)return}Ab(e,o)}}}function wb(e){if(!e.editable)return;let t=bb.getState(e.state);t&&t.activeHandle>-1&&!t.dragging&&Ab(e,-1)}function Tb(e,t,n,r){if(!e.editable)return!1;let i=e.dom.ownerDocument.defaultView??window,a=bb.getState(e.state);if(!a||a.activeHandle==-1||a.dragging)return!1;let o=e.state.doc.nodeAt(a.activeHandle),s=Eb(e,a.activeHandle,o.attrs);e.dispatch(e.state.tr.setMeta(bb,{setDragging:{startX:t.clientX,startWidth:s}}));function c(t){i.removeEventListener(`mouseup`,c),i.removeEventListener(`mousemove`,l);let r=bb.getState(e.state);r?.dragging&&(jb(e,r.activeHandle,kb(r.dragging,t,n)),e.dispatch(e.state.tr.setMeta(bb,{setDragging:null})))}function l(t){if(!t.which)return c(t);let i=bb.getState(e.state);if(i&&i.dragging){let a=kb(i.dragging,t,n);Mb(e,i.activeHandle,a,r)}}return Mb(e,a.activeHandle,s,r),i.addEventListener(`mouseup`,c),i.addEventListener(`mousemove`,l),t.preventDefault(),!0}function Eb(e,t,{colspan:n,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let a=e.domAtPos(t),o=a.node.childNodes[a.offset].offsetWidth,s=n;if(r)for(let e=0;e<n;e++)r[e]&&(o-=r[e],s--);return o/s}function Db(e){for(;e&&e.nodeName!=`TD`&&e.nodeName!=`TH`;)e=e.classList&&e.classList.contains(`ProseMirror`)?null:e.parentNode;return e}function Ob(e,t,n,r){let i=n==`right`?-r:r,a=e.posAtCoords({left:t.clientX+i,top:t.clientY});if(!a)return-1;let{pos:o}=a,s=oy(e.state.doc.resolve(o));if(!s)return-1;if(n==`right`)return s.pos;let c=$v.get(s.node(-1)),l=s.start(-1),u=c.map.indexOf(s.pos-l);return u%c.width==0?-1:l+c.map[u-1]}function kb(e,t,n){let r=t.clientX-e.startX;return Math.max(n,e.startWidth+r)}function Ab(e,t){e.dispatch(e.state.tr.setMeta(bb,{setHandle:t}))}function jb(e,t,n){let r=e.state.doc.resolve(t),i=r.node(-1),a=$v.get(i),o=r.start(-1),s=a.colCount(r.pos-o)+r.nodeAfter.attrs.colspan-1,c=e.state.tr;for(let e=0;e<a.height;e++){let t=e*a.width+s;if(e&&a.map[t]==a.map[t-a.width])continue;let r=a.map[t],l=i.nodeAt(r).attrs,u=l.colspan==1?0:s-a.colCount(r);if(l.colwidth&&l.colwidth[u]==n)continue;let d=l.colwidth?l.colwidth.slice():Nb(l.colspan);d[u]=n,c.setNodeMarkup(o+r,null,{...l,colwidth:d})}c.docChanged&&e.dispatch(c)}function Mb(e,t,n,r){let i=e.state.doc.resolve(t),a=i.node(-1),o=i.start(-1),s=$v.get(a).colCount(i.pos-o)+i.nodeAfter.attrs.colspan-1,c=e.domAtPos(i.start(-1)).node;for(;c&&c.nodeName!=`TABLE`;)c=c.parentNode;c&&yb(a,c.firstChild,c,r,s,n)}function Nb(e){return Array(e).fill(0)}function Pb(e,t){let n=[],r=e.doc.resolve(t),i=r.node(-1);if(!i)return lc.empty;let a=$v.get(i),o=r.start(-1),s=a.colCount(r.pos-o)+r.nodeAfter.attrs.colspan-1;for(let t=0;t<a.height;t++){let r=s+t*a.width;if((s==a.width-1||a.map[r]!=a.map[r+1])&&(t==0||a.map[r]!=a.map[r-a.width])){let t=a.map[r],s=o+t+i.nodeAt(t).nodeSize-1,c=document.createElement(`div`);c.className=`column-resize-handle`,bb.getState(e)?.dragging&&n.push(oc.node(o+t,o+t+i.nodeAt(t).nodeSize,{class:`column-resize-dragging`})),n.push(oc.widget(s,c))}}return lc.create(e.doc,n)}function Fb({allowTableNodeSelection:e=!1}={}){return new Mr({key:ay,state:{init(){return null},apply(e,t){let n=e.getMeta(ay);if(n!=null)return n==-1?null:n;if(t==null||!e.docChanged)return t;let{deleted:r,pos:i}=e.mapping.mapResult(t);return r?null:i}},props:{decorations:by,handleDOMEvents:{mousedown:mb},createSelectionBetween(e){return ay.getState(e.state)==null?null:e.state.selection},handleTripleClick:fb,handleKeyDown:cb,handlePaste:pb},appendTransaction(t,n,r){return Cy(r,Ey(r,n),e)}})}function Ib(e){return e===`left`||e===`right`||e===`center`?e:null}function Lb(e){let t=(e.style.textAlign||``).trim().toLowerCase(),n=(e.getAttribute(`align`)||``).trim().toLowerCase();return Ib(t||n)}function Rb(e){return Ib(e?.align)}function zb(){return{default:null,parseHTML:e=>Lb(e),renderHTML:e=>e.align?{style:`text-align: ${e.align}`}:{}}}var Bb=Wf.create({name:`tableCell`,addOptions(){return{HTMLAttributes:{}}},content:`block+`,addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:e=>{let t=e.getAttribute(`colwidth`),n=t?t.split(`,`).map(e=>parseInt(e,10)):null;if(!n){let t=e.closest(`table`)?.querySelectorAll(`colgroup > col`),n=Array.from(e.parentElement?.children||[]).indexOf(e);if(n&&n>-1&&t&&t[n]){let e=t[n].getAttribute(`width`);return e?[parseInt(e,10)]:null}}return n}},align:zb()}},tableRole:`cell`,isolating:!0,parseHTML(){return[{tag:`td`}]},renderHTML({HTMLAttributes:e}){return[`td`,Bu(this.options.HTMLAttributes,e),0]}}),Vb=Wf.create({name:`tableHeader`,addOptions(){return{HTMLAttributes:{}}},content:`block+`,addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:e=>{let t=e.getAttribute(`colwidth`);return t?t.split(`,`).map(e=>parseInt(e,10)):null}},align:zb()}},tableRole:`header_cell`,isolating:!0,parseHTML(){return[{tag:`th`}]},renderHTML({HTMLAttributes:e}){return[`th`,Bu(this.options.HTMLAttributes,e),0]}}),Hb=Wf.create({name:`tableRow`,addOptions(){return{HTMLAttributes:{}}},content:`(tableCell | tableHeader)*`,tableRole:`row`,parseHTML(){return[{tag:`tr`}]},renderHTML({HTMLAttributes:e}){return[`tr`,Bu(this.options.HTMLAttributes,e),0]}});function Ub(e,t){return t?[`width`,`${Math.max(t,e)}px`]:[`min-width`,`${e}px`]}function Wb(e,t,n,r,i,a){var o;let s=0,c=!0,l=t.firstChild,u=e.firstChild;if(u!==null)for(let e=0,n=0;e<u.childCount;e+=1){let{colspan:o,colwidth:d}=u.child(e).attrs;for(let e=0;e<o;e+=1,n+=1){let o=i===n?a:d&&d[e],u=o?`${o}px`:``;if(s+=o||r,o||(c=!1),l){if(l.style.width!==u){let[e,t]=Ub(r,o);l.style.setProperty(e,t)}l=l.nextSibling}else{let e=document.createElement(`col`),[n,i]=Ub(r,o);e.style.setProperty(n,i),t.appendChild(e)}}}for(;l;){let e=l.nextSibling;(o=l.parentNode)==null||o.removeChild(l),l=e}let d=e.attrs.style&&typeof e.attrs.style==`string`&&/\bwidth\s*:/i.test(e.attrs.style);c&&!d?(n.style.width=`${s}px`,n.style.minWidth=``):(n.style.width=``,n.style.minWidth=`${s}px`)}var Gb=class{constructor(e,t){this.node=e,this.cellMinWidth=t,this.dom=document.createElement(`div`),this.dom.className=`tableWrapper`,this.table=this.dom.appendChild(document.createElement(`table`)),e.attrs.style&&(this.table.style.cssText=e.attrs.style),this.colgroup=this.table.appendChild(document.createElement(`colgroup`)),Wb(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement(`tbody`))}update(e){return e.type===this.node.type?(this.node=e,Wb(e,this.colgroup,this.table,this.cellMinWidth),!0):!1}ignoreMutation(e){let t=e.target,n=this.dom.contains(t),r=this.contentDOM.contains(t);return!!(n&&!r&&(e.type===`attributes`||e.type===`childList`||e.type===`characterData`))}};function Kb(e,t,n,r){let i=0,a=!0,o=[],s=e.firstChild;if(!s)return{};for(let e=0,c=0;e<s.childCount;e+=1){let{colspan:l,colwidth:u}=s.child(e).attrs;for(let e=0;e<l;e+=1,c+=1){let s=n===c?r:u&&u[e];i+=s||t,s||(a=!1);let[l,d]=Ub(t,s);o.push([`col`,{style:`${l}: ${d}`}])}}let c=a?`${i}px`:``,l=a?``:`${i}px`;return{colgroup:[`colgroup`,{},...o],tableWidth:c,tableMinWidth:l}}function qb(e,t){return t?e.createChecked(null,t):e.createAndFill()}function Jb(e){if(e.cached.tableNodeTypes)return e.cached.tableNodeTypes;let t={};return Object.keys(e.nodes).forEach(n=>{let r=e.nodes[n];r.spec.tableRole&&(t[r.spec.tableRole]=r)}),e.cached.tableNodeTypes=t,t}function Yb(e,t,n,r,i){let a=Jb(e),o=[],s=[];for(let e=0;e<n;e+=1){let e=qb(a.cell,i);if(e&&s.push(e),r){let e=qb(a.header_cell,i);e&&o.push(e)}}let c=[];for(let e=0;e<t;e+=1)c.push(a.row.createChecked(null,r&&e===0?o:s));return a.table.createChecked(null,c)}function Xb(e){return e instanceof vy}var Zb=({editor:e})=>{let{selection:t}=e.state;if(!Xb(t))return!1;let n=0;return Au(t.ranges[0].$from,e=>e.type.name===`table`)?.node.descendants(e=>{if(e.type.name===`table`)return!1;[`tableCell`,`tableHeader`].includes(e.type.name)&&(n+=1)}),n===t.ranges.length?(e.commands.deleteTable(),!0):!1};function Qb(e){return(e||``).replace(/\s+/g,` `).trim()}function $b(e,t,n={}){let r=n.cellLineSeparator??``;if(!e||!e.content||e.content.length===0)return``;let i=[];e.content.forEach(e=>{let n=[];e.content&&e.content.forEach(e=>{let i=``;i=e.content&&Array.isArray(e.content)&&e.content.length>1?e.content.map(e=>t.renderChildren(e)).join(r):e.content?t.renderChildren(e.content):``;let a=Qb(i),o=e.type===`tableHeader`,s=Rb(e.attrs);n.push({text:a,isHeader:o,align:s})}),i.push(n)});let a=i.reduce((e,t)=>Math.max(e,t.length),0);if(a===0)return``;let o=Array(a).fill(0);i.forEach(e=>{for(let t=0;t<a;t+=1){let n=(e[t]?.text||``).length;n>o[t]&&(o[t]=n),o[t]<3&&(o[t]=3)}});let s=(e,t)=>e+` `.repeat(Math.max(0,t-e.length)),c=i[0],l=c.some(e=>e.isHeader),u=Array(a).fill(null);i.forEach(e=>{for(let t=0;t<a;t+=1)!u[t]&&e[t]?.align&&(u[t]=e[t].align)});let d=`
251
+ `):``,markdownTokenizer:{name:`taskList`,level:`block`,start(e){let t=e.match(/^\s*[-+*]\s+\[([ xX])\]\s+/)?.index;return t===void 0?-1:t},tokenize(e,t,n){let r=e=>{let t=Vf(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);return t?[{type:`taskList`,raw:t.raw,items:t.items}]:n.blockTokens(e)},i=Vf(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);if(i)return{type:`taskList`,raw:i.raw,items:i.items}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleTaskList:()=>({commands:e})=>e.toggleList(this.name,this.options.itemTypeName)}},addKeyboardShortcuts(){return{"Mod-Shift-9":()=>this.editor.commands.toggleTaskList()}}});N.create({name:`listKit`,addExtensions(){let e=[];return this.options.bulletList!==!1&&e.push(T_.configure(this.options.bulletList)),this.options.listItem!==!1&&e.push(E_.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(L_.configure(this.options.listKeymap)),this.options.orderedList!==!1&&e.push(K_.configure(this.options.orderedList)),this.options.taskItem!==!1&&e.push(J_.configure(this.options.taskItem)),this.options.taskList!==!1&&e.push(Y_.configure(this.options.taskList)),e}});var X_=`&nbsp;`,Z_=`\xA0`,Q_=Wf.create({name:`paragraph`,priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:`block`,content:`inline*`,parseHTML(){return[{tag:`p`}]},renderHTML({HTMLAttributes:e}){return[`p`,Bu(this.options.HTMLAttributes,e),0]},parseMarkdown:(e,t)=>{let n=e.tokens||[];if(n.length===1&&n[0].type===`image`)return t.parseChildren([n[0]]);let r=t.parseInline(n);return n.length===1&&n[0].type===`text`&&(n[0].raw===X_||n[0].text===X_||n[0].raw===Z_||n[0].text===Z_)&&r.length===1&&r[0].type===`text`&&(r[0].text===X_||r[0].text===Z_)?t.createNode(`paragraph`,void 0,[]):t.createNode(`paragraph`,void 0,r)},renderMarkdown:(e,t,n)=>{if(!e)return``;let r=Array.isArray(e.content)?e.content:[];if(r.length===0){let e=Array.isArray(n?.previousNode?.content)?n.previousNode.content:[];return n?.previousNode?.type===`paragraph`&&e.length===0?X_:``}return t.renderChildren(r)},addCommands(){return{setParagraph:()=>({commands:e})=>e.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),$_=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,ev=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,tv=tf.create({name:`strike`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`s`},{tag:`del`},{tag:`strike`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`line-through`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`s`,Bu(this.options.HTMLAttributes,e),0]},markdownTokenName:`del`,parseMarkdown:(e,t)=>t.applyMark(`strike`,t.parseInline(e.tokens||[])),renderMarkdown:(e,t)=>`~~${t.renderChildren(e)}~~`,addCommands(){return{setStrike:()=>({commands:e})=>e.setMark(this.name),toggleStrike:()=>({commands:e})=>e.toggleMark(this.name),unsetStrike:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[Ef({find:$_,type:this.type})]},addPasteRules(){return[Gf({find:ev,type:this.type})]}}),nv=Wf.create({name:`text`,group:`inline`,parseMarkdown:e=>({type:`text`,text:e.text||``}),renderMarkdown:e=>e.text||``}),rv=tf.create({name:`underline`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`u`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`underline`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`u`,Bu(this.options.HTMLAttributes,e),0]},parseMarkdown(e,t){return t.applyMark(this.name||`underline`,t.parseInline(e.tokens||[]))},renderMarkdown(e,t){return`++${t.renderChildren(e)}++`},markdownTokenizer:{name:`underline`,level:`inline`,start(e){return e.indexOf(`++`)},tokenize(e,t,n){let r=/^(\+\+)([\s\S]+?)(\+\+)/.exec(e);if(!r)return;let i=r[2].trim();return{type:`underline`,raw:r[0],text:i,tokens:n.inlineTokens(i)}}},addCommands(){return{setUnderline:()=>({commands:e})=>e.setMark(this.name),toggleUnderline:()=>({commands:e})=>e.toggleMark(this.name),unsetUnderline:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}});function iv(e={}){return new j({view(t){return new av(t,e)}})}var av=class{constructor(e,t){this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=t.width??1,this.color=t.color===!1?void 0:t.color||`black`,this.class=t.class,this.handlers=[`dragover`,`dragend`,`drop`,`dragleave`].map(t=>{let n=e=>{this[t](e)};return e.dom.addEventListener(t,n),{name:t,handler:n}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,n,r=this.editorView.dom,i=r.getBoundingClientRect(),a=i.width/r.offsetWidth,o=i.height/r.offsetHeight;if(t){let t=e.nodeBefore,r=e.nodeAfter;if(t||r){let e=this.editorView.nodeDOM(this.cursorPos-(t?t.nodeSize:0));if(e){let i=e.getBoundingClientRect(),a=t?i.bottom:i.top;t&&r&&(a=(a+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let s=this.width/2*o;n={left:i.left,right:i.right,top:a-s,bottom:a+s}}}}if(!n){let e=this.editorView.coordsAtPos(this.cursorPos),t=this.width/2*a;n={left:e.left-t,right:e.left+t,top:e.top,bottom:e.bottom}}let s=this.editorView.dom.offsetParent;this.element||(this.element=s.appendChild(document.createElement(`div`)),this.class&&(this.element.className=this.class),this.element.style.cssText=`position: absolute; z-index: 50; pointer-events: none;`,this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle(`prosemirror-dropcursor-block`,t),this.element.classList.toggle(`prosemirror-dropcursor-inline`,!t);let c,l;if(!s||s==document.body&&getComputedStyle(s).position==`static`)c=-pageXOffset,l=-pageYOffset;else{let e=s.getBoundingClientRect(),t=e.width/s.offsetWidth,n=e.height/s.offsetHeight;c=e.left-s.scrollLeft*t,l=e.top-s.scrollTop*n}this.element.style.left=(n.left-c)/a+`px`,this.element.style.top=(n.top-l)/o+`px`,this.element.style.width=(n.right-n.left)/a+`px`,this.element.style.height=(n.bottom-n.top)/o+`px`}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=n&&n.type.spec.disableDropCursor,i=typeof r==`function`?r(this.editorView,t,e):r;if(t&&!i){let e=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let t=Kn(this.editorView.state.doc,e,this.editorView.dragging.slice);t!=null&&(e=t)}this.setCursor(e),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}},ov=class e extends O{constructor(e){super(e,e)}map(t,n){let r=t.resolve(n.map(this.head));return e.valid(r)?new e(r):O.near(r)}content(){return D.empty}eq(t){return t instanceof e&&t.head==this.head}toJSON(){return{type:`gapcursor`,pos:this.head}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for GapCursor.fromJSON`);return new e(t.resolve(n.pos))}getBookmark(){return new sv(this.anchor)}static valid(e){let t=e.parent;if(t.inlineContent||!lv(e)||!uv(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(t,n,r=!1){search:for(;;){if(!r&&e.valid(t))return t;let i=t.pos,a=null;for(let r=t.depth;;r--){let o=t.node(r);if(n>0?t.indexAfter(r)<o.childCount:t.index(r)>0){a=o.child(n>0?t.indexAfter(r):t.index(r)-1);break}else if(r==0)return null;i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}for(;;){let o=n>0?a.firstChild:a.lastChild;if(!o){if(a.isAtom&&!a.isText&&!A.isSelectable(a)){t=t.doc.resolve(i+a.nodeSize*n),r=!1;continue search}break}a=o,i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}return null}}};ov.prototype.visible=!1,ov.findFrom=ov.findGapCursorFrom,O.jsonID(`gapcursor`,ov);var sv=class e{constructor(e){this.pos=e}map(t){return new e(t.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return ov.valid(t)?new ov(t):O.near(t)}};function cv(e){return e.isAtom||e.spec.isolating||e.spec.createGapCursor}function lv(e){for(let t=e.depth;t>=0;t--){let n=e.index(t),r=e.node(t);if(n==0){if(r.type.spec.isolating)return!0;continue}for(let e=r.child(n-1);;e=e.lastChild){if(e.childCount==0&&!e.inlineContent||cv(e.type))return!0;if(e.inlineContent)return!1}}return!0}function uv(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),r=e.node(t);if(n==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let e=r.child(n);;e=e.firstChild){if(e.childCount==0&&!e.inlineContent||cv(e.type))return!0;if(e.inlineContent)return!1}}return!0}function dv(){return new j({props:{decorations:gv,createSelectionBetween(e,t,n){return t.pos==n.pos&&ov.valid(n)?new ov(n):null},handleClick:mv,handleKeyDown:fv,handleDOMEvents:{beforeinput:hv}}})}var fv=ll({ArrowLeft:pv(`horiz`,-1),ArrowRight:pv(`horiz`,1),ArrowUp:pv(`vert`,-1),ArrowDown:pv(`vert`,1)});function pv(e,t){let n=e==`vert`?t>0?`down`:`up`:t>0?`right`:`left`;return function(e,r,i){let a=e.selection,o=t>0?a.$to:a.$from,s=a.empty;if(a instanceof k){if(!i.endOfTextblock(n)||o.depth==0)return!1;s=!1,o=e.doc.resolve(t>0?o.after():o.before())}let c=ov.findGapCursorFrom(o,t,s);return c?(r&&r(e.tr.setSelection(new ov(c))),!0):!1}}function mv(e,t,n){if(!e||!e.editable)return!1;let r=e.state.doc.resolve(t);if(!ov.valid(r))return!1;let i=e.posAtCoords({left:n.clientX,top:n.clientY});return i&&i.inside>-1&&A.isSelectable(e.state.doc.nodeAt(i.inside))?!1:(e.dispatch(e.state.tr.setSelection(new ov(r))),!0)}function hv(e,t){if(t.inputType!=`insertCompositionText`||!(e.state.selection instanceof ov))return!1;let{$from:n}=e.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!r)return!1;let i=E.empty;for(let e=r.length-1;e>=0;e--)i=E.from(r[e].createAndFill(null,i));let a=e.state.tr.replace(n.pos,n.pos,new D(i,0,0));return a.setSelection(k.near(a.doc.resolve(n.pos+1))),e.dispatch(a),!1}function gv(e){if(!(e.selection instanceof ov))return null;let t=document.createElement(`div`);return t.className=`ProseMirror-gapcursor`,cc.create(e.doc,[ac.widget(e.selection.head,t,{key:`gapcursor`})])}var _v=200,vv=function(){};vv.prototype.append=function(e){return e.length?(e=vv.from(e),!this.length&&e||e.length<_v&&this.leafAppend(e)||this.length<_v&&e.leafPrepend(this)||this.appendInner(e)):this},vv.prototype.prepend=function(e){return e.length?vv.from(e).append(this):this},vv.prototype.appendInner=function(e){return new bv(this,e)},vv.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?vv.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},vv.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},vv.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},vv.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var r=[];return this.forEach(function(t,n){return r.push(e(t,n))},t,n),r},vv.from=function(e){return e instanceof vv?e:e&&e.length?new yv(e):vv.empty};var yv=function(e){function t(t){e.call(this),this.values=t}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var n={length:{configurable:!0},depth:{configurable:!0}};return t.prototype.flatten=function(){return this.values},t.prototype.sliceInner=function(e,n){return e==0&&n==this.length?this:new t(this.values.slice(e,n))},t.prototype.getInner=function(e){return this.values[e]},t.prototype.forEachInner=function(e,t,n,r){for(var i=t;i<n;i++)if(e(this.values[i],r+i)===!1)return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){for(var i=t-1;i>=n;i--)if(e(this.values[i],r+i)===!1)return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=_v)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=_v)return new t(e.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(t.prototype,n),t}(vv);vv.empty=new yv([]);var bv=function(e){function t(t,n){e.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},t.prototype.getInner=function(e){return e<this.left.length?this.left.get(e):this.right.get(e-this.left.length)},t.prototype.forEachInner=function(e,t,n,r){var i=this.left.length;if(t<i&&this.left.forEachInner(e,t,Math.min(n,i),r)===!1||n>i&&this.right.forEachInner(e,Math.max(t-i,0),Math.min(this.length,n)-i,r+i)===!1)return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){var i=this.left.length;if(t>i&&this.right.forEachInvertedInner(e,t-i,Math.max(n,i)-i,r+i)===!1||n<i&&this.left.forEachInvertedInner(e,Math.min(t,i),n,r)===!1)return!1},t.prototype.sliceInner=function(e,t){if(e==0&&t==this.length)return this;var n=this.left.length;return t<=n?this.left.slice(e,t):e>=n?this.right.slice(e-n,t-n):this.left.slice(e,n).append(this.right.slice(0,t-n))},t.prototype.leafAppend=function(e){var n=this.right.leafAppend(e);if(n)return new t(this.left,n)},t.prototype.leafPrepend=function(e){var n=this.left.leafPrepend(e);if(n)return new t(n,this.right)},t.prototype.appendInner=function(e){return this.left.depth>=Math.max(this.right.depth,e.depth)+1?new t(this.left,new t(this.right,e)):new t(this,e)},t}(vv),xv=500,Sv=class e{constructor(e,t){this.items=e,this.eventCount=t}popEvent(t,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,a;n&&(i=this.remapping(r,this.items.length),a=i.maps.length);let o=t.tr,s,c,l=[],u=[];return this.items.forEach((t,n)=>{if(!t.step){i||(i=this.remapping(r,n+1),a=i.maps.length),a--,u.push(t);return}if(i){u.push(new wv(t.map));let e=t.step.map(i.slice(a)),n;e&&o.maybeStep(e).doc&&(n=o.mapping.maps[o.mapping.maps.length-1],l.push(new wv(n,void 0,void 0,l.length+u.length))),a--,n&&i.appendMap(n,a)}else o.maybeStep(t.step);if(t.selection)return s=i?t.selection.map(i.slice(a)):t.selection,c=new e(this.items.slice(0,r).append(u.reverse().concat(l)),this.eventCount-1),!1},this.items.length,0),{remaining:c,transform:o,selection:s}}addTransform(t,n,r,i){let a=[],o=this.eventCount,s=this.items,c=!i&&s.length?s.get(s.length-1):null;for(let e=0;e<t.steps.length;e++){let r=t.steps[e].invert(t.docs[e]),l=new wv(t.mapping.maps[e],r,n),u;(u=c&&c.merge(l))&&(l=u,e?a.pop():s=s.slice(0,s.length-1)),a.push(l),n&&=(o++,void 0),i||(c=l)}let l=o-r.depth;return l>Ev&&(s=Cv(s,l),o-=l),new e(s.append(a),o)}remapping(e,t){let n=new un;return this.items.forEach((t,r)=>{let i=t.mirrorOffset!=null&&r-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,i)},e,t),n}addMaps(t){return this.eventCount==0?this:new e(this.items.append(t.map(e=>new wv(e))),this.eventCount)}rebased(t,n){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-n),a=t.mapping,o=t.steps.length,s=this.eventCount;this.items.forEach(e=>{e.selection&&s--},i);let c=n;this.items.forEach(e=>{let n=a.getMirror(--c);if(n==null)return;o=Math.min(o,n);let i=a.maps[n];if(e.step){let o=t.steps[n].invert(t.docs[n]),l=e.selection&&e.selection.map(a.slice(c+1,n));l&&s++,r.push(new wv(i,o,l))}else r.push(new wv(i))},i);let l=[];for(let e=n;e<o;e++)l.push(new wv(a.maps[e]));let u=new e(this.items.slice(0,i).append(l).append(r),s);return u.emptyItemCount()>xv&&(u=u.compress(this.items.length-r.length)),u}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(t=this.items.length){let n=this.remapping(0,t),r=n.maps.length,i=[],a=0;return this.items.forEach((e,o)=>{if(o>=t)i.push(e),e.selection&&a++;else if(e.step){let t=e.step.map(n.slice(r)),o=t&&t.getMap();if(r--,o&&n.appendMap(o,r),t){let s=e.selection&&e.selection.map(n.slice(r));s&&a++;let c=new wv(o.invert(),t,s),l,u=i.length-1;(l=i.length&&i[u].merge(c))?i[u]=l:i.push(c)}}else e.map&&r--},this.items.length,0),new e(vv.from(i.reverse()),a)}};Sv.empty=new Sv(vv.empty,0);function Cv(e,t){let n;return e.forEach((e,r)=>{if(e.selection&&t--==0)return n=r,!1}),e.slice(n)}var wv=class e{constructor(e,t,n,r){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=r}merge(t){if(this.step&&t.step&&!t.selection){let n=t.step.merge(this.step);if(n)return new e(n.getMap().invert(),n,this.selection)}}},Tv=class{constructor(e,t,n,r,i){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=r,this.prevComposition=i}},Ev=20;function Dv(e,t,n,r){let i=n.getMeta(Iv),a;if(i)return i.historyState;n.getMeta(Lv)&&(e=new Tv(e.done,e.undone,null,0,-1));let o=n.getMeta(`appendedTransaction`);if(n.steps.length==0)return e;if(o&&o.getMeta(Iv))return o.getMeta(Iv).redo?new Tv(e.done.addTransform(n,void 0,r,Pv(t)),e.undone,kv(n.mapping.maps),e.prevTime,e.prevComposition):new Tv(e.done,e.undone.addTransform(n,void 0,r,Pv(t)),null,e.prevTime,e.prevComposition);if(n.getMeta(`addToHistory`)!==!1&&!(o&&o.getMeta(`addToHistory`)===!1)){let i=n.getMeta(`composition`),a=e.prevTime==0||!o&&e.prevComposition!=i&&(e.prevTime<(n.time||0)-r.newGroupDelay||!Ov(n,e.prevRanges)),s=o?Av(e.prevRanges,n.mapping):kv(n.mapping.maps);return new Tv(e.done.addTransform(n,a?t.selection.getBookmark():void 0,r,Pv(t)),Sv.empty,s,n.time,i??e.prevComposition)}else if(a=n.getMeta(`rebased`))return new Tv(e.done.rebased(n,a),e.undone.rebased(n,a),Av(e.prevRanges,n.mapping),e.prevTime,e.prevComposition);else return new Tv(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),Av(e.prevRanges,n.mapping),e.prevTime,e.prevComposition)}function Ov(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((e,r)=>{for(let i=0;i<t.length;i+=2)e<=t[i+1]&&r>=t[i]&&(n=!0)}),n}function kv(e){let t=[];for(let n=e.length-1;n>=0&&t.length==0;n--)e[n].forEach((e,n,r,i)=>t.push(r,i));return t}function Av(e,t){if(!e)return null;let n=[];for(let r=0;r<e.length;r+=2){let i=t.map(e[r],1),a=t.map(e[r+1],-1);i<=a&&n.push(i,a)}return n}function jv(e,t,n){let r=Pv(t),i=Iv.get(t).spec.config,a=(n?e.undone:e.done).popEvent(t,r);if(!a)return null;let o=a.selection.resolve(a.transform.doc),s=(n?e.done:e.undone).addTransform(a.transform,t.selection.getBookmark(),i,r),c=new Tv(n?s:a.remaining,n?a.remaining:s,null,0,-1);return a.transform.setSelection(o).setMeta(Iv,{redo:n,historyState:c})}var Mv=!1,Nv=null;function Pv(e){let t=e.plugins;if(Nv!=t){Mv=!1,Nv=t;for(let e=0;e<t.length;e++)if(t[e].spec.historyPreserveItems){Mv=!0;break}}return Mv}function Fv(e){return e.setMeta(Lv,!0)}var Iv=new Pr(`history`),Lv=new Pr(`closeHistory`);function Rv(e={}){return e={depth:e.depth||100,newGroupDelay:e.newGroupDelay||500},new j({key:Iv,state:{init(){return new Tv(Sv.empty,Sv.empty,null,0,-1)},apply(t,n,r){return Dv(n,r,t,e)}},config:e,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,r=n==`historyUndo`?Bv:n==`historyRedo`?Vv:null;return!r||!e.editable?!1:(t.preventDefault(),r(e.state,e.dispatch))}}}})}function zv(e,t){return(n,r)=>{let i=Iv.getState(n);if(!i||(e?i.undone:i.done).eventCount==0)return!1;if(r){let a=jv(i,n,e);a&&r(t?a.scrollIntoView():a)}return!0}}var Bv=zv(!1,!0),Vv=zv(!0,!0);N.create({name:`characterCount`,addOptions(){return{limit:null,mode:`textSize`,textCounter:e=>e.length,wordCounter:e=>e.split(` `).filter(e=>e!==``).length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=e=>{let t=e?.node||this.editor.state.doc;if((e?.mode||this.options.mode)===`textSize`){let e=t.textBetween(0,t.content.size,void 0,` `);return this.options.textCounter(e)}return t.nodeSize},this.storage.words=e=>{let t=e?.node||this.editor.state.doc,n=t.textBetween(0,t.content.size,` `,` `);return this.options.wordCounter(n)}},addProseMirrorPlugins(){let e=!1;return[new j({key:new Pr(`characterCount`),appendTransaction:(t,n,r)=>{if(e)return;let i=this.options.limit;if(i==null||i===0){e=!0;return}let a=this.storage.characters({node:r.doc});if(a>i){let t=a-i;console.warn(`[CharacterCount] Initial content exceeded limit of ${i} characters. Content was automatically trimmed.`);let n=r.tr.deleteRange(0,t);return e=!0,n}e=!0},filterTransaction:(e,t)=>{let n=this.options.limit;if(!e.docChanged||n===0||n==null)return!0;let r=this.storage.characters({node:t.doc}),i=this.storage.characters({node:e.doc});if(i<=n||r>n&&i>n&&i<=r)return!0;if(r>n&&i>n&&i>r||!e.getMeta(`paste`))return!1;let a=e.selection.$head.pos,o=a-(i-n),s=a;return e.deleteRange(o,s),!(this.storage.characters({node:e.doc})>n)}})]}});var Hv=N.create({name:`dropCursor`,addOptions(){return{color:`currentColor`,width:1,class:void 0}},addProseMirrorPlugins(){return[iv(this.options)]}});N.create({name:`focus`,addOptions(){return{className:`has-focus`,mode:`all`}},addProseMirrorPlugins(){return[new j({key:new Pr(`focus`),props:{decorations:({doc:e,selection:t})=>{let{isEditable:n,isFocused:r}=this.editor,{anchor:i}=t,a=[];if(!n||!r)return cc.create(e,[]);let o=0;this.options.mode===`deepest`&&e.descendants((e,t)=>{if(!e.isText){if(!(i>=t&&i<=t+e.nodeSize-1))return!1;o+=1}});let s=0;return e.descendants((e,t)=>{if(e.isText||!(i>=t&&i<=t+e.nodeSize-1))return!1;if(s+=1,this.options.mode===`deepest`&&o-s>0||this.options.mode===`shallowest`&&s>1)return this.options.mode===`deepest`;a.push(ac.node(t,t+e.nodeSize,{class:this.options.className}))}),cc.create(e,a)}}})]}});var Uv=N.create({name:`gapCursor`,addProseMirrorPlugins(){return[dv()]},extendNodeSchema(e){return{allowGapCursor:Pu(M(e,`allowGapCursor`,{name:e.name,options:e.options,storage:e.storage}))??null}}}),Wv=`placeholder`;function Gv(e){return e.replace(/\s+/g,`-`).replace(/[^a-zA-Z0-9-]/g,``).replace(/^[0-9-]+/,``).replace(/^-+/,``).toLowerCase()}var Kv=N.create({name:`placeholder`,addOptions(){return{emptyEditorClass:`is-editor-empty`,emptyNodeClass:`is-empty`,dataAttribute:Wv,placeholder:`Write something …`,showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){let e=this.options.dataAttribute?`data-${Gv(this.options.dataAttribute)}`:`data-${Wv}`;return[new j({key:new Pr(`placeholder`),props:{decorations:({doc:t,selection:n})=>{let r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:i}=n,a=[];if(!r)return null;let o=this.editor.isEmpty;return t.descendants((t,n)=>{let r=i>=n&&i<=n+t.nodeSize,s=!t.isLeaf&&_d(t);if(!t.type.isTextblock)return this.options.includeChildren;if((r||!this.options.showOnlyCurrent)&&s){let i=[this.options.emptyNodeClass];o&&i.push(this.options.emptyEditorClass);let s=ac.node(n,n+t.nodeSize,{class:i.join(` `),[e]:typeof this.options.placeholder==`function`?this.options.placeholder({editor:this.editor,node:t,pos:n,hasAnchor:r}):this.options.placeholder});a.push(s)}return this.options.includeChildren}),cc.create(t,a)}}})]}});N.create({name:`selection`,addOptions(){return{className:`selection`}},addProseMirrorPlugins(){let{editor:e,options:t}=this;return[new j({key:new Pr(`selection`),props:{decorations(n){return n.selection.empty||e.isFocused||!e.isEditable||vd(n.selection)||e.view.dragging?null:cc.create(n.doc,[ac.inline(n.selection.from,n.selection.to,{class:t.className})])}}})]}});function qv({types:e,node:t}){return t&&Array.isArray(e)&&e.includes(t.type)||t?.type===e}var Jv=N.create({name:`trailingNode`,addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){let e=new Pr(this.name),t=this.options.node||this.editor.schema.topNodeType.contentMatch.defaultType?.name||`paragraph`,n=Object.entries(this.editor.schema.nodes).map(([,e])=>e).filter(e=>(this.options.notAfter||[]).concat(t).includes(e.name));return[new j({key:e,appendTransaction:(n,r,i)=>{let{doc:a,tr:o,schema:s}=i,c=e.getState(i),l=a.content.size,u=s.nodes[t];if(!n.some(e=>e.getMeta(`skipTrailingNode`))&&c)return o.insert(l,u.create())},state:{init:(e,t)=>{let r=t.tr.doc.lastChild;return!qv({node:r,types:n})},apply:(e,t)=>{if(!e.docChanged||e.getMeta(`__uniqueIDTransaction`))return t;let r=e.doc.lastChild;return!qv({node:r,types:n})}}})]}}),Yv=N.create({name:`undoRedo`,addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:e,dispatch:t})=>Bv(e,t),redo:()=>({state:e,dispatch:t})=>Vv(e,t)}},addProseMirrorPlugins(){return[Rv(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),Xv=N.create({name:`starterKit`,addExtensions(){let e=[];return this.options.bold!==!1&&e.push(qm.configure(this.options.bold)),this.options.blockquote!==!1&&e.push(Hm.configure(this.options.blockquote)),this.options.bulletList!==!1&&e.push(T_.configure(this.options.bulletList)),this.options.code!==!1&&e.push(Xm.configure(this.options.code)),this.options.codeBlock!==!1&&e.push(Rm.configure(this.options.codeBlock)),this.options.document!==!1&&e.push(Zm.configure(this.options.document)),this.options.dropcursor!==!1&&e.push(Hv.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&e.push(Uv.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&e.push(Qm.configure(this.options.hardBreak)),this.options.heading!==!1&&e.push($m.configure(this.options.heading)),this.options.undoRedo!==!1&&e.push(Yv.configure(this.options.undoRedo)),this.options.horizontalRule!==!1&&e.push(eh.configure(this.options.horizontalRule)),this.options.italic!==!1&&e.push(ah.configure(this.options.italic)),this.options.listItem!==!1&&e.push(E_.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(L_.configure(this.options?.listKeymap)),this.options.link!==!1&&e.push(y_.configure(this.options?.link)),this.options.orderedList!==!1&&e.push(K_.configure(this.options.orderedList)),this.options.paragraph!==!1&&e.push(Q_.configure(this.options.paragraph)),this.options.strike!==!1&&e.push(tv.configure(this.options.strike)),this.options.text!==!1&&e.push(nv.configure(this.options.text)),this.options.underline!==!1&&e.push(rv.configure(this.options?.underline)),this.options.trailingNode!==!1&&e.push(Jv.configure(this.options?.trailingNode)),e}}),Zv,Qv;if(typeof WeakMap<`u`){let e=new WeakMap;Zv=t=>e.get(t),Qv=(t,n)=>(e.set(t,n),n)}else{let e=[],t=0;Zv=t=>{for(let n=0;n<e.length;n+=2)if(e[n]==t)return e[n+1]},Qv=(n,r)=>(t==10&&(t=0),e[t++]=n,e[t++]=r)}var $v=class{constructor(e,t,n,r){this.width=e,this.height=t,this.map=n,this.problems=r}findCell(e){for(let t=0;t<this.map.length;t++){let n=this.map[t];if(n!=e)continue;let r=t%this.width,i=t/this.width|0,a=r+1,o=i+1;for(let e=1;a<this.width&&this.map[t+e]==n;e++)a++;for(let e=1;o<this.height&&this.map[t+this.width*e]==n;e++)o++;return{left:r,top:i,right:a,bottom:o}}throw RangeError(`No cell with offset ${e} found`)}colCount(e){for(let t=0;t<this.map.length;t++)if(this.map[t]==e)return t%this.width;throw RangeError(`No cell with offset ${e} found`)}nextCell(e,t,n){let{left:r,right:i,top:a,bottom:o}=this.findCell(e);return t==`horiz`?(n<0?r==0:i==this.width)?null:this.map[a*this.width+(n<0?r-1:i)]:(n<0?a==0:o==this.height)?null:this.map[r+this.width*(n<0?a-1:o)]}rectBetween(e,t){let{left:n,right:r,top:i,bottom:a}=this.findCell(e),{left:o,right:s,top:c,bottom:l}=this.findCell(t);return{left:Math.min(n,o),top:Math.min(i,c),right:Math.max(r,s),bottom:Math.max(a,l)}}cellsInRect(e){let t=[],n={};for(let r=e.top;r<e.bottom;r++)for(let i=e.left;i<e.right;i++){let a=r*this.width+i,o=this.map[a];n[o]||(n[o]=!0,!(i==e.left&&i&&this.map[a-1]==o||r==e.top&&r&&this.map[a-this.width]==o)&&t.push(o))}return t}positionAt(e,t,n){for(let r=0,i=0;;r++){let a=i+n.child(r).nodeSize;if(r==e){let n=t+e*this.width,r=(e+1)*this.width;for(;n<r&&this.map[n]<i;)n++;return n==r?a-1:this.map[n]}i=a}}static get(e){return Zv(e)||Qv(e,ey(e))}};function ey(e){if(e.type.spec.tableRole!=`table`)throw RangeError(`Not a table node: `+e.type.name);let t=ty(e),n=e.childCount,r=[],i=0,a=null,o=[];for(let e=0,i=t*n;e<i;e++)r[e]=0;for(let s=0,c=0;s<n;s++){let l=e.child(s);c++;for(let e=0;;e++){for(;i<r.length&&r[i]!=0;)i++;if(e==l.childCount)break;let u=l.child(e),{colspan:d,rowspan:f,colwidth:p}=u.attrs;for(let e=0;e<f;e++){if(e+s>=n){(a||=[]).push({type:`overlong_rowspan`,pos:c,n:f-e});break}let l=i+e*t;for(let e=0;e<d;e++){r[l+e]==0?r[l+e]=c:(a||=[]).push({type:`collision`,row:s,pos:c,n:d-e});let n=p&&p[e];if(n){let r=(l+e)%t*2,i=o[r];i==null||i!=n&&o[r+1]==1?(o[r]=n,o[r+1]=1):i==n&&o[r+1]++}}}i+=d,c+=u.nodeSize}let u=(s+1)*t,d=0;for(;i<u;)r[i++]==0&&d++;d&&(a||=[]).push({type:`missing`,row:s,n:d}),c++}(t===0||n===0)&&(a||=[]).push({type:`zero_sized`});let s=new $v(t,n,r,a),c=!1;for(let e=0;!c&&e<o.length;e+=2)o[e]!=null&&o[e+1]<n&&(c=!0);return c&&ny(s,o,e),s}function ty(e){let t=-1,n=!1;for(let r=0;r<e.childCount;r++){let i=e.child(r),a=0;if(n)for(let t=0;t<r;t++){let n=e.child(t);for(let e=0;e<n.childCount;e++){let i=n.child(e);t+i.attrs.rowspan>r&&(a+=i.attrs.colspan)}}for(let e=0;e<i.childCount;e++){let t=i.child(e);a+=t.attrs.colspan,t.attrs.rowspan>1&&(n=!0)}t==-1?t=a:t!=a&&(t=Math.max(t,a))}return t}function ny(e,t,n){e.problems||=[];let r={};for(let i=0;i<e.map.length;i++){let a=e.map[i];if(r[a])continue;r[a]=!0;let o=n.nodeAt(a);if(!o)throw RangeError(`No cell with offset ${a} found`);let s=null,c=o.attrs;for(let n=0;n<c.colspan;n++){let r=t[(i+n)%e.width*2];r!=null&&(!c.colwidth||c.colwidth[n]!=r)&&((s||=ry(c))[n]=r)}s&&e.problems.unshift({type:`colwidth mismatch`,pos:a,colwidth:s})}}function ry(e){if(e.colwidth)return e.colwidth.slice();let t=[];for(let n=0;n<e.colspan;n++)t.push(0);return t}function iy(e){let t=e.cached.tableNodeTypes;if(!t){t=e.cached.tableNodeTypes={};for(let n in e.nodes){let r=e.nodes[n],i=r.spec.tableRole;i&&(t[i]=r)}}return t}var ay=new Pr(`selectingCells`);function oy(e){for(let t=e.depth-1;t>0;t--)if(e.node(t).type.spec.tableRole==`row`)return e.node(0).resolve(e.before(t+1));return null}function sy(e){for(let t=e.depth;t>0;t--){let n=e.node(t).type.spec.tableRole;if(n===`cell`||n===`header_cell`)return e.node(t)}return null}function cy(e){let t=e.selection.$head;for(let e=t.depth;e>0;e--)if(t.node(e).type.spec.tableRole==`row`)return!0;return!1}function ly(e){let t=e.selection;if(`$anchorCell`in t&&t.$anchorCell)return t.$anchorCell.pos>t.$headCell.pos?t.$anchorCell:t.$headCell;if(`node`in t&&t.node&&t.node.type.spec.tableRole==`cell`)return t.$anchor;let n=oy(t.$head)||uy(t.$head);if(n)return n;throw RangeError(`No cell found around position ${t.head}`)}function uy(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){let r=t.type.spec.tableRole;if(r==`cell`||r==`header_cell`)return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){let r=t.type.spec.tableRole;if(r==`cell`||r==`header_cell`)return e.doc.resolve(n-t.nodeSize)}}function dy(e){return e.parent.type.spec.tableRole==`row`&&!!e.nodeAfter}function fy(e){return e.node(0).resolve(e.pos+e.nodeAfter.nodeSize)}function py(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function my(e,t,n){let r=e.node(-1),i=$v.get(r),a=e.start(-1),o=i.nextCell(e.pos-a,t,n);return o==null?null:e.node(0).resolve(a+o)}function hy(e,t,n=1){let r={...e,colspan:e.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(t,n),r.colwidth.some(e=>e>0)||(r.colwidth=null)),r}function gy(e,t,n=1){let r={...e,colspan:e.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let e=0;e<n;e++)r.colwidth.splice(t,0,0)}return r}function _y(e,t,n){let r=iy(t.type.schema).header_cell;for(let i=0;i<e.height;i++)if(t.nodeAt(e.map[n+i*e.width]).type!=r)return!1;return!0}var vy=class e extends O{constructor(e,t=e){let n=e.node(-1),r=$v.get(n),i=e.start(-1),a=r.rectBetween(e.pos-i,t.pos-i),o=e.node(0),s=r.cellsInRect(a).filter(e=>e!=t.pos-i);s.unshift(t.pos-i);let c=s.map(e=>{let t=n.nodeAt(e);if(!t)throw RangeError(`No cell with offset ${e} found`);let r=i+e+1;return new pr(o.resolve(r),o.resolve(r+t.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=t}map(t,n){let r=t.resolve(n.map(this.$anchorCell.pos)),i=t.resolve(n.map(this.$headCell.pos));if(dy(r)&&dy(i)&&py(r,i)){let t=this.$anchorCell.node(-1)!=r.node(-1);return t&&this.isRowSelection()?e.rowSelection(r,i):t&&this.isColSelection()?e.colSelection(r,i):new e(r,i)}return k.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=$v.get(e),n=this.$anchorCell.start(-1),r=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),i={},a=[];for(let n=r.top;n<r.bottom;n++){let o=[];for(let a=n*t.width+r.left,s=r.left;s<r.right;s++,a++){let n=t.map[a];if(i[n])continue;i[n]=!0;let s=t.findCell(n),c=e.nodeAt(n);if(!c)throw RangeError(`No cell with offset ${n} found`);let l=r.left-s.left,u=s.right-r.right;if(l>0||u>0){let e=c.attrs;if(l>0&&(e=hy(e,0,l)),u>0&&(e=hy(e,e.colspan-u,u)),s.left<r.left){if(c=c.type.createAndFill(e),!c)throw RangeError(`Could not create cell with attrs ${JSON.stringify(e)}`)}else c=c.type.create(e,c.content)}if(s.top<r.top||s.bottom>r.bottom){let e={...c.attrs,rowspan:Math.min(s.bottom,r.bottom)-Math.max(s.top,r.top)};c=s.top<r.top?c.type.createAndFill(e):c.type.create(e,c.content)}o.push(c)}a.push(e.child(n).copy(E.from(o)))}let o=this.isColSelection()&&this.isRowSelection()?e:a;return new D(E.from(o),1,1)}replace(e,t=D.empty){let n=e.steps.length,r=this.ranges;for(let i=0;i<r.length;i++){let{$from:a,$to:o}=r[i],s=e.mapping.slice(n);e.replace(s.map(a.pos),s.map(o.pos),i?D.empty:t)}let i=O.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)),-1);i&&e.setSelection(i)}replaceWith(e,t){this.replace(e,new D(E.from(t),0,0))}forEachCell(e){let t=this.$anchorCell.node(-1),n=$v.get(t),r=this.$anchorCell.start(-1),i=n.cellsInRect(n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r));for(let n=0;n<i.length;n++)e(t.nodeAt(i[n]),r+i[n])}isColSelection(){let e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);if(Math.min(e,t)>0)return!1;let n=e+this.$anchorCell.nodeAfter.attrs.rowspan,r=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(n,r)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){let r=t.node(-1),i=$v.get(r),a=t.start(-1),o=i.findCell(t.pos-a),s=i.findCell(n.pos-a),c=t.node(0);return o.top<=s.top?(o.top>0&&(t=c.resolve(a+i.map[o.left])),s.bottom<i.height&&(n=c.resolve(a+i.map[i.width*(i.height-1)+s.right-1]))):(s.top>0&&(n=c.resolve(a+i.map[s.left])),o.bottom<i.height&&(t=c.resolve(a+i.map[i.width*(i.height-1)+o.right-1]))),new e(t,n)}isRowSelection(){let e=this.$anchorCell.node(-1),t=$v.get(e),n=this.$anchorCell.start(-1),r=t.colCount(this.$anchorCell.pos-n),i=t.colCount(this.$headCell.pos-n);if(Math.min(r,i)>0)return!1;let a=r+this.$anchorCell.nodeAfter.attrs.colspan,o=i+this.$headCell.nodeAfter.attrs.colspan;return Math.max(a,o)==t.width}eq(t){return t instanceof e&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){let r=t.node(-1),i=$v.get(r),a=t.start(-1),o=i.findCell(t.pos-a),s=i.findCell(n.pos-a),c=t.node(0);return o.left<=s.left?(o.left>0&&(t=c.resolve(a+i.map[o.top*i.width])),s.right<i.width&&(n=c.resolve(a+i.map[i.width*(s.top+1)-1]))):(s.left>0&&(n=c.resolve(a+i.map[s.top*i.width])),o.right<i.width&&(t=c.resolve(a+i.map[i.width*(o.top+1)-1]))),new e(t,n)}toJSON(){return{type:`cell`,anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(t,n){return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){return new e(t.resolve(n),t.resolve(r))}getBookmark(){return new yy(this.$anchorCell.pos,this.$headCell.pos)}};vy.prototype.visible=!1,O.jsonID(`cell`,vy);var yy=class e{constructor(e,t){this.anchor=e,this.head=t}map(t){return new e(t.map(this.anchor),t.map(this.head))}resolve(e){let t=e.resolve(this.anchor),n=e.resolve(this.head);return t.parent.type.spec.tableRole==`row`&&n.parent.type.spec.tableRole==`row`&&t.index()<t.parent.childCount&&n.index()<n.parent.childCount&&py(t,n)?new vy(t,n):O.near(n,1)}};function by(e){if(!(e.selection instanceof vy))return null;let t=[];return e.selection.forEachCell((e,n)=>{t.push(ac.node(n,n+e.nodeSize,{class:`selectedCell`}))}),cc.create(e.doc,t)}function xy({$from:e,$to:t}){if(e.pos==t.pos||e.pos<t.pos-6)return!1;let n=e.pos,r=t.pos,i=e.depth;for(;i>=0&&!(e.after(i+1)<e.end(i));i--,n++);for(let e=t.depth;e>=0&&!(t.before(e+1)>t.start(e));e--,r--);return n==r&&/row|table/.test(e.node(i).type.spec.tableRole)}function Sy({$from:e,$to:t}){let n,r;for(let t=e.depth;t>0;t--){let r=e.node(t);if(r.type.spec.tableRole===`cell`||r.type.spec.tableRole===`header_cell`){n=r;break}}for(let e=t.depth;e>0;e--){let n=t.node(e);if(n.type.spec.tableRole===`cell`||n.type.spec.tableRole===`header_cell`){r=n;break}}return n!==r&&t.parentOffset===0}function Cy(e,t,n){let r=(t||e).selection,i=(t||e).doc,a,o;if(r instanceof A&&(o=r.node.type.spec.tableRole)){if(o==`cell`||o==`header_cell`)a=vy.create(i,r.from);else if(o==`row`){let e=i.resolve(r.from+1);a=vy.rowSelection(e,e)}else if(!n){let e=$v.get(r.node),t=r.from+1,n=t+e.map[e.width*e.height-1];a=vy.create(i,t+1,n)}}else r instanceof k&&xy(r)?a=k.create(i,r.from):r instanceof k&&Sy(r)&&(a=k.create(i,r.$from.start(),r.$from.end()));return a&&(t||=e.tr).setSelection(a),t}var wy=new Pr(`fix-tables`);function Ty(e,t,n,r){let i=e.childCount,a=t.childCount;outer:for(let o=0,s=0;o<a;o++){let a=t.child(o);for(let t=s,r=Math.min(i,o+3);t<r;t++)if(e.child(t)==a){s=t+1,n+=a.nodeSize;continue outer}r(a,n),s<i&&e.child(s).sameMarkup(a)?Ty(e.child(s),a,n+1,r):a.nodesBetween(0,a.content.size,r,n+1),n+=a.nodeSize}}function Ey(e,t){let n,r=(t,r)=>{t.type.spec.tableRole==`table`&&(n=Dy(e,t,r,n))};return t?t.doc!=e.doc&&Ty(t.doc,e.doc,0,r):e.doc.descendants(r),n}function Dy(e,t,n,r){let i=$v.get(t);if(!i.problems)return r;r||=e.tr;let a=[];for(let e=0;e<i.height;e++)a.push(0);for(let e=0;e<i.problems.length;e++){let o=i.problems[e];if(o.type==`collision`){let e=t.nodeAt(o.pos);if(!e)continue;let i=e.attrs;for(let e=0;e<i.rowspan;e++)a[o.row+e]+=o.n;r.setNodeMarkup(r.mapping.map(n+1+o.pos),null,hy(i,i.colspan-o.n,o.n))}else if(o.type==`missing`)a[o.row]+=o.n;else if(o.type==`overlong_rowspan`){let e=t.nodeAt(o.pos);if(!e)continue;r.setNodeMarkup(r.mapping.map(n+1+o.pos),null,{...e.attrs,rowspan:e.attrs.rowspan-o.n})}else if(o.type==`colwidth mismatch`){let e=t.nodeAt(o.pos);if(!e)continue;r.setNodeMarkup(r.mapping.map(n+1+o.pos),null,{...e.attrs,colwidth:o.colwidth})}else if(o.type==`zero_sized`){let e=r.mapping.map(n);r.delete(e,e+t.nodeSize)}}let o,s;for(let e=0;e<a.length;e++)a[e]&&(o??=e,s=e);for(let c=0,l=n+1;c<i.height;c++){let n=t.child(c),i=l+n.nodeSize,u=a[c];if(u>0){let t=`cell`;n.firstChild&&(t=n.firstChild.type.spec.tableRole);let a=[];for(let n=0;n<u;n++){let n=iy(e.schema)[t].createAndFill();n&&a.push(n)}let d=(c==0||o==c-1)&&s==c?l+1:i-1;r.insert(r.mapping.map(d),a)}l=i}return r.setMeta(wy,{fixTables:!0})}function Oy(e){let t=e.selection,n=ly(e),r=n.node(-1),i=n.start(-1),a=$v.get(r);return{...t instanceof vy?a.rectBetween(t.$anchorCell.pos-i,t.$headCell.pos-i):a.findCell(n.pos-i),tableStart:i,map:a,table:r}}function ky(e,{map:t,tableStart:n,table:r},i){let a=i>0?-1:0;_y(t,r,i+a)&&(a=i==0||i==t.width?null:0);for(let o=0;o<t.height;o++){let s=o*t.width+i;if(i>0&&i<t.width&&t.map[s-1]==t.map[s]){let a=t.map[s],c=r.nodeAt(a);e.setNodeMarkup(e.mapping.map(n+a),null,gy(c.attrs,i-t.colCount(a))),o+=c.attrs.rowspan-1}else{let c=a==null?iy(r.type.schema).cell:r.nodeAt(t.map[s+a]).type,l=t.positionAt(o,i,r);e.insert(e.mapping.map(n+l),c.createAndFill())}}return e}function Ay(e,t){if(!cy(e))return!1;if(t){let n=Oy(e);t(ky(e.tr,n,n.left))}return!0}function jy(e,t){if(!cy(e))return!1;if(t){let n=Oy(e);t(ky(e.tr,n,n.right))}return!0}function My(e,{map:t,table:n,tableStart:r},i){let a=e.mapping.maps.length;for(let o=0;o<t.height;){let s=o*t.width+i,c=t.map[s],l=n.nodeAt(c),u=l.attrs;if(i>0&&t.map[s-1]==c||i<t.width-1&&t.map[s+1]==c)e.setNodeMarkup(e.mapping.slice(a).map(r+c),null,hy(u,i-t.colCount(c)));else{let t=e.mapping.slice(a).map(r+c);e.delete(t,t+l.nodeSize)}o+=u.rowspan}}function Ny(e,t){if(!cy(e))return!1;if(t){let n=Oy(e),r=e.tr;if(n.left==0&&n.right==n.map.width)return!1;for(let e=n.right-1;My(r,n,e),e!=n.left;e--){let e=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!e)throw RangeError(`No table found`);n.table=e,n.map=$v.get(e)}t(r)}return!0}function Py(e,t,n){let r=iy(t.type.schema).header_cell;for(let i=0;i<e.width;i++)if(t.nodeAt(e.map[i+n*e.width])?.type!=r)return!1;return!0}function Fy(e,{map:t,tableStart:n,table:r},i){let a=n;for(let e=0;e<i;e++)a+=r.child(e).nodeSize;let o=[],s=i>0?-1:0;Py(t,r,i+s)&&(s=i==0||i==t.height?null:0);for(let a=0,c=t.width*i;a<t.width;a++,c++)if(i>0&&i<t.height&&t.map[c]==t.map[c-t.width]){let i=t.map[c],o=r.nodeAt(i).attrs;e.setNodeMarkup(n+i,null,{...o,rowspan:o.rowspan+1}),a+=o.colspan-1}else{let e=(s==null?iy(r.type.schema).cell:r.nodeAt(t.map[c+s*t.width])?.type)?.createAndFill();e&&o.push(e)}return e.insert(a,iy(r.type.schema).row.create(null,o)),e}function Iy(e,t){if(!cy(e))return!1;if(t){let n=Oy(e);t(Fy(e.tr,n,n.top))}return!0}function Ly(e,t){if(!cy(e))return!1;if(t){let n=Oy(e);t(Fy(e.tr,n,n.bottom))}return!0}function Ry(e,{map:t,table:n,tableStart:r},i){let a=0;for(let e=0;e<i;e++)a+=n.child(e).nodeSize;let o=a+n.child(i).nodeSize,s=e.mapping.maps.length;e.delete(a+r,o+r);let c=new Set;for(let a=0,o=i*t.width;a<t.width;a++,o++){let l=t.map[o];if(!c.has(l)){if(c.add(l),i>0&&l==t.map[o-t.width]){let t=n.nodeAt(l).attrs;e.setNodeMarkup(e.mapping.slice(s).map(l+r),null,{...t,rowspan:t.rowspan-1}),a+=t.colspan-1}else if(i<t.height&&l==t.map[o+t.width]){let o=n.nodeAt(l),c=o.attrs,u=o.type.create({...c,rowspan:o.attrs.rowspan-1},o.content),d=t.positionAt(i+1,a,n);e.insert(e.mapping.slice(s).map(r+d),u),a+=c.colspan-1}}}}function zy(e,t){if(!cy(e))return!1;if(t){let n=Oy(e),r=e.tr;if(n.top==0&&n.bottom==n.map.height)return!1;for(let e=n.bottom-1;Ry(r,n,e),e!=n.top;e--){let e=n.tableStart?r.doc.nodeAt(n.tableStart-1):r.doc;if(!e)throw RangeError(`No table found`);n.table=e,n.map=$v.get(n.table)}t(r)}return!0}function By(e){let t=e.content;return t.childCount==1&&t.child(0).isTextblock&&t.child(0).childCount==0}function Vy({width:e,height:t,map:n},r){let i=r.top*e+r.left,a=i,o=(r.bottom-1)*e+r.left,s=i+(r.right-r.left-1);for(let t=r.top;t<r.bottom;t++){if(r.left>0&&n[a]==n[a-1]||r.right<e&&n[s]==n[s+1])return!0;a+=e,s+=e}for(let a=r.left;a<r.right;a++){if(r.top>0&&n[i]==n[i-e]||r.bottom<t&&n[o]==n[o+e])return!0;i++,o++}return!1}function Hy(e,t){let n=e.selection;if(!(n instanceof vy)||n.$anchorCell.pos==n.$headCell.pos)return!1;let r=Oy(e),{map:i}=r;if(Vy(i,r))return!1;if(t){let n=e.tr,a={},o=E.empty,s,c;for(let e=r.top;e<r.bottom;e++)for(let t=r.left;t<r.right;t++){let l=i.map[e*i.width+t],u=r.table.nodeAt(l);if(!(a[l]||!u))if(a[l]=!0,s==null)s=l,c=u;else{By(u)||(o=o.append(u.content));let e=n.mapping.map(l+r.tableStart);n.delete(e,e+u.nodeSize)}}if(s==null||c==null)return!0;if(n.setNodeMarkup(s+r.tableStart,null,{...gy(c.attrs,c.attrs.colspan,r.right-r.left-c.attrs.colspan),rowspan:r.bottom-r.top}),o.size>0){let e=s+1+c.content.size,t=By(c)?s+1:e;n.replaceWith(t+r.tableStart,e+r.tableStart,o)}n.setSelection(new vy(n.doc.resolve(s+r.tableStart))),t(n)}return!0}function Uy(e,t){let n=iy(e.schema);return Wy(({node:e})=>n[e.type.spec.tableRole])(e,t)}function Wy(e){return(t,n)=>{let r=t.selection,i,a;if(r instanceof vy){if(r.$anchorCell.pos!=r.$headCell.pos)return!1;i=r.$anchorCell.nodeAfter,a=r.$anchorCell.pos}else{if(i=sy(r.$from),!i)return!1;a=oy(r.$from)?.pos}if(i==null||a==null||i.attrs.colspan==1&&i.attrs.rowspan==1)return!1;if(n){let o=i.attrs,s=[],c=o.colwidth;o.rowspan>1&&(o={...o,rowspan:1}),o.colspan>1&&(o={...o,colspan:1});let l=Oy(t),u=t.tr;for(let e=0;e<l.right-l.left;e++)s.push(c?{...o,colwidth:c&&c[e]?[c[e]]:null}:o);let d;for(let t=l.top;t<l.bottom;t++){let n=l.map.positionAt(t,l.left,l.table);t==l.top&&(n+=i.nodeSize);for(let r=l.left,a=0;r<l.right;r++,a++)r==l.left&&t==l.top||u.insert(d=u.mapping.map(n+l.tableStart,1),e({node:i,row:t,col:r}).createAndFill(s[a]))}u.setNodeMarkup(a,e({node:i,row:l.top,col:l.left}),s[0]),r instanceof vy&&u.setSelection(new vy(u.doc.resolve(r.$anchorCell.pos),d?u.doc.resolve(d):void 0)),n(u)}return!0}}function Gy(e,t){return function(n,r){if(!cy(n))return!1;let i=ly(n);if(i.nodeAfter.attrs[e]===t)return!1;if(r){let a=n.tr;n.selection instanceof vy?n.selection.forEachCell((n,r)=>{n.attrs[e]!==t&&a.setNodeMarkup(r,null,{...n.attrs,[e]:t})}):a.setNodeMarkup(i.pos,null,{...i.nodeAfter.attrs,[e]:t}),r(a)}return!0}}function Ky(e){return function(t,n){if(!cy(t))return!1;if(n){let r=iy(t.schema),i=Oy(t),a=t.tr,o=i.map.cellsInRect(e==`column`?{left:i.left,top:0,right:i.right,bottom:i.map.height}:e==`row`?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),s=o.map(e=>i.table.nodeAt(e));for(let e=0;e<o.length;e++)s[e].type==r.header_cell&&a.setNodeMarkup(i.tableStart+o[e],r.cell,s[e].attrs);if(a.steps.length===0)for(let e=0;e<o.length;e++)a.setNodeMarkup(i.tableStart+o[e],r.header_cell,s[e].attrs);n(a)}return!0}}function qy(e,t,n){let r=t.map.cellsInRect({left:0,top:0,right:e==`row`?t.map.width:1,bottom:e==`column`?t.map.height:1});for(let e=0;e<r.length;e++){let i=t.table.nodeAt(r[e]);if(i&&i.type!==n.header_cell)return!1}return!0}function Jy(e,t){return t||={useDeprecatedLogic:!1},t.useDeprecatedLogic?Ky(e):function(t,n){if(!cy(t))return!1;if(n){let r=iy(t.schema),i=Oy(t),a=t.tr,o=qy(`row`,i,r),s=qy(`column`,i,r),c=(e===`column`?o:e===`row`&&s)?1:0,l=e==`column`?{left:0,top:c,right:1,bottom:i.map.height}:e==`row`?{left:c,top:0,right:i.map.width,bottom:1}:i,u=e==`column`?s?r.cell:r.header_cell:e==`row`?o?r.cell:r.header_cell:r.cell;i.map.cellsInRect(l).forEach(e=>{let t=e+i.tableStart,n=a.doc.nodeAt(t);n&&a.setNodeMarkup(t,u,n.attrs)}),n(a)}return!0}}Jy(`row`,{useDeprecatedLogic:!0}),Jy(`column`,{useDeprecatedLogic:!0});var Yy=Jy(`cell`,{useDeprecatedLogic:!0});function Xy(e,t){if(t<0){let t=e.nodeBefore;if(t)return e.pos-t.nodeSize;for(let t=e.index(-1)-1,n=e.before();t>=0;t--){let r=e.node(-1).child(t),i=r.lastChild;if(i)return n-1-i.nodeSize;n-=r.nodeSize}}else{if(e.index()<e.parent.childCount-1)return e.pos+e.nodeAfter.nodeSize;let t=e.node(-1);for(let n=e.indexAfter(-1),r=e.after();n<t.childCount;n++){let e=t.child(n);if(e.childCount)return r+1;r+=e.nodeSize}}return null}function Zy(e){return function(t,n){if(!cy(t))return!1;let r=Xy(ly(t),e);if(r==null)return!1;if(n){let e=t.doc.resolve(r);n(t.tr.setSelection(k.between(e,fy(e))).scrollIntoView())}return!0}}function Qy(e,t){let n=e.selection.$anchor;for(let r=n.depth;r>0;r--)if(n.node(r).type.spec.tableRole==`table`)return t&&t(e.tr.delete(n.before(r),n.after(r)).scrollIntoView()),!0;return!1}function $y(e,t){let n=e.selection;if(!(n instanceof vy))return!1;if(t){let r=e.tr,i=iy(e.schema).cell.createAndFill().content;n.forEachCell((e,t)=>{e.content.eq(i)||r.replace(r.mapping.map(t+1),r.mapping.map(t+e.nodeSize-1),new D(i,0,0))}),r.docChanged&&t(r)}return!0}function eb(e){if(e.size===0)return null;let{content:t,openStart:n,openEnd:r}=e;for(;t.childCount==1&&(n>0&&r>0||t.child(0).type.spec.tableRole==`table`);)n--,r--,t=t.child(0).content;let i=t.child(0),a=i.type.spec.tableRole,o=i.type.schema,s=[];if(a==`row`)for(let e=0;e<t.childCount;e++){let i=t.child(e).content,a=e?0:Math.max(0,n-1),c=e<t.childCount-1?0:Math.max(0,r-1);(a||c)&&(i=nb(iy(o).row,new D(i,a,c)).content),s.push(i)}else if(a==`cell`||a==`header_cell`)s.push(n||r?nb(iy(o).row,new D(t,n,r)).content:t);else return null;return tb(o,s)}function tb(e,t){let n=[];for(let e=0;e<t.length;e++){let r=t[e];for(let t=r.childCount-1;t>=0;t--){let{rowspan:i,colspan:a}=r.child(t).attrs;for(let t=e;t<e+i;t++)n[t]=(n[t]||0)+a}}let r=0;for(let e=0;e<n.length;e++)r=Math.max(r,n[e]);for(let i=0;i<n.length;i++)if(i>=t.length&&t.push(E.empty),n[i]<r){let a=iy(e).cell.createAndFill(),o=[];for(let e=n[i];e<r;e++)o.push(a);t[i]=t[i].append(E.from(o))}return{height:t.length,width:r,rows:t}}function nb(e,t){let n=e.createAndFill();return new dr(n).replace(0,n.content.size,t).doc}function rb({width:e,height:t,rows:n},r,i){if(e!=r){let t=[],i=[];for(let e=0;e<n.length;e++){let a=n[e],o=[];for(let n=t[e]||0,i=0;n<r;i++){let s=a.child(i%a.childCount);n+s.attrs.colspan>r&&(s=s.type.createChecked(hy(s.attrs,s.attrs.colspan,n+s.attrs.colspan-r),s.content)),o.push(s),n+=s.attrs.colspan;for(let n=1;n<s.attrs.rowspan;n++)t[e+n]=(t[e+n]||0)+s.attrs.colspan}i.push(E.from(o))}n=i,e=r}if(t!=i){let e=[];for(let r=0,a=0;r<i;r++,a++){let o=[],s=n[a%t];for(let e=0;e<s.childCount;e++){let t=s.child(e);r+t.attrs.rowspan>i&&(t=t.type.create({...t.attrs,rowspan:Math.max(1,i-t.attrs.rowspan)},t.content)),o.push(t)}e.push(E.from(o))}n=e,t=i}return{width:e,height:t,rows:n}}function ib(e,t,n,r,i,a,o){let s=e.doc.type.schema,c=iy(s),l,u;if(i>t.width)for(let a=0,s=0;a<t.height;a++){let d=n.child(a);s+=d.nodeSize;let f=[],p;p=d.lastChild==null||d.lastChild.type==c.cell?l||=c.cell.createAndFill():u||=c.header_cell.createAndFill();for(let e=t.width;e<i;e++)f.push(p);e.insert(e.mapping.slice(o).map(s-1+r),f)}if(a>t.height){let s=[];for(let e=0,r=(t.height-1)*t.width;e<Math.max(t.width,i);e++){let i=e>=t.width?!1:n.nodeAt(t.map[r+e]).type==c.header_cell;s.push(i?u||=c.header_cell.createAndFill():l||=c.cell.createAndFill())}let d=c.row.create(null,E.from(s)),f=[];for(let e=t.height;e<a;e++)f.push(d);e.insert(e.mapping.slice(o).map(r+n.nodeSize-2),f)}return!!(l||u)}function ab(e,t,n,r,i,a,o,s){if(o==0||o==t.height)return!1;let c=!1;for(let l=i;l<a;l++){let i=o*t.width+l,a=t.map[i];if(t.map[i-t.width]==a){c=!0;let i=n.nodeAt(a),{top:u,left:d}=t.findCell(a);e.setNodeMarkup(e.mapping.slice(s).map(a+r),null,{...i.attrs,rowspan:o-u}),e.insert(e.mapping.slice(s).map(t.positionAt(o,d,n)),i.type.createAndFill({...i.attrs,rowspan:u+i.attrs.rowspan-o})),l+=i.attrs.colspan-1}}return c}function ob(e,t,n,r,i,a,o,s){if(o==0||o==t.width)return!1;let c=!1;for(let l=i;l<a;l++){let i=l*t.width+o,a=t.map[i];if(t.map[i-1]==a){c=!0;let i=n.nodeAt(a),u=t.colCount(a),d=e.mapping.slice(s).map(a+r);e.setNodeMarkup(d,null,hy(i.attrs,o-u,i.attrs.colspan-(o-u))),e.insert(d+i.nodeSize,i.type.createAndFill(hy(i.attrs,0,o-u))),l+=i.attrs.rowspan-1}}return c}function sb(e,t,n,r,i){let a=n?e.doc.nodeAt(n-1):e.doc;if(!a)throw Error(`No table found`);let o=$v.get(a),{top:s,left:c}=r,l=c+i.width,u=s+i.height,d=e.tr,f=0;function p(){if(a=n?d.doc.nodeAt(n-1):d.doc,!a)throw Error(`No table found`);o=$v.get(a),f=d.mapping.maps.length}ib(d,o,a,n,l,u,f)&&p(),ab(d,o,a,n,c,l,s,f)&&p(),ab(d,o,a,n,c,l,u,f)&&p(),ob(d,o,a,n,s,u,c,f)&&p(),ob(d,o,a,n,s,u,l,f)&&p();for(let e=s;e<u;e++){let t=o.positionAt(e,c,a),r=o.positionAt(e,l,a);d.replace(d.mapping.slice(f).map(t+n),d.mapping.slice(f).map(r+n),new D(i.rows[e-s],0,0))}p(),d.setSelection(new vy(d.doc.resolve(n+o.positionAt(s,c,a)),d.doc.resolve(n+o.positionAt(u-1,l-1,a)))),t(d)}var cb=ll({ArrowLeft:ub(`horiz`,-1),ArrowRight:ub(`horiz`,1),ArrowUp:ub(`vert`,-1),ArrowDown:ub(`vert`,1),"Shift-ArrowLeft":db(`horiz`,-1),"Shift-ArrowRight":db(`horiz`,1),"Shift-ArrowUp":db(`vert`,-1),"Shift-ArrowDown":db(`vert`,1),Backspace:$y,"Mod-Backspace":$y,Delete:$y,"Mod-Delete":$y});function lb(e,t,n){return n.eq(e.selection)?!1:(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function ub(e,t){return(n,r,i)=>{if(!i)return!1;let a=n.selection;if(a instanceof vy)return lb(n,r,O.near(a.$headCell,t));if(e!=`horiz`&&!a.empty)return!1;let o=hb(i,e,t);if(o==null)return!1;if(e==`horiz`)return lb(n,r,O.near(n.doc.resolve(a.head+t),t));{let i=n.doc.resolve(o),a=my(i,e,t),s;return s=a?O.near(a,1):t<0?O.near(n.doc.resolve(i.before(-1)),-1):O.near(n.doc.resolve(i.after(-1)),1),lb(n,r,s)}}}function db(e,t){return(n,r,i)=>{if(!i)return!1;let a=n.selection,o;if(a instanceof vy)o=a;else{let r=hb(i,e,t);if(r==null)return!1;o=new vy(n.doc.resolve(r))}let s=my(o.$headCell,e,t);return s?lb(n,r,new vy(o.$anchorCell,s)):!1}}function fb(e,t){let n=e.state.doc,r=oy(n.resolve(t));return r?(e.dispatch(e.state.tr.setSelection(new vy(r))),!0):!1}function pb(e,t,n){if(!cy(e.state))return!1;let r=eb(n),i=e.state.selection;if(i instanceof vy){r||={width:1,height:1,rows:[E.from(nb(iy(e.state.schema).cell,n))]};let t=i.$anchorCell.node(-1),a=i.$anchorCell.start(-1),o=$v.get(t).rectBetween(i.$anchorCell.pos-a,i.$headCell.pos-a);return r=rb(r,o.right-o.left,o.bottom-o.top),sb(e.state,e.dispatch,a,o,r),!0}else if(r){let t=ly(e.state),n=t.start(-1);return sb(e.state,e.dispatch,n,$v.get(t.node(-1)).findCell(t.pos-n),r),!0}else return!1}function mb(e,t){if(t.button!=0||t.ctrlKey||t.metaKey)return;let n=gb(e,t.target),r;if(t.shiftKey&&e.state.selection instanceof vy)i(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&n&&(r=oy(e.state.selection.$anchor))!=null&&_b(e,t)?.pos!=r.pos)i(r,t),t.preventDefault();else if(!n)return;function i(t,n){let r=_b(e,n),i=ay.getState(e.state)==null;if(!r||!py(t,r))if(i)r=t;else return;let a=new vy(t,r);if(i||!e.state.selection.eq(a)){let n=e.state.tr.setSelection(a);i&&n.setMeta(ay,t.pos),e.dispatch(n)}}function a(){e.root.removeEventListener(`mouseup`,a),e.root.removeEventListener(`dragstart`,a),e.root.removeEventListener(`mousemove`,o),ay.getState(e.state)!=null&&e.dispatch(e.state.tr.setMeta(ay,-1))}function o(r){let o=r,s=ay.getState(e.state),c;if(s!=null)c=e.state.doc.resolve(s);else if(gb(e,o.target)!=n&&(c=_b(e,t),!c))return a();c&&i(c,o)}e.root.addEventListener(`mouseup`,a),e.root.addEventListener(`dragstart`,a),e.root.addEventListener(`mousemove`,o)}function hb(e,t,n){if(!(e.state.selection instanceof k))return null;let{$head:r}=e.state.selection;for(let i=r.depth-1;i>=0;i--){let a=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:a.childCount))return null;if(a.type.spec.tableRole==`cell`||a.type.spec.tableRole==`header_cell`){let a=r.before(i),o=t==`vert`?n>0?`down`:`up`:n>0?`right`:`left`;return e.endOfTextblock(o)?a:null}}return null}function gb(e,t){for(;t&&t!=e.dom;t=t.parentNode)if(t.nodeName==`TD`||t.nodeName==`TH`)return t;return null}function _b(e,t){let n=e.posAtCoords({left:t.clientX,top:t.clientY});if(!n)return null;let{inside:r,pos:i}=n;return r>=0&&oy(e.state.doc.resolve(r))||oy(e.state.doc.resolve(i))}var vb=class{constructor(e,t){this.node=e,this.defaultCellMinWidth=t,this.dom=document.createElement(`div`),this.dom.className=`tableWrapper`,this.table=this.dom.appendChild(document.createElement(`table`)),this.table.style.setProperty(`--default-cell-min-width`,`${t}px`),this.colgroup=this.table.appendChild(document.createElement(`colgroup`)),yb(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement(`tbody`))}update(e){return e.type==this.node.type?(this.node=e,yb(e,this.colgroup,this.table,this.defaultCellMinWidth),!0):!1}ignoreMutation(e){return e.type==`attributes`&&(e.target==this.table||this.colgroup.contains(e.target))}};function yb(e,t,n,r,i,a){let o=0,s=!0,c=t.firstChild,l=e.firstChild;if(l){for(let e=0,n=0;e<l.childCount;e++){let{colspan:u,colwidth:d}=l.child(e).attrs;for(let e=0;e<u;e++,n++){let l=i==n?a:d&&d[e],u=l?l+`px`:``;if(o+=l||r,l||(s=!1),c)c.style.width!=u&&(c.style.width=u),c=c.nextSibling;else{let e=document.createElement(`col`);e.style.width=u,t.appendChild(e)}}}for(;c;){var u;let e=c.nextSibling;(u=c.parentNode)==null||u.removeChild(c),c=e}s?(n.style.width=o+`px`,n.style.minWidth=``):(n.style.width=``,n.style.minWidth=o+`px`)}}var bb=new Pr(`tableColumnResizing`);function xb({handleWidth:e=5,cellMinWidth:t=25,defaultCellMinWidth:n=100,View:r=vb,lastColumnResizable:i=!0}={}){let a=new j({key:bb,state:{init(e,t){var i;let o=(i=a.spec)==null||(i=i.props)==null?void 0:i.nodeViews,s=iy(t.schema).table.name;return r&&o&&(o[s]=(e,t)=>new r(e,n,t)),new Sb(-1,!1)},apply(e,t){return t.apply(e)}},props:{attributes:e=>{let t=bb.getState(e);return t&&t.activeHandle>-1?{class:`resize-cursor`}:{}},handleDOMEvents:{mousemove:(t,n)=>{Cb(t,n,e,i)},mouseleave:e=>{wb(e)},mousedown:(e,r)=>{Tb(e,r,t,n)}},decorations:e=>{let t=bb.getState(e);if(t&&t.activeHandle>-1)return Pb(e,t.activeHandle)},nodeViews:{}}});return a}var Sb=class e{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(t){let n=this,r=t.getMeta(bb);if(r&&r.setHandle!=null)return new e(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new e(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&t.docChanged){let r=t.mapping.map(n.activeHandle,-1);return dy(t.doc.resolve(r))||(r=-1),new e(r,n.dragging)}return n}};function Cb(e,t,n,r){if(!e.editable)return;let i=bb.getState(e.state);if(i&&!i.dragging){let a=Db(t.target),o=-1;if(a){let{left:r,right:i}=a.getBoundingClientRect();t.clientX-r<=n?o=Ob(e,t,`left`,n):i-t.clientX<=n&&(o=Ob(e,t,`right`,n))}if(o!=i.activeHandle){if(!r&&o!==-1){let t=e.state.doc.resolve(o),n=t.node(-1),r=$v.get(n),i=t.start(-1);if(r.colCount(t.pos-i)+t.nodeAfter.attrs.colspan-1==r.width-1)return}Ab(e,o)}}}function wb(e){if(!e.editable)return;let t=bb.getState(e.state);t&&t.activeHandle>-1&&!t.dragging&&Ab(e,-1)}function Tb(e,t,n,r){if(!e.editable)return!1;let i=e.dom.ownerDocument.defaultView??window,a=bb.getState(e.state);if(!a||a.activeHandle==-1||a.dragging)return!1;let o=e.state.doc.nodeAt(a.activeHandle),s=Eb(e,a.activeHandle,o.attrs);e.dispatch(e.state.tr.setMeta(bb,{setDragging:{startX:t.clientX,startWidth:s}}));function c(t){i.removeEventListener(`mouseup`,c),i.removeEventListener(`mousemove`,l);let r=bb.getState(e.state);r?.dragging&&(jb(e,r.activeHandle,kb(r.dragging,t,n)),e.dispatch(e.state.tr.setMeta(bb,{setDragging:null})))}function l(t){if(!t.which)return c(t);let i=bb.getState(e.state);if(i&&i.dragging){let a=kb(i.dragging,t,n);Mb(e,i.activeHandle,a,r)}}return Mb(e,a.activeHandle,s,r),i.addEventListener(`mouseup`,c),i.addEventListener(`mousemove`,l),t.preventDefault(),!0}function Eb(e,t,{colspan:n,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let a=e.domAtPos(t),o=a.node.childNodes[a.offset].offsetWidth,s=n;if(r)for(let e=0;e<n;e++)r[e]&&(o-=r[e],s--);return o/s}function Db(e){for(;e&&e.nodeName!=`TD`&&e.nodeName!=`TH`;)e=e.classList&&e.classList.contains(`ProseMirror`)?null:e.parentNode;return e}function Ob(e,t,n,r){let i=n==`right`?-r:r,a=e.posAtCoords({left:t.clientX+i,top:t.clientY});if(!a)return-1;let{pos:o}=a,s=oy(e.state.doc.resolve(o));if(!s)return-1;if(n==`right`)return s.pos;let c=$v.get(s.node(-1)),l=s.start(-1),u=c.map.indexOf(s.pos-l);return u%c.width==0?-1:l+c.map[u-1]}function kb(e,t,n){let r=t.clientX-e.startX;return Math.max(n,e.startWidth+r)}function Ab(e,t){e.dispatch(e.state.tr.setMeta(bb,{setHandle:t}))}function jb(e,t,n){let r=e.state.doc.resolve(t),i=r.node(-1),a=$v.get(i),o=r.start(-1),s=a.colCount(r.pos-o)+r.nodeAfter.attrs.colspan-1,c=e.state.tr;for(let e=0;e<a.height;e++){let t=e*a.width+s;if(e&&a.map[t]==a.map[t-a.width])continue;let r=a.map[t],l=i.nodeAt(r).attrs,u=l.colspan==1?0:s-a.colCount(r);if(l.colwidth&&l.colwidth[u]==n)continue;let d=l.colwidth?l.colwidth.slice():Nb(l.colspan);d[u]=n,c.setNodeMarkup(o+r,null,{...l,colwidth:d})}c.docChanged&&e.dispatch(c)}function Mb(e,t,n,r){let i=e.state.doc.resolve(t),a=i.node(-1),o=i.start(-1),s=$v.get(a).colCount(i.pos-o)+i.nodeAfter.attrs.colspan-1,c=e.domAtPos(i.start(-1)).node;for(;c&&c.nodeName!=`TABLE`;)c=c.parentNode;c&&yb(a,c.firstChild,c,r,s,n)}function Nb(e){return Array(e).fill(0)}function Pb(e,t){let n=[],r=e.doc.resolve(t),i=r.node(-1);if(!i)return cc.empty;let a=$v.get(i),o=r.start(-1),s=a.colCount(r.pos-o)+r.nodeAfter.attrs.colspan-1;for(let t=0;t<a.height;t++){let r=s+t*a.width;if((s==a.width-1||a.map[r]!=a.map[r+1])&&(t==0||a.map[r]!=a.map[r-a.width])){let t=a.map[r],s=o+t+i.nodeAt(t).nodeSize-1,c=document.createElement(`div`);c.className=`column-resize-handle`,bb.getState(e)?.dragging&&n.push(ac.node(o+t,o+t+i.nodeAt(t).nodeSize,{class:`column-resize-dragging`})),n.push(ac.widget(s,c))}}return cc.create(e.doc,n)}function Fb({allowTableNodeSelection:e=!1}={}){return new j({key:ay,state:{init(){return null},apply(e,t){let n=e.getMeta(ay);if(n!=null)return n==-1?null:n;if(t==null||!e.docChanged)return t;let{deleted:r,pos:i}=e.mapping.mapResult(t);return r?null:i}},props:{decorations:by,handleDOMEvents:{mousedown:mb},createSelectionBetween(e){return ay.getState(e.state)==null?null:e.state.selection},handleTripleClick:fb,handleKeyDown:cb,handlePaste:pb},appendTransaction(t,n,r){return Cy(r,Ey(r,n),e)}})}function Ib(e){return e===`left`||e===`right`||e===`center`?e:null}function Lb(e){let t=(e.style.textAlign||``).trim().toLowerCase(),n=(e.getAttribute(`align`)||``).trim().toLowerCase();return Ib(t||n)}function Rb(e){return Ib(e?.align)}function zb(){return{default:null,parseHTML:e=>Lb(e),renderHTML:e=>e.align?{style:`text-align: ${e.align}`}:{}}}var Bb=Wf.create({name:`tableCell`,addOptions(){return{HTMLAttributes:{}}},content:`block+`,addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:e=>{let t=e.getAttribute(`colwidth`),n=t?t.split(`,`).map(e=>parseInt(e,10)):null;if(!n){let t=e.closest(`table`)?.querySelectorAll(`colgroup > col`),n=Array.from(e.parentElement?.children||[]).indexOf(e);if(n&&n>-1&&t&&t[n]){let e=t[n].getAttribute(`width`);return e?[parseInt(e,10)]:null}}return n}},align:zb()}},tableRole:`cell`,isolating:!0,parseHTML(){return[{tag:`td`}]},renderHTML({HTMLAttributes:e}){return[`td`,Bu(this.options.HTMLAttributes,e),0]}}),Vb=Wf.create({name:`tableHeader`,addOptions(){return{HTMLAttributes:{}}},content:`block+`,addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:e=>{let t=e.getAttribute(`colwidth`);return t?t.split(`,`).map(e=>parseInt(e,10)):null}},align:zb()}},tableRole:`header_cell`,isolating:!0,parseHTML(){return[{tag:`th`}]},renderHTML({HTMLAttributes:e}){return[`th`,Bu(this.options.HTMLAttributes,e),0]}}),Hb=Wf.create({name:`tableRow`,addOptions(){return{HTMLAttributes:{}}},content:`(tableCell | tableHeader)*`,tableRole:`row`,parseHTML(){return[{tag:`tr`}]},renderHTML({HTMLAttributes:e}){return[`tr`,Bu(this.options.HTMLAttributes,e),0]}});function Ub(e,t){return t?[`width`,`${Math.max(t,e)}px`]:[`min-width`,`${e}px`]}function Wb(e,t,n,r,i,a){var o;let s=0,c=!0,l=t.firstChild,u=e.firstChild;if(u!==null)for(let e=0,n=0;e<u.childCount;e+=1){let{colspan:o,colwidth:d}=u.child(e).attrs;for(let e=0;e<o;e+=1,n+=1){let o=i===n?a:d&&d[e],u=o?`${o}px`:``;if(s+=o||r,o||(c=!1),l){if(l.style.width!==u){let[e,t]=Ub(r,o);l.style.setProperty(e,t)}l=l.nextSibling}else{let e=document.createElement(`col`),[n,i]=Ub(r,o);e.style.setProperty(n,i),t.appendChild(e)}}}for(;l;){let e=l.nextSibling;(o=l.parentNode)==null||o.removeChild(l),l=e}let d=e.attrs.style&&typeof e.attrs.style==`string`&&/\bwidth\s*:/i.test(e.attrs.style);c&&!d?(n.style.width=`${s}px`,n.style.minWidth=``):(n.style.width=``,n.style.minWidth=`${s}px`)}var Gb=class{constructor(e,t){this.node=e,this.cellMinWidth=t,this.dom=document.createElement(`div`),this.dom.className=`tableWrapper`,this.table=this.dom.appendChild(document.createElement(`table`)),e.attrs.style&&(this.table.style.cssText=e.attrs.style),this.colgroup=this.table.appendChild(document.createElement(`colgroup`)),Wb(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement(`tbody`))}update(e){return e.type===this.node.type?(this.node=e,Wb(e,this.colgroup,this.table,this.cellMinWidth),!0):!1}ignoreMutation(e){let t=e.target,n=this.dom.contains(t),r=this.contentDOM.contains(t);return!!(n&&!r&&(e.type===`attributes`||e.type===`childList`||e.type===`characterData`))}};function Kb(e,t,n,r){let i=0,a=!0,o=[],s=e.firstChild;if(!s)return{};for(let e=0,c=0;e<s.childCount;e+=1){let{colspan:l,colwidth:u}=s.child(e).attrs;for(let e=0;e<l;e+=1,c+=1){let s=n===c?r:u&&u[e];i+=s||t,s||(a=!1);let[l,d]=Ub(t,s);o.push([`col`,{style:`${l}: ${d}`}])}}let c=a?`${i}px`:``,l=a?``:`${i}px`;return{colgroup:[`colgroup`,{},...o],tableWidth:c,tableMinWidth:l}}function qb(e,t){return t?e.createChecked(null,t):e.createAndFill()}function Jb(e){if(e.cached.tableNodeTypes)return e.cached.tableNodeTypes;let t={};return Object.keys(e.nodes).forEach(n=>{let r=e.nodes[n];r.spec.tableRole&&(t[r.spec.tableRole]=r)}),e.cached.tableNodeTypes=t,t}function Yb(e,t,n,r,i){let a=Jb(e),o=[],s=[];for(let e=0;e<n;e+=1){let e=qb(a.cell,i);if(e&&s.push(e),r){let e=qb(a.header_cell,i);e&&o.push(e)}}let c=[];for(let e=0;e<t;e+=1)c.push(a.row.createChecked(null,r&&e===0?o:s));return a.table.createChecked(null,c)}function Xb(e){return e instanceof vy}var Zb=({editor:e})=>{let{selection:t}=e.state;if(!Xb(t))return!1;let n=0;return ku(t.ranges[0].$from,e=>e.type.name===`table`)?.node.descendants(e=>{if(e.type.name===`table`)return!1;[`tableCell`,`tableHeader`].includes(e.type.name)&&(n+=1)}),n===t.ranges.length?(e.commands.deleteTable(),!0):!1};function Qb(e){return(e||``).replace(/\s+/g,` `).trim()}function $b(e,t,n={}){let r=n.cellLineSeparator??``;if(!e||!e.content||e.content.length===0)return``;let i=[];e.content.forEach(e=>{let n=[];e.content&&e.content.forEach(e=>{let i=``;i=e.content&&Array.isArray(e.content)&&e.content.length>1?e.content.map(e=>t.renderChildren(e)).join(r):e.content?t.renderChildren(e.content):``;let a=Qb(i),o=e.type===`tableHeader`,s=Rb(e.attrs);n.push({text:a,isHeader:o,align:s})}),i.push(n)});let a=i.reduce((e,t)=>Math.max(e,t.length),0);if(a===0)return``;let o=Array(a).fill(0);i.forEach(e=>{for(let t=0;t<a;t+=1){let n=(e[t]?.text||``).length;n>o[t]&&(o[t]=n),o[t]<3&&(o[t]=3)}});let s=(e,t)=>e+` `.repeat(Math.max(0,t-e.length)),c=i[0],l=c.some(e=>e.isHeader),u=Array(a).fill(null);i.forEach(e=>{for(let t=0;t<a;t+=1)!u[t]&&e[t]?.align&&(u[t]=e[t].align)});let d=`
252
252
  `,f=Array(a).fill(0).map((e,t)=>l&&c[t]&&c[t].text||``);return d+=`| ${f.map((e,t)=>s(e,o[t])).join(` | `)} |
253
253
  `,d+=`| ${o.map((e,t)=>{let n=Math.max(3,e),r=u[t];return r===`left`?`:${`-`.repeat(n)}`:r===`right`?`${`-`.repeat(n)}:`:r===`center`?`:${`-`.repeat(n)}:`:`-`.repeat(n)}).join(` | `)} |
254
254
  `,(l?i.slice(1):i).forEach(e=>{d+=`| ${Array(a).fill(0).map((t,n)=>s(e[n]&&e[n].text||``,o[n])).join(` | `)} |
255
- `}),d}var ex=$b,tx=Wf.create({name:`table`,addOptions(){return{HTMLAttributes:{},resizable:!1,renderWrapper:!1,handleWidth:5,cellMinWidth:25,View:Gb,lastColumnResizable:!0,allowTableNodeSelection:!1}},content:`tableRow+`,tableRole:`table`,isolating:!0,group:`block`,parseHTML(){return[{tag:`table`}]},renderHTML({node:e,HTMLAttributes:t}){let{colgroup:n,tableWidth:r,tableMinWidth:i}=Kb(e,this.options.cellMinWidth),a=t.style;function o(){return a||(r?`width: ${r}`:`min-width: ${i}`)}let s=[`table`,Bu(this.options.HTMLAttributes,t,{style:o()}),n,[`tbody`,0]];return this.options.renderWrapper?[`div`,{class:`tableWrapper`},s]:s},parseMarkdown:(e,t)=>{let n=[],r=Array.isArray(e.align)?e.align:[];if(e.header){let i=[];e.header.forEach((e,n)=>{let a=Ib(r[n]??e.align),o=a?{align:a}:{};i.push(t.createNode(`tableHeader`,o,[{type:`paragraph`,content:t.parseInline(e.tokens)}]))}),n.push(t.createNode(`tableRow`,{},i))}return e.rows&&e.rows.forEach(e=>{let i=[];e.forEach((e,n)=>{let a=Ib(r[n]??e.align),o=a?{align:a}:{};i.push(t.createNode(`tableCell`,o,[{type:`paragraph`,content:t.parseInline(e.tokens)}]))}),n.push(t.createNode(`tableRow`,{},i))}),t.createNode(`table`,void 0,n)},renderMarkdown:(e,t)=>ex(e,t),addCommands(){return{insertTable:({rows:e=3,cols:t=3,withHeaderRow:n=!0}={})=>({tr:r,dispatch:i,editor:a})=>{let o=Yb(a.schema,e,t,n);if(i){let e=r.selection.from+1;r.replaceSelectionWith(o).scrollIntoView().setSelection(k.near(r.doc.resolve(e)))}return!0},addColumnBefore:()=>({state:e,dispatch:t})=>Ay(e,t),addColumnAfter:()=>({state:e,dispatch:t})=>jy(e,t),deleteColumn:()=>({state:e,dispatch:t})=>Ny(e,t),addRowBefore:()=>({state:e,dispatch:t})=>Iy(e,t),addRowAfter:()=>({state:e,dispatch:t})=>Ly(e,t),deleteRow:()=>({state:e,dispatch:t})=>zy(e,t),deleteTable:()=>({state:e,dispatch:t})=>Qy(e,t),mergeCells:()=>({state:e,dispatch:t})=>Hy(e,t),splitCell:()=>({state:e,dispatch:t})=>Uy(e,t),toggleHeaderColumn:()=>({state:e,dispatch:t})=>Jy(`column`)(e,t),toggleHeaderRow:()=>({state:e,dispatch:t})=>Jy(`row`)(e,t),toggleHeaderCell:()=>({state:e,dispatch:t})=>Yy(e,t),mergeOrSplit:()=>({state:e,dispatch:t})=>Hy(e,t)?!0:Uy(e,t),setCellAttribute:(e,t)=>({state:n,dispatch:r})=>Gy(e,t)(n,r),goToNextCell:()=>({state:e,dispatch:t})=>Zy(1)(e,t),goToPreviousCell:()=>({state:e,dispatch:t})=>Zy(-1)(e,t),fixTables:()=>({state:e,dispatch:t})=>(t&&Ey(e),!0),setCellSelection:e=>({tr:t,dispatch:n})=>{if(n){let n=vy.create(t.doc,e.anchorCell,e.headCell);t.setSelection(n)}return!0}}},addKeyboardShortcuts(){return{Tab:()=>this.editor.commands.goToNextCell()?!0:this.editor.can().addRowAfter()?this.editor.chain().addRowAfter().goToNextCell().run():!1,"Shift-Tab":()=>this.editor.commands.goToPreviousCell(),Backspace:Zb,"Mod-Backspace":Zb,Delete:Zb,"Mod-Delete":Zb}},addProseMirrorPlugins(){return[...this.options.resizable&&this.editor.isEditable?[xb({handleWidth:this.options.handleWidth,cellMinWidth:this.options.cellMinWidth,defaultCellMinWidth:this.options.cellMinWidth,View:this.options.View,lastColumnResizable:this.options.lastColumnResizable})]:[],Fb({allowTableNodeSelection:this.options.allowTableNodeSelection})]},extendNodeSchema(e){return{tableRole:M(j(e,`tableRole`,{name:e.name,options:e.options,storage:e.storage}))}}});N.create({name:`tableKit`,addExtensions(){let e=[];return this.options.table!==!1&&e.push(tx.configure(this.options.table)),this.options.tableCell!==!1&&e.push(Bb.configure(this.options.tableCell)),this.options.tableHeader!==!1&&e.push(Vb.configure(this.options.tableHeader)),this.options.tableRow!==!1&&e.push(Hb.configure(this.options.tableRow)),e}});var nx=`footnote`,rx=/^(?: {4}|\t)/,ix=/^\[\^([^\]\n]+)\]:(.*)(?:\n|$)/;function ax(e){return typeof e==`string`?e.trim().replace(/\s+/g,` `):``}function ox(e){return ax(e).toLowerCase()}function sx(e){return`[^${ax(e)||nx}]`}function cx(e){return`${sx(e)}:`}function lx(e){return ox(e).replace(/[^a-z0-9_-]+/g,`-`).replace(/^-+|-+$/g,``)||nx}function ux(e){return e.split(`
255
+ `}),d}var ex=$b,tx=Wf.create({name:`table`,addOptions(){return{HTMLAttributes:{},resizable:!1,renderWrapper:!1,handleWidth:5,cellMinWidth:25,View:Gb,lastColumnResizable:!0,allowTableNodeSelection:!1}},content:`tableRow+`,tableRole:`table`,isolating:!0,group:`block`,parseHTML(){return[{tag:`table`}]},renderHTML({node:e,HTMLAttributes:t}){let{colgroup:n,tableWidth:r,tableMinWidth:i}=Kb(e,this.options.cellMinWidth),a=t.style;function o(){return a||(r?`width: ${r}`:`min-width: ${i}`)}let s=[`table`,Bu(this.options.HTMLAttributes,t,{style:o()}),n,[`tbody`,0]];return this.options.renderWrapper?[`div`,{class:`tableWrapper`},s]:s},parseMarkdown:(e,t)=>{let n=[],r=Array.isArray(e.align)?e.align:[];if(e.header){let i=[];e.header.forEach((e,n)=>{let a=Ib(r[n]??e.align),o=a?{align:a}:{};i.push(t.createNode(`tableHeader`,o,[{type:`paragraph`,content:t.parseInline(e.tokens)}]))}),n.push(t.createNode(`tableRow`,{},i))}return e.rows&&e.rows.forEach(e=>{let i=[];e.forEach((e,n)=>{let a=Ib(r[n]??e.align),o=a?{align:a}:{};i.push(t.createNode(`tableCell`,o,[{type:`paragraph`,content:t.parseInline(e.tokens)}]))}),n.push(t.createNode(`tableRow`,{},i))}),t.createNode(`table`,void 0,n)},renderMarkdown:(e,t)=>ex(e,t),addCommands(){return{insertTable:({rows:e=3,cols:t=3,withHeaderRow:n=!0}={})=>({tr:r,dispatch:i,editor:a})=>{let o=Yb(a.schema,e,t,n);if(i){let e=r.selection.from+1;r.replaceSelectionWith(o).scrollIntoView().setSelection(k.near(r.doc.resolve(e)))}return!0},addColumnBefore:()=>({state:e,dispatch:t})=>Ay(e,t),addColumnAfter:()=>({state:e,dispatch:t})=>jy(e,t),deleteColumn:()=>({state:e,dispatch:t})=>Ny(e,t),addRowBefore:()=>({state:e,dispatch:t})=>Iy(e,t),addRowAfter:()=>({state:e,dispatch:t})=>Ly(e,t),deleteRow:()=>({state:e,dispatch:t})=>zy(e,t),deleteTable:()=>({state:e,dispatch:t})=>Qy(e,t),mergeCells:()=>({state:e,dispatch:t})=>Hy(e,t),splitCell:()=>({state:e,dispatch:t})=>Uy(e,t),toggleHeaderColumn:()=>({state:e,dispatch:t})=>Jy(`column`)(e,t),toggleHeaderRow:()=>({state:e,dispatch:t})=>Jy(`row`)(e,t),toggleHeaderCell:()=>({state:e,dispatch:t})=>Yy(e,t),mergeOrSplit:()=>({state:e,dispatch:t})=>Hy(e,t)?!0:Uy(e,t),setCellAttribute:(e,t)=>({state:n,dispatch:r})=>Gy(e,t)(n,r),goToNextCell:()=>({state:e,dispatch:t})=>Zy(1)(e,t),goToPreviousCell:()=>({state:e,dispatch:t})=>Zy(-1)(e,t),fixTables:()=>({state:e,dispatch:t})=>(t&&Ey(e),!0),setCellSelection:e=>({tr:t,dispatch:n})=>{if(n){let n=vy.create(t.doc,e.anchorCell,e.headCell);t.setSelection(n)}return!0}}},addKeyboardShortcuts(){return{Tab:()=>this.editor.commands.goToNextCell()?!0:this.editor.can().addRowAfter()?this.editor.chain().addRowAfter().goToNextCell().run():!1,"Shift-Tab":()=>this.editor.commands.goToPreviousCell(),Backspace:Zb,"Mod-Backspace":Zb,Delete:Zb,"Mod-Delete":Zb}},addProseMirrorPlugins(){return[...this.options.resizable&&this.editor.isEditable?[xb({handleWidth:this.options.handleWidth,cellMinWidth:this.options.cellMinWidth,defaultCellMinWidth:this.options.cellMinWidth,View:this.options.View,lastColumnResizable:this.options.lastColumnResizable})]:[],Fb({allowTableNodeSelection:this.options.allowTableNodeSelection})]},extendNodeSchema(e){return{tableRole:Pu(M(e,`tableRole`,{name:e.name,options:e.options,storage:e.storage}))}}});N.create({name:`tableKit`,addExtensions(){let e=[];return this.options.table!==!1&&e.push(tx.configure(this.options.table)),this.options.tableCell!==!1&&e.push(Bb.configure(this.options.tableCell)),this.options.tableHeader!==!1&&e.push(Vb.configure(this.options.tableHeader)),this.options.tableRow!==!1&&e.push(Hb.configure(this.options.tableRow)),e}});var nx=`footnote`,rx=/^(?: {4}|\t)/,ix=/^\[\^([^\]\n]+)\]:(.*)(?:\n|$)/;function ax(e){return typeof e==`string`?e.trim().replace(/\s+/g,` `):``}function ox(e){return ax(e).toLowerCase()}function sx(e){return`[^${ax(e)||nx}]`}function cx(e){return`${sx(e)}:`}function lx(e){return ox(e).replace(/[^a-z0-9_-]+/g,`-`).replace(/^-+|-+$/g,``)||nx}function ux(e){return e.split(`
256
256
  `).map(e=>` ${e}`).join(`
257
257
  `)}function dx(e){return e?.type===`paragraph`&&(!e.content||e.content.length===0)}function fx(e){if(e.type!==`doc`||!Array.isArray(e.content)||e.content.length<2)return e;let t=[...e.content];for(;t.length>=2&&dx(t[t.length-1])&&t[t.length-2]?.type===`footnoteDefinition`;)t.pop();return t.length===e.content.length?e:{...e,content:t}}function px(e){let t=e.match(ix);if(!t)return null;let n=ax(t[1]);if(!n)return null;let r=[],i=(t[2]??``).replace(/^ /,``);i&&r.push(i);let a=t[0],o=a.length;for(;o<e.length;){let t=e.slice(o).match(/^(.*)(\n|$)/);if(!t)break;let n=t[1]??``,i=t[0];if(rx.test(n)){r.push(n.replace(rx,``)),a+=i,o+=i.length;continue}if(n.trim()===``){let t=e.slice(o+i.length).match(/^(.*)(?:\n|$)/)?.[1]??``;if(rx.test(t)){r.push(``),a+=i,o+=i.length;continue}}break}return{label:n,raw:a,contentMarkdown:r.join(`
258
258
  `)}}function mx(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`)}function hx(e){let t=e.layout&&String(e.layout)!==`regular`?String(e.layout):`regular`;return{src:String(e.src??``),alt:String(e.alt??``),title:String(e.title??``),caption:String(e.caption??``),href:String(e.href??``),layout:t}}function gx(e){let n=[`src="${mx(e.src)}"`];e.alt&&n.push(`alt="${mx(e.alt)}"`),e.title&&n.push(`title="${mx(e.title)}"`);let r=`<img ${n.join(` `)}>`,i=e.href?t(e.href):``;return`${i?`<a href="${mx(i)}">${r}</a>`:r}${e.caption?`<figcaption>${mx(e.caption)}</figcaption>`:``}`}function _x(e){let t=hx(e);return`<figure${t.layout===`regular`?``:` data-layout="${mx(t.layout)}"`}>${gx(t)}</figure>`}function vx(e){let t=hx(e),n=[`data-jant-node="image"`];return t.layout!==`regular`&&n.push(`data-jant-layout="${mx(t.layout)}"`),`<figure ${n.join(` `)}>${gx(t)}</figure>`}function yx(e){let t=hx(e);return t.caption||t.href||t.layout!==`regular`?vx(t):t.title?`![${t.alt}](${t.src} "${t.title}")`:`![${t.alt}](${t.src})`}var bx={gfm:!0,breaks:!1},xx=`<!--more-->`,Sx=[`Read More ↓`,`Read More`],Cx=/^(?:<!--more-->|Read More ↓|Read More)[ \t]*(?:\n|$)/;function wx(e){let t=Math.max(2,...Array.from(e.matchAll(/`+/g),e=>e[0].length));return"`".repeat(Math.max(3,t+1))}function Tx(e){let t=e.querySelector(`img`),n=e.querySelector(`figcaption`),r=e.querySelector(`a`);return{src:t?.getAttribute(`src`)??``,alt:t?.getAttribute(`alt`)??``,title:t?.getAttribute(`title`)??``,caption:n?.textContent??``,href:r?.getAttribute(`href`)??``,layout:e.getAttribute(`data-layout`)??`regular`}}function Ex(e,t){return e.match(RegExp(`${t}="([^"]*)"`,`i`))?.[1]??null}function Dx(e){return e.replace(/&quot;/g,`"`).replace(/&#39;/g,`'`).replace(/&lt;/g,`<`).replace(/&gt;/g,`>`).replace(/&amp;/g,`&`)}function Ox(e){let t=e.trim().match(/^<figure\b([^>]*)data-jant-node="image"([^>]*)>([\s\S]*?)<\/figure>$/i);if(!t)return null;let n=`${t[1]??``} ${t[2]??``}`,r=t[3]??``,i=Ex(n,`data-jant-layout`)||Ex(n,`data-layout`)||void 0,a=r.match(/<a\b[^>]*href="([^"]*)"[^>]*>/i)?.[1],o=r.match(/<img\b([^>]*)>/i);if(!o)return null;let s=o[1]??``,c=Ex(s,`src`);if(!c)return null;let l=r.match(/<figcaption>([\s\S]*?)<\/figcaption>/i)?.[1],u=l?Dx(l.trim()):void 0,d={src:Dx(c)},f=Ex(s,`alt`),p=Ex(s,`title`);return f&&(d.alt=Dx(f)),p&&(d.title=Dx(p)),u&&(d.caption=u),a&&(d.href=Dx(a)),i&&i!==`regular`&&(d.layout=Dx(i)),d}var kx=Wf.create({name:`image`,group:`block`,atom:!0,selectable:!0,draggable:!0,addAttributes(){return{src:{default:``},alt:{default:``},title:{default:``},caption:{default:``},href:{default:``},layout:{default:`regular`}}},parseHTML(){return[{tag:`figure[data-image]`,getAttrs(e){return Tx(e)}},{tag:`figure`,getAttrs(e){let t=e;return t.querySelector(`img`)?Tx(t):!1}},{tag:`img[src]`,getAttrs(e){let t=e;return{src:t.getAttribute(`src`)??``,alt:t.getAttribute(`alt`)??``,title:t.getAttribute(`title`)??``}}}]},renderHTML({node:e}){let t={"data-image":``};e.attrs.layout&&e.attrs.layout!==`regular`&&(t[`data-layout`]=e.attrs.layout);let n={src:e.attrs.src};e.attrs.alt&&(n.alt=e.attrs.alt),e.attrs.title&&(n.title=e.attrs.title);let r=[`img`,n],i=[];return e.attrs.href?i.push([`a`,{href:e.attrs.href},r]):i.push(r),e.attrs.caption&&i.push([`figcaption`,{},e.attrs.caption]),[`figure`,t,...i]},parseMarkdown:(e,t)=>t.createNode(`image`,{src:e.href,title:e.title??``,alt:e.text??``}),renderMarkdown:e=>yx(e.attrs??{})}),Ax=zm.extend({renderMarkdown(e,t){let n=e.attrs?.language?String(e.attrs.language):``,r=t.renderChildren(e.content??[]),i=wx(r);return`${i}${n}\n${r}\n${i}`}}),jx=N.create({name:`markdownFigureImageSupport`,markdownTokenName:`imageFigure`,parseMarkdown:(e,t)=>t.createNode(`image`,e.attrs??{}),markdownTokenizer:{name:`imageFigure`,level:`block`,start(e){return e.indexOf(`<figure`)},tokenize(e){let t=e.match(/^<figure\b[^>]*data-jant-node="image"[\s\S]*?<\/figure>(?:\n|$)?/i);if(!t)return;let n=Ox(t[0]);if(n)return{type:`imageFigure`,raw:t[0],attrs:n}}}});function Mx(){return{name:`embed`,level:`block`,start(e){return e.indexOf("```jant-embed")},tokenize(e){let t=e.match(/^```jant-embed[ \t]*\n([\s\S]*?)\n?```(?:\n|$)/);if(!t)return;let n=(t[1]??``).split(`
@@ -265,7 +265,7 @@ ${t.slice(l+2)}`,d+=1;else break}t.push({indent:l,number:parseInt(s,10),content:
265
265
  `)){let t=r.text.replace(/\n$/,``);t&&e.push({...r,text:t});continue}r&&e.push(r)}t.content=e}return t}function Ux(e){return e}function Wx(e=Vx()){return new Mm({extensions:e,markedOptions:bx})}var Gx=null;function Kx(){return Gx??=Wx(),Gx}function qx(e){return Hx(Kx().parse(e))}function Jx(e){return Ux(Kx().serialize(fx(e)))}function Yx(e,t){let n=Zx(e);return n?n===t?0:n.startsWith(t)?1:n.split(/[\s\-_.:/]+/).filter(Boolean).some(e=>e.startsWith(t))?2:n.includes(t)?3:null:null}function Xx(e,t){let n=null;for(let r of e){let e=Yx(r,t);if(e===0)return 0;e!==null&&(n===null||e<n)&&(n=e)}return n}function Zx(e){if(!e)return``;let t=``;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);r>=65281&&r<=65374?t+=String.fromCharCode(r-65248):r===12288?t+=` `:t+=e[n]}return t.trim().toLowerCase()}function Qx(e,t){return Xx([e.title,e.slug],t)}function $x(e,t){if(e.length===0)return[];let n=new Set(t),r=[],i=[];for(let t of e)n.has(t.id)?r.push(t.id):i.push(t.id);return[...r,...i]}function eS(e,t){if(e.length===0||t.length===0)return[...e];let n=new Map(e.map(e=>[e.id,e])),r=[],i=new Set;for(let e of t){let t=n.get(e);!t||i.has(e)||(r.push(t),i.add(e))}for(let t of e)i.has(t.id)||r.push(t);return r}function tS(e,t){let n=Zx(t);return n?e.map((e,t)=>({item:e,index:t,rank:Qx(e,n)})).filter(e=>e.rank!==null).sort((e,t)=>e.rank-t.rank||e.index-t.index).map(e=>e.item):[...e]}var nS=/^—\s*(.*?)(?:\s+(https?:\/\/\S+))?\s*$/;function rS(e){return e?JSON.parse(JSON.stringify(e)):null}function iS(e){return e?typeof e.text==`string`?e.text:Array.isArray(e.content)?e.content.map(iS).join(``):``:``}function aS(e,t=2){return{type:`heading`,attrs:{level:t},content:[{type:`text`,text:e}]}}function oS(e){return e?{type:`paragraph`,content:[{type:`text`,text:e}]}:{type:`paragraph`}}function sS(e){return{type:`paragraph`,content:[{type:`text`,text:e,marks:[{type:`link`,attrs:{href:e}}]}]}}function cS(e){let t=nS.exec(e.trim());return t?{author:t[1].trim(),url:t[2]??null}:{author:``,url:null}}function lS(e){if(!e)return null;if(Array.isArray(e.marks)){let t=e.marks.find(e=>e.type===`link`)?.attrs?.href;if(typeof t==`string`&&t)return t}if(Array.isArray(e.content))for(let t of e.content){let e=lS(t);if(e)return e}return null}function uS(e,t){let n=e.trim(),r=t?.trim()??``;if(!n&&!r)return null;let i=e=>({type:`text`,text:e,marks:[{type:`link`,attrs:{href:r}}]});return n&&r?{type:`paragraph`,content:[{type:`text`,text:`— `},i(n)]}:n?{type:`paragraph`,content:[{type:`text`,text:`— ${n}`}]}:{type:`paragraph`,content:[{type:`text`,text:`— `},i(r)]}}function dS(e,t){let n=e.split(`
266
266
  `).map(e=>oS(e));return t&&n.push(t),{type:`blockquote`,content:n}}function fS(e,t,n){if(e===t)return n;let r={...n},i=rS(n.bodyJson),a=Array.isArray(i?.content)?[...i.content]:[];if(t===`link`&&r.url===``){let e=a[0],t=lS(e);t&&e?.type===`paragraph`&&Array.isArray(e.content)&&e.content.length===1&&iS(e)===t&&(r.url=t,a.shift())}if(t===`quote`&&r.quoteText===``&&a[0]?.type===`blockquote`){let e=Array.isArray(a[0].content)?[...a[0].content]:[],t=e[e.length-1],n=iS(t);if(e.length>0&&/^—/.test(n.trim())){let i=cS(n),a=lS(t)??i.url,o=i.author===a?``:i.author;o&&(r.quoteAuthor=r.quoteAuthor||o),a&&r.url===``&&(r.url=a),e.pop()}r.quoteText=e.map(iS).join(`
267
267
  `).trim(),a.shift()}let o=[];if(t===`quote`&&r.title.trim()!==``&&(o.push(aS(r.title.trim())),r.title=``),t!==`quote`&&r.quoteText.trim()!==``){let e=t===`note`?r.url:null;o.push(dS(r.quoteText,uS(r.quoteAuthor,e))),r.quoteText=``,r.quoteAuthor=``,t===`note`&&(r.url=``)}else t===`note`&&r.url.trim()!==``&&(o.push(sS(r.url.trim())),r.url=``);return o.length&&a.unshift(...o),r.bodyJson=a.length?{type:`doc`,content:a}:null,r.showTitle=t===`note`&&r.title.trim().length>0,r}var pS={site:`sit`,siteDomain:`sdm`,post:`pst`,media:`med`,uploadSession:`upl`,collection:`col`,path:`pth`,collectionDirectoryItem:`cdi`,navItem:`nav`,apiToken:`api`,user:`usr`,session:`ses`,account:`acc`,verification:`vrf`,telegramBinding:`tgb`,telegramBindingCode:`tgc`,telegramMediaGroupItem:`tmg`,storagePurge:`spg`};pS.user,pS.session,pS.account,pS.verification;var mS=[`image/jpeg`,`image/png`,`image/gif`,`image/webp`,`image/svg+xml`,`image/avif`,`image/bmp`,`image/x-icon`],hS=[`video/mp4`,`video/webm`,`video/quicktime`,`video/x-msvideo`,`video/x-matroska`,`video/mpeg`,`video/3gpp`,`video/x-flv`,`video/ogg`],gS=[`audio/mpeg`,`audio/ogg`,`audio/wav`,`audio/mp4`,`audio/x-m4a`,`audio/flac`,`audio/aac`,`audio/webm`,`audio/x-aiff`,`audio/opus`,`audio/3gpp`,`audio/midi`],_S=[`application/pdf`,`application/epub+zip`,`application/x-mobipocket-ebook`,`application/vnd.amazon.ebook`],vS=[`application/msword`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/vnd.ms-excel`,`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,`application/vnd.ms-powerpoint`,`application/vnd.openxmlformats-officedocument.presentationml.presentation`,`application/vnd.oasis.opendocument.text`,`application/vnd.oasis.opendocument.spreadsheet`,`application/vnd.oasis.opendocument.presentation`,`application/vnd.apple.pages`,`application/vnd.apple.numbers`,`application/vnd.apple.keynote`],yS=[`text/plain`,`text/markdown`,`text/csv`,`text/html`,`text/css`,`text/javascript`,`text/xml`,`text/rtf`,`text/tab-separated-values`,`text/calendar`,`application/json`,`application/xml`,`application/yaml`,`application/toml`],bS=[`application/zip`,`application/x-tar`,`application/gzip`,`application/x-bzip2`,`application/x-7z-compressed`,`application/x-rar-compressed`,`application/zstd`],xS=[`font/ttf`,`font/otf`,`font/woff`,`font/woff2`],SS=[`model/gltf+json`,`model/gltf-binary`,`model/obj`,`application/x-figma`,`image/vnd.dxf`],CS=[`application/sql`,`application/wasm`,`application/x-ipynb+json`,`application/x-sh`,`application/x-python-code`],wS=new Map([...mS.map(e=>[e,`image`]),...hS.map(e=>[e,`video`]),...gS.map(e=>[e,`audio`]),..._S.map(e=>[e,`document`]),...vS.map(e=>[e,`office`]),...yS.map(e=>[e,`text`]),...bS.map(e=>[e,`archive`]),...xS.map(e=>[e,`font`]),...SS.map(e=>[e,`3d`]),...CS.map(e=>[e,`code`])]);function TS(e){return wS.get(e)||(e.startsWith(`image/`)?`image`:e.startsWith(`video/`)?`video`:e.startsWith(`audio/`)?`audio`:e.startsWith(`font/`)?`font`:e.startsWith(`model/`)?`3d`:e.startsWith(`text/`)?`text`:`archive`)}function ES(e){return e.startsWith(`image/`)}function DS(e,t){return OS(e.type,e.size,t)}function OS(e,t,n){if(n?.imagesOnly&&!ES(e))return`File type not allowed.`;let r=n.maxFileSizeMB;return t>r*1024*1024?`File too large (max ${r}MB).`:null}var kS={SITE_NAME:{defaultValue:`Jant`,envOnly:!1,envKeys:[`SITE_NAME`]},SITE_DESCRIPTION:{defaultValue:``,envOnly:!1,envKeys:[`SITE_DESCRIPTION`]},SITE_LANGUAGE:{defaultValue:`en`,envOnly:!1,envKeys:[`SITE_LANGUAGE`]},DASHBOARD_LANGUAGE:{defaultValue:``,envOnly:!1,envKeys:[`DASHBOARD_LANGUAGE`]},CJK_SERIF_FONT:{defaultValue:`off`,envOnly:!1,envKeys:[`CJK_SERIF_FONT`]},HOME_DEFAULT_VIEW:{defaultValue:`latest`,envOnly:!1,envKeys:[`HOME_DEFAULT_VIEW`]},MAIN_RSS_FEED:{defaultValue:`featured`,envOnly:!1,envKeys:[`MAIN_RSS_FEED`]},DEFAULT_THEME:{defaultValue:`tufte`,envOnly:!0,envKeys:[`DEFAULT_THEME`]},DEFAULT_FONT_THEME:{defaultValue:`classic`,envOnly:!0,envKeys:[`DEFAULT_FONT_THEME`]},SITE_ORIGIN:{defaultValue:``,envOnly:!0,envKeys:[`SITE_ORIGIN`]},SITE_PATH_PREFIX:{defaultValue:``,envOnly:!0,envKeys:[`SITE_PATH_PREFIX`]},AUTH_SECRET:{defaultValue:``,envOnly:!0,envKeys:[`AUTH_SECRET`]},R2_PUBLIC_URL:{defaultValue:``,envOnly:!0,envKeys:[`R2_PUBLIC_URL`]},IMAGE_TRANSFORM_URL:{defaultValue:``,envOnly:!0,envKeys:[`IMAGE_TRANSFORM_URL`]},DEMO_EMAIL:{defaultValue:``,envOnly:!0,envKeys:[`DEMO_EMAIL`]},DEMO_PASSWORD:{defaultValue:``,envOnly:!0,envKeys:[`DEMO_PASSWORD`]},DEMO_MODE:{defaultValue:`false`,envOnly:!0,envKeys:[`DEMO_MODE`]},PAGE_SIZE:{defaultValue:`50`,envOnly:!0,envKeys:[`PAGE_SIZE`]},SEARCH_PAGE_SIZE:{defaultValue:``,envOnly:!0,envKeys:[`SEARCH_PAGE_SIZE`]},ARCHIVE_PAGE_SIZE:{defaultValue:``,envOnly:!0,envKeys:[`ARCHIVE_PAGE_SIZE`]},STORAGE_DRIVER:{defaultValue:`r2`,envOnly:!0,envKeys:[`STORAGE_DRIVER`]},S3_ENDPOINT:{defaultValue:``,envOnly:!0,envKeys:[`S3_ENDPOINT`]},S3_BUCKET:{defaultValue:``,envOnly:!0,envKeys:[`S3_BUCKET`]},S3_ACCESS_KEY_ID:{defaultValue:``,envOnly:!0,envKeys:[`S3_ACCESS_KEY_ID`]},S3_SECRET_ACCESS_KEY:{defaultValue:``,envOnly:!0,envKeys:[`S3_SECRET_ACCESS_KEY`]},S3_REGION:{defaultValue:`auto`,envOnly:!0,envKeys:[`S3_REGION`]},S3_PUBLIC_URL:{defaultValue:``,envOnly:!0,envKeys:[`S3_PUBLIC_URL`]},ASSET_BASE_URL:{defaultValue:``,envOnly:!0,envKeys:[`ASSET_BASE_URL`]},UPLOAD_MAX_FILE_SIZE_MB:{defaultValue:`1024`,envOnly:!0,envKeys:[`UPLOAD_MAX_FILE_SIZE_MB`]},SUMMARY_MAX_PARAGRAPHS:{defaultValue:`5`,envOnly:!0,envKeys:[`SUMMARY_MAX_PARAGRAPHS`]},SUMMARY_MAX_CHARS:{defaultValue:`500`,envOnly:!0,envKeys:[`SUMMARY_MAX_CHARS`]},SLUG_ID_LENGTH:{defaultValue:`5`,envOnly:!0,envKeys:[`SLUG_ID_LENGTH`]},RSS_FEED_LIMIT:{defaultValue:`50`,envOnly:!0,envKeys:[`RSS_FEED_LIMIT`]},THEME:{defaultValue:``,envOnly:!1,internal:!0},CUSTOM_CSS:{defaultValue:``,envOnly:!1,internal:!0},CUSTOM_HEAD_HTML:{defaultValue:``,envOnly:!1,internal:!0},CUSTOM_BODY_END_HTML:{defaultValue:``,envOnly:!1,internal:!0},SITE_AVATAR:{defaultValue:``,envOnly:!1,internal:!0},SHOW_HEADER_AVATAR:{defaultValue:``,envOnly:!1,internal:!0},SITE_FAVICON_ICO:{defaultValue:``,envOnly:!1,internal:!0},SITE_FAVICON_APPLE_TOUCH:{defaultValue:``,envOnly:!1,internal:!0},SITE_FAVICON_VERSION:{defaultValue:``,envOnly:!1,internal:!0},FONT_THEME:{defaultValue:``,envOnly:!1,internal:!0},THEME_MODE:{defaultValue:``,envOnly:!1,internal:!0},TIME_ZONE:{defaultValue:`UTC`,envOnly:!1,envKeys:[`TIME_ZONE`]},SITE_FOOTER:{defaultValue:``,envOnly:!1,envKeys:[`SITE_FOOTER`]},SHOW_JANT_BRANDING_ON_HOME:{defaultValue:``,envOnly:!1,envKeys:[`SHOW_JANT_BRANDING_ON_HOME`]},NOINDEX:{defaultValue:``,envOnly:!1,envKeys:[`NOINDEX`]},DISCOVERY_COMPOSE_OPEN_SHORTCUT_AT:{defaultValue:``,envOnly:!1,internal:!0},DISCOVERY_SLASH_COMMAND_AT:{defaultValue:``,envOnly:!1,internal:!0},ONBOARDING_STATUS:{defaultValue:`pending`,envOnly:!1,internal:!0},PASSWORD_RESET_TOKEN:{defaultValue:``,envOnly:!1,internal:!0},DELETE_CSRF_TOKEN:{defaultValue:``,envOnly:!1,internal:!0},GITHUB_SYNC_ENABLED:{defaultValue:`false`,envOnly:!1,internal:!0},GITHUB_SYNC_REPO:{defaultValue:``,envOnly:!1,internal:!0},GITHUB_SYNC_TOKEN:{defaultValue:``,envOnly:!1,internal:!0},GITHUB_SYNC_WEBHOOK_SECRET:{defaultValue:``,envOnly:!1,internal:!0},GITHUB_SYNC_WEBHOOK_ID:{defaultValue:``,envOnly:!1,internal:!0},GITHUB_SYNC_LAST_PUSH_SHA:{defaultValue:``,envOnly:!1,internal:!0},GITHUB_SYNC_LAST_PUSH_AT:{defaultValue:``,envOnly:!1,internal:!0},GITHUB_SYNC_PENDING:{defaultValue:``,envOnly:!1,internal:!0},GITHUB_SYNC_PENDING_AT:{defaultValue:``,envOnly:!1,internal:!0},GITHUB_SYNC_DIRTY:{defaultValue:``,envOnly:!1,internal:!0},GITHUB_SYNC_LAST_ERROR:{defaultValue:``,envOnly:!1,internal:!0},GITHUB_SYNC_AUTH_MODE:{defaultValue:`pat`,envOnly:!1,internal:!0},GITHUB_SYNC_APP_INSTALLATION_ID:{defaultValue:``,envOnly:!1,internal:!0},GITHUB_APP_ID:{defaultValue:``,envOnly:!0,envKeys:[`GITHUB_APP_ID`]},GITHUB_APP_PRIVATE_KEY:{defaultValue:``,envOnly:!0,envKeys:[`GITHUB_APP_PRIVATE_KEY`]},GITHUB_APP_SLUG:{defaultValue:``,envOnly:!0,envKeys:[`GITHUB_APP_SLUG`]},GITHUB_APP_WEBHOOK_SECRET:{defaultValue:``,envOnly:!0,envKeys:[`GITHUB_APP_WEBHOOK_SECRET`]},TELEGRAM_BOT_TOKENS:{defaultValue:``,envOnly:!0,envKeys:[`TELEGRAM_BOT_TOKENS`]},TELEGRAM_WEBHOOK_SECRET:{defaultValue:``,envOnly:!0,envKeys:[`TELEGRAM_WEBHOOK_SECRET`]},TELEGRAM_BOT_TOKEN:{defaultValue:``,envOnly:!1,internal:!0},TELEGRAM_BOT_ID:{defaultValue:``,envOnly:!1,internal:!0},TELEGRAM_BOT_USERNAME:{defaultValue:``,envOnly:!1,internal:!0},TELEGRAM_BOT_WEBHOOK_SECRET:{defaultValue:``,envOnly:!1,internal:!0}},AS=[`featured`,`latest`,`signin`,`signout`,`setup`,`settings`,`dash`,`api`,`feed`,`search`,`archive`,`media`,`pages`,`reset`,`collections`,`compose`,`new`,`static`,`assets`,`_assets`,`healthz`,`readyz`];function jS(e){let t=e.split(`/`)[0]?.toLowerCase();return AS.includes(t)}Object.fromEntries(Object.entries(kS).filter(([,e])=>!e.envOnly||`internal`in e).map(([e])=>[e,e]));var MS=/^[a-z0-9]+(?:-[a-z0-9]+)*$/;function NS(e){return e.toLowerCase().replace(/[^a-z0-9-]/g,`-`).replace(/-{2,}/g,`-`).replace(/^-|-$/g,``)}function PS(e,t){return NS(e.slice(0,t))}function FS(e,t={}){let n=e.trim();return n?t.maxLength&&n.length>t.maxLength?`too_long`:MS.test(n)?jS(n)||t.additionalReservedValues?.some(e=>e.toLowerCase()===n.toLowerCase())?`reserved`:null:`invalid`:null}var IS=Kv;function LS(e){let{char:t,allowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,$position:o}=e,s=n&&!r,c=jf(t),l=RegExp(`\\s${c}$`),u=a?`^`:``,d=r?``:c,f=s?RegExp(`${u}${c}.*?(?=\\s${d}|$)`,`gm`):RegExp(`${u}(?:^)?${c}[^\\s${d}]*`,`gm`),p=o.nodeBefore?.isText&&o.nodeBefore.text;if(!p)return null;let m=o.pos-p.length,h=Array.from(p.matchAll(f)).pop();if(!h||h.input===void 0||h.index===void 0)return null;let g=h.input.slice(Math.max(0,h.index-1),h.index),_=RegExp(`^[${i?.join(``)}\0]?$`).test(g);if(i!==null&&!_)return null;let v=m+h.index,y=v+h[0].length;return s&&l.test(p.slice(y-1,y+1))&&(h[0]+=` `,y+=1),v<o.pos&&y>=o.pos?{range:{from:v,to:y},query:h[0].slice(t.length),text:h[0]}:null}function RS(e){return e.docChanged?e.steps.some(e=>{let t=e.slice;if(!t?.content)return!1;let n=t.content.textBetween(0,t.content.size,`
268
- `);return/\s/.test(n)}):!1}var zS=new Fr(`suggestion`);function BS({pluginKey:e=zS,editor:t,char:n=`@`,allowSpaces:r=!1,allowToIncludeChar:i=!1,allowedPrefixes:a=[` `],startOfLine:o=!1,decorationTag:s=`span`,decorationClass:c=`suggestion`,decorationContent:l=``,decorationEmptyClass:u=`is-empty`,command:d=()=>null,items:f=()=>[],render:p=()=>({}),allow:m=()=>!0,findSuggestionMatch:h=LS,shouldShow:g,shouldResetDismissed:_}){let v,y=p?.(),b=r&&!i,x=()=>{let e=t.state.selection.$anchor.pos,{top:n,right:r,bottom:i,left:a}=t.view.coordsAtPos(e);try{return new DOMRect(a,n,r-a,i-n)}catch{return null}},S=(n,r)=>r?()=>{let r=e.getState(t.state)?.decorationId;return n.dom.querySelector(`[data-decoration-id="${r}"]`)?.getBoundingClientRect()||null}:x,C=({match:e,dismissedRange:n,state:r,transaction:i})=>_?.({editor:t,state:r,range:n,match:e,transaction:i,allowSpaces:b})?!1:b?e.range.from===n.from:e.range.from===n.from&&!RS(i);function ee(n,r){var i;try{let r=e.getState(n.state),a=r?.decorationId?n.dom.querySelector(`[data-decoration-id="${r.decorationId}"]`):null,o={editor:t,range:r?.range||{from:0,to:0},query:r?.query||null,text:r?.text||null,items:[],command:e=>d({editor:t,range:r?.range||{from:0,to:0},props:e}),decorationNode:a,clientRect:S(n,a)};(i=y?.onExit)==null||i.call(y,o)}catch{}let a=n.state.tr.setMeta(r,{exit:!0});n.dispatch(a)}let te=new Mr({key:e,view(){return{update:async(e,n)=>{var r,i,a,o,s;let c=this.key?.getState(n),l=this.key?.getState(e.state),u=c.active&&l.active&&c.range.from!==l.range.from,p=!c.active&&l.active,m=c.active&&!l.active,h=!p&&!m&&c.query!==l.query,g=p||u&&h,_=h||u,b=m||u&&h;if(!g&&!_&&!b)return;let x=b&&!g?c:l,C=e.dom.querySelector(`[data-decoration-id="${x.decorationId}"]`);v={editor:t,range:x.range,query:x.query,text:x.text,items:[],command:e=>d({editor:t,range:x.range,props:e}),decorationNode:C,clientRect:S(e,C)},g&&((r=y?.onBeforeStart)==null||r.call(y,v)),_&&((i=y?.onBeforeUpdate)==null||i.call(y,v)),(_||g)&&(v.items=await f({editor:t,query:x.query})),b&&((a=y?.onExit)==null||a.call(y,v)),_&&((o=y?.onUpdate)==null||o.call(y,v)),g&&((s=y?.onStart)==null||s.call(y,v))},destroy:()=>{var e;v&&((e=y?.onExit)==null||e.call(y,v))}}},state:{init(){return{active:!1,range:{from:0,to:0},query:null,text:null,composing:!1,dismissedRange:null}},apply(s,c,l,u){let{isEditable:d}=t,{composing:f}=t.view,{selection:p}=s,{empty:_,from:v}=p,y={...c},b=s.getMeta(e);if(b&&b.exit)return y.active=!1,y.decorationId=null,y.range={from:0,to:0},y.query=null,y.text=null,y.dismissedRange=c.active?{...c.range}:c.dismissedRange,y;if(y.composing=f,s.docChanged&&y.dismissedRange!==null&&(y.dismissedRange={from:s.mapping.map(y.dismissedRange.from),to:s.mapping.map(y.dismissedRange.to)}),d&&(_||t.view.composing)){(v<c.range.from||v>c.range.to)&&!f&&!c.composing&&(y.active=!1);let e=h({char:n,allowSpaces:r,allowToIncludeChar:i,allowedPrefixes:a,startOfLine:o,$position:p.$from}),l=`id_${Math.floor(Math.random()*4294967295)}`;e&&m({editor:t,state:u,range:e.range,isActive:c.active})&&(!g||g({editor:t,range:e.range,query:e.query,text:e.text,transaction:s}))?(y.dismissedRange!==null&&!C({match:e,dismissedRange:y.dismissedRange,state:u,transaction:s})&&(y.dismissedRange=null),y.dismissedRange===null?(y.active=!0,y.decorationId=c.decorationId?c.decorationId:l,y.range=e.range,y.query=e.query,y.text=e.text):y.active=!1):(e||(y.dismissedRange=null),y.active=!1)}else y.active=!1;return y.active||(y.decorationId=null,y.range={from:0,to:0},y.query=null,y.text=null),y}},props:{handleKeyDown(t,n){var r;let{active:i,range:a}=te.getState(t.state);if(!i)return!1;if(n.key===`Escape`||n.key===`Esc`){let i=te.getState(t.state);return(r=y?.onKeyDown)==null||r.call(y,{view:t,event:n,range:i.range}),ee(t,e),!0}return(y?.onKeyDown)?.call(y,{view:t,event:n,range:a})||!1},decorations(e){let{active:t,range:n,decorationId:r,query:i}=te.getState(e);if(!t)return null;let a=!i?.length,o=[c];return a&&o.push(u),lc.create(e.doc,[oc.inline(n.from,n.to,{nodeName:s,class:o.join(` `),"data-decoration-id":r,"data-decoration-content":l})])}}});return te}var VS=BS;function HS(e,t,n){return n<t?t:Math.min(Math.max(e,t),n)}function US(e,t,n,r,i){let a=n.top,o=n.top+n.height;return e===`top`?Math.max(t.top-a-r-i,0):Math.max(o-t.bottom-r-i,0)}function WS(e){if(!e||e===document.body)return{left:0,top:0,width:window.innerWidth,height:window.innerHeight};let t=e.getBoundingClientRect();return{left:t.left,top:t.top,width:t.width,height:t.height}}function GS(e){let t=e.gap??8,n=e.padding??8,r=e.fallbackPlacement??(e.preferredPlacement===`top`?`bottom`:`top`),i=US(e.preferredPlacement,e.anchorRect,e.containerRect,t,n),a=US(r,e.anchorRect,e.containerRect,t,n),o=e.floatingHeight<=i||i>=a?e.preferredPlacement:r,s=o===e.preferredPlacement?i:a,c=s>0&&e.floatingHeight>s?s:null,l=c??e.floatingHeight,u=e.align===`center`?(e.anchorRect.left+e.anchorRect.right)/2-e.floatingWidth/2:e.anchorRect.left,d=n,f=e.containerRect.width-e.floatingWidth-n;return{left:HS(u-e.containerRect.left,d,f),top:HS(o===`top`?e.anchorRect.top-e.containerRect.top-l-t:e.anchorRect.bottom-e.containerRect.top+t,n,e.containerRect.height-l-n),placement:o,maxHeight:c}}var KS=[`https://www.youtube-nocookie.com`],qS=[`https://player.vimeo.com`],JS=[`https://open.spotify.com`],YS=[`https://bandcamp.com`],XS=[`https://codepen.io`],ZS=`allow-scripts allow-same-origin allow-popups`,QS=`allow-scripts allow-same-origin allow-popups allow-presentation`;function $S(e,t,n){return{provider:`youtube`,providerName:`YouTube`,src:`https://www.youtube-nocookie.com/embed/${e}${n&&n>0?`?start=${n}`:``}`,url:``,orientation:t?`portrait`:`landscape`,sandbox:QS,allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share`,cspFrameSrc:KS,cspScriptSrc:[]}}function eC(e){if(!e)return;if(/^\d+$/.test(e)){let t=Number.parseInt(e,10);return Number.isFinite(t)&&t>0?t:void 0}let t=e.match(/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s?)?$/);if(!t)return;let n=Number.parseInt(t[1]??`0`,10)||0,r=Number.parseInt(t[2]??`0`,10)||0,i=Number.parseInt(t[3]??`0`,10)||0,a=n*3600+r*60+i;return a>0?a:void 0}var tC=[{id:`youtube`,name:`YouTube`,pattern:/^(?:https?:\/\/)?(?:www\.|m\.)?youtube\.com\/watch\?(?=[^#]*v=([\w-]{6,}))/i,build:(e,t)=>{let n=e[1];return n?$S(n,!1,eC(t.searchParams.get(`t`))):null}},{id:`youtube`,name:`YouTube`,pattern:/^(?:https?:\/\/)?(?:www\.|m\.)?youtube\.com\/shorts\/([\w-]{6,})/i,build:e=>e[1]?$S(e[1],!0):null},{id:`youtube`,name:`YouTube`,pattern:/^(?:https?:\/\/)?youtu\.be\/([\w-]{6,})/i,build:(e,t)=>{let n=e[1];return n?$S(n,!1,eC(t.searchParams.get(`t`))):null}},{id:`vimeo`,name:`Vimeo`,pattern:/^(?:https?:\/\/)?(?:www\.)?vimeo\.com\/(\d+)(?:\/(\w+))?/i,build:e=>{let t=e[1],n=e[2];return{provider:`vimeo`,providerName:`Vimeo`,src:`https://player.vimeo.com/video/${t}${n?`?h=${n}`:``}`,url:``,orientation:`landscape`,sandbox:QS,allow:`autoplay; fullscreen; picture-in-picture`,cspFrameSrc:qS,cspScriptSrc:[]}}},{id:`spotify`,name:`Spotify`,pattern:/^(?:https?:\/\/)?open\.spotify\.com\/(track|album|playlist|episode|show)\/([\w-]+)/i,build:e=>{let t=e[1];return{provider:`spotify`,providerName:`Spotify`,src:`https://open.spotify.com/embed/${t}/${e[2]}`,url:``,orientation:`auto`,heightPx:t===`track`||t===`episode`?152:352,sandbox:QS,allow:`autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture`,cspFrameSrc:JS,cspScriptSrc:[]}}},{id:`bandcamp`,name:`Bandcamp`,pattern:/^(?:https?:\/\/)?([a-z0-9-]+)\.bandcamp\.com\/(track|album)\/([\w-]+)/i,build:(e,t)=>({provider:`bandcamp`,providerName:`Bandcamp`,src:`https://bandcamp.com/EmbeddedPlayer/v=2/linkcol=0687f5/tracklist=false/artwork=small/url=${encodeURIComponent(t.toString())}`,url:``,orientation:`auto`,heightPx:120,sandbox:QS,cspFrameSrc:YS,cspScriptSrc:[]})},{id:`codepen`,name:`CodePen`,pattern:/^(?:https?:\/\/)?codepen\.io\/([\w-]+)\/(?:pen|full|details)\/([\w-]+)/i,build:e=>({provider:`codepen`,providerName:`CodePen`,src:`https://codepen.io/${e[1]}/embed/${e[2]}?default-tab=result&theme-id=default`,url:``,orientation:`auto`,heightPx:420,sandbox:ZS,cspFrameSrc:XS,cspScriptSrc:[]})}];function nC(e){let t=e.trim();if(!t)return null;let n;try{n=new URL(t.startsWith(`http`)?t:`https://${t}`)}catch{return null}if(n.protocol!==`https:`&&n.protocol!==`http:`)return null;for(let e of tC){let r=t.match(e.pattern);if(r){let i=e.build(r,n);if(i)return{...i,url:t}}}return n.protocol===`https:`?{provider:`iframe`,providerName:n.hostname,src:n.toString(),url:t,orientation:`landscape`,sandbox:ZS,cspFrameSrc:[n.origin],cspScriptSrc:[]}:null}function rC(e){let t=nC(e);return t!==null&&t.provider!==`iframe`}function iC(e={}){return new Promise(t=>{let n=document.createElement(`dialog`);n.className=`dialog tiptap-embed-dialog`;let r=document.createElement(`div`);r.className=`tiptap-embed-dialog-panel`,r.tabIndex=-1,n.appendChild(r);let i=document.createElement(`h2`);i.className=`tiptap-embed-dialog-title`,i.textContent=`Insert embed`,r.appendChild(i);let a=document.createElement(`div`);a.className=`tiptap-embed-dialog-field`,r.appendChild(a);let o=document.createElement(`label`);o.className=`tiptap-embed-dialog-label`,o.textContent=`URL`,a.appendChild(o);let s=document.createElement(`input`);s.type=`url`,s.className=`input tiptap-embed-dialog-input`,s.placeholder=`https://www.youtube.com/watch?v=…`,s.value=e.initialUrl??``,o.appendChild(s);let c=document.createElement(`p`);c.className=`tiptap-embed-dialog-hint`,a.appendChild(c);let l=document.createElement(`div`);l.className=`tiptap-embed-dialog-field`,r.appendChild(l);let u=document.createElement(`label`);u.className=`tiptap-embed-dialog-label`,u.textContent=`Caption (optional)`,l.appendChild(u);let d=document.createElement(`input`);d.type=`text`,d.className=`input tiptap-embed-dialog-input`,d.value=e.initialCaption??``,u.appendChild(d);let f=document.createElement(`div`);f.className=`tiptap-embed-dialog-field`,f.hidden=!0,r.appendChild(f);let p=document.createElement(`label`);p.className=`tiptap-embed-dialog-label`,p.textContent=`Raw HTML`,f.appendChild(p);let m=document.createElement(`textarea`);m.className=`textarea tiptap-embed-dialog-textarea`,m.rows=8,m.placeholder=`<script data-letterbirduser="you" src="https://letterbird.co/embed/v1.js"><\/script>`,m.value=e.initialHtml??``,p.appendChild(m);let h=document.createElement(`p`);h.className=`tiptap-embed-dialog-warning`,h.textContent=`Anything you paste here runs in your visitors' browsers. Only use code you trust.`,f.appendChild(h);let g=document.createElement(`button`);g.type=`button`,g.className=`tiptap-embed-dialog-toggle`,r.appendChild(g);let _=e.initialMode??`url`;function v(){_===`url`?(i.textContent=`Insert embed`,a.hidden=!1,l.hidden=!1,f.hidden=!0,g.textContent=`Paste raw HTML instead`):(i.textContent=`Paste raw HTML`,a.hidden=!0,l.hidden=!0,f.hidden=!1,g.textContent=`Use a URL instead`),y(),ee(),queueMicrotask(()=>{_===`url`?s.focus():m.focus()})}function y(){if(_!==`url`){c.textContent=``;return}let e=s.value.trim();if(!e){c.textContent=`YouTube, Vimeo, Spotify, CodePen, or any HTTPS page.`;return}let t=nC(e);if(!t){c.textContent=`Not a valid URL.`;return}c.textContent=t.provider===`iframe`?`Generic iframe — ${t.providerName}`:`Detected: ${t.providerName}`}g.addEventListener(`click`,e=>{e.preventDefault(),_=_===`url`?`html`:`url`,v()}),s.addEventListener(`input`,()=>{y(),ee()});let b=document.createElement(`div`);b.className=`tiptap-embed-dialog-actions`,r.appendChild(b);let x=document.createElement(`button`);x.type=`button`,x.className=`tiptap-embed-dialog-link-instead`,x.textContent=`Insert as link instead`,x.addEventListener(`click`,e=>{e.preventDefault();let t=s.value.trim();if(!t){s.focus();return}oe({kind:`link`,url:t})}),b.appendChild(x);let S=document.createElement(`button`);S.type=`button`,S.className=`btn-outline`,S.textContent=`Cancel`,S.addEventListener(`click`,e=>{e.preventDefault(),oe(null)}),b.appendChild(S);let C=document.createElement(`button`);C.type=`button`,C.className=`btn`,C.textContent=`Insert`,C.addEventListener(`click`,e=>{e.preventDefault(),te()}),b.appendChild(C);function ee(){x.hidden=!(_===`url`&&s.value.trim().length>0)}function te(){if(_===`url`){let e=s.value.trim();if(!e){s.focus();return}if(!nC(e)){c.textContent=`Not a valid URL.`,s.focus();return}oe({kind:`embed`,url:e,caption:d.value.trim()||void 0})}else{if(!m.value.trim()){m.focus();return}oe({kind:`html`,html:m.value})}}function ne(e){if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),oe(null);return}if(e.key===`Enter`&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey){if(e.target instanceof HTMLTextAreaElement)return;e.preventDefault(),te()}}function re(e){e.target===n&&oe(null)}function ie(e){e.preventDefault(),oe(null)}let ae=!1;function oe(e){ae||(ae=!0,n.removeEventListener(`cancel`,ie),n.removeEventListener(`click`,re),n.removeEventListener(`keydown`,ne),n.open&&n.close(),n.remove(),t(e))}n.addEventListener(`cancel`,ie),n.addEventListener(`click`,re),n.addEventListener(`keydown`,ne),document.body.appendChild(n),v(),n.showModal(),r.focus()})}var aC={image:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/></svg>`,embed:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="14" x="2" y="3" rx="2" ry="2"/><line x1="8" x2="16" y1="21" y2="21"/><line x1="12" x2="12" y1="17" y2="21"/><polygon points="10 8 15 11 10 14 10 8" fill="currentColor"/></svg>`,divider:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12h18"/></svg>`,readMore:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12h18"/><path d="m9 18 3 3 3-3"/><path d="m9 6-3-3-3 3"/><path d="M3 6h18"/></svg>`,footnote:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7 4h10"/><path d="M12 4v11"/><path d="M9 9h6"/><path d="M16 20h4"/><path d="M18 14v6"/></svg>`,table:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3v18"/><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M3 9h18"/><path d="M3 15h18"/></svg>`,code:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>`,blockquote:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 21c3 0 7-1 7-8V5c0-1.25-.756-2.017-2-2H4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2 1 0 1 0 1 1v1c0 1-1 2-2 2s-1 .008-1 1.031V20c0 1 0 1 1 1z"/><path d="M15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2h.75c0 2.25.25 4-2.75 4v3c0 1 0 1 1 1z"/></svg>`,bulletList:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="8" x2="21" y1="6" y2="6"/><line x1="8" x2="21" y1="12" y2="12"/><line x1="8" x2="21" y1="18" y2="18"/><line x1="3" x2="3.01" y1="6" y2="6"/><line x1="3" x2="3.01" y1="12" y2="12"/><line x1="3" x2="3.01" y1="18" y2="18"/></svg>`,orderedList:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="10" x2="21" y1="6" y2="6"/><line x1="10" x2="21" y1="12" y2="12"/><line x1="10" x2="21" y1="18" y2="18"/><path d="M4 6h1v4"/><path d="M4 10h2"/><path d="M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"/></svg>`,h1:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="M17 12l3-2v10"/></svg>`,h2:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1"/></svg>`,h3:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2"/><path d="M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2"/></svg>`},oC={media:`Media`,structure:`Structure`,formatting:`Formatting`,headings:`Headings`},sC=[`media`,`structure`,`formatting`,`headings`],cC=`No matches. Try another command.`,lC={insert:`Insert`,close:`Close`},uC=[{label:`Media`,description:`Upload an image or video.`,group:`media`,keywords:[`image`,`video`,`photo`,`upload`],icon:aC.image,command:(e,t)=>{e.chain().focus().deleteRange(t).run(),document.dispatchEvent(new CustomEvent(`jant:slash-image`,{bubbles:!0}))}},{label:`Embed`,description:`Embed a YouTube video, tweet, or any HTTPS page.`,group:`media`,keywords:[`embed`,`youtube`,`vimeo`,`spotify`,`video`,`iframe`,`html`,`letterbird`],icon:aC.embed,command:(e,t)=>{e.chain().focus().deleteRange(t).run(),iC().then(t=>{if(!t){e.commands.focus();return}t.kind===`embed`?e.chain().focus().setEmbed({url:t.url,caption:t.caption}).run():t.kind===`link`?e.chain().focus().insertContent({type:`text`,text:t.url,marks:[{type:`link`,attrs:{href:t.url}}]}).run():e.chain().focus().setHtmlBlock({html:t.html}).run()})}},{label:`Divider`,description:`Separate one thought from the next.`,group:`structure`,keywords:[`line`,`rule`,`separator`,`break`,`hr`],icon:aC.divider,command:(e,t)=>{e.chain().focus().deleteRange(t).setHorizontalRule().run()}},{label:`Read More`,description:`Collapse the rest of a longer post.`,group:`structure`,keywords:[`excerpt`,`continue`,`teaser`,`more`,`break`],icon:aC.readMore,command:(e,t)=>{e.chain().focus().deleteRange(t).insertMoreBreak().run()}},{label:`Footnote`,description:`Insert a numbered footnote and jump to its note.`,group:`structure`,keywords:[`footnote`,`note`,`citation`,`reference`,`superscript`],icon:aC.footnote,command:(e,t)=>{e.chain().focus().deleteRange(t).insertFootnote().run()}},{label:`Table`,description:`Insert a 3 by 3 table.`,group:`structure`,keywords:[`grid`,`rows`,`columns`,`spreadsheet`],icon:aC.table,command:(e,t)=>{e.chain().focus().deleteRange(t).insertTable({rows:3,cols:3,withHeaderRow:!0}).run()}},{label:`Code Block`,description:`Format a block of code or monospace text.`,group:`formatting`,keywords:[`code`,`snippet`,`pre`,`monospace`],icon:aC.code,command:(e,t)=>{e.chain().focus().deleteRange(t).toggleCodeBlock().run()}},{label:`Blockquote`,description:`Set off quoted text or a pull quote.`,group:`formatting`,keywords:[`quote`,`citation`,`excerpt`,`callout`],icon:aC.blockquote,command:(e,t)=>{e.chain().focus().deleteRange(t).toggleBlockquote().run()}},{label:`Bullet List`,description:`Start an unordered list.`,group:`formatting`,keywords:[`list`,`bullets`,`unordered`,`ul`],icon:aC.bulletList,command:(e,t)=>{e.chain().focus().deleteRange(t).toggleBulletList().run()}},{label:`Ordered List`,description:`Start a numbered list.`,group:`formatting`,keywords:[`list`,`numbered`,`ordered`,`ol`],icon:aC.orderedList,command:(e,t)=>{e.chain().focus().deleteRange(t).toggleOrderedList().run()}},{label:`Heading 1`,description:`Insert the largest section heading.`,group:`headings`,keywords:[`title`,`h1`,`large heading`,`section title`],icon:aC.h1,command:(e,t)=>{e.chain().focus().deleteRange(t).toggleHeading({level:1}).run()}},{label:`Heading 2`,description:`Insert a medium section heading.`,group:`headings`,keywords:[`subtitle`,`h2`,`section heading`],icon:aC.h2,command:(e,t)=>{e.chain().focus().deleteRange(t).toggleHeading({level:2}).run()}},{label:`Heading 3`,description:`Insert a small section heading.`,group:`headings`,keywords:[`subheading`,`h3`,`small heading`],icon:aC.h3,command:(e,t)=>{e.chain().focus().deleteRange(t).toggleHeading({level:3}).run()}}];function dC(e){let t=!1;return e.state.doc.descendants(e=>e.type.name===`moreBreak`?(t=!0,!1):!t),t}function fC(e){return e&&dC(e)?uC.filter(e=>e.label!==`Read More`):uC}var pC=null,mC=0,hC=[],gC=null,_C=null,vC=null,yC=null;function bC(){return pC?pC.querySelector(`.tiptap-slash-menu-scroll`)??pC:null}function xC(){let e=document.createElement(`div`);return e.className=`tiptap-slash-menu`,e.dataset.editorFloatingUi=`true`,e.style.position=`fixed`,e}function SC(){if(!pC)return;let e=bC();if(!e)return;let t=pC.querySelector(`.tiptap-slash-item.is-selected`);if(!t)return;let n=t.offsetTop-e.offsetTop,r=n+t.offsetHeight,i=e.scrollTop,a=i+e.clientHeight;n<i?e.scrollTop=n:r>a&&(e.scrollTop=r-e.clientHeight)}function CC(){pC?.querySelectorAll(`.tiptap-slash-item`).forEach((e,t)=>{let n=t===mC;e.classList.toggle(`is-selected`,n),e.setAttribute(`aria-selected`,n?`true`:`false`)}),TC(),SC()}function wC(){return hC[mC]??null}function TC(){let e=pC?.querySelector(`.tiptap-slash-footer-description`);e&&(e.textContent=wC()?.description??``)}function EC(e){return`<div class="tiptap-slash-footer">
268
+ `);return/\s/.test(n)}):!1}var zS=new Pr(`suggestion`);function BS({pluginKey:e=zS,editor:t,char:n=`@`,allowSpaces:r=!1,allowToIncludeChar:i=!1,allowedPrefixes:a=[` `],startOfLine:o=!1,decorationTag:s=`span`,decorationClass:c=`suggestion`,decorationContent:l=``,decorationEmptyClass:u=`is-empty`,command:d=()=>null,items:f=()=>[],render:p=()=>({}),allow:m=()=>!0,findSuggestionMatch:h=LS,shouldShow:g,shouldResetDismissed:_}){let v,y=p?.(),b=r&&!i,x=()=>{let e=t.state.selection.$anchor.pos,{top:n,right:r,bottom:i,left:a}=t.view.coordsAtPos(e);try{return new DOMRect(a,n,r-a,i-n)}catch{return null}},S=(n,r)=>r?()=>{let r=e.getState(t.state)?.decorationId;return n.dom.querySelector(`[data-decoration-id="${r}"]`)?.getBoundingClientRect()||null}:x,C=({match:e,dismissedRange:n,state:r,transaction:i})=>_?.({editor:t,state:r,range:n,match:e,transaction:i,allowSpaces:b})?!1:b?e.range.from===n.from:e.range.from===n.from&&!RS(i);function ee(n,r){var i;try{let r=e.getState(n.state),a=r?.decorationId?n.dom.querySelector(`[data-decoration-id="${r.decorationId}"]`):null,o={editor:t,range:r?.range||{from:0,to:0},query:r?.query||null,text:r?.text||null,items:[],command:e=>d({editor:t,range:r?.range||{from:0,to:0},props:e}),decorationNode:a,clientRect:S(n,a)};(i=y?.onExit)==null||i.call(y,o)}catch{}let a=n.state.tr.setMeta(r,{exit:!0});n.dispatch(a)}let te=new j({key:e,view(){return{update:async(e,n)=>{var r,i,a,o,s;let c=this.key?.getState(n),l=this.key?.getState(e.state),u=c.active&&l.active&&c.range.from!==l.range.from,p=!c.active&&l.active,m=c.active&&!l.active,h=!p&&!m&&c.query!==l.query,g=p||u&&h,_=h||u,b=m||u&&h;if(!g&&!_&&!b)return;let x=b&&!g?c:l,C=e.dom.querySelector(`[data-decoration-id="${x.decorationId}"]`);v={editor:t,range:x.range,query:x.query,text:x.text,items:[],command:e=>d({editor:t,range:x.range,props:e}),decorationNode:C,clientRect:S(e,C)},g&&((r=y?.onBeforeStart)==null||r.call(y,v)),_&&((i=y?.onBeforeUpdate)==null||i.call(y,v)),(_||g)&&(v.items=await f({editor:t,query:x.query})),b&&((a=y?.onExit)==null||a.call(y,v)),_&&((o=y?.onUpdate)==null||o.call(y,v)),g&&((s=y?.onStart)==null||s.call(y,v))},destroy:()=>{var e;v&&((e=y?.onExit)==null||e.call(y,v))}}},state:{init(){return{active:!1,range:{from:0,to:0},query:null,text:null,composing:!1,dismissedRange:null}},apply(s,c,l,u){let{isEditable:d}=t,{composing:f}=t.view,{selection:p}=s,{empty:_,from:v}=p,y={...c},b=s.getMeta(e);if(b&&b.exit)return y.active=!1,y.decorationId=null,y.range={from:0,to:0},y.query=null,y.text=null,y.dismissedRange=c.active?{...c.range}:c.dismissedRange,y;if(y.composing=f,s.docChanged&&y.dismissedRange!==null&&(y.dismissedRange={from:s.mapping.map(y.dismissedRange.from),to:s.mapping.map(y.dismissedRange.to)}),d&&(_||t.view.composing)){(v<c.range.from||v>c.range.to)&&!f&&!c.composing&&(y.active=!1);let e=h({char:n,allowSpaces:r,allowToIncludeChar:i,allowedPrefixes:a,startOfLine:o,$position:p.$from}),l=`id_${Math.floor(Math.random()*4294967295)}`;e&&m({editor:t,state:u,range:e.range,isActive:c.active})&&(!g||g({editor:t,range:e.range,query:e.query,text:e.text,transaction:s}))?(y.dismissedRange!==null&&!C({match:e,dismissedRange:y.dismissedRange,state:u,transaction:s})&&(y.dismissedRange=null),y.dismissedRange===null?(y.active=!0,y.decorationId=c.decorationId?c.decorationId:l,y.range=e.range,y.query=e.query,y.text=e.text):y.active=!1):(e||(y.dismissedRange=null),y.active=!1)}else y.active=!1;return y.active||(y.decorationId=null,y.range={from:0,to:0},y.query=null,y.text=null),y}},props:{handleKeyDown(t,n){var r;let{active:i,range:a}=te.getState(t.state);if(!i)return!1;if(n.key===`Escape`||n.key===`Esc`){let i=te.getState(t.state);return(r=y?.onKeyDown)==null||r.call(y,{view:t,event:n,range:i.range}),ee(t,e),!0}return(y?.onKeyDown)?.call(y,{view:t,event:n,range:a})||!1},decorations(e){let{active:t,range:n,decorationId:r,query:i}=te.getState(e);if(!t)return null;let a=!i?.length,o=[c];return a&&o.push(u),cc.create(e.doc,[ac.inline(n.from,n.to,{nodeName:s,class:o.join(` `),"data-decoration-id":r,"data-decoration-content":l})])}}});return te}var VS=BS;function HS(e,t,n){return n<t?t:Math.min(Math.max(e,t),n)}function US(e,t,n,r,i){let a=n.top,o=n.top+n.height;return e===`top`?Math.max(t.top-a-r-i,0):Math.max(o-t.bottom-r-i,0)}function WS(e){if(!e||e===document.body)return{left:0,top:0,width:window.innerWidth,height:window.innerHeight};let t=e.getBoundingClientRect();return{left:t.left,top:t.top,width:t.width,height:t.height}}function GS(e){let t=e.gap??8,n=e.padding??8,r=e.fallbackPlacement??(e.preferredPlacement===`top`?`bottom`:`top`),i=US(e.preferredPlacement,e.anchorRect,e.containerRect,t,n),a=US(r,e.anchorRect,e.containerRect,t,n),o=e.floatingHeight<=i||i>=a?e.preferredPlacement:r,s=o===e.preferredPlacement?i:a,c=s>0&&e.floatingHeight>s?s:null,l=c??e.floatingHeight,u=e.align===`center`?(e.anchorRect.left+e.anchorRect.right)/2-e.floatingWidth/2:e.anchorRect.left,d=n,f=e.containerRect.width-e.floatingWidth-n;return{left:HS(u-e.containerRect.left,d,f),top:HS(o===`top`?e.anchorRect.top-e.containerRect.top-l-t:e.anchorRect.bottom-e.containerRect.top+t,n,e.containerRect.height-l-n),placement:o,maxHeight:c}}var KS=[`https://www.youtube-nocookie.com`],qS=[`https://player.vimeo.com`],JS=[`https://open.spotify.com`],YS=[`https://bandcamp.com`],XS=[`https://codepen.io`],ZS=`allow-scripts allow-same-origin allow-popups`,QS=`allow-scripts allow-same-origin allow-popups allow-presentation`;function $S(e,t,n){return{provider:`youtube`,providerName:`YouTube`,src:`https://www.youtube-nocookie.com/embed/${e}${n&&n>0?`?start=${n}`:``}`,url:``,orientation:t?`portrait`:`landscape`,sandbox:QS,allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share`,cspFrameSrc:KS,cspScriptSrc:[]}}function eC(e){if(!e)return;if(/^\d+$/.test(e)){let t=Number.parseInt(e,10);return Number.isFinite(t)&&t>0?t:void 0}let t=e.match(/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s?)?$/);if(!t)return;let n=Number.parseInt(t[1]??`0`,10)||0,r=Number.parseInt(t[2]??`0`,10)||0,i=Number.parseInt(t[3]??`0`,10)||0,a=n*3600+r*60+i;return a>0?a:void 0}var tC=[{id:`youtube`,name:`YouTube`,pattern:/^(?:https?:\/\/)?(?:www\.|m\.)?youtube\.com\/watch\?(?=[^#]*v=([\w-]{6,}))/i,build:(e,t)=>{let n=e[1];return n?$S(n,!1,eC(t.searchParams.get(`t`))):null}},{id:`youtube`,name:`YouTube`,pattern:/^(?:https?:\/\/)?(?:www\.|m\.)?youtube\.com\/shorts\/([\w-]{6,})/i,build:e=>e[1]?$S(e[1],!0):null},{id:`youtube`,name:`YouTube`,pattern:/^(?:https?:\/\/)?youtu\.be\/([\w-]{6,})/i,build:(e,t)=>{let n=e[1];return n?$S(n,!1,eC(t.searchParams.get(`t`))):null}},{id:`vimeo`,name:`Vimeo`,pattern:/^(?:https?:\/\/)?(?:www\.)?vimeo\.com\/(\d+)(?:\/(\w+))?/i,build:e=>{let t=e[1],n=e[2];return{provider:`vimeo`,providerName:`Vimeo`,src:`https://player.vimeo.com/video/${t}${n?`?h=${n}`:``}`,url:``,orientation:`landscape`,sandbox:QS,allow:`autoplay; fullscreen; picture-in-picture`,cspFrameSrc:qS,cspScriptSrc:[]}}},{id:`spotify`,name:`Spotify`,pattern:/^(?:https?:\/\/)?open\.spotify\.com\/(track|album|playlist|episode|show)\/([\w-]+)/i,build:e=>{let t=e[1];return{provider:`spotify`,providerName:`Spotify`,src:`https://open.spotify.com/embed/${t}/${e[2]}`,url:``,orientation:`auto`,heightPx:t===`track`||t===`episode`?152:352,sandbox:QS,allow:`autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture`,cspFrameSrc:JS,cspScriptSrc:[]}}},{id:`bandcamp`,name:`Bandcamp`,pattern:/^(?:https?:\/\/)?([a-z0-9-]+)\.bandcamp\.com\/(track|album)\/([\w-]+)/i,build:(e,t)=>({provider:`bandcamp`,providerName:`Bandcamp`,src:`https://bandcamp.com/EmbeddedPlayer/v=2/linkcol=0687f5/tracklist=false/artwork=small/url=${encodeURIComponent(t.toString())}`,url:``,orientation:`auto`,heightPx:120,sandbox:QS,cspFrameSrc:YS,cspScriptSrc:[]})},{id:`codepen`,name:`CodePen`,pattern:/^(?:https?:\/\/)?codepen\.io\/([\w-]+)\/(?:pen|full|details)\/([\w-]+)/i,build:e=>({provider:`codepen`,providerName:`CodePen`,src:`https://codepen.io/${e[1]}/embed/${e[2]}?default-tab=result&theme-id=default`,url:``,orientation:`auto`,heightPx:420,sandbox:ZS,cspFrameSrc:XS,cspScriptSrc:[]})}];function nC(e){let t=e.trim();if(!t)return null;let n;try{n=new URL(t.startsWith(`http`)?t:`https://${t}`)}catch{return null}if(n.protocol!==`https:`&&n.protocol!==`http:`)return null;for(let e of tC){let r=t.match(e.pattern);if(r){let i=e.build(r,n);if(i)return{...i,url:t}}}return n.protocol===`https:`?{provider:`iframe`,providerName:n.hostname,src:n.toString(),url:t,orientation:`landscape`,sandbox:ZS,cspFrameSrc:[n.origin],cspScriptSrc:[]}:null}function rC(e){let t=nC(e);return t!==null&&t.provider!==`iframe`}function iC(e={}){return new Promise(t=>{let n=document.createElement(`dialog`);n.className=`dialog tiptap-embed-dialog`;let r=document.createElement(`div`);r.className=`tiptap-embed-dialog-panel`,r.tabIndex=-1,n.appendChild(r);let i=document.createElement(`h2`);i.className=`tiptap-embed-dialog-title`,i.textContent=`Insert embed`,r.appendChild(i);let a=document.createElement(`div`);a.className=`tiptap-embed-dialog-field`,r.appendChild(a);let o=document.createElement(`label`);o.className=`tiptap-embed-dialog-label`,o.textContent=`URL`,a.appendChild(o);let s=document.createElement(`input`);s.type=`url`,s.className=`input tiptap-embed-dialog-input`,s.placeholder=`https://www.youtube.com/watch?v=…`,s.value=e.initialUrl??``,o.appendChild(s);let c=document.createElement(`p`);c.className=`tiptap-embed-dialog-hint`,a.appendChild(c);let l=document.createElement(`div`);l.className=`tiptap-embed-dialog-field`,r.appendChild(l);let u=document.createElement(`label`);u.className=`tiptap-embed-dialog-label`,u.textContent=`Caption (optional)`,l.appendChild(u);let d=document.createElement(`input`);d.type=`text`,d.className=`input tiptap-embed-dialog-input`,d.value=e.initialCaption??``,u.appendChild(d);let f=document.createElement(`div`);f.className=`tiptap-embed-dialog-field`,f.hidden=!0,r.appendChild(f);let p=document.createElement(`label`);p.className=`tiptap-embed-dialog-label`,p.textContent=`Raw HTML`,f.appendChild(p);let m=document.createElement(`textarea`);m.className=`textarea tiptap-embed-dialog-textarea`,m.rows=8,m.placeholder=`<script data-letterbirduser="you" src="https://letterbird.co/embed/v1.js"><\/script>`,m.value=e.initialHtml??``,p.appendChild(m);let h=document.createElement(`p`);h.className=`tiptap-embed-dialog-warning`,h.textContent=`Anything you paste here runs in your visitors' browsers. Only use code you trust.`,f.appendChild(h);let g=document.createElement(`button`);g.type=`button`,g.className=`tiptap-embed-dialog-toggle`,r.appendChild(g);let _=e.initialMode??`url`;function v(){_===`url`?(i.textContent=`Insert embed`,a.hidden=!1,l.hidden=!1,f.hidden=!0,g.textContent=`Paste raw HTML instead`):(i.textContent=`Paste raw HTML`,a.hidden=!0,l.hidden=!0,f.hidden=!1,g.textContent=`Use a URL instead`),y(),ee(),queueMicrotask(()=>{_===`url`?s.focus():m.focus()})}function y(){if(_!==`url`){c.textContent=``;return}let e=s.value.trim();if(!e){c.textContent=`YouTube, Vimeo, Spotify, CodePen, or any HTTPS page.`;return}let t=nC(e);if(!t){c.textContent=`Not a valid URL.`;return}c.textContent=t.provider===`iframe`?`Generic iframe — ${t.providerName}`:`Detected: ${t.providerName}`}g.addEventListener(`click`,e=>{e.preventDefault(),_=_===`url`?`html`:`url`,v()}),s.addEventListener(`input`,()=>{y(),ee()});let b=document.createElement(`div`);b.className=`tiptap-embed-dialog-actions`,r.appendChild(b);let x=document.createElement(`button`);x.type=`button`,x.className=`tiptap-embed-dialog-link-instead`,x.textContent=`Insert as link instead`,x.addEventListener(`click`,e=>{e.preventDefault();let t=s.value.trim();if(!t){s.focus();return}oe({kind:`link`,url:t})}),b.appendChild(x);let S=document.createElement(`button`);S.type=`button`,S.className=`btn-outline`,S.textContent=`Cancel`,S.addEventListener(`click`,e=>{e.preventDefault(),oe(null)}),b.appendChild(S);let C=document.createElement(`button`);C.type=`button`,C.className=`btn`,C.textContent=`Insert`,C.addEventListener(`click`,e=>{e.preventDefault(),te()}),b.appendChild(C);function ee(){x.hidden=!(_===`url`&&s.value.trim().length>0)}function te(){if(_===`url`){let e=s.value.trim();if(!e){s.focus();return}if(!nC(e)){c.textContent=`Not a valid URL.`,s.focus();return}oe({kind:`embed`,url:e,caption:d.value.trim()||void 0})}else{if(!m.value.trim()){m.focus();return}oe({kind:`html`,html:m.value})}}function ne(e){if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),oe(null);return}if(e.key===`Enter`&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey){if(e.target instanceof HTMLTextAreaElement)return;e.preventDefault(),te()}}function re(e){e.target===n&&oe(null)}function ie(e){e.preventDefault(),oe(null)}let ae=!1;function oe(e){ae||(ae=!0,n.removeEventListener(`cancel`,ie),n.removeEventListener(`click`,re),n.removeEventListener(`keydown`,ne),n.open&&n.close(),n.remove(),t(e))}n.addEventListener(`cancel`,ie),n.addEventListener(`click`,re),n.addEventListener(`keydown`,ne),document.body.appendChild(n),v(),n.showModal(),r.focus()})}var aC={image:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/></svg>`,embed:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="14" x="2" y="3" rx="2" ry="2"/><line x1="8" x2="16" y1="21" y2="21"/><line x1="12" x2="12" y1="17" y2="21"/><polygon points="10 8 15 11 10 14 10 8" fill="currentColor"/></svg>`,divider:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12h18"/></svg>`,readMore:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12h18"/><path d="m9 18 3 3 3-3"/><path d="m9 6-3-3-3 3"/><path d="M3 6h18"/></svg>`,footnote:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7 4h10"/><path d="M12 4v11"/><path d="M9 9h6"/><path d="M16 20h4"/><path d="M18 14v6"/></svg>`,table:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3v18"/><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M3 9h18"/><path d="M3 15h18"/></svg>`,code:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>`,blockquote:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 21c3 0 7-1 7-8V5c0-1.25-.756-2.017-2-2H4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2 1 0 1 0 1 1v1c0 1-1 2-2 2s-1 .008-1 1.031V20c0 1 0 1 1 1z"/><path d="M15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2h.75c0 2.25.25 4-2.75 4v3c0 1 0 1 1 1z"/></svg>`,bulletList:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="8" x2="21" y1="6" y2="6"/><line x1="8" x2="21" y1="12" y2="12"/><line x1="8" x2="21" y1="18" y2="18"/><line x1="3" x2="3.01" y1="6" y2="6"/><line x1="3" x2="3.01" y1="12" y2="12"/><line x1="3" x2="3.01" y1="18" y2="18"/></svg>`,orderedList:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="10" x2="21" y1="6" y2="6"/><line x1="10" x2="21" y1="12" y2="12"/><line x1="10" x2="21" y1="18" y2="18"/><path d="M4 6h1v4"/><path d="M4 10h2"/><path d="M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"/></svg>`,h1:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="M17 12l3-2v10"/></svg>`,h2:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1"/></svg>`,h3:`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2"/><path d="M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2"/></svg>`},oC={media:`Media`,structure:`Structure`,formatting:`Formatting`,headings:`Headings`},sC=[`media`,`structure`,`formatting`,`headings`],cC=`No matches. Try another command.`,lC={insert:`Insert`,close:`Close`},uC=[{label:`Media`,description:`Upload an image or video.`,group:`media`,keywords:[`image`,`video`,`photo`,`upload`],icon:aC.image,command:(e,t)=>{e.chain().focus().deleteRange(t).run(),document.dispatchEvent(new CustomEvent(`jant:slash-image`,{bubbles:!0}))}},{label:`Embed`,description:`Embed a YouTube video, tweet, or any HTTPS page.`,group:`media`,keywords:[`embed`,`youtube`,`vimeo`,`spotify`,`video`,`iframe`,`html`,`letterbird`],icon:aC.embed,command:(e,t)=>{e.chain().focus().deleteRange(t).run(),iC().then(t=>{if(!t){e.commands.focus();return}t.kind===`embed`?e.chain().focus().setEmbed({url:t.url,caption:t.caption}).run():t.kind===`link`?e.chain().focus().insertContent({type:`text`,text:t.url,marks:[{type:`link`,attrs:{href:t.url}}]}).run():e.chain().focus().setHtmlBlock({html:t.html}).run()})}},{label:`Divider`,description:`Separate one thought from the next.`,group:`structure`,keywords:[`line`,`rule`,`separator`,`break`,`hr`],icon:aC.divider,command:(e,t)=>{e.chain().focus().deleteRange(t).setHorizontalRule().run()}},{label:`Read More`,description:`Collapse the rest of a longer post.`,group:`structure`,keywords:[`excerpt`,`continue`,`teaser`,`more`,`break`],icon:aC.readMore,command:(e,t)=>{e.chain().focus().deleteRange(t).insertMoreBreak().run()}},{label:`Footnote`,description:`Insert a numbered footnote and jump to its note.`,group:`structure`,keywords:[`footnote`,`note`,`citation`,`reference`,`superscript`],icon:aC.footnote,command:(e,t)=>{e.chain().focus().deleteRange(t).insertFootnote().run()}},{label:`Table`,description:`Insert a 3 by 3 table.`,group:`structure`,keywords:[`grid`,`rows`,`columns`,`spreadsheet`],icon:aC.table,command:(e,t)=>{e.chain().focus().deleteRange(t).insertTable({rows:3,cols:3,withHeaderRow:!0}).run()}},{label:`Code Block`,description:`Format a block of code or monospace text.`,group:`formatting`,keywords:[`code`,`snippet`,`pre`,`monospace`],icon:aC.code,command:(e,t)=>{e.chain().focus().deleteRange(t).toggleCodeBlock().run()}},{label:`Blockquote`,description:`Set off quoted text or a pull quote.`,group:`formatting`,keywords:[`quote`,`citation`,`excerpt`,`callout`],icon:aC.blockquote,command:(e,t)=>{e.chain().focus().deleteRange(t).toggleBlockquote().run()}},{label:`Bullet List`,description:`Start an unordered list.`,group:`formatting`,keywords:[`list`,`bullets`,`unordered`,`ul`],icon:aC.bulletList,command:(e,t)=>{e.chain().focus().deleteRange(t).toggleBulletList().run()}},{label:`Ordered List`,description:`Start a numbered list.`,group:`formatting`,keywords:[`list`,`numbered`,`ordered`,`ol`],icon:aC.orderedList,command:(e,t)=>{e.chain().focus().deleteRange(t).toggleOrderedList().run()}},{label:`Heading 1`,description:`Insert the largest section heading.`,group:`headings`,keywords:[`title`,`h1`,`large heading`,`section title`],icon:aC.h1,command:(e,t)=>{e.chain().focus().deleteRange(t).toggleHeading({level:1}).run()}},{label:`Heading 2`,description:`Insert a medium section heading.`,group:`headings`,keywords:[`subtitle`,`h2`,`section heading`],icon:aC.h2,command:(e,t)=>{e.chain().focus().deleteRange(t).toggleHeading({level:2}).run()}},{label:`Heading 3`,description:`Insert a small section heading.`,group:`headings`,keywords:[`subheading`,`h3`,`small heading`],icon:aC.h3,command:(e,t)=>{e.chain().focus().deleteRange(t).toggleHeading({level:3}).run()}}];function dC(e){let t=!1;return e.state.doc.descendants(e=>e.type.name===`moreBreak`?(t=!0,!1):!t),t}function fC(e){return e&&dC(e)?uC.filter(e=>e.label!==`Read More`):uC}var pC=null,mC=0,hC=[],gC=null,_C=null,vC=null,yC=null;function bC(){return pC?pC.querySelector(`.tiptap-slash-menu-scroll`)??pC:null}function xC(){let e=document.createElement(`div`);return e.className=`tiptap-slash-menu`,e.dataset.editorFloatingUi=`true`,e.style.position=`fixed`,e}function SC(){if(!pC)return;let e=bC();if(!e)return;let t=pC.querySelector(`.tiptap-slash-item.is-selected`);if(!t)return;let n=t.offsetTop-e.offsetTop,r=n+t.offsetHeight,i=e.scrollTop,a=i+e.clientHeight;n<i?e.scrollTop=n:r>a&&(e.scrollTop=r-e.clientHeight)}function CC(){pC?.querySelectorAll(`.tiptap-slash-item`).forEach((e,t)=>{let n=t===mC;e.classList.toggle(`is-selected`,n),e.setAttribute(`aria-selected`,n?`true`:`false`)}),TC(),SC()}function wC(){return hC[mC]??null}function TC(){let e=pC?.querySelector(`.tiptap-slash-footer-description`);e&&(e.textContent=wC()?.description??``)}function EC(e){return`<div class="tiptap-slash-footer">
269
269
  <span class="tiptap-slash-footer-description">${mx(e?.description??``)}</span>
270
270
  <span class="tiptap-slash-footer-actions" aria-hidden="true">
271
271
  <span class="tiptap-slash-footer-note">
@@ -297,15 +297,15 @@ ${t.slice(l+2)}`,d+=1;else break}t.push({indent:l,number:parseInt(s,10),content:
297
297
  </section>`}).join(``);pC.innerHTML=`<div class="tiptap-slash-menu-scroll">
298
298
  ${n}
299
299
  </div>
300
- ${EC(wC())}`,pC.querySelectorAll(`.tiptap-slash-item`).forEach(e=>{e.addEventListener(`mousedown`,n=>{n.preventDefault(),t(parseInt(e.dataset.index??`0`,10))}),e.addEventListener(`mouseenter`,()=>{mC=parseInt(e.dataset.index??`0`,10),CC()})});let r=bC();r&&(r.scrollTop=0)}function kC(){yC&&=(document.removeEventListener(`mousedown`,yC,!0),null),pC?.remove(),pC=null,mC=0,hC=[],gC=null,_C=null,vC=null}function AC(e,t){if(!pC)return;pC.style.maxHeight=``;let n=WS(null),r=t?WS(t):n,i=GS({anchorRect:{left:e.left,right:e.left,top:e.top,bottom:e.bottom},containerRect:n,floatingWidth:pC.offsetWidth,floatingHeight:pC.offsetHeight,preferredPlacement:`bottom`,fallbackPlacement:`top`,align:`start`,gap:6});pC.style.left=`${i.left-r.left}px`,pC.style.top=`${i.top-r.top}px`,pC.style.maxHeight=i.maxHeight===null?``:`${i.maxHeight}px`}function jC(){yC=e=>{if(!(!pC||pC.contains(e.target))&&_C&&vC){let{state:e,view:t}=_C;t.dispatch(e.tr.delete(vC.from,vC.to))}},document.addEventListener(`mousedown`,yC,!0)}var MC=new Fr(`jantSlashTyping`);function NC(){return new Mr({key:MC,state:{init:()=>({docChanged:!1}),apply:e=>({docChanged:e.docChanged})}})}function PC({state:e,range:t}){let n=e.doc.resolve(t.to),r=n.parent,i=t.to-n.start();if(i>=r.content.size)return!0;let a=r.textBetween(i,i+1,` `,` `);return a?/\s/.test(a):!0}function FC({state:e,range:t,isActive:n}){return PC({state:e,range:t})?n?!0:MC.getState(e)?.docChanged??!1:!1}var IC=N.create({name:`slashCommands`,addOptions(){return{suggestion:{char:`/`,startOfLine:!1,allow:FC,items:({query:e,editor:t})=>{let n=fC(t),r=Zx(e);return r?n.map((e,t)=>({item:e,index:t,rank:Xx([e.label,e.description,...e.keywords],r)})).filter(e=>e.rank!==null).sort((e,t)=>e.rank-t.rank||e.index-t.index).map(e=>e.item):n},render:()=>{function e(e){let t=e.options.element;return t instanceof globalThis.Element?t:null}return{onStart:t=>{pC=xC(),mC=0,gC=t.command,_C=t.editor,vC=t.range,OC(t.items,e=>t.command({index:e})),document.dispatchEvent(new CustomEvent(`jant:slash-command-discovered`,{bubbles:!0}));let n=e(t.editor)?.closest(`dialog`)??null;(n??document.body).appendChild(pC);let r=t.clientRect?.();r&&AC(r,n),jC()},onUpdate:t=>{gC=t.command,vC=t.range,OC(t.items,e=>t.command({index:e}));let n=t.clientRect?.();n&&AC(n,e(t.editor)?.closest(`dialog`)??null)},onKeyDown:e=>{let{event:t,view:n,range:r}=e;return t.key===`ArrowDown`?(t.preventDefault(),hC.length===0?!0:(mC=(mC+1)%hC.length,CC(),!0)):t.key===`ArrowUp`?(t.preventDefault(),hC.length===0?!0:(mC=(mC-1+hC.length)%hC.length,CC(),!0)):t.key===`Enter`?(t.preventDefault(),hC.length===0||gC?.({index:mC}),!0):t.key===`Escape`?(t.stopPropagation(),t.preventDefault(),n.dispatch(n.state.tr.delete(r.from,r.to)),!0):!1},onExit:()=>{kC()}}},command:({editor:e,range:t,props:n})=>{let r=hC[n.index];r&&r.command(e,t)}}}},addProseMirrorPlugins(){return[NC(),VS({editor:this.editor,...this.options.suggestion})]}}),LC=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~`.split(``),RC=(e,t)=>{var n=``;for(let r=1;r<=t;r++){let i=Math.floor(e)/83**(t-r)%83;n+=LC[Math.floor(i)]}return n},zC=e=>{let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4},BC=e=>{let t=Math.max(0,Math.min(1,e));return t<=.0031308?Math.trunc(t*12.92*255+.5):Math.trunc((1.055*t**.4166666666666667-.055)*255+.5)},VC=e=>e<0?-1:1,HC=(e,t)=>VC(e)*Math.abs(e)**+t,UC=class extends Error{constructor(e){super(e),this.name=`ValidationError`,this.message=e}},WC=4,GC=(e,t,n,r)=>{let i=0,a=0,o=0,s=t*WC;for(let c=0;c<t;c++){let t=WC*c;for(let l=0;l<n;l++){let n=t+l*s,u=r(c,l);i+=u*zC(e[n]),a+=u*zC(e[n+1]),o+=u*zC(e[n+2])}}let c=1/(t*n);return[i*c,a*c,o*c]},KC=e=>{let t=BC(e[0]),n=BC(e[1]),r=BC(e[2]);return(t<<16)+(n<<8)+r},qC=(e,t)=>{let n=Math.floor(Math.max(0,Math.min(18,Math.floor(HC(e[0]/t,.5)*9+9.5)))),r=Math.floor(Math.max(0,Math.min(18,Math.floor(HC(e[1]/t,.5)*9+9.5)))),i=Math.floor(Math.max(0,Math.min(18,Math.floor(HC(e[2]/t,.5)*9+9.5))));return n*19*19+r*19+i},JC=(e,t,n,r,i)=>{if(r<1||r>9||i<1||i>9)throw new UC(`BlurHash must have between 1 and 9 components`);if(t*n*4!==e.length)throw new UC(`Width and height must match the pixels array`);let a=[];for(let o=0;o<i;o++)for(let i=0;i<r;i++){let r=i==0&&o==0?1:2,s=GC(e,t,n,(e,a)=>r*Math.cos(Math.PI*i*e/t)*Math.cos(Math.PI*o*a/n));a.push(s)}let o=a[0],s=a.slice(1),c=``,l=r-1+(i-1)*9;c+=RC(l,1);let u;if(s.length>0){let e=Math.max(...s.map(e=>Math.max(...e))),t=Math.floor(Math.max(0,Math.min(82,Math.floor(e*166-.5))));u=(t+1)/166,c+=RC(t,1)}else u=1,c+=RC(0,1);return c+=RC(KC(o),4),s.forEach(e=>{c+=RC(qC(e,u),2)}),c};async function YC(e){let t=await $C(e),{width:n,height:r}=t,i=Math.min(32/n,32/r,1),a=Math.max(Math.round(n*i),1),o=Math.max(Math.round(r*i),1),s=document.createElement(`canvas`);s.width=a,s.height=o;let c=s.getContext(`2d`);if(!c)throw Error(`Failed to get canvas context`);return c.drawImage(t,0,0,a,o),{width:n,height:r,blurhash:JC(c.getImageData(0,0,a,o).data,a,o,4,3)}}async function XC(e){let t=URL.createObjectURL(e);try{let e=document.createElement(`video`);e.muted=!0,e.preload=`auto`;let{width:n,height:r,duration:i}=await new Promise((n,r)=>{e.onloadedmetadata=()=>n({width:e.videoWidth,height:e.videoHeight,duration:e.duration}),e.onerror=()=>r(Error(`Failed to load video metadata`)),e.src=t}),a,o;try{let t=Math.min(i*.1,1),s=await Promise.race([ew(e,n,r,t),tw(8e3)]);a=s.blurhash,o=s.poster}catch{}return{width:n,height:r,blurhash:a,poster:o}}finally{URL.revokeObjectURL(t)}}async function ZC(e){let t=await e.arrayBuffer(),n=new AudioContext;try{let e=(await n.decodeAudioData(t)).getChannelData(0),r=Math.max(1,Math.floor(e.length/100)),i=Array(100);for(let t=0;t<100;t++){let n=0,a=t*r,o=Math.min(a+r,e.length);for(let t=a;t<o;t++){let r=Math.abs(e[t]);r>n&&(n=r)}i[t]=n}let a=0;for(let e of i)e>a&&(a=e);if(a>0)for(let e=0;e<100;e++)i[e]=Math.round(i[e]/a*100)/100;return JSON.stringify(i)}finally{await n.close()}}async function QC(e){try{if(e.type.startsWith(`image/`))return await YC(e);if(e.type.startsWith(`video/`)){let t=await XC(e);return{width:t.width,height:t.height,blurhash:t.blurhash,poster:t.poster}}if(e.type.startsWith(`audio/`))return{waveform:await ZC(e)}}catch{}return{}}function $C(e){return new Promise((t,n)=>{let r=new Image,i=URL.createObjectURL(e);r.onload=()=>{URL.revokeObjectURL(i),t(r)},r.onerror=()=>{URL.revokeObjectURL(i),n(Error(`Failed to load image`))},r.src=i})}function ew(e,t,n,r){return new Promise((i,a)=>{e.currentTime=r,e.onseeked=()=>{try{let r=Math.min(32/t,32/n,1),a=Math.max(Math.round(t*r),1),o=Math.max(Math.round(n*r),1),s=document.createElement(`canvas`);s.width=a,s.height=o;let c=s.getContext(`2d`);if(!c)throw Error(`Failed to get canvas context`);c.drawImage(e,0,0,a,o);let l=JC(c.getImageData(0,0,a,o).data,a,o,4,3),u=Math.min(640/t,1),d=Math.round(t*u),f=Math.round(n*u),p=document.createElement(`canvas`);p.width=d,p.height=f;let m=p.getContext(`2d`);if(!m){i({blurhash:l});return}m.drawImage(e,0,0,d,f),p.toBlob(e=>{i({blurhash:l,poster:e??void 0})},`image/webp`,.8)}catch(e){a(e)}},e.onerror=()=>a(Error(`Video seek failed`))})}function tw(e){return new Promise((t,n)=>setTimeout(()=>n(Error(`Timeout`)),e))}function nw(e){if(!le(e))return null;let t=w(e,`kind`),n=w(e,`method`),r=w(e,`url`);if(!t||n!==`PUT`||!r)return null;if(t===`relay`)return{kind:t,method:`PUT`,url:r};if(t===`multipartRelay`){let n=de(e,`partSize`);return n?{kind:t,method:`PUT`,url:r,partSize:n}:null}if(t===`put`){let n=de(e,`expiresAt`),i=e.headers;if(!n||!le(i))return null;let a={};for(let[e,t]of Object.entries(i))typeof t==`string`&&(a[e]=t);return{kind:t,method:`PUT`,url:r,headers:a,expiresAt:n}}return null}function rw(e,t,n,r){return new Promise((i,a)=>{let o=new globalThis.XMLHttpRequest;o.open(`PUT`,e);for(let[e,t]of Object.entries(n))o.setRequestHeader(e,t);o.upload.addEventListener(`progress`,e=>{e.lengthComputable&&r&&r(e.loaded/e.total)}),o.addEventListener(`load`,()=>{i({status:o.status,ok:o.status>=200&&o.status<300,text:o.responseText})}),o.addEventListener(`error`,()=>a(Error(`Network error`))),o.addEventListener(`abort`,()=>a(Error(`Upload aborted`))),o.send(t)})}function iw(e){try{let t=JSON.parse(e);return le(t)?t:null}catch{return null}}async function aw(e){let t=await fetch(o(`/api/uploads/init`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({filename:e.name,contentType:e.type||`application/octet-stream`,size:e.size})});if(!t.ok)throw Error(await pe(t,`Failed to start upload`));let n=await fe(t),r=w(n,`id`),i=nw(n.transport);if(!r||!i)throw Error(`Failed to start upload`);return{id:r,transport:i}}async function ow(e,t){let n=await fetch(o(`/api/uploads/${e}/poster`),{method:`PUT`,headers:{"Content-Type":t.type||`image/webp`},body:t});if(!n.ok)throw Error(await pe(n,`Failed to upload poster`))}async function sw(e){await fetch(o(`/api/uploads/${e}/abort`),{method:`POST`}).catch(()=>{})}async function cw(e,t){let n=await fetch(o(`/api/uploads/${e}/complete`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok)throw Error(await pe(n,`Failed to complete upload`));let r=await fe(n),i=w(r,`id`),a=w(r,`filename`),s=w(r,`url`),c=w(r,`mimeType`),l=de(r,`size`);if(!i||!a||!s||!c||l===void 0)throw Error(`Failed to complete upload`);return{id:i,filename:a,url:s,mimeType:c,size:l}}async function lw(e,t,n,r){let i=Math.ceil(n.size/t.partSize),a=[],s=0;for(let e=0;e<i;e+=1){let i=e*t.partSize,c=Math.min(i+t.partSize,n.size),l=e+1,u=n.slice(i,c),d=c-i,f=await rw(o(`${t.url}?partNumber=${l}`),u,{},e=>{r?.((s+d*e)/n.size)});if(!f.ok)throw Error(me(f.text,`Failed to upload part ${l}`));let p=iw(f.text),m=p?de(p,`partNumber`):null,h=p?w(p,`etag`):null;if(!m||!h)throw Error(`Failed to upload part ${l}`);a.push({partNumber:m,etag:h}),s+=d,r?.(s/n.size)}return a}async function uw(e,t,n){let{id:r,transport:i}=await aw(e);try{if(i.kind===`put`){let t=await rw(i.url,e,i.headers,n);if(!t.ok)throw Error(me(t.text,`Upload failed`));n?.(1)}else if(i.kind===`relay`){let t=await rw(o(i.url),e,{"Content-Type":e.type},n);if(!t.ok)throw Error(me(t.text,`Upload failed`));n?.(1)}let a=i.kind===`multipartRelay`?await lw(r,i,e,n):void 0;return t.poster&&await ow(r,t.poster),cw(r,{...t,parts:a})}catch(e){throw await sw(r),e}}async function dw(e){let{file:t,width:n,height:r}=await oe.processToFile(e),i;try{i=(await YC(t)).blurhash}catch{}let a=await uw(t,{width:n,height:r,blurhash:i});return{url:a.url,id:a.id}}var fw=new Map,pw=new Map;function mw(e,t,n){if(e.isDestroyed)return;let{doc:r}=e.state,i=!1;r.descendants((r,a)=>{i||r.type.name!==`image`||r.attrs.src!==t||(e.chain().command(({tr:e})=>(e.setNodeMarkup(a,void 0,{...r.attrs,src:n}),!0)).run(),i=!0)})}function hw(e,t){if(e.isDestroyed)return;let{doc:n}=e.state;n.descendants((n,r)=>{n.type.name===`image`&&n.attrs.src===t&&e.chain().command(({tr:e})=>(e.delete(r,r+n.nodeSize),!0)).run()})}async function gw(e,t,n=dw){let r=URL.createObjectURL(t);e.chain().focus().setImage({src:r}).run();let i=n(t).then(e=>e.url);fw.set(r,i);try{mw(e,r,await i)}catch{hw(e,r)}finally{fw.delete(r)&&URL.revokeObjectURL(r)}}function _w(e){let t=[],{doc:n}=e.state;return n.descendants(n=>{if(n.type.name!==`image`)return;let r=n.attrs.src;if(!r?.startsWith(`blob:`))return;let i=fw.get(r);if(!i)return;fw.delete(r),pw.set(r,i);let a=i.then(t=>mw(e,r,t),()=>hw(e,r)).finally(()=>{pw.delete(r),URL.revokeObjectURL(r)});t.push(a)}),t}async function vw(e){if(!e)return e;let t=new Map;if(yw(e,t),t.size===0)return e;let n=new Map;return await Promise.allSettled(Array.from(t.entries()).map(async([e,t])=>{let r=await t;n.set(e,r)})),bw(e,n)}function yw(e,t){if(e.type===`image`&&typeof e.attrs?.src==`string`&&e.attrs.src.startsWith(`blob:`)){let n=fw.get(e.attrs.src)??pw.get(e.attrs.src);n&&t.set(e.attrs.src,n)}if(e.content)for(let n of e.content)yw(n,t)}function bw(e,t){if(e.type===`image`&&typeof e.attrs?.src==`string`&&e.attrs.src.startsWith(`blob:`)){let n=t.get(e.attrs.src);return n?{...e,attrs:{...e.attrs,src:n}}:{type:`__removed__`}}if(!e.content)return e;let n=e.content.map(e=>bw(e,t)).filter(e=>e.type!==`__removed__`);return n===e.content?e:{...e,content:n}}var xw=new Fr(`pasteMedia`);function Sw(e){return`${e.name}:${e.type}:${e.size}:${e.lastModified}`}function Cw(e){if(!e)return[];let t=Array.from(e.items??[]).filter(e=>e.kind===`file`).map(e=>e.getAsFile()).filter(e=>e!==null),n=t.length>0?t:Array.from(e.files??[]),r=new Set;return n.filter(e=>{let t=Sw(e);return r.has(t)?!1:(r.add(t),!0)})}var ww=N.create({name:`pasteMedia`,addOptions(){return{shouldInsertInline:void 0,onPasteFiles:void 0}},addProseMirrorPlugins(){let e=this,t=t=>{let n=t.filter(t=>e.options.shouldInsertInline?.(t)===!0),r=t.filter(e=>!n.includes(e));if(n.length===0&&(r.length===0||e.options.onPasteFiles===void 0))return!1;for(let t of n){let n=e.options.uploadInlineImage;if(n){n(t);continue}gw(e.editor,t)}return r.length>0&&e.options.onPasteFiles!==void 0&&e.options.onPasteFiles(r),!0};return[new Mr({key:xw,props:{handlePaste(e,n){let r=Cw(n.clipboardData);return r.length===0||!t(r)?!1:(n.preventDefault(),!0)},handleDrop(e,n){let r=Cw(n.dataTransfer);return r.length===0||!t(r)?!1:(n.preventDefault(),!0)}}})]}}),Tw=new Fr(`linkToolbar`),Ew=`hidden`,Dw=!1;function Ow(){return Ew===`input`&&Dw}var kw=`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 10 4 15 9 20"/><path d="M20 4v7a4 4 0 0 1-4 4H4"/></svg>`;function Aw(e){let{selection:t}=e;if(!t.empty)return null;let n=t.$from,r=e.schema.marks.link;if(!r)return null;let i=n.marks().find(e=>e.type===r);if(!i)return null;let a=n.parent,o=n.start(),s=0,c=0,l=!1,u=0;for(let e=0;e<a.childCount;e++){let t=a.child(e),n=o+u,d=n+t.nodeSize;if(t.marks.some(e=>e.type===r&&e.attrs.href===i.attrs.href))l||=(s=n,!0),c=d;else if(l)break;u+=t.nodeSize}return l?{from:s,to:c,href:i.attrs.href}:null}var jw=N.create({name:`linkToolbar`,addProseMirrorPlugins(){let e=this.editor,t=null,n=null,r=null,i=0,a=0,o=!1,s=!1,c=null;function l(){t=document.createElement(`div`),t.className=`tiptap-link-input`,t.dataset.editorFloatingUi=`true`,t.style.display=`none`;let i=document.createElement(`div`);i.className=`tiptap-link-input-fields`,r=document.createElement(`input`),r.type=`text`,r.className=`tiptap-link-input-text`,r.placeholder=`Link text`,n=document.createElement(`input`),n.type=`url`,n.className=`tiptap-link-input-field`,n.placeholder=`https:// (empty to unlink)`,i.appendChild(r),i.appendChild(n);let a=document.createElement(`button`);a.type=`button`,a.className=`tiptap-link-input-confirm`,a.innerHTML=kw,a.title=`Apply link`,t.appendChild(i),t.appendChild(a);let o=t=>{t.key===`Enter`?(t.preventDefault(),t.stopPropagation(),m()):t.key===`Escape`&&(t.preventDefault(),t.stopPropagation(),s=!0,f(),e.commands.focus())};r.addEventListener(`keydown`,o),n.addEventListener(`keydown`,o);let c=()=>{Dw=!0},l=()=>{requestAnimationFrame(()=>{let e=document.activeElement;(!t||!t.contains(e))&&(Dw=!1)})};r.addEventListener(`focus`,c),n.addEventListener(`focus`,c),r.addEventListener(`blur`,l),n.addEventListener(`blur`,l),a.addEventListener(`mousedown`,e=>{e.preventDefault(),m()}),t.addEventListener(`mousedown`,e=>{e.stopPropagation()})}function u(e,t,n,r){e.style.display=`flex`;let i=t.dom.closest(`dialog`),a=t.coordsAtPos(n),o=t.coordsAtPos(r),s=e.getBoundingClientRect(),c=GS({anchorRect:{left:a.left,right:o.right,top:Math.min(a.top,o.top),bottom:Math.max(a.bottom,o.bottom)},containerRect:WS(i),floatingWidth:s.width,floatingHeight:s.height,preferredPlacement:`top`,fallbackPlacement:`bottom`,align:`center`});e.style.left=`${c.left}px`,e.style.top=`${c.top}px`}function d(e,o){if(!(!t||!n||!r)){if(o.from!==void 0&&o.to!==void 0?(i=o.from,a=o.to):(i=e.state.selection.from,a=e.state.selection.to),Ew=`input`,n.value=o.href,r.value=o.text??e.state.doc.textBetween(i,a,``),u(t,e,i,a),o.focus){let e=r.value.length>0?n:r;requestAnimationFrame(()=>{e.focus(),e.select()})}p(),c=e=>{t&&!t.contains(e.target)&&(s=!0,f())},setTimeout(()=>{c&&document.addEventListener(`mousedown`,c,!0)},0)}}function f(){t&&(t.style.display=`none`),Ew=`hidden`,Dw=!1,p()}function p(){c&&=(document.removeEventListener(`mousedown`,c,!0),null)}function m(){if(!n||!r)return;let t=n.value.trim(),s=e.state.doc.textBetween(i,a,``),c=r.value,l=c.length>0?c:t;if(f(),!t){e.chain().focus().setTextSelection({from:i,to:a}).unsetLink().setTextSelection(a).run(),o=!0;return}let u=l!==s,d=i+l.length;u?e.chain().focus().command(({tr:e})=>(e.insertText(l,i,a),!0)).setTextSelection({from:i,to:d}).setLink({href:t}).setTextSelection(d).run():e.chain().focus().setTextSelection({from:i,to:a}).setLink({href:t}).setTextSelection(a).run(),o=!0}return[new Mr({key:Tw,view(e){l();let n=e.dom.closest(`dialog`);t&&(n??document.body).appendChild(t);let r=()=>{s=!1,o=!0,d(e,{href:``,focus:!0})};e.dom.addEventListener(`tiptap:open-link-input`,r);let c=e=>{e.key===`Escape`&&Ew===`input`&&(e.preventDefault(),e.stopPropagation(),s=!0,f())};return e.dom.addEventListener(`keydown`,c),{update(e){if(o){o=!1;return}let n=Aw(e.state);if(Ew===`input`&&Dw){t&&u(t,e,i,a);return}if(n){if(s)return;d(e,{href:n.href,from:n.from,to:n.to,focus:!1})}else s=!1,Ew===`input`&&f()},destroy(){e.dom.removeEventListener(`tiptap:open-link-input`,r),e.dom.removeEventListener(`keydown`,c),p(),t?.remove(),t=null,Ew=`hidden`,Dw=!1}}}})]}}),Mw=new Fr(`bubbleMenu`),Nw={bold:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M6 12h9a4 4 0 0 1 0 8H6V4h8a4 4 0 0 1 0 8"/></svg>`,italic:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="4" x2="10" y2="4"/><line x1="14" y1="20" x2="5" y2="20"/><line x1="15" y1="4" x2="9" y2="20"/></svg>`,h1:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="M17 12l3-2v10"/></svg>`,h2:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1"/></svg>`,blockquote:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 21c3 0 7-1 7-8V5c0-1.25-.756-2.017-2-2H4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2 1 0 1 0 1 1v1c0 1-1 2-2 2s-1 .008-1 1.031V20c0 1 0 1 1 1z"/><path d="M15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2h.75c0 2.25.25 4-2.75 4v3c0 1 0 1 1 1z"/></svg>`,link:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>`,clear:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m16 22-1-4"/><path d="M19 14a1 1 0 0 0 1-1v-1a2 2 0 0 0-2-2h-3a1 1 0 0 1-1-1V4a2 2 0 0 0-4 0v5a1 1 0 0 1-1 1H6a2 2 0 0 0-2 2v1a1 1 0 0 0 1 1"/><path d="M19 14H5l-1.973 6.767A1 1 0 0 0 4 22h16a1 1 0 0 0 .973-1.233z"/><path d="m8 22 1-4"/></svg>`};function Pw(e,t){let{to:n,empty:r}=e.state.selection;if(r){e.chain().focus().toggleMark(t).run();return}let i=e.schema.marks[t];e.chain().focus().toggleMark(t).setTextSelection(n).command(({tr:e})=>(i&&e.removeStoredMark(i),!0)).run()}function Fw(e,t){return t===`compose`?[{key:`bold`,icon:Nw.bold,title:`Bold`,action:()=>Pw(e,`bold`),isActive:()=>e.isActive(`bold`)},{key:`italic`,icon:Nw.italic,title:`Italic`,action:()=>Pw(e,`italic`),isActive:()=>e.isActive(`italic`)},{key:`sep`,icon:``,title:``,action:()=>{},isActive:()=>!1},{key:`link`,icon:Nw.link,title:`Link`,action:t=>{e.isActive(`link`)?e.chain().focus().unsetLink().run():t.dom.dispatchEvent(new CustomEvent(`tiptap:open-link-input`))},isActive:()=>e.isActive(`link`)},{key:`clear`,icon:Nw.clear,title:`Clear formatting`,action:()=>{let{to:t}=e.state.selection;e.chain().focus().unsetAllMarks().clearNodes().setTextSelection(t).run()},isActive:()=>!1}]:[{key:`bold`,icon:Nw.bold,title:`Bold`,action:()=>Pw(e,`bold`),isActive:()=>e.isActive(`bold`)},{key:`italic`,icon:Nw.italic,title:`Italic`,action:()=>Pw(e,`italic`),isActive:()=>e.isActive(`italic`)},{key:`h1`,icon:Nw.h1,title:`Heading 1`,action:()=>e.chain().focus().toggleHeading({level:1}).run(),isActive:()=>e.isActive(`heading`,{level:1})},{key:`h2`,icon:Nw.h2,title:`Heading 2`,action:()=>e.chain().focus().toggleHeading({level:2}).run(),isActive:()=>e.isActive(`heading`,{level:2})},{key:`sep`,icon:``,title:``,action:()=>{},isActive:()=>!1},{key:`blockquote`,icon:Nw.blockquote,title:`Quote`,action:()=>e.chain().focus().toggleBlockquote().run(),isActive:()=>e.isActive(`blockquote`)},{key:`link`,icon:Nw.link,title:`Link`,action:t=>{e.isActive(`link`)?e.chain().focus().unsetLink().run():t.dom.dispatchEvent(new CustomEvent(`tiptap:open-link-input`))},isActive:()=>e.isActive(`link`)}]}var Iw=N.create({name:`bubbleMenu`,addOptions(){return{toolbarMode:`default`}},addProseMirrorPlugins(){let e=this.editor,t=this.options.toolbarMode,n=null,r=[],i=new Map;function a(){n=document.createElement(`div`),n.className=`tiptap-bubble-menu`,n.dataset.editorFloatingUi=`true`,n.style.position=`fixed`,n.style.display=`none`,r=Fw(e,t);for(let t of r){if(t.key===`sep`){let e=document.createElement(`span`);e.className=`tiptap-bubble-sep`,n.appendChild(e);continue}let r=document.createElement(`button`);r.type=`button`,r.innerHTML=t.icon,r.title=t.title,r.className=`tiptap-bubble-btn`,r.addEventListener(`mousedown`,n=>{n.preventDefault(),t.action(e.view)}),n.appendChild(r),i.set(t.key,r)}}function o(e){if(!n)return;n.style.display=`flex`;let{from:t,to:r}=e.state.selection,i=e.coordsAtPos(t),a=e.coordsAtPos(r),o=e.dom.closest(`dialog`),s=n.getBoundingClientRect(),l=GS({anchorRect:{left:i.left,right:a.right,top:Math.min(i.top,a.top),bottom:Math.max(i.bottom,a.bottom)},containerRect:WS(o),floatingWidth:s.width,floatingHeight:s.height,preferredPlacement:`top`,fallbackPlacement:`bottom`,align:`center`});n.style.left=`${l.left}px`,n.style.top=`${l.top}px`,c()}function s(){n&&(n.style.display=`none`)}function c(){for(let t of r){if(t.key===`sep`)continue;let n=i.get(t.key);n&&n.classList.toggle(`is-active`,t.isActive(e.view))}}function l(e){let{state:t}=e,{selection:n}=t,{empty:r}=n;return!(r||!n.$from.parent.isTextblock||Ow())}return[new Mr({key:Mw,view(e){a();let t=e.dom.closest(`dialog`)??document.body;n&&t.appendChild(n);function r(t){let r=t.target;if(!r||e.dom.contains(r)||r.closest(`[data-editor-floating-ui]`)||n?.contains(r))return;let{state:i}=e,a=i.selection.from;e.dispatch(i.tr.setSelection(O.near(i.doc.resolve(a)))),e.dom.blur()}return t.addEventListener(`mousedown`,r),{update(e){l(e)?o(e):s()},destroy(){t.removeEventListener(`mousedown`,r),n?.remove(),n=null}}}})]}}),Lw=new Set([`bold`,`italic`,`strike`,`code`,`underline`]);function Rw(e){return e.filter(e=>Lw.has(e.type.name))}var zw=N.create({name:`exitableMarks`,addKeyboardShortcuts(){return{ArrowRight:({editor:e})=>{let{selection:t}=e.state,{$from:n}=t;if(!t.empty||n.pos!==n.end())return!1;let r=Rw(n.marks());if(!r.length)return!1;let{tr:i}=e.state;for(let e of r)i.removeStoredMark(e);return e.view.dispatch(i),!0},Enter:({editor:e})=>{let{selection:t}=e.state,{$from:n}=t;return!t.empty||n.parent.textContent.length>0||!Rw(e.state.storedMarks??n.marks()).length||requestAnimationFrame(()=>{let{tr:t}=e.state;t.setStoredMarks([]),e.view.dispatch(t)}),!1}}}}),Bw=` `,Vw=N.create({name:`tabIndent`,addKeyboardShortcuts(){return{Tab:({editor:e})=>{if(e.isActive(`listItem`))return e.commands.sinkListItem(`listItem`);if(e.isActive(`codeBlock`)){let{state:t,dispatch:n}=e.view,{selection:r}=t,{from:i,to:a}=r,o=t.doc.resolve(i),s=o.parent;if(s.type.name!==`codeBlock`)return!1;let c=o.start(),l=s.textContent;if(i===a)return n(t.tr.insertText(Bw,i)),!0;let u=i-c,d=a-c,f=[],p=l.lastIndexOf(`
300
+ ${EC(wC())}`,pC.querySelectorAll(`.tiptap-slash-item`).forEach(e=>{e.addEventListener(`mousedown`,n=>{n.preventDefault(),t(parseInt(e.dataset.index??`0`,10))}),e.addEventListener(`mouseenter`,()=>{mC=parseInt(e.dataset.index??`0`,10),CC()})});let r=bC();r&&(r.scrollTop=0)}function kC(){yC&&=(document.removeEventListener(`mousedown`,yC,!0),null),pC?.remove(),pC=null,mC=0,hC=[],gC=null,_C=null,vC=null}function AC(e,t){if(!pC)return;pC.style.maxHeight=``;let n=WS(null),r=t?WS(t):n,i=GS({anchorRect:{left:e.left,right:e.left,top:e.top,bottom:e.bottom},containerRect:n,floatingWidth:pC.offsetWidth,floatingHeight:pC.offsetHeight,preferredPlacement:`bottom`,fallbackPlacement:`top`,align:`start`,gap:6});pC.style.left=`${i.left-r.left}px`,pC.style.top=`${i.top-r.top}px`,pC.style.maxHeight=i.maxHeight===null?``:`${i.maxHeight}px`}function jC(){yC=e=>{if(!(!pC||pC.contains(e.target))&&_C&&vC){let{state:e,view:t}=_C;t.dispatch(e.tr.delete(vC.from,vC.to))}},document.addEventListener(`mousedown`,yC,!0)}var MC=new Pr(`jantSlashTyping`);function NC(){return new j({key:MC,state:{init:()=>({docChanged:!1}),apply:e=>({docChanged:e.docChanged})}})}function PC({state:e,range:t}){let n=e.doc.resolve(t.to),r=n.parent,i=t.to-n.start();if(i>=r.content.size)return!0;let a=r.textBetween(i,i+1,` `,` `);return a?/\s/.test(a):!0}function FC({state:e,range:t,isActive:n}){return PC({state:e,range:t})?n?!0:MC.getState(e)?.docChanged??!1:!1}var IC=N.create({name:`slashCommands`,addOptions(){return{suggestion:{char:`/`,startOfLine:!1,allow:FC,items:({query:e,editor:t})=>{let n=fC(t),r=Zx(e);return r?n.map((e,t)=>({item:e,index:t,rank:Xx([e.label,e.description,...e.keywords],r)})).filter(e=>e.rank!==null).sort((e,t)=>e.rank-t.rank||e.index-t.index).map(e=>e.item):n},render:()=>{function e(e){let t=e.options.element;return t instanceof globalThis.Element?t:null}return{onStart:t=>{pC=xC(),mC=0,gC=t.command,_C=t.editor,vC=t.range,OC(t.items,e=>t.command({index:e})),document.dispatchEvent(new CustomEvent(`jant:slash-command-discovered`,{bubbles:!0}));let n=e(t.editor)?.closest(`dialog`)??null;(n??document.body).appendChild(pC);let r=t.clientRect?.();r&&AC(r,n),jC()},onUpdate:t=>{gC=t.command,vC=t.range,OC(t.items,e=>t.command({index:e}));let n=t.clientRect?.();n&&AC(n,e(t.editor)?.closest(`dialog`)??null)},onKeyDown:e=>{let{event:t,view:n,range:r}=e;return t.key===`ArrowDown`?(t.preventDefault(),hC.length===0?!0:(mC=(mC+1)%hC.length,CC(),!0)):t.key===`ArrowUp`?(t.preventDefault(),hC.length===0?!0:(mC=(mC-1+hC.length)%hC.length,CC(),!0)):t.key===`Enter`?(t.preventDefault(),hC.length===0||gC?.({index:mC}),!0):t.key===`Escape`?(t.stopPropagation(),t.preventDefault(),n.dispatch(n.state.tr.delete(r.from,r.to)),!0):!1},onExit:()=>{kC()}}},command:({editor:e,range:t,props:n})=>{let r=hC[n.index];r&&r.command(e,t)}}}},addProseMirrorPlugins(){return[NC(),VS({editor:this.editor,...this.options.suggestion})]}}),LC=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~`.split(``),RC=(e,t)=>{var n=``;for(let r=1;r<=t;r++){let i=Math.floor(e)/83**(t-r)%83;n+=LC[Math.floor(i)]}return n},zC=e=>{let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4},BC=e=>{let t=Math.max(0,Math.min(1,e));return t<=.0031308?Math.trunc(t*12.92*255+.5):Math.trunc((1.055*t**.4166666666666667-.055)*255+.5)},VC=e=>e<0?-1:1,HC=(e,t)=>VC(e)*Math.abs(e)**+t,UC=class extends Error{constructor(e){super(e),this.name=`ValidationError`,this.message=e}},WC=4,GC=(e,t,n,r)=>{let i=0,a=0,o=0,s=t*WC;for(let c=0;c<t;c++){let t=WC*c;for(let l=0;l<n;l++){let n=t+l*s,u=r(c,l);i+=u*zC(e[n]),a+=u*zC(e[n+1]),o+=u*zC(e[n+2])}}let c=1/(t*n);return[i*c,a*c,o*c]},KC=e=>{let t=BC(e[0]),n=BC(e[1]),r=BC(e[2]);return(t<<16)+(n<<8)+r},qC=(e,t)=>{let n=Math.floor(Math.max(0,Math.min(18,Math.floor(HC(e[0]/t,.5)*9+9.5)))),r=Math.floor(Math.max(0,Math.min(18,Math.floor(HC(e[1]/t,.5)*9+9.5)))),i=Math.floor(Math.max(0,Math.min(18,Math.floor(HC(e[2]/t,.5)*9+9.5))));return n*19*19+r*19+i},JC=(e,t,n,r,i)=>{if(r<1||r>9||i<1||i>9)throw new UC(`BlurHash must have between 1 and 9 components`);if(t*n*4!==e.length)throw new UC(`Width and height must match the pixels array`);let a=[];for(let o=0;o<i;o++)for(let i=0;i<r;i++){let r=i==0&&o==0?1:2,s=GC(e,t,n,(e,a)=>r*Math.cos(Math.PI*i*e/t)*Math.cos(Math.PI*o*a/n));a.push(s)}let o=a[0],s=a.slice(1),c=``,l=r-1+(i-1)*9;c+=RC(l,1);let u;if(s.length>0){let e=Math.max(...s.map(e=>Math.max(...e))),t=Math.floor(Math.max(0,Math.min(82,Math.floor(e*166-.5))));u=(t+1)/166,c+=RC(t,1)}else u=1,c+=RC(0,1);return c+=RC(KC(o),4),s.forEach(e=>{c+=RC(qC(e,u),2)}),c};async function YC(e){let t=await $C(e),{width:n,height:r}=t,i=Math.min(32/n,32/r,1),a=Math.max(Math.round(n*i),1),o=Math.max(Math.round(r*i),1),s=document.createElement(`canvas`);s.width=a,s.height=o;let c=s.getContext(`2d`);if(!c)throw Error(`Failed to get canvas context`);return c.drawImage(t,0,0,a,o),{width:n,height:r,blurhash:JC(c.getImageData(0,0,a,o).data,a,o,4,3)}}async function XC(e){let t=URL.createObjectURL(e);try{let e=document.createElement(`video`);e.muted=!0,e.preload=`auto`;let{width:n,height:r,duration:i}=await new Promise((n,r)=>{e.onloadedmetadata=()=>n({width:e.videoWidth,height:e.videoHeight,duration:e.duration}),e.onerror=()=>r(Error(`Failed to load video metadata`)),e.src=t}),a,o;try{let t=Math.min(i*.1,1),s=await Promise.race([ew(e,n,r,t),tw(8e3)]);a=s.blurhash,o=s.poster}catch{}return{width:n,height:r,blurhash:a,poster:o}}finally{URL.revokeObjectURL(t)}}async function ZC(e){let t=await e.arrayBuffer(),n=new AudioContext;try{let e=(await n.decodeAudioData(t)).getChannelData(0),r=Math.max(1,Math.floor(e.length/100)),i=Array(100);for(let t=0;t<100;t++){let n=0,a=t*r,o=Math.min(a+r,e.length);for(let t=a;t<o;t++){let r=Math.abs(e[t]);r>n&&(n=r)}i[t]=n}let a=0;for(let e of i)e>a&&(a=e);if(a>0)for(let e=0;e<100;e++)i[e]=Math.round(i[e]/a*100)/100;return JSON.stringify(i)}finally{await n.close()}}async function QC(e){try{if(e.type.startsWith(`image/`))return await YC(e);if(e.type.startsWith(`video/`)){let t=await XC(e);return{width:t.width,height:t.height,blurhash:t.blurhash,poster:t.poster}}if(e.type.startsWith(`audio/`))return{waveform:await ZC(e)}}catch{}return{}}function $C(e){return new Promise((t,n)=>{let r=new Image,i=URL.createObjectURL(e);r.onload=()=>{URL.revokeObjectURL(i),t(r)},r.onerror=()=>{URL.revokeObjectURL(i),n(Error(`Failed to load image`))},r.src=i})}function ew(e,t,n,r){return new Promise((i,a)=>{e.currentTime=r,e.onseeked=()=>{try{let r=Math.min(32/t,32/n,1),a=Math.max(Math.round(t*r),1),o=Math.max(Math.round(n*r),1),s=document.createElement(`canvas`);s.width=a,s.height=o;let c=s.getContext(`2d`);if(!c)throw Error(`Failed to get canvas context`);c.drawImage(e,0,0,a,o);let l=JC(c.getImageData(0,0,a,o).data,a,o,4,3),u=Math.min(640/t,1),d=Math.round(t*u),f=Math.round(n*u),p=document.createElement(`canvas`);p.width=d,p.height=f;let m=p.getContext(`2d`);if(!m){i({blurhash:l});return}m.drawImage(e,0,0,d,f),p.toBlob(e=>{i({blurhash:l,poster:e??void 0})},`image/webp`,.8)}catch(e){a(e)}},e.onerror=()=>a(Error(`Video seek failed`))})}function tw(e){return new Promise((t,n)=>setTimeout(()=>n(Error(`Timeout`)),e))}function nw(e){if(!le(e))return null;let t=w(e,`kind`),n=w(e,`method`),r=w(e,`url`);if(!t||n!==`PUT`||!r)return null;if(t===`relay`)return{kind:t,method:`PUT`,url:r};if(t===`multipartRelay`){let n=de(e,`partSize`);return n?{kind:t,method:`PUT`,url:r,partSize:n}:null}if(t===`put`){let n=de(e,`expiresAt`),i=e.headers;if(!n||!le(i))return null;let a={};for(let[e,t]of Object.entries(i))typeof t==`string`&&(a[e]=t);return{kind:t,method:`PUT`,url:r,headers:a,expiresAt:n}}return null}function rw(e,t,n,r){return new Promise((i,a)=>{let o=new globalThis.XMLHttpRequest;o.open(`PUT`,e);for(let[e,t]of Object.entries(n))o.setRequestHeader(e,t);o.upload.addEventListener(`progress`,e=>{e.lengthComputable&&r&&r(e.loaded/e.total)}),o.addEventListener(`load`,()=>{i({status:o.status,ok:o.status>=200&&o.status<300,text:o.responseText})}),o.addEventListener(`error`,()=>a(Error(`Network error`))),o.addEventListener(`abort`,()=>a(Error(`Upload aborted`))),o.send(t)})}function iw(e){try{let t=JSON.parse(e);return le(t)?t:null}catch{return null}}async function aw(e){let t=await fetch(o(`/api/uploads/init`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({filename:e.name,contentType:e.type||`application/octet-stream`,size:e.size})});if(!t.ok)throw Error(await pe(t,`Failed to start upload`));let n=await fe(t),r=w(n,`id`),i=nw(n.transport);if(!r||!i)throw Error(`Failed to start upload`);return{id:r,transport:i}}async function ow(e,t){let n=await fetch(o(`/api/uploads/${e}/poster`),{method:`PUT`,headers:{"Content-Type":t.type||`image/webp`},body:t});if(!n.ok)throw Error(await pe(n,`Failed to upload poster`))}async function sw(e){await fetch(o(`/api/uploads/${e}/abort`),{method:`POST`}).catch(()=>{})}async function cw(e,t){let n=await fetch(o(`/api/uploads/${e}/complete`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok)throw Error(await pe(n,`Failed to complete upload`));let r=await fe(n),i=w(r,`id`),a=w(r,`filename`),s=w(r,`url`),c=w(r,`mimeType`),l=de(r,`size`);if(!i||!a||!s||!c||l===void 0)throw Error(`Failed to complete upload`);return{id:i,filename:a,url:s,mimeType:c,size:l}}async function lw(e,t,n,r){let i=Math.ceil(n.size/t.partSize),a=[],s=0;for(let e=0;e<i;e+=1){let i=e*t.partSize,c=Math.min(i+t.partSize,n.size),l=e+1,u=n.slice(i,c),d=c-i,f=await rw(o(`${t.url}?partNumber=${l}`),u,{},e=>{r?.((s+d*e)/n.size)});if(!f.ok)throw Error(me(f.text,`Failed to upload part ${l}`));let p=iw(f.text),m=p?de(p,`partNumber`):null,h=p?w(p,`etag`):null;if(!m||!h)throw Error(`Failed to upload part ${l}`);a.push({partNumber:m,etag:h}),s+=d,r?.(s/n.size)}return a}async function uw(e,t,n){let{id:r,transport:i}=await aw(e);try{if(i.kind===`put`){let t=await rw(i.url,e,i.headers,n);if(!t.ok)throw Error(me(t.text,`Upload failed`));n?.(1)}else if(i.kind===`relay`){let t=await rw(o(i.url),e,{"Content-Type":e.type},n);if(!t.ok)throw Error(me(t.text,`Upload failed`));n?.(1)}let a=i.kind===`multipartRelay`?await lw(r,i,e,n):void 0;return t.poster&&await ow(r,t.poster),cw(r,{...t,parts:a})}catch(e){throw await sw(r),e}}async function dw(e){let{file:t,width:n,height:r}=await oe.processToFile(e),i;try{i=(await YC(t)).blurhash}catch{}let a=await uw(t,{width:n,height:r,blurhash:i});return{url:a.url,id:a.id}}var fw=new Map,pw=new Map;function mw(e,t,n){if(e.isDestroyed)return;let{doc:r}=e.state,i=!1;r.descendants((r,a)=>{i||r.type.name!==`image`||r.attrs.src!==t||(e.chain().command(({tr:e})=>(e.setNodeMarkup(a,void 0,{...r.attrs,src:n}),!0)).run(),i=!0)})}function hw(e,t){if(e.isDestroyed)return;let{doc:n}=e.state;n.descendants((n,r)=>{n.type.name===`image`&&n.attrs.src===t&&e.chain().command(({tr:e})=>(e.delete(r,r+n.nodeSize),!0)).run()})}async function gw(e,t,n=dw){let r=URL.createObjectURL(t);e.chain().focus().setImage({src:r}).run();let i=n(t).then(e=>e.url);fw.set(r,i);try{mw(e,r,await i)}catch{hw(e,r)}finally{fw.delete(r)&&URL.revokeObjectURL(r)}}function _w(e){let t=[],{doc:n}=e.state;return n.descendants(n=>{if(n.type.name!==`image`)return;let r=n.attrs.src;if(!r?.startsWith(`blob:`))return;let i=fw.get(r);if(!i)return;fw.delete(r),pw.set(r,i);let a=i.then(t=>mw(e,r,t),()=>hw(e,r)).finally(()=>{pw.delete(r),URL.revokeObjectURL(r)});t.push(a)}),t}async function vw(e){if(!e)return e;let t=new Map;if(yw(e,t),t.size===0)return e;let n=new Map;return await Promise.allSettled(Array.from(t.entries()).map(async([e,t])=>{let r=await t;n.set(e,r)})),bw(e,n)}function yw(e,t){if(e.type===`image`&&typeof e.attrs?.src==`string`&&e.attrs.src.startsWith(`blob:`)){let n=fw.get(e.attrs.src)??pw.get(e.attrs.src);n&&t.set(e.attrs.src,n)}if(e.content)for(let n of e.content)yw(n,t)}function bw(e,t){if(e.type===`image`&&typeof e.attrs?.src==`string`&&e.attrs.src.startsWith(`blob:`)){let n=t.get(e.attrs.src);return n?{...e,attrs:{...e.attrs,src:n}}:{type:`__removed__`}}if(!e.content)return e;let n=e.content.map(e=>bw(e,t)).filter(e=>e.type!==`__removed__`);return n===e.content?e:{...e,content:n}}var xw=new Pr(`pasteMedia`);function Sw(e){return`${e.name}:${e.type}:${e.size}:${e.lastModified}`}function Cw(e){if(!e)return[];let t=Array.from(e.items??[]).filter(e=>e.kind===`file`).map(e=>e.getAsFile()).filter(e=>e!==null),n=t.length>0?t:Array.from(e.files??[]),r=new Set;return n.filter(e=>{let t=Sw(e);return r.has(t)?!1:(r.add(t),!0)})}var ww=N.create({name:`pasteMedia`,addOptions(){return{shouldInsertInline:void 0,onPasteFiles:void 0}},addProseMirrorPlugins(){let e=this,t=t=>{let n=t.filter(t=>e.options.shouldInsertInline?.(t)===!0),r=t.filter(e=>!n.includes(e));if(n.length===0&&(r.length===0||e.options.onPasteFiles===void 0))return!1;for(let t of n){let n=e.options.uploadInlineImage;if(n){n(t);continue}gw(e.editor,t)}return r.length>0&&e.options.onPasteFiles!==void 0&&e.options.onPasteFiles(r),!0};return[new j({key:xw,props:{handlePaste(e,n){let r=Cw(n.clipboardData);return r.length===0||!t(r)?!1:(n.preventDefault(),!0)},handleDrop(e,n){let r=Cw(n.dataTransfer);return r.length===0||!t(r)?!1:(n.preventDefault(),!0)}}})]}}),Tw=new Pr(`linkToolbar`),Ew=`hidden`,Dw=!1;function Ow(){return Ew===`input`&&Dw}var kw=`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 10 4 15 9 20"/><path d="M20 4v7a4 4 0 0 1-4 4H4"/></svg>`;function Aw(e){let{selection:t}=e;if(!t.empty)return null;let n=t.$from,r=e.schema.marks.link;if(!r)return null;let i=n.marks().find(e=>e.type===r);if(!i)return null;let a=n.parent,o=n.start(),s=0,c=0,l=!1,u=0;for(let e=0;e<a.childCount;e++){let t=a.child(e),n=o+u,d=n+t.nodeSize;if(t.marks.some(e=>e.type===r&&e.attrs.href===i.attrs.href))l||=(s=n,!0),c=d;else if(l)break;u+=t.nodeSize}return l?{from:s,to:c,href:i.attrs.href}:null}var jw=N.create({name:`linkToolbar`,addProseMirrorPlugins(){let e=this.editor,t=null,n=null,r=null,i=0,a=0,o=!1,s=!1,c=null;function l(){t=document.createElement(`div`),t.className=`tiptap-link-input`,t.dataset.editorFloatingUi=`true`,t.style.display=`none`;let i=document.createElement(`div`);i.className=`tiptap-link-input-fields`,r=document.createElement(`input`),r.type=`text`,r.className=`tiptap-link-input-text`,r.placeholder=`Link text`,n=document.createElement(`input`),n.type=`url`,n.className=`tiptap-link-input-field`,n.placeholder=`https:// (empty to unlink)`,i.appendChild(r),i.appendChild(n);let a=document.createElement(`button`);a.type=`button`,a.className=`tiptap-link-input-confirm`,a.innerHTML=kw,a.title=`Apply link`,t.appendChild(i),t.appendChild(a);let o=t=>{t.key===`Enter`?(t.preventDefault(),t.stopPropagation(),m()):t.key===`Escape`&&(t.preventDefault(),t.stopPropagation(),s=!0,f(),e.commands.focus())};r.addEventListener(`keydown`,o),n.addEventListener(`keydown`,o);let c=()=>{Dw=!0},l=()=>{requestAnimationFrame(()=>{let e=document.activeElement;(!t||!t.contains(e))&&(Dw=!1)})};r.addEventListener(`focus`,c),n.addEventListener(`focus`,c),r.addEventListener(`blur`,l),n.addEventListener(`blur`,l),a.addEventListener(`mousedown`,e=>{e.preventDefault(),m()}),t.addEventListener(`mousedown`,e=>{e.stopPropagation()})}function u(e,t,n,r){e.style.display=`flex`;let i=t.dom.closest(`dialog`),a=t.coordsAtPos(n),o=t.coordsAtPos(r),s=e.getBoundingClientRect(),c=GS({anchorRect:{left:a.left,right:o.right,top:Math.min(a.top,o.top),bottom:Math.max(a.bottom,o.bottom)},containerRect:WS(i),floatingWidth:s.width,floatingHeight:s.height,preferredPlacement:`top`,fallbackPlacement:`bottom`,align:`center`});e.style.left=`${c.left}px`,e.style.top=`${c.top}px`}function d(e,o){if(!(!t||!n||!r)){if(o.from!==void 0&&o.to!==void 0?(i=o.from,a=o.to):(i=e.state.selection.from,a=e.state.selection.to),Ew=`input`,n.value=o.href,r.value=o.text??e.state.doc.textBetween(i,a,``),u(t,e,i,a),o.focus){let e=r.value.length>0?n:r;requestAnimationFrame(()=>{e.focus(),e.select()})}p(),c=e=>{t&&!t.contains(e.target)&&(s=!0,f())},setTimeout(()=>{c&&document.addEventListener(`mousedown`,c,!0)},0)}}function f(){t&&(t.style.display=`none`),Ew=`hidden`,Dw=!1,p()}function p(){c&&=(document.removeEventListener(`mousedown`,c,!0),null)}function m(){if(!n||!r)return;let t=n.value.trim(),s=e.state.doc.textBetween(i,a,``),c=r.value,l=c.length>0?c:t;if(f(),!t){e.chain().focus().setTextSelection({from:i,to:a}).unsetLink().setTextSelection(a).run(),o=!0;return}let u=l!==s,d=i+l.length;u?e.chain().focus().command(({tr:e})=>(e.insertText(l,i,a),!0)).setTextSelection({from:i,to:d}).setLink({href:t}).setTextSelection(d).run():e.chain().focus().setTextSelection({from:i,to:a}).setLink({href:t}).setTextSelection(a).run(),o=!0}function h(e,t){if(t.button!==0)return;let n=t.target?.closest(`a`);if(!n||!e.dom.contains(n))return;let r=e.state.schema.marks.link;if(!r||!e.state.selection.empty)return;let i=e.state.selection.from,a=t=>e.state.doc.resolve(t).marks().some(e=>e.type===r),o=i;if(!a(i)){try{o=e.posAtDOM(n,0)+1}catch{return}if(o<0||o>e.state.doc.content.size||!a(o))return}s=!1,e.dispatch(e.state.tr.setSelection(k.create(e.state.doc,o)))}return[new j({key:Tw,props:{handleDOMEvents:{click:(e,t)=>(h(e,t),!1)}},view(e){l();let n=e.dom.closest(`dialog`);t&&(n??document.body).appendChild(t);let r=()=>{s=!1,o=!0,d(e,{href:``,focus:!0})};e.dom.addEventListener(`tiptap:open-link-input`,r);let c=e=>{e.key===`Escape`&&Ew===`input`&&(e.preventDefault(),e.stopPropagation(),s=!0,f())};return e.dom.addEventListener(`keydown`,c),{update(e){if(o){o=!1;return}let n=Aw(e.state);if(Ew===`input`&&Dw){t&&u(t,e,i,a);return}if(n){if(s)return;d(e,{href:n.href,from:n.from,to:n.to,focus:!1})}else s=!1,Ew===`input`&&f()},destroy(){e.dom.removeEventListener(`tiptap:open-link-input`,r),e.dom.removeEventListener(`keydown`,c),p(),t?.remove(),t=null,Ew=`hidden`,Dw=!1}}}})]}}),Mw=new Pr(`bubbleMenu`),Nw={bold:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M6 12h9a4 4 0 0 1 0 8H6V4h8a4 4 0 0 1 0 8"/></svg>`,italic:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="4" x2="10" y2="4"/><line x1="14" y1="20" x2="5" y2="20"/><line x1="15" y1="4" x2="9" y2="20"/></svg>`,h1:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="M17 12l3-2v10"/></svg>`,h2:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12h8"/><path d="M4 18V6"/><path d="M12 18V6"/><path d="M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1"/></svg>`,blockquote:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 21c3 0 7-1 7-8V5c0-1.25-.756-2.017-2-2H4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2 1 0 1 0 1 1v1c0 1-1 2-2 2s-1 .008-1 1.031V20c0 1 0 1 1 1z"/><path d="M15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2h.75c0 2.25.25 4-2.75 4v3c0 1 0 1 1 1z"/></svg>`,link:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>`,clear:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m16 22-1-4"/><path d="M19 14a1 1 0 0 0 1-1v-1a2 2 0 0 0-2-2h-3a1 1 0 0 1-1-1V4a2 2 0 0 0-4 0v5a1 1 0 0 1-1 1H6a2 2 0 0 0-2 2v1a1 1 0 0 0 1 1"/><path d="M19 14H5l-1.973 6.767A1 1 0 0 0 4 22h16a1 1 0 0 0 .973-1.233z"/><path d="m8 22 1-4"/></svg>`};function Pw(e,t){let{to:n,empty:r}=e.state.selection;if(r){e.chain().focus().toggleMark(t).run();return}let i=e.schema.marks[t];e.chain().focus().toggleMark(t).setTextSelection(n).command(({tr:e})=>(i&&e.removeStoredMark(i),!0)).run()}function Fw(e,t){return t===`compose`?[{key:`bold`,icon:Nw.bold,title:`Bold`,action:()=>Pw(e,`bold`),isActive:()=>e.isActive(`bold`)},{key:`italic`,icon:Nw.italic,title:`Italic`,action:()=>Pw(e,`italic`),isActive:()=>e.isActive(`italic`)},{key:`sep`,icon:``,title:``,action:()=>{},isActive:()=>!1},{key:`link`,icon:Nw.link,title:`Link`,action:t=>{e.isActive(`link`)?e.chain().focus().unsetLink().run():t.dom.dispatchEvent(new CustomEvent(`tiptap:open-link-input`))},isActive:()=>e.isActive(`link`)},{key:`clear`,icon:Nw.clear,title:`Clear formatting`,action:()=>{let{to:t}=e.state.selection;e.chain().focus().unsetAllMarks().clearNodes().setTextSelection(t).run()},isActive:()=>!1}]:[{key:`bold`,icon:Nw.bold,title:`Bold`,action:()=>Pw(e,`bold`),isActive:()=>e.isActive(`bold`)},{key:`italic`,icon:Nw.italic,title:`Italic`,action:()=>Pw(e,`italic`),isActive:()=>e.isActive(`italic`)},{key:`h1`,icon:Nw.h1,title:`Heading 1`,action:()=>e.chain().focus().toggleHeading({level:1}).run(),isActive:()=>e.isActive(`heading`,{level:1})},{key:`h2`,icon:Nw.h2,title:`Heading 2`,action:()=>e.chain().focus().toggleHeading({level:2}).run(),isActive:()=>e.isActive(`heading`,{level:2})},{key:`sep`,icon:``,title:``,action:()=>{},isActive:()=>!1},{key:`blockquote`,icon:Nw.blockquote,title:`Quote`,action:()=>e.chain().focus().toggleBlockquote().run(),isActive:()=>e.isActive(`blockquote`)},{key:`link`,icon:Nw.link,title:`Link`,action:t=>{e.isActive(`link`)?e.chain().focus().unsetLink().run():t.dom.dispatchEvent(new CustomEvent(`tiptap:open-link-input`))},isActive:()=>e.isActive(`link`)}]}var Iw=N.create({name:`bubbleMenu`,addOptions(){return{toolbarMode:`default`}},addProseMirrorPlugins(){let e=this.editor,t=this.options.toolbarMode,n=null,r=[],i=new Map;function a(){n=document.createElement(`div`),n.className=`tiptap-bubble-menu`,n.dataset.editorFloatingUi=`true`,n.style.position=`fixed`,n.style.display=`none`,r=Fw(e,t);for(let t of r){if(t.key===`sep`){let e=document.createElement(`span`);e.className=`tiptap-bubble-sep`,n.appendChild(e);continue}let r=document.createElement(`button`);r.type=`button`,r.innerHTML=t.icon,r.title=t.title,r.className=`tiptap-bubble-btn`,r.addEventListener(`mousedown`,n=>{n.preventDefault(),t.action(e.view)}),n.appendChild(r),i.set(t.key,r)}}function o(e){if(!n)return;n.style.display=`flex`;let{from:t,to:r}=e.state.selection,i=e.coordsAtPos(t),a=e.coordsAtPos(r),o=e.dom.closest(`dialog`),s=n.getBoundingClientRect(),l=GS({anchorRect:{left:i.left,right:a.right,top:Math.min(i.top,a.top),bottom:Math.max(i.bottom,a.bottom)},containerRect:WS(o),floatingWidth:s.width,floatingHeight:s.height,preferredPlacement:`top`,fallbackPlacement:`bottom`,align:`center`});n.style.left=`${l.left}px`,n.style.top=`${l.top}px`,c()}function s(){n&&(n.style.display=`none`)}function c(){for(let t of r){if(t.key===`sep`)continue;let n=i.get(t.key);n&&n.classList.toggle(`is-active`,t.isActive(e.view))}}function l(e){let{state:t}=e,{selection:n}=t,{empty:r}=n;return!(r||!n.$from.parent.isTextblock||Ow())}return[new j({key:Mw,view(e){a();let t=e.dom.closest(`dialog`)??document.body;n&&t.appendChild(n);function r(t){let r=t.target;if(!r||e.dom.contains(r)||r.closest(`[data-editor-floating-ui]`)||n?.contains(r))return;let{state:i}=e,a=i.selection.from;e.dispatch(i.tr.setSelection(O.near(i.doc.resolve(a)))),e.dom.blur()}return t.addEventListener(`mousedown`,r),{update(e){l(e)?o(e):s()},destroy(){t.removeEventListener(`mousedown`,r),n?.remove(),n=null}}}})]}}),Lw=new Set([`bold`,`italic`,`strike`,`code`,`underline`]);function Rw(e){return e.filter(e=>Lw.has(e.type.name))}var zw=N.create({name:`exitableMarks`,addKeyboardShortcuts(){return{ArrowRight:({editor:e})=>{let{selection:t}=e.state,{$from:n}=t;if(!t.empty||n.pos!==n.end())return!1;let r=Rw(n.marks());if(!r.length)return!1;let{tr:i}=e.state;for(let e of r)i.removeStoredMark(e);return e.view.dispatch(i),!0},Enter:({editor:e})=>{let{selection:t}=e.state,{$from:n}=t;return!t.empty||n.parent.textContent.length>0||!Rw(e.state.storedMarks??n.marks()).length||requestAnimationFrame(()=>{let{tr:t}=e.state;t.setStoredMarks([]),e.view.dispatch(t)}),!1}}}}),Bw=` `,Vw=N.create({name:`tabIndent`,addKeyboardShortcuts(){return{Tab:({editor:e})=>{if(e.isActive(`listItem`))return e.commands.sinkListItem(`listItem`);if(e.isActive(`codeBlock`)){let{state:t,dispatch:n}=e.view,{selection:r}=t,{from:i,to:a}=r,o=t.doc.resolve(i),s=o.parent;if(s.type.name!==`codeBlock`)return!1;let c=o.start(),l=s.textContent;if(i===a)return n(t.tr.insertText(Bw,i)),!0;let u=i-c,d=a-c,f=[],p=l.lastIndexOf(`
301
301
  `,u-1)+1;f.push(p);let m=p;for(;;){let e=l.indexOf(`
302
302
  `,m);if(e===-1||e>=d)break;f.push(e+1),m=e+1}let h=t.tr,g=0;for(let e of f)h=h.insertText(Bw,c+e+g),g+=2;let _=i+2,v=a+g;return h.setSelection(k.create(h.doc,_,v)),n(h),!0}return!1},"Shift-Tab":({editor:e})=>{if(e.isActive(`listItem`))return e.commands.liftListItem(`listItem`);if(e.isActive(`codeBlock`)){let{state:t,dispatch:n}=e.view,{selection:r}=t,{from:i,to:a}=r,o=t.doc.resolve(i),s=o.parent;if(s.type.name!==`codeBlock`)return!1;let c=o.start(),l=s.textContent;if(i===a){let e=i-c,r=l.lastIndexOf(`
303
303
  `,e-1)+1,a=l.slice(r),o=a.startsWith(Bw)?2:a.startsWith(` `)?1:0;return o===0||n(t.tr.delete(c+r,c+r+o)),!0}let u=i-c,d=a-c,f=[],p=l.lastIndexOf(`
304
304
  `,u-1)+1;f.push(p);let m=p;for(;;){let e=l.indexOf(`
305
- `,m);if(e===-1||e>=d)break;f.push(e+1),m=e+1}let h=t.tr,g=0,_=0;for(let e=0;e<f.length;e++){let t=f[e],n=l.slice(t),r=n.startsWith(Bw)?2:n.startsWith(` `)?1:0;if(r>0){let n=c+t+g;h=h.delete(n,n+r),g-=r,e===0&&(_=r)}}if(g<0){let e=Math.max(i-_,c),t=a+g;h.setSelection(k.create(h.doc,e,Math.max(t,e)))}return n(h),!0}return!1}}}}),Hw=/\[([^\]]+)\]\(((?:[^()\s]|\([^()\s]*\))+)\)/,Uw=RegExp(Hw.source+`$`),Ww=RegExp(Hw.source+`\\s$`),Gw=/((?:https?:\/\/|mailto:)[^\s<]+)\s$/,Kw=N.create({name:`linkInputRules`,addInputRules(){let e=this.editor.schema.marks.link;if(!e)return[];function n(n,r,i,a){let o=i[1]?.trim(),s=t(i[2]??``);if(!o||!s)return null;let c=a?o+a:o;n.tr.insertText(c,r.from,r.to),n.tr.addMark(r.from,r.from+o.length,e.create({href:s})),n.tr.removeStoredMark(e)}return[new qd({find:Gw,handler:({state:n,range:r,match:i})=>{let a=t(i[1]??``);if(!a)return null;let o=r.from+a.length;if(n.doc.rangeHasMark(r.from,o,e))return null;n.tr.addMark(r.from,o,e.create({href:a})),n.tr.removeStoredMark(e)}}),new qd({find:Uw,handler:({state:e,range:t,match:r})=>{n(e,t,r,``)}}),new qd({find:Ww,handler:({state:e,range:t,match:r})=>{n(e,t,r,` `)}})]}});function qw(e){return new qd({find:e.find,handler:({state:t,range:n,match:r})=>{let i=M(e.getAttributes,void 0,r)||{},a=t.tr.delete(n.from,n.to),o=a.doc.resolve(n.from).blockRange(),s=o&&On(o,e.type,i);if(!s)return null;a.wrap(o,s)}})}var Jw=N.create({name:`wrappingInputRules`,priority:1e3,addInputRules(){let{schema:e}=this.editor,t=[],n=e.nodes.blockquote;n&&t.push(qw({find:/^\s*>\s$/,type:n}));let r=e.nodes.bulletList;r&&t.push(qw({find:/^\s*([-+*])\s$/,type:r}));let i=e.nodes.orderedList;return i&&t.push(qw({find:/^(\d+)\.\s$/,type:i,getAttributes:e=>({start:Number(e[1])})})),t}});function Yw(e,t){let{state:n}=e,r=n.schema.nodes.paragraph;if(!r)return!1;let{selection:i}=n,{$from:a,$to:o}=i,s;s=a.depth===0?t===`above`?i.from:i.to:t===`above`?a.before(1):o.after(1);let c=n.tr.insert(s,r.create());return c.setSelection(k.create(c.doc,s+1)),e.view.dispatch(c.scrollIntoView()),!0}var Xw=N.create({name:`insertParagraphAround`,addKeyboardShortcuts(){let e=({editor:e})=>{let{state:t}=e,{selection:n}=t;if(!n.empty)return!1;let{$from:r}=n;if(r.depth<1||r.pos!==r.depth)return!1;let i=t.doc.firstChild;return!i||i.type.name===`paragraph`?!1:Yw(e,`above`)};return{ArrowUp:e,ArrowLeft:e,"Mod-Shift-Enter":({editor:e})=>Yw(e,`above`),"Mod-Alt-Enter":({editor:e})=>Yw(e,`below`)}}}),Zw=/\[\^([^\]\n]+)\]([ \t.,!?;)]$)/,Qw=/^\[\^([^\]\n]+)\]: $/,$w=/\[\^([^\]\n]+)\]$/;function eT(e){let t=new Set;return e.descendants(e=>{if(e.type.name!==`footnoteReference`&&e.type.name!==`footnoteDefinition`)return!0;let n=ax(e.attrs.label);return n&&t.add(ox(n)),!0}),t}function tT(e){let t=eT(e),n=1;for(;t.has(String(n));)n+=1;return String(n)}function nT(e){let t=e.content.size;return e.forEach((e,n)=>{e.type.name===`footnoteDefinition`&&(t=n+e.nodeSize)}),t}function rT(e,t){let n=ox(t),r=null;return e.forEach((e,t)=>{r===null&&e.type.name===`footnoteDefinition`&&ox(e.attrs.label)===n&&(r=t)}),r}function iT(e,t){let n=ox(t),r=null;return e.forEach((e,t)=>{r===null&&e.type.name===`footnoteDefinition`&&ox(e.attrs.label)===n&&(r={from:t,to:t+e.nodeSize})}),r}function aT(e,t){let n=ox(t),r=[];return e.descendants((e,t)=>(e.type.name===`footnoteReference`&&ox(e.attrs.label)===n&&r.push({from:t,to:t+e.nodeSize}),!0)),r}function oT(e,t){let n=e.schema.nodes.footnoteReference;return n?n.create({label:t}):null}function sT(e,t){let n=e.schema.nodes.footnoteDefinition,r=e.schema.nodes.paragraph;return!n||!r?null:n.create({label:t},[r.create()])}function cT(e,t){let n=Math.min(t+2,e.doc.content.size);e.setSelection(k.near(e.doc.resolve(n),1))}function lT(e,t){let n=null,r=null;e.doc.forEach((e,i)=>{i===t&&e.type.name===`paragraph`&&e.content.size===0&&(n=i,r=i+e.nodeSize)}),n!==null&&r!==null&&e.delete(n,r)}function uT(e,t,n){let r=rT(t.doc,n);if(r!==null)return r;let i=sT(e,n);if(!i)return null;let a=nT(t.doc);return t.insert(a,i),lT(t,a+i.nodeSize),a}function dT(e,t){if(t.doc.childCount>0)return;let n=e.schema.nodes.paragraph;n&&t.insert(0,n.create())}function fT(e,t){if(!t||e.doc.childCount<2)return;let n=e.doc.lastChild,r=e.doc.child(e.doc.childCount-2);n?.type.name===`paragraph`&&n.content.size===0&&r.type.name!==`footnoteDefinition`&&e.delete(e.doc.content.size-n.nodeSize,e.doc.content.size)}function pT(e,t){let n=Math.min(Math.max(t,0),e.doc.content.size);e.setSelection(k.near(e.doc.resolve(n),-1))}function mT(e,t){let n=[...t].sort((e,t)=>t.from-e.from);for(let t of n)e.delete(t.from,t.to)}function hT(e,t){let n=iT(e.doc,t),r=[...aT(e.doc,t),...n?[n]:[]];if(r.length===0)return null;let i=e.tr;return mT(i,r),dT(e,i),fT(i,n),pT(i,r[0]?.from??0),i.scrollIntoView(),i}function gT(e,t){let n=e.doc.nodeAt(t.from);if(!n||n.type.name!==`footnoteReference`)return null;let r=ax(n.attrs.label);if(!r)return null;let i=aT(e.doc,r),a=iT(e.doc,r),o=i.length<=1?[t,...a?[a]:[]]:[t],s=e.tr;return mT(s,o),dT(e,s),fT(s,i.length<=1?a:null),pT(s,t.from),s.scrollIntoView(),s}function _T(e,t){let{selection:n}=e;if(n instanceof A)return n.node.type.name===`footnoteReference`?{from:n.from,to:n.to}:null;if(!n.empty)return null;let{$from:r}=n,i=t===`backward`?r.nodeBefore:r.nodeAfter;if(!i||i.type.name!==`footnoteReference`)return null;let a=t===`backward`?n.from-i.nodeSize:n.from;return{from:a,to:a+i.nodeSize}}function vT(e){let{selection:t}=e;if(t instanceof A)return t.node.type.name===`footnoteDefinition`?ax(t.node.attrs.label):null;if(!t.empty)return null;let{$from:n}=t,r=-1;for(let e=n.depth;e>0;--e)if(n.node(e).type.name===`footnoteDefinition`){r=e;break}return r===-1||!(n.parent.type.name===`paragraph`&&n.parentOffset===0&&n.index(r)===0)?null:ax(n.node(r).attrs.label)}function yT(e,t,n,r,i){let a=oT(e,t);if(!a)return!1;let o=[a];n&&o.push(e.schema.text(n));let s=e.tr;return s.replaceWith(r,i,E.fromArray(o)),uT(e,s,t)!==null}function bT(e,t){let n=sT(e,t);if(!n)return!1;let{$from:r}=e.selection;if(r.depth!==1||r.parent.type.name!==`paragraph`)return!1;let i=e.tr.replaceWith(r.before(),r.after(),n);return lT(i,r.before()+n.nodeSize),cT(i,r.before()),i.scrollIntoView(),!0}function xT(e,t){let n=sT(e,t);if(!n)return!1;let{$from:r}=e.selection;if(r.parent.type.name!==`paragraph`||r.depth<2||r.node(r.depth-1).type.name!==`footnoteDefinition`)return!1;let i=r.depth,a=r.before(i),o=r.after(i),s=i-1,c=r.node(s),l=r.after(s),u=e.tr;c.childCount===1?u.delete(a+1,o-1):u.delete(a,o);let d=u.mapping.map(l);return u.insert(d,n),lT(u,d+n.nodeSize),cT(u,d),u.scrollIntoView(),!0}function ST(e){let{$from:t}=e.selection;for(let e=t.depth;e>0;--e)if(t.node(e).type.name===`footnoteDefinition`)return!0;return!1}function CT(e){let{selection:t}=e,{$from:n}=t;if(!t.empty||ST(e)||!n.parent.inlineContent||n.parent.type.name!==`paragraph`||n.parentOffset!==n.parent.content.size)return null;let r=n.parent.textBetween(0,n.parentOffset,void 0,``).match($w),i=ax(r?.[1]);return!r||!i?null:{label:i,from:t.from-r[0].length,to:t.from}}function wT(e){let t=CT(e);if(t){let n=oT(e,t.label);if(!n)return null;let r=e.tr.replaceWith(t.from,t.to,n),i=uT(e,r,t.label);return i===null?null:(cT(r,i),r.scrollIntoView(),r)}return null}function TT(){return[new qd({find:Qw,handler:({state:e,match:t})=>{let n=ax(t[1]);if(!n)return null;let{$from:r}=e.selection;return r.depth!==1||r.parent.type.name!==`paragraph`?xT(e,n)?void 0:null:bT(e,n)?void 0:null}}),new qd({find:Zw,handler:({state:e,range:t,match:n})=>{let r=ax(n[1]),i=n[2]??``;return!r||!i||!e.selection.$from.parent.inlineContent?null:yT(e,r,i,t.from,t.to)?void 0:null}})]}var ET=N.create({name:`footnotes`,addCommands(){return{insertFootnote:()=>({state:e,dispatch:t})=>{if(!e.selection.$from.parent.inlineContent)return!1;let n=tT(e.doc),r=oT(e,n),i=sT(e,n);if(!r||!i)return!1;let a=nT(e.doc),o=e.tr.replaceSelectionWith(r,!1),s=o.mapping.map(a);return o.insert(s,i),lT(o,s+i.nodeSize),cT(o,s),t&&t(o.scrollIntoView()),!0}}},addInputRules(){return TT()},addKeyboardShortcuts(){return{Enter:({editor:e})=>{let t=wT(e.state);return t?(e.view.dispatch(t),!0):!1},Backspace:({editor:e})=>{let t=vT(e.state);if(t){let n=hT(e.state,t);return n?(e.view.dispatch(n),!0):!1}let n=_T(e.state,`backward`);if(!n)return!1;let r=gT(e.state,n);return r?(e.view.dispatch(r),!0):!1},Delete:({editor:e})=>{let t=_T(e.state,`forward`);if(!t)return!1;let n=gT(e.state,t);return n?(e.view.dispatch(n),!0):!1}}}});function DT(e,t,n=`paragraph`){let{$to:r}=e.selection,i=r.end();if(r.nodeAfter)r.nodeAfter.isTextblock?e.setSelection(k.create(e.doc,r.pos+1)):r.nodeAfter.isBlock?e.setSelection(A.create(e.doc,r.pos)):e.setSelection(k.create(e.doc,r.pos));else{let a=(t.nodes[n]??r.parent.type.contentMatch.defaultType)?.create();a&&(e.insert(i,a),e.setSelection(k.create(e.doc,i+1)))}e.scrollIntoView()}var OT={regular:`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><rect x="3" y="3" width="10" height="10" rx="1.5"/></svg>`,wide:`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><rect x="1.5" y="4" width="13" height="8" rx="1.5"/></svg>`,full:`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><rect x="0.75" y="3" width="14.5" height="10" rx="1"/><path d="M4 8h8M4 6l-1.5 2L4 10M12 6l1.5 2L12 10"/></svg>`,link:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>`,replace:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"/><path d="M16 16h5v5"/></svg>`,expand:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 3h6v6"/><path d="M9 21H3v-6"/><path d="M21 3l-7 7"/><path d="M3 21l7-7"/></svg>`},kT=class{dom;img;figcaption;captionInput;altBtn;toolbar;captionBar;layoutBtns=new Map;node;view;getPos;editor;editingAlt=!1;constructor(e,t,n,r){this.node=e,this.view=t,this.getPos=n,this.editor=r;let i=document.createElement(`figure`);i.className=`tiptap-image-figure`,i.dataset.selected=`false`,i.dataset.layout=String(e.attrs.layout||`regular`),this.dom=i;let a=document.createElement(`div`);a.className=`tiptap-image-container`,i.appendChild(a);let o=document.createElement(`img`);o.src=String(e.attrs.src??``),o.alt=String(e.attrs.alt??``),e.attrs.title&&(o.title=String(e.attrs.title)),o.draggable=!1,a.appendChild(o),this.img=o;let s=document.createElement(`div`);s.className=`tiptap-image-toolbar`,a.appendChild(s),this.toolbar=s;let c=[[`regular`,OT.regular,`Content width`],[`wide`,OT.wide,`Wide — max 1200px`],[`full`,OT.full,`Full width — edge to edge`]];for(let[t,n,r]of c){this.layoutBtns.size>0&&s.appendChild(this.sep());let i=document.createElement(`button`);i.type=`button`,i.innerHTML=n,i.title=r,i.dataset.layout=t,t===(e.attrs.layout||`regular`)&&(i.className=`is-active`),i.addEventListener(`mousedown`,e=>{e.preventDefault(),this.updateAttrs({layout:t})}),s.appendChild(i),this.layoutBtns.set(t,i)}s.appendChild(this.sep());let l=this.iconBtn(OT.link,`Add link`);l.addEventListener(`mousedown`,e=>{e.preventDefault(),this.handleLink()}),s.appendChild(l),s.appendChild(this.sep());let u=this.iconBtn(OT.replace,`Replace image`);u.addEventListener(`mousedown`,e=>{e.preventDefault(),this.handleReplace()}),s.appendChild(u),s.appendChild(this.sep());let d=this.iconBtn(OT.expand,`Preview fullscreen`);d.addEventListener(`mousedown`,e=>{e.preventDefault(),this.handleExpand()}),s.appendChild(d);let f=document.createElement(`div`);f.className=`tiptap-image-caption-bar`,i.appendChild(f),this.captionBar=f;let p=document.createElement(`input`);p.type=`text`,p.placeholder=`Add a caption…`,p.value=String(e.attrs.caption??``),p.addEventListener(`input`,()=>{this.editingAlt?this.updateAttrs({alt:p.value}):this.updateAttrs({caption:p.value})}),p.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),this.view.focus())}),f.appendChild(p),this.captionInput=p;let m=document.createElement(`button`);m.type=`button`,m.className=`tiptap-image-alt-btn`,m.textContent=`Alt`,m.addEventListener(`mousedown`,e=>{e.preventDefault(),this.toggleAltMode()}),f.appendChild(m),this.altBtn=m;let h=document.createElement(`figcaption`);h.className=`tiptap-image-figcaption`,h.textContent=String(e.attrs.caption??``),i.appendChild(h),this.figcaption=h}update(e){if(e.type!==this.node.type)return!1;this.node=e,this.img.src=String(e.attrs.src??``),this.img.alt=String(e.attrs.alt??``),this.img.title=String(e.attrs.title??``),this.dom.dataset.layout=String(e.attrs.layout||`regular`),this.layoutBtns.forEach((t,n)=>{t.classList.toggle(`is-active`,n===(e.attrs.layout||`regular`))});let t=String(e.attrs.caption??``);return this.figcaption.textContent=t,document.activeElement!==this.captionInput&&(this.editingAlt?this.captionInput.value=String(e.attrs.alt??``):this.captionInput.value=t),!0}selectNode(){this.dom.dataset.selected=`true`}deselectNode(){this.dom.dataset.selected=`false`,this.editingAlt=!1,this.altBtn.classList.remove(`is-active`),this.captionInput.placeholder=`Add a caption…`,this.captionInput.value=String(this.node.attrs.caption??``)}stopEvent(e){let t=e.target;return!!(t.closest(`.tiptap-image-toolbar`)||t.closest(`.tiptap-image-caption-bar`))}ignoreMutation(){return!0}destroy(){}sep(){let e=document.createElement(`span`);return e.className=`tiptap-toolbar-sep`,e}iconBtn(e,t){let n=document.createElement(`button`);return n.type=`button`,n.innerHTML=e,n.title=t,n}updateAttrs(e){let t=this.getPos();if(t===void 0)return;let n=this.view.state.tr.setNodeMarkup(t,void 0,{...this.node.attrs,...e});this.view.dispatch(n)}handleLink(){if(String(this.node.attrs.href??``))this.updateAttrs({href:``});else{let e=globalThis.prompt(`Enter URL`);e&&this.updateAttrs({href:e})}}handleReplace(){let e=document.createElement(`input`);e.type=`file`,e.accept=`image/*`,e.addEventListener(`change`,async()=>{let t=e.files?.[0];if(t)try{let e=await dw(t);this.updateAttrs({src:e.url})}catch{}}),e.click()}handleExpand(){let e=document.querySelector(`jant-media-lightbox`);e&&e.open([{url:String(this.node.attrs.src??``),alt:String(this.node.attrs.alt??``)}],0)}toggleAltMode(){this.editingAlt=!this.editingAlt,this.altBtn.classList.toggle(`is-active`,this.editingAlt),this.editingAlt?(this.captionInput.placeholder=`Add alt text…`,this.captionInput.value=String(this.node.attrs.alt??``)):(this.captionInput.placeholder=`Add a caption…`,this.captionInput.value=String(this.node.attrs.caption??``)),this.captionInput.focus()}},AT=Wf.create({name:`image`,group:`block`,atom:!0,selectable:!0,draggable:!0,addAttributes(){return{src:{default:``},alt:{default:``},title:{default:``},caption:{default:``},href:{default:``},layout:{default:`regular`}}},parseHTML(){return[{tag:`figure[data-image]`,getAttrs(e){let t=e,n=t.querySelector(`img`),r=t.querySelector(`figcaption`),i=t.querySelector(`a`);return{src:n?.getAttribute(`src`)??``,alt:n?.getAttribute(`alt`)??``,title:n?.getAttribute(`title`)??``,caption:r?.textContent??``,href:i?.getAttribute(`href`)??``,layout:t.dataset.layout??`regular`}}},{tag:`figure`,getAttrs(e){let t=e,n=t.querySelector(`img`);if(!n)return!1;let r=t.querySelector(`figcaption`),i=t.querySelector(`a`);return{src:n.getAttribute(`src`)??``,alt:n.getAttribute(`alt`)??``,title:n.getAttribute(`title`)??``,caption:r?.textContent??``,href:i?.getAttribute(`href`)??``,layout:t.dataset.layout??`regular`}}},{tag:`img[src]`,getAttrs(e){let t=e;return{src:t.getAttribute(`src`)??``,alt:t.getAttribute(`alt`)??``,title:t.getAttribute(`title`)??``}}}]},renderHTML({node:e}){let t={};e.attrs.layout&&e.attrs.layout!==`regular`&&(t[`data-layout`]=e.attrs.layout),t[`data-image`]=``;let n={src:e.attrs.src};e.attrs.alt&&(n.alt=e.attrs.alt),e.attrs.title&&(n.title=e.attrs.title);let r=[`img`,n],i=[];return e.attrs.href?i.push([`a`,{href:e.attrs.href},r]):i.push(r),e.attrs.caption&&i.push([`figcaption`,{},e.attrs.caption]),[`figure`,t,...i]},parseMarkdown:(e,t)=>t.createNode(`image`,{src:e.href,title:e.title??``,alt:e.text??``}),renderMarkdown:e=>yx(e.attrs??{}),addCommands(){return{setImage:e=>({chain:t,state:n})=>{if(!Af(n,n.schema.nodes[this.name]))return!1;let{$to:r}=n.selection,i=t();return vd(n.selection)?i.insertContentAt(r.pos,{type:this.name,attrs:e}):i.insertContent({type:this.name,attrs:e}),i.command(({state:e,tr:t,dispatch:n})=>(n&&DT(t,e.schema),!0)).run()}}},addNodeView(){return({node:e,view:t,getPos:n,editor:r})=>new kT(e,t,n,r)}}),jT=`<!--more-->`,MT=Wf.create({name:`moreBreak`,group:`block`,atom:!0,selectable:!0,draggable:!1,parseHTML(){return[{tag:`div[data-more-break]`}]},renderHTML(){return[`div`,{"data-more-break":``,class:`tiptap-more-break`},`Read More ↓`]},renderText(){return jT},parseMarkdown:(e,t)=>t.createNode(`moreBreak`),renderMarkdown:()=>jT,markdownTokenizer:Px(),addCommands(){return{insertMoreBreak:()=>({chain:e,state:t})=>{if(!Af(t,t.schema.nodes[this.name]))return!1;let{$to:n}=t.selection,r=e();return vd(t.selection)?r.insertContentAt(n.pos,{type:this.name}):r.insertContent({type:this.name}),r.command(({state:e,tr:t,dispatch:n})=>(n&&DT(t,e.schema),!0)).run()}}}}),NT=class{dom;node;view;getPos;editor;providerLabel;urlLink;captionInput;constructor(e,t,n,r){this.node=e,this.view=t,this.getPos=n,this.editor=r;let i=document.createElement(`div`);i.className=`tiptap-embed-card`,i.dataset.selected=`false`,this.dom=i;let a=document.createElement(`div`);a.className=`tiptap-embed-card-header`,i.appendChild(a);let o=document.createElement(`span`);o.className=`tiptap-embed-card-provider`,a.appendChild(o),this.providerLabel=o;let s=document.createElement(`span`);s.className=`tiptap-embed-card-actions`,a.appendChild(s);let c=document.createElement(`button`);c.type=`button`,c.textContent=`Edit`,c.className=`tiptap-embed-card-btn`,c.addEventListener(`mousedown`,e=>{e.preventDefault(),this.requestEdit()}),s.appendChild(c);let l=document.createElement(`a`);l.className=`tiptap-embed-card-url`,l.target=`_blank`,l.rel=`noopener noreferrer`,i.appendChild(l),this.urlLink=l;let u=document.createElement(`input`);u.type=`text`,u.placeholder=`Add a caption…`,u.className=`tiptap-embed-card-caption`,u.value=String(e.attrs.caption??``),u.addEventListener(`input`,()=>{this.updateAttrs({caption:u.value})}),u.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),this.view.focus())}),i.appendChild(u),this.captionInput=u,this.refresh()}update(e){return e.type===this.node.type?(this.node=e,document.activeElement!==this.captionInput&&(this.captionInput.value=String(e.attrs.caption??``)),this.refresh(),!0):!1}selectNode(){this.dom.dataset.selected=`true`}deselectNode(){this.dom.dataset.selected=`false`}stopEvent(e){let t=e.target;return!!(t.closest(`.tiptap-embed-card-header`)||t.closest(`.tiptap-embed-card-caption`))}ignoreMutation(){return!0}destroy(){}refresh(){let e=String(this.node.attrs.url??``),t=String(this.node.attrs.providerName??``)||PT(e);this.providerLabel.textContent=t,this.urlLink.href=e,this.urlLink.textContent=e}updateAttrs(e){let t=this.getPos();if(t===void 0)return;let n=this.view.state.tr.setNodeMarkup(t,void 0,{...this.node.attrs,...e});this.view.dispatch(n)}requestEdit(){iC({initialUrl:String(this.node.attrs.url??``),initialCaption:String(this.node.attrs.caption??``)}).then(e=>{if(!e)return;let t=this.getPos();if(t===void 0)return;if(e.kind===`link`){let n=t,r=t+this.node.nodeSize;this.editor.chain().focus().insertContentAt({from:n,to:r},{type:`paragraph`,content:[{type:`text`,text:e.url,marks:[{type:`link`,attrs:{href:e.url}}]}]}).run();return}if(e.kind!==`embed`)return;let n=nC(e.url),r=n?{url:n.url||e.url,provider:n.provider,providerName:n.providerName,src:n.src,orientation:n.orientation,heightPx:n.heightPx??null,sandbox:n.sandbox,allow:n.allow??``,caption:e.caption??``}:{...this.node.attrs,url:e.url,caption:e.caption??``},i=this.view.state.tr.setNodeMarkup(t,void 0,r);this.view.dispatch(i)})}};function PT(e){if(!e)return`Embed`;try{return new URL(e.startsWith(`http`)?e:`https://${e}`).hostname}catch{return`Embed`}}var FT=Wf.create({name:`embed`,group:`block`,atom:!0,selectable:!0,draggable:!0,addAttributes(){return{url:{default:``},provider:{default:``},providerName:{default:``},src:{default:``},orientation:{default:`landscape`},heightPx:{default:null},sandbox:{default:``},allow:{default:``},caption:{default:``}}},parseHTML(){return[{tag:`figure[data-jant-node="embed"]`,getAttrs(e){let t=e;return{url:t.getAttribute(`data-url`)??``,provider:t.getAttribute(`data-provider`)??``,providerName:t.getAttribute(`data-provider-name`)??``,src:t.getAttribute(`data-src`)??``,orientation:t.getAttribute(`data-orientation`)??`landscape`}}}]},renderHTML({node:e}){let t={"data-jant-node":`embed`};return e.attrs.provider&&(t[`data-provider`]=String(e.attrs.provider)),e.attrs.providerName&&(t[`data-provider-name`]=String(e.attrs.providerName)),e.attrs.url&&(t[`data-url`]=String(e.attrs.url)),e.attrs.src&&(t[`data-src`]=String(e.attrs.src)),e.attrs.orientation&&(t[`data-orientation`]=String(e.attrs.orientation)),[`figure`,t]},parseMarkdown:(e,t)=>{let n=typeof e.url==`string`?e.url:``,r=e.attrs&&typeof e.attrs==`object`?e.attrs:{};return t.createNode(`embed`,{url:n,caption:r.caption??``})},renderMarkdown:e=>{let t=e.attrs??{},n=typeof t.url==`string`?t.url.trim():``;if(!n)return``;let r=[n],i=typeof t.caption==`string`?t.caption.trim():``;return i&&r.push(`caption=${i}`),["```jant-embed",...r,"```"].join(`
305
+ `,m);if(e===-1||e>=d)break;f.push(e+1),m=e+1}let h=t.tr,g=0,_=0;for(let e=0;e<f.length;e++){let t=f[e],n=l.slice(t),r=n.startsWith(Bw)?2:n.startsWith(` `)?1:0;if(r>0){let n=c+t+g;h=h.delete(n,n+r),g-=r,e===0&&(_=r)}}if(g<0){let e=Math.max(i-_,c),t=a+g;h.setSelection(k.create(h.doc,e,Math.max(t,e)))}return n(h),!0}return!1}}}}),Hw=/\[([^\]]+)\]\(((?:[^()\s]|\([^()\s]*\))+)\)/,Uw=RegExp(Hw.source+`$`),Ww=RegExp(Hw.source+`\\s$`),Gw=/((?:https?:\/\/|mailto:)[^\s<]+)\s$/,Kw=N.create({name:`linkInputRules`,addInputRules(){let e=this.editor.schema.marks.link;if(!e)return[];function n(n,r,i,a){let o=i[1]?.trim(),s=t(i[2]??``);if(!o||!s)return null;let c=a?o+a:o;n.tr.insertText(c,r.from,r.to),n.tr.addMark(r.from,r.from+o.length,e.create({href:s})),n.tr.removeStoredMark(e)}return[new qd({find:Gw,handler:({state:n,range:r,match:i})=>{let a=t(i[1]??``);if(!a)return null;let o=r.from+a.length;if(n.doc.rangeHasMark(r.from,o,e))return null;n.tr.addMark(r.from,o,e.create({href:a})),n.tr.removeStoredMark(e)}}),new qd({find:Uw,handler:({state:e,range:t,match:r})=>{n(e,t,r,``)}}),new qd({find:Ww,handler:({state:e,range:t,match:r})=>{n(e,t,r,` `)}})]}});function qw(e){return new qd({find:e.find,handler:({state:t,range:n,match:r})=>{let i=Pu(e.getAttributes,void 0,r)||{},a=t.tr.delete(n.from,n.to),o=a.doc.resolve(n.from).blockRange(),s=o&&On(o,e.type,i);if(!s)return null;a.wrap(o,s)}})}var Jw=N.create({name:`wrappingInputRules`,priority:1e3,addInputRules(){let{schema:e}=this.editor,t=[],n=e.nodes.blockquote;n&&t.push(qw({find:/^\s*>\s$/,type:n}));let r=e.nodes.bulletList;r&&t.push(qw({find:/^\s*([-+*])\s$/,type:r}));let i=e.nodes.orderedList;return i&&t.push(qw({find:/^(\d+)\.\s$/,type:i,getAttributes:e=>({start:Number(e[1])})})),t}});function Yw(e,t){let{state:n}=e,r=n.schema.nodes.paragraph;if(!r)return!1;let{selection:i}=n,{$from:a,$to:o}=i,s;s=a.depth===0?t===`above`?i.from:i.to:t===`above`?a.before(1):o.after(1);let c=n.tr.insert(s,r.create());return c.setSelection(k.create(c.doc,s+1)),e.view.dispatch(c.scrollIntoView()),!0}var Xw=N.create({name:`insertParagraphAround`,addKeyboardShortcuts(){let e=({editor:e})=>{let{state:t}=e,{selection:n}=t;if(!n.empty)return!1;let{$from:r}=n;if(r.depth<1||r.pos!==r.depth)return!1;let i=t.doc.firstChild;return!i||i.type.name===`paragraph`?!1:Yw(e,`above`)};return{ArrowUp:e,ArrowLeft:e,"Mod-Shift-Enter":({editor:e})=>Yw(e,`above`),"Mod-Alt-Enter":({editor:e})=>Yw(e,`below`)}}}),Zw=/\[\^([^\]\n]+)\]([ \t.,!?;)]$)/,Qw=/^\[\^([^\]\n]+)\]: $/,$w=/\[\^([^\]\n]+)\]$/;function eT(e){let t=new Set;return e.descendants(e=>{if(e.type.name!==`footnoteReference`&&e.type.name!==`footnoteDefinition`)return!0;let n=ax(e.attrs.label);return n&&t.add(ox(n)),!0}),t}function tT(e){let t=eT(e),n=1;for(;t.has(String(n));)n+=1;return String(n)}function nT(e){let t=e.content.size;return e.forEach((e,n)=>{e.type.name===`footnoteDefinition`&&(t=n+e.nodeSize)}),t}function rT(e,t){let n=ox(t),r=null;return e.forEach((e,t)=>{r===null&&e.type.name===`footnoteDefinition`&&ox(e.attrs.label)===n&&(r=t)}),r}function iT(e,t){let n=ox(t),r=null;return e.forEach((e,t)=>{r===null&&e.type.name===`footnoteDefinition`&&ox(e.attrs.label)===n&&(r={from:t,to:t+e.nodeSize})}),r}function aT(e,t){let n=ox(t),r=[];return e.descendants((e,t)=>(e.type.name===`footnoteReference`&&ox(e.attrs.label)===n&&r.push({from:t,to:t+e.nodeSize}),!0)),r}function oT(e,t){let n=e.schema.nodes.footnoteReference;return n?n.create({label:t}):null}function sT(e,t){let n=e.schema.nodes.footnoteDefinition,r=e.schema.nodes.paragraph;return!n||!r?null:n.create({label:t},[r.create()])}function cT(e,t){let n=Math.min(t+2,e.doc.content.size);e.setSelection(k.near(e.doc.resolve(n),1))}function lT(e,t){let n=null,r=null;e.doc.forEach((e,i)=>{i===t&&e.type.name===`paragraph`&&e.content.size===0&&(n=i,r=i+e.nodeSize)}),n!==null&&r!==null&&e.delete(n,r)}function uT(e,t,n){let r=rT(t.doc,n);if(r!==null)return r;let i=sT(e,n);if(!i)return null;let a=nT(t.doc);return t.insert(a,i),lT(t,a+i.nodeSize),a}function dT(e,t){if(t.doc.childCount>0)return;let n=e.schema.nodes.paragraph;n&&t.insert(0,n.create())}function fT(e,t){if(!t||e.doc.childCount<2)return;let n=e.doc.lastChild,r=e.doc.child(e.doc.childCount-2);n?.type.name===`paragraph`&&n.content.size===0&&r.type.name!==`footnoteDefinition`&&e.delete(e.doc.content.size-n.nodeSize,e.doc.content.size)}function pT(e,t){let n=Math.min(Math.max(t,0),e.doc.content.size);e.setSelection(k.near(e.doc.resolve(n),-1))}function mT(e,t){let n=[...t].sort((e,t)=>t.from-e.from);for(let t of n)e.delete(t.from,t.to)}function hT(e,t){let n=iT(e.doc,t),r=[...aT(e.doc,t),...n?[n]:[]];if(r.length===0)return null;let i=e.tr;return mT(i,r),dT(e,i),fT(i,n),pT(i,r[0]?.from??0),i.scrollIntoView(),i}function gT(e,t){let n=e.doc.nodeAt(t.from);if(!n||n.type.name!==`footnoteReference`)return null;let r=ax(n.attrs.label);if(!r)return null;let i=aT(e.doc,r),a=iT(e.doc,r),o=i.length<=1?[t,...a?[a]:[]]:[t],s=e.tr;return mT(s,o),dT(e,s),fT(s,i.length<=1?a:null),pT(s,t.from),s.scrollIntoView(),s}function _T(e,t){let{selection:n}=e;if(n instanceof A)return n.node.type.name===`footnoteReference`?{from:n.from,to:n.to}:null;if(!n.empty)return null;let{$from:r}=n,i=t===`backward`?r.nodeBefore:r.nodeAfter;if(!i||i.type.name!==`footnoteReference`)return null;let a=t===`backward`?n.from-i.nodeSize:n.from;return{from:a,to:a+i.nodeSize}}function vT(e){let{selection:t}=e;if(t instanceof A)return t.node.type.name===`footnoteDefinition`?ax(t.node.attrs.label):null;if(!t.empty)return null;let{$from:n}=t,r=-1;for(let e=n.depth;e>0;--e)if(n.node(e).type.name===`footnoteDefinition`){r=e;break}return r===-1||!(n.parent.type.name===`paragraph`&&n.parentOffset===0&&n.index(r)===0)?null:ax(n.node(r).attrs.label)}function yT(e,t,n,r,i){let a=oT(e,t);if(!a)return!1;let o=[a];n&&o.push(e.schema.text(n));let s=e.tr;return s.replaceWith(r,i,E.fromArray(o)),uT(e,s,t)!==null}function bT(e,t){let n=sT(e,t);if(!n)return!1;let{$from:r}=e.selection;if(r.depth!==1||r.parent.type.name!==`paragraph`)return!1;let i=e.tr.replaceWith(r.before(),r.after(),n);return lT(i,r.before()+n.nodeSize),cT(i,r.before()),i.scrollIntoView(),!0}function xT(e,t){let n=sT(e,t);if(!n)return!1;let{$from:r}=e.selection;if(r.parent.type.name!==`paragraph`||r.depth<2||r.node(r.depth-1).type.name!==`footnoteDefinition`)return!1;let i=r.depth,a=r.before(i),o=r.after(i),s=i-1,c=r.node(s),l=r.after(s),u=e.tr;c.childCount===1?u.delete(a+1,o-1):u.delete(a,o);let d=u.mapping.map(l);return u.insert(d,n),lT(u,d+n.nodeSize),cT(u,d),u.scrollIntoView(),!0}function ST(e){let{$from:t}=e.selection;for(let e=t.depth;e>0;--e)if(t.node(e).type.name===`footnoteDefinition`)return!0;return!1}function CT(e){let{selection:t}=e,{$from:n}=t;if(!t.empty||ST(e)||!n.parent.inlineContent||n.parent.type.name!==`paragraph`||n.parentOffset!==n.parent.content.size)return null;let r=n.parent.textBetween(0,n.parentOffset,void 0,``).match($w),i=ax(r?.[1]);return!r||!i?null:{label:i,from:t.from-r[0].length,to:t.from}}function wT(e){let t=CT(e);if(t){let n=oT(e,t.label);if(!n)return null;let r=e.tr.replaceWith(t.from,t.to,n),i=uT(e,r,t.label);return i===null?null:(cT(r,i),r.scrollIntoView(),r)}return null}function TT(){return[new qd({find:Qw,handler:({state:e,match:t})=>{let n=ax(t[1]);if(!n)return null;let{$from:r}=e.selection;return r.depth!==1||r.parent.type.name!==`paragraph`?xT(e,n)?void 0:null:bT(e,n)?void 0:null}}),new qd({find:Zw,handler:({state:e,range:t,match:n})=>{let r=ax(n[1]),i=n[2]??``;return!r||!i||!e.selection.$from.parent.inlineContent?null:yT(e,r,i,t.from,t.to)?void 0:null}})]}var ET=N.create({name:`footnotes`,addCommands(){return{insertFootnote:()=>({state:e,dispatch:t})=>{if(!e.selection.$from.parent.inlineContent)return!1;let n=tT(e.doc),r=oT(e,n),i=sT(e,n);if(!r||!i)return!1;let a=nT(e.doc),o=e.tr.replaceSelectionWith(r,!1),s=o.mapping.map(a);return o.insert(s,i),lT(o,s+i.nodeSize),cT(o,s),t&&t(o.scrollIntoView()),!0}}},addInputRules(){return TT()},addKeyboardShortcuts(){return{Enter:({editor:e})=>{let t=wT(e.state);return t?(e.view.dispatch(t),!0):!1},Backspace:({editor:e})=>{let t=vT(e.state);if(t){let n=hT(e.state,t);return n?(e.view.dispatch(n),!0):!1}let n=_T(e.state,`backward`);if(!n)return!1;let r=gT(e.state,n);return r?(e.view.dispatch(r),!0):!1},Delete:({editor:e})=>{let t=_T(e.state,`forward`);if(!t)return!1;let n=gT(e.state,t);return n?(e.view.dispatch(n),!0):!1}}}});function DT(e,t,n=`paragraph`){let{$to:r}=e.selection,i=r.end();if(r.nodeAfter)r.nodeAfter.isTextblock?e.setSelection(k.create(e.doc,r.pos+1)):r.nodeAfter.isBlock?e.setSelection(A.create(e.doc,r.pos)):e.setSelection(k.create(e.doc,r.pos));else{let a=(t.nodes[n]??r.parent.type.contentMatch.defaultType)?.create();a&&(e.insert(i,a),e.setSelection(k.create(e.doc,i+1)))}e.scrollIntoView()}var OT={regular:`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><rect x="3" y="3" width="10" height="10" rx="1.5"/></svg>`,wide:`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><rect x="1.5" y="4" width="13" height="8" rx="1.5"/></svg>`,full:`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><rect x="0.75" y="3" width="14.5" height="10" rx="1"/><path d="M4 8h8M4 6l-1.5 2L4 10M12 6l1.5 2L12 10"/></svg>`,link:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>`,replace:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"/><path d="M16 16h5v5"/></svg>`,expand:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 3h6v6"/><path d="M9 21H3v-6"/><path d="M21 3l-7 7"/><path d="M3 21l7-7"/></svg>`},kT=class{dom;img;figcaption;captionInput;altBtn;toolbar;captionBar;layoutBtns=new Map;node;view;getPos;editor;editingAlt=!1;constructor(e,t,n,r){this.node=e,this.view=t,this.getPos=n,this.editor=r;let i=document.createElement(`figure`);i.className=`tiptap-image-figure`,i.dataset.selected=`false`,i.dataset.layout=String(e.attrs.layout||`regular`),this.dom=i;let a=document.createElement(`div`);a.className=`tiptap-image-container`,i.appendChild(a);let o=document.createElement(`img`);o.src=String(e.attrs.src??``),o.alt=String(e.attrs.alt??``),e.attrs.title&&(o.title=String(e.attrs.title)),o.draggable=!1,a.appendChild(o),this.img=o;let s=document.createElement(`div`);s.className=`tiptap-image-toolbar`,a.appendChild(s),this.toolbar=s;let c=[[`regular`,OT.regular,`Content width`],[`wide`,OT.wide,`Wide — max 1200px`],[`full`,OT.full,`Full width — edge to edge`]];for(let[t,n,r]of c){this.layoutBtns.size>0&&s.appendChild(this.sep());let i=document.createElement(`button`);i.type=`button`,i.innerHTML=n,i.title=r,i.dataset.layout=t,t===(e.attrs.layout||`regular`)&&(i.className=`is-active`),i.addEventListener(`mousedown`,e=>{e.preventDefault(),this.updateAttrs({layout:t})}),s.appendChild(i),this.layoutBtns.set(t,i)}s.appendChild(this.sep());let l=this.iconBtn(OT.link,`Add link`);l.addEventListener(`mousedown`,e=>{e.preventDefault(),this.handleLink()}),s.appendChild(l),s.appendChild(this.sep());let u=this.iconBtn(OT.replace,`Replace image`);u.addEventListener(`mousedown`,e=>{e.preventDefault(),this.handleReplace()}),s.appendChild(u),s.appendChild(this.sep());let d=this.iconBtn(OT.expand,`Preview fullscreen`);d.addEventListener(`mousedown`,e=>{e.preventDefault(),this.handleExpand()}),s.appendChild(d);let f=document.createElement(`div`);f.className=`tiptap-image-caption-bar`,i.appendChild(f),this.captionBar=f;let p=document.createElement(`input`);p.type=`text`,p.placeholder=`Add a caption…`,p.value=String(e.attrs.caption??``),p.addEventListener(`input`,()=>{this.editingAlt?this.updateAttrs({alt:p.value}):this.updateAttrs({caption:p.value})}),p.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),this.view.focus())}),f.appendChild(p),this.captionInput=p;let m=document.createElement(`button`);m.type=`button`,m.className=`tiptap-image-alt-btn`,m.textContent=`Alt`,m.addEventListener(`mousedown`,e=>{e.preventDefault(),this.toggleAltMode()}),f.appendChild(m),this.altBtn=m;let h=document.createElement(`figcaption`);h.className=`tiptap-image-figcaption`,h.textContent=String(e.attrs.caption??``),i.appendChild(h),this.figcaption=h}update(e){if(e.type!==this.node.type)return!1;this.node=e,this.img.src=String(e.attrs.src??``),this.img.alt=String(e.attrs.alt??``),this.img.title=String(e.attrs.title??``),this.dom.dataset.layout=String(e.attrs.layout||`regular`),this.layoutBtns.forEach((t,n)=>{t.classList.toggle(`is-active`,n===(e.attrs.layout||`regular`))});let t=String(e.attrs.caption??``);return this.figcaption.textContent=t,document.activeElement!==this.captionInput&&(this.editingAlt?this.captionInput.value=String(e.attrs.alt??``):this.captionInput.value=t),!0}selectNode(){this.dom.dataset.selected=`true`}deselectNode(){this.dom.dataset.selected=`false`,this.editingAlt=!1,this.altBtn.classList.remove(`is-active`),this.captionInput.placeholder=`Add a caption…`,this.captionInput.value=String(this.node.attrs.caption??``)}stopEvent(e){let t=e.target;return!!(t.closest(`.tiptap-image-toolbar`)||t.closest(`.tiptap-image-caption-bar`))}ignoreMutation(){return!0}destroy(){}sep(){let e=document.createElement(`span`);return e.className=`tiptap-toolbar-sep`,e}iconBtn(e,t){let n=document.createElement(`button`);return n.type=`button`,n.innerHTML=e,n.title=t,n}updateAttrs(e){let t=this.getPos();if(t===void 0)return;let n=this.view.state.tr.setNodeMarkup(t,void 0,{...this.node.attrs,...e});this.view.dispatch(n)}handleLink(){if(String(this.node.attrs.href??``))this.updateAttrs({href:``});else{let e=globalThis.prompt(`Enter URL`);e&&this.updateAttrs({href:e})}}handleReplace(){let e=document.createElement(`input`);e.type=`file`,e.accept=`image/*`,e.addEventListener(`change`,async()=>{let t=e.files?.[0];if(t)try{let e=await dw(t);this.updateAttrs({src:e.url})}catch{}}),e.click()}handleExpand(){let e=document.querySelector(`jant-media-lightbox`);e&&e.open([{url:String(this.node.attrs.src??``),alt:String(this.node.attrs.alt??``)}],0)}toggleAltMode(){this.editingAlt=!this.editingAlt,this.altBtn.classList.toggle(`is-active`,this.editingAlt),this.editingAlt?(this.captionInput.placeholder=`Add alt text…`,this.captionInput.value=String(this.node.attrs.alt??``)):(this.captionInput.placeholder=`Add a caption…`,this.captionInput.value=String(this.node.attrs.caption??``)),this.captionInput.focus()}},AT=Wf.create({name:`image`,group:`block`,atom:!0,selectable:!0,draggable:!0,addAttributes(){return{src:{default:``},alt:{default:``},title:{default:``},caption:{default:``},href:{default:``},layout:{default:`regular`}}},parseHTML(){return[{tag:`figure[data-image]`,getAttrs(e){let t=e,n=t.querySelector(`img`),r=t.querySelector(`figcaption`),i=t.querySelector(`a`);return{src:n?.getAttribute(`src`)??``,alt:n?.getAttribute(`alt`)??``,title:n?.getAttribute(`title`)??``,caption:r?.textContent??``,href:i?.getAttribute(`href`)??``,layout:t.dataset.layout??`regular`}}},{tag:`figure`,getAttrs(e){let t=e,n=t.querySelector(`img`);if(!n)return!1;let r=t.querySelector(`figcaption`),i=t.querySelector(`a`);return{src:n.getAttribute(`src`)??``,alt:n.getAttribute(`alt`)??``,title:n.getAttribute(`title`)??``,caption:r?.textContent??``,href:i?.getAttribute(`href`)??``,layout:t.dataset.layout??`regular`}}},{tag:`img[src]`,getAttrs(e){let t=e;return{src:t.getAttribute(`src`)??``,alt:t.getAttribute(`alt`)??``,title:t.getAttribute(`title`)??``}}}]},renderHTML({node:e}){let t={};e.attrs.layout&&e.attrs.layout!==`regular`&&(t[`data-layout`]=e.attrs.layout),t[`data-image`]=``;let n={src:e.attrs.src};e.attrs.alt&&(n.alt=e.attrs.alt),e.attrs.title&&(n.title=e.attrs.title);let r=[`img`,n],i=[];return e.attrs.href?i.push([`a`,{href:e.attrs.href},r]):i.push(r),e.attrs.caption&&i.push([`figcaption`,{},e.attrs.caption]),[`figure`,t,...i]},parseMarkdown:(e,t)=>t.createNode(`image`,{src:e.href,title:e.title??``,alt:e.text??``}),renderMarkdown:e=>yx(e.attrs??{}),addCommands(){return{setImage:e=>({chain:t,state:n})=>{if(!Af(n,n.schema.nodes[this.name]))return!1;let{$to:r}=n.selection,i=t();return vd(n.selection)?i.insertContentAt(r.pos,{type:this.name,attrs:e}):i.insertContent({type:this.name,attrs:e}),i.command(({state:e,tr:t,dispatch:n})=>(n&&DT(t,e.schema),!0)).run()}}},addNodeView(){return({node:e,view:t,getPos:n,editor:r})=>new kT(e,t,n,r)}}),jT=`<!--more-->`,MT=Wf.create({name:`moreBreak`,group:`block`,atom:!0,selectable:!0,draggable:!1,parseHTML(){return[{tag:`div[data-more-break]`}]},renderHTML(){return[`div`,{"data-more-break":``,class:`tiptap-more-break`},`Read More ↓`]},renderText(){return jT},parseMarkdown:(e,t)=>t.createNode(`moreBreak`),renderMarkdown:()=>jT,markdownTokenizer:Px(),addCommands(){return{insertMoreBreak:()=>({chain:e,state:t})=>{if(!Af(t,t.schema.nodes[this.name]))return!1;let{$to:n}=t.selection,r=e();return vd(t.selection)?r.insertContentAt(n.pos,{type:this.name}):r.insertContent({type:this.name}),r.command(({state:e,tr:t,dispatch:n})=>(n&&DT(t,e.schema),!0)).run()}}}}),NT=class{dom;node;view;getPos;editor;providerLabel;urlLink;captionInput;constructor(e,t,n,r){this.node=e,this.view=t,this.getPos=n,this.editor=r;let i=document.createElement(`div`);i.className=`tiptap-embed-card`,i.dataset.selected=`false`,this.dom=i;let a=document.createElement(`div`);a.className=`tiptap-embed-card-header`,i.appendChild(a);let o=document.createElement(`span`);o.className=`tiptap-embed-card-provider`,a.appendChild(o),this.providerLabel=o;let s=document.createElement(`span`);s.className=`tiptap-embed-card-actions`,a.appendChild(s);let c=document.createElement(`button`);c.type=`button`,c.textContent=`Edit`,c.className=`tiptap-embed-card-btn`,c.addEventListener(`mousedown`,e=>{e.preventDefault(),this.requestEdit()}),s.appendChild(c);let l=document.createElement(`a`);l.className=`tiptap-embed-card-url`,l.target=`_blank`,l.rel=`noopener noreferrer`,i.appendChild(l),this.urlLink=l;let u=document.createElement(`input`);u.type=`text`,u.placeholder=`Add a caption…`,u.className=`tiptap-embed-card-caption`,u.value=String(e.attrs.caption??``),u.addEventListener(`input`,()=>{this.updateAttrs({caption:u.value})}),u.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),this.view.focus())}),i.appendChild(u),this.captionInput=u,this.refresh()}update(e){return e.type===this.node.type?(this.node=e,document.activeElement!==this.captionInput&&(this.captionInput.value=String(e.attrs.caption??``)),this.refresh(),!0):!1}selectNode(){this.dom.dataset.selected=`true`}deselectNode(){this.dom.dataset.selected=`false`}stopEvent(e){let t=e.target;return!!(t.closest(`.tiptap-embed-card-header`)||t.closest(`.tiptap-embed-card-caption`))}ignoreMutation(){return!0}destroy(){}refresh(){let e=String(this.node.attrs.url??``),t=String(this.node.attrs.providerName??``)||PT(e);this.providerLabel.textContent=t,this.urlLink.href=e,this.urlLink.textContent=e}updateAttrs(e){let t=this.getPos();if(t===void 0)return;let n=this.view.state.tr.setNodeMarkup(t,void 0,{...this.node.attrs,...e});this.view.dispatch(n)}requestEdit(){iC({initialUrl:String(this.node.attrs.url??``),initialCaption:String(this.node.attrs.caption??``)}).then(e=>{if(!e)return;let t=this.getPos();if(t===void 0)return;if(e.kind===`link`){let n=t,r=t+this.node.nodeSize;this.editor.chain().focus().insertContentAt({from:n,to:r},{type:`paragraph`,content:[{type:`text`,text:e.url,marks:[{type:`link`,attrs:{href:e.url}}]}]}).run();return}if(e.kind!==`embed`)return;let n=nC(e.url),r=n?{url:n.url||e.url,provider:n.provider,providerName:n.providerName,src:n.src,orientation:n.orientation,heightPx:n.heightPx??null,sandbox:n.sandbox,allow:n.allow??``,caption:e.caption??``}:{...this.node.attrs,url:e.url,caption:e.caption??``},i=this.view.state.tr.setNodeMarkup(t,void 0,r);this.view.dispatch(i)})}};function PT(e){if(!e)return`Embed`;try{return new URL(e.startsWith(`http`)?e:`https://${e}`).hostname}catch{return`Embed`}}var FT=Wf.create({name:`embed`,group:`block`,atom:!0,selectable:!0,draggable:!0,addAttributes(){return{url:{default:``},provider:{default:``},providerName:{default:``},src:{default:``},orientation:{default:`landscape`},heightPx:{default:null},sandbox:{default:``},allow:{default:``},caption:{default:``}}},parseHTML(){return[{tag:`figure[data-jant-node="embed"]`,getAttrs(e){let t=e;return{url:t.getAttribute(`data-url`)??``,provider:t.getAttribute(`data-provider`)??``,providerName:t.getAttribute(`data-provider-name`)??``,src:t.getAttribute(`data-src`)??``,orientation:t.getAttribute(`data-orientation`)??`landscape`}}}]},renderHTML({node:e}){let t={"data-jant-node":`embed`};return e.attrs.provider&&(t[`data-provider`]=String(e.attrs.provider)),e.attrs.providerName&&(t[`data-provider-name`]=String(e.attrs.providerName)),e.attrs.url&&(t[`data-url`]=String(e.attrs.url)),e.attrs.src&&(t[`data-src`]=String(e.attrs.src)),e.attrs.orientation&&(t[`data-orientation`]=String(e.attrs.orientation)),[`figure`,t]},parseMarkdown:(e,t)=>{let n=typeof e.url==`string`?e.url:``,r=e.attrs&&typeof e.attrs==`object`?e.attrs:{};return t.createNode(`embed`,{url:n,caption:r.caption??``})},renderMarkdown:e=>{let t=e.attrs??{},n=typeof t.url==`string`?t.url.trim():``;if(!n)return``;let r=[n],i=typeof t.caption==`string`?t.caption.trim():``;return i&&r.push(`caption=${i}`),["```jant-embed",...r,"```"].join(`
306
306
  `)},markdownTokenizer:Mx(),addCommands(){return{setEmbed:e=>({chain:t,state:n})=>{if(!Af(n,n.schema.nodes[this.name]))return!1;let r=nC(e.url),i=r?{url:r.url||e.url,provider:r.provider,providerName:r.providerName,src:r.src,orientation:r.orientation,heightPx:r.heightPx??null,sandbox:r.sandbox,allow:r.allow??``,caption:e.caption??``}:{url:e.url,caption:e.caption??``},{$to:a}=n.selection,o=t();return vd(n.selection)?o.insertContentAt(a.pos,{type:this.name,attrs:i}):o.insertContent({type:this.name,attrs:i}),o.command(({state:e,tr:t,dispatch:n})=>(n&&DT(t,e.schema),!0)).run()}}},addNodeView(){return({node:e,view:t,getPos:n,editor:r})=>new NT(e,t,n,r)}}),IT=class{dom;node;view;getPos;editor;textarea;constructor(e,t,n,r){this.node=e,this.view=t,this.getPos=n,this.editor=r;let i=document.createElement(`div`);i.className=`tiptap-html-block-card`,i.dataset.selected=`false`,this.dom=i;let a=document.createElement(`div`);a.className=`tiptap-html-block-header`,a.textContent=`Raw HTML`,i.appendChild(a);let o=document.createElement(`textarea`);o.className=`tiptap-html-block-textarea`,o.spellcheck=!1,o.value=String(e.attrs.html??``),o.rows=Math.max(3,o.value.split(`
307
307
  `).length),o.addEventListener(`input`,()=>{this.updateAttrs({html:o.value}),this.autoGrow()}),i.appendChild(o),this.textarea=o;let s=document.createElement(`p`);s.className=`tiptap-html-block-hint`,s.textContent=`Renders on the published page only.`,i.appendChild(s),queueMicrotask(()=>this.autoGrow())}update(e){return e.type===this.node.type?(this.node=e,document.activeElement!==this.textarea&&(this.textarea.value=String(e.attrs.html??``),this.autoGrow()),!0):!1}selectNode(){this.dom.dataset.selected=`true`}deselectNode(){this.dom.dataset.selected=`false`}stopEvent(e){return e.target.closest(`.tiptap-html-block-textarea`)!==null}ignoreMutation(){return!0}destroy(){}autoGrow(){this.textarea.style.height=`auto`,this.textarea.style.height=`${this.textarea.scrollHeight}px`}updateAttrs(e){let t=this.getPos();if(t===void 0)return;let n=this.view.state.tr.setNodeMarkup(t,void 0,{...this.node.attrs,...e});this.view.dispatch(n)}},LT=Wf.create({name:`htmlBlock`,group:`block`,atom:!0,selectable:!0,draggable:!0,addAttributes(){return{html:{default:``}}},parseHTML(){return[{tag:`div[data-jant-node="html-block"]`,getAttrs(e){return{html:e.textContent??``}}}]},renderHTML({node:e}){return[`div`,{"data-jant-node":`html-block`},String(e.attrs.html??``)]},parseMarkdown:(e,t)=>{let n=typeof e.html==`string`?e.html:``;return t.createNode(`htmlBlock`,{html:n})},renderMarkdown:e=>["```jant-html",typeof e.attrs?.html==`string`?e.attrs.html:``,"```"].join(`
308
- `),markdownTokenizer:Nx(),addCommands(){return{setHtmlBlock:e=>({chain:t,state:n})=>{if(!Af(n,n.schema.nodes[this.name]))return!1;let r={html:e.html},{$to:i}=n.selection,a=t();return vd(n.selection)?a.insertContentAt(i.pos,{type:this.name,attrs:r}):a.insertContent({type:this.name,attrs:r}),a.command(({state:e,tr:t,dispatch:n})=>(n&&DT(t,e.schema),!0)).run()}}},addNodeView(){return({node:e,view:t,getPos:n,editor:r})=>new IT(e,t,n,r)}}),RT=/^https?:\/\/\S+$/i,zT=new Fr(`jantEmbedPaste`),BT=N.create({name:`embedPaste`,addProseMirrorPlugins(){let e=this.editor;return[new Mr({key:zT,props:{handlePaste(t,n){let r=n.clipboardData;if(!r)return!1;let i=r.getData(`text/plain`)?.trim()??``;if(!i||!RT.test(i))return!1;let{selection:a}=t.state;if(!a.empty)return!1;let o=a.$from,s=o.parent;if(s.type.name!==`paragraph`||s.content.size>0||!rC(i)||!nC(i))return!1;n.preventDefault();let c=t.state.schema.marks.link,l=o.pos,u=t.state.tr.insertText(i,l);return c&&u.addMark(l,l+i.length,c.create({href:i})),t.dispatch(u),queueMicrotask(()=>{let n=l,r=l+i.length,a=Fv(t.state.tr).delete(n,r);t.dispatch(a),e.commands.setEmbed({url:i})}),!0}}})]}});function VT(e){return e instanceof E?e:e.content}function HT(e){if(/data-vscode-/i.test(e))return!0;let t=e.match(/^[^<]*(?:<(?:meta|html|head|body)\b[^>]*>\s*)*<(?:div|pre)\b[^>]*style="([^"]*)"/i);if(t){let e=t[1]??``,n=/font-family:[^;"]*\b(?:monospace|Menlo|Monaco|Consolas|Courier|JetBrains Mono|Fira Code|Source Code Pro)\b/i.test(e),r=/white-space:\s*pre\b/i.test(e);if(n&&r)return!0}return!1}var UT=N.create({name:`markdownClipboard`,addProseMirrorPlugins(){return[new Mr({props:{handlePaste:(e,t)=>{let n=t.clipboardData?.getData(`text/html`)??``;if(!n||!HT(n))return!1;let r=t.clipboardData?.getData(`text/plain`)?.trim()??``;if(!r||!this.editor.markdown)return!1;let i=this.editor.markdown.parse(r);if(i.type!==`doc`||!i.content)return!1;let a=Jl(i,e.state.schema,{slice:!1}),o=D.maxOpen(VT(a));return t.preventDefault(),e.dispatch(e.state.tr.replaceSelection(o).scrollIntoView()),!0},clipboardTextParser:(e,t,n,r)=>{if(!e.trim()||!this.editor.markdown)return D.empty;let i=this.editor.markdown.parse(e);if(i.type!==`doc`||!i.content)return D.empty;if(i.content.length===1&&i.content[0]?.type===`paragraph`){let e=i.content[0];if(!e?.content)return D.empty;let t=Jl(e.content,r.state.schema,{slice:!0});return D.maxOpen(VT(t))}let a=Jl(i,r.state.schema,{slice:!1});return D.maxOpen(VT(a))}}})]}}),WT=N.create({name:`reclaimModEnter`,priority:1e3,addKeyboardShortcuts(){return{"Mod-Enter":()=>!0}}});function GT(e={}){return[...Vx(),Pm.configure({markedOptions:bx}),IS.configure({placeholder:e.placeholder??``}),WT,Kw,Jw,UT,zw,Xw,Iw.configure({toolbarMode:`compose`}),jw]}function KT(e={}){return[...Vx({imageExtension:AT,moreBreakExtension:MT,embedExtension:FT,htmlBlockExtension:LT}),WT,Pm.configure({markedOptions:bx}),IS.configure({placeholder:e.placeholder??`Write something…`}),ET,Kw,Jw,UT,IC,BT,ww.configure(e.pasteMedia??{}),Iw.configure({toolbarMode:e.toolbarMode??`default`}),jw,zw,Xw,Vw]}function qT(e){try{let t=JSON.parse(e);return t.type===`doc`?Jx(t).trimEnd():``}catch{return``}}function JT(e){return new Tf({element:e.element,extensions:KT({placeholder:e.placeholder,toolbarMode:e.toolbarMode,pasteMedia:e.pasteMedia}),content:e.content??void 0,editorProps:{scrollMargin:{top:5,right:5,bottom:80,left:5},scrollThreshold:{top:5,right:5,bottom:80,left:5}},onUpdate:({editor:t})=>{e.onUpdate?.(fx(t.getJSON()))},onFocus:()=>{e.onFocus?.()},onSelectionUpdate:({editor:t})=>{e.onSelectionUpdate?.({from:t.state.selection.from,to:t.state.selection.to})}})}function YT(e){return qT(JSON.stringify(e))}function XT(e){let t=e.content?qx(e.content):void 0;return new Tf({element:e.element,extensions:GT({placeholder:e.placeholder}),content:t,onUpdate:({editor:t})=>{e.onUpdate?.(YT(t.getJSON()))}})}var ZT=()=>typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e===`x`?t:t&3|8).toString(16)}),QT=`[data-editor-floating-ui]`,$T=`(max-width: 700px), (max-height: 760px), (hover: none) and (pointer: coarse)`,eE={drafts:`
308
+ `),markdownTokenizer:Nx(),addCommands(){return{setHtmlBlock:e=>({chain:t,state:n})=>{if(!Af(n,n.schema.nodes[this.name]))return!1;let r={html:e.html},{$to:i}=n.selection,a=t();return vd(n.selection)?a.insertContentAt(i.pos,{type:this.name,attrs:r}):a.insertContent({type:this.name,attrs:r}),a.command(({state:e,tr:t,dispatch:n})=>(n&&DT(t,e.schema),!0)).run()}}},addNodeView(){return({node:e,view:t,getPos:n,editor:r})=>new IT(e,t,n,r)}}),RT=/^https?:\/\/\S+$/i,zT=new Pr(`jantEmbedPaste`),BT=N.create({name:`embedPaste`,addProseMirrorPlugins(){let e=this.editor;return[new j({key:zT,props:{handlePaste(t,n){let r=n.clipboardData;if(!r)return!1;let i=r.getData(`text/plain`)?.trim()??``;if(!i||!RT.test(i))return!1;let{selection:a}=t.state;if(!a.empty)return!1;let o=a.$from,s=o.parent;if(s.type.name!==`paragraph`||s.content.size>0||!rC(i)||!nC(i))return!1;n.preventDefault();let c=t.state.schema.marks.link,l=o.pos,u=t.state.tr.insertText(i,l);return c&&u.addMark(l,l+i.length,c.create({href:i})),t.dispatch(u),queueMicrotask(()=>{let n=l,r=l+i.length,a=Fv(t.state.tr).delete(n,r);t.dispatch(a),e.commands.setEmbed({url:i})}),!0}}})]}});function VT(e){return e instanceof E?e:e.content}function HT(e){if(/data-vscode-/i.test(e))return!0;let t=e.match(/^[^<]*(?:<(?:meta|html|head|body)\b[^>]*>\s*)*<(?:div|pre)\b[^>]*style="([^"]*)"/i);if(t){let e=t[1]??``,n=/font-family:[^;"]*\b(?:monospace|Menlo|Monaco|Consolas|Courier|JetBrains Mono|Fira Code|Source Code Pro)\b/i.test(e),r=/white-space:\s*pre\b/i.test(e);if(n&&r)return!0}return!1}var UT=N.create({name:`markdownClipboard`,addProseMirrorPlugins(){return[new j({props:{handlePaste:(e,t)=>{let n=t.clipboardData?.getData(`text/html`)??``;if(!n||!HT(n))return!1;let r=t.clipboardData?.getData(`text/plain`)?.trim()??``;if(!r||!this.editor.markdown)return!1;let i=this.editor.markdown.parse(r);if(i.type!==`doc`||!i.content)return!1;let a=ql(i,e.state.schema,{slice:!1}),o=D.maxOpen(VT(a));return t.preventDefault(),e.dispatch(e.state.tr.replaceSelection(o).scrollIntoView()),!0},clipboardTextParser:(e,t,n,r)=>{if(!e.trim()||!this.editor.markdown)return D.empty;let i=this.editor.markdown.parse(e);if(i.type!==`doc`||!i.content)return D.empty;if(i.content.length===1&&i.content[0]?.type===`paragraph`){let e=i.content[0];if(!e?.content)return D.empty;let t=ql(e.content,r.state.schema,{slice:!0});return D.maxOpen(VT(t))}let a=ql(i,r.state.schema,{slice:!1});return D.maxOpen(VT(a))}}})]}}),WT=N.create({name:`reclaimModEnter`,priority:1e3,addKeyboardShortcuts(){return{"Mod-Enter":()=>!0}}});function GT(e={}){return[...Vx(),Pm.configure({markedOptions:bx}),IS.configure({placeholder:e.placeholder??``}),WT,Kw,Jw,UT,zw,Xw,Iw.configure({toolbarMode:`compose`}),jw]}function KT(e={}){return[...Vx({imageExtension:AT,moreBreakExtension:MT,embedExtension:FT,htmlBlockExtension:LT}),WT,Pm.configure({markedOptions:bx}),IS.configure({placeholder:e.placeholder??`Write something…`}),ET,Kw,Jw,UT,IC,BT,ww.configure(e.pasteMedia??{}),Iw.configure({toolbarMode:e.toolbarMode??`default`}),jw,zw,Xw,Vw]}function qT(e){try{let t=JSON.parse(e);return t.type===`doc`?Jx(t).trimEnd():``}catch{return``}}function JT(e){return new Tf({element:e.element,extensions:KT({placeholder:e.placeholder,toolbarMode:e.toolbarMode,pasteMedia:e.pasteMedia}),content:e.content??void 0,editorProps:{scrollMargin:{top:5,right:5,bottom:80,left:5},scrollThreshold:{top:5,right:5,bottom:80,left:5}},onUpdate:({editor:t})=>{e.onUpdate?.(fx(t.getJSON()))},onFocus:()=>{e.onFocus?.()},onSelectionUpdate:({editor:t})=>{e.onSelectionUpdate?.({from:t.state.selection.from,to:t.state.selection.to})}})}function YT(e){return qT(JSON.stringify(e))}function XT(e){let t=e.content?qx(e.content):void 0;return new Tf({element:e.element,extensions:GT({placeholder:e.placeholder}),content:t,onUpdate:({editor:t})=>{e.onUpdate?.(YT(t.getJSON()))}})}var ZT=()=>typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e===`x`?t:t&3|8).toString(16)}),QT=`[data-editor-floating-ui]`,$T=`(max-width: 700px), (max-height: 760px), (hover: none) and (pointer: coarse)`,eE={drafts:`
309
309
  <rect x="3.85" y="3.45" width="7.85" height="8.35" rx="2.35" />
310
310
  <rect
311
311
  x="6.15"
@@ -2193,7 +2193,7 @@ The @mediabunny/aac-encoder extension package provides support for encoding AAC.
2193
2193
  The @mediabunny/ac3 extension package provides support for encoding and decoding AC-3/E-AC-3.`),t.includes(`flac`)&&e.push(`
2194
2194
  The @mediabunny/flac-encoder extension package provides support for encoding FLAC.`)}else e.push(`
2195
2195
  Check the discardedTracks field for more info.`)}return e}async execute(){if(!this.isValid)throw Error(`Cannot execute this conversion because its output configuration is invalid. Make sure to always check the isValid field before executing a conversion.
2196
- `+this._getInvalidityExplanation().join(``));if(this._executed)throw Error(`Conversion cannot be executed twice.`);if(this._executed=!0,this.onProgress){let e=this.utilizedTracks.map(e=>e.computeDuration()),t=Math.max(0,...await Promise.all(e));this._computeProgress=!0,this._totalDuration=Math.min(t-this._startTimestamp,this._endTimestamp-this._startTimestamp);for(let e of this.utilizedTracks)this._maxTimestamps.set(e.id,0);this.onProgress?.(0)}await this.output.start(),this._start();try{await Promise.all(this._trackPromises)}catch(e){throw this._canceled||this.cancel(),e}if(this._canceled)throw new TR;await this.output.finalize(),this._computeProgress&&this.onProgress?.(1)}async cancel(){if(!(this.output.state===`finalizing`||this.output.state===`finalized`)){if(this._canceled){console.warn(`Conversion already canceled.`);return}this._canceled=!0,await this.output.cancel()}}async _processVideoTrack(e,t){let n=e.codec;if(!n){this.discardedTracks.push({track:e,reason:`unknown_source_codec`});return}let r,i=xk(e.rotation+(t.rotate??0)),a=i,o=this.output.format.supportsVideoRotationMetadata&&(t.allowRotationMetadata??!0),[s,c]=i%180==0?[e.squarePixelWidth,e.squarePixelHeight]:[e.squarePixelHeight,e.squarePixelWidth],l=t.crop;l&&FM(l,s,c);let[u,d]=l?[l.width,l.height]:[s,c],f=u,p=d,m=f/p,h=e=>Math.ceil(e/2)*2;t.width!==void 0&&t.height===void 0?(f=h(t.width),p=h(Math.round(f/m))):t.width===void 0&&t.height!==void 0?(p=h(t.height),f=h(Math.round(p*m))):t.width!==void 0&&t.height!==void 0&&(f=h(t.width),p=h(t.height));let g=await e.getFirstTimestamp(),_=this.output.format.getSupportedVideoCodecs(),v=!!t.forceTranscode||g<this._startTimestamp||!!t.frameRate||t.keyFrameInterval!==void 0||t.process!==void 0||t.bitrate!==void 0||!_.includes(n)||t.codec&&t.codec!==n||f!==u||p!==d||i!==0&&!o||!!l,y=t.alpha??`discard`;if(v){if(!await e.canDecode()){this.discardedTracks.push({track:e,reason:`undecodable_source_codec`});return}t.codec&&(_=_.filter(e=>e===t.codec));let n=t.bitrate??tR,s=await aR(_,{width:t.process&&t.processedWidth?t.processedWidth:f,height:t.process&&t.processedHeight?t.processedHeight:p,bitrate:n});if(!s){this.discardedTracks.push({track:e,reason:`no_encodable_target_codec`});return}let c={codec:s,bitrate:n,keyFrameInterval:t.keyFrameInterval,sizeChangeBehavior:t.fit??`passThrough`,alpha:y,hardwareAcceleration:t.hardwareAcceleration},m=new dR(c);r=m;let h=f!==u||p!==d||i!==0&&(!o||t.process!==void 0)||!!l||e.squarePixelWidth!==e.codedWidth||e.squarePixelHeight!==e.codedHeight;if(!h){let t=new yR({format:new KL,target:new RL}),n=new dR(c);t.addVideoTrack(n),await t.start();let r=await new rN(e).getSample(g);if(r)try{await n.add(r),r.close(),await t.finalize()}catch(e){console.info(`Error when probing encoder support. Falling back to rerender path.`,e),h=!0,t.cancel()}else await t.cancel()}h?this._trackPromises.push((async()=>{await this._started;let n=new iN(e,{width:f,height:p,fit:t.fit??`fill`,rotation:i,crop:t.crop,poolSize:1,alpha:y===`keep`}).canvases(this._startTimestamp,this._endTimestamp),r=t.frameRate;a=0;let o=null,s=null,c=null,l=async n=>{U(o),U(r!==void 0);let i=Math.round((n-s)*r);for(let n=1;n<i;n++){let i=new MM(o,{timestamp:s+n/r,duration:1/r});await this._registerVideoSample(e,t,m,i),i.close()}};for await(let{canvas:i,timestamp:a,duration:u}of n){if(this._canceled)return;let n=Math.max(a-this._startTimestamp,0);if(c=n+u,r!==void 0){let e=Math.floor(n*r)/r;if(o!==null)if(e<=s){o=i,s=e;continue}else await l(e);n=e}let d=new MM(i,{timestamp:n,duration:r===void 0?u:1/r});await this._registerVideoSample(e,t,m,d),d.close(),r!==void 0&&(o=i,s=n)}o&&(U(c!==null),U(r!==void 0),await l(Math.floor(c*r)/r)),m.close(),this._synchronizer.closeTrack(e.id)})()):this._trackPromises.push((async()=>{await this._started;let n=new rN(e),r=t.frameRate,i=null,a=null,o=null,s=async n=>{U(i),U(r!==void 0);let o=Math.round((n-a)*r);for(let n=1;n<o;n++)i.setTimestamp(a+n/r),i.setDuration(1/r),await this._registerVideoSample(e,t,m,i);i.close()};for await(let c of n.samples(this._startTimestamp,this._endTimestamp)){if(this._canceled){c.close(),i?.close();return}let n=Math.max(c.timestamp-this._startTimestamp,0);if(o=n+c.duration,r!==void 0){let e=Math.floor(n*r)/r;if(i!==null)if(e<=a){i.close(),i=c,a=e;continue}else await s(e);n=e,c.setDuration(1/r)}c.setTimestamp(n),await this._registerVideoSample(e,t,m,c),r===void 0?c.close():(i=c,a=n)}i&&(U(o!==null),U(r!==void 0),await s(Math.floor(o*r)/r)),m.close(),this._synchronizer.closeTrack(e.id)})())}else{let t=new cR(n);r=t,this._trackPromises.push((async()=>{await this._started;let n=new ZM(e),r={decoderConfig:await e.getDecoderConfig()??void 0},i=Number.isFinite(this._endTimestamp)?await n.getPacket(this._endTimestamp,{metadataOnly:!0})??void 0:void 0;for await(let a of n.packets(void 0,i,{verifyKeyPackets:!0})){if(this._canceled)return;let n=a.clone({timestamp:a.timestamp-this._startTimestamp,sideData:y===`discard`?{}:a.sideData});U(n.timestamp>=0),this._reportProgress(e.id,n.timestamp),await t.add(n,r),this._synchronizer.shouldWait(e.id,n.timestamp)&&await this._synchronizer.wait(n.timestamp)}t.close(),this._synchronizer.closeTrack(e.id)})())}this.output.addVideoTrack(r,{frameRate:t.frameRate,languageCode:sA(e.languageCode)?e.languageCode:void 0,name:e.name??void 0,disposition:e.disposition,rotation:a}),this._addedCounts.video++,this._totalTrackCount++,this.utilizedTracks.push(e)}async _registerVideoSample(e,t,n,r){if(this._canceled)return;this._reportProgress(e.id,r.timestamp);let i;if(!t.process)i=[r];else{let e=t.process(r);e instanceof Promise&&(e=await e),Array.isArray(e)||(e=e===null?[]:[e]),i=e.map(e=>e instanceof MM?e:typeof VideoFrame<`u`&&e instanceof VideoFrame?new MM(e):new MM(e,{timestamp:r.timestamp,duration:r.duration}))}for(let t of i){if(this._canceled)break;await n.add(t),this._synchronizer.shouldWait(e.id,t.timestamp)&&await this._synchronizer.wait(t.timestamp)}for(let e of i)e!==r&&e.close()}async _processAudioTrack(e,t){let n=e.codec;if(!n){this.discardedTracks.push({track:e,reason:`unknown_source_codec`});return}let r,i=e.numberOfChannels,a=e.sampleRate,o=await e.getFirstTimestamp(),s=t.numberOfChannels??i,c=t.sampleRate??a,l=s!==i||c!==a||o<this._startTimestamp||o>this._startTimestamp&&!this.output.format.supportsTimestampedMediaData,u=this.output.format.getSupportedAudioCodecs();if(!t.forceTranscode&&!t.bitrate&&!l&&u.includes(n)&&(!t.codec||t.codec===n)&&!t.process){let t=new pR(n);r=t,this._trackPromises.push((async()=>{await this._started;let n=new ZM(e),r={decoderConfig:await e.getDecoderConfig()??void 0},i=Number.isFinite(this._endTimestamp)?await n.getPacket(this._endTimestamp,{metadataOnly:!0})??void 0:void 0;for await(let a of n.packets(void 0,i)){if(this._canceled)return;let n=a.clone({timestamp:a.timestamp-this._startTimestamp});U(n.timestamp>=0),this._reportProgress(e.id,n.timestamp),await t.add(n,r),this._synchronizer.shouldWait(e.id,n.timestamp)&&await this._synchronizer.wait(n.timestamp)}t.close(),this._synchronizer.closeTrack(e.id)})())}else{if(!await e.canDecode()){this.discardedTracks.push({track:e,reason:`undecodable_source_codec`});return}let n=null;t.codec&&(u=u.filter(e=>e===t.codec));let i=t.bitrate??tR,a=await iR(u,{numberOfChannels:t.process&&t.processedNumberOfChannels?t.processedNumberOfChannels:s,sampleRate:t.process&&t.processedSampleRate?t.processedSampleRate:c,bitrate:i});if(!a.some(e=>zA.includes(e))&&u.some(e=>zA.includes(e))&&(s!==SR||c!==CR)){let e=(await iR(u,{numberOfChannels:SR,sampleRate:CR,bitrate:i})).find(e=>zA.includes(e));e&&(l=!0,n=e,s=SR,c=CR)}else n=a[0]??null;if(n===null){this.discardedTracks.push({track:e,reason:`no_encodable_target_codec`});return}if(l)r=this._resampleAudio(e,t,n,s,c,i);else{let a=new hR({codec:n,bitrate:i});r=a,this._trackPromises.push((async()=>{await this._started;let n=new sN(e);for await(let r of n.samples(void 0,this._endTimestamp)){if(this._canceled){r.close();return}r.setTimestamp(r.timestamp-this._startTimestamp),await this._registerAudioSample(e,t,a,r),r.close()}a.close(),this._synchronizer.closeTrack(e.id)})())}}this.output.addAudioTrack(r,{languageCode:sA(e.languageCode)?e.languageCode:void 0,name:e.name??void 0,disposition:e.disposition}),this._addedCounts.audio++,this._totalTrackCount++,this.utilizedTracks.push(e)}async _registerAudioSample(e,t,n,r){if(this._canceled)return;this._reportProgress(e.id,r.timestamp);let i;if(!t.process)i=[r];else{let e=t.process(r);if(e instanceof Promise&&(e=await e),Array.isArray(e)||(e=e===null?[]:[e]),!e.every(e=>e instanceof VM))throw TypeError(`The audio process function must return an AudioSample, null, or an array of AudioSamples.`);i=e}for(let t of i){if(this._canceled)break;await n.add(t),this._synchronizer.shouldWait(e.id,t.timestamp)&&await this._synchronizer.wait(t.timestamp)}for(let e of i)e!==r&&e.close()}_resampleAudio(e,t,n,r,i,a){let o=new hR({codec:n,bitrate:a});return this._trackPromises.push((async()=>{await this._started;let n=new OR({targetNumberOfChannels:r,targetSampleRate:i,startTime:this._startTimestamp,endTime:this._endTimestamp,onSample:async n=>{await this._registerAudioSample(e,t,o,n),n.close()}}),a=new sN(e).samples(this._startTimestamp,this._endTimestamp);for await(let e of a){if(this._canceled){e.close();return}await n.add(e),e.close()}await n.finalize(),o.close(),this._synchronizer.closeTrack(e.id)})()),o}_reportProgress(e,t){if(!this._computeProgress)return;U(this._totalDuration!==null),this._maxTimestamps.set(e,Math.max(t,this._maxTimestamps.get(e)));let n=tA(Math.min(...this._maxTimestamps.values())/this._totalDuration,0,1);n!==this._lastProgress&&(this._lastProgress=n,this.onProgress?.(n))}},TR=class extends Error{constructor(e=`Conversion has been canceled.`){super(e),this.name=`ConversionCanceledError`}},ER=5,DR=class{constructor(){this.maxTimestamps=new Map,this.resolvers=[]}computeMinAndMaybeResolve(){let e=1/0;for(let[,t]of this.maxTimestamps)e=Math.min(e,t);for(let t=0;t<this.resolvers.length;t++){let n=this.resolvers[t];n.timestamp-e<ER&&(n.resolve(),this.resolvers.splice(t,1),t--)}return e}shouldWait(e,t){return this.maxTimestamps.set(e,Math.max(t,this.maxTimestamps.get(e)??-1/0)),t-this.computeMinAndMaybeResolve()>=ER}wait(e){let{promise:t,resolve:n}=Wk();return this.resolvers.push({timestamp:e,resolve:n}),t}closeTrack(e){this.maxTimestamps.delete(e),this.computeMinAndMaybeResolve()}},OR=class{constructor(e){this.sourceSampleRate=null,this.sourceNumberOfChannels=null,this.targetSampleRate=e.targetSampleRate,this.targetNumberOfChannels=e.targetNumberOfChannels,this.startTime=e.startTime,this.endTime=e.endTime,this.onSample=e.onSample,this.bufferSizeInFrames=Math.floor(this.targetSampleRate*5),this.bufferSizeInSamples=this.bufferSizeInFrames*this.targetNumberOfChannels,this.outputBuffer=new Float32Array(this.bufferSizeInSamples),this.bufferStartFrame=0,this.maxWrittenFrame=-1}doChannelMixerSetup(){U(this.sourceNumberOfChannels!==null);let e=this.sourceNumberOfChannels,t=this.targetNumberOfChannels;e===1&&t===2?this.channelMixer=(t,n)=>t[n*e]:e===1&&t===4?this.channelMixer=(t,n,r)=>t[n*e]*+(r<2):e===1&&t===6?this.channelMixer=(t,n,r)=>t[n*e]*+(r===2):e===2&&t===1?this.channelMixer=(t,n)=>{let r=n*e;return .5*(t[r]+t[r+1])}:e===2&&t===4||e===2&&t===6?this.channelMixer=(t,n,r)=>t[n*e+r]*+(r<2):e===4&&t===1?this.channelMixer=(t,n)=>{let r=n*e;return .25*(t[r]+t[r+1]+t[r+2]+t[r+3])}:e===4&&t===2?this.channelMixer=(t,n,r)=>{let i=n*e;return .5*(t[i+r]+t[i+r+2])}:e===4&&t===6?this.channelMixer=(t,n,r)=>{let i=n*e;return r<2?t[i+r]:r===2||r===3?0:t[i+r-2]}:e===6&&t===1?this.channelMixer=(t,n)=>{let r=n*e;return Math.SQRT1_2*(t[r]+t[r+1])+t[r+2]+.5*(t[r+4]+t[r+5])}:e===6&&t===2?this.channelMixer=(t,n,r)=>{let i=n*e;return t[i+r]+Math.SQRT1_2*(t[i+2]+t[i+r+4])}:e===6&&t===4?this.channelMixer=(t,n,r)=>{let i=n*e;return r<2?t[i+r]+Math.SQRT1_2*t[i+2]:t[i+r+2]}:this.channelMixer=(t,n,r)=>r<e?t[n*e+r]:0}ensureTempBufferSize(e){let t=this.tempSourceBuffer.length;for(;t<e;)t*=2;if(t!==this.tempSourceBuffer.length){let e=new Float32Array(t);e.set(this.tempSourceBuffer),this.tempSourceBuffer=e}}async add(e){this.sourceSampleRate===null&&(this.sourceSampleRate=e.sampleRate,this.sourceNumberOfChannels=e.numberOfChannels,this.tempSourceBuffer=new Float32Array(this.sourceSampleRate*this.sourceNumberOfChannels),this.doChannelMixerSetup());let t=e.numberOfFrames*e.numberOfChannels;this.ensureTempBufferSize(t);let n=e.allocationSize({planeIndex:0,format:`f32`}),r=new Float32Array(this.tempSourceBuffer.buffer,0,n/4);e.copyTo(r,{planeIndex:0,format:`f32`});let i=e.timestamp-this.startTime,a=e.numberOfFrames/this.sourceSampleRate,o=Math.min(i+a,this.endTime-this.startTime),s=Math.floor(i*this.targetSampleRate),c=Math.ceil(o*this.targetSampleRate);for(let t=s;t<c;t++){if(t<this.bufferStartFrame)continue;for(;t>=this.bufferStartFrame+this.bufferSizeInFrames;)await this.finalizeCurrentBuffer(),this.bufferStartFrame+=this.bufferSizeInFrames;let n=t-this.bufferStartFrame;U(n<this.bufferSizeInFrames);let a=(t/this.targetSampleRate-i)*this.sourceSampleRate,o=Math.floor(a),s=Math.ceil(a),c=a-o;for(let t=0;t<this.targetNumberOfChannels;t++){let i=0,a=0;o>=0&&o<e.numberOfFrames&&(i=this.channelMixer(r,o,t)),s>=0&&s<e.numberOfFrames&&(a=this.channelMixer(r,s,t));let l=i+c*(a-i),u=n*this.targetNumberOfChannels+t;this.outputBuffer[u]+=l}this.maxWrittenFrame=Math.max(this.maxWrittenFrame,n)}}async finalizeCurrentBuffer(){if(this.maxWrittenFrame<0)return;let e=(this.maxWrittenFrame+1)*this.targetNumberOfChannels,t=new Float32Array(e);t.set(this.outputBuffer.subarray(0,e));let n=this.bufferStartFrame/this.targetSampleRate,r=new VM({format:`f32`,sampleRate:this.targetSampleRate,numberOfChannels:this.targetNumberOfChannels,timestamp:n,data:t});await this.onSample(r),this.outputBuffer.fill(0),this.maxWrittenFrame=-1}finalize(){return this.finalizeCurrentBuffer()}};function kR(){return typeof AudioEncoder<`u`}async function AR(e,t){let n=new gF({source:new fF(e),formats:uF}),r=new LL,i=new yR({format:new KL({fastStart:`in-memory`}),target:r});try{let a=await wR.init({input:n,output:i,video:{discard:!0},audio:{codec:`aac`,bitrate:tR}});t&&(a.onProgress=t),await a.execute();let o=r.buffer;if(!o)throw Error(`Audio processing produced no output`);let s=e.name.replace(/\.[^.]+$/,``);return{file:new File([o],`${s}.m4a`,{type:`audio/mp4`})}}finally{n.dispose()}}var jR={isSupported:kR,processToFile:AR},MR=new Set([`moov`,`trak`]);function NR(e){return 12+(e===1?32:20)+8+2}function PR(e){let t=new DataView(e),n=(e,r)=>{let i=e;for(;i+8<=r;){let e=t.getUint32(i),a=String.fromCharCode(t.getUint8(i+4),t.getUint8(i+5),t.getUint8(i+6),t.getUint8(i+7));if(e===0&&(e=r-i),e<8||i+e>r)break;if(a===`tkhd`){let n=t.getUint8(i+8),r=i+NR(n);r+2<=i+e&&t.getUint16(r)!==0&&t.setUint16(r,0)}else MR.has(a)&&n(i+8,i+e);i+=e}};n(0,e.byteLength)}var FR=1920,IR=1080,LR=640,RR=32;function zR(){return typeof VideoEncoder<`u`}async function BR(e){let t=new gF({source:new fF(e),formats:uF});try{let e=await t.getPrimaryVideoTrack();if(!e)return{};let n=e.displayWidth,r=e.displayHeight,i=e.rotation,a=await t.computeDuration(),o=l(a),s=Math.min(a*.1,1),c=await new iN(e).getCanvas(s);if(!c)return{sourceWidth:n,sourceHeight:r,rotation:i,durationSeconds:o};let u=c.canvas,d=u.width,f=u.height,p=Math.min(LR/d,1),m=Math.round(d*p),h=Math.round(f*p),g=document.createElement(`canvas`);g.width=m,g.height=h;let _=g.getContext(`2d`);if(!_)return{sourceWidth:n,sourceHeight:r};_.drawImage(u,0,0,m,h);let v=await new Promise(e=>{g.toBlob(t=>e(t??void 0),`image/webp`,.8)}),y=Math.min(RR/d,RR/f,1),b=Math.max(Math.round(d*y),1),x=Math.max(Math.round(f*y),1),S=document.createElement(`canvas`);S.width=b,S.height=x;let C=S.getContext(`2d`);return C?(C.drawImage(u,0,0,b,x),{poster:v,blurhash:JC(C.getImageData(0,0,b,x).data,b,x,4,3),sourceWidth:n,sourceHeight:r,rotation:i,durationSeconds:o}):{poster:v,sourceWidth:n,sourceHeight:r}}catch{return{}}finally{t.dispose()}}async function VR(e,t){let{poster:n,blurhash:r,sourceWidth:i,sourceHeight:a,rotation:o,durationSeconds:s}=await BR(e),c=i||FR,l=a||IR;if(i&&a){let e=Math.max(i,a),t=Math.min(i,a),n=Math.min(FR/e,IR/t,1);c=Math.round(i*n),l=Math.round(a*n)}c+=c%2,l+=l%2;let u=new gF({source:new fF(e),formats:uF}),d=new LL,f=new yR({format:new KL({fastStart:`in-memory`}),target:d});try{let i=await wR.init({input:u,output:f,video:{codec:`avc`,width:c,height:l,fit:`contain`,bitrate:tR},audio:{codec:`aac`}});t&&(i.onProgress=t),await i.execute();let a=d.buffer;if(!a)throw Error(`Video processing produced no output`);PR(a);let p=e.name.replace(/\.[^.]+$/,``),m=new File([a],`${p}.mp4`,{type:`video/mp4`}),h=await GR(m),g=Math.abs(h.width-c)<=2&&Math.abs(h.height-l)<=2;return o&&!g&&(WR(a),m=new File([a],`${p}.mp4`,{type:`video/mp4`}),h=await GR(m)),{file:m,width:h.width,height:h.height,durationSeconds:s,poster:n,blurhash:r}}finally{u.dispose()}}var HR=[65536,0,0,0,65536,0,0,0,1073741824];function UR(e,t,n,r){let i=t;for(;i+8<=n;){let t=e.getUint32(i),a=String.fromCharCode(e.getUint8(i+4),e.getUint8(i+5),e.getUint8(i+6),e.getUint8(i+7));if(t===0&&(t=n-i),t<8||i+t>n)break;r(i,t,a),(a===`moov`||a===`trak`||a===`mdia`||a===`edts`)&&UR(e,i+8,i+t,r),i+=t}}function WR(e){let t=new DataView(e);UR(t,0,e.byteLength,(n,r,i)=>{if(i!==`tkhd`)return;let a=n+8,o=a+(t.getUint8(a)===0?40:52);if(o+36>e.byteLength)return;let s=!0;for(let e=0;e<9;e++)if(t.getInt32(o+e*4)!==HR[e]){s=!1;break}if(!s)for(let e=0;e<9;e++)t.setInt32(o+e*4,HR[e])})}function GR(e){return new Promise((t,n)=>{let r=URL.createObjectURL(e),i=document.createElement(`video`);i.preload=`metadata`,i.onloadedmetadata=()=>{URL.revokeObjectURL(r),t({width:i.videoWidth,height:i.videoHeight})},i.onerror=()=>{URL.revokeObjectURL(r),n(Error(`Failed to probe transcoded video dimensions`))},i.src=r})}var KR={isSupported:zR,processToFile:VR};function qR(){return document.querySelector(`jant-compose-dialog`)}function JR(){return document.querySelector(`[data-page='collection'][data-collection-id]`)?.dataset.collectionId||void 0}function YR(e=document){if(e===document){let e=document.querySelector(`[data-page='post'] article[data-post]:hover`);if(e)return e}return e.querySelector(`[data-post-current] article[data-post]`)||e.querySelector(`[data-post-view] article[data-post]`)||(e===document?document.querySelector(`article[data-post]:hover`):null)}function XR(e){let t=e.closest(`[data-post-view]`)?.dataset.postViewId;if(t)return{kind:`post-view`,id:t};let n=e.closest(`[data-timeline-item]`),r=n?.dataset.threadRootId??e.dataset.threadRootId??e.dataset.postId;if(n&&r)return{kind:`timeline-item`,id:r};let i=e.dataset.postId;return i?{kind:`post-card`,id:i}:null}function ZR(e){let t=e.cloneNode(!0);t.querySelector(`[data-post-meta]`)?.remove(),t.querySelector(`.post-status-badges`)?.remove();let n=e.querySelector(`time.dt-published`);return{contentHtml:t.innerHTML,dateText:n?.textContent?.trim()??``}}async function QR(e){await qR()?.openNew(e)}async function $R(e){let t=e.dataset.postId;if(!t)return;let n=qR();if(!n)return;let r=e.dataset.threadRootId??t;await n.openReply(t,ZR(e),r,XR(e)??void 0)}function ez(e){b(e),S(e),C(e)}function tz(e){return e instanceof globalThis.Element?e.closest(`jant-compose-editor`):null}function nz(e){return e instanceof globalThis.Element?e.closest(`jant-compose-dialog`):null}async function rz(e){let t=await fetch(e,{headers:{Accept:`text/html`}});return t.ok?t.text():null}async function iz(e){try{let t=document.querySelector(`[data-timeline-item][data-thread-root-id="${e}"]`)?.querySelector(`[data-timeline-item-content]`);if(!t)return!1;let n=await rz(`/_/timeline-item/${encodeURIComponent(e)}`);return n?(t.innerHTML=n,ez(t),!0):!1}catch{return!1}}async function az(e){try{let t=document.querySelector(`article[data-post-id="${e}"]`)?.closest(`[data-timeline-item]`),n=await rz(`/_/post-card/${encodeURIComponent(e)}`);if(!n)return!1;if(t){let e=t.querySelector(`[data-timeline-item-content]`);return e?(e.innerHTML=n,ez(e),!0):!1}let r=document.querySelector(`article[data-post-id="${e}"]`);if(!r)return!1;r.outerHTML=n;let i=document.querySelector(`article[data-post-id="${e}"]`);return i&&ez(i),!0}catch{return!1}}async function oz(e){try{let t=document.querySelector(`[data-post-view][data-post-view-id="${e}"]`);if(!t)return!1;let n=await rz(`/_/post-view/${encodeURIComponent(e)}`);if(!n)return!1;t.outerHTML=n;let r=document.querySelector(`[data-post-view][data-post-view-id="${e}"]`);return r&&ez(r),!0}catch{return!1}}async function sz(e){return!e.replyRefreshKind||!e.replyRefreshId?!1:e.replyRefreshKind===`timeline-item`?iz(e.replyThreadRootId??e.replyRefreshId):e.replyRefreshKind===`post-view`?oz(e.replyRefreshId):az(e.replyRefreshId)}var cz=new Map,lz=new Set,uz=new Map,dz=null;function fz(){if(!dz)return;let{clientIds:e,baseMsg:t}=dz;if(e.length===0)return;let n=0,r=0;for(let t of e){let e=uz.get(t)??0;n+=Math.min(1,Math.max(0,e)),e>=1&&(r+=1)}let i=e.length,a=Math.floor(n/i*100),o=Math.min(r+1,i);g(`compose-deferred`,i===1?`${t} ${a}%`:`${t} ${a}% ${o}/${i}`)}var pz=new Map;function mz(e){return new Promise(t=>{let n=setTimeout(()=>{a(),t(null)},3e3),r=URL.createObjectURL(e),i=document.createElement(`video`);i.muted=!0,i.playsInline=!0,i.preload=`auto`;function a(){clearTimeout(n),i.removeAttribute(`src`),i.load(),URL.revokeObjectURL(r)}i.onloadeddata=()=>{try{let e=i.videoWidth,n=i.videoHeight;if(!e||!n){a(),t(null);return}let r=Math.min(640/e,1),o=Math.round(e*r),s=Math.round(n*r),c=document.createElement(`canvas`);c.width=o,c.height=s;let l=c.getContext(`2d`);if(!l){a(),t(null);return}l.drawImage(i,0,0,o,s),c.toBlob(e=>{a(),t(e)},`image/webp`,.6)}catch{a(),t(null)}},i.onerror=()=>{a(),t(null)},i.src=r})}async function hz(e,t,n){let r=e.type,i=e.name;try{let o,s,c,l,u,d,f;if(r.startsWith(`video/`)){if(!KR.isSupported())return n?.updateAttachmentStatus(t,`error`,null,`Your browser doesn't support video processing. Use Chrome or Edge to upload videos.`),null;mz(e).then(e=>{e&&n?.updateAttachmentPoster(t,e)}),n?.updateAttachmentStatus(t,`processing`,null,null);let r=await KR.processToFile(e,e=>{n?.updateAttachmentProgress(t,e)});o=r.file,e=null,s=r.width,c=r.height,l=r.durationSeconds,u=r.blurhash,f=r.poster,f&&n?.updateAttachmentPoster(t,f)}else if(r.startsWith(`audio/`)){if(!jR.isSupported())return n?.updateAttachmentStatus(t,`error`,null,`Your browser doesn't support audio processing. Use Chrome or Edge to upload audio.`),null;try{d=await ZC(e)}catch{}n?.updateAttachmentStatus(t,`processing`,null,null),o=(await jR.processToFile(e,e=>{n?.updateAttachmentProgress(t,e)})).file,e=null}else if(r.startsWith(`image/`)||/\.heic$/i.test(i)||/\.heif$/i.test(i)){let r=e;try{let{isHeic:a,heicTo:l}=await pk(async()=>{let{isHeic:e,heicTo:t}=await import(`./chunks/heic-to-DUUaO23q.js`);return{isHeic:e,heicTo:t}},[]);if(await a(r)){n?.updateAttachmentStatus(t,`processing`,null,null);let e=await l({blob:r,type:`image/jpeg`,quality:.92});r=new File([e],i.replace(/\.heic$/i,`.jpg`),{type:`image/jpeg`}),n?.updateAttachmentPreview(t,r)}let u=await oe.processToFile(r);o=u.file,s=u.width,c=u.height,e=null,r=null}catch{return n?.removeAttachment(t),a(`Image format not supported.`,`error`),null}}else o=e;if(n?.updateAttachmentStatus(t,`uploading`,null,null),!r.startsWith(`video/`)){let e=await QC(o);s??=e.width,c??=e.height,u??=e.blurhash,d??=e.waveform,!f&&e.poster&&(f=e.poster,n?.updateAttachmentPoster(t,f))}let p,m;if(TS(r)===`text`)try{let e=await o.text(),t=e.replace(/\s+/g,` `).trim();m=e.length,p=t.length<=100?t:t.slice(0,100)+`…`}catch{}uz.set(t,0),fz();let h=await uw(o,{width:s,height:c,durationSeconds:l,blurhash:u,waveform:d,poster:f,summary:p,chars:m},e=>{n?.updateAttachmentProgress(t,e),uz.set(t,e),fz()});return uz.set(t,1),fz(),n?.updateAttachmentStatus(t,`done`,h.id,null),pz.set(t,h.id),h.id}catch(e){uz.delete(t),fz();let r=e instanceof Error?e.message:`Upload failed`;return n?.updateAttachmentStatus(t,`error`,null,r),n||a(r,`error`),null}}document.addEventListener(`jant:attachment-removed`,e=>{let{clientId:t,mediaId:n}=e.detail;pz.delete(t),n?fetch(`/api/upload/${n}`,{method:`DELETE`}).catch(()=>{}):lz.add(t)}),document.addEventListener(`jant:files-selected`,e=>{let t=e,n=tz(t.target);for(let{file:e,clientId:r}of t.detail.files){let t=hz(e,r,n).then(e=>lz.has(r)?(lz.delete(r),e&&fetch(`/api/upload/${e}`,{method:`DELETE`}).catch(()=>{}),null):e);cz.set(r,t),t.finally(()=>cz.delete(r))}}),document.addEventListener(`click`,e=>{let t=e.target.closest(`[data-reply-trigger]`);if(!t)return;let n=t.closest(`article[data-post]`);n&&$R(n)});function gz(e,t){let n=e.format===`quote`,r=e.format===`link`,i=!!e.editPostId,a=e=>e||void 0,o=e=>e||null;return{format:e.format,title:n?void 0:i?o(e.title):a(e.title),body:i?o(e.body):a(e.body),url:r?i?o(e.url):a(e.url):i?null:void 0,sourceName:n?i?o(e.quoteAuthor):a(e.quoteAuthor):void 0,sourceUrl:n?i?o(e.url):a(e.url):void 0,quoteText:n?i?o(e.quoteText):a(e.quoteText):i?null:void 0,slug:e.slug||void 0,status:e.status,publishedAt:e.status===`published`?e.publishedAt:void 0,visibility:e.visibility||void 0,rating:i?e.rating>0?e.rating:null:e.rating||void 0,collectionIds:e.collectionIds,attachments:t.length>0?t:void 0,replyToId:e.replyToId||void 0,quietReply:e.quietReply||void 0}}function _z(e){return JSON.stringify(e.bodyJson)!==JSON.stringify(e.originalBodyJson??null)}function vz(e,t){let n=[];for(let r of e.attachments){if(r.type===`media`){let e=r.mediaId??t.get(r.clientId)??pz.get(r.clientId);if(!e)continue;n.push({type:`media`,mediaId:e,alt:r.alt});continue}if(r.mediaId&&!_z(r)){n.push({type:`media`,mediaId:r.mediaId});continue}n.push({type:`text`,contentFormat:`markdown`,content:qT(JSON.stringify(r.bodyJson)),summary:r.summary})}return n}document.addEventListener(`jant:compose-submit-deferred`,async e=>{let t=e,n=t.detail,r=nz(t.target)??document.querySelector(`jant-compose-dialog`),i=!!r?.pageMode,s=r?.labels,c=s?.uploading??`Uploading...`,l=n.threadPosts?n.threadPosts.some(e=>e.body.includes(`"blob:`)):n.body.includes(`"blob:`),u=n.pendingAttachments.length>0||l,d=s?.published??`Published!`,p=s?.view??`View`;u&&(f(`compose-deferred`,c),n.pendingAttachments.length>0&&(dz={clientIds:n.pendingAttachments.map(e=>e.clientId),baseMsg:c},fz()));let m=(e,t=`success`)=>{if(dz){for(let e of dz.clientIds)uz.delete(e);dz=null}u?v(`compose-deferred`,e,t):a(e,t)},g=()=>{!i||!r||(r.reset(),r.updateComplete.then(()=>{r.querySelector(`jant-compose-editor`)?.focusInput()}))},_=()=>{!i||!r||(r.loading=!1)},y=()=>{if(te){n.editPostId&&r?.clearEditDraftFromStorage?.(n.editPostId);return}r?.clearLocalDraftFromStorage?.()},b=async()=>{if(!(!r||i)){if(te&&n.editPostId){if(typeof r.openEdit!=`function`)return;await r.openEdit(n.editPostId);return}if(n.replyToId){if(typeof r.openReply!=`function`)return;await r.openReply(n.replyToId,void 0,n.replyThreadRootId,n.replyRefreshKind&&n.replyRefreshId?{kind:n.replyRefreshKind,id:n.replyRefreshId}:void 0,{restoreDraft:!0,initialFormat:n.format});return}typeof r.openNew==`function`&&await r.openNew({restoreDraft:!0})}},x=async e=>{_(),await b(),m(e,`error`)},S=async()=>{await r?.refreshCollections()},C=(e,t)=>{h(e,`success`,t)},ee=()=>!i||!r||!r.consumePageLeaveRequest()?!1:(r.preparePageLeave(),globalThis.location.assign(r.closeHref||o(`/`)),!0),te=!!n.editPostId,ne=!!(n.threadPosts&&n.threadPosts.length>=2),re=null;try{let e=n.pendingAttachments.map(e=>e.clientId),t=e.map(e=>cz.get(e)??Promise.resolve(null)),a=await Promise.all(t);if(a.filter((t,n)=>t===null&&!pz.has(e[n]??``)).length>0)if(n.status===`published`&&!te)re=`upload`;else{await x(`Upload failed. Post not created.`);return}let c=new Map;for(let t=0;t<e.length;t++){let n=e[t],r=a[t];n&&r&&c.set(n,r)}if(ne&&n.threadPosts){let e=n.threadPosts,t=re?`draft`:n.status,a=(await Promise.all(e.map(async e=>{let n=e.body;if(n.includes(`"blob:`))try{let e=await vw(JSON.parse(n));n=e?JSON.stringify(e):``}catch{}return{...e,body:n,status:t}}))).map(e=>gz(e,vz(e,c))),o={posts:a};te&&n.editPostId&&(o.replaceThreadId=n.editPostId);let l=await fetch(`/compose/thread`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify(o)});if(!l.ok){if(n.status===`published`&&!re){let e={posts:a.map(e=>({...e,status:`draft`}))};if((await fetch(`/compose/thread`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify(e)})).ok){re=`server`,y();let e=s?.publishFailedDraft??`Couldn't publish. Saved as draft.`;await S(),ee()||g(),m(e);return}}await x(w(await fe(l),`error`)??`Something went wrong`);return}if(re===`upload`){y();let e=s?.uploadFailedDraft??`Some uploads failed. Saved as draft.`;await S(),g(),m(e);return}let u=await fe(l),f=w(u,`status`),h=w(u,`permalink`),_=w(u,`toast`);f===`published`?(y(),i?(await S(),g(),m(d)):(C(d,h?{label:p,href:h}:void 0),globalThis.location.reload())):(y(),await S(),ee()||g(),m(_??`Draft saved.`),yz(r,`draft`));return}let u=vz(n,c);if(l)try{let e=await vw(JSON.parse(n.body));n.body=e?JSON.stringify(e):``}catch{}let f=te?`/api/posts/${n.editPostId}`:`/compose`,h=te?`PUT`:`POST`,_=gz({...n,status:re?`draft`:n.status},u),v=await fetch(f,{method:h,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify(_)});if(!v.ok){if(n.status===`published`&&!te&&!re){let e={..._,status:`draft`},t=await fetch(f,{method:h,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify(e)});if(t.ok){re=`server`,y();let e=await fe(t),n=s?.publishFailedDraft??`Couldn't publish. Saved as draft.`;await S(),ee()||g(),m(n);let r=w(e,`toast`);r&&m(r);return}}await x(w(await fe(v),`error`)??`Something went wrong`);return}if(te){y();let e=await fe(v),t=n.editPostId??``,r=w(e,`slug`),a=r?o(`/${r}`):null;if(i)a&&a!==globalThis.location.pathname?(C(`Post updated.`),globalThis.location.assign(a)):t&&await oz(t)?m(`Post updated.`):(C(`Post updated.`),globalThis.location.assign(globalThis.location.pathname));else if(t)if(document.querySelector(`[data-post-view][data-post-view-id="${t}"]`)){if(a&&a!==globalThis.location.pathname){C(`Post updated.`),globalThis.location.assign(a);return}await oz(t)?m(`Post updated.`):(C(`Post updated.`),globalThis.location.reload())}else{let e=document.querySelector(`article[data-post-id="${t}"]`)?.closest(`[data-timeline-item]`)?.dataset.threadRootId;(e?await iz(e):await az(t))?m(`Post updated.`):(C(`Post updated.`),globalThis.location.reload())}else C(`Post updated.`),globalThis.location.reload();return}if(re===`upload`){y();let e=s?.uploadFailedDraft??`Some uploads failed. Saved as draft.`;await S(),g(),m(e);return}let b=await fe(v),ie=w(b,`status`),ae=w(b,`permalink`),oe=w(b,`toast`);if(ie===`published`){if(y(),i)await S(),g(),m(d);else if(n.replyToId){if(await S(),!await sz(n)){C(d,ae?{label:p,href:ae}:void 0),globalThis.location.reload();return}m(d)}else C(d,ae?{label:p,href:ae}:void 0),globalThis.location.reload();return}else y(),await S(),ee()||g(),m(oe??`Draft saved.`),yz(r,`draft`)}catch{await x(`Something went wrong`)}});function yz(e,t){(e??document).dispatchEvent(new CustomEvent(`jant:compose-submit-complete`,{bubbles:!0,detail:{status:t}}))}var bz=`.compose-prompt`,xz=`.compose-prompt-trigger`,Sz=`jant.composeOpenShortcutDiscovery`,Cz=`/api/settings/discovery/compose-open-shortcut`,wz=350,Tz=1800,Ez=3,Dz=`compose-prompt-discovery-visible`,Oz=!1,kz=null,Az=null,jz=null;function Mz(){try{return globalThis.localStorage!==void 0}catch{return!1}}function Nz(){if(!Mz())return{shownCount:0,completed:!1};let e=globalThis.localStorage.getItem(Sz);if(!e)return{shownCount:0,completed:!1};try{let t=JSON.parse(e);return{shownCount:typeof t.shownCount==`number`&&t.shownCount>=0?t.shownCount:0,completed:t.completed===!0}}catch{return globalThis.localStorage.removeItem(Sz),{shownCount:0,completed:!1}}}function Pz(e){if(Mz())try{globalThis.localStorage.setItem(Sz,JSON.stringify(e))}catch{}}function Fz(){kz!==null&&(clearTimeout(kz),kz=null)}function Iz(){Az!==null&&(clearTimeout(Az),Az=null)}function Lz(){return typeof globalThis.matchMedia==`function`&&globalThis.matchMedia(`(min-width: 700px)`).matches}function Rz(e){return Nz().completed?!0:e?.dataset.composeOpenShortcutDiscovered===`true`}function zz(e){e&&(e.dataset.composeOpenShortcutDiscovered=`true`,e.classList.remove(Dz)),document.querySelectorAll(bz).forEach(e=>{e.dataset.composeOpenShortcutDiscovered=`true`,e.classList.remove(Dz)})}function Bz(){let e=Nz();e.completed||Oz||e.shownCount>=Ez||(Oz=!0,Pz({...e,shownCount:e.shownCount+1}))}function Vz(e){return!Lz()||Rz(e)?!1:Nz().shownCount<Ez||Oz}function Hz(e){Fz(),Iz(),e?e.classList.remove(Dz):jz&&jz.classList.remove(Dz),(!e||e===jz)&&(jz=null)}function Uz(e){Vz(e)&&(Hz(jz),jz=e,e.classList.add(Dz),Bz(),Az=setTimeout(()=>{Hz(e)},Tz))}function Wz(e){Vz(e)&&(e.classList.contains(Dz)||(Fz(),kz=setTimeout(()=>{Uz(e)},wz)))}function Gz(e){if(e.dataset.composeOpenShortcutDiscoveryBound===`true`)return;let t=e.querySelector(xz);t&&(e.dataset.composeOpenShortcutDiscoveryBound=`true`,t.addEventListener(`pointerenter`,()=>{Wz(e)}),t.addEventListener(`pointerleave`,()=>{Hz(e)}),t.addEventListener(`focusin`,()=>{Wz(e)}),t.addEventListener(`focusout`,()=>{Hz(e)}))}function Kz(e=document){e.querySelectorAll(bz).forEach(e=>Gz(e))}function qz(){let e=Nz();e.completed||Pz({shownCount:Math.max(e.shownCount,Ez),completed:!0}),zz(jz),Hz(jz),typeof globalThis.fetch==`function`&&globalThis.fetch(Cz,{method:`POST`,headers:{Accept:`application/json`},credentials:`same-origin`}).catch(()=>{})}document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>{Kz()}):Kz(),document.readyState===`loading`&&document.addEventListener(`DOMContentLoaded`,()=>{});var Jz=[`input`,`textarea`,`select`,`button`,`a[href]`,`[contenteditable='']`,`[contenteditable='true']`,`[role='textbox']`,`.ProseMirror`].join(`, `);function Yz(e){return e instanceof globalThis.Element&&e.closest(Jz)!==null}function Xz(e){if(e.defaultPrevented||e.isComposing||e.repeat||e.metaKey||e.ctrlKey||e.altKey||!qR()||document.querySelector(`[data-page="compose"]`)||document.querySelector(`dialog[open]`))return!0;let t=document.activeElement;return Yz(e.target)||t!==e.target&&Yz(t)}async function Zz(e,t,n){try{if(!(await fetch(`/api/posts/${e}`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({featured:t})})).ok)throw Error();t?n.setAttribute(`data-post-featured`,``):n.removeAttribute(`data-post-featured`),a(t?`Added to Featured.`:`Removed from Featured.`)}catch{a(`Could not update post. Try again.`,`error`)}}document.addEventListener(`keydown`,e=>{let t=e.key.toLowerCase();if(t!==`n`&&t!==`l`&&t!==`q`&&t!==`r`&&t!==`e`&&t!==`c`&&t!==`f`||Xz(e))return;if(t===`n`||t===`l`||t===`q`){e.preventDefault(),qz();let n=JR(),r=t===`l`?`link`:t===`q`?`quote`:void 0;QR({...n?{collectionId:n}:void 0,...r?{initialFormat:r}:void 0});return}let n=YR();if(n){if(t===`r`){e.preventDefault(),$R(n);return}if(t===`e`){let t=n.dataset.postId;if(!t)return;e.preventDefault();let r=qR();r&&r.openEdit(t);return}if(t===`c`){e.preventDefault();let t=document.querySelector(`jant-post-menu`);t&&t.openCollectionsForPost(n);return}if(t===`f`){let t=n.dataset.postId;if(!t)return;e.preventDefault(),Zz(t,!n.hasAttribute(`data-post-featured`),n);return}}});var Qz=[`en`,`zh-Hans`,`zh-Hant`];function $z(e){return typeof e==`string`&&Qz.includes(e)}function eB(e){let t=e.trim();if(!t)return`en`;let n;try{n=new Intl.Locale(t)}catch{return`en`}if($z(n.baseName))return n.baseName;if(n.language===`zh`){let e=n.region;return n.script===`Hant`||e===`TW`||e===`HK`||e===`MO`?`zh-Hant`:`zh-Hans`}return`en`}var tB={en:1,"zh-Hans":1,"zh-Hant":1},nB=`en.zh-Hans.zh-Hant.ja.ko.es.fr.de.it.pt.ru.ar.hi.bn.ur.tr.vi.th.id.fa.he.nl.pl.sv.da.no.fi.cs.hu.el.ro.uk.en-GB.en-US.fr-CA.pt-BR.es-MX`.split(`.`),rB=null;function iB(e){let t=e,n=e;try{let n=new Intl.DisplayNames([e],{type:`language`}).of(e);typeof n==`string`&&n.length>0&&(t=n)}catch{}try{let t=new Intl.DisplayNames([`en`],{type:`language`}).of(e);typeof t==`string`&&t.length>0&&(n=t)}catch{}return{tag:e,native:t,english:n,coverage:aB(e)}}function aB(e){let t=eB(e);if(t===`en`){let t;try{t=new Intl.Locale(e).language}catch{return 0}if(t!==`en`)return 0}return tB[t]}function oB(){return rB||(rB=nB.map(iB),rB)}function sB(e){let t=e.trim();return oB().find(e=>e.tag===t)||iB(t)}var cB=class extends _{static properties={labels:{type:Object},timezones:{type:Array},cjkFonts:{type:Array,attribute:`cjk-fonts`},siteNameFallback:{type:String,attribute:`sitename-fallback`},siteDescriptionFallback:{type:String,attribute:`sitedescription-fallback`},dashboardLanguages:{type:Array,attribute:`dashboard-languages`},demoMode:{type:Boolean,attribute:`demo-mode`},mainFeedUrl:{type:String,attribute:`main-feed-url`},latestFeedUrl:{type:String,attribute:`latest-feed-url`},featuredFeedUrl:{type:String,attribute:`featured-feed-url`},_siteName:{state:!0},_siteDescription:{state:!0},_siteFooter:{state:!0},_origSite:{state:!0},_siteDirty:{state:!0},_siteLoading:{state:!0},_siteLanguage:{state:!0},_dashboardLanguage:{state:!0},_localeOpen:{state:!0},_localeQuery:{state:!0},_cjkSerifFont:{state:!0},_timeZone:{state:!0},_origLocale:{state:!0},_localeDirty:{state:!0},_localeLoading:{state:!0},_mainRssFeed:{state:!0},_origMainRssFeed:{state:!0},_feedDirty:{state:!0},_feedLoading:{state:!0},_showJantBrandingOnHome:{state:!0},_origShowJantBrandingOnHome:{state:!0},_homeLoading:{state:!0},_noindex:{state:!0},_origNoindex:{state:!0},_searchLoading:{state:!0}};_descEditor=null;_footerEditor=null;createRenderRoot(){return this.innerHTML=``,this}constructor(){super(),this.labels={},this.timezones=[],this.cjkFonts=[],this.dashboardLanguages=[],this.siteNameFallback=``,this.siteDescriptionFallback=``,this.demoMode=!1,this.mainFeedUrl=`/feed`,this.latestFeedUrl=`/feed/latest`,this.featuredFeedUrl=`/feed/featured`,this._siteName=``,this._siteDescription=``,this._siteFooter=``,this._origSite={siteName:``,siteDescription:``,siteFooter:``},this._siteDirty=!1,this._siteLoading=!1,this._siteLanguage=`en`,this._dashboardLanguage=`en`,this._localeOpen=!1,this._localeQuery=``,this._cjkSerifFont=`off`,this._timeZone=`UTC`,this._origLocale={siteLanguage:`en`,dashboardLanguage:`en`,cjkSerifFont:`off`,timeZone:`UTC`},this._localeDirty=!1,this._localeLoading=!1,this._mainRssFeed=`featured`,this._origMainRssFeed=`featured`,this._feedDirty=!1,this._feedLoading=!1,this._noindex=!1,this._origNoindex=!1,this._showJantBrandingOnHome=!1,this._origShowJantBrandingOnHome=!1,this._homeLoading=!1,this._searchLoading=!1}connectedCallback(){super.connectedCallback(),document.addEventListener(`click`,this._onLocalePickerDocumentClick),document.addEventListener(`keydown`,this._onLocalePickerKeydown)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener(`click`,this._onLocalePickerDocumentClick),document.removeEventListener(`keydown`,this._onLocalePickerKeydown),this._descEditor?.destroy(),this._descEditor=null,this._footerEditor?.destroy(),this._footerEditor=null}initData(e){this._siteName=e.siteName,this._siteDescription=e.siteDescription,this._siteFooter=e.siteFooter,this._siteLanguage=e.siteLanguage,this._dashboardLanguage=e.dashboardLanguage,this._cjkSerifFont=e.cjkSerifFont,this._timeZone=e.timeZone,this._origLocale={siteLanguage:e.siteLanguage,dashboardLanguage:e.dashboardLanguage,cjkSerifFont:e.cjkSerifFont,timeZone:e.timeZone},this._mainRssFeed=e.mainRssFeed,this._origMainRssFeed=e.mainRssFeed,this._showJantBrandingOnHome=e.showJantBrandingOnHome,this._origShowJantBrandingOnHome=e.showJantBrandingOnHome,this._noindex=e.noindex,this._origNoindex=e.noindex,this.updateComplete.then(()=>{this._initEditors(),this._origSite={siteName:e.siteName,siteDescription:this._siteDescription,siteFooter:this._siteFooter}})}sectionSaved(e){e===`site`?(this._origSite={siteName:this._siteName,siteDescription:this._siteDescription,siteFooter:this._siteFooter},this._siteDirty=!1,this._siteLoading=!1):e===`language-time`?(this._origLocale={siteLanguage:this._siteLanguage,dashboardLanguage:this._dashboardLanguage,cjkSerifFont:this._cjkSerifFont,timeZone:this._timeZone},this._localeDirty=!1,this._localeLoading=!1):e===`feeds`?(this._origMainRssFeed=this._mainRssFeed,this._feedDirty=!1,this._feedLoading=!1):e===`home`?(this._origShowJantBrandingOnHome=this._showJantBrandingOnHome,this._homeLoading=!1):e===`search`&&(this._origNoindex=this._noindex,this._searchLoading=!1)}sectionError(e){e===`site`?this._siteLoading=!1:e===`language-time`?this._localeLoading=!1:e===`feeds`?this._feedLoading=!1:e===`home`?(this._showJantBrandingOnHome=this._origShowJantBrandingOnHome,this._homeLoading=!1):e===`search`&&(this._noindex=this._origNoindex,this._searchLoading=!1)}_initEditors(){this._initDescEditor(),this._initFooterEditor()}_initDescEditor(){let e=this.querySelector(`[data-settings-desc-editor]`);if(!e||this._descEditor)return;this._descEditor=XT({element:e,placeholder:this.siteDescriptionFallback,content:this._siteDescription||void 0,onUpdate:e=>{this._siteDescription=e,this._syncSiteDirty()}}),this._siteDescription=YT(this._descEditor.getJSON());let t=e.querySelector(`.ProseMirror`);t&&(t.style.outline=`none`,t.style.minHeight=`3rem`)}_initFooterEditor(){let e=this.querySelector(`[data-settings-footer-editor]`);if(!e||this._footerEditor)return;this._footerEditor=XT({element:e,content:this._siteFooter||void 0,onUpdate:e=>{this._siteFooter=e,this._syncSiteDirty()}}),this._siteFooter=YT(this._footerEditor.getJSON());let t=e.querySelector(`.ProseMirror`);t&&(t.style.outline=`none`,t.style.minHeight=`6rem`)}_syncSiteDirty(){this._siteDirty=this._siteName!==this._origSite.siteName||this._siteDescription!==this._origSite.siteDescription||this._siteFooter!==this._origSite.siteFooter}_saveSite(){this._siteLoading||!this._siteDirty||(this._siteLoading=!0,this.dispatchEvent(new CustomEvent(`jant:settings-save`,{bubbles:!0,detail:{endpoint:`/settings/general`,data:{siteName:this._siteName,siteDescription:this._siteDescription,siteFooter:this._siteFooter},section:`site`}})))}_syncLocaleDirty(){this._localeDirty=this._siteLanguage!==this._origLocale.siteLanguage||this._dashboardLanguage!==this._origLocale.dashboardLanguage||this._cjkSerifFont!==this._origLocale.cjkSerifFont||this._timeZone!==this._origLocale.timeZone}_saveLocale(){this._localeLoading||!this._localeDirty||(this._localeLoading=!0,this.dispatchEvent(new CustomEvent(`jant:settings-save`,{bubbles:!0,detail:{endpoint:`/settings/general/language-time`,data:{siteLanguage:this._siteLanguage,dashboardLanguage:this._dashboardLanguage,cjkSerifFont:this._cjkSerifFont,timeZone:this._timeZone},section:`language-time`}})))}_filteredLocaleEntries(){let e=oB(),t=this._localeQuery.trim().toLowerCase();return t?e.filter(e=>e.tag.toLowerCase().includes(t)||e.native.toLowerCase().includes(t)||e.english.toLowerCase().includes(t)):e}_toggleLocalePicker=()=>{this._localeOpen=!this._localeOpen,this._localeOpen?this.updateComplete.then(()=>{this.querySelector(`[data-locale-search]`)?.focus()}):this._localeQuery=``};_selectLocale(e){this._siteLanguage=e,this._localeOpen=!1,this._localeQuery=``,this._syncLocaleDirty()}_onLocalePickerDocumentClick=e=>{if(!this._localeOpen)return;let t=e.target,n=this.querySelector(`[data-locale-picker]`);n&&t&&!n.contains(t)&&(this._localeOpen=!1)};_onLocalePickerKeydown=e=>{e.isComposing||e.keyCode===229||e.key===`Escape`&&this._localeOpen&&(this._localeOpen=!1,this._localeQuery=``)};_renderLanguagePicker(){let e=sB(this._siteLanguage||`en`),t=this._filteredLocaleEntries(),n=this.labels.siteLanguageSearchPlaceholder||`Search…`,r=this.labels.siteLanguageNoMatches||`No matches.`;return u`
2196
+ `+this._getInvalidityExplanation().join(``));if(this._executed)throw Error(`Conversion cannot be executed twice.`);if(this._executed=!0,this.onProgress){let e=this.utilizedTracks.map(e=>e.computeDuration()),t=Math.max(0,...await Promise.all(e));this._computeProgress=!0,this._totalDuration=Math.min(t-this._startTimestamp,this._endTimestamp-this._startTimestamp);for(let e of this.utilizedTracks)this._maxTimestamps.set(e.id,0);this.onProgress?.(0)}await this.output.start(),this._start();try{await Promise.all(this._trackPromises)}catch(e){throw this._canceled||this.cancel(),e}if(this._canceled)throw new TR;await this.output.finalize(),this._computeProgress&&this.onProgress?.(1)}async cancel(){if(!(this.output.state===`finalizing`||this.output.state===`finalized`)){if(this._canceled){console.warn(`Conversion already canceled.`);return}this._canceled=!0,await this.output.cancel()}}async _processVideoTrack(e,t){let n=e.codec;if(!n){this.discardedTracks.push({track:e,reason:`unknown_source_codec`});return}let r,i=xk(e.rotation+(t.rotate??0)),a=i,o=this.output.format.supportsVideoRotationMetadata&&(t.allowRotationMetadata??!0),[s,c]=i%180==0?[e.squarePixelWidth,e.squarePixelHeight]:[e.squarePixelHeight,e.squarePixelWidth],l=t.crop;l&&FM(l,s,c);let[u,d]=l?[l.width,l.height]:[s,c],f=u,p=d,m=f/p,h=e=>Math.ceil(e/2)*2;t.width!==void 0&&t.height===void 0?(f=h(t.width),p=h(Math.round(f/m))):t.width===void 0&&t.height!==void 0?(p=h(t.height),f=h(Math.round(p*m))):t.width!==void 0&&t.height!==void 0&&(f=h(t.width),p=h(t.height));let g=await e.getFirstTimestamp(),_=this.output.format.getSupportedVideoCodecs(),v=!!t.forceTranscode||g<this._startTimestamp||!!t.frameRate||t.keyFrameInterval!==void 0||t.process!==void 0||t.bitrate!==void 0||!_.includes(n)||t.codec&&t.codec!==n||f!==u||p!==d||i!==0&&!o||!!l,y=t.alpha??`discard`;if(v){if(!await e.canDecode()){this.discardedTracks.push({track:e,reason:`undecodable_source_codec`});return}t.codec&&(_=_.filter(e=>e===t.codec));let n=t.bitrate??tR,s=await aR(_,{width:t.process&&t.processedWidth?t.processedWidth:f,height:t.process&&t.processedHeight?t.processedHeight:p,bitrate:n});if(!s){this.discardedTracks.push({track:e,reason:`no_encodable_target_codec`});return}let c={codec:s,bitrate:n,keyFrameInterval:t.keyFrameInterval,sizeChangeBehavior:t.fit??`passThrough`,alpha:y,hardwareAcceleration:t.hardwareAcceleration},m=new dR(c);r=m;let h=f!==u||p!==d||i!==0&&(!o||t.process!==void 0)||!!l||e.squarePixelWidth!==e.codedWidth||e.squarePixelHeight!==e.codedHeight;if(!h){let t=new yR({format:new KL,target:new RL}),n=new dR(c);t.addVideoTrack(n),await t.start();let r=await new rN(e).getSample(g);if(r)try{await n.add(r),r.close(),await t.finalize()}catch(e){console.info(`Error when probing encoder support. Falling back to rerender path.`,e),h=!0,t.cancel()}else await t.cancel()}h?this._trackPromises.push((async()=>{await this._started;let n=new iN(e,{width:f,height:p,fit:t.fit??`fill`,rotation:i,crop:t.crop,poolSize:1,alpha:y===`keep`}).canvases(this._startTimestamp,this._endTimestamp),r=t.frameRate;a=0;let o=null,s=null,c=null,l=async n=>{U(o),U(r!==void 0);let i=Math.round((n-s)*r);for(let n=1;n<i;n++){let i=new MM(o,{timestamp:s+n/r,duration:1/r});await this._registerVideoSample(e,t,m,i),i.close()}};for await(let{canvas:i,timestamp:a,duration:u}of n){if(this._canceled)return;let n=Math.max(a-this._startTimestamp,0);if(c=n+u,r!==void 0){let e=Math.floor(n*r)/r;if(o!==null)if(e<=s){o=i,s=e;continue}else await l(e);n=e}let d=new MM(i,{timestamp:n,duration:r===void 0?u:1/r});await this._registerVideoSample(e,t,m,d),d.close(),r!==void 0&&(o=i,s=n)}o&&(U(c!==null),U(r!==void 0),await l(Math.floor(c*r)/r)),m.close(),this._synchronizer.closeTrack(e.id)})()):this._trackPromises.push((async()=>{await this._started;let n=new rN(e),r=t.frameRate,i=null,a=null,o=null,s=async n=>{U(i),U(r!==void 0);let o=Math.round((n-a)*r);for(let n=1;n<o;n++)i.setTimestamp(a+n/r),i.setDuration(1/r),await this._registerVideoSample(e,t,m,i);i.close()};for await(let c of n.samples(this._startTimestamp,this._endTimestamp)){if(this._canceled){c.close(),i?.close();return}let n=Math.max(c.timestamp-this._startTimestamp,0);if(o=n+c.duration,r!==void 0){let e=Math.floor(n*r)/r;if(i!==null)if(e<=a){i.close(),i=c,a=e;continue}else await s(e);n=e,c.setDuration(1/r)}c.setTimestamp(n),await this._registerVideoSample(e,t,m,c),r===void 0?c.close():(i=c,a=n)}i&&(U(o!==null),U(r!==void 0),await s(Math.floor(o*r)/r)),m.close(),this._synchronizer.closeTrack(e.id)})())}else{let t=new cR(n);r=t,this._trackPromises.push((async()=>{await this._started;let n=new ZM(e),r={decoderConfig:await e.getDecoderConfig()??void 0},i=Number.isFinite(this._endTimestamp)?await n.getPacket(this._endTimestamp,{metadataOnly:!0})??void 0:void 0;for await(let a of n.packets(void 0,i,{verifyKeyPackets:!0})){if(this._canceled)return;let n=a.clone({timestamp:a.timestamp-this._startTimestamp,sideData:y===`discard`?{}:a.sideData});U(n.timestamp>=0),this._reportProgress(e.id,n.timestamp),await t.add(n,r),this._synchronizer.shouldWait(e.id,n.timestamp)&&await this._synchronizer.wait(n.timestamp)}t.close(),this._synchronizer.closeTrack(e.id)})())}this.output.addVideoTrack(r,{frameRate:t.frameRate,languageCode:sA(e.languageCode)?e.languageCode:void 0,name:e.name??void 0,disposition:e.disposition,rotation:a}),this._addedCounts.video++,this._totalTrackCount++,this.utilizedTracks.push(e)}async _registerVideoSample(e,t,n,r){if(this._canceled)return;this._reportProgress(e.id,r.timestamp);let i;if(!t.process)i=[r];else{let e=t.process(r);e instanceof Promise&&(e=await e),Array.isArray(e)||(e=e===null?[]:[e]),i=e.map(e=>e instanceof MM?e:typeof VideoFrame<`u`&&e instanceof VideoFrame?new MM(e):new MM(e,{timestamp:r.timestamp,duration:r.duration}))}for(let t of i){if(this._canceled)break;await n.add(t),this._synchronizer.shouldWait(e.id,t.timestamp)&&await this._synchronizer.wait(t.timestamp)}for(let e of i)e!==r&&e.close()}async _processAudioTrack(e,t){let n=e.codec;if(!n){this.discardedTracks.push({track:e,reason:`unknown_source_codec`});return}let r,i=e.numberOfChannels,a=e.sampleRate,o=await e.getFirstTimestamp(),s=t.numberOfChannels??i,c=t.sampleRate??a,l=s!==i||c!==a||o<this._startTimestamp||o>this._startTimestamp&&!this.output.format.supportsTimestampedMediaData,u=this.output.format.getSupportedAudioCodecs();if(!t.forceTranscode&&!t.bitrate&&!l&&u.includes(n)&&(!t.codec||t.codec===n)&&!t.process){let t=new pR(n);r=t,this._trackPromises.push((async()=>{await this._started;let n=new ZM(e),r={decoderConfig:await e.getDecoderConfig()??void 0},i=Number.isFinite(this._endTimestamp)?await n.getPacket(this._endTimestamp,{metadataOnly:!0})??void 0:void 0;for await(let a of n.packets(void 0,i)){if(this._canceled)return;let n=a.clone({timestamp:a.timestamp-this._startTimestamp});U(n.timestamp>=0),this._reportProgress(e.id,n.timestamp),await t.add(n,r),this._synchronizer.shouldWait(e.id,n.timestamp)&&await this._synchronizer.wait(n.timestamp)}t.close(),this._synchronizer.closeTrack(e.id)})())}else{if(!await e.canDecode()){this.discardedTracks.push({track:e,reason:`undecodable_source_codec`});return}let n=null;t.codec&&(u=u.filter(e=>e===t.codec));let i=t.bitrate??tR,a=await iR(u,{numberOfChannels:t.process&&t.processedNumberOfChannels?t.processedNumberOfChannels:s,sampleRate:t.process&&t.processedSampleRate?t.processedSampleRate:c,bitrate:i});if(!a.some(e=>zA.includes(e))&&u.some(e=>zA.includes(e))&&(s!==SR||c!==CR)){let e=(await iR(u,{numberOfChannels:SR,sampleRate:CR,bitrate:i})).find(e=>zA.includes(e));e&&(l=!0,n=e,s=SR,c=CR)}else n=a[0]??null;if(n===null){this.discardedTracks.push({track:e,reason:`no_encodable_target_codec`});return}if(l)r=this._resampleAudio(e,t,n,s,c,i);else{let a=new hR({codec:n,bitrate:i});r=a,this._trackPromises.push((async()=>{await this._started;let n=new sN(e);for await(let r of n.samples(void 0,this._endTimestamp)){if(this._canceled){r.close();return}r.setTimestamp(r.timestamp-this._startTimestamp),await this._registerAudioSample(e,t,a,r),r.close()}a.close(),this._synchronizer.closeTrack(e.id)})())}}this.output.addAudioTrack(r,{languageCode:sA(e.languageCode)?e.languageCode:void 0,name:e.name??void 0,disposition:e.disposition}),this._addedCounts.audio++,this._totalTrackCount++,this.utilizedTracks.push(e)}async _registerAudioSample(e,t,n,r){if(this._canceled)return;this._reportProgress(e.id,r.timestamp);let i;if(!t.process)i=[r];else{let e=t.process(r);if(e instanceof Promise&&(e=await e),Array.isArray(e)||(e=e===null?[]:[e]),!e.every(e=>e instanceof VM))throw TypeError(`The audio process function must return an AudioSample, null, or an array of AudioSamples.`);i=e}for(let t of i){if(this._canceled)break;await n.add(t),this._synchronizer.shouldWait(e.id,t.timestamp)&&await this._synchronizer.wait(t.timestamp)}for(let e of i)e!==r&&e.close()}_resampleAudio(e,t,n,r,i,a){let o=new hR({codec:n,bitrate:a});return this._trackPromises.push((async()=>{await this._started;let n=new OR({targetNumberOfChannels:r,targetSampleRate:i,startTime:this._startTimestamp,endTime:this._endTimestamp,onSample:async n=>{await this._registerAudioSample(e,t,o,n),n.close()}}),a=new sN(e).samples(this._startTimestamp,this._endTimestamp);for await(let e of a){if(this._canceled){e.close();return}await n.add(e),e.close()}await n.finalize(),o.close(),this._synchronizer.closeTrack(e.id)})()),o}_reportProgress(e,t){if(!this._computeProgress)return;U(this._totalDuration!==null),this._maxTimestamps.set(e,Math.max(t,this._maxTimestamps.get(e)));let n=tA(Math.min(...this._maxTimestamps.values())/this._totalDuration,0,1);n!==this._lastProgress&&(this._lastProgress=n,this.onProgress?.(n))}},TR=class extends Error{constructor(e=`Conversion has been canceled.`){super(e),this.name=`ConversionCanceledError`}},ER=5,DR=class{constructor(){this.maxTimestamps=new Map,this.resolvers=[]}computeMinAndMaybeResolve(){let e=1/0;for(let[,t]of this.maxTimestamps)e=Math.min(e,t);for(let t=0;t<this.resolvers.length;t++){let n=this.resolvers[t];n.timestamp-e<ER&&(n.resolve(),this.resolvers.splice(t,1),t--)}return e}shouldWait(e,t){return this.maxTimestamps.set(e,Math.max(t,this.maxTimestamps.get(e)??-1/0)),t-this.computeMinAndMaybeResolve()>=ER}wait(e){let{promise:t,resolve:n}=Wk();return this.resolvers.push({timestamp:e,resolve:n}),t}closeTrack(e){this.maxTimestamps.delete(e),this.computeMinAndMaybeResolve()}},OR=class{constructor(e){this.sourceSampleRate=null,this.sourceNumberOfChannels=null,this.targetSampleRate=e.targetSampleRate,this.targetNumberOfChannels=e.targetNumberOfChannels,this.startTime=e.startTime,this.endTime=e.endTime,this.onSample=e.onSample,this.bufferSizeInFrames=Math.floor(this.targetSampleRate*5),this.bufferSizeInSamples=this.bufferSizeInFrames*this.targetNumberOfChannels,this.outputBuffer=new Float32Array(this.bufferSizeInSamples),this.bufferStartFrame=0,this.maxWrittenFrame=-1}doChannelMixerSetup(){U(this.sourceNumberOfChannels!==null);let e=this.sourceNumberOfChannels,t=this.targetNumberOfChannels;e===1&&t===2?this.channelMixer=(t,n)=>t[n*e]:e===1&&t===4?this.channelMixer=(t,n,r)=>t[n*e]*+(r<2):e===1&&t===6?this.channelMixer=(t,n,r)=>t[n*e]*+(r===2):e===2&&t===1?this.channelMixer=(t,n)=>{let r=n*e;return .5*(t[r]+t[r+1])}:e===2&&t===4||e===2&&t===6?this.channelMixer=(t,n,r)=>t[n*e+r]*+(r<2):e===4&&t===1?this.channelMixer=(t,n)=>{let r=n*e;return .25*(t[r]+t[r+1]+t[r+2]+t[r+3])}:e===4&&t===2?this.channelMixer=(t,n,r)=>{let i=n*e;return .5*(t[i+r]+t[i+r+2])}:e===4&&t===6?this.channelMixer=(t,n,r)=>{let i=n*e;return r<2?t[i+r]:r===2||r===3?0:t[i+r-2]}:e===6&&t===1?this.channelMixer=(t,n)=>{let r=n*e;return Math.SQRT1_2*(t[r]+t[r+1])+t[r+2]+.5*(t[r+4]+t[r+5])}:e===6&&t===2?this.channelMixer=(t,n,r)=>{let i=n*e;return t[i+r]+Math.SQRT1_2*(t[i+2]+t[i+r+4])}:e===6&&t===4?this.channelMixer=(t,n,r)=>{let i=n*e;return r<2?t[i+r]+Math.SQRT1_2*t[i+2]:t[i+r+2]}:this.channelMixer=(t,n,r)=>r<e?t[n*e+r]:0}ensureTempBufferSize(e){let t=this.tempSourceBuffer.length;for(;t<e;)t*=2;if(t!==this.tempSourceBuffer.length){let e=new Float32Array(t);e.set(this.tempSourceBuffer),this.tempSourceBuffer=e}}async add(e){this.sourceSampleRate===null&&(this.sourceSampleRate=e.sampleRate,this.sourceNumberOfChannels=e.numberOfChannels,this.tempSourceBuffer=new Float32Array(this.sourceSampleRate*this.sourceNumberOfChannels),this.doChannelMixerSetup());let t=e.numberOfFrames*e.numberOfChannels;this.ensureTempBufferSize(t);let n=e.allocationSize({planeIndex:0,format:`f32`}),r=new Float32Array(this.tempSourceBuffer.buffer,0,n/4);e.copyTo(r,{planeIndex:0,format:`f32`});let i=e.timestamp-this.startTime,a=e.numberOfFrames/this.sourceSampleRate,o=Math.min(i+a,this.endTime-this.startTime),s=Math.floor(i*this.targetSampleRate),c=Math.ceil(o*this.targetSampleRate);for(let t=s;t<c;t++){if(t<this.bufferStartFrame)continue;for(;t>=this.bufferStartFrame+this.bufferSizeInFrames;)await this.finalizeCurrentBuffer(),this.bufferStartFrame+=this.bufferSizeInFrames;let n=t-this.bufferStartFrame;U(n<this.bufferSizeInFrames);let a=(t/this.targetSampleRate-i)*this.sourceSampleRate,o=Math.floor(a),s=Math.ceil(a),c=a-o;for(let t=0;t<this.targetNumberOfChannels;t++){let i=0,a=0;o>=0&&o<e.numberOfFrames&&(i=this.channelMixer(r,o,t)),s>=0&&s<e.numberOfFrames&&(a=this.channelMixer(r,s,t));let l=i+c*(a-i),u=n*this.targetNumberOfChannels+t;this.outputBuffer[u]+=l}this.maxWrittenFrame=Math.max(this.maxWrittenFrame,n)}}async finalizeCurrentBuffer(){if(this.maxWrittenFrame<0)return;let e=(this.maxWrittenFrame+1)*this.targetNumberOfChannels,t=new Float32Array(e);t.set(this.outputBuffer.subarray(0,e));let n=this.bufferStartFrame/this.targetSampleRate,r=new VM({format:`f32`,sampleRate:this.targetSampleRate,numberOfChannels:this.targetNumberOfChannels,timestamp:n,data:t});await this.onSample(r),this.outputBuffer.fill(0),this.maxWrittenFrame=-1}finalize(){return this.finalizeCurrentBuffer()}};function kR(){return typeof AudioEncoder<`u`}async function AR(e,t){let n=new gF({source:new fF(e),formats:uF}),r=new LL,i=new yR({format:new KL({fastStart:`in-memory`}),target:r});try{let a=await wR.init({input:n,output:i,video:{discard:!0},audio:{codec:`aac`,bitrate:tR}});t&&(a.onProgress=t),await a.execute();let o=r.buffer;if(!o)throw Error(`Audio processing produced no output`);let s=e.name.replace(/\.[^.]+$/,``);return{file:new File([o],`${s}.m4a`,{type:`audio/mp4`})}}finally{n.dispose()}}var jR={isSupported:kR,processToFile:AR},MR=new Set([`moov`,`trak`]);function NR(e){return 12+(e===1?32:20)+8+2}function PR(e){let t=new DataView(e),n=(e,r)=>{let i=e;for(;i+8<=r;){let e=t.getUint32(i),a=String.fromCharCode(t.getUint8(i+4),t.getUint8(i+5),t.getUint8(i+6),t.getUint8(i+7));if(e===0&&(e=r-i),e<8||i+e>r)break;if(a===`tkhd`){let n=t.getUint8(i+8),r=i+NR(n);r+2<=i+e&&t.getUint16(r)!==0&&t.setUint16(r,0)}else MR.has(a)&&n(i+8,i+e);i+=e}};n(0,e.byteLength)}var FR=1920,IR=1080,LR=640,RR=32;function zR(){return typeof VideoEncoder<`u`}async function BR(e){let t=new gF({source:new fF(e),formats:uF});try{let e=await t.getPrimaryVideoTrack();if(!e)return{};let n=e.displayWidth,r=e.displayHeight,i=e.rotation,a=await t.computeDuration(),o=l(a),s=Math.min(a*.1,1),c=await new iN(e).getCanvas(s);if(!c)return{sourceWidth:n,sourceHeight:r,rotation:i,durationSeconds:o};let u=c.canvas,d=u.width,f=u.height,p=Math.min(LR/d,1),m=Math.round(d*p),h=Math.round(f*p),g=document.createElement(`canvas`);g.width=m,g.height=h;let _=g.getContext(`2d`);if(!_)return{sourceWidth:n,sourceHeight:r};_.drawImage(u,0,0,m,h);let v=await new Promise(e=>{g.toBlob(t=>e(t??void 0),`image/webp`,.8)}),y=Math.min(RR/d,RR/f,1),b=Math.max(Math.round(d*y),1),x=Math.max(Math.round(f*y),1),S=document.createElement(`canvas`);S.width=b,S.height=x;let C=S.getContext(`2d`);return C?(C.drawImage(u,0,0,b,x),{poster:v,blurhash:JC(C.getImageData(0,0,b,x).data,b,x,4,3),sourceWidth:n,sourceHeight:r,rotation:i,durationSeconds:o}):{poster:v,sourceWidth:n,sourceHeight:r}}catch{return{}}finally{t.dispose()}}async function VR(e,t){let{poster:n,blurhash:r,sourceWidth:i,sourceHeight:a,rotation:o,durationSeconds:s}=await BR(e),c=i||FR,l=a||IR;if(i&&a){let e=Math.max(i,a),t=Math.min(i,a),n=Math.min(FR/e,IR/t,1);c=Math.round(i*n),l=Math.round(a*n)}c+=c%2,l+=l%2;let u=new gF({source:new fF(e),formats:uF}),d=new LL,f=new yR({format:new KL({fastStart:`in-memory`}),target:d});try{let i=await wR.init({input:u,output:f,video:{codec:`avc`,width:c,height:l,fit:`contain`,bitrate:tR},audio:{codec:`aac`}});t&&(i.onProgress=t),await i.execute();let a=d.buffer;if(!a)throw Error(`Video processing produced no output`);PR(a);let p=e.name.replace(/\.[^.]+$/,``),m=new File([a],`${p}.mp4`,{type:`video/mp4`}),h=await GR(m),g=Math.abs(h.width-c)<=2&&Math.abs(h.height-l)<=2;return o&&!g&&(WR(a),m=new File([a],`${p}.mp4`,{type:`video/mp4`}),h=await GR(m)),{file:m,width:h.width,height:h.height,durationSeconds:s,poster:n,blurhash:r}}finally{u.dispose()}}var HR=[65536,0,0,0,65536,0,0,0,1073741824];function UR(e,t,n,r){let i=t;for(;i+8<=n;){let t=e.getUint32(i),a=String.fromCharCode(e.getUint8(i+4),e.getUint8(i+5),e.getUint8(i+6),e.getUint8(i+7));if(t===0&&(t=n-i),t<8||i+t>n)break;r(i,t,a),(a===`moov`||a===`trak`||a===`mdia`||a===`edts`)&&UR(e,i+8,i+t,r),i+=t}}function WR(e){let t=new DataView(e);UR(t,0,e.byteLength,(n,r,i)=>{if(i!==`tkhd`)return;let a=n+8,o=a+(t.getUint8(a)===0?40:52);if(o+36>e.byteLength)return;let s=!0;for(let e=0;e<9;e++)if(t.getInt32(o+e*4)!==HR[e]){s=!1;break}if(!s)for(let e=0;e<9;e++)t.setInt32(o+e*4,HR[e])})}function GR(e){return new Promise((t,n)=>{let r=URL.createObjectURL(e),i=document.createElement(`video`);i.preload=`metadata`,i.onloadedmetadata=()=>{URL.revokeObjectURL(r),t({width:i.videoWidth,height:i.videoHeight})},i.onerror=()=>{URL.revokeObjectURL(r),n(Error(`Failed to probe transcoded video dimensions`))},i.src=r})}var KR={isSupported:zR,processToFile:VR};function qR(){return document.querySelector(`jant-compose-dialog`)}function JR(){return document.querySelector(`[data-page='collection'][data-collection-id]`)?.dataset.collectionId||void 0}function YR(e=document){if(e===document){let e=document.querySelector(`[data-page='post'] article[data-post]:hover`);if(e)return e}return e.querySelector(`[data-post-current] article[data-post]`)||e.querySelector(`[data-post-view] article[data-post]`)||(e===document?document.querySelector(`article[data-post]:hover`):null)}function XR(e){let t=e.closest(`[data-post-view]`)?.dataset.postViewId;if(t)return{kind:`post-view`,id:t};let n=e.closest(`[data-timeline-item]`),r=n?.dataset.threadRootId??e.dataset.threadRootId??e.dataset.postId;if(n&&r)return{kind:`timeline-item`,id:r};let i=e.dataset.postId;return i?{kind:`post-card`,id:i}:null}function ZR(e){let t=e.cloneNode(!0);t.querySelector(`[data-post-meta]`)?.remove(),t.querySelector(`.post-status-badges`)?.remove();let n=e.querySelector(`time.dt-published`);return{contentHtml:t.innerHTML,dateText:n?.textContent?.trim()??``}}async function QR(e){await qR()?.openNew(e)}async function $R(e){let t=e.dataset.postId;if(!t)return;let n=qR();if(!n)return;let r=e.dataset.threadRootId??t;await n.openReply(t,ZR(e),r,XR(e)??void 0)}function ez(e){b(e),S(e),C(e)}function tz(e){return e instanceof globalThis.Element?e.closest(`jant-compose-editor`):null}function nz(e){return e instanceof globalThis.Element?e.closest(`jant-compose-dialog`):null}async function rz(e){let t=await fetch(e,{headers:{Accept:`text/html`}});return t.ok?t.text():null}async function iz(e){try{let t=document.querySelector(`[data-timeline-item][data-thread-root-id="${e}"]`)?.querySelector(`[data-timeline-item-content]`);if(!t)return!1;let n=await rz(`/_/timeline-item/${encodeURIComponent(e)}`);return n?(t.innerHTML=n,ez(t),!0):!1}catch{return!1}}async function az(e){try{let t=document.querySelector(`article[data-post-id="${e}"]`)?.closest(`[data-timeline-item]`),n=await rz(`/_/post-card/${encodeURIComponent(e)}`);if(!n)return!1;if(t){let e=t.querySelector(`[data-timeline-item-content]`);return e?(e.innerHTML=n,ez(e),!0):!1}let r=document.querySelector(`article[data-post-id="${e}"]`);if(!r)return!1;r.outerHTML=n;let i=document.querySelector(`article[data-post-id="${e}"]`);return i&&ez(i),!0}catch{return!1}}async function oz(e){try{let t=document.querySelector(`[data-post-view][data-post-view-id="${e}"]`);if(!t)return!1;let n=await rz(`/_/post-view/${encodeURIComponent(e)}`);if(!n)return!1;t.outerHTML=n;let r=document.querySelector(`[data-post-view][data-post-view-id="${e}"]`);return r&&ez(r),!0}catch{return!1}}async function sz(e){return!e.replyRefreshKind||!e.replyRefreshId?!1:e.replyRefreshKind===`timeline-item`?iz(e.replyThreadRootId??e.replyRefreshId):e.replyRefreshKind===`post-view`?oz(e.replyRefreshId):az(e.replyRefreshId)}var cz=new Map,lz=new Set,uz=new Map,dz=null;function fz(){if(!dz)return;let{clientIds:e,baseMsg:t}=dz;if(e.length===0)return;let n=0,r=0;for(let t of e){let e=uz.get(t)??0;n+=Math.min(1,Math.max(0,e)),e>=1&&(r+=1)}let i=e.length,a=Math.floor(n/i*100),o=Math.min(r+1,i);g(`compose-deferred`,i===1?`${t} ${a}%`:`${t} ${a}% ${o}/${i}`)}var pz=new Map;function mz(e){return new Promise(t=>{let n=setTimeout(()=>{a(),t(null)},3e3),r=URL.createObjectURL(e),i=document.createElement(`video`);i.muted=!0,i.playsInline=!0,i.preload=`auto`;function a(){clearTimeout(n),i.removeAttribute(`src`),i.load(),URL.revokeObjectURL(r)}i.onloadeddata=()=>{try{let e=i.videoWidth,n=i.videoHeight;if(!e||!n){a(),t(null);return}let r=Math.min(640/e,1),o=Math.round(e*r),s=Math.round(n*r),c=document.createElement(`canvas`);c.width=o,c.height=s;let l=c.getContext(`2d`);if(!l){a(),t(null);return}l.drawImage(i,0,0,o,s),c.toBlob(e=>{a(),t(e)},`image/webp`,.6)}catch{a(),t(null)}},i.onerror=()=>{a(),t(null)},i.src=r})}async function hz(e,t,n){let r=e.type,i=e.name;try{let o,s,c,l,u,d,f;if(r.startsWith(`video/`)){if(!KR.isSupported())return n?.updateAttachmentStatus(t,`error`,null,`Your browser doesn't support video processing. Use Chrome or Edge to upload videos.`),null;mz(e).then(e=>{e&&n?.updateAttachmentPoster(t,e)}),n?.updateAttachmentStatus(t,`processing`,null,null);let r=await KR.processToFile(e,e=>{n?.updateAttachmentProgress(t,e)});o=r.file,e=null,s=r.width,c=r.height,l=r.durationSeconds,u=r.blurhash,f=r.poster,f&&n?.updateAttachmentPoster(t,f)}else if(r.startsWith(`audio/`)){if(!jR.isSupported())return n?.updateAttachmentStatus(t,`error`,null,`Your browser doesn't support audio processing. Use Chrome or Edge to upload audio.`),null;try{d=await ZC(e)}catch{}n?.updateAttachmentStatus(t,`processing`,null,null),o=(await jR.processToFile(e,e=>{n?.updateAttachmentProgress(t,e)})).file,e=null}else if(r.startsWith(`image/`)||/\.heic$/i.test(i)||/\.heif$/i.test(i)){let r=e;try{let{isHeic:a,heicTo:l}=await pk(async()=>{let{isHeic:e,heicTo:t}=await import(`./chunks/heic-to-DUUaO23q.js`);return{isHeic:e,heicTo:t}},[]);if(await a(r)){n?.updateAttachmentStatus(t,`processing`,null,null);let e=await l({blob:r,type:`image/jpeg`,quality:.92});r=new File([e],i.replace(/\.heic$/i,`.jpg`),{type:`image/jpeg`}),n?.updateAttachmentPreview(t,r)}let u=await oe.processToFile(r);o=u.file,s=u.width,c=u.height,e=null,r=null}catch{return n?.removeAttachment(t),a(`Image format not supported.`,`error`),null}}else o=e;if(n?.updateAttachmentStatus(t,`uploading`,null,null),!r.startsWith(`video/`)){let e=await QC(o);s??=e.width,c??=e.height,u??=e.blurhash,d??=e.waveform,!f&&e.poster&&(f=e.poster,n?.updateAttachmentPoster(t,f))}let p,m;if(TS(r)===`text`)try{let e=await o.text(),t=e.replace(/\s+/g,` `).trim();m=e.length,p=t.length<=100?t:t.slice(0,100)+`…`}catch{}uz.set(t,0),fz();let h=await uw(o,{width:s,height:c,durationSeconds:l,blurhash:u,waveform:d,poster:f,summary:p,chars:m},e=>{n?.updateAttachmentProgress(t,e),uz.set(t,e),fz()});return uz.set(t,1),fz(),n?.updateAttachmentStatus(t,`done`,h.id,null),pz.set(t,h.id),h.id}catch(e){uz.delete(t),fz();let r=e instanceof Error?e.message:`Upload failed`;return n?.updateAttachmentStatus(t,`error`,null,r),n||a(r,`error`),null}}document.addEventListener(`jant:attachment-removed`,e=>{let{clientId:t,mediaId:n}=e.detail;pz.delete(t),n?fetch(`/api/upload/${n}`,{method:`DELETE`}).catch(()=>{}):lz.add(t)}),document.addEventListener(`jant:files-selected`,e=>{let t=e,n=tz(t.target);for(let{file:e,clientId:r}of t.detail.files){let t=hz(e,r,n).then(e=>lz.has(r)?(lz.delete(r),e&&fetch(`/api/upload/${e}`,{method:`DELETE`}).catch(()=>{}),null):e);cz.set(r,t),t.finally(()=>cz.delete(r))}}),document.addEventListener(`click`,e=>{let t=e.target.closest(`[data-reply-trigger]`);if(!t)return;let n=t.closest(`article[data-post]`);n&&$R(n)});function gz(e,t){let n=e.format===`quote`,r=e.format===`link`,i=!!e.editPostId,a=e=>e||void 0,o=e=>e||null;return{format:e.format,title:n?void 0:i?o(e.title):a(e.title),body:i?o(e.body):a(e.body),url:r?i?o(e.url):a(e.url):i?null:void 0,sourceName:n?i?o(e.quoteAuthor):a(e.quoteAuthor):void 0,sourceUrl:n?i?o(e.url):a(e.url):void 0,quoteText:n?i?o(e.quoteText):a(e.quoteText):i?null:void 0,slug:e.slug||void 0,status:e.status,publishedAt:e.status===`published`?e.publishedAt:void 0,visibility:e.visibility||void 0,rating:i?e.rating>0?e.rating:null:e.rating||void 0,collectionIds:e.collectionIds,attachments:t.length>0?t:void 0,replyToId:e.replyToId||void 0,quietReply:e.quietReply||void 0}}function _z(e){return JSON.stringify(e.bodyJson)!==JSON.stringify(e.originalBodyJson??null)}function vz(e,t){let n=[];for(let r of e.attachments){if(r.type===`media`){let e=r.mediaId??t.get(r.clientId)??pz.get(r.clientId);if(!e)continue;n.push({type:`media`,mediaId:e,alt:r.alt});continue}if(r.mediaId&&!_z(r)){n.push({type:`media`,mediaId:r.mediaId});continue}n.push({type:`text`,contentFormat:`markdown`,content:qT(JSON.stringify(r.bodyJson)),summary:r.summary})}return n}document.addEventListener(`jant:compose-submit-deferred`,async e=>{let t=e,n=t.detail,r=nz(t.target)??document.querySelector(`jant-compose-dialog`),i=!!r?.pageMode,s=r?.labels,c=s?.uploading??`Uploading...`,l=n.threadPosts?n.threadPosts.some(e=>e.body.includes(`"blob:`)):n.body.includes(`"blob:`),u=n.pendingAttachments.length>0||l,d=s?.published??`Published!`,p=s?.view??`View`;u&&(f(`compose-deferred`,c),n.pendingAttachments.length>0&&(dz={clientIds:n.pendingAttachments.map(e=>e.clientId),baseMsg:c},fz()));let m=(e,t=`success`)=>{if(dz){for(let e of dz.clientIds)uz.delete(e);dz=null}u?v(`compose-deferred`,e,t):a(e,t)},g=()=>{!i||!r||(r.reset(),r.updateComplete.then(()=>{r.querySelector(`jant-compose-editor`)?.focusInput()}))},_=()=>{!i||!r||(r.loading=!1)},y=()=>{if(te){n.editPostId&&r?.clearEditDraftFromStorage?.(n.editPostId);return}r?.clearLocalDraftFromStorage?.()},b=async()=>{if(!(!r||i)){if(te&&n.editPostId){if(typeof r.openEdit!=`function`)return;await r.openEdit(n.editPostId);return}if(n.replyToId){if(typeof r.openReply!=`function`)return;await r.openReply(n.replyToId,void 0,n.replyThreadRootId,n.replyRefreshKind&&n.replyRefreshId?{kind:n.replyRefreshKind,id:n.replyRefreshId}:void 0,{restoreDraft:!0,initialFormat:n.format});return}typeof r.openNew==`function`&&await r.openNew({restoreDraft:!0})}},x=async e=>{_(),await b(),m(e,`error`)},S=async()=>{await r?.refreshCollections()},C=(e,t)=>{h(e,`success`,t)},ee=()=>!i||!r||!r.consumePageLeaveRequest()?!1:(r.preparePageLeave(),globalThis.location.assign(r.closeHref||o(`/`)),!0),te=!!n.editPostId,ne=!!(n.threadPosts&&n.threadPosts.length>=2),re=null;try{let e=n.pendingAttachments.map(e=>e.clientId),t=e.map(e=>cz.get(e)??Promise.resolve(null)),a=await Promise.all(t);if(a.filter((t,n)=>t===null&&!pz.has(e[n]??``)).length>0)if(n.status===`published`&&!te)re=`upload`;else{await x(`Upload failed. Post not created.`);return}let c=new Map;for(let t=0;t<e.length;t++){let n=e[t],r=a[t];n&&r&&c.set(n,r)}if(ne&&n.threadPosts){let e=n.threadPosts,t=re?`draft`:n.status,a=(await Promise.all(e.map(async e=>{let n=e.body;if(n.includes(`"blob:`))try{let e=await vw(JSON.parse(n));n=e?JSON.stringify(e):``}catch{}return{...e,body:n,status:t}}))).map(e=>gz(e,vz(e,c))),o={posts:a};te&&n.editPostId&&(o.replaceThreadId=n.editPostId);let l=await fetch(`/compose/thread`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify(o)});if(!l.ok){if(n.status===`published`&&!re){let e={posts:a.map(e=>({...e,status:`draft`}))};if((await fetch(`/compose/thread`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify(e)})).ok){re=`server`,y();let e=s?.publishFailedDraft??`Couldn't publish. Saved as draft.`;await S(),ee()||g(),m(e);return}}await x(w(await fe(l),`error`)??`Something went wrong`);return}if(re===`upload`){y();let e=s?.uploadFailedDraft??`Some uploads failed. Saved as draft.`;await S(),g(),m(e);return}let u=await fe(l),f=w(u,`status`),h=w(u,`permalink`),_=w(u,`toast`);f===`published`?(y(),i?(await S(),g(),m(d)):(C(d,h?{label:p,href:h}:void 0),globalThis.location.reload())):(y(),await S(),ee()||g(),m(_??`Draft saved.`),yz(r,`draft`));return}let u=vz(n,c);if(l)try{let e=await vw(JSON.parse(n.body));n.body=e?JSON.stringify(e):``}catch{}let f=te?`/api/posts/${n.editPostId}`:`/compose`,h=te?`PUT`:`POST`,_=gz({...n,status:re?`draft`:n.status},u),v=await fetch(f,{method:h,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify(_)});if(!v.ok){if(n.status===`published`&&!te&&!re){let e={..._,status:`draft`},t=await fetch(f,{method:h,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify(e)});if(t.ok){re=`server`,y();let e=await fe(t),n=s?.publishFailedDraft??`Couldn't publish. Saved as draft.`;await S(),ee()||g(),m(n);let r=w(e,`toast`);r&&m(r);return}}await x(w(await fe(v),`error`)??`Something went wrong`);return}if(te){y();let e=await fe(v),t=n.editPostId??``,r=w(e,`slug`),a=r?o(`/${r}`):null;if(i)a&&a!==globalThis.location.pathname?(C(`Post updated.`),globalThis.location.assign(a)):t&&await oz(t)?m(`Post updated.`):(C(`Post updated.`),globalThis.location.assign(globalThis.location.pathname));else if(t)if(document.querySelector(`[data-post-view][data-post-view-id="${t}"]`)){if(a&&a!==globalThis.location.pathname){C(`Post updated.`),globalThis.location.assign(a);return}await oz(t)?m(`Post updated.`):(C(`Post updated.`),globalThis.location.reload())}else{let e=document.querySelector(`article[data-post-id="${t}"]`)?.closest(`[data-timeline-item]`)?.dataset.threadRootId;(e?await iz(e):await az(t))?m(`Post updated.`):(C(`Post updated.`),globalThis.location.reload())}else C(`Post updated.`),globalThis.location.reload();return}if(re===`upload`){y();let e=s?.uploadFailedDraft??`Some uploads failed. Saved as draft.`;await S(),g(),m(e);return}let b=await fe(v),ie=w(b,`status`),ae=w(b,`permalink`),oe=w(b,`toast`);if(ie===`published`){if(y(),i)await S(),g(),m(d);else if(n.replyToId){if(await S(),!await sz(n)){C(d,ae?{label:p,href:ae}:void 0),globalThis.location.reload();return}m(d)}else C(d,ae?{label:p,href:ae}:void 0),globalThis.location.reload();return}else y(),await S(),ee()||g(),m(oe??`Draft saved.`),yz(r,`draft`)}catch{await x(`Something went wrong`)}});function yz(e,t){(e??document).dispatchEvent(new CustomEvent(`jant:compose-submit-complete`,{bubbles:!0,detail:{status:t}}))}var bz=`.compose-prompt`,xz=`.compose-prompt-trigger`,Sz=`jant.composeOpenShortcutDiscovery`,Cz=`/api/settings/discovery/compose-open-shortcut`,wz=350,Tz=1800,Ez=3,Dz=`compose-prompt-discovery-visible`,Oz=!1,kz=null,Az=null,jz=null;function Mz(){try{return globalThis.localStorage!==void 0}catch{return!1}}function Nz(){if(!Mz())return{shownCount:0,completed:!1};let e=globalThis.localStorage.getItem(Sz);if(!e)return{shownCount:0,completed:!1};try{let t=JSON.parse(e);return{shownCount:typeof t.shownCount==`number`&&t.shownCount>=0?t.shownCount:0,completed:t.completed===!0}}catch{return globalThis.localStorage.removeItem(Sz),{shownCount:0,completed:!1}}}function Pz(e){if(Mz())try{globalThis.localStorage.setItem(Sz,JSON.stringify(e))}catch{}}function Fz(){kz!==null&&(clearTimeout(kz),kz=null)}function Iz(){Az!==null&&(clearTimeout(Az),Az=null)}function Lz(){return typeof globalThis.matchMedia==`function`&&globalThis.matchMedia(`(min-width: 700px)`).matches}function Rz(e){return Nz().completed?!0:e?.dataset.composeOpenShortcutDiscovered===`true`}function zz(e){e&&(e.dataset.composeOpenShortcutDiscovered=`true`,e.classList.remove(Dz)),document.querySelectorAll(bz).forEach(e=>{e.dataset.composeOpenShortcutDiscovered=`true`,e.classList.remove(Dz)})}function Bz(){let e=Nz();e.completed||Oz||e.shownCount>=Ez||(Oz=!0,Pz({...e,shownCount:e.shownCount+1}))}function Vz(e){return!Lz()||Rz(e)?!1:Nz().shownCount<Ez||Oz}function Hz(e){Fz(),Iz(),e?e.classList.remove(Dz):jz&&jz.classList.remove(Dz),(!e||e===jz)&&(jz=null)}function Uz(e){Vz(e)&&(Hz(jz),jz=e,e.classList.add(Dz),Bz(),Az=setTimeout(()=>{Hz(e)},Tz))}function Wz(e){Vz(e)&&(e.classList.contains(Dz)||(Fz(),kz=setTimeout(()=>{Uz(e)},wz)))}function Gz(e){if(e.dataset.composeOpenShortcutDiscoveryBound===`true`)return;let t=e.querySelector(xz);t&&(e.dataset.composeOpenShortcutDiscoveryBound=`true`,t.addEventListener(`pointerenter`,()=>{Wz(e)}),t.addEventListener(`pointerleave`,()=>{Hz(e)}),t.addEventListener(`focusin`,()=>{Wz(e)}),t.addEventListener(`focusout`,()=>{Hz(e)}))}function Kz(e=document){e.querySelectorAll(bz).forEach(e=>Gz(e))}function qz(){let e=Nz();e.completed||Pz({shownCount:Math.max(e.shownCount,Ez),completed:!0}),zz(jz),Hz(jz),typeof globalThis.fetch==`function`&&globalThis.fetch(Cz,{method:`POST`,headers:{Accept:`application/json`},credentials:`same-origin`}).catch(()=>{})}document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>{Kz()}):Kz(),document.readyState===`loading`&&document.addEventListener(`DOMContentLoaded`,()=>{});var Jz=[`input`,`textarea`,`select`,`button`,`a[href]`,`[contenteditable='']`,`[contenteditable='true']`,`[role='textbox']`,`.ProseMirror`].join(`, `);function Yz(e){return e instanceof globalThis.Element&&e.closest(Jz)!==null}function Xz(e){if(e.defaultPrevented||e.isComposing||e.repeat||e.metaKey||e.ctrlKey||e.altKey||!qR()||document.querySelector(`[data-page="compose"]`)||document.querySelector(`dialog[open]`))return!0;let t=document.activeElement;return Yz(e.target)||t!==e.target&&Yz(t)}async function Zz(e,t,n){try{if(!(await fetch(`/api/posts/${e}`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({featured:t})})).ok)throw Error();t?n.setAttribute(`data-post-featured`,``):n.removeAttribute(`data-post-featured`),a(t?`Added to Featured.`:`Removed from Featured.`)}catch{a(`Could not update post. Try again.`,`error`)}}document.addEventListener(`keydown`,e=>{let t=e.key.toLowerCase();if(t!==`n`&&t!==`l`&&t!==`q`&&t!==`r`&&t!==`e`&&t!==`c`&&t!==`f`||Xz(e))return;if(t===`n`||t===`l`||t===`q`){e.preventDefault(),qz();let n=JR(),r=t===`l`?`link`:t===`q`?`quote`:void 0;QR({...n?{collectionId:n}:void 0,...r?{initialFormat:r}:void 0});return}let n=YR();if(n){if(t===`r`){e.preventDefault(),$R(n);return}if(t===`e`){let t=n.dataset.postId;if(!t)return;e.preventDefault();let r=qR();r&&r.openEdit(t);return}if(t===`c`){e.preventDefault();let t=document.querySelector(`jant-post-menu`);t&&t.openCollectionsForPost(n);return}if(t===`f`){let t=n.dataset.postId;if(!t)return;e.preventDefault(),Zz(t,!n.hasAttribute(`data-post-featured`),n);return}}});var Qz=[`en`,`zh-Hans`,`zh-Hant`];function $z(e){return typeof e==`string`&&Qz.includes(e)}function eB(e){let t=e.trim();if(!t)return`en`;let n;try{n=new Intl.Locale(t)}catch{return`en`}if($z(n.baseName))return n.baseName;if(n.language===`zh`){let e=n.region;return n.script===`Hant`||e===`TW`||e===`HK`||e===`MO`?`zh-Hant`:`zh-Hans`}return`en`}var tB={en:1,"zh-Hans":1,"zh-Hant":1},nB=`en.zh-Hans.zh-Hant.ja.ko.es.fr.de.it.pt.ru.ar.hi.bn.ur.tr.vi.th.id.fa.he.nl.pl.sv.da.no.fi.cs.hu.el.ro.uk.en-GB.en-US.fr-CA.pt-BR.es-MX`.split(`.`),rB=null;function iB(e){let t=e,n=e;try{let n=new Intl.DisplayNames([e],{type:`language`}).of(e);typeof n==`string`&&n.length>0&&(t=n)}catch{}try{let t=new Intl.DisplayNames([`en`],{type:`language`}).of(e);typeof t==`string`&&t.length>0&&(n=t)}catch{}return{tag:e,native:t,english:n,coverage:aB(e)}}function aB(e){let t=eB(e);if(t===`en`){let t;try{t=new Intl.Locale(e).language}catch{return 0}if(t!==`en`)return 0}return tB[t]}function oB(){return rB||(rB=nB.map(iB),rB)}function sB(e){let t=e.trim();return oB().find(e=>e.tag===t)||iB(t)}var cB=class extends _{static properties={labels:{type:Object},timezones:{type:Array},cjkFonts:{type:Array,attribute:`cjk-fonts`},siteNameFallback:{type:String,attribute:`sitename-fallback`},siteDescriptionFallback:{type:String,attribute:`sitedescription-fallback`},dashboardLanguages:{type:Array,attribute:`dashboard-languages`},demoMode:{type:Boolean,attribute:`demo-mode`},mainFeedUrl:{type:String,attribute:`main-feed-url`},latestFeedUrl:{type:String,attribute:`latest-feed-url`},featuredFeedUrl:{type:String,attribute:`featured-feed-url`},archiveFeedUrl:{type:String,attribute:`archive-feed-url`},_siteName:{state:!0},_siteDescription:{state:!0},_siteFooter:{state:!0},_origSite:{state:!0},_siteDirty:{state:!0},_siteLoading:{state:!0},_siteLanguage:{state:!0},_dashboardLanguage:{state:!0},_localeOpen:{state:!0},_localeQuery:{state:!0},_cjkSerifFont:{state:!0},_timeZone:{state:!0},_origLocale:{state:!0},_localeDirty:{state:!0},_localeLoading:{state:!0},_mainRssFeed:{state:!0},_origMainRssFeed:{state:!0},_feedDirty:{state:!0},_feedLoading:{state:!0},_showJantBrandingOnHome:{state:!0},_origShowJantBrandingOnHome:{state:!0},_homeLoading:{state:!0},_noindex:{state:!0},_origNoindex:{state:!0},_searchLoading:{state:!0}};_descEditor=null;_footerEditor=null;createRenderRoot(){return this.innerHTML=``,this}constructor(){super(),this.labels={},this.timezones=[],this.cjkFonts=[],this.dashboardLanguages=[],this.siteNameFallback=``,this.siteDescriptionFallback=``,this.demoMode=!1,this.mainFeedUrl=`/feed`,this.latestFeedUrl=`/latest/feed`,this.featuredFeedUrl=`/featured/feed`,this.archiveFeedUrl=`/archive/feed`,this._siteName=``,this._siteDescription=``,this._siteFooter=``,this._origSite={siteName:``,siteDescription:``,siteFooter:``},this._siteDirty=!1,this._siteLoading=!1,this._siteLanguage=`en`,this._dashboardLanguage=`en`,this._localeOpen=!1,this._localeQuery=``,this._cjkSerifFont=`off`,this._timeZone=`UTC`,this._origLocale={siteLanguage:`en`,dashboardLanguage:`en`,cjkSerifFont:`off`,timeZone:`UTC`},this._localeDirty=!1,this._localeLoading=!1,this._mainRssFeed=`featured`,this._origMainRssFeed=`featured`,this._feedDirty=!1,this._feedLoading=!1,this._noindex=!1,this._origNoindex=!1,this._showJantBrandingOnHome=!1,this._origShowJantBrandingOnHome=!1,this._homeLoading=!1,this._searchLoading=!1}connectedCallback(){super.connectedCallback(),document.addEventListener(`click`,this._onLocalePickerDocumentClick),document.addEventListener(`keydown`,this._onLocalePickerKeydown)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener(`click`,this._onLocalePickerDocumentClick),document.removeEventListener(`keydown`,this._onLocalePickerKeydown),this._descEditor?.destroy(),this._descEditor=null,this._footerEditor?.destroy(),this._footerEditor=null}initData(e){this._siteName=e.siteName,this._siteDescription=e.siteDescription,this._siteFooter=e.siteFooter,this._siteLanguage=e.siteLanguage,this._dashboardLanguage=e.dashboardLanguage,this._cjkSerifFont=e.cjkSerifFont,this._timeZone=e.timeZone,this._origLocale={siteLanguage:e.siteLanguage,dashboardLanguage:e.dashboardLanguage,cjkSerifFont:e.cjkSerifFont,timeZone:e.timeZone},this._mainRssFeed=e.mainRssFeed,this._origMainRssFeed=e.mainRssFeed,this._showJantBrandingOnHome=e.showJantBrandingOnHome,this._origShowJantBrandingOnHome=e.showJantBrandingOnHome,this._noindex=e.noindex,this._origNoindex=e.noindex,this.updateComplete.then(()=>{this._initEditors(),this._origSite={siteName:e.siteName,siteDescription:this._siteDescription,siteFooter:this._siteFooter}})}sectionSaved(e){e===`site`?(this._origSite={siteName:this._siteName,siteDescription:this._siteDescription,siteFooter:this._siteFooter},this._siteDirty=!1,this._siteLoading=!1):e===`language-time`?(this._origLocale={siteLanguage:this._siteLanguage,dashboardLanguage:this._dashboardLanguage,cjkSerifFont:this._cjkSerifFont,timeZone:this._timeZone},this._localeDirty=!1,this._localeLoading=!1):e===`feeds`?(this._origMainRssFeed=this._mainRssFeed,this._feedDirty=!1,this._feedLoading=!1):e===`home`?(this._origShowJantBrandingOnHome=this._showJantBrandingOnHome,this._homeLoading=!1):e===`search`&&(this._origNoindex=this._noindex,this._searchLoading=!1)}sectionError(e){e===`site`?this._siteLoading=!1:e===`language-time`?this._localeLoading=!1:e===`feeds`?this._feedLoading=!1:e===`home`?(this._showJantBrandingOnHome=this._origShowJantBrandingOnHome,this._homeLoading=!1):e===`search`&&(this._noindex=this._origNoindex,this._searchLoading=!1)}_initEditors(){this._initDescEditor(),this._initFooterEditor()}_initDescEditor(){let e=this.querySelector(`[data-settings-desc-editor]`);if(!e||this._descEditor)return;this._descEditor=XT({element:e,placeholder:this.siteDescriptionFallback,content:this._siteDescription||void 0,onUpdate:e=>{this._siteDescription=e,this._syncSiteDirty()}}),this._siteDescription=YT(this._descEditor.getJSON());let t=e.querySelector(`.ProseMirror`);t&&(t.style.outline=`none`,t.style.minHeight=`3rem`)}_initFooterEditor(){let e=this.querySelector(`[data-settings-footer-editor]`);if(!e||this._footerEditor)return;this._footerEditor=XT({element:e,content:this._siteFooter||void 0,onUpdate:e=>{this._siteFooter=e,this._syncSiteDirty()}}),this._siteFooter=YT(this._footerEditor.getJSON());let t=e.querySelector(`.ProseMirror`);t&&(t.style.outline=`none`,t.style.minHeight=`6rem`)}_syncSiteDirty(){this._siteDirty=this._siteName!==this._origSite.siteName||this._siteDescription!==this._origSite.siteDescription||this._siteFooter!==this._origSite.siteFooter}_saveSite(){this._siteLoading||!this._siteDirty||(this._siteLoading=!0,this.dispatchEvent(new CustomEvent(`jant:settings-save`,{bubbles:!0,detail:{endpoint:`/settings/general`,data:{siteName:this._siteName,siteDescription:this._siteDescription,siteFooter:this._siteFooter},section:`site`}})))}_syncLocaleDirty(){this._localeDirty=this._siteLanguage!==this._origLocale.siteLanguage||this._dashboardLanguage!==this._origLocale.dashboardLanguage||this._cjkSerifFont!==this._origLocale.cjkSerifFont||this._timeZone!==this._origLocale.timeZone}_saveLocale(){this._localeLoading||!this._localeDirty||(this._localeLoading=!0,this.dispatchEvent(new CustomEvent(`jant:settings-save`,{bubbles:!0,detail:{endpoint:`/settings/general/language-time`,data:{siteLanguage:this._siteLanguage,dashboardLanguage:this._dashboardLanguage,cjkSerifFont:this._cjkSerifFont,timeZone:this._timeZone},section:`language-time`}})))}_filteredLocaleEntries(){let e=oB(),t=this._localeQuery.trim().toLowerCase();return t?e.filter(e=>e.tag.toLowerCase().includes(t)||e.native.toLowerCase().includes(t)||e.english.toLowerCase().includes(t)):e}_toggleLocalePicker=()=>{this._localeOpen=!this._localeOpen,this._localeOpen?this.updateComplete.then(()=>{this.querySelector(`[data-locale-search]`)?.focus()}):this._localeQuery=``};_selectLocale(e){this._siteLanguage=e,this._localeOpen=!1,this._localeQuery=``,this._syncLocaleDirty()}_onLocalePickerDocumentClick=e=>{if(!this._localeOpen)return;let t=e.target,n=this.querySelector(`[data-locale-picker]`);n&&t&&!n.contains(t)&&(this._localeOpen=!1)};_onLocalePickerKeydown=e=>{e.isComposing||e.keyCode===229||e.key===`Escape`&&this._localeOpen&&(this._localeOpen=!1,this._localeQuery=``)};_renderLanguagePicker(){let e=sB(this._siteLanguage||`en`),t=this._filteredLocaleEntries(),n=this.labels.siteLanguageSearchPlaceholder||`Search…`,r=this.labels.siteLanguageNoMatches||`No matches.`;return u`
2197
2197
  <div class="relative w-fit max-w-full" data-locale-picker>
2198
2198
  <button
2199
2199
  type="button"
@@ -2288,9 +2288,10 @@ Check the discardedTracks field for more info.`)}return e}async execute(){if(!th
2288
2288
  <div class="text-sm text-muted-foreground">${n}</div>
2289
2289
  </div>
2290
2290
  </label>
2291
- `}async _copyFeedUrl(e){try{if(!globalThis.navigator.clipboard?.writeText)throw Error(`Clipboard unavailable`);await globalThis.navigator.clipboard.writeText(e),a(this.labels.feedUrlCopied)}catch{a(this.labels.copyFailed,`error`)}}_renderFeedInfoRow(e,t){return u`
2291
+ `}async _copyFeedUrl(e){try{if(!globalThis.navigator.clipboard?.writeText)throw Error(`Clipboard unavailable`);await globalThis.navigator.clipboard.writeText(e),a(this.labels.feedUrlCopied)}catch{a(this.labels.copyFailed,`error`)}}_renderFeedInfoRow(e,t,n){return u`
2292
2292
  <div class="flex min-w-0 flex-col gap-1">
2293
2293
  <p class="text-sm font-medium">${e}</p>
2294
+ ${n?u`<p class="text-sm text-muted-foreground">${n}</p>`:``}
2294
2295
  <div class="relative">
2295
2296
  <input
2296
2297
  type="text"
@@ -2473,6 +2474,7 @@ Check the discardedTracks field for more info.`)}return e}async execute(){if(!th
2473
2474
  ${this._renderFeedInfoRow(this.labels.mainFeedUrl,this.mainFeedUrl)}
2474
2475
  ${this._renderFeedInfoRow(this.labels.latestFeedUrl,this.latestFeedUrl)}
2475
2476
  ${this._renderFeedInfoRow(this.labels.featuredFeedUrl,this.featuredFeedUrl)}
2477
+ ${this._renderFeedInfoRow(this.labels.archiveFeedUrl,this.archiveFeedUrl,this.labels.archiveFeedUrlHelp)}
2476
2478
  </div>
2477
2479
  </div>
2478
2480