var lu=Object.defineProperty;var au=(n,e,t)=>e in n?lu(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var Y=(n,e,t)=>au(n,typeof e!="symbol"?e+"":e,t);var kr,A,gl,yt,So,bl,yl,xl,$i,ui,di,kl,kn={},_l=[],cu=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,Dn=Array.isArray;function Ke(n,e){for(var t in e)n[t]=e[t];return n}function Vi(n){n&&n.parentNode&&n.parentNode.removeChild(n)}function fi(n,e,t){var r,i,o,s={};for(o in e)o=="key"?r=e[o]:o=="ref"?i=e[o]:s[o]=e[o];if(arguments.length>2&&(s.children=arguments.length>3?kr.call(arguments,2):t),typeof n=="function"&&n.defaultProps!=null)for(o in n.defaultProps)s[o]===void 0&&(s[o]=n.defaultProps[o]);return Qn(n,s,r,i,null)}function Qn(n,e,t,r,i){var o={type:n,props:e,key:t,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++gl,__i:-1,__u:0};return i==null&&A.vnode!=null&&A.vnode(o),o}function te(n){return n.children}function Ge(n,e){this.props=n,this.context=e}function Gt(n,e){if(e==null)return n.__?Gt(n.__,n.__i+1):null;for(var t;el&&yt.sort(yl),n=yt.shift(),l=yt.length,n.__d&&(t=void 0,r=void 0,i=(r=(e=n).__v).__e,o=[],s=[],e.__P&&((t=Ke({},r)).__v=r.__v+1,A.vnode&&A.vnode(t),Ui(e.__P,t,r,e.__n,e.__P.namespaceURI,32&r.__u?[i]:null,o,i??Gt(r),!!(32&r.__u),s),t.__v=r.__v,t.__.__k[t.__i]=t,Sl(o,t,s),r.__e=r.__=null,t.__e!=i&&vl(t)));ir.__r=0}function wl(n,e,t,r,i,o,s,l,a,c,u){var f,h,p,m,g,y,x,v=r&&r.__k||_l,S=e.length;for(a=uu(t,e,v,a,S),f=0;f0?Qn(s.type,s.props,s.key,s.ref?s.ref:null,s.__v):s).__=n,s.__b=n.__b+1,l=null,(c=s.__i=du(s,t,a,f))!=-1&&(f--,(l=t[c])&&(l.__u|=2)),l==null||l.__v==null?(c==-1&&(i>u?h--:ia?h--:h++,s.__u|=4))):n.__k[o]=null;if(f)for(o=0;o(u?1:0)){for(i=t-1,o=t+1;i>=0||o=0?i--:o++])!=null&&!(2&c.__u)&&l==c.key&&a==c.type)return s}return-1}function Mo(n,e,t){e[0]=="-"?n.setProperty(e,t??""):n[e]=t==null?"":typeof t!="number"||cu.test(e)?t:t+"px"}function Hn(n,e,t,r,i){var o,s;e:if(e=="style")if(typeof t=="string")n.style.cssText=t;else{if(typeof r=="string"&&(n.style.cssText=r=""),r)for(e in r)t&&e in t||Mo(n.style,e,"");if(t)for(e in t)r&&t[e]==r[e]||Mo(n.style,e,t[e])}else if(e[0]=="o"&&e[1]=="n")o=e!=(e=e.replace(xl,"$1")),s=e.toLowerCase(),e=s in n||e=="onFocusOut"||e=="onFocusIn"?s.slice(2):e.slice(2),n.l||(n.l={}),n.l[e+o]=t,t?r?t.u=r.u:(t.u=$i,n.addEventListener(e,o?di:ui,o)):n.removeEventListener(e,o?di:ui,o);else{if(i=="http://www.w3.org/2000/svg")e=e.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(e!="width"&&e!="height"&&e!="href"&&e!="list"&&e!="form"&&e!="tabIndex"&&e!="download"&&e!="rowSpan"&&e!="colSpan"&&e!="role"&&e!="popover"&&e in n)try{n[e]=t??"";break e}catch{}typeof t=="function"||(t==null||t===!1&&e[4]!="-"?n.removeAttribute(e):n.setAttribute(e,e=="popover"&&t==1?"":t))}}function Oo(n){return function(e){if(this.l){var t=this.l[e.type+n];if(e.t==null)e.t=$i++;else if(e.t0?n:Dn(n)?n.map(Ml):Ke({},n)}function fu(n,e,t,r,i,o,s,l,a){var c,u,f,h,p,m,g,y=t.props,x=e.props,v=e.type;if(v=="svg"?i="http://www.w3.org/2000/svg":v=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),o!=null){for(c=0;c=t.__.length&&t.__.push({}),t.__[n]}function w(n){return _n=1,yu(Il,n)}function yu(n,e,t){var r=An(Et++,2);if(r.t=n,!r.__c&&(r.__=[t?t(e):Il(void 0,e),function(l){var a=r.__N?r.__N[0]:r.__[0],c=r.t(a,l);a!==c&&(r.__N=[c,r.__[1]],r.__c.setState({}))}],r.__c=j,!j.__f)){var i=function(l,a,c){if(!r.__c.__H)return!0;var u=r.__c.__H.__.filter(function(h){return!!h.__c});if(u.every(function(h){return!h.__N}))return!o||o.call(this,l,a,c);var f=r.__c.props!==l;return u.forEach(function(h){if(h.__N){var p=h.__[0];h.__=h.__N,h.__N=void 0,p!==h.__[0]&&(f=!0)}}),o&&o.call(this,l,a,c)||f};j.__f=!0;var o=j.shouldComponentUpdate,s=j.componentWillUpdate;j.componentWillUpdate=function(l,a,c){if(this.__e){var u=o;o=void 0,i(l,a,c),o=u}s&&s.call(this,l,a,c)},j.shouldComponentUpdate=i}return r.__N||r.__}function B(n,e){var t=An(Et++,3);!Q.__s&&Tl(t.__H,e)&&(t.__=n,t.u=e,j.__H.__h.push(t))}function H(n){return _n=5,El(function(){return{current:n}},[])}function El(n,e){var t=An(Et++,7);return Tl(t.__H,e)&&(t.__=n(),t.__H=e,t.__h=n),t.__}function xu(n,e){return _n=8,El(function(){return n},e)}function ku(n){var e=j.context[n.__c],t=An(Et++,9);return t.c=n,e?(t.__==null&&(t.__=!0,e.sub(j)),e.props.value):n.__}function _u(n){var e=An(Et++,10),t=w();return e.__=n,j.componentDidCatch||(j.componentDidCatch=function(r,i){e.__&&e.__(r,i),t[1](r)}),[t[0],function(){t[1](void 0)}]}function vu(){for(var n;n=Nl.shift();)if(n.__P&&n.__H)try{n.__H.__h.forEach(Zn),n.__H.__h.forEach(mi),n.__H.__h=[]}catch(e){n.__H.__h=[],Q.__e(e,n.__v)}}Q.__b=function(n){j=null,Eo&&Eo(n)},Q.__=function(n,e){n&&e.__k&&e.__k.__m&&(n.__m=e.__k.__m),Ro&&Ro(n,e)},Q.__r=function(n){To&&To(n),Et=0;var e=(j=n.__c).__H;e&&(Rr===j?(e.__h=[],j.__h=[],e.__.forEach(function(t){t.__N&&(t.__=t.__N),t.u=t.__N=void 0})):(e.__h.forEach(Zn),e.__h.forEach(mi),e.__h=[],Et=0)),Rr=j},Q.diffed=function(n){Io&&Io(n);var e=n.__c;e&&e.__H&&(e.__H.__h.length&&(Nl.push(e)!==1&&No===Q.requestAnimationFrame||((No=Q.requestAnimationFrame)||wu)(vu)),e.__H.__.forEach(function(t){t.u&&(t.__H=t.u),t.u=void 0})),Rr=j=null},Q.__c=function(n,e){e.some(function(t){try{t.__h.forEach(Zn),t.__h=t.__h.filter(function(r){return!r.__||mi(r)})}catch(r){e.some(function(i){i.__h&&(i.__h=[])}),e=[],Q.__e(r,t.__v)}}),Do&&Do(n,e)},Q.unmount=function(n){Ao&&Ao(n);var e,t=n.__c;t&&t.__H&&(t.__H.__.forEach(function(r){try{Zn(r)}catch(i){e=i}}),t.__H=void 0,e&&Q.__e(e,t.__v))};var Po=typeof requestAnimationFrame=="function";function wu(n){var e,t=function(){clearTimeout(r),Po&&cancelAnimationFrame(e),setTimeout(n)},r=setTimeout(t,35);Po&&(e=requestAnimationFrame(t))}function Zn(n){var e=j,t=n.__c;typeof t=="function"&&(n.__c=void 0,t()),j=e}function mi(n){var e=j;n.__c=n.__(),j=e}function Tl(n,e){return!n||n.length!==e.length||e.some(function(t,r){return t!==n[r]})}function Il(n,e){return typeof e=="function"?e(n):e}function Dl(n,e){for(var t in e)n[t]=e[t];return n}function zo(n,e){for(var t in n)if(t!=="__source"&&!(t in e))return!0;for(var r in e)if(r!=="__source"&&n[r]!==e[r])return!0;return!1}function Bo(n,e){this.props=n,this.context=e}(Bo.prototype=new Ge).isPureReactComponent=!0,Bo.prototype.shouldComponentUpdate=function(n,e){return zo(this.props,n)||zo(this.state,e)};var Lo=A.__b;A.__b=function(n){n.type&&n.type.__f&&n.ref&&(n.props.ref=n.ref,n.ref=null),Lo&&Lo(n)};var Cu=typeof Symbol<"u"&&Symbol.for&&Symbol.for("react.forward_ref")||3911;function Su(n){function e(t){var r=Dl({},t);return delete r.ref,n(r,t.ref||null)}return e.$$typeof=Cu,e.render=n,e.prototype.isReactComponent=e.__f=!0,e.displayName="ForwardRef("+(n.displayName||n.name)+")",e}var Mu=A.__e;A.__e=function(n,e,t,r){if(n.then){for(var i,o=e;o=o.__;)if((i=o.__c)&&i.__c)return e.__e==null&&(e.__e=t.__e,e.__k=t.__k),i.__c(n,e)}Mu(n,e,t,r)};var Fo=A.unmount;function Al(n,e,t){return n&&(n.__c&&n.__c.__H&&(n.__c.__H.__.forEach(function(r){typeof r.__c=="function"&&r.__c()}),n.__c.__H=null),(n=Dl({},n)).__c!=null&&(n.__c.__P===t&&(n.__c.__P=e),n.__c.__e=!0,n.__c=null),n.__k=n.__k&&n.__k.map(function(r){return Al(r,e,t)})),n}function Rl(n,e,t){return n&&t&&(n.__v=null,n.__k=n.__k&&n.__k.map(function(r){return Rl(r,e,t)}),n.__c&&n.__c.__P===e&&(n.__e&&t.appendChild(n.__e),n.__c.__e=!0,n.__c.__P=t)),n}function Pr(){this.__u=0,this.o=null,this.__b=null}function Pl(n){var e=n.__.__c;return e&&e.__a&&e.__a(n)}function qn(){this.i=null,this.l=null}A.unmount=function(n){var e=n.__c;e&&e.__R&&e.__R(),e&&32&n.__u&&(n.type=null),Fo&&Fo(n)},(Pr.prototype=new Ge).__c=function(n,e){var t=e.__c,r=this;r.o==null&&(r.o=[]),r.o.push(t);var i=Pl(r.__v),o=!1,s=function(){o||(o=!0,t.__R=null,i?i(l):l())};t.__R=s;var l=function(){if(!--r.__u){if(r.state.__a){var a=r.state.__a;r.__v.__k[0]=Rl(a,a.__c.__P,a.__c.__O)}var c;for(r.setState({__a:r.__b=null});c=r.o.pop();)c.forceUpdate()}};r.__u++||32&e.__u||r.setState({__a:r.__b=r.__v.__k[0]}),n.then(s,s)},Pr.prototype.componentWillUnmount=function(){this.o=[]},Pr.prototype.render=function(n,e){if(this.__b){if(this.__v.__k){var t=document.createElement("div"),r=this.__v.__k[0].__c;this.__v.__k[0]=Al(this.__b,t,r.__O=r.__P)}this.__b=null}var i=e.__a&&fi(te,null,n.fallback);return i&&(i.__u&=-33),[fi(te,null,e.__a?null:n.children),i]};var $o=function(n,e,t){if(++t[1]===t[0]&&n.l.delete(e),n.props.revealOrder&&(n.props.revealOrder[0]!=="t"||!n.l.size))for(t=n.i;t;){for(;t.length>3;)t.pop()();if(t[1](n.events=n.events||{},n.events[t+Kn]||(n.events[t+Kn]=r(i=>{n.events[t].reduceRight((o,s)=>(s(o),o),{shared:{},...i})})),n.events[t]=n.events[t]||[],n.events[t].push(e),()=>{let i=n.events[t],o=i.indexOf(e);i.splice(o,1),i.length||(delete n.events[t],n.events[t+Kn](),delete n.events[t+Kn])}),Fu=1e3,Hi=(n,e)=>Lu(n,r=>{let i=e(r);i&&n.events[Wn].push(i)},Bu,r=>{let i=n.listen;n.listen=s=>(!n.lc&&!n.active&&(r(),n.active=!0),i(s));let o=n.off;return n.events[Wn]=[],n.off=()=>{setTimeout(()=>{if(n.active&&!n.lc){n.active=!1;for(let s of n.events[Wn])s();n.events[Wn]=[],o()}},Fu)},()=>{n.listen=i,n.off=o}}),mt=[],gi=0,E=n=>{let e,t=[],r={lc:0,value:n,set(i){r.value=i,r.notify()},get(){return r.lc||r.listen(()=>{})(),r.value},notify(i){e=t;let o=!mt.length;for(let s=0;s{t===e&&(t=t.slice());let o=t.indexOf(i);~o&&(t.splice(o,1),r.lc--,r.lc||r.off())}},subscribe(i){let o=r.listen(i);return i(r.value),o},off(){}};return r},$u=(n={})=>{let e=E(n);return e.setKey=function(t,r){typeof r>"u"?t in e.value&&(e.value={...e.value},delete e.value[t],e.notify(t)):e.value[t]!==r&&(e.value={...e.value,[t]:r},e.notify(t))},e};function Vu(n){let e=(t,...r)=>(e.cache[t]||(e.cache[t]=e.build(t,...r)),e.cache[t]);return e.build=(t,...r)=>{let i=$u({id:t});return Hi(i,()=>{let o;return n&&(o=n(i,t,...r)),()=>{delete e.cache[t],o&&o()}}),i},e.cache={},e}function Uu(n,e,t){let r=new Set([...e,void 0]);return n.listen((i,o)=>{r.has(o)&&t(i,o)})}let zr=(n,e)=>{Array.isArray(n)||(n=[n]);let t,r=[],i=()=>{let s=n.map(l=>l.get());(t!==gi||s.some((l,a)=>l!==r[a]))&&(t=gi,r=s,o.set(e(...s)))},o=E();return Hi(o,()=>{let s=n.map(l=>l.listen(i,e));return i(),()=>{for(let l of s)l()}}),o};function zt(n,e={}){let[,t]=w({});return B(()=>{let r,i,o,s=()=>{r||(r=1,i=setTimeout(()=>{r=void 0,t({})}))};return e.keys?o=Uu(n,e.keys,s):o=n.listen(s),()=>{o(),clearTimeout(i)}},[n,""+e.keys]),n.get()}function Bl(n){let e="";for(const t in n)e!=""&&(e+="&"),e+=t+"="+encodeURIComponent(n[t]);return e}function ju(n,e){const t=Bl(e);return n+"?"+t}function O(n,e){let t=b.get(n,"website");const r=e.split(".");for(const i of r)t=t[i];return t}function qo(n){window.open(n,"_blank","menubar=no,toolbar=no,location=no,scrollbars=yes,resizable=yes,width=600,height=600")}function Hu(n){return O(n,"auth.type")==="hyvor"}function Rn(n){return O(n,"auth.type")==="sso"&&O(n,"auth.sso_type")==="stateless"}function qu(n){return O(n,"auth.type")==="sso"&&O(n,"auth.sso_type")==="openid"}class Pe{static getKey(e){return"ht_"+b.get(e,"websiteId")+"_token"}static getToken(e){if(b.get(e,"website").id&&Rn(e))return b.get(e,"statelessSsoToken");try{return window.localStorage.getItem(this.getKey(e))}catch{return null}}static saveToken(e,t){window.localStorage.setItem(this.getKey(e),t)}static removeToken(e){window.localStorage.removeItem(this.getKey(e))}static handleRequest(e,t){if(t==="logout"){s({user:null,user_page_state:null,user_website_state:null,token:null}),Hu(e)&&qo("https://hyvor.com/account/logout");return}const r=Math.ceil(Math.random()*1e16),i=ju(Ll(e,qu(e)?"/auth/oidc":"/auth/hyvor"),{action:t,nonce:r,origin:location.origin,pageId:b.get(e,"page").id});function o(l){const a=l.data;a.nonce===r&&(window.removeEventListener("message",o),s(a))}function s(l){b.set(e,"user",l.user),Xl(e,l.user_page_state),Ql(e,l.user_website_state),l.token?Pe.saveToken(e,l.token):Pe.removeToken(e)}window.addEventListener("message",o),qo(i)}static login(e){Pe.handleRequest(e,"login")}static signup(e){Pe.handleRequest(e,"signup")}static logout(e){Pe.handleRequest(e,"logout")}}function k(n,e,t){let r=b.get(n,"language").translations[e]||"";if(t)for(const[i,o]of Object.entries(t))r=r.replace(i,o);return r}function Ll(n,e){return b.get(n,"htDomain")+"/api/embed/v3/"+b.get(n,"websiteId")+e}function Wu(n,e){return b.get(n,"htDomain")+"/api/console/v1/"+b.get(n,"websiteId")+e}const Fl="An error occurred while trying to load the comments section.";class R{static call(e){let t=e.customUrl||(e.isConsoleApi?Wu(e.context,e.endpoint):Ll(e.context,e.endpoint));e.method==="get"&&e.data&&(t+="?"+Bl(e.data));const r=new XMLHttpRequest;if(r.timeout=15e3,r.onreadystatechange=function(){if(this.readyState===4)if(e.complete&&e.complete(),this.status===200){let o;try{o=JSON.parse(this.responseText)}catch{e.error&&e.error(null)}e.success&&e.success(o)}else{let o=null;try{o=JSON.parse(this.responseText).error;const s=o.match(/t:([a-zA-Z0-9_]+)(?:\:({.+}))?/);if(s){const l=s[2]?JSON.parse(s[2]):null;o=k(e.context,s[1],l)}}catch{}e.error&&e.error(o||Fl)}},r.open(e.method.toUpperCase(),t),e.data instanceof FormData||r.setRequestHeader("Content-type","application/json;charset=UTF-8"),!e.customUrl){const o=Pe.getToken(e.context);o&&r.setRequestHeader("X-Embed-Token",o);const s=b.get(e.context,"socketId");s&&r.setRequestHeader("X-Socket-ID",s)}let i;return e.method!=="get"&&(i=e.data instanceof FormData?e.data:JSON.stringify(e.data)),r.send(i),r}static callPageApi(e){const t=b.get(e.context,"page").id;return e.endpoint=`/page/${t}`+e.endpoint,R.call(e)}}function qi(n,e){return n.id===e.id&&n.type===e.type}const Yt=E([]);function Wi(n){Yt.set([...Yt.get(),...n.map(e=>e.id)])}function $l(n){const e=typeof n=="number"?n:n.id;Yt.set(Yt.get().filter(t=>t!==e))}function Ku(n){return zt(Yt).indexOf(n.id)>=0}function Ju(n){return Yt.get()}function Gu(n,e){const t=[],r=b.get(n,"lastOnlineAt"),i=b.get(n,"user");if(r&&i){for(const o of e)!o.is_hidden&&!qi(i,o.user)&&o.created_at>r&&t.push(o);Wi(t)}}function Yu(){const n=new URLSearchParams(window.location.search).get("ht-comment-id");return n?Number(n):null}function Xu(n){const e=Yu();b.set(n,"specificCommentId",e),e&&Yi(n,e)}function Qu(n,e){if(!b.get(n,"specificCommentId")||!e.parent_id)return;const t=b.get(n,"specificCommentRepliesList"),r=e.parent_id;let i=!1;for(const s of Object.values(t))if(s.indexOf(r)>=0){i=!0;break}if(!i)return;const o=t[r]||[];t[r]=[e.id,...o],b.set(n,"specificCommentRepliesList",t)}function Vl(n,e){const t=b.get(n,"page").identifier;R.call({context:n,method:"post",endpoint:"/error/log",data:{error:e.message,stack:e.stack,page_identifier:t,page_url:window.location.href,context:{embed_app_version:""}}})}function _r(n){const e=b.get(n,"hyvorTalkElement");return e===null&&Vl(n,new Error("Called getEmbedByContext before setting the store")),e}function Ki(n){return _r(n).shadowRoot.getElementById("root")}function Ul(n,e){return Ki(n).querySelector(".comment.comment-"+e)}function jl(n,e){var t;return(t=Ul(n,e))==null?void 0:t.querySelector(".comment-inside")}function Fe(n,e,t){const r=_r(n);if(!r)return;const i=new CustomEvent(e,{detail:t,cancelable:!0});return r.dispatchEvent(i),i}class Zu{constructor(){Y(this,"stores",{})}set(e){this.stores[e.id]?this.stores[e.id].set(e):this.stores[e.id]=E(e)}get(e){return this.stores[e].get()}has(e){return!!this.stores[e]}use(e){return zt(this.stores[e]||E(null))}all(){const e={};for(const[t,r]of Object.entries(this.stores))e[Number(t)]=r.get();return e}}const Oe=new Zu;function Bt(n,e,t){const r=b.get(n,"page");b.set(n,"page",{...r,[e]:t})}function ed(n,e){b.set(n,"page",e)}function Hl(n){const e=b.use("page");if(e.is_closed)return!0;const t=O(n,"comments_view.close_after_days");return t>0&&Math.ceil(new Date().getTime()/1e3)>e.created_at+t*24*60*60}function ql(n,e,t){const r=b.get(n,"page");R.call({context:n,method:"patch",isConsoleApi:!0,endpoint:`/page/${r.id}`,data:{[e]:t}})}function td(n,e){ql(n,"is_closed",e),Bt(n,"is_closed",e)}function nd(n,e){ql(n,"is_premoderation_on",e),Bt(n,"is_premoderation_on",e)}function Ji(n){Bt(n,"comments_count",b.get(n,"page").comments_count+1)}function Gi(n){Bt(n,"comments_count",Math.max(b.get(n,"page").comments_count-1,0))}function Wl({context:n,sort:e,isMore:t,parentCommentId:r=null,onSuccess:i}){e||(e=b.get(n,"commentsSort"));const o=on(r),s=t?(b.get(n,"commentsList")[o]||[]).length:0,l={sort:e,offset:s};r&&(l.parent_comment_id=r),t&&(l.target_time=b.get(n,"commentsFirstLoadedAt")),R.callPageApi({context:n,method:"get",endpoint:"/comments",data:l,success:a=>{if(Qe(n,a.indexed),b.set(n,"commentsHasMoreIds",b.get(n,"commentsHasMoreIds").filter(c=>c!==o)),t){const c=b.get(n,"commentsList");for(const[f,h]of Object.entries(a.list)){const p=c[f]||[];for(const m of h)p.indexOf(m)<0&&p.push(m);c[f]=p}b.set(n,"commentsList",c);const u=b.get(n,"commentsHasMoreIds");u.push(...a.has_more_ids),b.set(n,"commentsHasMoreIds",u)}else b.set(n,"commentsList",a.list),b.set(n,"commentsHasMoreIds",a.has_more_ids);i&&i(a)}})}function rd(n,{body:e,parentCommentId:t=null,guestName:r=null,guestEmail:i=null},o,s){const l={body:e};t&&(l.parent_comment_id=t),r&&(l.guest_name=r),i&&(l.guest_email=i),R.callPageApi({context:n,method:"post",endpoint:"/comment",data:l,success:a=>{if(Qe(n,{[a.id]:a}),a.status!=="published")kd(n,a);else{const c={...b.get(n,"commentsList")},u=t??"PARENT",f=c[u]||[];c[u]=[a.id,...f],b.set(n,"commentsList",c),Ji(n),Qu(n,a)}o&&o(a),Fe(n,"comment:published",a)},error:a=>s&&s(a)})}function id(n,e,t,r,i){R.callPageApi({context:n,method:"post",endpoint:`/comment/${e}/edit`,data:{body:t},success:o=>{o.is_hidden||(Xt(n,o.id,"content",o.content),Xt(n,o.id,"content_html",o.content_html)),Qe(n,{[o.id]:o}),r&&r(o),Fe(n,"comment:edited",o)},error:o=>i&&i(o)})}function od(n,e){Jl(n,e),e.status==="published"&&Gi(n),R.callPageApi({context:n,method:"post",endpoint:`/comment/${e.id}/delete`,success:t=>{Fe(n,"comment:deleted",t)}})}function sd(n,e,t){R.callPageApi({context:n,method:"get",endpoint:`/comment/${e}`,success:r=>{Qe(n,{[r.id]:r}),t&&t(r)}})}function on(n){return n??"PARENT"}function vn(n){return n.parent_id??"PARENT"}function vr(n,e){Qe(n,{[e.id]:e})}function Qe(n,e){for(const t of Object.values(e))Oe.set(t);Gu(n,Object.values(e))}function Kl(n,e){const t={};e.forEach(r=>t[r.id]=r),Qe(n,t)}function wr(n,e){return Oe.get(e)}function Xt(n,e,t,r){let i=Oe.get(e);i&&(i={...i,[t]:r},Oe.set(i))}function Jl(n,e){const r=b.get(n,"commentsList")[e.id]||[];if(Qe(n,{[e.id]:ld(e)}),!r.length){const i={...b.get(n,"commentsList")},o=e.parent_id??"PARENT",s=i[o]||[];i[o]=s.filter(l=>l!==e.id),b.set(n,"commentsList",i)}_d(n,e.id)}function ld(n){return{id:n.id,is_hidden:!0,page_id:n.page_id,parent_id:n.parent_id,depth:n.depth,created_at:n.created_at}}function Gl(n,e,t=!1){const r=b.get(n,"commentsList")[e]||[];let i=0;return r.forEach(o=>{i++,t&&(i+=Gl(n,o,t))}),i}function Yl(n,e){const t=b.get(n,"commentsList");for(const r of Object.values(t))if(r.indexOf(e)>=0)return!0;return!1}function Cr(n,e,t,r,i){R.call({context:n,method:"patch",isConsoleApi:!0,endpoint:`/comment/${e}`,data:{[t]:r},success:()=>{i&&i()}})}function Wo(n,e,t){Cr(n,e.id,"status",t),Jl(n,e),!e.is_hidden&&e.status==="published"&&Gi(n)}function ad(n,e,t){Cr(n,e,"is_featured",t),Xt(n,e,"is_featured",t)}function cd(n,e,t){Cr(n,e,"is_loved",t),Xt(n,e,"is_loved",t)}function ud(n,e){Ji(n),Wi([e]),vr(n,e);const t={...b.get(n,"commentsList")},r=vn(e),i=t[r]||[];i.indexOf(e.id)>=0||(t[r]=[e.id,...i],b.set(n,"commentsList",t))}function dd(n,e){const t=wr(n,e.id);(!t.is_hidden&&e.is_hidden||!t.is_hidden&&t.status==="published"&&!e.is_hidden&&e.status!=="published")&&Gi(n),(t.is_hidden&&!e.is_hidden||!t.is_hidden&&t.status!=="published"&&!e.is_hidden&&e.status==="published")&&Ji(n),vr(n,e)}function fd(n){const e=b.use("commentsBroadcasted");let t=0;for(const r of e)vn(r)===n&&t++;return t}function hd(n,e){const t=b.get(n,"commentsBroadcasted"),r=t.filter(s=>vn(s)===e),i=r.map(s=>s.id),o={...b.get(n,"commentsList")};o[e]=[...i,...o[e]||[]],b.set(n,"commentsList",o),b.set(n,"commentsBroadcasted",t.filter(s=>vn(s)!==e)),Wi(r)}function pd(n,e){const t=b.get(n,"commentsBroadcasted").find(o=>o.id===e);if(!t)return!1;const r={...b.get(n,"commentsList")},i=vn(t);return r[i]=[e,...r[i]||[]],b.set(n,"commentsList",r),b.set(n,"commentsBroadcasted",b.get(n,"commentsBroadcasted").filter(o=>o.id!==e)),!0}function md(n,e){const t=Yl(n,e),r=pd(n,e);return!t&&!r?!1:(Yi(n,e),!0)}function Yi(n,e){b.set(n,"flashingCommentId",e),setTimeout(()=>{b.set(n,"flashingCommentId",null)},3e3)}function gd(n){var t;const e=(t=_r(n).shadowRoot)==null?void 0:t.querySelector(".comment.flashing");e&&e.scrollIntoView(!0)}function bd(n,e){const t=Oe.all(),[r,i]=n.split("_");return Object.values(t).filter(o=>e?"user"in o&&o.user.id===Number(i)&&o.user.type===r:"blocked_user_htid"in o&&o.blocked_user_htid===n).map(o=>o.id)}function yd(n,e){for(const t of e)Oe.set(t);b.set(n,"userHiddenComments",e.map(t=>({id:t.id,parent_id:t.parent_id})))}function xd(n,e){const t=b.use("userHiddenComments"),r=[];for(const i of t)on(i.parent_id)===n&&e.indexOf(i.id)===-1&&r.push(i.id);return r}function kd(n,e){b.set(n,"userHiddenComments",[{id:e.id,parent_id:e.parent_id},...b.get(n,"userHiddenComments")])}function _d(n,e){b.set(n,"userHiddenComments",b.get(n,"userHiddenComments").filter(t=>t.id!==e))}const vd={hyvorTalkElement:()=>E(null),htDomain:()=>E(null),components:()=>E({}),colors:()=>E("light"),palette:()=>E({}),websiteId:()=>E(0),website:()=>E({}),page:()=>E({}),language:()=>E({}),notifsCount:()=>E(0),reactions:({page:n})=>zr(n,e=>e.reactions),ratings:({page:n})=>zr(n,e=>e.ratings),commentsCount:({page:n})=>zr(n,e=>e.comments_count),commentsView:()=>E("comments"),commentsSort:()=>E("newest"),commentsFirstLoadedAt:()=>E(0),commentsList:()=>E({PARENT:[]}),commentsHasMoreIds:()=>E([]),commentsBroadcasted:()=>E([]),specificCommentId:()=>E(null),specificCommentRepliesList:()=>E({PARENT:[]}),specificCommentHasMoreIds:()=>E([]),focusedCommentId:()=>E(null),flashingCommentId:()=>E(null),badges:()=>E([]),pageBadges:()=>E({}),plans:()=>E([]),typing:()=>E({PARENT:[]}),user:()=>E(null),userReaction:()=>E(null),userRating:()=>E(null),userVotes:()=>E({}),userFlags:()=>E([]),userBlocked:()=>E([]),userIsMod:()=>E(!1),userIsShadowBanned:()=>E(!1),userBan:()=>E(null),userMembershipSubscription:()=>E(null),userHiddenComments:()=>E([]),lastOnlineAt:()=>E(null),statelessSsoToken:()=>E(null),socketId:()=>E(""),profilePopupUser:()=>E(null),modalImageUrl:()=>E(null),license:()=>E({}),hooks:()=>E({})};function wd(){const n={};function e(s){if(!n[s]){const l={};for(const[a,c]of Object.entries(vd))l[a]=c(l);n[s]=l}return n[s]}function t(s,l){return e(s)[l]}function r(s){const l=M(),a=t(l,s);return zt(a)}function i(s,l,a){t(s,l).set(a)}function o(s,l){return t(s,l).get()}return{getStore:t,use:r,set:i,get:o}}const b=wd();function Xl(n,e){b.set(n,"lastOnlineAt",e?e.last_online:null),b.set(n,"userReaction",e?e.reaction:null),b.set(n,"userRating",e?e.rating:null),b.set(n,"userVotes",e?e.votes:{}),b.set(n,"userFlags",e?e.flags:[]),yd(n,e?e.hidden_comments:[])}function Ql(n,e){b.set(n,"notifsCount",e?e.notifs_count:0),b.set(n,"userIsMod",e?e.is_mod:!1),b.set(n,"userIsShadowBanned",e?e.is_shadow_banned:!1),b.set(n,"userBan",e?e.ban:null),b.set(n,"userMembershipSubscription",e?e.membership_subscription:null)}function Cd(n,e){return{reload:e,page:()=>b.get(n,"page"),auth:{user:()=>b.get(n,"user"),logout:()=>{Pe.logout(n)}}}}const Sd=function(){const e=typeof document<"u"&&document.createElement("link").relList;return e&&e.supports&&e.supports("modulepreload")?"modulepreload":"preload"}(),Md=function(n){return"/"+n},Ko={},Xi=function(e,t,r){let i=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const s=document.querySelector("meta[property=csp-nonce]"),l=(s==null?void 0:s.nonce)||(s==null?void 0:s.getAttribute("nonce"));i=Promise.allSettled(t.map(a=>{if(a=Md(a),a in Ko)return;Ko[a]=!0;const c=a.endsWith(".css"),u=c?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="proxy.php?url=${a}"]${u}`))return;const f=document.createElement("link");if(f.rel=c?"stylesheet":Sd,c||(f.as="script"),f.crossOrigin="",f.href=a,l&&f.setAttribute("nonce",l),document.head.appendChild(f),c)return new Promise((h,p)=>{f.addEventListener("load",h),f.addEventListener("error",()=>p(new Error(`Unable to preload CSS for ${a}`)))})}))}function o(s){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=s,window.dispatchEvent(l),!l.defaultPrevented)throw s}return i.then(s=>{for(const l of s||[])l.status==="rejected"&&o(l.reason);return e().catch(o)})},Zl=(n,e,t)=>{const r={...b.get(n,"userVotes")};r[e]&&!t?delete r[e]:t&&(r[e]=t),b.set(n,"userVotes",r)},Od=(n,e,t)=>{R.callPageApi({context:n,method:"post",endpoint:`/comment/${e}/vote`,data:{type:t},success:()=>{Fe(n,"comment:voted",{comment:wr(n,e),vote:t})}})},ea=15,Jo={PARENT:0};function Nd(n,e){if(!e)return;const t=on(e),r=Jo[t],i=Math.ceil(new Date().getTime()/1e3);(!r||rs.socket_id===e.socket_id)||{socket_id:e.socket_id};o.at=e.at,o.user=e.user,r[t]=[...i,o],setTimeout(()=>{Td(n,e.comment_id,e.socket_id)},ea*1e3)}else r[t]=i.filter(o=>o.socket_id!==e.socket_id);b.set(n,"typing",r)}function Td(n,e,t){const r=b.get(n,"typing"),i=on(e);r[i]=(r[i]||[]).filter(o=>o.socket_id!==t),b.set(n,"typing",r)}function ta(n,e,t){R.callPageApi({context:n,method:"post",endpoint:"/online/typing",data:{comment_id:e,status:t}})}const na=E({}),Ht=new Map,Br=new Map;function Yo(n,e,t){Ht.has(n)||Ht.set(n,[]);const r=Ht.get(n)||[];Ht.set(n,[...r,{id:e,type:t}]),ra(n)}function Id(n){const e=Ht.get(n);if(!e)return;e.length>100&&ra(n);const t=e.slice(0,100);t.length!==0&&(Ht.set(n,e.filter(r=>!t.includes(r))),R.callPageApi({context:n,method:"post",endpoint:"/comments/ids",data:{ids:t.map(r=>r.id)},success:r=>{t.forEach(({id:i,type:o})=>{const s=r.find(l=>l.id===i);s&&(o==="create"?ud(n,s):o==="update"&&dd(n,s))})}}))}function ra(n){Br.has(n)&&clearTimeout(Br.get(n)),Br.set(n,setTimeout(()=>{Id(n)},5e3))}const ia={};function Dd(n){return ia[n]}class Ad{constructor(e){Y(this,"context");Y(this,"pageChannel");Y(this,"userChannel");Y(this,"client",null);this.context=e,O(this.context,"realtime.on")&&(Xi(()=>import("./comments-pusher.js"),[]).then(t=>{const r=na.get().services.pusher;this.client=new t.default(r.app_key,{wsHost:r.host,wsPort:r.port,forceTLS:!1,disableStats:!0,enabledTransports:["ws","wss"]}),this.client.connection.bind("connected",()=>{var i;b.set(this.context,"socketId",((i=this.client)==null?void 0:i.connection.socket_id)||"")}),this.pageChannel=this.client.subscribe("page."+b.get(this.context,"page").id),b.getStore(e,"user").subscribe(i=>{this.setUserChannel(i)}),this.subscribePageEvent("online_count",i=>Bt(this.context,"online_count",i.count)),this.subscribePageEvent("comment.created",i=>Yo(this.context,i.id,"create")),this.subscribePageEvent("comment.updated",i=>Yo(this.context,i.id,"update")),this.subscribePageEvent("typing",i=>Ed(this.context,i)),this.subscribePageEvent("page.updated",i=>{ed(this.context,i)})}),ia[e]=this)}setUserChannel(e){this.client&&(this.userChannel&&this.client.unsubscribe(this.userChannel.name),e&&(this.userChannel=this.client.subscribe(`user.${e.type}.${e.id}`),this.subscribeUserEvent("voted",t=>t.page_id===b.get(this.context,"page").id&&Zl(this.context,t.comment_id,t.type)),this.subscribeUserEvent("notification",t=>t.website_id===b.get(this.context,"websiteId")&&b.set(this.context,"notifsCount",b.get(this.context,"notifsCount")+1)),this.subscribeUserEvent("reacted",t=>t.page_id===b.get(this.context,"page").id&&b.set(this.context,"userReaction",t.reaction))))}subscribeUserEvent(e,t){this.userChannel&&this.userChannel.bind(e,t)}subscribePageEvent(e,t){this.pageChannel&&this.pageChannel.bind(e,t)}disconnect(){var e;(e=this.client)==null||e.disconnect()}}class Rd{constructor(){Y(this,"ui",{});Y(this,"light_palette",{});Y(this,"dark_palette",{});Y(this,"stylesheet",null);Y(this,"current",{mode:"light"})}setFromConfig(e,t,r){this.ui=e.ui,this.light_palette=e.light_palette,this.dark_palette=e.dark_palette,t!=="os"&&t!=="light"&&t!=="dark"&&(t=e.ui.color_theme),this.setStyles(t,r)}setStyles(e,t){let r;window.hyvorTalkStyles?r=window.hyvorTalkStyles:(r=this,window.hyvorTalkStyles=r),r.stylesheet&&document.head.removeChild(r.stylesheet);let i=e||"light";i==="os"&&(i=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");const o=i==="dark"?r.dark_palette:r.light_palette,s=document.createElement("style");s.textContent=`:root { --ht-color-text: ${o.text}; --ht-color-accent: ${o.accent}; --ht-color-accent-text: ${o.accent_text}; --ht-color-box: ${o.box}; --ht-color-box-text: ${o.box_text}; --ht-color-box-text-light: ${o.box_text_light}; --ht-color-input: ${o.input}; /* accent variations */ --ht-color-accent-35: color-mix(in srgb, var(--ht-color-accent) 35%, transparent); --ht-color-accent-15: color-mix(in srgb, var(--ht-color-accent) 15%, transparent); --ht-color-accent-5: color-mix(in srgb, var(--ht-color-accent) 5%, transparent); --ht-box-shadow: ${r.ui.box_shadow}; --ht-box-radius: ${r.ui.box_radius}; --ht-box-border: ${r.ui.box_border_size} solid ${r.ui.box_border_color}; --ht-button-radius: ${r.ui.button_radius}; --ht-color-danger: #ab2525; --ht-color-success: #5d995d; --ht-color-info: #5875b9; --ht-color-warning: #8b5b04; }`,document.head.append(s),r.stylesheet=s,this.current={mode:i},t&&b.set(t,"colors",this.current.mode)}}const Xo=new Rd;function Pd({size:n}){const e={small:16,medium:24,large:30}[n];return d("span",{class:"loader-spinner",style:{width:e,height:e,borderWidth:{small:2,medium:3,large:3}[n]}})}const ee={star:n=>d("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",...n,children:d("path",{d:"M12 .587l3.668 7.568 8.332 1.151-6.064 5.828 1.48 8.279-7.416-3.967-7.417 3.967 1.481-8.279-6.064-5.828 8.332-1.151z"})}),heart:()=>d("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:d("path",{d:"M12 4.435c-1.989-5.399-12-4.597-12 3.568 0 4.068 3.06 9.481 12 14.997 8.94-5.516 12-10.929 12-14.997 0-8.118-10-8.999-12-3.568z"})}),caret:()=>d("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 105.83 105.83",children:[d("path",{d:"M1.743 29.457a5.82 5.82 0 0 1 8.217-.676l46.446 39.381a5.82 5.82 0 1 1-7.541 8.894L2.42 37.674a5.82 5.82 0 0 1-.676-8.217z",paintOrder:"stroke fill markers"}),d("path",{d:"M104.09 29.456a5.82 5.82 0 0 0-8.217-.676L49.428 68.16a5.82 5.82 0 1 0 7.541 8.894l46.445-39.381a5.82 5.82 0 0 0 .676-8.217z",paintOrder:"stroke fill markers"})]}),thumbsUp:()=>d("svg",{xmlns:"http://www.w3.org/2000/svg",width:200,height:200,viewBox:"0 0 52.917 52.917",children:d("path",{d:"M12.06 22.283l-4.395.066-3.057.066-1.059.044-.355.022-.191.027a1.48 1.48 0 0 0-.18.044c-.045.013-.101.027-.186.066a2.76 2.76 0 0 0-.153.082 36.79 36.79 0 0 1-.235.18 2 2 0 0 0-.535.939 3.92 3.92 0 0 0-.098.808l-.027 2.97v11.95l.027 2.97v.006c.014.289.029.523.098.802.083.332.266.684.535.939.481.456 1.077.538 1.512.568.427.029.954.027 1.818.027h6.496l1.818-.027c.436-.029 1.031-.112 1.512-.568.268-.255.458-.609.54-.939a3.92 3.92 0 0 0 .098-.808l.022-2.97v-11.95l-.022-2.97c-.014-.288-.029-.528-.098-.808a1.98 1.98 0 0 0-.535-.933v-.005c-.466-.442-1.063-.537-1.512-.568-.443-.03-.966-.027-1.823-.027h-.005zm.016 2.795l1.179.011.016 2.506v11.95l-.016 2.5-1.179.016H5.58c-.617 0-.879-.008-1.174-.016l-.022-2.5v-11.95L4.4 25.22l.289-.011 3.024-.065 4.362-.066zM33.22 4.306c-.564.046-1.118.357-1.425.584-1.29.954-1.945 2.527-2.451 4.656-.708 2.98-.934 3.558-1.458 4.203l-5.415 6.524c-.942 1.029-1.074 1.083-1.67 1.365-.415.196-.869.32-1.398.786s-.841 1.202-.972 1.971c-.262 1.537-.202 3.837-.202 8.909l.169 8.898c.089.758.198 1.363.655 1.938s1.139.76 1.474.835c1.635.368 2.372.578 4.94 1.408 3.403 1.1 5.142 1.563 7.299 1.932 1.175.201 2.91.285 4.624.3l.524.006.044-.038c1.441.002 2.815-.002 3.734-.197 3.466-.735 5.857-3.486 5.868-6.906.001-.404.031-.669.049-.753s.004.088-.218.273c1.282-1.064 1.721-2.758 1.78-4.749.034-1.16.154-1.671.338-2.053.715-1.478.94-3.168.551-4.711l-.082-.338c-.004.019.101-.254.442-.857.69-1.22.906-2.09.906-3.63 0-.682-.142-1.259-.267-1.676l-.158-.48c-.035-.103.011-.351.011.213 0-.665-.157-.706-.246-.868a4.56 4.56 0 0 0-.289-.453c-.214-.302-.481-.628-.775-.955-.793-.882-1.681-1.629-2.92-1.949s-2.683-.333-5.164-.333c-1.006 0-1.509-.017-2.102-.033l.229-.497c.875-1.81 1.388-3.258 1.119-5.546l.011.164-.104-2.74c-.117-.696-.403-1.247-.726-1.818-1.01-1.788-2.732-2.856-5.006-3.226-.72-.117-1.155-.204-1.72-.158zm.229 2.784c-.004 0 .346.023 1.043.136 1.809.295 2.349.654 3.019 1.84.311.552.355.612.404.906s.066.951.066 2.276v.082l.011.082c.219 1.865-.011 2.241-.863 4.001l-.726 1.572-.24.584-.087.246c-.028.09-.082.095-.082.502 0 .386.187.76.366.961a1.43 1.43 0 0 0 .459.349c.24.121.382.146.524.175.284.057.552.077.912.098l3.265.055c2.45 0 3.785.07 4.466.246s.853.338 1.545 1.108a8.49 8.49 0 0 1 .568.704l.12.18c.019.026.03.174.044.213l.126.388c.082.274.147.588.147.868 0 1.463.091 1.127-.546 2.255-.351.622-.602 1.019-.737 1.621s-.014 1.164.104 1.632c.185.734.061 1.941-.36 2.811s-.578 1.86-.617 3.188c-.046 1.562-.497 2.454-.77 2.68-.455.378-.637.872-.726 1.288s-.113.83-.115 1.332c-.008 2.251-1.185 3.659-3.652 4.182-.395.084-2.074.184-3.701.169s-3.368-.118-4.176-.257c-2.022-.346-3.546-.753-6.906-1.84l-5.104-1.452c.017.01.001.026-.049-.399-.131-1.117-.153-3.664-.153-8.571l.164-8.445.066-.338c-.021.019.22-.108.742-.355.735-.348 1.478-.846 2.538-2.003l5.525-6.655c.859-1.059 1.28-2.274 2.003-5.317.439-1.846 1.039-2.79 1.392-3.052.216-.159-.002-.049-.005-.049z",dominantBaseline:"auto"})}),thumbsDown:()=>d("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 52.917 52.917",children:d("path",{d:"M12.06 30.634l-4.395-.066-3.057-.066-1.059-.044-.355-.022-.191-.027a1.48 1.48 0 0 1-.18-.044c-.045-.013-.101-.027-.186-.066a2.76 2.76 0 0 1-.153-.082 36.79 36.79 0 0 0-.235-.18 2 2 0 0 1-.535-.939 3.92 3.92 0 0 1-.098-.808l-.027-2.97V13.37l.027-2.97v-.006c.014-.289.029-.523.098-.802.083-.332.266-.684.535-.939.481-.456 1.077-.538 1.512-.568.427-.029.954-.027 1.818-.027h6.496l1.818.027c.436.029 1.031.112 1.512.568.268.255.458.609.54.939a3.92 3.92 0 0 1 .098.808l.022 2.97v11.95l-.022 2.97c-.014.288-.029.528-.098.808a1.98 1.98 0 0 1-.535.933v.005c-.466.442-1.063.537-1.512.568-.443.03-.966.027-1.823.027h-.005zm.016-2.795l1.179-.011.016-2.506v-11.95l-.016-2.5-1.179-.016H5.58l-1.174.016-.022 2.5v11.95l.016 2.375.289.011 3.024.065 4.362.066zM33.22 48.611c-.564-.046-1.118-.357-1.425-.584-1.29-.954-1.945-2.527-2.451-4.656-.708-2.98-.934-3.558-1.458-4.203l-5.415-6.524c-.942-1.029-1.074-1.083-1.67-1.365-.415-.196-.869-.32-1.398-.786s-.841-1.202-.972-1.971c-.262-1.537-.202-3.837-.202-8.909l.169-8.898c.089-.758.198-1.363.655-1.938s1.139-.76 1.474-.835c1.635-.368 2.372-.578 4.94-1.408 3.403-1.1 5.142-1.563 7.299-1.932 1.175-.201 2.91-.285 4.624-.3l.524-.006.044.038c1.441-.002 2.815.002 3.734.197 3.466.735 5.857 3.486 5.868 6.906.001.404.031.669.049.753s.004-.088-.218-.273c1.282 1.064 1.721 2.758 1.78 4.749.034 1.16.154 1.671.338 2.053.715 1.478.94 3.168.551 4.711l-.082.338c-.004-.019.101.254.442.857.69 1.22.906 2.09.906 3.63 0 .682-.142 1.259-.267 1.676l-.158.48c-.035.103.011.351.011-.213 0 .665-.157.706-.246.868a4.56 4.56 0 0 1-.289.453c-.214.302-.481.628-.775.955-.793.882-1.681 1.629-2.92 1.949s-2.683.333-5.164.333l-2.102.033.229.497c.875 1.81 1.388 3.258 1.119 5.546l.011-.164-.104 2.74c-.117.696-.403 1.247-.726 1.818-1.01 1.788-2.732 2.856-5.006 3.226-.72.117-1.155.204-1.72.158zm.229-2.784c-.004 0 .346-.023 1.043-.136 1.809-.295 2.349-.654 3.019-1.84.311-.552.355-.612.404-.906s.066-.951.066-2.276v-.082l.011-.082c.219-1.865-.011-2.241-.863-4.001l-.726-1.572-.24-.584-.087-.246c-.028-.09-.082-.095-.082-.502 0-.386.187-.76.366-.961a1.43 1.43 0 0 1 .459-.349c.24-.121.382-.146.524-.175.284-.057.552-.077.912-.098l3.265-.055c2.45 0 3.785-.07 4.466-.246s.853-.338 1.545-1.108a8.49 8.49 0 0 0 .568-.704l.12-.18c.019-.026.03-.174.044-.213l.126-.388c.082-.274.147-.588.147-.868 0-1.463.091-1.127-.546-2.255-.351-.622-.602-1.019-.737-1.621s-.014-1.164.104-1.632c.185-.734.061-1.941-.36-2.811s-.578-1.86-.617-3.188c-.046-1.562-.497-2.454-.77-2.68-.455-.378-.637-.872-.726-1.288s-.113-.83-.115-1.332c-.008-2.251-1.185-3.659-3.652-4.182-.395-.084-2.074-.184-3.701-.169s-3.368.118-4.176.257c-2.022.346-3.546.753-6.906 1.84l-5.104 1.452c.017-.01.001-.026-.049.399-.131 1.117-.153 3.664-.153 8.571l.164 8.445.066.338c-.021-.019.22.108.742.355.735.348 1.478.846 2.538 2.003l5.525 6.655c.859 1.059 1.28 2.274 2.003 5.317.439 1.846 1.039 2.79 1.392 3.052.216.159-.002.049-.005.049z",dominantBaseline:"auto"})}),thumbsUpActive:()=>d("svg",{viewBox:"0 0 33.867 33.867",xmlns:"http://www.w3.org/2000/svg",children:d("g",{transform:"translate(0 -244.08)",children:d("path",{d:"m20.457 275.96c-1.5247-0.26113-2.7181-0.57778-5.1853-1.3758-1.8822-0.60878-2.4846-0.78039-3.6956-1.0529-0.8605-0.19365-0.8797-0.35787-0.8797-7.5208 0-7.4101-0.07864-6.9469 1.2894-7.594 0.97126-0.45949 1.2861-0.80315 5.5285-6.0338 0.50421-0.62168 0.74363-1.2792 1.266-3.4771 0.34479-1.4507 0.80203-2.3677 1.4017-2.8111 0.38162-0.28217 0.49151-0.29102 1.5251-0.12275 1.4897 0.24254 2.315 0.76367 2.9278 1.8487 0.4627 0.8193 0.47371 0.88492 0.47371 2.8236 0.17821 1.5156-0.09467 2.1806-0.72442 3.4832-0.39843 0.82413-0.72443 1.5781-0.72444 1.6755-1.6e-5 0.12841 0.82739 0.17704 3.0121 0.17704 3.5985 0 4.0594 0.11866 5.143 1.3238 0.3798 0.42244 0.69054 0.86358 0.69054 0.98033s0.30502 0.71575 0.30502 1.4177c0 1.0956-0.04852 1.2913-0.53275 2.148-0.50516 0.89371-0.52388 0.97777-0.36147 1.6228 0.20918 0.83073 0.08061 1.886-0.33419 2.7428-0.2218 0.45818-0.32146 1.006-0.34818 1.9137-0.03815 1.2963-0.36164 2.2408-0.92867 2.7114-0.16963 0.14078-0.24089 0.47287-0.24326 1.1336-0.0074 2.069-1.3088 3.5833-3.4738 4.0422-1.0616 0.22502-4.6837 0.19202-6.131-0.0558zm-17.504-16.975c-0.62703 0-1.0101 6.1e-4 -1.2602 0.0176-0.25007 0.0169-0.38206 0.0533-0.4715 0.13814-0.044719 0.0424-0.080509 0.10302-0.10245 0.19083-0.021937 0.0878-0.034387 0.20722-0.0432 0.391-0.017627 0.36759-0.018515 0.99443-0.018515 2.1178v8.7227c0 1.1233 8.847e-4 1.7502 0.018515 2.1178 0.00881 0.18378 0.021262 0.30322 0.0432 0.39101 0.021938 0.0878 0.057711 0.14844 0.10245 0.19082 0.089447 0.0847 0.22143 0.1212 0.4715 0.13814 0.25006 0.0169 0.63319 0.0164 1.2602 0.0164h4.7372c0.62703 0 1.0102 5.4e-4 1.2602-0.0164 0.25005-0.0169 0.38212-0.0546 0.4715-0.13931 0.044687-0.0424 0.080536-0.10187 0.10245-0.18965 0.02191-0.0878 0.034402-0.20723 0.043203-0.39101 0.017603-0.36756 0.018515-0.99442 0.018515-2.1178v-8.7227c0-1.1234-8.846e-4 -1.7502-0.018515-2.1178-0.00885-0.18378-0.021293-0.3032-0.043203-0.391s-0.057777-0.14841-0.10245-0.19083c-0.089363-0.0849-0.22145-0.12118-0.4715-0.13814-0.25005-0.017-0.63319-0.0176-1.2602-0.0176z"})})}),thumbsDownActive:()=>d("svg",{viewBox:"0 0 33.867 33.867",xmlns:"http://www.w3.org/2000/svg",children:d("path",{d:"m20.457 1.987c-1.5247 0.26113-2.7181 0.57778-5.1853 1.3758-1.8822 0.60878-2.4846 0.78039-3.6956 1.0529-0.8605 0.19365-0.87971 0.35787-0.87971 7.5208 0 7.4101-0.0786 6.9469 1.2894 7.594 0.97126 0.45949 1.2861 0.80315 5.5285 6.0338 0.50421 0.62168 0.74363 1.2792 1.266 3.4771 0.34479 1.4507 0.80203 2.3677 1.4017 2.8111 0.38162 0.28217 0.49151 0.29102 1.5251 0.12275 1.4897-0.24254 2.315-0.76367 2.9278-1.8487 0.4627-0.8193 0.47371-0.88492 0.47371-2.8236 0.17821-1.5156-0.0947-2.1806-0.72442-3.4832-0.39843-0.82413-0.72443-1.5781-0.72445-1.6755-1e-5 -0.12841 0.8274-0.17704 3.0121-0.17704 3.5984 0 4.0594-0.11866 5.143-1.3238 0.3798-0.42244 0.69054-0.86358 0.69054-0.98033s0.30502-0.71575 0.30502-1.4177c0-1.0956-0.0485-1.2913-0.53275-2.148-0.50515-0.89371-0.52388-0.97777-0.36147-1.6228 0.20918-0.83073 0.0806-1.886-0.33419-2.7428-0.2218-0.45818-0.32146-1.006-0.34818-1.9137-0.0382-1.2963-0.36164-2.2408-0.92867-2.7114-0.16963-0.14078-0.24089-0.47287-0.24326-1.1336-7e-3 -2.069-1.3088-3.5833-3.4738-4.0422-1.0616-0.22502-4.6837-0.19202-6.131 0.0558zm-17.504 16.975c-0.62703 0-1.0101-6.1e-4 -1.2602-0.0176-0.25008-0.0169-0.38207-0.0533-0.4715-0.13814-0.0447-0.0424-0.0805-0.10302-0.10245-0.19083-0.0219-0.0878-0.0344-0.20722-0.0432-0.391-0.0176-0.36759-0.0185-0.99443-0.0185-2.1178v-8.7227c0-1.1233 8.8e-4 -1.7502 0.0185-2.1178 9e-3 -0.18378 0.0213-0.30322 0.0432-0.39101 0.0219-0.0878 0.0577-0.14844 0.10245-0.19082 0.0894-0.0847 0.22143-0.1212 0.4715-0.13814 0.25006-0.0169 0.63319-0.0164 1.2602-0.0164h4.7372c0.62703 0 1.0102-5.3e-4 1.2602 0.0164 0.25004 0.0169 0.38212 0.0546 0.4715 0.13931 0.0447 0.0424 0.0805 0.10187 0.10244 0.18965 0.0219 0.0878 0.0344 0.20723 0.0432 0.39101 0.0176 0.36756 0.0185 0.99442 0.0185 2.1178v8.7227c0 1.1234-8.7e-4 1.7502-0.0185 2.1178-9e-3 0.18378-0.0213 0.3032-0.0432 0.391s-0.0578 0.14841-0.10244 0.19083c-0.0894 0.0849-0.22145 0.12118-0.4715 0.13814-0.25005 0.017-0.63319 0.0176-1.2602 0.0176z"})}),link:()=>d("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 16 16",children:d("path",{fillRule:"evenodd",d:"M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"})}),bold:()=>d("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 16 16",children:d("path",{fillRule:"evenodd",d:"M4 2a1 1 0 00-1 1v10a1 1 0 001 1h5.5a3.5 3.5 0 001.852-6.47A3.5 3.5 0 008.5 2H4zm4.5 5a1.5 1.5 0 100-3H5v3h3.5zM5 9v3h4.5a1.5 1.5 0 000-3H5z"})}),italic:()=>d("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 16 16",children:d("path",{fillRule:"evenodd",d:"M6 2.75A.75.75 0 016.75 2h6.5a.75.75 0 010 1.5h-2.505l-3.858 9H9.25a.75.75 0 010 1.5h-6.5a.75.75 0 010-1.5h2.505l3.858-9H6.75A.75.75 0 016 2.75z"})}),quote:()=>d("svg",{viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg",children:d("g",{children:[d("path",{d:"m7.3792 5.8233q0.38363 2.0672-0.94531 4.5398-1.3258 2.4896-3.5444 4.0406l-0.9688-1.0647q0.7485-0.59463 1.3828-1.2382 0.6512-0.64668 1.1015-1.4314 0.46097-0.82171 0.66149-1.6301 0.22061-0.79463 0.10723-1.8778l-0.94887 0.17609q-1.7283 0.32074-2.754-0.29517-1.0257-0.61591-1.2804-1.9884-0.20125-1.0844 0.48558-2.1058 0.68369-1.0383 1.9206-1.2679 1.8977-0.35218 3.1226 0.77013 1.2387 1.1022 1.66 3.3727z"}),d("path",{d:"m15.769 5.8233q0.38363 2.0672-0.94531 4.5398-1.3258 2.4896-3.5444 4.0406l-0.9688-1.0647q0.7485-0.59463 1.3828-1.2382 0.6512-0.64668 1.1015-1.4314 0.46097-0.82171 0.66149-1.6301 0.22061-0.79463 0.10723-1.8778l-0.94887 0.17609q-1.7283 0.32074-2.754-0.29517-1.0257-0.61591-1.2804-1.9884-0.20125-1.0844 0.48558-2.1058 0.68369-1.0383 1.9206-1.2679 1.8977-0.35218 3.1226 0.77013 1.2387 1.1022 1.66 3.3727z"})]})}),emoji:()=>d("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 16 16",children:d("path",{fillRule:"evenodd",d:"M1.5 8a6.5 6.5 0 1113 0 6.5 6.5 0 01-13 0zM8 0a8 8 0 100 16A8 8 0 008 0zM5 8a1 1 0 100-2 1 1 0 000 2zm7-1a1 1 0 11-2 0 1 1 0 012 0zM5.32 9.636a.75.75 0 011.038.175l.007.009c.103.118.22.222.35.31.264.178.683.37 1.285.37.602 0 1.02-.192 1.285-.371.13-.088.247-.192.35-.31l.007-.008a.75.75 0 111.222.87l-.614-.431c.614.43.614.431.613.431v.001l-.001.002-.002.003-.005.007-.014.019a1.984 1.984 0 01-.184.213c-.16.166-.338.316-.53.445-.63.418-1.37.638-2.127.629-.946 0-1.652-.308-2.126-.63a3.32 3.32 0 01-.715-.657l-.014-.02-.005-.006-.002-.003v-.002h-.001l.613-.432-.614.43a.75.75 0 01.183-1.044h.001z"})}),image:()=>d("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 16 16",children:d("path",{fillRule:"evenodd",d:"M1.75 2.5a.25.25 0 00-.25.25v10.5c0 .138.112.25.25.25h.94a.76.76 0 01.03-.03l6.077-6.078a1.75 1.75 0 012.412-.06L14.5 10.31V2.75a.25.25 0 00-.25-.25H1.75zm12.5 11H4.81l5.048-5.047a.25.25 0 01.344-.009l4.298 3.889v.917a.25.25 0 01-.25.25zm1.75-.25V2.75A1.75 1.75 0 0014.25 1H1.75A1.75 1.75 0 000 2.75v10.5C0 14.216.784 15 1.75 15h12.5A1.75 1.75 0 0016 13.25zM5.5 6a.5.5 0 11-1 0 .5.5 0 011 0zM7 6a2 2 0 11-4 0 2 2 0 014 0z"})}),gif:()=>d("svg",{viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg",children:[d("path",{d:"m1.1426 1c-0.63314 0-1.1426 0.446-1.1426 1v12c0 0.554 0.50942 1 1.1426 1h13.715c0.63314 0 1.1426-0.446 1.1426-1v-12c0-0.554-0.50942-1-1.1426-1h-13.715zm0.64258 1.3125h12.43c0.15829 0 0.28516 0.1115 0.28516 0.25v10.875c0 0.1385-0.12687 0.25-0.28516 0.25h-12.43c-0.15829 0-0.28516-0.1115-0.28516-0.25v-10.875c0-0.1385 0.12687-0.25 0.28516-0.25z"}),d("path",{d:"m5.0742 5.3145c-0.48419 0-0.90166 0.084406-1.2441 0.26172-0.43632 0.22436-0.77418 0.55423-1.002 0.97656-0.2268 0.42052-0.33984 0.90137-0.33984 1.4316 0 0.4898 0.10137 0.94769 0.30273 1.3691 0.20408 0.42477 0.51524 0.75957 0.92188 0.99023 0.4066 0.22827 0.88168 0.3418 1.4141 0.3418 0.42164 0 0.83853-0.08081 1.2461-0.23828 0.40542-0.15804 0.72429-0.34104 0.95312-0.5625l0.050781-0.050781v-2.1797h-2.457v1.1602h0.16992 0.95508v0.34961c-0.12229 0.086475-0.25678 0.16785-0.42578 0.23438v-0.0019531c-0.1879 0.072736-0.37093 0.10938-0.55469 0.10938-0.37662 0-0.65663-0.12152-0.88281-0.375-0.21941-0.24778-0.3418-0.63541-0.3418-1.1875-1e-7 -0.50772 0.1203-0.86245 0.33398-1.0938v-0.0019532c0.22153-0.23596 0.50827-0.35352 0.90039-0.35352 0.25521 0 0.45028 0.060755 0.60547 0.17578l0.0019531 0.0019531c0.16008 0.1154 0.26478 0.26557 0.32422 0.47266l0.041016 0.14844 1.3008-0.24219-0.037109-0.17188c-0.10469-0.4806-0.34965-0.87232-0.72266-1.1484-0.37711-0.28285-0.88672-0.41602-1.5137-0.41602zm2.8379 0.083984v5.2031h0.16992 1.1523v-5.2031h-1.3223zm1.9258 0v5.2031h0.16992 1.1523v-2.0664h2.0293v-1.1621h-2.0293v-0.8125h2.3516v-1.1621h-3.6738z"})]}),bell:()=>d("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 16 16",children:d("path",{d:"M8 16a2 2 0 0 0 2-2H6a2 2 0 0 0 2 2zm.995-14.901a1 1 0 1 0-1.99 0A5.002 5.002 0 0 0 3 6c0 1.098-.5 6-2 7h14c-1.5-1-2-5.902-2-7 0-2.42-1.72-4.44-4.005-4.901z"})}),search:()=>d("svg",{viewBox:"0 0 33.867 33.867",xmlns:"http://www.w3.org/2000/svg",children:d("g",{transform:"translate(0 -244.08)",children:d("path",{d:"m21.354 244.61a11.536 11.536 0 0 0-11.536 11.536 11.536 11.536 0 0 0 2.0382 6.5449l-10.553 11.201c-0.45492 0.48287-0.43212 1.2376 0.05055 1.6928l1.5971 1.5064c0.48267 0.45512 1.2372 0.43299 1.6921-0.0498l10.518-11.164a11.536 11.536 0 0 0 6.1928 1.8057 11.536 11.536 0 0 0 11.536-11.537 11.536 11.536 0 0 0-11.536-11.536zm-0.0035 4.0508a7.4854 7.4854 0 0 1 0.0035 0 7.4854 7.4854 0 0 1 7.4855 7.4852 7.4854 7.4854 0 0 1-7.4855 7.4855 7.4854 7.4854 0 0 1-7.4852-7.4855 7.4854 7.4854 0 0 1 7.4818-7.4852z",style:{paintOrder:"stroke fill markers"}})})}),flag:()=>d("svg",{viewBox:"0 0 33.867 33.867",xmlns:"http://www.w3.org/2000/svg",children:d("g",{transform:"translate(0 -263.13)",children:d("path",{transform:"matrix(.26458 0 0 .26458 0 263.13)",d:"m19.73 0.85156c-2.6026 0.010149-5.1413 1.5828-6.2891 4.0898-0.94198 2.0576-0.84397 3.7648 0.41602 7.3066 1.1961 3.3623 1.1211-0.45338 1.1211 57.354 0 43.293 0.04982 53.213 0.26758 54.053 0.35827 1.3812 1.0117 2.1539 2.4395 2.8867 0.82586 0.42406 1.4777 0.61006 2.1191 0.60742 1.7309-0.00828 3.6006-1.2213 4.3379-2.8145l0.42188-0.91406 0.10547-54.09 0.10547-54.088 0.44531-1.5684c0.24428-0.86166 0.54324-1.753 0.66602-1.9824 0.6911-1.2914 1.0423-3.4345 0.80273-4.8984-0.46518-2.8431-2.2915-4.8563-5.1641-5.6914-0.59125-0.17187-1.1943-0.25234-1.7949-0.25zm33.09 7.1973c-5.9403-0.01372-12.721 1.9223-17.947 5.125-1.8658 1.1433-2.4721 1.7787-3.3242 3.4863-1.2926 2.5905-1.2317 1.1739-1.2305 28.242 7.37e-4 16.259 0.071905 24.883 0.20898 25.377 0.11421 0.41118 0.45443 0.94391 0.75586 1.1816 0.84531 0.66705 1.7966 0.41822 4.998-1.3066 7.0886-3.8192 14.035-5.6115 19.346-4.9902 4.0124 0.46934 7.2601 1.8227 16.219 6.7617 7.6678 4.2274 12.362 6.2285 15.891 6.7734 0.88803 0.13682 1.7515 0.27848 1.918 0.3125 0.95556 0.1937 3.4331 0.05525 5.3828-0.30078 4.7794-0.87303 9.4358-3.1011 14.447-6.9102 2.7261-2.072 3.4768-2.8749 4.3281-4.6367 1.4932-3.0901 1.373-0.58066 1.373-28.748v-25.264l-0.42383-0.57031c-0.30726-0.41318-0.62971-0.5867-1.1719-0.63281-0.85518-0.072378-1.4031 0.21265-4.9648 2.5879-5.3758 3.585-9.6034 5.5326-14.299 6.5859-2.069 0.46382-2.6422 0.51403-4.8711 0.41992-2.983-0.12586-5.0835-0.62042-7.9023-1.8574-2.0668-0.90701-3.2142-1.5313-9.457-5.1523-8.5897-4.9824-13.012-6.473-19.275-6.4844z"})})}),mod:()=>d("svg",{viewBox:"0 0 33.867 33.867",xmlns:"http://www.w3.org/2000/svg",children:d("g",{transform:"translate(0 -164.71)",children:d("g",{children:d("path",{d:"m16.933 165.76c-0.1797 0-0.13703 0.0137-0.17283 0.0218-0.0358 8e-3 -0.07591 0.0185-0.12371 0.0309-0.09561 0.0247-0.22348 0.0597-0.38205 0.10371-0.31715 0.088-0.75679 0.21269-1.2862 0.36568-1.0589 0.30596-2.4732 0.72157-3.9552 1.1607-2.9639 0.87828-6.1868 1.8493-7.3845 2.2359l-0.61856 0.20012c-0.23069 0.0743-0.38718 0.28887-0.38751 0.53124v1.0133c0 0.6171 0.090013 1.9563 0.20012 3.0746 1.1681 11.864 5.4411 19.527 12.791 22.536 0.06697 0.0275 0.13865 0.0417 0.21104 0.0418h-0.10916l0.98424 0.40206c0.13062 0.0541 0.27688 0.0567 0.40934 7e-3l0.79321-0.30018c2.2647-0.85244 4.1433-2.0861 5.9491-3.9024 3.3688-3.3885 5.5235-8.2832 6.6695-14.978 0.28941-1.6907 0.71823-5.7798 0.72044-7.0243l0.0019-0.86962c-3.31e-4 -0.24238-0.15682-0.45691-0.38751-0.53125l-0.61856-0.20011c-1.1977-0.38662-4.4207-1.3576-7.3845-2.2359-1.4819-0.43914-2.8962-0.85474-3.9551-1.1607-0.52946-0.15298-0.97091-0.27761-1.2881-0.36568-0.15858-0.0441-0.28462-0.079-0.38023-0.1037-0.0478-0.0123-0.08791-0.0228-0.12371-0.0309-0.0358-8e-3 0.0069-0.0218-0.17283-0.0218z"})})})}),reply:()=>d("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 16 16",children:d("path",{d:"M5.921 11.9 1.353 8.62a.719.719 0 0 1 0-1.238L5.921 4.1A.716.716 0 0 1 7 4.719V6c1.5 0 6 0 7 8-2.5-4.5-7-4-7-4v1.281c0 .56-.606.898-1.079.62z"})})};function de({wrapperProps:n={},svgProps:e={},name:t}){return d("span",{style:{verticalAlign:"middle"},className:"icon "+t+(n.class?" "+n.class:""),...n,children:d(oa,{name:"icon."+t,...e})})}const zd={loader:Pd,"icon.star":ee.star,"icon.heart":ee.heart,"icon.caret":ee.caret,"icon.thumbsUp":ee.thumbsUp,"icon.thumbsDown":ee.thumbsDown,"icon.thumbsUpActive":ee.thumbsUpActive,"icon.thumbsDownActive":ee.thumbsDownActive,"icon.link":ee.link,"icon.bold":ee.bold,"icon.italic":ee.italic,"icon.quote":ee.quote,"icon.emoji":ee.emoji,"icon.image":ee.image,"icon.gif":ee.gif,"icon.bell":ee.bell,"icon.search":ee.search,"icon.flag":ee.flag,"icon.mod":ee.mod,"icon.reply":ee.reply};function oa(n){const e=M(),{name:t}=n,r=b.get(e,"components")[t],i=zd[t],o=Object.keys(n).filter(s=>s!=="name").reduce((s,l)=>(s[l]=n[l],s),{});return r?d(r,{...o}):d(i,{...o})}function K({padding:n,size:e="medium"}){return d("div",{className:"loader-wrap",part:"loader-wrap",style:{padding:n},children:d(oa,{name:"loader",size:e})})}const Bd=(n,e)=>{const t=b.get(n,"userReaction");b.set(n,"userReaction",t===e?null:e);const r={};t&&(r[t]=-1),e!==t&&(r[e]=1),Ld(n,r),R.callPageApi({context:n,method:"post",endpoint:"/react",data:{type:e},success:()=>{e!==t&&Fe(n,"reaction",{type:e})}})};function Ld(n,e){const t=b.get(n,"reactions");for(const[r,i]of Object.entries(e))t[r]+=i;Bt(n,"reactions",t)}function Fd(n,e=1){const t=[{value:1,symbol:""},{value:1e3,symbol:"k"},{value:1e6,symbol:"m"},{value:1e9,symbol:"b"},{value:1e12,symbol:"t"},{value:1e15,symbol:"p"},{value:1e18,symbol:"e"}],r=/\.0+$|(\.[0-9]*[1-9])0+$/,i=t.slice().reverse().find(function(o){return n>=o.value});return i?(n/i.value).toFixed(e).replace(r,"$1")+i.symbol:"0"}function Qi(n,e,t=!1){let r=e.toString();switch(t&&(r=Fd(e)),b.get(n,"language").code){case"fa":const o=["۰","۱","۲","۳","۴","۵","۶","۷","۸","۹"];return r.replace(/\d/g,function(s){return o[s]})}return r}function sa({number:n}){const e=M(),t=Qi(e,n);return d("span",{dangerouslySetInnerHTML:{__html:t}})}function $d({index:n,hasReacted:e,userReaction:t,count:r,reaction:i,onClick:o,displayType:s,onKeyDown:l}){const a=M(),c=i.image_url||`${b.get(a,"htDomain")}/res/reactions/`+i.type+".svg";return d("button",{className:"reaction"+(e?" reacted":""),onClick:()=>o(i.type),onKeyDown:u=>l(u,i.type),"aria-label":i.text,"aria-pressed":e,tabIndex:e||t===null&&n===0?0:-1,children:[d("span",{class:"reaction-top",children:[(s==="image"||s==="both")&&d("img",{src:c,alt:i.text||i.type}),d("span",{className:"reaction-number",children:d(sa,{number:r})})]}),(s==="text"||s==="both")&&d("span",{className:"reaction-text",children:i.text})]})}function Vd(){const n=b.use("reactions"),e=b.use("userReaction"),t=M(),r=O(t,"reactions.configs");function i(o){var s,l;if(o.code==="ArrowRight"||o.code==="ArrowDown"){const a=o.target.nextElementSibling;if(a)a.focus();else{const c=(s=o.target.parentElement)==null?void 0:s.firstElementChild;c&&c.focus()}}else if(o.code==="ArrowLeft"||o.code==="ArrowUp"){const a=o.target.previousElementSibling;if(a)a.focus();else{const c=(l=o.target.parentElement)==null?void 0:l.lastElementChild;c&&c.focus()}}}return d("div",{className:"reactions-wrap",part:"reactions-wrap",role:"group","aria-labelledby":"reactions-title-"+t,children:[d("div",{id:"reactions-title-"+t,className:"reactions-title",part:"reactions-title",children:O(t,"text.reactions")||k(t,"reactions_text")}),d("div",{class:"reactions",part:"reactions",children:r.map((o,s)=>o.is_shown&&d($d,{index:s,hasReacted:e===o.type,userReaction:e,reaction:o,count:n[o.type],onClick:l=>Bd(t,l),onKeyDown:i,displayType:O(t,"reactions.display_type")},s))})]})}function la(n){const e=M();let t;if(n===0)t=O(e,"text.comment_count_0")||k(e,"comments_0");else if(n===1)t=O(e,"text.comment_count_1")||k(e,"comments_1");else{const r=O(e,"text.comment_count_multi")||k(e,"comments_multi"),i=Qi(e,n);t=r.replace("*",i)}return t}function Ud(){const n=b.use("commentsCount");return d("span",{className:"comments-count",dangerouslySetInnerHTML:{__html:la(n)}})}function ht({children:n,name:e,onClose:t,vertical:r,horizontal:i,popupProps:o={}}){return d(te,{children:[d("div",{class:`global-popup ${e} ${r} ${i}`,...o,children:n}),t&&d("div",{class:"global-popup-closer",onClick:s=>{s.stopPropagation(),t()}})]})}function Lt({text:n,padding:e=10}){const t=M();return n=n||k(t,"no_results"),d("div",{class:"global-no-results",style:{padding:e},children:n})}function aa(n){const e=M(),t=b.use("user"),r=O(e,"profiles.profile");return n.type?r?!0:t&&t.id===n.id&&t.type===n.type:!1}function $e({user:n,size:e=32,profileOpener:t=!0}){const r={borderRadius:"50%",width:e,height:e},i=M(),o=O(i,"profiles.mod_alias_picture"),s=O(i,"profiles.default_picture"),l=n.type&&n.is_mod&&n.is_mod_alias&&o,[a,c]=w(!1),[u,f]=w((l?o:n.picture_url)||s);function h(){c(!0)}const p=t&&aa(n);function m(){p&&ou(i,n)}return a||!u?d("span",{class:"profile-picture custom",style:r,onClick:m,children:n.name.substring(0,1)}):d("img",{class:"profile-picture",src:u,alt:n.name,loading:"lazy",onError:h,style:r,onClick:m})}function jd(n){const e=b.use("user");return e&&e.id===n.id&&e.type===n.type}function Zi(n){return n.type+"_"+n.id}function Hd(n,e,t,r,i){R.call({context:n,method:"patch",isConsoleApi:!0,endpoint:`/user/${Zi(e)}`,data:{[t]:r},success:i})}function re(n){return d(dt,{...n,buttonType:"accent"})}const dt=Su((n,e)=>{const t=n.scale||"normal",r=n.isLoading?"loading":"",i=`global-button ${t} button-${n.buttonType} ${r}`+(n.class?" "+n.class:"");return d("button",{...n,className:i,ref:e,children:[n.children,n.isLoading&&d("div",{class:"button-loader",children:d(K,{padding:0,size:"small"})})]})});function ca(n,e){const r=b.use("hooks")[n];return()=>{if(!r)return e;let i=e;for(const o of r)i=o(i);return i}}const er=E(0);Hi(er,()=>{const n=setInterval(()=>{er.set(er.get()+1)},1e4);return()=>clearInterval(n)});const bi=60,yi=60*bi,sr=24*yi,Qo=30*sr,Zo=365*sr;function qd(n,e){const t=new Date(e*1e3),r=Math.floor((new Date().getTime()-t.getTime())/1e3);if(r<=5)return{text:k(n,"just_now"),datetime:t};let i,o;return r>=Zo?(i=Math.floor(r/Zo),o="year"):r>=Qo?(i=Math.floor(r/Qo),o="month"):r>=sr?(i=Math.floor(r/sr),o="day"):r>=yi?(i=Math.floor(r/yi),o="hour"):r>=bi?(i=Math.floor(r/bi),o="minute"):(i=Math.floor(r),o="second"),{text:k(n,"ago_"+o+(i!==1?"s":""),{"*":i}),datetime:t}}function ua({time:n}){const e=M();zt(er);const r=ca("time:format",qd(e,n))();return d("time",{dateTime:r.datetime.toLocaleString(),children:r.text})}function Wd({onCollapse:n,comment:e}){return d("div",{class:"collapser",onClick:()=>n(),style:{zIndex:e.depth},children:d("div",{class:"collapse-bar"})})}function Kd({commentId:n,onExpand:e}){const t=M(),r=Gl(t,n,!0),i=r>0?k(t,"expand_comments",{"*":(r+1).toString()}):k(t,"expand_comment");return d("div",{class:"expander",children:d(re,{scale:"small",onClick:()=>e(),children:[i," ",d(de,{name:"caret"})]})})}function Jd({commentId:n,type:e}){const t=M(),[r,i]=w(!0),[o,s]=w([]);return B(()=>{R.callPageApi({context:t,method:"get",endpoint:"/comment/"+n+"/voters",data:{type:e},complete:()=>{i(!1)},success:l=>{s(l)}})},[]),d(ht,{name:"voters",vertical:"top",horizontal:"left",onClose:null,popupProps:{onClick:l=>l.stopPropagation()},children:r?d(K,{padding:10,size:"small"}):d("div",{children:o.map(l=>d("div",{class:"user-row",children:[d($e,{user:l,size:16}),d(an,{user:l})]}))})})}const un=E(null);let Lr=null,Fr=null;function Gd(){const n=zt(un);return n?d("div",{class:`global-one-time-notification ${n.type} ${n.status}`,children:d("div",{class:"notification",children:[n.type==="error"&&d("span",{class:"error-icon",children:"!"}),n.content]})}):null}function Tt(n,e="default",t=3e3){Lr&&clearTimeout(Lr),Fr&&clearTimeout(Fr),un.set({content:n,status:"shown",type:e}),Lr=setTimeout(()=>{un.set({...un.get(),status:"hidden"}),Fr=setTimeout(()=>{un.set(null)},300)},t)}function es({comment:n,type:e}){const t=b.use("userVotes"),r=b.use("user"),i=b.use("userBan"),o=t[n.id]===e,s=M(),l=n[e+"votes"],[a,c]=w(!1),u=H(null),f=window.innerWidth<768;function h(){if(!r&&!O(s,"voting.guest")){Tt(k(s,"guest_vote"));return}const x=o?-1:1,v=e+"votes";if(Xt(s,n.id,v,n[v]+x),t[n.id]&&!o){const N=v==="upvotes"?"downvotes":"upvotes";Xt(s,n.id,N,n[N]-1)}const S=o?null:e;Od(s,n.id,S),Zl(s,n.id,S)}function p(){O(s,"voting.voters")&&l&&(u.current&&clearTimeout(u.current),a||(u.current=setTimeout(()=>{c(!0)},250)))}function m(){u.current&&clearTimeout(u.current),a&&(u.current=setTimeout(()=>{c(!1)},250))}function g(){O(s,"voting.voters")&&l&&(u.current&&clearTimeout(u.current),a||(u.current=setTimeout(()=>{c(!0)},250)))}function y(){u.current&&clearTimeout(u.current),a&&(u.current=setTimeout(()=>{c(!1)},250))}return d("span",{className:"vote-wrap",children:d("button",{class:"vote "+e+(o?" voted":""),onClick:h,disabled:i!==null,"aria-pressed":o,"aria-label":e==="up"?"Upvote":"Downvote",onMouseEnter:f?void 0:p,onMouseLeave:f?void 0:m,onFocus:f?void 0:g,onBlur:f?void 0:y,children:[d(de,{name:"thumbs"+e[0].toUpperCase()+e.slice(1)+(o?"Active":"")}),d("span",{class:"vote-number",children:l}),a&&d(Jd,{type:e,commentId:n.id})]})})}function Yd({comment:n}){const e=M(),t=O(e,"voting.type");return t==="none"?null:d("div",{className:"votes",children:[d(es,{comment:n,type:"up"}),t==="both"&&d(es,{comment:n,type:"down"})]})}function Xd(){const n=b.use("user");return n?d("div",{class:"editor-user",children:d($e,{user:n})}):null}function da(n){let e=O(n,"auth.sso_stateless_login_url");return e&&(e=e.replace("$PATH_ENCODED",encodeURIComponent(window.location.pathname)),e=e.replace("$PATH",window.location.pathname),e=e.replace("$URL_ENCODED",encodeURIComponent(window.location.href)),e=e.replace("$URL",window.location.href)),e||void 0}function xi(n,e){const t=Fe(n,"auth:login:clicked",null);if(t&&t.defaultPrevented){e.preventDefault();return}Rn(n)||Pe.login(n)}function Qd(){return d("div",{class:"login-signup",children:d(Zd,{})})}function Zd({onClick:n}){const e="login",t=M(),r=Rn(t),i=o=>{n&&n(),xi(t,o)};return r?d("a",{className:e,onClick:i,href:da(t),children:k(t,e)}):d("button",{className:e,onClick:i,children:k(t,e)})}function ef(){const n=M();return Rn(n)?d("a",{className:"login-required",onClick:t=>xi(n,t),href:da(n),children:k(n,"login_to_comment")}):d("button",{className:"login-required",onClick:t=>xi(n,t),children:k(n,"login_to_comment")})}function ie(n){this.content=n}ie.prototype={constructor:ie,find:function(n){for(var e=0;e>1}};ie.from=function(n){if(n instanceof ie)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new ie(e)};function fa(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),o=e.child(r);if(i==o){t+=i.nodeSize;continue}if(!i.sameMarkup(o))return t;if(i.isText&&i.text!=o.text){for(let s=0;i.text[s]==o.text[s];s++)t++;return t}if(i.content.size||o.content.size){let s=fa(i.content,o.content,t+1);if(s!=null)return s}t+=i.nodeSize}}function ha(n,e,t,r){for(let i=n.childCount,o=e.childCount;;){if(i==0||o==0)return i==o?null:{a:t,b:r};let s=n.child(--i),l=e.child(--o),a=s.nodeSize;if(s==l){t-=a,r-=a;continue}if(!s.sameMarkup(l))return{a:t,b:r};if(s.isText&&s.text!=l.text){let c=0,u=Math.min(s.text.length,l.text.length);for(;ce&&r(a,i+l,o||null,s)!==!1&&a.content.size){let u=l+1;a.nodesBetween(Math.max(0,e-u),Math.min(a.content.size,t-u),r,i+u)}l=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let o="",s=!0;return this.nodesBetween(e,t,(l,a)=>{let c=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&c||l.isTextblock)&&r&&(s?s=!1:o+=r),o+=c},0),o}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),o=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),o=1);oe)for(let o=0,s=0;se&&((st)&&(l.isText?l=l.cut(Math.max(0,e-s),Math.min(l.text.length,t-s)):l=l.cut(Math.max(0,e-s-1),Math.min(l.content.size,t-s-1))),r.push(l),i+=l.nodeSize),s=a}return new _(r,i)}cutByIndex(e,t){return e==t?_.empty:e==0&&t==this.content.length?this:new _(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),o=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new _(i,o)}addToStart(e){return new _([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new _(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,r=0;;t++){let i=this.child(t),o=r+i.nodeSize;if(o>=e)return o==e?Jn(t+1,o):Jn(t,r);r=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return _.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new _(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return _.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(o)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}}$.none=[];class ar extends Error{}class C{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=ma(this.content,e+this.openStart,t);return r&&new C(r,this.openStart,this.openEnd)}removeBetween(e,t){return new C(pa(this.content,e+this.openStart,t+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,t){if(!t)return C.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new C(_.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)r++;for(let o=e.lastChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.lastChild)i++;return new C(e,r,i)}}C.empty=new C(_.empty,0,0);function pa(n,e,t){let{index:r,offset:i}=n.findIndex(e),o=n.maybeChild(r),{index:s,offset:l}=n.findIndex(t);if(i==e||o.isText){if(l!=t&&!n.child(s).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=s)throw new RangeError("Removing non-flat range");return n.replaceChild(r,o.copy(pa(o.content,e-i-1,t-i-1)))}function ma(n,e,t,r){let{index:i,offset:o}=n.findIndex(e),s=n.maybeChild(i);if(o==e||s.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=ma(s.content,e-o-1,t,s);return l&&n.replaceChild(i,s.copy(l))}function tf(n,e,t){if(t.openStart>n.depth)throw new ar("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new ar("Inconsistent open depths");return ga(n,e,t,0)}function ga(n,e,t,r){let i=n.index(r),o=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function mn(n,e,t,r){let i=(e||n).node(t),o=0,s=e?e.index(t):i.childCount;n&&(o=n.index(t),n.depth>t?o++:n.textOffset&&(Ct(n.nodeAfter,r),o++));for(let l=o;li&&ki(n,e,i+1),s=r.depth>i&&ki(t,r,i+1),l=[];return mn(null,n,i,l),o&&s&&e.index(i)==t.index(i)?(ba(o,s),Ct(St(o,ya(n,e,t,r,i+1)),l)):(o&&Ct(St(o,cr(n,e,i+1)),l),mn(e,t,i,l),s&&Ct(St(s,cr(t,r,i+1)),l)),mn(r,null,i,l),new _(l)}function cr(n,e,t){let r=[];if(mn(null,n,t,r),n.depth>t){let i=ki(n,e,t+1);Ct(St(i,cr(n,e,t+1)),r)}return mn(e,null,t,r),new _(r)}function nf(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let o=t-1;o>=0;o--)i=e.node(o).copy(_.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}class wn{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.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,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let o=0;o0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new ur(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&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,o=t;for(let s=e;;){let{index:l,offset:a}=s.content.findIndex(o),c=o-a;if(r.push(s,l,i+a),!c||(s=s.child(l),s.isText))break;o=c-1,i+=a+1}return new wn(t,r,o)}static resolveCached(e,t){let r=ts.get(e);if(r)for(let o=0;oe&&this.nodesBetween(e,t,o=>(r.isInSet(o.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()+")"),xa(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=_.empty,i=0,o=r.childCount){let s=this.contentMatchAt(e).matchFragment(r,i,o),l=s&&s.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=i;at.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t 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(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=_.fromJSON(e,t.content),o=e.nodeType(t.type).create(t.attrs,i,r);return o.type.checkAttrs(o.attrs),o}}Te.prototype.text=void 0;class dr extends Te{constructor(e,t,r,i){if(super(e,t,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):xa(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new dr(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new dr(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function xa(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class It{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new lf(e,t);if(r.next==null)return It.empty;let i=ka(r);r.next&&r.err("Unexpected trailing text");let o=pf(hf(i));return mf(o,r),o}matchType(e){for(let t=0;tc.createAndFill()));for(let c=0;c=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let o=i+(r.validEnd?"*":" ")+" ";for(let s=0;s"+e.indexOf(r.next[s].next);return o}).join(` `)}}It.empty=new It(!0);class lf{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function ka(n){let e=[];do e.push(af(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function af(n){let e=[];do e.push(cf(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function cf(n){let e=ff(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=uf(n,e);else break;return e}function ns(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function uf(n,e){let t=ns(n),r=t;return n.eat(",")&&(n.next!="}"?r=ns(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function df(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let o in t){let s=t[o];s.isInGroup(e)&&i.push(s)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function ff(n){if(n.eat("(")){let e=ka(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=df(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function hf(n){let e=[[]];return i(o(n,0),t()),e;function t(){return e.push([])-1}function r(s,l,a){let c={term:a,to:l};return e[s].push(c),c}function i(s,l){s.forEach(a=>a.to=l)}function o(s,l){if(s.type=="choice")return s.exprs.reduce((a,c)=>a.concat(o(c,l)),[]);if(s.type=="seq")for(let a=0;;a++){let c=o(s.exprs[a],l);if(a==s.exprs.length-1)return c;i(c,l=t())}else if(s.type=="star"){let a=t();return r(l,a),i(o(s.expr,a),a),[r(a)]}else if(s.type=="plus"){let a=t();return i(o(s.expr,l),a),i(o(s.expr,a),a),[r(a)]}else{if(s.type=="opt")return[r(l)].concat(o(s.expr,l));if(s.type=="range"){let a=l;for(let c=0;c{n[s].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let u=0;u{c||i.push([l,c=[]]),c.indexOf(u)==-1&&c.push(u)})})});let o=e[r.join(",")]=new It(r.indexOf(n.length-1)>-1);for(let s=0;s-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:wa(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Te(this,this.computeAttrs(e),_.from(t),$.setFrom(r))}createChecked(e=null,t,r){return t=_.from(t),this.checkContent(t),new Te(this,this.computeAttrs(e),t,$.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=_.from(t),t.size){let s=this.contentMatch.fillBefore(t);if(!s)return null;t=s.append(t)}let i=this.contentMatch.matchFragment(t),o=i&&i.fillBefore(_.empty,!0);return o?new Te(this,e,t.append(o),$.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[o]=new Ma(o,t,s));let i=t.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 o in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function gf(n,e,t){let r=t.split("|");return i=>{let o=i===null?"null":typeof i;if(r.indexOf(o)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${o}`)}}class bf{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?gf(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class Sr{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=Sa(e,i.attrs),this.excluded=null;let o=va(this.attrs);this.instance=o?new $(this,o):null}create(e=null){return!e&&this.instance?this.instance:new $(this,wa(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((o,s)=>r[o]=new Sr(o,i++,t,s)),r}removeFromSet(e){for(var t=0;t-1}}class Oa{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=ie.from(e.nodes),t.marks=ie.from(e.marks||{}),this.nodes=is.compile(this.spec.nodes,this),this.marks=Sr.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 o=this.nodes[i],s=o.spec.content||"",l=o.spec.marks;if(o.contentMatch=r[s]||(r[s]=It.parse(s,this.nodes)),o.inlineContent=o.contentMatch.inlineContent,o.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!o.isInline||!o.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=o}o.markSet=l=="_"?null:l?ss(this,l.split(" ")):l==""||!o.inlineContent?[]:null}for(let i in this.marks){let o=this.marks[i],s=o.spec.excludes;o.excluded=s==null?[o]:s==""?[]:ss(this,s.split(" "))}this.nodeFromJSON=i=>Te.fromJSON(this,i),this.markFromJSON=i=>$.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof is){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(t,r,i)}text(e,t){let r=this.nodes.text;return new dr(r,r.defaultAttrs,e,$.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function ss(n,e){let t=[];for(let r=0;r-1)&&t.push(s=a)}if(!s)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function yf(n){return n.tag!=null}function xf(n){return n.style!=null}class Cn{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let r=this.matchedStyles=[];t.forEach(i=>{if(yf(i))this.tags.push(i);else if(xf(i)){let o=/[^=]*/.exec(i.style)[0];r.indexOf(o)<0&&r.push(o),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let o=e.nodes[i.node];return o.contentMatch.matchType(o)})}parse(e,t={}){let r=new as(this,t,!1);return r.addAll(e,$.none,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new as(this,t,!0);return r.addAll(e,$.none,t.from,t.to),C.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(s.getAttrs){let a=s.getAttrs(t);if(a===!1)continue;s.attrs=a||void 0}return s}}}static schemaRules(e){let t=[];function r(i){let o=i.priority==null?50:i.priority,s=0;for(;s{r(s=cs(s)),s.mark||s.ignore||s.clearMark||(s.mark=i)})}for(let i in e.nodes){let o=e.nodes[i].spec.parseDOM;o&&o.forEach(s=>{r(s=cs(s)),s.node||s.ignore||s.mark||(s.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Cn(e,Cn.schemaRules(e)))}}const Na={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},kf={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Ea={ol:!0,ul:!0},Sn=1,_i=2,gn=4;function ls(n,e,t){return e!=null?(e?Sn:0)|(e==="full"?_i:0):n&&n.whitespace=="pre"?Sn|_i:t&~gn}class Gn{constructor(e,t,r,i,o,s){this.type=e,this.attrs=t,this.marks=r,this.solid=i,this.options=s,this.content=[],this.activeMarks=$.none,this.match=o||(s&gn?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(_.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);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&Sn)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let o=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=o.withText(o.text.slice(0,o.text.length-i[0].length))}}let t=_.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(_.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Na.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class as{constructor(e,t,r){this.parser=e,this.options=t,this.isOpen=r,this.open=0,this.localPreserveWS=!1;let i=t.topNode,o,s=ls(null,t.preserveWhitespace,0)|(r?gn:0);i?o=new Gn(i.type,i.attrs,$.none,!0,t.topMatch||i.type.contentMatch,s):r?o=new Gn(null,null,$.none,!0,null,s):o=new Gn(e.schema.topNodeType,null,$.none,!0,null,s),this.nodes=[o],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let r=e.nodeValue,i=this.top,o=i.options&_i?"full":this.localPreserveWS||(i.options&Sn)>0;if(o==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(o)o!=="full"?r=r.replace(/\r?\n|\r/g," "):r=r.replace(/\r\n?/g,` `);else if(r=r.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(r)&&this.open==this.nodes.length-1){let s=i.content[i.content.length-1],l=e.previousSibling;(!s||l&&l.nodeName=="BR"||s.isText&&/[ \t\r\n\u000c]$/.test(s.text))&&(r=r.slice(1))}r&&this.insertNode(this.parser.schema.text(r),t,!/\S/.test(r)),this.findInText(e)}else this.findInside(e)}addElement(e,t,r){let i=this.localPreserveWS,o=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let s=e.nodeName.toLowerCase(),l;Ea.hasOwnProperty(s)&&this.parser.normalizeLists&&_f(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,r));e:if(a?a.ignore:kf.hasOwnProperty(s))this.findInside(e),this.ignoreFallback(e,t);else if(!a||a.skip||a.closeParent){a&&a.closeParent?this.open=Math.max(0,this.open-1):a&&a.skip.nodeType&&(e=a.skip);let c,u=this.needsBlock;if(Na.hasOwnProperty(s))o.content.length&&o.content[0].isInline&&this.open&&(this.open--,o=this.top),c=!0,o.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let f=a&&a.skip?t:this.readStyles(e,t);f&&this.addAll(e,f),c&&this.sync(o),this.needsBlock=u}else{let c=this.readStyles(e,t);c&&this.addElementByRule(e,a,c,a.consuming===!1?l:void 0)}this.localPreserveWS=i}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(` `),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let r=e.style;if(r&&r.length)for(let i=0;i!a.clearMark(c)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,r,i){let o,s;if(t.node)if(s=this.parser.schema.nodes[t.node],s.isLeaf)this.insertNode(s.create(t.attrs),r,e.nodeName=="BR")||this.leafFallback(e,r);else{let a=this.enter(s,t.attrs||null,r,t.preserveWhitespace);a&&(o=!0,r=a)}else{let a=this.parser.schema.marks[t.mark];r=r.concat(a.create(t.attrs))}let l=this.top;if(s&&s.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,r,!1));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,r),this.findAround(e,a,!1)}o&&this.sync(l)&&this.open--}addAll(e,t,r,i){let o=r||0;for(let s=r?e.childNodes[r]:e.firstChild,l=i==null?null:e.childNodes[i];s!=l;s=s.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(s,t);this.findAtPoint(e,o)}findPlace(e,t,r){let i,o;for(let s=this.open,l=0;s>=0;s--){let a=this.nodes[s],c=a.findWrapping(e);if(c&&(!i||i.length>c.length+l)&&(i=c,o=a,!c.length))break;if(a.solid){if(r)break;l+=2}}if(!i)return null;this.sync(o);for(let s=0;s(s.type?s.type.allowsMarkType(c.type):us(c.type,e))?(a=c.addToSet(a),!1):!0),this.nodes.push(new Gn(e,t,a,i,null,l)),this.open++,r}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=Sn)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),o=-(r?r.depth+1:0)+(i?0:1),s=(l,a)=>{for(;l>=0;l--){let c=t[l];if(c==""){if(l==t.length-1||l==0)continue;for(;a>=o;a--)if(s(l-1,a))return!0;return!1}else{let u=a>0||a==0&&i?this.nodes[a].type:r&&a>=o?r.node(a-o).type:null;if(!u||u.name!=c&&!u.isInGroup(c))return!1;a--}}return!0};return s(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}}function _f(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&Ea.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function vf(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function cs(n){let e={};for(let t in n)e[t]=n[t];return e}function us(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let o=[],s=l=>{o.push(l);for(let a=0;a{if(o.length||s.marks.length){let l=0,a=0;for(;l=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,t);o&&((o.contentDOM||o.dom).appendChild(r),r=o.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&tr(Vr(r),i(e,t),null,e.attrs)}static renderSpec(e,t,r=null,i){return tr(e,t,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new sn(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=ds(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return ds(e.marks)}}function ds(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function Vr(n){return n.document||window.document}const fs=new WeakMap;function wf(n){let e=fs.get(n);return e===void 0&&fs.set(n,e=Cf(n)),e}function Cf(n){let e=null;function t(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 s=i.indexOf(" ");s>0&&(t=i.slice(0,s),i=i.slice(s+1));let l,a=t?n.createElementNS(t,i):n.createElement(i),c=e[1],u=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){u=2;for(let f in c)if(c[f]!=null){let h=f.indexOf(" ");h>0?a.setAttributeNS(f.slice(0,h),f.slice(h+1),c[f]):f=="style"&&a.style?a.style.cssText=c[f]:a.setAttribute(f,c[f])}}for(let f=u;fu)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:p,contentDOM:m}=tr(n,h,t,r);if(a.appendChild(p),m){if(l)throw new RangeError("Multiple content holes");l=m}}}return{dom:a,contentDOM:l}}const Ta=65535,Ia=Math.pow(2,16);function Sf(n,e){return n+e*Ia}function hs(n){return n&Ta}function Mf(n){return(n-(n&Ta))/Ia}const Da=1,Aa=2,nr=4,Ra=8;class vi{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&Ra)>0}get deletedBefore(){return(this.delInfo&(Da|nr))>0}get deletedAfter(){return(this.delInfo&(Aa|nr))>0}get deletedAcross(){return(this.delInfo&nr)>0}}class ye{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&ye.empty)return ye.empty}recover(e){let t=0,r=hs(e);if(!this.inverted)for(let i=0;ie)break;let c=this.ranges[l+o],u=this.ranges[l+s],f=a+c;if(e<=f){let h=c?e==a?-1:e==f?1:t:t,p=a+i+(h<0?0:u);if(r)return p;let m=e==(t<0?a:f)?null:Sf(l/3,e-a),g=e==a?Aa:e==f?Da:nr;return(t<0?e!=a:e!=f)&&(g|=Ra),new vi(p,g,m)}i+=u-c}return r?e+i:new vi(e+i,0,null)}touches(e,t){let r=0,i=hs(t),o=this.inverted?2:1,s=this.inverted?1:2;for(let l=0;le)break;let c=this.ranges[l+o],u=a+c;if(e<=u&&l==i*3)return!0;r+=this.ranges[l+s]-c}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,o=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e._maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new Mn;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;ro&&a!s.isAtom||!l.type.allowsMarkType(this.mark.type)?s:s.mark(this.mark.addToSet(s.marks)),i),t.openStart,t.openEnd);return Z.fromReplace(e,this.from,this.to,o)}invert(){return new ze(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new ot(t.pos,r.pos,this.mark)}merge(e){return e instanceof ot&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ot(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,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new ot(t.from,t.to,e.markFromJSON(t.mark))}}fe.jsonID("addMark",ot);class ze extends fe{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new C(eo(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return Z.fromReplace(e,this.from,this.to,r)}invert(){return new ot(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new ze(t.pos,r.pos,this.mark)}merge(e){return e instanceof ze&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ze(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,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new ze(t.from,t.to,e.markFromJSON(t.mark))}}fe.jsonID("removeMark",ze);class st extends fe{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Z.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Z.fromReplace(e,this.pos,this.pos+1,new C(_.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new le(t.pos,r.pos,i,o,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,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new le(t.from,t.to,t.gapFrom,t.gapTo,C.fromJSON(e,t.slice),t.insert,!!t.structure)}}fe.jsonID("replaceAround",le);function wi(n,e,t){let r=n.resolve(e),i=t-e,o=r.depth;for(;i>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,i--;if(i>0){let s=r.node(o).maybeChild(r.indexAfter(o));for(;i>0;){if(!s||s.isLeaf)return!0;s=s.firstChild,i--}}return!1}function Of(n,e,t,r){let i=[],o=[],s,l;n.doc.nodesBetween(e,t,(a,c,u)=>{if(!a.isInline)return;let f=a.marks;if(!r.isInSet(f)&&u.type.allowsMarkType(r.type)){let h=Math.max(c,e),p=Math.min(c+a.nodeSize,t),m=r.addToSet(f);for(let g=0;gn.step(a)),o.forEach(a=>n.step(a))}function Nf(n,e,t,r){let i=[],o=0;n.doc.nodesBetween(e,t,(s,l)=>{if(!s.isInline)return;o++;let a=null;if(r instanceof Sr){let c=s.marks,u;for(;u=r.isInSet(c);)(a||(a=[])).push(u),c=u.removeFromSet(c)}else r?r.isInSet(s.marks)&&(a=[r]):a=s.marks;if(a&&a.length){let c=Math.min(l+s.nodeSize,t);for(let u=0;un.step(new ze(s.from,s.to,s.style)))}function to(n,e,t,r=t.contentMatch,i=!0){let o=n.doc.nodeAt(e),s=[],l=e+1;for(let a=0;a=0;a--)n.step(s[a])}function Ef(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function Pn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),o=n.$from.index(r),s=n.$to.indexAfter(r);if(rt;m--)g||r.index(m)>0?(g=!0,u=_.from(r.node(m).copy(u)),f++):a--;let h=_.empty,p=0;for(let m=o,g=!1;m>t;m--)g||i.after(m+1)=0;s--){if(r.size){let l=t[s].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=_.from(t[s].type.create(t[s].attrs,r))}let i=e.start,o=e.end;n.step(new le(i,o,i,o,new C(r,0,0),t.length,!0))}function Rf(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let o=n.steps.length;n.doc.nodesBetween(e,t,(s,l)=>{let a=typeof i=="function"?i(s):i;if(s.isTextblock&&!s.hasMarkup(r,a)&&Pf(n.doc,n.mapping.slice(o).map(l),r)){let c=null;if(r.schema.linebreakReplacement){let p=r.whitespace=="pre",m=!!r.contentMatch.matchType(r.schema.linebreakReplacement);p&&!m?c=!1:!p&&m&&(c=!0)}c===!1&&za(n,s,l,o),to(n,n.mapping.slice(o).map(l,1),r,void 0,c===null);let u=n.mapping.slice(o),f=u.map(l,1),h=u.map(l+s.nodeSize,1);return n.step(new le(f,h,f+1,h-1,new C(_.from(r.create(a,null,s.marks)),0,0),1,!0)),c===!0&&Pa(n,s,l,o),!1}})}function Pa(n,e,t,r){e.forEach((i,o)=>{if(i.isText){let s,l=/\r?\n|\r/g;for(;s=l.exec(i.text);){let a=n.mapping.slice(r).map(t+1+o+s.index);n.replaceWith(a,a+1,e.type.schema.linebreakReplacement.create())}}})}function za(n,e,t,r){e.forEach((i,o)=>{if(i.type==i.type.schema.linebreakReplacement){let s=n.mapping.slice(r).map(t+1+o);n.replaceWith(s,s+1,e.type.schema.text(` `))}})}function Pf(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function zf(n,e,t,r,i){let o=n.doc.nodeAt(e);if(!o)throw new RangeError("No node at given position");t||(t=o.type);let s=t.create(r,null,i||o.marks);if(o.isLeaf)return n.replaceWith(e,e+o.nodeSize,s);if(!t.validContent(o.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new le(e,e+o.nodeSize,e+1,e+o.nodeSize-1,new C(_.from(s),0,0),1,!0))}function Wt(n,e,t=1,r){let i=n.resolve(e),o=i.depth-t,s=r&&r[r.length-1]||i.parent;if(o<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!s.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let c=i.depth-1,u=t-2;c>o;c--,u--){let f=i.node(c),h=i.index(c);if(f.type.spec.isolating)return!1;let p=f.content.cutByIndex(h,f.childCount),m=r&&r[u+1];m&&(p=p.replaceChild(0,m.type.create(m.attrs)));let g=r&&r[u]||f;if(!f.canReplace(h+1,f.childCount)||!g.type.validContent(p))return!1}let l=i.indexAfter(o),a=r&&r[0];return i.node(o).canReplaceWith(l,l,a?a.type:i.node(o+1).type)}function Bf(n,e,t=1,r){let i=n.doc.resolve(e),o=_.empty,s=_.empty;for(let l=i.depth,a=i.depth-t,c=t-1;l>a;l--,c--){o=_.from(i.node(l).copy(o));let u=r&&r[c];s=_.from(u?u.type.create(u.attrs,s):i.node(l).copy(s))}n.step(new ce(e,e,new C(o.append(s),t,t),!0))}function ln(n,e){let t=n.resolve(e),r=t.index();return Ba(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function Lf(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:r}=n.type.schema;for(let i=0;i0?(o=r.node(i+1),l++,s=r.node(i).maybeChild(l)):(o=r.node(i).maybeChild(l-1),s=r.node(i+1)),o&&!o.isTextblock&&Ba(o,s)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function Ff(n,e,t){let r=null,{linebreakReplacement:i}=n.doc.type.schema,o=n.doc.resolve(e-t),s=o.node().type;if(i&&s.inlineContent){let u=s.whitespace=="pre",f=!!s.contentMatch.matchType(i);u&&!f?r=!1:!u&&f&&(r=!0)}let l=n.steps.length;if(r===!1){let u=n.doc.resolve(e+t);za(n,u.node(),u.before(),l)}s.inlineContent&&to(n,e+t-1,s,o.node().contentMatchAt(o.index()),r==null);let a=n.mapping.slice(l),c=a.map(e-t);if(n.step(new ce(c,a.map(e+t,-1),C.empty,!0)),r===!0){let u=n.doc.resolve(c);Pa(n,u.node(),u.before(),n.steps.length)}return n}function $f(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let o=r.index(i);if(r.node(i).canReplaceWith(o,o,t))return r.before(i+1);if(o>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let o=r.indexAfter(i);if(r.node(i).canReplaceWith(o,o,t))return r.after(i+1);if(o=0;s--){let l=s==r.depth?0:r.pos<=(r.start(s+1)+r.end(s+1))/2?-1:1,a=r.index(s)+(l>0?1:0),c=r.node(s),u=!1;if(o==1)u=c.canReplace(a,a,i);else{let f=c.contentMatchAt(a).findWrapping(i.firstChild.type);u=f&&c.canReplaceWith(a,a,f[0])}if(u)return l==0?r.pos:l<0?r.before(s+1):r.after(s+1)}return null}function ro(n,e,t=e,r=C.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),o=n.resolve(t);return Fa(i,o,r)?new ce(e,t,r):new Uf(i,o,r).fit()}function Fa(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}class Uf{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=_.empty;for(let i=0;i<=e.depth;i++){let o=e.node(i);this.frontier.push({type:o.type,match:o.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=_.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=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 o=this.placed,s=r.depth,l=i.depth;for(;s&&l&&o.childCount==1;)o=o.firstChild.content,s--,l--;let a=new C(o,s,l);return e>-1?new le(r.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||r.pos!=this.$to.pos?new ce(r.pos,i.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),o.type.spec.isolating&&i<=r){e=r;break}t=o.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,o=null;r?(o=jr(this.unplaced.content,r-1).firstChild,i=o.content):i=this.unplaced.content;let s=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:c}=this.frontier[l],u,f=null;if(t==1&&(s?c.matchType(s.type)||(f=c.fillBefore(_.from(s),!1)):o&&a.compatibleContent(o.type)))return{sliceDepth:r,frontierDepth:l,parent:o,inject:f};if(t==2&&s&&(u=c.findWrapping(s.type)))return{sliceDepth:r,frontierDepth:l,parent:o,wrap:u};if(o&&c.matchType(o.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=jr(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new C(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=jr(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new C(dn(e,t-1,1),t-1,o?t-1:r)}else this.unplaced=new C(dn(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let g=0;g1||a==0||g.content.size)&&(f=y,u.push($a(g.mark(h.allowedMarks(g.marks)),c==1?a:0,c==l.childCount?p:-1)))}let m=c==l.childCount;m||(p=-1),this.placed=fn(this.placed,t,_.from(u)),this.frontier[t].match=f,m&&p<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let g=0,y=l;g1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],o=t=0;l--){let{match:a,type:c}=this.frontier[l],u=Hr(e,l,c,a,!0);if(!u||u.childCount)continue e}return{depth:t,fit:s,move:o?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=fn(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),o=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,o)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=fn(this.placed,this.depth,_.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(_.empty,!0);t.childCount&&(this.placed=fn(this.placed,this.frontier.length,t))}}function dn(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(dn(n.firstChild.content,e-1,t)))}function fn(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(fn(n.lastChild.content,e-1,t)))}function jr(n,e){for(let t=0;t1&&(r=r.replaceChild(0,$a(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(_.empty,!0)))),n.copy(r)}function Hr(n,e,t,r,i){let o=n.node(e),s=i?n.indexAfter(e):n.index(e);if(s==o.childCount&&!t.compatibleContent(o.type))return null;let l=r.fillBefore(o.content,!0,s);return l&&!jf(t,o.content,s)?l:null}function jf(n,e,t){for(let r=t;r0;h--,p--){let m=i.node(h).type.spec;if(m.defining||m.definingAsContext||m.isolating)break;s.indexOf(h)>-1?l=h:i.before(h)==p&&s.splice(1,0,-h)}let a=s.indexOf(l),c=[],u=r.openStart;for(let h=r.content,p=0;;p++){let m=h.firstChild;if(c.push(m),p==r.openStart)break;h=m.content}for(let h=u-1;h>=0;h--){let p=c[h],m=Hf(p.type);if(m&&!p.sameMarkup(i.node(Math.abs(l)-1)))u=h;else if(m||!p.type.isTextblock)break}for(let h=r.openStart;h>=0;h--){let p=(h+u+1)%(r.openStart+1),m=c[p];if(m)for(let g=0;g=0&&(n.replace(e,t,r),!(n.steps.length>f));h--){let p=s[h];p<0||(e=i.before(p),t=o.after(p))}}function Va(n,e,t,r,i){if(er){let o=i.contentMatchAt(0),s=o.fillBefore(n).append(n);n=s.append(o.matchFragment(s).fillBefore(_.empty,!0))}return n}function Wf(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=$f(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new C(_.from(r),0,0))}function Kf(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),o=Ua(r,i);for(let s=0;s0&&(a||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(e-r.start(s)==r.depth-s&&t>r.end(s)&&i.end(s)-t!=i.depth-s&&r.start(s-1)==i.start(s-1)&&r.node(s-1).canReplace(r.index(s-1),i.index(s-1)))return n.delete(r.before(s),t);n.delete(e,t)}function Ua(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let o=n.start(i);if(oe.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(o==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==o-1)&&t.push(i)}return t}class Kt extends fe{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return Z.fail("No node at attribute step's position");let r=Object.create(null);for(let o in t.attrs)r[o]=t.attrs[o];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return Z.fromReplace(e,this.pos,this.pos+1,new C(_.from(i),0,t.isLeaf?0:1))}getMap(){return ye.empty}invert(e){return new Kt(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Kt(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Kt(t.pos,t.attr,t.value)}}fe.jsonID("attr",Kt);class On extends fe{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return Z.ok(r)}getMap(){return ye.empty}invert(e){return new On(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new On(t.attr,t.value)}}fe.jsonID("docAttr",On);let Qt=class extends Error{};Qt=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Qt.prototype=Object.create(Error.prototype);Qt.prototype.constructor=Qt;Qt.prototype.name="TransformError";class Jf{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Mn}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Qt(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=C.empty){let i=ro(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new C(_.from(r),0,0))}delete(e,t){return this.replace(e,t,C.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return qf(this,e,t,r),this}replaceRangeWith(e,t,r){return Wf(this,e,t,r),this}deleteRange(e,t){return Kf(this,e,t),this}lift(e,t){return Tf(this,e,t),this}join(e,t=1){return Ff(this,e,t),this}wrap(e,t){return Af(this,e,t),this}setBlockType(e,t=e,r,i=null){return Rf(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return zf(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Kt(e,t,r)),this}setDocAttribute(e,t){return this.step(new On(e,t)),this}addNodeMark(e,t){return this.step(new st(e,t)),this}removeNodeMark(e,t){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t instanceof $)t.isInSet(r.marks)&&this.step(new Dt(e,t));else{let i=r.marks,o,s=[];for(;o=t.isInSet(i);)s.push(new Dt(e,o)),i=o.removeFromSet(i);for(let l=s.length-1;l>=0;l--)this.step(s[l])}return this}split(e,t=1,r){return Bf(this,e,t,r),this}addMark(e,t,r){return Of(this,e,t,r),this}removeMark(e,t,r){return Nf(this,e,t,r),this}clearIncompatible(e,t,r){return to(this,e,t,r),this}}const qr=Object.create(null);class F{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new Gf(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t=0;o--){let s=t<0?Ut(e.node(0),e.node(o),e.before(o+1),e.index(o),t,r):Ut(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,t,r);if(s)return s}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new ke(e.node(0))}static atStart(e){return Ut(e,e,0,0,1)||new ke(e)}static atEnd(e){return Ut(e,e,e.content.size,e.childCount,-1)||new ke(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=qr[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in qr)throw new RangeError("Duplicate use of selection JSON ID "+e);return qr[e]=t,t.prototype.jsonID=e,t}getBookmark(){return D.between(this.$anchor,this.$head).getBookmark()}}F.prototype.visible=!0;class Gf{constructor(e,t){this.$from=e,this.$to=t}}let ms=!1;function gs(n){!ms&&!n.parent.inlineContent&&(ms=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}class D extends F{constructor(e,t=e){gs(e),gs(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return F.near(r);let i=e.resolve(t.map(this.anchor));return new D(i.parent.inlineContent?i:r,r)}replace(e,t=C.empty){if(super.replace(e,t),t==C.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof D&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Mr(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new D(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let o=F.findFrom(t,r,!0)||F.findFrom(t,-r,!0);if(o)t=o.$head;else return F.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(F.findFrom(e,-r,!0)||F.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?s=0;s+=i){let l=e.child(s);if(l.isAtom){if(!o&&T.isSelectable(l))return T.create(n,t-(i<0?l.nodeSize:0))}else{let a=Ut(n,l,t+i,i<0?l.childCount:0,i,o);if(a)return a}t+=l.nodeSize*i}return null}function bs(n,e,t){let r=n.steps.length-1;if(r{s==null&&(s=u)}),n.setSelection(F.near(n.doc.resolve(s),t))}const ys=1,Yn=2,xs=4;class Xf extends Jf{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|=Yn,this}ensureMarks(e){return $.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&Yn)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Yn,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||$.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let o=this.storedMarks;if(!o){let s=this.doc.resolve(t);o=r==t?s.marks():s.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,o)),this.selection.empty||this.setSelection(F.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=xs,this}get scrolledIntoView(){return(this.updated&xs)>0}}function ks(n,e){return!e||!n?n:n.bind(e)}class hn{constructor(e,t,r){this.name=e,this.init=ks(t.init,r),this.apply=ks(t.apply,r)}}const Qf=[new hn("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new hn("selection",{init(n,e){return n.selection||F.atStart(e.doc)},apply(n){return n.selection}}),new hn("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new hn("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];class Wr{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Qf.slice(),t&&t.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 hn(r.key,r.spec.state,r))})}}class qt{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let 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],o=i.spec.state;o&&o.toJSON&&(t[r]=o.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Wr(e.schema,e.plugins),o=new qt(i);return i.fields.forEach(s=>{if(s.name=="doc")o.doc=Te.fromJSON(e.schema,t.doc);else if(s.name=="selection")o.selection=F.fromJSON(o.doc,t.selection);else if(s.name=="storedMarks")t.storedMarks&&(o.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let a=r[l],c=a.spec.state;if(a.key==s.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){o[s.name]=c.fromJSON.call(a,e,t[l],o);return}}o[s.name]=s.init(e,o)}}),o}}function ja(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=ja(i,e,{})),t[r]=i}return t}class Ze{constructor(e){this.spec=e,this.props={},e.props&&ja(e.props,this,this.props),this.key=e.key?e.key.key:Ha("plugin")}getState(e){return e[this.key]}}const Kr=Object.create(null);function Ha(n){return n in Kr?n+"$"+ ++Kr[n]:(Kr[n]=0,n+"$")}class Or{constructor(e="key"){this.key=Ha(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const oe=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Zt=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e};let Ci=null;const qe=function(n,e,t){let r=Ci||(Ci=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},Zf=function(){Ci=null},At=function(n,e,t,r){return t&&(_s(n,e,t,r,-1)||_s(n,e,t,r,1))},eh=/^(img|br|input|textarea|hr)$/i;function _s(n,e,t,r,i){for(var o;;){if(n==t&&e==r)return!0;if(e==(i<0?0:Ce(n))){let s=n.parentNode;if(!s||s.nodeType!=1||zn(n)||eh.test(n.nodeName)||n.contentEditable=="false")return!1;e=oe(n)+(i<0?0:1),n=s}else if(n.nodeType==1){let s=n.childNodes[e+(i<0?-1:0)];if(s.nodeType==1&&s.contentEditable=="false")if(!((o=s.pmViewDesc)===null||o===void 0)&&o.ignoreForSelection)e+=i;else return!1;else n=s,e=i<0?Ce(n):0}else return!1}}function Ce(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function th(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=Ce(n)}else if(n.parentNode&&!zn(n))e=oe(n),n=n.parentNode;else return null}}function nh(n,e){for(;;){if(n.nodeType==3&&e2),we=en||(Be?/Mac/.test(Be.platform):!1),sh=Be?/Win/.test(Be.platform):!1,Je=/Android \d/.test(pt),Bn=!!vs&&"webkitFontSmoothing"in vs.documentElement.style,lh=Bn?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function ah(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function He(n,e){return typeof n=="number"?n:n[e]}function ch(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function ws(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,o=n.dom.ownerDocument;for(let s=t||n.dom;s;){if(s.nodeType!=1){s=Zt(s);continue}let l=s,a=l==o.body,c=a?ah(o):ch(l),u=0,f=0;if(e.topc.bottom-He(r,"bottom")&&(f=e.bottom-e.top>c.bottom-c.top?e.top+He(i,"top")-c.top:e.bottom-c.bottom+He(i,"bottom")),e.leftc.right-He(r,"right")&&(u=e.right-c.right+He(i,"right")),u||f)if(a)o.defaultView.scrollBy(u,f);else{let p=l.scrollLeft,m=l.scrollTop;f&&(l.scrollTop+=f),u&&(l.scrollLeft+=u);let g=l.scrollLeft-p,y=l.scrollTop-m;e={left:e.left-g,top:e.top-y,right:e.right-g,bottom:e.bottom-y}}let h=a?"fixed":getComputedStyle(s).position;if(/^(fixed|sticky)$/.test(h))break;s=h=="absolute"?s.offsetParent:Zt(s)}}function uh(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let o=(e.left+e.right)/2,s=t+1;s=t-20){r=l,i=a.top;break}}return{refDOM:r,refTop:i,stack:Ka(n.dom)}}function Ka(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=Zt(r));return e}function dh({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;Ja(t,r==0?0:r-e)}function Ja(n,e){for(let t=0;t=l){s=Math.max(m.bottom,s),l=Math.min(m.top,l);let g=m.left>e.left?m.left-e.left:m.right=(m.left+m.right)/2?1:0));continue}}else m.top>e.top&&!a&&m.left<=e.left&&m.right>=e.left&&(a=u,c={left:Math.max(m.left,Math.min(m.right,e.left)),top:m.top});!t&&(e.left>=m.right&&e.top>=m.top||e.left>=m.left&&e.top>=m.bottom)&&(o=f+1)}}return!t&&a&&(t=a,i=c,r=0),t&&t.nodeType==3?hh(t,i):!t||r&&t.nodeType==1?{node:n,offset:o}:Ga(t,i)}function hh(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(o.left+o.right)/2?1:0)}}return{node:n,offset:0}}function oo(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function ph(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(s.left+s.right)/2?1:-1}return n.docView.posFromDOM(r,i,o)}function gh(n,e,t,r){let i=-1;for(let o=e,s=!1;o!=n.dom;){let l=n.docView.nearestDesc(o,!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)&&(!s&&a.left>r.left||a.top>r.top?i=l.posBefore:(!s&&a.right-1?i:n.docView.posFromDOM(e,t,-1)}function Ya(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let c;Bn&&i&&r.nodeType==1&&(c=r.childNodes[i-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=gh(n,r,i,e))}l==null&&(l=mh(n,s,e));let a=n.docView.nearestDesc(s,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Cs(n){return n.top=0&&i==r.nodeValue.length?(a--,u=1):t<0?a--:c++,cn(et(qe(r,a,c),u),u<0)}if(!n.state.doc.resolve(e-(o||0)).parent.inlineContent){if(o==null&&i&&(t<0||i==Ce(r))){let a=r.childNodes[i-1];if(a.nodeType==1)return Jr(a.getBoundingClientRect(),!1)}if(o==null&&i=0)}if(o==null&&i&&(t<0||i==Ce(r))){let a=r.childNodes[i-1],c=a.nodeType==3?qe(a,Ce(a)-(s?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return cn(et(c,1),!1)}if(o==null&&i=0)}function cn(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Jr(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Qa(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function xh(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return Qa(n,e,()=>{let{node:o}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(o,!0);if(!l)break;if(l.node.isBlock){o=l.contentDOM||l.dom;break}o=l.dom.parentNode}let s=Xa(n,i.pos,1);for(let l=o.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=qe(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;cu.top+1&&(t=="up"?s.top-u.top>(u.bottom-s.top)*2:u.bottom-s.bottom>(s.bottom-u.top)*2))return!1}}return!0})}const kh=/[\u0590-\u08ac]/;function _h(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,o=!i,s=i==r.parent.content.size,l=n.domSelection();return l?!kh.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?o:s:Qa(n,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:u,anchorOffset:f}=n.domSelectionRange(),h=l.caretBidiLevel;l.modify("move",t,"character");let p=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:m,focusOffset:g}=n.domSelectionRange(),y=m&&!p.contains(m.nodeType==1?m:m.parentNode)||a==m&&c==g;try{l.collapse(u,f),a&&(a!=u||c!=f)&&l.extend&&l.extend(a,c)}catch{}return h!=null&&(l.caretBidiLevel=h),y}):r.pos==r.start()||r.pos==r.end()}let Ss=null,Ms=null,Os=!1;function vh(n,e,t){return Ss==e&&Ms==t?Os:(Ss=e,Ms=t,Os=t=="up"||t=="down"?xh(n,e,t):_h(n,e,t))}const Me=0,Ns=1,_t=2,Le=3;class Ln{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=Me,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;toe(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(t==0)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!1;break}if(o.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let o=e;;o=o.parentNode){if(o==this.dom){i=!0;break}if(o.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let o=this.getDesc(i),s;if(o&&(!t||o.node))if(r&&(s=o.nodeDOM)&&!(s.nodeType==1?s.contains(e.nodeType==1?e:e.parentNode):s==e))r=!1;else return o}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let o=this.getDesc(i);if(o)return o.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||s instanceof ec){i=e-o;break}o=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let o;r&&!(o=this.children[r-1]).size&&o instanceof Za&&o.side>=0;r--);if(t<=0){let o,s=!0;for(;o=r?this.children[r-1]:null,!(!o||o.dom.parentNode==this.contentDOM);r--,s=!1);return o&&t&&s&&!o.border&&!o.domAtom?o.domFromPos(o.size,t):{node:this.contentDOM,offset:o?oe(o.dom)+1:0}}else{let o,s=!0;for(;o=r=u&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,u);e=s;for(let f=l;f>0;f--){let h=this.children[f-1];if(h.size&&h.dom.parentNode==this.contentDOM&&!h.emptyChildAt(1)){i=oe(h.dom)+1;break}e-=h.size}i==-1&&(i=0)}if(i>-1&&(c>t||l==this.children.length-1)){t=c;for(let u=l+1;um&&st){let m=l;l=a,a=m}let p=document.createRange();p.setEnd(a.node,a.offset),p.setStart(l.node,l.offset),c.removeAllRanges(),c.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){let l=r+o.border,a=s-o.border;if(e>=l&&t<=a){this.dirty=e==r||t==s?_t:Ns,e==l&&t==a&&(o.contentLost||o.dom.parentNode!=this.contentDOM)?o.dirty=Le:o.markDirty(e-l,t-l);return}else o.dirty=o.dom==o.contentDOM&&o.dom.parentNode==this.contentDOM&&!o.children.length?_t:Le}r=s}this.dirty=_t}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?_t:Ns;t.dirty{if(!o)return i;if(o.parent)return o.parent.posBeforeChild(o)})),!t.type.spec.raw){if(s.nodeType!=1){let l=document.createElement("span");l.appendChild(s),s=l}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,o=this}matchesWidget(e){return this.dirty==Me&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class wh extends Ln{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}}class Rt extends Ln{constructor(e,t,r,i,o){super(e,[],r,i),this.mark=t,this.spec=o}static create(e,t,r,i){let o=i.nodeViews[t.type.name],s=o&&o(t,i,r);return(!s||!s.dom)&&(s=sn.renderSpec(document,t.type.spec.toDOM(t,r),null,t.attrs)),new Rt(e,t,s.dom,s.contentDOM||s.dom,s)}parseRule(){return this.dirty&Le||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Le&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Me){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(o=Ei(o,0,e,r));for(let l=0;l{if(!a)return s;if(a.parent)return a.parent.posBeforeChild(a)},r,i),u=c&&c.dom,f=c&&c.contentDOM;if(t.isText){if(!u)u=document.createTextNode(t.text);else if(u.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else u||({dom:u,contentDOM:f}=sn.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&u.nodeName!="BR"&&(u.hasAttribute("contenteditable")||(u.contentEditable="false"),t.type.spec.draggable&&(u.draggable=!0));let h=u;return u=rc(u,r,t),c?a=new Ch(e,t,r,i,u,f||null,h,c,o,s+1):t.isText?new Er(e,t,r,i,u,h,o):new ct(e,t,r,i,u,f||null,h,o,s+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>_.empty)}return e}matchesNode(e,t,r){return this.dirty==Me&&e.eq(this.node)&&fr(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,o=e.composing?this.localCompositionInfo(e,t):null,s=o&&o.pos>-1?o:null,l=o&&o.pos<0,a=new Mh(this,s&&s.node,e);Eh(this.node,this.innerDeco,(c,u,f)=>{c.spec.marks?a.syncToMarks(c.spec.marks,r,e):c.type.side>=0&&!f&&a.syncToMarks(u==this.node.childCount?$.none:this.node.child(u).marks,r,e),a.placeWidget(c,e,i)},(c,u,f,h)=>{a.syncToMarks(c.marks,r,e);let p;a.findNodeMatch(c,u,f,h)||l&&e.state.selection.from>i&&e.state.selection.to-1&&a.updateNodeAt(c,u,f,p,e)||a.updateNextNode(c,u,f,e,h,i)||a.addNode(c,u,f,e,i),i+=c.nodeSize}),a.syncToMarks([],r,e),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==_t)&&(s&&this.protectLocalComposition(e,s),tc(this.contentDOM,this.children,e),en&&Th(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof D)||rt+this.node.content.size)return null;let o=e.input.compositionNode;if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let s=o.nodeValue,l=Ih(this.node.content,s,r-t,i-t);return l<0?null:{node:o,pos:l,text:s}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let o=t;for(;o.parentNode!=this.contentDOM;o=o.parentNode){for(;o.previousSibling;)o.parentNode.removeChild(o.previousSibling);for(;o.nextSibling;)o.parentNode.removeChild(o.nextSibling);o.pmViewDesc&&(o.pmViewDesc=void 0)}let s=new wh(this,o,t,i);e.input.compositionNodes.push(s),this.children=Ei(this.children,r,r+i.length,e,s)}update(e,t,r,i){return this.dirty==Le||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=Me}updateOuterDeco(e){if(fr(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=nc(this.dom,this.nodeDOM,Ni(this.outerDeco,this.node,t),Ni(e,this.node,t)),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 Es(n,e,t,r,i){rc(r,e,n);let o=new ct(void 0,n,e,t,r,r,r,i,0);return o.contentDOM&&o.updateChildren(i,0),o}class Er extends ct{constructor(e,t,r,i,o,s,l){super(e,t,r,i,o,null,s,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==Le||this.dirty!=Me&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Me||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=Me,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),o=document.createTextNode(i.text);return new Er(this.parent,i,this.outerDeco,this.innerDeco,o,o,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Le)}get domAtom(){return!1}isText(e){return this.node.text==e}}class ec extends Ln{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Me&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class Ch extends ct{constructor(e,t,r,i,o,s,l,a,c,u){super(e,t,r,i,o,s,l,c,u),this.spec=a}update(e,t,r,i){if(this.dirty==Le)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let o=this.spec.update(e,t,r);return o&&this.updateInner(e,t,r,i),o}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r.root):super.setSelection(e,t,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 tc(n,e,t){let r=n.firstChild,i=!1;for(let o=0;o>1,s=Math.min(o,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let a=Rt.create(this.top,e[o],t,r);this.top.children.splice(this.index,0,a),this.top=a,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,r,i){let o=-1,s;if(i>=this.preMatch.index&&(s=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&s.matchesNode(e,t,r))o=this.top.children.indexOf(s,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let c=t.children[r-1];if(c instanceof Rt)t=c,r=c.children.length;else{l=c,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=n.child(i-1))break;--i,o.set(l,i),s.push(l)}}return{index:i,matched:o,matches:s.reverse()}}function Nh(n,e){return n.type.side-e.type.side}function Eh(n,e,t,r){let i=e.locals(n),o=0;if(i.length==0){for(let c=0;co;)l.push(i[s++]);let m=o+h.nodeSize;if(h.isText){let y=m;s!y.inline):l.slice();r(h,g,e.forChild(o,h),p),o=m}}function Th(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function Ih(n,e,t,r){for(let i=0,o=0;i=t){if(o>=r&&a.slice(r-e.length-l,r-l)==e)return r-e.length;let c=l=0&&c+e.length+l>=t)return l+c;if(t==r&&a.length>=r+e.length-l&&a.slice(r-l,r-l+e.length)==e)return r}}return-1}function Ei(n,e,t,r,i){let o=[];for(let s=0,l=0;s=t||u<=e?o.push(a):(ct&&o.push(a.slice(t-c,a.size,r)))}return o}function so(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),o=i&&i.size==0,s=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(s<0)return null;let l=r.resolve(s),a,c;if(Nr(t)){for(a=s;i&&!i.node;)i=i.parent;let f=i.node;if(i&&f.isAtom&&T.isSelectable(f)&&i.parent&&!(f.isInline&&rh(t.focusNode,t.focusOffset,i.dom))){let h=i.posBefore;c=new T(s==h?l:r.resolve(h))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=s,h=s;for(let p=0;p{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!ic(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Ah(n){let e=n.domSelection();if(!e)return;let t=n.cursorWrapper.dom,r=t.nodeName=="IMG";r?e.collapse(t.parentNode,oe(t)+1):e.collapse(t,0),!r&&!n.state.selection.visible&&be&&at<=11&&(t.disabled=!0,t.disabled=!1)}function oc(n,e){if(e instanceof T){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(Rs(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else Rs(n)}function Rs(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function lo(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||D.between(e,t,r)}function Ps(n){return n.editable&&!n.hasFocus()?!1:sc(n)}function sc(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function Rh(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return At(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Ti(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),o=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return o&&F.findFrom(o,e)}function nt(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function zs(n,e,t){let r=n.state.selection;if(r instanceof D)if(t.indexOf("s")>-1){let{$head:i}=r,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let s=n.state.doc.resolve(i.pos+o.nodeSize*(e<0?-1:1));return nt(n,new D(r.$anchor,s))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Ti(n.state,e);return i&&i instanceof T?nt(n,i):!1}else if(!(we&&t.indexOf("m")>-1)){let i=r.$head,o=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,s;if(!o||o.isText)return!1;let l=e<0?i.pos-o.nodeSize:i.pos;return o.isAtom||(s=n.docView.descAt(l))&&!s.contentDOM?T.isSelectable(o)?nt(n,new T(e<0?n.state.doc.resolve(i.pos-o.nodeSize):i)):Bn?nt(n,new D(n.state.doc.resolve(e<0?l:l+o.nodeSize))):!1:!1}}else return!1;else{if(r instanceof T&&r.node.isInline)return nt(n,new D(e>0?r.$to:r.$from));{let i=Ti(n.state,e);return i?nt(n,i):!1}}}function hr(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function yn(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function Vt(n,e){return e<0?Ph(n):zh(n)}function Ph(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,o,s=!1;for(Se&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(yn(l,-1))i=t,o=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(lc(t))break;{let l=t.previousSibling;for(;l&&yn(l,-1);)i=t.parentNode,o=oe(l),l=l.previousSibling;if(l)t=l,r=hr(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}s?Ii(n,t,r):i&&Ii(n,i,o)}function zh(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=hr(t),o,s;for(;;)if(r{n.state==i&&Ye(n)},50)}function Bs(n,e){let t=n.state.doc.resolve(e);if(!(ue||sh)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let o=n.coordsAtPos(e-1),s=(o.top+o.bottom)/2;if(s>i.top&&s1)return o.lefti.top&&s1)return o.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function Ls(n,e,t){let r=n.state.selection;if(r instanceof D&&!r.empty||t.indexOf("s")>-1||we&&t.indexOf("m")>-1)return!1;let{$from:i,$to:o}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let s=Ti(n.state,e);if(s&&s instanceof T)return nt(n,s)}if(!i.parent.inlineContent){let s=e<0?i:o,l=r instanceof ke?F.near(s,e):F.findFrom(s,e);return l?nt(n,l):!1}return!1}function Fs(n,e){if(!(n.state.selection instanceof D))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let o=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(o&&!o.isText){let s=n.state.tr;return e<0?s.delete(t.pos-o.nodeSize,t.pos):s.delete(t.pos,t.pos+o.nodeSize),n.dispatch(s),!0}return!1}function $s(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Fh(n){if(!pe||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;$s(n,r,"true"),setTimeout(()=>$s(n,r,"false"),20)}return!1}function $h(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Vh(n,e){let t=e.keyCode,r=$h(e);if(t==8||we&&t==72&&r=="c")return Fs(n,-1)||Vt(n,-1);if(t==46&&!e.shiftKey||we&&t==68&&r=="c")return Fs(n,1)||Vt(n,1);if(t==13||t==27)return!0;if(t==37||we&&t==66&&r=="c"){let i=t==37?Bs(n,n.state.selection.from)=="ltr"?-1:1:-1;return zs(n,i,r)||Vt(n,i)}else if(t==39||we&&t==70&&r=="c"){let i=t==39?Bs(n,n.state.selection.from)=="ltr"?1:-1:1;return zs(n,i,r)||Vt(n,i)}else{if(t==38||we&&t==80&&r=="c")return Ls(n,-1,r)||Vt(n,-1);if(t==40||we&&t==78&&r=="c")return Fh(n)||Ls(n,1,r)||Vt(n,1);if(r==(we?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function ao(n,e){n.someProp("transformCopied",p=>{e=p(e,n)});let t=[],{content:r,openStart:i,openEnd:o}=e;for(;i>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,o--;let p=r.firstChild;t.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),r=p.content}let s=n.someProp("clipboardSerializer")||sn.fromSchema(n.state.schema),l=hc(),a=l.createElement("div");a.appendChild(s.serializeFragment(r,{document:l}));let c=a.firstChild,u,f=0;for(;c&&c.nodeType==1&&(u=fc[c.nodeName.toLowerCase()]);){for(let p=u.length-1;p>=0;p--){let m=l.createElement(u[p]);for(;a.firstChild;)m.appendChild(a.firstChild);a.appendChild(m),f++}c=a.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${i} ${o}${f?` -${f}`:""} ${JSON.stringify(t)}`);let h=n.someProp("clipboardTextSerializer",p=>p(e,n))||e.content.textBetween(0,e.content.size,` `);return{dom:a,text:h,slice:e}}function ac(n,e,t,r,i){let o=i.parent.type.spec.code,s,l;if(!t&&!e)return null;let a=!!e&&(r||o||!t);if(a){if(n.someProp("transformPastedText",h=>{e=h(e,o||r,n)}),o)return l=new C(_.from(n.state.schema.text(e.replace(/\r\n?/g,` `))),0,0),n.someProp("transformPasted",h=>{l=h(l,n,!0)}),l;let f=n.someProp("clipboardTextParser",h=>h(e,i,r,n));if(f)l=f;else{let h=i.marks(),{schema:p}=n.state,m=sn.fromSchema(p);s=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(g=>{let y=s.appendChild(document.createElement("p"));g&&y.appendChild(m.serializeNode(p.text(g,h)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),s=qh(t),Bn&&Wh(s);let c=s&&s.querySelector("[data-pm-slice]"),u=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(u&&u[3])for(let f=+u[3];f>0;f--){let h=s.firstChild;for(;h&&h.nodeType!=1;)h=h.nextSibling;if(!h)break;s=h}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||Cn.fromSchema(n.state.schema)).parseSlice(s,{preserveWhitespace:!!(a||u),context:i,ruleFromNode(h){return h.nodeName=="BR"&&!h.nextSibling&&h.parentNode&&!Uh.test(h.parentNode.nodeName)?{ignore:!0}:null}})),u)l=Kh(Vs(l,+u[1],+u[2]),u[4]);else if(l=C.maxOpen(jh(l.content,i),!0),l.openStart||l.openEnd){let f=0,h=0;for(let p=l.content.firstChild;f{l=f(l,n,a)}),l}const Uh=/^(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 jh(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),o,s=[];if(n.forEach(l=>{if(!s)return;let a=i.findWrapping(l.type),c;if(!a)return s=null;if(c=s.length&&o.length&&uc(a,o,l,s[s.length-1],0))s[s.length-1]=c;else{s.length&&(s[s.length-1]=dc(s[s.length-1],o.length));let u=cc(l,a);s.push(u),i=i.matchType(u.type),o=a}}),s)return _.from(s)}return n}function cc(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,_.from(n));return n}function uc(n,e,t,r,i){if(i1&&(o=0),i=t&&(l=e<0?s.contentMatchAt(0).fillBefore(l,o<=i).append(l):l.append(s.contentMatchAt(s.childCount).fillBefore(_.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,s.copy(l))}function Vs(n,e,t){return et})),Yr.createHTML(n)):n}function qh(n){let e=/^(\s*]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=hc().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&fc[r[1].toLowerCase()])&&(n=i.map(o=>"<"+o+">").join("")+n+i.map(o=>"").reverse().join("")),t.innerHTML=Hh(n),i)for(let o=0;o=0;l-=2){let a=t.nodes[r[l]];if(!a||a.hasRequiredAttrs())break;i=_.from(a.create(r[l+1],i)),o++,s++}return new C(i,o,s)}const me={},ge={},Jh={touchstart:!0,touchmove:!0};class Gh{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.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function Yh(n){for(let e in me){let t=me[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{Qh(n,r)&&!co(n,r)&&(n.editable||!(r.type in ge))&&t(n,r)},Jh[e]?{passive:!0}:void 0)}pe&&n.dom.addEventListener("input",()=>null),Ai(n)}function lt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Xh(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function Ai(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>co(n,r))})}function co(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function Qh(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function Zh(n,e){!co(n,e)&&me[e.type]&&(n.editable||!(e.type in ge))&&me[e.type](n,e)}ge.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!mc(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(Je&&ue&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),en&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,xt(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Vh(n,t)?t.preventDefault():lt(n,"key")};ge.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};ge.keypress=(n,e)=>{let t=e;if(mc(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||we&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof D)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode),o=()=>n.state.tr.insertText(i).scrollIntoView();!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",s=>s(n,r.$from.pos,r.$to.pos,i,o))&&n.dispatch(o()),t.preventDefault()}};function Tr(n){return{left:n.clientX,top:n.clientY}}function ep(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function uo(n,e,t,r,i){if(r==-1)return!1;let o=n.state.doc.resolve(r);for(let s=o.depth+1;s>0;s--)if(n.someProp(e,l=>s>o.depth?l(n,t,o.nodeAfter,o.before(s),i,!0):l(n,t,o.node(s),o.before(s),i,!1)))return!0;return!1}function Jt(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);r.setMeta("pointer",!0),n.dispatch(r)}function tp(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&T.isSelectable(r)?(Jt(n,new T(t)),!0):!1}function np(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof T&&(r=t.node);let o=n.state.doc.resolve(e);for(let s=o.depth+1;s>0;s--){let l=s>o.depth?o.nodeAfter:o.node(s);if(T.isSelectable(l)){r&&t.$from.depth>0&&s>=t.$from.depth&&o.before(t.$from.depth+1)==t.$from.pos?i=o.before(t.$from.depth):i=o.before(s);break}}return i!=null?(Jt(n,T.create(n.state.doc,i)),!0):!1}function rp(n,e,t,r,i){return uo(n,"handleClickOn",e,t,r)||n.someProp("handleClick",o=>o(n,e,r))||(i?np(n,t):tp(n,t))}function ip(n,e,t,r){return uo(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function op(n,e,t,r){return uo(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||sp(n,t,r)}function sp(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(Jt(n,D.create(r,0,r.content.size)),!0):!1;let i=r.resolve(e);for(let o=i.depth+1;o>0;o--){let s=o>i.depth?i.nodeAfter:i.node(o),l=i.before(o);if(s.inlineContent)Jt(n,D.create(r,l+1,l+1+s.content.size));else if(T.isSelectable(s))Jt(n,T.create(r,l));else continue;return!0}}function fo(n){return pr(n)}const pc=we?"metaKey":"ctrlKey";me.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=fo(n),i=Date.now(),o="singleClick";i-n.input.lastClick.time<500&&ep(t,n.input.lastClick)&&!t[pc]&&n.input.lastClick.button==t.button&&(n.input.lastClick.type=="singleClick"?o="doubleClick":n.input.lastClick.type=="doubleClick"&&(o="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:o,button:t.button};let s=n.posAtCoords(Tr(t));s&&(o=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new lp(n,s,t,!!r)):(o=="doubleClick"?ip:op)(n,s.pos,s.inside,t)?t.preventDefault():lt(n,"pointer"))};class lp{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[pc],this.allowDefault=r.shiftKey;let o,s;if(t.inside>-1)o=e.state.doc.nodeAt(t.inside),s=t.inside;else{let u=e.state.doc.resolve(t.pos);o=u.parent,s=u.depth?u.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:c}=e.state;(r.button==0&&o.type.spec.draggable&&o.type.spec.selectable!==!1||c instanceof T&&c.from<=s&&c.to>s)&&(this.mightDrag={node:o,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Se&&!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)),lt(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(()=>Ye(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(Tr(e))),this.updateAllowDefault(e),this.allowDefault||!t?lt(this.view,"pointer"):rp(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||pe&&this.mightDrag&&!this.mightDrag.node.isAtom||ue&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(Jt(this.view,F.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):lt(this.view,"pointer")}move(e){this.updateAllowDefault(e),lt(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)}}me.touchstart=n=>{n.input.lastTouch=Date.now(),fo(n),lt(n,"pointer")};me.touchmove=n=>{n.input.lastTouch=Date.now(),lt(n,"pointer")};me.contextmenu=n=>fo(n);function mc(n,e){return n.composing?!0:pe&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}const ap=Je?5e3:-1;ge.compositionstart=ge.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof D&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),pr(n,!0),n.markCursor=null;else if(pr(n,!e.selection.empty),Se&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,o=r.focusOffset;i&&i.nodeType==1&&o!=0;){let s=o<0?i.lastChild:i.childNodes[o-1];if(!s)break;if(s.nodeType==3){let l=n.domSelection();l&&l.collapse(s,s.nodeValue.length);break}else i=s,o=-1}}n.input.composing=!0}gc(n,ap)};ge.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,gc(n,20))};function gc(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>pr(n),e))}function bc(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=up());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function cp(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=th(e.focusNode,e.focusOffset),r=nh(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,o=n.domObserver.lastChangedTextNode;if(t==o||r==o)return o;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let s=t.pmViewDesc;if(!(!s||!s.isText(t.nodeValue)))return r}}return t||r}function up(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function pr(n,e=!1){if(!(Je&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),bc(n),e||n.docView&&n.docView.dirty){let t=so(n),r=n.state.selection;return t&&!t.eq(r)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function dp(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}const Nn=be&&at<15||en&&lh<604;me.copy=ge.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let o=Nn?null:t.clipboardData,s=r.content(),{dom:l,text:a}=ao(n,s);o?(t.preventDefault(),o.clearData(),o.setData("text/html",l.innerHTML),o.setData("text/plain",a)):dp(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function fp(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function hp(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?En(n,r.value,null,i,e):En(n,r.textContent,r.innerHTML,i,e)},50)}function En(n,e,t,r,i){let o=ac(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",a=>a(n,i,o||C.empty)))return!0;if(!o)return!1;let s=fp(o),l=s?n.state.tr.replaceSelectionWith(s,r):n.state.tr.replaceSelection(o);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function yc(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}ge.paste=(n,e)=>{let t=e;if(n.composing&&!Je)return;let r=Nn?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&En(n,yc(r),r.getData("text/html"),i,t)?t.preventDefault():hp(n,t)};class xc{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}}const pp=we?"altKey":"ctrlKey";function kc(n,e){let t=n.someProp("dragCopies",r=>!r(e));return t??!e[pp]}me.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,o=i.empty?null:n.posAtCoords(Tr(t)),s;if(!(o&&o.pos>=i.from&&o.pos<=(i instanceof T?i.to-1:i.to))){if(r&&r.mightDrag)s=T.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(s=T.create(n.state.doc,f.posBefore))}}let l=(s||n.state.selection).content(),{dom:a,text:c,slice:u}=ao(n,l);(!t.dataTransfer.files.length||!ue||Wa>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Nn?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",Nn||t.dataTransfer.setData("text/plain",c),n.dragging=new xc(u,kc(n,t),s)};me.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};ge.dragover=ge.dragenter=(n,e)=>e.preventDefault();ge.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(Tr(t));if(!i)return;let o=n.state.doc.resolve(i.pos),s=r&&r.slice;s?n.someProp("transformPasted",m=>{s=m(s,n,!1)}):s=ac(n,yc(t.dataTransfer),Nn?null:t.dataTransfer.getData("text/html"),!1,o);let l=!!(r&&kc(n,t));if(n.someProp("handleDrop",m=>m(n,t,s||C.empty,l))){t.preventDefault();return}if(!s)return;t.preventDefault();let a=s?Vf(n.state.doc,o.pos,s):o.pos;a==null&&(a=o.pos);let c=n.state.tr;if(l){let{node:m}=r;m?m.replace(c):c.deleteSelection()}let u=c.mapping.map(a),f=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,h=c.doc;if(f?c.replaceRangeWith(u,u,s.content.firstChild):c.replaceRange(u,u,s),c.doc.eq(h))return;let p=c.doc.resolve(u);if(f&&T.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))c.setSelection(new T(p));else{let m=c.mapping.map(a);c.mapping.maps[c.mapping.maps.length-1].forEach((g,y,x,v)=>m=v),c.setSelection(lo(n,p,c.doc.resolve(m)))}n.focus(),n.dispatch(c.setMeta("uiEvent","drop"))};me.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&Ye(n)},20))};me.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};me.beforeinput=(n,e)=>{if(ue&&Je&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",o=>o(n,xt(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in ge)me[n]=ge[n];function Tn(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}class mr{constructor(e,t){this.toDOM=e,this.spec=t||Mt,this.side=this.spec.side||0}map(e,t,r,i){let{pos:o,deleted:s}=e.mapResult(t.from+i,this.side<0?-1:1);return s?null:new xe(o-r,o-r,this)}valid(){return!0}eq(e){return this==e||e instanceof mr&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Tn(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class ut{constructor(e,t){this.attrs=e,this.spec=t||Mt}map(e,t,r,i){let o=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,s=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return o>=s?null:new xe(o,s,this)}valid(e,t){return t.from=e&&(!o||o(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let s=0;se){let l=this.children[s]+1;this.children[s+2].findInner(e-l,t-l,r,i+l,o)}}map(e,t,r){return this==ae||e.maps.length==0?this:this.mapInner(e,t,0,0,r||Mt)}mapInner(e,t,r,i,o){let s;for(let l=0;l{let c=a+r,u;if(u=vc(t,l,c)){for(i||(i=this.children.slice());ol&&f.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let o=e+1,s=o+t.content.size;for(let l=0;lo&&a.type instanceof ut){let c=Math.max(o,a.from)-o,u=Math.min(s,a.to)-o;ci.map(e,t,Mt));return it.from(r)}forChild(e,t){if(t.isLeaf)return W.empty;let r=[];for(let i=0;it instanceof W)?e:e.reduce((t,r)=>t.concat(r instanceof W?r:r.members),[]))}}forEachSet(e){for(let t=0;t{let y=g-m-(p-h);for(let x=0;xv+u-f)continue;let S=l[x]+u-f;p>=S?l[x+1]=h<=S?-2:-1:h>=u&&y&&(l[x]+=y,l[x+1]+=y)}f+=y}),u=t.maps[c].map(u,-1)}let a=!1;for(let c=0;c=r.content.size){a=!0;continue}let h=t.map(n[c+1]+o,-1),p=h-i,{index:m,offset:g}=r.content.findIndex(f),y=r.maybeChild(m);if(y&&g==f&&g+y.nodeSize==p){let x=l[c+2].mapInner(t,y,u+1,n[c]+o+1,s);x!=ae?(l[c]=f,l[c+1]=p,l[c+2]=x):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=gp(l,n,e,t,i,o,s),u=gr(c,r,0,s);e=u.local;for(let f=0;ft&&s.to{let c=vc(n,l,a+t);if(c){o=!0;let u=gr(c,l,t+a+1,r);u!=ae&&i.push(a,a+l.nodeSize,u)}});let s=_c(o?wc(n):n,-t).sort(Ot);for(let l=0;l0;)e++;n.splice(e,0,t)}function Xr(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=ae&&e.push(r)}),n.cursorWrapper&&e.push(W.create(n.state.doc,[n.cursorWrapper.deco])),it.from(e)}const bp={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},yp=be&&at<=11;class xp{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 kp{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new xp,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():this.flush()}),yp&&(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,bp)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;tthis.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(Ps(this.view)){if(this.suppressingSelectionUpdates)return Ye(this.view);if(be&&at<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&At(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let o=e.focusNode;o;o=Zt(o))t.add(o);for(let o=e.anchorNode;o;o=Zt(o))if(t.has(o)){r=o;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 t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&Ps(e)&&!this.ignoreSelectionChange(r),o=-1,s=-1,l=!1,a=[];if(e.editable)for(let u=0;uf.nodeName=="BR");if(u.length==2){let[f,h]=u;f.parentNode&&f.parentNode.parentNode==h.parentNode?h.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let h of u){let p=h.parentNode;p&&p.nodeName=="LI"&&(!f||wp(e,f)!=p)&&h.remove()}}}let c=null;o<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(o>-1&&(e.docView.markDirty(o,s),_p(e)),this.handleDOMChange(o,s,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||Ye(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.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 u=0;ui;y--){let x=r.childNodes[y-1],v=x.pmViewDesc;if(x.nodeName=="BR"&&!v){o=y;break}if(!v||v.size)break}let f=n.state.doc,h=n.someProp("domParser")||Cn.fromSchema(n.state.schema),p=f.resolve(s),m=null,g=h.parse(r,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:i,to:o,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:Sp,context:p});if(c&&c[0].pos!=null){let y=c[0].pos,x=c[1]&&c[1].pos;x==null&&(x=y),m={anchor:y+s,head:x+s}}return{doc:g,sel:m,from:s,to:l}}function Sp(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(pe&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||pe&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}const Mp=/^(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 Op(n,e,t,r,i){let o=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let I=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,L=so(n,I);if(L&&!n.state.selection.eq(L)){if(ue&&Je&&n.input.lastKeyCode===13&&Date.now()-100Ve(n,xt(13,"Enter"))))return;let U=n.state.tr.setSelection(L);I=="pointer"?U.setMeta("pointer",!0):I=="key"&&U.scrollIntoView(),o&&U.setMeta("composition",o),n.dispatch(U)}return}let s=n.state.doc.resolve(e),l=s.sharedDepth(t);e=s.before(l+1),t=n.state.doc.resolve(t).after(l+1);let a=n.state.selection,c=Cp(n,e,t),u=n.state.doc,f=u.slice(c.from,c.to),h,p;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||Je)&&i.some(I=>I.nodeType==1&&!Mp.test(I.nodeName))&&(!m||m.endA>=m.endB)&&n.someProp("handleKeyDown",I=>I(n,xt(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!m)if(r&&a instanceof D&&!a.empty&&a.$head.sameParent(a.$anchor)&&!n.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))m={start:a.from,endA:a.to,endB:a.to};else{if(c.sel){let I=Ks(n,n.state.doc,c.sel);if(I&&!I.eq(n.state.selection)){let L=n.state.tr.setSelection(I);o&&L.setMeta("composition",o),n.dispatch(L)}}return}n.state.selection.fromn.state.selection.from&&m.start<=n.state.selection.from+2&&n.state.selection.from>=c.from?m.start=n.state.selection.from:m.endA=n.state.selection.to-2&&n.state.selection.to<=c.to&&(m.endB+=n.state.selection.to-m.endA,m.endA=n.state.selection.to)),be&&at<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>c.from&&c.doc.textBetween(m.start-c.from-1,m.start-c.from+1)=="  "&&(m.start--,m.endA--,m.endB--);let g=c.doc.resolveNoCache(m.start-c.from),y=c.doc.resolveNoCache(m.endB-c.from),x=u.resolve(m.start),v=g.sameParent(y)&&g.parent.inlineContent&&x.end()>=m.endA;if((en&&n.input.lastIOSEnter>Date.now()-225&&(!v||i.some(I=>I.nodeName=="DIV"||I.nodeName=="P"))||!v&&g.posI(n,xt(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>m.start&&Ep(u,m.start,m.endA,g,y)&&n.someProp("handleKeyDown",I=>I(n,xt(8,"Backspace")))){Je&&ue&&n.domObserver.suppressSelectionUpdates();return}ue&&m.endB==m.start&&(n.input.lastChromeDelete=Date.now()),Je&&!v&&g.start()!=y.start()&&y.parentOffset==0&&g.depth==y.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==m.endA&&(m.endB-=2,y=c.doc.resolveNoCache(m.endB-c.from),setTimeout(()=>{n.someProp("handleKeyDown",function(I){return I(n,xt(13,"Enter"))})},20));let S=m.start,N=m.endA,J=I=>{let L=I||n.state.tr.replace(S,N,c.doc.slice(m.start-c.from,m.endB-c.from));if(c.sel){let U=Ks(n,L.doc,c.sel);U&&!(ue&&n.composing&&U.empty&&(m.start!=m.endB||n.input.lastChromeDeleteYe(n),20));let I=J(n.state.tr.delete(S,N)),L=u.resolve(m.start).marksAcross(u.resolve(m.endA));L&&I.ensureMarks(L),n.dispatch(I)}else if(m.endA==m.endB&&(V=Np(g.parent.content.cut(g.parentOffset,y.parentOffset),x.parent.content.cut(x.parentOffset,m.endA-x.start())))){let I=J(n.state.tr);V.type=="add"?I.addMark(S,N,V.mark):I.removeMark(S,N,V.mark),n.dispatch(I)}else if(g.parent.child(g.index()).isText&&g.index()==y.index()-(y.textOffset?0:1)){let I=g.parent.textBetween(g.parentOffset,y.parentOffset),L=()=>J(n.state.tr.insertText(I,S,N));n.someProp("handleTextInput",U=>U(n,S,N,I,L))||n.dispatch(L())}}else n.dispatch(J())}function Ks(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:lo(n,e.resolve(t.anchor),e.resolve(t.head))}function Np(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,o=r,s,l,a;for(let u=0;uu.mark(l.addToSet(u.marks));else if(i.length==0&&o.length==1)l=o[0],s="remove",a=u=>u.mark(l.removeFromSet(u.marks));else return null;let c=[];for(let u=0;ut||Qr(s,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let o=n.node(r).maybeChild(n.indexAfter(r));for(;o&&!o.isLeaf;)o=o.firstChild,i++}return i}function Tp(n,e,t,r,i){let o=n.findDiffStart(e,t);if(o==null)return null;let{a:s,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let a=Math.max(0,o-Math.min(s,l));r-=s+a-o}if(s=s?o-r:0;o-=a,o&&o=l?o-r:0;o-=a,o&&o=56320&&e<=57343&&t>=55296&&t<=56319}class Cc{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new Gh,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Zs),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=Xs(this),Ys(this),this.nodeViews=Qs(this),this.docView=Es(this.state.doc,Gs(this),Xr(this),this.dom,this),this.domObserver=new kp(this,(r,i,o,s)=>Op(this,r,i,o,s)),this.domObserver.start(),Yh(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&Ai(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Zs),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,o=!1,s=!1;e.storedMarks&&this.composing&&(bc(this),s=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let p=Qs(this);Dp(p,this.nodeViews)&&(this.nodeViews=p,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&Ai(this),this.editable=Xs(this),Ys(this);let a=Xr(this),c=Gs(this),u=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=o||!this.docView.matchesNode(e.doc,c,a);(f||!e.selection.eq(i.selection))&&(s=!0);let h=u=="preserve"&&s&&this.dom.style.overflowAnchor==null&&uh(this);if(s){this.domObserver.stop();let p=f&&(be||ue)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Ip(i.selection,e.selection);if(f){let m=ue?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=cp(this)),(o||!this.docView.update(e.doc,c,a,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=Es(e.doc,c,a,this.dom,this)),m&&!this.trackWrites&&(p=!0)}p||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Rh(this))?Ye(this,p):(oc(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),u=="reset"?this.dom.scrollTop=0:u=="to selection"?this.scrollToSelection():h&&dh(h)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof T){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&ws(this,t.getBoundingClientRect(),e)}else ws(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 t=0;t0&&this.state.doc.nodeAt(o))==r.node&&(i=o)}this.dragging=new xc(e.slice,e.move,i<0?void 0:T.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let s=0;st.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return bh(this,e)}coordsAtPos(e,t=1){return Xa(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return vh(this,t||this.state,e)}pasteHTML(e,t){return En(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return En(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return ao(this,e)}destroy(){this.docView&&(Xh(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Xr(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Zf())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Zh(this,e)}domSelectionRange(){let e=this.domSelection();return e?pe&&this.root.nodeType===11&&ih(this.dom.ownerDocument)==this.dom&&vp(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}Cc.prototype.dispatch=function(n){let e=this._props.dispatchTransaction;e?e.call(this,n):this.updateState(this.state.apply(n))};function Gs(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[xe.node(0,n.state.doc.content.size,e)]}function Ys(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:xe.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function Xs(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Ip(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function Qs(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function Dp(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function Zs(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}const Sc=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Ap(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}const Rp=(n,e,t)=>{let r=Ap(n,t);if(!r)return!1;let i=Mc(r);if(!i){let s=r.blockRange(),l=s&&Pn(s);return l==null?!1:(e&&e(n.tr.lift(s,l).scrollIntoView()),!0)}let o=i.nodeBefore;if(Tc(n,i,e,-1))return!0;if(r.parent.content.size==0&&(tn(o,"end")||T.isSelectable(o)))for(let s=r.depth;;s--){let l=ro(n.doc,r.before(s),r.after(s),C.empty);if(l&&l.slice.size1)break}return o.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-o.nodeSize,i.pos).scrollIntoView()),!0):!1};function tn(n,e,t=!1){for(let r=n;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(t&&r.childCount!=1)return!1}return!1}const Pp=(n,e,t)=>{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;o=Mc(r)}let s=o&&o.nodeBefore;return!s||!T.isSelectable(s)?!1:(e&&e(n.tr.setSelection(T.create(n.doc,o.pos-s.nodeSize)).scrollIntoView()),!0)};function Mc(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function zp(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=zp(n,t);if(!r)return!1;let i=Oc(r);if(!i)return!1;let o=i.nodeAfter;if(Tc(n,i,e,1))return!0;if(r.parent.content.size==0&&(tn(o,"start")||T.isSelectable(o))){let s=ro(n.doc,r.before(),r.after(),C.empty);if(s&&s.slice.size{let{$head:r,empty:i}=n.selection,o=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset=0;e--){let t=n.node(e);if(n.index(e)+1{let t=n.selection,r=t instanceof T,i;if(r){if(t.node.isTextblock||!ln(n.doc,t.from))return!1;i=t.from}else if(i=La(n.doc,t.from,-1),i==null)return!1;if(e){let o=n.tr.join(i);r&&o.setSelection(T.create(o.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(o.scrollIntoView())}return!0},$p=(n,e)=>{let t=n.selection,r;if(t instanceof T){if(t.node.isTextblock||!ln(n.doc,t.to))return!1;r=t.to}else if(r=La(n.doc,t.to,1),r==null)return!1;return e&&e(n.tr.join(r).scrollIntoView()),!0},Nc=(n,e)=>{let{$from:t,$to:r}=n.selection,i=t.blockRange(r),o=i&&Pn(i);return o==null?!1:(e&&e(n.tr.lift(i,o).scrollIntoView()),!0)},Vp=(n,e)=>{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(` `).scrollIntoView()),!0)};function mo(n){for(let e=0;e{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),o=t.indexAfter(-1),s=mo(i.contentMatchAt(o));if(!s||!i.canReplaceWith(o,o,s))return!1;if(e){let l=t.after(),a=n.tr.replaceWith(l,l,s.createAndFill());a.setSelection(F.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},Up=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof ke||r.parent.inlineContent||i.parent.inlineContent)return!1;let o=mo(i.parent.contentMatchAt(i.indexAfter()));if(!o||!o.isTextblock)return!1;if(e){let s=(!r.parentOffset&&i.index(){let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let o=t.before();if(Wt(n.doc,o))return e&&e(n.tr.split(o).scrollIntoView()),!0}let r=t.blockRange(),i=r&&Pn(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function Hp(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof T&&e.selection.node.isBlock)return!r.parentOffset||!Wt(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let o=[],s,l,a=!1,c=!1;for(let p=r.depth;;p--)if(r.node(p).isBlock){a=r.end(p)==r.pos+(r.depth-p),c=r.start(p)==r.pos-(r.depth-p),l=mo(r.node(p-1).contentMatchAt(r.indexAfter(p-1))),o.unshift(a&&l?{type:l}:null),s=p;break}else{if(p==1)return!1;o.unshift(null)}let u=e.tr;(e.selection instanceof D||e.selection instanceof ke)&&u.deleteSelection();let f=u.mapping.map(r.pos),h=Wt(u.doc,f,o.length,o);if(h||(o[0]=l?{type:l}:null,h=Wt(u.doc,f,o.length,o)),!h)return!1;if(u.split(f,o.length,o),!a&&c&&r.node(s).type!=l){let p=u.mapping.map(r.before(s)),m=u.doc.resolve(p);l&&r.node(s-1).canReplaceWith(m.index(),m.index()+1,l)&&u.setNodeMarkup(u.mapping.map(r.before(s)),l)}return t&&t(u.scrollIntoView()),!0}}const qp=Hp(),Wp=(n,e)=>{let{$from:t,to:r}=n.selection,i,o=t.sharedDepth(r);return o==0?!1:(i=t.before(o),e&&e(n.tr.setSelection(T.create(n.doc,i))),!0)},Kp=(n,e)=>(e&&e(n.tr.setSelection(new ke(n.doc))),!0);function Jp(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,o=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(o-1,o)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(o,o+1)||!(i.isTextblock||ln(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function Tc(n,e,t,r){let i=e.nodeBefore,o=e.nodeAfter,s,l,a=i.type.spec.isolating||o.type.spec.isolating;if(!a&&Jp(n,e,t))return!0;let c=!a&&e.parent.canReplace(e.index(),e.index()+1);if(c&&(s=(l=i.contentMatchAt(i.childCount)).findWrapping(o.type))&&l.matchType(s[0]||o.type).validEnd){if(t){let p=e.pos+o.nodeSize,m=_.empty;for(let x=s.length-1;x>=0;x--)m=_.from(s[x].create(null,m));m=_.from(i.copy(m));let g=n.tr.step(new le(e.pos-1,p,e.pos,p,new C(m,1,0),s.length,!0)),y=g.doc.resolve(p+2*s.length);y.nodeAfter&&y.nodeAfter.type==i.type&&ln(g.doc,y.pos)&&g.join(y.pos),t(g.scrollIntoView())}return!0}let u=o.type.spec.isolating||r>0&&a?null:F.findFrom(e,1),f=u&&u.$from.blockRange(u.$to),h=f&&Pn(f);if(h!=null&&h>=e.depth)return t&&t(n.tr.lift(f,h).scrollIntoView()),!0;if(c&&tn(o,"start",!0)&&tn(i,"end")){let p=i,m=[];for(;m.push(p),!p.isTextblock;)p=p.lastChild;let g=o,y=1;for(;!g.isTextblock;g=g.firstChild)y++;if(p.canReplace(p.childCount,p.childCount,g.content)){if(t){let x=_.empty;for(let S=m.length-1;S>=0;S--)x=_.from(m[S].copy(x));let v=n.tr.step(new le(e.pos-m.length,e.pos+o.nodeSize,e.pos+y,e.pos+o.nodeSize-y,new C(x,m.length,0),0,!0));t(v.scrollIntoView())}return!0}}return!1}function Ic(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,o=i.depth;for(;i.node(o).isInline;){if(!o)return!1;o--}return i.node(o).isTextblock?(t&&t(e.tr.setSelection(D.create(e.doc,n<0?i.start(o):i.end(o)))),!0):!1}}const Gp=Ic(-1),Yp=Ic(1);function Dc(n,e=null){return function(t,r){let{$from:i,$to:o}=t.selection,s=i.blockRange(o),l=s&&no(s,n,e);return l?(r&&r(t.tr.wrap(s,l).scrollIntoView()),!0):!1}}function Zr(n,e=null){return function(t,r){let i=!1;for(let o=0;o{if(i)return!1;if(!(!a.isTextblock||a.hasMarkup(n,e)))if(a.type==n)i=!0;else{let u=t.doc.resolve(c),f=u.index();i=u.parent.canReplaceWith(f,f+1,n)}})}if(!i)return!1;if(r){let o=t.tr;for(let s=0;s{if(l)return!1;l=a.inlineContent&&a.type.allowsMarkType(t)}),l)return!0}return!1}function kt(n,e=null,t){return function(r,i){let{empty:o,$cursor:s,ranges:l}=r.selection;if(o&&!s||!Xp(r.doc,l,n))return!1;if(i)if(s)n.isInSet(r.storedMarks||s.marks())?i(r.tr.removeStoredMark(n)):i(r.tr.addStoredMark(n.create(e)));else{let a,c=r.tr;a=!l.some(u=>r.doc.rangeHasMark(u.$from.pos,u.$to.pos,n));for(let u=0;u{n.setKey("type",t),n.setKey("commentId",r||null),n.setKey("view",null),n.setKey("guestName",tl("ht-guest-name")||""),n.setKey("guestEmail",tl("ht-guest-email")||""),n.setKey("hasFocused",t!=="comment"),n.setKey("uploadingImages",0),n.setKey("mention",{search:null,index:null,range:null})});function em(n,e){const r=M()+"-"+(n==="comment"?"comment":`${e}-${n}`),i=nn(r,n,e||null);return zt(i)}function X(n,e,t){const r=nn(n.id);r.set({...r.get(),[e]:t}),e==="guestName"&&nl("ht-guest-name",t),e==="guestEmail"&&nl("ht-guest-email",t)}function go(n){const e=nn(n),t=e.get();e.set({...t,uploadingImages:t.uploadingImages+1})}function xn(n){const e=nn(n),t=e.get();e.set({...t,uploadingImages:Math.max(0,t.uploadingImages-1)})}const tm=["p",0],nm=["blockquote",0],rm=["pre",["code",0]],Ae={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return tm}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return nm}},code_block:{content:"text*",attrs:{language:{default:null}},marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM(){return rm}},math:{content:"text*",group:"inline",marks:"",inline:!0,selectable:!1,parseDOM:[{tag:"x-math",preserveWhitespace:"full"}],toDOM:()=>["x-math",0]},text:{group:"inline"},image:{attrs:{src:{},alt:{default:null}},group:"block",draggable:!0,selectable:!0,parseDOM:[{tag:"img[src]",getAttrs(n){return{src:n.getAttribute("src"),alt:n.getAttribute("alt")}}}],toDOM(n){const{src:e,alt:t}=n.attrs;return["img",{src:e,alt:t}]}},mention:{attrs:{user:{},name:{}},group:"inline",inline:!0,atom:!0,selectable:!0,parseDOM:[{tag:"x-mention",getAttrs(n){return{user:n.getAttribute("data-user"),name:n.getAttribute("data-name")}}}],toDOM:n=>["x-mention",{"data-user":n.attrs.user,"data-name":n.attrs.name},"@"+n.attrs.name]},embed:{attrs:{url:{}},group:"block",selectable:!0,draggable:!0,atom:!0,parseDOM:[{tag:"x-embed[data-url]",getAttrs(n){return{url:n.dataset.url}}}],toDOM(n){return["x-embed",{"data-url":n.attrs.url}]}}},im=["em",0],om=["strong",0],sm=["code",0],bt={code:{parseDOM:[{tag:"code"}],toDOM(){return sm}},link:{attrs:{href:{}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs(n){return{href:n.getAttribute("href")}}}],toDOM(n){const{href:e}=n.attrs;return["a",{href:e},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"}],toDOM(){return im}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!="normal"&&null},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}],toDOM(){return om}},strike:{parseDOM:[{tag:"s"},{tag:"strike"},{tag:"del"}],toDOM(){return["s",0]}},spoiler:{parseDOM:[{tag:"x-spoiler"}],toDOM(){return["x-spoiler",0]}}};new Oa({nodes:Ae,marks:bt});var ft={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:"'"},br={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},lm=typeof navigator<"u"&&/Mac/.test(navigator.platform),am=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var se=0;se<10;se++)ft[48+se]=ft[96+se]=String(se);for(var se=1;se<=24;se++)ft[se+111]="F"+se;for(var se=65;se<=90;se++)ft[se]=String.fromCharCode(se+32),br[se]=String.fromCharCode(se);for(var ti in ft)br.hasOwnProperty(ti)||(br[ti]=ft[ti]);function cm(n){var e=lm&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||am&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?br:ft)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}const um=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),dm=typeof navigator<"u"&&/Win/.test(navigator.platform);function fm(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,o,s;for(let l=0;l=t?ne.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};ne.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};ne.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)};ne.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(o,s){return i.push(e(o,s))},t,r),i};ne.from=function(e){return e instanceof ne?e:e&&e.length?new Rc(e):ne.empty};var Rc=function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,o){return i==0&&o==this.length?this:new e(this.values.slice(i,o))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,o,s,l){for(var a=o;a=s;a--)if(i(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=yr)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=yr)return new e(i.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}(ne);ne.empty=new Rc([]);var mm=function(n){function e(t,r){n.call(this),this.left=t,this.right=r,this.length=t.length+r.length,this.depth=Math.max(t.depth,r.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.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,o)-l,s+l)===!1)return!1},e.prototype.forEachInvertedInner=function(r,i,o,s){var l=this.left.length;if(i>l&&this.right.forEachInvertedInner(r,i-l,Math.max(o,l)-l,s+l)===!1||o=o?this.right.slice(r-o,i-o):this.left.slice(r,o).append(this.right.slice(0,i-o))},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}(ne);const gm=500;class Ee{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,o;t&&(i=this.remapping(r,this.items.length),o=i.maps.length);let s=e.tr,l,a,c=[],u=[];return this.items.forEach((f,h)=>{if(!f.step){i||(i=this.remapping(r,h+1),o=i.maps.length),o--,u.push(f);return}if(i){u.push(new Re(f.map));let p=f.step.map(i.slice(o)),m;p&&s.maybeStep(p).doc&&(m=s.mapping.maps[s.mapping.maps.length-1],c.push(new Re(m,void 0,void 0,c.length+u.length))),o--,m&&i.appendMap(m,o)}else s.maybeStep(f.step);if(f.selection)return l=i?f.selection.map(i.slice(o)):f.selection,a=new Ee(this.items.slice(0,r).append(u.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:s,selection:l}}addTransform(e,t,r,i){let o=[],s=this.eventCount,l=this.items,a=!i&&l.length?l.get(l.length-1):null;for(let u=0;uym&&(l=bm(l,c),s-=c),new Ee(l.append(o),s)}remapping(e,t){let r=new Mn;return this.items.forEach((i,o)=>{let s=i.mirrorOffset!=null&&o-i.mirrorOffset>=e?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,s)},e,t),r}addMaps(e){return this.eventCount==0?this:new Ee(this.items.append(e.map(t=>new Re(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-t),o=e.mapping,s=e.steps.length,l=this.eventCount;this.items.forEach(h=>{h.selection&&l--},i);let a=t;this.items.forEach(h=>{let p=o.getMirror(--a);if(p==null)return;s=Math.min(s,p);let m=o.maps[p];if(h.step){let g=e.steps[p].invert(e.docs[p]),y=h.selection&&h.selection.map(o.slice(a+1,p));y&&l++,r.push(new Re(m,g,y))}else r.push(new Re(m))},i);let c=[];for(let h=t;hgm&&(f=f.compress(this.items.length-r.length)),f}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),r=t.maps.length,i=[],o=0;return this.items.forEach((s,l)=>{if(l>=e)i.push(s),s.selection&&o++;else if(s.step){let a=s.step.map(t.slice(r)),c=a&&a.getMap();if(r--,c&&t.appendMap(c,r),a){let u=s.selection&&s.selection.map(t.slice(r));u&&o++;let f=new Re(c.invert(),a,u),h,p=i.length-1;(h=i.length&&i[p].merge(f))?i[p]=h:i.push(f)}}else s.map&&r--},this.items.length,0),new Ee(ne.from(i.reverse()),o)}}Ee.empty=new Ee(ne.empty,0);function bm(n,e){let t;return n.forEach((r,i)=>{if(r.selection&&e--==0)return t=i,!1}),n.slice(t)}class Re{constructor(e,t,r,i){this.map=e,this.step=t,this.selection=r,this.mirrorOffset=i}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new Re(t.getMap().invert(),t,this.selection)}}}class rt{constructor(e,t,r,i,o){this.done=e,this.undone=t,this.prevRanges=r,this.prevTime=i,this.prevComposition=o}}const ym=20;function xm(n,e,t,r){let i=t.getMeta(Nt),o;if(i)return i.historyState;t.getMeta(vm)&&(n=new rt(n.done,n.undone,null,0,-1));let s=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(s&&s.getMeta(Nt))return s.getMeta(Nt).redo?new rt(n.done.addTransform(t,void 0,r,rr(e)),n.undone,il(t.mapping.maps),n.prevTime,n.prevComposition):new rt(n.done,n.undone.addTransform(t,void 0,r,rr(e)),null,n.prevTime,n.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(s&&s.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=n.prevTime==0||!s&&n.prevComposition!=l&&(n.prevTime<(t.time||0)-r.newGroupDelay||!km(t,n.prevRanges)),c=s?ri(n.prevRanges,t.mapping):il(t.mapping.maps);return new rt(n.done.addTransform(t,a?e.selection.getBookmark():void 0,r,rr(e)),Ee.empty,c,t.time,l??n.prevComposition)}else return(o=t.getMeta("rebased"))?new rt(n.done.rebased(t,o),n.undone.rebased(t,o),ri(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new rt(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),ri(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function km(n,e){if(!e)return!1;if(!n.docChanged)return!0;let t=!1;return n.mapping.maps[0].forEach((r,i)=>{for(let o=0;o=e[o]&&(t=!0)}),t}function il(n){let e=[];for(let t=n.length-1;t>=0&&e.length==0;t--)n[t].forEach((r,i,o,s)=>e.push(o,s));return e}function ri(n,e){if(!n)return null;let t=[];for(let r=0;r{let i=Nt.getState(t);if(!i||(n?i.undone:i.done).eventCount==0)return!1;if(r){let o=_m(i,t,n);o&&r(e?o.scrollIntoView():o)}return!0}}const zc=Pc(!1,!0),Ri=Pc(!0,!0);function sl(n,e=null){return function(t,r){let{$from:i,$to:o}=t.selection,s=i.blockRange(o);if(!s)return!1;let l=r?t.tr:null;return Cm(l,s,n,e)?(r&&r(l.scrollIntoView()),!0):!1}}function Cm(n,e,t,r=null){let i=!1,o=e,s=e.$from.doc;if(e.depth>=2&&e.$from.node(e.depth-1).type.compatibleContent(t)&&e.startIndex==0){if(e.$from.index(e.depth-1)==0)return!1;let a=s.resolve(e.start-2);o=new ur(a,a,e.depth),e.endIndex=0;u--)o=_.from(t[u].type.create(t[u].attrs,o));n.step(new le(e.start-(r?2:0),e.end,e.start,e.end,new C(o,0,0),t.length,!0));let s=0;for(let u=0;u=i.depth-3;x--)f=_.from(i.node(x).copy(f));let p=i.indexAfter(-1){if(y>-1)return!1;x.isTextblock&&x.content.size==0&&(y=v+1)}),y>-1&&g.setSelection(F.near(g.doc.resolve(y))),r(g.scrollIntoView())}return!0}let a=o.pos==i.end()?l.contentMatchAt(0).defaultType:null,c=t.tr.delete(i.pos,o.pos),u=a?[null,{type:a}]:void 0;return Wt(c.doc,i.pos,2,u)?(r&&r(c.split(i.pos,2,u).scrollIntoView()),!0):!1}}function Om(n){return function(e,t){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,s=>s.childCount>0&&s.firstChild.type==n);return o?t?r.node(o.depth-1).type==n?Nm(e,t,n,o):Em(e,t,o):!0:!1}}function Nm(n,e,t,r){let i=n.tr,o=r.end,s=r.$to.end(r.depth);og;m--)p-=i.child(m).nodeSize,r.delete(p-1,p+1);let o=r.doc.resolve(t.start),s=o.nodeAfter;if(r.mapping.map(t.end)!=t.start+o.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==i.childCount,c=o.node(-1),u=o.index(-1);if(!c.canReplace(u+(l?0:1),u+1,s.content.append(a?_.empty:_.from(i))))return!1;let f=o.pos,h=f+s.nodeSize;return r.step(new le(f-(l?1:0),h+(a?1:0),f+1,h-1,new C((l?_.empty:_.from(i.copy(_.empty))).append(a?_.empty:_.from(i.copy(_.empty))),l?0:1,a?0:1),l?0:1)),e(r.scrollIntoView()),!0}function Tm(n){return function(e,t){let{$from:r,$to:i}=e.selection,o=r.blockRange(i,c=>c.childCount>0&&c.firstChild.type==n);if(!o)return!1;let s=o.startIndex;if(s==0)return!1;let l=o.parent,a=l.child(s-1);if(a.type!=n)return!1;if(t){let c=a.lastChild&&a.lastChild.type==l.type,u=_.from(c?n.create():null),f=new C(_.from(n.create(null,_.from(l.type.create(null,u)))),c?3:1,0),h=o.start,p=o.end;t(e.tr.step(new le(h-(c?3:1),p,h,p,f,1,!0)).scrollIntoView())}return!0}}class Ie{constructor(e,t,r={}){this.match=e,this.match=e,this.handler=typeof t=="string"?Im(t):t,this.undoable=r.undoable!==!1,this.inCode=r.inCode||!1,this.inCodeMark=r.inCodeMark!==!1}}function Im(n){return function(e,t,r,i){let o=n;if(t[1]){let s=t[0].lastIndexOf(t[1]);o+=t[0].slice(s+t[1].length),r+=s;let l=r-i;l>0&&(o=t[0].slice(s-l,s)+o,r=i)}return e.tr.insertText(o,r,i)}}const Dm=500;function bo({rules:n}){let e=new Ze({state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,o){return ll(t,r,i,o,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&ll(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function ll(n,e,t,r,i,o){if(n.composing)return!1;let s=n.state,l=s.doc.resolve(e),a=l.parent.textBetween(Math.max(0,l.parentOffset-Dm),l.parentOffset,null,"")+r;for(let c=0;cp.type.spec.code))continue;if(l.parent.type.spec.code){if(!u.inCode)continue}else if(u.inCode==="only")continue;let f=u.match.exec(a),h=f&&f[0].length>=r.length&&u.handler(s,f,e-(f[0].length-r.length),t);if(h)return u.undoable&&h.setMeta(o,{transform:h,from:e,to:t,text:r}),n.dispatch(h),!0}return!1}const Bc=(n,e)=>{let t=n.plugins;for(let r=0;r=0;a--)s.step(l.steps[a].invert(l.docs[a]));if(o.text){let a=s.doc.resolve(o.from).marks();s.replaceWith(o.from,o.to,n.schema.text(o.text,a))}else s.delete(o.from,o.to);e(s)}return!0}}return!1},Am=new Ie(/--$/,"—",{inCodeMark:!1}),Rm=new Ie(/\.\.\.$/,"…",{inCodeMark:!1}),Pm=new Ie(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"“",{inCodeMark:!1}),zm=new Ie(/"$/,"”",{inCodeMark:!1}),Bm=new Ie(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"‘",{inCodeMark:!1}),Lm=new Ie(/'$/,"’",{inCodeMark:!1}),Fm=[Pm,zm,Bm,Lm];function Dr(n,e,t=null,r){return new Ie(n,(i,o,s,l)=>{let a=t instanceof Function?t(o):t,c=i.tr.delete(s,l),u=c.doc.resolve(s),f=u.blockRange(),h=f&&no(f,e,a);if(!h)return null;c.wrap(f,h);let p=c.doc.resolve(s-1).nodeBefore;return p&&p.type==e&&ln(c.doc,s-1)&&(!r||r(o,p))&&c.join(s-1),c})}function yo(n,e,t=null){return new Ie(n,(r,i,o,s)=>{let l=r.doc.resolve(o),a=t instanceof Function?t(i):t;return l.node(-1).canReplaceWith(l.index(-1),l.indexAfter(-1),e)?r.tr.delete(o,s).setBlockType(o,o,e,a):null})}const al=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):!1;function $m(n,e){let t={},r;function i(o,s){t[o]=s}if(i("Mod-z",zc),i("Shift-Mod-z",Ri),i("Backspace",Bc),al||i("Mod-y",Ri),i("Alt-ArrowUp",Fp),i("Alt-ArrowDown",$p),i("Mod-BracketLeft",Nc),i("Escape",Wp),(r=n.marks.strong)&&(i("Mod-b",kt(r)),i("Mod-B",kt(r))),(r=n.marks.em)&&(i("Mod-i",kt(r)),i("Mod-I",kt(r))),(r=n.marks.code)&&i("Mod-`",kt(r)),(r=n.nodes.bullet_list)&&i("Shift-Ctrl-8",sl(r)),(r=n.nodes.ordered_list)&&i("Shift-Ctrl-9",sl(r)),(r=n.nodes.blockquote)&&i("Ctrl->",Dc(r)),r=n.nodes.hard_break){let o=r,s=Ir(Ec,(l,a)=>(a&&a(l.tr.replaceSelectionWith(o.create()).scrollIntoView()),!0));i("Mod-Enter",s),i("Shift-Enter",s),al&&i("Ctrl-Enter",s)}if((r=n.nodes.list_item)&&(i("Enter",Mm(r)),i("Mod-[",Om(r)),i("Mod-]",Tm(r))),(r=n.nodes.paragraph)&&i("Shift-Ctrl-0",Zr(r)),(r=n.nodes.code_block)&&i("Shift-Ctrl-\\",Zr(r)),r=n.nodes.heading)for(let o=1;o<=6;o++)i("Shift-Ctrl-"+o,Zr(r,{level:o}));if(r=n.nodes.horizontal_rule){let o=r;i("Mod-_",(s,l)=>(l&&l(s.tr.replaceSelectionWith(o.create()).scrollIntoView()),!0))}return t}function Vm(n){return Dr(/^\s*>\s$/,n)}function Um(n){return Dr(/^(\d+)\.\s$/,n,e=>({order:+e[1]}),(e,t)=>t.childCount+t.attrs.order==+e[1])}function jm(n){return Dr(/^\s*([-+*])\s$/,n)}function Hm(n){return yo(/^```$/,n)}function qm(n,e){return yo(new RegExp("^(#{1,"+e+"})\\s$"),n,t=>({level:t[1].length}))}function Wm(n){let e=Fm.concat(Rm,Am),t;return(t=n.nodes.blockquote)&&e.push(Vm(t)),(t=n.nodes.ordered_list)&&e.push(Um(t)),(t=n.nodes.bullet_list)&&e.push(jm(t)),(t=n.nodes.code_block)&&e.push(Hm(t)),(t=n.nodes.heading)&&e.push(qm(t,6)),bo({rules:e})}function Km(n){const e=t=>{t.state.doc.toString()!=="doc(paragraph)"?t.dom.removeAttribute("data-placeholder"):t.dom.setAttribute("data-placeholder",n),t.dom.setAttribute("aria-label",n),t.dom.setAttribute("role","textbox"),t.dom.setAttribute("aria-multiline","true")};return new Ze({view(t){return e(t),{update:e}}})}const Jm="codemark",Pi=100,Gm=new Or(Jm);function tt(n,e){var t,r;return"schema"in n?(t=e==null?void 0:e.markType)!==null&&t!==void 0?t:n.schema.marks.code:(r=e==null?void 0:e.markType)!==null&&r!==void 0?r:n.state.schema.marks.code}function Pt(n,e){return n.resolve(Math.min(Math.max(1,e),n.nodeSize-2))}function Lc(n,e,t,r){var i;const o=n.isInSet((i=e.state.storedMarks)!==null&&i!==void 0?i:e.state.doc.resolve(t).marks()),s=e.state.doc.rangeHasMark(t,r,n);return!!(o||s)}const cl={match:/`((?:[^`\w]|[\w])+)`$/,handler:(n,e,t,r,i,o,s)=>{if(Lc(n,e,i,o))return!1;const l=r[1],a=n.create(),c=i+l.length,u=e.state.tr.delete(i,o).insertText(l).addMark(i,c,a),f=u.setSelection(D.create(u.doc,c)).removeStoredMark(n),h=f.setMeta(s.input,{transform:f,from:i,to:o,text:`\`${l}${t}`});return e.dispatch(h),!0}},ul={match:/^`((?:[^`\w]|[\w])+)`/,handler:(n,e,t,r,i,o,s)=>{if(Lc(n,e,i,o))return!1;const l=n.create(),a=r[1],c=i,u=e.state.tr.delete(i,o).insertText(a).addMark(i,i+a.length,l),f=u.setSelection(D.create(u.doc,c)).addStoredMark(n.create()),h=f.setMeta(s.input,{transform:f,from:i,to:o,text:`\`${a}${t}`});return e.dispatch(h),!0}};function Ym(n,e,t,r,i,o){if(e.composing)return!1;const{state:s}=e,l=s.doc.resolve(t);if(l.parent.type.spec.code)return!1;const a="",c=l.parent.textBetween(Math.max(0,l.parentOffset-Pi),l.parentOffset,void 0,a)+i,u=i+l.parent.textBetween(l.parentOffset,Math.min(l.parent.nodeSize-2,l.parentOffset+Pi),void 0,a),f=cl.match.exec(c),h=ul.match.exec(u);if(f){const p=cl.handler(n,e,i,f,t-f[0].length+i.length,r,o);if(p)return p}return h?ul.handler(n,e,i,h,t,r+h[0].length-i.length,o):!1}function Xm(n,e){const t=new Ze({isInputRules:!0,state:{init:()=>null,apply(r,i){const o=r.getMeta(t);return o||(r.selectionSet||r.docChanged?null:i)}},props:{handleTextInput(r,i,o,s){const l=tt(r,e);return Ym(l,r,i,o,s,{input:t,cursor:n})}}});return t}function Xe(n,e,t="next"){const r={action:t};return n.dispatch(n.state.tr.setMeta(e,r)),!1}function Qm(n,e,t,r){if(n.state.selection.empty||t.metaKey||t.shiftKey||t.altKey||t.ctrlKey)return!1;const{from:i,to:o}=n.state.selection;if(o-i>=Pi||n.state.doc.rangeHasMark(i,o,r))return!1;const s=n.state.tr.addMark(i,o,r.create()),l=s.setSelection(D.create(s.doc,o)).removeStoredMark(r);return n.dispatch(l),!0}function Zm(n,e,t,r){var i;if(t.metaKey)return Xe(n,e);if(t.shiftKey||t.altKey||t.ctrlKey)return!1;const{selection:o,doc:s}=n.state;if(!o.empty)return!1;const l=e.getState(n.state),a=o.$from,c=!!r.isInSet(a.marks()),u=!!r.isInSet((i=a.marksAcross(Pt(s,o.from+1)))!==null&&i!==void 0?i:[]);return a.pos===n.state.doc.nodeSize-3&&a.parentOffset===a.parent.nodeSize-2&&(l!=null&&l.active)?(n.dispatch(n.state.tr.removeStoredMark(r)),!0):c===u&&a.parentOffset!==0?!1:c&&(!(l!=null&&l.active)||l.side===-1)&&a.parentOffset!==0?(n.dispatch(n.state.tr.removeStoredMark(r)),!0):u&&(l==null?void 0:l.side)===-1?(n.dispatch(n.state.tr.addStoredMark(r.create())),!0):!1}function e0(n,e,t,r){if(Zm(n,e,t,r))return!0;const{selection:o}=n.state,s=o.$from;return o.empty&&s.parentOffset===s.parent.nodeSize-2?Xe(n,e):!1}function t0(n,e,t,r){var i;if(t.metaKey)return Xe(n,e);if(t.shiftKey||t.altKey||t.ctrlKey)return!1;const{selection:o,doc:s}=n.state,l=e.getState(n.state),a=!!r.isInSet(o.$from.marks()),c=!!r.isInSet((i=Pt(s,o.empty?o.from-1:o.from+1).marks())!==null&&i!==void 0?i:[]);if(a&&(l==null?void 0:l.side)===-1&&o.$from.parentOffset===0)return!1;if((l==null?void 0:l.side)===0&&o.$from.parentOffset===0)return n.dispatch(n.state.tr.removeStoredMark(r)),!0;if(a&&c&&(l==null?void 0:l.side)===0)return n.dispatch(n.state.tr.addStoredMark(r.create())),!0;if(a&&!c&&(l!=null&&l.active)&&o.$from.parentOffset===0||!a&&(l!=null&&l.active)&&(l==null?void 0:l.side)===0)return n.dispatch(n.state.tr.removeStoredMark(r)),!0;if(a===c)return!1;if(c||!o.empty&&a){const u=o.empty?o.from-1:o.from,f=n.state.tr.setSelection(D.create(s,u));return!o.empty&&c?n.dispatch(f.addStoredMark(r.create())):n.dispatch(f.removeStoredMark(r)),!0}if((c||!o.empty&&a)&&!(l!=null&&l.active)){const u=o.empty?o.from-1:o.from;return n.dispatch(n.state.tr.setSelection(D.create(s,u)).removeStoredMark(r)),!0}if(a&&!(l!=null&&l.active)&&o.$from.parentOffset>0)return n.dispatch(n.state.tr.setSelection(D.create(s,o.from-1)).addStoredMark(r.create())),!0;if(a&&!c&&(l!=null&&l.active)&&l.side!==-1)return n.dispatch(n.state.tr.addStoredMark(r.create())),!0;if(a&&!c&&(l!=null&&l.active)){const u=o.from-1;return n.dispatch(n.state.tr.setSelection(D.create(s,u)).addStoredMark(r.create())),!0}return!1}function n0(n,e,t,r){if(t0(n,e,t,r))return!0;const{selection:o}=n.state,s=o.$from,l=e.getState(n.state);return s.pos===1&&s.parentOffset===0&&(l==null?void 0:l.side)===-1?!0:o.empty&&s.parentOffset===0?Xe(n,e):!1}function r0(n,e,t,r){if(t.metaKey||t.shiftKey||t.altKey||t.ctrlKey)return!1;const{selection:i,doc:o}=n.state,s=Pt(o,i.from-1),l=!!r.isInSet(s.marks()),a=s.parentOffset===0,c=!!r.isInSet(Pt(o,i.to+1).marks());if((!l||a)&&!c)return Xe(n,e);const u=e.getState(n.state);if(i.empty&&(u==null?void 0:u.side)===-1){const f=n.state.tr.delete(i.from-1,i.from);return n.dispatch(f),!0}return!1}function i0(n,e,t,r){if(t.metaKey||t.shiftKey||t.altKey||t.ctrlKey)return!1;const{selection:i,doc:o}=n.state,s=!!r.isInSet(i.$from.marks()),l=i.$from.parentOffset===0,a=!!r.isInSet(Pt(o,i.to+2).marks());return(!s||l)&&!a?Xe(n,e):!1}function o0(n,e){var t,r;if(!n)return null;const{selection:i,doc:o}=n;if(!i.empty)return null;const s=!!e.isInSet((t=n.storedMarks)!==null&&t!==void 0?t:[]),l=!!e.isInSet(i.$from.marks()),a=!!e.isInSet((r=Pt(o,i.from+1).marks())!==null&&r!==void 0?r:[]),c=i.$from.parentOffset===0;return l!==a||!l&&s!==l||l&&c?n.tr.removeStoredMark(e):null}function s0(){const n=document.createElement("span");return n.classList.add("fake-cursor"),n}function l0(n){const e=new Ze({key:Gm,appendTransaction:(t,r,i)=>{var o;const s=e.getState(r),l=(o=t[0])===null||o===void 0?void 0:o.getMeta(e);return s!=null&&s.next||(l==null?void 0:l.action)==="click"?o0(i,tt(i,n)):null},state:{init:()=>null,apply(t,r,i,o){var s;const l=t.getMeta(e);if((l==null?void 0:l.action)==="next")return{next:!0};const a=tt(o,n),c=a.isInSet((s=o.storedMarks)!==null&&s!==void 0?s:o.doc.resolve(t.selection.from).marks()),u=a.isInSet(o.doc.resolve(t.selection.from).marks()),f=a.isInSet(Pt(o.doc,t.selection.from+1).marks()),h=t.selection.$from.parentOffset===0;return t.selection.empty?!c&&f&&(!u||h)?{active:!0,side:-1}:c&&(!u||h)?{active:!0,side:0}:!c&&u&&!f?{active:!0,side:0}:c&&u&&!f?{active:!0,side:-1}:null:null}},props:{attributes:t=>{var r;const{active:i=!1}=(r=e.getState(t))!==null&&r!==void 0?r:{};return Object.assign({},i?{class:"no-cursor"}:{})},decorations:t=>{var r;const{active:i,side:o}=(r=e.getState(t))!==null&&r!==void 0?r:{};if(!i)return W.empty;const s=xe.widget(t.selection.from,s0,{side:o});return W.create(t.doc,[s])},handleKeyDown(t,r){switch(r.key){case"`":return Qm(t,e,r,tt(t,n));case"ArrowRight":return e0(t,e,r,tt(t,n));case"ArrowLeft":return n0(t,e,r,tt(t,n));case"Backspace":return r0(t,e,r,tt(t,n));case"Delete":return i0(t,e,r,tt(t,n));case"ArrowUp":case"ArrowDown":case"Home":case"End":return Xe(t,e);case"e":case"a":return r.ctrlKey?Xe(t,e):!1;default:return!1}},handleClick(t){return Xe(t,e,"click")}}});return e}function a0(n){const e=l0(n),t=Xm(e,n);return[e,t]}const c0="KEEP_OPEN";var q;(function(n){n.open="open",n.close="close",n.filter="filter",n.up="ArrowUp",n.down="ArrowDown",n.left="ArrowLeft",n.right="ArrowRight",n.enter="enter"})(q||(q={}));const xo=new Or("autocomplete");function xr(n,e){return e.find(n.from,n.to).length>0}function pn(n){const e=xo.get(n.state),t={action:"remove"},r=n.state.tr.setMeta(e,t);return n.dispatch(r),!0}const oi={active:!1,decorations:W.empty};function u0(n){switch(n.key){case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":return n.key;case"Tab":case"Enter":return q.enter;case"Escape":return q.close;default:return null}}function dl(n){const e=xo.get(n.state),{decorations:t}=e.getState(n.state);return xr(n.state.selection,t)&&pn(n),!1}function d0(n){const e=new Ze({key:xo,view(){return{update:(t,r)=>{var i,o,s,l;const a=e.getState(r),c=e.getState(t.state),u=!a.active&&c.active,f=a.active&&!c.active,h=c.active&&!u&&!f&&a.filter!==c.filter,p={view:t,trigger:(i=c.trigger)!==null&&i!==void 0?i:a.trigger,filter:(o=c.filter)!==null&&o!==void 0?o:a.filter,range:(s=c.range)!==null&&s!==void 0?s:a.range,type:(l=c.type)!==null&&l!==void 0?l:a.type};u&&n(Object.assign(Object.assign({},p),{kind:q.open})),h&&n(Object.assign(Object.assign({},p),{kind:q.filter})),f&&n(Object.assign(Object.assign({},p),{kind:q.close}))}}},state:{init:()=>oi,apply(t,r){var i,o,s;const l=t.getMeta(e);if((l==null?void 0:l.action)==="add"){const{trigger:x,filter:v,type:S}=l,N=t.selection.from-x.length-((i=v==null?void 0:v.length)!==null&&i!==void 0?i:0),J=t.selection.from,V=!((o=S==null?void 0:S.decorationAttrs)===null||o===void 0)&&o.class?["autocomplete",(s=S==null?void 0:S.decorationAttrs)===null||s===void 0?void 0:s.class].join(" "):"autocomplete",I=Object.assign(Object.assign({},S==null?void 0:S.decorationAttrs),{class:V}),L=xe.inline(N,J,I,{inclusiveStart:!1,inclusiveEnd:!0});return{active:!0,trigger:l.trigger,decorations:W.create(t.doc,[L]),filter:v??"",range:{from:N,to:J},type:S}}const{decorations:a}=r,c=a.map(t.mapping,t.doc),u=c.find().length>0;if((l==null?void 0:l.action)==="remove"||!xr(t.selection,c)||!u)return oi;const{active:f,trigger:h,type:p}=r,{from:m,to:g}=c.find()[0],y=t.doc.textBetween(m,g);return y.startsWith(h)?{active:f,trigger:h,decorations:c,filter:y.slice(h.length),range:{from:m,to:g},type:p}:oi}},props:{decorations:t=>{var r;return(r=e.getState(t))===null||r===void 0?void 0:r.decorations},handlePaste:t=>dl(t),handleDrop:t=>dl(t),handleKeyDown(t,r){var i,o;const{trigger:s,active:l,decorations:a,type:c}=e.getState(t.state);if(!l||!xr(t.state.selection,a))return!1;const{from:u,to:f}=a.find()[0],p=t.state.doc.textBetween(u,f).slice((i=s==null?void 0:s.length)!==null&&i!==void 0?i:1);if(((o=c==null?void 0:c.cancelOnFirstSpace)!==null&&o!==void 0?o:!0)&&p.length===0&&(r.key===" "||r.key==="Spacebar"))return pn(t),t.dispatch(t.state.tr.insertText(" ").scrollIntoView()),!0;if(p.length===0&&r.key==="Backspace")return Bc(t.state,t.dispatch),pn(t),!0;const g=u0(r),y={view:t,trigger:s,filter:p,range:{from:u,to:f},type:c,event:r};switch(g){case q.close:return pn(t);case q.enter:{const x=n(Object.assign(Object.assign({},y),{kind:q.enter}));return x===c0?!0:x||pn(t)}case q.up:case q.down:return!!n(Object.assign(Object.assign({},y),{kind:g}));case q.left:case q.right:return c!=null&&c.allArrowKeys?!!n(Object.assign(Object.assign({},y),{kind:g})):!1}return!1}}});return e}function f0(n,e){const t=typeof e.trigger=="string"?RegExp(`(?:^|\\s|\\n|[^\\d\\w])(${e.trigger.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})$`):e.trigger;return new Ie(t,(r,i)=>{const{decorations:o}=n.getState(r);if(xr(r.selection,o))return null;const s=r.tr.insertText(i[1][i[1].length-1]).scrollIntoView(),l={action:"add",trigger:i[1],type:e};return s.setMeta(n,l),s})}function h0(n){return e=>{var t,r,i,o,s,l,a,c,u,f;switch(e.kind){case q.open:return(r=(t=n.onOpen)===null||t===void 0?void 0:t.call(n,e))!==null&&r!==void 0?r:!1;case q.close:return(o=(i=n.onClose)===null||i===void 0?void 0:i.call(n,e))!==null&&o!==void 0?o:!1;case q.up:case q.down:case q.left:case q.right:return(l=(s=n.onArrow)===null||s===void 0?void 0:s.call(n,e))!==null&&l!==void 0?l:!1;case q.filter:return(c=(a=n.onFilter)===null||a===void 0?void 0:a.call(n,e))!==null&&c!==void 0?c:!1;case q.enter:return(f=(u=n.onEnter)===null||u===void 0?void 0:u.call(n,e))!==null&&f!==void 0?f:!1;default:return!1}}}function p0(n={}){const e=Object.assign({triggers:[],reducer:h0(n)},n),{reducer:t,triggers:r}=e,i=d0(t);return[i,bo({rules:r.map(s=>f0(i,s))})]}function Fc(n,e=300){let t;return function(...r){clearTimeout(t);const i=this;t=window.setTimeout(function(){n.apply(i,r)},e)}}const rn=E({});function m0(n,e){const t=rn.get()[n];if(!t)return!1;for(const r of t)if(qi(r,e))return!0;return!1}function $c(n,e){const t=[];for(const r of Object.values(Oe.all())){if(t.length>15||r.is_hidden)continue;const i=r.user;i.type&&i.name.startsWith(e)&&(t.find(o=>o.id===i.id&&o.type===i.type)||t.push(i))}Vc(e,t)}function Vc(n,e){const t=rn.get(),r=t[n]||[];for(const i of e)m0(n,i)||r.push(i);rn.set({...t,[n]:r})}function g0(n,e){return(rn.get()[n]||[])[e]||null}const b0=Fc((n,e,t)=>{$c(n,e),R.call({context:n,method:"get",endpoint:"/commenter/mentions",data:{search:e},success:r=>{t(r),Vc(e,r)}})},400);function y0(n){return n.type+"_"+n.id}function Uc(n){return`mention-suggestions-${n}`}const zi="rich-editor-mention-autocomplete";function jc(n){const{range:e,index:t,search:r}=n.mention,i=n.view,o=i.state.tr;if(e===null||t===null||r===null)return;const{from:s,to:l}=e;o.delete(s,l);const a=g0(r,t);if(!a)return;const c=i.state.schema;o.insert(s,c.nodes.mention.create({user:y0(a),name:a.username||a.name})),o.insert(s+1,c.text(" ")),i.dispatch(o)}function x0(n){const e={triggers:[{name:"mention",trigger:"@",decorationAttrs:{id:`${zi}-${n.id}`,class:zi},cancelOnFirstSpace:!1}],onOpen:({view:t,range:r,trigger:i,type:o})=>(X(n,"mention",{search:"",index:0,range:r}),!0),onArrow:({view:t,range:r,kind:i})=>{const o=nn(n.id).get().mention;if(o.search===null)return!1;const s=rn.get()[o.search];let l=o.index||0;return i==="ArrowUp"?l===0?l=s.length>0?s.length-1:0:l=l-1:i==="ArrowDown"&&(l>=s.length-1?l=0:l=l+1),X(n,"mention",{search:o.search,index:l,range:r}),setTimeout(()=>{var u;const a=Uc(n.id),c=(u=t.dom.getRootNode())==null?void 0:u.querySelector(`#${a} .user.active`);c&&c.scrollIntoView(!1)},100),!0},onFilter:({view:t,range:r,filter:i})=>(X(n,"mention",{search:i||"",index:0,range:r}),!0),onEnter:()=>(jc(nn(n.id).get()),!0),onClose:({view:t})=>(X(n,"mention",{search:null,index:null,range:null}),!0)};return p0(e)}function k0(n,e){const t=[..._0(n.marks,e),...v0(n,e)];return bo({rules:t})}function _0(n,e){const t=[];return e.inline_styles&&(t.push(gt(/(?:\*\*)([^\*]+)(?:\*\*)$/,n.strong)),t.push(gt(/(?:\w__)([^_]+)(?:__)$/,n.strong)),t.push(gt(/(?:^|[^\*])(?:\*)([^\*]+)(?:\*)$/,n.em,{},/^[^\*]/)),t.push(gt(/(?:^|[^_])(?:_)([^_]+)(?:_)$/,n.em,{},/^[^_]/)),t.push(gt(/(?:~~)([^~]+)(?:~~)$/,n.strike)),e.spoiler&&t.push(gt(/(?:!!)([^!]+)(?:!!)$/,n.spoiler))),e.links&&t.push(gt(/(?:\[([^\]]+)\])(\([^\)]+\))$/,n.link,function(r){return{href:r[2]}})),t}function v0(n,e){const t=n.nodes,r=[];return e.math&&r.push(new Ie(/([^$]|^)\$\$\s$/,(i,o,s)=>{const{$from:l}=i.selection;if(l.node().type.name!=="paragraph")return null;o[0].match(/^[^$]/)&&s++;const a=i.tr.replaceWith(s,s+3,[t.math.create(null),n.text(" ")]).scrollIntoView();return a.setSelection(D.create(a.doc,s+1)),a})),e.code_blocks&&r.push(yo(/^```([a-zA-Z0-9]+)?\s$/,t.code_block,i=>({language:i[1]||null}))),e.blockquotes&&r.push(Dr(/^\s*>\s$/,t.blockquote)),r}function gt(n,e,t={},r=void 0){return new Ie(n,(i,o,s,l)=>{const a=t instanceof Function?t(o):t,c=i.tr;if(o[1]){let u,f=0;(u=r&&o[0].match(r))&&(f=u[0].length,s+=f);const h=s+o[0].indexOf(o[1])-f,p=h+o[1].length;ps&&c.delete(s,h),l=s+o[1].length}return c.addMark(s,l,e.create(a)),c.removeStoredMark(e),c})}function w0(n){return new Ze({props:{transformPasted:(e,t)=>{if(n){const r=C0(e,t);if(r)return Yc(t,r),new C(_.empty,0,0)}return new C(qc(e.content),e.openStart,e.openEnd)}}})}const Hc=/\b((https?:\/\/)[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)/g;function C0(n,e){const t=e.state.selection.$from.parent;if(t.type.name!=="paragraph"||t.textContent!==""||n.content.childCount!==1)return null;function r(){const s=n.content.firstChild;if(!s)return null;if(s.isText)return s;if(s.type.name==="paragraph"){if(s.childCount!==1)return null;const l=s.firstChild;if(!l)return null;if(l.isText)return l}}const i=r();if(!i||!i.text)return null;const o=i.text.match(Hc);return o?o[0]:null}function qc(n){const e=[];return n.forEach(function(t){if(t.isText){const r=t.text;let i=0,o;for(;o=Hc.exec(r);){const s=o.index,l=s+o[0].length,a=t.type.schema.marks.link;s>0&&e.push(t.cut(i,s));const c=r.slice(s,l);e.push(t.cut(s,l).mark(a.create({href:c}).addToSet(t.marks))),i=l}i{const s=r.dataTransfer&&r.dataTransfer.files&&r.dataTransfer.files.length>0;if(o||!s)return!1;const l=Array.from(r.dataTransfer.files).filter(c=>c.type.startsWith("image/"));if(l.length===0)return!1;r.preventDefault();const a=t.posAtCoords({left:r.clientX,top:r.clientY});return a?(l.forEach(c=>{M0(c,a.pos,t,n,e)}),!0):!1},handlePaste:(t,r,i)=>{const o=i.content,s=[];o.descendants(l=>{l.type.name==="image"&&l.attrs.src.startsWith("data:")&&s.push(l.attrs.src)}),s.length!==0&&(s.forEach(()=>go(e)),setTimeout(()=>{O0(s,t,n,e)},100))}}})}function M0(n,e,t,r,i){const o=URL.createObjectURL(n),s=t.state.schema.nodes.image.create({src:o}),l=t.state.tr.insert(e,s);t.dispatch(l),go(i),Wc(n,r,i,a=>{Kc(o,a,t),URL.revokeObjectURL(o)})}async function O0(n,e,t,r){for(const i of n)fetch(i).then(o=>o.blob()).then(async o=>{Wc(o,t,r,s=>{Kc(i,s,e)})}).catch(()=>{xn(r)})}function Wc(n,e,t,r){if(n.type.indexOf("image")===-1){xn(t);return}if(n.size>5*1e6){xn(t);return}const i=new FormData;i.append("image",n),R.call({context:e,method:"post",endpoint:"/media/upload",data:i,complete:()=>{xn(t)},success:o=>{r(o.url)}})}function Kc(n,e,t){t.state.doc.descendants((r,i)=>{if(r.type.name==="image"&&r.attrs.src===n){const o=t.state.tr.setNodeMarkup(i,void 0,{src:e,alt:r.attrs.alt});t.dispatch(o)}})}function Jc(n,e,t){const r=n.state.schema.nodes.image.create({src:e,alt:t}),i=n.state.tr;n.state.selection.empty||i.setSelection(D.create(i.doc,n.state.selection.to));const o=n.state.selection.to;i.insert(o,r);let s=o;i.doc.nodesBetween(o,i.doc.content.size,(l,a)=>l.type.name==="image"?(s=a,!1):!0),i.insert(s+1,n.state.schema.nodes.paragraph.create()),i.setSelection(D.create(i.doc,s+1)),n.dispatch(i),n.focus()}function N0(n,e){if(n.state.selection.empty){const t=n.state.tr;t.insert(n.state.selection.to,n.state.schema.text(e,[n.state.schema.marks.link.create({href:e})])),n.dispatch(t)}else kt(n.state.schema.marks.link,{href:e})(n.state,n.dispatch);n.focus()}function E0(n,e,t){const r=n.state.tr;if(!n.state.selection.empty)return;let i=n.state.selection.to;if(t!==null){const{from:o,to:s,$from:l}=n.state.selection,a=Gc(n.state),c=a?a[0].length:t.length+1;r.delete(o-c,s),i=o-c}r.insert(i,n.state.schema.text(e)),n.dispatch(r),n.focus()}function Gc(n){const{$to:e}=n.selection;return e.parent.textContent.match(/:([a-zA-Z0-9-_+]*)(:?)$/i)}function Yc(n,e){const{$from:t,$to:r}=n.state.selection,i=n.state.selection.$from.parent,o=n.state.schema.nodes.embed.create({url:e}),s=n.state.tr;n.state.selection.empty||s.setSelection(D.create(s.doc,n.state.selection.to));const l=n.state.selection.to;s.insert(l,o);let a=l;s.doc.nodesBetween(l,s.doc.content.size,(c,u)=>c.type.name==="embed"?(a=u,!1):!0),s.insert(a+1,n.state.schema.nodes.paragraph.create()),i.type.name==="paragraph"&&i.textContent===""&&(s.setSelection(T.create(s.doc,t.before())),s.deleteSelection()),s.setSelection(D.create(s.doc,a+1)),n.dispatch(s),n.focus()}function T0(n,e){kt(e)(n.state,n.dispatch),n.focus()}function I0(n,e){e.view.updateState(Xc(n,e,ko)),X(e,"hasFocused",!1)}function D0(n){const e=O(n,"editor"),t={doc:Ae.doc,paragraph:Ae.paragraph,text:Ae.text};e.blockquotes&&(t.blockquote=Ae.blockquote),e.embeds&&(t.embed=Ae.embed),e.images&&(t.image=Ae.image),e.code_blocks&&(t.code_block=Ae.code_block),e.mentions&&(t.mention=Ae.mention),e.math&&(t.math=Ae.math);const r={};return e.links&&(r.link=bt.link),e.inline_styles&&(r.em=bt.em,r.strong=bt.strong,r.code=bt.code,r.strike=bt.strike,e.spoiler&&(r.spoiler=bt.spoiler)),new Oa({nodes:t,marks:r})}const ko={type:"doc",content:[{type:"paragraph"}]};function A0(n,e,t){const r=O(n,"editor"),i=[Wm(e),k0(e,r),rl($m(e)),rl(Zp),wm(),Km(t.type==="reply"?O(n,"text.reply_box")||k(n,"reply_box_text"):O(n,"text.comment_box")||k(n,"comment_box_text")),S0(n,t.id),w0(r.embeds)];return r.mentions&&i.unshift(...x0(t)),r.inline_styles&&i.push(...a0({markType:e.marks.code})),i}function Xc(n,e,t=ko){const r=D0(n);return qt.create({schema:r,doc:Te.fromJSON(r,t),plugins:A0(n,r,e)})}let wt=null;function R0({editor:n}){const[e,t]=w(!wt),r=M();B(()=>{wt===null&&R.call({context:r,method:"get",endpoint:"/media/emojis",success:o=>{wt=JSON.parse(o),t(!1)}})},[]);function i(o){const s=o.unicode.split("-"),l=[];for(let c=0;c=g.scrollHeight-g.clientHeight}function p(){if(!s.current)return;const g=s.current.getBoundingClientRect().top;if(h(s.current))return r(8);let y=null;for(let x=0,v=u.length;x"u"&&(S.icon=!0,m.push(v)))}return m.sort((g,y)=>u[g.categoryId].sort-u[y.categoryId].sort),u.sort((g,y)=>g.sort-y.sort),d("div",{className:"emoji-panel",children:[a?null:d("div",{className:"ep-header",children:m.map(g=>d("span",{className:"eph-icon"+(t==g.categoryId?" active":""),onClick:()=>f(g.categoryId),children:d(Bi,{dataObj:g})}))}),d("div",{className:"ep-body",ref:s,onScroll:p,children:d(z0,{data:u,onEmojiAdd:e,onMouseEnter:g=>o(g),onCataRef:(g,y)=>l.current[y]=g})}),d("div",{className:"ep-footer",children:i?d("span",{className:"eph-active",children:[d(Bi,{dataObj:i}),d("span",{className:"epha-name",children:[":",i.shortName,":"]})]}):null})]})}function z0({data:n,onEmojiAdd:e,onMouseEnter:t,onCataRef:r}){const i=n.map(o=>o.nodes.length?d("div",{ref:s=>r(s,o.id),className:"ep-cat",children:[d("div",{className:"epc-title",children:o.name}),d("div",{children:o.nodes.map(s=>d(Bi,{dataObj:s,onClick:()=>{e(s)},onMouseEnter:()=>{t(s)}},s.shortName))})]},o.id):null);return d("div",{children:i})}function Bi({dataObj:n,onClick:e,onMouseEnter:t}){const r=n.unicode.split("-"),i=[];for(let s=0;sm*1e6)return c(`Image is too large (Max ${m}MB)`);const g=new FormData;g.append("image",p),R.call({context:a,method:"post",endpoint:"/media/upload",data:g,complete:()=>{r(!1),xn(n.id)},success:y=>{u(y.url,p.name)},error:()=>c("Unable to upload. Please check your network connection.")})}return d("div",{className:"panel-image",children:t?d(K,{size:"small",padding:5}):d(te,{children:[d("div",{className:"left",children:[d(re,{scale:"medium",onClick:()=>s.current&&s.current.click(),children:k(a,"upload_image")}),d("input",{ref:s,type:"file",onChange:f,style:{display:"none"},accept:"image/*"})]}),d("span",{className:"or",children:k(a,"or")}),d("div",{className:"right",children:[d("input",{type:"text",placeholder:k(a,"paste_url"),value:i,onInput:h=>o(h.target.value)}),d(re,{scale:"medium",onClick:()=>l?null:u(i),children:k(a,"add")})]})]})})}function L0({editor:n}){const[e,t]=w(""),[r,i]=w(!1),[o,s]=w([]),l=H(null),a=H(null),c=M();function u(h,p){Jc(n.view,h,p),X(n,"panel",null)}function f(h=0){l.current&&l.current.abort(),i(!0),l.current=R.call({context:c,method:"get",customUrl:"https://api.tenor.com/v1/search",data:{key:"B78YRG1PAJIN",q:e,limit:20,media_filter:"basic"},success:p=>{i(!1),s(p.results)}})}return B(()=>{if(e.trim()==="")return s([]),i(!1);f()},[e]),B(()=>{a.current&&a.current.focus()},[]),d("div",{class:"panel-gif",children:[d("input",{type:"text",ref:a,placeholder:k(c,"search")+" GIF...",value:e,onInput:h=>t(h.target.value)}),r?d(K,{padding:20}):e.trim()&&d(te,{children:[d("div",{className:"gifs",children:o.length?o.map(h=>d("img",{src:h.media[0].nanogif.url,title:h.title,onClick:()=>u(h.media[0].gif.url,h.title)})):d(Lt,{})}),d("div",{className:"gif-footer",children:[k(c,"powered_by")," ",d("a",{href:"https://tenor.com/",target:"_blank",rel:"nofollow",children:"Tenor"})]})]})]})}function F0({editor:n}){const[e,t]=w(""),r=H(null),i=M();B(()=>{r.current&&r.current.focus()},[]);function o(){N0(n.view,e),X(n,"panel",null)}function s(){Yc(n.view,e),X(n,"panel",null)}return d("div",{class:"panel-link",children:[d("div",{class:"input-wrap",children:d("input",{ref:r,type:"text",placeholder:k(i,"paste_url"),value:e,onInput:l=>t(l.target.value)})}),d("div",{class:"button-wrap",children:[d(re,{scale:"medium",onClick:o,children:k(i,"link")}),d(re,{scale:"medium",onClick:s,children:k(i,"embed")})]})]})}function $0({type:n,editor:e,onClose:t}){return d("div",{class:"panel",children:[n==="emoji"&&d(R0,{editor:e}),n==="image"&&d(B0,{editor:e,onClose:t}),n==="gif"&&d(L0,{editor:e}),n==="link"&&d(F0,{editor:e})]})}function V0({editor:n}){const e=H(null),[t,r]=w(!1),{search:i,index:o,range:s}=n.mention,l=zt(rn),a=M(),c=xu(()=>{var x;const p=e.current,m=`${zi}-${n.id}`,g=(x=p.getRootNode())==null?void 0:x.querySelector("#"+m);if(!g)return;const y=g.getBoundingClientRect();p.style.top=y.top+y.height+"px",p.style.left=y.left+"px"},[]);function u(p){p=p.trim(),p!==""?(r(!0),b0(a,p,()=>{r(!1)})):$c(a,p)}function f(p){X(n,"mention",{search:i,index:p,range:s})}B(()=>{if(i===null){window.removeEventListener("scroll",c),r(!1);return}c(),window.addEventListener("scroll",c),l[i]===void 0&&u(i)},[i]);const h=i!==null?l[i]||[]:[];return d("div",{ref:e,id:Uc(n.id),class:"mention-suggestions"+(i!==null?" active":""),children:t?d(K,{padding:10,size:"small"}):h.length?h.map((p,m)=>d("div",{class:"user"+(m===o?" active":""),onMouseEnter:()=>f(m),onClick:()=>jc(n),children:[d($e,{user:p,size:20,profileOpener:!1}),d("div",{class:"name-wrap",children:d(an,{user:p,profileOpener:!1})}),p.username&&d("span",{class:"username",children:["@",p.username," "]})]})):d(Lt,{})})}function U0(n,e){n.innerHTML=e,Array.from(n.querySelectorAll("script")).forEach(t=>{var i;const r=document.createElement("script");Array.from(t.attributes).forEach(o=>r.setAttribute(o.name,o.value)),r.appendChild(document.createTextNode(t.innerHTML)),(i=t.parentNode)==null||i.replaceChild(r,t)})}function Qc(n,e){const t=e.dataset.url;if(!t||e.querySelector("a.bookmark"))return;const r=b.get(n,"htDomain")+"/embed/media/embed-iframe?url="+encodeURIComponent(t),i=document.createElement("iframe");i.src=r,i.style.border="none",i.style.minWidth="100%",i.style.overflow="hidden",window.addEventListener("message",function(s){s.data.type==="hyvor-talk-embed-height"&&s.data.url===t&&(i.style.height=s.data.height+"px")});function o(){var s;(s=i.contentWindow)==null||s.postMessage({type:"hyvor-talk-embed-request-height",url:t},"*")}window.addEventListener("resize",Fc(o)),e.innerHTML="",e.appendChild(i)}class j0{constructor(e,t,r,i){Y(this,"dom");this.dom=document.createElement("x-embed");const o=t.attrs.url;this.dom.dataset.url=o,this.dom.innerHTML='
Loading embed...
',this.dom.classList.add("loading"),R.call({context:e,method:"get",endpoint:"/media/embed",data:{url:o},success:s=>{U0(this.dom,s.html),Qc(e,this.dom)},error:()=>{Tt("Unable to embed this URL","error");const s=i(),l=r.state.schema.nodes.paragraph.create({},r.state.schema.text(o,[r.state.schema.marks.link.create({href:o})])),a=r.state.tr.replaceRangeWith(s,s+1,l);r.dispatch(a)}})}}function _o(){return Math.floor(new Date().getTime()/1e3)}const Zc="ht_drafts";function H0(n,e,t){const r=vo(n,e),i=wo();i[r]={at:_o(),doc:t},eu(i)}function vo(n,e){return b.get(n,"page").id+":"+(e||"comment")}function wo(){try{const n=localStorage.getItem(Zc);if(n)return JSON.parse(n)}catch{}return{}}function eu(n){try{localStorage.setItem(Zc,JSON.stringify(n))}catch{}}function q0(n,e){const t=wo(),r=vo(n,e);return t[r]?t[r].doc:null}function W0(n,e){const t=vo(n,e),r=wo();delete r[t],eu(r)}class K0{constructor(){Y(this,"dom");Y(this,"contentDOM");this.dom=document.createElement("pre"),this.contentDOM=document.createElement("code"),this.dom.appendChild(this.contentDOM)}destroy(){this.dom.remove()}update(e){return e.type.name==="code_block"}}function J0(n,e){const{$from:t}=n.state.selection,r=t.node();if(r&&r.type.name!=="code_block")return!1;function i(){const{tr:o}=n.state,l=t.start()+r.nodeSize-1;o.insert(l,n.state.schema.nodes.paragraph.create());const a=new D(o.doc.resolve(l+1));o.setSelection(a),n.dispatch(o)}if(e.key==="Enter"&&e.shiftKey||e.key==="ArrowDown"&&t.pos===t.end())return i(),!0;if(e.key==="Backspace"&&r.textContent.length===0){const{tr:o}=n.state,s=o.selection.from;return o.delete(s-1,s+r.nodeSize-1),n.dispatch(o),!0}return!1}function G0(n,e){const{from:t,$from:r,to:i,empty:o}=n.selection;return o?!!e.isInSet(n.storedMarks||r.marks()):n.doc.rangeHasMark(t,i,e)}function fl(n,e){const t=n.selection.$from;let r,i=t.depth;for(;i>0;){const o=t.node(i);e.name===o.type.name&&(r=i),i-=1}return!!r}function Y0({type:n,commentId:e=null,onPublish:t,onCancel:r,isModEdit:i=!1}){const o=M(),s=b.use("user"),l=b.use("userIsMod"),a=em(n,e),c=H(a),u=H(null),f=H(null),[h,p]=w(null),[m,g]=w(!1);B(()=>{c.current=a},[a]);const y=H(null),[,x]=w({}),[v,S]=w(!1),[N,J]=w(0),V=O(o,"commenting.min_chars");B(()=>{let z=ko;const P=c.current.type;P==="edit"&&(z=JSON.parse(Oe.get(c.current.commentId).content));const Ne=q0(o,c.current.commentId);P!=="edit"&&Ne&&(z=Ne);const _e=new Cc(y.current,{state:Xc(o,a,z),handleDOMEvents:{focus:he},nodeViews:{embed:(ve,G,je)=>new j0(o,ve,G,je),code_block:()=>new K0},dispatchTransaction:ve=>{he(),Nd(o,c.current.commentId);const G=_e.state.apply(ve);_e.updateState(G),x(G.toJSON()),P!=="edit"&&H0(o,c.current.commentId,G.doc.toJSON()),J(G.doc.textContent.length),I(_e)},handleKeyDown:De});if(P==="reply"||P==="edit"){const ve=_e.state.tr;ve.setSelection(D.near(ve.doc.resolve(ve.doc.content.size))),_e.dispatch(ve),_e.focus()}return X(a,"view",_e),()=>{Go(o,c.current.commentId),_e.destroy()}},[]);function I(z){const P=O(o,"editor"),Ne=Gc(z.state);P.emoji&&Ne?(X(a,"panel","emoji"),X(a,"emoji",Ne[1].toLowerCase())):(X(a,"panel",null),X(a,"emoji",null))}function L(z){g(!0)}function U(z){const P=z.currentTarget;P&&!P.contains(z.relatedTarget)&&g(!1)}function Ve(z){g(!1)}function he(){c.current.hasFocused!==!0&&X(a,"hasFocused",!0)}function De(z,P){var Ne;if(P.key==="Escape")return((Ne=c.current.mention)==null?void 0:Ne.search)!==null?void 0:(P.stopPropagation(),P.preventDefault(),$n(),document.body.focus(),!0);if(P.key==="Enter"&&(P.metaKey||P.ctrlKey))return Fn(),!0;if(J0(z,P))return!0}function Fn(){if(!c.current.view)return;const z=b.get(o,"user"),P=b.get(o,"userIsMod"),Ne=O(o,"commenting.max_chars");if(N>Ne){const G=k(o,"comment_char_limit")+` (${Ne})`;p(G),c.current.view.focus();return}if(!P&&V>0&&N{const je=jl(o,G.id);je&&(je.focus(),je.scrollIntoView({behavior:"smooth",block:"center"}))},10)}n==="edit"?i?Cr(o,e,"body",_e,()=>{sd(o,e,G=>{S(!1),ve(G)})}):id(o,e,_e,G=>{S(!1),ve(G)},Ft):(W0(o,c.current.commentId),rd(o,{body:_e,parentCommentId:c.current.commentId,guestName:c.current.guestName,guestEmail:c.current.guestEmail},G=>{I0(o,c.current),S(!1),ve(G)},Ft)),Go(o,c.current.commentId)}function Ft(z){p(z??k(o,"default_error")),S(!1)}function $n(){X(c.current,"hasFocused",!1),r&&r()}const Vn=["emoji","image","gif","link"],Un=["bold","italic"],Ue={bold:"strong",italic:"em",link:"link"};function jn(z){const P=c.current.view;P&&(Vn.indexOf(z)>=0&&X(a,"panel",c.current.panel===z?null:z),Un.indexOf(z)>=0&&T0(P,P.state.schema.marks[Ue[z]]),z==="quote"&&(fl(P.state,P.state.schema.nodes.blockquote)?Nc(P.state,P.dispatch):Dc(P.state.schema.nodes.blockquote)(P.state,P.dispatch),P.focus()))}function su(z){const P=a.view;return P?Un.indexOf(z)>=0||z==="link"?G0(P.state,P.state.schema.marks[Ue[z]]):Vn.indexOf(z)>=0?a.panel===z:z==="quote"?fl(P.state,P.state.schema.nodes.blockquote):!1:!1}return d("div",{class:"rich-editor"+(v?" publishing":"")+(a.hasFocused?" focused":""),onDragEnter:L,onDragLeave:U,onDrop:Ve,children:[m&&d("div",{class:"drop-overlay",children:k(o,"drop_text")}),d("div",{class:"comment-writer",ref:y}),!l&&V>0&&N>0&&NX(a,"guestName",z.target.value),ref:u})}),O(o,"commenting.guest_email")!=="no"&&d("div",{class:"guest-input",children:d("input",{type:"text",placeholder:k(o,"guest_email"),maxLength:250,value:a.guestEmail,onChange:z=>X(a,"guestEmail",z.target.value),ref:f})})]}),h&&d("div",{class:"comment-error",children:[d("span",{class:"error-icon",children:"!"})," ",h]}),d("div",{class:"comment-buttons",children:[d("div",{class:"writer-buttons",children:Q0().map(z=>d(X0,{name:z,editor:a.view,onClick:jn,isActive:su(z)}))}),d("div",{class:"action-buttons",children:[n!=="comment"&&d("button",{className:"cancel-button",onClick:$n,children:k(o,"cancel")}),d(re,{onClick:Fn,className:"main-button",isLoading:v,disabled:v||a.uploadingImages>0,children:n==="comment"?O(o,"text.comment_button")||k(o,"comment_button_text"):n==="reply"?O(o,"text.reply_button")||k(o,"reply_button_text"):k(o,"edit")})]})]}),a.panel&&d($0,{type:a.panel,onClose:()=>X(a,"panel",null),editor:a}),d(V0,{editor:a})]})]})}function X0({name:n,editor:e,onClick:t,isActive:r}){return d("button",{type:"button",class:"comment-button"+(r?" active":""),onClick:i=>{e.focus(),t(n)},"aria-label":n,children:d(de,{name:n})})}function Q0(){const n=M(),e=O(n,"editor"),t=[];return e.emoji&&t.push("emoji"),e.images&&t.push("image"),e.images&&e.gifs&&t.push("gif"),e.links&&t.push("link"),e.inline_styles&&t.push("bold","italic"),e.blockquotes&&t.push("quote"),t}function Li(n){const e=M(),t=b.use("user"),r=Hl(e),i=b.use("userBan");let o;return r?o=d("div",{class:"page-closed",children:k(e,"page_closed")}):i!==null?o=d("div",{class:"user-banned",title:i.ends_at?new Date(i.ends_at*1e3).toLocaleString():void 0,children:[i.ends_at?k(e,"banned_until",{"{until}":new Date(i.ends_at*1e3).toLocaleDateString()}):k(e,"banned"),i.reason?d("div",{class:"user-banned-reason",children:['"',i.reason,'"']}):null]}):!t&&!O(e,"commenting.guest")?o=d(ef,{}):o=d(Y0,{...n}),d("div",{class:"editor-wrap",children:[!n.commentId&&d(Xd,{}),o]})}function Z0({comment:n,onClose:e}){const t=M(),r=H(null),i=H(null);function o(){od(t,n),e()}function s(l){l.key==="Escape"&&e()}return B(()=>{i.current&&i.current.focus();const l=Ki(t);return l.addEventListener("keydown",s),()=>{l.removeEventListener("keydown",s)}}),d(ht,{name:"comment-deleter",vertical:"top",horizontal:"center",onClose:()=>e(),children:[d("div",{class:"text",children:k(t,"delete_confirm")}),d("div",{class:"footer",children:[d(dt,{buttonType:"no-background",scale:"medium",onClick:()=>e(),ref:r,children:k(t,"cancel")}),d(dt,{buttonType:"accent",scale:"medium",onClick:o,ref:i,children:k(t,"delete")})]})]})}function eg(n,e){return b.get(n,"badges").find(t=>t.id===e)}function tg({user:n}){const e=M();let t=n.badges;const r=O(e,"profiles.mod_badge_id"),i=b.get(e,"pageBadges");r&&n.type&&n.is_mod&&(t=[r,...t]);const o=Object.keys(i).filter(s=>s===n.type+"_"+n.id).map(s=>i[s]);return o.length&&(t=[...t,...o]),t.length===0||!n.id?null:d(te,{children:t.map(s=>{const l=eg(e,s);return l?d("span",{class:"user-badge",style:{backgroundColor:"#"+l.bg,color:"#"+l.fg},children:[l.icon_url&&d("span",{class:"img-wrap",children:d("img",{src:l.icon_url,alt:"Badge Icon"})}),l.text]}):null})})}function ng(n){const t=b.use("userFlags").find(r=>r.comment_id===n);return t||null}function rg(n,e){b.set(n,"userFlags",b.get(n,"userFlags").filter(t=>t.comment_id!==e)),R.callPageApi({context:n,method:"post",endpoint:`/comment/${e}/flag/remove`})}function ig(n,e,t){b.set(n,"userFlags",[...b.get(n,"userFlags"),{comment_id:e,reason:t}]),R.callPageApi({context:n,method:"post",endpoint:`/comment/${e}/flag`,data:{reason:t},success:()=>{Fe(n,"comment:flagged",{comment:wr(n,e)})}})}function og({comment:n}){const[e,t]=w(!1),[r,i]=w(""),o=H(null),s=M(),l=ng(n.id);B(()=>{o.current&&o.current.focus()},[e]);function a(){l?rg(s,n.id):t(!0)}function c(){ig(s,n.id,r),i(""),t(!1)}return d("div",{class:"flag"+(l?" active":""),children:[d("button",{class:"flag-button",onClick:a,title:k(s,"flag_comment"),children:d(de,{name:"flag"})}),e&&d(ht,{name:"flag-popup",vertical:"top",horizontal:"right",onClose:()=>t(!1),children:[d("div",{class:"body",children:[d("div",{class:"title",children:k(s,"flag_comment")}),d("textarea",{placeholder:k(s,"flag_reason")+" ("+k(s,"optional")+")",ref:o,value:r,onChange:u=>i(u.target.value)})]}),d("div",{class:"footer",children:[d(dt,{buttonType:"no-background",scale:"medium",onClick:()=>t(!1),children:k(s,"cancel")}),d(dt,{buttonType:"accent",scale:"medium",onClick:c,children:k(s,"flag")})]})]})]})}function sg(n){R.callPageApi({context:n,method:"post",endpoint:"/online/ping",success:e=>{b.set(n,"lastOnlineAt",e.at)}})}function lg({comment:n,onModEdit:e}){const[t,r]=w(!1),i=M();function o(){r(!1)}function s(){Wo(i,n,"deleted")}function l(){Wo(i,n,"spam")}function a(){ad(i,n.id,!n.is_featured),o()}function c(){cd(i,n.id,!n.is_loved),o()}function u(){e(),o()}function f({name:h,onClick:p}){return d("button",{onClick:()=>p(),children:h})}return d("div",{className:"mod",children:[d("button",{className:"mod-button",onClick:()=>r(!0),title:k(i,"moderate"),children:d(de,{name:"mod"})}),t&&d(ht,{name:"mod-popup",vertical:"top",horizontal:"right",onClose:o,children:[d("div",{class:"mod-title",children:k(i,"moderate")}),d(f,{name:k(i,"delete"),onClick:s}),d(f,{name:k(i,"spam"),onClick:l}),n.parent_id===null&&d(f,{name:k(i,n.is_featured?"unfeature":"feature"),onClick:a}),d(f,{name:k(i,n.is_loved?"unlove":"love"),onClick:c}),d(f,{name:k(i,"edit"),onClick:u})]})]})}let Xn=null,si=null;async function ag(n,e){(await cg(n)).render(e.textContent,e,{throwOnError:!1})}async function cg(n){if(Xn)return Xn;Xn=(await Xi(async()=>{const{default:r}=await import("https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.mjs");return{default:r}},[])).default;const e=_r(n).shadowRoot,t=document.createElement("link");return t.rel="stylesheet",t.href="proxy.php?url=https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.css",e==null||e.appendChild(t),Xn}async function ug(n,e){si||(si=(await Xi(async()=>{const{default:t}=await import("./comments-index.js");return{default:t}},[])).default),si.highlightBlock(e)}const hl=800;function tu({content:n}){const e=H(null),t=H(null),r=M(),[i,o]=w(null);function s(){return e.current}function l(){s().getBoundingClientRect().height>hl?o("overflowed"):o(null)}function a(){o(i==="overflowed"?"overflowed-expanded":"overflowed")}return B(()=>{l(),s().querySelectorAll("img").forEach(c=>{c.addEventListener("load",l),c.addEventListener("click",()=>{var u;((u=c.parentElement)==null?void 0:u.className)!=="bookmark-thumbnail"&&b.set(r,"modalImageUrl",c.src)})}),s().querySelectorAll("x-embed").forEach(c=>Qc(r,c)),O(r,"editor.math")&&s().querySelectorAll("x-math").forEach(c=>{ag(r,c)}),O(r,"editor.code_blocks")&&s().querySelectorAll("pre code").forEach(c=>{ug(r,c)})},[]),B(()=>{const c=s();i==="overflowed"?c.style.height=hl+"px":c.style.height="initial"},[i]),d("div",{class:"comment-content",children:[d("div",{class:"comment-content-inner",ref:e,dangerouslySetInnerHTML:{__html:n}}),i!==null&&d("div",{class:"overflow-expander",children:d(dt,{ref:t,buttonType:"no-background",scale:"small",onClick:a,children:k(r,i==="overflowed"?"show_more":"show_less")})})]})}function dg({commentId:n}){const[e,t]=w(!1),r=b.use("typing")[on(n)]||[],i=M(),o=O(i,"realtime.typing");if(o==="off"||!r.length)return null;function s(){o!=="on_without_typer"&&t(!0)}function l(){t(!1)}return d("div",{class:"typing",onClick:()=>e?l():s(),children:[d("span",{className:"typing-text",children:[k(i,"replying_with_count",{"*":r.length.toString()}),e&&d(hg,{typings:r,onClose:l})]}),d(fg,{})]})}function fg(){const[n,e]=w(0);return B(()=>{const t=setInterval(()=>e(r=>r>=3?0:r+1),500);return()=>clearInterval(t)},[]),d(te,{children:".".repeat(n)})}function hg({typings:n,onClose:e}){const t=[];let r=0;const i=M();for(const o of n)o.user?t.find(s=>qi(s,o.user))||t.push(o.user):r++;return d(ht,{name:"typers-popup",vertical:"top",horizontal:"center",onClose:e,popupProps:{onClick:o=>o.stopPropagation()},children:[t.map(o=>d("div",{class:"user-row",children:[d($e,{user:o,size:16}),d(an,{user:o})]})),r>0&&d("div",{class:"user-row",children:r===1?k(i,"guest"):k(i,"guests",{"*":r.toString()})})]})}function pg(n,e){R.call({context:n,method:"get",endpoint:"/user/blocked",data:{user_id:e.id,user_type:e.type},success:t=>{t.length===1&&ru(n,e.type+"_"+e.id)}})}function mg(n){if(!n.id)return!1;const e=b.use("userBlocked");for(const t of e)if(t.htid===n.type+"_"+n.id)return!0;return!1}async function nu(n,e,t,r){const[i,o]=e.split("_"),s=bd(e,t);R.call({context:n,method:"post",endpoint:"/user/block",data:{status:t,user_id:o,user_type:i,comment_ids:s},complete:()=>{r&&r()},success:l=>{for(const a of l.comments)vr(n,a);gg(n,e,t)}})}function gg(n,e,t){t?ru(n,e):bg(n,e)}function ru(n,e){b.set(n,"userBlocked",[...b.get(n,"userBlocked"),{htid:e}])}function bg(n,e){b.set(n,"userBlocked",b.get(n,"userBlocked").filter(t=>t.htid!==e))}function yg({comment:n}){const e=M(),[t,r]=w(!1);function i(o){r(!0),nu(e,o,!1,()=>{r(!1)})}return d("div",{class:"comment-hidden",children:[k(e,"blocked_comment"),d(dt,{buttonType:"secondary",onClick:()=>{n.blocked_user_htid&&i(n.blocked_user_htid)},style:{pointerEvents:t?"none":"auto",opacity:t?.5:1,textDecoration:"underline",padding:"0",marginLeft:"20px"},children:k(e,"unblock_user")})]})}function Ar({id:n,replies:e=null,canReply:t,onReply:r}){const i=M(),o=Oe.use(n)||{is_hidden:!0},s=b.use("userBan");t=t===void 0?!!e:t;const[l,a]=w(!1),[c,u]=w(!1),[f,h]=w(!1),[p,m]=w(!1),[g,y]=w(!1),x=b.use("user"),v=b.use("userIsMod"),S=b.use("specificCommentId"),N=b.use("focusedCommentId"),J=b.use("flashingCommentId"),V=b.use("userIsShadowBanned"),I=o.is_hidden,L=!I&&x&&o.user.id===x.id&&o.user.type===x.type,U=Ku(o);function Ve(){U&&($l(o),sg(i))}function he(){if(!f&&!pl(i,o)){Tt(k(i,"edit_cant"));return}h(!f)}function De(){navigator.clipboard.writeText(o.url).then(()=>{Tt(k(i,"link_copied"))})}function Fn(){m(!0)}function Ft(Ue){var jn;return(jn=Ul(i,o.id))==null?void 0:jn.querySelector(`.action-button.${Ue} button`)}function $n(){u(!1),setTimeout(()=>Ft("reply").focus(),0)}function Vn(){h(!1),m(!1),setTimeout(()=>Ft("edit").focus(),0)}function Un(){y(!1),setTimeout(()=>{var Ue;return(Ue=Ft("delete"))==null?void 0:Ue.focus()},0)}return B(()=>{J===o.id&&gd(i)},[J]),d("div",{class:"comment comment-"+o.id+(l?" collapsed":"")+(U&&O(i,"highlight.new")?" new":"")+xg(o)+(o.depth>=O(i,"comments_view.nested_levels")?" depth-exceeded":"")+(!o.is_hidden&&o.is_featured?" featured":"")+(S===o.id?" specific":"")+(N===o.id?" focused":"")+(J===o.id?" flashing":""),onClick:Ve,children:[d("div",{class:"comment-inside",tabIndex:-1,children:[!I&&d("div",{className:"comment-side",children:O(i,"profiles.pictures")?d($e,{user:o.user}):d("div",{style:{marginLeft:"32px"}})}),d("div",{className:"comment-main",children:[I?o.blocked_user_htid!=null?d(yg,{comment:o}):d("div",{class:"comment-hidden",children:k(i,"hidden_comment")}):d(te,{children:[d("div",{className:"comment-meta",children:[d("div",{class:"comment-meta-left",children:d("span",{class:"comment-user",children:[d("span",{className:"comment-user-name",children:[d(an,{user:o.user}),d(tg,{user:o.user}),d("a",{className:"comment-time","aria-label":`View ${o.user.name}'s comment`,href:o.url,target:"_blank",rel:"nofollow noindex",children:d(ua,{time:o.created_at})}),o.is_edited&&d("span",{className:"comment-edited",children:["(",k(i,"edited"),")"]}),e!==null&&d(kg,{comment:o})]}),o.user.title&&d("span",{class:"comment-user-title",children:o.user.title})]})}),d("div",{className:"comment-tags",children:[(o.status==="pending"||o.status==="spam"||o.status==="deleted")&&!(V&&o.status==="deleted")&&d("span",{class:"comment-tag "+o.status,children:k(i,o.status)}),o.is_featured&&d("span",{className:"comment-tag featured",children:k(i,"featured")}),o.is_loved&&d("span",{className:"comment-tag loved",children:[d(de,{name:"heart"})," ",k(i,"loved_by",{"*":b.get(i,"website").name})]})]})]}),f||p?d("div",{class:"comment-edit-editor",children:d(Li,{type:"edit",commentId:o.id,onPublish:()=>{h(!1),m(!1)},onCancel:Vn,isModEdit:p})}):d(tu,{content:o.content_html}),d("div",{className:"comment-actions",children:[d("div",{class:"comment-actions-left",children:[o.status==="published"&&d(Yd,{comment:o}),t&&!Hl(i)&&s===null&&o.status==="published"&&d(li,{label:k(i,"reply"),additionalClass:"reply",onClick:()=>u(!c)}),L&&d(te,{children:[pl(i,o)&&s===null&&d(li,{label:k(i,"edit"),additionalClass:"edit",onClick:he}),d(li,{label:k(i,"delete"),additionalClass:"delete",onClick:()=>y(!g),children:g&&d(Z0,{comment:o,onClose:Un})})]}),d("button",{className:"action-button comment-link-copy",onClick:De,title:k(i,"copy_link"),children:d(de,{name:"link"})}),d(dg,{commentId:o.id})]}),d("div",{class:"comment-actions-right",children:[x&&v&&d(lg,{comment:o,onModEdit:Fn}),x&&!L&&d(og,{comment:o})]})]}),c&&d("div",{class:"comment-reply-editor",children:d(Li,{type:"reply",commentId:o.id,onPublish:Ue=>{u(!1),r&&r(Ue)},onCancel:$n})})]}),l&&d(Kd,{commentId:o.id,onExpand:()=>a(!1)})]})]}),e&&d(te,{children:[d("div",{class:"comment-replies",children:e}),d(Wd,{comment:o,onCollapse:()=>a(!0)})]})]})}function xg(n){const e=M();if(n.is_hidden)return"";const t=O(e,"highlight.upvote_1_threshold"),r=O(e,"highlight.upvote_2_threshold");return t&&n.upvotes>=t?" highlight-upvote-1":r&&n.upvotes>=r?" highlight-upvote-2":""}function pl(n,e){if(!O(n,"commenting.editing"))return!1;const t=O(n,"commenting.editing_timeout");if(!t)return!0;const r=e.created_at;return(Date.now()/1e3-r)/60n(),"aria-label":t,children:t}),r]})}function kg({comment:n}){const e=M();if(!n.parent_id||!Oe.has(n.parent_id))return null;const t=wr(e,n.parent_id);if(t.is_hidden)return null;const r=O(e,"comments_view.display_replied_to_type");return r==="none"||r==="deep"&&n.depthYi(e,n.parent_id),children:[d("span",{children:d(de,{name:"reply"})}),d("span",{class:"user-data",children:[d($e,{user:t.user,size:13,profileOpener:!1}),d(an,{user:t.user,profileOpener:!1})]})]})}function _g({id:n,pages:e}){const t=Oe.use(n),r=e[t.page_id];return d("div",{class:"user-comment",children:[d("div",{class:"page-title",children:d("a",{href:t.url,target:"_blank",children:(r==null?void 0:r.title)||"(Untitled)"})}),d(Ar,{id:n,replies:null})]})}function vg({user:n}){const[e,t]=w(!0),[r,i]=w([]),[o,s]=w({}),[l,a]=w(!1),[c,u]=w(!1),f=M();function h(p=!1){p&&u(!0),R.call({context:f,method:"get",endpoint:"/commenter/comments",data:{user_id:n.id,user_type:n.type,offset:p?r.length:0},complete:()=>{t(!1),u(!1)},success:m=>{Kl(f,m.comments);const g=m.comments.map(y=>y.id);i(p?[...r,...g]:g),s({...o,...m.pages}),a(m.comments.length===25)}})}return B(()=>{h()},[]),e?d(K,{padding:60}):d("div",{class:"user-comments",children:[r.length?r.map(p=>d(_g,{id:p,pages:o})):d(Lt,{padding:50}),l&&(c?d(K,{padding:15}):d("div",{class:"has-more",children:d(re,{scale:"medium",onClick:()=>h(!0),children:k(f,"load_more")})}))]})}function wg(){const[n,e]=w(),[t,r]=w(!1),i=M();B(()=>{R.call({context:i,method:"get",endpoint:"/user/settings",success:s=>{e(s)}})},[]);function o(){r(!0),R.call({context:i,method:"post",endpoint:"/user/settings",data:n,success:s=>{Tt(k(i,"saved"))},complete:()=>{r(!1)}})}return n?d("div",{class:"user-settings",children:[d("div",{class:"title",children:k(i,"settings_for_website",{"{website}":O(i,"name")})}),d("div",{className:"setting",children:[d("div",{className:"text",children:k(i,"reply_emails")}),d("input",{type:"checkbox",checked:n.email_reply,onChange:s=>e({...n,email_reply:s.target.checked})})]}),d("div",{className:"setting",children:[d("div",{className:"text",children:k(i,"mention_emails")}),d("input",{type:"checkbox",checked:n.email_mention,onChange:s=>e({...n,email_mention:s.target.checked})})]}),d("div",{class:"save-wrap",children:d(re,{onClick:o,isLoading:t,children:"SAVE"})})]}):d(K,{padding:60})}function iu({user:n}){const e=M(),t=mg(n),[r,i]=w(!1),[o,s]=w(!1);B(()=>{i(t)},[t]),B(()=>{pg(e,n)},[]);function l(){s(!0),nu(e,Zi(n),!r,()=>{Tt(r?k(e,"unblocked"):k(e,"blocked")),s(!1)})}return d(re,{scale:"small",isLoading:o,onClick:l,children:k(e,r?"unblock":"block_button")})}function Cg(){const[n,e]=w(!0),[t,r]=w([]),[i,o]=w(!1),[s,l]=w(!1),a=M();function c(u=!1){u&&l(!0),R.call({context:a,method:"get",endpoint:"/user/blocked",data:{offset:u?t.length:0},success:f=>{e(!1),l(!1),r(f),o(f.length===25)}})}return B(()=>{c()},[]),n?d(K,{padding:60}):d("div",{class:"user-blocked",children:[t.length?t.map(u=>d(Sg,{user:u})):d(Lt,{padding:50}),i&&(s?d(K,{padding:15}):d("div",{class:"has-more",children:d(re,{scale:"medium",onClick:()=>c(!0),children:k(a,"load_more")})}))]})}function Sg({user:n}){const e=M();return d("div",{class:"block",children:[d($e,{user:n,profileOpener:!1}),d("div",{class:"user-name",children:In(e,n)}),d(iu,{user:n})]})}function Mg({user:n}){const e=M(),[t,r]=w(),[i,o]=w(!0),s=t==null?void 0:t.state,l=(t==null?void 0:t.note)||"",a=(t==null?void 0:t.ban_reason)||"",c=t==null?void 0:t.state_ends_at;B(()=>{R.call({context:e,method:"get",isConsoleApi:!0,endpoint:`/user/${Zi(n)}`,success:x=>{r(x),o(!1)},error:()=>{r({state:"default",note:"",state_ends_at:null,ban_reason:""}),o(!1)}})},[n]);function u(x,v){r({...t,[x]:v}),Hd(e,n,x,v,S=>r(S))}function f(x){u("state",x)}function h(x){u("note",x)}function p(x){u("ban_reason",x)}function m(){let x;c===null?x=Math.floor(Date.now()/1e3)+86400*7:x=null,u("state_ends_at",x)}function g(x){const v=new Date(x),S=Math.floor(v.getTime()/1e3);u("state_ends_at",S)}const y=({value:x})=>{const v="user-state-"+x;return d("div",{class:"state-input",children:[d("input",{type:"radio",name:"state",id:v,value:x,checked:s===x,onChange:S=>f(S.target.value)}),d("label",{for:v,children:x})]})};return i?d(K,{padding:60}):d("div",{class:"user-moderation",children:[d("div",{class:"privacy-note",children:k(e,"mod_privacy")}),d("div",{class:"dual-view",children:[d("div",{class:"left",children:"State"}),d("div",{class:"right",children:[d(y,{value:"default"}),d(y,{value:"banned"}),d(y,{value:"shadowed"}),d(y,{value:"trusted"})]})]}),(s==="banned"||s==="shadowed")&&d("div",{class:"dual-view",children:[d("div",{class:"left",children:"Temporary Ban"}),d("div",{class:"right",children:[d("div",{class:"temp-ban-wrap",children:d("input",{type:"checkbox",name:"temporary-ban",id:"temporary-ban",checked:c!==null,onChange:()=>m()})}),c&&d("input",{type:"date",name:"temporary-ban-date",id:"temporary-ban-date",min:new Date().toISOString().split("T")[0],value:new Date(c*1e3).toISOString().split("T")[0],onChange:x=>g(x.target.value)})]})]}),s=="banned"&&d("div",{class:"dual-view",children:[d("div",{class:"left",children:"Ban Reason"}),d("div",{class:"right",children:d("textarea",{class:"user-note",onBlur:x=>p(x.target.value),children:a})})]}),d("div",{class:"dual-view",children:[d("div",{class:"left",children:"Note"}),d("div",{class:"right",children:d("textarea",{class:"user-note",onBlur:x=>h(x.target.value),children:l})})]})]})}function ou(n,e){const t=Fe(n,"profile:clicked",e);t&&t.defaultPrevented||b.set(n,"profilePopupUser",e)}function Og(){const[n,e]=w(null),[t,r]=w("comments"),i=M(),o=b.use("profilePopupUser"),s=b.use("user"),l=o&&jd(o),a=b.use("userIsMod");function c(f){return f.replace(/^https?:\/\//,"")}B(()=>{o&&R.call({context:i,method:"get",endpoint:"/commenter",data:{user_id:o.id,user_type:o.type},success:f=>{e(f)}})},[o]);function u({name:f,label:h,count:p}){return d("button",{class:"selector"+(f===t?" active":""),onClick:()=>r(f),children:[h,p!==void 0&&d("span",{class:"count",title:f==="comments"?la(p):void 0,children:Qi(i,p,!0)})]})}return o?d("div",{class:"user-profile-popup-wrap",children:[d("div",{class:"popup-closer",onClick:f=>{f.stopPropagation(),b.set(i,"profilePopupUser",null)}}),d("div",{class:"popup-content",children:[d("div",{class:"user-profile",children:[d("button",{class:"close-button",onClick:()=>b.set(i,"profilePopupUser",null),"aria-label":"Close",children:"×"}),d("div",{class:"user-profile-inner",children:[d("div",{class:"profile-left",children:d($e,{user:o,profileOpener:!1,size:100})}),d("div",{class:"profile-right",children:[d("div",{class:"name",children:In(i,o)}),o.username&&d("div",{class:"username",children:["@",o.username]}),o.location&&d("div",{class:"location",children:o.location}),o.bio&&d("div",{class:"bio",children:o.bio}),o.website_url&&d("div",{className:"website",children:d("a",{href:o.website_url,target:"_blank",rel:"nofollow noindex",children:[c(o.website_url)," ",d(de,{name:"link"})]})}),d("div",{class:"actions",children:[l?d(te,{children:[d(Eg,{user:o}),d(Ng,{})]}):null,s&&!l&&d(iu,{user:o})]})]})]})]}),d("div",{class:"section-selector",children:[d(u,{name:"comments",label:k(i,"comments"),count:n?n.comments_count:void 0}),l&&d(te,{children:[d(u,{name:"blocked",label:k(i,"blocked")}),d(u,{name:"settings",label:k(i,"settings")})]}),a&&d(u,{name:"moderate",label:k(i,"moderate")})]}),d("div",{class:"section-wrap",children:[t==="comments"&&d(vg,{user:o}),t==="settings"&&d(wg,{}),t==="blocked"&&d(Cg,{}),t==="moderate"&&d(Mg,{user:o})]})]})]}):null}function Ng(){const n=M();return Rn(n)?null:d(re,{scale:"medium",onClick:()=>Pe.logout(n),children:k(n,"account_logout")})}function Eg({user:n}){const e=M();return n.type!=="hyvor"?null:d("a",{href:"https://hyvor.com/account",target:"_blank",children:d(re,{scale:"medium",children:k(e,"account_my")})})}function In(n,e){const t=O(n,"profiles.display_name_type");if(e.type&&e.is_mod&&e.is_mod_alias){const r=O(n,"profiles.mod_alias_name");if(r)return r}return t==="username"&&e.username||e.name}function an({user:n,profileOpener:e=!0}){const t=M(),[r,i]=w(!1),o=e&&aa(n);function s(){o&&(ou(t,n),i(!0))}return B(()=>{function l(a){a.key==="Escape"&&r&&(i(!1),b.set(t,"profilePopupUser",null))}return document.addEventListener("keyup",l),()=>{document.removeEventListener("keyup",l)}},[r,t]),o?d("button",{class:"user-name clickable",onClick:s,children:In(t,n)}):d("span",{class:"user-name",children:In(t,n)})}function Tg({notification:n,onRead:e,onClose:t}){const r=M();Yl(r,n.comment_id);function i(o){n.is_read||e(),md(r,n.comment_id)&&o.preventDefault(),t()}return d("a",{class:"notification"+(n.is_read?"":" not-read"),onClick:i,href:n.comment_url,target:"_blank",children:[d("div",{class:"left",children:d($e,{user:n.user})}),d("div",{class:"right",children:[d("div",{className:"text",children:k(r,n.type==="reply"?"notifications_reply":"notifications_mention",{"{name}":In(r,n.user)})}),d("div",{class:"meta",children:[d("div",{class:"page-title",children:n.page_title||"(Untitled Page)"}),d("div",{class:"time",children:d(ua,{time:n.created_at})})]})]})]})}function Ig(n,e){R.call({context:n,method:"post",endpoint:"/notifications/read",data:{id:e}});const t=b.get(n,"notifsCount");b.set(n,"notifsCount",Math.max(t-1,0))}function Dg(n){R.call({context:n,method:"post",endpoint:"/notifications/read-all"}),b.set(n,"notifsCount",0)}function Ag({onClose:n}){const[e,t]=w(!0),[r,i]=w(!1),[o,s]=w(!1),[l,a]=w([]),[c,u]=w(!0),f=M();b.use("notifsCount");function h(g=!1){g&&s(!0),R.call({context:f,method:"get",endpoint:"/notifications",data:{offset:g?l.length:0},complete:()=>{t(!1),s(!1)},success:y=>{a([...l,...y]),i(y.length===25)}})}function p(g){a(l.map(y=>y.id===g?{...y,is_read:!0}:y)),Ig(f,g)}function m(){a(l.map(g=>({...g,is_read:!0}))),Dg(f)}return B(()=>{function g(y){y.key==="Escape"&&c&&(u(!1),n())}return document.addEventListener("keyup",g),()=>{document.removeEventListener("keyup",g)}},[c,n]),B(h,[]),c?d(ht,{name:"notifications-popup",vertical:"bottom",horizontal:"right",onClose:n,children:e?d(K,{padding:25,size:"small"}):l.length?d("div",{class:"notifications-list",children:[d("div",{class:"read-all",children:d("button",{onClick:m,children:k(f,"notifications_read")})}),l.map(g=>d(Tg,{notification:g,onRead:()=>p(g.id),onClose:n})),r&&d("div",{class:"has-more",children:o?d(K,{padding:0,size:"small"}):d(re,{scale:"small",onClick:()=>h(!0),children:k(f,"notifications_load_more")})})]}):d(Lt,{text:k(f,"notifications_no"),padding:25})}):null}function ml({value:n,disabled:e,onChange:t}){return d("label",{class:"switch",children:[d("input",{type:"checkbox",checked:n,onChange:r=>{r.stopPropagation(),t()},disabled:!!e}),d("span",{class:"slider"})]})}function Rg(){const n=b.use("page"),[e,t]=w(!1),r=M(),i=H(null),o=H(null),s=n.is_closed,l=n.is_premoderation_on;function a(){td(r,!s),b.set(r,"page",{...n,is_closed:!s})}function c(){nd(r,!l)}function u(f){t(f)}return B(()=>{if(e&&i.current){const f=i.current.querySelector('input, button, select, textarea, [tabindex]:not([tabindex="-1"])');f?f.focus():i.current.focus()}},[e]),B(()=>{function f(p){p.key==="Escape"&&e&&(t(!1),o.current&&o.current.focus())}function h(p){if(e&&i.current&&!i.current.contains(p.target)){p.stopPropagation();const m=i.current.querySelector('input, button, select, textarea, [tabindex]:not([tabindex="-1"])');m?m.focus():i.current.focus()}}return document.addEventListener("keyup",f),document.addEventListener("focus",h,!0),()=>{document.removeEventListener("keyup",f),document.removeEventListener("focus",h,!0)}},[e]),d("div",{className:"page-mod-icon",children:[d("button",{ref:o,className:"page-mod-button",onClick:()=>u(!e),title:k(r,"moderate"),children:d(de,{name:"mod"})}),e&&d("div",{ref:i,class:"page-moderation-popup-wrap",children:[d("div",{class:"popup-closer",onClick:()=>u(!1)}),d("div",{class:"mod-content",role:"dialog","aria-modal":"true",children:d("div",{class:"page-moderation-panel",children:[d("p",{id:"modTitle",class:"mod-title",children:k(r,"mod_privacy")}),d("div",{class:"duel-view",children:[d("div",{class:"left",children:k(r,"mod_page_closed")}),d("div",{class:"right",children:d(ml,{value:s,onChange:a})})]}),d("div",{class:"duel-view",children:[d("div",{class:"left",children:k(r,"mod_page_premod")}),d("div",{class:"right",children:d(ml,{value:l,onChange:c})})]})]})})]})]})}function Pg(){const[n,e]=w(!1),t=M(),r=b.use("notifsCount"),i=b.use("userIsMod");return d("div",{class:"notifications",children:[i&&d(Rg,{}),d("button",{"aria-label":k(t,"notifications"),class:"notification-icon",onClick:()=>e(!n),children:[r>0&&d("span",{class:"notifs-count-tag",children:Math.min(99,r)}),d(de,{name:"bell"})]}),n&&d(Ag,{onClose:()=>e(!1)})]})}function zg({onClose:n}){const[e,t]=w(!0),[r,i]=w([]),[o,s]=w(!1),[l,a]=w(!1),c=H(0),u=M();function f(h=!1){h&&a(!0),R.callPageApi({context:u,method:"get",endpoint:"/online/users",data:{offset:h?r.length:0,filter_at:h?c.current:null},complete:()=>{t(!1),a(!1)},success:p=>{h||(c.current=_o()),i(h?[...r,...p]:p),s(p.length===50)}})}return B(f,[]),d(ht,{name:"online-list",vertical:"bottom",horizontal:"center",onClose:n,children:[e?d(K,{padding:20,size:"small"}):r.length?r.map(h=>d("div",{class:"user-row",children:[d($e,{size:20,user:h}),d(an,{user:h})]})):d(Lt,{}),o&&(l?d(K,{padding:15,size:"small"}):d("div",{class:"has-more",children:d(re,{scale:"small",onClick:()=>f(!0),children:k(u,"load_more")})}))]})}function Bg(){const[n,e]=w(!1),{online_count:t}=b.use("page"),r=M(),i=O(r,"realtime.users"),o=H(null);return B(()=>{O(r,"realtime.on")&&O(r,"realtime.count")},[]),B(()=>{function s(l){l.key==="Escape"&&n&&(e(!1),o.current&&o.current.focus())}return document.addEventListener("keyup",s),()=>{document.removeEventListener("keyup",s)}},[n]),!O(r,"realtime.on")||!O(r,"realtime.count")?null:d("button",{class:"online-count",onClick:()=>i&&e(!0),ref:o,tabindex:i?0:-1,children:[d(sa,{number:Math.max(t,1)}),"  ",k(r,"online"),n&&d(zg,{onClose:()=>e(!1)})]})}function Lg(){const n=b.use("user"),e=M();return d("div",{className:"main-box-header-wrap",children:d("div",{className:"main-box-header",children:[d("div",{className:"main-box-header-left",children:[d(Ud,{}),d(Bg,{})]}),d("div",{className:"main-box-header-right",children:n?d(Pg,{}):!O(e,"commenting.force_guest")&&d(Qd,{})})]})})}function Fg({index:n}){const e=M(),[t,r]=w(!1),i=n==="PARENT";function o(){r(!0),Wl({context:e,isMore:!0,parentCommentId:i?null:n,onSuccess:()=>{r(!1)}})}return d("div",{class:"load-more"+(i?" parent":""),children:t?d(K,{padding:5}):i?d(re,{onClick:o,children:k(e,"load_more_comments")}):d("button",{onClick:o,children:[k(e,"more_replies"),"..."]})})}function Co({index:n,type:e}){let t=b.use(e==="main"?"commentsList":"specificCommentRepliesList")[n]||[];const r=b.use(e==="main"?"commentsHasMoreIds":"specificCommentHasMoreIds"),i=fd(n),o=n==="PARENT";t=[...xd(n,t),...t];const l=M();return d("div",{class:"comments-list"+(o?" parent":""),children:[i>0&&d("div",{class:"show-new-comments"+(o?" parent":" reply"),children:d(re,{scale:"medium",onClick:()=>hd(l,n),children:i===1?k(l,o?"show_new_comment":"show_new_reply"):k(l,o?"show_new_comments":"show_new_replies",{"*":i.toString()})})}),t.map(a=>d(Ar,{id:a,replies:d(Co,{index:a,type:e})},a)),o&&t.length===0&&d("div",{class:"no-comments",children:O(l,"text.no_comments")||k(l,"no_comments_text")}),r.indexOf(n)>=0&&d(Fg,{index:n})]})}function $g({onChange:n}){const e=b.use("commentsList"),t=b.use("commentsSort"),r=M(),[i,o]=w(!1);function s(c){o(!1),b.set(r,"commentsSort",c),n(c)}function l({type:c}){return d("button",{onClick:()=>s(c),class:t===c?"active":"","aria-selected":t===c?"true":"false",role:"option",children:k(r,c)})}return e&&e.PARENT&&e.PARENT.length>0?d("div",{id:"sorter",children:[d("button",{class:"sort-button",onClick:()=>o(!i),"aria-haspopup":"listbox","aria-expanded":i,"aria-controls":"sort-options","aria-label":k(r,"sort_comments"),children:[k(r,t)," ",d(de,{name:"caret"})]}),i&&d(ht,{name:"sort-selector",vertical:"bottom",horizontal:"left",onClose:()=>o(!1),children:d("div",{role:"listbox",id:"sort-options","aria-labelledby":"sort-button-label",children:[d(l,{type:"top"}),d(l,{type:"newest"}),d(l,{type:"oldest"})]})})]}):null}class Vg{constructor(e){Y(this,"embedRoot");this.context=e,this.embedRoot=Ki(e)}init(){let e=!1,t=!1;document.body.addEventListener("keydown",r=>{r.shiftKey||r.ctrlKey||r.altKey||r.metaKey||r.target!==document.body||(r.key==="c"?e?(this.focusNextComment(),e=!1):(e=!0,setTimeout(()=>{e=!1},300)):r.key==="n"&&(t?(r.preventDefault(),this.focusCommentWriter(),t=!1):(t=!0,setTimeout(()=>{t=!1},300))))}),this.embedRoot.addEventListener("keydown",r=>{if(r.ctrlKey||r.altKey||r.metaKey)return;const i=r.target;if(!(i.tagName==="INPUT"||i.tagName==="TEXTAREA"||i.isContentEditable)){if(r.stopPropagation(),r.key==="c")this.focusNextComment();else if(r.key==="x")this.focusPreviousComment();else if(r.key==="z")this.focusNextUnreadComment();else if(r.key==="n")r.preventDefault(),this.focusCommentWriter();else if(r.key==="Backspace")this.clickButton("delete");else if(r.key==="e")this.clickButton("edit");else if(r.key==="r")this.clickButton("reply");else if(r.key==="+")this.clickButton("upvote");else if(r.key==="-")this.clickButton("downvote");else if(r.key==="Escape"){const o=i.closest(".comment-inside");o&&o.focus()}}})}getFocusedCommentInside(){return this.embedRoot.querySelector(".comment-inside:focus")}getCurrentlyFocusedCommentIdPath(){const e=this.getFocusedCommentInside();if(!e)return null;const t=[];let r=e;for(;r&&r!==this.embedRoot;){const i=this.getIdFromElement(r);i&&t.unshift(i),r=r.parentElement}return t.length>0?t:null}getIdFromElement(e){if(!e)return null;const r=Array.from(e.classList).find(i=>i.startsWith("comment-"));if(r){const i=r.replace("comment-",""),o=parseInt(i);if(!isNaN(o))return o}return null}getCurrentlyFocusedCommentId(){var t;const e=(t=this.getFocusedCommentInside())==null?void 0:t.parentElement;return this.getIdFromElement(e)}focusCommentById(e,t=!0){if(e===null)return;const r=jl(this.context,e);r==null||r.focus(),t&&$l(e)}focusNextComment(){const e=this.findNextOrPreviousCommentId("next");this.focusCommentById(e)}focusPreviousComment(e=!1){const t=this.findNextOrPreviousCommentId("previous",e);this.focusCommentById(t)}focusNextUnreadComment(){const e=this.getCurrentlyFocusedCommentId();if(e===null)return;const r=(()=>{const i=this.getFlatCommentsList(!1),o=Ju(this.context);let s=!1;for(const l of i){if(s&&o.indexOf(l)>=0)return l;l===e&&(s=!0)}return null})();this.focusCommentById(r)}findNextOrPreviousCommentId(e,t=!1){const r=this.getFlatCommentsList(t),i=this.getCurrentlyFocusedCommentIdPath(),o=i?i[i.length-1]:null;if(!o)return r.length>0?r[0]:null;const s=r.indexOf(o);return s===-1?r.length>0?r[0]:null:e==="next"&&s===r.length-1||e==="previous"&&s===0?null:e==="next"?r[s+1]:r[s-1]}focusCommentWriter(){const e=this.embedRoot.querySelector(".comment-writer .ProseMirror");e&&e.focus()}getFlatCommentsList(e){let t=[];if(!e){const r=b.get(this.context,"commentsList"),i=o=>{if(r[o])for(const s of r[o])t.push(s),i(s)};i("PARENT")}return t}clickButton(e){const t=this.getFocusedCommentInside();if(!t)return;let r=null;e==="upvote"||e==="downvote"?r=t.querySelector(`button.vote.${e.replace("vote","")}`):r=t.querySelector(`.action-button.${e} button`),r&&r.click()}}function Ug(){const[n,e]=w(!1),t=b.use("commentsList"),r=t.PARENT&&t.PARENT.length>0,i=M();function o(l){e(!0),Wl({context:i,sort:l,isMore:!1,onSuccess:()=>{e(!1)}})}function s(){b.set(i,"commentsView","search")}return B(()=>{O(i,"comments_view.is_keyboard_navigation_on")&&setTimeout(()=>{new Vg(i).init()},10)},[]),d("section",{id:"comments",children:[r&&d("div",{class:"comments-top",children:[d($g,{onChange:o}),d("button",{className:"search-button","aria-label":k(i,"search"),onClick:s,children:d(de,{name:"search"})})]}),n?d(K,{padding:100}):d(Co,{index:"PARENT",type:"main"})]})}function jg(){const[n,e]=w(""),t=H(null),[r,i]=w([]),[o,s]=w(!1),[l,a]=w(!1),[c,u]=w(!1),f=H(null),h=M();function p(){b.set(h,"commentsView","comments")}function m(y=0){if(t.current&&t.current.abort(),!n.trim()){s(!1),u(!1),i([]),a(!1);return}y?u(!0):s(!0),t.current=R.callPageApi({context:h,method:"get",endpoint:"/comments/search",data:{query:n,offset:y},success:v=>{s(!1),u(!1),Kl(h,v);const S=v.map(N=>N.id);i(y?[...r,...S]:S),a(v.length===25)}})}function g(){m(r.length)}return B(()=>{m()},[n]),B(()=>{f.current&&f.current.focus()},[]),d("div",{id:"search",children:[d("div",{class:"back",children:d("button",{onClick:p,children:[d(de,{name:"caret"})," ",k(h,"search_back")]})}),d("input",{ref:f,id:"search",class:"search-input",type:"text",name:"search",value:n,onChange:y=>e(y.target.value),placeholder:k(h,"search_comments")+"..."}),o?d(K,{padding:60}):d("div",{class:"search-results",children:d("label",{for:"search",class:"search-results",children:r.length?r.map(y=>d(Ar,{id:y,replies:null})):d(Lt,{padding:50,text:n.trim()?k(h,"no_results"):k(h,"search_type")+"..."})})}),l&&(c?d(K,{padding:15}):d("div",{class:"has-more",children:d(re,{scale:"medium",onClick:g,children:k(h,"load_more")})}))]})}function Hg(){const n=M(),e=O(n,"comments_view.note");return e?d("div",{class:"comments-note",children:d(tu,{content:e})}):null}function qg(){const n=b.use("commentsView");let e;return n==="comments"?e=d(Ug,{}):n==="search"&&(e=d(jg,{})),d("div",{class:"comments-wrap",children:[d(Hg,{}),d(Li,{type:"comment"}),e]})}function Wg(){const n=b.use("specificCommentId"),[e,t]=w(!0),r=Oe.use(n),i=M();return B(()=>{t(!0),R.callPageApi({context:i,method:"get",endpoint:`/comment/${n}/specific`,success:o=>{const s=b.get(i,"page");if(s&&o.comment.page_id!==s.id){b.set(i,"specificCommentId",null);return}vr(i,o.comment),Qe(i,o.replies.indexed),b.set(i,"specificCommentRepliesList",o.replies.list),b.set(i,"specificCommentHasMoreIds",o.replies.has_more_ids),t(!1)},error:()=>{b.set(i,"specificCommentId",null)}})},[n]),e?d(K,{padding:60}):d("div",{class:"specific-comment-view",children:[d("div",{class:"button-wrap",children:d(re,{onClick:()=>b.set(i,"specificCommentId",null),scale:"medium",children:k(i,"show_all_comments")})}),r.parent_id&&d("div",{class:"parent-loader",children:d(dt,{buttonType:"no-background",onClick:()=>{t(!0),b.set(i,"specificCommentId",r.parent_id)},children:k(i,"show_parent_comment")})}),d(Ar,{id:n,replies:d(Co,{index:n,type:"specific"}),canReply:!0})]})}function Kg(){const n=b.use("license"),t=ca("misc:branding",{text:"by Hyvor Talk",props:{href:"https://talk.hyvor.com?utm_source=embed&utm_medium="+location.hostname,target:"_blank",rel:"noopener noreferrer"}})();return n.no_branding?null:d("div",{className:"main-box-footer",children:d("a",{...t.props,children:t.text})})}function Jg(){const n=b.use("specificCommentId");let e;return n?e=d(Wg,{}):e=d(qg,{}),d("div",{className:"main-box",children:[d(Lg,{}),e,d(Kg,{})]})}const ai={},Gg=(n,e)=>{const t=b.get(n,"ratings"),r=b.get(n,"userRating");b.set(n,"userRating",e);const i=r?t.count:t.count+1,o=(()=>{let s=t.average*t.count;return r&&(s-=r),s+=e,s/i})();Bt(n,"ratings",{count:i,average:o}),ai[n]&&clearTimeout(ai[n]),ai[n]=setTimeout(()=>{R.callPageApi({context:n,method:"post",endpoint:"/rate",data:{rating:e},success:()=>{Fe(n,"rating",{rating:e,count:i,average:o})}})},300)};function Yg(){const[n,e]=w(null),t=b.use("userRating"),r=M(),i=H(null);function o(f){if(Gg(r,f),!i.current)return;const h=i.current.getRootNode().querySelector("#star-"+r+"-"+f);h&&h.focus()}function s(){return window.innerWidth<768}function l(f){s()||e(f)}function a(){s()||e(null)}function c(f,h){switch(f.key){case" ":case"Enter":o(h);break;case"Up":case"ArrowUp":case"Left":case"ArrowLeft":o(h===1?5:h-1);break;case"Down":case"ArrowDown":case"Right":case"ArrowRight":o(h===5?1:h+1);break}}const u=O(r,"ratings.star_color");return d("div",{class:"rater-wrap",ref:i,children:d("div",{class:"rater",children:[d("div",{className:"star-placeholders",children:[1,2,3,4,5].map(()=>d(de,{name:"star",wrapperProps:{"aria-hidden":"true"}}))}),d("div",{className:"star-handlers",onMouseLeave:()=>a(),style:{color:u,"--star-color":u},"aria-labelledby":"ratings-title-"+r,role:"radiogroup",children:[1,2,3,4,5].map(f=>{let h=!1;const p=t??0;return n&&n>=f&&(h=!0),n?n>=f&&(h=!0):p>=f&&(h=!0),d(de,{name:"star",wrapperProps:{onMouseEnter:()=>l(f),style:{color:h?"inherit":"transparent"},onClick:()=>o(f),onKeyDown:m=>c(m,f),role:"radio","aria-checked":p===f,"aria-label":f+" stars",id:"star-"+r+"-"+f,tabindex:p===0?f===1?0:-1:p===f?0:-1},svgProps:{"aria-hidden":!0}})})})]})})}function Xg(){const n=b.use("ratings"),e=M();return d("section",{class:"ratings","aria-labelledby":"ratings-title-"+e,children:[d("div",{class:"ratings-title",id:"ratings-title-"+e,children:[O(e,"text.ratings")||k(e,"ratings_text")," "]}),d(Yg,{}),n.average?d("div",{class:"ratings-average","aria-label":k(e,"ratings_average_aria",{"*":n.average.toFixed(1)}),children:n.average.toFixed(1)}):null,n.count?d("div",{class:"ratings-count","aria-label":k(e,"ratings_total_aria",{"*":n.count.toString()}),children:n.count===1?k(e,"ratings_1"):k(e,"ratings_multi",{"*":n.count.toString()})}):null]})}function ci(n){return n&&typeof n=="object"&&!Array.isArray(n)}function Fi(n,...e){if(!e.length)return n;const t=e.shift();if(ci(n)&&ci(t))for(const r in t)ci(t[r])?(n[r]||Object.assign(n,{[r]:{}}),Fi(n[r],t[r])):Object.assign(n,{[r]:t[r]});return Fi(n,...e)}function Qg(){const n=b.use("modalImageUrl"),e=M();return n?d("div",{class:"image-modal",children:[d("div",{class:"modal-closer",onClick:()=>b.set(e,"modalImageUrl",null)}),d("img",{src:n,alt:"Popup image"})]}):null}function Zg(n){const e=M(),[t,r]=w("loading"),[i,o]=w(null);_u(y=>Vl(e,y));const[s,l]=w(0),a=[1e3,3e3,5e3],c=b.use("language"),u=b.use("colors");function f(y=!1){var v,S;const x=((S=(v=n.settings)==null?void 0:v.comments_view)==null?void 0:S.default_sort)||void 0;R.call({context:e,method:"post",endpoint:"/init",data:{domain:location.hostname,page:n.page,sso:n.sso,comments:{sort:x}},success:N=>{na.set(N.config);const J=n1(N.website,n.settings);b.set(e,"website",J),b.set(e,"page",N.page),b.set(e,"license",N.license);const V=N.language;n.translations&&(V.translations={...V.translations,...n.translations}),b.set(e,"language",V),N.page_badges&&b.set(e,"pageBadges",N.page_badges),b.set(e,"badges",N.badges),b.set(e,"plans",N.plans),n.onLoad(J),Xl(e,N.user_page_state),Ql(e,N.user_website_state),N.user&&b.set(e,"user",N.user),b.set(e,"commentsFirstLoadedAt",_o()),b.set(e,"commentsSort",x||N.website.comments_view.default_sort),Qe(e,N.comments.indexed),b.set(e,"commentsList",N.comments.list),b.set(e,"commentsHasMoreIds",N.comments.has_more_ids),N.stateless_sso_token&&b.set(e,"statelessSsoToken",N.stateless_sso_token),new Ad(e),Xu(e),r("success"),Fe(e,"loaded",null)},error:N=>{r("error"),o(N),p(!y)}})}function h(y=!1){y&&(r("loading"),o(null)),f(y)}function p(y=!0){y&&l(x=>x>2?x:(setTimeout(()=>{h()},a[x]),x+1))}B(()=>{b.set(e,"websiteId",n.website.id),b.set(e,"htDomain",n.instance||"https://talk.hyvor.com"),b.set(e,"components",n.components),f()},[]);let m,g=null;return t==="loading"?m=d(K,{padding:60}):t==="error"?m=d(e1,{error:i,onRetry:h}):(g=O(e,"ui.width"),m=d("div",{children:[d(t1,{}),d(Jg,{})]})),d("div",{id:"app",part:"app",class:u+(c.is_rtl?" rtl":""),dir:c.is_rtl?"rtl":"ltr",style:{width:g?g+"px":"100%"},children:[m,d(Og,{}),d(Qg,{}),d(Gd,{})]})}function e1({error:n,onRetry:e}){return n?d(te,{children:[d("div",{id:"embed-error",children:n}),n===Fl&&d("div",{id:"retry",children:d("button",{onClick:()=>e(!0),children:"Reload"})})]}):null}function t1(){const n=M(),e=O(n,"top_widget");return e==="reactions"?d(Vd,{}):e==="ratings"?d(Xg,{}):null}function n1(n,e){return delete e.id,delete(e.auth||{}).type,delete(e.auth||{}).sso_type,Fi(n,e)}class r1 extends HTMLElement{constructor(){super();Y(this,"root");Y(this,"settings",{});Y(this,"translations",null);Y(this,"components",{});Y(this,"loaded",!1);Y(this,"context");const t=this.attachShadow({mode:"open"}),r=document.createElement("div");r.id="root",t.append(r),this.addStylesheet(bu),this.root=r,this.context=Math.ceil(Math.random()*1e9),b.set(this.context,"hyvorTalkElement",this)}connectedCallback(){this.id="hyvor-talk-comments-"+this.context;const t=this.getLoading();if(t==="default")this.load();else if(t==="lazy"){const r=new IntersectionObserver(i=>{i[0].isIntersecting&&(this.load(),r.disconnect())},{threshold:0});r.observe(this)}}disconnectedCallback(){var t;(t=Dd(this.context))==null||t.disconnect()}load(){const t=this.getAttribute("sso-user"),r=this.getAttribute("sso-hash"),i=this.getAttribute("instance");i&&this.observeImages(i),pu(d(zl.Provider,{value:this.context,children:d(Zg,{website:{id:Number(this.getAttribute("website-id"))},page:{identifier:this.getPageIdentifier(),url:this.getPageUrl(),title:this.getAttribute("page-title")||document.title,language:this.getAttribute("page-language"),author:this.getAttribute("page-author"),badges:this.getAttribute("page-badges")},sso:t?{user:t,hash:r??""}:null,settings:this.getSettings(),translations:this.getTranslations(),components:this.components,onLoad:o=>this.handleLoad(o),instance:i})}),this.root)}observeImages(t){const r=o=>{o.src.includes("https://talk.hyvor.com")&&(o.src=o.src.replace("https://talk.hyvor.com",t))};new MutationObserver(o=>{for(const s of o)s.type==="childList"&&s.addedNodes.forEach(l=>{l.tagName==="IMG"&&r(l),l.querySelectorAll&&l.querySelectorAll("img").forEach(r)})}).observe(this.shadowRoot,{childList:!0,subtree:!0})}getSettings(){if(Object.keys(this.settings).length)return this.settings;const t=this.getAttribute("settings");if(!t)return{};let r={};try{if(r=JSON.parse(t),typeof r!="object")return console.error("Invalid settings attribute"),{}}catch(i){return console.error("Invalid settings attribute",i),{}}return r}getTranslations(){if(this.translations)return this.translations;const t=this.attributes,r={};for(let i=0;i