From 2272206a2e2ff8a0d5dc0f9741642a86f1f31537 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 26 Jun 2026 18:13:18 -0400 Subject: [PATCH] Add character creation --- frontend/dist/assets/index-0vatXfR-.js | 231 +++++++++++ frontend/dist/assets/index-By0z_IQf.css | 1 + frontend/dist/icon.svg | 42 ++ frontend/dist/index.html | 23 ++ frontend/dist/manifest.json | 17 + frontend/src/components/CharactersPanel.jsx | 436 ++++++++++++++++++++ frontend/src/lib/api.js | 6 + frontend/src/pages/EditorPage.jsx | 13 +- frontend/src/styles/index.css | 332 +++++++++++++++ server/db.js | 20 + server/index.js | 8 +- server/routes/characters.js | 91 ++++ 12 files changed, 1215 insertions(+), 5 deletions(-) create mode 100644 frontend/dist/assets/index-0vatXfR-.js create mode 100644 frontend/dist/assets/index-By0z_IQf.css create mode 100644 frontend/dist/icon.svg create mode 100644 frontend/dist/index.html create mode 100644 frontend/dist/manifest.json create mode 100644 frontend/src/components/CharactersPanel.jsx create mode 100644 server/routes/characters.js diff --git a/frontend/dist/assets/index-0vatXfR-.js b/frontend/dist/assets/index-0vatXfR-.js new file mode 100644 index 0000000..a460203 --- /dev/null +++ b/frontend/dist/assets/index-0vatXfR-.js @@ -0,0 +1,231 @@ +function nv(t,e){for(var n=0;nr[i]})}}}return Object.freeze(Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}))}(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const s of i)if(s.type==="childList")for(const o of s.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function n(i){const s={};return i.integrity&&(s.integrity=i.integrity),i.referrerPolicy&&(s.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?s.credentials="include":i.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function r(i){if(i.ep)return;i.ep=!0;const s=n(i);fetch(i.href,s)}})();function wp(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Cp={exports:{}},ml={},Ep={exports:{}},J={};/** + * @license React + * react.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var Ds=Symbol.for("react.element"),rv=Symbol.for("react.portal"),iv=Symbol.for("react.fragment"),sv=Symbol.for("react.strict_mode"),ov=Symbol.for("react.profiler"),lv=Symbol.for("react.provider"),av=Symbol.for("react.context"),uv=Symbol.for("react.forward_ref"),cv=Symbol.for("react.suspense"),dv=Symbol.for("react.memo"),fv=Symbol.for("react.lazy"),jd=Symbol.iterator;function hv(t){return t===null||typeof t!="object"?null:(t=jd&&t[jd]||t["@@iterator"],typeof t=="function"?t:null)}var Np={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},bp=Object.assign,Mp={};function gi(t,e,n){this.props=t,this.context=e,this.refs=Mp,this.updater=n||Np}gi.prototype.isReactComponent={};gi.prototype.setState=function(t,e){if(typeof t!="object"&&typeof t!="function"&&t!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,t,e,"setState")};gi.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")};function Tp(){}Tp.prototype=gi.prototype;function oc(t,e,n){this.props=t,this.context=e,this.refs=Mp,this.updater=n||Np}var lc=oc.prototype=new Tp;lc.constructor=oc;bp(lc,gi.prototype);lc.isPureReactComponent=!0;var zd=Array.isArray,Op=Object.prototype.hasOwnProperty,ac={current:null},Dp={key:!0,ref:!0,__self:!0,__source:!0};function Pp(t,e,n){var r,i={},s=null,o=null;if(e!=null)for(r in e.ref!==void 0&&(o=e.ref),e.key!==void 0&&(s=""+e.key),e)Op.call(e,r)&&!Dp.hasOwnProperty(r)&&(i[r]=e[r]);var l=arguments.length-2;if(l===1)i.children=n;else if(1>>1,$=D[A];if(0>>1;Ai(pe,z))et<$&&0>i(fn,pe)?(D[A]=fn,D[et]=z,A=et):(D[A]=pe,D[he]=z,A=he);else if(et<$&&0>i(fn,z))D[A]=fn,D[et]=z,A=et;else break e}}return j}function i(D,j){var z=D.sortIndex-j.sortIndex;return z!==0?z:D.id-j.id}if(typeof performance=="object"&&typeof performance.now=="function"){var s=performance;t.unstable_now=function(){return s.now()}}else{var o=Date,l=o.now();t.unstable_now=function(){return o.now()-l}}var a=[],u=[],c=1,d=null,f=3,h=!1,p=!1,m=!1,x=typeof setTimeout=="function"?setTimeout:null,g=typeof clearTimeout=="function"?clearTimeout:null,v=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function S(D){for(var j=n(u);j!==null;){if(j.callback===null)r(u);else if(j.startTime<=D)r(u),j.sortIndex=j.expirationTime,e(a,j);else break;j=n(u)}}function w(D){if(m=!1,S(D),!p)if(n(a)!==null)p=!0,X(E);else{var j=n(u);j!==null&&U(w,j.startTime-D)}}function E(D,j){p=!1,m&&(m=!1,g(M),M=-1),h=!0;var z=f;try{for(S(j),d=n(a);d!==null&&(!(d.expirationTime>j)||D&&!T());){var A=d.callback;if(typeof A=="function"){d.callback=null,f=d.priorityLevel;var $=A(d.expirationTime<=j);j=t.unstable_now(),typeof $=="function"?d.callback=$:d===n(a)&&r(a),S(j)}else r(a);d=n(a)}if(d!==null)var ee=!0;else{var he=n(u);he!==null&&U(w,he.startTime-j),ee=!1}return ee}finally{d=null,f=z,h=!1}}var b=!1,C=null,M=-1,_=5,N=-1;function T(){return!(t.unstable_now()-N<_)}function V(){if(C!==null){var D=t.unstable_now();N=D;var j=!0;try{j=C(!0,D)}finally{j?G():(b=!1,C=null)}}else b=!1}var G;if(typeof v=="function")G=function(){v(V)};else if(typeof MessageChannel<"u"){var Y=new MessageChannel,ke=Y.port2;Y.port1.onmessage=V,G=function(){ke.postMessage(null)}}else G=function(){x(V,0)};function X(D){C=D,b||(b=!0,G())}function U(D,j){M=x(function(){D(t.unstable_now())},j)}t.unstable_IdlePriority=5,t.unstable_ImmediatePriority=1,t.unstable_LowPriority=4,t.unstable_NormalPriority=3,t.unstable_Profiling=null,t.unstable_UserBlockingPriority=2,t.unstable_cancelCallback=function(D){D.callback=null},t.unstable_continueExecution=function(){p||h||(p=!0,X(E))},t.unstable_forceFrameRate=function(D){0>D||125A?(D.sortIndex=z,e(u,D),n(a)===null&&D===n(u)&&(m?(g(M),M=-1):m=!0,U(w,z-A))):(D.sortIndex=$,e(a,D),p||h||(p=!0,X(E))),D},t.unstable_shouldYield=T,t.unstable_wrapCallback=function(D){var j=f;return function(){var z=f;f=j;try{return D.apply(this,arguments)}finally{f=z}}}})(jp);Lp.exports=jp;var Nv=Lp.exports;/** + * @license React + * react-dom.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var bv=k,ht=Nv;function P(t){for(var e="https://reactjs.org/docs/error-decoder.html?invariant="+t,n=1;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Wa=Object.prototype.hasOwnProperty,Mv=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,Fd={},_d={};function Tv(t){return Wa.call(_d,t)?!0:Wa.call(Fd,t)?!1:Mv.test(t)?_d[t]=!0:(Fd[t]=!0,!1)}function Ov(t,e,n,r){if(n!==null&&n.type===0)return!1;switch(typeof e){case"function":case"symbol":return!0;case"boolean":return r?!1:n!==null?!n.acceptsBooleans:(t=t.toLowerCase().slice(0,5),t!=="data-"&&t!=="aria-");default:return!1}}function Dv(t,e,n,r){if(e===null||typeof e>"u"||Ov(t,e,n,r))return!0;if(r)return!1;if(n!==null)switch(n.type){case 3:return!e;case 4:return e===!1;case 5:return isNaN(e);case 6:return isNaN(e)||1>e}return!1}function Ze(t,e,n,r,i,s,o){this.acceptsBooleans=e===2||e===3||e===4,this.attributeName=r,this.attributeNamespace=i,this.mustUseProperty=n,this.propertyName=t,this.type=e,this.sanitizeURL=s,this.removeEmptyString=o}var Be={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(t){Be[t]=new Ze(t,0,!1,t,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(t){var e=t[0];Be[e]=new Ze(e,1,!1,t[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(t){Be[t]=new Ze(t,2,!1,t.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(t){Be[t]=new Ze(t,2,!1,t,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(t){Be[t]=new Ze(t,3,!1,t.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(t){Be[t]=new Ze(t,3,!0,t,null,!1,!1)});["capture","download"].forEach(function(t){Be[t]=new Ze(t,4,!1,t,null,!1,!1)});["cols","rows","size","span"].forEach(function(t){Be[t]=new Ze(t,6,!1,t,null,!1,!1)});["rowSpan","start"].forEach(function(t){Be[t]=new Ze(t,5,!1,t.toLowerCase(),null,!1,!1)});var cc=/[\-:]([a-z])/g;function dc(t){return t[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(t){var e=t.replace(cc,dc);Be[e]=new Ze(e,1,!1,t,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(t){var e=t.replace(cc,dc);Be[e]=new Ze(e,1,!1,t,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(t){var e=t.replace(cc,dc);Be[e]=new Ze(e,1,!1,t,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(t){Be[t]=new Ze(t,1,!1,t.toLowerCase(),null,!1,!1)});Be.xlinkHref=new Ze("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(t){Be[t]=new Ze(t,1,!1,t.toLowerCase(),null,!0,!0)});function fc(t,e,n,r){var i=Be.hasOwnProperty(e)?Be[e]:null;(i!==null?i.type!==0:r||!(2l||i[o]!==s[l]){var a=` +`+i[o].replace(" at new "," at ");return t.displayName&&a.includes("")&&(a=a.replace("",t.displayName)),a}while(1<=o&&0<=l);break}}}finally{Yl=!1,Error.prepareStackTrace=n}return(t=t?t.displayName||t.name:"")?Ai(t):""}function Pv(t){switch(t.tag){case 5:return Ai(t.type);case 16:return Ai("Lazy");case 13:return Ai("Suspense");case 19:return Ai("SuspenseList");case 0:case 2:case 15:return t=Xl(t.type,!1),t;case 11:return t=Xl(t.type.render,!1),t;case 1:return t=Xl(t.type,!0),t;default:return""}}function Ga(t){if(t==null)return null;if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case Br:return"Fragment";case zr:return"Portal";case Ka:return"Profiler";case hc:return"StrictMode";case Ja:return"Suspense";case qa:return"SuspenseList"}if(typeof t=="object")switch(t.$$typeof){case Fp:return(t.displayName||"Context")+".Consumer";case Bp:return(t._context.displayName||"Context")+".Provider";case pc:var e=t.render;return t=t.displayName,t||(t=e.displayName||e.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case mc:return e=t.displayName||null,e!==null?e:Ga(t.type)||"Memo";case gn:e=t._payload,t=t._init;try{return Ga(t(e))}catch{}}return null}function Av(t){var e=t.type;switch(t.tag){case 24:return"Cache";case 9:return(e.displayName||"Context")+".Consumer";case 10:return(e._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return t=e.render,t=t.displayName||t.name||"",e.displayName||(t!==""?"ForwardRef("+t+")":"ForwardRef");case 7:return"Fragment";case 5:return e;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return Ga(e);case 8:return e===hc?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e}return null}function $n(t){switch(typeof t){case"boolean":case"number":case"string":case"undefined":return t;case"object":return t;default:return""}}function $p(t){var e=t.type;return(t=t.nodeName)&&t.toLowerCase()==="input"&&(e==="checkbox"||e==="radio")}function Iv(t){var e=$p(t)?"checked":"value",n=Object.getOwnPropertyDescriptor(t.constructor.prototype,e),r=""+t[e];if(!t.hasOwnProperty(e)&&typeof n<"u"&&typeof n.get=="function"&&typeof n.set=="function"){var i=n.get,s=n.set;return Object.defineProperty(t,e,{configurable:!0,get:function(){return i.call(this)},set:function(o){r=""+o,s.call(this,o)}}),Object.defineProperty(t,e,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(o){r=""+o},stopTracking:function(){t._valueTracker=null,delete t[e]}}}}function Hs(t){t._valueTracker||(t._valueTracker=Iv(t))}function Vp(t){if(!t)return!1;var e=t._valueTracker;if(!e)return!0;var n=e.getValue(),r="";return t&&(r=$p(t)?t.checked?"true":"false":t.value),t=r,t!==n?(e.setValue(t),!0):!1}function Po(t){if(t=t||(typeof document<"u"?document:void 0),typeof t>"u")return null;try{return t.activeElement||t.body}catch{return t.body}}function Qa(t,e){var n=e.checked;return ue({},e,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??t._wrapperState.initialChecked})}function Vd(t,e){var n=e.defaultValue==null?"":e.defaultValue,r=e.checked!=null?e.checked:e.defaultChecked;n=$n(e.value!=null?e.value:n),t._wrapperState={initialChecked:r,initialValue:n,controlled:e.type==="checkbox"||e.type==="radio"?e.checked!=null:e.value!=null}}function Up(t,e){e=e.checked,e!=null&&fc(t,"checked",e,!1)}function Ya(t,e){Up(t,e);var n=$n(e.value),r=e.type;if(n!=null)r==="number"?(n===0&&t.value===""||t.value!=n)&&(t.value=""+n):t.value!==""+n&&(t.value=""+n);else if(r==="submit"||r==="reset"){t.removeAttribute("value");return}e.hasOwnProperty("value")?Xa(t,e.type,n):e.hasOwnProperty("defaultValue")&&Xa(t,e.type,$n(e.defaultValue)),e.checked==null&&e.defaultChecked!=null&&(t.defaultChecked=!!e.defaultChecked)}function Ud(t,e,n){if(e.hasOwnProperty("value")||e.hasOwnProperty("defaultValue")){var r=e.type;if(!(r!=="submit"&&r!=="reset"||e.value!==void 0&&e.value!==null))return;e=""+t._wrapperState.initialValue,n||e===t.value||(t.value=e),t.defaultValue=e}n=t.name,n!==""&&(t.name=""),t.defaultChecked=!!t._wrapperState.initialChecked,n!==""&&(t.name=n)}function Xa(t,e,n){(e!=="number"||Po(t.ownerDocument)!==t)&&(n==null?t.defaultValue=""+t._wrapperState.initialValue:t.defaultValue!==""+n&&(t.defaultValue=""+n))}var Ii=Array.isArray;function Yr(t,e,n,r){if(t=t.options,e){e={};for(var i=0;i"+e.valueOf().toString()+"",e=Ws.firstChild;t.firstChild;)t.removeChild(t.firstChild);for(;e.firstChild;)t.appendChild(e.firstChild)}});function es(t,e){if(e){var n=t.firstChild;if(n&&n===t.lastChild&&n.nodeType===3){n.nodeValue=e;return}}t.textContent=e}var Fi={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},Rv=["Webkit","ms","Moz","O"];Object.keys(Fi).forEach(function(t){Rv.forEach(function(e){e=e+t.charAt(0).toUpperCase()+t.substring(1),Fi[e]=Fi[t]})});function Jp(t,e,n){return e==null||typeof e=="boolean"||e===""?"":n||typeof e!="number"||e===0||Fi.hasOwnProperty(t)&&Fi[t]?(""+e).trim():e+"px"}function qp(t,e){t=t.style;for(var n in e)if(e.hasOwnProperty(n)){var r=n.indexOf("--")===0,i=Jp(n,e[n],r);n==="float"&&(n="cssFloat"),r?t.setProperty(n,i):t[n]=i}}var Lv=ue({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function tu(t,e){if(e){if(Lv[t]&&(e.children!=null||e.dangerouslySetInnerHTML!=null))throw Error(P(137,t));if(e.dangerouslySetInnerHTML!=null){if(e.children!=null)throw Error(P(60));if(typeof e.dangerouslySetInnerHTML!="object"||!("__html"in e.dangerouslySetInnerHTML))throw Error(P(61))}if(e.style!=null&&typeof e.style!="object")throw Error(P(62))}}function nu(t,e){if(t.indexOf("-")===-1)return typeof e.is=="string";switch(t){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var ru=null;function gc(t){return t=t.target||t.srcElement||window,t.correspondingUseElement&&(t=t.correspondingUseElement),t.nodeType===3?t.parentNode:t}var iu=null,Xr=null,Zr=null;function Kd(t){if(t=Is(t)){if(typeof iu!="function")throw Error(P(280));var e=t.stateNode;e&&(e=Sl(e),iu(t.stateNode,t.type,e))}}function Gp(t){Xr?Zr?Zr.push(t):Zr=[t]:Xr=t}function Qp(){if(Xr){var t=Xr,e=Zr;if(Zr=Xr=null,Kd(t),e)for(t=0;t>>=0,t===0?32:31-(Kv(t)/Jv|0)|0}var Ks=64,Js=4194304;function Ri(t){switch(t&-t){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return t&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return t}}function Lo(t,e){var n=t.pendingLanes;if(n===0)return 0;var r=0,i=t.suspendedLanes,s=t.pingedLanes,o=n&268435455;if(o!==0){var l=o&~i;l!==0?r=Ri(l):(s&=o,s!==0&&(r=Ri(s)))}else o=n&~i,o!==0?r=Ri(o):s!==0&&(r=Ri(s));if(r===0)return 0;if(e!==0&&e!==r&&!(e&i)&&(i=r&-r,s=e&-e,i>=s||i===16&&(s&4194240)!==0))return e;if(r&4&&(r|=n&16),e=t.entangledLanes,e!==0)for(t=t.entanglements,e&=r;0n;n++)e.push(t);return e}function Ps(t,e,n){t.pendingLanes|=e,e!==536870912&&(t.suspendedLanes=0,t.pingedLanes=0),t=t.eventTimes,e=31-Lt(e),t[e]=n}function Yv(t,e){var n=t.pendingLanes&~e;t.pendingLanes=e,t.suspendedLanes=0,t.pingedLanes=0,t.expiredLanes&=e,t.mutableReadLanes&=e,t.entangledLanes&=e,e=t.entanglements;var r=t.eventTimes;for(t=t.expirationTimes;0=$i),tf=" ",nf=!1;function gm(t,e){switch(t){case"keyup":return N1.indexOf(e.keyCode)!==-1;case"keydown":return e.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function ym(t){return t=t.detail,typeof t=="object"&&"data"in t?t.data:null}var Fr=!1;function M1(t,e){switch(t){case"compositionend":return ym(e);case"keypress":return e.which!==32?null:(nf=!0,tf);case"textInput":return t=e.data,t===tf&&nf?null:t;default:return null}}function T1(t,e){if(Fr)return t==="compositionend"||!Ec&&gm(t,e)?(t=pm(),vo=kc=Cn=null,Fr=!1,t):null;switch(t){case"paste":return null;case"keypress":if(!(e.ctrlKey||e.altKey||e.metaKey)||e.ctrlKey&&e.altKey){if(e.char&&1=e)return{node:n,offset:e-t};t=r}e:{for(;n;){if(n.nextSibling){n=n.nextSibling;break e}n=n.parentNode}n=void 0}n=lf(n)}}function km(t,e){return t&&e?t===e?!0:t&&t.nodeType===3?!1:e&&e.nodeType===3?km(t,e.parentNode):"contains"in t?t.contains(e):t.compareDocumentPosition?!!(t.compareDocumentPosition(e)&16):!1:!1}function wm(){for(var t=window,e=Po();e instanceof t.HTMLIFrameElement;){try{var n=typeof e.contentWindow.location.href=="string"}catch{n=!1}if(n)t=e.contentWindow;else break;e=Po(t.document)}return e}function Nc(t){var e=t&&t.nodeName&&t.nodeName.toLowerCase();return e&&(e==="input"&&(t.type==="text"||t.type==="search"||t.type==="tel"||t.type==="url"||t.type==="password")||e==="textarea"||t.contentEditable==="true")}function z1(t){var e=wm(),n=t.focusedElem,r=t.selectionRange;if(e!==n&&n&&n.ownerDocument&&km(n.ownerDocument.documentElement,n)){if(r!==null&&Nc(n)){if(e=r.start,t=r.end,t===void 0&&(t=e),"selectionStart"in n)n.selectionStart=e,n.selectionEnd=Math.min(t,n.value.length);else if(t=(e=n.ownerDocument||document)&&e.defaultView||window,t.getSelection){t=t.getSelection();var i=n.textContent.length,s=Math.min(r.start,i);r=r.end===void 0?s:Math.min(r.end,i),!t.extend&&s>r&&(i=r,r=s,s=i),i=af(n,s);var o=af(n,r);i&&o&&(t.rangeCount!==1||t.anchorNode!==i.node||t.anchorOffset!==i.offset||t.focusNode!==o.node||t.focusOffset!==o.offset)&&(e=e.createRange(),e.setStart(i.node,i.offset),t.removeAllRanges(),s>r?(t.addRange(e),t.extend(o.node,o.offset)):(e.setEnd(o.node,o.offset),t.addRange(e)))}}for(e=[],t=n;t=t.parentNode;)t.nodeType===1&&e.push({element:t,left:t.scrollLeft,top:t.scrollTop});for(typeof n.focus=="function"&&n.focus(),n=0;n=document.documentMode,_r=null,cu=null,Ui=null,du=!1;function uf(t,e,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;du||_r==null||_r!==Po(r)||(r=_r,"selectionStart"in r&&Nc(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Ui&&ls(Ui,r)||(Ui=r,r=Bo(cu,"onSelect"),0Ur||(t.current=yu[Ur],yu[Ur]=null,Ur--)}function ne(t,e){Ur++,yu[Ur]=t.current,t.current=e}var Vn={},Ue=Wn(Vn),rt=Wn(!1),yr=Vn;function oi(t,e){var n=t.type.contextTypes;if(!n)return Vn;var r=t.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===e)return r.__reactInternalMemoizedMaskedChildContext;var i={},s;for(s in n)i[s]=e[s];return r&&(t=t.stateNode,t.__reactInternalMemoizedUnmaskedChildContext=e,t.__reactInternalMemoizedMaskedChildContext=i),i}function it(t){return t=t.childContextTypes,t!=null}function _o(){se(rt),se(Ue)}function gf(t,e,n){if(Ue.current!==Vn)throw Error(P(168));ne(Ue,e),ne(rt,n)}function Pm(t,e,n){var r=t.stateNode;if(e=e.childContextTypes,typeof r.getChildContext!="function")return n;r=r.getChildContext();for(var i in r)if(!(i in e))throw Error(P(108,Av(t)||"Unknown",i));return ue({},n,r)}function $o(t){return t=(t=t.stateNode)&&t.__reactInternalMemoizedMergedChildContext||Vn,yr=Ue.current,ne(Ue,t),ne(rt,rt.current),!0}function yf(t,e,n){var r=t.stateNode;if(!r)throw Error(P(169));n?(t=Pm(t,e,yr),r.__reactInternalMemoizedMergedChildContext=t,se(rt),se(Ue),ne(Ue,t)):se(rt),ne(rt,n)}var Xt=null,kl=!1,fa=!1;function Am(t){Xt===null?Xt=[t]:Xt.push(t)}function G1(t){kl=!0,Am(t)}function Kn(){if(!fa&&Xt!==null){fa=!0;var t=0,e=Q;try{var n=Xt;for(Q=1;t>=o,i-=o,Zt=1<<32-Lt(e)+i|n<M?(_=C,C=null):_=C.sibling;var N=f(g,C,S[M],w);if(N===null){C===null&&(C=_);break}t&&C&&N.alternate===null&&e(g,C),v=s(N,v,M),b===null?E=N:b.sibling=N,b=N,C=_}if(M===S.length)return n(g,C),oe&&Xn(g,M),E;if(C===null){for(;MM?(_=C,C=null):_=C.sibling;var T=f(g,C,N.value,w);if(T===null){C===null&&(C=_);break}t&&C&&T.alternate===null&&e(g,C),v=s(T,v,M),b===null?E=T:b.sibling=T,b=T,C=_}if(N.done)return n(g,C),oe&&Xn(g,M),E;if(C===null){for(;!N.done;M++,N=S.next())N=d(g,N.value,w),N!==null&&(v=s(N,v,M),b===null?E=N:b.sibling=N,b=N);return oe&&Xn(g,M),E}for(C=r(g,C);!N.done;M++,N=S.next())N=h(C,g,M,N.value,w),N!==null&&(t&&N.alternate!==null&&C.delete(N.key===null?M:N.key),v=s(N,v,M),b===null?E=N:b.sibling=N,b=N);return t&&C.forEach(function(V){return e(g,V)}),oe&&Xn(g,M),E}function x(g,v,S,w){if(typeof S=="object"&&S!==null&&S.type===Br&&S.key===null&&(S=S.props.children),typeof S=="object"&&S!==null){switch(S.$$typeof){case Us:e:{for(var E=S.key,b=v;b!==null;){if(b.key===E){if(E=S.type,E===Br){if(b.tag===7){n(g,b.sibling),v=i(b,S.props.children),v.return=g,g=v;break e}}else if(b.elementType===E||typeof E=="object"&&E!==null&&E.$$typeof===gn&&Sf(E)===b.type){n(g,b.sibling),v=i(b,S.props),v.ref=Ti(g,b,S),v.return=g,g=v;break e}n(g,b);break}else e(g,b);b=b.sibling}S.type===Br?(v=cr(S.props.children,g.mode,w,S.key),v.return=g,g=v):(w=bo(S.type,S.key,S.props,null,g.mode,w),w.ref=Ti(g,v,S),w.return=g,g=w)}return o(g);case zr:e:{for(b=S.key;v!==null;){if(v.key===b)if(v.tag===4&&v.stateNode.containerInfo===S.containerInfo&&v.stateNode.implementation===S.implementation){n(g,v.sibling),v=i(v,S.children||[]),v.return=g,g=v;break e}else{n(g,v);break}else e(g,v);v=v.sibling}v=Sa(S,g.mode,w),v.return=g,g=v}return o(g);case gn:return b=S._init,x(g,v,b(S._payload),w)}if(Ii(S))return p(g,v,S,w);if(Ci(S))return m(g,v,S,w);eo(g,S)}return typeof S=="string"&&S!==""||typeof S=="number"?(S=""+S,v!==null&&v.tag===6?(n(g,v.sibling),v=i(v,S),v.return=g,g=v):(n(g,v),v=xa(S,g.mode,w),v.return=g,g=v),o(g)):n(g,v)}return x}var ai=jm(!0),zm=jm(!1),Ho=Wn(null),Wo=null,Kr=null,Oc=null;function Dc(){Oc=Kr=Wo=null}function Pc(t){var e=Ho.current;se(Ho),t._currentValue=e}function Su(t,e,n){for(;t!==null;){var r=t.alternate;if((t.childLanes&e)!==e?(t.childLanes|=e,r!==null&&(r.childLanes|=e)):r!==null&&(r.childLanes&e)!==e&&(r.childLanes|=e),t===n)break;t=t.return}}function ti(t,e){Wo=t,Oc=Kr=null,t=t.dependencies,t!==null&&t.firstContext!==null&&(t.lanes&e&&(nt=!0),t.firstContext=null)}function Et(t){var e=t._currentValue;if(Oc!==t)if(t={context:t,memoizedValue:e,next:null},Kr===null){if(Wo===null)throw Error(P(308));Kr=t,Wo.dependencies={lanes:0,firstContext:t}}else Kr=Kr.next=t;return e}var rr=null;function Ac(t){rr===null?rr=[t]:rr.push(t)}function Bm(t,e,n,r){var i=e.interleaved;return i===null?(n.next=n,Ac(e)):(n.next=i.next,i.next=n),e.interleaved=n,un(t,r)}function un(t,e){t.lanes|=e;var n=t.alternate;for(n!==null&&(n.lanes|=e),n=t,t=t.return;t!==null;)t.childLanes|=e,n=t.alternate,n!==null&&(n.childLanes|=e),n=t,t=t.return;return n.tag===3?n.stateNode:null}var yn=!1;function Ic(t){t.updateQueue={baseState:t.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Fm(t,e){t=t.updateQueue,e.updateQueue===t&&(e.updateQueue={baseState:t.baseState,firstBaseUpdate:t.firstBaseUpdate,lastBaseUpdate:t.lastBaseUpdate,shared:t.shared,effects:t.effects})}function nn(t,e){return{eventTime:t,lane:e,tag:0,payload:null,callback:null,next:null}}function In(t,e,n){var r=t.updateQueue;if(r===null)return null;if(r=r.shared,q&2){var i=r.pending;return i===null?e.next=e:(e.next=i.next,i.next=e),r.pending=e,un(t,n)}return i=r.interleaved,i===null?(e.next=e,Ac(r)):(e.next=i.next,i.next=e),r.interleaved=e,un(t,n)}function So(t,e,n){if(e=e.updateQueue,e!==null&&(e=e.shared,(n&4194240)!==0)){var r=e.lanes;r&=t.pendingLanes,n|=r,e.lanes=n,vc(t,n)}}function kf(t,e){var n=t.updateQueue,r=t.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var i=null,s=null;if(n=n.firstBaseUpdate,n!==null){do{var o={eventTime:n.eventTime,lane:n.lane,tag:n.tag,payload:n.payload,callback:n.callback,next:null};s===null?i=s=o:s=s.next=o,n=n.next}while(n!==null);s===null?i=s=e:s=s.next=e}else i=s=e;n={baseState:r.baseState,firstBaseUpdate:i,lastBaseUpdate:s,shared:r.shared,effects:r.effects},t.updateQueue=n;return}t=n.lastBaseUpdate,t===null?n.firstBaseUpdate=e:t.next=e,n.lastBaseUpdate=e}function Ko(t,e,n,r){var i=t.updateQueue;yn=!1;var s=i.firstBaseUpdate,o=i.lastBaseUpdate,l=i.shared.pending;if(l!==null){i.shared.pending=null;var a=l,u=a.next;a.next=null,o===null?s=u:o.next=u,o=a;var c=t.alternate;c!==null&&(c=c.updateQueue,l=c.lastBaseUpdate,l!==o&&(l===null?c.firstBaseUpdate=u:l.next=u,c.lastBaseUpdate=a))}if(s!==null){var d=i.baseState;o=0,c=u=a=null,l=s;do{var f=l.lane,h=l.eventTime;if((r&f)===f){c!==null&&(c=c.next={eventTime:h,lane:0,tag:l.tag,payload:l.payload,callback:l.callback,next:null});e:{var p=t,m=l;switch(f=e,h=n,m.tag){case 1:if(p=m.payload,typeof p=="function"){d=p.call(h,d,f);break e}d=p;break e;case 3:p.flags=p.flags&-65537|128;case 0:if(p=m.payload,f=typeof p=="function"?p.call(h,d,f):p,f==null)break e;d=ue({},d,f);break e;case 2:yn=!0}}l.callback!==null&&l.lane!==0&&(t.flags|=64,f=i.effects,f===null?i.effects=[l]:f.push(l))}else h={eventTime:h,lane:f,tag:l.tag,payload:l.payload,callback:l.callback,next:null},c===null?(u=c=h,a=d):c=c.next=h,o|=f;if(l=l.next,l===null){if(l=i.shared.pending,l===null)break;f=l,l=f.next,f.next=null,i.lastBaseUpdate=f,i.shared.pending=null}}while(!0);if(c===null&&(a=d),i.baseState=a,i.firstBaseUpdate=u,i.lastBaseUpdate=c,e=i.shared.interleaved,e!==null){i=e;do o|=i.lane,i=i.next;while(i!==e)}else s===null&&(i.shared.lanes=0);Sr|=o,t.lanes=o,t.memoizedState=d}}function wf(t,e,n){if(t=e.effects,e.effects=null,t!==null)for(e=0;en?n:4,t(!0);var r=pa.transition;pa.transition={};try{t(!1),e()}finally{Q=n,pa.transition=r}}function ng(){return Nt().memoizedState}function Z1(t,e,n){var r=Ln(t);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},rg(t))ig(e,n);else if(n=Bm(t,e,n,r),n!==null){var i=qe();jt(n,t,r,i),sg(n,e,r)}}function ex(t,e,n){var r=Ln(t),i={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(rg(t))ig(e,i);else{var s=t.alternate;if(t.lanes===0&&(s===null||s.lanes===0)&&(s=e.lastRenderedReducer,s!==null))try{var o=e.lastRenderedState,l=s(o,n);if(i.hasEagerState=!0,i.eagerState=l,zt(l,o)){var a=e.interleaved;a===null?(i.next=i,Ac(e)):(i.next=a.next,a.next=i),e.interleaved=i;return}}catch{}finally{}n=Bm(t,e,i,r),n!==null&&(i=qe(),jt(n,t,r,i),sg(n,e,r))}}function rg(t){var e=t.alternate;return t===ae||e!==null&&e===ae}function ig(t,e){Hi=qo=!0;var n=t.pending;n===null?e.next=e:(e.next=n.next,n.next=e),t.pending=e}function sg(t,e,n){if(n&4194240){var r=e.lanes;r&=t.pendingLanes,n|=r,e.lanes=n,vc(t,n)}}var Go={readContext:Et,useCallback:Fe,useContext:Fe,useEffect:Fe,useImperativeHandle:Fe,useInsertionEffect:Fe,useLayoutEffect:Fe,useMemo:Fe,useReducer:Fe,useRef:Fe,useState:Fe,useDebugValue:Fe,useDeferredValue:Fe,useTransition:Fe,useMutableSource:Fe,useSyncExternalStore:Fe,useId:Fe,unstable_isNewReconciler:!1},tx={readContext:Et,useCallback:function(t,e){return _t().memoizedState=[t,e===void 0?null:e],t},useContext:Et,useEffect:Ef,useImperativeHandle:function(t,e,n){return n=n!=null?n.concat([t]):null,wo(4194308,4,Ym.bind(null,e,t),n)},useLayoutEffect:function(t,e){return wo(4194308,4,t,e)},useInsertionEffect:function(t,e){return wo(4,2,t,e)},useMemo:function(t,e){var n=_t();return e=e===void 0?null:e,t=t(),n.memoizedState=[t,e],t},useReducer:function(t,e,n){var r=_t();return e=n!==void 0?n(e):e,r.memoizedState=r.baseState=e,t={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:t,lastRenderedState:e},r.queue=t,t=t.dispatch=Z1.bind(null,ae,t),[r.memoizedState,t]},useRef:function(t){var e=_t();return t={current:t},e.memoizedState=t},useState:Cf,useDebugValue:$c,useDeferredValue:function(t){return _t().memoizedState=t},useTransition:function(){var t=Cf(!1),e=t[0];return t=X1.bind(null,t[1]),_t().memoizedState=t,[e,t]},useMutableSource:function(){},useSyncExternalStore:function(t,e,n){var r=ae,i=_t();if(oe){if(n===void 0)throw Error(P(407));n=n()}else{if(n=e(),Me===null)throw Error(P(349));xr&30||Um(r,e,n)}i.memoizedState=n;var s={value:n,getSnapshot:e};return i.queue=s,Ef(Wm.bind(null,r,s,t),[t]),r.flags|=2048,ms(9,Hm.bind(null,r,s,n,e),void 0,null),n},useId:function(){var t=_t(),e=Me.identifierPrefix;if(oe){var n=en,r=Zt;n=(r&~(1<<32-Lt(r)-1)).toString(32)+n,e=":"+e+"R"+n,n=hs++,0<\/script>",t=t.removeChild(t.firstChild)):typeof r.is=="string"?t=o.createElement(n,{is:r.is}):(t=o.createElement(n),n==="select"&&(o=t,r.multiple?o.multiple=!0:r.size&&(o.size=r.size))):t=o.createElementNS(t,n),t[Vt]=e,t[cs]=r,mg(t,e,!1,!1),e.stateNode=t;e:{switch(o=nu(n,r),n){case"dialog":re("cancel",t),re("close",t),i=r;break;case"iframe":case"object":case"embed":re("load",t),i=r;break;case"video":case"audio":for(i=0;idi&&(e.flags|=128,r=!0,Oi(s,!1),e.lanes=4194304)}else{if(!r)if(t=Jo(o),t!==null){if(e.flags|=128,r=!0,n=t.updateQueue,n!==null&&(e.updateQueue=n,e.flags|=4),Oi(s,!0),s.tail===null&&s.tailMode==="hidden"&&!o.alternate&&!oe)return _e(e),null}else 2*fe()-s.renderingStartTime>di&&n!==1073741824&&(e.flags|=128,r=!0,Oi(s,!1),e.lanes=4194304);s.isBackwards?(o.sibling=e.child,e.child=o):(n=s.last,n!==null?n.sibling=o:e.child=o,s.last=o)}return s.tail!==null?(e=s.tail,s.rendering=e,s.tail=e.sibling,s.renderingStartTime=fe(),e.sibling=null,n=le.current,ne(le,r?n&1|2:n&1),e):(_e(e),null);case 22:case 23:return Jc(),r=e.memoizedState!==null,t!==null&&t.memoizedState!==null!==r&&(e.flags|=8192),r&&e.mode&1?lt&1073741824&&(_e(e),e.subtreeFlags&6&&(e.flags|=8192)):_e(e),null;case 24:return null;case 25:return null}throw Error(P(156,e.tag))}function ux(t,e){switch(Mc(e),e.tag){case 1:return it(e.type)&&_o(),t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 3:return ui(),se(rt),se(Ue),jc(),t=e.flags,t&65536&&!(t&128)?(e.flags=t&-65537|128,e):null;case 5:return Lc(e),null;case 13:if(se(le),t=e.memoizedState,t!==null&&t.dehydrated!==null){if(e.alternate===null)throw Error(P(340));li()}return t=e.flags,t&65536?(e.flags=t&-65537|128,e):null;case 19:return se(le),null;case 4:return ui(),null;case 10:return Pc(e.type._context),null;case 22:case 23:return Jc(),null;case 24:return null;default:return null}}var no=!1,Ve=!1,cx=typeof WeakSet=="function"?WeakSet:Set,R=null;function Jr(t,e){var n=t.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){ce(t,e,r)}else n.current=null}function Ou(t,e,n){try{n()}catch(r){ce(t,e,r)}}var Lf=!1;function dx(t,e){if(fu=jo,t=wm(),Nc(t)){if("selectionStart"in t)var n={start:t.selectionStart,end:t.selectionEnd};else e:{n=(n=t.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var i=r.anchorOffset,s=r.focusNode;r=r.focusOffset;try{n.nodeType,s.nodeType}catch{n=null;break e}var o=0,l=-1,a=-1,u=0,c=0,d=t,f=null;t:for(;;){for(var h;d!==n||i!==0&&d.nodeType!==3||(l=o+i),d!==s||r!==0&&d.nodeType!==3||(a=o+r),d.nodeType===3&&(o+=d.nodeValue.length),(h=d.firstChild)!==null;)f=d,d=h;for(;;){if(d===t)break t;if(f===n&&++u===i&&(l=o),f===s&&++c===r&&(a=o),(h=d.nextSibling)!==null)break;d=f,f=d.parentNode}d=h}n=l===-1||a===-1?null:{start:l,end:a}}else n=null}n=n||{start:0,end:0}}else n=null;for(hu={focusedElem:t,selectionRange:n},jo=!1,R=e;R!==null;)if(e=R,t=e.child,(e.subtreeFlags&1028)!==0&&t!==null)t.return=e,R=t;else for(;R!==null;){e=R;try{var p=e.alternate;if(e.flags&1024)switch(e.tag){case 0:case 11:case 15:break;case 1:if(p!==null){var m=p.memoizedProps,x=p.memoizedState,g=e.stateNode,v=g.getSnapshotBeforeUpdate(e.elementType===e.type?m:Pt(e.type,m),x);g.__reactInternalSnapshotBeforeUpdate=v}break;case 3:var S=e.stateNode.containerInfo;S.nodeType===1?S.textContent="":S.nodeType===9&&S.documentElement&&S.removeChild(S.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(P(163))}}catch(w){ce(e,e.return,w)}if(t=e.sibling,t!==null){t.return=e.return,R=t;break}R=e.return}return p=Lf,Lf=!1,p}function Wi(t,e,n){var r=e.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var i=r=r.next;do{if((i.tag&t)===t){var s=i.destroy;i.destroy=void 0,s!==void 0&&Ou(e,n,s)}i=i.next}while(i!==r)}}function El(t,e){if(e=e.updateQueue,e=e!==null?e.lastEffect:null,e!==null){var n=e=e.next;do{if((n.tag&t)===t){var r=n.create;n.destroy=r()}n=n.next}while(n!==e)}}function Du(t){var e=t.ref;if(e!==null){var n=t.stateNode;switch(t.tag){case 5:t=n;break;default:t=n}typeof e=="function"?e(t):e.current=t}}function vg(t){var e=t.alternate;e!==null&&(t.alternate=null,vg(e)),t.child=null,t.deletions=null,t.sibling=null,t.tag===5&&(e=t.stateNode,e!==null&&(delete e[Vt],delete e[cs],delete e[gu],delete e[J1],delete e[q1])),t.stateNode=null,t.return=null,t.dependencies=null,t.memoizedProps=null,t.memoizedState=null,t.pendingProps=null,t.stateNode=null,t.updateQueue=null}function xg(t){return t.tag===5||t.tag===3||t.tag===4}function jf(t){e:for(;;){for(;t.sibling===null;){if(t.return===null||xg(t.return))return null;t=t.return}for(t.sibling.return=t.return,t=t.sibling;t.tag!==5&&t.tag!==6&&t.tag!==18;){if(t.flags&2||t.child===null||t.tag===4)continue e;t.child.return=t,t=t.child}if(!(t.flags&2))return t.stateNode}}function Pu(t,e,n){var r=t.tag;if(r===5||r===6)t=t.stateNode,e?n.nodeType===8?n.parentNode.insertBefore(t,e):n.insertBefore(t,e):(n.nodeType===8?(e=n.parentNode,e.insertBefore(t,n)):(e=n,e.appendChild(t)),n=n._reactRootContainer,n!=null||e.onclick!==null||(e.onclick=Fo));else if(r!==4&&(t=t.child,t!==null))for(Pu(t,e,n),t=t.sibling;t!==null;)Pu(t,e,n),t=t.sibling}function Au(t,e,n){var r=t.tag;if(r===5||r===6)t=t.stateNode,e?n.insertBefore(t,e):n.appendChild(t);else if(r!==4&&(t=t.child,t!==null))for(Au(t,e,n),t=t.sibling;t!==null;)Au(t,e,n),t=t.sibling}var Ae=null,At=!1;function pn(t,e,n){for(n=n.child;n!==null;)Sg(t,e,n),n=n.sibling}function Sg(t,e,n){if(Ht&&typeof Ht.onCommitFiberUnmount=="function")try{Ht.onCommitFiberUnmount(gl,n)}catch{}switch(n.tag){case 5:Ve||Jr(n,e);case 6:var r=Ae,i=At;Ae=null,pn(t,e,n),Ae=r,At=i,Ae!==null&&(At?(t=Ae,n=n.stateNode,t.nodeType===8?t.parentNode.removeChild(n):t.removeChild(n)):Ae.removeChild(n.stateNode));break;case 18:Ae!==null&&(At?(t=Ae,n=n.stateNode,t.nodeType===8?da(t.parentNode,n):t.nodeType===1&&da(t,n),is(t)):da(Ae,n.stateNode));break;case 4:r=Ae,i=At,Ae=n.stateNode.containerInfo,At=!0,pn(t,e,n),Ae=r,At=i;break;case 0:case 11:case 14:case 15:if(!Ve&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){i=r=r.next;do{var s=i,o=s.destroy;s=s.tag,o!==void 0&&(s&2||s&4)&&Ou(n,e,o),i=i.next}while(i!==r)}pn(t,e,n);break;case 1:if(!Ve&&(Jr(n,e),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(l){ce(n,e,l)}pn(t,e,n);break;case 21:pn(t,e,n);break;case 22:n.mode&1?(Ve=(r=Ve)||n.memoizedState!==null,pn(t,e,n),Ve=r):pn(t,e,n);break;default:pn(t,e,n)}}function zf(t){var e=t.updateQueue;if(e!==null){t.updateQueue=null;var n=t.stateNode;n===null&&(n=t.stateNode=new cx),e.forEach(function(r){var i=Sx.bind(null,t,r);n.has(r)||(n.add(r),r.then(i,i))})}}function Dt(t,e){var n=e.deletions;if(n!==null)for(var r=0;ri&&(i=o),r&=~s}if(r=i,r=fe()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*hx(r/1960))-r,10t?16:t,En===null)var r=!1;else{if(t=En,En=null,Xo=0,q&6)throw Error(P(331));var i=q;for(q|=4,R=t.current;R!==null;){var s=R,o=s.child;if(R.flags&16){var l=s.deletions;if(l!==null){for(var a=0;afe()-Wc?ur(t,0):Hc|=n),st(t,e)}function Tg(t,e){e===0&&(t.mode&1?(e=Js,Js<<=1,!(Js&130023424)&&(Js=4194304)):e=1);var n=qe();t=un(t,e),t!==null&&(Ps(t,e,n),st(t,n))}function xx(t){var e=t.memoizedState,n=0;e!==null&&(n=e.retryLane),Tg(t,n)}function Sx(t,e){var n=0;switch(t.tag){case 13:var r=t.stateNode,i=t.memoizedState;i!==null&&(n=i.retryLane);break;case 19:r=t.stateNode;break;default:throw Error(P(314))}r!==null&&r.delete(e),Tg(t,n)}var Og;Og=function(t,e,n){if(t!==null)if(t.memoizedProps!==e.pendingProps||rt.current)nt=!0;else{if(!(t.lanes&n)&&!(e.flags&128))return nt=!1,lx(t,e,n);nt=!!(t.flags&131072)}else nt=!1,oe&&e.flags&1048576&&Im(e,Uo,e.index);switch(e.lanes=0,e.tag){case 2:var r=e.type;Co(t,e),t=e.pendingProps;var i=oi(e,Ue.current);ti(e,n),i=Bc(null,e,r,t,i,n);var s=Fc();return e.flags|=1,typeof i=="object"&&i!==null&&typeof i.render=="function"&&i.$$typeof===void 0?(e.tag=1,e.memoizedState=null,e.updateQueue=null,it(r)?(s=!0,$o(e)):s=!1,e.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,Ic(e),i.updater=Cl,e.stateNode=i,i._reactInternals=e,wu(e,r,t,n),e=Nu(null,e,r,!0,s,n)):(e.tag=0,oe&&s&&bc(e),Je(null,e,i,n),e=e.child),e;case 16:r=e.elementType;e:{switch(Co(t,e),t=e.pendingProps,i=r._init,r=i(r._payload),e.type=r,i=e.tag=wx(r),t=Pt(r,t),i){case 0:e=Eu(null,e,r,t,n);break e;case 1:e=Af(null,e,r,t,n);break e;case 11:e=Df(null,e,r,t,n);break e;case 14:e=Pf(null,e,r,Pt(r.type,t),n);break e}throw Error(P(306,r,""))}return e;case 0:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:Pt(r,i),Eu(t,e,r,i,n);case 1:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:Pt(r,i),Af(t,e,r,i,n);case 3:e:{if(fg(e),t===null)throw Error(P(387));r=e.pendingProps,s=e.memoizedState,i=s.element,Fm(t,e),Ko(e,r,null,n);var o=e.memoizedState;if(r=o.element,s.isDehydrated)if(s={element:r,isDehydrated:!1,cache:o.cache,pendingSuspenseBoundaries:o.pendingSuspenseBoundaries,transitions:o.transitions},e.updateQueue.baseState=s,e.memoizedState=s,e.flags&256){i=ci(Error(P(423)),e),e=If(t,e,r,n,i);break e}else if(r!==i){i=ci(Error(P(424)),e),e=If(t,e,r,n,i);break e}else for(ut=An(e.stateNode.containerInfo.firstChild),dt=e,oe=!0,It=null,n=zm(e,null,r,n),e.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(li(),r===i){e=cn(t,e,n);break e}Je(t,e,r,n)}e=e.child}return e;case 5:return _m(e),t===null&&xu(e),r=e.type,i=e.pendingProps,s=t!==null?t.memoizedProps:null,o=i.children,pu(r,i)?o=null:s!==null&&pu(r,s)&&(e.flags|=32),dg(t,e),Je(t,e,o,n),e.child;case 6:return t===null&&xu(e),null;case 13:return hg(t,e,n);case 4:return Rc(e,e.stateNode.containerInfo),r=e.pendingProps,t===null?e.child=ai(e,null,r,n):Je(t,e,r,n),e.child;case 11:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:Pt(r,i),Df(t,e,r,i,n);case 7:return Je(t,e,e.pendingProps,n),e.child;case 8:return Je(t,e,e.pendingProps.children,n),e.child;case 12:return Je(t,e,e.pendingProps.children,n),e.child;case 10:e:{if(r=e.type._context,i=e.pendingProps,s=e.memoizedProps,o=i.value,ne(Ho,r._currentValue),r._currentValue=o,s!==null)if(zt(s.value,o)){if(s.children===i.children&&!rt.current){e=cn(t,e,n);break e}}else for(s=e.child,s!==null&&(s.return=e);s!==null;){var l=s.dependencies;if(l!==null){o=s.child;for(var a=l.firstContext;a!==null;){if(a.context===r){if(s.tag===1){a=nn(-1,n&-n),a.tag=2;var u=s.updateQueue;if(u!==null){u=u.shared;var c=u.pending;c===null?a.next=a:(a.next=c.next,c.next=a),u.pending=a}}s.lanes|=n,a=s.alternate,a!==null&&(a.lanes|=n),Su(s.return,n,e),l.lanes|=n;break}a=a.next}}else if(s.tag===10)o=s.type===e.type?null:s.child;else if(s.tag===18){if(o=s.return,o===null)throw Error(P(341));o.lanes|=n,l=o.alternate,l!==null&&(l.lanes|=n),Su(o,n,e),o=s.sibling}else o=s.child;if(o!==null)o.return=s;else for(o=s;o!==null;){if(o===e){o=null;break}if(s=o.sibling,s!==null){s.return=o.return,o=s;break}o=o.return}s=o}Je(t,e,i.children,n),e=e.child}return e;case 9:return i=e.type,r=e.pendingProps.children,ti(e,n),i=Et(i),r=r(i),e.flags|=1,Je(t,e,r,n),e.child;case 14:return r=e.type,i=Pt(r,e.pendingProps),i=Pt(r.type,i),Pf(t,e,r,i,n);case 15:return ug(t,e,e.type,e.pendingProps,n);case 17:return r=e.type,i=e.pendingProps,i=e.elementType===r?i:Pt(r,i),Co(t,e),e.tag=1,it(r)?(t=!0,$o(e)):t=!1,ti(e,n),og(e,r,i),wu(e,r,i,n),Nu(null,e,r,!0,t,n);case 19:return pg(t,e,n);case 22:return cg(t,e,n)}throw Error(P(156,e.tag))};function Dg(t,e){return rm(t,e)}function kx(t,e,n,r){this.tag=t,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=e,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function St(t,e,n,r){return new kx(t,e,n,r)}function Gc(t){return t=t.prototype,!(!t||!t.isReactComponent)}function wx(t){if(typeof t=="function")return Gc(t)?1:0;if(t!=null){if(t=t.$$typeof,t===pc)return 11;if(t===mc)return 14}return 2}function jn(t,e){var n=t.alternate;return n===null?(n=St(t.tag,e,t.key,t.mode),n.elementType=t.elementType,n.type=t.type,n.stateNode=t.stateNode,n.alternate=t,t.alternate=n):(n.pendingProps=e,n.type=t.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=t.flags&14680064,n.childLanes=t.childLanes,n.lanes=t.lanes,n.child=t.child,n.memoizedProps=t.memoizedProps,n.memoizedState=t.memoizedState,n.updateQueue=t.updateQueue,e=t.dependencies,n.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext},n.sibling=t.sibling,n.index=t.index,n.ref=t.ref,n}function bo(t,e,n,r,i,s){var o=2;if(r=t,typeof t=="function")Gc(t)&&(o=1);else if(typeof t=="string")o=5;else e:switch(t){case Br:return cr(n.children,i,s,e);case hc:o=8,i|=8;break;case Ka:return t=St(12,n,e,i|2),t.elementType=Ka,t.lanes=s,t;case Ja:return t=St(13,n,e,i),t.elementType=Ja,t.lanes=s,t;case qa:return t=St(19,n,e,i),t.elementType=qa,t.lanes=s,t;case _p:return bl(n,i,s,e);default:if(typeof t=="object"&&t!==null)switch(t.$$typeof){case Bp:o=10;break e;case Fp:o=9;break e;case pc:o=11;break e;case mc:o=14;break e;case gn:o=16,r=null;break e}throw Error(P(130,t==null?t:typeof t,""))}return e=St(o,n,e,i),e.elementType=t,e.type=r,e.lanes=s,e}function cr(t,e,n,r){return t=St(7,t,r,e),t.lanes=n,t}function bl(t,e,n,r){return t=St(22,t,r,e),t.elementType=_p,t.lanes=n,t.stateNode={isHidden:!1},t}function xa(t,e,n){return t=St(6,t,null,e),t.lanes=n,t}function Sa(t,e,n){return e=St(4,t.children!==null?t.children:[],t.key,e),e.lanes=n,e.stateNode={containerInfo:t.containerInfo,pendingChildren:null,implementation:t.implementation},e}function Cx(t,e,n,r,i){this.tag=e,this.containerInfo=t,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=ea(0),this.expirationTimes=ea(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=ea(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function Qc(t,e,n,r,i,s,o,l,a){return t=new Cx(t,e,n,l,a),e===1?(e=1,s===!0&&(e|=8)):e=0,s=St(3,null,null,e),t.current=s,s.stateNode=t,s.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},Ic(s),t}function Ex(t,e,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Rg)}catch(t){console.error(t)}}Rg(),Rp.exports=pt;var Pl=Rp.exports;const Ox=wp(Pl);var Wf=Pl;Ha.createRoot=Wf.createRoot,Ha.hydrateRoot=Wf.hydrateRoot;/** + * @remix-run/router v1.23.2 + * + * Copyright (c) Remix Software Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE.md file in the root directory of this source tree. + * + * @license MIT + */function ys(){return ys=Object.assign?Object.assign.bind():function(t){for(var e=1;e"u")throw new Error(e)}function ed(t,e){if(!t){typeof console<"u"&&console.warn(e);try{throw new Error(e)}catch{}}}function Px(){return Math.random().toString(36).substr(2,8)}function Jf(t,e){return{usr:t.state,key:t.key,idx:e}}function zu(t,e,n,r){return n===void 0&&(n=null),ys({pathname:typeof t=="string"?t:t.pathname,search:"",hash:""},typeof e=="string"?xi(e):e,{state:n,key:e&&e.key||r||Px()})}function Lg(t){let{pathname:e="/",search:n="",hash:r=""}=t;return n&&n!=="?"&&(e+=n.charAt(0)==="?"?n:"?"+n),r&&r!=="#"&&(e+=r.charAt(0)==="#"?r:"#"+r),e}function xi(t){let e={};if(t){let n=t.indexOf("#");n>=0&&(e.hash=t.substr(n),t=t.substr(0,n));let r=t.indexOf("?");r>=0&&(e.search=t.substr(r),t=t.substr(0,r)),t&&(e.pathname=t)}return e}function Ax(t,e,n,r){r===void 0&&(r={});let{window:i=document.defaultView,v5Compat:s=!1}=r,o=i.history,l=Nn.Pop,a=null,u=c();u==null&&(u=0,o.replaceState(ys({},o.state,{idx:u}),""));function c(){return(o.state||{idx:null}).idx}function d(){l=Nn.Pop;let x=c(),g=x==null?null:x-u;u=x,a&&a({action:l,location:m.location,delta:g})}function f(x,g){l=Nn.Push;let v=zu(m.location,x,g);u=c()+1;let S=Jf(v,u),w=m.createHref(v);try{o.pushState(S,"",w)}catch(E){if(E instanceof DOMException&&E.name==="DataCloneError")throw E;i.location.assign(w)}s&&a&&a({action:l,location:m.location,delta:1})}function h(x,g){l=Nn.Replace;let v=zu(m.location,x,g);u=c();let S=Jf(v,u),w=m.createHref(v);o.replaceState(S,"",w),s&&a&&a({action:l,location:m.location,delta:0})}function p(x){let g=i.location.origin!=="null"?i.location.origin:i.location.href,v=typeof x=="string"?x:Lg(x);return v=v.replace(/ $/,"%20"),xe(g,"No window.location.(origin|href) available to create URL for href: "+v),new URL(v,g)}let m={get action(){return l},get location(){return t(i,o)},listen(x){if(a)throw new Error("A history only accepts one active listener");return i.addEventListener(Kf,d),a=x,()=>{i.removeEventListener(Kf,d),a=null}},createHref(x){return e(i,x)},createURL:p,encodeLocation(x){let g=p(x);return{pathname:g.pathname,search:g.search,hash:g.hash}},push:f,replace:h,go(x){return o.go(x)}};return m}var qf;(function(t){t.data="data",t.deferred="deferred",t.redirect="redirect",t.error="error"})(qf||(qf={}));function Ix(t,e,n){return n===void 0&&(n="/"),Rx(t,e,n)}function Rx(t,e,n,r){let i=typeof e=="string"?xi(e):e,s=Bg(i.pathname||"/",n);if(s==null)return null;let o=jg(t);Lx(o);let l=null;for(let a=0;l==null&&a{let a={relativePath:l===void 0?s.path||"":l,caseSensitive:s.caseSensitive===!0,childrenIndex:o,route:s};a.relativePath.startsWith("/")&&(xe(a.relativePath.startsWith(r),'Absolute route path "'+a.relativePath+'" nested under path '+('"'+r+'" is not valid. An absolute child route path ')+"must start with the combined path of all its parent routes."),a.relativePath=a.relativePath.slice(r.length));let u=dr([r,a.relativePath]),c=n.concat(a);s.children&&s.children.length>0&&(xe(s.index!==!0,"Index routes must not have child routes. Please remove "+('all child routes from route path "'+u+'".')),jg(s.children,e,c,u)),!(s.path==null&&!s.index)&&e.push({path:u,score:Vx(u,s.index),routesMeta:c})};return t.forEach((s,o)=>{var l;if(s.path===""||!((l=s.path)!=null&&l.includes("?")))i(s,o);else for(let a of zg(s.path))i(s,o,a)}),e}function zg(t){let e=t.split("/");if(e.length===0)return[];let[n,...r]=e,i=n.endsWith("?"),s=n.replace(/\?$/,"");if(r.length===0)return i?[s,""]:[s];let o=zg(r.join("/")),l=[];return l.push(...o.map(a=>a===""?s:[s,a].join("/"))),i&&l.push(...o),l.map(a=>t.startsWith("/")&&a===""?"/":a)}function Lx(t){t.sort((e,n)=>e.score!==n.score?n.score-e.score:Ux(e.routesMeta.map(r=>r.childrenIndex),n.routesMeta.map(r=>r.childrenIndex)))}const jx=/^:[\w-]+$/,zx=3,Bx=2,Fx=1,_x=10,$x=-2,Gf=t=>t==="*";function Vx(t,e){let n=t.split("/"),r=n.length;return n.some(Gf)&&(r+=$x),e&&(r+=Bx),n.filter(i=>!Gf(i)).reduce((i,s)=>i+(jx.test(s)?zx:s===""?Fx:_x),r)}function Ux(t,e){return t.length===e.length&&t.slice(0,-1).every((r,i)=>r===e[i])?t[t.length-1]-e[e.length-1]:0}function Hx(t,e,n){let{routesMeta:r}=t,i={},s="/",o=[];for(let l=0;l{let{paramName:f,isOptional:h}=c;if(f==="*"){let m=l[d]||"";o=s.slice(0,s.length-m.length).replace(/(.)\/+$/,"$1")}const p=l[d];return h&&!p?u[f]=void 0:u[f]=(p||"").replace(/%2F/g,"/"),u},{}),pathname:s,pathnameBase:o,pattern:t}}function Kx(t,e,n){e===void 0&&(e=!1),n===void 0&&(n=!0),ed(t==="*"||!t.endsWith("*")||t.endsWith("/*"),'Route path "'+t+'" will be treated as if it were '+('"'+t.replace(/\*$/,"/*")+'" because the `*` character must ')+"always follow a `/` in the pattern. To get rid of this warning, "+('please change the route path to "'+t.replace(/\*$/,"/*")+'".'));let r=[],i="^"+t.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(o,l,a)=>(r.push({paramName:l,isOptional:a!=null}),a?"/?([^\\/]+)?":"/([^\\/]+)"));return t.endsWith("*")?(r.push({paramName:"*"}),i+=t==="*"||t==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):n?i+="\\/*$":t!==""&&t!=="/"&&(i+="(?:(?=\\/|$))"),[new RegExp(i,e?void 0:"i"),r]}function Jx(t){try{return t.split("/").map(e=>decodeURIComponent(e).replace(/\//g,"%2F")).join("/")}catch(e){return ed(!1,'The URL path "'+t+'" could not be decoded because it is is a malformed URL segment. This is probably due to a bad percent '+("encoding ("+e+").")),t}}function Bg(t,e){if(e==="/")return t;if(!t.toLowerCase().startsWith(e.toLowerCase()))return null;let n=e.endsWith("/")?e.length-1:e.length,r=t.charAt(n);return r&&r!=="/"?null:t.slice(n)||"/"}const qx=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,Gx=t=>qx.test(t);function Qx(t,e){e===void 0&&(e="/");let{pathname:n,search:r="",hash:i=""}=typeof t=="string"?xi(t):t,s;if(n)if(Gx(n))s=n;else{if(n.includes("//")){let o=n;n=n.replace(/\/\/+/g,"/"),ed(!1,"Pathnames cannot have embedded double slashes - normalizing "+(o+" -> "+n))}n.startsWith("/")?s=Qf(n.substring(1),"/"):s=Qf(n,e)}else s=e;return{pathname:s,search:Zx(r),hash:eS(i)}}function Qf(t,e){let n=e.replace(/\/+$/,"").split("/");return t.split("/").forEach(i=>{i===".."?n.length>1&&n.pop():i!=="."&&n.push(i)}),n.length>1?n.join("/"):"/"}function ka(t,e,n,r){return"Cannot include a '"+t+"' character in a manually specified "+("`to."+e+"` field ["+JSON.stringify(r)+"]. Please separate it out to the ")+("`to."+n+"` field. Alternatively you may provide the full path as ")+'a string in and the router will parse it for you.'}function Yx(t){return t.filter((e,n)=>n===0||e.route.path&&e.route.path.length>0)}function Fg(t,e){let n=Yx(t);return e?n.map((r,i)=>i===n.length-1?r.pathname:r.pathnameBase):n.map(r=>r.pathnameBase)}function _g(t,e,n,r){r===void 0&&(r=!1);let i;typeof t=="string"?i=xi(t):(i=ys({},t),xe(!i.pathname||!i.pathname.includes("?"),ka("?","pathname","search",i)),xe(!i.pathname||!i.pathname.includes("#"),ka("#","pathname","hash",i)),xe(!i.search||!i.search.includes("#"),ka("#","search","hash",i)));let s=t===""||i.pathname==="",o=s?"/":i.pathname,l;if(o==null)l=n;else{let d=e.length-1;if(!r&&o.startsWith("..")){let f=o.split("/");for(;f[0]==="..";)f.shift(),d-=1;i.pathname=f.join("/")}l=d>=0?e[d]:"/"}let a=Qx(i,l),u=o&&o!=="/"&&o.endsWith("/"),c=(s||o===".")&&n.endsWith("/");return!a.pathname.endsWith("/")&&(u||c)&&(a.pathname+="/"),a}const dr=t=>t.join("/").replace(/\/\/+/g,"/"),Xx=t=>t.replace(/\/+$/,"").replace(/^\/*/,"/"),Zx=t=>!t||t==="?"?"":t.startsWith("?")?t:"?"+t,eS=t=>!t||t==="#"?"":t.startsWith("#")?t:"#"+t;function tS(t){return t!=null&&typeof t.status=="number"&&typeof t.statusText=="string"&&typeof t.internal=="boolean"&&"data"in t}const $g=["post","put","patch","delete"];new Set($g);const nS=["get",...$g];new Set(nS);/** + * React Router v6.30.3 + * + * Copyright (c) Remix Software Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE.md file in the root directory of this source tree. + * + * @license MIT + */function vs(){return vs=Object.assign?Object.assign.bind():function(t){for(var e=1;e{l.current=!0}),k.useCallback(function(u,c){if(c===void 0&&(c={}),!l.current)return;if(typeof u=="number"){r.go(u);return}let d=_g(u,JSON.parse(o),s,c.relative==="path");t==null&&e!=="/"&&(d.pathname=d.pathname==="/"?e:dr([e,d.pathname])),(c.replace?r.replace:r.push)(d,c.state,c)},[e,r,o,s,t])}function sS(){let{matches:t}=k.useContext(Jn),e=t[t.length-1];return e?e.params:{}}function oS(t,e){return lS(t,e)}function lS(t,e,n,r){js()||xe(!1);let{navigator:i}=k.useContext(Ls),{matches:s}=k.useContext(Jn),o=s[s.length-1],l=o?o.params:{};o&&o.pathname;let a=o?o.pathnameBase:"/";o&&o.route;let u=nd(),c;if(e){var d;let x=typeof e=="string"?xi(e):e;a==="/"||(d=x.pathname)!=null&&d.startsWith(a)||xe(!1),c=x}else c=u;let f=c.pathname||"/",h=f;if(a!=="/"){let x=a.replace(/^\//,"").split("/");h="/"+f.replace(/^\//,"").split("/").slice(x.length).join("/")}let p=Ix(t,{pathname:h}),m=fS(p&&p.map(x=>Object.assign({},x,{params:Object.assign({},l,x.params),pathname:dr([a,i.encodeLocation?i.encodeLocation(x.pathname).pathname:x.pathname]),pathnameBase:x.pathnameBase==="/"?a:dr([a,i.encodeLocation?i.encodeLocation(x.pathnameBase).pathname:x.pathnameBase])})),s,n,r);return e&&m?k.createElement(Al.Provider,{value:{location:vs({pathname:"/",search:"",hash:"",state:null,key:"default"},c),navigationType:Nn.Pop}},m):m}function aS(){let t=gS(),e=tS(t)?t.status+" "+t.statusText:t instanceof Error?t.message:JSON.stringify(t),n=t instanceof Error?t.stack:null,i={padding:"0.5rem",backgroundColor:"rgba(200,200,200, 0.5)"};return k.createElement(k.Fragment,null,k.createElement("h2",null,"Unexpected Application Error!"),k.createElement("h3",{style:{fontStyle:"italic"}},e),n?k.createElement("pre",{style:i},n):null,null)}const uS=k.createElement(aS,null);class cS extends k.Component{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,n){return n.location!==e.location||n.revalidation!=="idle"&&e.revalidation==="idle"?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error!==void 0?e.error:n.error,location:n.location,revalidation:e.revalidation||n.revalidation}}componentDidCatch(e,n){console.error("React Router caught the following error during render",e,n)}render(){return this.state.error!==void 0?k.createElement(Jn.Provider,{value:this.props.routeContext},k.createElement(Vg.Provider,{value:this.state.error,children:this.props.component})):this.props.children}}function dS(t){let{routeContext:e,match:n,children:r}=t,i=k.useContext(td);return i&&i.static&&i.staticContext&&(n.route.errorElement||n.route.ErrorBoundary)&&(i.staticContext._deepestRenderedBoundaryId=n.route.id),k.createElement(Jn.Provider,{value:e},r)}function fS(t,e,n,r){var i;if(e===void 0&&(e=[]),n===void 0&&(n=null),r===void 0&&(r=null),t==null){var s;if(!n)return null;if(n.errors)t=n.matches;else if((s=r)!=null&&s.v7_partialHydration&&e.length===0&&!n.initialized&&n.matches.length>0)t=n.matches;else return null}let o=t,l=(i=n)==null?void 0:i.errors;if(l!=null){let c=o.findIndex(d=>d.route.id&&(l==null?void 0:l[d.route.id])!==void 0);c>=0||xe(!1),o=o.slice(0,Math.min(o.length,c+1))}let a=!1,u=-1;if(n&&r&&r.v7_partialHydration)for(let c=0;c=0?o=o.slice(0,u+1):o=[o[0]];break}}}return o.reduceRight((c,d,f)=>{let h,p=!1,m=null,x=null;n&&(h=l&&d.route.id?l[d.route.id]:void 0,m=d.route.errorElement||uS,a&&(u<0&&f===0?(vS("route-fallback"),p=!0,x=null):u===f&&(p=!0,x=d.route.hydrateFallbackElement||null)));let g=e.concat(o.slice(0,f+1)),v=()=>{let S;return h?S=m:p?S=x:d.route.Component?S=k.createElement(d.route.Component,null):d.route.element?S=d.route.element:S=c,k.createElement(dS,{match:d,routeContext:{outlet:c,matches:g,isDataRoute:n!=null},children:S})};return n&&(d.route.ErrorBoundary||d.route.errorElement||f===0)?k.createElement(cS,{location:n.location,revalidation:n.revalidation,component:m,error:h,children:v(),routeContext:{outlet:null,matches:g,isDataRoute:!0}}):v()},null)}var Hg=function(t){return t.UseBlocker="useBlocker",t.UseRevalidator="useRevalidator",t.UseNavigateStable="useNavigate",t}(Hg||{}),Wg=function(t){return t.UseBlocker="useBlocker",t.UseLoaderData="useLoaderData",t.UseActionData="useActionData",t.UseRouteError="useRouteError",t.UseNavigation="useNavigation",t.UseRouteLoaderData="useRouteLoaderData",t.UseMatches="useMatches",t.UseRevalidator="useRevalidator",t.UseNavigateStable="useNavigate",t.UseRouteId="useRouteId",t}(Wg||{});function hS(t){let e=k.useContext(td);return e||xe(!1),e}function pS(t){let e=k.useContext(rS);return e||xe(!1),e}function mS(t){let e=k.useContext(Jn);return e||xe(!1),e}function Kg(t){let e=mS(),n=e.matches[e.matches.length-1];return n.route.id||xe(!1),n.route.id}function gS(){var t;let e=k.useContext(Vg),n=pS(),r=Kg();return e!==void 0?e:(t=n.errors)==null?void 0:t[r]}function yS(){let{router:t}=hS(Hg.UseNavigateStable),e=Kg(Wg.UseNavigateStable),n=k.useRef(!1);return Ug(()=>{n.current=!0}),k.useCallback(function(i,s){s===void 0&&(s={}),n.current&&(typeof i=="number"?t.navigate(i):t.navigate(i,vs({fromRouteId:e},s)))},[t,e])}const Yf={};function vS(t,e,n){Yf[t]||(Yf[t]=!0)}function xS(t,e){t==null||t.v7_startTransition,t==null||t.v7_relativeSplatPath}function so(t){let{to:e,replace:n,state:r,relative:i}=t;js()||xe(!1);let{future:s,static:o}=k.useContext(Ls),{matches:l}=k.useContext(Jn),{pathname:a}=nd(),u=rd(),c=_g(e,Fg(l,s.v7_relativeSplatPath),a,i==="path"),d=JSON.stringify(c);return k.useEffect(()=>u(JSON.parse(d),{replace:n,state:r,relative:i}),[u,d,i,n,r]),null}function Rr(t){xe(!1)}function SS(t){let{basename:e="/",children:n=null,location:r,navigationType:i=Nn.Pop,navigator:s,static:o=!1,future:l}=t;js()&&xe(!1);let a=e.replace(/^\/*/,"/"),u=k.useMemo(()=>({basename:a,navigator:s,static:o,future:vs({v7_relativeSplatPath:!1},l)}),[a,l,s,o]);typeof r=="string"&&(r=xi(r));let{pathname:c="/",search:d="",hash:f="",state:h=null,key:p="default"}=r,m=k.useMemo(()=>{let x=Bg(c,a);return x==null?null:{location:{pathname:x,search:d,hash:f,state:h,key:p},navigationType:i}},[a,c,d,f,h,p,i]);return m==null?null:k.createElement(Ls.Provider,{value:u},k.createElement(Al.Provider,{children:n,value:m}))}function kS(t){let{children:e,location:n}=t;return oS(Bu(e),n)}new Promise(()=>{});function Bu(t,e){e===void 0&&(e=[]);let n=[];return k.Children.forEach(t,(r,i)=>{if(!k.isValidElement(r))return;let s=[...e,i];if(r.type===k.Fragment){n.push.apply(n,Bu(r.props.children,s));return}r.type!==Rr&&xe(!1),!r.props.index||!r.props.children||xe(!1);let o={id:r.props.id||s.join("-"),caseSensitive:r.props.caseSensitive,element:r.props.element,Component:r.props.Component,index:r.props.index,path:r.props.path,loader:r.props.loader,action:r.props.action,errorElement:r.props.errorElement,ErrorBoundary:r.props.ErrorBoundary,hasErrorBoundary:r.props.ErrorBoundary!=null||r.props.errorElement!=null,shouldRevalidate:r.props.shouldRevalidate,handle:r.props.handle,lazy:r.props.lazy};r.props.children&&(o.children=Bu(r.props.children,s)),n.push(o)}),n}/** + * React Router DOM v6.30.3 + * + * Copyright (c) Remix Software Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE.md file in the root directory of this source tree. + * + * @license MIT + */const wS="6";try{window.__reactRouterVersion=wS}catch{}const CS="startTransition",Xf=vv[CS];function ES(t){let{basename:e,children:n,future:r,window:i}=t,s=k.useRef();s.current==null&&(s.current=Dx({window:i,v5Compat:!0}));let o=s.current,[l,a]=k.useState({action:o.action,location:o.location}),{v7_startTransition:u}=r||{},c=k.useCallback(d=>{u&&Xf?Xf(()=>a(d)):a(d)},[a,u]);return k.useLayoutEffect(()=>o.listen(c),[o,c]),k.useEffect(()=>xS(r),[r]),k.createElement(SS,{basename:e,children:n,location:l.location,navigationType:l.action,navigator:o,future:r})}var Zf;(function(t){t.UseScrollRestoration="useScrollRestoration",t.UseSubmit="useSubmit",t.UseSubmitFetcher="useSubmitFetcher",t.UseFetcher="useFetcher",t.useViewTransitionState="useViewTransitionState"})(Zf||(Zf={}));var eh;(function(t){t.UseFetcher="useFetcher",t.UseFetchers="useFetchers",t.UseScrollRestoration="useScrollRestoration"})(eh||(eh={}));const id="sw-token";function sd(){return localStorage.getItem(id)}function NS(t){localStorage.setItem(id,t)}function Jg(){localStorage.removeItem(id)}function bS(){const t=sd();if(!t)return null;try{const e=JSON.parse(atob(t.split(".")[1]));return e.exp*1e3({}));if(!l.ok)throw Object.assign(new Error(a.error||"Request failed"),{status:l.status});return a}async function th(t){var o,l;const e=sd(),n=await fetch(t,{headers:{Authorization:`Bearer ${e}`}});if(!n.ok)throw new Error("Export failed");const r=await n.blob(),i=((l=(o=n.headers.get("content-disposition"))==null?void 0:o.match(/filename="([^"]+)"/))==null?void 0:l[1])||"export",s=document.createElement("a");s.href=URL.createObjectURL(r),s.download=i,s.click(),URL.revokeObjectURL(s.href)}const ie={login:async(t,e)=>{const n=await Ee("POST","/api/auth/login",{username:t,password:e});return NS(n.token),n.user},logout:Jg,changePassword:(t,e)=>Ee("PUT","/api/auth/password",{current:t,newPassword:e}),getStories:()=>Ee("GET","/api/stories"),getStory:t=>Ee("GET",`/api/stories/${t}`),createStory:t=>Ee("POST","/api/stories",t),updateStory:(t,e)=>Ee("PUT",`/api/stories/${t}`,e),deleteStory:t=>Ee("DELETE",`/api/stories/${t}`),uploadImage:async t=>{const e=new FormData;return e.append("file",t),(await Ee("POST","/api/images",e)).url},getNotes:t=>Ee("GET",`/api/stories/${t}/notes`),createNote:t=>Ee("POST",`/api/stories/${t}/notes`),updateNote:(t,e,n)=>Ee("PUT",`/api/stories/${t}/notes/${e}`,n),deleteNote:(t,e)=>Ee("DELETE",`/api/stories/${t}/notes/${e}`),lintCheck:(t,e="en-US")=>Ee("POST","/api/lint/check",{text:t,language:e}),getPrompt:()=>Ee("GET","/api/prompts"),exportEpub:t=>th(`/api/stories/${t}/export/epub`),exportOdt:t=>th(`/api/stories/${t}/export/odt`),admin:{getUsers:t=>Ee("GET","/api/admin/users",null,{"x-admin-password":t}),createUser:(t,e)=>Ee("POST","/api/admin/users",e,{"x-admin-password":t}),resetPassword:(t,e,n)=>Ee("PUT",`/api/admin/users/${e}/password`,{password:n},{"x-admin-password":t}),deleteUser:(t,e)=>Ee("DELETE",`/api/admin/users/${e}`,null,{"x-admin-password":t})}},qg=k.createContext(null);function MS({children:t}){const[e,n]=k.useState([]),r=k.useCallback((i,s="info")=>{const o=Date.now()+Math.random();n(l=>[...l,{id:o,message:i,type:s}]),setTimeout(()=>n(l=>l.filter(a=>a.id!==o)),4e3)},[]);return y.jsxs(qg.Provider,{value:r,children:[t,y.jsx("div",{className:"toast-container","aria-live":"polite",children:e.map(i=>y.jsx("div",{className:`toast toast--${i.type}`,children:i.message},i.id))})]})}function od(){return k.useContext(qg)}const Gg=k.createContext(null);function TS({children:t}){const[e,n]=k.useState(null),r=k.useCallback((s,o={})=>new Promise(l=>n({message:s,opts:o,resolve:l})),[]);function i(s){e==null||e.resolve(s),n(null)}return y.jsxs(Gg.Provider,{value:r,children:[t,e&&y.jsx("div",{className:"confirm-backdrop",onClick:()=>i(!1),children:y.jsxs("div",{className:"confirm-box",onClick:s=>s.stopPropagation(),role:"dialog","aria-modal":!0,children:[y.jsx("p",{className:"confirm-message",children:e.message}),y.jsxs("div",{className:"confirm-actions",children:[y.jsx("button",{className:"btn btn-ghost",onClick:()=>i(!1),children:e.opts.cancelLabel||"Cancel"}),y.jsx("button",{className:"btn btn-primary",style:e.opts.danger?{background:"var(--danger)",borderColor:"var(--danger)"}:{},onClick:()=>i(!0),autoFocus:!0,children:e.opts.confirmLabel||"OK"})]})]})})]})}function ld(){return k.useContext(Gg)}function OS({onLogin:t}){const[e,n]=k.useState(""),[r,i]=k.useState(""),[s,o]=k.useState(""),[l,a]=k.useState(!1);async function u(c){c.preventDefault(),a(!0),o("");try{const d=await ie.login(e,r);t(d)}catch(d){o(d.message||"Wrong username or password")}finally{a(!1)}}return y.jsx("div",{className:"login-page",children:y.jsxs("div",{className:"login-box",children:[y.jsx("div",{className:"login-quill",children:"✍"}),y.jsx("h1",{className:"login-title",children:"Grimoire"}),y.jsx("p",{className:"login-sub",children:"Your stories, your magic"}),y.jsxs("form",{onSubmit:u,className:"login-form",children:[y.jsx("input",{type:"text",placeholder:"Username",value:e,onChange:c=>n(c.target.value),required:!0,className:"input",autoComplete:"username",autoCapitalize:"none"}),y.jsx("input",{type:"password",placeholder:"Password",value:r,onChange:c=>i(c.target.value),required:!0,className:"input",autoComplete:"current-password"}),s&&y.jsx("p",{className:"error-msg",children:s}),y.jsx("button",{type:"submit",className:"btn btn-primary",disabled:l,children:l?"Opening…":"Enter"})]})]})})}const Qg="sw-streak",ad="sw-goal";function Gr(){return new Date().toISOString().slice(0,10)}function DS(){return new Date(Date.now()-864e5).toISOString().slice(0,10)}function Yg(){try{return JSON.parse(localStorage.getItem(Qg))||{lastDate:null,streak:0}}catch{return{lastDate:null,streak:0}}}function PS(){const t=Gr(),e=Yg();if(e.lastDate===t)return e.streak;const n={lastDate:t,streak:e.lastDate===DS()?e.streak+1:1};return localStorage.setItem(Qg,JSON.stringify(n)),n.streak}function ud(){try{const t=JSON.parse(localStorage.getItem(ad));return t?t.date===Gr()?t:{...t,date:Gr(),count:0}:{target:0,date:Gr(),count:0}}catch{return{target:0,date:Gr(),count:0}}}function AS(t){localStorage.setItem(ad,JSON.stringify({...ud(),target:t}))}function IS(t){if(t<=0)return 0;const e=ud(),n={...e,date:Gr(),count:(e.count||0)+t};return localStorage.setItem(ad,JSON.stringify(n)),n.count}function RS(t){return!t||typeof t!="object"?0:JSON.stringify(t).replace(/"[^"]*":/g," ").replace(/[^a-zA-Z\s]/g," ").trim().split(/\s+/).filter(n=>n.length>1).length}function LS(t){const e=Date.now()-new Date(t),n=Math.floor(e/6e4);if(n<1)return"just now";if(n<60)return`${n}m ago`;const r=Math.floor(n/60);if(r<24)return`${r}h ago`;const i=Math.floor(r/24);return i<7?`${i}d ago`:new Date(t).toLocaleDateString()}function jS({story:t,onClick:e,onDelete:n}){const r=t.cover_image||null,i=RS(t.content);return y.jsxs("div",{className:"story-card",onClick:e,role:"button",tabIndex:0,onKeyDown:s=>s.key==="Enter"&&e(),children:[r?y.jsx("img",{src:r,alt:"",className:"story-card-cover"}):y.jsx("div",{className:"story-card-placeholder"}),y.jsxs("div",{className:"story-card-body",children:[y.jsx("h2",{className:"story-card-title",children:t.title}),y.jsxs("p",{className:"story-card-meta",children:[i," words · ",LS(t.updated_at)]}),y.jsx("button",{className:"story-card-delete",onClick:n,title:"Delete story","aria-label":"Delete story",children:"×"})]})]})}function zS({onLogout:t}){const[e,n]=k.useState([]),[r,i]=k.useState(!0),[s,o]=k.useState(""),[l,a]=k.useState(0),[u,c]=k.useState({target:0,count:0}),[d,f]=k.useState(!1),[h,p]=k.useState(""),[m,x]=k.useState(!1),[g,v]=k.useState({current:"",next:"",confirm:""}),[S,w]=k.useState(""),[E,b]=k.useState(!1),C=rd(),M=ld(),_=od();k.useEffect(()=>{ie.getStories().then(n).catch(()=>_("Could not load stories","error")).finally(()=>i(!1)),a(Yg().streak),c(ud())},[]);const N=e.filter(U=>!s||U.title.toLowerCase().includes(s.toLowerCase()));async function T(){const U=await ie.createStory({title:"Untitled Story",content:{}});C(`/story/${U.id}`)}async function V(U,D,j){U.stopPropagation(),await M(`Delete "${j}"? This cannot be undone.`,{confirmLabel:"Delete",cancelLabel:"Keep it",danger:!0})&&(await ie.deleteStory(D),n(A=>A.filter($=>$.id!==D)),_("Story deleted"))}function G(){ie.logout(),t()}async function Y(U){if(U.preventDefault(),w(""),g.next!==g.confirm){w("Passwords do not match");return}if(g.next.length<6){w("New password must be at least 6 characters");return}try{await ie.changePassword(g.current,g.next),b(!0),v({current:"",next:"",confirm:""}),setTimeout(()=>{x(!1),b(!1)},1500)}catch(D){w(D.message)}}function ke(U){U.preventDefault();const D=parseInt(h);!D||D<1||(AS(D),c(j=>({...j,target:D})),f(!1),_(`Daily goal set to ${D} words`))}const X=u.target>0?Math.min(100,Math.round(u.count/u.target*100)):0;return y.jsxs("div",{className:"stories-page",children:[y.jsxs("header",{className:"stories-header",children:[y.jsx("h1",{className:"page-title",children:"My Stories"}),y.jsxs("div",{className:"header-actions",children:[y.jsx("button",{onClick:T,className:"btn btn-primary",children:"+ New Story"}),y.jsx("button",{onClick:()=>{x(U=>!U),w(""),b(!1)},className:"btn btn-ghost",children:"Password"}),y.jsx("button",{onClick:G,className:"btn btn-ghost",children:"Sign Out"})]})]}),m&&y.jsxs("form",{className:"goal-form",onSubmit:Y,style:{alignItems:"flex-start",flexDirection:"column",maxWidth:320},children:[y.jsx("label",{className:"goal-label",children:"Change password"}),y.jsx("input",{type:"password",className:"input",placeholder:"Current password",value:g.current,onChange:U=>v(D=>({...D,current:U.target.value})),required:!0,autoFocus:!0}),y.jsx("input",{type:"password",className:"input",placeholder:"New password",value:g.next,onChange:U=>v(D=>({...D,next:U.target.value})),required:!0}),y.jsx("input",{type:"password",className:"input",placeholder:"Confirm new",value:g.confirm,onChange:U=>v(D=>({...D,confirm:U.target.value})),required:!0}),S&&y.jsx("p",{className:"error-msg",children:S}),E&&y.jsx("p",{className:"success-msg",children:"Password updated!"}),y.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[y.jsx("button",{type:"submit",className:"btn btn-primary",children:"Update"}),y.jsx("button",{type:"button",className:"btn btn-ghost",onClick:()=>x(!1),children:"Cancel"})]})]}),y.jsxs("div",{className:"stats-bar",children:[l>0&&y.jsxs("div",{className:"stat-chip",children:[y.jsx("span",{className:"stat-icon",children:"🔥"}),y.jsxs("span",{children:[l," day streak"]})]}),y.jsx("div",{className:"stat-chip goal-chip",onClick:()=>{p(u.target||""),f(!0)},children:u.target>0?y.jsxs(y.Fragment,{children:[y.jsx("span",{className:"stat-icon",children:"✍"}),y.jsxs("span",{children:[u.count," / ",u.target," words today"]}),y.jsx("span",{className:"goal-bar-wrap",children:y.jsx("span",{className:"goal-bar",style:{width:X+"%"}})}),y.jsxs("span",{className:"goal-pct",children:[X,"%"]})]}):y.jsx("span",{className:"goal-set-cta",children:"+ Set a daily writing goal"})})]}),d&&y.jsxs("form",{className:"goal-form",onSubmit:ke,children:[y.jsx("label",{className:"goal-label",children:"Daily word goal:"}),y.jsx("input",{type:"number",min:"1",className:"input goal-input",value:h,onChange:U=>p(U.target.value),placeholder:"e.g. 500",autoFocus:!0}),y.jsx("button",{type:"submit",className:"btn btn-primary",children:"Set"}),y.jsx("button",{type:"button",className:"btn btn-ghost",onClick:()=>f(!1),children:"Cancel"})]}),y.jsx("div",{className:"search-bar",children:y.jsx("input",{type:"search",className:"input search-input",placeholder:"Search stories…",value:s,onChange:U=>o(U.target.value)})}),r?y.jsx("div",{className:"loading",children:"Loading your stories…"}):N.length===0&&s?y.jsxs("div",{className:"empty-state",children:[y.jsxs("p",{children:['No stories match "',s,'"']}),y.jsx("button",{className:"btn btn-ghost",onClick:()=>o(""),children:"Clear search"})]}):N.length===0?y.jsxs("div",{className:"empty-state",children:[y.jsx("span",{className:"empty-quill",children:"📖"}),y.jsx("p",{children:"No stories yet. Time to write one!"}),y.jsx("button",{onClick:T,className:"btn btn-primary",children:"Start Writing"})]}):y.jsx("div",{className:"stories-grid",children:N.map(U=>y.jsx(jS,{story:U,onClick:()=>C(`/story/${U.id}`),onDelete:D=>V(D,U.id,U.title)},U.id))})]})}function Ie(t){this.content=t}Ie.prototype={constructor:Ie,find:function(t){for(var e=0;e>1}};Ie.from=function(t){if(t instanceof Ie)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new Ie(e)};function Xg(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let i=t.child(r),s=e.child(r);if(i==s){n+=i.nodeSize;continue}if(!i.sameMarkup(s))return n;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)n++;return n}if(i.content.size||s.content.size){let o=Xg(i.content,s.content,n+1);if(o!=null)return o}n+=i.nodeSize}}function Zg(t,e,n,r){for(let i=t.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:n,b:r};let o=t.child(--i),l=e.child(--s),a=o.nodeSize;if(o==l){n-=a,r-=a;continue}if(!o.sameMarkup(l))return{a:n,b:r};if(o.isText&&o.text!=l.text){let u=0,c=Math.min(o.text.length,l.text.length);for(;ue&&r(a,i+l,s||null,o)!==!1&&a.content.size){let c=l+1;a.nodesBetween(Math.max(0,e-c),Math.min(a.content.size,n-c),r,i+c)}l=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,i){let s="",o=!0;return this.nodesBetween(e,n,(l,a)=>{let u=l.isText?l.text.slice(Math.max(e,a)-a,n-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&u||l.isTextblock)&&r&&(o?o=!1:s+=r),s+=u},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),s=1);se)for(let s=0,o=0;oe&&((on)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,n-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,n-o-1))),r.push(l),i+=l.nodeSize),o=a}return new O(r,i)}cutByIndex(e,n){return e==n?O.empty:e==0&&n==this.content.length?this:new O(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let i=this.content.slice(),s=this.size+n.nodeSize-r.nodeSize;return i[e]=n,new O(i,s)}addToStart(e){return new O([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new O(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;nthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,r=0;;n++){let i=this.child(n),s=r+i.nodeSize;if(s>=e)return s==e?oo(n+1,s):oo(n,r);r=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return O.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new O(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return O.empty;let n,r=0;for(let i=0;ithis.type.rank&&(n||(n=e.slice(0,i)),n.push(this),r=!0),n&&n.push(s)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;nr.type.rank-i.type.rank),n}};Z.none=[];class nl extends Error{}class I{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=ty(this.content,e+this.openStart,n);return r&&new I(r,this.openStart,this.openEnd)}removeBetween(e,n){return new I(ey(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return I.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new I(O.fromJSON(e,n.content),r,i)}static maxOpen(e,n=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(n||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(n||!s.type.spec.isolating);s=s.lastChild)i++;return new I(e,r,i)}}I.empty=new I(O.empty,0,0);function ey(t,e,n){let{index:r,offset:i}=t.findIndex(e),s=t.maybeChild(r),{index:o,offset:l}=t.findIndex(n);if(i==e||s.isText){if(l!=n&&!t.child(o).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=o)throw new RangeError("Removing non-flat range");return t.replaceChild(r,s.copy(ey(s.content,e-i-1,n-i-1)))}function ty(t,e,n,r){let{index:i,offset:s}=t.findIndex(e),o=t.maybeChild(i);if(s==e||o.isText)return r&&!r.canReplace(i,i,n)?null:t.cut(0,e).append(n).append(t.cut(e));let l=ty(o.content,e-s-1,n,o);return l&&t.replaceChild(i,o.copy(l))}function BS(t,e,n){if(n.openStart>t.depth)throw new nl("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new nl("Inconsistent open depths");return ny(t,e,n,0)}function ny(t,e,n,r){let i=t.index(r),s=t.node(r);if(i==e.index(r)&&r=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function qi(t,e,n,r){let i=(e||t).node(n),s=0,o=e?e.index(n):i.childCount;t&&(s=t.index(n),t.depth>n?s++:t.textOffset&&(fr(t.nodeAfter,r),s++));for(let l=s;li&&_u(t,e,i+1),o=r.depth>i&&_u(n,r,i+1),l=[];return qi(null,t,i,l),s&&o&&e.index(i)==n.index(i)?(ry(s,o),fr(hr(s,iy(t,e,n,r,i+1)),l)):(s&&fr(hr(s,rl(t,e,i+1)),l),qi(e,n,i,l),o&&fr(hr(o,rl(n,r,i+1)),l)),qi(r,null,i,l),new O(l)}function rl(t,e,n){let r=[];if(qi(null,t,n,r),t.depth>n){let i=_u(t,e,n+1);fr(hr(i,rl(t,e,n+1)),r)}return qi(e,null,n,r),new O(r)}function FS(t,e){let n=e.depth-t.openStart,i=e.node(n).copy(t.content);for(let s=n-1;s>=0;s--)i=e.node(s).copy(O.from(i));return{start:i.resolveNoCache(t.openStart+n),end:i.resolveNoCache(i.content.size-t.openEnd-n)}}class xs{constructor(e,n,r){this.pos=e,this.path=n,this.parentOffset=r,this.depth=n.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,n=this.index(this.depth);if(n==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(n);return r?e.child(n).cut(r):i}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let r=this.path[n*3],i=n==0?0:this.path[n*3-1]+1;for(let s=0;s0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!n||n(this.node(r))))return new il(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let r=[],i=0,s=n;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(s),u=s-a;if(r.push(o,l,i+a),!u||(o=o.child(l),o.isText))break;s=u-1,i+=a+1}return new xs(n,r,s)}static resolveCached(e,n){let r=nh.get(e);if(r)for(let s=0;se&&this.nodesBetween(e,n,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),sy(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,r=O.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),l=o&&o.matchFragment(this.content,n);if(!l||!l.validEnd)return!1;for(let a=i;an.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let r;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,r)}let i=O.fromJSON(e,n.content),s=e.nodeType(n.type).create(n.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};rn.prototype.text=void 0;class sl extends rn{constructor(e,n,r,i){if(super(e,n,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):sy(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new sl(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new sl(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function sy(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}class wr{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let r=new US(e,n);if(r.next==null)return wr.empty;let i=oy(r);r.next&&r.err("Unexpected trailing text");let s=QS(GS(i));return YS(s,r),s}matchType(e){for(let n=0;nu.createAndFill()));for(let u=0;u=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function n(r){e.push(r);for(let i=0;i{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(r.next[o].next);return s}).join(` +`)}}wr.empty=new wr(!0);class US{constructor(e,n){this.string=e,this.nodeTypes=n,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 new SyntaxError(e+" (in content expression '"+this.string+"')")}}function oy(t){let e=[];do e.push(HS(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function HS(t){let e=[];do e.push(WS(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function WS(t){let e=qS(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else if(t.eat("{"))e=KS(t,e);else break;return e}function rh(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function KS(t,e){let n=rh(t),r=n;return t.eat(",")&&(t.next!="}"?r=rh(t):r=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:e}}function JS(t,e){let n=t.nodeTypes,r=n[e];if(r)return[r];let i=[];for(let s in n){let o=n[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&t.err("No node type or group '"+e+"' found"),i}function qS(t){if(t.eat("(")){let e=oy(t);return t.eat(")")||t.err("Missing closing paren"),e}else if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=JS(t,t.next).map(n=>(t.inline==null?t.inline=n.isInline:t.inline!=n.isInline&&t.err("Mixing inline and block content"),{type:"name",value:n}));return t.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function GS(t){let e=[[]];return i(s(t,0),n()),e;function n(){return e.push([])-1}function r(o,l,a){let u={term:a,to:l};return e[o].push(u),u}function i(o,l){o.forEach(a=>a.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((a,u)=>a.concat(s(u,l)),[]);if(o.type=="seq")for(let a=0;;a++){let u=s(o.exprs[a],l);if(a==o.exprs.length-1)return u;i(u,l=n())}else if(o.type=="star"){let a=n();return r(l,a),i(s(o.expr,a),a),[r(a)]}else if(o.type=="plus"){let a=n();return i(s(o.expr,l),a),i(s(o.expr,a),a),[r(a)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let u=0;u{t[o].forEach(({term:l,to:a})=>{if(!l)return;let u;for(let c=0;c{u||i.push([l,u=[]]),u.indexOf(c)==-1&&u.push(c)})})});let s=e[r.join(",")]=new wr(r.indexOf(t.length-1)>-1);for(let o=0;o-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:uy(this.attrs,e)}create(e=null,n,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new rn(this,this.computeAttrs(e),O.from(n),Z.setFrom(r))}createChecked(e=null,n,r){return n=O.from(n),this.checkContent(n),new rn(this,this.computeAttrs(e),n,Z.setFrom(r))}createAndFill(e=null,n,r){if(e=this.computeAttrs(e),n=O.from(n),n.size){let o=this.contentMatch.fillBefore(n);if(!o)return null;n=o.append(n)}let i=this.contentMatch.matchFragment(n),s=i&&i.fillBefore(O.empty,!0);return s?new rn(this,e,n.append(s),Z.setFrom(r)):null}validContent(e){let n=this.contentMatch.matchFragment(e);if(!n||!n.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let n=0;nr[s]=new fy(s,n,o));let i=n.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function XS(t,e,n){let r=n.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${t}, got ${s}`)}}class ZS{constructor(e,n,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?XS(e,n,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class Il{constructor(e,n,r,i){this.name=e,this.rank=n,this.schema=r,this.spec=i,this.attrs=dy(e,i.attrs),this.excluded=null;let s=ay(this.attrs);this.instance=s?new Z(this,s):null}create(e=null){return!e&&this.instance?this.instance:new Z(this,uy(this.attrs,e))}static compile(e,n){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new Il(s,i++,n,o)),r}removeFromSet(e){for(var n=0;n-1}}class hy{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let n=this.spec={};for(let i in e)n[i]=e[i];n.nodes=Ie.from(e.nodes),n.marks=Ie.from(e.marks||{}),this.nodes=sh.compile(this.spec.nodes,this),this.marks=Il.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=wr.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?oh(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:oh(this,o.split(" "))}this.nodeFromJSON=i=>rn.fromJSON(this,i),this.markFromJSON=i=>Z.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,n=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof sh){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(n,r,i)}text(e,n){let r=this.nodes.text;return new sl(r,r.defaultAttrs,e,Z.setFrom(n))}mark(e,n){return typeof e=="string"&&(e=this.marks[e]),e.create(n)}nodeType(e){let n=this.nodes[e];if(!n)throw new RangeError("Unknown node type: "+e);return n}}function oh(t,e){let n=[];for(let r=0;r-1)&&n.push(o=a)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return n}function ek(t){return t.tag!=null}function tk(t){return t.style!=null}class zn{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[];let r=this.matchedStyles=[];n.forEach(i=>{if(ek(i))this.tags.push(i);else if(tk(i)){let s=/[^=]*/.exec(i.style)[0];r.indexOf(s)<0&&r.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,n={}){let r=new ah(this,n,!1);return r.addAll(e,Z.none,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new ah(this,n,!0);return r.addAll(e,Z.none,n.from,n.to),I.maxOpen(r.finish())}matchTag(e,n,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=n))){if(o.getAttrs){let a=o.getAttrs(n);if(a===!1)continue;o.attrs=a||void 0}return o}}}static schemaRules(e){let n=[];function r(i){let s=i.priority==null?50:i.priority,o=0;for(;o{r(o=uh(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{r(o=uh(o)),o.node||o.ignore||o.mark||(o.node=i)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new zn(e,zn.schemaRules(e)))}}const py={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},nk={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},my={ol:!0,ul:!0},Ss=1,Vu=2,Gi=4;function lh(t,e,n){return e!=null?(e?Ss:0)|(e==="full"?Vu:0):t&&t.whitespace=="pre"?Ss|Vu:n&~Gi}class lo{constructor(e,n,r,i,s,o){this.type=e,this.attrs=n,this.marks=r,this.solid=i,this.options=o,this.content=[],this.activeMarks=Z.none,this.match=s||(o&Gi?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(O.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Ss)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let n=O.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(O.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!py.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class ah{constructor(e,n,r){this.parser=e,this.options=n,this.isOpen=r,this.open=0,this.localPreserveWS=!1;let i=n.topNode,s,o=lh(null,n.preserveWhitespace,0)|(r?Gi:0);i?s=new lo(i.type,i.attrs,Z.none,!0,n.topMatch||i.type.contentMatch,o):r?s=new lo(null,null,Z.none,!0,null,o):s=new lo(e.schema.topNodeType,null,Z.none,!0,null,o),this.nodes=[s],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,n){e.nodeType==3?this.addTextNode(e,n):e.nodeType==1&&this.addElement(e,n)}addTextNode(e,n){let r=e.nodeValue,i=this.top,s=i.options&Vu?"full":this.localPreserveWS||(i.options&Ss)>0,{schema:o}=this.parser;if(s==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(s)if(s==="full")r=r.replace(/\r\n?/g,` +`);else if(o.linebreakReplacement&&/[\r\n]/.test(r)&&this.top.findWrapping(o.linebreakReplacement.create())){let l=r.split(/\r?\n|\r/);for(let a=0;a!a.clearMark(u)):n=n.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return n}addElementByRule(e,n,r,i){let s,o;if(n.node)if(o=this.parser.schema.nodes[n.node],o.isLeaf)this.insertNode(o.create(n.attrs),r,e.nodeName=="BR")||this.leafFallback(e,r);else{let a=this.enter(o,n.attrs||null,r,n.preserveWhitespace);a&&(s=!0,r=a)}else{let a=this.parser.schema.marks[n.mark];r=r.concat(a.create(n.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,r,!1));else{let a=e;typeof n.contentElement=="string"?a=e.querySelector(n.contentElement):typeof n.contentElement=="function"?a=n.contentElement(e):n.contentElement&&(a=n.contentElement),this.findAround(e,a,!0),this.addAll(a,r),this.findAround(e,a,!1)}s&&this.sync(l)&&this.open--}addAll(e,n,r,i){let s=r||0;for(let o=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,n);this.findAtPoint(e,s)}findPlace(e,n,r){let i,s;for(let o=this.open,l=0;o>=0;o--){let a=this.nodes[o],u=a.findWrapping(e);if(u&&(!i||i.length>u.length+l)&&(i=u,s=a,!u.length))break;if(a.solid){if(r)break;l+=2}}if(!i)return null;this.sync(s);for(let o=0;o(o.type?o.type.allowsMarkType(u.type):ch(u.type,e))?(a=u.addToSet(a),!1):!0),this.nodes.push(new lo(e,n,a,i,null,l)),this.open++,r}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].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 n=this.open;n>=0;n--){if(this.nodes[n]==e)return this.open=n,!0;this.localPreserveWS&&(this.nodes[n].options|=Ss)}return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),o=(l,a)=>{for(;l>=0;l--){let u=n[l];if(u==""){if(l==n.length-1||l==0)continue;for(;a>=s;a--)if(o(l-1,a))return!0;return!1}else{let c=a>0||a==0&&i?this.nodes[a].type:r&&a>=s?r.node(a-s).type:null;if(!c||c.name!=u&&!c.isInGroup(u))return!1;a--}}return!0};return o(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}}function rk(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&my.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function ik(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function uh(t){let e={};for(let n in t)e[n]=t[n];return e}function ch(t,e){let n=e.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(t))continue;let s=[],o=l=>{s.push(l);for(let a=0;a{if(s.length||o.marks.length){let l=0,a=0;for(;l=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,n);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,n,r={}){let i=this.marks[e.type.name];return i&&Mo(Ca(r),i(e,n),null,e.attrs)}static renderSpec(e,n,r=null,i){return Mo(e,n,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new Dr(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let n=dh(e.nodes);return n.text||(n.text=r=>r.text),n}static marksFromSchema(e){return dh(e.marks)}}function dh(t){let e={};for(let n in t){let r=t[n].spec.toDOM;r&&(e[n]=r)}return e}function Ca(t){return t.document||window.document}const fh=new WeakMap;function sk(t){let e=fh.get(t);return e===void 0&&fh.set(t,e=ok(t)),e}function ok(t){let e=null;function n(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new 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 l,a=n?t.createElementNS(n,i):t.createElement(i),u=e[1],c=1;if(u&&typeof u=="object"&&u.nodeType==null&&!Array.isArray(u)){c=2;for(let d in u)if(u[d]!=null){let f=d.indexOf(" ");f>0?a.setAttributeNS(d.slice(0,f),d.slice(f+1),u[d]):d=="style"&&a.style?a.style.cssText=u[d]:a.setAttribute(d,u[d])}}for(let d=c;dc)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:h,contentDOM:p}=Mo(t,f,n,r);if(a.appendChild(h),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:a,contentDOM:l}}const gy=65535,yy=Math.pow(2,16);function lk(t,e){return t+e*yy}function hh(t){return t&gy}function ak(t){return(t-(t&gy))/yy}const vy=1,xy=2,To=4,Sy=8;class Uu{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&Sy)>0}get deletedBefore(){return(this.delInfo&(vy|To))>0}get deletedAfter(){return(this.delInfo&(xy|To))>0}get deletedAcross(){return(this.delInfo&To)>0}}class at{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&at.empty)return at.empty}recover(e){let n=0,r=hh(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[l+s],c=this.ranges[l+o],d=a+u;if(e<=d){let f=u?e==a?-1:e==d?1:n:n,h=a+i+(f<0?0:c);if(r)return h;let p=e==(n<0?a:d)?null:lk(l/3,e-a),m=e==a?xy:e==d?vy:To;return(n<0?e!=a:e!=d)&&(m|=Sy),new Uu(h,m,p)}i+=c-u}return r?e+i:new Uu(e+i,0,null)}touches(e,n){let r=0,i=hh(n),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let u=this.ranges[l+s],c=a+u;if(e<=c&&l==i*3)return!0;r+=this.ranges[l+o]-u}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i=0;n--){let i=e.getMirror(n);this.appendMap(e._maps[n].invert(),i!=null&&i>n?r-i-1:void 0)}}invert(){let e=new ks;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let r=this.from;rs&&a!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),n.openStart,n.openEnd);return ve.fromReplace(e,this.from,this.to,s)}invert(){return new Ut(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new bn(n.pos,r.pos,this.mark)}merge(e){return e instanceof bn&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new bn(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new bn(n.from,n.to,e.markFromJSON(n.mark))}}We.jsonID("addMark",bn);class Ut extends We{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new I(cd(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return ve.fromReplace(e,this.from,this.to,r)}invert(){return new bn(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Ut(n.pos,r.pos,this.mark)}merge(e){return e instanceof Ut&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ut(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Ut(n.from,n.to,e.markFromJSON(n.mark))}}We.jsonID("removeMark",Ut);class Mn extends We{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return ve.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return ve.fromReplace(e,this.pos,this.pos+1,new I(O.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let i=0;ir.pos?null:new Te(n.pos,r.pos,i,s,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(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Te(n.from,n.to,n.gapFrom,n.gapTo,I.fromJSON(e,n.slice),n.insert,!!n.structure)}}We.jsonID("replaceAround",Te);function Hu(t,e,n){let r=t.resolve(e),i=n-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function uk(t,e,n,r){let i=[],s=[],o,l;t.doc.nodesBetween(e,n,(a,u,c)=>{if(!a.isInline)return;let d=a.marks;if(!r.isInSet(d)&&c.type.allowsMarkType(r.type)){let f=Math.max(u,e),h=Math.min(u+a.nodeSize,n),p=r.addToSet(d);for(let m=0;mt.step(a)),s.forEach(a=>t.step(a))}function ck(t,e,n,r){let i=[],s=0;t.doc.nodesBetween(e,n,(o,l)=>{if(!o.isInline)return;s++;let a=null;if(r instanceof Il){let u=o.marks,c;for(;c=r.isInSet(u);)(a||(a=[])).push(c),u=c.removeFromSet(u)}else r?r.isInSet(o.marks)&&(a=[r]):a=o.marks;if(a&&a.length){let u=Math.min(l+o.nodeSize,n);for(let c=0;ct.step(new Ut(o.from,o.to,o.style)))}function dd(t,e,n,r=n.contentMatch,i=!0){let s=t.doc.nodeAt(e),o=[],l=e+1;for(let a=0;a=0;a--)t.step(o[a])}function dk(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function Si(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth,i=0,s=0;;--r){let o=t.$from.node(r),l=t.$from.index(r)+i,a=t.$to.indexAfter(r)-s;if(rn;p--)m||r.index(p)>0?(m=!0,c=O.from(r.node(p).copy(c)),d++):a--;let f=O.empty,h=0;for(let p=s,m=!1;p>n;p--)m||i.after(p+1)=0;o--){if(r.size){let l=n[o].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=O.from(n[o].type.create(n[o].attrs,r))}let i=e.start,s=e.end;t.step(new Te(i,s,i,s,new I(r,0,0),n.length,!0))}function gk(t,e,n,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=t.steps.length;t.doc.nodesBetween(e,n,(o,l)=>{let a=typeof i=="function"?i(o):i;if(o.isTextblock&&!o.hasMarkup(r,a)&&yk(t.doc,t.mapping.slice(s).map(l),r)){let u=null;if(r.schema.linebreakReplacement){let h=r.whitespace=="pre",p=!!r.contentMatch.matchType(r.schema.linebreakReplacement);h&&!p?u=!1:!h&&p&&(u=!0)}u===!1&&wy(t,o,l,s),dd(t,t.mapping.slice(s).map(l,1),r,void 0,u===null);let c=t.mapping.slice(s),d=c.map(l,1),f=c.map(l+o.nodeSize,1);return t.step(new Te(d,f,d+1,f-1,new I(O.from(r.create(a,null,o.marks)),0,0),1,!0)),u===!0&&ky(t,o,l,s),!1}})}function ky(t,e,n,r){e.forEach((i,s)=>{if(i.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(i.text);){let a=t.mapping.slice(r).map(n+1+s+o.index);t.replaceWith(a,a+1,e.type.schema.linebreakReplacement.create())}}})}function wy(t,e,n,r){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let o=t.mapping.slice(r).map(n+1+s);t.replaceWith(o,o+1,e.type.schema.text(` +`))}})}function yk(t,e,n){let r=t.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function vk(t,e,n,r,i){let s=t.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");n||(n=s.type);let o=n.create(r,null,i||s.marks);if(s.isLeaf)return t.replaceWith(e,e+s.nodeSize,o);if(!n.validContent(s.content))throw new RangeError("Invalid content for node type "+n.name);t.step(new Te(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new I(O.from(o),0,0),1,!0))}function sn(t,e,n=1,r){let i=t.resolve(e),s=i.depth-n,o=r&&r[r.length-1]||i.parent;if(s<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 u=i.depth-1,c=n-2;u>s;u--,c--){let d=i.node(u),f=i.index(u);if(d.type.spec.isolating)return!1;let h=d.content.cutByIndex(f,d.childCount),p=r&&r[c+1];p&&(h=h.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[c]||d;if(!d.canReplace(f+1,d.childCount)||!m.type.validContent(h))return!1}let l=i.indexAfter(s),a=r&&r[0];return i.node(s).canReplaceWith(l,l,a?a.type:i.node(s+1).type)}function xk(t,e,n=1,r){let i=t.doc.resolve(e),s=O.empty,o=O.empty;for(let l=i.depth,a=i.depth-n,u=n-1;l>a;l--,u--){s=O.from(i.node(l).copy(s));let c=r&&r[u];o=O.from(c?c.type.create(c.attrs,o):i.node(l).copy(o))}t.step(new me(e,e,new I(s.append(o),n,n),!0))}function qn(t,e){let n=t.resolve(e),r=n.index();return Cy(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Sk(t,e){e.content.size||t.type.compatibleContent(e.type);let n=t.contentMatchAt(t.childCount),{linebreakReplacement:r}=t.type.schema;for(let i=0;i0?(s=r.node(i+1),l++,o=r.node(i).maybeChild(l)):(s=r.node(i).maybeChild(l-1),o=r.node(i+1)),s&&!s.isTextblock&&Cy(s,o)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=n<0?r.before(i):r.after(i)}}function kk(t,e,n){let r=null,{linebreakReplacement:i}=t.doc.type.schema,s=t.doc.resolve(e-n),o=s.node().type;if(i&&o.inlineContent){let c=o.whitespace=="pre",d=!!o.contentMatch.matchType(i);c&&!d?r=!1:!c&&d&&(r=!0)}let l=t.steps.length;if(r===!1){let c=t.doc.resolve(e+n);wy(t,c.node(),c.before(),l)}o.inlineContent&&dd(t,e+n-1,o,s.node().contentMatchAt(s.index()),r==null);let a=t.mapping.slice(l),u=a.map(e-n);if(t.step(new me(u,a.map(e+n,-1),I.empty,!0)),r===!0){let c=t.doc.resolve(u);ky(t,c.node(),c.before(),t.steps.length)}return t}function wk(t,e,n){let r=t.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),n))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,n))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,n))return r.after(i+1);if(s=0;o--){let l=o==r.depth?0:r.pos<=(r.start(o+1)+r.end(o+1))/2?-1:1,a=r.index(o)+(l>0?1:0),u=r.node(o),c=!1;if(s==1)c=u.canReplace(a,a,i);else{let d=u.contentMatchAt(a).findWrapping(i.firstChild.type);c=d&&u.canReplaceWith(a,a,d[0])}if(c)return l==0?r.pos:l<0?r.before(o+1):r.after(o+1)}return null}function Ll(t,e,n=e,r=I.empty){if(e==n&&!r.size)return null;let i=t.resolve(e),s=t.resolve(n);return Ny(i,s,r)?new me(e,n,r):new Ck(i,s,r).fit()}function Ny(t,e,n){return!n.openStart&&!n.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),n.content)}class Ck{constructor(e,n,r){this.$from=e,this.$to=n,this.unplaced=r,this.frontier=[],this.placed=O.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=O.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),n=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let s=this.placed,o=r.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let a=new I(s,o,l);return e>-1?new Te(r.pos,e,this.$to.pos,this.$to.end(),a,n):a.size||r.pos!=this.$to.pos?new me(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}n=s.content}for(let n=1;n<=2;n++)for(let r=n==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=Na(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:u}=this.frontier[l],c,d=null;if(n==1&&(o?u.matchType(o.type)||(d=u.fillBefore(O.from(o),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:l,parent:s,inject:d};if(n==2&&o&&(c=u.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:s,wrap:c};if(s&&u.matchType(s.type))break}}}openMore(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Na(e,n);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new I(e,n+1,Math.max(r,i.size+n>=e.size-r?n+1:0)),!0)}dropNode(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=Na(e,n);if(i.childCount<=1&&n>0){let s=e.size-n<=n+i.size;this.unplaced=new I(ji(e,n-1,1),n-1,s?n-1:r)}else this.unplaced=new I(ji(e,n,1),n,r)}placeNodes({sliceDepth:e,frontierDepth:n,parent:r,inject:i,wrap:s}){for(;this.depth>n;)this.closeFrontierNode();if(s)for(let m=0;m1||a==0||m.content.size)&&(d=x,c.push(by(m.mark(f.allowedMarks(m.marks)),u==1?a:0,u==l.childCount?h:-1)))}let p=u==l.childCount;p||(h=-1),this.placed=zi(this.placed,n,O.from(c)),this.frontier[n].match=d,p&&h<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,x=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:r,type:i}=this.frontier[n],s=n=0;l--){let{match:a,type:u}=this.frontier[l],c=ba(e,l,u,a,!0);if(!c||c.childCount)continue e}return{depth:n,fit:o,move:s?e.doc.resolve(e.after(n+1)):e}}}}close(e){let n=this.findCloseLevel(e);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=zi(this.placed,n.depth,n.fit)),e=n.move;for(let r=n.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,n=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=zi(this.placed,this.depth,O.from(e.create(n,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(O.empty,!0);n.childCount&&(this.placed=zi(this.placed,this.frontier.length,n))}}function ji(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(ji(t.firstChild.content,e-1,n)))}function zi(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(zi(t.lastChild.content,e-1,n)))}function Na(t,e){for(let n=0;n1&&(r=r.replaceChild(0,by(r.firstChild,e-1,r.childCount==1?n-1:0))),e>0&&(r=t.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(O.empty,!0)))),t.copy(r)}function ba(t,e,n,r,i){let s=t.node(e),o=i?t.indexAfter(e):t.index(e);if(o==s.childCount&&!n.compatibleContent(s.type))return null;let l=r.fillBefore(s.content,!0,o);return l&&!Ek(n,s.content,o)?l:null}function Ek(t,e,n){for(let r=n;r0;f--,h--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(f)>-1?l=f:i.before(f)==h&&o.splice(1,0,-f)}let a=o.indexOf(l),u=[],c=r.openStart;for(let f=r.content,h=0;;h++){let p=f.firstChild;if(u.push(p),h==r.openStart)break;f=p.content}for(let f=c-1;f>=0;f--){let h=u[f],p=Nk(h.type);if(p&&!h.sameMarkup(i.node(Math.abs(l)-1)))c=f;else if(p||!h.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let h=(f+c+1)%(r.openStart+1),p=u[h];if(p)for(let m=0;m=0&&(t.replace(e,n,r),!(t.steps.length>d));f--){let h=o[f];h<0||(e=i.before(h),n=s.after(h))}}function My(t,e,n,r,i){if(er){let s=i.contentMatchAt(0),o=s.fillBefore(t).append(t);t=o.append(s.matchFragment(o).fillBefore(O.empty,!0))}return t}function Mk(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let i=wk(t.doc,e,r.type);i!=null&&(e=n=i)}t.replaceRange(e,n,new I(O.from(r),0,0))}function Tk(t,e,n){let r=t.doc.resolve(e),i=t.doc.resolve(n);if(r.parent.isTextblock&&i.parent.isTextblock&&r.start()!=i.start()&&r.parentOffset==0&&i.parentOffset==0){let o=r.sharedDepth(n),l=!1;for(let a=r.depth;a>o;a--)r.node(a).type.spec.isolating&&(l=!0);for(let a=i.depth;a>o;a--)i.node(a).type.spec.isolating&&(l=!0);if(!l){for(let a=r.depth;a>0&&e==r.start(a);a--)e=r.before(a);for(let a=i.depth;a>0&&n==i.start(a);a--)n=i.before(a);r=t.doc.resolve(e),i=t.doc.resolve(n)}}let s=Ty(r,i);for(let o=0;o0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return t.delete(r.before(l),i.after(l))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(e-r.start(o)==r.depth-o&&n>r.end(o)&&i.end(o)-n!=i.depth-o&&r.start(o-1)==i.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),i.index(o-1)))return t.delete(r.before(o),n);t.delete(e,n)}function Ty(t,e){let n=[],r=Math.min(t.depth,e.depth);for(let i=r;i>=0;i--){let s=t.start(i);if(se.pos+(e.depth-i)||t.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==t.depth&&i==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&n.push(i)}return n}class ri extends We{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return ve.fail("No node at attribute step's position");let r=Object.create(null);for(let s in n.attrs)r[s]=n.attrs[s];r[this.attr]=this.value;let i=n.type.create(r,null,n.marks);return ve.fromReplace(e,this.pos,this.pos+1,new I(O.from(i),0,n.isLeaf?0:1))}getMap(){return at.empty}invert(e){return new ri(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new ri(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new ri(n.pos,n.attr,n.value)}}We.jsonID("attr",ri);class ws extends We{constructor(e,n){super(),this.attr=e,this.value=n}apply(e){let n=Object.create(null);for(let i in e.attrs)n[i]=e.attrs[i];n[this.attr]=this.value;let r=e.type.create(n,e.content,e.marks);return ve.ok(r)}getMap(){return at.empty}invert(e){return new ws(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new ws(n.attr,n.value)}}We.jsonID("docAttr",ws);let fi=class extends Error{};fi=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};fi.prototype=Object.create(Error.prototype);fi.prototype.constructor=fi;fi.prototype.name="TransformError";class Ok{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new ks}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let n=this.maybeStep(e);if(n.failed)throw new fi(n.failed);return this}maybeStep(e){let n=e.apply(this.doc);return n.failed||this.addStep(e,n.doc),n}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,n=-1e9;for(let r=0;r{e=Math.min(e,l),n=Math.max(n,a)})}return e==1e9?null:{from:e,to:n}}addStep(e,n){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=n}replace(e,n=e,r=I.empty){let i=Ll(this.doc,e,n,r);return i&&this.step(i),this}replaceWith(e,n,r){return this.replace(e,n,new I(O.from(r),0,0))}delete(e,n){return this.replace(e,n,I.empty)}insert(e,n){return this.replaceWith(e,e,n)}replaceRange(e,n,r){return bk(this,e,n,r),this}replaceRangeWith(e,n,r){return Mk(this,e,n,r),this}deleteRange(e,n){return Tk(this,e,n),this}lift(e,n){return fk(this,e,n),this}join(e,n=1){return kk(this,e,n),this}wrap(e,n){return mk(this,e,n),this}setBlockType(e,n=e,r,i=null){return gk(this,e,n,r,i),this}setNodeMarkup(e,n,r=null,i){return vk(this,e,n,r,i),this}setNodeAttribute(e,n,r){return this.step(new ri(e,n,r)),this}setDocAttribute(e,n){return this.step(new ws(e,n)),this}addNodeMark(e,n){return this.step(new Mn(e,n)),this}removeNodeMark(e,n){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(n instanceof Z)n.isInSet(r.marks)&&this.step(new Cr(e,n));else{let i=r.marks,s,o=[];for(;s=n.isInSet(i);)o.push(new Cr(e,s)),i=s.removeFromSet(i);for(let l=o.length-1;l>=0;l--)this.step(o[l])}return this}split(e,n=1,r){return xk(this,e,n,r),this}addMark(e,n,r){return uk(this,e,n,r),this}removeMark(e,n,r){return ck(this,e,n,r),this}clearIncompatible(e,n,r){return dd(this,e,n,r),this}}const Ma=Object.create(null);class W{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new Dk(e.min(n),e.max(n))]}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 n=0;n=0;s--){let o=n<0?Lr(e.node(0),e.node(s),e.before(s+1),e.index(s),n,r):Lr(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,n,r);if(o)return o}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new ft(e.node(0))}static atStart(e){return Lr(e,e,0,0,1)||new ft(e)}static atEnd(e){return Lr(e,e,e.content.size,e.childCount,-1)||new ft(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Ma[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in Ma)throw new RangeError("Duplicate use of selection JSON ID "+e);return Ma[e]=n,n.prototype.jsonID=e,n}getBookmark(){return H.between(this.$anchor,this.$head).getBookmark()}}W.prototype.visible=!0;class Dk{constructor(e,n){this.$from=e,this.$to=n}}let mh=!1;function gh(t){!mh&&!t.parent.inlineContent&&(mh=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class H extends W{constructor(e,n=e){gh(e),gh(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return W.near(r);let i=e.resolve(n.map(this.anchor));return new H(i.parent.inlineContent?i:r,r)}replace(e,n=I.empty){if(super.replace(e,n),n==I.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof H&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new jl(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new H(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let i=e.resolve(n);return new this(i,r==n?i:e.resolve(r))}static between(e,n,r){let i=e.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let s=W.findFrom(n,r,!0)||W.findFrom(n,-r,!0);if(s)n=s.$head;else return W.near(n,r)}return e.parent.inlineContent||(i==0?e=n:(e=(W.findFrom(e,-r,!0)||W.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&F.isSelectable(l))return F.create(t,n-(i<0?l.nodeSize:0))}else{let a=Lr(t,l,n+i,i<0?l.childCount:0,i,s);if(a)return a}n+=l.nodeSize*i}return null}function yh(t,e,n){let r=t.steps.length-1;if(r{o==null&&(o=c)}),t.setSelection(W.near(t.doc.resolve(o),n))}const vh=1,ao=2,xh=4;class Ak extends Ok{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.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=ao,this}ensureMarks(e){return Z.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&ao)>0}addStep(e,n){super.addStep(e,n),this.updated=this.updated&~ao,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,n=!0){let r=this.selection;return n&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||Z.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,n,r){let i=this.doc.type.schema;if(n==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=n),!e)return this.deleteRange(n,r);let s=this.storedMarks;if(!s){let o=this.doc.resolve(n);s=r==n?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(n,r,i.text(e,s)),!this.selection.empty&&this.selection.to==n+e.length&&this.setSelection(W.near(this.selection.$to)),this}}setMeta(e,n){return this.meta[typeof e=="string"?e:e.key]=n,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|=xh,this}get scrolledIntoView(){return(this.updated&xh)>0}}function Sh(t,e){return!e||!t?t:t.bind(e)}class Bi{constructor(e,n,r){this.name=e,this.init=Sh(n.init,r),this.apply=Sh(n.apply,r)}}const Ik=[new Bi("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new Bi("selection",{init(t,e){return t.selection||W.atStart(e.doc)},apply(t){return t.selection}}),new Bi("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new Bi("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}})];class Ta{constructor(e,n){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Ik.slice(),n&&n.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new Bi(r.key,r.spec.state,r))})}}class Qr{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,n=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(n[r]=s.toJSON.call(i,this[i.key]))}return n}static fromJSON(e,n,r){if(!n)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Ta(e.schema,e.plugins),s=new Qr(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=rn.fromJSON(e.schema,n.doc);else if(o.name=="selection")s.selection=W.fromJSON(s.doc,n.selection);else if(o.name=="storedMarks")n.storedMarks&&(s.storedMarks=n.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[l],u=a.spec.state;if(a.key==o.name&&u&&u.fromJSON&&Object.prototype.hasOwnProperty.call(n,l)){s[o.name]=u.fromJSON.call(a,e,n[l],s);return}}s[o.name]=o.init(e,s)}}),s}}function Oy(t,e,n){for(let r in t){let i=t[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Oy(i,e,{})),n[r]=i}return n}class Ke{constructor(e){this.spec=e,this.props={},e.props&&Oy(e.props,this,this.props),this.key=e.key?e.key.key:Dy("plugin")}getState(e){return e[this.key]}}const Oa=Object.create(null);function Dy(t){return t in Oa?t+"$"+ ++Oa[t]:(Oa[t]=0,t+"$")}class Mt{constructor(e="key"){this.key=Dy(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Re=function(t){for(var e=0;;e++)if(t=t.previousSibling,!t)return e},hi=function(t){let e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e};let Wu=null;const Yt=function(t,e,n){let r=Wu||(Wu=document.createRange());return r.setEnd(t,n??t.nodeValue.length),r.setStart(t,e||0),r},Rk=function(){Wu=null},Er=function(t,e,n,r){return n&&(kh(t,e,n,r,-1)||kh(t,e,n,r,1))},Lk=/^(img|br|input|textarea|hr)$/i;function kh(t,e,n,r,i){for(var s;;){if(t==n&&e==r)return!0;if(e==(i<0?0:xt(t))){let o=t.parentNode;if(!o||o.nodeType!=1||zs(t)||Lk.test(t.nodeName)||t.contentEditable=="false")return!1;e=Re(t)+(i<0?0:1),t=o}else if(t.nodeType==1){let o=t.childNodes[e+(i<0?-1:0)];if(o.nodeType==1&&o.contentEditable=="false")if(!((s=o.pmViewDesc)===null||s===void 0)&&s.ignoreForSelection)e+=i;else return!1;else t=o,e=i<0?xt(t):0}else return!1}}function xt(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function jk(t,e){for(;;){if(t.nodeType==3&&e)return t;if(t.nodeType==1&&e>0){if(t.contentEditable=="false")return null;t=t.childNodes[e-1],e=xt(t)}else if(t.parentNode&&!zs(t))e=Re(t),t=t.parentNode;else return null}}function zk(t,e){for(;;){if(t.nodeType==3&&e2),gt=pi||(Kt?/Mac/.test(Kt.platform):!1),Iy=Kt?/Win/.test(Kt.platform):!1,tn=/Android \d/.test(Gn),Bs=!!wh&&"webkitFontSmoothing"in wh.documentElement.style,$k=Bs?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Vk(t){let e=t.defaultView&&t.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function Gt(t,e){return typeof t=="number"?t:t[e]}function Uk(t){let e=t.getBoundingClientRect(),n=e.width/t.offsetWidth||1,r=e.height/t.offsetHeight||1;return{left:e.left,right:e.left+t.clientWidth*n,top:e.top,bottom:e.top+t.clientHeight*r}}function Ch(t,e,n){let r=t.someProp("scrollThreshold")||0,i=t.someProp("scrollMargin")||5,s=t.dom.ownerDocument;for(let o=n||t.dom;o;){if(o.nodeType!=1){o=hi(o);continue}let l=o,a=l==s.body,u=a?Vk(s):Uk(l),c=0,d=0;if(e.topu.bottom-Gt(r,"bottom")&&(d=e.bottom-e.top>u.bottom-u.top?e.top+Gt(i,"top")-u.top:e.bottom-u.bottom+Gt(i,"bottom")),e.leftu.right-Gt(r,"right")&&(c=e.right-u.right+Gt(i,"right")),c||d)if(a)s.defaultView.scrollBy(c,d);else{let h=l.scrollLeft,p=l.scrollTop;d&&(l.scrollTop+=d),c&&(l.scrollLeft+=c);let m=l.scrollLeft-h,x=l.scrollTop-p;e={left:e.left-m,top:e.top-x,right:e.right-m,bottom:e.bottom-x}}let f=a?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(f))break;o=f=="absolute"?o.offsetParent:hi(o)}}function Hk(t){let e=t.dom.getBoundingClientRect(),n=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,o=n+1;o=n-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:Ry(t.dom)}}function Ry(t){let e=[],n=t.ownerDocument;for(let r=t;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),t!=n);r=hi(r));return e}function Wk({refDOM:t,refTop:e,stack:n}){let r=t?t.getBoundingClientRect().top:0;Ly(n,r==0?0:r-e)}function Ly(t,e){for(let n=0;n=l){o=Math.max(p.bottom,o),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!a&&p.left<=e.left&&p.right>=e.left&&(a=c,u={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!n&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(s=d+1)}}return!n&&a&&(n=a,i=u,r=0),n&&n.nodeType==3?Jk(n,i):!n||r&&n.nodeType==1?{node:t,offset:s}:jy(n,i)}function Jk(t,e){let n=t.nodeValue.length,r=document.createRange(),i;for(let s=0;s=(o.left+o.right)/2?1:0)};break}}return r.detach(),i||{node:t,offset:0}}function pd(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function qk(t,e){let n=t.parentNode;return n&&/^li$/i.test(n.nodeName)&&e.left(o.left+o.right)/2?1:-1}return t.docView.posFromDOM(r,i,s)}function Qk(t,e,n,r){let i=-1;for(let s=e,o=!1;s!=t.dom;){let l=t.docView.nearestDesc(s,!0),a;if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)&&((a=l.dom.getBoundingClientRect()).width||a.height)&&(l.node.isBlock&&l.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(l.dom.nodeName)&&(!o&&a.left>r.left||a.top>r.top?i=l.posBefore:(!o&&a.right-1?i:t.docView.posFromDOM(e,n,-1)}function zy(t,e,n){let r=t.childNodes.length;if(r&&n.tope.top&&i++}let u;Bs&&i&&r.nodeType==1&&(u=r.childNodes[i-1]).nodeType==1&&u.contentEditable=="false"&&u.getBoundingClientRect().top>=e.top&&i--,r==t.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=t.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=Qk(t,r,i,e))}l==null&&(l=Gk(t,o,e));let a=t.docView.nearestDesc(o,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Eh(t){return t.top=0&&i==r.nodeValue.length?(a--,c=1):n<0?a--:u++,Pi(mn(Yt(r,a,u),c),c<0)}if(!t.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(n<0||i==xt(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return Da(a.getBoundingClientRect(),!1)}if(s==null&&i=0)}if(s==null&&i&&(n<0||i==xt(r))){let a=r.childNodes[i-1],u=a.nodeType==3?Yt(a,xt(a)-(o?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(u)return Pi(mn(u,1),!1)}if(s==null&&i=0)}function Pi(t,e){if(t.width==0)return t;let n=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:n,right:n}}function Da(t,e){if(t.height==0)return t;let n=e?t.top:t.bottom;return{top:n,bottom:n,left:t.left,right:t.right}}function Fy(t,e,n){let r=t.state,i=t.root.activeElement;r!=e&&t.updateState(e),i!=t.dom&&t.focus();try{return n()}finally{r!=e&&t.updateState(r),i!=t.dom&&i&&i.focus()}}function Zk(t,e,n){let r=e.selection,i=n=="up"?r.$from:r.$to;return Fy(t,e,()=>{let{node:s}=t.docView.domFromPos(i.pos,n=="up"?-1:1);for(;;){let l=t.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=By(t,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=Yt(l,0,l.nodeValue.length).getClientRects();else continue;for(let u=0;uc.top+1&&(n=="up"?o.top-c.top>(c.bottom-o.top)*2:c.bottom-o.bottom>(o.bottom-c.top)*2))return!1}}return!0})}const ew=/[\u0590-\u08ac]/;function tw(t,e,n){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,o=i==r.parent.content.size,l=t.domSelection();return l?!ew.test(r.parent.textContent)||!l.modify?n=="left"||n=="backward"?s:o:Fy(t,e,()=>{let{focusNode:a,focusOffset:u,anchorNode:c,anchorOffset:d}=t.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",n,"character");let h=r.depth?t.docView.domAfterPos(r.before()):t.dom,{focusNode:p,focusOffset:m}=t.domSelectionRange(),x=p&&!h.contains(p.nodeType==1?p:p.parentNode)||a==p&&u==m;try{l.collapse(c,d),a&&(a!=c||u!=d)&&l.extend&&l.extend(a,u)}catch{}return f!=null&&(l.caretBidiLevel=f),x}):r.pos==r.start()||r.pos==r.end()}let Nh=null,bh=null,Mh=!1;function nw(t,e,n){return Nh==e&&bh==n?Mh:(Nh=e,bh=n,Mh=n=="up"||n=="down"?Zk(t,e,n):tw(t,e,n))}const Ct=0,Th=1,sr=2,Jt=3;class Fs{constructor(e,n,r,i){this.parent=e,this.children=n,this.dom=r,this.contentDOM=i,this.dirty=Ct,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,n,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let n=0;nRe(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(n==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&n==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,n=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!n||s.node))if(r&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return s}}getDesc(e){let n=e.pmViewDesc;for(let r=n;r;r=r.parent)if(r==this)return n}posFromDOM(e,n,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,n,r)}return-1}descAt(e){for(let n=0,r=0;ne||o instanceof $y){i=e-s;break}s=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,n);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof _y&&s.side>=0;r--);if(n<=0){let s,o=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,o=!1);return s&&n&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,n):{node:this.contentDOM,offset:s?Re(s.dom)+1:0}}else{let s,o=!0;for(;s=r=c&&n<=u-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,n,c);e=o;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=Re(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(u>n||l==this.children.length-1)){n=u;for(let c=l+1;cp&&on){let p=l;l=a,a=p}let h=document.createRange();h.setEnd(a.node,a.offset),h.setStart(l.node,l.offset),u.removeAllRanges(),u.addRange(h)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,n){for(let r=0,i=0;i=r:er){let l=r+s.border,a=o-s.border;if(e>=l&&n<=a){this.dirty=e==r||n==o?sr:Th,e==l&&n==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=Jt:s.markDirty(e-l,n-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?sr:Jt}r=o}this.dirty=sr}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){let r=e==1?sr:Th;n.dirty{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!n.type.spec.raw){if(o.nodeType!=1){let l=document.createElement("span");l.appendChild(o),o=l}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=n,this.widget=n,s=this}matchesWidget(e){return this.dirty==Ct&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let n=this.widget.spec.stopEvent;return n?n(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}}class rw extends Fs{constructor(e,n,r,i){super(e,[],n,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,n){return e!=this.textDOM?this.posAtStart+(n?this.size:0):this.posAtStart+n}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}}class Nr extends Fs{constructor(e,n,r,i,s){super(e,[],r,i),this.mark=n,this.spec=s}static create(e,n,r,i){let s=i.nodeViews[n.type.name],o=s&&s(n,i,r);return(!o||!o.dom)&&(o=Dr.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new Nr(e,n,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&Jt||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Jt&&this.mark.eq(e)}markDirty(e,n){if(super.markDirty(e,n),this.dirty!=Ct){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=Qu(s,0,e,r));for(let l=0;l{if(!a)return o;if(a.parent)return a.parent.posBeforeChild(a)},r,i),c=u&&u.dom,d=u&&u.contentDOM;if(n.isText){if(!c)c=document.createTextNode(n.text);else if(c.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else c||({dom:c,contentDOM:d}=Dr.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs));!d&&!n.isText&&c.nodeName!="BR"&&(c.hasAttribute("contenteditable")||(c.contentEditable="false"),n.type.spec.draggable&&(c.draggable=!0));let f=c;return c=Hy(c,r,n),u?a=new iw(e,n,r,i,c,d||null,f,u,s,o+1):n.isText?new Bl(e,n,r,i,c,f,s):new Fn(e,n,r,i,c,d||null,f,s,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 n=this.children.length-1;n>=0;n--){let r=this.children[n];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>O.empty)}return e}matchesNode(e,n,r){return this.dirty==Ct&&e.eq(this.node)&&ol(n,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,n){let r=this.node.inlineContent,i=n,s=e.composing?this.localCompositionInfo(e,n):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,a=new ow(this,o&&o.node,e);uw(this.node,this.innerDeco,(u,c,d)=>{u.spec.marks?a.syncToMarks(u.spec.marks,r,e,c):u.type.side>=0&&!d&&a.syncToMarks(c==this.node.childCount?Z.none:this.node.child(c).marks,r,e,c),a.placeWidget(u,e,i)},(u,c,d,f)=>{a.syncToMarks(u.marks,r,e,f);let h;a.findNodeMatch(u,c,d,f)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(u,c,d,h,e)||a.updateNextNode(u,c,d,e,f,i)||a.addNode(u,c,d,e,i),i+=u.nodeSize}),a.syncToMarks([],r,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==sr)&&(o&&this.protectLocalComposition(e,o),Vy(this.contentDOM,this.children,e),pi&&cw(this.dom))}localCompositionInfo(e,n){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof H)||rn+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=dw(this.node.content,o,r-n,i-n);return l<0?null:{node:s,pos:l,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:n,pos:r,text:i}){if(this.getDesc(n))return;let s=n;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new rw(this,s,n,i);e.input.compositionNodes.push(o),this.children=Qu(this.children,r,r+i.length,e,o)}update(e,n,r,i){return this.dirty==Jt||!e.sameMarkup(this.node)?!1:(this.updateInner(e,n,r,i),!0)}updateInner(e,n,r,i){this.updateOuterDeco(n),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=Ct}updateOuterDeco(e){if(ol(e,this.outerDeco))return;let n=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=Uy(this.dom,this.nodeDOM,Gu(this.outerDeco,this.node,n),Gu(e,this.node,n)),this.dom!=r&&(r.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 Oh(t,e,n,r,i){Hy(r,e,t);let s=new Fn(void 0,t,e,n,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class Bl extends Fn{constructor(e,n,r,i,s,o,l){super(e,n,r,i,s,null,o,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,n,r,i){return this.dirty==Jt||this.dirty!=Ct&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(n),(this.dirty!=Ct||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=Ct,!0)}inParent(){let e=this.parent.contentDOM;for(let n=this.nodeDOM;n;n=n.parentNode)if(n==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,n,r){return e==this.nodeDOM?this.posAtStart+Math.min(n,this.node.text.length):super.localPosFromDOM(e,n,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,n,r){let i=this.node.cut(e,n),s=document.createTextNode(i.text);return new Bl(this.parent,i,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,n){super.markDirty(e,n),this.dom!=this.nodeDOM&&(e==0||n==this.nodeDOM.nodeValue.length)&&(this.dirty=Jt)}get domAtom(){return!1}isText(e){return this.node.text==e}}class $y extends Fs{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Ct&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class iw extends Fn{constructor(e,n,r,i,s,o,l,a,u,c){super(e,n,r,i,s,o,l,u,c),this.spec=a}update(e,n,r,i){if(this.dirty==Jt)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,n,r);return s&&this.updateInner(e,n,r,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,n,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,n,r,i){this.spec.setSelection?this.spec.setSelection(e,n,r.root):super.setSelection(e,n,r,i)}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 Vy(t,e,n){let r=t.firstChild,i=!1;for(let s=0;s>1,l=Math.min(o,e.length);for(;s-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let c=Nr.create(this.top,e[o],n,r);this.top.children.splice(this.index,0,c),this.top=c,this.changed=!0}this.index=0,o++}}findNodeMatch(e,n,r,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,n,r))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let u=n.children[r-1];if(u instanceof Nr)n=u,r=u.children.length;else{l=u,r--;break}}else{if(n==e)break e;r=n.parent.children.indexOf(n),n=n.parent}let a=l.node;if(a){if(a!=t.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function aw(t,e){return t.type.side-e.type.side}function uw(t,e,n,r){let i=e.locals(t),s=0;if(i.length==0){for(let u=0;us;)l.push(i[o++]);let p=s+f.nodeSize;if(f.isText){let x=p;o!x.inline):l.slice();r(f,m,e.forChild(s,f),h),s=p}}function cw(t){if(t.nodeName=="UL"||t.nodeName=="OL"){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important",window.getComputedStyle(t).listStyle,t.style.cssText=e}}function dw(t,e,n,r){for(let i=0,s=0;i=n){if(s>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let u=l=0&&u+e.length+l>=n)return l+u;if(n==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function Qu(t,e,n,r,i){let s=[];for(let o=0,l=0;o=n||c<=e?s.push(a):(un&&s.push(a.slice(n-u,a.size,r)))}return s}function md(t,e=null){let n=t.domSelectionRange(),r=t.state.doc;if(!n.focusNode)return null;let i=t.docView.nearestDesc(n.focusNode),s=i&&i.size==0,o=t.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(o<0)return null;let l=r.resolve(o),a,u;if(zl(n)){for(a=o;i&&!i.node;)i=i.parent;let d=i.node;if(i&&d.isAtom&&F.isSelectable(d)&&i.parent&&!(d.isInline&&Bk(n.focusNode,n.focusOffset,i.dom))){let f=i.posBefore;u=new F(o==f?l:r.resolve(f))}}else{if(n instanceof t.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let d=o,f=o;for(let h=0;h{(n.anchorNode!=r||n.anchorOffset!=i)&&(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout(()=>{(!Wy(t)||t.state.selection.visible)&&t.dom.classList.remove("ProseMirror-hideselection")},20))})}function hw(t){let e=t.domSelection();if(!e)return;let n=t.cursorWrapper.dom,r=n.nodeName=="IMG";r?e.collapse(n.parentNode,Re(n)+1):e.collapse(n,0),!r&&!t.state.selection.visible&&ot&&Bn<=11&&(n.disabled=!0,n.disabled=!1)}function Ky(t,e){if(e instanceof F){let n=t.docView.descAt(e.from);n!=t.lastSelectedViewDesc&&(Rh(t),n&&n.selectNode(),t.lastSelectedViewDesc=n)}else Rh(t)}function Rh(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function gd(t,e,n,r){return t.someProp("createSelectionBetween",i=>i(t,e,n))||H.between(e,n,r)}function Lh(t){return t.editable&&!t.hasFocus()?!1:Jy(t)}function Jy(t){let e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function pw(t){let e=t.docView.domFromPos(t.state.selection.anchor,0),n=t.domSelectionRange();return Er(e.node,e.offset,n.anchorNode,n.anchorOffset)}function Yu(t,e){let{$anchor:n,$head:r}=t.selection,i=e>0?n.max(r):n.min(r),s=i.parent.inlineContent?i.depth?t.doc.resolve(e>0?i.after():i.before()):null:i;return s&&W.findFrom(s,e)}function vn(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function jh(t,e,n){let r=t.state.selection;if(r instanceof H)if(n.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=t.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return vn(t,new H(r.$anchor,o))}else if(r.empty){if(t.endOfTextblock(e>0?"forward":"backward")){let i=Yu(t.state,e);return i&&i instanceof F?vn(t,i):!1}else if(!(gt&&n.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=t.docView.descAt(l))&&!o.contentDOM?F.isSelectable(s)?vn(t,new F(e<0?t.state.doc.resolve(i.pos-s.nodeSize):i)):Bs?vn(t,new H(t.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof F&&r.node.isInline)return vn(t,new H(e>0?r.$to:r.$from));{let i=Yu(t.state,e);return i?vn(t,i):!1}}}function ll(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function Yi(t,e){let n=t.pmViewDesc;return n&&n.size==0&&(e<0||t.nextSibling||t.nodeName!="BR")}function Ir(t,e){return e<0?mw(t):gw(t)}function mw(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i,s,o=!1;for(wt&&n.nodeType==1&&r0){if(n.nodeType!=1)break;{let l=n.childNodes[r-1];if(Yi(l,-1))i=n,s=--r;else if(l.nodeType==3)n=l,r=n.nodeValue.length;else break}}else{if(qy(n))break;{let l=n.previousSibling;for(;l&&Yi(l,-1);)i=n.parentNode,s=Re(l),l=l.previousSibling;if(l)n=l,r=ll(n);else{if(n=n.parentNode,n==t.dom)break;r=0}}}o?Xu(t,n,r):i&&Xu(t,i,s)}function gw(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i=ll(n),s,o;for(;;)if(r{t.state==i&&on(t)},50)}function zh(t,e){let n=t.state.doc.resolve(e);if(!(je||Iy)&&n.parent.inlineContent){let i=t.coordsAtPos(e);if(e>n.start()){let s=t.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o1)return s.lefti.top&&o1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(t.dom).direction=="rtl"?"rtl":"ltr"}function Bh(t,e,n){let r=t.state.selection;if(r instanceof H&&!r.empty||n.indexOf("s")>-1||gt&&n.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let o=Yu(t.state,e);if(o&&o instanceof F)return vn(t,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=r instanceof ft?W.near(o,e):W.findFrom(o,e);return l?vn(t,l):!1}return!1}function Fh(t,e){if(!(t.state.selection instanceof H))return!0;let{$head:n,$anchor:r,empty:i}=t.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(t.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!n.textOffset&&(e<0?n.nodeBefore:n.nodeAfter);if(s&&!s.isText){let o=t.state.tr;return e<0?o.delete(n.pos-s.nodeSize,n.pos):o.delete(n.pos,n.pos+s.nodeSize),t.dispatch(o),!0}return!1}function _h(t,e,n){t.domObserver.stop(),e.contentEditable=n,t.domObserver.start()}function xw(t){if(!He||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(e&&e.nodeType==1&&n==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;_h(t,r,"true"),setTimeout(()=>_h(t,r,"false"),20)}return!1}function Sw(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}function kw(t,e){let n=e.keyCode,r=Sw(e);if(n==8||gt&&n==72&&r=="c")return Fh(t,-1)||Ir(t,-1);if(n==46&&!e.shiftKey||gt&&n==68&&r=="c")return Fh(t,1)||Ir(t,1);if(n==13||n==27)return!0;if(n==37||gt&&n==66&&r=="c"){let i=n==37?zh(t,t.state.selection.from)=="ltr"?-1:1:-1;return jh(t,i,r)||Ir(t,i)}else if(n==39||gt&&n==70&&r=="c"){let i=n==39?zh(t,t.state.selection.from)=="ltr"?1:-1:1;return jh(t,i,r)||Ir(t,i)}else{if(n==38||gt&&n==80&&r=="c")return Bh(t,-1,r)||Ir(t,-1);if(n==40||gt&&n==78&&r=="c")return xw(t)||Bh(t,1,r)||Ir(t,1);if(r==(gt?"m":"c")&&(n==66||n==73||n==89||n==90))return!0}return!1}function yd(t,e){t.someProp("transformCopied",h=>{e=h(e,t)});let n=[],{content:r,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,s--;let h=r.firstChild;n.push(h.type.name,h.attrs!=h.type.defaultAttrs?h.attrs:null),r=h.content}let o=t.someProp("clipboardSerializer")||Dr.fromSchema(t.state.schema),l=e0(),a=l.createElement("div");a.appendChild(o.serializeFragment(r,{document:l}));let u=a.firstChild,c,d=0;for(;u&&u.nodeType==1&&(c=Zy[u.nodeName.toLowerCase()]);){for(let h=c.length-1;h>=0;h--){let p=l.createElement(c[h]);for(;a.firstChild;)p.appendChild(a.firstChild);a.appendChild(p),d++}u=a.firstChild}u&&u.nodeType==1&&u.setAttribute("data-pm-slice",`${i} ${s}${d?` -${d}`:""} ${JSON.stringify(n)}`);let f=t.someProp("clipboardTextSerializer",h=>h(e,t))||e.content.textBetween(0,e.content.size,` + +`);return{dom:a,text:f,slice:e}}function Gy(t,e,n,r,i){let s=i.parent.type.spec.code,o,l;if(!n&&!e)return null;let a=!!e&&(r||s||!n);if(a){if(t.someProp("transformPastedText",f=>{e=f(e,s||r,t)}),s)return l=new I(O.from(t.state.schema.text(e.replace(/\r\n?/g,` +`))),0,0),t.someProp("transformPasted",f=>{l=f(l,t,!0)}),l;let d=t.someProp("clipboardTextParser",f=>f(e,i,r,t));if(d)l=d;else{let f=i.marks(),{schema:h}=t.state,p=Dr.fromSchema(h);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let x=o.appendChild(document.createElement("p"));m&&x.appendChild(p.serializeNode(h.text(m,f)))})}}else t.someProp("transformPastedHTML",d=>{n=d(n,t)}),o=Nw(n),Bs&&bw(o);let u=o&&o.querySelector("[data-pm-slice]"),c=u&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(u.getAttribute("data-pm-slice")||"");if(c&&c[3])for(let d=+c[3];d>0;d--){let f=o.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;o=f}if(l||(l=(t.someProp("clipboardParser")||t.someProp("domParser")||zn.fromSchema(t.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||c),context:i,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!ww.test(f.parentNode.nodeName)?{ignore:!0}:null}})),c)l=Mw($h(l,+c[1],+c[2]),c[4]);else if(l=I.maxOpen(Cw(l.content,i),!0),l.openStart||l.openEnd){let d=0,f=0;for(let h=l.content.firstChild;d{l=d(l,t,a)}),l}const ww=/^(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 Cw(t,e){if(t.childCount<2)return t;for(let n=e.depth;n>=0;n--){let i=e.node(n).contentMatchAt(e.index(n)),s,o=[];if(t.forEach(l=>{if(!o)return;let a=i.findWrapping(l.type),u;if(!a)return o=null;if(u=o.length&&s.length&&Yy(a,s,l,o[o.length-1],0))o[o.length-1]=u;else{o.length&&(o[o.length-1]=Xy(o[o.length-1],s.length));let c=Qy(l,a);o.push(c),i=i.matchType(c.type),s=a}}),o)return O.from(o)}return t}function Qy(t,e,n=0){for(let r=e.length-1;r>=n;r--)t=e[r].create(null,O.from(t));return t}function Yy(t,e,n,r,i){if(i1&&(s=0),i=n&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(O.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,o.copy(l))}function $h(t,e,n){return en})),Aa.createHTML(t)):t}function Nw(t){let e=/^(\s*]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let n=e0().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(t),i;if((i=r&&Zy[r[1].toLowerCase()])&&(t=i.map(s=>"<"+s+">").join("")+t+i.map(s=>"").reverse().join("")),n.innerHTML=Ew(t),i)for(let s=0;s=0;l-=2){let a=n.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;i=O.from(a.create(r[l+1],i)),s++,o++}return new I(i,s,o)}const Ge={},Qe={},Tw={touchstart:!0,touchmove:!0};class Ow{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 Dw(t){for(let e in Ge){let n=Ge[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=r=>{Aw(t,r)&&!vd(t,r)&&(t.editable||!(r.type in Qe))&&n(t,r)},Tw[e]?{passive:!0}:void 0)}He&&t.dom.addEventListener("input",()=>null),ec(t)}function Tn(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function Pw(t){t.domObserver.stop();for(let e in t.input.eventHandlers)t.dom.removeEventListener(e,t.input.eventHandlers[e]);clearTimeout(t.input.composingTimeout),clearTimeout(t.input.lastIOSEnterFallbackTimeout)}function ec(t){t.someProp("handleDOMEvents",e=>{for(let n in e)t.input.eventHandlers[n]||t.dom.addEventListener(n,t.input.eventHandlers[n]=r=>vd(t,r))})}function vd(t,e){return t.someProp("handleDOMEvents",n=>{let r=n[e.type];return r?r(t,e)||e.defaultPrevented:!1})}function Aw(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let n=e.target;n!=t.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(e))return!1;return!0}function Iw(t,e){!vd(t,e)&&Ge[e.type]&&(t.editable||!(e.type in Qe))&&Ge[e.type](t,e)}Qe.keydown=(t,e)=>{let n=e;if(t.input.shiftKey=n.keyCode==16||n.shiftKey,!n0(t,n)&&(t.input.lastKeyCode=n.keyCode,t.input.lastKeyCodeTime=Date.now(),!(tn&&je&&n.keyCode==13)))if(n.keyCode!=229&&t.domObserver.forceFlush(),pi&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let r=Date.now();t.input.lastIOSEnter=r,t.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{t.input.lastIOSEnter==r&&(t.someProp("handleKeyDown",i=>i(t,er(13,"Enter"))),t.input.lastIOSEnter=0)},200)}else t.someProp("handleKeyDown",r=>r(t,n))||kw(t,n)?n.preventDefault():Tn(t,"key")};Qe.keyup=(t,e)=>{e.keyCode==16&&(t.input.shiftKey=!1)};Qe.keypress=(t,e)=>{let n=e;if(n0(t,n)||!n.charCode||n.ctrlKey&&!n.altKey||gt&&n.metaKey)return;if(t.someProp("handleKeyPress",i=>i(t,n))){n.preventDefault();return}let r=t.state.selection;if(!(r instanceof H)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(n.charCode),s=()=>t.state.tr.insertText(i).scrollIntoView();!/[\r\n]/.test(i)&&!t.someProp("handleTextInput",o=>o(t,r.$from.pos,r.$to.pos,i,s))&&t.dispatch(s()),n.preventDefault()}};function Fl(t){return{left:t.clientX,top:t.clientY}}function Rw(t,e){let n=e.x-t.clientX,r=e.y-t.clientY;return n*n+r*r<100}function xd(t,e,n,r,i){if(r==-1)return!1;let s=t.state.doc.resolve(r);for(let o=s.depth+1;o>0;o--)if(t.someProp(e,l=>o>s.depth?l(t,n,s.nodeAfter,s.before(o),i,!0):l(t,n,s.node(o),s.before(o),i,!1)))return!0;return!1}function ii(t,e,n){if(t.focused||t.focus(),t.state.selection.eq(e))return;let r=t.state.tr.setSelection(e);r.setMeta("pointer",!0),t.dispatch(r)}function Lw(t,e){if(e==-1)return!1;let n=t.state.doc.resolve(e),r=n.nodeAfter;return r&&r.isAtom&&F.isSelectable(r)?(ii(t,new F(n)),!0):!1}function jw(t,e){if(e==-1)return!1;let n=t.state.selection,r,i;n instanceof F&&(r=n.node);let s=t.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(F.isSelectable(l)){r&&n.$from.depth>0&&o>=n.$from.depth&&s.before(n.$from.depth+1)==n.$from.pos?i=s.before(n.$from.depth):i=s.before(o);break}}return i!=null?(ii(t,F.create(t.state.doc,i)),!0):!1}function zw(t,e,n,r,i){return xd(t,"handleClickOn",e,n,r)||t.someProp("handleClick",s=>s(t,e,r))||(i?jw(t,n):Lw(t,n))}function Bw(t,e,n,r){return xd(t,"handleDoubleClickOn",e,n,r)||t.someProp("handleDoubleClick",i=>i(t,e,r))}function Fw(t,e,n,r){return xd(t,"handleTripleClickOn",e,n,r)||t.someProp("handleTripleClick",i=>i(t,e,r))||_w(t,n,r)}function _w(t,e,n){if(n.button!=0)return!1;let r=t.state.doc;if(e==-1)return r.inlineContent?(ii(t,H.create(r,0,r.content.size)),!0):!1;let i=r.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)ii(t,H.create(r,l+1,l+1+o.content.size));else if(F.isSelectable(o))ii(t,F.create(r,l));else continue;return!0}}function Sd(t){return al(t)}const t0=gt?"metaKey":"ctrlKey";Ge.mousedown=(t,e)=>{let n=e;t.input.shiftKey=n.shiftKey;let r=Sd(t),i=Date.now(),s="singleClick";i-t.input.lastClick.time<500&&Rw(n,t.input.lastClick)&&!n[t0]&&t.input.lastClick.button==n.button&&(t.input.lastClick.type=="singleClick"?s="doubleClick":t.input.lastClick.type=="doubleClick"&&(s="tripleClick")),t.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:s,button:n.button};let o=t.posAtCoords(Fl(n));o&&(s=="singleClick"?(t.input.mouseDown&&t.input.mouseDown.done(),t.input.mouseDown=new $w(t,o,n,!!r)):(s=="doubleClick"?Bw:Fw)(t,o.pos,o.inside,n)?n.preventDefault():Tn(t,"pointer"))};class $w{constructor(e,n,r,i){this.view=e,this.pos=n,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[t0],this.allowDefault=r.shiftKey;let s,o;if(n.inside>-1)s=e.state.doc.nodeAt(n.inside),o=n.inside;else{let c=e.state.doc.resolve(n.pos);s=c.parent,o=c.depth?c.before():0}const l=i?null:r.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.nodeDOM.nodeType==1?a.nodeDOM:null;let{selection:u}=e.state;r.button==0&&(s.type.spec.draggable&&s.type.spec.selectable!==!1||u instanceof F&&u.from<=o&&u.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&wt&&!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)),Tn(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(()=>on(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let n=this.pos;this.view.state.doc!=this.startDoc&&(n=this.view.posAtCoords(Fl(e))),this.updateAllowDefault(e),this.allowDefault||!n?Tn(this.view,"pointer"):zw(this.view,n.pos,n.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||He&&this.mightDrag&&!this.mightDrag.node.isAtom||je&&!this.view.state.selection.visible&&Math.min(Math.abs(n.pos-this.view.state.selection.from),Math.abs(n.pos-this.view.state.selection.to))<=2)?(ii(this.view,W.near(this.view.state.doc.resolve(n.pos))),e.preventDefault()):Tn(this.view,"pointer")}move(e){this.updateAllowDefault(e),Tn(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)}}Ge.touchstart=t=>{t.input.lastTouch=Date.now(),Sd(t),Tn(t,"pointer")};Ge.touchmove=t=>{t.input.lastTouch=Date.now(),Tn(t,"pointer")};Ge.contextmenu=t=>Sd(t);function n0(t,e){return t.composing?!0:He&&Math.abs(e.timeStamp-t.input.compositionEndedAt)<500?(t.input.compositionEndedAt=-2e8,!0):!1}const Vw=tn?5e3:-1;Qe.compositionstart=Qe.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,n=e.selection.$to;if(e.selection instanceof H&&(e.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)||je&&Iy&&Uw(t)))t.markCursor=t.state.storedMarks||n.marks(),al(t,!0),t.markCursor=null;else if(al(t,!e.selection.empty),wt&&e.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let r=t.domSelectionRange();for(let i=r.focusNode,s=r.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){let l=t.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else i=o,s=-1}}t.input.composing=!0}r0(t,Vw)};function Uw(t){let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(!e||e.nodeType!=1||n>=e.childNodes.length)return!1;let r=e.childNodes[n];return r.nodeType==1&&r.contentEditable=="false"}Qe.compositionend=(t,e)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=e.timeStamp,t.input.compositionPendingChanges=t.domObserver.pendingRecords().length?t.input.compositionID:0,t.input.compositionNode=null,t.input.badSafariComposition?t.domObserver.forceFlush():t.input.compositionPendingChanges&&Promise.resolve().then(()=>t.domObserver.flush()),t.input.compositionID++,r0(t,20))};function r0(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout(()=>al(t),e))}function i0(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=Ww());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function Hw(t){let e=t.domSelectionRange();if(!e.focusNode)return null;let n=jk(e.focusNode,e.focusOffset),r=zk(e.focusNode,e.focusOffset);if(n&&r&&n!=r){let i=r.pmViewDesc,s=t.domObserver.lastChangedTextNode;if(n==s||r==s)return s;if(!i||!i.isText(r.nodeValue))return r;if(t.input.compositionNode==r){let o=n.pmViewDesc;if(!(!o||!o.isText(n.nodeValue)))return r}}return n||r}function Ww(){let t=document.createEvent("Event");return t.initEvent("event",!0,!0),t.timeStamp}function al(t,e=!1){if(!(tn&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),i0(t),e||t.docView&&t.docView.dirty){let n=md(t),r=t.state.selection;return n&&!n.eq(r)?t.dispatch(t.state.tr.setSelection(n)):(t.markCursor||e)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?t.dispatch(t.state.tr.deleteSelection()):t.updateState(t.state),!0}return!1}}function Kw(t,e){if(!t.dom.parentNode)return;let n=t.dom.parentNode.appendChild(document.createElement("div"));n.appendChild(e),n.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),t.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),t.focus()},50)}const Cs=ot&&Bn<15||pi&&$k<604;Ge.copy=Qe.cut=(t,e)=>{let n=e,r=t.state.selection,i=n.type=="cut";if(r.empty)return;let s=Cs?null:n.clipboardData,o=r.content(),{dom:l,text:a}=yd(t,o);s?(n.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):Kw(t,l),i&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Jw(t){return t.openStart==0&&t.openEnd==0&&t.content.childCount==1?t.content.firstChild:null}function qw(t,e){if(!t.dom.parentNode)return;let n=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,r=t.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=t.input.shiftKey&&t.input.lastKeyCode!=45;setTimeout(()=>{t.focus(),r.parentNode&&r.parentNode.removeChild(r),n?Es(t,r.value,null,i,e):Es(t,r.textContent,r.innerHTML,i,e)},50)}function Es(t,e,n,r,i){let s=Gy(t,e,n,r,t.state.selection.$from);if(t.someProp("handlePaste",a=>a(t,i,s||I.empty)))return!0;if(!s)return!1;let o=Jw(s),l=o?t.state.tr.replaceSelectionWith(o,r):t.state.tr.replaceSelection(s);return t.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function s0(t){let e=t.getData("text/plain")||t.getData("Text");if(e)return e;let n=t.getData("text/uri-list");return n?n.replace(/\r?\n/g," "):""}Qe.paste=(t,e)=>{let n=e;if(t.composing&&!tn)return;let r=Cs?null:n.clipboardData,i=t.input.shiftKey&&t.input.lastKeyCode!=45;r&&Es(t,s0(r),r.getData("text/html"),i,n)?n.preventDefault():qw(t,n)};class o0{constructor(e,n,r){this.slice=e,this.move=n,this.node=r}}const Gw=gt?"altKey":"ctrlKey";function l0(t,e){let n;return t.someProp("dragCopies",r=>{n=n||r(e)}),n!=null?!n:!e[Gw]}Ge.dragstart=(t,e)=>{let n=e,r=t.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=t.state.selection,s=i.empty?null:t.posAtCoords(Fl(n)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof F?i.to-1:i.to))){if(r&&r.mightDrag)o=F.create(t.state.doc,r.mightDrag.pos);else if(n.target&&n.target.nodeType==1){let d=t.docView.nearestDesc(n.target,!0);d&&d.node.type.spec.draggable&&d!=t.docView&&(o=F.create(t.state.doc,d.posBefore))}}let l=(o||t.state.selection).content(),{dom:a,text:u,slice:c}=yd(t,l);(!n.dataTransfer.files.length||!je||Ay>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(Cs?"Text":"text/html",a.innerHTML),n.dataTransfer.effectAllowed="copyMove",Cs||n.dataTransfer.setData("text/plain",u),t.dragging=new o0(c,l0(t,n),o)};Ge.dragend=t=>{let e=t.dragging;window.setTimeout(()=>{t.dragging==e&&(t.dragging=null)},50)};Qe.dragover=Qe.dragenter=(t,e)=>e.preventDefault();Qe.drop=(t,e)=>{try{Qw(t,e,t.dragging)}finally{t.dragging=null}};function Qw(t,e,n){if(!e.dataTransfer)return;let r=t.posAtCoords(Fl(e));if(!r)return;let i=t.state.doc.resolve(r.pos),s=n&&n.slice;s?t.someProp("transformPasted",h=>{s=h(s,t,!1)}):s=Gy(t,s0(e.dataTransfer),Cs?null:e.dataTransfer.getData("text/html"),!1,i);let o=!!(n&&l0(t,e));if(t.someProp("handleDrop",h=>h(t,e,s||I.empty,o))){e.preventDefault();return}if(!s)return;e.preventDefault();let l=s?Ey(t.state.doc,i.pos,s):i.pos;l==null&&(l=i.pos);let a=t.state.tr;if(o){let{node:h}=n;h?h.replace(a):a.deleteSelection()}let u=a.mapping.map(l),c=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,d=a.doc;if(c?a.replaceRangeWith(u,u,s.content.firstChild):a.replaceRange(u,u,s),a.doc.eq(d))return;let f=a.doc.resolve(u);if(c&&F.isSelectable(s.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(s.content.firstChild))a.setSelection(new F(f));else{let h=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((p,m,x,g)=>h=g),a.setSelection(gd(t,f,a.doc.resolve(h)))}t.focus(),t.dispatch(a.setMeta("uiEvent","drop"))}Ge.focus=t=>{t.input.lastFocus=Date.now(),t.focused||(t.domObserver.stop(),t.dom.classList.add("ProseMirror-focused"),t.domObserver.start(),t.focused=!0,setTimeout(()=>{t.docView&&t.hasFocus()&&!t.domObserver.currentSelection.eq(t.domSelectionRange())&&on(t)},20))};Ge.blur=(t,e)=>{let n=e;t.focused&&(t.domObserver.stop(),t.dom.classList.remove("ProseMirror-focused"),t.domObserver.start(),n.relatedTarget&&t.dom.contains(n.relatedTarget)&&t.domObserver.currentSelection.clear(),t.focused=!1)};Ge.beforeinput=(t,e)=>{if(je&&tn&&e.inputType=="deleteContentBackward"){t.domObserver.flushSoon();let{domChangeCount:r}=t.input;setTimeout(()=>{if(t.input.domChangeCount!=r||(t.dom.blur(),t.focus(),t.someProp("handleKeyDown",s=>s(t,er(8,"Backspace")))))return;let{$cursor:i}=t.state.selection;i&&i.pos>0&&t.dispatch(t.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let t in Qe)Ge[t]=Qe[t];function Ns(t,e){if(t==e)return!0;for(let n in t)if(t[n]!==e[n])return!1;for(let n in e)if(!(n in t))return!1;return!0}class ul{constructor(e,n){this.toDOM=e,this.spec=n||pr,this.side=this.spec.side||0}map(e,n,r,i){let{pos:s,deleted:o}=e.mapResult(n.from+i,this.side<0?-1:1);return o?null:new ct(s-r,s-r,this)}valid(){return!0}eq(e){return this==e||e instanceof ul&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Ns(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class _n{constructor(e,n){this.attrs=e,this.spec=n||pr}map(e,n,r,i){let s=e.map(n.from+i,this.spec.inclusiveStart?-1:1)-r,o=e.map(n.to+i,this.spec.inclusiveEnd?1:-1)-r;return s>=o?null:new ct(s,o,this)}valid(e,n){return n.from=e&&(!s||s(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let o=0;oe){let l=this.children[o]+1;this.children[o+2].findInner(e-l,n-l,r,i+l,s)}}map(e,n,r){return this==$e||e.maps.length==0?this:this.mapInner(e,n,0,0,r||pr)}mapInner(e,n,r,i,s){let o;for(let l=0;l{let u=a+r,c;if(c=u0(n,l,u)){for(i||(i=this.children.slice());sl&&d.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let s=e+1,o=s+n.content.size;for(let l=0;ls&&a.type instanceof _n){let u=Math.max(s,a.from)-s,c=Math.min(o,a.to)-s;ui.map(e,n,pr));return wn.from(r)}forChild(e,n){if(n.isLeaf)return ge.empty;let r=[];for(let i=0;in instanceof ge)?e:e.reduce((n,r)=>n.concat(r instanceof ge?r:r.members),[]))}}forEachSet(e){for(let n=0;n{let x=m-p-(h-f);for(let g=0;gv+c-d)continue;let S=l[g]+c-d;h>=S?l[g+1]=f<=S?-2:-1:f>=c&&x&&(l[g]+=x,l[g+1]+=x)}d+=x}),c=n.maps[u].map(c,-1)}let a=!1;for(let u=0;u=r.content.size){a=!0;continue}let f=n.map(t[u+1]+s,-1),h=f-i,{index:p,offset:m}=r.content.findIndex(d),x=r.maybeChild(p);if(x&&m==d&&m+x.nodeSize==h){let g=l[u+2].mapInner(n,x,c+1,t[u]+s+1,o);g!=$e?(l[u]=d,l[u+1]=h,l[u+2]=g):(l[u+1]=-2,a=!0)}else a=!0}if(a){let u=Xw(l,t,e,n,i,s,o),c=cl(u,r,0,o);e=c.local;for(let d=0;dn&&o.to{let u=u0(t,l,a+n);if(u){s=!0;let c=cl(u,l,n+a+1,r);c!=$e&&i.push(a,a+l.nodeSize,c)}});let o=a0(s?c0(t):t,-n).sort(mr);for(let l=0;l0;)e++;t.splice(e,0,n)}function Ia(t){let e=[];return t.someProp("decorations",n=>{let r=n(t.state);r&&r!=$e&&e.push(r)}),t.cursorWrapper&&e.push(ge.create(t.state.doc,[t.cursorWrapper.deco])),wn.from(e)}const Zw={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},eC=ot&&Bn<=11;class tC{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}}class nC{constructor(e,n){this.view=e,this.handleDOMChange=n,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new tC,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():He&&e.composing&&r.some(i=>i.type=="childList"&&i.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),eC&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.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,Zw)),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 n=0;nthis.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(Lh(this.view)){if(this.suppressingSelectionUpdates)return on(this.view);if(ot&&Bn<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Er(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 n=new Set,r;for(let s=e.focusNode;s;s=hi(s))n.add(s);for(let s=e.anchorNode;s;s=hi(s))if(n.has(s)){r=s;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))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 n=this.pendingRecords();n.length&&(this.queue=[]);let r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&Lh(e)&&!this.ignoreSelectionChange(r),s=-1,o=-1,l=!1,a=[];if(e.editable)for(let c=0;cc.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46)){for(let c of a)if(c.nodeName=="BR"&&c.parentNode){let d=c.nextSibling;for(;d&&d.nodeType==1;){if(d.contentEditable=="false"){c.parentNode.removeChild(c);break}d=d.firstChild}}}else if(wt&&a.length){let c=a.filter(d=>d.nodeName=="BR");if(c.length==2){let[d,f]=c;d.parentNode&&d.parentNode.parentNode==f.parentNode?f.remove():d.remove()}else{let{focusNode:d}=this.currentSelection;for(let f of c){let h=f.parentNode;h&&h.nodeName=="LI"&&(!d||sC(e,d)!=h)&&f.remove()}}}let u=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(s>-1&&(e.docView.markDirty(s,o),rC(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,oC(e,a)),this.handleDOMChange(s,o,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||on(e),this.currentSelection.set(r))}registerMutation(e,n){if(n.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let c=0;ci;x--){let g=r.childNodes[x-1],v=g.pmViewDesc;if(g.nodeName=="BR"&&!v){s=x;break}if(!v||v.size)break}let d=t.state.doc,f=t.someProp("domParser")||zn.fromSchema(t.state.schema),h=d.resolve(o),p=null,m=f.parse(r,{topNode:h.parent,topMatch:h.parent.contentMatchAt(h.index()),topOpen:!0,from:i,to:s,preserveWhitespace:h.parent.type.whitespace=="pre"?"full":!0,findPositions:u,ruleFromNode:aC,context:h});if(u&&u[0].pos!=null){let x=u[0].pos,g=u[1]&&u[1].pos;g==null&&(g=x),p={anchor:x+o,head:g+o}}return{doc:m,sel:p,from:o,to:l}}function aC(t){let e=t.pmViewDesc;if(e)return e.parseRule();if(t.nodeName=="BR"&&t.parentNode){if(He&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let n=document.createElement("div");return n.appendChild(document.createElement("li")),{skip:n}}else if(t.parentNode.lastChild==t||He&&/^(tr|table)$/i.test(t.parentNode.nodeName))return{ignore:!0}}else if(t.nodeName=="IMG"&&t.getAttribute("mark-placeholder"))return{ignore:!0};return null}const uC=/^(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 cC(t,e,n,r,i){let s=t.input.compositionPendingChanges||(t.composing?t.input.compositionID:0);if(t.input.compositionPendingChanges=0,e<0){let C=t.input.lastSelectionTime>Date.now()-50?t.input.lastSelectionOrigin:null,M=md(t,C);if(M&&!t.state.selection.eq(M)){if(je&&tn&&t.input.lastKeyCode===13&&Date.now()-100N(t,er(13,"Enter"))))return;let _=t.state.tr.setSelection(M);C=="pointer"?_.setMeta("pointer",!0):C=="key"&&_.scrollIntoView(),s&&_.setMeta("composition",s),t.dispatch(_)}return}let o=t.state.doc.resolve(e),l=o.sharedDepth(n);e=o.before(l+1),n=t.state.doc.resolve(n).after(l+1);let a=t.state.selection,u=lC(t,e,n),c=t.state.doc,d=c.slice(u.from,u.to),f,h;t.input.lastKeyCode===8&&Date.now()-100Date.now()-225||tn)&&i.some(C=>C.nodeType==1&&!uC.test(C.nodeName))&&(!p||p.endA>=p.endB)&&t.someProp("handleKeyDown",C=>C(t,er(13,"Enter")))){t.input.lastIOSEnter=0;return}if(!p)if(r&&a instanceof H&&!a.empty&&a.$head.sameParent(a.$anchor)&&!t.composing&&!(u.sel&&u.sel.anchor!=u.sel.head))p={start:a.from,endA:a.to,endB:a.to};else{if(u.sel){let C=Jh(t,t.state.doc,u.sel);if(C&&!C.eq(t.state.selection)){let M=t.state.tr.setSelection(C);s&&M.setMeta("composition",s),t.dispatch(M)}}return}t.state.selection.fromt.state.selection.from&&p.start<=t.state.selection.from+2&&t.state.selection.from>=u.from?p.start=t.state.selection.from:p.endA=t.state.selection.to-2&&t.state.selection.to<=u.to&&(p.endB+=t.state.selection.to-p.endA,p.endA=t.state.selection.to)),ot&&Bn<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>u.from&&u.doc.textBetween(p.start-u.from-1,p.start-u.from+1)=="  "&&(p.start--,p.endA--,p.endB--);let m=u.doc.resolveNoCache(p.start-u.from),x=u.doc.resolveNoCache(p.endB-u.from),g=c.resolve(p.start),v=m.sameParent(x)&&m.parent.inlineContent&&g.end()>=p.endA;if((pi&&t.input.lastIOSEnter>Date.now()-225&&(!v||i.some(C=>C.nodeName=="DIV"||C.nodeName=="P"))||!v&&m.posC(t,er(13,"Enter")))){t.input.lastIOSEnter=0;return}if(t.state.selection.anchor>p.start&&fC(c,p.start,p.endA,m,x)&&t.someProp("handleKeyDown",C=>C(t,er(8,"Backspace")))){tn&&je&&t.domObserver.suppressSelectionUpdates();return}je&&p.endB==p.start&&(t.input.lastChromeDelete=Date.now()),tn&&!v&&m.start()!=x.start()&&x.parentOffset==0&&m.depth==x.depth&&u.sel&&u.sel.anchor==u.sel.head&&u.sel.head==p.endA&&(p.endB-=2,x=u.doc.resolveNoCache(p.endB-u.from),setTimeout(()=>{t.someProp("handleKeyDown",function(C){return C(t,er(13,"Enter"))})},20));let S=p.start,w=p.endA,E=C=>{let M=C||t.state.tr.replace(S,w,u.doc.slice(p.start-u.from,p.endB-u.from));if(u.sel){let _=Jh(t,M.doc,u.sel);_&&!(je&&t.composing&&_.empty&&(p.start!=p.endB||t.input.lastChromeDeleteon(t),20));let C=E(t.state.tr.delete(S,w)),M=c.resolve(p.start).marksAcross(c.resolve(p.endA));M&&C.ensureMarks(M),t.dispatch(C)}else if(p.endA==p.endB&&(b=dC(m.parent.content.cut(m.parentOffset,x.parentOffset),g.parent.content.cut(g.parentOffset,p.endA-g.start())))){let C=E(t.state.tr);b.type=="add"?C.addMark(S,w,b.mark):C.removeMark(S,w,b.mark),t.dispatch(C)}else if(m.parent.child(m.index()).isText&&m.index()==x.index()-(x.textOffset?0:1)){let C=m.parent.textBetween(m.parentOffset,x.parentOffset),M=()=>E(t.state.tr.insertText(C,S,w));t.someProp("handleTextInput",_=>_(t,S,w,C,M))||t.dispatch(M())}else t.dispatch(E());else t.dispatch(E())}function Jh(t,e,n){return Math.max(n.anchor,n.head)>e.content.size?null:gd(t,e.resolve(n.anchor),e.resolve(n.head))}function dC(t,e){let n=t.firstChild.marks,r=e.firstChild.marks,i=n,s=r,o,l,a;for(let c=0;cc.mark(l.addToSet(c.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",a=c=>c.mark(l.removeFromSet(c.marks));else return null;let u=[];for(let c=0;cn||Ra(o,!0,!1)0&&(e||t.indexAfter(r)==t.node(r).childCount);)r--,i++,e=!1;if(n){let s=t.node(r).maybeChild(t.indexAfter(r));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function hC(t,e,n,r,i){let s=t.findDiffStart(e,n);if(s==null)return null;let{a:o,b:l}=t.findDiffEnd(e,n+t.size,n+e.size);if(i=="end"){let a=Math.max(0,s-Math.min(o,l));r-=o+a-s}if(o=o?s-r:0;s-=a,s&&s=l?s-r:0;s-=a,s&&s=56320&&e<=57343&&n>=55296&&n<=56319}class d0{constructor(e,n){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 Ow,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=n,this.state=n.state,this.directPlugins=n.plugins||[],this.directPlugins.forEach(Zh),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=Yh(this),Qh(this),this.nodeViews=Xh(this),this.docView=Oh(this.state.doc,Gh(this),Ia(this),this.dom,this),this.domObserver=new nC(this,(r,i,s,o)=>cC(this,r,i,s,o)),this.domObserver.start(),Dw(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 n in e)this._props[n]=e[n];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&ec(this);let n=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Zh),this.directPlugins=e.plugins),this.updateStateInner(e.state,n)}setProps(e){let n={};for(let r in this._props)n[r]=this._props[r];n.state=this.state;for(let r in e)n[r]=e[r];this.update(n)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,n){var r;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(i0(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=n.plugins;if(l||this._props.plugins!=n.plugins||this._props.nodeViews!=n.nodeViews){let h=Xh(this);mC(h,this.nodeViews)&&(this.nodeViews=h,s=!0)}(l||n.handleDOMEvents!=this._props.handleDOMEvents)&&ec(this),this.editable=Yh(this),Qh(this);let a=Ia(this),u=Gh(this),c=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",d=s||!this.docView.matchesNode(e.doc,u,a);(d||!e.selection.eq(i.selection))&&(o=!0);let f=c=="preserve"&&o&&this.dom.style.overflowAnchor==null&&Hk(this);if(o){this.domObserver.stop();let h=d&&(ot||je)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&pC(i.selection,e.selection);if(d){let p=je?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=Hw(this)),(s||!this.docView.update(e.doc,u,a,this))&&(this.docView.updateOuterDeco(u),this.docView.destroy(),this.docView=Oh(e.doc,u,a,this.dom,this)),p&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(h=!0)}h||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&pw(this))?on(this,h):(Ky(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),c=="reset"?this.dom.scrollTop=0:c=="to selection"?this.scrollToSelection():f&&Wk(f)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",n=>n(this)))if(this.state.selection instanceof F){let n=this.docView.domAfterPos(this.state.selection.from);n.nodeType==1&&Ch(this,n.getBoundingClientRect(),e)}else Ch(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 n=0;n0&&sn.ownerDocument.getSelection()),this._root=n}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Yk(this,e)}coordsAtPos(e,n=1){return By(this,e,n)}domAtPos(e,n=0){return this.docView.domFromPos(e,n)}nodeDOM(e){let n=this.docView.descAt(e);return n?n.nodeDOM:null}posAtDOM(e,n,r=-1){let i=this.docView.posFromDOM(e,n,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,n){return nw(this,n||this.state,e)}pasteHTML(e,n){return Es(this,"",e,!1,n||new ClipboardEvent("paste"))}pasteText(e,n){return Es(this,e,null,!0,n||new ClipboardEvent("paste"))}serializeForClipboard(e){return yd(this,e)}destroy(){this.docView&&(Pw(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Ia(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Rk())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Iw(this,e)}domSelectionRange(){let e=this.domSelection();return e?He&&this.root.nodeType===11&&Fk(this.dom.ownerDocument)==this.dom&&iC(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}d0.prototype.dispatch=function(t){let e=this._props.dispatchTransaction;e?e.call(this,t):this.updateState(this.state.apply(t))};function Gh(t){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(t.editable),t.someProp("attributes",n=>{if(typeof n=="function"&&(n=n(t.state)),n)for(let r in n)r=="class"?e.class+=" "+n[r]:r=="style"?e.style=(e.style?e.style+";":"")+n[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(n[r]))}),e.translate||(e.translate="no"),[ct.node(0,t.state.doc.content.size,e)]}function Qh(t){if(t.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),t.cursorWrapper={dom:e,deco:ct.widget(t.state.selection.from,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function Yh(t){return!t.someProp("editable",e=>e(t.state)===!1)}function pC(t,e){let n=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(n)!=e.$anchor.start(n)}function Xh(t){let e=Object.create(null);function n(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return t.someProp("nodeViews",n),t.someProp("markViews",n),e}function mC(t,e){let n=0,r=0;for(let i in t){if(t[i]!=e[i])return!0;n++}for(let i in e)r++;return n!=r}function Zh(t){if(t.spec.state||t.spec.filterTransaction||t.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var Un={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:"'"},dl={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},gC=typeof navigator<"u"&&/Mac/.test(navigator.platform),yC=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var Le=0;Le<10;Le++)Un[48+Le]=Un[96+Le]=String(Le);for(var Le=1;Le<=24;Le++)Un[Le+111]="F"+Le;for(var Le=65;Le<=90;Le++)Un[Le]=String.fromCharCode(Le+32),dl[Le]=String.fromCharCode(Le);for(var La in Un)dl.hasOwnProperty(La)||(dl[La]=Un[La]);function vC(t){var e=gC&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||yC&&t.shiftKey&&t.key&&t.key.length==1||t.key=="Unidentified",n=!e&&t.key||(t.shiftKey?dl:Un)[t.keyCode]||t.key||"Unidentified";return n=="Esc"&&(n="Escape"),n=="Del"&&(n="Delete"),n=="Left"&&(n="ArrowLeft"),n=="Up"&&(n="ArrowUp"),n=="Right"&&(n="ArrowRight"),n=="Down"&&(n="ArrowDown"),n}const xC=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),SC=typeof navigator<"u"&&/Win/.test(navigator.platform);function kC(t){let e=t.split(/-(?!$)/),n=e[e.length-1];n=="Space"&&(n=" ");let r,i,s,o;for(let l=0;lt.selection.empty?!1:(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function h0(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("backward",t):n.parentOffset>0)?null:n}const p0=(t,e,n)=>{let r=h0(t,n);if(!r)return!1;let i=Ed(r);if(!i){let o=r.blockRange(),l=o&&Si(o);return l==null?!1:(e&&e(t.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(C0(t,i,e,-1))return!0;if(r.parent.content.size==0&&(mi(s,"end")||F.isSelectable(s)))for(let o=r.depth;;o--){let l=Ll(t.doc,r.before(o),r.after(o),I.empty);if(l&&l.slice.size1)break}return s.isAtom&&i.depth==r.depth-1?(e&&e(t.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1},EC=(t,e,n)=>{let r=h0(t,n);if(!r)return!1;let i=Ed(r);return i?m0(t,i,e):!1},NC=(t,e,n)=>{let r=y0(t,n);if(!r)return!1;let i=Nd(r);return i?m0(t,i,e):!1};function m0(t,e,n){let r=e.nodeBefore,i=r,s=e.pos-1;for(;!i.isTextblock;s--){if(i.type.spec.isolating)return!1;let c=i.lastChild;if(!c)return!1;i=c}let o=e.nodeAfter,l=o,a=e.pos+1;for(;!l.isTextblock;a++){if(l.type.spec.isolating)return!1;let c=l.firstChild;if(!c)return!1;l=c}let u=Ll(t.doc,s,a,I.empty);if(!u||u.from!=s||u instanceof me&&u.slice.size>=a-s)return!1;if(n){let c=t.tr.step(u);c.setSelection(H.create(c.doc,s)),n(c.scrollIntoView())}return!0}function mi(t,e,n=!1){for(let r=t;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&r.childCount!=1)return!1}return!1}const g0=(t,e,n)=>{let{$head:r,empty:i}=t.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",t):r.parentOffset>0)return!1;s=Ed(r)}let o=s&&s.nodeBefore;return!o||!F.isSelectable(o)?!1:(e&&e(t.tr.setSelection(F.create(t.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function Ed(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){if(t.index(e)>0)return t.doc.resolve(t.before(e+1));if(t.node(e).type.spec.isolating)break}return null}function y0(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("forward",t):n.parentOffset{let r=y0(t,n);if(!r)return!1;let i=Nd(r);if(!i)return!1;let s=i.nodeAfter;if(C0(t,i,e,1))return!0;if(r.parent.content.size==0&&(mi(s,"start")||F.isSelectable(s))){let o=Ll(t.doc,r.before(),r.after(),I.empty);if(o&&o.slice.size{let{$head:r,empty:i}=t.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",t):r.parentOffset=0;e--){let n=t.node(e);if(t.index(e)+1{let n=t.selection,r=n instanceof F,i;if(r){if(n.node.isTextblock||!qn(t.doc,n.from))return!1;i=n.from}else if(i=Rl(t.doc,n.from,-1),i==null)return!1;if(e){let s=t.tr.join(i);r&&s.setSelection(F.create(s.doc,i-t.doc.resolve(i).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},MC=(t,e)=>{let n=t.selection,r;if(n instanceof F){if(n.node.isTextblock||!qn(t.doc,n.to))return!1;r=n.to}else if(r=Rl(t.doc,n.to,1),r==null)return!1;return e&&e(t.tr.join(r).scrollIntoView()),!0},TC=(t,e)=>{let{$from:n,$to:r}=t.selection,i=n.blockRange(r),s=i&&Si(i);return s==null?!1:(e&&e(t.tr.lift(i,s).scrollIntoView()),!0)},S0=(t,e)=>{let{$head:n,$anchor:r}=t.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(e&&e(t.tr.insertText(` +`).scrollIntoView()),!0)};function bd(t){for(let e=0;e{let{$head:n,$anchor:r}=t.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),s=n.indexAfter(-1),o=bd(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=n.after(),a=t.tr.replaceWith(l,l,o.createAndFill());a.setSelection(W.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},k0=(t,e)=>{let n=t.selection,{$from:r,$to:i}=n;if(n instanceof ft||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=bd(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!r.parentOffset&&i.index(){let{$cursor:n}=t.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let s=n.before();if(sn(t.doc,s))return e&&e(t.tr.split(s).scrollIntoView()),!0}let r=n.blockRange(),i=r&&Si(r);return i==null?!1:(e&&e(t.tr.lift(r,i).scrollIntoView()),!0)};function DC(t){return(e,n)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof F&&e.selection.node.isBlock)return!r.parentOffset||!sn(e.doc,r.pos)?!1:(n&&n(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let s=[],o,l,a=!1,u=!1;for(let h=r.depth;;h--)if(r.node(h).isBlock){a=r.end(h)==r.pos+(r.depth-h),u=r.start(h)==r.pos-(r.depth-h),l=bd(r.node(h-1).contentMatchAt(r.indexAfter(h-1))),s.unshift(a&&l?{type:l}:null),o=h;break}else{if(h==1)return!1;s.unshift(null)}let c=e.tr;(e.selection instanceof H||e.selection instanceof ft)&&c.deleteSelection();let d=c.mapping.map(r.pos),f=sn(c.doc,d,s.length,s);if(f||(s[0]=l?{type:l}:null,f=sn(c.doc,d,s.length,s)),!f)return!1;if(c.split(d,s.length,s),!a&&u&&r.node(o).type!=l){let h=c.mapping.map(r.before(o)),p=c.doc.resolve(h);l&&r.node(o-1).canReplaceWith(p.index(),p.index()+1,l)&&c.setNodeMarkup(c.mapping.map(r.before(o)),l)}return n&&n(c.scrollIntoView()),!0}}const PC=DC(),AC=(t,e)=>{let{$from:n,to:r}=t.selection,i,s=n.sharedDepth(r);return s==0?!1:(i=n.before(s),e&&e(t.tr.setSelection(F.create(t.doc,i))),!0)};function IC(t,e,n){let r=e.nodeBefore,i=e.nodeAfter,s=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(s-1,s)?(n&&n(t.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||qn(t.doc,e.pos))?!1:(n&&n(t.tr.join(e.pos).scrollIntoView()),!0)}function C0(t,e,n,r){let i=e.nodeBefore,s=e.nodeAfter,o,l,a=i.type.spec.isolating||s.type.spec.isolating;if(!a&&IC(t,e,n))return!0;let u=!a&&e.parent.canReplace(e.index(),e.index()+1);if(u&&(o=(l=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(n){let h=e.pos+s.nodeSize,p=O.empty;for(let g=o.length-1;g>=0;g--)p=O.from(o[g].create(null,p));p=O.from(i.copy(p));let m=t.tr.step(new Te(e.pos-1,h,e.pos,h,new I(p,1,0),o.length,!0)),x=m.doc.resolve(h+2*o.length);x.nodeAfter&&x.nodeAfter.type==i.type&&qn(m.doc,x.pos)&&m.join(x.pos),n(m.scrollIntoView())}return!0}let c=s.type.spec.isolating||r>0&&a?null:W.findFrom(e,1),d=c&&c.$from.blockRange(c.$to),f=d&&Si(d);if(f!=null&&f>=e.depth)return n&&n(t.tr.lift(d,f).scrollIntoView()),!0;if(u&&mi(s,"start",!0)&&mi(i,"end")){let h=i,p=[];for(;p.push(h),!h.isTextblock;)h=h.lastChild;let m=s,x=1;for(;!m.isTextblock;m=m.firstChild)x++;if(h.canReplace(h.childCount,h.childCount,m.content)){if(n){let g=O.empty;for(let S=p.length-1;S>=0;S--)g=O.from(p[S].copy(g));let v=t.tr.step(new Te(e.pos-p.length,e.pos+s.nodeSize,e.pos+x,e.pos+s.nodeSize-x,new I(g,p.length,0),0,!0));n(v.scrollIntoView())}return!0}}return!1}function E0(t){return function(e,n){let r=e.selection,i=t<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(n&&n(e.tr.setSelection(H.create(e.doc,t<0?i.start(s):i.end(s)))),!0):!1}}const RC=E0(-1),LC=E0(1);function jC(t,e=null){return function(n,r){let{$from:i,$to:s}=n.selection,o=i.blockRange(s),l=o&&fd(o,t,e);return l?(r&&r(n.tr.wrap(o,l).scrollIntoView()),!0):!1}}function ep(t,e=null){return function(n,r){let i=!1;for(let s=0;s{if(i)return!1;if(!(!a.isTextblock||a.hasMarkup(t,e)))if(a.type==t)i=!0;else{let c=n.doc.resolve(u),d=c.index();i=c.parent.canReplaceWith(d,d+1,t)}})}if(!i)return!1;if(r){let s=n.tr;for(let o=0;o=2&&e.$from.node(e.depth-1).type.compatibleContent(n)&&e.startIndex==0){if(e.$from.index(e.depth-1)==0)return!1;let a=o.resolve(e.start-2);s=new il(a,a,e.depth),e.endIndex=0;c--)s=O.from(n[c].type.create(n[c].attrs,s));t.step(new Te(e.start-(r?2:0),e.end,e.start,e.end,new I(s,0,0),n.length,!0));let o=0;for(let c=0;co.childCount>0&&o.firstChild.type==t);return s?n?r.node(s.depth-1).type==t?$C(e,n,t,s):VC(e,n,s):!0:!1}}function $C(t,e,n,r){let i=t.tr,s=r.end,o=r.$to.end(r.depth);sm;p--)h-=i.child(p).nodeSize,r.delete(h-1,h+1);let s=r.doc.resolve(n.start),o=s.nodeAfter;if(r.mapping.map(n.end)!=n.start+s.nodeAfter.nodeSize)return!1;let l=n.startIndex==0,a=n.endIndex==i.childCount,u=s.node(-1),c=s.index(-1);if(!u.canReplace(c+(l?0:1),c+1,o.content.append(a?O.empty:O.from(i))))return!1;let d=s.pos,f=d+o.nodeSize;return r.step(new Te(d-(l?1:0),f+(a?1:0),d+1,f-1,new I((l?O.empty:O.from(i.copy(O.empty))).append(a?O.empty:O.from(i.copy(O.empty))),l?0:1,a?0:1),l?0:1)),e(r.scrollIntoView()),!0}function UC(t){return function(e,n){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,u=>u.childCount>0&&u.firstChild.type==t);if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,a=l.child(o-1);if(a.type!=t)return!1;if(n){let u=a.lastChild&&a.lastChild.type==l.type,c=O.from(u?t.create():null),d=new I(O.from(t.create(null,O.from(l.type.create(null,c)))),u?3:1,0),f=s.start,h=s.end;n(e.tr.step(new Te(f-(u?3:1),h,f,h,d,1,!0)).scrollIntoView())}return!0}}function _l(t){const{state:e,transaction:n}=t;let{selection:r}=n,{doc:i}=n,{storedMarks:s}=n;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return s},get selection(){return r},get doc(){return i},get tr(){return r=n.selection,i=n.doc,s=n.storedMarks,n}}}class $l{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(){const{rawCommands:e,editor:n,state:r}=this,{view:i}=n,{tr:s}=r,o=this.buildProps(s);return Object.fromEntries(Object.entries(e).map(([l,a])=>[l,(...c)=>{const d=a(...c)(o);return!s.getMeta("preventDispatch")&&!this.hasCustomState&&i.dispatch(s),d}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,n=!0){const{rawCommands:r,editor:i,state:s}=this,{view:o}=i,l=[],a=!!e,u=e||s.tr,c=()=>(!a&&n&&!u.getMeta("preventDispatch")&&!this.hasCustomState&&o.dispatch(u),l.every(f=>f===!0)),d={...Object.fromEntries(Object.entries(r).map(([f,h])=>[f,(...m)=>{const x=this.buildProps(u,n),g=h(...m)(x);return l.push(g),d}])),run:c};return d}createCan(e){const{rawCommands:n,state:r}=this,i=!1,s=e||r.tr,o=this.buildProps(s,i);return{...Object.fromEntries(Object.entries(n).map(([a,u])=>[a,(...c)=>u(...c)({...o,dispatch:void 0})])),chain:()=>this.createChain(s,i)}}buildProps(e,n=!0){const{rawCommands:r,editor:i,state:s}=this,{view:o}=i,l={tr:e,editor:i,view:o,state:_l({state:s,transaction:e}),dispatch:n?()=>{}:void 0,chain:()=>this.createChain(e,n),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(r).map(([a,u])=>[a,(...c)=>u(...c)(l)]))}};return l}}class HC{constructor(){this.callbacks={}}on(e,n){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(n),this}emit(e,...n){const r=this.callbacks[e];return r&&r.forEach(i=>i.apply(this,n)),this}off(e,n){const r=this.callbacks[e];return r&&(n?this.callbacks[e]=r.filter(i=>i!==n):delete this.callbacks[e]),this}once(e,n){const r=(...i)=>{this.off(e,r),n.apply(this,i)};return this.on(e,r)}removeAllListeners(){this.callbacks={}}}function L(t,e,n){return t.config[e]===void 0&&t.parent?L(t.parent,e,n):typeof t.config[e]=="function"?t.config[e].bind({...n,parent:t.parent?L(t.parent,e,n):null}):t.config[e]}function Vl(t){const e=t.filter(i=>i.type==="extension"),n=t.filter(i=>i.type==="node"),r=t.filter(i=>i.type==="mark");return{baseExtensions:e,nodeExtensions:n,markExtensions:r}}function N0(t){const e=[],{nodeExtensions:n,markExtensions:r}=Vl(t),i=[...n,...r],s={default:null,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1};return t.forEach(o=>{const l={name:o.name,options:o.options,storage:o.storage,extensions:i},a=L(o,"addGlobalAttributes",l);if(!a)return;a().forEach(c=>{c.types.forEach(d=>{Object.entries(c.attributes).forEach(([f,h])=>{e.push({type:d,name:f,attribute:{...s,...h}})})})})}),i.forEach(o=>{const l={name:o.name,options:o.options,storage:o.storage},a=L(o,"addAttributes",l);if(!a)return;const u=a();Object.entries(u).forEach(([c,d])=>{const f={...s,...d};typeof(f==null?void 0:f.default)=="function"&&(f.default=f.default()),f!=null&&f.isRequired&&(f==null?void 0:f.default)===void 0&&delete f.default,e.push({type:o.name,name:c,attribute:f})})}),e}function De(t,e){if(typeof t=="string"){if(!e.nodes[t])throw Error(`There is no node type named '${t}'. Maybe you forgot to add the extension?`);return e.nodes[t]}return t}function Se(...t){return t.filter(e=>!!e).reduce((e,n)=>{const r={...e};return Object.entries(n).forEach(([i,s])=>{if(!r[i]){r[i]=s;return}if(i==="class"){const l=s?String(s).split(" "):[],a=r[i]?r[i].split(" "):[],u=l.filter(c=>!a.includes(c));r[i]=[...a,...u].join(" ")}else if(i==="style"){const l=s?s.split(";").map(c=>c.trim()).filter(Boolean):[],a=r[i]?r[i].split(";").map(c=>c.trim()).filter(Boolean):[],u=new Map;a.forEach(c=>{const[d,f]=c.split(":").map(h=>h.trim());u.set(d,f)}),l.forEach(c=>{const[d,f]=c.split(":").map(h=>h.trim());u.set(d,f)}),r[i]=Array.from(u.entries()).map(([c,d])=>`${c}: ${d}`).join("; ")}else r[i]=s}),r},{})}function fl(t,e){return e.filter(n=>n.type===t.type.name).filter(n=>n.attribute.rendered).map(n=>n.attribute.renderHTML?n.attribute.renderHTML(t.attrs)||{}:{[n.name]:t.attrs[n.name]}).reduce((n,r)=>Se(n,r),{})}function b0(t){return typeof t=="function"}function K(t,e=void 0,...n){return b0(t)?e?t.bind(e)(...n):t(...n):t}function WC(t={}){return Object.keys(t).length===0&&t.constructor===Object}function KC(t){return typeof t!="string"?t:t.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(t):t==="true"?!0:t==="false"?!1:t}function tp(t,e){return"style"in t?t:{...t,getAttrs:n=>{const r=t.getAttrs?t.getAttrs(n):t.attrs;if(r===!1)return!1;const i=e.reduce((s,o)=>{const l=o.attribute.parseHTML?o.attribute.parseHTML(n):KC(n.getAttribute(o.name));return l==null?s:{...s,[o.name]:l}},{});return{...r,...i}}}}function np(t){return Object.fromEntries(Object.entries(t).filter(([e,n])=>e==="attrs"&&WC(n)?!1:n!=null))}function M0(t,e){var n;const r=N0(t),{nodeExtensions:i,markExtensions:s}=Vl(t),o=(n=i.find(u=>L(u,"topNode")))===null||n===void 0?void 0:n.name,l=Object.fromEntries(i.map(u=>{const c=r.filter(g=>g.type===u.name),d={name:u.name,options:u.options,storage:u.storage,editor:e},f=t.reduce((g,v)=>{const S=L(v,"extendNodeSchema",d);return{...g,...S?S(u):{}}},{}),h=np({...f,content:K(L(u,"content",d)),marks:K(L(u,"marks",d)),group:K(L(u,"group",d)),inline:K(L(u,"inline",d)),atom:K(L(u,"atom",d)),selectable:K(L(u,"selectable",d)),draggable:K(L(u,"draggable",d)),code:K(L(u,"code",d)),whitespace:K(L(u,"whitespace",d)),linebreakReplacement:K(L(u,"linebreakReplacement",d)),defining:K(L(u,"defining",d)),isolating:K(L(u,"isolating",d)),attrs:Object.fromEntries(c.map(g=>{var v;return[g.name,{default:(v=g==null?void 0:g.attribute)===null||v===void 0?void 0:v.default}]}))}),p=K(L(u,"parseHTML",d));p&&(h.parseDOM=p.map(g=>tp(g,c)));const m=L(u,"renderHTML",d);m&&(h.toDOM=g=>m({node:g,HTMLAttributes:fl(g,c)}));const x=L(u,"renderText",d);return x&&(h.toText=x),[u.name,h]})),a=Object.fromEntries(s.map(u=>{const c=r.filter(x=>x.type===u.name),d={name:u.name,options:u.options,storage:u.storage,editor:e},f=t.reduce((x,g)=>{const v=L(g,"extendMarkSchema",d);return{...x,...v?v(u):{}}},{}),h=np({...f,inclusive:K(L(u,"inclusive",d)),excludes:K(L(u,"excludes",d)),group:K(L(u,"group",d)),spanning:K(L(u,"spanning",d)),code:K(L(u,"code",d)),attrs:Object.fromEntries(c.map(x=>{var g;return[x.name,{default:(g=x==null?void 0:x.attribute)===null||g===void 0?void 0:g.default}]}))}),p=K(L(u,"parseHTML",d));p&&(h.parseDOM=p.map(x=>tp(x,c)));const m=L(u,"renderHTML",d);return m&&(h.toDOM=x=>m({mark:x,HTMLAttributes:fl(x,c)})),[u.name,h]}));return new hy({topNode:o,nodes:l,marks:a})}function za(t,e){return e.nodes[t]||e.marks[t]||null}function rp(t,e){return Array.isArray(e)?e.some(n=>(typeof n=="string"?n:n.name)===t.name):e}function Ul(t,e){const n=Dr.fromSchema(e).serializeFragment(t),i=document.implementation.createHTMLDocument().createElement("div");return i.appendChild(n),i.innerHTML}const JC=(t,e=500)=>{let n="";const r=t.parentOffset;return t.parent.nodesBetween(Math.max(0,r-e),r,(i,s,o,l)=>{var a,u;const c=((u=(a=i.type.spec).toText)===null||u===void 0?void 0:u.call(a,{node:i,pos:s,parent:o,index:l}))||i.textContent||"%leaf%";n+=i.isAtom&&!i.isText?c:c.slice(0,Math.max(0,r-s))}),n};function Td(t){return Object.prototype.toString.call(t)==="[object RegExp]"}class Hl{constructor(e){this.find=e.find,this.handler=e.handler}}const qC=(t,e)=>{if(Td(e))return e.exec(t);const n=e(t);if(!n)return null;const r=[n.text];return r.index=n.index,r.input=t,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 uo(t){var e;const{editor:n,from:r,to:i,text:s,rules:o,plugin:l}=t,{view:a}=n;if(a.composing)return!1;const u=a.state.doc.resolve(r);if(u.parent.type.spec.code||!((e=u.nodeBefore||u.nodeAfter)===null||e===void 0)&&e.marks.find(f=>f.type.spec.code))return!1;let c=!1;const d=JC(u)+s;return o.forEach(f=>{if(c)return;const h=qC(d,f.find);if(!h)return;const p=a.state.tr,m=_l({state:a.state,transaction:p}),x={from:r-(h[0].length-s.length),to:i},{commands:g,chain:v,can:S}=new $l({editor:n,state:m});f.handler({state:m,range:x,match:h,commands:g,chain:v,can:S})===null||!p.steps.length||(p.setMeta(l,{transform:p,from:r,to:i,text:s}),a.dispatch(p),c=!0)}),c}function GC(t){const{editor:e,rules:n}=t,r=new Ke({state:{init(){return null},apply(i,s,o){const l=i.getMeta(r);if(l)return l;const a=i.getMeta("applyInputRules");return!!a&&setTimeout(()=>{let{text:c}=a;typeof c=="string"?c=c:c=Ul(O.from(c),o.schema);const{from:d}=a,f=d+c.length;uo({editor:e,from:d,to:f,text:c,rules:n,plugin:r})}),i.selectionSet||i.docChanged?null:s}},props:{handleTextInput(i,s,o,l){return uo({editor:e,from:s,to:o,text:l,rules:n,plugin:r})},handleDOMEvents:{compositionend:i=>(setTimeout(()=>{const{$cursor:s}=i.state.selection;s&&uo({editor:e,from:s.pos,to:s.pos,text:"",rules:n,plugin:r})}),!1)},handleKeyDown(i,s){if(s.key!=="Enter")return!1;const{$cursor:o}=i.state.selection;return o?uo({editor:e,from:o.pos,to:o.pos,text:` +`,rules:n,plugin:r}):!1}},isInputRules:!0});return r}function QC(t){return Object.prototype.toString.call(t).slice(8,-1)}function co(t){return QC(t)!=="Object"?!1:t.constructor===Object&&Object.getPrototypeOf(t)===Object.prototype}function Wl(t,e){const n={...t};return co(t)&&co(e)&&Object.keys(e).forEach(r=>{co(e[r])&&co(t[r])?n[r]=Wl(t[r],e[r]):n[r]=e[r]}),n}class bt{constructor(e={}){this.type="mark",this.name="mark",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=K(L(this,"addOptions",{name:this.name}))),this.storage=K(L(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new bt(e)}configure(e={}){const n=this.extend({...this.config,addOptions:()=>Wl(this.options,e)});return n.name=this.name,n.parent=this.parent,n}extend(e={}){const n=new bt(e);return n.parent=this,this.child=n,n.name=e.name?e.name:n.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=K(L(n,"addOptions",{name:n.name})),n.storage=K(L(n,"addStorage",{name:n.name,options:n.options})),n}static handleExit({editor:e,mark:n}){const{tr:r}=e.state,i=e.state.selection.$from;if(i.pos===i.end()){const o=i.marks();if(!!!o.find(u=>(u==null?void 0:u.type.name)===n.name))return!1;const a=o.find(u=>(u==null?void 0:u.type.name)===n.name);return a&&r.removeStoredMark(a),r.insertText(" ",i.pos),e.view.dispatch(r),!0}return!1}}function YC(t){return typeof t=="number"}class XC{constructor(e){this.find=e.find,this.handler=e.handler}}const ZC=(t,e,n)=>{if(Td(e))return[...t.matchAll(e)];const r=e(t,n);return r?r.map(i=>{const s=[i.text];return s.index=i.index,s.input=t,s.data=i.data,i.replaceWith&&(i.text.includes(i.replaceWith)||console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'),s.push(i.replaceWith)),s}):[]};function eE(t){const{editor:e,state:n,from:r,to:i,rule:s,pasteEvent:o,dropEvent:l}=t,{commands:a,chain:u,can:c}=new $l({editor:e,state:n}),d=[];return n.doc.nodesBetween(r,i,(h,p)=>{if(!h.isTextblock||h.type.spec.code)return;const m=Math.max(r,p),x=Math.min(i,p+h.content.size),g=h.textBetween(m-p,x-p,void 0,"");ZC(g,s.find,o).forEach(S=>{if(S.index===void 0)return;const w=m+S.index+1,E=w+S[0].length,b={from:n.tr.mapping.map(w),to:n.tr.mapping.map(E)},C=s.handler({state:n,range:b,match:S,commands:a,chain:u,can:c,pasteEvent:o,dropEvent:l});d.push(C)})}),d.every(h=>h!==null)}let fo=null;const tE=t=>{var e;const n=new ClipboardEvent("paste",{clipboardData:new DataTransfer});return(e=n.clipboardData)===null||e===void 0||e.setData("text/html",t),n};function nE(t){const{editor:e,rules:n}=t;let r=null,i=!1,s=!1,o=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,l;try{l=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{l=null}const a=({state:c,from:d,to:f,rule:h,pasteEvt:p})=>{const m=c.tr,x=_l({state:c,transaction:m});if(!(!eE({editor:e,state:x,from:Math.max(d-1,0),to:f.b-1,rule:h,pasteEvent:p,dropEvent:l})||!m.steps.length)){try{l=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{l=null}return o=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,m}};return n.map(c=>new Ke({view(d){const f=p=>{var m;r=!((m=d.dom.parentElement)===null||m===void 0)&&m.contains(p.target)?d.dom.parentElement:null,r&&(fo=e)},h=()=>{fo&&(fo=null)};return window.addEventListener("dragstart",f),window.addEventListener("dragend",h),{destroy(){window.removeEventListener("dragstart",f),window.removeEventListener("dragend",h)}}},props:{handleDOMEvents:{drop:(d,f)=>{if(s=r===d.dom.parentElement,l=f,!s){const h=fo;h!=null&&h.isEditable&&setTimeout(()=>{const p=h.state.selection;p&&h.commands.deleteRange({from:p.from,to:p.to})},10)}return!1},paste:(d,f)=>{var h;const p=(h=f.clipboardData)===null||h===void 0?void 0:h.getData("text/html");return o=f,i=!!(p!=null&&p.includes("data-pm-slice")),!1}}},appendTransaction:(d,f,h)=>{const p=d[0],m=p.getMeta("uiEvent")==="paste"&&!i,x=p.getMeta("uiEvent")==="drop"&&!s,g=p.getMeta("applyPasteRules"),v=!!g;if(!m&&!x&&!v)return;if(v){let{text:E}=g;typeof E=="string"?E=E:E=Ul(O.from(E),h.schema);const{from:b}=g,C=b+E.length,M=tE(E);return a({rule:c,state:h,from:b,to:{b:C},pasteEvt:M})}const S=f.doc.content.findDiffStart(h.doc.content),w=f.doc.content.findDiffEnd(h.doc.content);if(!(!YC(S)||!w||S===w.b))return a({rule:c,state:h,from:S,to:w,pasteEvt:o})}}))}function rE(t){const e=t.filter((n,r)=>t.indexOf(n)!==r);return Array.from(new Set(e))}class lr{constructor(e,n){this.splittableMarks=[],this.editor=n,this.extensions=lr.resolve(e),this.schema=M0(this.extensions,n),this.setupExtensions()}static resolve(e){const n=lr.sort(lr.flatten(e)),r=rE(n.map(i=>i.name));return r.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${r.map(i=>`'${i}'`).join(", ")}]. This can lead to issues.`),n}static flatten(e){return e.map(n=>{const r={name:n.name,options:n.options,storage:n.storage},i=L(n,"addExtensions",r);return i?[n,...this.flatten(i())]:n}).flat(10)}static sort(e){return e.sort((r,i)=>{const s=L(r,"priority")||100,o=L(i,"priority")||100;return s>o?-1:s{const r={name:n.name,options:n.options,storage:n.storage,editor:this.editor,type:za(n.name,this.schema)},i=L(n,"addCommands",r);return i?{...e,...i()}:e},{})}get plugins(){const{editor:e}=this,n=lr.sort([...this.extensions].reverse()),r=[],i=[],s=n.map(o=>{const l={name:o.name,options:o.options,storage:o.storage,editor:e,type:za(o.name,this.schema)},a=[],u=L(o,"addKeyboardShortcuts",l);let c={};if(o.type==="mark"&&L(o,"exitable",l)&&(c.ArrowRight=()=>bt.handleExit({editor:e,mark:o})),u){const m=Object.fromEntries(Object.entries(u()).map(([x,g])=>[x,()=>g({editor:e})]));c={...c,...m}}const d=CC(c);a.push(d);const f=L(o,"addInputRules",l);rp(o,e.options.enableInputRules)&&f&&r.push(...f());const h=L(o,"addPasteRules",l);rp(o,e.options.enablePasteRules)&&h&&i.push(...h());const p=L(o,"addProseMirrorPlugins",l);if(p){const m=p();a.push(...m)}return a}).flat();return[GC({editor:e,rules:r}),...nE({editor:e,rules:i}),...s]}get attributes(){return N0(this.extensions)}get nodeViews(){const{editor:e}=this,{nodeExtensions:n}=Vl(this.extensions);return Object.fromEntries(n.filter(r=>!!L(r,"addNodeView")).map(r=>{const i=this.attributes.filter(a=>a.type===r.name),s={name:r.name,options:r.options,storage:r.storage,editor:e,type:De(r.name,this.schema)},o=L(r,"addNodeView",s);if(!o)return[];const l=(a,u,c,d,f)=>{const h=fl(a,i);return o()({node:a,view:u,getPos:c,decorations:d,innerDecorations:f,editor:e,extension:r,HTMLAttributes:h})};return[r.name,l]}))}setupExtensions(){this.extensions.forEach(e=>{var n;this.editor.extensionStorage[e.name]=e.storage;const r={name:e.name,options:e.options,storage:e.storage,editor:this.editor,type:za(e.name,this.schema)};e.type==="mark"&&(!((n=K(L(e,"keepOnSplit",r)))!==null&&n!==void 0)||n)&&this.splittableMarks.push(e.name);const i=L(e,"onBeforeCreate",r),s=L(e,"onCreate",r),o=L(e,"onUpdate",r),l=L(e,"onSelectionUpdate",r),a=L(e,"onTransaction",r),u=L(e,"onFocus",r),c=L(e,"onBlur",r),d=L(e,"onDestroy",r);i&&this.editor.on("beforeCreate",i),s&&this.editor.on("create",s),o&&this.editor.on("update",o),l&&this.editor.on("selectionUpdate",l),a&&this.editor.on("transaction",a),u&&this.editor.on("focus",u),c&&this.editor.on("blur",c),d&&this.editor.on("destroy",d)})}}class Pe{constructor(e={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=K(L(this,"addOptions",{name:this.name}))),this.storage=K(L(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new Pe(e)}configure(e={}){const n=this.extend({...this.config,addOptions:()=>Wl(this.options,e)});return n.name=this.name,n.parent=this.parent,n}extend(e={}){const n=new Pe({...this.config,...e});return n.parent=this,this.child=n,n.name=e.name?e.name:n.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=K(L(n,"addOptions",{name:n.name})),n.storage=K(L(n,"addStorage",{name:n.name,options:n.options})),n}}function T0(t,e,n){const{from:r,to:i}=e,{blockSeparator:s=` + +`,textSerializers:o={}}=n||{};let l="";return t.nodesBetween(r,i,(a,u,c,d)=>{var f;a.isBlock&&u>r&&(l+=s);const h=o==null?void 0:o[a.type.name];if(h)return c&&(l+=h({node:a,pos:u,parent:c,index:d,range:e})),!1;a.isText&&(l+=(f=a==null?void 0:a.text)===null||f===void 0?void 0:f.slice(Math.max(r,u)-u,i-u))}),l}function O0(t){return Object.fromEntries(Object.entries(t.nodes).filter(([,e])=>e.spec.toText).map(([e,n])=>[e,n.spec.toText]))}const iE=Pe.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new Ke({key:new Mt("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:t}=this,{state:e,schema:n}=t,{doc:r,selection:i}=e,{ranges:s}=i,o=Math.min(...s.map(c=>c.$from.pos)),l=Math.max(...s.map(c=>c.$to.pos)),a=O0(n);return T0(r,{from:o,to:l},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:a})}}})]}}),sE=()=>({editor:t,view:e})=>(requestAnimationFrame(()=>{var n;t.isDestroyed||(e.dom.blur(),(n=window==null?void 0:window.getSelection())===null||n===void 0||n.removeAllRanges())}),!0),oE=(t=!1)=>({commands:e})=>e.setContent("",t),lE=()=>({state:t,tr:e,dispatch:n})=>{const{selection:r}=e,{ranges:i}=r;return n&&i.forEach(({$from:s,$to:o})=>{t.doc.nodesBetween(s.pos,o.pos,(l,a)=>{if(l.type.isText)return;const{doc:u,mapping:c}=e,d=u.resolve(c.map(a)),f=u.resolve(c.map(a+l.nodeSize)),h=d.blockRange(f);if(!h)return;const p=Si(h);if(l.type.isTextblock){const{defaultType:m}=d.parent.contentMatchAt(d.index());e.setNodeMarkup(h.start,m)}(p||p===0)&&e.lift(h,p)})}),!0},aE=t=>e=>t(e),uE=()=>({state:t,dispatch:e})=>k0(t,e),cE=(t,e)=>({editor:n,tr:r})=>{const{state:i}=n,s=i.doc.slice(t.from,t.to);r.deleteRange(t.from,t.to);const o=r.mapping.map(e);return r.insert(o,s.content),r.setSelection(new H(r.doc.resolve(Math.max(o-1,0)))),!0},dE=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,r=n.$anchor.node();if(r.content.size>0)return!1;const i=t.selection.$anchor;for(let s=i.depth;s>0;s-=1)if(i.node(s).type===r.type){if(e){const l=i.before(s),a=i.after(s);t.delete(l,a).scrollIntoView()}return!0}return!1},fE=t=>({tr:e,state:n,dispatch:r})=>{const i=De(t,n.schema),s=e.selection.$anchor;for(let o=s.depth;o>0;o-=1)if(s.node(o).type===i){if(r){const a=s.before(o),u=s.after(o);e.delete(a,u).scrollIntoView()}return!0}return!1},hE=t=>({tr:e,dispatch:n})=>{const{from:r,to:i}=t;return n&&e.delete(r,i),!0},pE=()=>({state:t,dispatch:e})=>Cd(t,e),mE=()=>({commands:t})=>t.keyboardShortcut("Enter"),gE=()=>({state:t,dispatch:e})=>OC(t,e);function hl(t,e,n={strict:!0}){const r=Object.keys(e);return r.length?r.every(i=>n.strict?e[i]===t[i]:Td(e[i])?e[i].test(t[i]):e[i]===t[i]):!0}function D0(t,e,n={}){return t.find(r=>r.type===e&&hl(Object.fromEntries(Object.keys(n).map(i=>[i,r.attrs[i]])),n))}function ip(t,e,n={}){return!!D0(t,e,n)}function Kl(t,e,n){var r;if(!t||!e)return;let i=t.parent.childAfter(t.parentOffset);if((!i.node||!i.node.marks.some(c=>c.type===e))&&(i=t.parent.childBefore(t.parentOffset)),!i.node||!i.node.marks.some(c=>c.type===e)||(n=n||((r=i.node.marks[0])===null||r===void 0?void 0:r.attrs),!D0([...i.node.marks],e,n)))return;let o=i.index,l=t.start()+i.offset,a=o+1,u=l+i.node.nodeSize;for(;o>0&&ip([...t.parent.child(o-1).marks],e,n);)o-=1,l-=t.parent.child(o).nodeSize;for(;a({tr:n,state:r,dispatch:i})=>{const s=Qn(t,r.schema),{doc:o,selection:l}=n,{$from:a,from:u,to:c}=l;if(i){const d=Kl(a,s,e);if(d&&d.from<=u&&d.to>=c){const f=H.create(o,d.from,d.to);n.setSelection(f)}}return!0},vE=t=>e=>{const n=typeof t=="function"?t(e):t;for(let r=0;r({editor:n,view:r,tr:i,dispatch:s})=>{e={scrollIntoView:!0,...e};const o=()=>{(bs()||tc())&&r.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),xE()&&!bs()&&!tc()&&r.dom.focus({preventScroll:!0}))})};if(r.hasFocus()&&t===null||t===!1)return!0;if(s&&t===null&&!P0(n.state.selection))return o(),!0;const l=A0(i.doc,t)||n.state.selection,a=n.state.selection.eq(l);return s&&(a||i.setSelection(l),a&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},kE=(t,e)=>n=>t.every((r,i)=>e(r,{...n,index:i})),wE=(t,e)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},t,e),I0=t=>{const e=t.childNodes;for(let n=e.length-1;n>=0;n-=1){const r=e[n];r.nodeType===3&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?t.removeChild(r):r.nodeType===1&&I0(r)}return t};function ho(t){const e=`${t}`,n=new window.DOMParser().parseFromString(e,"text/html").body;return I0(n)}function Ms(t,e,n){if(t instanceof rn||t instanceof O)return t;n={slice:!0,parseOptions:{},...n};const r=typeof t=="object"&&t!==null,i=typeof t=="string";if(r)try{if(Array.isArray(t)&&t.length>0)return O.fromArray(t.map(l=>e.nodeFromJSON(l)));const o=e.nodeFromJSON(t);return n.errorOnInvalidContent&&o.check(),o}catch(s){if(n.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:s});return console.warn("[tiptap warn]: Invalid content.","Passed value:",t,"Error:",s),Ms("",e,n)}if(i){if(n.errorOnInvalidContent){let o=!1,l="";const a=new hy({topNode:e.spec.topNode,marks:e.spec.marks,nodes:e.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:u=>(o=!0,l=typeof u=="string"?u:u.outerHTML,null)}]}})});if(n.slice?zn.fromSchema(a).parseSlice(ho(t),n.parseOptions):zn.fromSchema(a).parse(ho(t),n.parseOptions),n.errorOnInvalidContent&&o)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${l}`)})}const s=zn.fromSchema(e);return n.slice?s.parseSlice(ho(t),n.parseOptions).content:s.parse(ho(t),n.parseOptions)}return Ms("",e,n)}function CE(t,e,n){const r=t.steps.length-1;if(r{o===0&&(o=c)}),t.setSelection(W.near(t.doc.resolve(o),n))}const EE=t=>!("type"in t),NE=(t,e,n)=>({tr:r,dispatch:i,editor:s})=>{var o;if(i){n={parseOptions:s.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let l;const a=x=>{s.emit("contentError",{editor:s,error:x,disableCollaboration:()=>{s.storage.collaboration&&(s.storage.collaboration.isDisabled=!0)}})},u={preserveWhitespace:"full",...n.parseOptions};if(!n.errorOnInvalidContent&&!s.options.enableContentCheck&&s.options.emitContentError)try{Ms(e,s.schema,{parseOptions:u,errorOnInvalidContent:!0})}catch(x){a(x)}try{l=Ms(e,s.schema,{parseOptions:u,errorOnInvalidContent:(o=n.errorOnInvalidContent)!==null&&o!==void 0?o:s.options.enableContentCheck})}catch(x){return a(x),!1}let{from:c,to:d}=typeof t=="number"?{from:t,to:t}:{from:t.from,to:t.to},f=!0,h=!0;if((EE(l)?l:[l]).forEach(x=>{x.check(),f=f?x.isText&&x.marks.length===0:!1,h=h?x.isBlock:!1}),c===d&&h){const{parent:x}=r.doc.resolve(c);x.isTextblock&&!x.type.spec.code&&!x.childCount&&(c-=1,d+=1)}let m;if(f){if(Array.isArray(e))m=e.map(x=>x.text||"").join("");else if(e instanceof O){let x="";e.forEach(g=>{g.text&&(x+=g.text)}),m=x}else typeof e=="object"&&e&&e.text?m=e.text:m=e;r.insertText(m,c,d)}else m=l,r.replaceWith(c,d,m);n.updateSelection&&CE(r,r.steps.length-1,-1),n.applyInputRules&&r.setMeta("applyInputRules",{from:c,text:m}),n.applyPasteRules&&r.setMeta("applyPasteRules",{from:c,text:m})}return!0},bE=()=>({state:t,dispatch:e})=>bC(t,e),ME=()=>({state:t,dispatch:e})=>MC(t,e),TE=()=>({state:t,dispatch:e})=>p0(t,e),OE=()=>({state:t,dispatch:e})=>v0(t,e),DE=()=>({state:t,dispatch:e,tr:n})=>{try{const r=Rl(t.doc,t.selection.$from.pos,-1);return r==null?!1:(n.join(r,2),e&&e(n),!0)}catch{return!1}},PE=()=>({state:t,dispatch:e,tr:n})=>{try{const r=Rl(t.doc,t.selection.$from.pos,1);return r==null?!1:(n.join(r,2),e&&e(n),!0)}catch{return!1}},AE=()=>({state:t,dispatch:e})=>EC(t,e),IE=()=>({state:t,dispatch:e})=>NC(t,e);function R0(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function RE(t){const e=t.split(/-(?!$)/);let n=e[e.length-1];n==="Space"&&(n=" ");let r,i,s,o;for(let l=0;l({editor:e,view:n,tr:r,dispatch:i})=>{const s=RE(t).split(/-(?!$)/),o=s.find(u=>!["Alt","Ctrl","Meta","Shift"].includes(u)),l=new KeyboardEvent("keydown",{key:o==="Space"?" ":o,altKey:s.includes("Alt"),ctrlKey:s.includes("Ctrl"),metaKey:s.includes("Meta"),shiftKey:s.includes("Shift"),bubbles:!0,cancelable:!0}),a=e.captureTransaction(()=>{n.someProp("handleKeyDown",u=>u(n,l))});return a==null||a.steps.forEach(u=>{const c=u.map(r.mapping);c&&i&&r.maybeStep(c)}),!0};function Ts(t,e,n={}){const{from:r,to:i,empty:s}=t.selection,o=e?De(e,t.schema):null,l=[];t.doc.nodesBetween(r,i,(d,f)=>{if(d.isText)return;const h=Math.max(r,f),p=Math.min(i,f+d.nodeSize);l.push({node:d,from:h,to:p})});const a=i-r,u=l.filter(d=>o?o.name===d.node.type.name:!0).filter(d=>hl(d.node.attrs,n,{strict:!1}));return s?!!u.length:u.reduce((d,f)=>d+f.to-f.from,0)>=a}const jE=(t,e={})=>({state:n,dispatch:r})=>{const i=De(t,n.schema);return Ts(n,i,e)?TC(n,r):!1},zE=()=>({state:t,dispatch:e})=>w0(t,e),BE=t=>({state:e,dispatch:n})=>{const r=De(t,e.schema);return _C(r)(e,n)},FE=()=>({state:t,dispatch:e})=>S0(t,e);function Jl(t,e){return e.nodes[t]?"node":e.marks[t]?"mark":null}function sp(t,e){const n=typeof e=="string"?[e]:e;return Object.keys(t).reduce((r,i)=>(n.includes(i)||(r[i]=t[i]),r),{})}const _E=(t,e)=>({tr:n,state:r,dispatch:i})=>{let s=null,o=null;const l=Jl(typeof t=="string"?t:t.name,r.schema);return l?(l==="node"&&(s=De(t,r.schema)),l==="mark"&&(o=Qn(t,r.schema)),i&&n.selection.ranges.forEach(a=>{r.doc.nodesBetween(a.$from.pos,a.$to.pos,(u,c)=>{s&&s===u.type&&n.setNodeMarkup(c,void 0,sp(u.attrs,e)),o&&u.marks.length&&u.marks.forEach(d=>{o===d.type&&n.addMark(c,c+u.nodeSize,o.create(sp(d.attrs,e)))})})}),!0):!1},$E=()=>({tr:t,dispatch:e})=>(e&&t.scrollIntoView(),!0),VE=()=>({tr:t,dispatch:e})=>{if(e){const n=new ft(t.doc);t.setSelection(n)}return!0},UE=()=>({state:t,dispatch:e})=>g0(t,e),HE=()=>({state:t,dispatch:e})=>x0(t,e),WE=()=>({state:t,dispatch:e})=>AC(t,e),KE=()=>({state:t,dispatch:e})=>LC(t,e),JE=()=>({state:t,dispatch:e})=>RC(t,e);function nc(t,e,n={},r={}){return Ms(t,e,{slice:!1,parseOptions:n,errorOnInvalidContent:r.errorOnInvalidContent})}const qE=(t,e=!1,n={},r={})=>({editor:i,tr:s,dispatch:o,commands:l})=>{var a,u;const{doc:c}=s;if(n.preserveWhitespace!=="full"){const d=nc(t,i.schema,n,{errorOnInvalidContent:(a=r.errorOnInvalidContent)!==null&&a!==void 0?a:i.options.enableContentCheck});return o&&s.replaceWith(0,c.content.size,d).setMeta("preventUpdate",!e),!0}return o&&s.setMeta("preventUpdate",!e),l.insertContentAt({from:0,to:c.content.size},t,{parseOptions:n,errorOnInvalidContent:(u=r.errorOnInvalidContent)!==null&&u!==void 0?u:i.options.enableContentCheck})};function L0(t,e){const n=Qn(e,t.schema),{from:r,to:i,empty:s}=t.selection,o=[];s?(t.storedMarks&&o.push(...t.storedMarks),o.push(...t.selection.$head.marks())):t.doc.nodesBetween(r,i,a=>{o.push(...a.marks)});const l=o.find(a=>a.type.name===n.name);return l?{...l.attrs}:{}}function GE(t){for(let e=0;e0;n-=1){const r=t.node(n);if(e(r))return{pos:n>0?t.before(n):0,start:t.start(n),depth:n,node:r}}}function Od(t){return e=>QE(e.$from,t)}function YE(t,e){const n=lr.resolve(t);return M0(n,e)}function XE(t,e){const n=YE(e),r=rn.fromJSON(n,t);return Ul(r.content,n)}function ZE(t,e){const n={from:0,to:t.content.size};return T0(t,n,e)}function eN(t,e){const n=De(e,t.schema),{from:r,to:i}=t.selection,s=[];t.doc.nodesBetween(r,i,l=>{s.push(l)});const o=s.reverse().find(l=>l.type.name===n.name);return o?{...o.attrs}:{}}function tN(t,e){const n=Jl(typeof e=="string"?e:e.name,t.schema);return n==="node"?eN(t,e):n==="mark"?L0(t,e):{}}function j0(t,e,n){const r=[];return t===e?n.resolve(t).marks().forEach(i=>{const s=n.resolve(t),o=Kl(s,i.type);o&&r.push({mark:i,...o})}):n.nodesBetween(t,e,(i,s)=>{!i||(i==null?void 0:i.nodeSize)===void 0||r.push(...i.marks.map(o=>({from:s,to:s+i.nodeSize,mark:o})))}),r}function Oo(t,e,n){return Object.fromEntries(Object.entries(n).filter(([r])=>{const i=t.find(s=>s.type===e&&s.name===r);return i?i.attribute.keepOnSplit:!1}))}function rc(t,e,n={}){const{empty:r,ranges:i}=t.selection,s=e?Qn(e,t.schema):null;if(r)return!!(t.storedMarks||t.selection.$from.marks()).filter(d=>s?s.name===d.type.name:!0).find(d=>hl(d.attrs,n,{strict:!1}));let o=0;const l=[];if(i.forEach(({$from:d,$to:f})=>{const h=d.pos,p=f.pos;t.doc.nodesBetween(h,p,(m,x)=>{if(!m.isText&&!m.marks.length)return;const g=Math.max(h,x),v=Math.min(p,x+m.nodeSize),S=v-g;o+=S,l.push(...m.marks.map(w=>({mark:w,from:g,to:v})))})}),o===0)return!1;const a=l.filter(d=>s?s.name===d.mark.type.name:!0).filter(d=>hl(d.mark.attrs,n,{strict:!1})).reduce((d,f)=>d+f.to-f.from,0),u=l.filter(d=>s?d.mark.type!==s&&d.mark.type.excludes(s):!0).reduce((d,f)=>d+f.to-f.from,0);return(a>0?a+u:a)>=o}function nN(t,e,n={}){if(!e)return Ts(t,null,n)||rc(t,null,n);const r=Jl(e,t.schema);return r==="node"?Ts(t,e,n):r==="mark"?rc(t,e,n):!1}function op(t,e){const{nodeExtensions:n}=Vl(e),r=n.find(o=>o.name===t);if(!r)return!1;const i={name:r.name,options:r.options,storage:r.storage},s=K(L(r,"group",i));return typeof s!="string"?!1:s.split(" ").includes("list")}function ql(t,{checkChildren:e=!0,ignoreWhitespace:n=!1}={}){var r;if(n){if(t.type.name==="hardBreak")return!0;if(t.isText)return/^\s*$/m.test((r=t.text)!==null&&r!==void 0?r:"")}if(t.isText)return!t.text;if(t.isAtom||t.isLeaf)return!1;if(t.content.childCount===0)return!0;if(e){let i=!0;return t.content.forEach(s=>{i!==!1&&(ql(s,{ignoreWhitespace:n,checkChildren:e})||(i=!1))}),i}return!1}function rN(t){return t instanceof F}function iN(t,e,n){var r;const{selection:i}=e;let s=null;if(P0(i)&&(s=i.$cursor),s){const l=(r=t.storedMarks)!==null&&r!==void 0?r:s.marks();return!!n.isInSet(l)||!l.some(a=>a.type.excludes(n))}const{ranges:o}=i;return o.some(({$from:l,$to:a})=>{let u=l.depth===0?t.doc.inlineContent&&t.doc.type.allowsMarkType(n):!1;return t.doc.nodesBetween(l.pos,a.pos,(c,d,f)=>{if(u)return!1;if(c.isInline){const h=!f||f.type.allowsMarkType(n),p=!!n.isInSet(c.marks)||!c.marks.some(m=>m.type.excludes(n));u=h&&p}return!u}),u})}const sN=(t,e={})=>({tr:n,state:r,dispatch:i})=>{const{selection:s}=n,{empty:o,ranges:l}=s,a=Qn(t,r.schema);if(i)if(o){const u=L0(r,a);n.addStoredMark(a.create({...u,...e}))}else l.forEach(u=>{const c=u.$from.pos,d=u.$to.pos;r.doc.nodesBetween(c,d,(f,h)=>{const p=Math.max(h,c),m=Math.min(h+f.nodeSize,d);f.marks.find(g=>g.type===a)?f.marks.forEach(g=>{a===g.type&&n.addMark(p,m,a.create({...g.attrs,...e}))}):n.addMark(p,m,a.create(e))})});return iN(r,n,a)},oN=(t,e)=>({tr:n})=>(n.setMeta(t,e),!0),lN=(t,e={})=>({state:n,dispatch:r,chain:i})=>{const s=De(t,n.schema);let o;return n.selection.$anchor.sameParent(n.selection.$head)&&(o=n.selection.$anchor.parent.attrs),s.isTextblock?i().command(({commands:l})=>ep(s,{...o,...e})(n)?!0:l.clearNodes()).command(({state:l})=>ep(s,{...o,...e})(l,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},aN=t=>({tr:e,dispatch:n})=>{if(n){const{doc:r}=e,i=ar(t,0,r.content.size),s=F.create(r,i);e.setSelection(s)}return!0},uN=t=>({tr:e,dispatch:n})=>{if(n){const{doc:r}=e,{from:i,to:s}=typeof t=="number"?{from:t,to:t}:t,o=H.atStart(r).from,l=H.atEnd(r).to,a=ar(i,o,l),u=ar(s,o,l),c=H.create(r,a,u);e.setSelection(c)}return!0},cN=t=>({state:e,dispatch:n})=>{const r=De(t,e.schema);return UC(r)(e,n)};function lp(t,e){const n=t.storedMarks||t.selection.$to.parentOffset&&t.selection.$from.marks();if(n){const r=n.filter(i=>e==null?void 0:e.includes(i.type.name));t.tr.ensureMarks(r)}}const dN=({keepMarks:t=!0}={})=>({tr:e,state:n,dispatch:r,editor:i})=>{const{selection:s,doc:o}=e,{$from:l,$to:a}=s,u=i.extensionManager.attributes,c=Oo(u,l.node().type.name,l.node().attrs);if(s instanceof F&&s.node.isBlock)return!l.parentOffset||!sn(o,l.pos)?!1:(r&&(t&&lp(n,i.extensionManager.splittableMarks),e.split(l.pos).scrollIntoView()),!0);if(!l.parent.isBlock)return!1;const d=a.parentOffset===a.parent.content.size,f=l.depth===0?void 0:GE(l.node(-1).contentMatchAt(l.indexAfter(-1)));let h=d&&f?[{type:f,attrs:c}]:void 0,p=sn(e.doc,e.mapping.map(l.pos),1,h);if(!h&&!p&&sn(e.doc,e.mapping.map(l.pos),1,f?[{type:f}]:void 0)&&(p=!0,h=f?[{type:f,attrs:c}]:void 0),r){if(p&&(s instanceof H&&e.deleteSelection(),e.split(e.mapping.map(l.pos),1,h),f&&!d&&!l.parentOffset&&l.parent.type!==f)){const m=e.mapping.map(l.before()),x=e.doc.resolve(m);l.node(-1).canReplaceWith(x.index(),x.index()+1,f)&&e.setNodeMarkup(e.mapping.map(l.before()),f)}t&&lp(n,i.extensionManager.splittableMarks),e.scrollIntoView()}return p},fN=(t,e={})=>({tr:n,state:r,dispatch:i,editor:s})=>{var o;const l=De(t,r.schema),{$from:a,$to:u}=r.selection,c=r.selection.node;if(c&&c.isBlock||a.depth<2||!a.sameParent(u))return!1;const d=a.node(-1);if(d.type!==l)return!1;const f=s.extensionManager.attributes;if(a.parent.content.size===0&&a.node(-1).childCount===a.indexAfter(-1)){if(a.depth===2||a.node(-3).type!==l||a.index(-2)!==a.node(-2).childCount-1)return!1;if(i){let g=O.empty;const v=a.index(-1)?1:a.index(-2)?2:3;for(let M=a.depth-v;M>=a.depth-3;M-=1)g=O.from(a.node(M).copy(g));const S=a.indexAfter(-1){if(C>-1)return!1;M.isTextblock&&M.content.size===0&&(C=_+1)}),C>-1&&n.setSelection(H.near(n.doc.resolve(C))),n.scrollIntoView()}return!0}const h=u.pos===a.end()?d.contentMatchAt(0).defaultType:null,p={...Oo(f,d.type.name,d.attrs),...e},m={...Oo(f,a.node().type.name,a.node().attrs),...e};n.delete(a.pos,u.pos);const x=h?[{type:l,attrs:p},{type:h,attrs:m}]:[{type:l,attrs:p}];if(!sn(n.doc,a.pos,2))return!1;if(i){const{selection:g,storedMarks:v}=r,{splittableMarks:S}=s.extensionManager,w=v||g.$to.parentOffset&&g.$from.marks();if(n.split(a.pos,2,x).scrollIntoView(),!w||!i)return!0;const E=w.filter(b=>S.includes(b.type.name));n.ensureMarks(E)}return!0},Ba=(t,e)=>{const n=Od(o=>o.type===e)(t.selection);if(!n)return!0;const r=t.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;const i=t.doc.nodeAt(r);return n.node.type===(i==null?void 0:i.type)&&qn(t.doc,n.pos)&&t.join(n.pos),!0},Fa=(t,e)=>{const n=Od(o=>o.type===e)(t.selection);if(!n)return!0;const r=t.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;const i=t.doc.nodeAt(r);return n.node.type===(i==null?void 0:i.type)&&qn(t.doc,r)&&t.join(r),!0},hN=(t,e,n,r={})=>({editor:i,tr:s,state:o,dispatch:l,chain:a,commands:u,can:c})=>{const{extensions:d,splittableMarks:f}=i.extensionManager,h=De(t,o.schema),p=De(e,o.schema),{selection:m,storedMarks:x}=o,{$from:g,$to:v}=m,S=g.blockRange(v),w=x||m.$to.parentOffset&&m.$from.marks();if(!S)return!1;const E=Od(b=>op(b.type.name,d))(m);if(S.depth>=1&&E&&S.depth-E.depth<=1){if(E.node.type===h)return u.liftListItem(p);if(op(E.node.type.name,d)&&h.validContent(E.node.content)&&l)return a().command(()=>(s.setNodeMarkup(E.pos,h),!0)).command(()=>Ba(s,h)).command(()=>Fa(s,h)).run()}return!n||!w||!l?a().command(()=>c().wrapInList(h,r)?!0:u.clearNodes()).wrapInList(h,r).command(()=>Ba(s,h)).command(()=>Fa(s,h)).run():a().command(()=>{const b=c().wrapInList(h,r),C=w.filter(M=>f.includes(M.type.name));return s.ensureMarks(C),b?!0:u.clearNodes()}).wrapInList(h,r).command(()=>Ba(s,h)).command(()=>Fa(s,h)).run()},pN=(t,e={},n={})=>({state:r,commands:i})=>{const{extendEmptyMarkRange:s=!1}=n,o=Qn(t,r.schema);return rc(r,o,e)?i.unsetMark(o,{extendEmptyMarkRange:s}):i.setMark(o,e)},mN=(t,e,n={})=>({state:r,commands:i})=>{const s=De(t,r.schema),o=De(e,r.schema),l=Ts(r,s,n);let a;return r.selection.$anchor.sameParent(r.selection.$head)&&(a=r.selection.$anchor.parent.attrs),l?i.setNode(o,a):i.setNode(s,{...a,...n})},gN=(t,e={})=>({state:n,commands:r})=>{const i=De(t,n.schema);return Ts(n,i,e)?r.lift(i):r.wrapIn(i,e)},yN=()=>({state:t,dispatch:e})=>{const n=t.plugins;for(let r=0;r=0;a-=1)o.step(l.steps[a].invert(l.docs[a]));if(s.text){const a=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,t.schema.text(s.text,a))}else o.delete(s.from,s.to)}return!0}}return!1},vN=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,{empty:r,ranges:i}=n;return r||e&&i.forEach(s=>{t.removeMark(s.$from.pos,s.$to.pos)}),!0},xN=(t,e={})=>({tr:n,state:r,dispatch:i})=>{var s;const{extendEmptyMarkRange:o=!1}=e,{selection:l}=n,a=Qn(t,r.schema),{$from:u,empty:c,ranges:d}=l;if(!i)return!0;if(c&&o){let{from:f,to:h}=l;const p=(s=u.marks().find(x=>x.type===a))===null||s===void 0?void 0:s.attrs,m=Kl(u,a,p);m&&(f=m.from,h=m.to),n.removeMark(f,h,a)}else d.forEach(f=>{n.removeMark(f.$from.pos,f.$to.pos,a)});return n.removeStoredMark(a),!0},SN=(t,e={})=>({tr:n,state:r,dispatch:i})=>{let s=null,o=null;const l=Jl(typeof t=="string"?t:t.name,r.schema);return l?(l==="node"&&(s=De(t,r.schema)),l==="mark"&&(o=Qn(t,r.schema)),i&&n.selection.ranges.forEach(a=>{const u=a.$from.pos,c=a.$to.pos;let d,f,h,p;n.selection.empty?r.doc.nodesBetween(u,c,(m,x)=>{s&&s===m.type&&(h=Math.max(x,u),p=Math.min(x+m.nodeSize,c),d=x,f=m)}):r.doc.nodesBetween(u,c,(m,x)=>{x=u&&x<=c&&(s&&s===m.type&&n.setNodeMarkup(x,void 0,{...m.attrs,...e}),o&&m.marks.length&&m.marks.forEach(g=>{if(o===g.type){const v=Math.max(x,u),S=Math.min(x+m.nodeSize,c);n.addMark(v,S,o.create({...g.attrs,...e}))}}))}),f&&(d!==void 0&&n.setNodeMarkup(d,void 0,{...f.attrs,...e}),o&&f.marks.length&&f.marks.forEach(m=>{o===m.type&&n.addMark(h,p,o.create({...m.attrs,...e}))}))}),!0):!1},kN=(t,e={})=>({state:n,dispatch:r})=>{const i=De(t,n.schema);return jC(i,e)(n,r)},wN=(t,e={})=>({state:n,dispatch:r})=>{const i=De(t,n.schema);return zC(i,e)(n,r)};var CN=Object.freeze({__proto__:null,blur:sE,clearContent:oE,clearNodes:lE,command:aE,createParagraphNear:uE,cut:cE,deleteCurrentNode:dE,deleteNode:fE,deleteRange:hE,deleteSelection:pE,enter:mE,exitCode:gE,extendMarkRange:yE,first:vE,focus:SE,forEach:kE,insertContent:wE,insertContentAt:NE,joinBackward:TE,joinDown:ME,joinForward:OE,joinItemBackward:DE,joinItemForward:PE,joinTextblockBackward:AE,joinTextblockForward:IE,joinUp:bE,keyboardShortcut:LE,lift:jE,liftEmptyBlock:zE,liftListItem:BE,newlineInCode:FE,resetAttributes:_E,scrollIntoView:$E,selectAll:VE,selectNodeBackward:UE,selectNodeForward:HE,selectParentNode:WE,selectTextblockEnd:KE,selectTextblockStart:JE,setContent:qE,setMark:sN,setMeta:oN,setNode:lN,setNodeSelection:aN,setTextSelection:uN,sinkListItem:cN,splitBlock:dN,splitListItem:fN,toggleList:hN,toggleMark:pN,toggleNode:mN,toggleWrap:gN,undoInputRule:yN,unsetAllMarks:vN,unsetMark:xN,updateAttributes:SN,wrapIn:kN,wrapInList:wN});const EN=Pe.create({name:"commands",addCommands(){return{...CN}}}),NN=Pe.create({name:"drop",addProseMirrorPlugins(){return[new Ke({key:new Mt("tiptapDrop"),props:{handleDrop:(t,e,n,r)=>{this.editor.emit("drop",{editor:this.editor,event:e,slice:n,moved:r})}}})]}}),bN=Pe.create({name:"editable",addProseMirrorPlugins(){return[new Ke({key:new Mt("editable"),props:{editable:()=>this.editor.options.editable}})]}}),MN=new Mt("focusEvents"),TN=Pe.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:t}=this;return[new Ke({key:MN,props:{handleDOMEvents:{focus:(e,n)=>{t.isFocused=!0;const r=t.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return e.dispatch(r),!1},blur:(e,n)=>{t.isFocused=!1;const r=t.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return e.dispatch(r),!1}}}})]}}),ON=Pe.create({name:"keymap",addKeyboardShortcuts(){const t=()=>this.editor.commands.first(({commands:o})=>[()=>o.undoInputRule(),()=>o.command(({tr:l})=>{const{selection:a,doc:u}=l,{empty:c,$anchor:d}=a,{pos:f,parent:h}=d,p=d.parent.isTextblock&&f>0?l.doc.resolve(f-1):d,m=p.parent.type.spec.isolating,x=d.pos-d.parentOffset,g=m&&p.parent.childCount===1?x===d.pos:W.atStart(u).from===f;return!c||!h.type.isTextblock||h.textContent.length||!g||g&&d.parent.type.name==="paragraph"?!1:o.clearNodes()}),()=>o.deleteSelection(),()=>o.joinBackward(),()=>o.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.deleteCurrentNode(),()=>o.joinForward(),()=>o.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:o})=>[()=>o.newlineInCode(),()=>o.createParagraphNear(),()=>o.liftEmptyBlock(),()=>o.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:t,"Mod-Backspace":t,"Shift-Backspace":t,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},i={...r},s={...r,"Ctrl-h":t,"Alt-Backspace":t,"Ctrl-d":e,"Ctrl-Alt-Backspace":e,"Alt-Delete":e,"Alt-d":e,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return bs()||R0()?s:i},addProseMirrorPlugins(){return[new Ke({key:new Mt("clearDocument"),appendTransaction:(t,e,n)=>{if(t.some(m=>m.getMeta("composition")))return;const r=t.some(m=>m.docChanged)&&!e.doc.eq(n.doc),i=t.some(m=>m.getMeta("preventClearDocument"));if(!r||i)return;const{empty:s,from:o,to:l}=e.selection,a=W.atStart(e.doc).from,u=W.atEnd(e.doc).to;if(s||!(o===a&&l===u)||!ql(n.doc))return;const f=n.tr,h=_l({state:n,transaction:f}),{commands:p}=new $l({editor:this.editor,state:h});if(p.clearNodes(),!!f.steps.length)return f}})]}}),DN=Pe.create({name:"paste",addProseMirrorPlugins(){return[new Ke({key:new Mt("tiptapPaste"),props:{handlePaste:(t,e,n)=>{this.editor.emit("paste",{editor:this.editor,event:e,slice:n})}}})]}}),PN=Pe.create({name:"tabindex",addProseMirrorPlugins(){return[new Ke({key:new Mt("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}});class tr{get name(){return this.node.type.name}constructor(e,n,r=!1,i=null){this.currentNode=null,this.actualDepth=null,this.isBlock=r,this.resolvedPos=e,this.editor=n,this.currentNode=i}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){var e;return(e=this.actualDepth)!==null&&e!==void 0?e:this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let n=this.from,r=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can’t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}n=this.from+1,r=this.to-1}this.editor.commands.insertContentAt({from:n,to:r},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;const e=this.resolvedPos.start(this.resolvedPos.depth-1),n=this.resolvedPos.doc.resolve(e);return new tr(n,this.editor)}get before(){let e=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.from-3)),new tr(e,this.editor)}get after(){let e=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.to+3)),new tr(e,this.editor)}get children(){const e=[];return this.node.content.forEach((n,r)=>{const i=n.isBlock&&!n.isTextblock,s=n.isAtom&&!n.isText,o=this.pos+r+(s?0:1);if(o<0||o>this.resolvedPos.doc.nodeSize-2)return;const l=this.resolvedPos.doc.resolve(o);if(!i&&l.depth<=this.depth)return;const a=new tr(l,this.editor,i,i?n:null);i&&(a.actualDepth=this.depth+1),e.push(new tr(l,this.editor,i,i?n:null))}),e}get firstChild(){return this.children[0]||null}get lastChild(){const e=this.children;return e[e.length-1]||null}closest(e,n={}){let r=null,i=this.parent;for(;i&&!r;){if(i.node.type.name===e)if(Object.keys(n).length>0){const s=i.node.attrs,o=Object.keys(n);for(let l=0;l{r&&i.length>0||(o.node.type.name===e&&s.every(a=>n[a]===o.node.attrs[a])&&i.push(o),!(r&&i.length>0)&&(i=i.concat(o.querySelectorAll(e,n,r))))}),i}setAttribute(e){const{tr:n}=this.editor.state;n.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(n)}}const AN=`.ProseMirror { + position: relative; +} + +.ProseMirror { + word-wrap: break-word; + white-space: pre-wrap; + white-space: break-spaces; + -webkit-font-variant-ligatures: none; + font-variant-ligatures: none; + font-feature-settings: "liga" 0; /* the above doesn't seem to work in Edge */ +} + +.ProseMirror [contenteditable="false"] { + white-space: normal; +} + +.ProseMirror [contenteditable="false"] [contenteditable="true"] { + white-space: pre-wrap; +} + +.ProseMirror pre { + white-space: pre-wrap; +} + +img.ProseMirror-separator { + display: inline !important; + border: none !important; + margin: 0 !important; + width: 0 !important; + height: 0 !important; +} + +.ProseMirror-gapcursor { + display: none; + pointer-events: none; + position: absolute; + margin: 0; +} + +.ProseMirror-gapcursor:after { + content: ""; + display: block; + position: absolute; + top: -2px; + width: 20px; + border-top: 1px solid black; + animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite; +} + +@keyframes ProseMirror-cursor-blink { + to { + visibility: hidden; + } +} + +.ProseMirror-hideselection *::selection { + background: transparent; +} + +.ProseMirror-hideselection *::-moz-selection { + background: transparent; +} + +.ProseMirror-hideselection * { + caret-color: transparent; +} + +.ProseMirror-focused .ProseMirror-gapcursor { + display: block; +} + +.tippy-box[data-animation=fade][data-state=hidden] { + opacity: 0 +}`;function IN(t,e,n){const r=document.querySelector("style[data-tiptap-style]");if(r!==null)return r;const i=document.createElement("style");return e&&i.setAttribute("nonce",e),i.setAttribute("data-tiptap-style",""),i.innerHTML=t,document.getElementsByTagName("head")[0].appendChild(i),i}let RN=class extends HC{constructor(e={}){super(),this.isFocused=!1,this.isInitialized=!1,this.extensionStorage={},this.options={element:document.createElement("div"),content:"",injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:n})=>{throw n},onPaste:()=>null,onDrop:()=>null},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on("beforeCreate",this.options.onBeforeCreate),this.emit("beforeCreate",{editor:this}),this.on("contentError",this.options.onContentError),this.createView(),this.injectCSS(),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:n,slice:r,moved:i})=>this.options.onDrop(n,r,i)),this.on("paste",({event:n,slice:r})=>this.options.onPaste(n,r)),window.setTimeout(()=>{this.isDestroyed||(this.commands.focus(this.options.autofocus),this.emit("create",{editor:this}),this.isInitialized=!0)},0)}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&&document&&(this.css=IN(AN,this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},!(!this.view||!this.state||this.isDestroyed)&&(this.options.editorProps&&this.view.setProps(this.options.editorProps),this.view.updateState(this.state))}setEditable(e,n=!0){this.setOptions({editable:e}),n&&this.emit("update",{editor:this,transaction:this.state.tr})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get state(){return this.view.state}registerPlugin(e,n){const r=b0(n)?n(e,[...this.state.plugins]):[...this.state.plugins,e],i=this.state.reconfigure({plugins:r});return this.view.updateState(i),i}unregisterPlugin(e){if(this.isDestroyed)return;const n=this.state.plugins;let r=n;if([].concat(e).forEach(s=>{const o=typeof s=="string"?`${s}$`:s.key;r=r.filter(l=>!l.key.startsWith(o))}),n.length===r.length)return;const i=this.state.reconfigure({plugins:r});return this.view.updateState(i),i}createExtensionManager(){var e,n;const i=[...this.options.enableCoreExtensions?[bN,iE.configure({blockSeparator:(n=(e=this.options.coreExtensionOptions)===null||e===void 0?void 0:e.clipboardTextSerializer)===null||n===void 0?void 0:n.blockSeparator}),EN,TN,ON,PN,NN,DN].filter(s=>typeof this.options.enableCoreExtensions=="object"?this.options.enableCoreExtensions[s.name]!==!1:!0):[],...this.options.extensions].filter(s=>["extension","node","mark"].includes(s==null?void 0:s.type));this.extensionManager=new lr(i,this)}createCommandManager(){this.commandManager=new $l({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createView(){var e;let n;try{n=nc(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(o){if(!(o instanceof Error)||!["[tiptap error]: Invalid JSON content","[tiptap error]: Invalid HTML content"].includes(o.message))throw o;this.emit("contentError",{editor:this,error:o,disableCollaboration:()=>{this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(l=>l.name!=="collaboration"),this.createExtensionManager()}}),n=nc(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1})}const r=A0(n,this.options.autofocus);this.view=new d0(this.options.element,{...this.options.editorProps,attributes:{role:"textbox",...(e=this.options.editorProps)===null||e===void 0?void 0:e.attributes},dispatchTransaction:this.dispatchTransaction.bind(this),state:Qr.create({doc:n,selection:r||void 0})});const i=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(i),this.createNodeViews(),this.prependClass();const s=this.view.dom;s.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`tiptap ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;const n=this.capturedTransaction;return this.capturedTransaction=null,n}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=e;return}e.steps.forEach(o=>{var l;return(l=this.capturedTransaction)===null||l===void 0?void 0:l.step(o)});return}const n=this.state.apply(e),r=!this.state.selection.eq(n.selection);this.emit("beforeTransaction",{editor:this,transaction:e,nextState:n}),this.view.updateState(n),this.emit("transaction",{editor:this,transaction:e}),r&&this.emit("selectionUpdate",{editor:this,transaction:e});const i=e.getMeta("focus"),s=e.getMeta("blur");i&&this.emit("focus",{editor:this,event:i.event,transaction:e}),s&&this.emit("blur",{editor:this,event:s.event,transaction:e}),!(!e.docChanged||e.getMeta("preventUpdate"))&&this.emit("update",{editor:this,transaction:e})}getAttributes(e){return tN(this.state,e)}isActive(e,n){const r=typeof e=="string"?e:null,i=typeof e=="string"?n:e;return nN(this.state,r,i)}getJSON(){return this.state.doc.toJSON()}getHTML(){return Ul(this.state.doc.content,this.schema)}getText(e){const{blockSeparator:n=` + +`,textSerializers:r={}}=e||{};return ZE(this.state.doc,{blockSeparator:n,textSerializers:{...O0(this.schema),...r}})}get isEmpty(){return ql(this.state.doc)}getCharacterCount(){return console.warn('[tiptap warn]: "editor.getCharacterCount()" is deprecated. Please use "editor.storage.characterCount.characters()" instead.'),this.state.doc.content.size-2}destroy(){if(this.emit("destroy"),this.view){const e=this.view.dom;e&&e.editor&&delete e.editor,this.view.destroy()}this.removeAllListeners()}get isDestroyed(){var e;return!(!((e=this.view)===null||e===void 0)&&e.docView)}$node(e,n){var r;return((r=this.$doc)===null||r===void 0?void 0:r.querySelector(e,n))||null}$nodes(e,n){var r;return((r=this.$doc)===null||r===void 0?void 0:r.querySelectorAll(e,n))||null}$pos(e){const n=this.state.doc.resolve(e);return new tr(n,this)}get $doc(){return this.$pos(0)}};function br(t){return new Hl({find:t.find,handler:({state:e,range:n,match:r})=>{const i=K(t.getAttributes,void 0,r);if(i===!1||i===null)return null;const{tr:s}=e,o=r[r.length-1],l=r[0];if(o){const a=l.search(/\S/),u=n.from+l.indexOf(o),c=u+o.length;if(j0(n.from,n.to,e.doc).filter(h=>h.mark.type.excluded.find(m=>m===t.type&&m!==h.mark.type)).filter(h=>h.to>u).length)return null;cn.from&&s.delete(n.from+a,u);const f=n.from+a+o.length;s.addMark(n.from+a,f,t.type.create(i||{})),s.removeStoredMark(t.type)}}})}function z0(t){return new Hl({find:t.find,handler:({state:e,range:n,match:r})=>{const i=K(t.getAttributes,void 0,r)||{},{tr:s}=e,o=n.from;let l=n.to;const a=t.type.create(i);if(r[1]){const u=r[0].lastIndexOf(r[1]);let c=o+u;c>l?c=l:l=c+r[1].length;const d=r[0][r[0].length-1];s.insertText(d,o+r[0].length-1),s.replaceWith(c,l,a)}else if(r[0]){const u=t.type.isInline?o:o-1;s.insert(u,t.type.create(i)).delete(s.mapping.map(o),s.mapping.map(l))}s.scrollIntoView()}})}function ic(t){return new Hl({find:t.find,handler:({state:e,range:n,match:r})=>{const i=e.doc.resolve(n.from),s=K(t.getAttributes,void 0,r)||{};if(!i.node(-1).canReplaceWith(i.index(-1),i.indexAfter(-1),t.type))return null;e.tr.delete(n.from,n.to).setBlockType(n.from,n.from,t.type,s)}})}function Os(t){return new Hl({find:t.find,handler:({state:e,range:n,match:r,chain:i})=>{const s=K(t.getAttributes,void 0,r)||{},o=e.tr.delete(n.from,n.to),a=o.doc.resolve(n.from).blockRange(),u=a&&fd(a,t.type,s);if(!u)return null;if(o.wrap(a,u),t.keepMarks&&t.editor){const{selection:d,storedMarks:f}=e,{splittableMarks:h}=t.editor.extensionManager,p=f||d.$to.parentOffset&&d.$from.marks();if(p){const m=p.filter(x=>h.includes(x.type.name));o.ensureMarks(m)}}if(t.keepAttributes){const d=t.type.name==="bulletList"||t.type.name==="orderedList"?"listItem":"taskList";i().updateAttributes(d,s).run()}const c=o.doc.resolve(n.from-1).nodeBefore;c&&c.type===t.type&&qn(o.doc,n.from-1)&&(!t.joinPredicate||t.joinPredicate(r,c))&&o.join(n.from-1)}})}class Ye{constructor(e={}){this.type="node",this.name="node",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=K(L(this,"addOptions",{name:this.name}))),this.storage=K(L(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new Ye(e)}configure(e={}){const n=this.extend({...this.config,addOptions:()=>Wl(this.options,e)});return n.name=this.name,n.parent=this.parent,n}extend(e={}){const n=new Ye(e);return n.parent=this,this.child=n,n.name=e.name?e.name:n.parent.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=K(L(n,"addOptions",{name:n.name})),n.storage=K(L(n,"addStorage",{name:n.name,options:n.options})),n}}class LN{constructor(e,n,r){this.isDragging=!1,this.component=e,this.editor=n.editor,this.options={stopEvent:null,ignoreMutation:null,...r},this.extension=n.extension,this.node=n.node,this.decorations=n.decorations,this.innerDecorations=n.innerDecorations,this.view=n.view,this.HTMLAttributes=n.HTMLAttributes,this.getPos=n.getPos,this.mount()}mount(){}get dom(){return this.editor.view.dom}get contentDOM(){return null}onDragStart(e){var n,r,i,s,o,l,a;const{view:u}=this.editor,c=e.target,d=c.nodeType===3?(n=c.parentElement)===null||n===void 0?void 0:n.closest("[data-drag-handle]"):c.closest("[data-drag-handle]");if(!this.dom||!((r=this.contentDOM)===null||r===void 0)&&r.contains(c)||!d)return;let f=0,h=0;if(this.dom!==d){const v=this.dom.getBoundingClientRect(),S=d.getBoundingClientRect(),w=(i=e.offsetX)!==null&&i!==void 0?i:(s=e.nativeEvent)===null||s===void 0?void 0:s.offsetX,E=(o=e.offsetY)!==null&&o!==void 0?o:(l=e.nativeEvent)===null||l===void 0?void 0:l.offsetY;f=S.x-v.x+w,h=S.y-v.y+E}const p=this.dom.cloneNode(!0);(a=e.dataTransfer)===null||a===void 0||a.setDragImage(p,f,h);const m=this.getPos();if(typeof m!="number")return;const x=F.create(u.state.doc,m),g=u.state.tr.setSelection(x);u.dispatch(g)}stopEvent(e){var n;if(!this.dom)return!1;if(typeof this.options.stopEvent=="function")return this.options.stopEvent({event:e});const r=e.target;if(!(this.dom.contains(r)&&!(!((n=this.contentDOM)===null||n===void 0)&&n.contains(r))))return!1;const s=e.type.startsWith("drag"),o=e.type==="drop";if((["INPUT","BUTTON","SELECT","TEXTAREA"].includes(r.tagName)||r.isContentEditable)&&!o&&!s)return!0;const{isEditable:a}=this.editor,{isDragging:u}=this,c=!!this.node.type.spec.draggable,d=F.isSelectable(this.node),f=e.type==="copy",h=e.type==="paste",p=e.type==="cut",m=e.type==="mousedown";if(!c&&d&&s&&e.target===this.dom&&e.preventDefault(),c&&s&&!u&&e.target===this.dom)return e.preventDefault(),!1;if(c&&a&&!u&&m){const x=r.closest("[data-drag-handle]");x&&(this.dom===x||this.dom.contains(x))&&(this.isDragging=!0,document.addEventListener("dragend",()=>{this.isDragging=!1},{once:!0}),document.addEventListener("drop",()=>{this.isDragging=!1},{once:!0}),document.addEventListener("mouseup",()=>{this.isDragging=!1},{once:!0}))}return!(u||o||f||h||p||m&&d)}ignoreMutation(e){return!this.dom||!this.contentDOM?!0:typeof this.options.ignoreMutation=="function"?this.options.ignoreMutation({mutation:e}):this.node.isLeaf||this.node.isAtom?!0:e.type==="selection"||this.dom.contains(e.target)&&e.type==="childList"&&(bs()||tc())&&this.editor.isFocused&&[...Array.from(e.addedNodes),...Array.from(e.removedNodes)].every(r=>r.isContentEditable)?!1:this.contentDOM===e.target&&e.type==="attributes"?!0:!this.contentDOM.contains(e.target)}updateAttributes(e){this.editor.commands.command(({tr:n})=>{const r=this.getPos();return typeof r!="number"?!1:(n.setNodeMarkup(r,void 0,{...this.node.attrs,...e}),!0)})}deleteNode(){const e=this.getPos();if(typeof e!="number")return;const n=e+this.node.nodeSize;this.editor.commands.deleteRange({from:e,to:n})}}function Mr(t){return new XC({find:t.find,handler:({state:e,range:n,match:r,pasteEvent:i})=>{const s=K(t.getAttributes,void 0,r,i);if(s===!1||s===null)return null;const{tr:o}=e,l=r[r.length-1],a=r[0];let u=n.to;if(l){const c=a.search(/\S/),d=n.from+a.indexOf(l),f=d+l.length;if(j0(n.from,n.to,e.doc).filter(p=>p.mark.type.excluded.find(x=>x===t.type&&x!==p.mark.type)).filter(p=>p.to>d).length)return null;fn.from&&o.delete(n.from+c,d),u=n.from+c+l.length,o.addMark(n.from+c,u,t.type.create(s||{})),o.removeStoredMark(t.type)}}})}function jN(t,e){const{selection:n}=t,{$from:r}=n;if(n instanceof F){const s=r.index();return r.parent.canReplaceWith(s,s+1,e)}let i=r.depth;for(;i>=0;){const s=r.index(i);if(r.node(i).contentMatchAt(s).matchType(e))return!0;i-=1}return!1}const zN=/^\s*>\s$/,BN=Ye.create({name:"blockquote",addOptions(){return{HTMLAttributes:{}}},content:"block+",group:"block",defining:!0,parseHTML(){return[{tag:"blockquote"}]},renderHTML({HTMLAttributes:t}){return["blockquote",Se(this.options.HTMLAttributes,t),0]},addCommands(){return{setBlockquote:()=>({commands:t})=>t.wrapIn(this.name),toggleBlockquote:()=>({commands:t})=>t.toggleWrap(this.name),unsetBlockquote:()=>({commands:t})=>t.lift(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-b":()=>this.editor.commands.toggleBlockquote()}},addInputRules(){return[Os({find:zN,type:this.type})]}}),FN=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,_N=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,$N=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,VN=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,UN=bt.create({name:"bold",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"strong"},{tag:"b",getAttrs:t=>t.style.fontWeight!=="normal"&&null},{style:"font-weight=400",clearMark:t=>t.type.name===this.name},{style:"font-weight",getAttrs:t=>/^(bold(er)?|[5-9]\d{2,})$/.test(t)&&null}]},renderHTML({HTMLAttributes:t}){return["strong",Se(this.options.HTMLAttributes,t),0]},addCommands(){return{setBold:()=>({commands:t})=>t.setMark(this.name),toggleBold:()=>({commands:t})=>t.toggleMark(this.name),unsetBold:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[br({find:FN,type:this.type}),br({find:$N,type:this.type})]},addPasteRules(){return[Mr({find:_N,type:this.type}),Mr({find:VN,type:this.type})]}}),HN="listItem",ap="textStyle",up=/^\s*([-+*])\s$/,WN=Ye.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:t}){return["ul",Se(this.options.HTMLAttributes,t),0]},addCommands(){return{toggleBulletList:()=>({commands:t,chain:e})=>this.options.keepAttributes?e().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(HN,this.editor.getAttributes(ap)).run():t.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let t=Os({find:up,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(t=Os({find:up,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(ap),editor:this.editor})),[t]}}),KN=/(^|[^`])`([^`]+)`(?!`)/,JN=/(^|[^`])`([^`]+)`(?!`)/g,qN=bt.create({name:"code",addOptions(){return{HTMLAttributes:{}}},excludes:"_",code:!0,exitable:!0,parseHTML(){return[{tag:"code"}]},renderHTML({HTMLAttributes:t}){return["code",Se(this.options.HTMLAttributes,t),0]},addCommands(){return{setCode:()=>({commands:t})=>t.setMark(this.name),toggleCode:()=>({commands:t})=>t.toggleMark(this.name),unsetCode:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-e":()=>this.editor.commands.toggleCode()}},addInputRules(){return[br({find:KN,type:this.type})]},addPasteRules(){return[Mr({find:JN,type:this.type})]}}),GN=/^```([a-z]+)?[\s\n]$/,QN=/^~~~([a-z]+)?[\s\n]$/,YN=Ye.create({name:"codeBlock",addOptions(){return{languageClassPrefix:"language-",exitOnTripleEnter:!0,exitOnArrowDown:!0,defaultLanguage:null,HTMLAttributes:{}}},content:"text*",marks:"",group:"block",code:!0,defining:!0,addAttributes(){return{language:{default:this.options.defaultLanguage,parseHTML:t=>{var e;const{languageClassPrefix:n}=this.options,s=[...((e=t.firstElementChild)===null||e===void 0?void 0:e.classList)||[]].filter(o=>o.startsWith(n)).map(o=>o.replace(n,""))[0];return s||null},rendered:!1}}},parseHTML(){return[{tag:"pre",preserveWhitespace:"full"}]},renderHTML({node:t,HTMLAttributes:e}){return["pre",Se(this.options.HTMLAttributes,e),["code",{class:t.attrs.language?this.options.languageClassPrefix+t.attrs.language:null},0]]},addCommands(){return{setCodeBlock:t=>({commands:e})=>e.setNode(this.name,t),toggleCodeBlock:t=>({commands:e})=>e.toggleNode(this.name,"paragraph",t)}},addKeyboardShortcuts(){return{"Mod-Alt-c":()=>this.editor.commands.toggleCodeBlock(),Backspace:()=>{const{empty:t,$anchor:e}=this.editor.state.selection,n=e.pos===1;return!t||e.parent.type.name!==this.name?!1:n||!e.parent.textContent.length?this.editor.commands.clearNodes():!1},Enter:({editor:t})=>{if(!this.options.exitOnTripleEnter)return!1;const{state:e}=t,{selection:n}=e,{$from:r,empty:i}=n;if(!i||r.parent.type!==this.type)return!1;const s=r.parentOffset===r.parent.nodeSize-2,o=r.parent.textContent.endsWith(` + +`);return!s||!o?!1:t.chain().command(({tr:l})=>(l.delete(r.pos-2,r.pos),!0)).exitCode().run()},ArrowDown:({editor:t})=>{if(!this.options.exitOnArrowDown)return!1;const{state:e}=t,{selection:n,doc:r}=e,{$from:i,empty:s}=n;if(!s||i.parent.type!==this.type||!(i.parentOffset===i.parent.nodeSize-2))return!1;const l=i.after();return l===void 0?!1:r.nodeAt(l)?t.commands.command(({tr:u})=>(u.setSelection(W.near(r.resolve(l))),!0)):t.commands.exitCode()}}},addInputRules(){return[ic({find:GN,type:this.type,getAttributes:t=>({language:t[1]})}),ic({find:QN,type:this.type,getAttributes:t=>({language:t[1]})})]},addProseMirrorPlugins(){return[new Ke({key:new Mt("codeBlockVSCodeHandler"),props:{handlePaste:(t,e)=>{if(!e.clipboardData||this.editor.isActive(this.type.name))return!1;const n=e.clipboardData.getData("text/plain"),r=e.clipboardData.getData("vscode-editor-data"),i=r?JSON.parse(r):void 0,s=i==null?void 0:i.mode;if(!n||!s)return!1;const{tr:o,schema:l}=t.state,a=l.text(n.replace(/\r\n?/g,` +`));return o.replaceSelectionWith(this.type.create({language:s},a)),o.selection.$from.parent.type!==this.type&&o.setSelection(H.near(o.doc.resolve(Math.max(0,o.selection.from-2)))),o.setMeta("paste",!0),t.dispatch(o),!0}}})]}}),XN=Ye.create({name:"doc",topNode:!0,content:"block+"});function ZN(t={}){return new Ke({view(e){return new eb(e,t)}})}class eb{constructor(e,n){var r;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=(r=n.width)!==null&&r!==void 0?r:1,this.color=n.color===!1?void 0:n.color||"black",this.class=n.class,this.handlers=["dragover","dragend","drop","dragleave"].map(i=>{let s=o=>{this[i](o)};return e.dom.addEventListener(i,s),{name:i,handler:s}})}destroy(){this.handlers.forEach(({name:e,handler:n})=>this.editorView.dom.removeEventListener(e,n))}update(e,n){this.cursorPos!=null&&n.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),n=!e.parent.inlineContent,r,i=this.editorView.dom,s=i.getBoundingClientRect(),o=s.width/i.offsetWidth,l=s.height/i.offsetHeight;if(n){let d=e.nodeBefore,f=e.nodeAfter;if(d||f){let h=this.editorView.nodeDOM(this.cursorPos-(d?d.nodeSize:0));if(h){let p=h.getBoundingClientRect(),m=d?p.bottom:p.top;d&&f&&(m=(m+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let x=this.width/2*l;r={left:p.left,right:p.right,top:m-x,bottom:m+x}}}}if(!r){let d=this.editorView.coordsAtPos(this.cursorPos),f=this.width/2*o;r={left:d.left-f,right:d.left+f,top:d.top,bottom:d.bottom}}let a=this.editorView.dom.offsetParent;this.element||(this.element=a.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",n),this.element.classList.toggle("prosemirror-dropcursor-inline",!n);let u,c;if(!a||a==document.body&&getComputedStyle(a).position=="static")u=-pageXOffset,c=-pageYOffset;else{let d=a.getBoundingClientRect(),f=d.width/a.offsetWidth,h=d.height/a.offsetHeight;u=d.left-a.scrollLeft*f,c=d.top-a.scrollTop*h}this.element.style.left=(r.left-u)/o+"px",this.element.style.top=(r.top-c)/l+"px",this.element.style.width=(r.right-r.left)/o+"px",this.element.style.height=(r.bottom-r.top)/l+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let n=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),r=n&&n.inside>=0&&this.editorView.state.doc.nodeAt(n.inside),i=r&&r.type.spec.disableDropCursor,s=typeof i=="function"?i(this.editorView,n,e):i;if(n&&!s){let o=n.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let l=Ey(this.editorView.state.doc,o,this.editorView.dragging.slice);l!=null&&(o=l)}this.setCursor(o),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}}const tb=Pe.create({name:"dropCursor",addOptions(){return{color:"currentColor",width:1,class:void 0}},addProseMirrorPlugins(){return[ZN(this.options)]}});class de extends W{constructor(e){super(e,e)}map(e,n){let r=e.resolve(n.map(this.head));return de.valid(r)?new de(r):W.near(r)}content(){return I.empty}eq(e){return e instanceof de&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new de(e.resolve(n.pos))}getBookmark(){return new Dd(this.anchor)}static valid(e){let n=e.parent;if(n.inlineContent||!nb(e)||!rb(e))return!1;let r=n.type.spec.allowGapCursor;if(r!=null)return r;let i=n.contentMatchAt(e.index()).defaultType;return i&&i.isTextblock}static findGapCursorFrom(e,n,r=!1){e:for(;;){if(!r&&de.valid(e))return e;let i=e.pos,s=null;for(let o=e.depth;;o--){let l=e.node(o);if(n>0?e.indexAfter(o)0){s=l.child(n>0?e.indexAfter(o):e.index(o)-1);break}else if(o==0)return null;i+=n;let a=e.doc.resolve(i);if(de.valid(a))return a}for(;;){let o=n>0?s.firstChild:s.lastChild;if(!o){if(s.isAtom&&!s.isText&&!F.isSelectable(s)){e=e.doc.resolve(i+s.nodeSize*n),r=!1;continue e}break}s=o,i+=n;let l=e.doc.resolve(i);if(de.valid(l))return l}return null}}}de.prototype.visible=!1;de.findFrom=de.findGapCursorFrom;W.jsonID("gapcursor",de);class Dd{constructor(e){this.pos=e}map(e){return new Dd(e.map(this.pos))}resolve(e){let n=e.resolve(this.pos);return de.valid(n)?new de(n):W.near(n)}}function B0(t){return t.isAtom||t.spec.isolating||t.spec.createGapCursor}function nb(t){for(let e=t.depth;e>=0;e--){let n=t.index(e),r=t.node(e);if(n==0){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(n-1);;i=i.lastChild){if(i.childCount==0&&!i.inlineContent||B0(i.type))return!0;if(i.inlineContent)return!1}}return!0}function rb(t){for(let e=t.depth;e>=0;e--){let n=t.indexAfter(e),r=t.node(e);if(n==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let i=r.child(n);;i=i.firstChild){if(i.childCount==0&&!i.inlineContent||B0(i.type))return!0;if(i.inlineContent)return!1}}return!0}function ib(){return new Ke({props:{decorations:ab,createSelectionBetween(t,e,n){return e.pos==n.pos&&de.valid(n)?new de(n):null},handleClick:ob,handleKeyDown:sb,handleDOMEvents:{beforeinput:lb}}})}const sb=f0({ArrowLeft:po("horiz",-1),ArrowRight:po("horiz",1),ArrowUp:po("vert",-1),ArrowDown:po("vert",1)});function po(t,e){const n=t=="vert"?e>0?"down":"up":e>0?"right":"left";return function(r,i,s){let o=r.selection,l=e>0?o.$to:o.$from,a=o.empty;if(o instanceof H){if(!s.endOfTextblock(n)||l.depth==0)return!1;a=!1,l=r.doc.resolve(e>0?l.after():l.before())}let u=de.findGapCursorFrom(l,e,a);return u?(i&&i(r.tr.setSelection(new de(u))),!0):!1}}function ob(t,e,n){if(!t||!t.editable)return!1;let r=t.state.doc.resolve(e);if(!de.valid(r))return!1;let i=t.posAtCoords({left:n.clientX,top:n.clientY});return i&&i.inside>-1&&F.isSelectable(t.state.doc.nodeAt(i.inside))?!1:(t.dispatch(t.state.tr.setSelection(new de(r))),!0)}function lb(t,e){if(e.inputType!="insertCompositionText"||!(t.state.selection instanceof de))return!1;let{$from:n}=t.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(t.state.schema.nodes.text);if(!r)return!1;let i=O.empty;for(let o=r.length-1;o>=0;o--)i=O.from(r[o].createAndFill(null,i));let s=t.state.tr.replace(n.pos,n.pos,new I(i,0,0));return s.setSelection(H.near(s.doc.resolve(n.pos+1))),t.dispatch(s),!1}function ab(t){if(!(t.selection instanceof de))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",ge.create(t.doc,[ct.widget(t.selection.head,e,{key:"gapcursor"})])}const ub=Pe.create({name:"gapCursor",addProseMirrorPlugins(){return[ib()]},extendNodeSchema(t){var e;const n={name:t.name,options:t.options,storage:t.storage};return{allowGapCursor:(e=K(L(t,"allowGapCursor",n)))!==null&&e!==void 0?e:null}}}),cb=Ye.create({name:"hardBreak",addOptions(){return{keepMarks:!0,HTMLAttributes:{}}},inline:!0,group:"inline",selectable:!1,linebreakReplacement:!0,parseHTML(){return[{tag:"br"}]},renderHTML({HTMLAttributes:t}){return["br",Se(this.options.HTMLAttributes,t)]},renderText(){return` +`},addCommands(){return{setHardBreak:()=>({commands:t,chain:e,state:n,editor:r})=>t.first([()=>t.exitCode(),()=>t.command(()=>{const{selection:i,storedMarks:s}=n;if(i.$from.parent.type.spec.isolating)return!1;const{keepMarks:o}=this.options,{splittableMarks:l}=r.extensionManager,a=s||i.$to.parentOffset&&i.$from.marks();return e().insertContent({type:this.name}).command(({tr:u,dispatch:c})=>{if(c&&a&&o){const d=a.filter(f=>l.includes(f.type.name));u.ensureMarks(d)}return!0}).run()})])}},addKeyboardShortcuts(){return{"Mod-Enter":()=>this.editor.commands.setHardBreak(),"Shift-Enter":()=>this.editor.commands.setHardBreak()}}}),db=Ye.create({name:"heading",addOptions(){return{levels:[1,2,3,4,5,6],HTMLAttributes:{}}},content:"inline*",group:"block",defining:!0,addAttributes(){return{level:{default:1,rendered:!1}}},parseHTML(){return this.options.levels.map(t=>({tag:`h${t}`,attrs:{level:t}}))},renderHTML({node:t,HTMLAttributes:e}){return[`h${this.options.levels.includes(t.attrs.level)?t.attrs.level:this.options.levels[0]}`,Se(this.options.HTMLAttributes,e),0]},addCommands(){return{setHeading:t=>({commands:e})=>this.options.levels.includes(t.level)?e.setNode(this.name,t):!1,toggleHeading:t=>({commands:e})=>this.options.levels.includes(t.level)?e.toggleNode(this.name,"paragraph",t):!1}},addKeyboardShortcuts(){return this.options.levels.reduce((t,e)=>({...t,[`Mod-Alt-${e}`]:()=>this.editor.commands.toggleHeading({level:e})}),{})},addInputRules(){return this.options.levels.map(t=>ic({find:new RegExp(`^(#{${Math.min(...this.options.levels)},${t}})\\s$`),type:this.type,getAttributes:{level:t}}))}});var pl=200,Oe=function(){};Oe.prototype.append=function(e){return e.length?(e=Oe.from(e),!this.length&&e||e.length=n?Oe.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,n))};Oe.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};Oe.prototype.forEach=function(e,n,r){n===void 0&&(n=0),r===void 0&&(r=this.length),n<=r?this.forEachInner(e,n,r,0):this.forEachInvertedInner(e,n,r,0)};Oe.prototype.map=function(e,n,r){n===void 0&&(n=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},n,r),i};Oe.from=function(e){return e instanceof Oe?e:e&&e.length?new F0(e):Oe.empty};var F0=function(t){function e(r){t.call(this),this.values=r}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var n={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var a=s;a=o;a--)if(i(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=pl)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=pl)return new e(i.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(e.prototype,n),e}(Oe);Oe.empty=new F0([]);var fb=function(t){function e(n,r){t.call(this),this.left=n,this.right=r,this.length=n.length+r.length,this.depth=Math.max(n.depth,r.depth)+1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(r){return rl&&this.right.forEachInner(r,Math.max(i-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,s,o){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(s,l)-l,o+l)===!1||s=s?this.right.slice(r-s,i-s):this.left.slice(r,s).append(this.right.slice(0,i-s))},e.prototype.leafAppend=function(r){var i=this.right.leafAppend(r);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(r){var i=this.left.leafPrepend(r);if(i)return new e(i,this.right)},e.prototype.appendInner=function(r){return this.left.depth>=Math.max(this.right.depth,r.depth)+1?new e(this.left,new e(this.right,r)):new e(this,r)},e}(Oe);const hb=500;class Rt{constructor(e,n){this.items=e,this.eventCount=n}popEvent(e,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,s;n&&(i=this.remapping(r,this.items.length),s=i.maps.length);let o=e.tr,l,a,u=[],c=[];return this.items.forEach((d,f)=>{if(!d.step){i||(i=this.remapping(r,f+1),s=i.maps.length),s--,c.push(d);return}if(i){c.push(new $t(d.map));let h=d.step.map(i.slice(s)),p;h&&o.maybeStep(h).doc&&(p=o.mapping.maps[o.mapping.maps.length-1],u.push(new $t(p,void 0,void 0,u.length+c.length))),s--,p&&i.appendMap(p,s)}else o.maybeStep(d.step);if(d.selection)return l=i?d.selection.map(i.slice(s)):d.selection,a=new Rt(this.items.slice(0,r).append(c.reverse().concat(u)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:o,selection:l}}addTransform(e,n,r,i){let s=[],o=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let c=0;cmb&&(l=pb(l,u),o-=u),new Rt(l.append(s),o)}remapping(e,n){let r=new ks;return this.items.forEach((i,s)=>{let o=i.mirrorOffset!=null&&s-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,o)},e,n),r}addMaps(e){return this.eventCount==0?this:new Rt(this.items.append(e.map(n=>new $t(n))),this.eventCount)}rebased(e,n){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-n),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(f=>{f.selection&&l--},i);let a=n;this.items.forEach(f=>{let h=s.getMirror(--a);if(h==null)return;o=Math.min(o,h);let p=s.maps[h];if(f.step){let m=e.steps[h].invert(e.docs[h]),x=f.selection&&f.selection.map(s.slice(a+1,h));x&&l++,r.push(new $t(p,m,x))}else r.push(new $t(p))},i);let u=[];for(let f=n;fhb&&(d=d.compress(this.items.length-r.length)),d}emptyItemCount(){let e=0;return this.items.forEach(n=>{n.step||e++}),e}compress(e=this.items.length){let n=this.remapping(0,e),r=n.maps.length,i=[],s=0;return this.items.forEach((o,l)=>{if(l>=e)i.push(o),o.selection&&s++;else if(o.step){let a=o.step.map(n.slice(r)),u=a&&a.getMap();if(r--,u&&n.appendMap(u,r),a){let c=o.selection&&o.selection.map(n.slice(r));c&&s++;let d=new $t(u.invert(),a,c),f,h=i.length-1;(f=i.length&&i[h].merge(d))?i[h]=f:i.push(d)}}else o.map&&r--},this.items.length,0),new Rt(Oe.from(i.reverse()),s)}}Rt.empty=new Rt(Oe.empty,0);function pb(t,e){let n;return t.forEach((r,i)=>{if(r.selection&&e--==0)return n=i,!1}),t.slice(n)}class $t{constructor(e,n,r,i){this.map=e,this.step=n,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let n=e.step.merge(this.step);if(n)return new $t(n.getMap().invert(),n,this.selection)}}}class xn{constructor(e,n,r,i,s){this.done=e,this.undone=n,this.prevRanges=r,this.prevTime=i,this.prevComposition=s}}const mb=20;function gb(t,e,n,r){let i=n.getMeta(gr),s;if(i)return i.historyState;n.getMeta(xb)&&(t=new xn(t.done,t.undone,null,0,-1));let o=n.getMeta("appendedTransaction");if(n.steps.length==0)return t;if(o&&o.getMeta(gr))return o.getMeta(gr).redo?new xn(t.done.addTransform(n,void 0,r,Do(e)),t.undone,cp(n.mapping.maps),t.prevTime,t.prevComposition):new xn(t.done,t.undone.addTransform(n,void 0,r,Do(e)),null,t.prevTime,t.prevComposition);if(n.getMeta("addToHistory")!==!1&&!(o&&o.getMeta("addToHistory")===!1)){let l=n.getMeta("composition"),a=t.prevTime==0||!o&&t.prevComposition!=l&&(t.prevTime<(n.time||0)-r.newGroupDelay||!yb(n,t.prevRanges)),u=o?_a(t.prevRanges,n.mapping):cp(n.mapping.maps);return new xn(t.done.addTransform(n,a?e.selection.getBookmark():void 0,r,Do(e)),Rt.empty,u,n.time,l??t.prevComposition)}else return(s=n.getMeta("rebased"))?new xn(t.done.rebased(n,s),t.undone.rebased(n,s),_a(t.prevRanges,n.mapping),t.prevTime,t.prevComposition):new xn(t.done.addMaps(n.mapping.maps),t.undone.addMaps(n.mapping.maps),_a(t.prevRanges,n.mapping),t.prevTime,t.prevComposition)}function yb(t,e){if(!e)return!1;if(!t.docChanged)return!0;let n=!1;return t.mapping.maps[0].forEach((r,i)=>{for(let s=0;s=e[s]&&(n=!0)}),n}function cp(t){let e=[];for(let n=t.length-1;n>=0&&e.length==0;n--)t[n].forEach((r,i,s,o)=>e.push(s,o));return e}function _a(t,e){if(!t)return null;let n=[];for(let r=0;r{let i=gr.getState(n);if(!i||(t?i.undone:i.done).eventCount==0)return!1;if(r){let s=vb(i,n,t);s&&r(e?s.scrollIntoView():s)}return!0}}const $0=_0(!1,!0),V0=_0(!0,!0),kb=Pe.create({name:"history",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:t,dispatch:e})=>$0(t,e),redo:()=>({state:t,dispatch:e})=>V0(t,e)}},addProseMirrorPlugins(){return[Sb(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()}}}),wb=Ye.create({name:"horizontalRule",addOptions(){return{HTMLAttributes:{}}},group:"block",parseHTML(){return[{tag:"hr"}]},renderHTML({HTMLAttributes:t}){return["hr",Se(this.options.HTMLAttributes,t)]},addCommands(){return{setHorizontalRule:()=>({chain:t,state:e})=>{if(!jN(e,e.schema.nodes[this.name]))return!1;const{selection:n}=e,{$from:r,$to:i}=n,s=t();return r.parentOffset===0?s.insertContentAt({from:Math.max(r.pos-1,0),to:i.pos},{type:this.name}):rN(n)?s.insertContentAt(i.pos,{type:this.name}):s.insertContent({type:this.name}),s.command(({tr:o,dispatch:l})=>{var a;if(l){const{$to:u}=o.selection,c=u.end();if(u.nodeAfter)u.nodeAfter.isTextblock?o.setSelection(H.create(o.doc,u.pos+1)):u.nodeAfter.isBlock?o.setSelection(F.create(o.doc,u.pos)):o.setSelection(H.create(o.doc,u.pos));else{const d=(a=u.parent.type.contentMatch.defaultType)===null||a===void 0?void 0:a.create();d&&(o.insert(c,d),o.setSelection(H.create(o.doc,c+1)))}o.scrollIntoView()}return!0}).run()}}},addInputRules(){return[z0({find:/^(?:---|—-|___\s|\*\*\*\s)$/,type:this.type})]}}),Cb=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,Eb=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,Nb=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,bb=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,Mb=bt.create({name:"italic",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"em"},{tag:"i",getAttrs:t=>t.style.fontStyle!=="normal"&&null},{style:"font-style=normal",clearMark:t=>t.type.name===this.name},{style:"font-style=italic"}]},renderHTML({HTMLAttributes:t}){return["em",Se(this.options.HTMLAttributes,t),0]},addCommands(){return{setItalic:()=>({commands:t})=>t.setMark(this.name),toggleItalic:()=>({commands:t})=>t.toggleMark(this.name),unsetItalic:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[br({find:Cb,type:this.type}),br({find:Nb,type:this.type})]},addPasteRules(){return[Mr({find:Eb,type:this.type}),Mr({find:bb,type:this.type})]}}),Tb=Ye.create({name:"listItem",addOptions(){return{HTMLAttributes:{},bulletListTypeName:"bulletList",orderedListTypeName:"orderedList"}},content:"paragraph block*",defining:!0,parseHTML(){return[{tag:"li"}]},renderHTML({HTMLAttributes:t}){return["li",Se(this.options.HTMLAttributes,t),0]},addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}}),Ob="listItem",fp="textStyle",hp=/^(\d+)\.\s$/,Db=Ye.create({name:"orderedList",addOptions(){return{itemTypeName:"listItem",HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:"block list",content(){return`${this.options.itemTypeName}+`},addAttributes(){return{start:{default:1,parseHTML:t=>t.hasAttribute("start")?parseInt(t.getAttribute("start")||"",10):1},type:{default:null,parseHTML:t=>t.getAttribute("type")}}},parseHTML(){return[{tag:"ol"}]},renderHTML({HTMLAttributes:t}){const{start:e,...n}=t;return e===1?["ol",Se(this.options.HTMLAttributes,n),0]:["ol",Se(this.options.HTMLAttributes,t),0]},addCommands(){return{toggleOrderedList:()=>({commands:t,chain:e})=>this.options.keepAttributes?e().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(Ob,this.editor.getAttributes(fp)).run():t.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addInputRules(){let t=Os({find:hp,type:this.type,getAttributes:e=>({start:+e[1]}),joinPredicate:(e,n)=>n.childCount+n.attrs.start===+e[1]});return(this.options.keepMarks||this.options.keepAttributes)&&(t=Os({find:hp,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:e=>({start:+e[1],...this.editor.getAttributes(fp)}),joinPredicate:(e,n)=>n.childCount+n.attrs.start===+e[1],editor:this.editor})),[t]}}),Pb=Ye.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:t}){return["p",Se(this.options.HTMLAttributes,t),0]},addCommands(){return{setParagraph:()=>({commands:t})=>t.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),Ab=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,Ib=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,Rb=bt.create({name:"strike",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"s"},{tag:"del"},{tag:"strike"},{style:"text-decoration",consuming:!1,getAttrs:t=>t.includes("line-through")?{}:!1}]},renderHTML({HTMLAttributes:t}){return["s",Se(this.options.HTMLAttributes,t),0]},addCommands(){return{setStrike:()=>({commands:t})=>t.setMark(this.name),toggleStrike:()=>({commands:t})=>t.toggleMark(this.name),unsetStrike:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[br({find:Ab,type:this.type})]},addPasteRules(){return[Mr({find:Ib,type:this.type})]}}),Lb=Ye.create({name:"text",group:"inline"}),Pd=Pe.create({name:"starterKit",addExtensions(){const t=[];return this.options.bold!==!1&&t.push(UN.configure(this.options.bold)),this.options.blockquote!==!1&&t.push(BN.configure(this.options.blockquote)),this.options.bulletList!==!1&&t.push(WN.configure(this.options.bulletList)),this.options.code!==!1&&t.push(qN.configure(this.options.code)),this.options.codeBlock!==!1&&t.push(YN.configure(this.options.codeBlock)),this.options.document!==!1&&t.push(XN.configure(this.options.document)),this.options.dropcursor!==!1&&t.push(tb.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&t.push(ub.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&t.push(cb.configure(this.options.hardBreak)),this.options.heading!==!1&&t.push(db.configure(this.options.heading)),this.options.history!==!1&&t.push(kb.configure(this.options.history)),this.options.horizontalRule!==!1&&t.push(wb.configure(this.options.horizontalRule)),this.options.italic!==!1&&t.push(Mb.configure(this.options.italic)),this.options.listItem!==!1&&t.push(Tb.configure(this.options.listItem)),this.options.orderedList!==!1&&t.push(Db.configure(this.options.orderedList)),this.options.paragraph!==!1&&t.push(Pb.configure(this.options.paragraph)),this.options.strike!==!1&&t.push(Rb.configure(this.options.strike)),this.options.text!==!1&&t.push(Lb.configure(this.options.text)),t}}),Ad=bt.create({name:"underline",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"u"},{style:"text-decoration",consuming:!1,getAttrs:t=>t.includes("underline")?{}:!1}]},renderHTML({HTMLAttributes:t}){return["u",Se(this.options.HTMLAttributes,t),0]},addCommands(){return{setUnderline:()=>({commands:t})=>t.setMark(this.name),toggleUnderline:()=>({commands:t})=>t.toggleMark(this.name),unsetUnderline:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}}),jb=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,Id=Ye.create({name:"image",addOptions(){return{inline:!1,allowBase64:!1,HTMLAttributes:{}}},inline(){return this.options.inline},group(){return this.options.inline?"inline":"block"},draggable:!0,addAttributes(){return{src:{default:null},alt:{default:null},title:{default:null}}},parseHTML(){return[{tag:this.options.allowBase64?"img[src]":'img[src]:not([src^="data:"])'}]},renderHTML({HTMLAttributes:t}){return["img",Se(this.options.HTMLAttributes,t)]},addCommands(){return{setImage:t=>({commands:e})=>e.insertContent({type:this.name,attrs:t})}},addInputRules(){return[z0({find:jb,type:this.type,getAttributes:t=>{const[,,e,n,r]=t;return{src:n,alt:e,title:r}}})]}}),U0=Pe.create({name:"textAlign",addOptions(){return{types:[],alignments:["left","center","right","justify"],defaultAlignment:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{textAlign:{default:this.options.defaultAlignment,parseHTML:t=>{const e=t.style.textAlign;return this.options.alignments.includes(e)?e:this.options.defaultAlignment},renderHTML:t=>t.textAlign?{style:`text-align: ${t.textAlign}`}:{}}}}]},addCommands(){return{setTextAlign:t=>({commands:e})=>this.options.alignments.includes(t)?this.options.types.map(n=>e.updateAttributes(n,{textAlign:t})).every(n=>n):!1,unsetTextAlign:()=>({commands:t})=>this.options.types.map(e=>t.resetAttributes(e,"textAlign")).every(e=>e),toggleTextAlign:t=>({editor:e,commands:n})=>this.options.alignments.includes(t)?e.isActive({textAlign:t})?n.unsetTextAlign():n.setTextAlign(t):!1}},addKeyboardShortcuts(){return{"Mod-Shift-l":()=>this.editor.commands.setTextAlign("left"),"Mod-Shift-e":()=>this.editor.commands.setTextAlign("center"),"Mod-Shift-r":()=>this.editor.commands.setTextAlign("right"),"Mod-Shift-j":()=>this.editor.commands.setTextAlign("justify")}}}),zb=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/,Bb=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g,H0=bt.create({name:"highlight",addOptions(){return{multicolor:!1,HTMLAttributes:{}}},addAttributes(){return this.options.multicolor?{color:{default:null,parseHTML:t=>t.getAttribute("data-color")||t.style.backgroundColor,renderHTML:t=>t.color?{"data-color":t.color,style:`background-color: ${t.color}; color: inherit`}:{}}}:{}},parseHTML(){return[{tag:"mark"}]},renderHTML({HTMLAttributes:t}){return["mark",Se(this.options.HTMLAttributes,t),0]},addCommands(){return{setHighlight:t=>({commands:e})=>e.setMark(this.name,t),toggleHighlight:t=>({commands:e})=>e.toggleMark(this.name,t),unsetHighlight:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-h":()=>this.editor.commands.toggleHighlight()}},addInputRules(){return[br({find:zb,type:this.type})]},addPasteRules(){return[Mr({find:Bb,type:this.type})]}}),Fb=[Pd,Ad,Id,U0.configure({types:["heading","paragraph"]}),H0.configure({multicolor:!0})],_b=` + * { box-sizing: border-box; margin: 0; padding: 0; } + body { + font-family: Georgia, "Times New Roman", serif; + font-size: 12pt; + line-height: 1.8; + color: #111; + max-width: 6.5in; + margin: 0 auto; + padding: 1in; + } + h1 { + font-size: 18pt; + margin-top: 2em; + margin-bottom: 0.5em; + page-break-before: always; + padding-bottom: 0.25em; + border-bottom: 1px solid #ccc; + } + h1.story-title { page-break-before: avoid; } + h2 { font-size: 14pt; margin-top: 1.5em; margin-bottom: 0.4em; } + h3 { font-size: 12pt; font-style: italic; margin-top: 1em; margin-bottom: 0.3em; } + p { margin-bottom: 0.4em; text-indent: 1.5em; } + h1+p, h2+p, h3+p { text-indent: 0; } + blockquote { + border-left: 3px solid #aaa; + padding-left: 1em; + margin: 1em 0; + font-style: italic; + color: #444; + } + img { max-width: 100%; } + ul, ol { padding-left: 1.5em; margin: 0.5em 0; } + hr { border: none; text-align: center; margin: 1.5em 0; } + hr::after { content: '✦ ✦ ✦'; letter-spacing: 0.5em; color: #888; font-size: 10pt; } + mark { border-radius: 2px; padding: 0.05em 0.15em; } + s { opacity: 0.6; } + @page { margin: 1in; } + @media print { + body { padding: 0; max-width: 100%; } + } +`;function $b(t,e){let n="";if(e&&Object.keys(e).length>0)try{n=XE(e,Fb)}catch{n="

(Could not render content)

"}const r=window.open("","_blank");if(!r){alert("Allow pop-ups to export as PDF.");return}r.document.write(` + + + + ${t} + + + +

${t}

+ ${n} + +`),r.document.close(),r.addEventListener("load",()=>{r.focus(),r.print()})}function W0(t){return t?t.type==="text"?t.text||"":(t.content||[]).map(W0).join(" "):""}function pp(t){return!t||typeof t!="object"?0:W0(t).trim().split(/\s+/).filter(e=>e.length>0).length}const K0="sw-milestones",Vb=[500,1e3,5e3,1e4,25e3,5e4,1e5],Ub={500:"500 words — you're off!",1e3:"1,000 words — a great start!",5e3:"5,000 words — keep going!",1e4:"10,000 words — you're flying!",25e3:"25,000 words — incredible!",5e4:"50,000 words — a whole novel!",1e5:"100,000 words — legendary!"};function Hb(){try{return JSON.parse(localStorage.getItem(K0))||{}}catch{return{}}}function Wb(t,e){const n=Hb(),r=new Set(n[t]||[]);for(const i of Vb)if(e>=i&&!r.has(i))return r.add(i),n[t]=[...r],localStorage.setItem(K0,JSON.stringify(n)),Ub[i];return null}function Kb(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var J0={exports:{}},Va={};/** + * @license React + * use-sync-external-store-shim.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var mp;function Jb(){if(mp)return Va;mp=1;var t=be;function e(d,f){return d===f&&(d!==0||1/d===1/f)||d!==d&&f!==f}var n=typeof Object.is=="function"?Object.is:e,r=t.useState,i=t.useEffect,s=t.useLayoutEffect,o=t.useDebugValue;function l(d,f){var h=f(),p=r({inst:{value:h,getSnapshot:f}}),m=p[0].inst,x=p[1];return s(function(){m.value=h,m.getSnapshot=f,a(m)&&x({inst:m})},[d,h,f]),i(function(){return a(m)&&x({inst:m}),d(function(){a(m)&&x({inst:m})})},[d]),o(h),h}function a(d){var f=d.getSnapshot;d=d.value;try{var h=f();return!n(d,h)}catch{return!0}}function u(d,f){return f()}var c=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?u:l;return Va.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:c,Va}J0.exports=Jb();var Rd=J0.exports;const qb=(...t)=>e=>{t.forEach(n=>{typeof n=="function"?n(e):n&&(n.current=e)})},Gb=({contentComponent:t})=>{const e=Rd.useSyncExternalStore(t.subscribe,t.getSnapshot,t.getServerSnapshot);return be.createElement(be.Fragment,null,Object.values(e))};function Qb(){const t=new Set;let e={};return{subscribe(n){return t.add(n),()=>{t.delete(n)}},getSnapshot(){return e},getServerSnapshot(){return e},setRenderer(n,r){e={...e,[n]:Ox.createPortal(r.reactElement,r.element,n)},t.forEach(i=>i())},removeRenderer(n){const r={...e};delete r[n],e=r,t.forEach(i=>i())}}}class Yb extends be.Component{constructor(e){var n;super(e),this.editorContentRef=be.createRef(),this.initialized=!1,this.state={hasContentComponentInitialized:!!(!((n=e.editor)===null||n===void 0)&&n.contentComponent)}}componentDidMount(){this.init()}componentDidUpdate(){this.init()}init(){const e=this.props.editor;if(e&&!e.isDestroyed&&e.options.element){if(e.contentComponent)return;const n=this.editorContentRef.current;n.append(...e.options.element.childNodes),e.setOptions({element:n}),e.contentComponent=Qb(),this.state.hasContentComponentInitialized||(this.unsubscribeToContentComponent=e.contentComponent.subscribe(()=>{this.setState(r=>r.hasContentComponentInitialized?r:{hasContentComponentInitialized:!0}),this.unsubscribeToContentComponent&&this.unsubscribeToContentComponent()})),e.createNodeViews(),this.initialized=!0}}componentWillUnmount(){const e=this.props.editor;if(!e||(this.initialized=!1,e.isDestroyed||e.view.setProps({nodeViews:{}}),this.unsubscribeToContentComponent&&this.unsubscribeToContentComponent(),e.contentComponent=null,!e.options.element.firstChild))return;const n=document.createElement("div");n.append(...e.options.element.childNodes),e.setOptions({element:n})}render(){const{editor:e,innerRef:n,...r}=this.props;return be.createElement(be.Fragment,null,be.createElement("div",{ref:qb(n,this.editorContentRef),...r}),(e==null?void 0:e.contentComponent)&&be.createElement(Gb,{contentComponent:e.contentComponent}))}}const Xb=k.forwardRef((t,e)=>{const n=be.useMemo(()=>Math.floor(Math.random()*4294967295).toString(),[t.editor]);return be.createElement(Yb,{key:n,innerRef:e,...t})}),q0=be.memo(Xb);var Zb=function t(e,n){if(e===n)return!0;if(e&&n&&typeof e=="object"&&typeof n=="object"){if(e.constructor!==n.constructor)return!1;var r,i,s;if(Array.isArray(e)){if(r=e.length,r!=n.length)return!1;for(i=r;i--!==0;)if(!t(e[i],n[i]))return!1;return!0}if(e instanceof Map&&n instanceof Map){if(e.size!==n.size)return!1;for(i of e.entries())if(!n.has(i[0]))return!1;for(i of e.entries())if(!t(i[1],n.get(i[0])))return!1;return!0}if(e instanceof Set&&n instanceof Set){if(e.size!==n.size)return!1;for(i of e.entries())if(!n.has(i[0]))return!1;return!0}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(n)){if(r=e.length,r!=n.length)return!1;for(i=r;i--!==0;)if(e[i]!==n[i])return!1;return!0}if(e.constructor===RegExp)return e.source===n.source&&e.flags===n.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===n.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===n.toString();if(s=Object.keys(e),r=s.length,r!==Object.keys(n).length)return!1;for(i=r;i--!==0;)if(!Object.prototype.hasOwnProperty.call(n,s[i]))return!1;for(i=r;i--!==0;){var o=s[i];if(!(o==="_owner"&&e.$$typeof)&&!t(e[o],n[o]))return!1}return!0}return e!==e&&n!==n},eM=Kb(Zb),G0={exports:{}},Ua={};/** + * @license React + * use-sync-external-store-shim/with-selector.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var gp;function tM(){if(gp)return Ua;gp=1;var t=be,e=Rd;function n(u,c){return u===c&&(u!==0||1/u===1/c)||u!==u&&c!==c}var r=typeof Object.is=="function"?Object.is:n,i=e.useSyncExternalStore,s=t.useRef,o=t.useEffect,l=t.useMemo,a=t.useDebugValue;return Ua.useSyncExternalStoreWithSelector=function(u,c,d,f,h){var p=s(null);if(p.current===null){var m={hasValue:!1,value:null};p.current=m}else m=p.current;p=l(function(){function g(b){if(!v){if(v=!0,S=b,b=f(b),h!==void 0&&m.hasValue){var C=m.value;if(h(C,b))return w=C}return w=b}if(C=w,r(S,b))return C;var M=f(b);return h!==void 0&&h(C,M)?C:(S=b,w=M)}var v=!1,S,w,E=d===void 0?null:d;return[function(){return g(c())},E===null?void 0:function(){return g(E())}]},[c,d,f,h]);var x=i(u,p[0],p[1]);return o(function(){m.hasValue=!0,m.value=x},[x]),a(x),x},Ua}G0.exports=tM();var nM=G0.exports;const rM=typeof window<"u"?k.useLayoutEffect:k.useEffect;class iM{constructor(e){this.transactionNumber=0,this.lastTransactionNumber=0,this.subscribers=new Set,this.editor=e,this.lastSnapshot={editor:e,transactionNumber:0},this.getSnapshot=this.getSnapshot.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.watch=this.watch.bind(this),this.subscribe=this.subscribe.bind(this)}getSnapshot(){return this.transactionNumber===this.lastTransactionNumber?this.lastSnapshot:(this.lastTransactionNumber=this.transactionNumber,this.lastSnapshot={editor:this.editor,transactionNumber:this.transactionNumber},this.lastSnapshot)}getServerSnapshot(){return{editor:null,transactionNumber:0}}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}watch(e){if(this.editor=e,this.editor){const n=()=>{this.transactionNumber+=1,this.subscribers.forEach(i=>i())},r=this.editor;return r.on("transaction",n),()=>{r.off("transaction",n)}}}}function sM(t){var e;const[n]=k.useState(()=>new iM(t.editor)),r=nM.useSyncExternalStoreWithSelector(n.subscribe,n.getSnapshot,n.getServerSnapshot,t.selector,(e=t.equalityFn)!==null&&e!==void 0?e:eM);return rM(()=>n.watch(t.editor),[t.editor,n]),k.useDebugValue(r),r}const oM=!1,sc=typeof window>"u",lM=sc||!!(typeof window<"u"&&window.next);class Ld{constructor(e){this.editor=null,this.subscriptions=new Set,this.isComponentMounted=!1,this.previousDeps=null,this.instanceId="",this.options=e,this.subscriptions=new Set,this.setEditor(this.getInitialEditor()),this.scheduleDestroy(),this.getEditor=this.getEditor.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.subscribe=this.subscribe.bind(this),this.refreshEditorInstance=this.refreshEditorInstance.bind(this),this.scheduleDestroy=this.scheduleDestroy.bind(this),this.onRender=this.onRender.bind(this),this.createEditor=this.createEditor.bind(this)}setEditor(e){this.editor=e,this.instanceId=Math.random().toString(36).slice(2,9),this.subscriptions.forEach(n=>n())}getInitialEditor(){return this.options.current.immediatelyRender===void 0?sc||lM?null:this.createEditor():(this.options.current.immediatelyRender,this.options.current.immediatelyRender?this.createEditor():null)}createEditor(){const e={...this.options.current,onBeforeCreate:(...r)=>{var i,s;return(s=(i=this.options.current).onBeforeCreate)===null||s===void 0?void 0:s.call(i,...r)},onBlur:(...r)=>{var i,s;return(s=(i=this.options.current).onBlur)===null||s===void 0?void 0:s.call(i,...r)},onCreate:(...r)=>{var i,s;return(s=(i=this.options.current).onCreate)===null||s===void 0?void 0:s.call(i,...r)},onDestroy:(...r)=>{var i,s;return(s=(i=this.options.current).onDestroy)===null||s===void 0?void 0:s.call(i,...r)},onFocus:(...r)=>{var i,s;return(s=(i=this.options.current).onFocus)===null||s===void 0?void 0:s.call(i,...r)},onSelectionUpdate:(...r)=>{var i,s;return(s=(i=this.options.current).onSelectionUpdate)===null||s===void 0?void 0:s.call(i,...r)},onTransaction:(...r)=>{var i,s;return(s=(i=this.options.current).onTransaction)===null||s===void 0?void 0:s.call(i,...r)},onUpdate:(...r)=>{var i,s;return(s=(i=this.options.current).onUpdate)===null||s===void 0?void 0:s.call(i,...r)},onContentError:(...r)=>{var i,s;return(s=(i=this.options.current).onContentError)===null||s===void 0?void 0:s.call(i,...r)},onDrop:(...r)=>{var i,s;return(s=(i=this.options.current).onDrop)===null||s===void 0?void 0:s.call(i,...r)},onPaste:(...r)=>{var i,s;return(s=(i=this.options.current).onPaste)===null||s===void 0?void 0:s.call(i,...r)}};return new RN(e)}getEditor(){return this.editor}getServerSnapshot(){return null}subscribe(e){return this.subscriptions.add(e),()=>{this.subscriptions.delete(e)}}static compareOptions(e,n){return Object.keys(e).every(r=>["onCreate","onBeforeCreate","onDestroy","onUpdate","onTransaction","onFocus","onBlur","onSelectionUpdate","onContentError","onDrop","onPaste"].includes(r)?!0:r==="extensions"&&e.extensions&&n.extensions?e.extensions.length!==n.extensions.length?!1:e.extensions.every((i,s)=>{var o;return i===((o=n.extensions)===null||o===void 0?void 0:o[s])}):e[r]===n[r])}onRender(e){return()=>(this.isComponentMounted=!0,clearTimeout(this.scheduledDestructionTimeout),this.editor&&!this.editor.isDestroyed&&e.length===0?Ld.compareOptions(this.options.current,this.editor.options)||this.editor.setOptions({...this.options.current,editable:this.editor.isEditable}):this.refreshEditorInstance(e),()=>{this.isComponentMounted=!1,this.scheduleDestroy()})}refreshEditorInstance(e){if(this.editor&&!this.editor.isDestroyed){if(this.previousDeps===null){this.previousDeps=e;return}if(this.previousDeps.length===e.length&&this.previousDeps.every((r,i)=>r===e[i]))return}this.editor&&!this.editor.isDestroyed&&this.editor.destroy(),this.setEditor(this.createEditor()),this.previousDeps=e}scheduleDestroy(){const e=this.instanceId,n=this.editor;this.scheduledDestructionTimeout=setTimeout(()=>{if(this.isComponentMounted&&this.instanceId===e){n&&n.setOptions(this.options.current);return}n&&!n.isDestroyed&&(n.destroy(),this.instanceId===e&&this.setEditor(null))},1)}}function Q0(t={},e=[]){const n=k.useRef(t);n.current=t;const[r]=k.useState(()=>new Ld(n)),i=Rd.useSyncExternalStore(r.subscribe,r.getEditor,r.getServerSnapshot);return k.useDebugValue(i),k.useEffect(r.onRender(e)),sM({editor:i,selector:({transactionNumber:s})=>t.shouldRerenderOnTransaction===!1?null:t.immediatelyRender&&s===0?0:s+1}),i}const aM=k.createContext({editor:null});aM.Consumer;const Y0=k.createContext({onDragStart:void 0}),uM=()=>k.useContext(Y0),cM=be.forwardRef((t,e)=>{const{onDragStart:n}=uM(),r=t.as||"div";return be.createElement(r,{...t,ref:e,"data-node-view-wrapper":"",onDragStart:n,style:{whiteSpace:"normal",...t.style}})});function yp(t){return!!(typeof t=="function"&&t.prototype&&t.prototype.isReactComponent)}function vp(t){return!!(typeof t=="object"&&t.$$typeof&&(t.$$typeof.toString()==="Symbol(react.forward_ref)"||t.$$typeof.description==="react.forward_ref"))}function dM(t){return!!(typeof t=="object"&&t.$$typeof&&(t.$$typeof.toString()==="Symbol(react.memo)"||t.$$typeof.description==="react.memo"))}function fM(t){if(yp(t)||vp(t))return!0;if(dM(t)){const e=t.type;if(e)return yp(e)||vp(e)}return!1}function hM(){try{if(k.version)return parseInt(k.version.split(".")[0],10)>=19}catch{}return!1}class pM{constructor(e,{editor:n,props:r={},as:i="div",className:s=""}){this.ref=null,this.id=Math.floor(Math.random()*4294967295).toString(),this.component=e,this.editor=n,this.props=r,this.element=document.createElement(i),this.element.classList.add("react-renderer"),s&&this.element.classList.add(...s.split(" ")),this.editor.isInitialized?Pl.flushSync(()=>{this.render()}):queueMicrotask(()=>{this.render()})}render(){var e;const n=this.component,r=this.props,i=this.editor,s=hM(),o=fM(n),l={...r};l.ref&&!(s||o)&&delete l.ref,!l.ref&&(s||o)&&(l.ref=a=>{this.ref=a}),this.reactElement=be.createElement(n,{...l}),(e=i==null?void 0:i.contentComponent)===null||e===void 0||e.setRenderer(this.id,this)}updateProps(e={}){this.props={...this.props,...e},this.render()}destroy(){var e;const n=this.editor;(e=n==null?void 0:n.contentComponent)===null||e===void 0||e.removeRenderer(this.id)}updateAttributes(e){Object.keys(e).forEach(n=>{this.element.setAttribute(n,e[n])})}}class mM extends LN{constructor(e,n,r){if(super(e,n,r),!this.node.isLeaf){this.options.contentDOMElementTag?this.contentDOMElement=document.createElement(this.options.contentDOMElementTag):this.contentDOMElement=document.createElement(this.node.isInline?"span":"div"),this.contentDOMElement.dataset.nodeViewContentReact="",this.contentDOMElement.dataset.nodeViewWrapper="",this.contentDOMElement.style.whiteSpace="inherit";const i=this.dom.querySelector("[data-node-view-content]");if(!i)return;i.appendChild(this.contentDOMElement)}}mount(){const e={editor:this.editor,node:this.node,decorations:this.decorations,innerDecorations:this.innerDecorations,view:this.view,selected:!1,extension:this.extension,HTMLAttributes:this.HTMLAttributes,getPos:()=>this.getPos(),updateAttributes:(u={})=>this.updateAttributes(u),deleteNode:()=>this.deleteNode(),ref:k.createRef()};if(!this.component.displayName){const u=c=>c.charAt(0).toUpperCase()+c.substring(1);this.component.displayName=u(this.extension.name)}const i={onDragStart:this.onDragStart.bind(this),nodeViewContentRef:u=>{u&&this.contentDOMElement&&u.firstChild!==this.contentDOMElement&&(u.hasAttribute("data-node-view-wrapper")&&u.removeAttribute("data-node-view-wrapper"),u.appendChild(this.contentDOMElement))}},s=this.component,o=k.memo(u=>be.createElement(Y0.Provider,{value:i},k.createElement(s,u)));o.displayName="ReactNodeView";let l=this.node.isInline?"span":"div";this.options.as&&(l=this.options.as);const{className:a=""}=this.options;this.handleSelectionUpdate=this.handleSelectionUpdate.bind(this),this.renderer=new pM(o,{editor:this.editor,props:e,as:l,className:`node-${this.node.type.name} ${a}`.trim()}),this.editor.on("selectionUpdate",this.handleSelectionUpdate),this.updateElementAttributes()}get dom(){var e;if(this.renderer.element.firstElementChild&&!(!((e=this.renderer.element.firstElementChild)===null||e===void 0)&&e.hasAttribute("data-node-view-wrapper")))throw Error("Please use the NodeViewWrapper component for your node view.");return this.renderer.element}get contentDOM(){return this.node.isLeaf?null:this.contentDOMElement}handleSelectionUpdate(){const{from:e,to:n}=this.editor.state.selection,r=this.getPos();if(typeof r=="number")if(e<=r&&n>=r+this.node.nodeSize){if(this.renderer.props.selected)return;this.selectNode()}else{if(!this.renderer.props.selected)return;this.deselectNode()}}update(e,n,r){const i=s=>{this.renderer.updateProps(s),typeof this.options.attrs=="function"&&this.updateElementAttributes()};if(e.type!==this.node.type)return!1;if(typeof this.options.update=="function"){const s=this.node,o=this.decorations,l=this.innerDecorations;return this.node=e,this.decorations=n,this.innerDecorations=r,this.options.update({oldNode:s,oldDecorations:o,newNode:e,newDecorations:n,oldInnerDecorations:l,innerDecorations:r,updateProps:()=>i({node:e,decorations:n,innerDecorations:r})})}return e===this.node&&this.decorations===n&&this.innerDecorations===r||(this.node=e,this.decorations=n,this.innerDecorations=r,i({node:e,decorations:n,innerDecorations:r})),!0}selectNode(){this.renderer.updateProps({selected:!0}),this.renderer.element.classList.add("ProseMirror-selectednode")}deselectNode(){this.renderer.updateProps({selected:!1}),this.renderer.element.classList.remove("ProseMirror-selectednode")}destroy(){this.renderer.destroy(),this.editor.off("selectionUpdate",this.handleSelectionUpdate),this.contentDOMElement=null}updateElementAttributes(){if(this.options.attrs){let e={};if(typeof this.options.attrs=="function"){const n=this.editor.extensionManager.attributes,r=fl(this.node,n);e=this.options.attrs({node:this.node,HTMLAttributes:r})}else e=this.options.attrs;this.renderer.updateAttributes(e)}}}function X0(t,e){return n=>n.editor.contentComponent?new mM(t,n,e):{}}const Z0=Pe.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new Ke({key:new Mt("placeholder"),props:{decorations:({doc:t,selection:e})=>{const n=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:r}=e,i=[];if(!n)return null;const s=this.editor.isEmpty;return t.descendants((o,l)=>{const a=r>=l&&r<=l+o.nodeSize,u=!o.isLeaf&&ql(o);if((a||!this.options.showOnlyCurrent)&&u){const c=[this.options.emptyNodeClass];s&&c.push(this.options.emptyEditorClass);const d=ct.node(l,l+o.nodeSize,{class:c.join(" "),"data-placeholder":typeof this.options.placeholder=="function"?this.options.placeholder({editor:this.editor,node:o,pos:l,hasAnchor:a}):this.options.placeholder});i.push(d)}return this.options.includeChildren}),ge.create(t,i)}}})]}}),gM=Pe.create({name:"characterCount",addOptions(){return{limit:null,mode:"textSize",textCounter:t=>t.length,wordCounter:t=>t.split(" ").filter(e=>e!=="").length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=t=>{const e=(t==null?void 0:t.node)||this.editor.state.doc;if(((t==null?void 0:t.mode)||this.options.mode)==="textSize"){const r=e.textBetween(0,e.content.size,void 0," ");return this.options.textCounter(r)}return e.nodeSize},this.storage.words=t=>{const e=(t==null?void 0:t.node)||this.editor.state.doc,n=e.textBetween(0,e.content.size," "," ");return this.options.wordCounter(n)}},addProseMirrorPlugins(){let t=!1;return[new Ke({key:new Mt("characterCount"),appendTransaction:(e,n,r)=>{if(t)return;const i=this.options.limit;if(i==null||i===0){t=!0;return}const s=this.storage.characters({node:r.doc});if(s>i){const o=s-i,l=0,a=o;console.warn(`[CharacterCount] Initial content exceeded limit of ${i} characters. Content was automatically trimmed.`);const u=r.tr.deleteRange(l,a);return t=!0,u}t=!0},filterTransaction:(e,n)=>{const r=this.options.limit;if(!e.docChanged||r===0||r===null||r===void 0)return!0;const i=this.storage.characters({node:n.doc}),s=this.storage.characters({node:e.doc});if(s<=r||i>r&&s>r&&s<=i)return!0;if(i>r&&s>r&&s>i||!e.getMeta("paste"))return!1;const l=e.selection.$head.pos,a=s-r,u=l-a,c=l;return e.deleteRange(u,c),!(this.storage.characters({node:e.doc})>r)}})]}});function yM(t,e,n){const r=[],i=[];return t.nodesBetween(e,n,(s,o)=>{if(s.isText){for(let l=0;l=e&&a0&&r[r.length-1]!==` +`&&(r.push(` +`),i.push(null))}),{text:r.join(""),posMap:i}}function vM(t,e,n){if(n<0||n>=t.length||!/\w/.test(t[n]))return{pmFrom:null,pmTo:null};let r=n;for(;r>0&&/\w/.test(t[r-1]);)r--;let i=n;for(;ir&&!/\w/.test(t[i-1]);)i--;let s=null,o=null;for(let l=r;llocalStorage.getItem("sw-tts-voice")||""),[g,v]=k.useState(()=>parseFloat(localStorage.getItem("sw-tts-rate")||"1")),[S,w]=k.useState(!1),E=k.useCallback(()=>{var $;const A=(($=window.speechSynthesis)==null?void 0:$.getVoices())??[];A.length&&(p(A),x(ee=>{if(ee&&A.find(pe=>pe.voiceURI===ee))return ee;const he=A.find(pe=>!pe.name.toLowerCase().includes("espeak")&&pe.lang.startsWith("en"))||A.find(pe=>pe.lang.startsWith("en"))||A[0];return he?he.voiceURI:""}))},[]);k.useEffect(()=>(E(),window.speechSynthesis.addEventListener("voiceschanged",E),()=>window.speechSynthesis.removeEventListener("voiceschanged",E)),[E]),k.useEffect(()=>{localStorage.setItem("sw-tts-voice",m)},[m]),k.useEffect(()=>{localStorage.setItem("sw-tts-rate",g)},[g]);const b=k.useRef(m),C=k.useRef(g);k.useEffect(()=>{b.current=m},[m]),k.useEffect(()=>{C.current=g},[g]);const[M,_]=k.useState(!1),N=k.useRef(!1),T=k.useRef(null);k.useEffect(()=>{N.current=M},[M]),k.useEffect(()=>()=>document.documentElement.classList.remove("typewriter"),[]),k.useEffect(()=>{if(!t)return;function A(){N.current&&(T.current&&cancelAnimationFrame(T.current),T.current=requestAnimationFrame(()=>{try{const $=t.view.coordsAtPos(t.state.selection.$head.pos),ee=Math.round($.top-window.innerHeight*.5);Math.abs(ee)>2&&window.scrollBy(0,ee)}catch{}}))}return t.on("update",A),t.on("selectionUpdate",A),()=>{t.off("update",A),t.off("selectionUpdate",A),T.current&&cancelAnimationFrame(T.current)}},[t]);function V(){const A=!M;_(A),N.current=A,document.documentElement.classList.toggle("typewriter",A),A&&requestAnimationFrame(()=>{try{const $=t.view.coordsAtPos(t.state.selection.$head.pos);window.scrollBy(0,Math.round($.top-window.innerHeight*.5))}catch{}})}function G(){if(!("speechSynthesis"in window))return;const{from:A}=t.state.selection,$=t.state.doc.content.size,{text:ee,posMap:he}=yM(t.state.doc,A,$),pe=[];let et;const fn=/[^.!?…]+[.!?…]*['"'"]?\s*/g;for(;(et=fn.exec(ee))!==null;)et[0].trim()&&pe.push({text:et[0],startOffset:et.index});if(!pe.length)if(ee.trim())pe.push({text:ee,startOffset:0});else return;speechSynthesis.cancel(),f.current=!0,d(!0);const _s=window.speechSynthesis.getVoices().find(hn=>hn.voiceURI===b.current);let $s=0;function ki(){if(!f.current||$s>=pe.length){f.current=!1,d(!1),a==null||a();return}const hn=pe[$s++],qt=new SpeechSynthesisUtterance(hn.text);_s&&(qt.voice=_s),qt.rate=C.current,qt.onstart=()=>{const{pmFrom:Tt,pmTo:wi}=xM(ee,he,hn);Tt!==null&&(l==null||l(Tt,wi),requestAnimationFrame(()=>{var Yn;(Yn=t.view.dom.querySelector(".reading-word"))==null||Yn.scrollIntoView({behavior:"smooth",block:"center"})}))},qt.onboundary=Tt=>{if(Tt.name==="sentence")return;const wi=hn.startOffset+(Tt.charIndex??0),{pmFrom:Yn,pmTo:B}=vM(ee,he,wi);Yn!==null&&(l==null||l(Yn,B),requestAnimationFrame(()=>{var te;(te=t.view.dom.querySelector(".reading-word"))==null||te.scrollIntoView({behavior:"smooth",block:"center"})}))},qt.onend=ki,qt.onerror=Tt=>{Tt.error!=="interrupted"&&(f.current=!1,d(!1),a==null||a())},speechSynthesis.speak(qt)}ki()}function Y(){f.current=!1,d(!1),speechSynthesis.cancel(),a==null||a()}if(!t)return null;const ke=()=>y.jsxs("svg",{width:"13",height:"11",viewBox:"0 0 13 11",fill:"currentColor","aria-hidden":"true",children:[y.jsx("rect",{x:"0",y:"0",width:"13",height:"1.8"}),y.jsx("rect",{x:"0",y:"3.1",width:"9",height:"1.8"}),y.jsx("rect",{x:"0",y:"6.2",width:"11",height:"1.8"}),y.jsx("rect",{x:"0",y:"9.3",width:"7",height:"1.8"})]}),X=()=>y.jsxs("svg",{width:"13",height:"11",viewBox:"0 0 13 11",fill:"currentColor","aria-hidden":"true",children:[y.jsx("rect",{x:"0",y:"0",width:"13",height:"1.8"}),y.jsx("rect",{x:"2",y:"3.1",width:"9",height:"1.8"}),y.jsx("rect",{x:"1",y:"6.2",width:"11",height:"1.8"}),y.jsx("rect",{x:"3",y:"9.3",width:"7",height:"1.8"})]}),U=()=>y.jsxs("svg",{width:"13",height:"11",viewBox:"0 0 13 11",fill:"currentColor","aria-hidden":"true",children:[y.jsx("rect",{x:"0",y:"0",width:"13",height:"1.8"}),y.jsx("rect",{x:"4",y:"3.1",width:"9",height:"1.8"}),y.jsx("rect",{x:"2",y:"6.2",width:"11",height:"1.8"}),y.jsx("rect",{x:"6",y:"9.3",width:"7",height:"1.8"})]}),D=()=>y.jsxs("svg",{width:"13",height:"11",viewBox:"0 0 13 11",fill:"currentColor","aria-hidden":"true",children:[y.jsx("rect",{x:"0",y:"0",width:"13",height:"1.8"}),y.jsx("rect",{x:"0",y:"3.1",width:"13",height:"1.8"}),y.jsx("rect",{x:"0",y:"6.2",width:"13",height:"1.8"}),y.jsx("rect",{x:"0",y:"9.3",width:"9",height:"1.8"})]});async function j(A){const $=A.target.files[0];if($){A.target.value="";try{const ee=await e($);t.chain().focus().setImage({src:ee}).run()}catch{alert("Image upload failed. Try again.")}}}function z(A,$,ee,he){return y.jsx("button",{className:`toolbar-btn${ee?" active":""}`,onMouseDown:pe=>{pe.preventDefault(),$()},title:he||A,children:A},A)}return y.jsxs("div",{className:"toolbar",role:"toolbar","aria-label":"Formatting",children:[z("Ch.",()=>t.chain().focus().toggleHeading({level:1}).run(),t.isActive("heading",{level:1}),"Chapter heading"),z("H2",()=>t.chain().focus().toggleHeading({level:2}).run(),t.isActive("heading",{level:2}),"Section heading"),z("H3",()=>t.chain().focus().toggleHeading({level:3}).run(),t.isActive("heading",{level:3}),"Sub-heading"),y.jsx("span",{className:"toolbar-sep"}),z("B",()=>t.chain().focus().toggleBold().run(),t.isActive("bold"),"Bold (Ctrl+B)"),z("I",()=>t.chain().focus().toggleItalic().run(),t.isActive("italic"),"Italic (Ctrl+I)"),z("U",()=>t.chain().focus().toggleUnderline().run(),t.isActive("underline"),"Underline (Ctrl+U)"),z(y.jsx("s",{children:"S"}),()=>t.chain().focus().toggleStrike().run(),t.isActive("strike"),"Strikethrough"),y.jsx("span",{className:"toolbar-sep"}),[{Icon:ke,align:"left",label:"Align left"},{Icon:X,align:"center",label:"Align centre"},{Icon:U,align:"right",label:"Align right"},{Icon:D,align:"justify",label:"Justify"}].map(({Icon:A,align:$,label:ee})=>y.jsx("button",{className:`toolbar-btn${t.isActive({textAlign:$})?" active":""}`,onMouseDown:he=>{he.preventDefault(),t.chain().focus().setTextAlign($).run()},title:ee,children:y.jsx(A,{})},$)),y.jsx("span",{className:"toolbar-sep"}),z("•—",()=>t.chain().focus().toggleBulletList().run(),t.isActive("bulletList"),"Bullet list"),z("1.",()=>t.chain().focus().toggleOrderedList().run(),t.isActive("orderedList"),"Numbered list"),z('"…"',()=>t.chain().focus().toggleBlockquote().run(),t.isActive("blockquote"),"Quote block"),y.jsx("button",{className:"toolbar-btn",onMouseDown:A=>{A.preventDefault(),t.chain().focus().setHorizontalRule().run()},title:"Scene break (✦ ✦ ✦)",children:"✦"}),y.jsx("span",{className:"toolbar-sep"}),y.jsx("button",{className:"toolbar-btn",onMouseDown:A=>{A.preventDefault(),u.current.click()},title:"Insert photo",children:"Photo"}),y.jsx("input",{ref:u,type:"file",accept:"image/*",onChange:j,style:{display:"none"}}),y.jsx("span",{className:"toolbar-sep"}),["#fef08a","#fda4af","#93c5fd","#86efac"].map(A=>y.jsx("button",{className:`toolbar-btn highlight-swatch${t.isActive("highlight",{color:A})?" active":""}`,style:{"--swatch":A},onMouseDown:$=>{$.preventDefault(),t.chain().focus().toggleHighlight({color:A}).run()},title:"Highlight"},A)),y.jsx("span",{className:"toolbar-sep"}),y.jsx("button",{className:"toolbar-btn font-btn",onMouseDown:A=>{A.preventDefault(),r(-1)},title:"Smaller text",children:"A−"}),y.jsxs("span",{className:"toolbar-font-size",children:[n,"px"]}),y.jsx("button",{className:"toolbar-btn font-btn",onMouseDown:A=>{A.preventDefault(),r(1)},title:"Larger text",children:"A+"}),y.jsx("span",{className:"toolbar-sep"}),y.jsx("button",{className:`toolbar-btn${M?" active":""}`,onMouseDown:A=>{A.preventDefault(),V()},title:"Typewriter mode — keeps cursor centred on screen",children:"⌨"}),i&&y.jsx("button",{className:`toolbar-btn lint-btn${s==="done"&&o===0?" lint-clean":s==="done"&&o>0?" lint-errors":s==="stale"?" lint-stale":""}`,onMouseDown:A=>{A.preventDefault(),i()},disabled:s==="checking",title:s==="checking"?"Checking…":s==="done"&&o===0?"No issues found — click to re-check":s==="done"?`${o} issue${o!==1?"s":""} — click to re-check`:s==="stale"?"Text changed — click to re-check":"Check spelling & grammar",children:s==="checking"?"…":s==="done"&&o===0?"✓":s==="done"?`${o}`:s==="stale"?"ABC*":"ABC"}),y.jsxs("div",{className:"tts-settings-wrap",children:[y.jsx("button",{className:`toolbar-btn${S?" active":""}`,onMouseDown:A=>{A.preventDefault(),w($=>!$)},title:"Read-aloud settings (voice & speed)",children:"⚙"}),S&&y.jsxs("div",{className:"tts-menu",children:[y.jsx("label",{className:"tts-label",children:"Voice"}),y.jsxs("select",{className:"tts-select",value:m,onChange:A=>x(A.target.value),children:[h.length===0&&y.jsx("option",{value:"",children:"Loading…"}),h.map(A=>y.jsxs("option",{value:A.voiceURI,children:[A.name,A.localService?"":" ☁"]},A.voiceURI))]}),y.jsxs("label",{className:"tts-label",children:["Speed — ",g.toFixed(1),"×"]}),y.jsx("input",{type:"range",min:"0.5",max:"2",step:"0.1",value:g,onChange:A=>v(parseFloat(A.target.value)),className:"tts-slider"})]})]}),y.jsx("button",{className:`toolbar-btn read-aloud-btn${c?" reading-active":""}`,onMouseDown:A=>{A.preventDefault(),c?Y():G()},title:c?"Stop reading":"Read aloud from cursor (reads to end of story)",children:c?"⏹":"🔊"})]})}const kM=["25%","50%","75%","100%"];function ev({node:t,updateAttributes:e,deleteNode:n,selected:r}){const{src:i,alt:s,width:o="100%",align:l="center"}=t.attrs,a={width:o,display:"block",marginLeft:l==="left"?"0":"auto",marginRight:l==="right"?"0":"auto"};return y.jsxs(cM,{className:"image-view-wrap",children:[y.jsx("img",{src:i,alt:s||"",style:a,draggable:"false"}),r&&y.jsxs("div",{className:"image-controls",contentEditable:!1,children:[y.jsx("div",{className:"image-ctrl-group",children:kM.map(u=>y.jsx("button",{className:`img-ctrl-btn${o===u?" active":""}`,onMouseDown:c=>{c.preventDefault(),e({width:u})},children:u},u))}),y.jsx("span",{className:"image-ctrl-sep"}),y.jsx("div",{className:"image-ctrl-group",children:[["left","←"],["center","↔"],["right","→"]].map(([u,c])=>y.jsx("button",{className:`img-ctrl-btn${l===u?" active":""}`,onMouseDown:d=>{d.preventDefault(),e({align:u})},children:c},u))}),y.jsx("span",{className:"image-ctrl-sep"}),y.jsx("button",{className:"img-ctrl-btn img-ctrl-delete",onMouseDown:u=>{u.preventDefault(),n()},title:"Remove image",children:"🗑"})]})]})}const wM=Id.extend({addAttributes(){var t;return{...(t=this.parent)==null?void 0:t.call(this),width:{default:"100%"},align:{default:"center"}}},addNodeView(){return X0(ev)}}).configure({allowBase64:!1,inline:!1}),CM=bt.create({name:"readingWord",inclusive:!1,parseHTML(){return[]},renderHTML({HTMLAttributes:t}){return["span",Se({class:"reading-word"},t),0]}}),EM=bt.create({name:"lintError",inclusive:!1,addAttributes(){return{kind:{default:"grammar"},message:{default:""},replacements:{default:[],parseHTML:t=>JSON.parse(t.getAttribute("data-r")||"[]"),renderHTML:t=>({"data-r":JSON.stringify(t.replacements??[])})}}},parseHTML(){return[]},renderHTML({HTMLAttributes:t}){return["span",Se({"data-lint":"",class:`lint-mark lint-mark--${t.kind}`},t),0]}});function NM(t){const e=[],n=[];return t.descendants((r,i)=>{if(r.isText){for(let s=0;s0&&e[e.length-1]!==` +`&&(e.push(` +`),n.push(null))}),{text:e.join(""),posMap:n}}function xp(t){const{tr:e,doc:n,schema:r}=t.state,i=r.marks.lintError;i&&(n.descendants((s,o)=>{s.isText&&s.marks.filter(l=>l.type===i).forEach(()=>e.removeMark(o,o+s.nodeSize,i))}),t.view.dispatch(e))}function tv(t){if(!t)return t;const e={...t};return e.marks&&(e.marks=e.marks.filter(n=>n.type!=="lintError"&&n.type!=="readingWord"),e.marks.length||delete e.marks),e.content&&(e.content=e.content.map(tv)),e}const bM=k.forwardRef(function({content:e,onChange:n,onImageUpload:r,fontSize:i,onFontSizeChange:s},o){const l=k.useRef(!1),[a,u]=k.useState("idle"),[c,d]=k.useState(0),[f,h]=k.useState(null),p=k.useRef("idle"),m=k.useRef(null),x=k.useRef(null),g=k.useRef(!1),v=Q0({extensions:[Pd,Ad,wM,EM,CM,Z0.configure({placeholder:"Begin your story here…"}),gM,U0.configure({types:["heading","paragraph"]}),H0.configure({multicolor:!0})],content:"",onUpdate({editor:N}){g.current||(n(tv(N.getJSON())),clearTimeout(m.current),m.current=setTimeout(()=>{var T;return(T=x.current)==null?void 0:T.call(x)},3e3))}});k.useImperativeHandle(o,()=>({insertPrompt:N=>{v&&v.chain().focus().insertContent({type:"blockquote",content:[{type:"paragraph",content:[{type:"text",text:N}]}]}).run()}})),k.useEffect(()=>{v&&!l.current&&(e&&Object.keys(e).length>0&&v.commands.setContent(e,!1),l.current=!0)},[v,e]);const S=k.useCallback(async()=>{if(!(!v||p.current==="checking")){p.current="checking",u("checking");try{const{text:N,posMap:T}=NM(v.state.doc);if(!N.trim()){g.current=!0,xp(v),g.current=!1,d(0),u("done"),p.current="done";return}const V=await ie.lintCheck(N);g.current=!0,xp(v);const{tr:G,schema:Y}=v.state,ke=Y.marks.lintError;for(const X of V.matches){let U=null,D=null;for(let j=X.offset;j{x.current=S},[S]),k.useEffect(()=>()=>clearTimeout(m.current),[]);const w=k.useCallback((N,T)=>{if(!v)return;const V=v.state.schema.marks.readingWord;if(!V)return;const{tr:G}=v.state;v.state.doc.descendants((Y,ke)=>{Y.isText&&Y.marks.filter(X=>X.type===V).forEach(()=>G.removeMark(ke,ke+Y.nodeSize,V))}),G.addMark(N,T,V.create()),g.current=!0,v.view.dispatch(G),g.current=!1},[v]),E=k.useCallback(()=>{if(!v)return;const N=v.state.schema.marks.readingWord;if(!N)return;const{tr:T}=v.state;v.state.doc.descendants((V,G)=>{V.isText&&V.marks.filter(Y=>Y.type===N).forEach(()=>T.removeMark(G,G+V.nodeSize,N))}),g.current=!0,v.view.dispatch(T),g.current=!1},[v]);function b(N){if(!v)return;const T=N.target.closest("[data-lint]");if(!T){h(null);return}const V=v.view.posAtCoords({left:N.clientX,top:N.clientY});if(!V)return;const G=v.state.doc.resolve(V.pos),Y=v.state.schema.marks.lintError,ke=G.marks().find(D=>D.type===Y);if(!ke)return;const X=Kl(G,Y);if(!X)return;const U=T.getBoundingClientRect();h({top:U.bottom+8,left:Math.max(8,Math.min(U.left,window.innerWidth-270)),message:ke.attrs.message,replacements:ke.attrs.replacements||[],from:X.from,to:X.to})}function C(N){if(!f||!v)return;const{from:T,to:V}=f;v.chain().setTextSelection({from:T,to:V}).insertContent(N).focus().run(),h(null),setTimeout(S,600)}function M(){if(!f||!v)return;const{from:N,to:T}=f,{tr:V,schema:G}=v.state;V.removeMark(N,T,G.marks.lintError),v.view.dispatch(V),h(null),d(Y=>Math.max(0,Y-1))}const _=(v==null?void 0:v.storage.characterCount.words())??0;return y.jsxs("div",{className:"editor-outer",style:{"--editor-font-size":(i||17)+"px"},children:[y.jsx(SM,{editor:v,onImageUpload:r,fontSize:i,onFontSizeChange:s,onLint:S,lintStatus:a,lintCount:c,applyReadingMark:w,clearReadingMark:E}),y.jsxs("div",{className:"editor-wrap",onClick:b,children:[y.jsx(q0,{editor:v,className:"editor-body",spellCheck:!1}),y.jsxs("div",{className:"word-count",children:[_.toLocaleString()," ",_===1?"word":"words"]})]}),f&&Pl.createPortal(y.jsxs("div",{className:"lint-popover",style:{top:f.top,left:f.left},onMouseDown:N=>N.preventDefault(),onClick:N=>N.stopPropagation(),children:[y.jsx("p",{className:"lint-popover-msg",children:f.message}),f.replacements.length>0&&y.jsx("div",{className:"lint-suggestions",children:f.replacements.map((N,T)=>y.jsx("button",{className:"lint-suggestion",onClick:()=>C(N),children:N},T))}),y.jsxs("div",{className:"lint-popover-actions",children:[y.jsx("button",{className:"btn btn-ghost lint-ignore",onClick:M,children:"Ignore"}),y.jsx("button",{className:"btn btn-ghost lint-close",onClick:()=>h(null),children:"✕"})]})]}),document.body)]})});function MM(t){var n;const e=[];for(const r of(t==null?void 0:t.content)||[])r.type==="heading"&&((n=r.attrs)==null?void 0:n.level)===1&&e.push((r.content||[]).map(i=>i.text||"").join("")||"Untitled Chapter");return e}function TM({content:t,open:e,onClose:n}){const r=k.useMemo(()=>MM(t),[t]),i=k.useRef();k.useEffect(()=>{if(!e)return;function o(l){l.key==="Escape"&&n()}return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[e,n]);function s(o){const l=document.querySelectorAll(".editor-body h1");l[o]&&(l[o].scrollIntoView({behavior:"smooth",block:"start"}),window.innerWidth<768&&n())}return y.jsxs(y.Fragment,{children:[e&&y.jsx("div",{className:"panel-backdrop",onClick:n}),y.jsxs("aside",{className:`chapter-panel${e?" open":""}`,ref:i,"aria-label":"Chapters",children:[y.jsxs("div",{className:"chapter-panel-header",children:[y.jsx("span",{className:"chapter-panel-title",children:"Chapters"}),y.jsx("button",{className:"chapter-panel-close",onClick:n,"aria-label":"Close",children:"×"})]}),r.length===0?y.jsxs("p",{className:"chapter-panel-empty",children:["Use the ",y.jsx("strong",{children:"Ch."})," button to add chapter headings and they'll appear here."]}):y.jsx("ol",{className:"chapter-list",children:r.map((o,l)=>y.jsx("li",{children:y.jsxs("button",{className:"chapter-btn",onClick:()=>s(l),children:[y.jsxs("span",{className:"chapter-num",children:["Ch. ",l+1]}),y.jsx("span",{className:"chapter-name",children:o})]})},l))})]})]})}const OM=Id.extend({addAttributes(){var t;return{...(t=this.parent)==null?void 0:t.call(this),width:{default:"100%"},align:{default:"center"}}},addNodeView(){return X0(ev)}}).configure({allowBase64:!1,inline:!1});function DM({content:t,onChange:e,onImageUpload:n}){const r=k.useRef(!1),i=k.useRef(),s=Q0({extensions:[Pd,Ad,OM,Z0.configure({placeholder:"Write your note here…"})],content:"",onUpdate({editor:a}){e(a.getJSON())}});k.useEffect(()=>{s&&!r.current&&(t&&Object.keys(t).length>0&&s.commands.setContent(t,!1),r.current=!0)},[s,t]);async function o(a){const u=a.target.files[0];if(u){a.target.value="";try{const c=await n(u);s.chain().focus().setImage({src:c}).run()}catch{alert("Image upload failed. Try again.")}}}function l(a,u,c,d){return y.jsx("button",{className:`toolbar-btn${c?" active":""}`,onMouseDown:f=>{f.preventDefault(),u()},title:d||String(a),children:a},String(a))}return s?y.jsxs("div",{className:"note-editor-outer",children:[y.jsxs("div",{className:"note-toolbar",role:"toolbar","aria-label":"Note formatting",children:[l("B",()=>s.chain().focus().toggleBold().run(),s.isActive("bold"),"Bold (Ctrl+B)"),l("I",()=>s.chain().focus().toggleItalic().run(),s.isActive("italic"),"Italic (Ctrl+I)"),l("U",()=>s.chain().focus().toggleUnderline().run(),s.isActive("underline"),"Underline (Ctrl+U)"),y.jsx("span",{className:"toolbar-sep"}),l("H2",()=>s.chain().focus().toggleHeading({level:2}).run(),s.isActive("heading",{level:2}),"Heading"),l("H3",()=>s.chain().focus().toggleHeading({level:3}).run(),s.isActive("heading",{level:3}),"Sub-heading"),y.jsx("span",{className:"toolbar-sep"}),l("•—",()=>s.chain().focus().toggleBulletList().run(),s.isActive("bulletList"),"Bullet list"),l('"…"',()=>s.chain().focus().toggleBlockquote().run(),s.isActive("blockquote"),"Quote block"),y.jsx("span",{className:"toolbar-sep"}),y.jsx("button",{className:"toolbar-btn",onMouseDown:a=>{a.preventDefault(),i.current.click()},title:"Insert image",children:"Photo"}),y.jsx("input",{ref:i,type:"file",accept:"image/*",onChange:o,style:{display:"none"}})]}),y.jsx("div",{className:"note-editor-wrap",children:y.jsx(q0,{editor:s,className:"note-editor-body"})})]}):null}function PM(t){return t?new Date(t).toLocaleDateString(void 0,{month:"short",day:"numeric"}):""}function AM(t){function e(r){return(r||[]).flatMap(i=>i.text?[i.text]:e(i.content))}const n=e((t==null?void 0:t.content)||[]).join(" ").trim();return n?n.slice(0,90)+(n.length>90?"…":""):"No content yet"}function IM({storyId:t,open:e,onClose:n}){const r=od(),i=ld(),[s,o]=k.useState([]),[l,a]=k.useState(!1),[u,c]=k.useState(null),[d,f]=k.useState(""),h=k.useRef(""),p=k.useRef({}),m=k.useRef(null),x=k.useRef(null);k.useEffect(()=>{e&&!l&&ie.getNotes(t).then(T=>{o(T),a(!0)}).catch(()=>r("Could not load notes","error"))},[e,l,t,r]),k.useEffect(()=>{if(!e)return;function T(V){V.key==="Escape"&&(V.stopPropagation(),u?(S(u.id),c(null)):n())}return document.addEventListener("keydown",T,!0),()=>document.removeEventListener("keydown",T,!0)},[e,u,n]);const g=k.useCallback(async T=>{if(T)try{const V=await ie.updateNote(t,T,{title:h.current,content:p.current});o(G=>G.map(Y=>Y.id===T?V:Y))}catch{r("Could not save note","error")}},[t,r]);function v(T){clearTimeout(m.current),m.current=setTimeout(()=>g(T),1500)}function S(T){clearTimeout(m.current),g(T)}k.useEffect(()=>()=>clearTimeout(m.current),[]);function w(T){x.current&&x.current!==T.id&&S(x.current),x.current=T.id,h.current=T.title,p.current=T.content||{},f(T.title),c(T)}async function E(){try{const T=await ie.createNote(t);o(V=>[T,...V]),w(T)}catch{r("Could not create note","error")}}function b(T){h.current=T.target.value,f(T.target.value),v(u.id)}function C(T){p.current=T,v(u.id)}function M(){S(u.id),x.current=null,c(null)}async function _(){if(await i(`Delete "${u.title||"this note"}"?`,{confirmLabel:"Delete",danger:!0}))try{clearTimeout(m.current),await ie.deleteNote(t,u.id),o(V=>V.filter(G=>G.id!==u.id)),x.current=null,c(null)}catch{r("Could not delete note","error")}}function N(){u&&S(u.id),n()}return y.jsxs(y.Fragment,{children:[e&&y.jsx("div",{className:"panel-backdrop",onClick:N}),y.jsx("aside",{className:`notes-panel${e?" open":""}`,"aria-label":"Notes",children:u?y.jsxs("div",{className:"note-edit-view",children:[y.jsxs("div",{className:"notes-panel-header",children:[y.jsx("button",{className:"note-back-btn btn btn-ghost",onClick:M,children:"← Notes"}),y.jsx("button",{className:"chapter-panel-close",onClick:N,"aria-label":"Close",children:"×"})]}),y.jsx("input",{className:"note-title-input",value:d,onChange:b,placeholder:"Note title…"}),y.jsx("div",{className:"note-editor-scroll",children:y.jsx(DM,{content:u.content,onChange:C,onImageUpload:ie.uploadImage},u.id)}),y.jsx("div",{className:"note-edit-footer",children:y.jsx("button",{className:"btn btn-ghost note-delete-btn",onClick:_,children:"Delete note"})})]}):y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"notes-panel-header",children:[y.jsx("span",{className:"notes-panel-title",children:"Notes"}),y.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[y.jsx("button",{className:"note-new-btn btn btn-ghost",onClick:E,title:"New note",children:"+ New"}),y.jsx("button",{className:"chapter-panel-close",onClick:N,"aria-label":"Close",children:"×"})]})]}),l?s.length===0?y.jsxs("div",{className:"notes-empty",children:[y.jsx("p",{className:"notes-empty-msg",children:"No notes yet."}),y.jsx("button",{className:"btn btn-primary notes-empty-cta",onClick:E,children:"+ Create first note"})]}):y.jsx("ol",{className:"notes-list",children:s.map(T=>y.jsx("li",{children:y.jsxs("button",{className:"note-item",onClick:()=>w(T),children:[y.jsx("span",{className:"note-item-title",children:T.title||"Untitled"}),y.jsx("span",{className:"note-item-snippet",children:AM(T.content)}),y.jsx("span",{className:"note-item-date",children:PM(T.updated_at)})]})},T.id))}):y.jsx("p",{className:"chapter-panel-empty",children:"Loading…"})]})})]})}const Sp=13,kp=26,RM=(()=>{const t=["A door appears in your bedroom wall overnight. It wasn't there when you went to sleep.","You find a letter in your pocket written in your own handwriting — dated next week.","The last dragon in the world lands in your garden. It is very small and very scared.","Your shadow starts leaving notes under your pillow.","Every story you write comes true — but always with one small, wrong detail.","A train arrives at your station that isn't on any timetable. The conductor says you have been expected.","You discover you have one magical power: you can always find things that are lost. Not everything that is lost wants to be found.","The stars rearrange themselves every night. Last night you finally worked out what language they're writing in.","A bookshop appears on your street that wasn't there yesterday. Inside are books about your life — including things that haven't happened yet.","Everyone in your town wakes up speaking a different language. Everyone except you.","The person chosen to save the world is seventy-three years old, very tired, and was just about to have a cup of tea.","You are the only one who can hear the sea talking. It is furious about something."];let e=[];const n=r=>[...r].sort(()=>Math.random()-.5);return{next(){return e.length||(e=n(t)),{prompt:e.pop(),source:"local",model:null}}}})();function LM(){const{id:t}=sS(),e=rd(),n=od(),r=ld(),[i,s]=k.useState(null),[o,l]=k.useState(!1),[a,u]=k.useState(""),[c,d]=k.useState({}),[f,h]=k.useState("saved"),[p,m]=k.useState(!1),[x,g]=k.useState(!1),[v,S]=k.useState(!1),[w,E]=k.useState(!1),[b,C]=k.useState(null),[M,_]=k.useState(null),[N,T]=k.useState(null),[V,G]=k.useState(()=>Math.max(Sp,Math.min(kp,parseInt(localStorage.getItem("sw-fontsize"))||17))),Y=k.useRef(null),ke=k.useRef(""),X=k.useRef({}),U=k.useRef(0),D=k.useRef(),j=k.useRef([]),z=k.useRef([]),A=k.useRef(),$=k.useRef(null);k.useEffect(()=>{ie.getStory(t).then(B=>{s(B),u(B.title),d(B.content||{}),ke.current=B.title,X.current=B.content||{},U.current=pp(B.content)}).catch(()=>l(!0))},[t]),k.useEffect(()=>{ki()},[]),k.useEffect(()=>{localStorage.setItem("sw-fontsize",V)},[V]);const ee=k.useCallback(async()=>{h("saving");try{await ie.updateStory(t,{title:ke.current,content:X.current}),h("saved");const B=PS(),te=pp(X.current),Ot=te-U.current;Ot>0&&(IS(Ot),U.current=te);const Bt=Wb(t,te);Bt&&n(`🎉 ${Bt}`,"success"),B>1&&B%7===0&&n(`🔥 ${B} day writing streak!`,"success")}catch(B){console.error("Save failed:",B),h("error"),n("Could not save — check your connection","error")}},[t,n]);k.useEffect(()=>{$.current=ee},[ee]);function he(){h("unsaved"),clearTimeout(Y.current),Y.current=setTimeout(()=>{var B;return(B=$.current)==null?void 0:B.call($)},2e3)}k.useEffect(()=>()=>clearTimeout(Y.current),[]),k.useEffect(()=>{function B(te){var Ot;(te.ctrlKey||te.metaKey)&&te.key==="s"&&(te.preventDefault(),clearTimeout(Y.current),(Ot=$.current)==null||Ot.call($)),te.key==="Escape"&&(E(!1),m(!1),g(!1),S(!1),C(null)),(te.key==="F11"||te.altKey&&te.key==="z")&&(te.preventDefault(),E(Bt=>!Bt))}return document.addEventListener("keydown",B),()=>document.removeEventListener("keydown",B)},[]);function pe(B){ke.current=B.target.value,u(B.target.value),he()}function et(B){X.current=B,d(B),he()}function fn(B){G(te=>Math.max(Sp,Math.min(kp,te+B)))}async function _s(B){const te=B.target.files[0];if(te){B.target.value="";try{const Ot=await ie.uploadImage(te);s(Bt=>({...Bt,cover_image:Ot})),await ie.updateStory(t,{cover_image:Ot}),n("Cover image updated")}catch{n("Cover upload failed","error")}}}async function $s(){await r("Remove the cover image?",{confirmLabel:"Remove",danger:!0})&&(s(te=>({...te,cover_image:null})),await ie.updateStory(t,{cover_image:null}))}function ki(){const B=5-j.current.length-z.current.length;for(let te=0;te{j.current.push(Bt)}).catch(()=>{}).finally(()=>{z.current=z.current.filter(Bt=>Bt!==Ot)});z.current=[...z.current,Ot]}}function hn(){const B=j.current.shift()??RM.next();C(B.prompt),_(B.source??"local"),T(B.model??null),ki()}function qt(){var B;b&&((B=A.current)==null||B.insertPrompt(b),C(null),n("Prompt inserted as a quote block"))}async function Tt(B){if(S(!1),B==="pdf"){$b(ke.current||a,X.current);return}if(B==="epub"){await ie.exportEpub(t);return}B==="odt"&&await ie.exportOdt(t)}function wi(){var B;clearTimeout(Y.current),(B=$.current)==null||B.call($).finally(()=>e("/"))}if(o)return y.jsxs("div",{className:"loading",children:["Could not load story."," ",y.jsx("button",{className:"btn btn-ghost",style:{marginLeft:"1rem"},onClick:()=>e("/"),children:"Go back"})]});if(!i)return y.jsx("div",{className:"loading",children:"Opening story…"});const Yn={saved:"Saved",saving:"Saving…",unsaved:"Unsaved",error:"Error saving"};return y.jsxs("div",{className:`editor-page${w?" focus-mode":""}${p?" panel-open":""}`,children:[y.jsx(TM,{content:c,open:p,onClose:()=>m(!1)}),y.jsx(IM,{storyId:t,open:x,onClose:()=>g(!1)}),y.jsxs("div",{className:"editor-main",children:[y.jsxs("div",{className:"editor-topbar",children:[y.jsxs("div",{className:"topbar-left",children:[y.jsxs("button",{onClick:wi,className:"btn btn-ghost back-btn",children:["← ",y.jsx("span",{children:"Stories"})]}),y.jsxs("button",{className:`btn btn-ghost${p?" active":""}`,onClick:()=>m(B=>!B),title:"Toggle chapter list",children:["☰ ",y.jsx("span",{children:"Chapters"})]}),y.jsxs("button",{className:`btn btn-ghost${x?" active":""}`,onClick:()=>g(B=>!B),title:"Toggle notes",children:["✎ ",y.jsx("span",{children:"Notes"})]}),y.jsxs("button",{className:`btn btn-ghost${w?" active":""}`,onClick:()=>E(B=>!B),title:"Focus mode (F11 or Alt+Z)",children:[w?"⊠":"⊡"," ",y.jsx("span",{children:w?"Exit Focus":"Focus"})]})]}),y.jsxs("div",{className:"topbar-right",children:[y.jsxs("div",{className:"prompt-wrap",children:[y.jsxs("button",{className:"btn btn-ghost",onClick:hn,title:"Get a writing prompt",children:["💡 ",y.jsx("span",{children:"Prompt"})]}),b&&y.jsxs("div",{className:"prompt-popover",children:[M&&y.jsx("span",{className:`prompt-source-icon prompt-source--${M}`,title:M==="ollama"?`AI · ${N||"ollama"}`:"Built-in prompt",children:M==="ollama"?"🤖":"📚"}),y.jsx("p",{className:"prompt-text",children:b}),y.jsxs("div",{className:"prompt-actions",children:[y.jsx("button",{className:"btn btn-ghost",onClick:hn,children:"↻ Another"}),y.jsx("button",{className:"btn btn-primary",onClick:qt,children:"Insert"}),y.jsx("button",{className:"btn btn-ghost",onClick:()=>C(null),children:"×"})]})]})]}),y.jsx("span",{className:`save-status save-status--${f}`,children:Yn[f]}),y.jsxs("div",{className:"export-wrap",children:[y.jsxs("button",{className:"btn btn-ghost",onClick:()=>S(B=>!B),children:[y.jsx("span",{children:"Export"})," ▾"]}),v&&y.jsxs("div",{className:"export-menu",children:[y.jsx("button",{onClick:()=>Tt("pdf"),children:"PDF (print)"}),y.jsx("button",{onClick:()=>Tt("epub"),children:"EPUB (.epub)"}),y.jsx("button",{onClick:()=>Tt("odt"),children:"Open Document (.odt)"})]})]})]})]}),y.jsxs("div",{className:"editor-container",children:[y.jsxs("div",{className:"cover-area",children:[i.cover_image?y.jsxs("div",{className:"cover-preview",children:[y.jsx("img",{src:i.cover_image,alt:"Cover",className:"cover-img"}),y.jsxs("div",{className:"cover-actions",children:[y.jsx("button",{className:"btn btn-ghost cover-btn",onClick:()=>D.current.click(),children:"Change cover"}),y.jsx("button",{className:"btn btn-ghost cover-btn",onClick:$s,children:"Remove"})]})]}):y.jsx("button",{className:"cover-add",onClick:()=>D.current.click(),children:"+ Add cover image"}),y.jsx("input",{ref:D,type:"file",accept:"image/*",onChange:_s,style:{display:"none"}})]}),y.jsx("input",{className:"story-title-input",value:a,onChange:pe,placeholder:"Story title…"}),y.jsx(bM,{ref:A,content:i.content,onChange:et,onImageUpload:ie.uploadImage,fontSize:V,onFontSizeChange:fn})]})]}),w&&y.jsx("button",{className:"focus-exit",onClick:()=>E(!1),title:"Exit focus mode (Esc)",children:"Exit Focus"})]})}function jM(){const[t,e]=k.useState(""),[n,r]=k.useState(!1),[i,s]=k.useState([]),[o,l]=k.useState(""),[a,u]=k.useState({name:"",username:"",password:""}),[c,d]=k.useState(""),[f,h]=k.useState(""),[p,m]=k.useState(!1),[x,g]=k.useState(null),[v,S]=k.useState(""),[w,E]=k.useState("");async function b(N){N.preventDefault(),l("");try{const T=await ie.admin.getUsers(t);s(T),r(!0)}catch{l("Wrong password")}}async function C(N){N.preventDefault(),d(""),h(""),m(!0);try{const T=await ie.admin.createUser(t,a);s(V=>[T,...V]),u({name:"",username:"",password:""}),h(`Account created for ${T.name}!`)}catch(T){d(T.message)}finally{m(!1)}}async function M(N,T){N.preventDefault(),E("");try{await ie.admin.resetPassword(t,T,v),E("Password updated"),S(""),setTimeout(()=>{g(null),E("")},1500)}catch(V){E(V.message)}}async function _(N,T){confirm(`Delete ${T}'s account and all their stories?`)&&(await ie.admin.deleteUser(t,N),s(V=>V.filter(G=>G.id!==N)))}return n?y.jsxs("div",{className:"stories-page",children:[y.jsxs("header",{className:"stories-header",children:[y.jsx("h1",{className:"page-title",children:"Admin"}),y.jsx("a",{href:"/",className:"btn btn-ghost",children:"← Back to App"})]}),y.jsxs("div",{className:"admin-grid",children:[y.jsxs("section",{className:"admin-card",children:[y.jsx("h2",{className:"admin-section-title",children:"Add Account"}),y.jsxs("form",{onSubmit:C,className:"login-form",children:[y.jsx("input",{type:"text",placeholder:"Display name",value:a.name,onChange:N=>u(T=>({...T,name:N.target.value})),required:!0,className:"input"}),y.jsx("input",{type:"text",placeholder:"Username",value:a.username,onChange:N=>u(T=>({...T,username:N.target.value})),required:!0,className:"input",autoCapitalize:"none"}),y.jsx("input",{type:"password",placeholder:"Password",value:a.password,onChange:N=>u(T=>({...T,password:N.target.value})),required:!0,className:"input"}),c&&y.jsx("p",{className:"error-msg",children:c}),f&&y.jsx("p",{className:"success-msg",children:f}),y.jsx("button",{type:"submit",className:"btn btn-primary",disabled:p,children:p?"Creating…":"Create Account"})]})]}),y.jsxs("section",{className:"admin-card",children:[y.jsxs("h2",{className:"admin-section-title",children:["Accounts (",i.length,")"]}),i.length===0?y.jsx("p",{style:{color:"var(--text-muted)",fontStyle:"italic"},children:"No accounts yet."}):y.jsx("ul",{className:"user-list",children:i.map(N=>y.jsxs("li",{className:"user-row",style:{flexDirection:"column",alignItems:"stretch",gap:"0.5rem"},children:[y.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[y.jsxs("div",{children:[y.jsx("strong",{children:N.name}),y.jsxs("span",{className:"user-email",children:["@",N.username]})]}),y.jsxs("div",{style:{display:"flex",gap:"0.4rem"},children:[y.jsx("button",{className:"btn btn-ghost",style:{fontSize:"0.72rem",padding:"0.25rem 0.5rem"},onClick:()=>{g(x===N.id?null:N.id),S(""),E("")},children:x===N.id?"Cancel":"Reset PW"}),y.jsx("button",{className:"btn btn-ghost",style:{fontSize:"0.72rem",padding:"0.25rem 0.5rem",color:"var(--danger)",borderColor:"var(--danger)"},onClick:()=>_(N.id,N.name),children:"Delete"})]})]}),x===N.id&&y.jsxs("form",{onSubmit:T=>M(T,N.id),style:{display:"flex",gap:"0.5rem",flexWrap:"wrap"},children:[y.jsx("input",{type:"password",placeholder:"New password",value:v,onChange:T=>S(T.target.value),required:!0,minLength:6,className:"input",style:{flex:1,minWidth:0},autoFocus:!0}),y.jsx("button",{type:"submit",className:"btn btn-primary",style:{flexShrink:0},children:"Set"}),w&&y.jsx("p",{className:w==="Password updated"?"success-msg":"error-msg",style:{width:"100%",margin:0},children:w})]})]},N.id))})]})]})]}):y.jsx("div",{className:"login-page",children:y.jsxs("div",{className:"login-box",children:[y.jsx("div",{className:"login-quill",children:"🔑"}),y.jsx("h1",{className:"login-title",children:"Admin"}),y.jsx("p",{className:"login-sub",children:"Enter admin password"}),y.jsxs("form",{onSubmit:b,className:"login-form",children:[y.jsx("input",{type:"password",placeholder:"Admin password",value:t,onChange:N=>e(N.target.value),required:!0,className:"input",autoComplete:"current-password"}),o&&y.jsx("p",{className:"error-msg",children:o}),y.jsx("button",{type:"submit",className:"btn btn-primary",children:"Unlock"})]})]})})}const zM={grunge:{label:"Midnight",bg:"#09090f",accent:"#c8901a",dot:"#ddd8f2"},gothic:{label:"Gothic Night",bg:"#0f0810",accent:"#c4244e",dot:"#d4b8d8"},forest:{label:"Enchanted Forest",bg:"#080e0a",accent:"#3d9e50",dot:"#a8c4a0"},manuscript:{label:"Aged Manuscript",bg:"#f4e8d0",accent:"#8b4513",dot:"#2a1f0e"},noir:{label:"Neon Noir",bg:"#080808",accent:"#9933ff",dot:"#e0e0e0"}};function BM({theme:t,setTheme:e,themes:n}){const[r,i]=k.useState(!1);return y.jsxs("div",{className:"theme-picker",children:[y.jsx("button",{className:"theme-toggle",onClick:()=>i(s=>!s),title:"Change theme","aria-label":"Change theme","aria-expanded":r,children:"🎨"}),r&&y.jsx("div",{className:"theme-menu",role:"listbox","aria-label":"Themes",children:n.map(s=>{const{label:o,bg:l,accent:a,dot:u}=zM[s];return y.jsxs("button",{role:"option","aria-selected":t===s,className:`theme-option${t===s?" active":""}`,onClick:()=>{e(s),i(!1)},children:[y.jsx("span",{className:"theme-swatch",style:{background:l,border:`2px solid ${a}`},children:y.jsx("span",{style:{color:u},children:"Aa"})}),y.jsx("span",{className:"theme-label",children:o})]},s)})})]})}const Xi=[{id:"lora",label:"Lora",category:"Serif",family:"'Lora', Georgia, serif"},{id:"merriweather",label:"Merriweather",category:"Serif",family:"'Merriweather', Georgia, serif"},{id:"playfair",label:"Playfair Display",category:"Serif",family:"'Playfair Display', 'Palatino Linotype', serif"},{id:"garamond",label:"EB Garamond",category:"Serif",family:"'EB Garamond', 'Palatino Linotype', serif"},{id:"baskerville",label:"Libre Baskerville",category:"Serif",family:"'Libre Baskerville', Georgia, serif"},{id:"crimson",label:"Crimson Text",category:"Serif",family:"'Crimson Text', Georgia, serif"},{id:"cormorant",label:"Cormorant Garamond",category:"Serif",family:"'Cormorant Garamond', 'Palatino Linotype', serif"},{id:"pt-serif",label:"PT Serif",category:"Serif",family:"'PT Serif', Georgia, serif"},{id:"literata",label:"Literata",category:"Serif",family:"'Literata', Georgia, serif"},{id:"vollkorn",label:"Vollkorn",category:"Serif",family:"'Vollkorn', Georgia, serif"},{id:"inter",label:"Inter",category:"Sans",family:"'Inter', system-ui, sans-serif"},{id:"source-sans",label:"Source Sans 3",category:"Sans",family:"'Source Sans 3', system-ui, sans-serif"},{id:"nunito",label:"Nunito",category:"Sans",family:"'Nunito', system-ui, sans-serif"},{id:"special-elite",label:"Special Elite",category:"Typewriter",family:"'Special Elite', 'Courier New', monospace"},{id:"courier-prime",label:"Courier Prime",category:"Typewriter",family:"'Courier Prime', 'Courier New', monospace"}];function FM({fontId:t,setFont:e}){const[n,r]=k.useState(!1),i=Xi.find(s=>s.id===t)??Xi[0];return y.jsxs("div",{className:"font-picker",children:[y.jsx("button",{className:"font-toggle",onClick:()=>r(s=>!s),title:"Change writing font","aria-label":"Change writing font","aria-expanded":n,style:{fontFamily:i.family},children:"Aa"}),n&&y.jsxs("div",{className:"font-menu",role:"listbox","aria-label":"Writing fonts",children:[y.jsx("p",{className:"font-menu-label",children:"Writing font"}),Xi.map(s=>y.jsxs("button",{role:"option","aria-selected":t===s.id,className:`font-option${t===s.id?" active":""}`,onClick:()=>{e(s.id),r(!1)},children:[y.jsx("span",{className:"font-preview",style:{fontFamily:s.family},children:"Aa"}),y.jsxs("span",{className:"font-info",children:[y.jsx("span",{className:"font-name",style:{fontFamily:s.family},children:s.label}),y.jsx("span",{className:"font-category",children:s.category})]})]},s.id))]})]})}const _M=["grunge","gothic","forest","manuscript","noir"];function $M(){const[t,e]=k.useState(()=>bS()),[n,r]=k.useState(()=>localStorage.getItem("sw-theme")||"grunge"),[i,s]=k.useState(()=>localStorage.getItem("sw-font")||"lora");return k.useEffect(()=>{document.documentElement.setAttribute("data-theme",n),localStorage.setItem("sw-theme",n)},[n]),k.useEffect(()=>{const o=Xi.find(l=>l.id===i)??Xi[0];document.documentElement.style.setProperty("--font-body",o.family),localStorage.setItem("sw-font",i)},[i]),y.jsx(MS,{children:y.jsxs(TS,{children:[y.jsxs(kS,{children:[y.jsx(Rr,{path:"/login",element:t?y.jsx(so,{to:"/"}):y.jsx(OS,{onLogin:e})}),y.jsx(Rr,{path:"/admin",element:y.jsx(jM,{})}),y.jsx(Rr,{path:"/",element:t?y.jsx(zS,{onLogout:()=>e(null)}):y.jsx(so,{to:"/login"})}),y.jsx(Rr,{path:"/story/:id",element:t?y.jsx(LM,{}):y.jsx(so,{to:"/login"})}),y.jsx(Rr,{path:"*",element:y.jsx(so,{to:"/"})})]}),t&&y.jsx(BM,{theme:n,setTheme:r,themes:_M}),t&&y.jsx(FM,{fontId:i,setFont:s})]})})}Ha.createRoot(document.getElementById("root")).render(y.jsx(ES,{children:y.jsx($M,{})})); diff --git a/frontend/dist/assets/index-By0z_IQf.css b/frontend/dist/assets/index-By0z_IQf.css new file mode 100644 index 0000000..062c88a --- /dev/null +++ b/frontend/dist/assets/index-By0z_IQf.css @@ -0,0 +1 @@ +@import"https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700&family=Cormorant+Garamond:ital,wght@0,400;0,500;1,400&family=Courier+Prime:ital,wght@0,400;1,400&family=Crimson+Text:ital,wght@0,400;0,600;1,400&family=EB+Garamond:ital,wght@0,400;1,400&family=Inter:wght@400;500&family=Libre+Baskerville:ital,wght@0,400;0,700;1,400&family=Literata:ital,wght@0,400;0,500;1,400&family=Lora:ital,wght@0,400;0,500;1,400;1,500&family=Merriweather:ital,wght@0,400;0,700;1,400&family=Nunito:ital,wght@0,400;0,600;1,400&family=PT+Serif:ital,wght@0,400;1,400&family=Playfair+Display:ital,wght@0,400;0,700;1,400&family=Source+Sans+3:ital,wght@0,400;0,600;1,400&family=Special+Elite&family=Vollkorn:ital,wght@0,400;0,500;1,400&display=swap";:root,[data-theme=grunge]{--bg: #09090f;--bg-surface: #0e0e1a;--bg-raised: #151525;--text: #ddd8f2;--text-muted: #6058a0;--accent: #7c5010;--accent-hi: #c8901a;--border: #1c1c35;--danger: #8b2030;--font-head: "Cinzel", "Palatino Linotype", serif;--font-body: "Lora", Georgia, serif;--noise: .025;--radius: 5px;--topbar-h: 49px}[data-theme=gothic]{--bg: #0f0810;--bg-surface: #160d1a;--bg-raised: #1e1225;--text: #d4b8d8;--text-muted: #7a5a80;--accent: #8b1a3a;--accent-hi: #c4244e;--border: #2d1a35;--danger: #8b1a1a;--font-head: "Cinzel", "Palatino Linotype", serif;--font-body: "Lora", Georgia, serif;--noise: .03;--radius: 5px}[data-theme=forest]{--bg: #080e0a;--bg-surface: #0d1610;--bg-raised: #121f15;--text: #a8c4a0;--text-muted: #5a7858;--accent: #2d6e3a;--accent-hi: #3d9e50;--border: #1a2e1d;--danger: #6e2d2d;--font-head: "Cinzel", "Palatino Linotype", serif;--font-body: "Lora", Georgia, serif;--noise: .04;--radius: 5px}[data-theme=manuscript]{--bg: #f4e8d0;--bg-surface: #ede0c4;--bg-raised: #e8d8b4;--text: #2a1f0e;--text-muted: #6b5030;--accent: #8b4513;--accent-hi: #a0521a;--border: #c8a87a;--danger: #8b2020;--font-head: "Cinzel", "Palatino Linotype", serif;--font-body: "Lora", Georgia, serif;--noise: .07;--radius: 3px}[data-theme=noir]{--bg: #080808;--bg-surface: #0f0f0f;--bg-raised: #161616;--text: #e0e0e0;--text-muted: #606060;--accent: #6600cc;--accent-hi: #9933ff;--border: #1a1a2e;--danger: #cc0033;--font-head: "Special Elite", "Courier New", monospace;--font-body: "Special Elite", "Courier New", monospace;--noise: .02;--radius: 2px}*,*:before,*:after{box-sizing:border-box;margin:0;padding:0}html{height:100%;overflow-x:hidden}body{background:var(--bg);color:var(--text);font-family:var(--font-body);font-size:16px;line-height:1.7;min-height:100%;transition:background .3s,color .3s;-webkit-font-smoothing:antialiased}body:after{content:"";position:fixed;top:0;right:0;bottom:0;left:0;pointer-events:none;z-index:9999;opacity:var(--noise);background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)'/%3E%3C/svg%3E");background-size:200px 200px}button{cursor:pointer;font-family:inherit}.input{width:100%;padding:.75rem 1rem;background:var(--bg-raised);border:1px solid var(--border);border-radius:var(--radius);color:var(--text);font-family:var(--font-body);font-size:1rem;outline:none;transition:border-color .2s}.input:focus{border-color:var(--accent-hi)}.input::placeholder{color:var(--text-muted)}.btn{padding:.6rem 1.25rem;border-radius:var(--radius);font-family:var(--font-head);font-size:.8rem;font-weight:600;letter-spacing:.06em;text-transform:uppercase;border:1px solid transparent;transition:all .18s;white-space:nowrap}.btn-primary{background:var(--accent);color:var(--text);border-color:var(--accent-hi)}.btn-primary:hover{background:var(--accent-hi);color:var(--bg)}.btn-ghost{background:transparent;color:var(--text-muted);border-color:var(--border)}.btn-ghost:hover{color:var(--text);border-color:var(--text-muted)}.error-msg{color:var(--danger);font-size:.875rem;font-style:italic}.loading{display:flex;align-items:center;justify-content:center;min-height:100vh;color:var(--text-muted);font-family:var(--font-head);letter-spacing:.12em;font-size:.9rem}.login-page{min-height:100vh;display:flex;align-items:center;justify-content:center;padding:1rem;background:var(--bg)}.login-box{width:100%;max-width:380px;background:var(--bg-surface);border:1px solid var(--border);border-radius:calc(var(--radius) * 2);padding:3rem 2.25rem 2.5rem;text-align:center;box-shadow:0 8px 40px #00000080}.login-quill{font-size:2.5rem;margin-bottom:.5rem;line-height:1}.login-title{font-family:var(--font-head);font-size:1.9rem;letter-spacing:.18em;color:var(--accent-hi);margin-bottom:.25rem}.login-sub{color:var(--text-muted);font-size:.9rem;font-style:italic;margin-bottom:2rem}.login-form{display:flex;flex-direction:column;gap:.875rem}.stories-page{max-width:1100px;margin:0 auto;padding:1.75rem 1.25rem 5rem}.stories-header{display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:1rem;margin-bottom:2rem;padding-bottom:1rem;border-bottom:1px solid var(--border)}.page-title{font-family:var(--font-head);font-size:1.6rem;letter-spacing:.12em;color:var(--accent-hi)}.header-actions{display:flex;gap:.625rem}.stories-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:1.125rem}.empty-state{text-align:center;padding:5rem 1rem;color:var(--text-muted);display:flex;flex-direction:column;align-items:center;gap:1rem}.empty-quill{font-size:3rem;opacity:.5}.story-card{background:var(--bg-surface);border:1px solid var(--border);border-radius:var(--radius);overflow:hidden;cursor:pointer;transition:border-color .2s,transform .15s,box-shadow .2s;position:relative}.story-card:hover{border-color:var(--accent);transform:translateY(-3px);box-shadow:0 6px 20px #0006}.story-card:focus-visible{outline:2px solid var(--accent-hi);outline-offset:2px}.story-card-cover{width:100%;height:130px;object-fit:cover;display:block}.story-card-placeholder{width:100%;height:70px;background:linear-gradient(135deg,var(--bg-raised) 0%,var(--bg-surface) 100%);border-bottom:1px solid var(--border)}.story-card-body{padding:.875rem .875rem .75rem;position:relative}.story-card-title{font-family:var(--font-head);font-size:.95rem;letter-spacing:.04em;margin-bottom:.2rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;padding-right:1.5rem}.story-card-meta{font-size:.75rem;color:var(--text-muted);font-style:italic}.story-card-delete{position:absolute;top:.5rem;right:.5rem;width:22px;height:22px;background:transparent;border:none;color:var(--text-muted);font-size:1.1rem;line-height:1;border-radius:50%;display:flex;align-items:center;justify-content:center;opacity:0;transition:opacity .15s,color .15s}.story-card:hover .story-card-delete{opacity:1}.story-card-delete:hover{color:var(--danger)}.editor-page{min-height:100vh;display:flex}.editor-main{flex:1;display:flex;flex-direction:column;min-width:0;transition:margin-left .25s ease}.editor-topbar{display:flex;align-items:center;justify-content:space-between;padding:.5rem 1rem;background:var(--bg-surface);border-bottom:1px solid var(--border);position:sticky;top:0;z-index:200;gap:.5rem}.topbar-left,.topbar-right{display:flex;align-items:center;gap:.5rem}.back-btn{font-size:.75rem;padding:.4rem .875rem}.btn.active{border-color:var(--accent);color:var(--accent-hi)}.save-status{font-size:.78rem;font-style:italic;flex-shrink:0}.save-status--saved{color:var(--text-muted)}.save-status--saving{color:var(--accent-hi)}.save-status--unsaved{color:var(--text-muted)}.save-status--error{color:var(--danger)}.editor-container{max-width:860px;width:100%;margin:0 auto;padding:1.75rem 2rem 6rem;flex:1}@media (min-width: 1400px){.editor-container{max-width:1000px}}.story-title-input{width:100%;background:transparent;border:none;border-bottom:1px solid var(--border);color:var(--text);font-family:var(--font-head);font-size:1.6rem;letter-spacing:.06em;padding:0 0 .5rem;margin-bottom:1.5rem;outline:none;transition:border-color .2s}.story-title-input:focus{border-bottom-color:var(--accent-hi)}.story-title-input::placeholder{color:var(--text-muted)}.cover-area{margin-bottom:1.25rem}.cover-add{width:100%;padding:.6rem;background:transparent;border:1px dashed var(--border);border-radius:var(--radius);color:var(--text-muted);font-family:var(--font-body);font-size:.82rem;cursor:pointer;text-align:center;transition:border-color .2s,color .2s}.cover-add:hover{border-color:var(--accent);color:var(--text)}.cover-preview{position:relative}.cover-img{width:100%;max-height:260px;object-fit:cover;border-radius:var(--radius);border:1px solid var(--border);display:block}.cover-actions{position:absolute;bottom:.5rem;right:.5rem;display:flex;gap:.5rem}.cover-btn{font-size:.72rem;padding:.25rem .6rem;background:#000000a6;border-color:#fff3;color:#fff;-webkit-backdrop-filter:blur(4px);backdrop-filter:blur(4px)}.panel-backdrop{display:none}.chapter-panel{width:240px;min-width:240px;background:var(--bg-surface);border-right:1px solid var(--border);display:flex;flex-direction:column;transform:translate(-100%);transition:transform .25s ease;position:fixed;top:0;left:0;bottom:0;z-index:300;overflow-y:auto}.chapter-panel.open{transform:translate(0)}.chapter-panel-header{display:flex;align-items:center;justify-content:space-between;padding:.75rem 1rem;border-bottom:1px solid var(--border);position:sticky;top:0;background:var(--bg-surface)}.chapter-panel-title{font-family:var(--font-head);font-size:.8rem;letter-spacing:.1em;text-transform:uppercase;color:var(--accent-hi)}.chapter-panel-close{background:transparent;border:none;color:var(--text-muted);font-size:1.2rem;line-height:1;padding:.1rem .3rem;border-radius:3px;transition:color .15s}.chapter-panel-close:hover{color:var(--text)}.chapter-panel-empty{padding:1rem;font-size:.82rem;color:var(--text-muted);font-style:italic;line-height:1.6}.chapter-list{list-style:none;padding:.5rem 0}.chapter-btn{width:100%;background:transparent;border:none;padding:.5rem 1rem;text-align:left;cursor:pointer;display:flex;flex-direction:column;gap:.1rem;transition:background .14s}.chapter-btn:hover{background:var(--bg-raised)}.chapter-num{font-family:var(--font-head);font-size:.65rem;letter-spacing:.1em;color:var(--accent-hi);text-transform:uppercase}.chapter-name{font-size:.85rem;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%}.notes-panel{width:340px;background:var(--bg-surface);border-left:1px solid var(--border);display:flex;flex-direction:column;position:fixed;top:0;right:0;bottom:0;z-index:300;transform:translate(100%);transition:transform .25s ease;overflow:hidden}.notes-panel.open{transform:translate(0)}.notes-panel-header{display:flex;align-items:center;justify-content:space-between;padding:.75rem 1rem;border-bottom:1px solid var(--border);flex-shrink:0;gap:.5rem}.notes-panel-title{font-family:var(--font-head);font-size:.8rem;letter-spacing:.1em;text-transform:uppercase;color:var(--accent-hi)}.note-new-btn{font-size:.72rem;padding:.3rem .7rem}.notes-list{list-style:none;flex:1;overflow-y:auto}.note-item{width:100%;background:transparent;border:none;padding:.7rem 1rem;text-align:left;cursor:pointer;display:flex;flex-direction:column;gap:.2rem;border-bottom:1px solid var(--border);transition:background .14s}.note-item:hover{background:var(--bg-raised)}.note-item-title{font-size:.88rem;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-family:var(--font-head);letter-spacing:.02em}.note-item-snippet{font-size:.75rem;color:var(--text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-style:italic}.note-item-date{font-size:.7rem;color:var(--text-muted);margin-top:.1rem}.notes-empty{padding:1.5rem 1rem;display:flex;flex-direction:column;align-items:flex-start;gap:.75rem}.notes-empty-msg{font-size:.82rem;color:var(--text-muted);font-style:italic}.notes-empty-cta{font-size:.75rem;padding:.4rem .875rem}.note-edit-view{display:flex;flex-direction:column;flex:1;overflow:hidden}.note-back-btn{font-size:.72rem;padding:.3rem .6rem}.note-title-input{width:100%;background:transparent;border:none;border-bottom:1px solid var(--border);color:var(--text);font-family:var(--font-head);font-size:1rem;letter-spacing:.04em;padding:.6rem 1rem;outline:none;flex-shrink:0;transition:border-color .2s}.note-title-input:focus{border-bottom-color:var(--accent-hi)}.note-title-input::placeholder{color:var(--text-muted)}.note-editor-scroll{flex:1;overflow-y:auto}.note-edit-footer{flex-shrink:0;padding:.6rem 1rem;border-top:1px solid var(--border)}.note-delete-btn{font-size:.72rem;padding:.3rem .7rem;color:var(--danger);border-color:var(--danger)}.note-delete-btn:hover{background:var(--danger);color:var(--text);border-color:var(--danger)}.note-toolbar{display:flex;align-items:center;flex-wrap:wrap;gap:2px;padding:.35rem .5rem;background:var(--bg-raised);border-bottom:1px solid var(--border);position:sticky;top:0;z-index:5}.note-editor-body{background:var(--bg-surface)}.note-editor-body .ProseMirror{padding:1rem;min-height:240px;font-family:var(--font-body);font-size:.92rem;line-height:1.8;color:var(--text);outline:none}.note-editor-body .ProseMirror p.is-editor-empty:first-child:before{content:attr(data-placeholder);color:var(--text-muted);font-style:italic;pointer-events:none;float:left;height:0}.note-editor-body .ProseMirror h2{font-family:var(--font-head);font-size:1.05rem;letter-spacing:.05em;color:var(--text);margin:1.25rem 0 .4rem;line-height:1.3}.note-editor-body .ProseMirror h3{font-family:var(--font-head);font-size:.9rem;color:var(--text-muted);margin:1rem 0 .3rem;line-height:1.3}.note-editor-body .ProseMirror p{margin-bottom:.5rem}.note-editor-body .ProseMirror strong{font-weight:700;color:var(--text)}.note-editor-body .ProseMirror em{font-style:italic}.note-editor-body .ProseMirror blockquote{border-left:3px solid var(--accent);padding:.2rem 0 .2rem .9rem;margin:.75rem 0;color:var(--text-muted);font-style:italic}.note-editor-body .ProseMirror ul,.note-editor-body .ProseMirror ol{padding-left:1.25rem;margin:.4rem 0}.note-editor-body .ProseMirror li+li{margin-top:.15rem}.focus-mode .notes-panel{display:none}@media (max-width: 768px){.notes-panel{width:100%;max-width:340px}}.export-wrap{position:relative}.export-menu{position:absolute;top:calc(100% + 6px);right:0;background:var(--bg-surface);border:1px solid var(--border);border-radius:var(--radius);box-shadow:0 4px 20px #00000080;min-width:180px;z-index:400;overflow:hidden}.export-menu button{display:block;width:100%;padding:.6rem 1rem;background:transparent;border:none;color:var(--text);font-family:var(--font-body);font-size:.85rem;text-align:left;cursor:pointer;transition:background .14s}.export-menu button:hover{background:var(--bg-raised);color:var(--accent-hi)}.toolbar{display:flex;align-items:center;flex-wrap:wrap;gap:2px;padding:.4rem .6rem;background:var(--bg-raised);border:1px solid var(--border);border-radius:var(--radius) var(--radius) 0 0;border-bottom:none;position:sticky;top:var(--topbar-h);z-index:150}.toolbar-btn{padding:.28rem .55rem;background:transparent;border:1px solid transparent;border-radius:calc(var(--radius) - 1px);color:var(--text-muted);font-family:var(--font-body);font-size:.82rem;line-height:1.4;min-width:30px;text-align:center;transition:all .14s}.toolbar-btn:hover,.toolbar-btn.active{background:var(--bg-surface);border-color:var(--border);color:var(--text)}.toolbar-btn.active{color:var(--accent-hi);border-color:var(--accent)}.toolbar-sep{width:1px;height:18px;background:var(--border);margin:0 3px;flex-shrink:0}.editor-wrap{border:1px solid var(--border);border-top:none;border-radius:0 0 var(--radius) var(--radius);overflow:hidden}.editor-body{background:var(--bg-surface)}.editor-body .ProseMirror{padding:1.5rem 1.75rem;outline:none;min-height:60vh;font-family:var(--font-body);font-size:var(--editor-font-size, 17px);line-height:1.85;color:var(--text)}.editor-body .ProseMirror p.is-editor-empty:first-child:before{content:attr(data-placeholder);color:var(--text-muted);font-style:italic;pointer-events:none;float:left;height:0}.editor-body .ProseMirror h1{font-family:var(--font-head);font-size:1.7rem;letter-spacing:.1em;color:var(--accent-hi);margin:2rem 0 .75rem;padding-bottom:.4rem;border-bottom:1px solid var(--border);line-height:1.3}.editor-body .ProseMirror h2{font-family:var(--font-head);font-size:1.25rem;letter-spacing:.06em;color:var(--text);margin:1.5rem 0 .5rem;line-height:1.3}.editor-body .ProseMirror h3{font-family:var(--font-head);font-size:1.05rem;color:var(--text-muted);margin:1.2rem 0 .4rem;line-height:1.3}.editor-body .ProseMirror p{margin-bottom:.6rem}.editor-body .ProseMirror blockquote{border-left:3px solid var(--accent);padding:.25rem 0 .25rem 1.1rem;margin:1rem 0;color:var(--text-muted);font-style:italic}.image-view-wrap{position:relative;margin:1.25rem 0;display:block}.image-view-wrap img{max-width:100%;border-radius:var(--radius);border:1px solid var(--border)}.image-controls{position:absolute;bottom:calc(100% + 6px);left:50%;transform:translate(-50%);display:flex;align-items:center;gap:3px;background:var(--bg-raised);border:1px solid var(--border);border-radius:var(--radius);padding:3px 5px;z-index:20;white-space:nowrap;box-shadow:0 3px 12px #0006}.image-ctrl-group{display:flex;gap:2px}.image-ctrl-sep{width:1px;height:16px;background:var(--border);margin:0 2px;flex-shrink:0}.img-ctrl-btn{padding:.2rem .45rem;background:transparent;border:1px solid transparent;border-radius:calc(var(--radius) - 1px);color:var(--text-muted);font-size:.75rem;font-family:var(--font-body);cursor:pointer;transition:all .14s}.img-ctrl-btn:hover{color:var(--text);background:var(--bg-surface);border-color:var(--border)}.img-ctrl-btn.active{color:var(--accent-hi);border-color:var(--accent)}.img-ctrl-delete:hover{color:var(--danger);border-color:var(--danger);background:transparent}.editor-body .ProseMirror ul,.editor-body .ProseMirror ol{padding-left:1.5rem;margin:.5rem 0}.editor-body .ProseMirror li+li{margin-top:.2rem}.editor-body .ProseMirror strong{color:var(--text);font-weight:700}.editor-body .ProseMirror em{font-style:italic}.editor-body .ProseMirror s{opacity:.6}.editor-body .ProseMirror mark{border-radius:2px;padding:.05em .15em;color:#111!important;-webkit-print-color-adjust:exact;print-color-adjust:exact}.editor-body .ProseMirror hr{border:none;margin:2rem 0;text-align:center;overflow:visible;height:1.5rem;line-height:1.5rem}.editor-body .ProseMirror hr:after{content:"✦ ✦ ✦";letter-spacing:.5em;font-size:.85rem;color:var(--text-muted)}.editor-body .ProseMirror hr.ProseMirror-selectednode:after{outline:2px solid var(--accent);border-radius:3px}.word-count{padding:.35rem 1rem;background:var(--bg-raised);border-top:1px solid var(--border);font-size:.72rem;color:var(--text-muted);text-align:right;font-style:italic}.theme-picker{position:fixed;bottom:1.5rem;right:1.5rem;z-index:500}.theme-toggle{width:48px;height:48px;border-radius:50%;background:var(--bg-surface);border:1px solid var(--border);font-size:1.2rem;display:flex;align-items:center;justify-content:center;box-shadow:0 3px 14px #0000008c;transition:border-color .2s,transform .15s}.theme-toggle:hover{border-color:var(--accent-hi);transform:scale(1.06)}.theme-menu{position:absolute;bottom:58px;right:0;background:var(--bg-surface);border:1px solid var(--border);border-radius:calc(var(--radius) * 2);padding:.5rem;display:flex;flex-direction:column;gap:3px;box-shadow:0 6px 28px #000000a6;min-width:185px}.theme-option{display:flex;align-items:center;gap:.75rem;padding:.45rem .75rem;background:transparent;border:1px solid transparent;border-radius:var(--radius);color:var(--text);font-size:.83rem;text-align:left;transition:all .14s}.theme-option:hover{background:var(--bg-raised);border-color:var(--border)}.theme-option.active{border-color:var(--accent)}.theme-swatch{width:30px;height:30px;border-radius:50%;display:flex;align-items:center;justify-content:center;flex-shrink:0;font-size:9px;font-weight:700;font-family:serif}.font-picker{position:fixed;bottom:1.5rem;right:5.5rem;z-index:500}.font-toggle{width:48px;height:48px;border-radius:50%;background:var(--bg-surface);border:1px solid var(--border);font-size:1rem;font-weight:600;color:var(--text-muted);display:flex;align-items:center;justify-content:center;box-shadow:0 3px 14px #0000008c;transition:border-color .2s,transform .15s,color .2s}.font-toggle:hover{border-color:var(--accent-hi);color:var(--text);transform:scale(1.06)}.font-menu{position:absolute;bottom:58px;right:0;background:var(--bg-surface);border:1px solid var(--border);border-radius:calc(var(--radius) * 2);padding:.5rem;display:flex;flex-direction:column;gap:2px;box-shadow:0 6px 28px #000000a6;min-width:220px;max-height:440px;overflow-y:auto}.font-menu-label{font-family:var(--font-head);font-size:.65rem;letter-spacing:.12em;text-transform:uppercase;color:var(--text-muted);padding:.3rem .5rem .4rem}.font-option{display:flex;align-items:center;gap:.75rem;padding:.4rem .6rem;background:transparent;border:1px solid transparent;border-radius:var(--radius);text-align:left;cursor:pointer;transition:all .14s;width:100%}.font-option:hover{background:var(--bg-raised);border-color:var(--border)}.font-option.active{border-color:var(--accent)}.font-preview{font-size:1.3rem;color:var(--accent-hi);width:32px;text-align:center;flex-shrink:0;line-height:1}.font-info{display:flex;flex-direction:column;gap:1px;min-width:0}.font-name{font-size:.88rem;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.font-category{font-size:.68rem;color:var(--text-muted);font-family:var(--font-head);letter-spacing:.08em;text-transform:uppercase}.toast-container{position:fixed;bottom:5rem;left:50%;transform:translate(-50%);display:flex;flex-direction:column;align-items:center;gap:.5rem;z-index:9000;pointer-events:none}.toast{padding:.6rem 1.25rem;background:var(--bg-raised);border:1px solid var(--border);border-radius:99px;font-size:.85rem;color:var(--text);box-shadow:0 4px 16px #00000080;animation:toast-in .25s ease}.toast--success{border-color:var(--accent);color:var(--accent-hi)}.toast--error{border-color:var(--danger);color:var(--danger)}@keyframes toast-in{0%{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}.confirm-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background:#0009;display:flex;align-items:center;justify-content:center;z-index:8000;padding:1rem}.confirm-box{background:var(--bg-surface);border:1px solid var(--border);border-radius:calc(var(--radius) * 2);padding:1.75rem 2rem;max-width:360px;width:100%;box-shadow:0 8px 40px #0009}.confirm-message{font-size:1rem;line-height:1.6;margin-bottom:1.5rem;color:var(--text)}.confirm-actions{display:flex;justify-content:flex-end;gap:.75rem}.stats-bar{display:flex;align-items:center;gap:.75rem;flex-wrap:wrap;margin-bottom:1rem}.stat-chip{display:flex;align-items:center;gap:.5rem;padding:.4rem .875rem;background:var(--bg-surface);border:1px solid var(--border);border-radius:99px;font-size:.82rem;color:var(--text-muted);cursor:default}.stat-icon{font-size:1rem;line-height:1}.goal-chip{cursor:pointer;transition:border-color .2s}.goal-chip:hover{border-color:var(--accent);color:var(--text)}.goal-bar-wrap{width:60px;height:4px;background:var(--bg-raised);border-radius:2px;overflow:hidden}.goal-bar{height:100%;background:var(--accent-hi);border-radius:2px;transition:width .4s ease}.goal-pct{font-size:.75rem}.goal-set-cta{color:var(--accent-hi)}.goal-form{display:flex;align-items:center;gap:.625rem;margin-bottom:1rem;flex-wrap:wrap}.goal-label{font-size:.85rem;color:var(--text-muted)}.goal-input{width:100px}.search-bar{margin-bottom:1.25rem}.search-input{max-width:340px}.focus-mode .editor-topbar{opacity:0;pointer-events:none;transition:opacity .3s}.focus-mode:hover .editor-topbar{opacity:1;pointer-events:all}.focus-mode .toolbar{opacity:0;pointer-events:none;transition:opacity .3s}.focus-mode:hover .toolbar{opacity:1;pointer-events:all}.focus-mode .chapter-panel,.focus-mode .cover-area{display:none}.focus-exit{position:fixed;bottom:1.5rem;left:50%;transform:translate(-50%);background:var(--bg-surface);border:1px solid var(--border);border-radius:99px;color:var(--text-muted);font-size:.75rem;padding:.4rem 1rem;font-family:var(--font-head);letter-spacing:.06em;cursor:pointer;opacity:0;transition:opacity .2s;z-index:100}.editor-page:hover .focus-exit{opacity:1}.highlight-swatch{width:18px;height:18px;min-width:18px;border-radius:3px;background:var(--swatch);border:2px solid transparent;padding:0}.highlight-swatch:hover{border-color:var(--text-muted);background:var(--swatch)!important}.highlight-swatch.active{border-color:var(--text)}.font-btn{font-family:var(--font-head);font-size:.75rem}.toolbar-font-size{font-size:.72rem;color:var(--text-muted);min-width:30px;text-align:center;font-variant-numeric:tabular-nums}.read-aloud-btn{font-size:1rem;line-height:1;padding:.2rem .45rem}.read-aloud-btn.reading-active{color:var(--accent-hi);border-color:var(--accent);animation:reading-pulse 1.8s ease-in-out infinite}@keyframes reading-pulse{0%,to{opacity:1}50%{opacity:.45}}.reading-word{background:#fbbf2459;border-radius:2px;outline:1px solid rgba(251,191,36,.55);outline-offset:1px}.lint-mark{text-decoration-line:underline;text-decoration-style:wavy;text-decoration-skip-ink:none;text-decoration-thickness:1.5px;cursor:pointer}.lint-mark--spelling{text-decoration-color:#f87171}.lint-mark--grammar{text-decoration-color:#60a5fa}.lint-btn{font-family:var(--font-head);font-size:.75rem;min-width:36px}.lint-btn.lint-clean{color:#4ade80;border-color:#4ade8040}.lint-btn.lint-errors{color:#f87171;border-color:#f8717140}.lint-btn.lint-stale{color:var(--text-muted);opacity:.7}.lint-btn:disabled{opacity:.5;cursor:wait}.lint-popover{position:fixed;z-index:600;width:260px;background:var(--bg-raised);border:1px solid var(--border);border-radius:calc(var(--radius) * 2);padding:.75rem;box-shadow:0 6px 24px #0009}.lint-popover-msg{font-size:.82rem;color:var(--text);line-height:1.55;margin-bottom:.6rem}.lint-suggestions{display:flex;flex-wrap:wrap;gap:.35rem;margin-bottom:.5rem}.lint-suggestion{background:var(--bg-surface);border:1px solid var(--border);border-radius:calc(var(--radius) - 1px);color:var(--text);font-family:var(--font-body);font-size:.82rem;padding:.2rem .55rem;cursor:pointer;transition:border-color .12s,color .12s}.lint-suggestion:hover{border-color:var(--accent);color:var(--accent-hi)}.lint-popover-actions{display:flex;justify-content:space-between;align-items:center;margin-top:.1rem}.lint-ignore{font-size:.75rem;padding:.2rem .5rem}.lint-close{font-size:.85rem;padding:.2rem .45rem}.typewriter .editor-body .ProseMirror{padding-bottom:50vh}.tts-settings-wrap{position:relative}.tts-menu{position:absolute;bottom:calc(100% + 6px);right:0;width:240px;background:var(--bg-raised);border:1px solid var(--border);border-radius:var(--radius);padding:.75rem;box-shadow:0 4px 16px #00000080;z-index:300;display:flex;flex-direction:column;gap:.4rem}.tts-label{font-size:.72rem;color:var(--text-muted);font-family:var(--font-head);letter-spacing:.03em}.tts-select{width:100%;background:var(--bg-surface);border:1px solid var(--border);border-radius:calc(var(--radius) - 1px);color:var(--text);font-family:var(--font-body);font-size:.8rem;padding:.3rem .5rem;cursor:pointer}.tts-select:focus{outline:none;border-color:var(--accent)}.tts-slider{width:100%;accent-color:var(--accent-hi);cursor:pointer}.prompt-wrap{position:relative}.prompt-popover{position:absolute;top:calc(100% + 8px);right:0;width:300px;background:var(--bg-surface);border:1px solid var(--border);border-radius:calc(var(--radius) * 2);padding:1rem;box-shadow:0 6px 24px #0000008c;z-index:400}.prompt-text{font-style:italic;font-size:.9rem;line-height:1.65;color:var(--text);margin-bottom:.875rem}.prompt-source-icon{position:absolute;top:.6rem;right:.7rem;font-size:.85rem;line-height:1;opacity:.55}.prompt-actions{display:flex;gap:.5rem;justify-content:flex-end;flex-wrap:wrap}.prompt-actions .btn{padding:.45rem .875rem;font-size:.75rem}.admin-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(320px,1fr));gap:1.5rem;align-items:start}.admin-card{background:var(--bg-surface);border:1px solid var(--border);border-radius:var(--radius);padding:1.5rem}.admin-section-title{font-family:var(--font-head);font-size:1rem;letter-spacing:.08em;color:var(--accent-hi);margin-bottom:1rem}.user-list{list-style:none;display:flex;flex-direction:column;gap:.5rem}.user-row{display:flex;align-items:center;justify-content:space-between;padding:.625rem .75rem;background:var(--bg-raised);border-radius:calc(var(--radius) - 1px);gap:1rem}.user-email{display:block;font-size:.78rem;color:var(--text-muted);font-style:italic}.success-msg{color:var(--accent-hi);font-size:.875rem;font-style:italic}@media (min-width: 769px){.chapter-panel{position:relative;top:auto;left:auto;bottom:auto;transform:none;width:0;min-width:0;overflow:hidden;border-right:none;transition:width .25s ease,min-width .25s ease}.chapter-panel.open{width:240px;min-width:240px;border-right:1px solid var(--border);transform:none}.panel-backdrop{display:none!important}}@media (max-width: 768px){.panel-backdrop{display:block;position:fixed;top:0;right:0;bottom:0;left:0;background:#00000080;z-index:299}.chapter-panel{width:260px;min-width:260px}}@media (max-width: 600px){.stories-page{padding:1.25rem .875rem 5rem}.stories-header{flex-direction:column;align-items:flex-start}.stories-grid{grid-template-columns:repeat(auto-fill,minmax(160px,1fr));gap:.875rem}.editor-container{padding:1.25rem .875rem 5rem}.story-title-input{font-size:1.35rem}.editor-body .ProseMirror{padding:1rem 1.1rem;font-size:1rem}.editor-body .ProseMirror h1{font-size:1.4rem}.editor-topbar{padding:.4rem .5rem;gap:.25rem}.topbar-left,.topbar-right{gap:.25rem}.editor-topbar .btn-ghost{padding:.35rem .5rem;font-size:.72rem}.topbar-left span,.topbar-right span,.save-status{display:none}.cover-img{max-height:160px}.login-box{padding:2.25rem 1.5rem 2rem}.theme-picker{bottom:1rem;right:1rem}.theme-toggle{width:42px;height:42px;font-size:1.1rem}.font-picker{bottom:1rem;right:4.75rem}.font-toggle{width:42px;height:42px;font-size:.9rem}}@media (max-width: 400px){.toolbar{gap:1px;padding:.35rem .4rem}.toolbar-btn{padding:.25rem .4rem;font-size:.78rem;min-width:26px}} diff --git a/frontend/dist/icon.svg b/frontend/dist/icon.svg new file mode 100644 index 0000000..34396eb --- /dev/null +++ b/frontend/dist/icon.svg @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/frontend/dist/index.html b/frontend/dist/index.html new file mode 100644 index 0000000..ae6d6b3 --- /dev/null +++ b/frontend/dist/index.html @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + Grimoire + + + + +
+ + diff --git a/frontend/dist/manifest.json b/frontend/dist/manifest.json new file mode 100644 index 0000000..418bd9d --- /dev/null +++ b/frontend/dist/manifest.json @@ -0,0 +1,17 @@ +{ + "name": "Grimoire", + "short_name": "Grimoire", + "description": "Write your stories, anywhere.", + "start_url": "/", + "display": "standalone", + "background_color": "#09090f", + "theme_color": "#09090f", + "icons": [ + { + "src": "/icon.svg", + "sizes": "any", + "type": "image/svg+xml", + "purpose": "any maskable" + } + ] +} diff --git a/frontend/src/components/CharactersPanel.jsx b/frontend/src/components/CharactersPanel.jsx new file mode 100644 index 0000000..4003048 --- /dev/null +++ b/frontend/src/components/CharactersPanel.jsx @@ -0,0 +1,436 @@ +import { useState, useEffect, useRef, useCallback } from 'react' +import { api } from '../lib/api' +import { useToast } from './Toast' +import { useConfirm } from './ConfirmDialog' + +const ROLES = ['protagonist', 'antagonist', 'supporting', 'minor', 'other'] +const ROLE_LABELS = { + protagonist: 'Protagonist', + antagonist: 'Antagonist', + supporting: 'Supporting', + minor: 'Minor', + other: 'Other', +} + +const EMPTY_FORM = { name: '', role: 'supporting', age: '', description: '', notes: '' } + +export default function CharactersPanel({ storyId, open, onClose }) { + const toast = useToast() + const confirm = useConfirm() + + const [characters, setCharacters] = useState([]) + const [loaded, setLoaded] = useState(false) + const [activeChar, setActiveChar] = useState(null) + const [form, setForm] = useState(EMPTY_FORM) + const [charPhoto, setCharPhoto] = useState(null) + + // Import state + const [importOpen, setImportOpen] = useState(false) + const [importStories, setImportStories] = useState([]) + const [importSourceId, setImportSourceId] = useState(null) + const [importChars, setImportChars] = useState([]) + const [importSelected, setImportSelected] = useState(new Set()) + const [importLoadingChars,setImportLoadingChars]= useState(false) + + const saveTimer = useRef(null) + const latestForm = useRef(EMPTY_FORM) + const latestPhoto = useRef(null) + const photoRef = useRef() + + useEffect(() => { + if (open && !loaded) { + api.getCharacters(storyId) + .then(cs => { setCharacters(cs); setLoaded(true) }) + .catch(() => toast('Could not load characters', 'error')) + } + }, [open, loaded, storyId, toast]) + + useEffect(() => { + if (!open) return + function onKey(e) { + if (e.key !== 'Escape') return + e.stopPropagation() + if (importOpen) { + setImportOpen(false) + } else if (activeChar) { + flushAndClearTimer(activeChar.id) + setActiveChar(null) + } else { + onClose() + } + } + document.addEventListener('keydown', onKey, true) + return () => document.removeEventListener('keydown', onKey, true) + }, [open, activeChar, importOpen, onClose]) + + const saveChar = useCallback(async (charId) => { + if (!charId) return + try { + const updated = await api.updateCharacter(storyId, charId, { + ...latestForm.current, + photo: latestPhoto.current, + }) + setCharacters(prev => prev.map(c => c.id === charId ? updated : c)) + } catch { + toast('Could not save character', 'error') + } + }, [storyId, toast]) + + function scheduleSave(charId) { + clearTimeout(saveTimer.current) + saveTimer.current = setTimeout(() => saveChar(charId), 1500) + } + + function flushAndClearTimer(charId) { + clearTimeout(saveTimer.current) + saveChar(charId) + } + + useEffect(() => () => clearTimeout(saveTimer.current), []) + + function openChar(char) { + if (activeChar && activeChar.id !== char.id) flushAndClearTimer(activeChar.id) + const f = { + name: char.name || '', + role: char.role || 'supporting', + age: char.age || '', + description: char.description || '', + notes: char.notes || '', + } + latestForm.current = f + latestPhoto.current = char.photo ?? null + setForm(f) + setCharPhoto(char.photo ?? null) + setActiveChar(char) + } + + async function createCharacter() { + try { + const char = await api.createCharacter(storyId, { name: 'New Character', role: 'supporting' }) + setCharacters(prev => [...prev, char].sort((a, b) => a.name.localeCompare(b.name))) + openChar(char) + } catch { + toast('Could not create character', 'error') + } + } + + function handleFormChange(field, value) { + const updated = { ...latestForm.current, [field]: value } + latestForm.current = updated + setForm(updated) + scheduleSave(activeChar.id) + } + + async function handlePhotoUpload(e) { + const file = e.target.files[0] + if (!file) return + e.target.value = '' + try { + const url = await api.uploadImage(file) + latestPhoto.current = url + setCharPhoto(url) + scheduleSave(activeChar.id) + } catch { + toast('Photo upload failed', 'error') + } + } + + async function removePhoto() { + latestPhoto.current = null + setCharPhoto(null) + scheduleSave(activeChar.id) + } + + function backToList() { + flushAndClearTimer(activeChar.id) + setActiveChar(null) + } + + async function deleteChar() { + const ok = await confirm(`Delete "${activeChar.name || 'this character'}"?`, { + confirmLabel: 'Delete', + danger: true, + }) + if (!ok) return + try { + clearTimeout(saveTimer.current) + await api.deleteCharacter(storyId, activeChar.id) + setCharacters(prev => prev.filter(c => c.id !== activeChar.id)) + setActiveChar(null) + } catch { + toast('Could not delete character', 'error') + } + } + + function handleClose() { + if (activeChar) flushAndClearTimer(activeChar.id) + setImportOpen(false) + onClose() + } + + // ── Import ──────────────────────────────────────────── + + async function openImport() { + try { + const stories = await api.getStories() + setImportStories(stories.filter(s => s.id !== parseInt(storyId))) + setImportSourceId(null) + setImportChars([]) + setImportSelected(new Set()) + setImportOpen(true) + } catch { + toast('Could not load stories', 'error') + } + } + + async function selectImportStory(id) { + setImportSourceId(id) + setImportSelected(new Set()) + setImportLoadingChars(true) + try { + setImportChars(await api.getCharacters(id)) + } catch { + toast('Could not load characters from that story', 'error') + } finally { + setImportLoadingChars(false) + } + } + + function toggleImportChar(id) { + setImportSelected(prev => { + const next = new Set(prev) + next.has(id) ? next.delete(id) : next.add(id) + return next + }) + } + + async function doImport() { + if (!importSourceId || importSelected.size === 0) return + try { + const imported = await api.importCharacters(storyId, importSourceId, [...importSelected]) + setCharacters(prev => [...prev, ...imported].sort((a, b) => a.name.localeCompare(b.name))) + setImportOpen(false) + toast(`Imported ${imported.length} character${imported.length !== 1 ? 's' : ''}`) + } catch { + toast('Could not import characters', 'error') + } + } + + // ── Render ──────────────────────────────────────────── + + return ( + <> + {open &&
} + +